This commit is contained in:
nkorange 2018-12-25 20:59:08 +08:00
parent 478cb1533e
commit 16794d15e5
7 changed files with 55 additions and 26 deletions

View File

@ -25,6 +25,7 @@ import com.alibaba.nacos.naming.core.IpAddress;
import com.alibaba.nacos.naming.core.VirtualClusterDomain;
import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.HealthCheckMode;
import com.alibaba.nacos.naming.misc.Switch;
import com.alibaba.nacos.naming.misc.UtilsAndCommons;
import com.alibaba.nacos.naming.selector.LabelSelector;
import com.alibaba.nacos.naming.selector.NoneSelector;
@ -62,7 +63,7 @@ public class ServiceController {
}
float protectThreshold = NumberUtils.toFloat(WebUtils.optional(request, "protectThreshold", "0"));
String healthCheckMode = WebUtils.optional(request, "healthCheckMode", "client");
String healthCheckMode = WebUtils.optional(request, "healthCheckMode", Switch.getDefaultHealthCheckMode());
String metadata = WebUtils.optional(request, "metadata", StringUtils.EMPTY);
String selector = WebUtils.optional(request, "selector", StringUtils.EMPTY);
Map<String, String> metadataMap = new HashMap<>(16);

View File

@ -62,10 +62,8 @@ public class Switch {
if (StringUtils.isEmpty(value)) {
return;
}
SwitchDomain switchDomain = JSON.parseObject(value, new TypeReference<SwitchDomain>() {
dom = JSON.parseObject(value, new TypeReference<SwitchDomain>() {
});
dom = switchDomain;
}
@Override
@ -77,7 +75,7 @@ public class Switch {
public static long getPushCacheMillis(String dom) {
if (Switch.dom.pushCacheMillisMap == null
|| !Switch.dom.pushCacheMillisMap.containsKey(dom)) {
|| !Switch.dom.pushCacheMillisMap.containsKey(dom)) {
return Switch.dom.defaultPushCacheMillis;
}
@ -90,7 +88,7 @@ public class Switch {
public static long getCacheMillis(String dom) {
if (Switch.dom.cacheMillisMap == null
|| !Switch.dom.cacheMillisMap.containsKey(dom)) {
|| !Switch.dom.cacheMillisMap.containsKey(dom)) {
return Switch.dom.defaultCacheMillis;
}
@ -165,6 +163,14 @@ public class Switch {
Switch.dom.healthCheckEnabled = enabled;
}
public static String getDefaultHealthCheckMode() {
return Switch.dom.defaultHealthCheckMode;
}
public static void setDefaultHealthCheckMode(String healthCheckMode) {
Switch.dom.defaultHealthCheckMode = healthCheckMode;
}
public static boolean isEnableAuthentication() {
return dom.isEnableAuthentication();
}
@ -191,7 +197,7 @@ public class Switch {
public static Integer getAdWeight(String ip) {
if (dom.adWeightMap == null
|| !dom.adWeightMap.containsKey(ip)) {
|| !dom.adWeightMap.containsKey(ip)) {
return 0;
}
@ -205,6 +211,7 @@ public class Switch {
public static String getPushJavaVersion() {
return dom.pushJavaVersion;
}
public static String getPushGoVersion() {
return dom.pushGoVersion;
}
@ -220,6 +227,7 @@ public class Switch {
public static void setPushJavaVersion(String pushJavaVersion) {
dom.pushJavaVersion = pushJavaVersion;
}
public static void setPushGoVersion(String pushGoVersion) {
dom.pushGoVersion = pushGoVersion;
}

View File

@ -19,6 +19,7 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.nacos.naming.core.Domain;
import com.alibaba.nacos.naming.core.IpAddress;
import com.alibaba.nacos.naming.healthcheck.HealthCheckMode;
import com.alibaba.nacos.naming.raft.RaftListener;
import org.apache.commons.lang3.StringUtils;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
@ -52,6 +53,8 @@ public class SwitchDomain implements Domain, RaftListener {
public boolean healthCheckEnabled = true;
public String defaultHealthCheckMode = HealthCheckMode.client.name();
public boolean distroEnabled = true;
public boolean enableStandalone = true;

View File

@ -38,6 +38,7 @@ public class SwitchEntry {
public static final String MASTERS = "masters";
public static final String DISTRO = "distro";
public static final String CHECK = "check";
public static final String DEFAULT_HEALTH_CHECK_MODE = "defaultHealthCheckMode";
public static final String DOM_STATUS_SYNC_PERIOD = "domStatusSynchronizationPeriodMillis";
public static final String SERVER_STATUS_SYNC_PERIOD = "serverStatusSynchronizationPeriodMillis";
public static final String HEALTH_CHECK_TIMES = "healthCheckTimes";

View File

@ -27,10 +27,7 @@ import com.alibaba.nacos.core.utils.WebUtils;
import com.alibaba.nacos.naming.boot.RunningConfig;
import com.alibaba.nacos.naming.core.*;
import com.alibaba.nacos.naming.exception.NacosException;
import com.alibaba.nacos.naming.healthcheck.AbstractHealthCheckProcessor;
import com.alibaba.nacos.naming.healthcheck.HealthCheckTask;
import com.alibaba.nacos.naming.healthcheck.HealthCheckType;
import com.alibaba.nacos.naming.healthcheck.RsInfo;
import com.alibaba.nacos.naming.healthcheck.*;
import com.alibaba.nacos.naming.misc.*;
import com.alibaba.nacos.naming.push.ClientInfo;
import com.alibaba.nacos.naming.push.DataSource;
@ -386,11 +383,16 @@ public class ApiCommands {
boolean isUseSpecifiedURL = Boolean.parseBoolean(WebUtils.optional(request, "isUseSpecifiedURL", "false"));
String envAndSite = WebUtils.optional(request, "envAndSites", StringUtils.EMPTY);
boolean resetWeight = Boolean.parseBoolean(WebUtils.optional(request, "resetWeight", "false"));
boolean enableHealthCheck = Boolean.parseBoolean(WebUtils.optional(request, "enableHealthCheck", "true"));
boolean enableHealthCheck = Boolean.parseBoolean(WebUtils.optional(request, "enableHealthCheck",
String.valueOf(Switch.getDefaultHealthCheckMode().equals(HealthCheckMode.server.name()))));
boolean enable = Boolean.parseBoolean(WebUtils.optional(request, "serviceEnabled", "true"));
String disabledSites = WebUtils.optional(request, "disabledSites", StringUtils.EMPTY);
boolean eanbleClientBeat = Boolean.parseBoolean(WebUtils.optional(request, "enableClientBeat", "true"));
boolean eanbleClientBeat = Boolean.parseBoolean(WebUtils.optional(request, "enableClientBeat",
String.valueOf(Switch.getDefaultHealthCheckMode().equals(HealthCheckMode.client.name()))));
String clusterName = WebUtils.optional(request, "clusterName", UtilsAndCommons.DEFAULT_CLUSTER_NAME);
String serviceMetadataJson = WebUtils.optional(request, "serviceMetadata", StringUtils.EMPTY);
@ -1536,6 +1538,16 @@ public class ApiCommands {
return "ok";
}
if (entry.equals(SwitchEntry.DEFAULT_HEALTH_CHECK_MODE)) {
String defaultHealthCheckMode = WebUtils.required(request, "mode");
Switch.setDefaultHealthCheckMode(defaultHealthCheckMode);
if (!debug) {
Switch.save();
}
return "ok";
}
if (entry.equals(SwitchEntry.DOM_STATUS_SYNC_PERIOD)) {
Long millis = Long.parseLong(WebUtils.required(request, "millis"));

View File

@ -24,9 +24,9 @@ import static com.alibaba.nacos.test.naming.NamingBase.*;
/**
* @author <a href="mailto:zpf.073@gmail.com">nkorange</a>
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
// webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MultipleTenantTest {
private NamingService naming;
@ -42,6 +42,8 @@ public class MultipleTenantTest {
TimeUnit.SECONDS.sleep(10);
port = 8848;
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
Properties properties = new Properties();
@ -86,6 +88,8 @@ public class MultipleTenantTest {
instances = naming.getAllInstances(serviceName);
Assert.assertEquals(2, instances.size());
TimeUnit.SECONDS.sleep(10000000L);
}
@Test

View File

@ -42,9 +42,9 @@ import static com.alibaba.nacos.test.naming.NamingBase.*;
* @author wangtong.wt
* @date 2018/6/20
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
//@RunWith(SpringRunner.class)
//@SpringBootTest(classes = NamingApp.class, properties = {"server.servlet.context-path=/nacos"},
// webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class RegisterInstance_ITCase {
private NamingService naming;
@ -54,23 +54,23 @@ public class RegisterInstance_ITCase {
@Before
public void init() throws Exception {
if (naming == null) {
//TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
}
// if (naming == null) {
// TimeUnit.SECONDS.sleep(10);
// naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
// }
}
@Test
@Ignore
// @Ignore
public void regService() throws NacosException, InterruptedException {
Properties properties = new Properties();
properties.put(PropertyKeyConst.SERVER_ADDR, "127.0.0.1:8848");
properties.put(PropertyKeyConst.NAMESPACE, "t3");
naming = NacosFactory.createNamingService(properties);
naming = NamingFactory.createNamingService(properties);
String serviceName = "dungu.test.8";
String serviceName = "dungu.test.10";
naming.registerInstance(serviceName, "127.0.0.1", 80, "c1");
naming.registerInstance(serviceName, "127.0.0.2", 80, "c2");
Thread.sleep(100000000L);