@SuppressWarnings("SimplifiableIfStatement") @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof AgentInfo)) return false; AgentInfo agentInfo = (AgentInfo) o; if (config != null ? !config.equals(agentInfo.config) : agentInfo.config != null) return false; return !(member != null ? !member.equals(agentInfo.member) : agentInfo.member != null); }
private EndpointDefinition convertToServiceDefinition(final ServiceHealth serviceHealth) { final String host = serviceHealth.getNode().getAddress(); final int port = serviceHealth.getService().getPort(); final String id = serviceHealth.getService().getId(); final String name = serviceHealth.getService().getService(); final List<String> tags = serviceHealth.getService().getTags(); final EndpointDefinition endpointDefinition = new EndpointDefinition(HealthStatus.PASS, id, name, host, port, tags); if (debug) logger.debug(sputs("convertToServiceDefinition \nserviceHealth", serviceHealth, "\nserviceDefinition", endpointDefinition)); return endpointDefinition; }
private void assertHealth(String serviceId, boolean found, ConsulResponse<List<ServiceHealth>> response) { List<ServiceHealth> nodes = response.getResponse(); assertEquals(1, nodes.size()); for (ServiceHealth health : nodes) { if (health.getService().getId().equals(serviceId)) { found = true; } } assertTrue(found); }
private void verifyState(String state, Consul client, String serviceId, String serviceName) throws Exception { List<ServiceHealth> nodes = client.health().getAllNodes(serviceName).getResponse(); boolean found = false; for (ServiceHealth health : nodes) { if (health.getService().getId().equals(serviceId)) { List<HealthCheck> checks = health.getChecks(); found = true; assertEquals(serviceId, health.getService().getId()); assertNotNull(checks); checks = checks.stream().filter(healthCheck -> healthCheck.getStatus().equals(state)).collect(Collectors.toList()); assertEquals(state, checks.get(0).getStatus()); } } assertTrue(found); }
@SuppressWarnings("SimplifiableIfStatement") @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ServiceHealth)) return false; ServiceHealth that = (ServiceHealth) o; if (checks != null ? !checks.equals(that.checks) : that.checks != null) return false; return !(node != null ? !node.equals(that.node) : that.node != null) && !(service != null ? !service.equals(that.service) : that.service != null); }
/** * Registers the client as a service with Consul. Registration enables * the use of checks. * * @param host The public facing host of the service to register with Consul. * @param port The public facing port of the service to register with Consul. * @param ttl Time to live for the Consul dead man's switch. * @param serviceName Service name to register. * @param serviceId Service id to register. * @param tags Tags to register with. */ public void registerService(final String host, final int port, final long ttl, final String serviceName, final String serviceId, final String... tags) { RegistrationCheck check = new RegistrationCheck(); check.setTtl("" + ttl + "s"); registerServiceWithRegistrationCheck(host, port, check, serviceName, serviceId, tags); }
@Test public void getSingleService() throws Exception { Consul client = Consul.consul(); CatalogEndpoint catalogClient = client.catalog(); ConsulResponse<List<CatalogService>> services = catalogClient.getService("consul"); assertEquals("consul", services.getResponse().iterator().next().getServiceName()); }
@Test public void getSingleNode() throws Exception { Consul client = Consul.consul(); CatalogEndpoint catalogClient = client.catalog(); ConsulResponse<CatalogNode> node = catalogClient.getNode(catalogClient.getNodes() .getResponse().iterator().next().getNode()); assertNotNull(node); }
public static void die(Object... args) { throw new ConsulException(sputs(args)); } }
@Override public int hashCode() { int result = node != null ? node.hashCode() : 0; result = 31 * result + (services != null ? services.hashCode() : 0); return result; }
@Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CatalogNode)) return false; CatalogNode that = (CatalogNode) o; return !(node != null ? !node.equals(that.node) : that.node != null) && !(services != null ? !services.equals(that.services) : that.services != null); }
@SuppressWarnings("SimplifiableIfStatement") @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof Registration)) return false; Registration that = (Registration) o; if (port != that.port) return false; if (host != null ? !host.equals(that.host) : that.host != null) return false; if (check != null ? !check.equals(that.check) : that.check != null) return false; if (id != null ? !id.equals(that.id) : that.id != null) return false; return !(name != null ? !name.equals(that.name) : that.name != null) && Arrays.equals(tags, that.tags); }
@Override public int hashCode() { int result = name != null ? name.hashCode() : 0; result = 31 * result + (id != null ? id.hashCode() : 0); result = 31 * result + port; result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + (check != null ? check.hashCode() : 0); result = 31 * result + (tags != null ? Arrays.hashCode(tags) : 0); return result; }
public static void notRegistered(Object... args) { throw new NotRegisteredException(sputs(args)); } }
@Test public void retrieveAgentInformation() throws UnknownHostException { Consul client = Consul.consul(); AgentInfo agentInfo = client.agent().getAgentInfo(); assertNotNull(agentInfo); assertEquals("127.0.0.1", agentInfo.getConfig().getClientAddr()); }
public Session setSessionBehavior(SessionBehavior behavior) { this.behavior = behavior.name().toLowerCase(); return this; }
@Test public void register() throws UnknownHostException { Consul client = Consul.consul(); String serviceName = UUID.randomUUID().toString(); String serviceId = UUID.randomUUID().toString(); client.agent().registerService("localhost", 80, 20000L, serviceName, serviceId); boolean found = false; for (ServiceHealth health : client.health().getAllNodes(serviceName).getResponse()) { if (health.getService().getId().equals(serviceId)) { found = true; } } assertTrue(found); } }
public static void dieWithException(Exception ex, Object... args) { throw new ConsulException(sputs(args), ex); }