From cf740bab8252bf0543151ed634ff9bb7277a5a0d Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Fri, 3 Aug 2018 13:18:30 +0100 Subject: [PATCH 1/7] Adds REST client support for PutOperationMode in ILM --- .../client/IndexLifecycleClient.java | 30 +++++++ .../client/RequestConverters.java | 13 +++ .../IndexLifecycleMetadata.java | 1 + .../action/GetStatusAction.java | 2 +- .../action/PutOperationModeAction.java | 82 +------------------ .../indexlifecycle/IndexLifecycleService.java | 2 +- .../OperationModeUpdateTask.java | 2 +- .../action/RestStartAction.java | 5 +- .../indexlifecycle/action/RestStopAction.java | 5 +- .../action/TransportGetStatusAction.java | 2 +- .../action/TransportPutLifecycleAction.java | 2 +- .../TransportPutOperationModeAction.java | 22 ++--- .../ExecuteStepsUpdateTaskTests.java | 2 +- .../IndexLifecycleMetadataTests.java | 2 +- .../IndexLifecycleRunnerTests.java | 2 +- .../IndexLifecycleServiceTests.java | 2 +- .../OperationModeUpdateTaskTests.java | 2 +- .../PolicyStepsRegistryTests.java | 2 +- .../xpack}/indexlifecycle/OperationMode.java | 2 +- .../PutOperationModeRequest.java | 71 ++++++++++++++++ .../PutOperationModeResponse.java | 25 ++++++ .../indexlifecycle/OperationModeTests.java | 26 ++++++ .../PutOperationModeRequestTests.java | 46 +++++++++++ .../PutOperationModeResponseTests.java | 36 ++++++++ 24 files changed, 281 insertions(+), 105 deletions(-) rename x-pack/{plugin/core/src/main/java/org/elasticsearch/xpack/core => protocol/src/main/java/org/elasticsearch/protocol/xpack}/indexlifecycle/OperationMode.java (95%) create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java create mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java create mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java create mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java index eaeaa147bff85..22ea8e22e7001 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java @@ -20,6 +20,8 @@ package org.elasticsearch.client; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; @@ -65,6 +67,34 @@ public void setIndexLifecyclePolicyAsync(SetIndexLifecyclePolicyRequest request, SetIndexLifecyclePolicyResponse::fromXContent, listener, emptySet()); } + /** + * Set the operation mode for the Index Lifecycle Management feature. + * See + * the docs for more. + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @return the response + * @throws IOException in case there is a problem sending the request or parsing back the response + */ + public PutOperationModeResponse putOperationMode(PutOperationModeRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::putOperationMode, options, + PutOperationModeResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously set the operation mode for the Index Lifecycle Management feature. + * See + * the docs for more. + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @param listener the listener to be notified upon request completion + */ + public void putOperationModeAsync(PutOperationModeRequest request, RequestOptions options, + ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::putOperationMode, options, + PutOperationModeResponse::fromXContent, listener, emptySet()); + } + /** * Explain the lifecycle state for an index * See diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 45491147200c7..361ef31bbd632 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -109,6 +109,8 @@ import org.elasticsearch.protocol.xpack.XPackInfoRequest; import org.elasticsearch.protocol.xpack.license.GetLicenseRequest; import org.elasticsearch.protocol.xpack.XPackUsageRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.license.PutLicenseRequest; @@ -1170,6 +1172,17 @@ static Request setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest setPolicyR return request; } + static Request putOperationMode(PutOperationModeRequest putOperationModeRequest) { + Request request = new Request(HttpGet.METHOD_NAME, + new EndpointBuilder() + .addPathPartAsIs("_ilm") + .addPathPartAsIs(putOperationModeRequest.getMode() == OperationMode.RUNNING ? "start" : "stop") + .build()); + Params params = new Params(request); + params.withMasterTimeout(putOperationModeRequest.masterNodeTimeout()); + return request; + } + static Request explainLifecycle(ExplainLifecycleRequest explainLifecycleRequest) { String[] indices = explainLifecycleRequest.indices() == null ? Strings.EMPTY_ARRAY : explainLifecycleRequest.indices(); Request request = new Request(HttpGet.METHOD_NAME, diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java index b2322dd326823..03690e762ede4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/IndexLifecycleMetadata.java @@ -18,6 +18,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.XPackPlugin.XPackMetaDataCustom; import java.io.IOException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetStatusAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetStatusAction.java index 40765f0aa6650..55cb9b0edb4b5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetStatusAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetStatusAction.java @@ -15,7 +15,7 @@ import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import java.io.IOException; import java.util.Objects; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java index 3098fb02391a5..7e41da4c8b98a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java @@ -7,18 +7,9 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; -import java.io.IOException; -import java.util.Objects; - -public class PutOperationModeAction extends Action { +public class PutOperationModeAction extends Action { public static final PutOperationModeAction INSTANCE = new PutOperationModeAction(); public static final String NAME = "cluster:admin/ilm/operation_mode/set"; @@ -27,73 +18,8 @@ protected PutOperationModeAction() { } @Override - public Response newResponse() { - return new Response(); - } - - public static class Response extends AcknowledgedResponse implements ToXContentObject { - - public Response() { - } - - public Response(boolean acknowledged) { - super(acknowledged); - } - } - - public static class Request extends AcknowledgedRequest { - - private OperationMode mode; - - public Request(OperationMode mode) { - this.mode = mode; - } - - public Request() { - } - - public OperationMode getMode() { - return mode; - } - - @Override - public ActionRequestValidationException validate() { - if (mode == OperationMode.STOPPED) { - ActionRequestValidationException exception = new ActionRequestValidationException(); - exception.addValidationError("cannot directly stop index-lifecycle"); - return exception; - } - return null; - } - - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - mode = in.readEnum(OperationMode.class); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeEnum(mode); - } - - @Override - public int hashCode() { - return Objects.hash(mode); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - if (obj.getClass() != getClass()) { - return false; - } - Request other = (Request) obj; - return Objects.equals(mode, other.mode); - } + public PutOperationModeResponse newResponse() { + return new PutOperationModeResponse(); } } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java index 486bc8cce8a94..8c7447be3b471 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleService.java @@ -20,10 +20,10 @@ import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.scheduler.SchedulerEngine; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTask.java index 1956e5bb0e192..871a782a9acea 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTask.java @@ -10,8 +10,8 @@ import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.logging.ESLoggerFactory; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; public class OperationModeUpdateTask extends ClusterStateUpdateTask { private static final Logger logger = ESLoggerFactory.getLogger(OperationModeUpdateTask.class); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java index c097c14a57501..e2fc97d8dcf29 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java @@ -8,11 +8,12 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; 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.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction; public class RestStartAction extends BaseRestHandler { @@ -29,7 +30,7 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { - PutOperationModeAction.Request request = new PutOperationModeAction.Request(OperationMode.RUNNING); + PutOperationModeRequest request = new PutOperationModeRequest(OperationMode.RUNNING); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(PutOperationModeAction.INSTANCE, request, new RestToXContentListener<>(channel)); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java index 472a8cc8bb4c0..c258ba5dc7d45 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java @@ -8,11 +8,12 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; 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.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction; public class RestStopAction extends BaseRestHandler { @@ -29,7 +30,7 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { - PutOperationModeAction.Request request = new PutOperationModeAction.Request(OperationMode.STOPPING); + PutOperationModeRequest request = new PutOperationModeRequest(OperationMode.STOPPING); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); return channel -> client.execute(PutOperationModeAction.INSTANCE, request, new RestToXContentListener<>(channel)); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetStatusAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetStatusAction.java index 5d7b2b159c08e..2e20a8a20ebc9 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetStatusAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetStatusAction.java @@ -16,10 +16,10 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction; import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction.Request; import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction.Response; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java index e6797137e6559..db8f9ef65f250 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java @@ -19,12 +19,12 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.ClientHelper; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Request; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Response; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java index 257527076a2c0..3be5972aa2caf 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java @@ -17,21 +17,21 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction.Request; -import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction.Response; import org.elasticsearch.xpack.indexlifecycle.OperationModeUpdateTask; -public class TransportPutOperationModeAction extends TransportMasterNodeAction { +public class TransportPutOperationModeAction extends TransportMasterNodeAction { @Inject public TransportPutOperationModeAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, PutOperationModeAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, Request::new); + indexNameExpressionResolver, PutOperationModeRequest::new); } @Override @@ -40,28 +40,28 @@ protected String executor() { } @Override - protected Response newResponse() { - return new Response(); + protected PutOperationModeResponse newResponse() { + return new PutOperationModeResponse(); } @Override - protected void masterOperation(Request request, ClusterState state, ActionListener listener) { + protected void masterOperation(PutOperationModeRequest request, ClusterState state, ActionListener listener) { clusterService.submitStateUpdateTask("ilm_operation_mode_update", - new AckedClusterStateUpdateTask(request, listener) { + new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { return (new OperationModeUpdateTask(request.getMode())).execute(currentState); } @Override - protected Response newResponse(boolean acknowledged) { - return new Response(acknowledged); + protected PutOperationModeResponse newResponse(boolean acknowledged) { + return new PutOperationModeResponse(acknowledged); } }); } @Override - protected ClusterBlockException checkBlock(Request request, ClusterState state) { + protected ClusterBlockException checkBlock(PutOperationModeRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); } } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java index 79de60d812b61..56100d145eccb 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java @@ -20,6 +20,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.Index; import org.elasticsearch.node.Node; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; @@ -27,7 +28,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.MockAction; import org.elasticsearch.xpack.core.indexlifecycle.MockStep; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.Phase; import org.elasticsearch.xpack.core.indexlifecycle.Step; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java index eaf34c0cc4f45..db4e1bd3a431e 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java @@ -16,6 +16,7 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.AbstractDiffableSerializationTestCase; import org.elasticsearch.xpack.core.indexlifecycle.DeleteAction; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; @@ -24,7 +25,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.Phase; import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java index 21f089b8ffa23..70f1c469bbdd7 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java @@ -22,6 +22,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.index.Index; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.indexlifecycle.AbstractStepTestCase; import org.elasticsearch.xpack.core.indexlifecycle.AsyncActionStep; @@ -36,7 +37,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.MockAction; import org.elasticsearch.xpack.core.indexlifecycle.MockStep; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.Phase; import org.elasticsearch.xpack.core.indexlifecycle.RolloverAction; import org.elasticsearch.xpack.core.indexlifecycle.Step; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java index 99cfe87ee1767..2d58afa0159c0 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java @@ -24,13 +24,13 @@ import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.Index; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.ESTestCase; 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.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.MockAction; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.Phase; import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction; import org.elasticsearch.xpack.core.indexlifecycle.Step; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTaskTests.java index 1b934c1d928b3..cb0ba186ef30f 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/OperationModeUpdateTaskTests.java @@ -10,9 +10,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import java.util.Collections; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/PolicyStepsRegistryTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/PolicyStepsRegistryTests.java index 627ea574382db..9e636f49d5473 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/PolicyStepsRegistryTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/PolicyStepsRegistryTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.TransportAddress; import org.elasticsearch.node.Node; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; @@ -22,7 +23,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTests; import org.elasticsearch.xpack.core.indexlifecycle.MockStep; -import org.elasticsearch.xpack.core.indexlifecycle.OperationMode; import org.elasticsearch.xpack.core.indexlifecycle.Step; import org.mockito.Mockito; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/OperationMode.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java similarity index 95% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/OperationMode.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java index 51f50c44a7e72..c53e56243e0a4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/OperationMode.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java @@ -3,7 +3,7 @@ * 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; +package org.elasticsearch.protocol.xpack.indexlifecycle; /** * Enum representing the different modes that Index Lifecycle Service can operate in. diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java new file mode 100644 index 0000000000000..f46229856358c --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java @@ -0,0 +1,71 @@ +/* + * 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.protocol.xpack.indexlifecycle; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.master.AcknowledgedRequest; +import org.elasticsearch.common.io.stream.StreamInput; +import org.elasticsearch.common.io.stream.StreamOutput; + +import java.io.IOException; +import java.util.Objects; + +public class PutOperationModeRequest extends AcknowledgedRequest { + + private OperationMode mode; + + public PutOperationModeRequest(OperationMode mode) { + if (mode == null) { + throw new IllegalArgumentException("mode cannot be null"); + } + if (mode == OperationMode.STOPPED) { + throw new IllegalArgumentException("cannot directly stop index-lifecycle"); + } + this.mode = mode; + } + + public PutOperationModeRequest() { + } + + public OperationMode getMode() { + return mode; + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + @Override + public void readFrom(StreamInput in) throws IOException { + super.readFrom(in); + mode = in.readEnum(OperationMode.class); + } + + @Override + public void writeTo(StreamOutput out) throws IOException { + super.writeTo(out); + out.writeEnum(mode); + } + + @Override + public int hashCode() { + return Objects.hash(mode); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj.getClass() != getClass()) { + return false; + } + PutOperationModeRequest other = (PutOperationModeRequest) obj; + return Objects.equals(mode, other.mode); + } +} \ No newline at end of file diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java new file mode 100644 index 0000000000000..b8d10a1da0c35 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java @@ -0,0 +1,25 @@ +/* + * 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.protocol.xpack.indexlifecycle; + +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentParser; + +public class PutOperationModeResponse extends AcknowledgedResponse implements ToXContentObject { + + public static PutOperationModeResponse fromXContent(XContentParser parser) { + return new PutOperationModeResponse(parseAcknowledged(parser)); + } + + public PutOperationModeResponse() { + } + + public PutOperationModeResponse(boolean acknowledged) { + super(acknowledged); + } +} \ No newline at end of file diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java new file mode 100644 index 0000000000000..3fa5799c93a48 --- /dev/null +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java @@ -0,0 +1,26 @@ +/* + * 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.protocol.xpack.indexlifecycle; + +import org.elasticsearch.test.ESTestCase; + +public class OperationModeTests extends ESTestCase { + + public void testIsValidChange() { + assertFalse(OperationMode.RUNNING.isValidChange(OperationMode.RUNNING)); + assertTrue(OperationMode.RUNNING.isValidChange(OperationMode.STOPPING)); + assertFalse(OperationMode.RUNNING.isValidChange(OperationMode.STOPPED)); + + assertTrue(OperationMode.STOPPING.isValidChange(OperationMode.RUNNING)); + assertFalse(OperationMode.STOPPING.isValidChange(OperationMode.STOPPING)); + assertTrue(OperationMode.STOPPING.isValidChange(OperationMode.STOPPED)); + + assertTrue(OperationMode.STOPPED.isValidChange(OperationMode.RUNNING)); + assertFalse(OperationMode.STOPPED.isValidChange(OperationMode.STOPPING)); + assertFalse(OperationMode.STOPPED.isValidChange(OperationMode.STOPPED)); + } +} diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java new file mode 100644 index 0000000000000..45a62eb611306 --- /dev/null +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java @@ -0,0 +1,46 @@ +/* + * 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.protocol.xpack.indexlifecycle; + +import org.elasticsearch.test.AbstractStreamableTestCase; + +import java.io.IOException; + +public class PutOperationModeRequestTests extends AbstractStreamableTestCase { + + @Override + protected PutOperationModeRequest createBlankInstance() { + return new PutOperationModeRequest(); + } + + @Override + protected PutOperationModeRequest createTestInstance() { + return new PutOperationModeRequest(randomFrom(OperationMode.STOPPING, OperationMode.RUNNING)); + } + + @Override + protected PutOperationModeRequest mutateInstance(PutOperationModeRequest instance) throws IOException { + return new PutOperationModeRequest( + randomValueOtherThan(instance.getMode(), () -> randomFrom(OperationMode.STOPPING, OperationMode.RUNNING))); + } + + public void testNullMode() { + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new PutOperationModeRequest(null)); + assertEquals("mode cannot be null", exception.getMessage()); + } + + public void testStoppedMode() { + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new PutOperationModeRequest(OperationMode.STOPPED)); + assertEquals("cannot directly stop index-lifecycle", exception.getMessage()); + } + + public void testValidate() { + PutOperationModeRequest request = createTestInstance(); + assertNull(request.validate()); + } + +} diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java new file mode 100644 index 0000000000000..aeb95380380ce --- /dev/null +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java @@ -0,0 +1,36 @@ +/* + * 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.protocol.xpack.indexlifecycle; + +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; + +import java.io.IOException; + +public class PutOperationModeResponseTests extends AbstractStreamableXContentTestCase { + + @Override + protected PutOperationModeResponse createBlankInstance() { + return new PutOperationModeResponse(); + } + + @Override + protected PutOperationModeResponse createTestInstance() { + return new PutOperationModeResponse(randomBoolean()); + } + + @Override + protected PutOperationModeResponse mutateInstance(PutOperationModeResponse instance) throws IOException { + return new PutOperationModeResponse(instance.isAcknowledged() == false); + } + + @Override + protected PutOperationModeResponse doParseInstance(XContentParser parser) throws IOException { + return PutOperationModeResponse.fromXContent(parser); + } + +} From 373a024a0f87882228e9660d06593b19d11bbd73 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Fri, 3 Aug 2018 14:13:28 +0100 Subject: [PATCH 2/7] Corrects licence headers --- .../xpack/indexlifecycle/OperationMode.java | 21 ++++++++++++++++--- .../PutOperationModeRequest.java | 19 ++++++++++++++--- .../PutOperationModeResponse.java | 19 ++++++++++++++--- .../indexlifecycle/OperationModeTests.java | 19 ++++++++++++++--- .../PutOperationModeRequestTests.java | 19 ++++++++++++++--- .../PutOperationModeResponseTests.java | 19 ++++++++++++++--- 6 files changed, 98 insertions(+), 18 deletions(-) diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java index c53e56243e0a4..3186c11d33f73 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationMode.java @@ -1,10 +1,25 @@ /* - * 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. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.elasticsearch.protocol.xpack.indexlifecycle; +import org.elasticsearch.action.admin.indices.shrink.ShrinkAction; + /** * Enum representing the different modes that Index Lifecycle Service can operate in. */ diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java index f46229856358c..423860fd2f5f5 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.elasticsearch.protocol.xpack.indexlifecycle; diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java index b8d10a1da0c35..e49d1c02b2247 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.elasticsearch.protocol.xpack.indexlifecycle; diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java index 3fa5799c93a48..bc539ee4c6610 100644 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/OperationModeTests.java @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.elasticsearch.protocol.xpack.indexlifecycle; diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java index 45a62eb611306..faab10b64025d 100644 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.elasticsearch.protocol.xpack.indexlifecycle; diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java index aeb95380380ce..e2b8ab923ebaa 100644 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java @@ -1,7 +1,20 @@ /* - * 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. + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. */ package org.elasticsearch.protocol.xpack.indexlifecycle; From f07d79830f04d483b934c904f4ad691c25bf7aff Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 6 Aug 2018 13:59:12 +0100 Subject: [PATCH 3/7] iter --- .../client/IndexLifecycleIT.java | 84 +++++++++++++++++++ .../PutOperationModeRequestTests.java | 3 +- 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index 661caccd7a20b..0f7a51427097c 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -22,9 +22,13 @@ import org.apache.http.HttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.nio.entity.NStringEntity; +import org.apache.http.util.EntityUtils; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.IndexLifecycleExplainResponse; @@ -106,6 +110,86 @@ public void testSetIndexLifecyclePolicy() throws Exception { assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policy)); } + public void testPutOperationMode() throws Exception { + String policy = randomAlphaOfLength(10); + + // TODO: NORELEASE convert this to using the high level client once there are APIs for it + String jsonString = "{\n" + + " \"policy\": {\n" + + " \"type\": \"timeseries\",\n" + + " \"phases\": {\n" + + " \"hot\": {\n" + + " \"actions\": {\n" + + " \"rollover\": {\n" + + " \"max_age\": \"50d\"\n" + + " } \n" + + " }\n" + + " },\n" + + " \"warm\": {\n" + + " \"after\": \"1000s\",\n" + + " \"actions\": {\n" + + " \"allocate\": {\n" + + " \"require\": { \"_name\": \"node-1\" },\n" + + " \"include\": {},\n" + + " \"exclude\": {}\n" + + " },\n" + + " \"shrink\": {\n" + + " \"number_of_shards\": 1\n" + + " },\n" + + " \"forcemerge\": {\n" + + " \"max_num_segments\": 1000\n" + + " }\n" + + " }\n" + + " },\n" + + " \"cold\": {\n" + + " \"after\": \"2000s\",\n" + + " \"actions\": {\n" + + " \"replicas\": {\n" + + " \"number_of_replicas\": 0\n" + + " }\n" + + " }\n" + + " },\n" + + " \"delete\": {\n" + + " \"after\": \"3000s\",\n" + + " \"actions\": {\n" + + " \"delete\": {}\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + HttpEntity entity = new NStringEntity(jsonString, ContentType.APPLICATION_JSON); + Request request = new Request("PUT", "/_ilm/" + policy); + request.setEntity(entity); + client().performRequest(request); + + createIndex("foo", Settings.builder().put("index.lifecycle.name", "bar").build()); + createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build()); + createIndex("squash", Settings.EMPTY); + + PutOperationModeRequest req = new PutOperationModeRequest(OperationMode.STOPPING); + PutOperationModeResponse response = execute(req, highLevelClient().indexLifecycle()::putOperationMode, + highLevelClient().indexLifecycle()::putOperationModeAsync); + assertTrue(response.isAcknowledged()); + + // TODO: NORELEASE convert this to using the high level client once there are APIs for it + Request statusReq = new Request("GET", "/_ilm/status" + policy); + Response statusResponse = client().performRequest(statusReq); + String statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertEquals("{ \"operation_mode\": \"STOPPED\" }", statusResponseString); + + req = new PutOperationModeRequest(OperationMode.RUNNING); + response = execute(req, highLevelClient().indexLifecycle()::putOperationMode, + highLevelClient().indexLifecycle()::putOperationModeAsync); + assertTrue(response.isAcknowledged()); + + // TODO: NORELEASE convert this to using the high level client once there are APIs for it + statusReq = new Request("GET", "/_ilm/status" + policy); + statusResponse = client().performRequest(statusReq); + statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertEquals("{ \"operation_mode\": \"RUNNING\" }", statusResponseString); + } + public void testExplainLifecycle() throws Exception { String policy = randomAlphaOfLength(10); diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java index faab10b64025d..a5b7aa010283c 100644 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java @@ -47,7 +47,8 @@ public void testNullMode() { } public void testStoppedMode() { - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new PutOperationModeRequest(OperationMode.STOPPED)); + IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, + () -> new PutOperationModeRequest(OperationMode.STOPPED)); assertEquals("cannot directly stop index-lifecycle", exception.getMessage()); } From 8c4c83645b518009101363d819d0518cf2cd668e Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 6 Aug 2018 14:11:48 +0100 Subject: [PATCH 4/7] add request converter test --- .../client/RequestConverters.java | 2 +- .../client/RequestConvertersTests.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index 361ef31bbd632..fb88c0eca61d3 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -1173,7 +1173,7 @@ static Request setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest setPolicyR } static Request putOperationMode(PutOperationModeRequest putOperationModeRequest) { - Request request = new Request(HttpGet.METHOD_NAME, + Request request = new Request(HttpPut.METHOD_NAME, new EndpointBuilder() .addPathPartAsIs("_ilm") .addPathPartAsIs(putOperationModeRequest.getMode() == OperationMode.RUNNING ? "start" : "stop") diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index a8b0c845dcd36..dd46e8bb43d70 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -126,6 +126,8 @@ import org.elasticsearch.index.rankeval.RatedRequest; import org.elasticsearch.index.rankeval.RestRankEvalAction; import org.elasticsearch.protocol.xpack.XPackInfoRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; @@ -2602,6 +2604,26 @@ public void testSetIndexLifecyclePolicy() throws Exception { assertThat(request.getParameters(), equalTo(expectedParams)); } + public void testPutOperationMode() throws Exception { + PutOperationModeRequest req = new PutOperationModeRequest(OperationMode.RUNNING); + Map expectedParams = new HashMap<>(); + setRandomMasterTimeout(req, expectedParams); + + Request request = RequestConverters.putOperationMode(req); + assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME)); + assertThat(request.getEndpoint(), equalTo("/_ilm/start")); + assertThat(request.getParameters(), equalTo(expectedParams)); + + req = new PutOperationModeRequest(OperationMode.STOPPING); + expectedParams = new HashMap<>(); + setRandomMasterTimeout(req, expectedParams); + + request = RequestConverters.putOperationMode(req); + assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME)); + assertThat(request.getEndpoint(), equalTo("/_ilm/stop")); + assertThat(request.getParameters(), equalTo(expectedParams)); + } + public void testExplainLifecycle() throws Exception { ExplainLifecycleRequest req = new ExplainLifecycleRequest(); String[] indices = rarely() ? null : randomIndicesNames(0, 10); From 7bbecf5d0963c3f2e5d574bb45ed5aad91749cd8 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Mon, 6 Aug 2018 15:52:35 +0100 Subject: [PATCH 5/7] Fixes tests --- .../client/RequestConverters.java | 2 +- .../client/IndexLifecycleIT.java | 21 +++++++++++++------ .../client/RequestConvertersTests.java | 4 ++-- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index fb88c0eca61d3..a4ba8665bc552 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -1173,7 +1173,7 @@ static Request setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest setPolicyR } static Request putOperationMode(PutOperationModeRequest putOperationModeRequest) { - Request request = new Request(HttpPut.METHOD_NAME, + Request request = new Request(HttpPost.METHOD_NAME, new EndpointBuilder() .addPathPartAsIs("_ilm") .addPathPartAsIs(putOperationModeRequest.getMode() == OperationMode.RUNNING ? "start" : "stop") diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index 0f7a51427097c..1ee25a6d83453 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -34,6 +34,7 @@ import org.elasticsearch.protocol.xpack.indexlifecycle.IndexLifecycleExplainResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyResponse; +import org.hamcrest.Matchers; import java.util.Map; @@ -166,6 +167,13 @@ public void testPutOperationMode() throws Exception { createIndex("foo", Settings.builder().put("index.lifecycle.name", "bar").build()); createIndex("baz", Settings.builder().put("index.lifecycle.name", "eggplant").build()); createIndex("squash", Settings.EMPTY); + + // TODO: NORELEASE convert this to using the high level client once + // there are APIs for it + Request statusReq = new Request("GET", "/_ilm/status"); + Response statusResponse = client().performRequest(statusReq); + String statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); PutOperationModeRequest req = new PutOperationModeRequest(OperationMode.STOPPING); PutOperationModeResponse response = execute(req, highLevelClient().indexLifecycle()::putOperationMode, @@ -173,10 +181,11 @@ public void testPutOperationMode() throws Exception { assertTrue(response.isAcknowledged()); // TODO: NORELEASE convert this to using the high level client once there are APIs for it - Request statusReq = new Request("GET", "/_ilm/status" + policy); - Response statusResponse = client().performRequest(statusReq); - String statusResponseString = EntityUtils.toString(statusResponse.getEntity()); - assertEquals("{ \"operation_mode\": \"STOPPED\" }", statusResponseString); + statusReq = new Request("GET", "/_ilm/status"); + statusResponse = client().performRequest(statusReq); + statusResponseString = EntityUtils.toString(statusResponse.getEntity()); + assertThat(statusResponseString, + Matchers.anyOf(equalTo("{\"operation_mode\":\"STOPPING\"}"), equalTo("{\"operation_mode\":\"STOPPED\"}"))); req = new PutOperationModeRequest(OperationMode.RUNNING); response = execute(req, highLevelClient().indexLifecycle()::putOperationMode, @@ -184,10 +193,10 @@ public void testPutOperationMode() throws Exception { assertTrue(response.isAcknowledged()); // TODO: NORELEASE convert this to using the high level client once there are APIs for it - statusReq = new Request("GET", "/_ilm/status" + policy); + statusReq = new Request("GET", "/_ilm/status"); statusResponse = client().performRequest(statusReq); statusResponseString = EntityUtils.toString(statusResponse.getEntity()); - assertEquals("{ \"operation_mode\": \"RUNNING\" }", statusResponseString); + assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); } public void testExplainLifecycle() throws Exception { diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index dd46e8bb43d70..246faaa5c441e 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -2610,7 +2610,7 @@ public void testPutOperationMode() throws Exception { setRandomMasterTimeout(req, expectedParams); Request request = RequestConverters.putOperationMode(req); - assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME)); + assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); assertThat(request.getEndpoint(), equalTo("/_ilm/start")); assertThat(request.getParameters(), equalTo(expectedParams)); @@ -2619,7 +2619,7 @@ public void testPutOperationMode() throws Exception { setRandomMasterTimeout(req, expectedParams); request = RequestConverters.putOperationMode(req); - assertThat(request.getMethod(), equalTo(HttpPut.METHOD_NAME)); + assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); assertThat(request.getEndpoint(), equalTo("/_ilm/stop")); assertThat(request.getParameters(), equalTo(expectedParams)); } From df1d5cf3ed880ec9f5de6aedc1e9a29d2fa19abe Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Thu, 9 Aug 2018 13:40:16 +0100 Subject: [PATCH 6/7] Creates start and stop actions for controlling ILM operation --- .../client/IndexLifecycleClient.java | 50 +++++++++++--- .../client/RequestConverters.java | 25 +++++-- .../client/IndexLifecycleIT.java | 27 ++++---- .../client/RequestConvertersTests.java | 20 +++--- .../action/PutOperationModeAction.java | 25 ------- .../indexlifecycle/action/StartILMAction.java | 25 +++++++ .../indexlifecycle/action/StopILMAction.java | 25 +++++++ .../xpack/indexlifecycle/IndexLifecycle.java | 13 ++-- ...artAction.java => RestStartILMAction.java} | 13 ++-- .../indexlifecycle/action/RestStopAction.java | 9 ++- ...tion.java => TransportStartILMAction.java} | 31 +++++---- .../action/TransportStopILMAction.java | 68 +++++++++++++++++++ ...nModeRequest.java => StartILMRequest.java} | 42 ++---------- ...odeResponse.java => StartILMResponse.java} | 10 +-- .../xpack/indexlifecycle/StopILMRequest.java | 50 ++++++++++++++ .../xpack/indexlifecycle/StopILMResponse.java | 38 +++++++++++ .../PutOperationModeRequestTests.java | 60 ---------------- .../indexlifecycle/StartILMRequestTests.java | 41 +++++++++++ ...eTests.java => StartILMResponseTests.java} | 18 ++--- .../indexlifecycle/StopILMRequestTests.java | 41 +++++++++++ .../indexlifecycle/StopILMResponseTests.java | 49 +++++++++++++ 21 files changed, 473 insertions(+), 207 deletions(-) delete mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java create mode 100644 x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java rename x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/{RestStartAction.java => RestStartILMAction.java} (65%) rename x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/{TransportPutOperationModeAction.java => TransportStartILMAction.java} (56%) create mode 100644 x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java rename x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/{PutOperationModeRequest.java => StartILMRequest.java} (52%) rename x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/{PutOperationModeResponse.java => StartILMResponse.java} (75%) create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequest.java create mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java delete mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java create mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequestTests.java rename x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/{PutOperationModeResponseTests.java => StartILMResponseTests.java} (60%) create mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequestTests.java create mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java index 22ea8e22e7001..1c5b58d90603c 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java @@ -20,12 +20,14 @@ package org.elasticsearch.client; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyResponse; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; import java.io.IOException; @@ -68,7 +70,7 @@ public void setIndexLifecyclePolicyAsync(SetIndexLifecyclePolicyRequest request, } /** - * Set the operation mode for the Index Lifecycle Management feature. + * Start the Index Lifecycle Management feature. * See * the docs for more. * @param request the request @@ -76,23 +78,49 @@ public void setIndexLifecyclePolicyAsync(SetIndexLifecyclePolicyRequest request, * @return the response * @throws IOException in case there is a problem sending the request or parsing back the response */ - public PutOperationModeResponse putOperationMode(PutOperationModeRequest request, RequestOptions options) throws IOException { - return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::putOperationMode, options, - PutOperationModeResponse::fromXContent, emptySet()); + public StartILMResponse startILM(StartILMRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::startILM, options, + StartILMResponse::fromXContent, emptySet()); } /** - * Asynchronously set the operation mode for the Index Lifecycle Management feature. + * Asynchronously start the Index Lifecycle Management feature. * See * the docs for more. * @param request the request * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @param listener the listener to be notified upon request completion */ - public void putOperationModeAsync(PutOperationModeRequest request, RequestOptions options, - ActionListener listener) { - restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::putOperationMode, options, - PutOperationModeResponse::fromXContent, listener, emptySet()); + public void startILMAsync(StartILMRequest request, RequestOptions options, ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::startILM, options, + StartILMResponse::fromXContent, listener, emptySet()); + } + + /** + * Stop the Index Lifecycle Management feature. + * See + * the docs for more. + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @return the response + * @throws IOException in case there is a problem sending the request or parsing back the response + */ + public StopILMResponse stopILM(StopILMRequest request, RequestOptions options) throws IOException { + return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::stopILM, options, + StopILMResponse::fromXContent, emptySet()); + } + + /** + * Asynchronously stop the Index Lifecycle Management feature. + * See + * the docs for more. + * @param request the request + * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized + * @param listener the listener to be notified upon request completion + */ + public void stopILMAsync(StopILMRequest request, RequestOptions options, ActionListener listener) { + restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::stopILM, options, + StopILMResponse::fromXContent, listener, emptySet()); } /** diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java index a4ba8665bc552..577e3f37a324a 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/RequestConverters.java @@ -107,12 +107,12 @@ import org.elasticsearch.index.VersionType; import org.elasticsearch.index.rankeval.RankEvalRequest; import org.elasticsearch.protocol.xpack.XPackInfoRequest; -import org.elasticsearch.protocol.xpack.license.GetLicenseRequest; import org.elasticsearch.protocol.xpack.XPackUsageRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; +import org.elasticsearch.protocol.xpack.license.GetLicenseRequest; import org.elasticsearch.protocol.xpack.license.PutLicenseRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; @@ -1172,14 +1172,27 @@ static Request setIndexLifecyclePolicy(SetIndexLifecyclePolicyRequest setPolicyR return request; } - static Request putOperationMode(PutOperationModeRequest putOperationModeRequest) { + static Request startILM(StartILMRequest startILMRequest) { + Request request = new Request(HttpPost.METHOD_NAME, + new EndpointBuilder() + .addPathPartAsIs("_ilm") + .addPathPartAsIs("start") + .build()); + Params params = new Params(request); + params.withMasterTimeout(startILMRequest.masterNodeTimeout()); + params.withTimeout(startILMRequest.timeout()); + return request; + } + + static Request stopILM(StopILMRequest stopILMRequest) { Request request = new Request(HttpPost.METHOD_NAME, new EndpointBuilder() .addPathPartAsIs("_ilm") - .addPathPartAsIs(putOperationModeRequest.getMode() == OperationMode.RUNNING ? "start" : "stop") + .addPathPartAsIs("stop") .build()); Params params = new Params(request); - params.withMasterTimeout(putOperationModeRequest.masterNodeTimeout()); + params.withMasterTimeout(stopILMRequest.masterNodeTimeout()); + params.withTimeout(stopILMRequest.timeout()); return request; } diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index 1ee25a6d83453..a02b9fd8d359d 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -26,14 +26,15 @@ import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.IndexLifecycleExplainResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyResponse; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; import org.hamcrest.Matchers; import java.util.Map; @@ -111,7 +112,7 @@ public void testSetIndexLifecyclePolicy() throws Exception { assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policy)); } - public void testPutOperationMode() throws Exception { + public void testStartStopILM() throws Exception { String policy = randomAlphaOfLength(10); // TODO: NORELEASE convert this to using the high level client once there are APIs for it @@ -145,7 +146,7 @@ public void testPutOperationMode() throws Exception { " \"cold\": {\n" + " \"after\": \"2000s\",\n" + " \"actions\": {\n" + - " \"replicas\": {\n" + + " \"allocate\": {\n" + " \"number_of_replicas\": 0\n" + " }\n" + " }\n" + @@ -175,10 +176,10 @@ public void testPutOperationMode() throws Exception { String statusResponseString = EntityUtils.toString(statusResponse.getEntity()); assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); - PutOperationModeRequest req = new PutOperationModeRequest(OperationMode.STOPPING); - PutOperationModeResponse response = execute(req, highLevelClient().indexLifecycle()::putOperationMode, - highLevelClient().indexLifecycle()::putOperationModeAsync); - assertTrue(response.isAcknowledged()); + StopILMRequest stopReq = new StopILMRequest(); + StopILMResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM, + highLevelClient().indexLifecycle()::stopILMAsync); + assertTrue(stopResponse.isAcknowledged()); // TODO: NORELEASE convert this to using the high level client once there are APIs for it statusReq = new Request("GET", "/_ilm/status"); @@ -187,10 +188,10 @@ public void testPutOperationMode() throws Exception { assertThat(statusResponseString, Matchers.anyOf(equalTo("{\"operation_mode\":\"STOPPING\"}"), equalTo("{\"operation_mode\":\"STOPPED\"}"))); - req = new PutOperationModeRequest(OperationMode.RUNNING); - response = execute(req, highLevelClient().indexLifecycle()::putOperationMode, - highLevelClient().indexLifecycle()::putOperationModeAsync); - assertTrue(response.isAcknowledged()); + StartILMRequest startReq = new StartILMRequest(); + StartILMResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM, + highLevelClient().indexLifecycle()::startILMAsync); + assertTrue(startResponse.isAcknowledged()); // TODO: NORELEASE convert this to using the high level client once there are APIs for it statusReq = new Request("GET", "/_ilm/status"); diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java index 246faaa5c441e..8172ee38375eb 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/RequestConvertersTests.java @@ -126,10 +126,10 @@ import org.elasticsearch.index.rankeval.RatedRequest; import org.elasticsearch.index.rankeval.RestRankEvalAction; import org.elasticsearch.protocol.xpack.XPackInfoRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; import org.elasticsearch.protocol.xpack.watcher.DeleteWatchRequest; import org.elasticsearch.protocol.xpack.watcher.PutWatchRequest; import org.elasticsearch.repositories.fs.FsRepository; @@ -2604,21 +2604,25 @@ public void testSetIndexLifecyclePolicy() throws Exception { assertThat(request.getParameters(), equalTo(expectedParams)); } - public void testPutOperationMode() throws Exception { - PutOperationModeRequest req = new PutOperationModeRequest(OperationMode.RUNNING); + public void testStartILM() throws Exception { + StartILMRequest req = new StartILMRequest(); Map expectedParams = new HashMap<>(); setRandomMasterTimeout(req, expectedParams); + setRandomTimeout(req::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); - Request request = RequestConverters.putOperationMode(req); + Request request = RequestConverters.startILM(req); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); assertThat(request.getEndpoint(), equalTo("/_ilm/start")); assertThat(request.getParameters(), equalTo(expectedParams)); + } - req = new PutOperationModeRequest(OperationMode.STOPPING); - expectedParams = new HashMap<>(); + public void testStopILM() throws Exception { + StopILMRequest req = new StopILMRequest(); + Map expectedParams = new HashMap<>(); setRandomMasterTimeout(req, expectedParams); + setRandomTimeout(req::timeout, AcknowledgedRequest.DEFAULT_ACK_TIMEOUT, expectedParams); - request = RequestConverters.putOperationMode(req); + Request request = RequestConverters.stopILM(req); assertThat(request.getMethod(), equalTo(HttpPost.METHOD_NAME)); assertThat(request.getEndpoint(), equalTo("/_ilm/stop")); assertThat(request.getParameters(), equalTo(expectedParams)); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java deleted file mode 100644 index 7e41da4c8b98a..0000000000000 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutOperationModeAction.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -package org.elasticsearch.xpack.core.indexlifecycle.action; - -import org.elasticsearch.action.Action; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; - -public class PutOperationModeAction extends Action { - public static final PutOperationModeAction INSTANCE = new PutOperationModeAction(); - public static final String NAME = "cluster:admin/ilm/operation_mode/set"; - - protected PutOperationModeAction() { - super(NAME); - } - - @Override - public PutOperationModeResponse newResponse() { - return new PutOperationModeResponse(); - } - -} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java new file mode 100644 index 0000000000000..46e5d49cac29d --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java @@ -0,0 +1,25 @@ +/* + * 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.protocol.xpack.indexlifecycle.StartILMResponse; + +public class StartILMAction extends Action { + public static final StartILMAction INSTANCE = new StartILMAction(); + public static final String NAME = "cluster:admin/ilm/start"; + + protected StartILMAction() { + super(NAME); + } + + @Override + public StartILMResponse newResponse() { + return new StartILMResponse(); + } + +} diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java new file mode 100644 index 0000000000000..a2cceda762a79 --- /dev/null +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java @@ -0,0 +1,25 @@ +/* + * 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.protocol.xpack.indexlifecycle.StopILMResponse; + +public class StopILMAction extends Action { + public static final StopILMAction INSTANCE = new StopILMAction(); + public static final String NAME = "cluster:admin/ilm/stop"; + + protected StopILMAction() { + super(NAME); + } + + @Override + public StopILMResponse newResponse() { + return new StopILMResponse(); + } + +} diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java index 48acf5c701ee0..e5c57436190b4 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java @@ -40,10 +40,11 @@ import org.elasticsearch.xpack.core.indexlifecycle.action.GetStatusAction; import org.elasticsearch.xpack.core.indexlifecycle.action.MoveToStepAction; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction; -import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction; import org.elasticsearch.xpack.core.indexlifecycle.action.RemovePolicyForIndexAction; import org.elasticsearch.xpack.core.indexlifecycle.action.RetryAction; import org.elasticsearch.xpack.core.indexlifecycle.action.SetIndexLifecyclePolicyAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction; import org.elasticsearch.xpack.indexlifecycle.action.RestDeleteLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestExplainLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestGetLifecycleAction; @@ -53,7 +54,7 @@ import org.elasticsearch.xpack.indexlifecycle.action.RestRemovePolicyForIndexAction; import org.elasticsearch.xpack.indexlifecycle.action.RestRetryAction; import org.elasticsearch.xpack.indexlifecycle.action.RestSetIndexLifecyclePolicyAction; -import org.elasticsearch.xpack.indexlifecycle.action.RestStartAction; +import org.elasticsearch.xpack.indexlifecycle.action.RestStartILMAction; import org.elasticsearch.xpack.indexlifecycle.action.RestStopAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportDeleteLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportExplainLifecycleAction; @@ -61,10 +62,11 @@ import org.elasticsearch.xpack.indexlifecycle.action.TransportGetStatusAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportMoveToStepAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportPutLifecycleAction; -import org.elasticsearch.xpack.indexlifecycle.action.TransportPutOperationModeAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportRemovePolicyForIndexAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportRetryAction; import org.elasticsearch.xpack.indexlifecycle.action.TransportSetIndexLifecyclePolicyAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportStartILMAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportStopILMAction; import java.time.Clock; import java.util.ArrayList; @@ -164,7 +166,7 @@ public List getRestHandlers(Settings settings, RestController restC new RestMoveToStepAction(settings, restController), new RestRetryAction(settings, restController), new RestStopAction(settings, restController), - new RestStartAction(settings, restController), + new RestStartILMAction(settings, restController), new RestGetStatusAction(settings, restController) ); } @@ -183,7 +185,8 @@ public List getRestHandlers(Settings settings, RestController restC new ActionHandler<>(RemovePolicyForIndexAction.INSTANCE, TransportRemovePolicyForIndexAction.class), new ActionHandler<>(MoveToStepAction.INSTANCE, TransportMoveToStepAction.class), new ActionHandler<>(RetryAction.INSTANCE, TransportRetryAction.class), - new ActionHandler<>(PutOperationModeAction.INSTANCE, TransportPutOperationModeAction.class), + new ActionHandler<>(StartILMAction.INSTANCE, TransportStartILMAction.class), + new ActionHandler<>(StopILMAction.INSTANCE, TransportStopILMAction.class), new ActionHandler<>(GetStatusAction.INSTANCE, TransportGetStatusAction.class)); } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartILMAction.java similarity index 65% rename from x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartILMAction.java index e2fc97d8dcf29..5c36aef33bd7d 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStartILMAction.java @@ -8,17 +8,16 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; 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.PutOperationModeAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; -public class RestStartAction extends BaseRestHandler { +public class RestStartILMAction extends BaseRestHandler { - public RestStartAction(Settings settings, RestController controller) { + public RestStartILMAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(RestRequest.Method.POST, "/_ilm/start", this); } @@ -30,9 +29,9 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { - PutOperationModeRequest request = new PutOperationModeRequest(OperationMode.RUNNING); + StartILMRequest request = new StartILMRequest(); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); - return channel -> client.execute(PutOperationModeAction.INSTANCE, request, new RestToXContentListener<>(channel)); + return channel -> client.execute(StartILMAction.INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java index c258ba5dc7d45..7a5aae6843000 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestStopAction.java @@ -8,13 +8,12 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; 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.PutOperationModeAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction; public class RestStopAction extends BaseRestHandler { @@ -30,9 +29,9 @@ public String getName() { @Override protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) { - PutOperationModeRequest request = new PutOperationModeRequest(OperationMode.STOPPING); + StopILMRequest request = new StopILMRequest(); request.timeout(restRequest.paramAsTime("timeout", request.timeout())); request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout())); - return channel -> client.execute(PutOperationModeAction.INSTANCE, request, new RestToXContentListener<>(channel)); + return channel -> client.execute(StopILMAction.INSTANCE, request, new RestToXContentListener<>(channel)); } } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java similarity index 56% rename from x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java index 3be5972aa2caf..23d842f568bb3 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutOperationModeAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java @@ -17,21 +17,22 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.PutOperationModeResponse; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.indexlifecycle.action.PutOperationModeAction; +import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; import org.elasticsearch.xpack.indexlifecycle.OperationModeUpdateTask; -public class TransportPutOperationModeAction extends TransportMasterNodeAction { +public class TransportStartILMAction extends TransportMasterNodeAction { @Inject - public TransportPutOperationModeAction(Settings settings, TransportService transportService, ClusterService clusterService, + public TransportStartILMAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, PutOperationModeAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, PutOperationModeRequest::new); + super(settings, StartILMAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + StartILMRequest::new); } @Override @@ -40,28 +41,28 @@ protected String executor() { } @Override - protected PutOperationModeResponse newResponse() { - return new PutOperationModeResponse(); + protected StartILMResponse newResponse() { + return new StartILMResponse(); } @Override - protected void masterOperation(PutOperationModeRequest request, ClusterState state, ActionListener listener) { + protected void masterOperation(StartILMRequest request, ClusterState state, ActionListener listener) { clusterService.submitStateUpdateTask("ilm_operation_mode_update", - new AckedClusterStateUpdateTask(request, listener) { + new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { - return (new OperationModeUpdateTask(request.getMode())).execute(currentState); + return (new OperationModeUpdateTask(OperationMode.RUNNING)).execute(currentState); } @Override - protected PutOperationModeResponse newResponse(boolean acknowledged) { - return new PutOperationModeResponse(acknowledged); + protected StartILMResponse newResponse(boolean acknowledged) { + return new StartILMResponse(acknowledged); } }); } @Override - protected ClusterBlockException checkBlock(PutOperationModeRequest request, ClusterState state) { + protected ClusterBlockException checkBlock(StartILMRequest request, ClusterState state) { return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); } } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java new file mode 100644 index 0000000000000..9b58e88f1105e --- /dev/null +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java @@ -0,0 +1,68 @@ +/* + * 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.IndexNameExpressionResolver; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; +import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction; +import org.elasticsearch.xpack.indexlifecycle.OperationModeUpdateTask; + +public class TransportStopILMAction extends TransportMasterNodeAction { + + @Inject + public TransportStopILMAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver) { + super(settings, StopILMAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + StopILMRequest::new); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected StopILMResponse newResponse() { + return new StopILMResponse(); + } + + @Override + protected void masterOperation(StopILMRequest request, ClusterState state, ActionListener listener) { + clusterService.submitStateUpdateTask("ilm_operation_mode_update", + new AckedClusterStateUpdateTask(request, listener) { + @Override + public ClusterState execute(ClusterState currentState) { + return (new OperationModeUpdateTask(OperationMode.STOPPING)).execute(currentState); + } + + @Override + protected StopILMResponse newResponse(boolean acknowledged) { + return new StopILMResponse(acknowledged); + } + }); + } + + @Override + protected ClusterBlockException checkBlock(StopILMRequest request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } +} diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequest.java similarity index 52% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequest.java index 423860fd2f5f5..2e58a0b5581a3 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequest.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequest.java @@ -21,31 +21,10 @@ import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.common.io.stream.StreamInput; -import org.elasticsearch.common.io.stream.StreamOutput; -import java.io.IOException; -import java.util.Objects; +public class StartILMRequest extends AcknowledgedRequest { -public class PutOperationModeRequest extends AcknowledgedRequest { - - private OperationMode mode; - - public PutOperationModeRequest(OperationMode mode) { - if (mode == null) { - throw new IllegalArgumentException("mode cannot be null"); - } - if (mode == OperationMode.STOPPED) { - throw new IllegalArgumentException("cannot directly stop index-lifecycle"); - } - this.mode = mode; - } - - public PutOperationModeRequest() { - } - - public OperationMode getMode() { - return mode; + public StartILMRequest() { } @Override @@ -53,21 +32,9 @@ public ActionRequestValidationException validate() { return null; } - @Override - public void readFrom(StreamInput in) throws IOException { - super.readFrom(in); - mode = in.readEnum(OperationMode.class); - } - - @Override - public void writeTo(StreamOutput out) throws IOException { - super.writeTo(out); - out.writeEnum(mode); - } - @Override public int hashCode() { - return Objects.hash(mode); + return 64; } @Override @@ -78,7 +45,6 @@ public boolean equals(Object obj) { if (obj.getClass() != getClass()) { return false; } - PutOperationModeRequest other = (PutOperationModeRequest) obj; - return Objects.equals(mode, other.mode); + return true; } } \ No newline at end of file diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java similarity index 75% rename from x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java rename to x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java index e49d1c02b2247..9913dc6347757 100644 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponse.java +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java @@ -23,16 +23,16 @@ import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentParser; -public class PutOperationModeResponse extends AcknowledgedResponse implements ToXContentObject { +public class StartILMResponse extends AcknowledgedResponse implements ToXContentObject { - public static PutOperationModeResponse fromXContent(XContentParser parser) { - return new PutOperationModeResponse(parseAcknowledged(parser)); + public static StartILMResponse fromXContent(XContentParser parser) { + return new StartILMResponse(parseAcknowledged(parser)); } - public PutOperationModeResponse() { + public StartILMResponse() { } - public PutOperationModeResponse(boolean acknowledged) { + public StartILMResponse(boolean acknowledged) { super(acknowledged); } } \ No newline at end of file diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequest.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequest.java new file mode 100644 index 0000000000000..0054ae05de477 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequest.java @@ -0,0 +1,50 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.protocol.xpack.indexlifecycle; + +import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.support.master.AcknowledgedRequest; + +public class StopILMRequest extends AcknowledgedRequest { + + public StopILMRequest() { + } + + @Override + public ActionRequestValidationException validate() { + return null; + } + + @Override + public int hashCode() { + return 75; + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj.getClass() != getClass()) { + return false; + } + return true; + } +} \ No newline at end of file diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java new file mode 100644 index 0000000000000..c0e509d8932a0 --- /dev/null +++ b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java @@ -0,0 +1,38 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.protocol.xpack.indexlifecycle; + +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.common.xcontent.ToXContentObject; +import org.elasticsearch.common.xcontent.XContentParser; + +public class StopILMResponse extends AcknowledgedResponse implements ToXContentObject { + + public static StopILMResponse fromXContent(XContentParser parser) { + return new StopILMResponse(parseAcknowledged(parser)); + } + + public StopILMResponse() { + } + + public StopILMResponse(boolean acknowledged) { + super(acknowledged); + } +} \ No newline at end of file diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java deleted file mode 100644 index a5b7aa010283c..0000000000000 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeRequestTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.protocol.xpack.indexlifecycle; - -import org.elasticsearch.test.AbstractStreamableTestCase; - -import java.io.IOException; - -public class PutOperationModeRequestTests extends AbstractStreamableTestCase { - - @Override - protected PutOperationModeRequest createBlankInstance() { - return new PutOperationModeRequest(); - } - - @Override - protected PutOperationModeRequest createTestInstance() { - return new PutOperationModeRequest(randomFrom(OperationMode.STOPPING, OperationMode.RUNNING)); - } - - @Override - protected PutOperationModeRequest mutateInstance(PutOperationModeRequest instance) throws IOException { - return new PutOperationModeRequest( - randomValueOtherThan(instance.getMode(), () -> randomFrom(OperationMode.STOPPING, OperationMode.RUNNING))); - } - - public void testNullMode() { - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> new PutOperationModeRequest(null)); - assertEquals("mode cannot be null", exception.getMessage()); - } - - public void testStoppedMode() { - IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, - () -> new PutOperationModeRequest(OperationMode.STOPPED)); - assertEquals("cannot directly stop index-lifecycle", exception.getMessage()); - } - - public void testValidate() { - PutOperationModeRequest request = createTestInstance(); - assertNull(request.validate()); - } - -} diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequestTests.java new file mode 100644 index 0000000000000..5c754ca8a4875 --- /dev/null +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMRequestTests.java @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.protocol.xpack.indexlifecycle; + +import org.elasticsearch.test.AbstractStreamableTestCase; + +public class StartILMRequestTests extends AbstractStreamableTestCase { + + @Override + protected StartILMRequest createBlankInstance() { + return new StartILMRequest(); + } + + @Override + protected StartILMRequest createTestInstance() { + return new StartILMRequest(); + } + + public void testValidate() { + StartILMRequest request = createTestInstance(); + assertNull(request.validate()); + } + +} diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java similarity index 60% rename from x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java rename to x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java index e2b8ab923ebaa..67c10af7b05c3 100644 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/PutOperationModeResponseTests.java +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java @@ -24,26 +24,26 @@ import java.io.IOException; -public class PutOperationModeResponseTests extends AbstractStreamableXContentTestCase { +public class StartILMResponseTests extends AbstractStreamableXContentTestCase { @Override - protected PutOperationModeResponse createBlankInstance() { - return new PutOperationModeResponse(); + protected StartILMResponse createBlankInstance() { + return new StartILMResponse(); } @Override - protected PutOperationModeResponse createTestInstance() { - return new PutOperationModeResponse(randomBoolean()); + protected StartILMResponse createTestInstance() { + return new StartILMResponse(randomBoolean()); } @Override - protected PutOperationModeResponse mutateInstance(PutOperationModeResponse instance) throws IOException { - return new PutOperationModeResponse(instance.isAcknowledged() == false); + protected StartILMResponse mutateInstance(StartILMResponse instance) throws IOException { + return new StartILMResponse(instance.isAcknowledged() == false); } @Override - protected PutOperationModeResponse doParseInstance(XContentParser parser) throws IOException { - return PutOperationModeResponse.fromXContent(parser); + protected StartILMResponse doParseInstance(XContentParser parser) throws IOException { + return StartILMResponse.fromXContent(parser); } } diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequestTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequestTests.java new file mode 100644 index 0000000000000..9e5640bbd1594 --- /dev/null +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMRequestTests.java @@ -0,0 +1,41 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.protocol.xpack.indexlifecycle; + +import org.elasticsearch.test.AbstractStreamableTestCase; + +public class StopILMRequestTests extends AbstractStreamableTestCase { + + @Override + protected StopILMRequest createBlankInstance() { + return new StopILMRequest(); + } + + @Override + protected StopILMRequest createTestInstance() { + return new StopILMRequest(); + } + + public void testValidate() { + StopILMRequest request = createTestInstance(); + assertNull(request.validate()); + } + +} diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java new file mode 100644 index 0000000000000..d212461ae5daa --- /dev/null +++ b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java @@ -0,0 +1,49 @@ +/* + * Licensed to Elasticsearch under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.elasticsearch.protocol.xpack.indexlifecycle; + +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.test.AbstractStreamableXContentTestCase; + +import java.io.IOException; + +public class StopILMResponseTests extends AbstractStreamableXContentTestCase { + + @Override + protected StopILMResponse createBlankInstance() { + return new StopILMResponse(); + } + + @Override + protected StopILMResponse createTestInstance() { + return new StopILMResponse(randomBoolean()); + } + + @Override + protected StopILMResponse mutateInstance(StopILMResponse instance) throws IOException { + return new StopILMResponse(instance.isAcknowledged() == false); + } + + @Override + protected StopILMResponse doParseInstance(XContentParser parser) throws IOException { + return StopILMResponse.fromXContent(parser); + } + +} From 22736286be67c9ca9b9a23a2177c231d8a6c6914 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Thu, 9 Aug 2018 17:43:56 +0100 Subject: [PATCH 7/7] Addresses review comments --- .../client/IndexLifecycleClient.java | 19 ++++--- .../client/IndexLifecycleIT.java | 7 ++- .../indexlifecycle/action/StartILMAction.java | 8 +-- .../indexlifecycle/action/StopILMAction.java | 8 +-- .../action/TransportStartILMAction.java | 20 ++++---- .../action/TransportStopILMAction.java | 20 ++++---- .../indexlifecycle/StartILMResponse.java | 38 -------------- .../xpack/indexlifecycle/StopILMResponse.java | 38 -------------- .../indexlifecycle/StartILMResponseTests.java | 49 ------------------- .../indexlifecycle/StopILMResponseTests.java | 49 ------------------- 10 files changed, 40 insertions(+), 216 deletions(-) delete mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java delete mode 100644 x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java delete mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java delete mode 100644 x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java index 1c5b58d90603c..21fb4a0062402 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/IndexLifecycleClient.java @@ -20,14 +20,13 @@ package org.elasticsearch.client; import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; import java.io.IOException; @@ -78,9 +77,9 @@ public void setIndexLifecyclePolicyAsync(SetIndexLifecyclePolicyRequest request, * @return the response * @throws IOException in case there is a problem sending the request or parsing back the response */ - public StartILMResponse startILM(StartILMRequest request, RequestOptions options) throws IOException { + public AcknowledgedResponse startILM(StartILMRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::startILM, options, - StartILMResponse::fromXContent, emptySet()); + AcknowledgedResponse::fromXContent, emptySet()); } /** @@ -91,9 +90,9 @@ public StartILMResponse startILM(StartILMRequest request, RequestOptions options * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @param listener the listener to be notified upon request completion */ - public void startILMAsync(StartILMRequest request, RequestOptions options, ActionListener listener) { + public void startILMAsync(StartILMRequest request, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::startILM, options, - StartILMResponse::fromXContent, listener, emptySet()); + AcknowledgedResponse::fromXContent, listener, emptySet()); } /** @@ -105,9 +104,9 @@ public void startILMAsync(StartILMRequest request, RequestOptions options, Actio * @return the response * @throws IOException in case there is a problem sending the request or parsing back the response */ - public StopILMResponse stopILM(StopILMRequest request, RequestOptions options) throws IOException { + public AcknowledgedResponse stopILM(StopILMRequest request, RequestOptions options) throws IOException { return restHighLevelClient.performRequestAndParseEntity(request, RequestConverters::stopILM, options, - StopILMResponse::fromXContent, emptySet()); + AcknowledgedResponse::fromXContent, emptySet()); } /** @@ -118,9 +117,9 @@ public StopILMResponse stopILM(StopILMRequest request, RequestOptions options) t * @param options the request options (e.g. headers), use {@link RequestOptions#DEFAULT} if nothing needs to be customized * @param listener the listener to be notified upon request completion */ - public void stopILMAsync(StopILMRequest request, RequestOptions options, ActionListener listener) { + public void stopILMAsync(StopILMRequest request, RequestOptions options, ActionListener listener) { restHighLevelClient.performRequestAsyncAndParseEntity(request, RequestConverters::stopILM, options, - StopILMResponse::fromXContent, listener, emptySet()); + AcknowledgedResponse::fromXContent, listener, emptySet()); } /** diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index a02b9fd8d359d..faa8e6ef498f4 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -25,6 +25,7 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest; import org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.ExplainLifecycleResponse; @@ -32,9 +33,7 @@ import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyRequest; import org.elasticsearch.protocol.xpack.indexlifecycle.SetIndexLifecyclePolicyResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; import org.hamcrest.Matchers; import java.util.Map; @@ -177,7 +176,7 @@ public void testStartStopILM() throws Exception { assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); StopILMRequest stopReq = new StopILMRequest(); - StopILMResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM, + AcknowledgedResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM, highLevelClient().indexLifecycle()::stopILMAsync); assertTrue(stopResponse.isAcknowledged()); @@ -189,7 +188,7 @@ public void testStartStopILM() throws Exception { Matchers.anyOf(equalTo("{\"operation_mode\":\"STOPPING\"}"), equalTo("{\"operation_mode\":\"STOPPED\"}"))); StartILMRequest startReq = new StartILMRequest(); - StartILMResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM, + AcknowledgedResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM, highLevelClient().indexLifecycle()::startILMAsync); assertTrue(startResponse.isAcknowledged()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java index 46e5d49cac29d..5d2f066d60b15 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StartILMAction.java @@ -7,9 +7,9 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.action.Action; -import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; +import org.elasticsearch.action.support.master.AcknowledgedResponse; -public class StartILMAction extends Action { +public class StartILMAction extends Action { public static final StartILMAction INSTANCE = new StartILMAction(); public static final String NAME = "cluster:admin/ilm/start"; @@ -18,8 +18,8 @@ protected StartILMAction() { } @Override - public StartILMResponse newResponse() { - return new StartILMResponse(); + public AcknowledgedResponse newResponse() { + return new AcknowledgedResponse(); } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java index a2cceda762a79..63adeabb30f90 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/action/StopILMAction.java @@ -7,9 +7,9 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.action.Action; -import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; +import org.elasticsearch.action.support.master.AcknowledgedResponse; -public class StopILMAction extends Action { +public class StopILMAction extends Action { public static final StopILMAction INSTANCE = new StopILMAction(); public static final String NAME = "cluster:admin/ilm/stop"; @@ -18,8 +18,8 @@ protected StopILMAction() { } @Override - public StopILMResponse newResponse() { - return new StopILMResponse(); + public AcknowledgedResponse newResponse() { + return new AcknowledgedResponse(); } } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java index 23d842f568bb3..3d26cf652875d 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStartILMAction.java @@ -8,6 +8,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterState; @@ -19,18 +20,17 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.StartILMResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.indexlifecycle.action.StartILMAction; import org.elasticsearch.xpack.indexlifecycle.OperationModeUpdateTask; -public class TransportStartILMAction extends TransportMasterNodeAction { +public class TransportStartILMAction extends TransportMasterNodeAction { @Inject public TransportStartILMAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, - IndexNameExpressionResolver indexNameExpressionResolver) { + ThreadPool threadPool, ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, StartILMAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, StartILMRequest::new); } @@ -41,22 +41,22 @@ protected String executor() { } @Override - protected StartILMResponse newResponse() { - return new StartILMResponse(); + protected AcknowledgedResponse newResponse() { + return new AcknowledgedResponse(); } @Override - protected void masterOperation(StartILMRequest request, ClusterState state, ActionListener listener) { + protected void masterOperation(StartILMRequest request, ClusterState state, ActionListener listener) { clusterService.submitStateUpdateTask("ilm_operation_mode_update", - new AckedClusterStateUpdateTask(request, listener) { + new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { return (new OperationModeUpdateTask(OperationMode.RUNNING)).execute(currentState); } @Override - protected StartILMResponse newResponse(boolean acknowledged) { - return new StartILMResponse(acknowledged); + protected AcknowledgedResponse newResponse(boolean acknowledged) { + return new AcknowledgedResponse(acknowledged); } }); } diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java index 9b58e88f1105e..992b5b286aee1 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportStopILMAction.java @@ -8,6 +8,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.cluster.AckedClusterStateUpdateTask; import org.elasticsearch.cluster.ClusterState; @@ -19,18 +20,17 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMRequest; -import org.elasticsearch.protocol.xpack.indexlifecycle.StopILMResponse; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; import org.elasticsearch.xpack.core.indexlifecycle.action.StopILMAction; import org.elasticsearch.xpack.indexlifecycle.OperationModeUpdateTask; -public class TransportStopILMAction extends TransportMasterNodeAction { +public class TransportStopILMAction extends TransportMasterNodeAction { @Inject public TransportStopILMAction(Settings settings, TransportService transportService, ClusterService clusterService, - ThreadPool threadPool, ActionFilters actionFilters, - IndexNameExpressionResolver indexNameExpressionResolver) { + ThreadPool threadPool, ActionFilters actionFilters, + IndexNameExpressionResolver indexNameExpressionResolver) { super(settings, StopILMAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, StopILMRequest::new); } @@ -41,22 +41,22 @@ protected String executor() { } @Override - protected StopILMResponse newResponse() { - return new StopILMResponse(); + protected AcknowledgedResponse newResponse() { + return new AcknowledgedResponse(); } @Override - protected void masterOperation(StopILMRequest request, ClusterState state, ActionListener listener) { + protected void masterOperation(StopILMRequest request, ClusterState state, ActionListener listener) { clusterService.submitStateUpdateTask("ilm_operation_mode_update", - new AckedClusterStateUpdateTask(request, listener) { + new AckedClusterStateUpdateTask(request, listener) { @Override public ClusterState execute(ClusterState currentState) { return (new OperationModeUpdateTask(OperationMode.STOPPING)).execute(currentState); } @Override - protected StopILMResponse newResponse(boolean acknowledged) { - return new StopILMResponse(acknowledged); + protected AcknowledgedResponse newResponse(boolean acknowledged) { + return new AcknowledgedResponse(acknowledged); } }); } diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java deleted file mode 100644 index 9913dc6347757..0000000000000 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.protocol.xpack.indexlifecycle; - -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentParser; - -public class StartILMResponse extends AcknowledgedResponse implements ToXContentObject { - - public static StartILMResponse fromXContent(XContentParser parser) { - return new StartILMResponse(parseAcknowledged(parser)); - } - - public StartILMResponse() { - } - - public StartILMResponse(boolean acknowledged) { - super(acknowledged); - } -} \ No newline at end of file diff --git a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java b/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java deleted file mode 100644 index c0e509d8932a0..0000000000000 --- a/x-pack/protocol/src/main/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponse.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.protocol.xpack.indexlifecycle; - -import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.common.xcontent.ToXContentObject; -import org.elasticsearch.common.xcontent.XContentParser; - -public class StopILMResponse extends AcknowledgedResponse implements ToXContentObject { - - public static StopILMResponse fromXContent(XContentParser parser) { - return new StopILMResponse(parseAcknowledged(parser)); - } - - public StopILMResponse() { - } - - public StopILMResponse(boolean acknowledged) { - super(acknowledged); - } -} \ No newline at end of file diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java deleted file mode 100644 index 67c10af7b05c3..0000000000000 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StartILMResponseTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.protocol.xpack.indexlifecycle; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; - -import java.io.IOException; - -public class StartILMResponseTests extends AbstractStreamableXContentTestCase { - - @Override - protected StartILMResponse createBlankInstance() { - return new StartILMResponse(); - } - - @Override - protected StartILMResponse createTestInstance() { - return new StartILMResponse(randomBoolean()); - } - - @Override - protected StartILMResponse mutateInstance(StartILMResponse instance) throws IOException { - return new StartILMResponse(instance.isAcknowledged() == false); - } - - @Override - protected StartILMResponse doParseInstance(XContentParser parser) throws IOException { - return StartILMResponse.fromXContent(parser); - } - -} diff --git a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java b/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java deleted file mode 100644 index d212461ae5daa..0000000000000 --- a/x-pack/protocol/src/test/java/org/elasticsearch/protocol/xpack/indexlifecycle/StopILMResponseTests.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to Elasticsearch under one or more contributor - * license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright - * ownership. Elasticsearch licenses this file to you under - * the Apache License, Version 2.0 (the "License"); you may - * not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.elasticsearch.protocol.xpack.indexlifecycle; - -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.test.AbstractStreamableXContentTestCase; - -import java.io.IOException; - -public class StopILMResponseTests extends AbstractStreamableXContentTestCase { - - @Override - protected StopILMResponse createBlankInstance() { - return new StopILMResponse(); - } - - @Override - protected StopILMResponse createTestInstance() { - return new StopILMResponse(randomBoolean()); - } - - @Override - protected StopILMResponse mutateInstance(StopILMResponse instance) throws IOException { - return new StopILMResponse(instance.isAcknowledged() == false); - } - - @Override - protected StopILMResponse doParseInstance(XContentParser parser) throws IOException { - return StopILMResponse.fromXContent(parser); - } - -}