diff --git a/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java b/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java index 17d646a6a19..4153455539a 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistry.java @@ -40,7 +40,6 @@ import org.elasticsearch.xpack.ml.notifications.Auditor; import java.io.IOException; import java.util.Collections; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.BiConsumer; @@ -114,8 +113,8 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen } private void addMlNotificationsIndexTemplate(MetaData metaData) { - if (templateIsPresentAndUpToDate(Auditor.NOTIFICATIONS_INDEX, metaData) == false) { - if (putMlNotificationsIndexTemplateCheck.compareAndSet(false, true)) { + if (putMlNotificationsIndexTemplateCheck.compareAndSet(false, true)) { + if (templateIsPresentAndUpToDate(Auditor.NOTIFICATIONS_INDEX, metaData) == false) { threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> { putNotificationMessageIndexTemplate((result, error) -> { putMlNotificationsIndexTemplateCheck.set(false); @@ -127,13 +126,15 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen } }); }); + } else { + putMlNotificationsIndexTemplateCheck.set(false); } } } private void addMlMetaIndexTemplate(MetaData metaData) { - if (templateIsPresentAndUpToDate(AnomalyDetectorsIndex.ML_META_INDEX, metaData) == false) { - if (putMlMetaIndexTemplateCheck.compareAndSet(false, true)) { + if (putMlMetaIndexTemplateCheck.compareAndSet(false, true)) { + if (templateIsPresentAndUpToDate(AnomalyDetectorsIndex.ML_META_INDEX, metaData) == false) { threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> { putMetaIndexTemplate((result, error) -> { putMlMetaIndexTemplateCheck.set(false); @@ -145,14 +146,16 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen } }); }); + } else { + putMlMetaIndexTemplateCheck.set(false); } } } private void addStateIndexTemplate(MetaData metaData) { String stateIndexName = AnomalyDetectorsIndex.jobStateIndexName(); - if (templateIsPresentAndUpToDate(stateIndexName, metaData) == false) { - if (putStateIndexTemplateCheck.compareAndSet(false, true)) { + if (putStateIndexTemplateCheck.compareAndSet(false, true)) { + if (templateIsPresentAndUpToDate(stateIndexName, metaData) == false) { threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> { putJobStateIndexTemplate((result, error) -> { putStateIndexTemplateCheck.set(false); @@ -163,13 +166,15 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen } }); }); + } else { + putStateIndexTemplateCheck.set(false); } } } private void addResultsIndexTemplate(MetaData metaData) { - if (templateIsPresentAndUpToDate(AnomalyDetectorsIndex.jobResultsIndexPrefix(), metaData) == false) { - if (putResultsIndexTemplateCheck.compareAndSet(false, true)) { + if (putResultsIndexTemplateCheck.compareAndSet(false, true)) { + if (templateIsPresentAndUpToDate(AnomalyDetectorsIndex.jobResultsIndexPrefix(), metaData) == false) { threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> { putJobResultsIndexTemplate((result, error) -> { putResultsIndexTemplateCheck.set(false); @@ -182,6 +187,8 @@ public class MachineLearningTemplateRegistry extends AbstractComponent implemen } }); }); + } else { + putResultsIndexTemplateCheck.set(false); } } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java b/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java index 9255073d3f6..e61aee8f232 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/ml/MachineLearningTemplateRegistryTests.java @@ -148,7 +148,7 @@ public class MachineLearningTemplateRegistryTests extends ESTestCase { verify(threadPool, times(0)).executor(anyString()); assertFalse(templateRegistry.putMlNotificationsIndexTemplateCheck.get()); assertFalse(templateRegistry.putMlMetaIndexTemplateCheck.get()); - assertFalse(templateRegistry.putMlNotificationsIndexTemplateCheck.get()); + assertFalse(templateRegistry.putStateIndexTemplateCheck.get()); assertFalse(templateRegistry.putResultsIndexTemplateCheck.get()); } @@ -320,4 +320,4 @@ public class MachineLearningTemplateRegistryTests extends ESTestCase { .put(MapperService.INDEX_MAPPING_TOTAL_FIELDS_LIMIT_SETTING.getKey(), 1001L) .build(); } -} \ No newline at end of file +}