/** * Indicates whether or not a particular service is registered with * the local Consul agent. * * @return <code>true</code> if a particular service is registered with * the local Consul agent, otherwise <code>false</code>. */ public boolean isRegistered(String serviceId) { Map<String, Service> serviceIdToService = getServices(); return serviceIdToService.containsKey(serviceId); }
public static Map<String, String> getPEServices() { LOG.info("Load PE service status"); Consul consul = consulInstance(); AgentClient agent = consul.agentClient(); Map<String, Service> services = consul.agentClient().getServices(); Map<String, HealthCheck> checks = agent.getChecks(); Map<String, String> peServices = new HashMap<>(); for(Map.Entry<String, Service> entry : services.entrySet()) { if(entry.getValue().getTags().contains(PE_SERVICE_NAME)) { String serviceId = entry.getValue().getId(); String serviceStatus = "critical"; if(checks.containsKey("service:" + entry.getKey())) { serviceStatus = checks.get("service:" + entry.getKey()).getStatus(); } LOG.info("Service id: " + serviceId + " service status: " + serviceStatus); peServices.put(serviceId, serviceStatus); } } return peServices; }
@Override protected void doStop() throws Exception { if (scheduler != null) { getCamelContext().getExecutorServiceManager().shutdownNow(scheduler); scheduler = null; } if (configuration.isDeregisterServicesOnStop()) { for (Service service: client.agentClient().getServices().values()) { try { if (serviceList.contains(service.getId())) { client.agentClient().deregister(service.getId()); serviceList.remove(service.getId()); } } catch (Exception e) { LOGGER.warn("Error de-registering service: " + service, e); } } client = null; } }
public ConsulAgentProducer(ConsulEndpoint endpoint, ConsulConfiguration configuration) { super(endpoint, configuration, Consul::agentClient); bind(ConsulAgentActions.CHECKS, wrap(c -> c.getChecks())); bind(ConsulAgentActions.SERVICES, wrap(c -> c.getServices())); bind(ConsulAgentActions.MEMBERS, wrap(c -> c.getMembers())); bind(ConsulAgentActions.AGENT, wrap(c -> c.getAgent())); } }