Skip to content

Commit

Permalink
Refactor aspect.
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewAden committed Jan 10, 2025
1 parent 745949c commit 08564eb
Show file tree
Hide file tree
Showing 14 changed files with 396 additions and 492 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,15 @@
@Component
public class RequestLogAspect {

/**
* Publish config.
*/
private static final String PUBLISH_CONFIG =
"execution(* com.alibaba.nacos.config.server.service.ConfigOperationService.publishConfig(..))";

/**
* Get config.
*/
private static final String GET_CONFIG =
"execution(* com.alibaba.nacos.config.server.service.query.ConfigQueryChainService.handle(..))";

/**
* Delete config.
*/
private static final String DELETE_CONFIG =
"execution(* com.alibaba.nacos.config.server.service.ConfigOperationService.deleteConfig(..))";

/**
* Listen for config changes.
*/
private static final String CONFIG_CHANGE_LISTEN_RPC =
"execution(* com.alibaba.nacos.core.remote.RequestHandler.handleRequest(..)) "
+ " && target(com.alibaba.nacos.config.server.remote.ConfigChangeBatchListenRequestHandler) && args(request,meta)";
Expand All @@ -80,7 +68,6 @@ public Object interfacePublishConfig(ProceedingJoinPoint pjp) throws Throwable {
Object[] args = pjp.getArgs();
ConfigForm configForm = (ConfigForm) args[0];
ConfigRequestInfo configRequestInfo = (ConfigRequestInfo) args[1];

String dataId = configForm.getDataId();
String group = configForm.getGroup();
String namespaceId = configForm.getNamespaceId();
Expand All @@ -103,7 +90,6 @@ public Object interfacePublishConfig(ProceedingJoinPoint pjp) throws Throwable {
public Object interfaceGetConfig(ProceedingJoinPoint pjp) throws Throwable {
Object[] args = pjp.getArgs();
ConfigQueryChainRequest chainRequest = (ConfigQueryChainRequest) args[0];

String dataId = chainRequest.getDataId();
String group = chainRequest.getGroup();
String tenant = chainRequest.getTenant();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ public Boolean publishConfig(HttpServletRequest request, HttpServletResponse res

ConfigRequestInfo configRequestInfo = new ConfigRequestInfo();
configRequestInfo.setSrcIp(RequestUtil.getRemoteIp(request));
configRequestInfo.setSrcType("http");
configRequestInfo.setRequestIpApp(RequestUtil.getAppName(request));
configRequestInfo.setBetaIps(request.getHeader("betaIps"));
configRequestInfo.setCasMd5(request.getHeader("casMd5"));
Expand Down Expand Up @@ -299,7 +300,7 @@ public Boolean deleteConfig(HttpServletRequest request, HttpServletResponse resp
String clientIp = RequestUtil.getRemoteIp(request);
String srcUser = RequestUtil.getSrcUserName(request);

return configOperationService.deleteConfig(dataId, group, tenant, tag, clientIp, srcUser);
return configOperationService.deleteConfig(dataId, group, tenant, tag, clientIp, srcUser, "http");
}

/**
Expand Down Expand Up @@ -664,7 +665,7 @@ public RestResult<Map<String, Object>> importAndPublishConfig(HttpServletRequest
final String srcIp = RequestUtil.getRemoteIp(request);
String requestIpApp = RequestUtil.getAppName(request);
final Timestamp time = TimeUtils.getCurrentTime();
Map<String, Object> saveResult = configInfoPersistService.batchInsertOrUpdate(configInfoList, srcUser, srcIp,
Map<String, Object> saveResult = configOperationService.batchInsertOrUpdate(configInfoList, srcUser, srcIp,
null, policy);
for (ConfigInfo configInfo : configInfoList) {
ConfigChangePublisher.notifyConfigChange(
Expand Down Expand Up @@ -916,7 +917,7 @@ public RestResult<Map<String, Object>> cloneConfig(HttpServletRequest request,
final String srcIp = RequestUtil.getRemoteIp(request);
String requestIpApp = RequestUtil.getAppName(request);
final Timestamp time = TimeUtils.getCurrentTime();
Map<String, Object> saveResult = configInfoPersistService.batchInsertOrUpdate(configInfoList4Clone, srcUser,
Map<String, Object> saveResult = configOperationService.batchInsertOrUpdate(configInfoList4Clone, srcUser,
srcIp, null, policy);
for (ConfigInfo configInfo : configInfoList4Clone) {
ConfigChangePublisher.notifyConfigChange(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public Result<Boolean> publishConfig(ConfigForm configForm, HttpServletRequest r

ConfigRequestInfo configRequestInfo = new ConfigRequestInfo();
configRequestInfo.setSrcIp(RequestUtil.getRemoteIp(request));
configRequestInfo.setSrcType("http");
configRequestInfo.setRequestIpApp(RequestUtil.getAppName(request));
configRequestInfo.setBetaIps(request.getHeader("betaIps"));
configRequestInfo.setCasMd5(request.getHeader("casMd5"));
Expand Down Expand Up @@ -169,7 +170,7 @@ public Result<Boolean> deleteConfig(HttpServletRequest request, @RequestParam("d

String clientIp = RequestUtil.getRemoteIp(request);
String srcUser = RequestUtil.getSrcUserName(request);
return Result.success(configOperationService.deleteConfig(dataId, group, namespaceId, tag, clientIp, srcUser));
return Result.success(configOperationService.deleteConfig(dataId, group, namespaceId, tag, clientIp, srcUser, "http"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ public class ConfigRequestInfo implements Serializable {

private String srcIp;

private String srcType;

private String requestIpApp;

private String betaIps;

private String casMd5;

public ConfigRequestInfo(String srcIp, String requestIpApp, String betaIps, String casMd5) {
public ConfigRequestInfo(String srcIp, String srcType, String requestIpApp, String betaIps, String casMd5) {
this.srcIp = srcIp;
this.srcType = srcType;
this.requestIpApp = requestIpApp;
this.betaIps = betaIps;
this.casMd5 = casMd5;
Expand All @@ -54,6 +57,14 @@ public void setSrcIp(String srcIp) {
this.srcIp = srcIp;
}

public String getSrcType() {
return srcType;
}

public void setSrcType(String srcType) {
this.srcType = srcType;
}

public String getRequestIpApp() {
return requestIpApp;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public ConfigPublishResponse handle(ConfigPublishRequest request, RequestMeta me

ConfigRequestInfo configRequestInfo = new ConfigRequestInfo();
configRequestInfo.setSrcIp(srcIp);
configRequestInfo.setSrcType("rpc");
configRequestInfo.setRequestIpApp(meta.getLabels().get(Constants.APPNAME));
configRequestInfo.setBetaIps(request.getAdditionParam("betaIps"));
configRequestInfo.setCasMd5(request.getCasMd5());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public ConfigRemoveResponse handle(ConfigRemoveRequest configRemoveRequest, Requ
ParamUtils.checkParam(tag);

try {
configOperationService.deleteConfig(dataId, group, tenant, tag, clientIp, null);
configOperationService.deleteConfig(dataId, group, tenant, tag, clientIp, null, "rpc");
return ConfigRemoveResponse.buildSuccessResponse();
} catch (Exception e) {
Loggers.REMOTE_DIGEST.error("remove config error,error msg is {}", e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.alibaba.nacos.config.server.model.ConfigInfo;
import com.alibaba.nacos.config.server.model.ConfigOperateResult;
import com.alibaba.nacos.config.server.model.ConfigRequestInfo;
import com.alibaba.nacos.config.server.model.SameConfigPolicy;
import com.alibaba.nacos.config.server.model.event.ConfigDataChangeEvent;
import com.alibaba.nacos.config.server.model.form.ConfigForm;
import com.alibaba.nacos.config.server.model.gray.BetaGrayRule;
Expand Down Expand Up @@ -294,7 +295,7 @@ private int getMaxGrayVersionCount() {
* Synchronously delete all pre-aggregation data under a dataId.
*/
public Boolean deleteConfig(String dataId, String group, String namespaceId, String tag, String clientIp,
String srcUser) {
String srcUser, String srcType) {
String persistEvent = ConfigTraceService.PERSISTENCE_EVENT;
String grayName = "";
if (StringUtils.isBlank(tag)) {
Expand Down Expand Up @@ -343,6 +344,14 @@ public Boolean deleteConfigs(List<Long> ids, String srcIp, String srcUser) {
return true;
}

/**
* Batch insert or update configuration information.
*/
public Map<String, Object> batchInsertOrUpdate(List<ConfigAllInfo> configInfoList, String srcUser, String srcIp,
Map<String, Object> configAdvanceInfo, SameConfigPolicy policy) throws NacosException {
return configInfoPersistService.batchInsertOrUpdate(configInfoList, srcUser, srcIp, configAdvanceInfo, policy);
}

public Map<String, Object> getConfigAdvanceInfo(ConfigForm configForm) {
Map<String, Object> configAdvanceInfo = new HashMap<>(10);
MapUtil.putIfValNoNull(configAdvanceInfo, "config_tags", configForm.getConfigTags());
Expand Down
Loading

0 comments on commit 08564eb

Please sign in to comment.