public boolean wait_ready(long maxtimemillis, ClusterHealthStatus status) { // wait for yellow status long start = System.currentTimeMillis(); boolean is_ready; do { // wait for yellow status ClusterHealthResponse health = elasticsearchClient.admin().cluster().prepareHealth().setWaitForStatus(status).execute().actionGet(); is_ready = !health.isTimedOut(); if (!is_ready && System.currentTimeMillis() - start > maxtimemillis) return false; } while (!is_ready); return is_ready; }
@Override public ClusterHealthResponse get() { Profiler profiler = Profiler.createIfTrace(EsClient.LOGGER).start(); try { return super.execute().actionGet(); } catch (Exception e) { throw new IllegalStateException(String.format("Fail to execute %s", toString()), e); } finally { if (profiler.isTraceEnabled()) { profiler.stopTrace(toString()); } } }
@Test public void execute_should_throw_an_unsupported_operation_exception() { try { es.client().prepareHealth().execute(); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(UnsupportedOperationException.class).hasMessage("execute() should not be called as it's used for asynchronous"); } }
@Override public void setup() throws Exception { elasticSearchClient.admin() .cluster() .prepareHealth() .setWaitForGreenStatus() .execute() .get(); try { initIndex(); updateLogIndexName(); Executors.newScheduledThreadPool(1) .scheduleAtFixedRate(() -> updateLogIndexName(), 0, 1, TimeUnit.HOURS); } catch (Exception e) { logger.error(e.getMessage(), e); } //1. Create the required index addIndex(indexName); //2. Add Mappings for the workflow document type addMappingToIndex(indexName, WORKFLOW_DOC_TYPE, "/mappings_docType_workflow.json"); //3. Add Mappings for task document type addMappingToIndex(indexName, TASK_DOC_TYPE, "/mappings_docType_task.json"); }
public ElasticSearchIndex(Configuration config) { indexName = config.get(INDEX_NAME); useDeprecatedIgnoreUnmapped = config.get(USE_EDEPRECATED_IGNORE_UNMAPPED_OPTION); checkExpectedClientVersion(); final ElasticSearchSetup.Connection c; if (!config.has(INTERFACE)) { c = legacyConfiguration(config); } else { c = interfaceConfiguration(config); } node = c.getNode(); client = c.getClient(); maxResultsSize = config.get(INDEX_MAX_RESULT_SET_SIZE); log.debug("Configured ES query result set max size to {}", maxResultsSize); client.admin().cluster().prepareHealth().setTimeout(config.get(HEALTH_REQUEST_TIMEOUT)) .setWaitForYellowStatus().execute().actionGet(); checkForOrCreateIndex(config); }
adminClient = client.admin(); adminClient.cluster().prepareHealth() .setWaitForYellowStatus().execute().actionGet();
@BeforeClass public static void startServer() throws Exception { System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9203"); System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "localhost:9303"); configuration = new SystemPropertiesElasticSearchConfiguration(); String host = configuration.getEmbeddedHost(); int port = configuration.getEmbeddedPort(); String clusterName = configuration.getEmbeddedClusterName(); embeddedElasticSearch = new EmbeddedElasticSearchV5(clusterName, host, port); embeddedElasticSearch.start(); ElasticSearchTransportClientProvider transportClientProvider = new ElasticSearchTransportClientProvider(configuration); elasticSearchClient = transportClientProvider.get(); elasticSearchClient.admin() .cluster() .prepareHealth() .setWaitForGreenStatus() .execute() .get(); ObjectMapper objectMapper = new ObjectMapper(); indexDAO = new ElasticSearchDAOV5(elasticSearchClient, configuration, objectMapper); }
log.debug("waiting for cluster state {} and {} nodes", status.name(), expectedNodeCount); final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth() .setWaitForStatus(status).setTimeout(timeout).setMasterNodeTimeout(timeout).setWaitForNodes("" + expectedNodeCount).execute() .actionGet(); if (healthResponse.isTimedOut()) {
public boolean wait_ready(long maxtimemillis, ClusterHealthStatus status) { // wait for yellow status long start = System.currentTimeMillis(); boolean is_ready; do { // wait for yellow status ClusterHealthResponse health = elasticsearchClient.admin().cluster().prepareHealth().setWaitForStatus(status).execute().actionGet(); is_ready = !health.isTimedOut(); if (!is_ready && System.currentTimeMillis() - start > maxtimemillis) return false; } while (!is_ready); return is_ready; }
.prepareHealth().setWaitForYellowStatus().execute().actionGet(); System.out.println("ElasticSearch Health Check " + actionGet);
@Override public ClusterHealthResponse getClusterHealth(String clusterName) { Set<Node> nodeSet = nodesClusterMap.get(clusterName); if (nodeSet != null) { for (Node node : nodeSet) { ClusterAdminClient client = node.client().admin().cluster(); ClusterHealthResponse response = client.prepareHealth().execute().actionGet(); return response; } } return null; }
public static void waitForAvailable(final Client client, final String... indices) { final ClusterHealthResponse response = client.admin().cluster() .prepareHealth(indices).setWaitForYellowStatus().execute() .actionGet(); final List<String> failures = response.getValidationFailures(); if (!failures.isEmpty()) { throw new ElasticsearchException( "Cluster is not available: " + failures.toString()); } } }
public static void waitForAvailable(final Client client, final String... indices) { final ClusterHealthResponse response = client.admin().cluster() .prepareHealth(indices).setWaitForYellowStatus().execute() .actionGet(); final List<String> failures = response.getAllValidationFailures(); if (!failures.isEmpty()) { throw new EsUtilSystemException("Cluster is not available: " + failures.toString()); } } }
@SuppressWarnings("unused") protected void createIndex(String indexName, boolean storeSourceData) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).execute().actionGet(); LOGGER.debug(createResponse.toString()); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: " + health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for green index status, for index: " + indexName); } }
@SuppressWarnings("unused") protected void createIndex(String indexName, boolean storeSourceData) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).execute().actionGet(); LOGGER.debug(createResponse.toString()); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: " + health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for green index status, for index: " + indexName); } }
private void printClusterStatus() { ClusterHealthRequestBuilder healthRequestBuilder = elasticsearchClient.admin().cluster().prepareHealth(); ClusterHealthResponse response = healthRequestBuilder.execute().actionGet(); if (response.getStatus().equals(ClusterHealthStatus.RED)) { LOG.error("Cluster health is RED. Indexing ability will be limited"); } else if (response.getStatus().equals(ClusterHealthStatus.YELLOW)) { LOG.warn("Cluster health is YELLOW."); } else if (response.getStatus().equals(ClusterHealthStatus.GREEN)) { LOG.info("Cluster health is GREEN."); } } }
@Override public void open() { // Wait for Yellow status client().admin().cluster() .prepareHealth() .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueMinutes(1)) .execute() .actionGet(); }
private void printClusterStatus() { ClusterHealthRequestBuilder healthRequestBuilder = elasticsearchClient.admin().cluster().prepareHealth(); ClusterHealthResponse response = healthRequestBuilder.execute().actionGet(); if (response.getStatus().equals(ClusterHealthStatus.RED)) { LOG.error("Cluster health is RED. Indexing ability will be limited"); } else if (response.getStatus().equals(ClusterHealthStatus.YELLOW)) { LOG.warn("Cluster health is YELLOW."); } else if (response.getStatus().equals(ClusterHealthStatus.GREEN)) { LOG.info("Cluster health is GREEN."); } } }
@Override protected void ensureClusterReady(String catchAll) { ClusterHealthResponse health = getUnchecked(client .admin().cluster().prepareHealth(catchAll).execute()); checkState(health.getStatus() != ClusterHealthStatus.RED, "Health status is RED"); }
@Override public void doStart() { ImmutableSettings.Builder elasticsearchSettings = ImmutableSettings.settingsBuilder(); for (String key : settings.keySet()) { elasticsearchSettings.put(key, String.valueOf(settings.get(key))); } this.node = nodeBuilder().local(true).settings(elasticsearchSettings.build()).node(); node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet(initTimeout); }