Search in sources :

Example 41 with ClusterStateResponse

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

the class NoClusterManagerNodeIT method testNoClusterManagerActionsWriteClusterManagerBlock.

public void testNoClusterManagerActionsWriteClusterManagerBlock() throws Exception {
    Settings settings = Settings.builder().put(AutoCreateIndex.AUTO_CREATE_INDEX_SETTING.getKey(), false).put(NoMasterBlockService.NO_CLUSTER_MANAGER_BLOCK_SETTING.getKey(), "write").build();
    final List<String> nodes = internalCluster().startNodes(3, settings);
    prepareCreate("test1").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 2)).get();
    prepareCreate("test2").setSettings(Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 3).put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)).get();
    client().admin().cluster().prepareHealth("_all").setWaitForGreenStatus().get();
    client().prepareIndex("test1").setId("1").setSource("field", "value1").get();
    client().prepareIndex("test2").setId("1").setSource("field", "value1").get();
    refresh();
    ensureSearchable("test1", "test2");
    ClusterStateResponse clusterState = client().admin().cluster().prepareState().get();
    logger.info("Cluster state:\n{}", clusterState.getState());
    final NetworkDisruption disruptionScheme = new NetworkDisruption(new IsolateAllNodes(new HashSet<>(nodes)), NetworkDisruption.DISCONNECT);
    internalCluster().setDisruptionScheme(disruptionScheme);
    disruptionScheme.startDisrupting();
    final Client clientToClusterManagerlessNode = client();
    assertBusy(() -> {
        ClusterState state = clientToClusterManagerlessNode.admin().cluster().prepareState().setLocal(true).get().getState();
        assertTrue(state.blocks().hasGlobalBlockWithId(NoMasterBlockService.NO_MASTER_BLOCK_ID));
    });
    GetResponse getResponse = clientToClusterManagerlessNode.prepareGet("test1", "1").get();
    assertExists(getResponse);
    SearchResponse countResponse = clientToClusterManagerlessNode.prepareSearch("test1").setAllowPartialSearchResults(true).setSize(0).get();
    assertHitCount(countResponse, 1L);
    logger.info("--> here 3");
    SearchResponse searchResponse = clientToClusterManagerlessNode.prepareSearch("test1").setAllowPartialSearchResults(true).get();
    assertHitCount(searchResponse, 1L);
    countResponse = clientToClusterManagerlessNode.prepareSearch("test2").setAllowPartialSearchResults(true).setSize(0).get();
    assertThat(countResponse.getTotalShards(), equalTo(3));
    assertThat(countResponse.getSuccessfulShards(), equalTo(1));
    TimeValue timeout = TimeValue.timeValueMillis(200);
    long now = System.currentTimeMillis();
    try {
        clientToClusterManagerlessNode.prepareUpdate("test1", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "field", "value2").setTimeout(timeout).get();
        fail("Expected ClusterBlockException");
    } catch (ClusterBlockException e) {
        assertThat(System.currentTimeMillis() - now, greaterThan(timeout.millis() - 50));
        assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
    } catch (Exception e) {
        logger.info("unexpected", e);
        throw e;
    }
    try {
        clientToClusterManagerlessNode.prepareIndex("test1").setId("1").setSource(XContentFactory.jsonBuilder().startObject().endObject()).setTimeout(timeout).get();
        fail("Expected ClusterBlockException");
    } catch (ClusterBlockException e) {
        assertThat(e.status(), equalTo(RestStatus.SERVICE_UNAVAILABLE));
    }
    internalCluster().clearDisruptionScheme(true);
}
Also used : IsolateAllNodes(org.opensearch.test.disruption.NetworkDisruption.IsolateAllNodes) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) GetResponse(org.opensearch.action.get.GetResponse) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) MasterNotDiscoveredException(org.opensearch.discovery.MasterNotDiscoveredException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) SearchResponse(org.opensearch.action.search.SearchResponse) NetworkDisruption(org.opensearch.test.disruption.NetworkDisruption) Client(org.opensearch.client.Client) Settings(org.opensearch.common.settings.Settings) TimeValue(org.opensearch.common.unit.TimeValue) HashSet(java.util.HashSet)

Example 42 with ClusterStateResponse

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

the class SimpleClusterStateIT method testIndicesOptions.

