From 7b764f9bb5a95796eb7c1bd534562dfacec68623 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Tue, 19 Oct 2021 08:35:10 +0100 Subject: [PATCH 1/3] [ML] Removing legacy code from ML/transform auditor The ML/transform auditor had support for running in a mixed version cluster containing nodes that didn't understand composable templates. This functionality is no longer required in version 8, so this PR removes it. --- .../common/notifications/AbstractAuditor.java | 21 ++----- .../xpack/core/ml/utils/MlIndexAndAlias.java | 62 +++++-------------- .../xpack/core/template/TemplateUtils.java | 24 ++----- .../notifications_index_legacy_template.json | 17 ----- .../notifications/AbstractAuditorTests.java | 34 ++++------ .../core/ml/utils/MlIndexAndAliasTests.java | 42 +------------ .../xpack/ml/MachineLearning.java | 14 ++--- .../xpack/ml/MlIndexTemplateRegistry.java | 17 ----- .../ml/notifications/AbstractMlAuditor.java | 2 - .../xpack/ml/MlSingleNodeTestCase.java | 2 +- .../xpack/ml/support/BaseMlIntegTestCase.java | 2 +- .../integration/TransformAuditorIT.java | 7 +-- .../notifications/TransformAuditor.java | 39 +----------- 13 files changed, 50 insertions(+), 233 deletions(-) delete mode 100644 x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java index 9f6af80e15d40..b2175dd540354 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditor.java @@ -9,10 +9,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchParseException; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; @@ -24,7 +22,6 @@ import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xpack.core.ml.utils.MlIndexAndAlias; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; @@ -52,8 +49,6 @@ public abstract class AbstractAuditor { private final String nodeName; private final String auditIndex; private final String templateName; - private final Version versionComposableTemplateExpected; - private final Supplier legacyTemplateSupplier; private final Supplier templateSupplier; private final AbstractAuditMessageFactory messageFactory; private final AtomicBoolean hasLatestTemplate; @@ -64,16 +59,12 @@ public abstract class AbstractAuditor { protected AbstractAuditor(OriginSettingClient client, String auditIndex, - Version versionComposableTemplateExpected, - IndexTemplateConfig legacyTemplateConfig, IndexTemplateConfig templateConfig, String nodeName, AbstractAuditMessageFactory messageFactory, ClusterService clusterService) { - this(client, auditIndex, templateConfig.getTemplateName(), versionComposableTemplateExpected, - () -> new PutIndexTemplateRequest(legacyTemplateConfig.getTemplateName()) - .source(legacyTemplateConfig.loadBytes(), XContentType.JSON).masterNodeTimeout(MASTER_TIMEOUT), + this(client, auditIndex, templateConfig.getTemplateName(), () -> { try { return new PutComposableIndexTemplateAction.Request(templateConfig.getTemplateName()) @@ -90,8 +81,6 @@ protected AbstractAuditor(OriginSettingClient client, protected AbstractAuditor(OriginSettingClient client, String auditIndex, String templateName, - Version versionComposableTemplateExpected, - Supplier legacyTemplateSupplier, Supplier templateSupplier, String nodeName, AbstractAuditMessageFactory messageFactory, @@ -99,8 +88,6 @@ protected AbstractAuditor(OriginSettingClient client, this.client = Objects.requireNonNull(client); this.auditIndex = Objects.requireNonNull(auditIndex); this.templateName = Objects.requireNonNull(templateName); - this.versionComposableTemplateExpected = versionComposableTemplateExpected; - this.legacyTemplateSupplier = Objects.requireNonNull(legacyTemplateSupplier); this.templateSupplier = Objects.requireNonNull(templateSupplier); this.messageFactory = Objects.requireNonNull(messageFactory); this.clusterService = Objects.requireNonNull(clusterService); @@ -136,7 +123,7 @@ protected void indexDoc(ToXContent toXContent) { return; } - if (MlIndexAndAlias.hasIndexTemplate(clusterService.state(), templateName, templateName, versionComposableTemplateExpected)) { + if (MlIndexAndAlias.hasIndexTemplate(clusterService.state(), templateName)) { synchronized (this) { // synchronized so nothing can be added to backlog while this value changes hasLatestTemplate.set(true); @@ -177,8 +164,8 @@ protected void indexDoc(ToXContent toXContent) { // stop multiple invocations if (putTemplateInProgress.compareAndSet(false, true)) { - MlIndexAndAlias.installIndexTemplateIfRequired(clusterService.state(), client, versionComposableTemplateExpected, - legacyTemplateSupplier.get(), templateSupplier.get(), putTemplateListener); + MlIndexAndAlias.installIndexTemplateIfRequired(clusterService.state(), client, + templateSupplier.get(), putTemplateListener); } return; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java index 6a4afac3e368a..b009bbf7e85b8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAlias.java @@ -11,7 +11,6 @@ import org.apache.logging.log4j.message.ParameterizedMessage; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.ResourceAlreadyExistsException; -import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -22,7 +21,6 @@ import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.Client; @@ -35,7 +33,6 @@ import org.elasticsearch.index.Index; import org.elasticsearch.xcontent.DeprecationHandler; import org.elasticsearch.xcontent.NamedXContentRegistry; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.indices.SystemIndexDescriptor; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; @@ -311,24 +308,18 @@ private static void updateWriteAlias(Client client, public static void installIndexTemplateIfRequired( ClusterState clusterState, Client client, - Version versionComposableTemplateExpected, - IndexTemplateConfig legacyTemplateConfig, IndexTemplateConfig templateConfig, TimeValue masterTimeout, ActionListener listener ) { - String legacyTemplateName = legacyTemplateConfig.getTemplateName(); String templateName = templateConfig.getTemplateName(); // The check for existence of the template is against the cluster state, so very cheap - if (hasIndexTemplate(clusterState, legacyTemplateName, templateName, versionComposableTemplateExpected)) { + if (hasIndexTemplate(clusterState, templateName)) { listener.onResponse(true); return; } - PutIndexTemplateRequest legacyRequest = new PutIndexTemplateRequest(legacyTemplateName) - .source(legacyTemplateConfig.loadBytes(), XContentType.JSON).masterNodeTimeout(masterTimeout); - PutComposableIndexTemplateAction.Request request; try { request = new PutComposableIndexTemplateAction.Request(templateConfig.getTemplateName()) @@ -339,12 +330,11 @@ public static void installIndexTemplateIfRequired( throw new ElasticsearchParseException("unable to parse composable template " + templateConfig.getTemplateName(), e); } - installIndexTemplateIfRequired(clusterState, client, versionComposableTemplateExpected, legacyRequest, request, listener); + installIndexTemplateIfRequired(clusterState, client, request, listener); } /** - * See {@link #installIndexTemplateIfRequired(ClusterState, Client, Version, IndexTemplateConfig, IndexTemplateConfig, TimeValue, - * ActionListener)}. + * See {@link #installIndexTemplateIfRequired(ClusterState, Client, IndexTemplateConfig, TimeValue, ActionListener)}. * * Overload takes a {@code PutIndexTemplateRequest} instead of {@code IndexTemplateConfig} * @@ -356,51 +346,29 @@ public static void installIndexTemplateIfRequired( public static void installIndexTemplateIfRequired( ClusterState clusterState, Client client, - Version versionComposableTemplateExpected, - PutIndexTemplateRequest legacyTemplateRequest, PutComposableIndexTemplateAction.Request templateRequest, ActionListener listener ) { // The check for existence of the template is against the cluster state, so very cheap - if (hasIndexTemplate(clusterState, legacyTemplateRequest.name(), templateRequest.name(), versionComposableTemplateExpected)) { + if (hasIndexTemplate(clusterState, templateRequest.name())) { listener.onResponse(true); return; } - if (versionComposableTemplateExpected != null && - clusterState.nodes().getMinNodeVersion().onOrAfter(versionComposableTemplateExpected)) { - ActionListener innerListener = ActionListener.wrap( - response -> { - if (response.isAcknowledged() == false) { - logger.warn("error adding template [{}], request was not acknowledged", templateRequest.name()); - } - listener.onResponse(response.isAcknowledged()); - }, - listener::onFailure); - - executeAsyncWithOrigin(client, ML_ORIGIN, PutComposableIndexTemplateAction.INSTANCE, templateRequest, innerListener); - } else { - ActionListener innerListener = ActionListener.wrap( - response -> { - if (response.isAcknowledged() == false) { - logger.warn("error adding legacy template [{}], request was not acknowledged", legacyTemplateRequest.name()); - } - listener.onResponse(response.isAcknowledged()); - }, - listener::onFailure); + ActionListener innerListener = ActionListener.wrap( + response -> { + if (response.isAcknowledged() == false) { + logger.warn("error adding template [{}], request was not acknowledged", templateRequest.name()); + } + listener.onResponse(response.isAcknowledged()); + }, + listener::onFailure); - executeAsyncWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN, legacyTemplateRequest, innerListener, - client.admin().indices()::putTemplate); - } + executeAsyncWithOrigin(client, ML_ORIGIN, PutComposableIndexTemplateAction.INSTANCE, templateRequest, innerListener); } - public static boolean hasIndexTemplate(ClusterState state, String legacyTemplateName, - String templateName, Version versionComposableTemplateExpected) { - if (versionComposableTemplateExpected != null && state.nodes().getMinNodeVersion().onOrAfter(versionComposableTemplateExpected)) { - return state.getMetadata().templatesV2().containsKey(templateName); - } else { - return state.getMetadata().getTemplates().containsKey(legacyTemplateName); - } + public static boolean hasIndexTemplate(ClusterState state, String templateName) { + return state.getMetadata().templatesV2().containsKey(templateName); } public static boolean hasIndex(ClusterState state, String index) { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java index a755881edeab2..eeb7c323f102c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/TemplateUtils.java @@ -121,26 +121,14 @@ public static String replaceVariable(String input, String variable, String value * Checks if a versioned template exists, and if it exists checks if the version is greater than or equal to the current version. * @param templateName Name of the index template * @param state Cluster state - * @param versionComposableTemplateExpected In which version of Elasticsearch did this template switch to being a composable template? - * null means the template hasn't been switched yet. */ - public static boolean checkTemplateExistsAndVersionIsGTECurrentVersion(String templateName, ClusterState state, - Version versionComposableTemplateExpected) { - if (versionComposableTemplateExpected != null && state.nodes().getMinNodeVersion().onOrAfter(versionComposableTemplateExpected)) { - ComposableIndexTemplate templateMetadata = state.metadata().templatesV2().get(templateName); - if (templateMetadata == null) { - return false; - } - - return templateMetadata.version() != null && templateMetadata.version() >= Version.CURRENT.id; - } else { - IndexTemplateMetadata templateMetadata = state.metadata().templates().get(templateName); - if (templateMetadata == null) { - return false; - } - - return templateMetadata.version() != null && templateMetadata.version() >= Version.CURRENT.id; + public static boolean checkTemplateExistsAndVersionIsGTECurrentVersion(String templateName, ClusterState state) { + ComposableIndexTemplate templateMetadata = state.metadata().templatesV2().get(templateName); + if (templateMetadata == null) { + return false; } + + return templateMetadata.version() != null && templateMetadata.version() >= Version.CURRENT.id; } /** diff --git a/x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json b/x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json deleted file mode 100644 index 4330c16819cbb..0000000000000 --- a/x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "order" : 0, - "version" : ${xpack.ml.version.id}, - "index_patterns" : [ - ".ml-notifications-000002" - ], - "settings" : { - "index" : { - "number_of_shards" : "1", - "auto_expand_replicas" : "0-1", - "hidden": true - } - }, - "mappings" : { - "_doc": ${xpack.ml.notifications.mappings} - } -} diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java index 4c7341a4cb6ae..0ddd5eae80a30 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/common/notifications/AbstractAuditorTests.java @@ -8,9 +8,7 @@ import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateAction; import org.elasticsearch.action.bulk.BulkAction; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.index.IndexAction; @@ -99,7 +97,7 @@ public void shutdownThreadPool() { public void testInfo() throws IOException { AbstractAuditor auditor = - createTestAuditorWithTemplateInstalled(client, Version.CURRENT); + createTestAuditorWithTemplateInstalled(client); auditor.info("foo", "Here is my info"); verify(client).execute(eq(IndexAction.INSTANCE), indexRequestCaptor.capture(), any()); @@ -117,7 +115,7 @@ public void testInfo() throws IOException { public void testWarning() throws IOException { AbstractAuditor auditor = - createTestAuditorWithTemplateInstalled(client, Version.CURRENT); + createTestAuditorWithTemplateInstalled(client); auditor.warning("bar", "Here is my warning"); verify(client).execute(eq(IndexAction.INSTANCE), indexRequestCaptor.capture(), any()); @@ -135,7 +133,7 @@ public void testWarning() throws IOException { public void testError() throws IOException { AbstractAuditor auditor = - createTestAuditorWithTemplateInstalled(client, Version.CURRENT); + createTestAuditorWithTemplateInstalled(client); auditor.error("foobar", "Here is my error"); verify(client).execute(eq(IndexAction.INSTANCE), indexRequestCaptor.capture(), any()); @@ -154,8 +152,7 @@ public void testError() throws IOException { public void testAuditingBeforeTemplateInstalled() throws Exception { CountDownLatch writeSomeDocsBeforeTemplateLatch = new CountDownLatch(1); AbstractAuditor auditor = - // TODO: Both this call and the called method can be simplified in versions that will never have to talk to 7.13 - createTestAuditorWithoutTemplate(client, randomFrom(Version.CURRENT, Version.V_7_13_0), writeSomeDocsBeforeTemplateLatch); + createTestAuditorWithoutTemplate(client, writeSomeDocsBeforeTemplateLatch); auditor.error("foobar", "Here is my error to queue"); auditor.warning("foobar", "Here is my warning to queue"); @@ -181,7 +178,7 @@ public void testAuditingBeforeTemplateInstalled() throws Exception { public void testMaxBufferSize() throws Exception { CountDownLatch writeSomeDocsBeforeTemplateLatch = new CountDownLatch(1); AbstractAuditor auditor = - createTestAuditorWithoutTemplate(client, Version.CURRENT, writeSomeDocsBeforeTemplateLatch); + createTestAuditorWithoutTemplate(client, writeSomeDocsBeforeTemplateLatch); int numThreads = 2; int numMessagesToWrite = (AbstractAuditor.MAX_BUFFER_SIZE / numThreads) + 10; @@ -205,7 +202,7 @@ private static AbstractAuditMessageTests.TestAuditMessage parseAuditMessage(Byte return AbstractAuditMessageTests.TestAuditMessage.PARSER.apply(parser, null); } - private TestAuditor createTestAuditorWithTemplateInstalled(Client client, Version minNodeVersion) { + private TestAuditor createTestAuditorWithTemplateInstalled(Client client) { ImmutableOpenMap.Builder templates = ImmutableOpenMap.builder(1); templates.put(TEST_INDEX, mock(IndexTemplateMetadata.class)); Map templatesV2 = Collections.singletonMap(TEST_INDEX, mock(ComposableIndexTemplate.class)); @@ -213,7 +210,7 @@ private TestAuditor createTestAuditorWithTemplateInstalled(Client client, Versio when(metadata.getTemplates()).thenReturn(templates.build()); when(metadata.templatesV2()).thenReturn(templatesV2); DiscoveryNodes nodes = mock(DiscoveryNodes.class); - when(nodes.getMinNodeVersion()).thenReturn(minNodeVersion); + when(nodes.getMinNodeVersion()).thenReturn(Version.CURRENT); ClusterState state = mock(ClusterState.class); when(state.getMetadata()).thenReturn(metadata); when(state.nodes()).thenReturn(nodes); @@ -224,16 +221,11 @@ private TestAuditor createTestAuditorWithTemplateInstalled(Client client, Versio } @SuppressWarnings("unchecked") - private TestAuditor createTestAuditorWithoutTemplate(Client client, Version minNodeVersion, CountDownLatch latch) { + private TestAuditor createTestAuditorWithoutTemplate(Client client, CountDownLatch latch) { if (Mockito.mockingDetails(client).isMock() == false) { throw new AssertionError("client should be a mock"); } - ActionType expectedTemplateAction = - minNodeVersion.before(Version.CURRENT) - ? PutIndexTemplateAction.INSTANCE - : PutComposableIndexTemplateAction.INSTANCE; - doAnswer(invocationOnMock -> { ActionListener listener = (ActionListener)invocationOnMock.getArguments()[2]; @@ -252,7 +244,7 @@ private TestAuditor createTestAuditorWithoutTemplate(Client client, Version minN threadPool.generic().submit(onPutTemplate); return null; - }).when(client).execute(eq(expectedTemplateAction), any(), any()); + }).when(client).execute(eq(PutComposableIndexTemplateAction.INSTANCE), any(), any()); IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class); AdminClient adminClient = mock(AdminClient.class); @@ -263,7 +255,7 @@ private TestAuditor createTestAuditorWithoutTemplate(Client client, Version minN Metadata metadata = mock(Metadata.class); when(metadata.getTemplates()).thenReturn(templates.build()); DiscoveryNodes nodes = mock(DiscoveryNodes.class); - when(nodes.getMinNodeVersion()).thenReturn(minNodeVersion); + when(nodes.getMinNodeVersion()).thenReturn(Version.CURRENT); ClusterState state = mock(ClusterState.class); when(state.getMetadata()).thenReturn(metadata); when(state.nodes()).thenReturn(nodes); @@ -276,11 +268,7 @@ private TestAuditor createTestAuditorWithoutTemplate(Client client, Version minN public static class TestAuditor extends AbstractAuditor { TestAuditor(Client client, String nodeName, ClusterService clusterService) { - super(new OriginSettingClient(client, TEST_ORIGIN), TEST_INDEX, Version.CURRENT, - new IndexTemplateConfig(TEST_INDEX, - "/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json", Version.CURRENT.id, "xpack.ml.version", - Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), - "xpack.ml.notifications.mappings", NotificationsIndex.mapping())), + super(new OriginSettingClient(client, TEST_ORIGIN), TEST_INDEX, new IndexTemplateConfig(TEST_INDEX, "/org/elasticsearch/xpack/core/ml/notifications_index_template.json", Version.CURRENT.id, "xpack.ml.version", Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java index 299ce95ae4568..3d9aadf1ff61b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ml/utils/MlIndexAndAliasTests.java @@ -138,30 +138,6 @@ public void verifyNoMoreInteractionsWithMocks() { verifyNoMoreInteractions(indicesAdminClient, listener); } - public void testInstallIndexTemplateIfRequired_GivenTemplateLegacyTemplateExistsAndMixedCluster() throws UnknownHostException { - // TODO: this test can be removed from branches that will never need to talk to 7.13 - ClusterState clusterState = createClusterState(Version.V_7_13_0, Collections.emptyMap(), - Collections.singletonMap(NotificationsIndex.NOTIFICATIONS_INDEX, - createLegacyIndexTemplateMetaData(NotificationsIndex.NOTIFICATIONS_INDEX, - Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX))), - Collections.emptyMap()); - - IndexTemplateConfig legacyNotificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, - "/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json", Version.CURRENT.id, "xpack.ml.version", - Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), - "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); - IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, - "/org/elasticsearch/xpack/core/ml/notifications_index_template.json", Version.CURRENT.id, "xpack.ml.version", - Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), - "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); - - // ML didn't use composable templates in 7.13 and the legacy template exists, so nothing needs to be done - MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, Version.CURRENT, legacyNotificationsTemplate, - notificationsTemplate, TimeValue.timeValueMinutes(1), listener); - verify(listener).onResponse(true); - verifyNoMoreInteractions(client); - } - public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModernCluster() throws UnknownHostException { ClusterState clusterState = createClusterState(Version.CURRENT, Collections.emptyMap(), Collections.singletonMap(NotificationsIndex.NOTIFICATIONS_INDEX, @@ -169,16 +145,12 @@ public void testInstallIndexTemplateIfRequired_GivenLegacyTemplateExistsAndModer Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX))), Collections.emptyMap()); - IndexTemplateConfig legacyNotificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, - "/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json", Version.CURRENT.id, "xpack.ml.version", - Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), - "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, "/org/elasticsearch/xpack/core/ml/notifications_index_template.json", Version.CURRENT.id, "xpack.ml.version", Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); - MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, Version.CURRENT, legacyNotificationsTemplate, + MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, notificationsTemplate, TimeValue.timeValueMinutes(1), listener); InOrder inOrder = inOrder(client, listener); inOrder.verify(client).execute(same(PutComposableIndexTemplateAction.INSTANCE), any(), any()); @@ -191,16 +163,12 @@ public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() t createComposableIndexTemplateMetaData(NotificationsIndex.NOTIFICATIONS_INDEX, Collections.singletonList(NotificationsIndex.NOTIFICATIONS_INDEX)))); - IndexTemplateConfig legacyNotificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, - "/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json", Version.CURRENT.id, "xpack.ml.version", - Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), - "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, "/org/elasticsearch/xpack/core/ml/notifications_index_template.json", Version.CURRENT.id, "xpack.ml.version", Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); - MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, Version.CURRENT, legacyNotificationsTemplate, + MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, notificationsTemplate, TimeValue.timeValueMinutes(1), listener); verify(listener).onResponse(true); verifyNoMoreInteractions(client); @@ -209,16 +177,12 @@ public void testInstallIndexTemplateIfRequired_GivenComposableTemplateExists() t public void testInstallIndexTemplateIfRequired() throws UnknownHostException { ClusterState clusterState = createClusterState(Collections.emptyMap()); - IndexTemplateConfig legacyNotificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, - "/org/elasticsearch/xpack/core/ml/notifications_index_legacy_template.json", Version.CURRENT.id, "xpack.ml.version", - Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), - "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); IndexTemplateConfig notificationsTemplate = new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, "/org/elasticsearch/xpack/core/ml/notifications_index_template.json", Version.CURRENT.id, "xpack.ml.version", Map.of("xpack.ml.version.id", String.valueOf(Version.CURRENT.id), "xpack.ml.notifications.mappings", NotificationsIndex.mapping())); - MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, Version.CURRENT, legacyNotificationsTemplate, + MlIndexAndAlias.installIndexTemplateIfRequired(clusterState, client, notificationsTemplate, TimeValue.timeValueMinutes(1), listener); InOrder inOrder = inOrder(client, listener); inOrder.verify(client).execute(same(PutComposableIndexTemplateAction.INSTANCE), any(), any()); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index af1f4bbd67f7b..85a641846094c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -180,7 +180,6 @@ import org.elasticsearch.xpack.core.ml.job.config.JobTaskState; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; import org.elasticsearch.xpack.core.ml.job.snapshot.upgrade.SnapshotUpgradeTaskState; -import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex; import org.elasticsearch.xpack.core.ml.utils.ExceptionsHelper; import org.elasticsearch.xpack.core.template.TemplateUtils; import org.elasticsearch.xpack.ml.action.TransportCloseJobAction; @@ -1267,16 +1266,13 @@ public UnaryOperator> getIndexTemplateMetadat return UnaryOperator.identity(); } - public static boolean allTemplatesInstalled(ClusterState clusterState) { + public static boolean criticalTemplatesInstalled(ClusterState clusterState) { boolean allPresent = true; - List templateNames = - Arrays.asList( - NotificationsIndex.NOTIFICATIONS_INDEX, - STATE_INDEX_PREFIX, - AnomalyDetectorsIndex.jobResultsIndexPrefix()); + // The notifications index template is not critical up-front because every + // notification checks that it's installed and installs it if necessary + List templateNames = List.of(STATE_INDEX_PREFIX, AnomalyDetectorsIndex.jobResultsIndexPrefix()); for (String templateName : templateNames) { - allPresent = allPresent && TemplateUtils.checkTemplateExistsAndVersionIsGTECurrentVersion(templateName, clusterState, - MlIndexTemplateRegistry.COMPOSABLE_TEMPLATE_SWITCH_VERSION); + allPresent = allPresent && TemplateUtils.checkTemplateExistsAndVersionIsGTECurrentVersion(templateName, clusterState); } return allPresent; diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java index 83d67d02429cb..16f9970db900d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MlIndexTemplateRegistry.java @@ -29,11 +29,6 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry { - /** - * The version that the ML index templates were switched from legacy templates to composable templates. - */ - public static final Version COMPOSABLE_TEMPLATE_SWITCH_VERSION = Version.V_7_14_0; - private static final String ROOT_RESOURCE_PATH = "/org/elasticsearch/xpack/core/ml/"; private static final String ANOMALY_DETECTION_PATH = ROOT_RESOURCE_PATH + "anomalydetection/"; private static final String VERSION_PATTERN = "xpack.ml.version"; @@ -46,7 +41,6 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry { private static final IndexTemplateConfig ANOMALY_DETECTION_STATE_TEMPLATE = stateTemplate(); public static final IndexTemplateConfig NOTIFICATIONS_TEMPLATE = notificationsTemplate(); - public static final IndexTemplateConfig NOTIFICATIONS_LEGACY_TEMPLATE = notificationsLegacyTemplate(); private static final IndexTemplateConfig STATS_TEMPLATE = statsTemplate(); @@ -88,17 +82,6 @@ private static IndexTemplateConfig notificationsTemplate() { variables); } - private static IndexTemplateConfig notificationsLegacyTemplate() { - Map variables = new HashMap<>(); - variables.put(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id)); - variables.put("xpack.ml.notifications.mappings", NotificationsIndex.mapping()); - - return new IndexTemplateConfig(NotificationsIndex.NOTIFICATIONS_INDEX, - ROOT_RESOURCE_PATH + "notifications_index_legacy_template.json", - Version.CURRENT.id, VERSION_PATTERN, - variables); - } - private static IndexTemplateConfig statsTemplate() { Map variables = new HashMap<>(); variables.put(VERSION_ID_PATTERN, String.valueOf(Version.CURRENT.id)); diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AbstractMlAuditor.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AbstractMlAuditor.java index 864786f72e6b1..635d05d1612b7 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AbstractMlAuditor.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/notifications/AbstractMlAuditor.java @@ -31,8 +31,6 @@ protected AbstractMlAuditor(Client client, AbstractAuditMessageFactory messag super( new OriginSettingClient(client, ML_ORIGIN), NotificationsIndex.NOTIFICATIONS_INDEX, - MlIndexTemplateRegistry.COMPOSABLE_TEMPLATE_SWITCH_VERSION, - MlIndexTemplateRegistry.NOTIFICATIONS_LEGACY_TEMPLATE, MlIndexTemplateRegistry.NOTIFICATIONS_TEMPLATE, clusterService.getNodeName(), messageFactory, diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlSingleNodeTestCase.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlSingleNodeTestCase.java index 97101798a4dc1..1ba107f433366 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlSingleNodeTestCase.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/MlSingleNodeTestCase.java @@ -114,7 +114,7 @@ protected void waitForMlTemplates() throws Exception { assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().get().getState(); assertTrue("Timed out waiting for the ML templates to be installed", - MachineLearning.allTemplatesInstalled(state)); + MachineLearning.criticalTemplatesInstalled(state)); }); } diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java index cb3d10e98d0a4..a14bd511b4af9 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/support/BaseMlIntegTestCase.java @@ -159,7 +159,7 @@ public void ensureTemplatesArePresent() throws Exception { assertBusy(() -> { ClusterState state = client().admin().cluster().prepareState().get().getState(); assertTrue("Timed out waiting for the ML templates to be installed", - MachineLearning.allTemplatesInstalled(state)); + MachineLearning.criticalTemplatesInstalled(state)); }, 20, TimeUnit.SECONDS); } diff --git a/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java b/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java index 3a3af604df2d1..e6c4ff1d3a684 100644 --- a/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java +++ b/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformAuditorIT.java @@ -20,7 +20,6 @@ import java.util.List; import java.util.Map; -import static org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken.basicAuthHeaderValue; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.CoreMatchers.notNullValue; @@ -107,9 +106,9 @@ public void testAliasCreatedforBWCIndexes() throws Exception { request.setOptions(options); client().performRequest(request); - assertBusy(() -> { + assertBusy(() -> assertTrue(aliasExists(TransformInternalIndexConstants.AUDIT_INDEX_DEPRECATED, - TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)); - }); + TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS)) + ); } } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/notifications/TransformAuditor.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/notifications/TransformAuditor.java index 64d96a1567197..eddbca9ada8fc 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/notifications/TransformAuditor.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/notifications/TransformAuditor.java @@ -6,21 +6,14 @@ */ package org.elasticsearch.xpack.transform.notifications; -import com.carrotsearch.hppc.cursors.ObjectObjectCursor; - import org.elasticsearch.ElasticsearchException; import org.elasticsearch.Version; -import org.elasticsearch.action.admin.indices.alias.Alias; import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; -import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest; import org.elasticsearch.client.Client; import org.elasticsearch.client.OriginSettingClient; -import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; -import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.xcontent.ToXContent; -import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xpack.core.common.notifications.AbstractAuditor; import org.elasticsearch.xpack.core.transform.TransformMetadata; import org.elasticsearch.xpack.core.transform.notifications.TransformAuditMessage; @@ -44,38 +37,9 @@ public TransformAuditor(Client client, String nodeName, ClusterService clusterSe new OriginSettingClient(client, TRANSFORM_ORIGIN), TransformInternalIndexConstants.AUDIT_INDEX, TransformInternalIndexConstants.AUDIT_INDEX, - Version.V_7_16_0, - () -> { - // legacy template implementation, to be removed in 8.x - try { - IndexTemplateMetadata templateMeta = TransformInternalIndex.getAuditIndexTemplateMetadata(); - - PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateMeta.name()).patterns(templateMeta.patterns()) - .version(templateMeta.version()) - .settings(templateMeta.settings()) - .mapping(templateMeta.mappings().uncompressed(), XContentType.JSON); - - for (ObjectObjectCursor cursor : templateMeta.getAliases()) { - AliasMetadata meta = cursor.value; - Alias alias = new Alias(meta.alias()).indexRouting(meta.indexRouting()) - .searchRouting(meta.searchRouting()) - .isHidden(meta.isHidden()) - .writeIndex(meta.writeIndex()); - if (meta.filter() != null) { - alias.filter(meta.getFilter().string()); - } - - request.alias(alias); - } - - return request; - } catch (IOException e) { - throw new ElasticsearchException("Failure creating transform notification index", e); - } - }, () -> { try { - PutComposableIndexTemplateAction.Request request = new PutComposableIndexTemplateAction.Request( + return new PutComposableIndexTemplateAction.Request( TransformInternalIndexConstants.AUDIT_INDEX ).indexTemplate( new ComposableIndexTemplate.Builder().template(TransformInternalIndex.getAuditIndexTemplate()) @@ -84,7 +48,6 @@ public TransformAuditor(Client client, String nodeName, ClusterService clusterSe .priority(Long.MAX_VALUE) .build() ); - return request; } catch (IOException e) { throw new ElasticsearchException("Failure creating transform notification index", e); } From 2d668ae866458fc3db383cbda03745aa831adb69 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Tue, 19 Oct 2021 09:44:25 +0100 Subject: [PATCH 2/3] Add a few missing bits --- .../xpack/ml/MachineLearning.java | 5 +++-- .../persistence/TransformInternalIndex.java | 20 ------------------- .../TransformInternalIndexTests.java | 15 -------------- 3 files changed, 3 insertions(+), 37 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 85a641846094c..918d2decb6caa 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -1268,8 +1268,9 @@ public UnaryOperator> getIndexTemplateMetadat public static boolean criticalTemplatesInstalled(ClusterState clusterState) { boolean allPresent = true; - // The notifications index template is not critical up-front because every - // notification checks that it's installed and installs it if necessary + // The templates for the notifications and stats indices are not critical up-front because + // every notification and stats update checks if the appropriate template is installed and + // installs it if necessary List templateNames = List.of(STATE_INDEX_PREFIX, AnomalyDetectorsIndex.jobResultsIndexPrefix()); for (String templateName : templateNames) { allPresent = allPresent && TemplateUtils.checkTemplateExistsAndVersionIsGTECurrentVersion(templateName, clusterState); diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndex.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndex.java index 81c65c6ae73a3..f00b0c08d1d56 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndex.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndex.java @@ -19,7 +19,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.AliasMetadata; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.metadata.Template; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.service.ClusterService; @@ -101,25 +100,6 @@ public static SystemIndexDescriptor getSystemIndexDescriptor() throws IOExceptio .build(); } - // use getAuditIndexTemplate instead - @Deprecated - public static IndexTemplateMetadata getAuditIndexTemplateMetadata() throws IOException { - IndexTemplateMetadata transformTemplate = IndexTemplateMetadata.builder(TransformInternalIndexConstants.AUDIT_INDEX) - .patterns(Collections.singletonList(TransformInternalIndexConstants.AUDIT_INDEX_PREFIX + "*")) - .version(Version.CURRENT.id) - .settings( - Settings.builder() - // the audits are expected to be small - .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1") - .put(IndexMetadata.SETTING_INDEX_HIDDEN, true) - ) - .putMapping(MapperService.SINGLE_MAPPING_NAME, Strings.toString(auditMappings())) - .putAlias(AliasMetadata.builder(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS).isHidden(true)) - .build(); - return transformTemplate; - } - public static Template getAuditIndexTemplate() throws IOException { AliasMetadata alias = AliasMetadata.builder(TransformInternalIndexConstants.AUDIT_INDEX_READ_ALIAS).isHidden(true).build(); diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndexTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndexTests.java index b9c759783745c..efdf432bb5d66 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndexTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/persistence/TransformInternalIndexTests.java @@ -19,7 +19,6 @@ import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; -import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.RoutingTable; @@ -99,20 +98,6 @@ public static ClusterState randomTransformClusterState(boolean shardsReady) { return csBuilder.build(); } - public static ClusterState randomTransformAuditClusterState() { - ImmutableOpenMap.Builder templateMapBuilder = ImmutableOpenMap.builder(); - try { - templateMapBuilder.put(TransformInternalIndexConstants.AUDIT_INDEX, TransformInternalIndex.getAuditIndexTemplateMetadata()); - } catch (IOException e) { - throw new UncheckedIOException(e); - } - Metadata.Builder metaBuilder = Metadata.builder(); - metaBuilder.templates(templateMapBuilder.build()); - ClusterState.Builder csBuilder = ClusterState.builder(ClusterName.DEFAULT); - csBuilder.metadata(metaBuilder.build()); - return csBuilder.build(); - } - @Before public void setupClusterStates() { stateWithLatestVersionedIndex = randomTransformClusterState(); From c234675709912e4d31a6ce84c61eb35cf8cbc682 Mon Sep 17 00:00:00 2001 From: David Roberts Date: Tue, 19 Oct 2021 10:59:20 +0100 Subject: [PATCH 3/3] Remove some warnings --- .../elasticsearch/xpack/ml/MachineLearning.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 918d2decb6caa..d28d66575a0a7 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -23,7 +23,6 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.NamedDiff; import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; -import org.elasticsearch.cluster.metadata.IndexTemplateMetadata; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.metadata.SingleNodeShutdownMetadata; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -423,7 +422,6 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; -import java.util.function.UnaryOperator; import java.util.stream.Collectors; import static java.util.Collections.emptyList; @@ -1091,9 +1089,9 @@ public List getRestHandlers(Settings settings, RestController restC var infoAction = new ActionHandler<>(XPackInfoFeatureAction.MACHINE_LEARNING, MachineLearningInfoTransportAction.class); if (false == enabled) { - return Arrays.asList(usageAction, infoAction); + return List.of(usageAction, infoAction); } - return Arrays.asList( + return List.of( new ActionHandler<>(GetJobsAction.INSTANCE, TransportGetJobsAction.class), new ActionHandler<>(GetJobsStatsAction.INSTANCE, TransportGetJobsStatsAction.class), new ActionHandler<>(MlInfoAction.INSTANCE, TransportMlInfoAction.class), @@ -1216,7 +1214,7 @@ public List> getExecutorBuilders(Settings settings) { ScalingExecutorBuilder datafeed = new ScalingExecutorBuilder(DATAFEED_THREAD_POOL_NAME, 1, MAX_MAX_OPEN_JOBS_PER_NODE, TimeValue.timeValueMinutes(1), "xpack.ml.datafeed_thread_pool"); - return Arrays.asList(jobComms, utility, datafeed); + return List.of(jobComms, utility, datafeed); } @Override @@ -1244,14 +1242,14 @@ public List getPipelineAggregations() { @Override public List> getSignificanceHeuristics() { - return Arrays.asList( + return List.of( new SignificanceHeuristicSpec<>(PValueScore.NAME, PValueScore::new, PValueScore.PARSER) ); } @Override public List getAggregations() { - return Arrays.asList( + return List.of( new AggregationSpec( CategorizeTextAggregationBuilder.NAME, CategorizeTextAggregationBuilder::new, @@ -1261,11 +1259,6 @@ public List getAggregations() { ); } - @Override - public UnaryOperator> getIndexTemplateMetadataUpgrader() { - return UnaryOperator.identity(); - } - public static boolean criticalTemplatesInstalled(ClusterState clusterState) { boolean allPresent = true; // The templates for the notifications and stats indices are not critical up-front because