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); }
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()) {
protected boolean clusterKo(Client client) { try { client.admin().cluster().prepareHealth().setTimeout(TimeValue.timeValueSeconds(1)).execute().actionGet(); return false; } catch(Exception e) { return true; } }
@Override public void open() { // Wait for Yellow status client().admin().cluster() .prepareHealth() .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueMinutes(1)) .execute() .actionGet(); }
@Override public void open() { // Wait for Yellow status client().admin().cluster() .prepareHealth() .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueMinutes(1)) .execute() .actionGet(); }
private void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout) throws IOException { try { logger.debug("waiting for cluster state {}", status.name()); final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status) .setTimeout(timeout).execute().actionGet(); if (healthResponse.isTimedOut()) { throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name() + ", cowardly refusing to continue with operations"); } else { logger.debug("... cluster state ok"); } } catch (final ElasticsearchTimeoutException e) { throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations"); } }
@Override public boolean waitForYellowStatus(String[] indexNames, int timeoutSecond) { String timeout = timeoutSecond + "s"; log.debug("Waiting for cluster yellow health status, indexes: " + Arrays.toString(indexNames)); try { ClusterHealthResponse response = client.admin() .cluster() .prepareHealth(indexNames) .setTimeout(timeout) .setWaitForYellowStatus() .get(); if (response.isTimedOut()) { throw new NuxeoException( "Elasticsearch Cluster health status not Yellow after " + timeout + " give up: " + response); } if (response.getStatus() != ClusterHealthStatus.GREEN) { log.warn("Elasticsearch Cluster ready but not GREEN: " + response); return false; } log.info("Elasticsearch Cluster ready: " + response); } catch (NoNodeAvailableException e) { throw new NuxeoException( "Failed to connect to elasticsearch, check addressList and clusterName: " + e.getMessage()); } return true; }
@Override public boolean isReady() { return node != null && node.client().admin().cluster().prepareHealth() .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueSeconds(30L)) .get() .getStatus() != ClusterHealthStatus.RED; }
public void waitForGreen() { client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); }
public void waitForGreen() { client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); }
@Override public boolean isSearchEngineReady() { ClusterHealthStatus status = new ClusterHealthRequestBuilder(client, ClusterHealthAction.INSTANCE) .setIndices(configuration.getIndexName()) .setTimeout(new TimeValue(configuration.getTimeoutMillis(), TimeUnit.MILLISECONDS)) .request() .waitForStatus(); return status != ClusterHealthStatus.RED; }
@Override public void open() { if (node == null || node.isClosed()) { // Build and start the node node = NodeBuilder.nodeBuilder().settings(buildNodeSettings()).node(); // Get a client client = node.client(); // Wait for Yellow status client.admin().cluster() .prepareHealth() .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueMinutes(1)) .execute() .actionGet(); } }
@Override public void open() { if (node == null || node.isClosed()) { // Build and start the node node = NodeBuilder.nodeBuilder().settings(buildNodeSettings()).node(); // Get a client client = node.client(); // Wait for Yellow status client.admin().cluster() .prepareHealth() .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueMinutes(1)) .execute() .actionGet(); } }
public ElasticSearchIndex(Configuration config) { indexName = config.get(INDEX_NAME); 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); }
public static void waitForYellowCluster(Client client) throws IOException { ClusterHealthStatus status = ClusterHealthStatus.YELLOW; try { logger.debug("waiting for cluster state {}", status.name()); final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status) .setTimeout(TimeValue.timeValueSeconds(30)).execute().actionGet(); if (healthResponse.isTimedOut()) { logger.error("Timeout while waiting for cluster state: {}, current cluster state is: {}", status.name(), healthResponse.getStatus().name()); throw new IOException("cluster state is " + healthResponse.getStatus().name() + " and not " + status.name() + ", cowardly refusing to continue with operations"); } else { logger.debug("... cluster state ok"); } } catch (final Exception e) { logger.error("Exception while waiting for cluster state: {} due to ", e, status.name(), e.toString()); throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations", e); } } }
/** * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations. * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating * are now allocated and started. * * @param timeout time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest} */ public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) { ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(indices); builder.setTimeout(timeout) .setWaitForGreenStatus() .setWaitForEvents(Priority.LANGUID) .setWaitForNoRelocatingShards(true); ClusterHealthResponse actionGet = builder.get(); if (actionGet.isTimedOut()) { logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get()); assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false)); } assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN)); logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices); return actionGet.getStatus(); }
private boolean isClusterHealthy() throws UnknownHostException { ClusterHealthResponse healthResponse = getElasticClient() .admin() .cluster() .prepareHealth(policyIndexName) .setWaitForYellowStatus() .setTimeout(TimeValue.timeValueSeconds(elasticsearchProperties.getElasticsearchIndexStatusTimeout())) .get(); if (healthResponse.isTimedOut()) { logger.warn("Timed out while awaiting at least YELLOW status for Elasticsearch index {} ", policyIndexName); return false; } if (!healthResponse.getStatus().equals(ClusterHealthStatus.YELLOW) && !healthResponse.getStatus().equals(ClusterHealthStatus.GREEN)) { logger.warn("The Elasticsearch index {} is reporting status {}", policyIndexName, healthResponse.getStatus().name()); return false; } return true; }
protected void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) { if (viaNode == null) { viaNode = randomFrom(internalCluster().getNodeNames()); } logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue); ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth() .setWaitForEvents(Priority.LANGUID) .setWaitForNodes(Integer.toString(nodeCount)) .setTimeout(timeValue) .setLocal(local) .setWaitForNoRelocatingShards(true) .get(); if (clusterHealthResponse.isTimedOut()) { ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get(); fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n" + stateResponse.getState()); } assertThat(clusterHealthResponse.isTimedOut(), is(false)); ensureFullyConnectedCluster(); }
public void waitForYellowStatus(Client client) throws ExecutionException, InterruptedException { client.admin().cluster().prepareHealth().setWaitForYellowStatus().setTimeout(new TimeValue(10, TimeUnit.SECONDS)).execute().get(); } }
protected void waitForCluster(final ClusterHealthStatus status, final TimeValue timeout, final Client client) throws IOException { try { log.debug("waiting for cluster state {}", status.name()); final ClusterHealthResponse healthResponse = client.admin().cluster().prepareHealth().setWaitForStatus(status) .setTimeout(timeout).setWaitForNodes("3").execute().actionGet(); if (healthResponse.isTimedOut()) { throw new IOException("cluster state is " + healthResponse.getStatus().name() + " with " + healthResponse.getNumberOfNodes() + " nodes"); } else { log.debug("... cluster state ok " + healthResponse.getStatus().name() + " with " + healthResponse.getNumberOfNodes() + " nodes"); } final NodesInfoResponse res = esNode1.client().admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet(); final List<NodeInfo> nodes = res.getNodes(); for (NodeInfo nodeInfo: nodes) { if (nodeInfo.getHttp() != null && nodeInfo.getHttp().address() != null) { final TransportAddress is = nodeInfo.getHttp().address().publishAddress(); httpPort = is.getPort(); httpHost = is.getAddress(); } final TransportAddress is = nodeInfo.getTransport().getAddress().publishAddress(); nodePort = is.getPort(); nodeHost = is.getAddress(); } } catch (final ElasticsearchTimeoutException e) { throw new IOException("timeout, cluster does not respond to health request, cowardly refusing to continue with operations"); } }