/** * Retrieves all services registered with the Agent. * <p> * GET /v1/agent/services * * @return Map of Service ID to Services. */ public Map<String, Service> getServices() { final URI uri = createURI("/services"); final HTTP.Response response = HTTP.getResponse(uri.toString()); final JsonParserAndMapper jsonParserAndMapper = new JsonParserFactory().create(); if (response.status() == 200) { final Map<String, Object> map = jsonParserAndMapper.parseMap(response.payloadAsString()); final Map<String, Service> returnMap = new HashMap<>(map.size()); map.entrySet().forEach(entry -> { @SuppressWarnings("unchecked") Service service = fromMap((Map<String, Object>) entry.getValue(), Service.class); returnMap.put(entry.getKey(), service); }); return returnMap; } die("Unable to get list of services", uri, response.status(), response.payloadAsString()); return null; }
/** * Retrieves all checks registered with the Agent. * <p> * GET /v1/agent/checks * * @return Map of Check ID to Checks. */ public Map<String, HealthCheck> getChecks() { final URI uri = createURI("/checks"); final HTTP.Response response = HTTP.getResponse(uri.toString()); final JsonParserAndMapper jsonParserAndMapper = new JsonParserFactory().create(); if (response.status() == 200) { final Map<String, Object> map = jsonParserAndMapper.parseMap(response.payloadAsString()); final Map<String, HealthCheck> returnMap = new HashMap<>(map.size()); map.entrySet().forEach(entry -> { @SuppressWarnings("unchecked") HealthCheck healthCheck = fromMap((Map<String, Object>) entry.getValue(), HealthCheck.class); returnMap.put(entry.getKey(), healthCheck); }); return returnMap; } die("Unable to get health checks", uri, response.status(), response.statusMessageAsString(), response.payloadAsString()); return null; }
/** * Pings the Consul Agent. */ public void pingAgent() { HTTP.Response response = HTTP.getResponse(createURI("/self").toString()); if (response.status() != 200) { die("Error pinging Consul", response.payloadAsString()); } }
/** * Retrieves all checks registered with the Agent. * <p> * GET /v1/agent/checks * * @return Map of Check ID to Checks. */ public Map<String, HealthCheck> getChecks() { final URI uri = createURI("/checks"); final HTTP.Response response = HTTP.getResponse(uri.toString()); final JsonParserAndMapper jsonParserAndMapper = new JsonParserFactory().create(); if (response.status() == 200) { final Map<String, Object> map = jsonParserAndMapper.parseMap(response.payloadAsString()); final Map<String, HealthCheck> returnMap = new HashMap<>(map.size()); map.entrySet().forEach(entry -> { @SuppressWarnings("unchecked") HealthCheck healthCheck = fromMap((Map<String, Object>) entry.getValue(), HealthCheck.class); returnMap.put(entry.getKey(), healthCheck); }); return returnMap; } die("Unable to get health checks", uri, response.status(), response.statusMessageAsString(), response.payloadAsString()); return null; }
/** * Retrieves all services registered with the Agent. * <p> * GET /v1/agent/services * * @return Map of Service ID to Services. */ public Map<String, Service> getServices() { final URI uri = createURI("/services"); final HTTP.Response response = HTTP.getResponse(uri.toString()); final JsonParserAndMapper jsonParserAndMapper = new JsonParserFactory().create(); if (response.status() == 200) { final Map<String, Object> map = jsonParserAndMapper.parseMap(response.payloadAsString()); final Map<String, Service> returnMap = new HashMap<>(map.size()); map.entrySet().forEach(entry -> { @SuppressWarnings("unchecked") Service service = fromMap((Map<String, Object>) entry.getValue(), Service.class); returnMap.put(entry.getKey(), service); }); return returnMap; } die("Unable to get list of services", uri, response.status(), response.payloadAsString()); return null; }
/** * <p> * Retrieves the Agent's configuration and member information. * </p> * GET /v1/agent/self * * @return The Agent information. */ public AgentInfo getAgentInfo() { final URI uri = createURI("/self"); HTTP.Response response = HTTP.getResponse(uri.toString()); if (response.status() != 200) { die("Error getting info about this agent", uri, response.status(), response.statusMessageAsString(), response.payloadAsString()); } return fromJson(response.payloadAsString(), AgentInfo.class); }
public String body() { return payloadAsString(); }
/** * Remove registration of a particular service. * * @param serviceId the service id that you want to remove. */ public void deregister(final String serviceId) { final URI uri = createURI("/service/deregister/" + serviceId); HTTP.Response response = HTTP.getResponse(uri.toString()); if (response.status() != 200) { die("Error removing registration of service with Consul", uri, serviceId, response.status(), response.payloadAsString()); } }
/** * Registers a Health Check with the Agent. * * @param check The Check to register. */ public void registerCheck(Check check) { final URI uri = createURI("/check/register"); HTTP.Response response = HTTP.jsonRestCallViaPUT(uri.toString(), toJson(check)); if (response.status() != 200) { die("Error removing registration of service with Consul", uri, check, response.status(), response.statusMessageAsString(), response.payloadAsString()); } }
/** * De-registers a Health Check with the Agent * * @param checkId the id of the Check to deregister */ public void deregisterCheck(String checkId) { final URI uri = createURI("/check/deregister/" + checkId); HTTP.Response response = HTTP.getResponse(uri.toString()); if (response.status() != 200) { die("Error removing registration of service with Consul", uri, checkId, response.status(), response.statusMessageAsString(), response.payloadAsString()); } }
public String body() { return payloadAsString(); }
/** * Register a service with Consul. * * @param registration The registration payload. */ public void register(final Registration registration) { final URI uri = createURI("/service/register"); HTTP.Response response = HTTP.jsonRestCallViaPUT(uri.toString(), toJson(registration)); if (response.status() != 200) { die("Error registering service with Consul", uri, registration, response.payloadAsString()); } }
/** * Pings the Consul Agent. */ public void pingAgent() { HTTP.Response response = HTTP.getResponse(createURI("/self").toString()); if (response.status() != 200) { die("Error pinging Consul", response.payloadAsString()); } }
/** * <p> * Retrieves the Agent's configuration and member information. * </p> * GET /v1/agent/self * * @return The Agent information. */ public AgentInfo getAgentInfo() { final URI uri = createURI("/self"); HTTP.Response response = HTTP.getResponse(uri.toString()); if (response.status() != 200) { die("Error getting info about this agent", uri, response.status(), response.statusMessageAsString(), response.payloadAsString()); } return fromJson(response.payloadAsString(), AgentInfo.class); }
/** * De-registers a Health Check with the Agent * * @param checkId the id of the Check to deregister */ public void deregisterCheck(String checkId) { final URI uri = createURI("/check/deregister/" + checkId); HTTP.Response response = HTTP.getResponse(uri.toString()); if (response.status() != 200) { die("Error removing registration of service with Consul", uri, checkId, response.status(), response.statusMessageAsString(), response.payloadAsString()); } }
/** * Registers a Health Check with the Agent. * * @param check The Check to register. */ public void registerCheck(Check check) { final URI uri = createURI("/check/register"); HTTP.Response response = HTTP.jsonRestCallViaPUT(uri.toString(), toJson(check)); if (response.status() != 200) { die("Error removing registration of service with Consul", uri, check, response.status(), response.statusMessageAsString(), response.payloadAsString()); } }
public String body() { return payloadAsString(); }
/** * Remove registration of a particular service. * * @param serviceId the service id that you want to remove. */ public void deregister(final String serviceId) { final URI uri = createURI("/service/deregister/" + serviceId); HTTP.Response response = HTTP.getResponse(uri.toString()); if (response.status() != 200) { die("Error removing registration of service with Consul", uri, serviceId, response.status(), response.payloadAsString()); } }
/** * Register a service with Consul. * * @param registration The registration payload. */ public void register(final Registration registration) { final URI uri = createURI("/service/register"); HTTP.Response response = HTTP.jsonRestCallViaPUT(uri.toString(), toJson(registration)); if (response.status() != 200) { die("Error registering service with Consul", uri, registration, response.payloadAsString()); } }