diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationService.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationService.java index f3e707af199..4eaa2fc2ede 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationService.java +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationService.java @@ -5,6 +5,8 @@ */ package org.elasticsearch.xpack.indexlifecycle; +import com.google.common.base.Strings; + import org.apache.logging.log4j.Logger; import org.apache.lucene.util.SetOnce; import org.elasticsearch.cluster.ClusterChangedEvent; @@ -26,6 +28,7 @@ import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interva import java.io.Closeable; import java.io.IOException; import java.time.Clock; +import java.util.SortedMap; import static org.elasticsearch.xpack.indexlifecycle.IndexLifecycle.NAME; @@ -61,14 +64,16 @@ public class IndexLifecycleInitialisationService extends AbstractComponent public void triggered(SchedulerEngine.Event event) { if (event.getJobName().equals(NAME)) { logger.error("Job triggered: " + event.getJobName() + ", " + event.getScheduledTime() + ", " + event.getTriggeredTime()); - // clusterService.state().getMetaData().getIndices().valuesIt() - // .forEachRemaining((idxMeta) -> { - // if (LIFECYCLE_TIMESERIES_NAME_SETTING.get(idxMeta.getSettings()) - // != null) { - // // get policy by name - // // idxMeta.getIndex(), idxMeta.getCreationDate(),client - // } - // }); + IndexLifecycleMetadata indexLifecycleMetadata = clusterService.state().metaData().custom(IndexLifecycleMetadata.TYPE); + SortedMap policies = indexLifecycleMetadata.getPolicies(); + clusterService.state().getMetaData().getIndices().valuesIt().forEachRemaining((idxMeta) -> { + String policyName = IndexLifecycle.LIFECYCLE_TIMESERIES_NAME_SETTING.get(idxMeta.getSettings()); + if (Strings.isNullOrEmpty(policyName) == false) { + logger.error("Checking index for next action: " + idxMeta.getIndex().getName() + " (" + policyName + ")"); + LifecyclePolicy policy = policies.get(policyName); + policy.execute(idxMeta, client); + } + }); } } diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java index 2d2c90de039..d0eebc974b6 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/LifecyclePolicy.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.indexlifecycle; import org.elasticsearch.cluster.AbstractDiffable; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.io.stream.StreamInput; @@ -16,6 +17,7 @@ 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.xpack.security.InternalClient; import java.io.IOException; import java.util.List; @@ -78,4 +80,7 @@ public class LifecyclePolicy extends AbstractDiffable implement builder.endObject(); return builder; } + + public void execute(IndexMetaData idxMeta, InternalClient client) { + } }