@Test public void testUpdatedHealthStatus() { String namespaceId = "namespaceId"; String serviceName = "testService"; String serverIp = "127.0.0.1"; String example = "{\"ips\":[\"127.0.0.1:8848_true\"]}"; Message message = new Message(); message.setData(example); when(synchronizer.get(serverIp, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName))) .thenReturn(message); serviceManager.updatedHealthStatus(namespaceId, serviceName, serverIp); }
public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) { Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName)); JsonNode serviceJson = JacksonUtils.toObj(msg.getData()); ArrayNode ipList = (ArrayNode) serviceJson.get("ips"); Map<String, String> ipsMap = new HashMap<>(ipList.size()); for (int i = 0; i < ipList.size(); i++) { String ip = ipList.get(i).asText(); String[] strings = ip.split("_"); ipsMap.put(strings[0], strings[1]); } Service service = getService(namespaceId, serviceName); if (service == null) { return; } boolean changed = false; List<Instance> instances = service.allIPs(); for (Instance instance : instances) { boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIpAddr())); if (valid != instance.isHealthy()) { changed = true; instance.setHealthy(valid); Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}:{}@{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } } if (changed) { pushService.serviceChanged(service); if (Loggers.EVT_LOG.isDebugEnabled()) { StringBuilder stringBuilder = new StringBuilder(); List<Instance> allIps = service.allIPs(); for (Instance instance : allIps) { stringBuilder.append(instance.toIpAddr()).append("_").append(instance.isHealthy()).append(","); } Loggers.EVT_LOG .debug("[HEALTH-STATUS-UPDATED] namespace: {}, service: {}, ips: {}", service.getNamespaceId(), service.getName(), stringBuilder.toString()); } } }
ServiceManager implements RecordListener<Service> { public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) { Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName)); JsonNode serviceJson = JacksonUtils.toObj(msg.getData()); ArrayNode ipList = (ArrayNode) serviceJson.get("ips"); Map<String, String> ipsMap = new HashMap<>(ipList.size()); for (int i = 0; i < ipList.size(); i++) { String ip = ipList.get(i).asText(); String[] strings = ip.split("_"); ipsMap.put(strings[0], strings[1]); } Service service = getService(namespaceId, serviceName); if (service == null) { return; } boolean changed = false; List<Instance> instances = service.allIPs(); for (Instance instance : instances) { boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIpAddr())); if (valid != instance.isHealthy()) { changed = true; instance.setHealthy(valid); Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}:{}@{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } } if (changed) { pushService.serviceChanged(service); if (Loggers.EVT_LOG.isDebugEnabled()) { StringBuilder stringBuilder = new StringBuilder(); List<Instance> allIps = service.allIPs(); for (Instance instance : allIps) { stringBuilder.append(instance.toIpAddr()).append("_").append(instance.isHealthy()).append(","); } Loggers.EVT_LOG .debug("[HEALTH-STATUS-UPDATED] namespace: {}, service: {}, ips: {}", service.getNamespaceId(), service.getName(), stringBuilder.toString()); } } } }
ServiceManager implements RecordListener<Service> { public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) { Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName)); JsonNode serviceJson = JacksonUtils.toObj(msg.getData()); ArrayNode ipList = (ArrayNode) serviceJson.get("ips"); Map<String, String> ipsMap = new HashMap<>(ipList.size()); for (int i = 0; i < ipList.size(); i++) { String ip = ipList.get(i).asText(); String[] strings = ip.split("_"); ipsMap.put(strings[0], strings[1]); } Service service = getService(namespaceId, serviceName); if (service == null) { return; } boolean changed = false; List<Instance> instances = service.allIPs(); for (Instance instance : instances) { boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIpAddr())); if (valid != instance.isHealthy()) { changed = true; instance.setHealthy(valid); Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}:{}@{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } } if (changed) { pushService.serviceChanged(service); if (Loggers.EVT_LOG.isDebugEnabled()) { StringBuilder stringBuilder = new StringBuilder(); List<Instance> allIps = service.allIPs(); for (Instance instance : allIps) { stringBuilder.append(instance.toIpAddr()).append("_").append(instance.isHealthy()).append(","); } Loggers.EVT_LOG .debug("[HEALTH-STATUS-UPDATED] namespace: {}, service: {}, ips: {}", service.getNamespaceId(), service.getName(), stringBuilder.toString()); } } } ServiceManager(SwitchDomain switchDomain, DistroMapper distroMapper, ServerMemberManager memberManager,
            PushService pushService, RaftPeerSet raftPeerSet); }
