From c3e9a6040f7427b5d04c14671230033c3120f269 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Mon, 4 Jun 2018 16:10:01 -0700 Subject: [PATCH] update retry-action to be in line with indices requests (#31042) --- .../indexlifecycle/action/RetryAction.java | 20 +++++-- .../action/ReRunRequestTests.java | 27 --------- .../action/RetryRequestTests.java | 56 +++++++++++++++++++ ...onseTests.java => RetryResponseTests.java} | 2 +- .../action/RestRetryAction.java | 6 +- .../api/xpack.index_lifecycle.retry.json | 4 +- 6 files changed, 78 insertions(+), 37 deletions(-) delete mode 100644 x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java create mode 100644 x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryRequestTests.java rename x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/{ReRunResponseTests.java => RetryResponseTests.java} (92%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java index 56a44cc3ad0..5868f8eeb06 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java @@ -26,7 +26,7 @@ import java.util.Objects; public class RetryAction extends Action { 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 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 { - - @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(); - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryRequestTests.java new file mode 100644 index 00000000000..5b8fc85cd96 --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryRequestTests.java @@ -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 { + + @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(); + } +} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryResponseTests.java similarity index 92% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunResponseTests.java rename to x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryResponseTests.java index 4cfb64482f8..24e758f9503 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryResponseTests.java @@ -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 { +public class RetryResponseTests extends AbstractStreamableTestCase { @Override protected Response createTestInstance() { diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java index c021651bdf3..4cfd2f1cb7a 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java @@ -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)); } } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json index 9ac94985aa6..5f934b75aa8 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json @@ -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",