Skip to content

Commit

Permalink
Update Rest status for DecommissioningFailedException
Browse files Browse the repository at this point in the history
Signed-off-by: Rishab Nahata <rnnahata@amazon.com>
  • Loading branch information
imRishN committed Nov 16, 2022
1 parent aea7d09 commit 9617ccd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -52,4 +53,9 @@ public void writeTo(StreamOutput out) throws IOException {
public DecommissionAttribute decommissionAttribute() {
return decommissionAttribute;
}

@Override
public RestStatus status() {
return RestStatus.BAD_REQUEST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
};
Expand Down Expand Up @@ -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();
}
};
Expand All @@ -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();
}
};
Expand All @@ -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();
}
};
Expand Down Expand Up @@ -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();
}
};
Expand Down

0 comments on commit 9617ccd

Please sign in to comment.