} catch (Exception e) { String servcieid = "null"; if (orgService.getService() != null) { servcieid = orgService.getService().getId();
public static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.isNotBlank(service.getAddress())) { return service.getAddress(); } else if (StringUtils.isNotBlank(node.getAddress())) { return node.getAddress(); } return node.getNode(); }
@Override public Host apply(HealthService info) { String hostName = ConsulHelper.findHost(info); Map<String, String> metaData = ConsulHelper.getMetadata(info); Host.Status status = Host.Status.Up; for (com.ecwid.consul.v1.health.model.Check check : info.getChecks()) { if (check.getStatus() == Check.CheckStatus.CRITICAL) { status = Host.Status.Down; break; } } String rack = null; try { if (metaData.containsKey("cloud") && StringUtils.equals(metaData.get("cloud"), "aws")) { rack = metaData.get("availability-zone"); } else { rack = metaData.get("rack"); } } catch (Throwable t) { Logger.error("Error getting rack for host " + info.getNode(), t); } if (rack == null) { Logger.error("Rack wasn't found for host:" + info.getNode() + " there may be issues matching it up to the token map"); } Host host = new Host(hostName, hostName, info.getService().getPort(), rack, String.valueOf(metaData.get("datacenter")), status); return host; } }));
public boolean isPassingChecks() { for (Check check : this.service.getChecks()) { if (check.getStatus() != Check.CheckStatus.PASSING) { return false; } } return true; } }
private static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.isNotBlank(service.getAddress())) { return service.getAddress(); } else if (StringUtils.isNotBlank(node.getAddress())) { return node.getAddress(); } return node.getNode(); }
public boolean isPassingChecks() { for (Check check : this.service.getChecks()) { if (check.getStatus() != Check.CheckStatus.PASSING) { return false; } } return true; } }
private ConsulService convertToConsulService(HealthService healthService) { ConsulService service = new ConsulService(); Service org = healthService.getService(); service.setAddress(org.getAddress()); service.setId(org.getId()); service.setName(org.getService()); service.setPort(org.getPort()); service.setTags(org.getTags()); return service; }
public static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.hasText(service.getAddress())) { return fixIPv6Address(service.getAddress()); } else if (StringUtils.hasText(node.getAddress())) { return fixIPv6Address(node.getAddress()); } return node.getNode(); }
public boolean isPassingChecks(HealthService service) { for (Check check : service.getChecks()) { if (check.getStatus() != Check.CheckStatus.PASSING) { return false; } } return true; }
public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) { QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex); Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams); if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) { List<HealthService> healthServices = orgResponse.getValue(); List<ConsulService> consulServices = Lists.newArrayList(); for (HealthService orgService : healthServices) { Service org = orgService.getService(); ConsulService newService = ConsulService.newService()// .withAddress(org.getAddress())// .withName(org.getService())// .withId(org.getId())// .withPort(org.getPort().toString())// .withTags(org.getTags())// .build(); consulServices.add(newService); } if (!consulServices.isEmpty()) { ConsulServiceResp response = ConsulServiceResp.newResponse()// .withValue(consulServices)// .withConsulIndex(orgResponse.getConsulIndex())// .withConsulLastContact(orgResponse.getConsulLastContact())// .withConsulKnowLeader(orgResponse.isConsulKnownLeader())// .build(); return response; } } return null; }
public static String findHost(HealthService healthService) { HealthService.Service service = healthService.getService(); HealthService.Node node = healthService.getNode(); if (StringUtils.hasText(service.getAddress())) { return fixIPv6Address(service.getAddress()); } else if (StringUtils.hasText(node.getAddress())) { return fixIPv6Address(node.getAddress()); } return node.getNode(); }
public ConsulServiceResp lookupHealthService(String serviceName, long lastConsulIndex) { QueryParams queryParams = new QueryParams(ConsulConstants.CONSUL_BLOCK_TIME_SECONDS, lastConsulIndex); Response<List<HealthService>> orgResponse = client.getHealthServices(serviceName, true, queryParams); if (orgResponse != null && orgResponse.getValue() != null && !orgResponse.getValue().isEmpty()) { List<HealthService> healthServices = orgResponse.getValue(); List<ConsulService> consulServices = Lists.newArrayList(); for (HealthService orgService : healthServices) { Service org = orgService.getService(); ConsulService newService = ConsulService.newService()// .withAddress(org.getAddress())// .withName(org.getService())// .withId(org.getId())// .withPort(org.getPort().toString())// .withTags(org.getTags())// .build(); consulServices.add(newService); } if (!consulServices.isEmpty()) { ConsulServiceResp response = ConsulServiceResp.newResponse()// .withValue(consulServices)// .withConsulIndex(orgResponse.getConsulIndex())// .withConsulLastContact(orgResponse.getConsulLastContact())// .withConsulKnowLeader(orgResponse.isConsulKnownLeader())// .build(); return response; } } return null; }
@Override public String getInstanceId() { return service.getService().getId(); } };
@Override public String getAppName() { return service.getService().getService(); }
@Override public String getInstanceId() { return service.getService().getId(); } };
@Override public String getAppName() { return service.getService().getService(); }
@Override public List<Server> getFilteredListOfServers(List<Server> servers) { Set<String> liveNodes = filteringAgentClient.getAliveAgentsAddresses(); List<Server> filteredServers = new ArrayList<>(); for (Server server : servers) { ConsulServer consulServer = ConsulServer.class.cast(server); if (liveNodes.contains(consulServer.getHealthService().getService().getAddress())) { filteredServers.add(server); } } return filteredServers; } }
@Override public List<Server> getFilteredListOfServers(List<Server> servers) { Set<String> liveNodes = filteringAgentClient.getAliveAgentsAddresses(); List<Server> filteredServers = new ArrayList<>(); for (Server server : servers) { ConsulServer consulServer = ConsulServer.class.cast(server); if (liveNodes.contains(consulServer.getHealthService().getService().getAddress())) { filteredServers.add(server); } } return filteredServers; } }
public static Map<String, String> getMetadata(HealthService healthService) { return getMetadata(healthService.getService().getTags()); }
public static Map<String, String> getMetadata(HealthService healthService) { return getMetadata(healthService.getService().getTags()); }