@Test public void isAvailableReturnsTrue_whenStatusYellow() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(200).withBody("{ \"status\": \"yellow\" }", MediaType.JSON_UTF_8)); assertThat(connector.isAvailable()).isTrue(); }
@Override public boolean isAvailable() { boolean ret = false; try { final Response response = client.getLowLevelClient().performRequest(new Request(HttpGet.METHOD_NAME, CLUSTER_HEALTH_ENDPOINT)); final String body = EntityUtils.toString(response.getEntity()); final Map jsonMap = new ObjectMapper().readValue(body, Map.class); if (jsonMap.containsKey("status")) { final String status = jsonMap.get("status").toString(); if ("yellow".equals(status) || "green".equals(status)) { ret = true; } else { LOGGER.warn("Cluster status not healthy: {}", status); } } else { LOGGER.warn("No status in _cluster/health response - {}", body); } } catch (ResponseException e) { LOGGER.warn("Caught ResponseException calling {}: {}", CLUSTER_HEALTH_ENDPOINT, e.getResponse().getStatusLine()); } catch (IOException e) { LOGGER.error("Caught IOException calling _cluster/health: {}", e.getMessage()); } return ret; }
MappingTypeElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { final Response response = client.getLowLevelClient().performRequest(new Request(HttpGet.METHOD_NAME, CLUSTER_HEALTH_ENDPOINT)); final String body = EntityUtils.toString(response.getEntity()); final Map jsonMap = new ObjectMapper().readValue(body, Map.class); if (jsonMap.containsKey("status")) { final String status = jsonMap.get("status").toString(); if ("yellow".equals(status) || "green".equals(status)) { ret = true; } else { LOGGER.warn("Cluster status not healthy: {}", status); } } else { LOGGER.warn("No status in _cluster/health response - {}", body); } } catch (ResponseException e) { LOGGER.warn("Caught ResponseException calling {}: {}", CLUSTER_HEALTH_ENDPOINT, e.getResponse().getStatusLine()); } catch (IOException e) { LOGGER.error("Caught IOException calling _cluster/health: {}", e.getMessage()); } return ret; } }
MappingTypeElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { final Response response = client.getLowLevelClient().performRequest(new Request(HttpGet.METHOD_NAME, CLUSTER_HEALTH_ENDPOINT)); final String body = EntityUtils.toString(response.getEntity()); final Map jsonMap = new ObjectMapper().readValue(body, Map.class); if (jsonMap.containsKey("status")) { final String status = jsonMap.get("status").toString(); if ("yellow".equals(status) || "green".equals(status)) { ret = true; } else { LOGGER.warn("Cluster status not healthy: {}", status); } } else { LOGGER.warn("No status in _cluster/health response - {}", body); } } catch (ResponseException e) { LOGGER.warn("Caught ResponseException calling {}: {}", CLUSTER_HEALTH_ENDPOINT, e.getResponse().getStatusLine()); } catch (IOException e) { LOGGER.error("Caught IOException calling _cluster/health: {}", e.getMessage()); } return ret; } MappingTypeElasticsearchConnector(RestHighLevelClient client); }
MappingTypeElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { final Response response = client.getLowLevelClient().performRequest(new Request(HttpGet.METHOD_NAME, CLUSTER_HEALTH_ENDPOINT)); final String body = EntityUtils.toString(response.getEntity()); final Map jsonMap = new ObjectMapper().readValue(body, Map.class); if (jsonMap.containsKey("status")) { final String status = jsonMap.get("status").toString(); if ("yellow".equals(status) || "green".equals(status)) { ret = true; } else { LOGGER.warn("Cluster status not healthy: {}", status); } } else { LOGGER.warn("No status in _cluster/health response - {}", body); } } catch (ResponseException e) { LOGGER.warn("Caught ResponseException calling {}: {}", CLUSTER_HEALTH_ENDPOINT, e.getResponse().getStatusLine()); } catch (IOException e) { LOGGER.error("Caught IOException calling _cluster/health: {}", e.getMessage()); } return ret; } MappingTypeElasticsearchConnector(RestHighLevelClient client); @Override boolean isAvailable(); @Override boolean indexExists(String index); @Override boolean createIndex(String index); @Override void storeItems(String index, Collection<QueryVersionReport> reports); @Override void close(); }
MappingTypeElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { final Response response = client.getLowLevelClient().performRequest(new Request(HttpGet.METHOD_NAME, CLUSTER_HEALTH_ENDPOINT)); final String body = EntityUtils.toString(response.getEntity()); final Map jsonMap = new ObjectMapper().readValue(body, Map.class); if (jsonMap.containsKey("status")) { final String status = jsonMap.get("status").toString(); if ("yellow".equals(status) || "green".equals(status)) { ret = true; } else { LOGGER.warn("Cluster status not healthy: {}", status); } } else { LOGGER.warn("No status in _cluster/health response - {}", body); } } catch (ResponseException e) { LOGGER.warn("Caught ResponseException calling {}: {}", CLUSTER_HEALTH_ENDPOINT, e.getResponse().getStatusLine()); } catch (IOException e) { LOGGER.error("Caught IOException calling _cluster/health: {}", e.getMessage()); } return ret; } MappingTypeElasticsearchConnector(RestHighLevelClient client); @Override boolean isAvailable(); @Override boolean indexExists(String index); @Override boolean createIndex(String index); @Override void storeItems(String index, Collection<QueryVersionReport> reports); @Override void close();  }