-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Rest status for DecommissioningFailedException #5283
Changes from 8 commits
9617ccd
adb4e55
2592f88
19e24a8
eb35a3d
7e7aa43
10fc0c4
1ff5063
f9fc976
2026ce4
6fc8773
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> 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<String> 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<String, Double> 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()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/cluster/decommission/DecommissionService.java#L271 it seems its not a bad request due to which the exception is thrown. Should we use a different exception over here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm right. Will fix this in #5093 PR and would rather throw There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets break down to use specific exceptions and use 400/403 as needed in those relevant cases There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR just attempts to change the status code for |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is not a fix, but a change. Move above and say "Changed htto code for ... from 500 to 400" similar to what we did for NotXContentException
Also add a space before
(
like for all other lines, please.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done