diff --git a/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java b/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java index 3036ef58d..cf7fe3eb5 100644 --- a/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java +++ b/cmdb/src/main/java/com/alibaba/nacos/cmdb/controllers/OperationController.java @@ -40,7 +40,7 @@ public class OperationController { @Autowired private CmdbProvider cmdbProvider; - @RequestMapping(value = "/updateSwitch", method = RequestMethod.POST) + @RequestMapping(value = "/switch", method = RequestMethod.PUT) public String updateSwitch(HttpServletRequest request) throws Exception { String entry = WebUtils.required(request, "entry"); @@ -64,7 +64,7 @@ public class OperationController { return "ok"; } - @RequestMapping(value = "/queryLabel", method = RequestMethod.GET) + @RequestMapping(value = "/label", method = RequestMethod.GET) public String queryLabel(HttpServletRequest request) throws Exception { String entry = WebUtils.required(request, "entry"); String label = WebUtils.required(request, "label"); diff --git a/distribution/bin/startup.sh b/distribution/bin/startup.sh index 679361821..a7e9108ee 100644 --- a/distribution/bin/startup.sh +++ b/distribution/bin/startup.sh @@ -97,7 +97,7 @@ if [[ "$JAVA_MAJOR_VERSION" -ge "9" ]] ; then JAVA_OPT="${JAVA_OPT} -cp .:${BASE_DIR}/plugins/cmdb/*.jar" JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400" else - #JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${BASE_DIR}/plugins/cmdb" + JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/ext:${BASE_DIR}/plugins/cmdb" JAVA_OPT="${JAVA_OPT} -Xloggc:${BASE_DIR}/logs/nacos_gc.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=100M" fi diff --git a/distribution/plugins/cmdb/nacos-cmdb-plugin-example.jar b/distribution/plugins/cmdb/nacos-cmdb-plugin-example.jar index 30fbe4e2c..f44e73976 100644 Binary files a/distribution/plugins/cmdb/nacos-cmdb-plugin-example.jar and b/distribution/plugins/cmdb/nacos-cmdb-plugin-example.jar differ diff --git a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java index bd47f2865..afffbe885 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/consistency/ephemeral/distro/TaskDispatcher.java @@ -27,7 +27,9 @@ import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.*; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; /** * Data sync task dispatcher @@ -96,8 +98,7 @@ public class TaskDispatcher { String key = queue.poll(partitionConfig.getTaskDispatchPeriod(), TimeUnit.MILLISECONDS); - if (StringUtils.isBlank(key) || dataSyncer.getServers() == null || - dataSyncer.getServers().isEmpty()) { + if (dataSyncer.getServers() == null || dataSyncer.getServers().isEmpty()) { continue; } @@ -105,7 +106,7 @@ public class TaskDispatcher { keys = new ArrayList<>(); } - if (dataSize < partitionConfig.getBatchSyncKeyCount()) { + if (StringUtils.isNotBlank(key)) { keys.add(key); dataSize++; } diff --git a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java index d45f18e1a..77c8a06a2 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/controllers/ServiceController.java @@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import javax.servlet.http.HttpServletRequest; +import java.net.URLDecoder; import java.util.*; /** @@ -397,13 +398,13 @@ public class ServiceController { return filteredServices; } - private Selector parseSelector(String selectorJsonString) throws NacosException { + private Selector parseSelector(String selectorJsonString) throws Exception { if (StringUtils.isBlank(selectorJsonString)) { return new NoneSelector(); } - JSONObject selectorJson = JSON.parseObject(selectorJsonString); + JSONObject selectorJson = JSON.parseObject(URLDecoder.decode(selectorJsonString, "UTF-8")); switch (SelectorType.valueOf(selectorJson.getString("type"))) { case none: return new NoneSelector(); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java index 644b61f29..97d12da55 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/core/Service.java @@ -473,8 +473,8 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement for (Cluster cluster : clusters) { Cluster oldCluster = clusterMap.get(cluster.getName()); if (oldCluster != null) { - oldCluster.update(cluster); oldCluster.setService(this); + oldCluster.update(cluster); } else { cluster.init(); cluster.setService(this); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java b/naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java index 7627e12d2..401a2f30b 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/misc/SwitchManager.java @@ -20,9 +20,9 @@ import com.alibaba.nacos.api.common.Constants; import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.naming.cluster.ServerMode; import com.alibaba.nacos.naming.consistency.ConsistencyService; +import com.alibaba.nacos.naming.consistency.Datum; import com.alibaba.nacos.naming.consistency.KeyBuilder; import com.alibaba.nacos.naming.consistency.RecordListener; -import com.alibaba.nacos.naming.consistency.Datum; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -70,7 +70,7 @@ public class SwitchManager implements RecordListener { Datum datum = consistencyService.get(UtilsAndCommons.getSwitchDomainKey()); SwitchDomain switchDomain; - if (datum != null) { + if (datum != null && datum.value != null) { switchDomain = (SwitchDomain) datum.value; } else { switchDomain = this.switchDomain.clone(); diff --git a/naming/src/main/java/com/alibaba/nacos/naming/selector/LabelSelector.java b/naming/src/main/java/com/alibaba/nacos/naming/selector/LabelSelector.java index 2de169458..1f5a29fa2 100644 --- a/naming/src/main/java/com/alibaba/nacos/naming/selector/LabelSelector.java +++ b/naming/src/main/java/com/alibaba/nacos/naming/selector/LabelSelector.java @@ -57,8 +57,6 @@ import java.util.Set; */ public class LabelSelector extends ExpressionSelector implements Selector { - private CmdbReader cmdbReader; - /** * The labels relevant to this the selector. * @@ -93,9 +91,11 @@ public class LabelSelector extends ExpressionSelector implements Selector { public LabelSelector() { setType(SelectorType.label.name()); - cmdbReader = SpringContext.getAppContext().getBean(CmdbReader.class); } + private CmdbReader getCmdbReader() { + return SpringContext.getAppContext().getBean(CmdbReader.class); + } public static Set parseExpression(String expression) throws NacosException { return ExpressionInterpreter.parseExpression(expression); @@ -115,11 +115,11 @@ public class LabelSelector extends ExpressionSelector implements Selector { boolean matched = true; for (String labelName : getLabels()) { - String consumerLabelValue = cmdbReader.queryLabel(consumer, PreservedEntityTypes.ip.name(), labelName); + String consumerLabelValue = getCmdbReader().queryLabel(consumer, PreservedEntityTypes.ip.name(), labelName); if (StringUtils.isNotBlank(consumerLabelValue) && !StringUtils.equals(consumerLabelValue, - cmdbReader.queryLabel(instance.getIp(), PreservedEntityTypes.ip.name(), labelName))) { + getCmdbReader().queryLabel(instance.getIp(), PreservedEntityTypes.ip.name(), labelName))) { matched = false; break; }