update retry-action to be in line with indices requests (#31042)

This commit is contained in:
Tal Levy 2018-06-04 16:10:01 -07:00 committed by GitHub
parent 32902b78db
commit c3e9a6040f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 78 additions and 37 deletions

View File

@ -26,7 +26,7 @@ import java.util.Objects;
public class RetryAction extends Action<RetryAction.Request, RetryAction.Response> {
public static final RetryAction INSTANCE = new RetryAction();
public static final String NAME = "indices:admin/xpack/index_lifecycle/_retry/post";
public static final String NAME = "indices:admin/xpack/index_lifecycle/retry";
protected RetryAction() {
super(NAME);
@ -48,7 +48,8 @@ public class RetryAction extends Action<RetryAction.Request, RetryAction.Respons
}
public static class Request extends AcknowledgedRequest<Request> implements IndicesRequest.Replaceable {
private String[] indices;
private String[] indices = Strings.EMPTY_ARRAY;
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
public Request(String... indices) {
this.indices = indices;
@ -70,8 +71,12 @@ public class RetryAction extends Action<RetryAction.Request, RetryAction.Respons
@Override
public IndicesOptions indicesOptions() {
// Re-run should only resolve to open concrete indices (not aliases)
return new IndicesOptions(EnumSet.of(Option.IGNORE_ALIASES), EnumSet.of(WildcardStates.OPEN));
return indicesOptions;
}
public Request indicesOptions(IndicesOptions indicesOptions) {
this.indicesOptions = indicesOptions;
return this;
}
@Override
@ -83,17 +88,19 @@ public class RetryAction extends Action<RetryAction.Request, RetryAction.Respons
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
this.indices = in.readStringArray();
this.indicesOptions = IndicesOptions.readIndicesOptions(in);
}
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
}
@Override
public int hashCode() {
return Arrays.hashCode(indices);
return Objects.hash(Arrays.hashCode(indices), indicesOptions);
}
@Override
@ -105,7 +112,8 @@ public class RetryAction extends Action<RetryAction.Request, RetryAction.Respons
return false;
}
Request other = (Request) obj;
return Arrays.equals(indices, other.indices);
return Objects.deepEquals(indices, other.indices)
&& Objects.equals(indicesOptions, other.indicesOptions);
}
}

View File

@ -1,27 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*
*/
package org.elasticsearch.xpack.core.indexlifecycle.action;
import org.elasticsearch.test.AbstractStreamableTestCase;
import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Request;
public class ReRunRequestTests extends AbstractStreamableTestCase<Request> {
@Override
protected Request createTestInstance() {
String[] indices = new String[randomIntBetween(1, 10)];
for (int i = 0; i < indices.length; i++) {
indices[i] = randomAlphaOfLengthBetween(2, 5);
}
return new Request(indices);
}
@Override
protected Request createBlankInstance() {
return new Request();
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*
*/
package org.elasticsearch.xpack.core.indexlifecycle.action;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.test.AbstractStreamableTestCase;
import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Request;
import java.io.IOException;
public class RetryRequestTests extends AbstractStreamableTestCase<Request> {
@Override
protected Request createTestInstance() {
Request request = new Request();
if (randomBoolean()) {
request.indices(generateRandomStringArray(20, 20, false));
}
if (randomBoolean()) {
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean());
request.indicesOptions(indicesOptions);
}
return request;
}
@Override
protected Request mutateInstance(Request instance) throws IOException {
String[] indices = instance.indices();
IndicesOptions indicesOptions = instance.indicesOptions();
switch (between(0, 1)) {
case 0:
indices = generateRandomStringArray(20, 10, false);
break;
case 1:
indicesOptions = randomValueOtherThan(indicesOptions, () -> IndicesOptions.fromOptions(randomBoolean(), randomBoolean(),
randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean()));
break;
default:
throw new AssertionError("Illegal randomisation branch");
}
Request newRequest = new Request();
newRequest.indices(indices);
newRequest.indicesOptions(indicesOptions);
return newRequest;
}
@Override
protected Request createBlankInstance() {
return new Request();
}
}

View File

@ -9,7 +9,7 @@ package org.elasticsearch.xpack.core.indexlifecycle.action;
import org.elasticsearch.test.AbstractStreamableTestCase;
import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Response;
public class ReRunResponseTests extends AbstractStreamableTestCase<Response> {
public class RetryResponseTests extends AbstractStreamableTestCase<Response> {
@Override
protected Response createTestInstance() {

View File

@ -6,6 +6,7 @@
*/
package org.elasticsearch.xpack.indexlifecycle.action;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
@ -20,7 +21,8 @@ public class RestRetryAction extends BaseRestHandler {
public RestRetryAction(Settings settings, RestController controller) {
super(settings);
controller.registerHandler(RestRequest.Method.POST, IndexLifecycle.BASE_PATH + "_retry/{index}", this);
controller.registerHandler(RestRequest.Method.POST, "_" + IndexLifecycle.NAME + "/retry", this);
controller.registerHandler(RestRequest.Method.POST, "{index}/_" + IndexLifecycle.NAME + "/retry", this);
}
@Override
@ -34,6 +36,8 @@ public class RestRetryAction extends BaseRestHandler {
RetryAction.Request request = new RetryAction.Request(indices);
request.timeout(restRequest.paramAsTime("timeout", request.timeout()));
request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
request.indices(indices);
request.indicesOptions(IndicesOptions.fromRequest(restRequest, IndicesOptions.strictExpandOpen()));
return channel -> client.execute(RetryAction.INSTANCE, request, new RestToXContentListener<>(channel));
}
}

View File

@ -3,8 +3,8 @@
"documentation": "http://www.elastic.co/guide/en/index_lifecycle/current/index_lifecycle.html",
"methods": [ "POST" ],
"url": {
"path": "/_xpack/index_lifecycle/_retry/{index}",
"paths": ["/_xpack/index_lifecycle/_retry/{index}"],
"path": "/{index}/_index_lifecycle/retry",
"paths": ["/{index}/_index_lifecycle/retry", "/_index_lifecycle/retry"],
"parts": {
"index": {
"type" : "string",