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 19aeceea515..fcdac59a4df 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 @@ -63,6 +63,8 @@ public class IndexLifecycle extends Plugin { Setting.Property.Dynamic, Setting.Property.IndexScope); public static final Setting LIFECYCLE_TIMESERIES_PHASE_SETTING = Setting.simpleString("index.lifecycle.phase", Setting.Property.Dynamic, Setting.Property.IndexScope); + public static final Setting LIFECYCLE_TIMESERIES_ACTION_SETTING = Setting.simpleString("index.lifecycle.action", + Setting.Property.Dynamic, Setting.Property.IndexScope); public IndexLifecycle(Settings settings) { this.settings = settings; @@ -84,7 +86,10 @@ public class IndexLifecycle extends Plugin { @Override public List> getSettings() { - return Arrays.asList(LIFECYCLE_TIMESERIES_NAME_SETTING, LIFECYCLE_TIMESERIES_PHASE_SETTING); + return Arrays.asList( + LIFECYCLE_TIMESERIES_NAME_SETTING, + LIFECYCLE_TIMESERIES_PHASE_SETTING, + LIFECYCLE_TIMESERIES_ACTION_SETTING); } public Collection createComponents(InternalClient internalClient, ClusterService clusterService, Clock clock, 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 07377bf5c64..f3e707af199 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 @@ -17,15 +17,16 @@ import org.elasticsearch.common.component.AbstractComponent; import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xpack.ml.MlMetadata; import org.elasticsearch.xpack.scheduler.SchedulerEngine; import org.elasticsearch.xpack.security.InternalClient; +import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule; +import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interval; +import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interval.Unit; import java.io.Closeable; import java.io.IOException; import java.time.Clock; -import static org.elasticsearch.xpack.indexlifecycle.IndexLifecycle.LIFECYCLE_TIMESERIES_NAME_SETTING; import static org.elasticsearch.xpack.indexlifecycle.IndexLifecycle.NAME; public class IndexLifecycleInitialisationService extends AbstractComponent @@ -53,27 +54,27 @@ public class IndexLifecycleInitialisationService extends AbstractComponent if (event.localNodeMaster()) { MetaData metaData = event.state().metaData(); installMlMetadata(metaData); - if (scheduler.get() == null) { - scheduler.set(new SchedulerEngine(clock)); - scheduler.get().register(this); - scheduler.get().add(new SchedulerEngine.Job(NAME, ((startTime, now) -> now + 1000))); - } } } @Override public void triggered(SchedulerEngine.Event event) { - 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 - } - }); + 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 + // } + // }); + } } private void installMlMetadata(MetaData metaData) { - if (metaData.custom(MlMetadata.TYPE) == null) { + IndexLifecycleMetadata indexLifecycleMetadata = metaData.custom(IndexLifecycleMetadata.TYPE); + if (indexLifecycleMetadata == null) { threadPool.executor(ThreadPool.Names.GENERIC) .execute(() -> clusterService.submitStateUpdateTask("install-index-lifecycle-metadata", new ClusterStateUpdateTask() { @Override @@ -94,6 +95,13 @@ public class IndexLifecycleInitialisationService extends AbstractComponent logger.error("unable to install index lifecycle metadata", e); } })); + } else { + if (scheduler.get() == null) { + scheduler.set(new SchedulerEngine(clock)); + scheduler.get().register(this); + scheduler.get().add(new SchedulerEngine.Job(NAME, + new IntervalSchedule(new Interval(indexLifecycleMetadata.getPollInterval(), Unit.SECONDS)))); + } } } diff --git a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadata.java b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadata.java index e921357122a..0412bd054bc 100644 --- a/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadata.java +++ b/x-pack/plugin/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadata.java @@ -32,7 +32,7 @@ public class IndexLifecycleMetadata implements MetaData.Custom { public static final ParseField POLICIES_FIELD = new ParseField("policies"); public static final ParseField POLL_INTERVAL_FIELD = new ParseField("poll_interval"); - public static final IndexLifecycleMetadata EMPTY_METADATA = new IndexLifecycleMetadata(Collections.emptySortedMap(), 300000); + public static final IndexLifecycleMetadata EMPTY_METADATA = new IndexLifecycleMetadata(Collections.emptySortedMap(), 3); @SuppressWarnings("unchecked") public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( TYPE, a -> new IndexLifecycleMetadata((SortedMap) a[0], (long) a[1]));