Search in sources :

Example 1 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class GatewayIndexStateIT method testTwoNodesSingleDoc.

public void testTwoNodesSingleDoc() throws Exception {
    logger.info("--> cleaning nodes");
    logger.info("--> starting 2 nodes");
    internalCluster().startNodes(2);
    logger.info("--> indexing a simple document");
    client().prepareIndex("test").setId("1").setSource("field1", "value1").setRefreshPolicy(IMMEDIATE).get();
    logger.info("--> waiting for green status");
    ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    logger.info("--> verify 1 doc in the index");
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
    }
    logger.info("--> closing test index...");
    assertAcked(client().admin().indices().prepareClose("test"));
    ClusterStateResponse stateResponse = client().admin().cluster().prepareState().execute().actionGet();
    assertThat(stateResponse.getState().metadata().index("test").getState(), equalTo(IndexMetadata.State.CLOSE));
    assertThat(stateResponse.getState().routingTable().index("test"), notNullValue());
    logger.info("--> opening the index...");
    client().admin().indices().prepareOpen("test").execute().actionGet();
    logger.info("--> waiting for green status");
    health = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().setWaitForNodes("2").execute().actionGet();
    assertThat(health.isTimedOut(), equalTo(false));
    logger.info("--> verify 1 doc in the index");
    assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
    for (int i = 0; i < 10; i++) {
        assertHitCount(client().prepareSearch().setQuery(matchAllQuery()).get(), 1L);
    }
}
Also used : ClusterHealthResponse(org.opensearch.action.admin.cluster.health.ClusterHealthResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse)

Example 2 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testIndexTemplates.

public void testIndexTemplates() throws Exception {
    client().admin().indices().preparePutTemplate("foo_template").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).get();
    client().admin().indices().preparePutTemplate("fuu_template").setPatterns(Collections.singletonList("test*")).setOrder(1).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field2").field("type", "text").field("store", false).endObject().endObject().endObject().endObject()).get();
    ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().get();
    assertThat(clusterStateResponseUnfiltered.getState().metadata().templates().size(), is(greaterThanOrEqualTo(2)));
    GetIndexTemplatesResponse getIndexTemplatesResponse = client().admin().indices().prepareGetTemplates("foo_template").get();
    assertIndexTemplateExists(getIndexTemplatesResponse, "foo_template");
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) GetIndexTemplatesResponse(org.opensearch.action.admin.indices.template.get.GetIndexTemplatesResponse)

Example 3 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testNodes.

public void testNodes() throws Exception {
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().setNodes(true).get();
    assertThat(clusterStateResponse.getState().nodes().getNodes().size(), is(cluster().size()));
    ClusterStateResponse clusterStateResponseFiltered = client().admin().cluster().prepareState().clear().get();
    assertThat(clusterStateResponseFiltered.getState().nodes().getNodes().size(), is(0));
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse)

Example 4 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testFilteringByIndexWorks.

/**
 * Retrieves the cluster state for the given indices and then checks
 * that the cluster state returns coherent data for both routing table and metadata.
 */
private void testFilteringByIndexWorks(String[] indices, String[] expected) {
    ClusterStateResponse clusterState = client().admin().cluster().prepareState().clear().setMetadata(true).setRoutingTable(true).setIndices(indices).get();
    ImmutableOpenMap<String, IndexMetadata> metadata = clusterState.getState().getMetadata().indices();
    assertThat(metadata.size(), is(expected.length));
    RoutingTable routingTable = clusterState.getState().getRoutingTable();
    assertThat(routingTable.indicesRouting().size(), is(expected.length));
    for (String expectedIndex : expected) {
        assertThat(metadata, CollectionAssertions.hasKey(expectedIndex));
        assertThat(routingTable.hasIndex(expectedIndex), is(true));
    }
}
Also used : RoutingTable(org.opensearch.cluster.routing.RoutingTable) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) IndexMetadata(org.opensearch.cluster.metadata.IndexMetadata)

Example 5 with ClusterStateResponse

use of org.opensearch.action.admin.cluster.state.ClusterStateResponse in project OpenSearch by opensearch-project.

the class SimpleClusterStateIT method testRoutingTable.

public void testRoutingTable() throws Exception {
    ClusterStateResponse clusterStateResponseUnfiltered = client().admin().cluster().prepareState().clear().setRoutingTable(true).get();
    assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("foo"), is(true));
    assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("fuu"), is(true));
    assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("baz"), is(true));
    assertThat(clusterStateResponseUnfiltered.getState().routingTable().hasIndex("non-existent"), is(false));
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().get();
    assertThat(clusterStateResponse.getState().routingTable().hasIndex("foo"), is(false));
    assertThat(clusterStateResponse.getState().routingTable().hasIndex("fuu"), is(false));
    assertThat(clusterStateResponse.getState().routingTable().hasIndex("baz"), is(false));
    assertThat(clusterStateResponse.getState().routingTable().hasIndex("non-existent"), is(false));
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse)

Aggregations

ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)56 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)19 Settings (org.opensearch.common.settings.Settings)19 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)18 List (java.util.List)16 NodeClient (org.opensearch.client.node.NodeClient)13 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)13 RestRequest (org.opensearch.rest.RestRequest)12 GET (org.opensearch.rest.RestRequest.Method.GET)12 RestResponse (org.opensearch.rest.RestResponse)12 Table (org.opensearch.common.Table)11 ClusterState (org.opensearch.cluster.ClusterState)10 RestResponseListener (org.opensearch.rest.action.RestResponseListener)10 MockTransportService (org.opensearch.test.transport.MockTransportService)9 SearchResponse (org.opensearch.action.search.SearchResponse)8 ShardRouting (org.opensearch.cluster.routing.ShardRouting)8 Strings (org.opensearch.common.Strings)8 Arrays.asList (java.util.Arrays.asList)7 Collections.unmodifiableList (java.util.Collections.unmodifiableList)7 ClusterHealthResponse (org.opensearch.action.admin.cluster.health.ClusterHealthResponse)7