[ML] Extract MlInitializationService steps into respective methods (elastic/x-pack-elasticsearch#560)
Original commit: elastic/x-pack-elasticsearch@c43d02e752b6626593b76bfb1746ea5bbf8e9587
@@ -46,6 +46,14 @@ public class MlInitializationService extends AbstractComponent implements Cluste
public void clusterChanged(ClusterChangedEvent event) {
if (event.localNodeMaster()) {
MetaData metaData = event.state().metaData();
+ installMlMetadata(metaData);
+ createMlAuditIndex(metaData);
+ createMlMetaIndex(metaData);
+ createStateIndex(metaData);
+ }
+ }
+
+ private void installMlMetadata(MetaData metaData) {
if (metaData.custom(MlMetadata.TYPE) == null) {
if (installMlMetadataCheck.compareAndSet(false, true)) {
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> {
@@ -69,6 +77,9 @@ public class MlInitializationService extends AbstractComponent implements Cluste
} else {
installMlMetadataCheck.set(false);
}
+ }
+
+ private void createMlAuditIndex(MetaData metaData) {
if (metaData.hasIndex(Auditor.NOTIFICATIONS_INDEX) == false) {
if (createMlAuditIndexCheck.compareAndSet(false, true)) {
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> {
@@ -88,6 +99,9 @@ public class MlInitializationService extends AbstractComponent implements Cluste
});
}
}
+ }
+
+ private void createMlMetaIndex(MetaData metaData) {
if (metaData.hasIndex(JobProvider.ML_META_INDEX) == false) {
if (createMlMetaIndexCheck.compareAndSet(false, true)) {
threadPool.executor(ThreadPool.Names.GENERIC).execute(() -> {
@@ -106,6 +120,9 @@ public class MlInitializationService extends AbstractComponent implements Cluste
});
}
}
+ }
+
+ private void createStateIndex(MetaData metaData) {
String stateIndexName = AnomalyDetectorsIndex.jobStateIndexName();
if (metaData.hasIndex(stateIndexName) == false) {
if (createStateIndexCheck.compareAndSet(false, true)) {
@@ -127,4 +144,3 @@ public class MlInitializationService extends AbstractComponent implements Cluste
}
}
}
-}
