use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project crate by crate.
the class ESIntegTestCase method ensureColor.
private ClusterHealthStatus ensureColor(ClusterHealthStatus clusterHealthStatus, TimeValue timeout, boolean waitForNoInitializingShards, String... indices) {
String color = clusterHealthStatus.name().toLowerCase(Locale.ROOT);
String method = "ensure" + Strings.capitalize(color);
ClusterHealthRequest healthRequest = Requests.clusterHealthRequest(indices).timeout(timeout).waitForStatus(clusterHealthStatus).waitForEvents(Priority.LANGUID).waitForNoRelocatingShards(true).waitForNoInitializingShards(waitForNoInitializingShards).waitForNodes(Integer.toString(cluster().size()));
ClusterHealthResponse actionGet = client().admin().cluster().health(healthRequest).actionGet();
if (actionGet.isTimedOut()) {
logger.info("{} timed out, cluster state:\n{}\n{}", method, client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get());
fail("timed out waiting for " + color + " state");
}
assertThat("Expected at least " + clusterHealthStatus + " but got " + actionGet.getStatus(), actionGet.getStatus().value(), lessThanOrEqualTo(clusterHealthStatus.value()));
logger.debug("indices {} are {}", indices.length == 0 ? "[_all]" : indices, color);
return actionGet.getStatus();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project crate by crate.
the class ESIntegTestCase method waitForRelocation.
/**
* Waits for all relocating shards to become active and the cluster has reached the given health status
* using the cluster health API.
*/
public ClusterHealthStatus waitForRelocation(ClusterHealthStatus status) {
ClusterHealthRequest request = Requests.clusterHealthRequest().waitForNoRelocatingShards(true).waitForEvents(Priority.LANGUID);
if (status != null) {
request.waitForStatus(status);
}
ClusterHealthResponse actionGet = client().admin().cluster().health(request).actionGet();
if (actionGet.isTimedOut()) {
logger.info("waitForRelocation timed out (status={}), cluster state:\n{}\n{}", status, client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get());
assertThat("timed out waiting for relocation", actionGet.isTimedOut(), equalTo(false));
}
if (status != null) {
assertThat(actionGet.getStatus(), equalTo(status));
}
return actionGet.getStatus();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project graylog2-server by Graylog2.
the class ClusterAdapterES7 method clusterHealth.
private Optional<ClusterHealthResponse> clusterHealth(Collection<String> indices) {
final String[] indicesAry = indices.toArray(new String[0]);
if (!indices.isEmpty() && !indicesExist(indicesAry)) {
return Optional.empty();
}
final ClusterHealthRequest request = new ClusterHealthRequest(indicesAry).timeout(TimeValue.timeValueSeconds(Ints.saturatedCast(requestTimeout.toSeconds()))).indicesOptions(IndicesOptions.lenientExpand());
try {
return Optional.of(client.execute((c, requestOptions) -> c.cluster().health(request, requestOptions)));
} 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();
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project graylog2-server by Graylog2.
the class ClientES7 method waitForStatus.
private void waitForStatus(ClusterHealthStatus status, String... indices) {
final ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest(indices);
clusterHealthRequest.waitForStatus(status);
client.execute((c, requestOptions) -> c.cluster().health(clusterHealthRequest, requestOptions));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project snow-owl by b2ihealthcare.
the class EsIndexAdmin method waitForYellowHealth.
private void waitForYellowHealth(String... indices) {
if (!CompareUtils.isEmpty(indices)) {
/*
* See https://www.elastic.co/guide/en/elasticsearch/reference/6.3/cluster-health.html
* for the low-level structure of the cluster health request.
*/
final Object clusterTimeoutSetting = settings.getOrDefault(IndexClientFactory.CLUSTER_HEALTH_TIMEOUT, IndexClientFactory.DEFAULT_CLUSTER_HEALTH_TIMEOUT);
final Object socketTimeoutSetting = settings.getOrDefault(IndexClientFactory.SOCKET_TIMEOUT, IndexClientFactory.DEFAULT_SOCKET_TIMEOUT);
final int clusterTimeout = clusterTimeoutSetting instanceof Integer ? (int) clusterTimeoutSetting : Integer.parseInt((String) clusterTimeoutSetting);
final int socketTimeout = socketTimeoutSetting instanceof Integer ? (int) socketTimeoutSetting : Integer.parseInt((String) socketTimeoutSetting);
final int pollTimeout = socketTimeout / 2;
final ClusterHealthRequest req = new ClusterHealthRequest(indices).waitForYellowStatus().timeout(// Poll interval is half the socket timeout
String.format("%sms", pollTimeout));
// Detail level should be concerned with the indices in the path
req.level(Level.INDICES);
final long startTime = System.currentTimeMillis();
// Polling finishes when the cluster timeout is reached
final long endTime = startTime + clusterTimeout;
long currentTime = startTime;
ClusterHealthResponse response = null;
do {
try {
response = client().cluster().health(req);
currentTime = System.currentTimeMillis();
if (response != null && !response.isTimedOut()) {
break;
}
} catch (Exception e) {
throw new IndexException("Couldn't retrieve cluster health for index " + name, e);
}
} while (currentTime < endTime);
if (response == null || response.isTimedOut()) {
throw new IndexException(String.format("Cluster health did not reach yellow status for '%s' indexes after %s ms.", name, currentTime - startTime), null);
} else {
log.info("Cluster health for '{}' indexes reported as '{}' after {} ms.", name, response.getStatus(), currentTime - startTime);
}
}
}
Aggregations