public void testIndicesOptions() throws Exception {
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("f*").get();
    assertThat(clusterStateResponse.getState().metadata().indices().size(), is(2));
    ensureGreen("fuu");
    // close one index
    client().admin().indices().close(Requests.closeIndexRequest("fuu")).get();
    clusterStateResponse = client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("f*").get();
    assertThat(clusterStateResponse.getState().metadata().indices().size(), is(1));
    assertThat(clusterStateResponse.getState().metadata().index("foo").getState(), equalTo(IndexMetadata.State.OPEN));
    // expand_wildcards_closed should toggle return only closed index fuu
    IndicesOptions expandCloseOptions = IndicesOptions.fromOptions(false, true, false, true);
    clusterStateResponse = client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("f*").setIndicesOptions(expandCloseOptions).get();
    assertThat(clusterStateResponse.getState().metadata().indices().size(), is(1));
    assertThat(clusterStateResponse.getState().metadata().index("fuu").getState(), equalTo(IndexMetadata.State.CLOSE));
    // ignore_unavailable set to true should not raise exception on fzzbzz
    IndicesOptions ignoreUnavailabe = IndicesOptions.fromOptions(true, true, true, false);
    clusterStateResponse = client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("fzzbzz").setIndicesOptions(ignoreUnavailabe).get();
    assertThat(clusterStateResponse.getState().metadata().indices().isEmpty(), is(true));
    // empty wildcard expansion result should work when allowNoIndices is
    // turned on
    IndicesOptions allowNoIndices = IndicesOptions.fromOptions(false, true, true, false);
    clusterStateResponse = client().admin().cluster().prepareState().clear().setMetadata(true).setIndices("a*").setIndicesOptions(allowNoIndices).get();
    assertThat(clusterStateResponse.getState().metadata().indices().isEmpty(), is(true));
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) IndicesOptions(org.opensearch.action.support.IndicesOptions)

Example 43 with ClusterStateResponse

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

the class SimpleClusterStateIT method testPrivateCustomsAreExcluded.

public void testPrivateCustomsAreExcluded() throws Exception {
    // ensure that the custom is injected into the cluster state
    assertBusy(() -> assertTrue(clusterService().state().customs().containsKey("test")));
    ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().setCustoms(true).get();
    assertFalse(clusterStateResponse.getState().customs().containsKey("test"));
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse)

Example 44 with ClusterStateResponse

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

the class UpgradeSettingsIT method runUpgradeSettingsOnUpdateTest.

private void runUpgradeSettingsOnUpdateTest(final BiConsumer<Settings, ClusterUpdateSettingsRequestBuilder> consumer, final Function<Metadata, Settings> settingsFunction) {
    final String value = randomAlphaOfLength(8);
    final ClusterUpdateSettingsRequestBuilder builder = client().admin().cluster().prepareUpdateSettings();
    consumer.accept(Settings.builder().put("foo.old", value).build(), builder);
    builder.get();
    final ClusterStateResponse response = client().admin().cluster().prepareState().clear().setMetadata(true).get();
    assertFalse(UpgradeSettingsPlugin.oldSetting.exists(settingsFunction.apply(response.getState().metadata())));
    assertTrue(UpgradeSettingsPlugin.newSetting.exists(settingsFunction.apply(response.getState().metadata())));
    assertThat(UpgradeSettingsPlugin.newSetting.get(settingsFunction.apply(response.getState().metadata())), equalTo("new." + value));
}
Also used : ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) ClusterUpdateSettingsRequestBuilder(org.opensearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder)

Example 45 with ClusterStateResponse

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

the class SharedClusterSnapshotRestoreIT method testSnapshotClosedIndex.

public void testSnapshotClosedIndex() throws Exception {
    Client client = client();
    createRepository("test-repo", "fs");
    createIndex("test-idx", "test-idx-closed");
    ensureGreen();
    logger.info("-->  closing index test-idx-closed");
    assertAcked(client.admin().indices().prepareClose("test-idx-closed").setWaitForActiveShards(ActiveShardCount.ALL));
    ClusterStateResponse stateResponse = client.admin().cluster().prepareState().get();
    assertThat(stateResponse.getState().metadata().index("test-idx-closed").getState(), equalTo(IndexMetadata.State.CLOSE));
    assertThat(stateResponse.getState().routingTable().index("test-idx-closed"), notNullValue());
    logger.info("--> snapshot");
    CreateSnapshotResponse createSnapshotResponse = client.admin().cluster().prepareCreateSnapshot("test-repo", "test-snap").setWaitForCompletion(true).setIndices("test-idx*").setIndicesOptions(IndicesOptions.lenientExpand()).get();
    assertThat(createSnapshotResponse.getSnapshotInfo().indices().size(), equalTo(2));
    assertThat(createSnapshotResponse.getSnapshotInfo().shardFailures().size(), equalTo(0));
}
Also used : CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) ClusterStateResponse(org.opensearch.action.admin.cluster.state.ClusterStateResponse) Client(org.opensearch.client.Client)

Aggregations

ClusterStateResponse (org.opensearch.action.admin.cluster.state.ClusterStateResponse)60 Settings (org.opensearch.common.settings.Settings)23 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)20 ClusterStateRequest (org.opensearch.action.admin.cluster.state.ClusterStateRequest)19 List (java.util.List)17 NodeClient (org.opensearch.client.node.NodeClient)13 DiscoveryNodes (org.opensearch.cluster.node.DiscoveryNodes)13 DeprecationLogger (org.opensearch.common.logging.DeprecationLogger)12 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 SearchResponse (org.opensearch.action.search.SearchResponse)10 Client (org.opensearch.client.Client)10 ClusterState (org.opensearch.cluster.ClusterState)10 RestResponseListener (org.opensearch.rest.action.RestResponseListener)10 MockTransportService (org.opensearch.test.transport.MockTransportService)10 HashSet (java.util.HashSet)9 ShardRouting (org.opensearch.cluster.routing.ShardRouting)8 Strings (org.opensearch.common.Strings)8