From 9617ccd554693d808e73ec0c0de9f3d3aefa014d Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Wed, 16 Nov 2022 20:59:04 +0530 Subject: [PATCH 1/7] Update Rest status for DecommissioningFailedException Signed-off-by: Rishab Nahata --- .../decommission/DecommissioningFailedException.java | 6 ++++++ .../cluster/decommission/DecommissionServiceTests.java | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/server/src/main/java/org/opensearch/cluster/decommission/DecommissioningFailedException.java b/server/src/main/java/org/opensearch/cluster/decommission/DecommissioningFailedException.java index fe1b9368ac712..9d1325ccf4912 100644 --- a/server/src/main/java/org/opensearch/cluster/decommission/DecommissioningFailedException.java +++ b/server/src/main/java/org/opensearch/cluster/decommission/DecommissioningFailedException.java @@ -11,6 +11,7 @@ import org.opensearch.OpenSearchException; import org.opensearch.common.io.stream.StreamInput; import org.opensearch.common.io.stream.StreamOutput; +import org.opensearch.rest.RestStatus; import java.io.IOException; @@ -52,4 +53,9 @@ public void writeTo(StreamOutput out) throws IOException { public DecommissionAttribute decommissionAttribute() { return decommissionAttribute; } + + @Override + public RestStatus status() { + return RestStatus.BAD_REQUEST; + } } diff --git a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java index 7fe58d75932a1..56ed8abf0fa83 100644 --- a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java @@ -34,6 +34,7 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; +import org.opensearch.rest.RestStatus; import org.opensearch.test.ClusterServiceUtils; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.transport.MockTransport; @@ -140,6 +141,7 @@ public void onResponse(DecommissionResponse decommissionResponse) { public void onFailure(Exception e) { assertTrue(e instanceof DecommissioningFailedException); assertThat(e.getMessage(), Matchers.endsWith("invalid awareness attribute requested for decommissioning")); + assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -167,6 +169,7 @@ public void onFailure(Exception e) { + "Set forced awareness values before to decommission" ) ); + assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -192,6 +195,7 @@ public void onFailure(Exception e) { e.getMessage(), Matchers.containsString("weight for decommissioned attribute is expected to be [0.0] but found [1.0]") ); + assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -217,6 +221,7 @@ public void onFailure(Exception e) { "no weights are set to the attribute. Please set appropriate weights before triggering decommission action" ) ); + assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -254,6 +259,7 @@ public void onFailure(Exception e) { } else { assertThat(e.getMessage(), Matchers.endsWith("is in progress, cannot process this request")); } + assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; From 2592f88ece3b851b7542015cf436f6a385e11bbe Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 18 Nov 2022 15:28:24 +0530 Subject: [PATCH 2/7] Add tests for decommission response code Signed-off-by: Rishab Nahata --- .../AwarenessAttributeDecommissionRestIT.java | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java new file mode 100644 index 0000000000000..3822eccc2049b --- /dev/null +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java @@ -0,0 +1,101 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +package org.opensearch.http; + +import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingResponse; +import org.opensearch.client.Request; +import org.opensearch.client.Response; +import org.opensearch.client.ResponseException; +import org.opensearch.cluster.node.DiscoveryNodeRole; +import org.opensearch.cluster.routing.WeightedRouting; +import org.opensearch.common.settings.Settings; +import org.opensearch.rest.RestStatus; +import org.opensearch.test.OpenSearchIntegTestCase; + +import java.io.IOException; +import java.util.List; +import java.util.Map; + +import static org.opensearch.test.NodeRoles.onlyRole; + +@OpenSearchIntegTestCase.ClusterScope(scope = OpenSearchIntegTestCase.Scope.TEST, numDataNodes = 0) +public class AwarenessAttributeDecommissionRestIT extends HttpSmokeTestCase{ + + public void testRestStatusForDecommissioningFailedException() { + internalCluster().startNodes(3); + Request request = new Request("PUT", "/_cluster/decommission/awareness/zone/zone-1"); + ResponseException exception = expectThrows( + ResponseException.class, + () -> getRestClient().performRequest(request) + ); + assertEquals(exception.getResponse().getStatusLine().getStatusCode(), RestStatus.BAD_REQUEST.getStatus()); + assertTrue(exception.getMessage().contains("invalid awareness attribute requested for decommissioning")); + } + + public void testRestStatusForAcknowledgedDecommission() throws IOException { + Settings commonSettings = Settings.builder() + .put("cluster.routing.allocation.awareness.attributes", "zone") + .put("cluster.routing.allocation.awareness.force.zone.values", "a,b,c") + .build(); + + logger.info("--> start 3 cluster manager nodes on zones 'a' & 'b' & 'c'"); + List clusterManagerNodes = internalCluster().startNodes( + Settings.builder() + .put(commonSettings) + .put("node.attr.zone", "a") + .put(onlyRole(commonSettings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)) + .build(), + Settings.builder() + .put(commonSettings) + .put("node.attr.zone", "b") + .put(onlyRole(commonSettings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)) + .build(), + Settings.builder() + .put(commonSettings) + .put("node.attr.zone", "c") + .put(onlyRole(commonSettings, DiscoveryNodeRole.CLUSTER_MANAGER_ROLE)) + .build() + ); + + logger.info("--> start 3 data nodes on zones 'a' & 'b' & 'c'"); + List dataNodes = internalCluster().startNodes( + Settings.builder() + .put(commonSettings) + .put("node.attr.zone", "a") + .put(onlyRole(commonSettings, DiscoveryNodeRole.DATA_ROLE)) + .build(), + Settings.builder() + .put(commonSettings) + .put("node.attr.zone", "b") + .put(onlyRole(commonSettings, DiscoveryNodeRole.DATA_ROLE)) + .build(), + Settings.builder() + .put(commonSettings) + .put("node.attr.zone", "c") + .put(onlyRole(commonSettings, DiscoveryNodeRole.DATA_ROLE)) + .build() + ); + + ensureStableCluster(6); + logger.info("--> setting shard routing weights for weighted round robin"); + Map weights = Map.of("a", 1.0, "b", 1.0, "c", 0.0); + WeightedRouting weightedRouting = new WeightedRouting("zone", weights); + + ClusterPutWeightedRoutingResponse weightedRoutingResponse = client().admin() + .cluster() + .prepareWeightedRouting() + .setWeightedRouting(weightedRouting) + .get(); + assertTrue(weightedRoutingResponse.isAcknowledged()); + + Request request = new Request("PUT", "/_cluster/decommission/awareness/zone/c"); + Response response = getRestClient().performRequest(request); + assertEquals(response.getStatusLine().getStatusCode(), RestStatus.OK.getStatus()); + } +} From 19e24a8e2cf19b24f71ed3b53a83613316b63e0c Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 18 Nov 2022 15:34:55 +0530 Subject: [PATCH 3/7] Remove unnecessary test change Signed-off-by: Rishab Nahata --- .../cluster/decommission/DecommissionServiceTests.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java index 56ed8abf0fa83..410784eb33548 100644 --- a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java @@ -141,7 +141,6 @@ public void onResponse(DecommissionResponse decommissionResponse) { public void onFailure(Exception e) { assertTrue(e instanceof DecommissioningFailedException); assertThat(e.getMessage(), Matchers.endsWith("invalid awareness attribute requested for decommissioning")); - assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -169,7 +168,6 @@ public void onFailure(Exception e) { + "Set forced awareness values before to decommission" ) ); - assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -195,7 +193,6 @@ public void onFailure(Exception e) { e.getMessage(), Matchers.containsString("weight for decommissioned attribute is expected to be [0.0] but found [1.0]") ); - assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -221,7 +218,6 @@ public void onFailure(Exception e) { "no weights are set to the attribute. Please set appropriate weights before triggering decommission action" ) ); - assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; @@ -259,7 +255,6 @@ public void onFailure(Exception e) { } else { assertThat(e.getMessage(), Matchers.endsWith("is in progress, cannot process this request")); } - assertEquals(((DecommissioningFailedException) e).status(), RestStatus.BAD_REQUEST); countDownLatch.countDown(); } }; From eb35a3d1e7b3cf3526ed6250dc082ad1a1e20a8a Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 18 Nov 2022 15:36:08 +0530 Subject: [PATCH 4/7] Fix spotless check Signed-off-by: Rishab Nahata --- .../cluster/decommission/DecommissionServiceTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java index 410784eb33548..7fe58d75932a1 100644 --- a/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java +++ b/server/src/test/java/org/opensearch/cluster/decommission/DecommissionServiceTests.java @@ -34,7 +34,6 @@ import org.opensearch.common.settings.ClusterSettings; import org.opensearch.common.settings.Settings; import org.opensearch.common.unit.TimeValue; -import org.opensearch.rest.RestStatus; import org.opensearch.test.ClusterServiceUtils; import org.opensearch.test.OpenSearchTestCase; import org.opensearch.test.transport.MockTransport; From 10fc0c4d7026683f3dc97bb6d8da074bf4e99f3e Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Fri, 18 Nov 2022 16:22:30 +0530 Subject: [PATCH 5/7] Fix Signed-off-by: Rishab Nahata --- .../AwarenessAttributeDecommissionRestIT.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java b/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java index 3822eccc2049b..4d9115b8962ea 100644 --- a/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java +++ b/qa/smoke-test-http/src/test/java/org/opensearch/http/AwarenessAttributeDecommissionRestIT.java @@ -28,14 +28,14 @@ public class AwarenessAttributeDecommissionRestIT extends HttpSmokeTestCase{ public void testRestStatusForDecommissioningFailedException() { - internalCluster().startNodes(3); - Request request = new Request("PUT", "/_cluster/decommission/awareness/zone/zone-1"); - ResponseException exception = expectThrows( - ResponseException.class, - () -> getRestClient().performRequest(request) - ); - assertEquals(exception.getResponse().getStatusLine().getStatusCode(), RestStatus.BAD_REQUEST.getStatus()); - assertTrue(exception.getMessage().contains("invalid awareness attribute requested for decommissioning")); + internalCluster().startNodes(3); + Request request = new Request("PUT", "/_cluster/decommission/awareness/zone/zone-1"); + ResponseException exception = expectThrows( + ResponseException.class, + () -> getRestClient().performRequest(request) + ); + assertEquals(exception.getResponse().getStatusLine().getStatusCode(), RestStatus.BAD_REQUEST.getStatus()); + assertTrue(exception.getMessage().contains("invalid awareness attribute requested for decommissioning")); } public void testRestStatusForAcknowledgedDecommission() throws IOException { From 1ff506313ca7a32a157bf17710aaa44744fdbead Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Sat, 19 Nov 2022 19:09:55 +0530 Subject: [PATCH 6/7] Add changelog Signed-off-by: Rishab Nahata --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16af268875578..f445e161eae3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix 'org.apache.hc.core5.http.ParseException: Invalid protocol version' under JDK 16+ ([#4827](https://github.com/opensearch-project/OpenSearch/pull/4827)) - Fixed compression support for h2c protocol ([#4944](https://github.com/opensearch-project/OpenSearch/pull/4944)) - Add jvm option to allow security manager ([#5194](https://github.com/opensearch-project/OpenSearch/pull/5194)) +- Update Rest status for DecommissioningFailedException([#5283](https://github.com/opensearch-project/OpenSearch/pull/5283)) ### Security ## [Unreleased 2.x] From 6fc877334aecbeca36764f69b97c6d01f1c718f1 Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Wed, 30 Nov 2022 12:12:41 +0530 Subject: [PATCH 7/7] Update changelog Signed-off-by: Rishab Nahata --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6aad1d93cd14a..7afde82bb0771 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Migrate client transports to Apache HttpClient / Core 5.x ([#4459](https://github.com/opensearch-project/OpenSearch/pull/4459)) - Support remote translog transfer for request level durability([#4480](https://github.com/opensearch-project/OpenSearch/pull/4480)) - Changed http code on create index API with bad input raising NotXContentException from 500 to 400 ([#4773](https://github.com/opensearch-project/OpenSearch/pull/4773)) +- Change http code for DecommissioningFailedException from 500 to 400 ([#5283](https://github.com/opensearch-project/OpenSearch/pull/5283)) ### Deprecated @@ -77,7 +78,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Fix 'org.apache.hc.core5.http.ParseException: Invalid protocol version' under JDK 16+ ([#4827](https://github.com/opensearch-project/OpenSearch/pull/4827)) - Fixed compression support for h2c protocol ([#4944](https://github.com/opensearch-project/OpenSearch/pull/4944)) - Reject bulk requests with invalid actions ([#5299](https://github.com/opensearch-project/OpenSearch/issues/5299)) -- Update Rest status for DecommissioningFailedException([#5283](https://github.com/opensearch-project/OpenSearch/pull/5283)) ### Security