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