This commit is contained in:
nkorange 2019-03-13 18:41:00 +08:00
parent e7171c0eef
commit f0c71e6d8b
8 changed files with 19 additions and 17 deletions

View File

@ -40,7 +40,7 @@ public class OperationController {
@Autowired @Autowired
private CmdbProvider cmdbProvider; private CmdbProvider cmdbProvider;
@RequestMapping(value = "/updateSwitch", method = RequestMethod.POST) @RequestMapping(value = "/switch", method = RequestMethod.PUT)
public String updateSwitch(HttpServletRequest request) throws Exception { public String updateSwitch(HttpServletRequest request) throws Exception {
String entry = WebUtils.required(request, "entry"); String entry = WebUtils.required(request, "entry");
@ -64,7 +64,7 @@ public class OperationController {
return "ok"; return "ok";
} }
@RequestMapping(value = "/queryLabel", method = RequestMethod.GET) @RequestMapping(value = "/label", method = RequestMethod.GET)
public String queryLabel(HttpServletRequest request) throws Exception { public String queryLabel(HttpServletRequest request) throws Exception {
String entry = WebUtils.required(request, "entry"); String entry = WebUtils.required(request, "entry");
String label = WebUtils.required(request, "label"); String label = WebUtils.required(request, "label");

View File

@ -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} -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" JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${BASE_DIR}/logs/nacos_gc.log:time,tags:filecount=10,filesize=102400"
else 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" 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 fi

View File

@ -27,7 +27,9 @@ import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct; import javax.annotation.PostConstruct;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 * Data sync task dispatcher
@ -96,8 +98,7 @@ public class TaskDispatcher {
String key = queue.poll(partitionConfig.getTaskDispatchPeriod(), String key = queue.poll(partitionConfig.getTaskDispatchPeriod(),
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
if (StringUtils.isBlank(key) || dataSyncer.getServers() == null || if (dataSyncer.getServers() == null || dataSyncer.getServers().isEmpty()) {
dataSyncer.getServers().isEmpty()) {
continue; continue;
} }
@ -105,7 +106,7 @@ public class TaskDispatcher {
keys = new ArrayList<>(); keys = new ArrayList<>();
} }
if (dataSize < partitionConfig.getBatchSyncKeyCount()) { if (StringUtils.isNotBlank(key)) {
keys.add(key); keys.add(key);
dataSize++; dataSize++;
} }

View File

@ -38,6 +38,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.*; import java.util.*;
/** /**
@ -397,13 +398,13 @@ public class ServiceController {
return filteredServices; return filteredServices;
} }
private Selector parseSelector(String selectorJsonString) throws NacosException { private Selector parseSelector(String selectorJsonString) throws Exception {
if (StringUtils.isBlank(selectorJsonString)) { if (StringUtils.isBlank(selectorJsonString)) {
return new NoneSelector(); return new NoneSelector();
} }
JSONObject selectorJson = JSON.parseObject(selectorJsonString); JSONObject selectorJson = JSON.parseObject(URLDecoder.decode(selectorJsonString, "UTF-8"));
switch (SelectorType.valueOf(selectorJson.getString("type"))) { switch (SelectorType.valueOf(selectorJson.getString("type"))) {
case none: case none:
return new NoneSelector(); return new NoneSelector();

View File

@ -473,8 +473,8 @@ public class Service extends com.alibaba.nacos.api.naming.pojo.Service implement
for (Cluster cluster : clusters) { for (Cluster cluster : clusters) {
Cluster oldCluster = clusterMap.get(cluster.getName()); Cluster oldCluster = clusterMap.get(cluster.getName());
if (oldCluster != null) { if (oldCluster != null) {
oldCluster.update(cluster);
oldCluster.setService(this); oldCluster.setService(this);
oldCluster.update(cluster);
} else { } else {
cluster.init(); cluster.init();
cluster.setService(this); cluster.setService(this);

View File

@ -20,9 +20,9 @@ import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.exception.NacosException; import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.naming.cluster.ServerMode; import com.alibaba.nacos.naming.cluster.ServerMode;
import com.alibaba.nacos.naming.consistency.ConsistencyService; 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.KeyBuilder;
import com.alibaba.nacos.naming.consistency.RecordListener; import com.alibaba.nacos.naming.consistency.RecordListener;
import com.alibaba.nacos.naming.consistency.Datum;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -70,7 +70,7 @@ public class SwitchManager implements RecordListener<SwitchDomain> {
Datum datum = consistencyService.get(UtilsAndCommons.getSwitchDomainKey()); Datum datum = consistencyService.get(UtilsAndCommons.getSwitchDomainKey());
SwitchDomain switchDomain; SwitchDomain switchDomain;
if (datum != null) { if (datum != null && datum.value != null) {
switchDomain = (SwitchDomain) datum.value; switchDomain = (SwitchDomain) datum.value;
} else { } else {
switchDomain = this.switchDomain.clone(); switchDomain = this.switchDomain.clone();

View File

@ -57,8 +57,6 @@ import java.util.Set;
*/ */
public class LabelSelector extends ExpressionSelector implements Selector { public class LabelSelector extends ExpressionSelector implements Selector {
private CmdbReader cmdbReader;
/** /**
* The labels relevant to this the selector. * The labels relevant to this the selector.
* *
@ -93,9 +91,11 @@ public class LabelSelector extends ExpressionSelector implements Selector {
public LabelSelector() { public LabelSelector() {
setType(SelectorType.label.name()); setType(SelectorType.label.name());
cmdbReader = SpringContext.getAppContext().getBean(CmdbReader.class);
} }
private CmdbReader getCmdbReader() {
return SpringContext.getAppContext().getBean(CmdbReader.class);
}
public static Set<String> parseExpression(String expression) throws NacosException { public static Set<String> parseExpression(String expression) throws NacosException {
return ExpressionInterpreter.parseExpression(expression); return ExpressionInterpreter.parseExpression(expression);
@ -115,11 +115,11 @@ public class LabelSelector extends ExpressionSelector implements Selector {
boolean matched = true; boolean matched = true;
for (String labelName : getLabels()) { 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) && if (StringUtils.isNotBlank(consumerLabelValue) &&
!StringUtils.equals(consumerLabelValue, !StringUtils.equals(consumerLabelValue,
cmdbReader.queryLabel(instance.getIp(), PreservedEntityTypes.ip.name(), labelName))) { getCmdbReader().queryLabel(instance.getIp(), PreservedEntityTypes.ip.name(), labelName))) {
matched = false; matched = false;
break; break;
} }