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);
}
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);
}
}
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);
}
}
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);
}
Aggregations