use of org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY in project OpenSearch by opensearch-project.
the class MetadataCreateIndexServiceTests method testClusterStateCreateIndex.
public void testClusterStateCreateIndex() {
ClusterState currentClusterState = ClusterState.builder(ClusterState.EMPTY_STATE).build();
IndexMetadata newIndexMetadata = IndexMetadata.builder("test").settings(settings(Version.CURRENT).put(SETTING_READ_ONLY, true)).numberOfShards(1).numberOfReplicas(0).putAlias(AliasMetadata.builder("alias1").writeIndex(true).build()).build();
// used as a value container, not for the concurrency and visibility guarantees
AtomicBoolean allocationRerouted = new AtomicBoolean(false);
BiFunction<ClusterState, String, ClusterState> rerouteRoutingTable = (clusterState, reason) -> {
allocationRerouted.compareAndSet(false, true);
return clusterState;
};
ClusterState updatedClusterState = clusterStateCreateIndex(currentClusterState, org.opensearch.common.collect.Set.of(INDEX_READ_ONLY_BLOCK), newIndexMetadata, rerouteRoutingTable, null);
assertThat(updatedClusterState.blocks().getIndexBlockWithId("test", INDEX_READ_ONLY_BLOCK.id()), is(INDEX_READ_ONLY_BLOCK));
assertThat(updatedClusterState.routingTable().index("test"), is(notNullValue()));
assertThat(allocationRerouted.get(), is(true));
}
use of org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY in project OpenSearch by opensearch-project.
the class MetadataCreateIndexServiceTests method testClusterStateCreateIndexWithMetadataTransaction.
public void testClusterStateCreateIndexWithMetadataTransaction() {
ClusterState currentClusterState = ClusterState.builder(ClusterState.EMPTY_STATE).metadata(Metadata.builder().put(IndexMetadata.builder("my-index").settings(settings(Version.CURRENT).put(SETTING_READ_ONLY, true)).numberOfShards(1).numberOfReplicas(0))).build();
IndexMetadata newIndexMetadata = IndexMetadata.builder("test").settings(settings(Version.CURRENT).put(SETTING_READ_ONLY, true)).numberOfShards(1).numberOfReplicas(0).putAlias(AliasMetadata.builder("alias1").writeIndex(true).build()).build();
// adds alias from new index to existing index
BiConsumer<Metadata.Builder, IndexMetadata> metadataTransformer = (builder, indexMetadata) -> {
AliasMetadata newAlias = indexMetadata.getAliases().iterator().next().value;
IndexMetadata myIndex = builder.get("my-index");
builder.put(IndexMetadata.builder(myIndex).putAlias(AliasMetadata.builder(newAlias.getAlias()).build()));
};
ClusterState updatedClusterState = clusterStateCreateIndex(currentClusterState, org.opensearch.common.collect.Set.of(INDEX_READ_ONLY_BLOCK), newIndexMetadata, (clusterState, y) -> clusterState, metadataTransformer);
assertTrue(updatedClusterState.metadata().findAllAliases(new String[] { "my-index" }).containsKey("my-index"));
assertNotNull(updatedClusterState.metadata().findAllAliases(new String[] { "my-index" }).get("my-index"));
assertNotNull(updatedClusterState.metadata().findAllAliases(new String[] { "my-index" }).get("my-index").get(0).alias(), equalTo("alias1"));
}
Aggregations