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 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); }
private static void startElasticsearch() throws Exception { try { FileUtils.deleteDirectory(new File("build/elasticsearch")); } catch (IOException e) { // ignore } final Settings settings = Settings.builder() .put("path.home", "build/elasticsearch") .put("node.name", "junit-es-node") .put("path.logs", "build/elasticsearch/logs") .put("path.data", "build/elasticsearch/data") .put("transport.type", "local") .put("http.type", "netty4") .build(); node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class)); node.start(); node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get(); }
node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get(); adminClient.cluster().prepareHealth() .setWaitForYellowStatus().execute().actionGet();
throw new IllegalStateException("Failed to create index " + index.getName()); SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get(); SHARED_NODE.client().admin().cluster().prepareHealth(index.getName()).setWaitForStatus(ClusterHealthStatus.YELLOW).get(); result.add(index);
@Test public void transportClientClusterHealth() { try (ElasticsearchContainer container = new ElasticsearchContainer()) { container.start(); TransportAddress transportAddress = new TransportAddress(container.getTcpHost()); String expectedClusterName = "docker-cluster"; Settings settings = Settings.builder().put("cluster.name", expectedClusterName).build(); try (TransportClient transportClient = new PreBuiltTransportClient(settings) .addTransportAddress(transportAddress)) { ClusterHealthResponse healths = transportClient.admin().cluster().prepareHealth().get(); String clusterName = healths.getClusterName(); assertThat(clusterName, is(expectedClusterName)); } } }
@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); }
try { 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();
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; }
public boolean clusterReady() { if (clusterReadyCache) return true; ClusterHealthResponse chr = elasticsearchClient.admin().cluster().prepareHealth().get(); clusterReadyCache = chr.getStatus() != ClusterHealthStatus.RED; return clusterReadyCache; }
.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()); } } }
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."); } } }
protected void ensureNodeCount(InternalTestCluster cluster) { assertFalse("cluster failed to form after disruption was healed", cluster.client().admin().cluster().prepareHealth() .setWaitForNodes(String.valueOf(cluster.size())) .setWaitForNoRelocatingShards(true) .get().isTimedOut()); }
protected void startNode(long seed) throws Exception { ElassandraDaemon.instance.node(RandomizedContext.current().runWithPrivateRandomness(seed, this::newNode)); // we must wait for the node to actually be up and running. otherwise the node might have started, // elected itself master but might not yet have removed the // SERVICE_UNAVAILABLE/1/state not recovered / initialized block ClusterAdminClient clusterAdminClient = client().admin().cluster(); ClusterHealthRequestBuilder builder = clusterAdminClient.prepareHealth(); ClusterHealthResponse clusterHealthResponse = builder.setWaitForGreenStatus().get(); assertFalse(clusterHealthResponse.isTimedOut()); }