.build(); final JestResult clusterHealthResponse = JestUtils.execute(jestClient, clusterHealthRequest, () -> "Couldn't read Elasticsearch cluster health"); final JsonNode clusterHealthJson = clusterHealthResponse.getJsonObject();
private Optional<JsonNode> clusterHealth(Collection<? extends String> indices) { final Health request = new Health.Builder() .addIndex(indices) .timeout(Ints.saturatedCast(requestTimeout.toSeconds())) .build(); try { final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster health for indices " + indices); return Optional.of(jestResult.getJsonObject()); } catch(ElasticsearchException e) { if (LOG.isDebugEnabled()) { LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"), e); } else { LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a")); } return Optional.empty(); } }
private Health.Status waitForStatus(String index, Health.Status clusterHealthStatus) { LOG.debug("Waiting until index health status of index {} is {}", index, clusterHealthStatus); final Health request = new Health.Builder() .addIndex(index) .waitForStatus(clusterHealthStatus) .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read health status for index " + index); final String status = jestResult.getJsonObject().path("status").asText(); return Health.Status.valueOf(status.toUpperCase(Locale.ENGLISH)); }
.build(); final JestResult clusterHealthResponse = JestUtils.execute(jestClient, clusterHealthRequest, () -> "Couldn't read Elasticsearch cluster health"); final JsonNode clusterHealthJson = clusterHealthResponse.getJsonObject();
logger.info("Polling for Elasticsearch..."); try { esClient.execute(new Health.Builder().build()); cdl.countDown(); } catch (IOException e) {
logger.info("Polling for Elasticsearch..."); try { esClient.execute(new Health.Builder().build()); cdl.countDown(); } catch (IOException e) {
/** * Check if Elasticsearch is available and that there are data nodes in the cluster. * * @return {@code true} if the Elasticsearch client is up and the cluster contains data nodes, {@code false} otherwise */ public boolean isConnected() { final Health request = new Health.Builder() .local() .timeout(Ints.saturatedCast(requestTimeout.toSeconds())) .build(); try { final JestResult result = JestUtils.execute(jestClient, request, () -> "Couldn't check connection status of Elasticsearch"); final int numberOfDataNodes = result.getJsonObject().path("number_of_data_nodes").asInt(); return numberOfDataNodes > 0; } catch (ElasticsearchException e) { if (LOG.isDebugEnabled()) { LOG.error(e.getMessage(), e); } return false; } }
/** * Called to initialize the storage. * @param client the jest client * @param indexName the name of the ES index to initialize * @param defaultIndexName the default ES index - used to determine which -settings.json file to use */ protected void initializeClient(JestClient client, String indexName, String defaultIndexName) { try { client.execute(new Health.Builder().build()); Action<JestResult> action = new IndicesExists.Builder(indexName).build(); // There was occasions where a race occurred here when multiple threads try to // create the index simultaneously. This caused a non-fatal, but annoying, exception. synchronized(AbstractClientFactory.class) { JestResult result = client.execute(action); if (!result.isSucceeded()) { createIndex(client, indexName, defaultIndexName + "-settings.json"); //$NON-NLS-1$ } } } catch (Exception e) { throw new RuntimeException(e); } }
/** * Called to initialize the storage. * @param client the jest client * @param indexName the name of the ES index to initialize * @param defaultIndexName the default ES index - used to determine which -settings.json file to use */ protected void initializeClient(JestClient client, String indexName, String defaultIndexName) { try { client.execute(new Health.Builder().build()); Action<JestResult> action = new IndicesExists.Builder(indexName).build(); // There was occasions where a race occurred here when multiple threads try to // create the index simultaneously. This caused a non-fatal, but annoying, exception. synchronized(AbstractClientFactory.class) { JestResult result = client.execute(action); if (!result.isSucceeded()) { createIndex(client, indexName, defaultIndexName + "-settings.json"); //$NON-NLS-1$ } } } catch (Exception e) { throw new RuntimeException(e); } }
private Optional<JsonNode> clusterHealth(Collection<? extends String> indices) { final Health request = new Health.Builder() .addIndex(indices) .timeout(Ints.saturatedCast(requestTimeout.toSeconds())) .build(); try { final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read cluster health for indices " + indices); return Optional.of(jestResult.getJsonObject()); } catch(ElasticsearchException e) { if (LOG.isDebugEnabled()) { LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a"), e); } else { LOG.error("{} ({})", e.getMessage(), Optional.ofNullable(e.getCause()).map(Throwable::getMessage).orElse("n/a")); } return Optional.empty(); } }
private Health.Status waitForStatus(String index, Health.Status clusterHealthStatus) { LOG.debug("Waiting until index health status of index {} is {}", index, clusterHealthStatus); final Health request = new Health.Builder() .addIndex(index) .waitForStatus(clusterHealthStatus) .build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Couldn't read health status for index " + index); final String status = jestResult.getJsonObject().path("status").asText(); return Health.Status.valueOf(status.toUpperCase(Locale.ENGLISH)); }
@Override protected void doHealthCheck(Health.Builder builder) throws Exception { JestResult healthResult = this.jestClient .execute(new io.searchbox.cluster.Health.Builder().build()); if (healthResult.getResponseCode() != 200 || !healthResult.isSucceeded()) { builder.down(); builder.withDetail("statusCode", healthResult.getResponseCode()); } else { Map<String, Object> response = this.jsonParser .parseMap(healthResult.getJsonString()); String status = (String) response.get("status"); if (status.equals(io.searchbox.cluster.Health.Status.RED.getKey())) { builder.outOfService(); } else { builder.up(); } builder.withDetails(response); } }
/** * Check if Elasticsearch is available and that there are data nodes in the cluster. * * @return {@code true} if the Elasticsearch client is up and the cluster contains data nodes, {@code false} otherwise */ public boolean isConnected() { final Health request = new Health.Builder() .local() .timeout(Ints.saturatedCast(requestTimeout.toSeconds())) .build(); try { final JestResult result = JestUtils.execute(jestClient, request, () -> "Couldn't check connection status of Elasticsearch"); final int numberOfDataNodes = result.getJsonObject().path("number_of_data_nodes").asInt(); return numberOfDataNodes > 0; } catch (ElasticsearchException e) { if (LOG.isDebugEnabled()) { LOG.error(e.getMessage(), e); } return false; } }