From 50a40b577fd822cb94ac08df258e573d18f5460f Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Mon, 21 May 2018 16:23:22 -0700 Subject: [PATCH 1/9] add _rerun API to index lifecycle policies --- .../indexlifecycle/action/ReRunAction.java | 145 ++++++++++++++++++ .../xpack/indexlifecycle/IndexLifecycle.java | 10 +- .../indexlifecycle/IndexLifecycleRunner.java | 2 +- .../action/RestReRunAction.java | 42 +++++ .../action/TransportReRunAction.java | 91 +++++++++++ .../api/xpack.index_lifecycle.rerun.json | 19 +++ .../test/index_lifecycle/30_rerun.yml | 141 +++++++++++++++++ 7 files changed, 447 insertions(+), 3 deletions(-) create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java create mode 100644 x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java create mode 100644 x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json create mode 100644 x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java new file mode 100644 index 0000000000000..77a93d74d7a48 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java @@ -0,0 +1,145 @@ +/* + * 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.Action; +import org.elasticsearch.action.ActionRequestBuilder; +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.master.AcknowledgedRequest; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.client.ElasticsearchClient; +import org.elasticsearch.common.ParseField; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.xcontent.ConstructingObjectParser; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; + +import java.io.IOException; +import java.util.Objects; + +public class ReRunAction extends Action { + public static final ReRunAction INSTANCE = new ReRunAction(); + public static final String NAME = "cluster:admin/xpack/index_lifecycle/_rerun/post"; + + protected ReRunAction() { + super(NAME); + } + + @Override + public RequestBuilder newRequestBuilder(ElasticsearchClient client) { + return new RequestBuilder(client, this); + } + + @Override + public Response newResponse() { + return new Response(); + } + + public static class RequestBuilder extends ActionRequestBuilder { + + protected RequestBuilder(ElasticsearchClient client, Action action) { + super(client, action, new Request()); + } + + } + + public static class Response extends AcknowledgedResponse implements ToXContentObject { + + public Response() { + } + + public Response(boolean acknowledged) { + super(acknowledged); + } + + @Override + public void readFrom(StreamInput in) throws IOException { + readAcknowledged(in); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + writeAcknowledged(out); + } + + @Override + public int hashCode() { + return Objects.hash(isAcknowledged()); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj.getClass() != getClass()) { + return false; + } + Response other = (Response) obj; + return Objects.equals(isAcknowledged(), other.isAcknowledged()); + } + + @Override + public String toString() { + return Strings.toString(this, true, true); + } + + } + + public static class Request extends AcknowledgedRequest { + private String index; + + public Request(String index) { + this.index = index; + } + + public Request() { + } + + public String getIndex() { + return index; + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + this.index = in.readString(); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeString(index); + } + + @Override + public int hashCode() { + return Objects.hash(index); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj.getClass() != getClass()) { + return false; + } + Request other = (Request) obj; + return Objects.equals(index, other.index); + } + } +} diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java index f03eacb11f6ff..c8bcb3e5c76bd 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java @@ -38,14 +38,17 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction; import org.elasticsearch.xpack.indexlifecycle.action.RestDeleteLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestGetLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.RestPutLifecycleAction; +import org.elasticsearch.xpack.indexlifecycle.action.RestReRunAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportDeleteLifcycleAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportGetLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportPutLifecycleAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportReRunAction; import java.time.Clock; import java.util.ArrayList; @@ -139,7 +142,9 @@ public List getRestHandlers(Settings settings, RestController restC new RestPutLifecycleAction(settings, restController), new RestGetLifecycleAction(settings, restController), new RestDeleteLifecycleAction(settings, restController), - new RestMoveToStepAction(settings, restController)); + new RestMoveToStepAction(settings, restController), + new RestReRunAction(settings, restController) + ); } @Override @@ -151,7 +156,8 @@ public List getRestHandlers(Settings settings, RestController restC new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class), new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class), new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifcycleAction.class), - new ActionHandler<>(MoveToStepAction.INSTANCE, TransportMoveToStepAction.class)); + new ActionHandler<>(MoveToStepAction.INSTANCE, TransportMoveToStepAction.class), + new ActionHandler<>(ReRunAction.INSTANCE, TransportReRunAction.class)); } @Override diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 2adea516ce6b9..3e87b2dcb9ab3 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -122,7 +122,7 @@ private void executeClusterStateSteps(Index index, String policy, Step step) { * @param indexSettings * the index settings to extract the {@link StepKey} from. */ - static StepKey getCurrentStepKey(Settings indexSettings) { + public static StepKey getCurrentStepKey(Settings indexSettings) { String currentPhase = LifecycleSettings.LIFECYCLE_PHASE_SETTING.get(indexSettings); String currentAction = LifecycleSettings.LIFECYCLE_ACTION_SETTING.get(indexSettings); String currentStep = LifecycleSettings.LIFECYCLE_STEP_SETTING.get(indexSettings); diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java new file mode 100644 index 0000000000000..5f21baa0e9c40 --- /dev/null +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java @@ -0,0 +1,42 @@ +/* + * 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.indexlifecycle.action; + +import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.rest.BaseRestHandler; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.RestToXContentListener; +import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycle; + +import java.io.IOException; + +public class RestReRunAction extends BaseRestHandler { + + public RestReRunAction(Settings settings, RestController controller) { + super(settings); + controller.registerHandler(RestRequest.Method.POST, IndexLifecycle.BASE_PATH + "_rerun/{name}", this); + } + + @Override + public String getName() { + return "xpack_lifecycle_move_to_step_action"; + } + + @Override + protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { + String index = restRequest.param("name"); + ReRunAction.Request request = new ReRunAction.Request(index); + request.timeout(restRequest.paramAsTime("timeout", request.timeout())); + request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); + return channel -> client.execute(ReRunAction.INSTANCE, request, new RestToXContentListener<>(channel)); + } +} diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java new file mode 100644 index 0000000000000..2ac946a97a226 --- /dev/null +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java @@ -0,0 +1,91 @@ +/* + * 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.indexlifecycle.action; + +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.TransportMasterNodeAction; +import org.elasticsearch.cluster.AckedClusterStateUpdateTask; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockException; +import org.elasticsearch.cluster.block.ClusterBlockLevel; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.Strings; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; +import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; +import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; +import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction.Request; +import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction.Response; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunner; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; + +public class TransportReRunAction extends TransportMasterNodeAction { + IndexLifecycleService indexLifecycleService; + @Inject + public TransportReRunAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver, + IndexLifecycleService indexLifecycleService) { + super(settings, ReRunAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + Request::new); + this.indexLifecycleService = indexLifecycleService; + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected Response newResponse() { + return new Response(); + } + + @Override + protected void masterOperation(Request request, ClusterState state, ActionListener listener) { + IndexMetaData indexMetaData = state.metaData().index(request.getIndex()); + if (indexMetaData == null) { + listener.onFailure(new IllegalArgumentException("index [" + request.getIndex() + "] does not exist")); + return; + } + clusterService.submitStateUpdateTask("index[" + request.getIndex() + "]-move-to-step", + new AckedClusterStateUpdateTask(request, listener) { + @Override + public ClusterState execute(ClusterState currentState) { + IndexMetaData indexMetaData = currentState.metaData().index(request.getIndex()); + StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(indexMetaData.getSettings()); + String failedStep = LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.get(indexMetaData.getSettings()); + if (currentStepKey != null && ErrorStep.NAME.equals(currentStepKey.getName()) + && Strings.isNullOrEmpty(failedStep) == false) { + StepKey nextStepKey = new StepKey(currentStepKey.getPhase(), currentStepKey.getAction(), failedStep); + return indexLifecycleService.moveClusterStateToStep(currentState, request.getIndex(), currentStepKey, nextStepKey); + } else { + listener.onFailure(new IllegalArgumentException("cannot re-run an action for an index [" + + request.getIndex() + "] that has not encountered an error when running a Lifecycle Policy")); + return currentState; + } + } + + @Override + protected Response newResponse(boolean acknowledged) { + return new Response(acknowledged); + } + }); + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } +} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json new file mode 100644 index 0000000000000..cca6900d2b449 --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json @@ -0,0 +1,19 @@ +{ + "xpack.index_lifecycle.rerun": { + "documentation": "http://www.elastic.co/guide/en/index_lifecycle/current/index_lifecycle.html", + "methods": [ "POST" ], + "url": { + "path": "/_xpack/index_lifecycle/_rerun/{index}", + "paths": ["/_xpack/index_lifecycle/_rerun/{index}"], + "parts": { + "index": { + "type" : "string", + "description" : "The name of the index whose failed lifecycle step is to be re-run" + } + }, + "params": { + } + }, + "body": null + } +} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml new file mode 100644 index 0000000000000..442a62e1a7eec --- /dev/null +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml @@ -0,0 +1,141 @@ +--- +setup: + - do: + cluster.health: + wait_for_status: yellow + + - do: + acknowlege: true + xpack.index_lifecycle.put_lifecycle: + lifecycle: "my_lifecycle" + body: | + { + "policy": { + "type": "timeseries", + "phases": { + "warm": { + "after": "1000s", + "actions": { + "forcemerge": { + "max_num_segments": 10000 + } + } + }, + "hot": { + "after": "1000s", + "actions": { } + } + } + } + } + + - do: + acknowledge: true + xpack.index_lifecycle.get_lifecycle: + lifecycle: "my_lifecycle" + +--- +teardown: + + - do: + acknowledge: true + indices.delete: + index: my_index + + - do: + acknowledge: true + xpack.index_lifecycle.delete_lifecycle: + lifecycle: "my_lifecycle" + + - do: + catch: missing + xpack.index_lifecycle.get_lifecycle: + lifecycle: "my_lifecycle" + +--- +"Test Basic Re-run": + + - do: + indices.create: + index: my_index + body: + settings: + index.lifecycle.name: "my_lifecycle" + index.lifecycle.step: "error" + index.lifecycle.action: "pre-pre-readonly" + index.lifecycle.phase: "hot" + index.lifecycle.failed_step: "after" + + + - do: + acknowledge: true + xpack.index_lifecycle.rerun: + index: "my_index" + + - do: + acknowledge: true + indices.get: + index: my_index + - match: { my_index.settings.index.lifecycle.name: "my_lifecycle" } + - match: { my_index.settings.index.lifecycle.step: "after" } + - match: { my_index.settings.index.lifecycle.action: "pre-pre-readonly" } + - match: { my_index.settings.index.lifecycle.phase: "hot" } + +--- +"Test Invalid Re-run With Non-errored Policy": + + - do: + indices.create: + index: my_index + body: + settings: + index.lifecycle.name: "my_lifecycle" + + - do: + acknowledge: true + xpack.index_lifecycle.rerun: + index: "my_index" + + - do: + catch: bad_request + xpack.index_lifecycle.rerun: + index: "my_index" + - match: { error.root_cause.0.type: "illegal_argument_exception" } + - match: { error.root_cause.0.reason: "cannot re-run an action for an index [my_index] that has not encountered an error when running a Lifecycle Policy" } + + - do: + acknowledge: true + indices.get: + index: my_index + - match: { my_index.settings.index.lifecycle.name: "my_lifecycle" } + - match: { my_index.settings.index.lifecycle.step: "after" } + - match: { my_index.settings.index.lifecycle.action: "pre-pre-readonly" } + - match: { my_index.settings.index.lifecycle.phase: "hot" } + + +--- +"Test Invalid Re-run With No Policy": + + - do: + indices.create: + index: my_index + + - do: + catch: bad_request + xpack.index_lifecycle.rerun: + index: "my_index" + - match: { error.root_cause.0.type: "illegal_argument_exception" } + - match: { error.root_cause.0.reason: "cannot re-run an action for an index [my_index] that has not encountered an error when running a Lifecycle Policy" } + +--- +"Test Invalid Re-run With Invalid Index": + - do: + indices.create: + index: my_index + + - do: + catch: bad_request + xpack.index_lifecycle.rerun: + index: "does_not_exist" + - match: { error.root_cause.0.type: "illegal_argument_exception" } + - match: { error.root_cause.0.reason: "index [does_not_exist] does not exist" } From aedccfd09956366b0b59bf5c18e49dda2fee085d Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Wed, 23 May 2018 17:58:28 -0700 Subject: [PATCH 2/9] beef up testing and update rerun to be an indices-request --- .../indexlifecycle/action/ReRunAction.java | 45 +++-- .../action/ReRunRequestTests.java | 27 +++ .../action/ReRunResponseTests.java | 29 +++ .../indexlifecycle/IndexLifecycleRunner.java | 3 +- .../action/RestReRunAction.java | 9 +- .../action/TransportReRunAction.java | 41 +++-- .../IndexLifecycleRunnerTests.java | 4 +- .../action/ReRunActionTests.java | 165 ++++++++++++++++++ .../api/xpack.index_lifecycle.rerun.json | 2 +- .../test/index_lifecycle/30_rerun.yml | 53 ++++-- 10 files changed, 323 insertions(+), 55 deletions(-) create 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/ReRunResponseTests.java create mode 100644 x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java index 77a93d74d7a48..9358c6badc1fc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java @@ -9,20 +9,21 @@ import org.elasticsearch.action.Action; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.IndicesRequest; +import org.elasticsearch.action.support.IndicesOptions; +import org.elasticsearch.action.support.IndicesOptions.Option; +import org.elasticsearch.action.support.IndicesOptions.WildcardStates; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.ElasticsearchClient; -import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import java.io.IOException; +import java.util.Arrays; +import java.util.EnumSet; import java.util.Objects; public class ReRunAction extends Action { @@ -94,18 +95,31 @@ public String toString() { } - public static class Request extends AcknowledgedRequest { - private String index; + public static class Request extends AcknowledgedRequest implements IndicesRequest.Replaceable { + private String[] indices; - public Request(String index) { - this.index = index; + public Request(String... indices) { + this.indices = indices; } public Request() { } - public String getIndex() { - return index; + @Override + public Request indices(String... indices) { + this.indices = indices; + return this; + } + + @Override + public String[] indices() { + return indices; + } + + @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)); } @Override @@ -116,18 +130,18 @@ public ActionRequestValidationException validate() { @Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); - this.index = in.readString(); + this.indices = in.readStringArray(); } @Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); - out.writeString(index); + out.writeStringArray(indices); } @Override public int hashCode() { - return Objects.hash(index); + return Objects.hash(indices); } @Override @@ -139,7 +153,8 @@ public boolean equals(Object obj) { return false; } Request other = (Request) obj; - return Objects.equals(index, other.index); + return Arrays.equals(indices, other.indices); } + } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java new file mode 100644 index 0000000000000..6f6f467bb533b --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java @@ -0,0 +1,27 @@ +/* + * 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.ReRunAction.Request; + +public class ReRunRequestTests extends AbstractStreamableTestCase { + + @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/ReRunResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunResponseTests.java new file mode 100644 index 0000000000000..a1d4ab75faa9a --- /dev/null +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunResponseTests.java @@ -0,0 +1,29 @@ +/* + * 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.ReRunAction.Response; + +public class ReRunResponseTests extends AbstractStreamableTestCase { + + @Override + protected Response createTestInstance() { + return new Response(randomBoolean()); + } + + @Override + protected Response createBlankInstance() { + return new Response(); + } + + @Override + protected Response mutateInstance(Response response) { + return new Response(response.isAcknowledged() == false); + } + +} diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 3e87b2dcb9ab3..0b3dd5f1e8c61 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -200,7 +200,8 @@ private static Settings.Builder moveIndexSettingsToNextStep(Settings existingSet Settings.Builder newSettings = Settings.builder().put(existingSettings).put(LifecycleSettings.LIFECYCLE_PHASE, nextStep.getPhase()) .put(LifecycleSettings.LIFECYCLE_ACTION, nextStep.getAction()).put(LifecycleSettings.LIFECYCLE_STEP, nextStep.getName()) .put(LifecycleSettings.LIFECYCLE_STEP_TIME, nowAsMillis) - // clear any step info from the current step + // clear any step info or error-related settings from the current step + .put(LifecycleSettings.LIFECYCLE_FAILED_STEP, (String) null) .put(LifecycleSettings.LIFECYCLE_STEP_INFO, (String) null); if (currentStep.getPhase().equals(nextStep.getPhase()) == false) { newSettings.put(LifecycleSettings.LIFECYCLE_PHASE_TIME, nowAsMillis); diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java index 5f21baa0e9c40..ec810e3c34a94 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.indexlifecycle.action; import org.elasticsearch.client.node.NodeClient; +import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; @@ -23,18 +24,18 @@ public class RestReRunAction extends BaseRestHandler { public RestReRunAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(RestRequest.Method.POST, IndexLifecycle.BASE_PATH + "_rerun/{name}", this); + controller.registerHandler(RestRequest.Method.POST, IndexLifecycle.BASE_PATH + "_rerun/{index}", this); } @Override public String getName() { - return "xpack_lifecycle_move_to_step_action"; + return "xpack_lifecycle_re_run_action"; } @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { - String index = restRequest.param("name"); - ReRunAction.Request request = new ReRunAction.Request(index); + String[] indices = Strings.splitStringByCommaToArray(restRequest.param("index")); + ReRunAction.Request request = new ReRunAction.Request(indices); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(ReRunAction.INSTANCE, request, new RestToXContentListener<>(channel)); diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java index 2ac946a97a226..66bc914976e49 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java @@ -52,29 +52,34 @@ protected Response newResponse() { return new Response(); } + ClusterState innerExecute(ClusterState currentState, String[] indices) { + ClusterState newState = currentState; + for (String index : indices) { + IndexMetaData indexMetaData = currentState.metaData().index(index); + if (indexMetaData == null) { + throw new IllegalArgumentException("index [" + index + "] does not exist"); + } + StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(indexMetaData.getSettings()); + String failedStep = LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.get(indexMetaData.getSettings()); + if (currentStepKey != null && ErrorStep.NAME.equals(currentStepKey.getName()) + && Strings.isNullOrEmpty(failedStep) == false) { + StepKey nextStepKey = new StepKey(currentStepKey.getPhase(), currentStepKey.getAction(), failedStep); + newState = indexLifecycleService.moveClusterStateToStep(currentState, index, currentStepKey, nextStepKey); + } else { + throw new IllegalArgumentException("cannot re-run an action for an index [" + + index + "] that has not encountered an error when running a Lifecycle Policy"); + } + } + return newState; + } + @Override protected void masterOperation(Request request, ClusterState state, ActionListener listener) { - IndexMetaData indexMetaData = state.metaData().index(request.getIndex()); - if (indexMetaData == null) { - listener.onFailure(new IllegalArgumentException("index [" + request.getIndex() + "] does not exist")); - return; - } - clusterService.submitStateUpdateTask("index[" + request.getIndex() + "]-move-to-step", + clusterService.submitStateUpdateTask("ilm-re-run", new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { - IndexMetaData indexMetaData = currentState.metaData().index(request.getIndex()); - StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(indexMetaData.getSettings()); - String failedStep = LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.get(indexMetaData.getSettings()); - if (currentStepKey != null && ErrorStep.NAME.equals(currentStepKey.getName()) - && Strings.isNullOrEmpty(failedStep) == false) { - StepKey nextStepKey = new StepKey(currentStepKey.getPhase(), currentStepKey.getAction(), failedStep); - return indexLifecycleService.moveClusterStateToStep(currentState, request.getIndex(), currentStepKey, nextStepKey); - } else { - listener.onFailure(new IllegalArgumentException("cannot re-run an action for an index [" - + request.getIndex() + "] that has not encountered an error when running a Lifecycle Policy")); - return currentState; - } + return innerExecute(currentState, request.indices()); } @Override diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java index c95bae981cc73..dc2ea17e9c999 100644 --- a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java @@ -697,7 +697,7 @@ private ClusterState buildClusterState(String indexName, Settings.Builder indexS return ClusterState.builder(new ClusterName("my_cluster")).metaData(metadata).build(); } - private void assertClusterStateOnNextStep(ClusterState oldClusterState, Index index, StepKey currentStep, StepKey nextStep, + public static void assertClusterStateOnNextStep(ClusterState oldClusterState, Index index, StepKey currentStep, StepKey nextStep, ClusterState newClusterState, long now) { assertNotSame(oldClusterState, newClusterState); MetaData newMetadata = newClusterState.metaData(); @@ -722,7 +722,7 @@ private void assertClusterStateOnNextStep(ClusterState oldClusterState, Index in assertEquals(now, (long) LifecycleSettings.LIFECYCLE_ACTION_TIME_SETTING.get(newIndexSettings)); } assertEquals(now, (long) LifecycleSettings.LIFECYCLE_STEP_TIME_SETTING.get(newIndexSettings)); - assertFalse(LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.exists(newIndexSettings)); + assertEquals("", LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.get(newIndexSettings)); assertEquals("", LifecycleSettings.LIFECYCLE_STEP_INFO_SETTING.get(newIndexSettings)); } diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java new file mode 100644 index 0000000000000..9f187c4f447ab --- /dev/null +++ b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java @@ -0,0 +1,165 @@ +/* + * 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.indexlifecycle.action; + +import org.elasticsearch.Version; +import org.elasticsearch.action.support.ActionFilter; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.ClusterChangedEvent; +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.IndexMetaData; +import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.node.DiscoveryNode; +import org.elasticsearch.cluster.node.DiscoveryNodes; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.transport.TransportAddress; +import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; +import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; +import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; +import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; +import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTests; +import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; +import org.elasticsearch.xpack.core.indexlifecycle.Step; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunner; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunnerTests; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; +import org.junit.After; +import org.junit.Before; + +import java.time.Clock; +import java.time.Instant; +import java.time.ZoneId; +import java.util.Collections; +import java.util.List; + +import static org.elasticsearch.node.Node.NODE_MASTER_SETTING; +import static org.hamcrest.Matchers.equalTo; +import static org.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class ReRunActionTests extends ESTestCase { + + TransportReRunAction action; + ClusterState initialClusterState; + String[] indices; + LifecyclePolicy policy; + IndexLifecycleService lifecycleService; + + @Before + public void setup() { + String nodeId = randomAlphaOfLength(5); + DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) + .put(NODE_MASTER_SETTING.getKey(), true).build(), + new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); + ClusterService clusterService = mock(ClusterService.class); + doNothing().when(clusterService).addListener(any()); + TransportService transportService = mock(TransportService.class); + when(transportService.getTaskManager()).thenReturn(null); + doNothing().when(transportService).registerRequestHandler(anyString(), anyString(), any(), any()); + ActionFilters actionFilters = mock(ActionFilters.class); + when(actionFilters.filters()).thenReturn(new ActionFilter[] {}); + + String index = randomAlphaOfLength(5); + policy = LifecyclePolicyTests.randomLifecyclePolicy(randomAlphaOfLength(5)); + IndexMetaData indexMetaData = IndexMetaData.builder(index) + .settings(settings(Version.CURRENT) + .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policy.getName()) + ) + .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); + MetaData metaData = MetaData.builder() + .putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(Collections.singletonMap(policy.getName(), + new LifecyclePolicyMetadata(policy, Collections.emptyMap())))) + .persistentSettings(settings(Version.CURRENT).build()) + .put(indexMetaData, false) + .build(); + initialClusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData) + .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) + .build(); + Client client = mock(Client.class); + when(client.settings()).thenReturn(Settings.EMPTY); + when(client.threadPool()).thenReturn(null); + lifecycleService = new IndexLifecycleService(Settings.EMPTY, client, clusterService, + Clock.fixed(Instant.EPOCH, ZoneId.of(randomFrom(ZoneId.getAvailableZoneIds()))), null, () -> 0L); + lifecycleService.clusterChanged(new ClusterChangedEvent("_source", initialClusterState, ClusterState.EMPTY_STATE)); + indices = new String[] { index }; + action = new TransportReRunAction(Settings.EMPTY, transportService, clusterService, + null, actionFilters, null, lifecycleService); + } + + @After + public void close() { + lifecycleService.close(); + } + + public void testInnerExecute() { + List policySteps = policy.toSteps(null, () -> 0L); + IndexMetaData initialIdxMeta = initialClusterState.metaData().index(indices[0]); + IndexMetaData idxMeta = IndexMetaData.builder(initialIdxMeta) + .settings(Settings.builder().put(initialIdxMeta.getSettings()) + .put(LifecycleSettings.LIFECYCLE_PHASE, policySteps.get(0).getKey().getPhase()) + .put(LifecycleSettings.LIFECYCLE_ACTION, policySteps.get(0).getKey().getAction()) + .put(LifecycleSettings.LIFECYCLE_FAILED_STEP, policySteps.get(0).getKey().getName()) + .put(LifecycleSettings.LIFECYCLE_STEP, ErrorStep.NAME) + .build()).build(); + ClusterState clusterState = ClusterState.builder(initialClusterState) + .metaData(MetaData.builder(initialClusterState.metaData()).put(idxMeta, false)).build(); + Step.StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(idxMeta.getSettings()); + + ClusterState nextClusterState = action.innerExecute(clusterState, indices); + Step.StepKey nextStepKey = IndexLifecycleRunner.getCurrentStepKey( + nextClusterState.metaData().index(idxMeta.getIndex()).getSettings()); + + IndexLifecycleRunnerTests.assertClusterStateOnNextStep(clusterState, idxMeta.getIndex(), currentStepKey, nextStepKey, + nextClusterState, 0L); + } + + public void testInnerExecuteIndexNotFound() { + String invalidIndex = indices[0] + "other"; + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> action.innerExecute(initialClusterState, new String[] { invalidIndex })); + assertThat(exception.getMessage(), equalTo("index [" + invalidIndex + "] does not exist")); + } + + public void testInnerExecuteInvalidPolicySetting() { + IndexMetaData initialIdxMeta = initialClusterState.metaData().index(indices[0]); + IndexMetaData idxMeta = IndexMetaData.builder(initialIdxMeta) + .settings(Settings.builder().put(initialIdxMeta.getSettings()) + .put(LifecycleSettings.LIFECYCLE_NAME, (String) null) + .build()).build(); + ClusterState clusterState = ClusterState.builder(initialClusterState) + .metaData(MetaData.builder(initialClusterState.metaData()).put(idxMeta, false)).build(); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> action.innerExecute(clusterState, indices)); + assertThat(exception.getMessage(), equalTo("cannot re-run an action for an index [" + indices[0] + + "] that has not encountered an error when running a Lifecycle Policy")); + } + + public void testInnerExecuteNotOnError() { + List policySteps = policy.toSteps(null, () -> 0L); + IndexMetaData initialIdxMeta = initialClusterState.metaData().index(indices[0]); + IndexMetaData idxMeta = IndexMetaData.builder(initialIdxMeta) + .settings(Settings.builder().put(initialIdxMeta.getSettings()) + .put(LifecycleSettings.LIFECYCLE_PHASE, policySteps.get(0).getKey().getPhase()) + .put(LifecycleSettings.LIFECYCLE_ACTION, policySteps.get(0).getKey().getAction()) + .put(LifecycleSettings.LIFECYCLE_STEP, policySteps.get(0).getKey().getName()) + .build()).build(); + ClusterState clusterState = ClusterState.builder(initialClusterState) + .metaData(MetaData.builder(initialClusterState.metaData()).put(idxMeta, false)).build(); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> action.innerExecute(clusterState, indices)); + assertThat(exception.getMessage(), equalTo("cannot re-run an action for an index [" + indices[0] + + "] that has not encountered an error when running a Lifecycle Policy")); + } +} diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json index cca6900d2b449..a7f01b026ab9f 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json @@ -8,7 +8,7 @@ "parts": { "index": { "type" : "string", - "description" : "The name of the index whose failed lifecycle step is to be re-run" + "description" : "The name of the indices (comma-separated) whose failed lifecycle step is to be re-run" } }, "params": { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml index 442a62e1a7eec..1918fe32a098f 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml @@ -54,18 +54,48 @@ teardown: --- "Test Basic Re-run": + - skip: + version: "all" + reason: "NOCOMMIT: needs to be insensitive to timing" + - do: + acknowlege: true + xpack.index_lifecycle.put_lifecycle: + lifecycle: "my_errored_lifecycle" + body: | + { + "policy": { + "type": "timeseries", + "phases": { + "warm": { + "after": "0s", + "actions": { + "shrink": { + "number_of_shards": 2 + } + } + } + } + } + } - do: indices.create: index: my_index body: settings: - index.lifecycle.name: "my_lifecycle" - index.lifecycle.step: "error" - index.lifecycle.action: "pre-pre-readonly" - index.lifecycle.phase: "hot" - index.lifecycle.failed_step: "after" + index.lifecycle.name: "my_errored_lifecycle" + number_of_shards: 3 + number_of_replicas: 0 + - do: + acknowledge: true + indices.get: + index: my_index + - match: { my_index.settings.index.lifecycle.name: "my_errored_lifecycle" } + - match: { my_index.settings.index.lifecycle.step: "ERROR" } + - match: { my_index.settings.index.lifecycle.failed_step: "shrink" } + - match: { my_index.settings.index.lifecycle.action: "shrink" } + - match: { my_index.settings.index.lifecycle.phase: "warm" } - do: acknowledge: true @@ -76,10 +106,10 @@ teardown: acknowledge: true indices.get: index: my_index - - match: { my_index.settings.index.lifecycle.name: "my_lifecycle" } - - match: { my_index.settings.index.lifecycle.step: "after" } - - match: { my_index.settings.index.lifecycle.action: "pre-pre-readonly" } - - match: { my_index.settings.index.lifecycle.phase: "hot" } + - match: { my_index.settings.index.lifecycle.name: "my_errored_lifecycle" } + - match: { my_index.settings.index.lifecycle.step: "shrink" } + - match: { my_index.settings.index.lifecycle.action: "shrink" } + - match: { my_index.settings.index.lifecycle.phase: "warm" } --- "Test Invalid Re-run With Non-errored Policy": @@ -91,11 +121,6 @@ teardown: settings: index.lifecycle.name: "my_lifecycle" - - do: - acknowledge: true - xpack.index_lifecycle.rerun: - index: "my_index" - - do: catch: bad_request xpack.index_lifecycle.rerun: From 8c34d147e9a7be34db99164e8d90daaec44b05a2 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Wed, 23 May 2018 18:00:11 -0700 Subject: [PATCH 3/9] update action to be indices rather than cluster --- .../xpack/core/indexlifecycle/action/ReRunAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java index 9358c6badc1fc..de08b41e9fdc7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java @@ -28,7 +28,7 @@ public class ReRunAction extends Action { public static final ReRunAction INSTANCE = new ReRunAction(); - public static final String NAME = "cluster:admin/xpack/index_lifecycle/_rerun/post"; + public static final String NAME = "indices:admin/xpack/index_lifecycle/_rerun/post"; protected ReRunAction() { super(NAME); From 9180b3c329ce86719463266a32c36307725cf6e6 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Wed, 23 May 2018 18:37:45 -0700 Subject: [PATCH 4/9] fix hash method warning --- .../xpack/core/indexlifecycle/action/ReRunAction.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java index de08b41e9fdc7..6e8fcb66ed826 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java @@ -141,7 +141,7 @@ public void writeTo(StreamOutput out) throws IOException { @Override public int hashCode() { - return Objects.hash(indices); + return Arrays.hashCode(indices); } @Override From 9e1dd2b6feb67bedd619888b7ce02c8aedb066e2 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Wed, 23 May 2018 20:46:22 -0700 Subject: [PATCH 5/9] remove nocommitted rest test, checkStyle so no fan --- .../test/index_lifecycle/30_rerun.yml | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml index 1918fe32a098f..4009031b79f2c 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml @@ -52,65 +52,6 @@ teardown: xpack.index_lifecycle.get_lifecycle: lifecycle: "my_lifecycle" ---- -"Test Basic Re-run": - - skip: - version: "all" - reason: "NOCOMMIT: needs to be insensitive to timing" - - do: - acknowlege: true - xpack.index_lifecycle.put_lifecycle: - lifecycle: "my_errored_lifecycle" - body: | - { - "policy": { - "type": "timeseries", - "phases": { - "warm": { - "after": "0s", - "actions": { - "shrink": { - "number_of_shards": 2 - } - } - } - } - } - } - - - do: - indices.create: - index: my_index - body: - settings: - index.lifecycle.name: "my_errored_lifecycle" - number_of_shards: 3 - number_of_replicas: 0 - - - do: - acknowledge: true - indices.get: - index: my_index - - match: { my_index.settings.index.lifecycle.name: "my_errored_lifecycle" } - - match: { my_index.settings.index.lifecycle.step: "ERROR" } - - match: { my_index.settings.index.lifecycle.failed_step: "shrink" } - - match: { my_index.settings.index.lifecycle.action: "shrink" } - - match: { my_index.settings.index.lifecycle.phase: "warm" } - - - do: - acknowledge: true - xpack.index_lifecycle.rerun: - index: "my_index" - - - do: - acknowledge: true - indices.get: - index: my_index - - match: { my_index.settings.index.lifecycle.name: "my_errored_lifecycle" } - - match: { my_index.settings.index.lifecycle.step: "shrink" } - - match: { my_index.settings.index.lifecycle.action: "shrink" } - - match: { my_index.settings.index.lifecycle.phase: "warm" } - --- "Test Invalid Re-run With Non-errored Policy": From a9c72121dc7187584fd4e1478e0b4b3dfdf26c5f Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Fri, 25 May 2018 12:30:03 -0700 Subject: [PATCH 6/9] move step transition logic into IndexLifecycleRunner --- .../indexlifecycle/IndexLifecycleRunner.java | 22 +++ .../indexlifecycle/IndexLifecycleService.java | 12 ++ .../action/TransportReRunAction.java | 25 +-- .../IndexLifecycleRunnerTests.java | 77 +++++++- .../action/ReRunActionTests.java | 165 ------------------ 5 files changed, 113 insertions(+), 188 deletions(-) delete mode 100644 x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 0b3dd5f1e8c61..81a6a82e28227 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -32,6 +32,7 @@ import java.io.IOException; import java.util.function.LongSupplier; +import java.util.function.Supplier; public class IndexLifecycleRunner { private static final Logger logger = ESLoggerFactory.getLogger(IndexLifecycleRunner.class); @@ -194,6 +195,27 @@ static ClusterState moveClusterStateToErrorStep(Index index, ClusterState cluste return newClusterStateBuilder.build(); } + ClusterState moveClusterStateToFailedStep(ClusterState currentState, String[] indices) { + ClusterState newState = currentState; + for (String index : indices) { + IndexMetaData indexMetaData = currentState.metaData().index(index); + if (indexMetaData == null) { + throw new IllegalArgumentException("index [" + index + "] does not exist"); + } + StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(indexMetaData.getSettings()); + String failedStep = LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.get(indexMetaData.getSettings()); + if (currentStepKey != null && ErrorStep.NAME.equals(currentStepKey.getName()) + && Strings.isNullOrEmpty(failedStep) == false) { + StepKey nextStepKey = new StepKey(currentStepKey.getPhase(), currentStepKey.getAction(), failedStep); + newState = moveClusterStateToStep(index, currentState, currentStepKey, nextStepKey, nowSupplier, stepRegistry); + } else { + throw new IllegalArgumentException("cannot re-run an action for an index [" + + index + "] that has not encountered an error when running a Lifecycle Policy"); + } + } + return newState; + } + private static Settings.Builder moveIndexSettingsToNextStep(Settings existingSettings, StepKey currentStep, StepKey nextStep, LongSupplier nowSupplier) { long nowAsMillis = nowSupplier.getAsLong(); diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java index 0324b2237effb..e438652a07fbb 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java @@ -67,6 +67,10 @@ public ClusterState moveClusterStateToStep(ClusterState currentState, String ind nowSupplier, policyRegistry); } + public ClusterState moveClusterStateToFailedStep(ClusterState currentState, String[] indices) { + return lifecycleRunner.moveClusterStateToFailedStep(currentState, indices); + } + SchedulerEngine getScheduler() { return scheduler.get(); } @@ -75,6 +79,14 @@ SchedulerEngine.Job getScheduledJob() { return scheduledJob; } + public LongSupplier getNowSupplier() { + return nowSupplier; + } + + public PolicyStepsRegistry getPolicyRegistry() { + return policyRegistry; + } + @Override public void clusterChanged(ClusterChangedEvent event) { if (event.localNodeMaster()) { // only act if we are master, otherwise keep idle until elected diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java index 66bc914976e49..ed79fe2b5d5c9 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java @@ -31,7 +31,9 @@ import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; public class TransportReRunAction extends TransportMasterNodeAction { + IndexLifecycleService indexLifecycleService; + @Inject public TransportReRunAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, @@ -52,34 +54,13 @@ protected Response newResponse() { return new Response(); } - ClusterState innerExecute(ClusterState currentState, String[] indices) { - ClusterState newState = currentState; - for (String index : indices) { - IndexMetaData indexMetaData = currentState.metaData().index(index); - if (indexMetaData == null) { - throw new IllegalArgumentException("index [" + index + "] does not exist"); - } - StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(indexMetaData.getSettings()); - String failedStep = LifecycleSettings.LIFECYCLE_FAILED_STEP_SETTING.get(indexMetaData.getSettings()); - if (currentStepKey != null && ErrorStep.NAME.equals(currentStepKey.getName()) - && Strings.isNullOrEmpty(failedStep) == false) { - StepKey nextStepKey = new StepKey(currentStepKey.getPhase(), currentStepKey.getAction(), failedStep); - newState = indexLifecycleService.moveClusterStateToStep(currentState, index, currentStepKey, nextStepKey); - } else { - throw new IllegalArgumentException("cannot re-run an action for an index [" - + index + "] that has not encountered an error when running a Lifecycle Policy"); - } - } - return newState; - } - @Override protected void masterOperation(Request request, ClusterState state, ActionListener listener) { clusterService.submitStateUpdateTask("ilm-re-run", new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { - return innerExecute(currentState, request.indices()); + return indexLifecycleService.moveClusterStateToFailedStep(currentState, request.indices()); } @Override diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java index dc2ea17e9c999..245fbe0c4d901 100644 --- a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.ClusterStateWaitStep; import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; import org.elasticsearch.xpack.core.indexlifecycle.InitializePolicyContextStep; -import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.MockStep; @@ -674,6 +673,82 @@ public void testMoveClusterStateToErrorStep() throws IOException { assertClusterStateOnErrorStep(clusterState, index, currentStep, newClusterState, cause, now); } + public void testMoveClusterStateToFailedStep() { + String indexName = "my_index"; + String[] indices = new String[] { indexName }; + String policyName = "my_policy"; + long now = randomNonNegativeLong(); + StepKey failedStepKey = new StepKey("current_phase", "current_action", "current_step"); + StepKey errorStepKey = new StepKey(failedStepKey.getPhase(), failedStepKey.getAction(), ErrorStep.NAME); + Step step = new MockStep(failedStepKey, null); + PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); + Settings.Builder indexSettingsBuilder = Settings.builder() + .put(LifecycleSettings.LIFECYCLE_NAME, policyName) + .put(LifecycleSettings.LIFECYCLE_PHASE, errorStepKey.getPhase()) + .put(LifecycleSettings.LIFECYCLE_ACTION, errorStepKey.getAction()) + .put(LifecycleSettings.LIFECYCLE_FAILED_STEP, failedStepKey.getName()) + .put(LifecycleSettings.LIFECYCLE_STEP, errorStepKey.getName()); + ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder); + Index index = clusterState.metaData().index(indexName).getIndex(); + IndexLifecycleRunner runner = new IndexLifecycleRunner(policyRegistry, null, () -> now); + ClusterState nextClusterState = runner.moveClusterStateToFailedStep(clusterState, indices); + IndexLifecycleRunnerTests.assertClusterStateOnNextStep(clusterState, index, errorStepKey, failedStepKey, + nextClusterState, now); + } + + public void testMoveClusterStateToFailedStepIndexNotFound() { + String existingIndexName = "my_index"; + String invalidIndexName = "does_not_exist"; + ClusterState clusterState = buildClusterState(existingIndexName, Settings.builder()); + IndexLifecycleRunner runner = new IndexLifecycleRunner(null, null, () -> 0L); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> runner.moveClusterStateToFailedStep(clusterState, new String[] { invalidIndexName })); + assertThat(exception.getMessage(), equalTo("index [" + invalidIndexName + "] does not exist")); + } +// + public void testMoveClusterStateToFailedStepInvalidPolicySetting() { + String indexName = "my_index"; + String[] indices = new String[] { indexName }; + String policyName = "my_policy"; + long now = randomNonNegativeLong(); + StepKey failedStepKey = new StepKey("current_phase", "current_action", "current_step"); + StepKey errorStepKey = new StepKey(failedStepKey.getPhase(), failedStepKey.getAction(), ErrorStep.NAME); + Step step = new MockStep(failedStepKey, null); + PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); + Settings.Builder indexSettingsBuilder = Settings.builder() + .put(LifecycleSettings.LIFECYCLE_NAME, (String) null) + .put(LifecycleSettings.LIFECYCLE_PHASE, errorStepKey.getPhase()) + .put(LifecycleSettings.LIFECYCLE_ACTION, errorStepKey.getAction()) + .put(LifecycleSettings.LIFECYCLE_FAILED_STEP, failedStepKey.getName()) + .put(LifecycleSettings.LIFECYCLE_STEP, errorStepKey.getName()); + ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder); + IndexLifecycleRunner runner = new IndexLifecycleRunner(policyRegistry, null, () -> now); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> runner.moveClusterStateToFailedStep(clusterState, indices)); + assertThat(exception.getMessage(), equalTo("index [" + indexName + "] is not associated with an Index Lifecycle Policy")); + } + + public void testMoveClusterStateToFailedNotOnError() { + String indexName = "my_index"; + String[] indices = new String[] { indexName }; + String policyName = "my_policy"; + long now = randomNonNegativeLong(); + StepKey failedStepKey = new StepKey("current_phase", "current_action", "current_step"); + Step step = new MockStep(failedStepKey, null); + PolicyStepsRegistry policyRegistry = createOneStepPolicyStepRegistry(policyName, step); + Settings.Builder indexSettingsBuilder = Settings.builder() + .put(LifecycleSettings.LIFECYCLE_NAME, (String) null) + .put(LifecycleSettings.LIFECYCLE_PHASE, failedStepKey.getPhase()) + .put(LifecycleSettings.LIFECYCLE_ACTION, failedStepKey.getAction()) + .put(LifecycleSettings.LIFECYCLE_STEP, failedStepKey.getName()); + ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder); + IndexLifecycleRunner runner = new IndexLifecycleRunner(policyRegistry, null, () -> now); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> runner.moveClusterStateToFailedStep(clusterState, indices)); + assertThat(exception.getMessage(), equalTo("cannot re-run an action for an index [" + indices[0] + + "] that has not encountered an error when running a Lifecycle Policy")); + } + public void testAddStepInfoToClusterState() throws IOException { String indexName = "my_index"; StepKey currentStep = new StepKey("current_phase", "current_action", "current_step"); diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java deleted file mode 100644 index 9f187c4f447ab..0000000000000 --- a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/action/ReRunActionTests.java +++ /dev/null @@ -1,165 +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.indexlifecycle.action; - -import org.elasticsearch.Version; -import org.elasticsearch.action.support.ActionFilter; -import org.elasticsearch.action.support.ActionFilters; -import org.elasticsearch.client.Client; -import org.elasticsearch.cluster.ClusterChangedEvent; -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.IndexMetaData; -import org.elasticsearch.cluster.metadata.MetaData; -import org.elasticsearch.cluster.node.DiscoveryNode; -import org.elasticsearch.cluster.node.DiscoveryNodes; -import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.transport.TransportAddress; -import org.elasticsearch.test.ESTestCase; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; -import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; -import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTests; -import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; -import org.elasticsearch.xpack.core.indexlifecycle.Step; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunner; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunnerTests; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; -import org.junit.After; -import org.junit.Before; - -import java.time.Clock; -import java.time.Instant; -import java.time.ZoneId; -import java.util.Collections; -import java.util.List; - -import static org.elasticsearch.node.Node.NODE_MASTER_SETTING; -import static org.hamcrest.Matchers.equalTo; -import static org.mockito.Matchers.any; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class ReRunActionTests extends ESTestCase { - - TransportReRunAction action; - ClusterState initialClusterState; - String[] indices; - LifecyclePolicy policy; - IndexLifecycleService lifecycleService; - - @Before - public void setup() { - String nodeId = randomAlphaOfLength(5); - DiscoveryNode masterNode = DiscoveryNode.createLocal(settings(Version.CURRENT) - .put(NODE_MASTER_SETTING.getKey(), true).build(), - new TransportAddress(TransportAddress.META_ADDRESS, 9300), nodeId); - ClusterService clusterService = mock(ClusterService.class); - doNothing().when(clusterService).addListener(any()); - TransportService transportService = mock(TransportService.class); - when(transportService.getTaskManager()).thenReturn(null); - doNothing().when(transportService).registerRequestHandler(anyString(), anyString(), any(), any()); - ActionFilters actionFilters = mock(ActionFilters.class); - when(actionFilters.filters()).thenReturn(new ActionFilter[] {}); - - String index = randomAlphaOfLength(5); - policy = LifecyclePolicyTests.randomLifecyclePolicy(randomAlphaOfLength(5)); - IndexMetaData indexMetaData = IndexMetaData.builder(index) - .settings(settings(Version.CURRENT) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policy.getName()) - ) - .numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build(); - MetaData metaData = MetaData.builder() - .putCustom(IndexLifecycleMetadata.TYPE, new IndexLifecycleMetadata(Collections.singletonMap(policy.getName(), - new LifecyclePolicyMetadata(policy, Collections.emptyMap())))) - .persistentSettings(settings(Version.CURRENT).build()) - .put(indexMetaData, false) - .build(); - initialClusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData) - .nodes(DiscoveryNodes.builder().localNodeId(nodeId).masterNodeId(nodeId).add(masterNode).build()) - .build(); - Client client = mock(Client.class); - when(client.settings()).thenReturn(Settings.EMPTY); - when(client.threadPool()).thenReturn(null); - lifecycleService = new IndexLifecycleService(Settings.EMPTY, client, clusterService, - Clock.fixed(Instant.EPOCH, ZoneId.of(randomFrom(ZoneId.getAvailableZoneIds()))), null, () -> 0L); - lifecycleService.clusterChanged(new ClusterChangedEvent("_source", initialClusterState, ClusterState.EMPTY_STATE)); - indices = new String[] { index }; - action = new TransportReRunAction(Settings.EMPTY, transportService, clusterService, - null, actionFilters, null, lifecycleService); - } - - @After - public void close() { - lifecycleService.close(); - } - - public void testInnerExecute() { - List policySteps = policy.toSteps(null, () -> 0L); - IndexMetaData initialIdxMeta = initialClusterState.metaData().index(indices[0]); - IndexMetaData idxMeta = IndexMetaData.builder(initialIdxMeta) - .settings(Settings.builder().put(initialIdxMeta.getSettings()) - .put(LifecycleSettings.LIFECYCLE_PHASE, policySteps.get(0).getKey().getPhase()) - .put(LifecycleSettings.LIFECYCLE_ACTION, policySteps.get(0).getKey().getAction()) - .put(LifecycleSettings.LIFECYCLE_FAILED_STEP, policySteps.get(0).getKey().getName()) - .put(LifecycleSettings.LIFECYCLE_STEP, ErrorStep.NAME) - .build()).build(); - ClusterState clusterState = ClusterState.builder(initialClusterState) - .metaData(MetaData.builder(initialClusterState.metaData()).put(idxMeta, false)).build(); - Step.StepKey currentStepKey = IndexLifecycleRunner.getCurrentStepKey(idxMeta.getSettings()); - - ClusterState nextClusterState = action.innerExecute(clusterState, indices); - Step.StepKey nextStepKey = IndexLifecycleRunner.getCurrentStepKey( - nextClusterState.metaData().index(idxMeta.getIndex()).getSettings()); - - IndexLifecycleRunnerTests.assertClusterStateOnNextStep(clusterState, idxMeta.getIndex(), currentStepKey, nextStepKey, - nextClusterState, 0L); - } - - public void testInnerExecuteIndexNotFound() { - String invalidIndex = indices[0] + "other"; - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> action.innerExecute(initialClusterState, new String[] { invalidIndex })); - assertThat(exception.getMessage(), equalTo("index [" + invalidIndex + "] does not exist")); - } - - public void testInnerExecuteInvalidPolicySetting() { - IndexMetaData initialIdxMeta = initialClusterState.metaData().index(indices[0]); - IndexMetaData idxMeta = IndexMetaData.builder(initialIdxMeta) - .settings(Settings.builder().put(initialIdxMeta.getSettings()) - .put(LifecycleSettings.LIFECYCLE_NAME, (String) null) - .build()).build(); - ClusterState clusterState = ClusterState.builder(initialClusterState) - .metaData(MetaData.builder(initialClusterState.metaData()).put(idxMeta, false)).build(); - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> action.innerExecute(clusterState, indices)); - assertThat(exception.getMessage(), equalTo("cannot re-run an action for an index [" + indices[0] - + "] that has not encountered an error when running a Lifecycle Policy")); - } - - public void testInnerExecuteNotOnError() { - List policySteps = policy.toSteps(null, () -> 0L); - IndexMetaData initialIdxMeta = initialClusterState.metaData().index(indices[0]); - IndexMetaData idxMeta = IndexMetaData.builder(initialIdxMeta) - .settings(Settings.builder().put(initialIdxMeta.getSettings()) - .put(LifecycleSettings.LIFECYCLE_PHASE, policySteps.get(0).getKey().getPhase()) - .put(LifecycleSettings.LIFECYCLE_ACTION, policySteps.get(0).getKey().getAction()) - .put(LifecycleSettings.LIFECYCLE_STEP, policySteps.get(0).getKey().getName()) - .build()).build(); - ClusterState clusterState = ClusterState.builder(initialClusterState) - .metaData(MetaData.builder(initialClusterState.metaData()).put(idxMeta, false)).build(); - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> action.innerExecute(clusterState, indices)); - assertThat(exception.getMessage(), equalTo("cannot re-run an action for an index [" + indices[0] - + "] that has not encountered an error when running a Lifecycle Policy")); - } -} From 46fb8879f27f8be89ca62e1a998268c7c2fd5c7d Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Tue, 29 May 2018 12:35:05 -0700 Subject: [PATCH 7/9] rename rerun to retry --- .../{ReRunAction.java => RetryAction.java} | 8 ++++---- .../action/ReRunRequestTests.java | 2 +- .../action/ReRunResponseTests.java | 2 +- .../xpack/indexlifecycle/IndexLifecycle.java | 10 +++++----- .../indexlifecycle/IndexLifecycleRunner.java | 2 +- ...stReRunAction.java => RestRetryAction.java} | 18 +++++++----------- ...unAction.java => TransportRetryAction.java} | 18 ++++++------------ ...n.json => xpack.index_lifecycle.retry.json} | 8 ++++---- .../{30_rerun.yml => 30_retry.yml} | 14 +++++++------- 9 files changed, 36 insertions(+), 46 deletions(-) rename x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/{ReRunAction.java => RetryAction.java} (95%) rename x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/{RestReRunAction.java => RestRetryAction.java} (69%) rename x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/{TransportReRunAction.java => TransportRetryAction.java} (78%) rename x-pack/plugin/src/test/resources/rest-api-spec/api/{xpack.index_lifecycle.rerun.json => xpack.index_lifecycle.retry.json} (63%) rename x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/{30_rerun.yml => 30_retry.yml} (81%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java similarity index 95% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java index 6e8fcb66ed826..ded1bc7f1093b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/RetryAction.java @@ -26,11 +26,11 @@ import java.util.EnumSet; import java.util.Objects; -public class ReRunAction extends Action { - public static final ReRunAction INSTANCE = new ReRunAction(); - public static final String NAME = "indices:admin/xpack/index_lifecycle/_rerun/post"; +public class RetryAction extends Action { + public static final RetryAction INSTANCE = new RetryAction(); + public static final String NAME = "indices:admin/xpack/index_lifecycle/_retry/post"; - protected ReRunAction() { + protected RetryAction() { super(NAME); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java index 6f6f467bb533b..6675d27938ec3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/ReRunRequestTests.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction.Request; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Request; public class ReRunRequestTests extends AbstractStreamableTestCase { 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/ReRunResponseTests.java index a1d4ab75faa9a..4cfb64482f8de 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/ReRunResponseTests.java @@ -7,7 +7,7 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction.Response; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Response; public class ReRunResponseTests extends AbstractStreamableTestCase { diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java index c8bcb3e5c76bd..2fb89b1a59a84 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java @@ -38,17 +38,17 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; import org.elasticsearch.xpack.indexlifecycle.action.RestDeleteLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestGetLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.RestPutLifecycleAction; -import org.elasticsearch.xpack.indexlifecycle.action.RestReRunAction; +import org.elasticsearch.xpack.indexlifecycle.action.RestRetryAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportDeleteLifcycleAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportGetLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportPutLifecycleAction; -import org.elasticsearch.xpack.indexlifecycle.action.TransportReRunAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportRetryAction; import java.time.Clock; import java.util.ArrayList; @@ -143,7 +143,7 @@ public List getRestHandlers(Settings settings, RestController restC new RestGetLifecycleAction(settings, restController), new RestDeleteLifecycleAction(settings, restController), new RestMoveToStepAction(settings, restController), - new RestReRunAction(settings, restController) + new RestRetryAction(settings, restController) ); } @@ -157,7 +157,7 @@ public List getRestHandlers(Settings settings, RestController restC new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class), new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifcycleAction.class), new ActionHandler<>(MoveToStepAction.INSTANCE, TransportMoveToStepAction.class), - new ActionHandler<>(ReRunAction.INSTANCE, TransportReRunAction.class)); + new ActionHandler<>(RetryAction.INSTANCE, TransportRetryAction.class)); } @Override diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java index 81a6a82e28227..fc8038028f64a 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java @@ -209,7 +209,7 @@ ClusterState moveClusterStateToFailedStep(ClusterState currentState, String[] in StepKey nextStepKey = new StepKey(currentStepKey.getPhase(), currentStepKey.getAction(), failedStep); newState = moveClusterStateToStep(index, currentState, currentStepKey, nextStepKey, nowSupplier, stepRegistry); } else { - throw new IllegalArgumentException("cannot re-run an action for an index [" + throw new IllegalArgumentException("cannot retry an action for an index [" + index + "] that has not encountered an error when running a Lifecycle Policy"); } } diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java similarity index 69% rename from x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java rename to x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java index ec810e3c34a94..c021651bdf3ce 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestReRunAction.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestRetryAction.java @@ -9,35 +9,31 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; import org.elasticsearch.xpack.indexlifecycle.IndexLifecycle; -import java.io.IOException; +public class RestRetryAction extends BaseRestHandler { -public class RestReRunAction extends BaseRestHandler { - - public RestReRunAction(Settings settings, RestController controller) { + public RestRetryAction(Settings settings, RestController controller) { super(settings); - controller.registerHandler(RestRequest.Method.POST, IndexLifecycle.BASE_PATH + "_rerun/{index}", this); + controller.registerHandler(RestRequest.Method.POST, IndexLifecycle.BASE_PATH + "_retry/{index}", this); } @Override public String getName() { - return "xpack_lifecycle_re_run_action"; + return "xpack_lifecycle_retry_action"; } @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { String[] indices = Strings.splitStringByCommaToArray(restRequest.param("index")); - ReRunAction.Request request = new ReRunAction.Request(indices); + RetryAction.Request request = new RetryAction.Request(indices); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); - return channel -> client.execute(ReRunAction.INSTANCE, request, new RestToXContentListener<>(channel)); + return channel -> client.execute(RetryAction.INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRetryAction.java similarity index 78% rename from x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java rename to x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRetryAction.java index ed79fe2b5d5c9..ede40b703bb3d 100644 --- a/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportReRunAction.java +++ b/x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportRetryAction.java @@ -13,33 +13,27 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.block.ClusterBlockLevel; -import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.Strings; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; -import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; -import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction.Request; -import org.elasticsearch.xpack.core.indexlifecycle.action.ReRunAction.Response; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunner; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Request; +import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction.Response; import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleService; -public class TransportReRunAction extends TransportMasterNodeAction { +public class TransportRetryAction extends TransportMasterNodeAction { IndexLifecycleService indexLifecycleService; @Inject - public TransportReRunAction(Settings settings, TransportService transportService, ClusterService clusterService, + public TransportRetryAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver, IndexLifecycleService indexLifecycleService) { - super(settings, ReRunAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + super(settings, RetryAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, Request::new); this.indexLifecycleService = indexLifecycleService; } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json similarity index 63% rename from x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json rename to x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json index a7f01b026ab9f..9ac94985aa693 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.rerun.json +++ b/x-pack/plugin/src/test/resources/rest-api-spec/api/xpack.index_lifecycle.retry.json @@ -1,14 +1,14 @@ { - "xpack.index_lifecycle.rerun": { + "xpack.index_lifecycle.retry": { "documentation": "http://www.elastic.co/guide/en/index_lifecycle/current/index_lifecycle.html", "methods": [ "POST" ], "url": { - "path": "/_xpack/index_lifecycle/_rerun/{index}", - "paths": ["/_xpack/index_lifecycle/_rerun/{index}"], + "path": "/_xpack/index_lifecycle/_retry/{index}", + "paths": ["/_xpack/index_lifecycle/_retry/{index}"], "parts": { "index": { "type" : "string", - "description" : "The name of the indices (comma-separated) whose failed lifecycle step is to be re-run" + "description" : "The name of the indices (comma-separated) whose failed lifecycle step is to be retry" } }, "params": { diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml similarity index 81% rename from x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml rename to x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml index 4009031b79f2c..d9fda3afe904f 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_rerun.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml @@ -53,7 +53,7 @@ teardown: lifecycle: "my_lifecycle" --- -"Test Invalid Re-run With Non-errored Policy": +"Test Invalid Retry With Non-errored Policy": - do: indices.create: @@ -64,10 +64,10 @@ teardown: - do: catch: bad_request - xpack.index_lifecycle.rerun: + xpack.index_lifecycle.retry: index: "my_index" - match: { error.root_cause.0.type: "illegal_argument_exception" } - - match: { error.root_cause.0.reason: "cannot re-run an action for an index [my_index] that has not encountered an error when running a Lifecycle Policy" } + - match: { error.root_cause.0.reason: "cannot retry an action for an index [my_index] that has not encountered an error when running a Lifecycle Policy" } - do: acknowledge: true @@ -80,7 +80,7 @@ teardown: --- -"Test Invalid Re-run With No Policy": +"Test Invalid Retry With No Policy": - do: indices.create: @@ -88,10 +88,10 @@ teardown: - do: catch: bad_request - xpack.index_lifecycle.rerun: + xpack.index_lifecycle.retry: index: "my_index" - match: { error.root_cause.0.type: "illegal_argument_exception" } - - match: { error.root_cause.0.reason: "cannot re-run an action for an index [my_index] that has not encountered an error when running a Lifecycle Policy" } + - match: { error.root_cause.0.reason: "cannot retry an action for an index [my_index] that has not encountered an error when running a Lifecycle Policy" } --- "Test Invalid Re-run With Invalid Index": @@ -101,7 +101,7 @@ teardown: - do: catch: bad_request - xpack.index_lifecycle.rerun: + xpack.index_lifecycle.retry: index: "does_not_exist" - match: { error.root_cause.0.type: "illegal_argument_exception" } - match: { error.root_cause.0.reason: "index [does_not_exist] does not exist" } From a066aa87b7e4374f30db8099074cc0d35dc2bc72 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Tue, 29 May 2018 15:07:11 -0700 Subject: [PATCH 8/9] fix test to reflect latest changes in index-lifecycle --- .../resources/rest-api-spec/test/index_lifecycle/30_retry.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml index d9fda3afe904f..b5bef88489664 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/30_retry.yml @@ -75,8 +75,8 @@ teardown: index: my_index - match: { my_index.settings.index.lifecycle.name: "my_lifecycle" } - match: { my_index.settings.index.lifecycle.step: "after" } - - match: { my_index.settings.index.lifecycle.action: "pre-pre-readonly" } - - match: { my_index.settings.index.lifecycle.phase: "hot" } + - match: { my_index.settings.index.lifecycle.action: "after" } + - match: { my_index.settings.index.lifecycle.phase: "new" } --- From 3ee9a5b6d0a135b967d9d93772876380547f2235 Mon Sep 17 00:00:00 2001 From: Tal Levy Date: Tue, 29 May 2018 16:57:29 -0700 Subject: [PATCH 9/9] fix runner test --- .../xpack/indexlifecycle/IndexLifecycleRunnerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java index b6a700c3616f1..d3e970654351c 100644 --- a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java @@ -746,7 +746,7 @@ public void testMoveClusterStateToFailedNotOnError() { IndexLifecycleRunner runner = new IndexLifecycleRunner(policyRegistry, null, () -> now); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> runner.moveClusterStateToFailedStep(clusterState, indices)); - assertThat(exception.getMessage(), equalTo("cannot re-run an action for an index [" + indices[0] + assertThat(exception.getMessage(), equalTo("cannot retry an action for an index [" + indices[0] + "] that has not encountered an error when running a Lifecycle Policy")); }