mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-30 20:08:29 +00:00
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
This commit is contained in:
parent
a0990ca239
commit
75283294f5
@ -160,4 +160,18 @@ public class Zen2RestApiIT extends ESNetty4IntegTestCase {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testRemoveTwoNodesAtOnce() throws Exception {
|
||||||
|
internalCluster().setBootstrapMasterNodeIndex(2);
|
||||||
|
List<String> nodes = internalCluster().startNodes(3);
|
||||||
|
ensureStableCluster(3);
|
||||||
|
RestClient restClient = getRestClient();
|
||||||
|
Response response = restClient.performRequest(new Request("POST", "/_cluster/voting_config_exclusions/" +
|
||||||
|
nodes.get(2) + "," + nodes.get(0)));
|
||||||
|
assertThat(response.getStatusLine().getStatusCode(), is(200));
|
||||||
|
assertThat(response.getEntity().getContentLength(), is(0L));
|
||||||
|
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(0)));
|
||||||
|
internalCluster().stopRandomNode(InternalTestCluster.nameFilter(nodes.get(2)));
|
||||||
|
ensureStableCluster(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ package org.elasticsearch.rest.action.admin.cluster;
|
|||||||
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
|
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
|
||||||
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
|
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
@ -47,15 +48,19 @@ public class RestAddVotingConfigExclusionAction extends BaseRestHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||||
String nodeName = request.param("node_name");
|
AddVotingConfigExclusionsRequest votingConfigExclusionsRequest = resolveVotingConfigExclusionsRequest(request);
|
||||||
AddVotingConfigExclusionsRequest votingConfigExclusionsRequest = new AddVotingConfigExclusionsRequest(
|
|
||||||
new String[]{nodeName},
|
|
||||||
TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")
|
|
||||||
);
|
|
||||||
return channel -> client.execute(
|
return channel -> client.execute(
|
||||||
AddVotingConfigExclusionsAction.INSTANCE,
|
AddVotingConfigExclusionsAction.INSTANCE,
|
||||||
votingConfigExclusionsRequest,
|
votingConfigExclusionsRequest,
|
||||||
new RestToXContentListener<>(channel)
|
new RestToXContentListener<>(channel)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AddVotingConfigExclusionsRequest resolveVotingConfigExclusionsRequest(final RestRequest request) {
|
||||||
|
String nodeName = request.param("node_name");
|
||||||
|
return new AddVotingConfigExclusionsRequest(
|
||||||
|
Strings.splitStringByCommaToArray(nodeName),
|
||||||
|
TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout")
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Licensed to Elasticsearch under one or more contributor
|
||||||
|
* license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright
|
||||||
|
* ownership. Elasticsearch licenses this file to you under
|
||||||
|
* the Apache License, Version 2.0 (the "License"); you may
|
||||||
|
* not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.elasticsearch.rest.action.admin.cluster;
|
||||||
|
|
||||||
|
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
|
||||||
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.rest.RestRequest;
|
||||||
|
import org.elasticsearch.test.rest.FakeRestRequest;
|
||||||
|
import org.elasticsearch.test.rest.RestActionTestCase;
|
||||||
|
import org.junit.Before;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
|
public class RestAddVotingConfigExclusionActionTests extends RestActionTestCase {
|
||||||
|
|
||||||
|
private RestAddVotingConfigExclusionAction action;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setupAction() {
|
||||||
|
action = new RestAddVotingConfigExclusionAction(Settings.EMPTY, controller());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testResolveVotingConfigExclusionsRequest() {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("node_name", "node-1,node-2,node-3");
|
||||||
|
RestRequest deprecatedRequest = new FakeRestRequest.Builder(xContentRegistry())
|
||||||
|
.withMethod(RestRequest.Method.PUT)
|
||||||
|
.withPath("/_cluster/voting_config_exclusions")
|
||||||
|
.withParams(params)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
AddVotingConfigExclusionsRequest addVotingConfigExclusionsRequest = action.resolveVotingConfigExclusionsRequest(deprecatedRequest);
|
||||||
|
String[] expected = {"node-1","node-2", "node-3"};
|
||||||
|
assertArrayEquals(expected, addVotingConfigExclusionsRequest.getNodeDescriptions());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user