This commit is contained in:
nkorange 2019-03-05 14:54:53 +08:00
parent 116e9119c2
commit 7947fc29b1
4 changed files with 23 additions and 22 deletions

View File

@ -191,17 +191,17 @@ public class NamingProxy {
}
public void deregisterService(String serviceName, String ip, int port, String cluster) throws NacosException {
public void deregisterService(String serviceName, String ip, int port, String clusterName) throws NacosException {
NAMING_LOGGER.info("[DEREGISTER-SERVICE] {} deregistering service {} with instance: {}:{}@{}",
namespaceId, serviceName, ip, port, cluster);
namespaceId, serviceName, ip, port, clusterName);
final Map<String, String> params = new HashMap<String, String>(8);
params.put(CommonParams.NAMESPACE_ID, namespaceId);
params.put("ip", ip);
params.put("port", String.valueOf(port));
params.put(CommonParams.SERVICE_NAME, serviceName);
params.put(CommonParams.CLUSTER_NAME, cluster);
params.put(CommonParams.CLUSTER_NAME, clusterName);
reqAPI(UtilAndComs.NACOS_URL_INSTANCE, params, HttpMethod.DELETE);
}

View File

@ -218,9 +218,9 @@ public class Instance extends com.alibaba.nacos.api.naming.pojo.Instance impleme
@JSONField(serialize = false)
public String getDatumKey() {
if (getPort() > 0) {
return getIp() + ":" + getPort() + ":" + UtilsAndCommons.LOCALHOST_SITE;
return getIp() + ":" + getPort() + ":" + UtilsAndCommons.LOCALHOST_SITE + ":" + getClusterName();
} else {
return getIp() + ":" + UtilsAndCommons.LOCALHOST_SITE;
return getIp() + ":" + UtilsAndCommons.LOCALHOST_SITE + ":" + getClusterName();
}
}

View File

@ -36,12 +36,12 @@ public class HealthCheckStatus {
private static ConcurrentMap<String, HealthCheckStatus> statusMap =
new ConcurrentHashMap<String, HealthCheckStatus>();
public static void reset(Instance ip) {
statusMap.put(buildKey(ip), new HealthCheckStatus());
public static void reset(Instance instance) {
statusMap.put(buildKey(instance), new HealthCheckStatus());
}
public static HealthCheckStatus get(Instance ip) {
String key = buildKey(ip);
public static HealthCheckStatus get(Instance instance) {
String key = buildKey(instance);
if (!statusMap.containsKey(key)) {
statusMap.putIfAbsent(key, new HealthCheckStatus());
@ -50,23 +50,23 @@ public class HealthCheckStatus {
return statusMap.get(key);
}
public static void remv(Instance ip) {
statusMap.remove(buildKey(ip));
public static void remv(Instance instance) {
statusMap.remove(buildKey(instance));
}
private static String buildKey(Instance ip) {
private static String buildKey(Instance instance) {
try {
String clusterName = ip.getClusterName();
String serviceName = ip.getServiceName();
String datumKey = ip.getDatumKey();
String clusterName = instance.getClusterName();
String serviceName = instance.getServiceName();
String datumKey = instance.getDatumKey();
return serviceName + ":"
+ clusterName + ":"
+ datumKey;
} catch (Throwable e) {
Loggers.SRV_LOG.error("[BUILD-KEY] Exception while set rt, ip {}, error: {}", ip.toJSON(), e);
Loggers.SRV_LOG.error("[BUILD-KEY] Exception while set rt, ip {}, error: {}", instance.toJSON(), e);
}
return ip.getDefaultKey();
return instance.getDefaultKey();
}
}

View File

@ -57,10 +57,10 @@ public class AutoDeregisterInstance_ITCase {
@Before
public void init() throws Exception {
// NamingBase.prepareServer(port);
NamingBase.prepareServer(port);
if (naming == null) {
naming = NamingFactory.createNamingService("11.239.112.161:8848,11.239.113.204:8848,11.239.114.187:8848");
naming = NamingFactory.createNamingService("127.0.0.1:" + port);
}
while (true) {
@ -220,12 +220,11 @@ public class AutoDeregisterInstance_ITCase {
Assert.assertEquals(1, instances.size());
BeatInfo beatInfo = new BeatInfo();
beatInfo.setServiceName(serviceName);
beatInfo.setServiceName(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName);
beatInfo.setIp("127.0.0.1");
beatInfo.setPort(TEST_PORT);
beatInfo.setCluster("c1");
namingServiceImpl.getBeatReactor().
addBeatInfo(Constants.DEFAULT_GROUP + Constants.SERVICE_INFO_SPLITER + serviceName, beatInfo);
//TimeUnit.SECONDS.sleep(15);
@ -233,7 +232,9 @@ public class AutoDeregisterInstance_ITCase {
instances = naming.getAllInstances(serviceName);
Assert.assertEquals(instances.size(), 2);
// Thread.sleep(10000000000L);
Assert.assertEquals(2, instances.size());
instances = naming.getAllInstances(serviceName, Arrays.asList("c2"));
Assert.assertEquals(1, instances.size());