Skip to content

Commit 64e1f07

Browse files
barkbayywelsch
authored andcommitted
Fix multi-node parsing in voting config exclusions REST API (#41588)
Fixes an issue where multiple nodes where not properly parsed in the voting config exclusions REST API. Closes #41587
1 parent 39284f5 commit 64e1f07

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

modules/transport-netty4/src/test/java/org/elasticsearch/rest/discovery/Zen2RestApiIT.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,18 @@ public void testFailsOnUnknownNode() throws Exception {
160160
);
161161
}
162162
}
163+
164+
public void testRemoveTwoNodesAtOnce() throws Exception {
165+
internalCluster().setBootstrapMasterNodeIndex(2);
166+
List<String> nodes = internalCluster().startNodes(3);
167+
ensureStableCluster(3);
168+
RestClient restClient = getRestClient();
169+
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" +
170+
nodes.get(2) + "," + nodes.get(0)));
171+
assertThat(response.getStatusLine().getStatusCode(), is(200));
172+
assertThat(response.getEntity().getContentLength(), is(0L));
173+
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
174+
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(2)));
175+
ensureStableCluster(1);
176+
}
163177
}

server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
2323
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
2424
import org.elasticsearch.client.node.NodeClient;
25+
import org.elasticsearch.common.Strings;
2526
import org.elasticsearch.common.settings.Settings;
2627
import org.elasticsearch.common.unit.TimeValue;
2728
import org.elasticsearch.rest.BaseRestHandler;
@@ -47,15 +48,19 @@ public String getName() {
4748

4849
@Override
4950
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
50-
String nodeName = request.param("node_name");
51-
AddVotingConfigExclusionsRequest votingConfigExclusionsRequest = new AddVotingConfigExclusionsRequest(
52-
new String[]{nodeName},
53-
TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")
54-
);
51+
AddVotingConfigExclusionsRequest votingConfigExclusionsRequest = resolveVotingConfigExclusionsRequest(request);
5552
return channel -> client.execute(
5653
AddVotingConfigExclusionsAction.INSTANCE,
5754
votingConfigExclusionsRequest,
5855
new RestToXContentListener<>(channel)
5956
);
6057
}
58+
59+
AddVotingConfigExclusionsRequest resolveVotingConfigExclusionsRequest(final RestRequest request) {
60+
String nodeName = request.param("node_name");
61+
return new AddVotingConfigExclusionsRequest(
62+
Strings.splitStringByCommaToArray(nodeName),
63+
TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")
64+
);
65+
}
6166
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.rest.action.admin.cluster;
21+
22+
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
23+
import org.elasticsearch.common.settings.Settings;
24+
import org.elasticsearch.rest.RestRequest;
25+
import org.elasticsearch.test.rest.FakeRestRequest;
26+
import org.elasticsearch.test.rest.RestActionTestCase;
27+
import org.junit.Before;
28+
import java.util.HashMap;
29+
import java.util.Map;
30+
31+
32+
public class RestAddVotingConfigExclusionActionTests extends RestActionTestCase {
33+
34+
private RestAddVotingConfigExclusionAction action;
35+
36+
@Before
37+
public void setupAction() {
38+
action = new RestAddVotingConfigExclusionAction(Settings.EMPTY, controller());
39+
}
40+
41+
public void testResolveVotingConfigExclusionsRequest() {
42+
Map<String, String> params = new HashMap<>();
43+
params.put("node_name", "node-1,node-2,node-3");
44+
RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry())
45+
.withMethod(RestRequest.Method.PUT)
46+
.withPath("/_cluster/voting_config_exclusions")
47+
.withParams(params)
48+
.build();
49+
50+
AddVotingConfigExclusionsRequest addVotingConfigExclusionsRequest = action.resolveVotingConfigExclusionsRequest(deprecatedRequest);
51+
String[] expected = {"node-1","node-2", "node-3"};
52+
assertArrayEquals(expected, addVotingConfigExclusionsRequest.getNodeDescriptions());
53+
}
54+
}

0 commit comments

Comments
 (0)