@Test public void isAvailableReturnsFalse_whenStatusRed() { mockServerClient.when(request().withPath(ElasticsearchConnector.CLUSTER_HEALTH_ENDPOINT)) .respond(response().withStatusCode(200).withBody("{\"cluster_name\":\"elasticsearch\",\"status\":\"red\",\"timed_out\":false,\"number_of_nodes\":1,\"number_of_data_nodes\":1,\"active_primary_shards\":0,\"active_shards\":0,\"relocating_shards\":0,\"initializing_shards\":0,\"unassigned_shards\":0,\"delayed_unassigned_shards\":0,\"number_of_pending_tasks\":0,\"number_of_in_flight_fetch\":0,\"task_max_waiting_in_queue_millis\":0,\"active_shards_percent_as_number\":100.0}", MediaType.JSON_UTF_8)); assertThat(connector.isAvailable()).isFalse(); }
@Override public boolean isAvailable() { boolean ret = false; try { ClusterHealthResponse response = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT); ClusterHealthStatus status = response.getStatus(); ret = status.equals(ClusterHealthStatus.GREEN) || status.equals(ClusterHealthStatus.YELLOW); } 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; }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { ClusterHealthResponse response = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT); ClusterHealthStatus status = response.getStatus(); ret = status.equals(ClusterHealthStatus.GREEN) || status.equals(ClusterHealthStatus.YELLOW); } 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; } }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { ClusterHealthResponse response = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT); ClusterHealthStatus status = response.getStatus(); ret = status.equals(ClusterHealthStatus.GREEN) || status.equals(ClusterHealthStatus.YELLOW); } 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; } IndexOnlyElasticsearchConnector(RestHighLevelClient client); }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { ClusterHealthResponse response = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT); ClusterHealthStatus status = response.getStatus(); ret = status.equals(ClusterHealthStatus.GREEN) || status.equals(ClusterHealthStatus.YELLOW); } 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; } IndexOnlyElasticsearchConnector(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(); }
IndexOnlyElasticsearchConnector implements ElasticsearchConnector { @Override public boolean isAvailable() { boolean ret = false; try { ClusterHealthResponse response = client.cluster().health(new ClusterHealthRequest(), RequestOptions.DEFAULT); ClusterHealthStatus status = response.getStatus(); ret = status.equals(ClusterHealthStatus.GREEN) || status.equals(ClusterHealthStatus.YELLOW); } 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; } IndexOnlyElasticsearchConnector(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();  }