Search in sources :

Example 6 with ClusterHealthStatus

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project snow-owl by b2ihealthcare.

the class EsClientBase method status.

@Override
public final EsClusterStatus status(String... indices) {
    final String clusterDiagnosis = clusterAvailable.get();
    final boolean available = Strings.isNullOrEmpty(clusterDiagnosis);
    if (available) {
        final List<EsIndexStatus> indexStatuses = newArrayList();
        for (String index : indices == null || indices.length == 0 ? clusterHealth.get().getIndices().keySet() : Arrays.asList(indices)) {
            // ignore health check of system / hidden indices
            if (index.startsWith(".")) {
                continue;
            }
            ClusterHealthStatus indexHealth = getIndexHealth(index);
            String diagnosis = null;
            // if not in red health state, check the read only flag
            if (indexHealth != ClusterHealthStatus.RED && isIndexReadOnly(index)) {
                indexHealth = ClusterHealthStatus.RED;
                diagnosis = String.format("Index is read-only. Check/Fix source of the error (eg. run out of disk space), then run `curl -XPUT \"%s/%s/_settings\" -d '{ \"index.blocks.read_only_allow_delete\": null }'` to remove read-only flag.", host.toURI(), index);
            }
            indexStatuses.add(new EsIndexStatus(index, indexHealth, diagnosis));
        }
        return new EsClusterStatus(available, clusterDiagnosis, indexStatuses);
    } else {
        return new EsClusterStatus(available, clusterDiagnosis, Collections.emptyList());
    }
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus)

Example 7 with ClusterHealthStatus

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.

the class AllocationService method logClusterHealthStateChange.

private void logClusterHealthStateChange(ClusterStateHealth previousStateHealth, ClusterStateHealth newStateHealth, String reason) {
    ClusterHealthStatus previousHealth = previousStateHealth.getStatus();
    ClusterHealthStatus currentHealth = newStateHealth.getStatus();
    if (!previousHealth.equals(currentHealth)) {
        logger.info("Cluster health status changed from [{}] to [{}] (reason: [{}]).", previousHealth, currentHealth, reason);
    }
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus)

Example 8 with ClusterHealthStatus

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project elasticsearch by elastic.

the class SearchWhileCreatingIndexIT method searchWhileCreatingIndex.

private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas) throws Exception {
    // TODO: randomize the wait for active shards value on index creation and ensure the appropriate
    // number of data nodes are started for the randomized active shard count value
    String id = randomAsciiOfLength(5);
    // we will go the primary or the replica, but in a
    // randomized re-creatable manner
    int counter = 0;
    String preference = randomAsciiOfLength(5);
    logger.info("running iteration for id {}, preference {}", id, preference);
    if (createIndex) {
        createIndex("test");
    }
    client().prepareIndex("test", "type1", id).setSource("field", "test").execute().actionGet();
    RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet();
    // at least one shard should be successful when refreshing
    assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1));
    logger.info("using preference {}", preference);
    // we want to make sure that while recovery happens, and a replica gets recovered, its properly refreshed
    ClusterHealthStatus status = ClusterHealthStatus.RED;
    while (status != ClusterHealthStatus.GREEN) {
        // first, verify that search on the primary search works
        SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
        assertHitCount(searchResponse, 1);
        Client client = client();
        searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
        if (searchResponse.getHits().getTotalHits() != 1) {
            refresh();
            SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
            logger.info("hits count mismatch on any shard search failed, post explicit refresh hits are {}", searchResponseAfterRefresh.getHits().getTotalHits());
            ensureGreen();
            SearchResponse searchResponseAfterGreen = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
            logger.info("hits count mismatch on any shard search failed, post explicit wait for green hits are {}", searchResponseAfterGreen.getHits().getTotalHits());
            assertHitCount(searchResponse, 1);
        }
        assertHitCount(searchResponse, 1);
        status = client().admin().cluster().prepareHealth("test").get().getStatus();
        internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + 1);
    }
    cluster().wipeIndices("test");
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) RefreshResponse(org.elasticsearch.action.admin.indices.refresh.RefreshResponse) Client(org.elasticsearch.client.Client) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 9 with ClusterHealthStatus

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus in project crate by crate.

the class AllocationService method logClusterHealthStateChange.

private void logClusterHealthStateChange(ClusterStateHealth previousStateHealth, ClusterStateHealth newStateHealth, String reason) {
    ClusterHealthStatus previousHealth = previousStateHealth.getStatus();
    ClusterHealthStatus currentHealth = newStateHealth.getStatus();
    if (!previousHealth.equals(currentHealth)) {
        LOGGER.info("Cluster health status changed from [{}] to [{}] (reason: [{}]).", previousHealth, currentHealth, reason);
    }
}
Also used : ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus)

Example 10 with ClusterHealthStatus

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.cluster.health.ClusterHealthStatus 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)

Aggregations

ClusterHealthStatus (org.elasticsearch.cluster.health.ClusterHealthStatus)9 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)2 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 CommonStats (org.elasticsearch.action.admin.indices.stats.CommonStats)1 IndexStats (org.elasticsearch.action.admin.indices.stats.IndexStats)1 ShardStats (org.elasticsearch.action.admin.indices.stats.ShardStats)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 Client (org.elasticsearch.client.Client)1 ClusterState (org.elasticsearch.cluster.ClusterState)1 ClusterIndexHealth (org.elasticsearch.cluster.health.ClusterIndexHealth)1 ClusterStateHealth (org.elasticsearch.cluster.health.ClusterStateHealth)1 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)1 GroupShardsIterator (org.elasticsearch.cluster.routing.GroupShardsIterator)1 ShardIterator (org.elasticsearch.cluster.routing.ShardIterator)1