From 9617ccd554693d808e73ec0c0de9f3d3aefa014d Mon Sep 17 00:00:00 2001 From: Rishab Nahata Date: Wed, 16 Nov 2022 20:59:04 +0530 Subject: [PATCH] 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(); } };