Search in sources :

Example 1 with HealthResponse

use of org.opensearch.client.opensearch.cluster.HealthResponse in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthYellowClusterLevel.

public void testClusterHealthYellowClusterLevel() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    createIndex("index", Settings.EMPTY);
    createIndex("index2", Settings.EMPTY);
    HealthRequest request = new HealthRequest.Builder().timeout(t -> t.time("5s")).build();
    HealthResponse response = openSearchClient.cluster().health(request);
    assertEquals(response.indices().size(), 0);
}
Also used : GetClusterSettingsRequest(org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse) Collections.emptyMap(java.util.Collections.emptyMap) ShardHealthStats(org.opensearch.client.opensearch.cluster.health.ShardHealthStats) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) JsonData(org.opensearch.client.json.JsonData) IndexHealthStats(org.opensearch.client.opensearch.cluster.health.IndexHealthStats) EnableAllocationDecider(org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider) OpenSearchException(org.opensearch.client.opensearch._types.OpenSearchException) HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Settings(org.opensearch.common.settings.Settings) IOException(java.io.IOException) HashMap(java.util.HashMap) GetClusterSettingsResponse(org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse) ResponseException(org.opensearch.client.ResponseException) PutClusterSettingsRequest(org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) HealthStatus(org.opensearch.client.opensearch._types.HealthStatus) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings) Level(org.opensearch.client.opensearch._types.Level) PutClusterSettingsResponse(org.opensearch.client.opensearch.cluster.PutClusterSettingsResponse) HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Example 2 with HealthResponse

use of org.opensearch.client.opensearch.cluster.HealthResponse in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthYellowIndicesLevel.

public void testClusterHealthYellowIndicesLevel() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    String firstIndex = "index";
    String secondIndex = "index2";
    // including another index that we do not assert on, to ensure that we are not
    // accidentally asserting on entire cluster state
    String ignoredIndex = "tasks";
    createIndex(firstIndex, Settings.EMPTY);
    createIndex(secondIndex, Settings.EMPTY);
    if (randomBoolean()) {
        createIndex(ignoredIndex, Settings.EMPTY);
    }
    HealthRequest request = new HealthRequest.Builder().index(firstIndex, secondIndex).timeout(t -> t.time("5s")).level(Level.Indices).build();
    HealthResponse response = openSearchClient.cluster().health(request);
    assertYellowShards(response);
    assertEquals(response.indices().size(), 2);
    for (Map.Entry<String, IndexHealthStats> entry : response.indices().entrySet()) {
        assertYellowIndex(entry.getKey(), entry.getValue(), true);
    }
}
Also used : HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) IndexHealthStats(org.opensearch.client.opensearch.cluster.health.IndexHealthStats) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Example 3 with HealthResponse

use of org.opensearch.client.opensearch.cluster.HealthResponse in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthNotFoundIndex.

public void testClusterHealthNotFoundIndex() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    createIndex("index", Settings.EMPTY);
    HealthRequest request = new HealthRequest.Builder().index("notexisted-index").timeout(t -> t.time("5s")).level(Level.Indices).build();
    try {
        HealthResponse response = openSearchClient.cluster().health(request);
        assertNotNull(response);
        assertTrue(response.timedOut());
        assertEquals(response.status(), HealthStatus.Red);
        assertNoIndices(response);
    } catch (ResponseException e) {
        assertNotNull(e);
    }
}
Also used : HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) ResponseException(org.opensearch.client.ResponseException) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Example 4 with HealthResponse

use of org.opensearch.client.opensearch.cluster.HealthResponse in project opensearch-java by opensearch-project.

the class ClusterClientIT method testClusterHealthYellowSpecificIndex.

public void testClusterHealthYellowSpecificIndex() throws IOException {
    OpenSearchClient openSearchClient = highLevelClient();
    createIndex("index", Settings.EMPTY);
    createIndex("index2", Settings.EMPTY);
    HealthRequest request = new HealthRequest.Builder().index("index").timeout(t -> t.time("5s")).level(Level.Shards).build();
    HealthResponse response = openSearchClient.cluster().health(request);
    assertNotNull(response);
    assertFalse(response.timedOut());
    assertEquals(response.status(), HealthStatus.Yellow);
    assertEquals(response.activePrimaryShards(), 1);
    assertEquals(response.numberOfDataNodes(), 1);
    assertEquals(response.numberOfNodes(), 1);
    assertEquals(response.activeShards(), 1);
    assertEquals(response.delayedUnassignedShards(), 0);
    assertEquals(response.initializingShards(), 0);
    assertEquals(response.unassignedShards(), 1);
    assertEquals(response.indices().size(), 1);
    Map.Entry<String, IndexHealthStats> index = response.indices().entrySet().iterator().next();
    assertYellowIndex(index.getKey(), index.getValue(), false);
}
Also used : HealthRequest(org.opensearch.client.opensearch.cluster.HealthRequest) IndexHealthStats(org.opensearch.client.opensearch.cluster.health.IndexHealthStats) OpenSearchClient(org.opensearch.client.opensearch.OpenSearchClient) Collections.emptyMap(java.util.Collections.emptyMap) HashMap(java.util.HashMap) Map(java.util.Map) HealthResponse(org.opensearch.client.opensearch.cluster.HealthResponse)

Aggregations

OpenSearchClient (org.opensearch.client.opensearch.OpenSearchClient)4 HealthRequest (org.opensearch.client.opensearch.cluster.HealthRequest)4 HealthResponse (org.opensearch.client.opensearch.cluster.HealthResponse)4 Collections.emptyMap (java.util.Collections.emptyMap)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 IndexHealthStats (org.opensearch.client.opensearch.cluster.health.IndexHealthStats)3 ResponseException (org.opensearch.client.ResponseException)2 IOException (java.io.IOException)1 Matchers.notNullValue (org.hamcrest.Matchers.notNullValue)1 Matchers.nullValue (org.hamcrest.Matchers.nullValue)1 JsonData (org.opensearch.client.json.JsonData)1 HealthStatus (org.opensearch.client.opensearch._types.HealthStatus)1 Level (org.opensearch.client.opensearch._types.Level)1 OpenSearchException (org.opensearch.client.opensearch._types.OpenSearchException)1 GetClusterSettingsRequest (org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest)1 GetClusterSettingsResponse (org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse)1 PutClusterSettingsRequest (org.opensearch.client.opensearch.cluster.PutClusterSettingsRequest)1 PutClusterSettingsResponse (org.opensearch.client.opensearch.cluster.PutClusterSettingsResponse)1 ShardHealthStats (org.opensearch.client.opensearch.cluster.health.ShardHealthStats)1