From a37df9092ed1a210b25790e65f2db4ac6a4af82a Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Wed, 3 Jan 2018 10:45:33 +0000 Subject: [PATCH] Moves Actions and related to plugin:core This change moves the Action classes and referenced data model classes to the new :x-pack-elasticsearch:plugin:core project in preparation for splitting the x-pack features into their own gradle modules. Note that the TransportAction classes had to be promoted to their own class file (rather than being inner classes to their Action) so they can remain in the plugin project (and will late be move to the `index-lifecycle` project when its created. --- .../xpack/indexlifecycle/AllocateAction.java | 3 - .../xpack/indexlifecycle/DeleteAction.java | 0 .../indexlifecycle/ForceMergeAction.java | 3 - .../indexlifecycle/IndexLifecycleContext.java | 0 .../xpack/indexlifecycle/LifecycleAction.java | 0 .../xpack/indexlifecycle/LifecyclePolicy.java | 0 .../xpack/indexlifecycle/LifecycleType.java | 0 .../indexlifecycle/ObjectParserUtils.java | 0 .../xpack/indexlifecycle/Phase.java | 0 .../xpack/indexlifecycle/ReplicasAction.java | 3 - .../xpack/indexlifecycle/RolloverAction.java | 0 .../xpack/indexlifecycle/ShrinkAction.java | 3 - .../TimeseriesLifecycleType.java | 0 .../action/DeleteLifecycleAction.java | 70 ---------------- .../action/GetLifecycleAction.java | 54 ------------- .../action/PutLifecycleAction.java | 71 ---------------- .../xpack/indexlifecycle/IndexLifecycle.java | 9 ++- .../action/TransportDeleteLifcycleAction.java | 80 ++++++++++++++++++ .../action/TransportGetLifecycleAction.java | 64 +++++++++++++++ .../action/TransportPutLifecycleAction.java | 81 +++++++++++++++++++ 20 files changed, 231 insertions(+), 210 deletions(-) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java (92%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/DeleteAction.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java (98%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleContext.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleAction.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleType.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/ObjectParserUtils.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/Phase.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java (94%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/RolloverAction.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java (92%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/TimeseriesLifecycleType.java (100%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java (55%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java (64%) rename x-pack/plugin/{ => core}/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java (60%) create mode 100644 x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportDeleteLifcycleAction.java create mode 100644 x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetLifecycleAction.java create mode 100644 x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java similarity index 92% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java index 1b8f5fa9300..bec7cec3e3c 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/AllocateAction.java @@ -5,13 +5,11 @@ */ package org.elasticsearch.xpack.indexlifecycle; -import org.apache.logging.log4j.Logger; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -25,7 +23,6 @@ import java.io.IOException; public class AllocateAction implements LifecycleAction { public static final String NAME = "allocate"; - private static final Logger logger = ESLoggerFactory.getLogger(AllocateAction.class); private static final ObjectParser PARSER = new ObjectParser<>(NAME, AllocateAction::new); public static AllocateAction parse(XContentParser parser) { diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/DeleteAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/DeleteAction.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/DeleteAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/DeleteAction.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java similarity index 98% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java index e8c1fd7b5ac..1425eec84d5 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ForceMergeAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.indexlifecycle; -import org.apache.logging.log4j.Logger; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; @@ -18,7 +17,6 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -39,7 +37,6 @@ public class ForceMergeAction implements LifecycleAction { public static final String NAME = "forcemerge"; public static final ParseField MAX_NUM_SEGMENTS_FIELD = new ParseField("max_num_segments"); - private static final Logger logger = ESLoggerFactory.getLogger(ForceMergeAction.class); private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, false, a -> { int maxNumSegments = (Integer) a[0]; diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleContext.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleContext.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleContext.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleContext.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleAction.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleAction.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleType.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleType.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleType.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecycleType.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ObjectParserUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ObjectParserUtils.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ObjectParserUtils.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ObjectParserUtils.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/Phase.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/Phase.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/Phase.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/Phase.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java similarity index 94% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java index b00ccbbb443..07112f28166 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ReplicasAction.java @@ -5,14 +5,12 @@ */ package org.elasticsearch.xpack.indexlifecycle; -import org.apache.logging.log4j.Logger; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -29,7 +27,6 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.constru public class ReplicasAction implements LifecycleAction { public static final String NAME = "replicas"; - private static final Logger logger = ESLoggerFactory.getLogger(ReplicasAction.class); public static final ParseField NUMBER_OF_REPLICAS_FIELD = new ParseField("number_of_replicas"); private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, false, a -> new ReplicasAction((Integer) a[0])); diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/RolloverAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/RolloverAction.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/RolloverAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/RolloverAction.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java similarity index 92% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java index e6a351cb5c4..99ff9d7a69c 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/ShrinkAction.java @@ -5,13 +5,11 @@ */ package org.elasticsearch.xpack.indexlifecycle; -import org.apache.logging.log4j.Logger; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -25,7 +23,6 @@ import java.io.IOException; public class ShrinkAction implements LifecycleAction { public static final String NAME = "shrink"; - private static final Logger logger = ESLoggerFactory.getLogger(ShrinkAction.class); private static final ObjectParser PARSER = new ObjectParser<>(NAME, ShrinkAction::new); public static ShrinkAction parse(XContentParser parser) { diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/TimeseriesLifecycleType.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/TimeseriesLifecycleType.java similarity index 100% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/TimeseriesLifecycleType.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/TimeseriesLifecycleType.java diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java similarity index 55% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java index 7c4ee01a7d8..8d8e7f8545b 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/DeleteLifecycleAction.java @@ -5,40 +5,21 @@ */ package org.elasticsearch.xpack.indexlifecycle.action; -import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.client.ElasticsearchClient; -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.metadata.MetaData; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata; -import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy; import java.io.IOException; import java.util.Objects; -import java.util.SortedMap; -import java.util.TreeMap; public class DeleteLifecycleAction extends Action { @@ -171,55 +152,4 @@ public class DeleteLifecycleAction } - public static class TransportAction extends TransportMasterNodeAction { - - @Inject - public TransportAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, DeleteLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, Request::new); - } - - @Override - protected String executor() { - return ThreadPool.Names.SAME; - } - - @Override - protected Response newResponse() { - return new Response(); - } - - @Override - protected void masterOperation(Request request, ClusterState state, ActionListener listener) throws Exception { - clusterService.submitStateUpdateTask("delete-lifecycle-" + request.getPolicyName(), - new AckedClusterStateUpdateTask(request, listener) { - @Override - protected Response newResponse(boolean acknowledged) { - return new Response(acknowledged); - } - - @Override - public ClusterState execute(ClusterState currentState) throws Exception { - ClusterState.Builder newState = ClusterState.builder(currentState); - IndexLifecycleMetadata currentMetadata = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); - if (currentMetadata.getPolicies().containsKey(request.getPolicyName()) == false) { - throw new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName()); - } - SortedMap newPolicies = new TreeMap<>(currentMetadata.getPolicies()); - newPolicies.remove(request.getPolicyName()); - IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies); - newState.metaData(MetaData.builder(currentState.getMetaData()) - .putCustom(IndexLifecycleMetadata.TYPE, newMetadata).build()); - return newState.build(); - } - }); - } - - @Override - protected ClusterBlockException checkBlock(Request request, ClusterState state) { - return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); - } - } - } diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java similarity index 64% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java index 1b4d71c2c85..bb993993faa 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/GetLifecycleAction.java @@ -5,32 +5,18 @@ */ package org.elasticsearch.xpack.indexlifecycle.action; -import org.elasticsearch.ResourceNotFoundException; import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; import org.elasticsearch.action.ActionResponse; -import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.AcknowledgedRequest; -import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.client.ElasticsearchClient; -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.ParseField; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy; import java.io.IOException; @@ -171,44 +157,4 @@ public class GetLifecycleAction } - public static class TransportAction extends TransportMasterNodeAction { - - @Inject - public TransportAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, GetLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, Request::new); - } - - @Override - protected String executor() { - return ThreadPool.Names.SAME; - } - - @Override - protected Response newResponse() { - return new Response(); - } - - @Override - protected void masterOperation(Request request, ClusterState state, ActionListener listener) throws Exception { - IndexLifecycleMetadata metadata = clusterService.state().metaData().custom(IndexLifecycleMetadata.TYPE); - if (metadata == null) { - listener.onFailure(new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName())); - } else { - LifecyclePolicy policy = metadata.getPolicies().get(request.getPolicyName()); - if (policy == null) { - listener.onFailure(new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName())); - } else { - listener.onResponse(new Response(policy)); - } - } - } - - @Override - protected ClusterBlockException checkBlock(Request request, ClusterState state) { - return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); - } - } - } diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java similarity index 60% rename from x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java rename to x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java index 689efd014b7..4385650e03e 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/PutLifecycleAction.java @@ -5,44 +5,26 @@ */ package org.elasticsearch.xpack.indexlifecycle.action; -import org.elasticsearch.ResourceAlreadyExistsException; import org.elasticsearch.action.Action; -import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionRequestValidationException; -import org.elasticsearch.action.support.ActionFilters; import org.elasticsearch.action.support.master.AcknowledgedRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; -import org.elasticsearch.action.support.master.TransportMasterNodeAction; import org.elasticsearch.client.ElasticsearchClient; -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.metadata.MetaData; -import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ConstructingObjectParser; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy; import java.io.IOException; import java.util.Objects; -import java.util.SortedMap; -import java.util.TreeMap; public class PutLifecycleAction extends Action { public static final PutLifecycleAction INSTANCE = new PutLifecycleAction(); @@ -196,57 +178,4 @@ public class PutLifecycleAction extends Action { - - @Inject - public TransportAction(Settings settings, TransportService transportService, ClusterService clusterService, ThreadPool threadPool, - ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { - super(settings, PutLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, - indexNameExpressionResolver, - Request::new); - } - - @Override - protected String executor() { - return ThreadPool.Names.SAME; - } - - @Override - protected Response newResponse() { - return new Response(); - } - - @Override - protected void masterOperation(Request request, ClusterState state, ActionListener listener) throws Exception { - clusterService.submitStateUpdateTask("put-lifecycle-" + request.getPolicy().getName(), - new AckedClusterStateUpdateTask(request, listener) { - @Override - protected Response newResponse(boolean acknowledged) { - return new Response(acknowledged); - } - - @Override - public ClusterState execute(ClusterState currentState) throws Exception { - ClusterState.Builder newState = ClusterState.builder(currentState); - IndexLifecycleMetadata currentMetadata = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); - if (currentMetadata.getPolicies().containsKey(request.getPolicy().getName())) { - throw new ResourceAlreadyExistsException("Lifecycle policy already exists: {}", - request.getPolicy().getName()); - } - SortedMap newPolicies = new TreeMap<>(currentMetadata.getPolicies()); - newPolicies.put(request.getPolicy().getName(), request.getPolicy()); - IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies); - newState.metaData(MetaData.builder(currentState.getMetaData()) - .putCustom(IndexLifecycleMetadata.TYPE, newMetadata).build()); - return newState.build(); - } - }); - } - - @Override - protected ClusterBlockException checkBlock(Request request, ClusterState state) { - return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); - } - } - } diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java index 0647051359a..152d3a84636 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycle.java @@ -38,6 +38,9 @@ import org.elasticsearch.xpack.indexlifecycle.action.PutLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestDeleteLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestGetLifecycleAction; import org.elasticsearch.xpack.indexlifecycle.action.RestPutLifecycleAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportPutLifecycleAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportGetLifecycleAction; +import org.elasticsearch.xpack.indexlifecycle.action.TransportDeleteLifcycleAction; import java.io.IOException; import java.time.Clock; @@ -160,9 +163,9 @@ public class IndexLifecycle extends Plugin { public List> getActions() { return Arrays.asList( - new ActionHandler<>(PutLifecycleAction.INSTANCE, PutLifecycleAction.TransportAction.class), - new ActionHandler<>(GetLifecycleAction.INSTANCE, GetLifecycleAction.TransportAction.class), - new ActionHandler<>(DeleteLifecycleAction.INSTANCE, DeleteLifecycleAction.TransportAction.class)); + new ActionHandler<>(PutLifecycleAction.INSTANCE, TransportPutLifecycleAction.class), + new ActionHandler<>(GetLifecycleAction.INSTANCE, TransportGetLifecycleAction.class), + new ActionHandler<>(DeleteLifecycleAction.INSTANCE, TransportDeleteLifcycleAction.class)); } } diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportDeleteLifcycleAction.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportDeleteLifcycleAction.java new file mode 100644 index 00000000000..6c5c1b3b876 --- /dev/null +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportDeleteLifcycleAction.java @@ -0,0 +1,80 @@ +/* + * 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.ResourceNotFoundException; +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.metadata.MetaData; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata; +import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy; +import org.elasticsearch.xpack.indexlifecycle.action.DeleteLifecycleAction.Request; +import org.elasticsearch.xpack.indexlifecycle.action.DeleteLifecycleAction.Response; + +import java.util.SortedMap; +import java.util.TreeMap; + +public class TransportDeleteLifcycleAction extends TransportMasterNodeAction { + + @Inject + public TransportDeleteLifcycleAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + super(settings, DeleteLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, + indexNameExpressionResolver, Request::new); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected Response newResponse() { + return new Response(); + } + + @Override + protected void masterOperation(Request request, ClusterState state, ActionListener listener) throws Exception { + clusterService.submitStateUpdateTask("delete-lifecycle-" + request.getPolicyName(), + new AckedClusterStateUpdateTask(request, listener) { + @Override + protected Response newResponse(boolean acknowledged) { + return new Response(acknowledged); + } + + @Override + public ClusterState execute(ClusterState currentState) throws Exception { + ClusterState.Builder newState = ClusterState.builder(currentState); + IndexLifecycleMetadata currentMetadata = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); + if (currentMetadata.getPolicies().containsKey(request.getPolicyName()) == false) { + throw new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName()); + } + SortedMap newPolicies = new TreeMap<>(currentMetadata.getPolicies()); + newPolicies.remove(request.getPolicyName()); + IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies); + newState.metaData(MetaData.builder(currentState.getMetaData()) + .putCustom(IndexLifecycleMetadata.TYPE, newMetadata).build()); + return newState.build(); + } + }); + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } +} \ No newline at end of file diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetLifecycleAction.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetLifecycleAction.java new file mode 100644 index 00000000000..4e7124be798 --- /dev/null +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportGetLifecycleAction.java @@ -0,0 +1,64 @@ +/* + * 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.ResourceNotFoundException; +import org.elasticsearch.action.ActionListener; +import org.elasticsearch.action.support.ActionFilters; +import org.elasticsearch.action.support.master.TransportMasterNodeAction; +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.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata; +import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy; +import org.elasticsearch.xpack.indexlifecycle.action.GetLifecycleAction.Request; +import org.elasticsearch.xpack.indexlifecycle.action.GetLifecycleAction.Response; + +public class TransportGetLifecycleAction extends TransportMasterNodeAction { + + @Inject + public TransportGetLifecycleAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + super(settings, GetLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + Request::new); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected Response newResponse() { + return new Response(); + } + + @Override + protected void masterOperation(Request request, ClusterState state, ActionListener listener) throws Exception { + IndexLifecycleMetadata metadata = clusterService.state().metaData().custom(IndexLifecycleMetadata.TYPE); + if (metadata == null) { + listener.onFailure(new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName())); + } else { + LifecyclePolicy policy = metadata.getPolicies().get(request.getPolicyName()); + if (policy == null) { + listener.onFailure(new ResourceNotFoundException("Lifecycle policy not found: {}", request.getPolicyName())); + } else { + listener.onResponse(new Response(policy)); + } + } + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } +} \ No newline at end of file diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java new file mode 100644 index 00000000000..121a7d2dc73 --- /dev/null +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportPutLifecycleAction.java @@ -0,0 +1,81 @@ +/* + * 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.ResourceAlreadyExistsException; +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.metadata.MetaData; +import org.elasticsearch.cluster.service.ClusterService; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.threadpool.ThreadPool; +import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata; +import org.elasticsearch.xpack.indexlifecycle.LifecyclePolicy; +import org.elasticsearch.xpack.indexlifecycle.action.PutLifecycleAction.Request; +import org.elasticsearch.xpack.indexlifecycle.action.PutLifecycleAction.Response; + +import java.util.SortedMap; +import java.util.TreeMap; + +public class TransportPutLifecycleAction extends TransportMasterNodeAction { + + @Inject + public TransportPutLifecycleAction(Settings settings, TransportService transportService, ClusterService clusterService, + ThreadPool threadPool, ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) { + super(settings, PutLifecycleAction.NAME, transportService, clusterService, threadPool, actionFilters, indexNameExpressionResolver, + Request::new); + } + + @Override + protected String executor() { + return ThreadPool.Names.SAME; + } + + @Override + protected Response newResponse() { + return new Response(); + } + + @Override + protected void masterOperation(Request request, ClusterState state, ActionListener listener) throws Exception { + clusterService.submitStateUpdateTask("put-lifecycle-" + request.getPolicy().getName(), + new AckedClusterStateUpdateTask(request, listener) { + @Override + protected Response newResponse(boolean acknowledged) { + return new Response(acknowledged); + } + + @Override + public ClusterState execute(ClusterState currentState) throws Exception { + ClusterState.Builder newState = ClusterState.builder(currentState); + IndexLifecycleMetadata currentMetadata = currentState.metaData().custom(IndexLifecycleMetadata.TYPE); + if (currentMetadata.getPolicies().containsKey(request.getPolicy().getName())) { + throw new ResourceAlreadyExistsException("Lifecycle policy already exists: {}", + request.getPolicy().getName()); + } + SortedMap newPolicies = new TreeMap<>(currentMetadata.getPolicies()); + newPolicies.put(request.getPolicy().getName(), request.getPolicy()); + IndexLifecycleMetadata newMetadata = new IndexLifecycleMetadata(newPolicies); + newState.metaData(MetaData.builder(currentState.getMetaData()) + .putCustom(IndexLifecycleMetadata.TYPE, newMetadata).build()); + return newState.build(); + } + }); + } + + @Override + protected ClusterBlockException checkBlock(Request request, ClusterState state) { + return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_WRITE); + } +} \ No newline at end of file