From 861b4acbb33195450972b0cc81cf55682c2d213b Mon Sep 17 00:00:00 2001 From: Gaurav Chandani Date: Mon, 19 Feb 2024 13:41:38 +0530 Subject: [PATCH 1/3] Changes for introducing write_only_allow_delete block Signed-off-by: Gaurav Chandani --- .../put/TransportUpdateSettingsAction.java | 3 ++- .../opensearch/cluster/block/ClusterBlocks.java | 3 +++ .../opensearch/cluster/metadata/IndexMetadata.java | 14 +++++++++++++- .../common/settings/IndexScopedSettings.java | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java b/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java index 9265c6ae60678..f2203d5dce6bb 100644 --- a/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java +++ b/server/src/main/java/org/opensearch/action/admin/indices/settings/put/TransportUpdateSettingsAction.java @@ -123,7 +123,8 @@ protected ClusterBlockException checkBlock(UpdateSettingsRequest request, Cluste if (request.settings().size() == 1 && // we have to allow resetting these settings otherwise users can't unblock an index IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.exists(request.settings()) || IndexMetadata.INDEX_READ_ONLY_SETTING.exists(request.settings()) - || IndexMetadata.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.settings())) { + || IndexMetadata.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING.exists(request.settings()) + || IndexMetadata.INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING.exists(request.settings())) { return null; } diff --git a/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java b/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java index 304136166d515..023ee24f719c6 100644 --- a/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java +++ b/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java @@ -402,6 +402,9 @@ public Builder addBlocks(IndexMetadata indexMetadata) { if (IndexModule.Type.REMOTE_SNAPSHOT.match(indexMetadata.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()))) { addIndexBlock(indexName, IndexMetadata.REMOTE_READ_ONLY_ALLOW_DELETE); } + if(IndexMetadata.INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING.get(indexMetadata.getSettings())) { + addIndexBlock(indexName, IndexMetadata.INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK); + } return this; } diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java index 03784df509ed6..e9f578f7e0585 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -158,6 +158,16 @@ public class IndexMetadata implements Diffable, ToXContentFragmen EnumSet.of(ClusterBlockLevel.METADATA_WRITE, ClusterBlockLevel.WRITE) ); + public static final ClusterBlock INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK = new ClusterBlock( + 14, + "Index cannot be written. Only reads and deletes allowed", + false, + false, + true, + RestStatus.FORBIDDEN, + EnumSet.of(ClusterBlockLevel.METADATA_WRITE, ClusterBlockLevel.WRITE) + ); + /** * The state of the index. * @@ -461,7 +471,8 @@ public enum APIBlock implements Writeable { READ("read", INDEX_READ_BLOCK), WRITE("write", INDEX_WRITE_BLOCK), METADATA("metadata", INDEX_METADATA_BLOCK), - READ_ONLY_ALLOW_DELETE("read_only_allow_delete", INDEX_READ_ONLY_ALLOW_DELETE_BLOCK); + READ_ONLY_ALLOW_DELETE("read_only_allow_delete", INDEX_READ_ONLY_ALLOW_DELETE_BLOCK), + WRITE_ONLY_ALLOW_DELETE("write_only_allow_delete", INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK); final String name; final String settingName; @@ -529,6 +540,7 @@ public static APIBlock readFrom(StreamInput input) throws IOException { public static final String SETTING_READ_ONLY_ALLOW_DELETE = APIBlock.READ_ONLY_ALLOW_DELETE.settingName(); public static final Setting INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING = APIBlock.READ_ONLY_ALLOW_DELETE.setting(); + public static final Setting INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING = APIBlock.WRITE_ONLY_ALLOW_DELETE.setting(); public static final String SETTING_VERSION_CREATED = "index.version.created"; diff --git a/server/src/main/java/org/opensearch/common/settings/IndexScopedSettings.java b/server/src/main/java/org/opensearch/common/settings/IndexScopedSettings.java index 97d6a0ddf02c8..d3105326e2335 100644 --- a/server/src/main/java/org/opensearch/common/settings/IndexScopedSettings.java +++ b/server/src/main/java/org/opensearch/common/settings/IndexScopedSettings.java @@ -102,6 +102,7 @@ public final class IndexScopedSettings extends AbstractScopedSettings { IndexMetadata.INDEX_BLOCKS_WRITE_SETTING, IndexMetadata.INDEX_BLOCKS_METADATA_SETTING, IndexMetadata.INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING, + IndexMetadata.INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING, IndexMetadata.INDEX_PRIORITY_SETTING, IndexMetadata.INDEX_DATA_PATH_SETTING, IndexMetadata.INDEX_FORMAT_SETTING, From 1cf47e09924935ade745d95b93543fc295687c44 Mon Sep 17 00:00:00 2001 From: Gaurav Chandani Date: Tue, 20 Feb 2024 13:27:58 +0530 Subject: [PATCH 2/3] Added tests Signed-off-by: Gaurav Chandani --- .../cluster/tasks/PendingTasksBlocksIT.java | 4 +- .../clear/ClearIndicesCacheBlocksIT.java | 7 +- .../indices/delete/DeleteIndexBlocksIT.java | 67 +++++++++++-------- .../admin/indices/flush/FlushBlocksIT.java | 4 +- .../forcemerge/ForceMergeBlocksIT.java | 3 +- .../action/admin/indices/get/GetIndexIT.java | 3 +- .../indices/refresh/RefreshBlocksIT.java | 4 +- .../segments/IndicesSegmentsBlocksIT.java | 4 +- .../indices/stats/IndicesStatsBlocksIT.java | 4 +- .../org/opensearch/blocks/SimpleBlocksIT.java | 40 ++++++++++- .../cluster/allocation/ClusterRerouteIT.java | 4 +- .../cluster/shards/ClusterSearchShardsIT.java | 4 +- .../exists/indices/IndicesExistsIT.java | 4 +- .../indices/settings/GetSettingsBlocksIT.java | 3 +- .../indices/state/OpenCloseIndexIT.java | 3 +- .../cluster/metadata/IndexMetadata.java | 1 + 16 files changed, 115 insertions(+), 44 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/tasks/PendingTasksBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/tasks/PendingTasksBlocksIT.java index 83aa744a80599..63f24c86c1b3b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/tasks/PendingTasksBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/cluster/tasks/PendingTasksBlocksIT.java @@ -44,6 +44,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; public class PendingTasksBlocksIT extends OpenSearchIntegTestCase { @@ -57,7 +58,8 @@ public void testPendingTasksWithIndexBlocks() { SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/cache/clear/ClearIndicesCacheBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/cache/clear/ClearIndicesCacheBlocksIT.java index 31c1aca53ae4a..7a2161153c159 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/cache/clear/ClearIndicesCacheBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/cache/clear/ClearIndicesCacheBlocksIT.java @@ -43,6 +43,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.equalTo; @@ -60,7 +61,8 @@ public void testClearIndicesCacheWithBlocks() { SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test", blockSetting); @@ -102,7 +104,8 @@ public void testClearIndicesFileCacheWithBlocks() { SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java index 1ab5826329c8f..fe24bcfa4a3f7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java @@ -33,6 +33,7 @@ package org.opensearch.action.admin.indices.delete; import org.opensearch.action.support.IndicesOptions; +import org.opensearch.cluster.block.ClusterBlock; import org.opensearch.cluster.block.ClusterBlockException; import org.opensearch.cluster.metadata.IndexMetadata; import org.opensearch.cluster.metadata.Metadata; @@ -56,35 +57,7 @@ public void testDeleteIndexWithBlocks() { } public void testDeleteIndexOnIndexReadOnlyAllowDeleteSetting() { - createIndex("test"); - ensureGreen("test"); - client().prepareIndex().setIndex("test").setId("1").setSource("foo", "bar").get(); - refresh(); - try { - Settings settings = Settings.builder().put(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, true).build(); - assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settings).get()); - assertSearchHits(client().prepareSearch().get(), "1"); - assertBlocked( - client().prepareIndex().setIndex("test").setId("2").setSource("foo", "bar"), - IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK - ); - assertBlocked( - client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.number_of_replicas", 2)), - IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK - ); - assertSearchHits(client().prepareSearch().get(), "1"); - assertAcked(client().admin().indices().prepareDelete("test")); - } finally { - Settings settings = Settings.builder().putNull(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE).build(); - assertAcked( - client().admin() - .indices() - .prepareUpdateSettings("test") - .setIndicesOptions(IndicesOptions.lenientExpandOpen()) - .setSettings(settings) - .get() - ); - } + assertDeleteIndexOnAllowDeleteSetting(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK); } public void testClusterBlockMessageHasIndexName() { @@ -137,4 +110,40 @@ public void testDeleteIndexOnClusterReadOnlyAllowDeleteSetting() { assertAcked(client().admin().cluster().prepareUpdateSettings().setTransientSettings(settings).get()); } } + + public void testDeleteIndexOnIndexWriteOnlyAllowDeleteSetting() { + assertDeleteIndexOnAllowDeleteSetting(IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE, IndexMetadata.INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK); + } + + private void assertDeleteIndexOnAllowDeleteSetting(String settingName, ClusterBlock blockToAssert){ + createIndex("test"); + ensureGreen("test"); + client().prepareIndex().setIndex("test").setId("1").setSource("foo", "bar").get(); + refresh(); + try { + Settings settings = Settings.builder().put(settingName, true).build(); + assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settings).get()); + assertSearchHits(client().prepareSearch().get(), "1"); + assertBlocked( + client().prepareIndex().setIndex("test").setId("2").setSource("foo", "bar"), + blockToAssert + ); + assertBlocked( + client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.number_of_replicas", 2)), + blockToAssert + ); + assertSearchHits(client().prepareSearch().get(), "1"); + assertAcked(client().admin().indices().prepareDelete("test")); + } finally { + Settings settings = Settings.builder().putNull(settingName).build(); + assertAcked( + client().admin() + .indices() + .prepareUpdateSettings("test") + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) + .setSettings(settings) + .get() + ); + } + } } diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/flush/FlushBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/flush/FlushBlocksIT.java index f780f505a6557..816ba6b3d450b 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/flush/FlushBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/flush/FlushBlocksIT.java @@ -42,6 +42,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.equalTo; @@ -64,7 +65,8 @@ public void testFlushWithBlocks() { SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java index b279623c46969..a407bfa6969b3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java @@ -42,6 +42,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.equalTo; @@ -73,7 +74,7 @@ public void testForceMergeWithBlocks() { } // Request is blocked - for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, SETTING_READ_ONLY_ALLOW_DELETE)) { + for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_WRITE_ONLY_ALLOW_DELETE)) { try { enableIndexBlock("test", blockSetting); assertBlocked(client().admin().indices().prepareForceMerge("test")); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java index ac92c389e9a71..8b3948cc84f89 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java @@ -52,6 +52,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; import static org.hamcrest.Matchers.equalTo; @@ -213,7 +214,7 @@ public void testEmptyMixedFeatures() { } public void testGetIndexWithBlocks() { - for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE)) { + for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_WRITE_ONLY_ALLOW_DELETE)) { try { enableIndexBlock("idx", block); GetIndexResponse response = client().admin() diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/refresh/RefreshBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/refresh/RefreshBlocksIT.java index a5d7ea24fddc9..2e154e20537e3 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/refresh/RefreshBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/refresh/RefreshBlocksIT.java @@ -42,6 +42,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures; import static org.hamcrest.Matchers.equalTo; @@ -59,7 +60,8 @@ public void testRefreshWithBlocks() { SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/segments/IndicesSegmentsBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/segments/IndicesSegmentsBlocksIT.java index df885848d82ce..c8c33b63a3709 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/segments/IndicesSegmentsBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/segments/IndicesSegmentsBlocksIT.java @@ -42,6 +42,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertNoFailures; @@ -62,7 +63,8 @@ public void testIndicesSegmentsWithBlocks() { SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test-blocks", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/stats/IndicesStatsBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/stats/IndicesStatsBlocksIT.java index 69f0d5b97c05b..516f0b704d929 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/stats/IndicesStatsBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/stats/IndicesStatsBlocksIT.java @@ -43,6 +43,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; @ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST) public class IndicesStatsBlocksIT extends OpenSearchIntegTestCase { @@ -56,7 +57,8 @@ public void testIndicesStatsWithBlocks() { SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("ro", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java index 6275571cc2371..dff45a44c2a86 100644 --- a/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java @@ -68,6 +68,7 @@ import static org.opensearch.action.support.IndicesOptions.lenientExpandOpen; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.search.internal.SearchContext.TRACK_TOTAL_HITS_ACCURATE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; @@ -201,6 +202,16 @@ private void setIndexReadOnly(String index, Object value) { assertThat(settingsResponse, notNullValue()); } + private void setIndexWriteOnlyDeleteAllow(String index, Object value) { + HashMap newSettings = new HashMap<>(); + newSettings.put(SETTING_WRITE_ONLY_ALLOW_DELETE, value); + + UpdateSettingsRequestBuilder settingsRequest = client().admin().indices().prepareUpdateSettings(index); + settingsRequest.setSettings(newSettings); + AcknowledgedResponse settingsResponse = settingsRequest.execute().actionGet(); + assertThat(settingsResponse, notNullValue()); + } + public void testAddBlocksWhileExistingBlocks() { createIndex("test"); ensureGreen("test"); @@ -223,7 +234,7 @@ public void testAddBlocksWhileExistingBlocks() { } } - for (APIBlock block : Arrays.asList(APIBlock.READ_ONLY, APIBlock.METADATA, APIBlock.READ_ONLY_ALLOW_DELETE)) { + for (APIBlock block : Arrays.asList(APIBlock.READ_ONLY, APIBlock.METADATA, APIBlock.READ_ONLY_ALLOW_DELETE, APIBlock.WRITE_ONLY_ALLOW_DELETE)) { boolean success = false; try { enableIndexBlock("test", block.settingName()); @@ -542,6 +553,33 @@ public void testAddBlockWhileDeletingIndices() throws Exception { } } + public void testVerifyIndexWriteOnlyAllowDelete() { + // newly created an index has no plocks + canCreateIndex("test1"); + canIndexDocument("test1"); + canIndexExists("test1"); + + // adds index write-only-allow-delete block + setIndexWriteOnlyDeleteAllow("test1", "true"); + assertIndexHasBlock(APIBlock.WRITE_ONLY_ALLOW_DELETE, "test1"); + canNotIndexDocument("test1"); + canIndexExists("test1"); + + // other indices not blocked + canCreateIndex("test2"); + canIndexDocument("test2"); + canIndexExists("test2"); + + // assert index can be deleted + assertAcked(client().admin().indices().prepareDelete("test1")); + + // assert block can be removed + setIndexWriteOnlyDeleteAllow("test2", "true"); + assertIndexHasBlock(APIBlock.WRITE_ONLY_ALLOW_DELETE, "test2"); + setIndexWriteOnlyDeleteAllow("test2", "false"); + canIndexDocument("test2"); + } + static void assertIndexHasBlock(APIBlock block, final String... indices) { final ClusterState clusterState = client().admin().cluster().prepareState().get().getState(); for (String index : indices) { diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java index dbcb030d8a4f7..5eba803e27c16 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/allocation/ClusterRerouteIT.java @@ -80,6 +80,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.cluster.routing.allocation.decider.EnableAllocationDecider.CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; @@ -557,7 +558,8 @@ public void testClusterRerouteWithBlocks() { SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test-blocks", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/shards/ClusterSearchShardsIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/shards/ClusterSearchShardsIT.java index 86e83e01b008c..13678468e39ed 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/shards/ClusterSearchShardsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/shards/ClusterSearchShardsIT.java @@ -47,6 +47,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; import static org.hamcrest.Matchers.equalTo; @@ -182,7 +183,8 @@ public void testClusterSearchShardsWithBlocks() { SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("test-blocks", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/exists/indices/IndicesExistsIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/exists/indices/IndicesExistsIT.java index 5c3db0a4110f3..3bcd58ab74ff4 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/exists/indices/IndicesExistsIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/exists/indices/IndicesExistsIT.java @@ -44,6 +44,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.hamcrest.Matchers.equalTo; @@ -88,7 +89,8 @@ public void testIndicesExistsWithBlocks() { SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, - SETTING_READ_ONLY_ALLOW_DELETE + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE )) { try { enableIndexBlock("ro", blockSetting); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java index 4011a6918868e..f4d4cfa279a40 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java @@ -44,6 +44,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertBlocked; import static org.hamcrest.Matchers.equalTo; @@ -60,7 +61,7 @@ public void testGetSettingsWithBlocks() throws Exception { ) ); - for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE)) { + for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_WRITE_ONLY_ALLOW_DELETE)) { try { enableIndexBlock("test", block); GetSettingsResponse response = client().admin().indices().prepareGetSettings("test").get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java index 0bf561c606a2d..4d5ea24b87597 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java @@ -60,6 +60,7 @@ import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY; import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE; +import static org.opensearch.cluster.metadata.IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE; import static org.opensearch.indices.state.CloseIndexIT.assertIndexIsClosed; import static org.opensearch.indices.state.CloseIndexIT.assertIndexIsOpened; import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked; @@ -375,7 +376,7 @@ public void testOpenCloseIndexWithBlocks() { assertIndexIsClosed("test"); // Opening an index is blocked - for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_BLOCKS_METADATA)) { + for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_BLOCKS_METADATA, SETTING_WRITE_ONLY_ALLOW_DELETE)) { try { enableIndexBlock("test", blockSetting); assertBlocked(client().admin().indices().prepareOpen("test")); diff --git a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java index e9f578f7e0585..46fd9be5b868e 100644 --- a/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/opensearch/cluster/metadata/IndexMetadata.java @@ -541,6 +541,7 @@ public static APIBlock readFrom(StreamInput input) throws IOException { public static final String SETTING_READ_ONLY_ALLOW_DELETE = APIBlock.READ_ONLY_ALLOW_DELETE.settingName(); public static final Setting INDEX_BLOCKS_READ_ONLY_ALLOW_DELETE_SETTING = APIBlock.READ_ONLY_ALLOW_DELETE.setting(); public static final Setting INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING = APIBlock.WRITE_ONLY_ALLOW_DELETE.setting(); + public static final String SETTING_WRITE_ONLY_ALLOW_DELETE = APIBlock.WRITE_ONLY_ALLOW_DELETE.settingName(); public static final String SETTING_VERSION_CREATED = "index.version.created"; From 987dfa9ba6849d680d4561aa57e5bcfb0d22a9bf Mon Sep 17 00:00:00 2001 From: Gaurav Chandani Date: Tue, 20 Feb 2024 13:33:58 +0530 Subject: [PATCH 3/3] Applied spotless checks Signed-off-by: Gaurav Chandani --- .../indices/delete/DeleteIndexBlocksIT.java | 17 ++++++++++------- .../indices/forcemerge/ForceMergeBlocksIT.java | 7 ++++++- .../action/admin/indices/get/GetIndexIT.java | 8 +++++++- .../org/opensearch/blocks/SimpleBlocksIT.java | 7 ++++++- .../indices/settings/GetSettingsBlocksIT.java | 8 +++++++- .../indices/state/OpenCloseIndexIT.java | 7 ++++++- .../opensearch/cluster/block/ClusterBlocks.java | 2 +- 7 files changed, 43 insertions(+), 13 deletions(-) diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java index fe24bcfa4a3f7..ec6e9f57b58a8 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/delete/DeleteIndexBlocksIT.java @@ -57,7 +57,10 @@ public void testDeleteIndexWithBlocks() { } public void testDeleteIndexOnIndexReadOnlyAllowDeleteSetting() { - assertDeleteIndexOnAllowDeleteSetting(IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK); + assertDeleteIndexOnAllowDeleteSetting( + IndexMetadata.SETTING_READ_ONLY_ALLOW_DELETE, + IndexMetadata.INDEX_READ_ONLY_ALLOW_DELETE_BLOCK + ); } public void testClusterBlockMessageHasIndexName() { @@ -112,10 +115,13 @@ public void testDeleteIndexOnClusterReadOnlyAllowDeleteSetting() { } public void testDeleteIndexOnIndexWriteOnlyAllowDeleteSetting() { - assertDeleteIndexOnAllowDeleteSetting(IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE, IndexMetadata.INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK); + assertDeleteIndexOnAllowDeleteSetting( + IndexMetadata.SETTING_WRITE_ONLY_ALLOW_DELETE, + IndexMetadata.INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK + ); } - private void assertDeleteIndexOnAllowDeleteSetting(String settingName, ClusterBlock blockToAssert){ + private void assertDeleteIndexOnAllowDeleteSetting(String settingName, ClusterBlock blockToAssert) { createIndex("test"); ensureGreen("test"); client().prepareIndex().setIndex("test").setId("1").setSource("foo", "bar").get(); @@ -124,10 +130,7 @@ private void assertDeleteIndexOnAllowDeleteSetting(String settingName, ClusterB Settings settings = Settings.builder().put(settingName, true).build(); assertAcked(client().admin().indices().prepareUpdateSettings("test").setSettings(settings).get()); assertSearchHits(client().prepareSearch().get(), "1"); - assertBlocked( - client().prepareIndex().setIndex("test").setId("2").setSource("foo", "bar"), - blockToAssert - ); + assertBlocked(client().prepareIndex().setIndex("test").setId("2").setSource("foo", "bar"), blockToAssert); assertBlocked( client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put("index.number_of_replicas", 2)), blockToAssert diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java index a407bfa6969b3..26e607fa4c9fa 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/forcemerge/ForceMergeBlocksIT.java @@ -74,7 +74,12 @@ public void testForceMergeWithBlocks() { } // Request is blocked - for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_BLOCKS_METADATA, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_WRITE_ONLY_ALLOW_DELETE)) { + for (String blockSetting : Arrays.asList( + SETTING_READ_ONLY, + SETTING_BLOCKS_METADATA, + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE + )) { try { enableIndexBlock("test", blockSetting); assertBlocked(client().admin().indices().prepareForceMerge("test")); diff --git a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java index 8b3948cc84f89..3b8452e147477 100644 --- a/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/action/admin/indices/get/GetIndexIT.java @@ -214,7 +214,13 @@ public void testEmptyMixedFeatures() { } public void testGetIndexWithBlocks() { - for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_WRITE_ONLY_ALLOW_DELETE)) { + for (String block : Arrays.asList( + SETTING_BLOCKS_READ, + SETTING_BLOCKS_WRITE, + SETTING_READ_ONLY, + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE + )) { try { enableIndexBlock("idx", block); GetIndexResponse response = client().admin() diff --git a/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java index dff45a44c2a86..b231a5be36406 100644 --- a/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/blocks/SimpleBlocksIT.java @@ -234,7 +234,12 @@ public void testAddBlocksWhileExistingBlocks() { } } - for (APIBlock block : Arrays.asList(APIBlock.READ_ONLY, APIBlock.METADATA, APIBlock.READ_ONLY_ALLOW_DELETE, APIBlock.WRITE_ONLY_ALLOW_DELETE)) { + for (APIBlock block : Arrays.asList( + APIBlock.READ_ONLY, + APIBlock.METADATA, + APIBlock.READ_ONLY_ALLOW_DELETE, + APIBlock.WRITE_ONLY_ALLOW_DELETE + )) { boolean success = false; try { enableIndexBlock("test", block.settingName()); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java index f4d4cfa279a40..5b893de4331b1 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/settings/GetSettingsBlocksIT.java @@ -61,7 +61,13 @@ public void testGetSettingsWithBlocks() throws Exception { ) ); - for (String block : Arrays.asList(SETTING_BLOCKS_READ, SETTING_BLOCKS_WRITE, SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_WRITE_ONLY_ALLOW_DELETE)) { + for (String block : Arrays.asList( + SETTING_BLOCKS_READ, + SETTING_BLOCKS_WRITE, + SETTING_READ_ONLY, + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_WRITE_ONLY_ALLOW_DELETE + )) { try { enableIndexBlock("test", block); GetSettingsResponse response = client().admin().indices().prepareGetSettings("test").get(); diff --git a/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java b/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java index 4d5ea24b87597..61eb6f96b5ad7 100644 --- a/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/indices/state/OpenCloseIndexIT.java @@ -376,7 +376,12 @@ public void testOpenCloseIndexWithBlocks() { assertIndexIsClosed("test"); // Opening an index is blocked - for (String blockSetting : Arrays.asList(SETTING_READ_ONLY, SETTING_READ_ONLY_ALLOW_DELETE, SETTING_BLOCKS_METADATA, SETTING_WRITE_ONLY_ALLOW_DELETE)) { + for (String blockSetting : Arrays.asList( + SETTING_READ_ONLY, + SETTING_READ_ONLY_ALLOW_DELETE, + SETTING_BLOCKS_METADATA, + SETTING_WRITE_ONLY_ALLOW_DELETE + )) { try { enableIndexBlock("test", blockSetting); assertBlocked(client().admin().indices().prepareOpen("test")); diff --git a/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java b/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java index 023ee24f719c6..ab9a1de2627ad 100644 --- a/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java +++ b/server/src/main/java/org/opensearch/cluster/block/ClusterBlocks.java @@ -402,7 +402,7 @@ public Builder addBlocks(IndexMetadata indexMetadata) { if (IndexModule.Type.REMOTE_SNAPSHOT.match(indexMetadata.getSettings().get(IndexModule.INDEX_STORE_TYPE_SETTING.getKey()))) { addIndexBlock(indexName, IndexMetadata.REMOTE_READ_ONLY_ALLOW_DELETE); } - if(IndexMetadata.INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING.get(indexMetadata.getSettings())) { + if (IndexMetadata.INDEX_BLOCKS_WRITE_ONLY_ALLOW_DELETE_SETTING.get(indexMetadata.getSettings())) { addIndexBlock(indexName, IndexMetadata.INDEX_WRITE_ONLY_ALLOW_DELETE_BLOCK); } return this;