final Health clusterHealthRequest = new Health.Builder() .addIndex(Arrays.asList(indexSetRegistry.getIndexWildcards())) .build(); final JestResult clusterHealthResponse = JestUtils.execute(jestClient, clusterHealthRequest, () -> "Couldn't read Elasticsearch cluster health"); final JsonNode clusterHealthJson = clusterHealthResponse.getJsonObject();
/** * 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; } }
public Builder timeout(int seconds) { Preconditions.checkArgument(seconds >= 0, "seconds must not be negative"); return setParameter("timeout", seconds + "s"); }
final Health clusterHealthRequest = new Health.Builder() .addIndex(Arrays.asList(indexSetRegistry.getIndexWildcards())) .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 void waitForIndexCreation() { Builder healthBuilder = new Health.Builder() .setParameter( "wait_for_status", "green" ) .setParameter( "timeout", indexManagementWaitTimeout ); Health health = new Health( healthBuilder ) { @Override protected String buildURI() { return super.buildURI() + actualIndexName; } }; JestResult result = clientReference.get().executeRequest( health ); if ( !result.isSucceeded() ) { throw new SearchException( "Index " + actualIndexName + " wasn't created in time; Reason: " + result.getErrorMessage() ); } }
public Builder local(boolean local) { return setParameter("local", local); }
private Builder level(String level) { return setParameter("level", level); }
public Builder waitForStatus(Status status) { return waitForStatus(status.getKey()); }
public Builder local() { return local(true); }
public Builder waitForNoRelocatingShards() { return waitForNoRelocatingShards(true); }
private Builder waitForStatus(String status) { return setParameter("wait_for_status", status); }
public Builder waitForNoRelocatingShards(boolean wait) { return setParameter("wait_for_no_relocating_shards", wait); }
private Builder level(String level) { return setParameter("level", level); }
public Builder waitForStatus(Status status) { return waitForStatus(status.getKey()); }