/** * Getter accessor for attribute 'healthClient'. * * @return * current value of 'healthClient' */ public HealthClient getHealthClient() { if (healthClient == null) { this.healthClient = consul.healthClient(); } return healthClient; }
@Override public void start(StartContext startContext) throws StartException { this.healthClient = this.consulInjector.getValue().healthClient(); }
@GET @Timed @Path("/consul/{service}") public List<ServiceHealth> getHealthyServiceInstances(@PathParam("service") String service) { return consul.healthClient().getHealthyServiceInstances(service).getResponse(); }
@Override public Collection<ServiceHealth> discover(final Consul consul) { return consul.healthClient().getHealthyServiceInstances(service).getResponse(); } }
@Override public List<ServiceDefinition> getServices(String name) { List<CatalogService> services = client.get().catalogClient() .getService(name, queryOptions) .getResponse(); List<ServiceHealth> healths = client.get().healthClient() .getAllServiceInstances(name, queryOptions) .getResponse(); return services.stream() .map(service -> newService(name, service, healths)) .collect(Collectors.toList()); }
public synchronized Membership updateGroupMembership() throws ClusterMembershipException { if (panic) { throw new ClusterMembershipException("Already permanently failed a health check."); } final List<ServiceHealth> healthyServices = consul.healthClient().getHealthyServiceInstances(serviceName).getResponse(); final List<String> serviceKeys = healthyServices.stream() .map(ConsulCoordinator::serviceKey) .sorted() .collect(toList()); System.out.println(); serviceKeys.forEach(System.out::println); int i = 1; for (String key : serviceKeys) { if (key.endsWith(serviceUuid)) { return Membership.of(i, serviceKeys.size()); } i++; } throw new ClusterMembershipException("We're not in the list of healthy services." + " Was another connector worker started on this node without specifying a unique service ID?"); }
public NodeWatcher(Consul consul, String serviceName, Duration quietPeriod, BlockingQueue<LeaderEvent> eventQueue) { requireNonNull(eventQueue); this.quietPeriodExecutor = new QuietPeriodExecutor(quietPeriod, executorService); this.svHealth = ServiceHealthCache.newCache(consul.healthClient(), serviceName); svHealth.addListener(newValues -> { final ImmutableSet<String> currentEndpointIds = ImmutableSet.copyOf( newValues.values().stream(). map(NodeWatcher::endpointId) .collect(Collectors.toSet())); if (!currentEndpointIds.equals(prevEndpointIds)) { if (LOGGER.isInfoEnabled()) { final Set<String> joiningNodes = Sets.difference(currentEndpointIds, prevEndpointIds); final Set<String> leavingNodes = Sets.difference(prevEndpointIds, currentEndpointIds); LOGGER.info("Service health changed; will rebalance after {} quiet period. Joining: {} Leaving: {}", quietPeriod, joiningNodes, leavingNodes); } prevEndpointIds = currentEndpointIds; quietPeriodExecutor.schedule(() -> { eventQueue.add(LeaderEvent.MEMBERSHIP_CHANGE); }); } }); svHealth.start(); }
public static List<String> getActivePEServicesEndPoints() { LOG.info("Load active PE services endpoints"); Consul consul = consulInstance(); HealthClient healthClient = consul.healthClient(); List<String> endpoints = new LinkedList<>(); List<ServiceHealth> nodes = healthClient.getHealthyServiceInstances(PE_SERVICE_NAME).getResponse(); for (ServiceHealth node: nodes) { String endpoint = node.getService().getAddress() + ":" + node.getService().getPort(); LOG.info("Active PE endpoint:" + endpoint); endpoints.add(endpoint); } return endpoints; }
@Override public List<IServiceNode> getNodesForFunction(IFunctionIdentifier identifier) throws SiteWhereException { if (getConsulClient() != null) { HealthClient healthClient = getConsulClient().healthClient(); List<ServiceHealth> matches = healthClient.getHealthyServiceInstances(identifier.getShortName()) .getResponse(); List<IServiceNode> nodes = new ArrayList<>(); for (ServiceHealth match : matches) { String host = match.getService().getAddress(); ServiceNode node = new ServiceNode(); node.setAddress(host); nodes.add(node); } return nodes; } else { List<IServiceNode> nodes = new ArrayList<>(); return nodes; } }
this.consulHealthClient = consul.healthClient();
this.consulHealthClient = consul.healthClient();
ServiceHealthCache svHealth = ServiceHealthCache.newCache(consul.healthClient(), serviceName);
HealthClient consulHealthClient = consul.healthClient();