Search in sources :

Example 21 with ClusterHealthRequest

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();
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 22 with ClusterHealthRequest

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();
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 23 with ClusterHealthRequest

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();
    }
}
Also used : ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterGetSettingsRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsRequest) NodesStats(org.graylog2.system.stats.elasticsearch.NodesStats) LoggerFactory(org.slf4j.LoggerFactory) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) ClusterGetSettingsResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.settings.ClusterGetSettingsResponse) ClusterHealthStatus(org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus) HealthStatus(org.graylog2.indexer.indices.HealthStatus) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) ClusterStats(org.graylog2.system.stats.elasticsearch.ClusterStats) TimeValue(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.unit.TimeValue) Locale(java.util.Locale) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) ClusterHealth(org.graylog2.rest.models.system.indexer.responses.ClusterHealth) JsonNode(com.fasterxml.jackson.databind.JsonNode) Duration(com.github.joschi.jadconfig.util.Duration) Named(javax.inject.Named) JsonNodeType(com.fasterxml.jackson.databind.node.JsonNodeType) ClusterAllocationDiskSettingsFactory(org.graylog2.indexer.cluster.health.ClusterAllocationDiskSettingsFactory) GetIndexRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.indices.GetIndexRequest) Logger(org.slf4j.Logger) CatApi(org.graylog.storage.elasticsearch7.cat.CatApi) Collection(java.util.Collection) Request(org.graylog.shaded.elasticsearch7.org.elasticsearch.client.Request) PendingTasksStats(org.graylog2.indexer.cluster.PendingTasksStats) IndicesStats(org.graylog2.system.stats.elasticsearch.IndicesStats) Set(java.util.Set) ClusterAllocationDiskSettings(org.graylog2.indexer.cluster.health.ClusterAllocationDiskSettings) NodeFileDescriptorStats(org.graylog2.indexer.cluster.health.NodeFileDescriptorStats) Ints(com.google.common.primitives.Ints) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) Collectors(java.util.stream.Collectors) ShardStats(org.graylog2.system.stats.elasticsearch.ShardStats) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) List(java.util.List) NodeDiskUsageStats(org.graylog2.indexer.cluster.health.NodeDiskUsageStats) Optional(java.util.Optional) ClusterAdapter(org.graylog2.indexer.cluster.ClusterAdapter) NodeResponse(org.graylog.storage.elasticsearch7.cat.NodeResponse) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ElasticsearchException(org.graylog2.indexer.ElasticsearchException)

Example 24 with ClusterHealthRequest

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));
}
Also used : ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 25 with ClusterHealthRequest

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);
        }
    }
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IOException(java.io.IOException)

Aggregations

ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)22 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)15 IOException (java.io.IOException)6 Set (java.util.Set)4 ClusterHealthStatus (org.elasticsearch.cluster.health.ClusterHealthStatus)4 UnknownHostException (java.net.UnknownHostException)3 Collections (java.util.Collections)3 Locale (java.util.Locale)3 Properties (java.util.Properties)3 CreateIndexRequest (org.elasticsearch.action.admin.indices.create.CreateIndexRequest)3 Settings (org.elasticsearch.common.settings.Settings)3 Builder (org.elasticsearch.common.settings.Settings.Builder)3 InetSocketTransportAddress (org.elasticsearch.common.transport.InetSocketTransportAddress)3 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)3 XContentFactory.jsonBuilder (org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder)3 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2 List (java.util.List)2