-
Notifications
You must be signed in to change notification settings - Fork 25k
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
[Zen2] Implement Tombstone REST APIs #36007
Changes from 3 commits
6cae1b8
e167a09
8456401
0d5d5a7
2305b50
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,146 @@ | ||
/* | ||
* 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.discovery; | ||
|
||
import org.apache.http.HttpHost; | ||
import org.elasticsearch.ESNetty4IntegTestCase; | ||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; | ||
import org.elasticsearch.client.Client; | ||
import org.elasticsearch.client.Node; | ||
import org.elasticsearch.client.Request; | ||
import org.elasticsearch.client.Response; | ||
import org.elasticsearch.client.ResponseException; | ||
import org.elasticsearch.client.RestClient; | ||
import org.elasticsearch.cluster.coordination.ClusterBootstrapService; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.routing.UnassignedInfo; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.discovery.zen.ElectMasterService; | ||
import org.elasticsearch.http.HttpServerTransport; | ||
import org.elasticsearch.test.ESIntegTestCase; | ||
import org.elasticsearch.test.InternalTestCluster; | ||
import org.elasticsearch.test.discovery.TestZenDiscovery; | ||
import org.hamcrest.Matchers; | ||
|
||
import java.io.IOException; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
|
||
// TODO: Move these tests to a more appropriate module | ||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, transportClientRatio = 0, autoMinMasterNodes = false) | ||
public class Zen2RestApiIT extends ESNetty4IntegTestCase { | ||
|
||
@Override | ||
protected Settings nodeSettings(int nodeOrdinal) { | ||
return Settings.builder().put(super.nodeSettings(nodeOrdinal)) | ||
.put(TestZenDiscovery.USE_ZEN2.getKey(), true) | ||
.put(ElectMasterService.DISCOVERY_ZEN_MINIMUM_MASTER_NODES_SETTING.getKey(), Integer.MAX_VALUE) | ||
.put(ClusterBootstrapService.INITIAL_MASTER_NODE_COUNT_SETTING.getKey(), 2) | ||
.build(); | ||
} | ||
|
||
@Override | ||
protected boolean addMockHttpTransport() { | ||
return false; // enable http | ||
} | ||
|
||
public void testRollingRestartOfTwoNodeCluster() throws Exception { | ||
final List<String> nodes = internalCluster().startNodes(2); | ||
createIndex("test", | ||
Settings.builder() | ||
.put(UnassignedInfo.INDEX_DELAYED_NODE_LEFT_TIMEOUT_SETTING.getKey(), TimeValue.ZERO) // assign shards | ||
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2) // causes rebalancing | ||
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) | ||
.build()); | ||
ensureGreen("test"); | ||
|
||
RestClient restClient = getRestClient(); | ||
|
||
internalCluster().rollingRestart(new InternalTestCluster.RestartCallback() { | ||
@Override | ||
public void doAfterNodes(int n, Client client) throws IOException { | ||
ensureGreen("test"); | ||
Response response = | ||
restClient.performRequest(new Request("POST", "/_cluster/withdrawn_votes/" + internalCluster().getNodeNames()[n])); | ||
assertThat(response.getStatusLine().getStatusCode(), is(200)); | ||
} | ||
|
||
@Override | ||
public Settings onNodeStopped(String nodeName) throws IOException { | ||
String viaNode = randomValueOtherThan(nodeName, () -> randomFrom(nodes)); | ||
|
||
List<Node> allNodes = restClient.getNodes(); | ||
try { | ||
restClient.setNodes( | ||
Collections.singletonList( | ||
new Node( | ||
HttpHost.create( | ||
internalCluster().getInstance(HttpServerTransport.class, viaNode) | ||
.boundAddress().publishAddress().toString() | ||
) | ||
) | ||
) | ||
); | ||
Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/withdrawn_votes")); | ||
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200)); | ||
|
||
ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth() | ||
.setWaitForEvents(Priority.LANGUID) | ||
.setWaitForNodes(Integer.toString(1)) | ||
.setTimeout(TimeValue.timeValueSeconds(30L)) | ||
.setWaitForYellowStatus() | ||
.get(); | ||
assertFalse(nodeName, clusterHealthResponse.isTimedOut()); | ||
return Settings.EMPTY; | ||
} finally { | ||
restClient.setNodes(allNodes); | ||
} | ||
} | ||
}); | ||
ensureStableCluster(2); | ||
ensureGreen("test"); | ||
assertThat(internalCluster().size(), is(2)); | ||
} | ||
|
||
public void testBasicRestApi() throws Exception { | ||
List<String> nodes = internalCluster().startNodes(3); | ||
RestClient restClient = getRestClient(); | ||
Response response = restClient.performRequest(new Request("POST", "/_cluster/withdrawn_votes/" + nodes.get(2))); | ||
assertThat(response.getStatusLine().getStatusCode(), is(200)); | ||
assertThat(response.getEntity().getContentLength(), is(0L)); | ||
Response deleteResponse = restClient.performRequest(new Request("DELETE", "/_cluster/withdrawn_votes")); | ||
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. Think it'd make more sense to put this after the 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. I agree. Just tried making that change but running into this error as a result:
(no matter what node I add a Tombstone for, this happens)
Should I do that in the Rest API? 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. Yep :) |
||
assertThat(deleteResponse.getStatusLine().getStatusCode(), is(200)); | ||
assertThat(deleteResponse.getEntity().getContentLength(), is(0L)); | ||
try { | ||
restClient.performRequest(new Request("POST", "/_cluster/withdrawn_votes/invalid")); | ||
fail("Invalid node name should throw."); | ||
} catch (ResponseException e) { | ||
assertThat(e.getResponse().getStatusLine().getStatusCode(), is(400)); | ||
assertThat( | ||
e.getCause().getMessage(), | ||
Matchers.containsString("add voting tombstones request for [invalid] matched no master-eligible nodes") | ||
); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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.AddVotingTombstonesAction; | ||
import org.elasticsearch.action.admin.cluster.configuration.AddVotingTombstonesRequest; | ||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.unit.TimeValue; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.io.IOException; | ||
|
||
public class RestAddVotingTombstonesAction extends BaseRestHandler { | ||
|
||
private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(30L); | ||
|
||
public RestAddVotingTombstonesAction(Settings settings, RestController controller) { | ||
super(settings); | ||
controller.registerHandler(RestRequest.Method.POST, "/_cluster/withdrawn_votes/{node_name}", this); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "add_voting_tombstones_action"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { | ||
String nodeName = request.param("node_name"); | ||
AddVotingTombstonesRequest addVotingTombstonesRequest = new AddVotingTombstonesRequest( | ||
new String[]{nodeName}, | ||
TimeValue.parseTimeValue(request.param("timeout"), DEFAULT_TIMEOUT, getClass().getSimpleName() + ".timeout") | ||
); | ||
return channel -> client.execute( | ||
AddVotingTombstonesAction.INSTANCE, | ||
addVotingTombstonesRequest, | ||
new RestToXContentListener<>(channel) | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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.ClearVotingTombstonesAction; | ||
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingTombstonesRequest; | ||
import org.elasticsearch.client.node.NodeClient; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.rest.BaseRestHandler; | ||
import org.elasticsearch.rest.RestController; | ||
import org.elasticsearch.rest.RestRequest; | ||
import org.elasticsearch.rest.action.RestToXContentListener; | ||
|
||
import java.io.IOException; | ||
|
||
public class RestClearVotingTombstonesAction extends BaseRestHandler { | ||
|
||
public RestClearVotingTombstonesAction(Settings settings, RestController controller) { | ||
super(settings); | ||
controller.registerHandler(RestRequest.Method.DELETE, "/_cluster/withdrawn_votes", this); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "clear_voting_tombstones_action"; | ||
} | ||
|
||
@Override | ||
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { | ||
ClearVotingTombstonesRequest req = new ClearVotingTombstonesRequest(); | ||
req.setWaitForRemoval(false); | ||
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. Apologies, I meant this should be a parameter Now that I've written that, I think it'd be good to test both 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. Looking at other APIs, it should be |
||
return channel -> client.execute(ClearVotingTombstonesAction.INSTANCE, req, new RestToXContentListener<>(channel)); | ||
} | ||
} |
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.
Suggest: