public void waitForStatus(ClusterHealthStatus status) { prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForStatus(status).get(); }
private void waitForIndexYellow(String index) { Client nativeClient = esClient.nativeClient(); ClusterHealthAction.INSTANCE.newRequestBuilder(nativeClient).setIndices(index).setWaitForYellowStatus().get(TimeValue.timeValueMinutes(10)); }
@Test public void testDiscoveryWithoutInitialization() throws Exception { setup(Settings.EMPTY, null, Settings.EMPTY, false); Assert.assertEquals(clusterInfo.numNodes, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes()); Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus()); }
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 ClusterHealthStatus getClusterHealthStatus() { return getTransportClient().admin().cluster() .health(new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.YELLOW).timeout(timeValueSeconds(30))) .actionGet().getStatus(); }
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); }
/** * Check health of cluster. */ @Override public Health getClusterHealth() { try { ClusterHealthResponse chr = esProvider.getClient().admin() .cluster().health(new ClusterHealthRequest()).get(); return Health.valueOf( chr.getStatus().name() ); } catch ( Exception ex ) { ex.printStackTrace(); logger.error( "Error connecting to ElasticSearch", ex.getMessage() ); } // this is bad, red alert! return Health.RED; }
@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 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)); } } }
@Test public void get_with_string_timeout_is_not_yet_implemented() { try { es.client().prepareHealth().get("1"); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
Params withLevel(ClusterHealthRequest.Level level) { return putParam("level", level.name().toLowerCase(Locale.ROOT)); }
@Test public void testCustomInterclusterRequestEvaluator() throws Exception { final Settings settings = Settings.builder() .put(ConfigConstants.SG_INTERCLUSTER_REQUEST_EVALUATOR_CLASS, "com.floragunn.searchguard.AlwaysFalseInterClusterRequestEvaluator") .put("discovery.initial_state_timeout","8s") .build(); setup(Settings.EMPTY, null, settings, false,ClusterConfiguration.DEFAULT ,5,1); Assert.assertEquals(1, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes()); Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus()); }
/** * Check health of this specific index. */ @Override public Health getIndexHealth() { try { String[] indexNames = this.getIndexes(); final ActionFuture<ClusterHealthResponse> future = esProvider.getClient().admin().cluster().health( new ClusterHealthRequest( indexNames ) ); //only wait 2 seconds max ClusterHealthResponse chr = future.actionGet(2000); return Health.valueOf( chr.getStatus().name() ); } catch ( Exception ex ) { logger.error( "Error connecting to ElasticSearch", ex.getMessage() ); } // this is bad, red alert! return Health.RED; }
@Test public void trace_logs() { logTester.setLevel(LoggerLevel.TRACE); ClusterHealthRequestBuilder requestBuilder = es.client().prepareHealth(); ClusterHealthResponse state = requestBuilder.get(); assertThat(state.getStatus()).isEqualTo(ClusterHealthStatus.GREEN); assertThat(logTester.logs()).hasSize(1); }
@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"); } }
@Test public void get_with_time_value_timeout_is_not_yet_implemented() { try { es.client().prepareHealth().get(TimeValue.timeValueMinutes(1)); fail(); } catch (Exception e) { assertThat(e).isInstanceOf(IllegalStateException.class).hasMessage("Not yet implemented"); } }
@SuppressWarnings("resource") @Test public void testNodeClientAllowedWithServerCertificate() throws Exception { setup(); Assert.assertEquals(clusterInfo.numNodes, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes()); Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus()); final Settings tcSettings = Settings.builder() .put(minimumSearchGuardSettings(Settings.EMPTY).get(0)) .put("cluster.name", clusterInfo.clustername) .put("node.data", false) .put("node.master", false) .put("node.ingest", false) .put("path.home", ".") .put("discovery.initial_state_timeout","8s") .putList("discovery.zen.ping.unicast.hosts", clusterInfo.nodeHost+":"+clusterInfo.nodePort) .build(); log.debug("Start node client"); try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) { Thread.sleep(50); Assert.assertEquals(clusterInfo.numNodes+1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size()); } }
@SuppressWarnings("resource") @Test public void testNodeClientDisallowedWithNonServerCertificate2() throws Exception { setup(); Assert.assertEquals(clusterInfo.numNodes, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getNumberOfNodes()); Assert.assertEquals(ClusterHealthStatus.GREEN, clusterHelper.nodeClient().admin().cluster().health(new ClusterHealthRequest().waitForGreenStatus()).actionGet().getStatus()); final Settings tcSettings = Settings.builder() .put(minimumSearchGuardSettings(Settings.EMPTY).get(0)) .put("cluster.name", clusterInfo.clustername) .put("node.data", false) .put("node.master", false) .put("node.ingest", false) .put("path.home", ".") .put("discovery.initial_state_timeout","8s") .put("searchguard.ssl.transport.keystore_filepath", FileHelper.getAbsoluteFilePathFromClassPath("spock-keystore.jks")) .put(SSLConfigConstants.SEARCHGUARD_SSL_TRANSPORT_KEYSTORE_ALIAS,"spock") .build(); log.debug("Start node client"); try (Node node = new PluginAwareNode(false, tcSettings, Netty4Plugin.class, SearchGuardPlugin.class).start()) { Thread.sleep(50); Assert.assertEquals(1, node.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet().getNodes().size()); } }