Skip to content

Commit

Permalink
#502 fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Mar 13, 2019
1 parent e7171c0 commit f0c71e6
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 17 deletions.
Expand Up @@ -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");
Expand All @@ -64,7 +64,7 @@ public String updateSwitch(HttpServletRequest request) throws Exception {
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");
Expand Down
2 changes: 1 addition & 1 deletion distribution/bin/startup.sh
Expand Up @@ -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

Expand Down
Binary file modified distribution/plugins/cmdb/nacos-cmdb-plugin-example.jar
Binary file not shown.
Expand Up @@ -27,7 +27,9 @@
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
Expand Down Expand Up @@ -96,16 +98,15 @@ public void run() {
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;
}

if (dataSize == 0) {
keys = new ArrayList<>();
}

if (dataSize < partitionConfig.getBatchSyncKeyCount()) {
if (StringUtils.isNotBlank(key)) {
keys.add(key);
dataSize++;
}
Expand Down
Expand Up @@ -38,6 +38,7 @@
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.*;

/**
Expand Down Expand Up @@ -397,13 +398,13 @@ private List<String> filterServiceMetadata(String namespaceId, List<String> serv
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();
Expand Down
Expand Up @@ -473,8 +473,8 @@ private void updateOrAddCluster(Collection<Cluster> clusters) {
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);
Expand Down
Expand Up @@ -20,9 +20,9 @@
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;
Expand Down Expand Up @@ -70,7 +70,7 @@ public void update(String entry, String value, boolean debug) throws Exception {
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();
Expand Down
Expand Up @@ -57,8 +57,6 @@
*/
public class LabelSelector extends ExpressionSelector implements Selector {

private CmdbReader cmdbReader;

/**
* The labels relevant to this the selector.
*
Expand Down Expand Up @@ -93,9 +91,11 @@ public void setLabels(Set<String> labels) {

public LabelSelector() {
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 {
return ExpressionInterpreter.parseExpression(expression);
Expand All @@ -115,11 +115,11 @@ public List<Instance> select(String consumer, List<Instance> providers) {
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;
}
Expand Down

0 comments on commit f0c71e6

Please sign in to comment.