ServiceManager implements RecordListener<Service> { public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) { Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName)); JsonNode serviceJson = JacksonUtils.toObj(msg.getData()); ArrayNode ipList = (ArrayNode) serviceJson.get("ips"); Map<String, String> ipsMap = new HashMap<>(ipList.size()); for (int i = 0; i < ipList.size(); i++) { String ip = ipList.get(i).asText(); String[] strings = ip.split("_"); ipsMap.put(strings[0], strings[1]); } Service service = getService(namespaceId, serviceName); if (service == null) { return; } boolean changed = false; List<Instance> instances = service.allIPs(); for (Instance instance : instances) { boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIpAddr())); if (valid != instance.isHealthy()) { changed = true; instance.setHealthy(valid); Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}:{}@{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } } if (changed) { pushService.serviceChanged(service); if (Loggers.EVT_LOG.isDebugEnabled()) { StringBuilder stringBuilder = new StringBuilder(); List<Instance> allIps = service.allIPs(); for (Instance instance : allIps) { stringBuilder.append(instance.toIpAddr()).append("_").append(instance.isHealthy()).append(","); } Loggers.EVT_LOG .debug("[HEALTH-STATUS-UPDATED] namespace: {}, service: {}, ips: {}", service.getNamespaceId(), service.getName(), stringBuilder.toString()); } } } ServiceManager(SwitchDomain switchDomain, DistroMapper distroMapper, ServerMemberManager memberManager,
            PushService pushService, RaftPeerSet raftPeerSet); @PostConstruct void init(); Map<String, Service> chooseServiceMap(String namespaceId); void addUpdatedServiceToQueue(String namespaceId, String serviceName, String serverIP, String checksum); @Override boolean interests(String key); @Override boolean matchUnlistenKey(String key); @Override void onChange(String key, Service service); @Override void onDelete(String key); RaftPeer getMySelfClusterState(); void updatedHealthStatus(String namespaceId, String serviceName, String serverIP); Set<String> getAllServiceNames(String namespaceId); Map<String, Set<String>> getAllServiceNames(); Set<String> getAllNamespaces(); List<String> getAllServiceNameList(String namespaceId); Map<String, Set<Service>> getResponsibleServices(); int getResponsibleServiceCount(); int getResponsibleInstanceCount(); void easyRemoveService(String namespaceId, String serviceName); void addOrReplaceService(Service service); void createEmptyService(String namespaceId, String serviceName, boolean local); void createServiceIfAbsent(String namespaceId, String serviceName, boolean local, Cluster cluster); void registerInstance(String namespaceId, String serviceName, Instance instance); void updateInstance(String namespaceId, String serviceName, Instance instance); void addInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips); void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips); Instance getInstance(String namespaceId, String serviceName, String cluster, String ip, int port); List<Instance> updateIpAddresses(Service service, String action, boolean ephemeral, Instance... ips); Service getService(String namespaceId, String serviceName); boolean containService(String namespaceId, String serviceName); void putService(Service service); List<Service> searchServices(String namespaceId, String regex); int getServiceCount(); int getInstanceCount(); int getPagedService(String namespaceId, int startPage, int pageSize, String param, String containedInstance,
            List<Service> serviceList, boolean hasIpCount); }
ServiceManager implements RecordListener<Service> { public void updatedHealthStatus(String namespaceId, String serviceName, String serverIP) { Message msg = synchronizer.get(serverIP, UtilsAndCommons.assembleFullServiceName(namespaceId, serviceName)); JsonNode serviceJson = JacksonUtils.toObj(msg.getData()); ArrayNode ipList = (ArrayNode) serviceJson.get("ips"); Map<String, String> ipsMap = new HashMap<>(ipList.size()); for (int i = 0; i < ipList.size(); i++) { String ip = ipList.get(i).asText(); String[] strings = ip.split("_"); ipsMap.put(strings[0], strings[1]); } Service service = getService(namespaceId, serviceName); if (service == null) { return; } boolean changed = false; List<Instance> instances = service.allIPs(); for (Instance instance : instances) { boolean valid = Boolean.parseBoolean(ipsMap.get(instance.toIpAddr())); if (valid != instance.isHealthy()) { changed = true; instance.setHealthy(valid); Loggers.EVT_LOG.info("{} {SYNC} IP-{} : {}:{}@{}", serviceName, (instance.isHealthy() ? "ENABLED" : "DISABLED"), instance.getIp(), instance.getPort(), instance.getClusterName()); } } if (changed) { pushService.serviceChanged(service); if (Loggers.EVT_LOG.isDebugEnabled()) { StringBuilder stringBuilder = new StringBuilder(); List<Instance> allIps = service.allIPs(); for (Instance instance : allIps) { stringBuilder.append(instance.toIpAddr()).append("_").append(instance.isHealthy()).append(","); } Loggers.EVT_LOG .debug("[HEALTH-STATUS-UPDATED] namespace: {}, service: {}, ips: {}", service.getNamespaceId(), service.getName(), stringBuilder.toString()); } } } ServiceManager(SwitchDomain switchDomain, DistroMapper distroMapper, ServerMemberManager memberManager,
            PushService pushService, RaftPeerSet raftPeerSet); @PostConstruct void init(); Map<String, Service> chooseServiceMap(String namespaceId); void addUpdatedServiceToQueue(String namespaceId, String serviceName, String serverIP, String checksum); @Override boolean interests(String key); @Override boolean matchUnlistenKey(String key); @Override void onChange(String key, Service service); @Override void onDelete(String key); RaftPeer getMySelfClusterState(); void updatedHealthStatus(String namespaceId, String serviceName, String serverIP); Set<String> getAllServiceNames(String namespaceId); Map<String, Set<String>> getAllServiceNames(); Set<String> getAllNamespaces(); List<String> getAllServiceNameList(String namespaceId); Map<String, Set<Service>> getResponsibleServices(); int getResponsibleServiceCount(); int getResponsibleInstanceCount(); void easyRemoveService(String namespaceId, String serviceName); void addOrReplaceService(Service service); void createEmptyService(String namespaceId, String serviceName, boolean local); void createServiceIfAbsent(String namespaceId, String serviceName, boolean local, Cluster cluster); void registerInstance(String namespaceId, String serviceName, Instance instance); void updateInstance(String namespaceId, String serviceName, Instance instance); void addInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips); void removeInstance(String namespaceId, String serviceName, boolean ephemeral, Instance... ips); Instance getInstance(String namespaceId, String serviceName, String cluster, String ip, int port); List<Instance> updateIpAddresses(Service service, String action, boolean ephemeral, Instance... ips); Service getService(String namespaceId, String serviceName); boolean containService(String namespaceId, String serviceName); void putService(Service service); List<Service> searchServices(String namespaceId, String regex); int getServiceCount(); int getInstanceCount(); int getPagedService(String namespaceId, int startPage, int pageSize, String param, String containedInstance,
            List<Service> serviceList, boolean hasIpCount);  }