This commit is contained in:
nkorange 2019-01-17 19:50:57 +08:00
parent cc1f6647b0
commit 38e84cfb62
5 changed files with 13 additions and 25 deletions

View File

@ -173,7 +173,6 @@ public class RaftCore {
parameters.put("key", key); parameters.put("key", key);
raftProxy.proxyPostLarge(getLeader().ip, API_PUB, params.toJSONString(), parameters); raftProxy.proxyPostLarge(getLeader().ip, API_PUB, params.toJSONString(), parameters);
return; return;
} }
@ -818,6 +817,7 @@ public class RaftCore {
if (listenerList == null) { if (listenerList == null) {
listenerList = new CopyOnWriteArrayList<>(); listenerList = new CopyOnWriteArrayList<>();
listeners.put(key, listenerList);
} }
Loggers.RAFT.info("add listener: {}", key); Loggers.RAFT.info("add listener: {}", key);

View File

@ -42,7 +42,7 @@ public class RaftProxy {
} }
} }
public static void proxyPostLarge(String server, String api, String content, Map<String, String> headers) throws Exception { public void proxyPostLarge(String server, String api, String content, Map<String, String> headers) throws Exception {
// do proxy // do proxy
if (!server.contains(UtilsAndCommons.CLUSTER_CONF_IP_SPLITER)) { if (!server.contains(UtilsAndCommons.CLUSTER_CONF_IP_SPLITER)) {
server = server + UtilsAndCommons.CLUSTER_CONF_IP_SPLITER + RunningConfig.getServerPort(); server = server + UtilsAndCommons.CLUSTER_CONF_IP_SPLITER + RunningConfig.getServerPort();

View File

@ -174,7 +174,6 @@ public class ServiceManager implements DataListener {
consistencyService.listen(UtilsAndCommons.getDomStoreKey(dom), dom); consistencyService.listen(UtilsAndCommons.getDomStoreKey(dom), dom);
Loggers.SRV_LOG.info("[NEW-DOM-RAFT] {}", dom.toJSON()); Loggers.SRV_LOG.info("[NEW-DOM-RAFT] {}", dom.toJSON());
} }
wakeUp(UtilsAndCommons.assembleFullServiceName(dom.getNamespaceId(), dom.getName())); wakeUp(UtilsAndCommons.assembleFullServiceName(dom.getNamespaceId(), dom.getName()));
} catch (Throwable e) { } catch (Throwable e) {
@ -376,7 +375,6 @@ public class ServiceManager implements DataListener {
public void registerInstance(String namespaceId, String serviceName, IpAddress instance) throws Exception { public void registerInstance(String namespaceId, String serviceName, IpAddress instance) throws Exception {
VirtualClusterDomain service = getService(namespaceId, serviceName); VirtualClusterDomain service = getService(namespaceId, serviceName);
boolean serviceUpdated = false; boolean serviceUpdated = false;
if (service == null) { if (service == null) {
service = new VirtualClusterDomain(); service = new VirtualClusterDomain();
@ -411,9 +409,16 @@ public class ServiceManager implements DataListener {
} }
if (serviceUpdated) { if (serviceUpdated) {
Lock lock = addLockIfAbsent(UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName));
Condition condition = addCondtion(UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName));
addOrReplaceService(service); addOrReplaceService(service);
try {
lock.lock();
condition.await(5000, TimeUnit.MILLISECONDS);
} finally {
lock.unlock();
}
} }
addInstance(namespaceId, serviceName, instance); addInstance(namespaceId, serviceName, instance);
} }

View File

@ -105,21 +105,6 @@ public class HealthCheckTask implements Runnable {
} }
} }
} }
//
// @JSONField(serialize = false)
// public SwitchDomain getSwitchDomain() {
// return SpringContext.getAppContext().getBean(SwitchDomain.class);
// }
//
// @JSONField(serialize = false)
// public DistroMapper getDistroMapper() {
// return SpringContext.getAppContext().getBean(DistroMapper.class);
// }
//
// @JSONField(serialize = false)
// public HealthCheckProcessor getHealthCheckProcessor() {
// return SpringContext.getAppContext().getBean(HealthCheckProcessorDelegate.class);
// }
public Cluster getCluster() { public Cluster getCluster() {
return cluster; return cluster;

View File

@ -55,7 +55,7 @@ public class RegisterInstance_ITCase {
public void init() throws Exception { public void init() throws Exception {
if (naming == null) { if (naming == null) {
TimeUnit.SECONDS.sleep(10); TimeUnit.SECONDS.sleep(10);
naming = NamingFactory.createNamingService("127.0.0.1" + ":" + 8848); naming = NamingFactory.createNamingService("127.0.0.1" + ":" + port);
} }
} }
@ -92,16 +92,14 @@ public class RegisterInstance_ITCase {
@Test @Test
public void regDomTest() throws Exception { public void regDomTest() throws Exception {
String serviceName = randomDomainName(); String serviceName = randomDomainName();
naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT);
System.out.println(serviceName); System.out.println(serviceName);
naming.registerInstance(serviceName, TEST_IP_4_DOM_1, TEST_PORT);
TimeUnit.SECONDS.sleep(3); TimeUnit.SECONDS.sleep(3);
List<Instance> instances = naming.getAllInstances(serviceName); List<Instance> instances = naming.getAllInstances(serviceName);
Assert.assertEquals(instances.size(), 1); Assert.assertEquals(1, instances.size());
Assert.assertTrue(instances.get(0).getInstanceId().contains(serviceName)); Assert.assertTrue(instances.get(0).getInstanceId().contains(serviceName));
//Assert.assertEquals(instances.get(0).getService().getName(), serviceName); //Assert.assertEquals(instances.get(0).getService().getName(), serviceName);
Assert.assertEquals(instances.get(0).getIp(), TEST_IP_4_DOM_1); Assert.assertEquals(instances.get(0).getIp(), TEST_IP_4_DOM_1);