Search in sources :

Example 11 with ClusterHealthRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project graylog2-server by Graylog2.

the class IndicesAdapterES7 method waitForRecovery.

@Override
public HealthStatus waitForRecovery(String index, int timeout) {
    final ClusterHealthRequest clusterHealthRequest = new ClusterHealthRequest(index).timeout(TimeValue.timeValueSeconds(timeout));
    clusterHealthRequest.waitForGreenStatus();
    final ClusterHealthResponse result = client.execute((c, requestOptions) -> c.cluster().health(clusterHealthRequest, requestOptions));
    return HealthStatus.fromString(result.getStatus().toString());
}
Also used : ClusterHealthResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)

Example 12 with ClusterHealthRequest

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

the class EsClientBase method checkClusterHealth.

private ClusterHealthResponse checkClusterHealth(ClusterHealthResponse previousHealth) {
    try {
        log.info("Checking cluster health at '{}'...", host.toURI());
        ClusterHealthRequest req = new ClusterHealthRequest();
        req.level(Level.INDICES);
        // The default indices options (IndicesOptions.lenientExpandHidden()) returns all indices including system or hidden.
        // It is not possible to determine if a hidden index is read only or not.
        // This leads to the isIndexReadOnly() method waiting 60 seconds for each hidden index, eventually causing requests to be stalled.
        req.indicesOptions(IndicesOptions.lenientExpand());
        return cluster().health(req);
    } catch (IOException e) {
        throw new IndexException("Failed to get cluster health", e);
    }
}
Also used : IndexException(com.b2international.index.IndexException) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) IOException(java.io.IOException)

Example 13 with ClusterHealthRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project sonarqube by SonarSource.

the class EsRequestDetailsTest method should_format_ClusterHealthRequest.

@Test
public void should_format_ClusterHealthRequest() {
    ClusterHealthRequest request = new ClusterHealthRequest("index-1");
    assertThat(EsRequestDetails.computeDetailsAsString(request)).isEqualTo("ES cluster health request on indices 'index-1'");
}
Also used : ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) Test(org.junit.Test)

Example 14 with ClusterHealthRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project pancm_project by xuwujing.

the class EsHighLevelCluster method catHealth.

/**
 * @return void
 * @Author pancm
 * @Description 设获取集群的健康情况
 * @Date 2020/1/2
 * @Param [index]
 */
public static void catHealth() throws IOException {
    ClusterHealthRequest request = new ClusterHealthRequest();
    ClusterHealthResponse response = client.cluster().health(request, RequestOptions.DEFAULT);
    String clusterName = response.getClusterName();
    ClusterHealthStatus status = response.getStatus();
    boolean timedOut = response.isTimedOut();
    RestStatus restStatus = response.status();
    int numberOfNodes = response.getNumberOfNodes();
    int numberOfDataNodes = response.getNumberOfDataNodes();
    int activeShards = response.getActiveShards();
    int activePrimaryShards = response.getActivePrimaryShards();
    int relocatingShards = response.getRelocatingShards();
    int initializingShards = response.getInitializingShards();
    int unassignedShards = response.getUnassignedShards();
    int delayedUnassignedShards = response.getDelayedUnassignedShards();
    double activeShardsPercent = response.getActiveShardsPercent();
    logger.info("clusterName:{},status:{},timedOut:{},restStatus:{}", clusterName, status, timedOut, restStatus.getStatus());
    List<Map<String, Object>> mapList = new ArrayList<>();
    response.getIndices().forEach((k, v) -> {
        Map<String, Object> map = new HashMap<>();
        String index = v.getIndex();
        int replicas = v.getNumberOfReplicas();
        int allShards = v.getActiveShards();
        int shards = v.getActivePrimaryShards();
        int status2 = v.getStatus().value();
        map.put("index", index);
        map.put("replicas", replicas);
        map.put("shards", shards);
        map.put("status", status2);
        System.out.println(map);
    });
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClusterHealthStatus(org.elasticsearch.cluster.health.ClusterHealthStatus) RestStatus(org.elasticsearch.rest.RestStatus)

Example 15 with ClusterHealthRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest in project elasticsearch by elastic.

the class TransportClientTests method testThatUsingAClosedClientThrowsAnException.

public void testThatUsingAClosedClientThrowsAnException() throws ExecutionException, InterruptedException {
    final TransportClient client = new MockTransportClient(Settings.EMPTY);
    client.close();
    final IllegalStateException e = expectThrows(IllegalStateException.class, () -> client.admin().cluster().health(new ClusterHealthRequest()).get());
    assertThat(e, hasToString(containsString("transport client is closed")));
}
Also used : MockTransportClient(org.elasticsearch.transport.MockTransportClient) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) MockTransportClient(org.elasticsearch.transport.MockTransportClient)

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