From c6a7aa05501afce9aa1d08842c762278899191e8 Mon Sep 17 00:00:00 2001 From: Anshu Agarwal Date: Wed, 8 Feb 2023 16:35:14 +0530 Subject: [PATCH] Cluster local health call to throw exception if node is decommissioned or weighed away Signed-off-by: Anshu Agarwal --- CHANGELOG.md | 1 + .../AwarenessAttributeDecommissionIT.java | 4 +- .../cluster/routing/WeightedRoutingIT.java | 132 ++++++++++++++++++ .../org/opensearch/OpenSearchException.java | 2 + .../cluster/health/ClusterHealthRequest.java | 18 +-- .../health/ClusterHealthRequestBuilder.java | 4 +- .../health/TransportClusterHealthAction.java | 19 ++- .../routing/FailAwareWeightedRouting.java | 39 +----- .../routing/NodeWeighedAwayException.java | 36 +++++ .../cluster/routing/WeightedRoutingUtils.java | 53 +++++++ .../java/org/opensearch/rest/RestStatus.java | 6 + .../cluster/RestClusterHealthAction.java | 4 +- .../ExceptionSerializationTests.java | 2 + .../health/ClusterHealthRequestTests.java | 6 +- .../cluster/RestClusterHealthActionTests.java | 8 +- 15 files changed, 273 insertions(+), 61 deletions(-) create mode 100644 server/src/main/java/org/opensearch/cluster/routing/NodeWeighedAwayException.java create mode 100644 server/src/main/java/org/opensearch/cluster/routing/WeightedRoutingUtils.java diff --git a/CHANGELOG.md b/CHANGELOG.md index de7839ee6e1db..84696ef13d120 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -100,6 +100,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - [Refactor] Use local opensearch.common.SetOnce instead of lucene's utility class ([#5947](https://github.com/opensearch-project/OpenSearch/pull/5947)) - Cluster health call to throw decommissioned exception for local decommissioned node([#6008](https://github.com/opensearch-project/OpenSearch/pull/6008)) - [Refactor] core.common to new opensearch-common library ([#5976](https://github.com/opensearch-project/OpenSearch/pull/5976)) +- Cluster local health call to throw exception if node is decommissioned or weighed away ([#6198](https://github.com/opensearch-project/OpenSearch/pull/6198)) ### Deprecated diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/coordination/AwarenessAttributeDecommissionIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/coordination/AwarenessAttributeDecommissionIT.java index 676cebce9e6af..ed076dc2ed424 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/coordination/AwarenessAttributeDecommissionIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/coordination/AwarenessAttributeDecommissionIT.java @@ -310,7 +310,7 @@ public boolean innerMatch(LogEvent event) { .cluster() .prepareHealth() .setLocal(true) - .setEnsureNodeCommissioned(true) + .setEnsureNodeWeighedIn(true) .execute() .actionGet(); assertFalse(activeNodeLocalHealth.isTimedOut()); @@ -329,7 +329,7 @@ public boolean innerMatch(LogEvent event) { .cluster() .prepareHealth() .setLocal(true) - .setEnsureNodeCommissioned(true) + .setEnsureNodeWeighedIn(true) .execute() .actionGet() ); diff --git a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java index d3c0fa9ae73af..f18ee28a2de91 100644 --- a/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java +++ b/server/src/internalClusterTest/java/org/opensearch/cluster/routing/WeightedRoutingIT.java @@ -13,6 +13,7 @@ import org.opensearch.action.admin.cluster.shards.routing.weighted.delete.ClusterDeleteWeightedRoutingResponse; import org.opensearch.action.admin.cluster.shards.routing.weighted.get.ClusterGetWeightedRoutingResponse; import org.opensearch.action.admin.cluster.shards.routing.weighted.put.ClusterPutWeightedRoutingResponse; +import org.opensearch.cluster.health.ClusterHealthStatus; import org.opensearch.common.settings.Settings; import org.opensearch.rest.RestStatus; import org.opensearch.snapshots.mockstore.MockRepository; @@ -546,4 +547,135 @@ public void testPutAndDeleteWithVersioning() throws Exception { ); assertEquals(RestStatus.CONFLICT, deleteException.status()); } + + public void testClusterHealthResponseWithEnsureNodeWeighedInParam() throws Exception { + 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("--> starting 3 nodes on different zones"); + int nodeCountPerAZ = 1; + + logger.info("--> starting a dedicated cluster manager node"); + String clusterManager = internalCluster().startClusterManagerOnlyNode(Settings.builder().put(commonSettings).build()); + + logger.info("--> starting 2 nodes on zones 'a' & 'b' & 'c'"); + List nodes_in_zone_a = internalCluster().startDataOnlyNodes( + nodeCountPerAZ, + Settings.builder().put(commonSettings).put("node.attr.zone", "a").build() + ); + List nodes_in_zone_b = internalCluster().startDataOnlyNodes( + nodeCountPerAZ, + Settings.builder().put(commonSettings).put("node.attr.zone", "b").build() + ); + List nodes_in_zone_c = internalCluster().startDataOnlyNodes( + nodeCountPerAZ, + Settings.builder().put(commonSettings).put("node.attr.zone", "c").build() + ); + + logger.info("--> waiting for nodes to form a cluster"); + ClusterHealthResponse health = client().admin().cluster().prepareHealth().setWaitForNodes("4").execute().actionGet(); + assertThat(health.isTimedOut(), equalTo(false)); + + ensureGreen(); + + 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 response = client().admin() + .cluster() + .prepareWeightedRouting() + .setWeightedRouting(weightedRouting) + .setVersion(-1) + .get(); + assertTrue(response.isAcknowledged()); + assertNotNull(internalCluster().clusterService().state().metadata().weightedRoutingMetadata()); + + // Check cluster health for weighed in node, health check should return a response with 200 status code + ClusterHealthResponse nodeLocalHealth = client(nodes_in_zone_a.get(0)).admin() + .cluster() + .prepareHealth() + .setLocal(true) + .setEnsureNodeWeighedIn(true) + .get(); + assertFalse(nodeLocalHealth.isTimedOut()); + + // Check cluster health for weighed away node, health check should respond with an exception + NodeWeighedAwayException ex = expectThrows( + NodeWeighedAwayException.class, + () -> client(nodes_in_zone_c.get(0)).admin().cluster().prepareHealth().setLocal(true).setEnsureNodeWeighedIn(true).get() + ); + assertTrue(ex.getMessage().contains("local node is weighed away")); + + logger.info("--> running cluster health on an index that does not exists"); + ClusterHealthResponse healthResponse = client(nodes_in_zone_c.get(0)).admin() + .cluster() + .prepareHealth("test1") + .setLocal(true) + .setEnsureNodeWeighedIn(true) + .setTimeout("1s") + .execute() + .actionGet(); + assertThat(healthResponse.isTimedOut(), equalTo(true)); + assertThat(healthResponse.getStatus(), equalTo(ClusterHealthStatus.RED)); + assertThat(healthResponse.getIndices().isEmpty(), equalTo(true)); + + Set nodesInOneSide = Stream.of(nodes_in_zone_a.get(0), nodes_in_zone_b.get(0), nodes_in_zone_c.get(0)) + .collect(Collectors.toCollection(HashSet::new)); + Set nodesInOtherSide = Stream.of(clusterManager).collect(Collectors.toCollection(HashSet::new)); + + NetworkDisruption networkDisruption = new NetworkDisruption( + new NetworkDisruption.TwoPartitions(nodesInOneSide, nodesInOtherSide), + NetworkDisruption.DISCONNECT + ); + internalCluster().setDisruptionScheme(networkDisruption); + + logger.info("--> network disruption is started"); + networkDisruption.startDisrupting(); + + // wait for leader checker to fail + Thread.sleep(13000); + + // Check cluster health for weighed in node when cluster manager is not discovered, health check should + // return a response with 200 status code + nodeLocalHealth = client(nodes_in_zone_a.get(0)).admin() + .cluster() + .prepareHealth() + .setLocal(true) + .setEnsureNodeWeighedIn(true) + .get(); + assertFalse(nodeLocalHealth.isTimedOut()); + assertFalse(nodeLocalHealth.hasDiscoveredClusterManager()); + + // Check cluster health for weighed away node when cluster manager is not discovered, health check should + // return a response with 200 status code with cluster manager discovered as false + // ensure_node_weighed_in is not executed if cluster manager is not discovered + nodeLocalHealth = client(nodes_in_zone_c.get(0)).admin() + .cluster() + .prepareHealth() + .setLocal(true) + .setEnsureNodeWeighedIn(true) + .get(); + assertFalse(nodeLocalHealth.isTimedOut()); + assertFalse(nodeLocalHealth.hasDiscoveredClusterManager()); + + networkDisruption.stopDisrupting(); + Thread.sleep(1000); + + // delete weights + ClusterDeleteWeightedRoutingResponse deleteResponse = client().admin().cluster().prepareDeleteWeightedRouting().setVersion(0).get(); + assertTrue(deleteResponse.isAcknowledged()); + + // Check local cluster health + nodeLocalHealth = client(nodes_in_zone_c.get(0)).admin() + .cluster() + .prepareHealth() + .setLocal(true) + .setEnsureNodeWeighedIn(true) + .get(); + assertFalse(nodeLocalHealth.isTimedOut()); + assertTrue(nodeLocalHealth.hasDiscoveredClusterManager()); + } } diff --git a/server/src/main/java/org/opensearch/OpenSearchException.java b/server/src/main/java/org/opensearch/OpenSearchException.java index 4fa20f74eb044..132b5ad711442 100644 --- a/server/src/main/java/org/opensearch/OpenSearchException.java +++ b/server/src/main/java/org/opensearch/OpenSearchException.java @@ -34,6 +34,7 @@ import org.opensearch.action.support.replication.ReplicationOperation; import org.opensearch.cluster.action.shard.ShardStateAction; +import org.opensearch.cluster.routing.NodeWeighedAwayException; import org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException; import org.opensearch.cluster.routing.UnsupportedWeightedRoutingStateException; import org.opensearch.cluster.service.ClusterManagerThrottlingException; @@ -1640,6 +1641,7 @@ private enum OpenSearchExceptionHandle { 168, V_2_6_0 ), + NODE_WEIGHED_AWAY_EXCEPTION(NodeWeighedAwayException.class, NodeWeighedAwayException::new, 169, V_2_6_0), INDEX_CREATE_BLOCK_EXCEPTION( org.opensearch.cluster.block.IndexCreateBlockException.class, org.opensearch.cluster.block.IndexCreateBlockException::new, diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequest.java b/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequest.java index 3a1288cef0ea5..b1ebd63ef4676 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequest.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequest.java @@ -67,7 +67,7 @@ public class ClusterHealthRequest extends ClusterManagerNodeReadRequesttrue if local information is to be returned only when local node is also commissioned * false to not check local node if commissioned or not for a local request */ - public final boolean ensureNodeCommissioned() { - return ensureNodeCommissioned; + public final boolean ensureNodeWeighedIn() { + return ensureNodeWeighedIn; } @Override @@ -342,8 +342,8 @@ public ActionRequestValidationException validate() { } else if (!level.equals(Level.AWARENESS_ATTRIBUTES) && awarenessAttribute != null) { return addValidationError("level=awareness_attributes is required with awareness_attribute parameter", null); } - if (ensureNodeCommissioned && local == false) { - return addValidationError("not a local request to ensure local node commissioned", null); + if (ensureNodeWeighedIn && local == false) { + return addValidationError("not a local request to ensure local node commissioned or weighed in", null); } return null; } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java b/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java index 98d19b8e32247..cca9d35d8aa6f 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestBuilder.java @@ -165,8 +165,8 @@ public ClusterHealthRequestBuilder setLevel(String level) { /** * Specifies if the local request should ensure that the local node is commissioned */ - public final ClusterHealthRequestBuilder setEnsureNodeCommissioned(boolean ensureNodeCommissioned) { - request.ensureNodeCommissioned(ensureNodeCommissioned); + public final ClusterHealthRequestBuilder setEnsureNodeWeighedIn(boolean ensureNodeCommissioned) { + request.ensureNodeWeighedIn(ensureNodeCommissioned); return this; } } diff --git a/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java b/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java index a94631aae066f..4bb217057a2d3 100644 --- a/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java +++ b/server/src/main/java/org/opensearch/action/admin/cluster/health/TransportClusterHealthAction.java @@ -51,7 +51,10 @@ import org.opensearch.cluster.health.ClusterHealthStatus; import org.opensearch.cluster.metadata.IndexNameExpressionResolver; import org.opensearch.cluster.metadata.ProcessClusterEventTimeoutException; +import org.opensearch.cluster.node.DiscoveryNode; +import org.opensearch.cluster.routing.NodeWeighedAwayException; import org.opensearch.cluster.routing.UnassignedInfo; +import org.opensearch.cluster.routing.WeightedRoutingUtils; import org.opensearch.cluster.routing.allocation.AllocationService; import org.opensearch.cluster.service.ClusterService; import org.opensearch.common.Strings; @@ -140,12 +143,13 @@ protected void clusterManagerOperation( final ClusterState unusedState, final ActionListener listener ) { - if (request.ensureNodeCommissioned() + if (request.ensureNodeWeighedIn() && discovery instanceof Coordinator && ((Coordinator) discovery).localNodeCommissioned() == false) { listener.onFailure(new NodeDecommissionedException("local node is decommissioned")); return; } + final int waitCount = getWaitCount(request); if (request.waitForEvents() != null) { @@ -274,7 +278,18 @@ private void executeHealth( final Predicate validationPredicate = newState -> validateRequest(request, newState, waitCount); if (validationPredicate.test(currentState)) { - listener.onResponse(getResponse(request, currentState, waitCount, TimeoutState.OK)); + ClusterHealthResponse clusterHealthResponse = getResponse(request, currentState, waitCount, TimeoutState.OK); + if (request.ensureNodeWeighedIn() && clusterHealthResponse.hasDiscoveredClusterManager()) { + DiscoveryNode localNode = clusterService.state().getNodes().getLocalNode(); + assert request.local() == true : "local node request false for request for local node weighed in"; + boolean weighedAway = WeightedRoutingUtils.isWeighedAway(localNode.getId(), clusterService.state()); + if (weighedAway) { + listener.onFailure(new NodeWeighedAwayException("local node is weighed away")); + return; + } + } + + listener.onResponse(clusterHealthResponse); } else { final ClusterStateObserver observer = new ClusterStateObserver( currentState, diff --git a/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java b/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java index f07f4ec86ad8a..1e4c8a24863cd 100644 --- a/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java +++ b/server/src/main/java/org/opensearch/cluster/routing/FailAwareWeightedRouting.java @@ -14,15 +14,11 @@ import org.opensearch.OpenSearchException; import org.opensearch.action.search.SearchShardIterator; import org.opensearch.cluster.ClusterState; -import org.opensearch.cluster.metadata.WeightedRoutingMetadata; -import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.index.shard.ShardId; import org.opensearch.rest.RestStatus; import org.opensearch.search.SearchShardTarget; import java.util.List; -import java.util.Map; -import java.util.stream.Stream; /** * This class contains logic to find next shard to retry search request in case of failure from other shard copy. @@ -58,37 +54,6 @@ private boolean isInternalFailure(Exception exception) { return false; } - /** - * This function checks if the shard is present in data node with weighted routing weight set to 0, - * In such cases we fail open, if shard search request for the shard from other shard copies fail with non - * retryable exception. - * - * @param nodeId the node with the shard copy - * @return true if the node has attribute value with shard routing weight set to zero, else false - */ - private boolean isWeighedAway(String nodeId, ClusterState clusterState) { - DiscoveryNode node = clusterState.nodes().get(nodeId); - WeightedRoutingMetadata weightedRoutingMetadata = clusterState.metadata().weightedRoutingMetadata(); - if (weightedRoutingMetadata != null) { - WeightedRouting weightedRouting = weightedRoutingMetadata.getWeightedRouting(); - if (weightedRouting != null && weightedRouting.isSet()) { - // Fetch weighted routing attributes with weight set as zero - Stream keys = weightedRouting.weights() - .entrySet() - .stream() - .filter(entry -> entry.getValue().intValue() == WeightedRoutingMetadata.WEIGHED_AWAY_WEIGHT) - .map(Map.Entry::getKey); - - for (Object key : keys.toArray()) { - if (node.getAttributes().get(weightedRouting.attributeName()).equals(key.toString())) { - return true; - } - } - } - } - return false; - } - /** * This function returns next shard copy to retry search request in case of failure from previous copy returned * by the iterator. It has the logic to fail open ie request shard copies present in nodes with weighted shard @@ -99,7 +64,7 @@ private boolean isWeighedAway(String nodeId, ClusterState clusterState) { */ public SearchShardTarget findNext(final SearchShardIterator shardIt, ClusterState clusterState, Exception exception) { SearchShardTarget next = shardIt.nextOrNull(); - while (next != null && isWeighedAway(next.getNodeId(), clusterState)) { + while (next != null && WeightedRoutingUtils.isWeighedAway(next.getNodeId(), clusterState)) { SearchShardTarget nextShard = next; if (canFailOpen(nextShard.getShardId(), exception, clusterState)) { logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception", nextShard.getShardId()), exception); @@ -122,7 +87,7 @@ public SearchShardTarget findNext(final SearchShardIterator shardIt, ClusterStat public ShardRouting findNext(final ShardsIterator shardsIt, ClusterState clusterState, Exception exception) { ShardRouting next = shardsIt.nextOrNull(); - while (next != null && isWeighedAway(next.currentNodeId(), clusterState)) { + while (next != null && WeightedRoutingUtils.isWeighedAway(next.currentNodeId(), clusterState)) { ShardRouting nextShard = next; if (canFailOpen(nextShard.shardId(), exception, clusterState)) { logger.info(() -> new ParameterizedMessage("{}: Fail open executed due to exception", nextShard.shardId()), exception); diff --git a/server/src/main/java/org/opensearch/cluster/routing/NodeWeighedAwayException.java b/server/src/main/java/org/opensearch/cluster/routing/NodeWeighedAwayException.java new file mode 100644 index 0000000000000..ea614145a61bd --- /dev/null +++ b/server/src/main/java/org/opensearch/cluster/routing/NodeWeighedAwayException.java @@ -0,0 +1,36 @@ +/* + * 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.cluster.routing; + +import org.opensearch.OpenSearchException; +import org.opensearch.common.io.stream.StreamInput; +import org.opensearch.rest.RestStatus; + +import java.io.IOException; + +/** + * This exception is thrown if the node is weighed away by @{@link WeightedRoutingService} + * + * @opensearch.internal + */ +public class NodeWeighedAwayException extends OpenSearchException { + + public NodeWeighedAwayException(StreamInput in) throws IOException { + super(in); + } + + public NodeWeighedAwayException(String msg, Object... args) { + super(msg, args); + } + + @Override + public RestStatus status() { + return RestStatus.MISDIRECTED_REQUEST; + } +} diff --git a/server/src/main/java/org/opensearch/cluster/routing/WeightedRoutingUtils.java b/server/src/main/java/org/opensearch/cluster/routing/WeightedRoutingUtils.java new file mode 100644 index 0000000000000..e027ea8824e4c --- /dev/null +++ b/server/src/main/java/org/opensearch/cluster/routing/WeightedRoutingUtils.java @@ -0,0 +1,53 @@ +/* + * 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.cluster.routing; + +import org.opensearch.cluster.ClusterState; +import org.opensearch.cluster.metadata.WeightedRoutingMetadata; +import org.opensearch.cluster.node.DiscoveryNode; + +import java.util.Map; +import java.util.stream.Stream; + +/** + * Utils for Weighted Routing + * + * @opensearch.internal + */ +public class WeightedRoutingUtils { + + /** + * This function checks if the node is weighed away ie weighted routing weight is set to 0, + * + * @param nodeId the node + * @return true if the node has attribute value with shard routing weight set to zero, else false + */ + public static boolean isWeighedAway(String nodeId, ClusterState clusterState) { + DiscoveryNode node = clusterState.nodes().get(nodeId); + WeightedRoutingMetadata weightedRoutingMetadata = clusterState.metadata().weightedRoutingMetadata(); + if (weightedRoutingMetadata != null) { + WeightedRouting weightedRouting = weightedRoutingMetadata.getWeightedRouting(); + if (weightedRouting != null && weightedRouting.isSet()) { + // Fetch weighted routing attributes with weight set as zero + Stream keys = weightedRouting.weights() + .entrySet() + .stream() + .filter(entry -> entry.getValue().intValue() == WeightedRoutingMetadata.WEIGHED_AWAY_WEIGHT) + .map(Map.Entry::getKey); + + for (Object key : keys.toArray()) { + if (node.getAttributes().get(weightedRouting.attributeName()).equals(key.toString())) { + return true; + } + } + } + } + return false; + } +} diff --git a/server/src/main/java/org/opensearch/rest/RestStatus.java b/server/src/main/java/org/opensearch/rest/RestStatus.java index 0b0fdeb22fa03..8c718a5c8091c 100644 --- a/server/src/main/java/org/opensearch/rest/RestStatus.java +++ b/server/src/main/java/org/opensearch/rest/RestStatus.java @@ -431,6 +431,12 @@ public enum RestStatus { * next-hop server. */ EXPECTATION_FAILED(417), + /** + * The request was directed at a server that is not able to produce a response. This can be sent by a server + * that is not configured to produce responses for the combination of scheme and authority that are included + * in the request URI. + */ + MISDIRECTED_REQUEST(421), /** * The 422 (Unprocessable Entity) status code means the server understands the content type of the request * entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request diff --git a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthAction.java b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthAction.java index 04b82a536a4a9..c518d7a472b31 100644 --- a/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthAction.java +++ b/server/src/main/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthAction.java @@ -89,8 +89,8 @@ public static ClusterHealthRequest fromRequest(final RestRequest request) { final ClusterHealthRequest clusterHealthRequest = clusterHealthRequest(Strings.splitStringByCommaToArray(request.param("index"))); clusterHealthRequest.indicesOptions(IndicesOptions.fromRequest(request, clusterHealthRequest.indicesOptions())); clusterHealthRequest.local(request.paramAsBoolean("local", clusterHealthRequest.local())); - clusterHealthRequest.ensureNodeCommissioned( - request.paramAsBoolean("ensure_node_commissioned", clusterHealthRequest.ensureNodeCommissioned()) + clusterHealthRequest.ensureNodeWeighedIn( + request.paramAsBoolean("ensure_node_weighed_in", clusterHealthRequest.ensureNodeWeighedIn()) ); clusterHealthRequest.clusterManagerNodeTimeout( request.paramAsTime("cluster_manager_timeout", clusterHealthRequest.clusterManagerNodeTimeout()) diff --git a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java index 7783e21736c9f..53d25e6f72693 100644 --- a/server/src/test/java/org/opensearch/ExceptionSerializationTests.java +++ b/server/src/test/java/org/opensearch/ExceptionSerializationTests.java @@ -54,6 +54,7 @@ import org.opensearch.cluster.decommission.NodeDecommissionedException; import org.opensearch.cluster.node.DiscoveryNode; import org.opensearch.cluster.routing.IllegalShardRoutingStateException; +import org.opensearch.cluster.routing.NodeWeighedAwayException; import org.opensearch.cluster.routing.PreferenceBasedSearchNotAllowedException; import org.opensearch.cluster.routing.ShardRouting; import org.opensearch.cluster.routing.ShardRoutingState; @@ -876,6 +877,7 @@ public void testIds() { ids.put(166, SnapshotInUseDeletionException.class); ids.put(167, UnsupportedWeightedRoutingStateException.class); ids.put(168, PreferenceBasedSearchNotAllowedException.class); + ids.put(169, NodeWeighedAwayException.class); ids.put(10001, IndexCreateBlockException.class); Map, Integer> reverse = new HashMap<>(); diff --git a/server/src/test/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestTests.java b/server/src/test/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestTests.java index b87194ac717c5..284e8f1ac5cd1 100644 --- a/server/src/test/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestTests.java +++ b/server/src/test/java/org/opensearch/action/admin/cluster/health/ClusterHealthRequestTests.java @@ -75,14 +75,14 @@ public void testValidation() { ClusterHealthRequest clusterHealthRequest = randomRequest(); { clusterHealthRequest.local(false); - clusterHealthRequest.ensureNodeCommissioned(true); + clusterHealthRequest.ensureNodeWeighedIn(true); ActionRequestValidationException e = clusterHealthRequest.validate(); assertNotNull(e); - assertTrue(e.getMessage().contains("not a local request to ensure local node commissioned")); + assertTrue(e.getMessage().contains("not a local request to ensure local node commissioned or weighed in")); } { clusterHealthRequest.local(true); - clusterHealthRequest.ensureNodeCommissioned(false); + clusterHealthRequest.ensureNodeWeighedIn(false); ActionRequestValidationException e = clusterHealthRequest.validate(); assertNull(e); } diff --git a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthActionTests.java b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthActionTests.java index 4c60ea810f591..31a0ebfd6c805 100644 --- a/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthActionTests.java +++ b/server/src/test/java/org/opensearch/rest/action/admin/cluster/RestClusterHealthActionTests.java @@ -52,9 +52,9 @@ public void testFromRequest() { Map params = new HashMap<>(); String index = "index"; boolean local = randomBoolean(); - boolean ensureLocalNodeCommissioned = false; + boolean ensureLocalWeighedIn = false; if (local) { - ensureLocalNodeCommissioned = randomBoolean(); + ensureLocalWeighedIn = randomBoolean(); } String clusterManagerTimeout = randomTimeValue(); String timeout = randomTimeValue(); @@ -67,7 +67,7 @@ public void testFromRequest() { params.put("index", index); params.put("local", String.valueOf(local)); - params.put("ensure_node_commissioned", String.valueOf(ensureLocalNodeCommissioned)); + params.put("ensure_node_weighed_in", String.valueOf(ensureLocalWeighedIn)); params.put("cluster_manager_timeout", clusterManagerTimeout); params.put("timeout", timeout); params.put("wait_for_status", waitForStatus.name()); @@ -86,7 +86,7 @@ public void testFromRequest() { assertThat(clusterHealthRequest.indices().length, equalTo(1)); assertThat(clusterHealthRequest.indices()[0], equalTo(index)); assertThat(clusterHealthRequest.local(), equalTo(local)); - assertThat(clusterHealthRequest.ensureNodeCommissioned(), equalTo(ensureLocalNodeCommissioned)); + assertThat(clusterHealthRequest.ensureNodeWeighedIn(), equalTo(ensureLocalWeighedIn)); assertThat(clusterHealthRequest.clusterManagerNodeTimeout(), equalTo(TimeValue.parseTimeValue(clusterManagerTimeout, "test"))); assertThat(clusterHealthRequest.timeout(), equalTo(TimeValue.parseTimeValue(timeout, "test"))); assertThat(clusterHealthRequest.waitForStatus(), equalTo(waitForStatus));