From 874a7cc8dc92842a1a39d996e2e8d2428da0608d Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Fri, 29 Oct 2021 10:10:41 +0200 Subject: [PATCH 1/3] Fix IndexTemplateRegistry Deserializing Templates etc. During CS Updates This showed up pretty hot in profiling CS updates for many shards. We are loading+deserializing lifecycle policies and composable index templates on every CS update which gets expensive when you do a lot of them and needlessly duplicates the objects as well. Also, just throwing an unchecked exception on failure to deserialize one of these static resources seems broken as that's always a bug. This PR moves all these things to just be statically loaded on classload and makes the index template registry not show up in profiling CS updates any longer. --- .../core/template/IndexTemplateRegistry.java | 150 +++++------- .../core/template/LifecyclePolicyConfig.java | 24 ++ .../DeprecationIndexingTemplateRegistry.java | 92 +++++--- .../xpack/fleet/FleetTemplateRegistry.java | 12 +- .../slm/SLMSnapshotBlockingIntegTests.java | 2 +- .../xpack/ilm/IndexLifecycle.java | 14 +- .../history/ILMHistoryTemplateRegistry.java | 40 ++-- .../xpack/slm/SnapshotLifecycleTask.java | 2 +- .../xpack/slm/SnapshotRetentionTask.java | 2 +- ...ansportExecuteSnapshotLifecycleAction.java | 2 +- .../slm/history/SnapshotHistoryStore.java | 7 +- .../SnapshotLifecycleTemplateRegistry.java | 42 ++-- .../elasticsearch/xpack/slm/package-info.java | 2 +- .../ilm/history/ILMHistoryStoreTests.java | 9 +- .../xpack/slm/SnapshotLifecycleTaskTests.java | 2 +- .../slm/SnapshotRetentionServiceTests.java | 2 +- .../xpack/slm/SnapshotRetentionTaskTests.java | 2 +- .../history/SnapshotHistoryStoreTests.java | 22 +- ...napshotLifecycleTemplateRegistryTests.java | 21 +- .../ml/integration/MlNativeIntegTestCase.java | 2 +- .../xpack/ml/MlIndexTemplateRegistry.java | 43 ++-- .../xpack/stack/StackTemplateRegistry.java | 218 ++++++++---------- .../stack/StackTemplateRegistryTests.java | 66 +++--- .../support/WatcherIndexTemplateRegistry.java | 62 ++--- .../WatcherIndexTemplateRegistryTests.java | 10 +- 25 files changed, 404 insertions(+), 446 deletions(-) rename x-pack/plugin/{core/src/main/java/org/elasticsearch/xpack/core => ilm/src/main/java/org/elasticsearch/xpack}/slm/history/SnapshotHistoryStore.java (92%) rename x-pack/plugin/{core/src/main/java/org/elasticsearch/xpack/core => ilm/src/main/java/org/elasticsearch/xpack}/slm/history/SnapshotLifecycleTemplateRegistry.java (77%) rename x-pack/plugin/{core/src/test/java/org/elasticsearch/xpack/core => ilm/src/test/java/org/elasticsearch/xpack}/slm/history/SnapshotHistoryStoreTests.java (90%) rename x-pack/plugin/{core/src/test/java/org/elasticsearch/xpack/core => ilm/src/test/java/org/elasticsearch/xpack}/slm/history/SnapshotLifecycleTemplateRegistryTests.java (96%) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java index b4319320afe32..dd2e379cb491b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/IndexTemplateRegistry.java @@ -10,7 +10,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.message.ParameterizedMessage; -import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.template.put.PutComponentTemplateAction; import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; @@ -29,20 +28,21 @@ import org.elasticsearch.core.TimeValue; import org.elasticsearch.gateway.GatewayService; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xcontent.DeprecationHandler; import org.elasticsearch.xcontent.NamedXContentRegistry; +import org.elasticsearch.xcontent.XContentParserConfiguration; import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; +import java.io.IOException; +import java.util.Arrays; import java.util.Collections; -import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.Executor; @@ -102,8 +102,8 @@ protected List getLegacyTemplateConfigs() { * be referenced by a composable template. * @return The configurations for the templates that should be installed. */ - protected List getComponentTemplateConfigs() { - return Collections.emptyList(); + protected Map getComponentTemplateConfigs() { + return Map.of(); } /** @@ -111,16 +111,16 @@ protected List getComponentTemplateConfigs() { * the composable templates that should be installed and managed. * @return The configurations for the templates that should be installed. */ - protected List getComposableTemplateConfigs() { - return Collections.emptyList(); + protected Map getComposableTemplateConfigs() { + return Map.of(); } /** - * Retrieves a list of {@link LifecyclePolicyConfig} that represents the ILM + * Retrieves a list of {@link LifecyclePolicy} that represents the ILM * policies that should be installed and managed. Only called if ILM is enabled. * @return The configurations for the lifecycle policies that should be installed. */ - protected List getPolicyConfigs() { + protected List getPolicyConfigs() { return Collections.emptyList(); } @@ -132,19 +132,11 @@ protected List getPolicyConfigs() { /** * Called when creation of an index template fails. - * @param config The template config that failed to be created. + * @param templateName the template name that failed to be created. * @param e The exception that caused the failure. */ - protected void onPutTemplateFailure(IndexTemplateConfig config, Exception e) { - logger.error( - new ParameterizedMessage( - "error adding index template [{}] from [{}] for [{}]", - config.getTemplateName(), - config.getFileName(), - getOrigin() - ), - e - ); + protected void onPutTemplateFailure(String templateName, Exception e) { + logger.error(new ParameterizedMessage("error adding index template [{}] for [{}]", templateName, getOrigin()), e); } /** @@ -244,16 +236,16 @@ private void addLegacyTemplatesIfMissing(ClusterState state) { } private void addComponentTemplatesIfMissing(ClusterState state) { - final List indexTemplates = getComponentTemplateConfigs(); - for (IndexTemplateConfig newTemplate : indexTemplates) { - final String templateName = newTemplate.getTemplateName(); + final Map indexTemplates = getComponentTemplateConfigs(); + for (Map.Entry newTemplate : indexTemplates.entrySet()) { + final String templateName = newTemplate.getKey(); final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(templateName, key -> new AtomicBoolean(false)); if (creationCheck.compareAndSet(false, true)) { ComponentTemplate currentTemplate = state.metadata().componentTemplates().get(templateName); if (Objects.isNull(currentTemplate)) { logger.debug("adding component template [{}] for [{}], because it doesn't exist", templateName, getOrigin()); - putComponentTemplate(newTemplate, creationCheck); - } else if (Objects.isNull(currentTemplate.version()) || newTemplate.getVersion() > currentTemplate.version()) { + putComponentTemplate(templateName, newTemplate.getValue(), creationCheck); + } else if (Objects.isNull(currentTemplate.version()) || newTemplate.getValue().version() > currentTemplate.version()) { // IndexTemplateConfig now enforces templates contain a `version` property, so if the template doesn't have one we can // safely assume it's an old version of the template. logger.info( @@ -261,9 +253,9 @@ private void addComponentTemplatesIfMissing(ClusterState state) { templateName, getOrigin(), currentTemplate.version(), - newTemplate.getVersion() + newTemplate.getValue().version() ); - putComponentTemplate(newTemplate, creationCheck); + putComponentTemplate(templateName, newTemplate.getValue(), creationCheck); } else { creationCheck.set(false); logger.trace( @@ -284,13 +276,13 @@ private void addComponentTemplatesIfMissing(ClusterState state) { } private void addComposableTemplatesIfMissing(ClusterState state) { - final List indexTemplates = getComposableTemplateConfigs(); - for (IndexTemplateConfig newTemplate : indexTemplates) { - final String templateName = newTemplate.getTemplateName(); + final Map indexTemplates = getComposableTemplateConfigs(); + for (Map.Entry newTemplate : indexTemplates.entrySet()) { + final String templateName = newTemplate.getKey(); final AtomicBoolean creationCheck = templateCreationsInProgress.computeIfAbsent(templateName, key -> new AtomicBoolean(false)); if (creationCheck.compareAndSet(false, true)) { ComposableIndexTemplate currentTemplate = state.metadata().templatesV2().get(templateName); - boolean componentTemplatesAvailable = componentTemplatesExist(state, newTemplate); + boolean componentTemplatesAvailable = componentTemplatesExist(state, newTemplate.getValue()); if (componentTemplatesAvailable == false) { creationCheck.set(false); logger.trace( @@ -300,8 +292,8 @@ private void addComposableTemplatesIfMissing(ClusterState state) { ); } else if (Objects.isNull(currentTemplate)) { logger.debug("adding composable template [{}] for [{}], because it doesn't exist", templateName, getOrigin()); - putComposableTemplate(newTemplate, creationCheck); - } else if (Objects.isNull(currentTemplate.version()) || newTemplate.getVersion() > currentTemplate.version()) { + putComposableTemplate(templateName, newTemplate.getValue(), creationCheck); + } else if (Objects.isNull(currentTemplate.version()) || newTemplate.getValue().version() > currentTemplate.version()) { // IndexTemplateConfig now enforces templates contain a `version` property, so if the template doesn't have one we can // safely assume it's an old version of the template. logger.info( @@ -309,9 +301,9 @@ private void addComposableTemplatesIfMissing(ClusterState state) { templateName, getOrigin(), currentTemplate.version(), - newTemplate.getVersion() + newTemplate.getValue().version() ); - putComposableTemplate(newTemplate, creationCheck); + putComposableTemplate(templateName, newTemplate.getValue(), creationCheck); } else { creationCheck.set(false); logger.trace( @@ -334,21 +326,8 @@ private void addComposableTemplatesIfMissing(ClusterState state) { /** * Returns true if the cluster state contains all of the component templates needed by the composable template */ - private static boolean componentTemplatesExist(ClusterState state, IndexTemplateConfig composableTemplate) { - final ComposableIndexTemplate indexTemplate; - try { - indexTemplate = ComposableIndexTemplate.parse( - JsonXContent.jsonXContent.createParser( - NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - composableTemplate.loadBytes() - ) - ); - } catch (Exception e) { - throw new ElasticsearchParseException("unable to parse composable template " + composableTemplate.getTemplateName(), e); - } - Set neededComponents = new HashSet<>(indexTemplate.composedOf()); - return state.metadata().componentTemplates().keySet().containsAll(neededComponents); + private static boolean componentTemplatesExist(ClusterState state, ComposableIndexTemplate indexTemplate) { + return state.metadata().componentTemplates().keySet().containsAll(indexTemplate.composedOf()); } private void putLegacyTemplate(final IndexTemplateConfig config, final AtomicBoolean creationCheck) { @@ -378,7 +357,7 @@ public void onResponse(AcknowledgedResponse response) { @Override public void onFailure(Exception e) { creationCheck.set(false); - onPutTemplateFailure(config, e); + onPutTemplateFailure(templateName, e); } }, client.admin().indices()::putTemplate @@ -386,25 +365,10 @@ public void onFailure(Exception e) { }); } - private void putComponentTemplate(final IndexTemplateConfig config, final AtomicBoolean creationCheck) { + private void putComponentTemplate(final String templateName, final ComponentTemplate template, final AtomicBoolean creationCheck) { final Executor executor = threadPool.generic(); executor.execute(() -> { - final String templateName = config.getTemplateName(); - - PutComponentTemplateAction.Request request = new PutComponentTemplateAction.Request(templateName); - try { - request.componentTemplate( - ComponentTemplate.parse( - JsonXContent.jsonXContent.createParser( - NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - config.loadBytes() - ) - ) - ); - } catch (Exception e) { - throw new ElasticsearchParseException("unable to parse component template " + config.getTemplateName(), e); - } + PutComponentTemplateAction.Request request = new PutComponentTemplateAction.Request(templateName).componentTemplate(template); request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); executeAsyncWithOrigin( client.threadPool().getThreadContext(), @@ -426,7 +390,7 @@ public void onResponse(AcknowledgedResponse response) { @Override public void onFailure(Exception e) { creationCheck.set(false); - onPutTemplateFailure(config, e); + onPutTemplateFailure(templateName, e); } }, (req, listener) -> client.execute(PutComponentTemplateAction.INSTANCE, req, listener) @@ -434,25 +398,16 @@ public void onFailure(Exception e) { }); } - private void putComposableTemplate(final IndexTemplateConfig config, final AtomicBoolean creationCheck) { + private void putComposableTemplate( + final String templateName, + final ComposableIndexTemplate indexTemplate, + final AtomicBoolean creationCheck + ) { final Executor executor = threadPool.generic(); executor.execute(() -> { - final String templateName = config.getTemplateName(); - - PutComposableIndexTemplateAction.Request request = new PutComposableIndexTemplateAction.Request(templateName); - try { - request.indexTemplate( - ComposableIndexTemplate.parse( - JsonXContent.jsonXContent.createParser( - NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - config.loadBytes() - ) - ) - ); - } catch (Exception e) { - throw new ElasticsearchParseException("unable to parse composable template " + config.getTemplateName(), e); - } + PutComposableIndexTemplateAction.Request request = new PutComposableIndexTemplateAction.Request(templateName).indexTemplate( + indexTemplate + ); request.masterNodeTimeout(TimeValue.timeValueMinutes(1)); executeAsyncWithOrigin( client.threadPool().getThreadContext(), @@ -474,7 +429,7 @@ public void onResponse(AcknowledgedResponse response) { @Override public void onFailure(Exception e) { creationCheck.set(false); - onPutTemplateFailure(config, e); + onPutTemplateFailure(templateName, e); } }, (req, listener) -> client.execute(PutComposableIndexTemplateAction.INSTANCE, req, listener) @@ -483,13 +438,8 @@ public void onFailure(Exception e) { } private void addIndexLifecyclePoliciesIfMissing(ClusterState state) { - Optional maybeMeta = Optional.ofNullable(state.metadata().custom(IndexLifecycleMetadata.TYPE)); - List policies = getPolicyConfigs().stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); - - for (LifecyclePolicy policy : policies) { + for (LifecyclePolicy policy : getPolicyConfigs()) { final AtomicBoolean creationCheck = policyCreationsInProgress.computeIfAbsent( policy.getName(), key -> new AtomicBoolean(false) @@ -542,4 +492,16 @@ public void onFailure(Exception e) { }); } + protected static Map parseComposableTemplates(IndexTemplateConfig... config) { + return Arrays.stream(config).collect(Collectors.toUnmodifiableMap(IndexTemplateConfig::getTemplateName, indexTemplateConfig -> { + try { + return ComposableIndexTemplate.parse( + JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, indexTemplateConfig.loadBytes()) + ); + } catch (IOException e) { + throw new AssertionError(e); + } + })); + } + } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/LifecyclePolicyConfig.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/LifecyclePolicyConfig.java index d6262d8512e46..bc0e1f5ec7c7e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/LifecyclePolicyConfig.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/template/LifecyclePolicyConfig.java @@ -8,14 +8,38 @@ package org.elasticsearch.xpack.core.template; import org.elasticsearch.xcontent.NamedXContentRegistry; +import org.elasticsearch.xcontent.ParseField; +import org.elasticsearch.xpack.core.ilm.DeleteAction; +import org.elasticsearch.xpack.core.ilm.ForceMergeAction; +import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyUtils; +import org.elasticsearch.xpack.core.ilm.LifecycleType; +import org.elasticsearch.xpack.core.ilm.RolloverAction; +import org.elasticsearch.xpack.core.ilm.ShrinkAction; +import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType; + +import java.util.List; /** * Describes an index lifecycle policy to be loaded from a resource file for use with an {@link IndexTemplateRegistry}. */ public class LifecyclePolicyConfig { + public static final NamedXContentRegistry DEFAULT_X_CONTENT_REGISTRY = new NamedXContentRegistry( + List.of( + new NamedXContentRegistry.Entry( + LifecycleType.class, + new ParseField(TimeseriesLifecycleType.TYPE), + (p) -> TimeseriesLifecycleType.INSTANCE + ), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse) + ) + ); + private final String policyName; private final String fileName; diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingTemplateRegistry.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingTemplateRegistry.java index 89d2b9cc99ca0..d490c4e20952f 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingTemplateRegistry.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/logging/DeprecationIndexingTemplateRegistry.java @@ -8,15 +8,23 @@ package org.elasticsearch.xpack.deprecation.logging; import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.ComponentTemplate; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xcontent.NamedXContentRegistry; +import org.elasticsearch.xcontent.XContentParserConfiguration; +import org.elasticsearch.xcontent.json.JsonXContent; +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; +import java.io.IOException; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static org.elasticsearch.xpack.core.ClientHelper.DEPRECATION_ORIGIN; @@ -35,32 +43,6 @@ public class DeprecationIndexingTemplateRegistry extends IndexTemplateRegistry { public static final String DEPRECATION_INDEXING_TEMPLATE_NAME = ".deprecation-indexing-template"; public static final String DEPRECATION_INDEXING_POLICY_NAME = ".deprecation-indexing-ilm-policy"; - public static final IndexTemplateConfig DEPRECATION_INDEXING_MAPPINGS = new IndexTemplateConfig( - DEPRECATION_INDEXING_MAPPINGS_NAME, - "/org/elasticsearch/xpack/deprecation/deprecation-indexing-mappings.json", - INDEX_TEMPLATE_VERSION, - DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE - ); - - public static final IndexTemplateConfig DEPRECATION_INDEXING_SETTINGS = new IndexTemplateConfig( - DEPRECATION_INDEXING_SETTINGS_NAME, - "/org/elasticsearch/xpack/deprecation/deprecation-indexing-settings.json", - INDEX_TEMPLATE_VERSION, - DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE - ); - - public static final IndexTemplateConfig DEPRECATION_INDEXING_INDEX_TEMPLATE = new IndexTemplateConfig( - DEPRECATION_INDEXING_TEMPLATE_NAME, - "/org/elasticsearch/xpack/deprecation/deprecation-indexing-template.json", - INDEX_TEMPLATE_VERSION, - DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE - ); - - public static final LifecyclePolicyConfig DEPRECATION_INDEXING_HISTORY_POLICY = new LifecyclePolicyConfig( - DEPRECATION_INDEXING_POLICY_NAME, - "/org/elasticsearch/xpack/deprecation/deprecation-indexing-ilm-policy.json" - ); - public DeprecationIndexingTemplateRegistry( Settings nodeSettings, ClusterService clusterService, @@ -71,19 +53,65 @@ public DeprecationIndexingTemplateRegistry( super(nodeSettings, clusterService, threadPool, client, xContentRegistry); } + private static final Map COMPONENT_TEMPLATE_CONFIGS; + + static { + final Map componentTemplates = new HashMap<>(); + for (IndexTemplateConfig config : List.of( + new IndexTemplateConfig( + DEPRECATION_INDEXING_MAPPINGS_NAME, + "/org/elasticsearch/xpack/deprecation/deprecation-indexing-mappings.json", + INDEX_TEMPLATE_VERSION, + DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + DEPRECATION_INDEXING_SETTINGS_NAME, + "/org/elasticsearch/xpack/deprecation/deprecation-indexing-settings.json", + INDEX_TEMPLATE_VERSION, + DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE + ) + )) { + try { + componentTemplates.put( + config.getTemplateName(), + ComponentTemplate.parse(JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, config.loadBytes())) + ); + } catch (IOException e) { + throw new AssertionError(e); + } + } + COMPONENT_TEMPLATE_CONFIGS = Map.copyOf(componentTemplates); + } + @Override - protected List getComponentTemplateConfigs() { - return List.of(DEPRECATION_INDEXING_MAPPINGS, DEPRECATION_INDEXING_SETTINGS); + protected Map getComponentTemplateConfigs() { + return COMPONENT_TEMPLATE_CONFIGS; } + private static final Map COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates( + new IndexTemplateConfig( + DEPRECATION_INDEXING_TEMPLATE_NAME, + "/org/elasticsearch/xpack/deprecation/deprecation-indexing-template.json", + INDEX_TEMPLATE_VERSION, + DEPRECATION_INDEXING_TEMPLATE_VERSION_VARIABLE + ) + ); + @Override - protected List getComposableTemplateConfigs() { - return List.of(DEPRECATION_INDEXING_INDEX_TEMPLATE); + protected Map getComposableTemplateConfigs() { + return COMPOSABLE_INDEX_TEMPLATE_CONFIGS; } + private static final List LIFECYCLE_POLICIES = List.of( + new LifecyclePolicyConfig( + DEPRECATION_INDEXING_POLICY_NAME, + "/org/elasticsearch/xpack/deprecation/deprecation-indexing-ilm-policy.json" + ).load(LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY) + ); + @Override - protected List getPolicyConfigs() { - return List.of(DEPRECATION_INDEXING_HISTORY_POLICY); + protected List getPolicyConfigs() { + return LIFECYCLE_POLICIES; } @Override diff --git a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/FleetTemplateRegistry.java b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/FleetTemplateRegistry.java index b34cb820e972f..4be86b31fb58d 100644 --- a/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/FleetTemplateRegistry.java +++ b/x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet/FleetTemplateRegistry.java @@ -13,6 +13,7 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; @@ -20,9 +21,10 @@ public class FleetTemplateRegistry extends IndexTemplateRegistry { - public static final LifecyclePolicyConfig FLEET_ACTIONS_RESULTS_POLICY = new LifecyclePolicyConfig( - ".fleet-actions-results-ilm-policy", - "/fleet-actions-results-ilm-policy.json" + private static final List LIFECYCLE_POLICIES = List.of( + new LifecyclePolicyConfig(".fleet-actions-results-ilm-policy", "/fleet-actions-results-ilm-policy.json").load( + LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY + ) ); public FleetTemplateRegistry( @@ -41,7 +43,7 @@ protected String getOrigin() { } @Override - protected List getPolicyConfigs() { - return List.of(FLEET_ACTIONS_RESULTS_POLICY); + protected List getPolicyConfigs() { + return LIFECYCLE_POLICIES; } } diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java index b1eb667d3d5ec..f33f300a2bf2c 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/slm/SLMSnapshotBlockingIntegTests.java @@ -58,7 +58,7 @@ import java.util.concurrent.atomic.AtomicReference; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; +import static org.elasticsearch.xpack.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.empty; import static org.hamcrest.Matchers.equalTo; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java index 4e1372d8ab898..464193b915622 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java @@ -81,8 +81,6 @@ import org.elasticsearch.xpack.core.slm.action.PutSnapshotLifecycleAction; import org.elasticsearch.xpack.core.slm.action.StartSLMAction; import org.elasticsearch.xpack.core.slm.action.StopSLMAction; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; -import org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry; import org.elasticsearch.xpack.ilm.action.RestDeleteLifecycleAction; import org.elasticsearch.xpack.ilm.action.RestExplainLifecycleAction; import org.elasticsearch.xpack.ilm.action.RestGetLifecycleAction; @@ -131,6 +129,8 @@ import org.elasticsearch.xpack.slm.action.TransportPutSnapshotLifecycleAction; import org.elasticsearch.xpack.slm.action.TransportStartSLMAction; import org.elasticsearch.xpack.slm.action.TransportStopSLMAction; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; +import org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry; import java.io.IOException; import java.time.Clock; @@ -145,6 +145,9 @@ import static org.elasticsearch.xpack.core.ClientHelper.INDEX_LIFECYCLE_ORIGIN; public class IndexLifecycle extends Plugin implements ActionPlugin { + + public static final List NAMED_X_CONTENT_ENTRIES = xContentEntries(); + private final SetOnce indexLifecycleInitialisationService = new SetOnce<>(); private final SetOnce ilmHistoryStore = new SetOnce<>(); private final SetOnce snapshotLifecycleService = new SetOnce<>(); @@ -272,6 +275,10 @@ public List getNamedWriteables() { @Override public List getNamedXContent() { + return NAMED_X_CONTENT_ENTRIES; + } + + private static List xContentEntries() { List entries = new ArrayList<>( Arrays.asList( // Custom Metadata @@ -320,8 +327,7 @@ public List getNamedXContent() { new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RollupILMAction.NAME), RollupILMAction::parse) ); } - - return entries; + return List.copyOf(entries); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryTemplateRegistry.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryTemplateRegistry.java index acbf7d3edf1e4..249b8ae559569 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryTemplateRegistry.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/history/ILMHistoryTemplateRegistry.java @@ -8,18 +8,22 @@ package org.elasticsearch.xpack.ilm.history; import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; +import org.elasticsearch.xpack.ilm.IndexLifecycle; import java.util.Collections; import java.util.List; +import java.util.Map; /** * The {@link ILMHistoryTemplateRegistry} class sets up and configures an ILM policy and index @@ -44,18 +48,6 @@ protected boolean requiresMasterNode() { return true; } - public static final IndexTemplateConfig TEMPLATE_ILM_HISTORY = new IndexTemplateConfig( - ILM_TEMPLATE_NAME, - "/ilm-history.json", - INDEX_TEMPLATE_VERSION, - ILM_TEMPLATE_VERSION_VARIABLE - ); - - public static final LifecyclePolicyConfig ILM_HISTORY_POLICY = new LifecyclePolicyConfig( - ILM_POLICY_NAME, - "/ilm-history-ilm-policy.json" - ); - private final boolean ilmHistoryEnabled; public ILMHistoryTemplateRegistry( @@ -69,22 +61,28 @@ public ILMHistoryTemplateRegistry( this.ilmHistoryEnabled = LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING.get(nodeSettings); } + private static final Map COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates( + new IndexTemplateConfig(ILM_TEMPLATE_NAME, "/ilm-history.json", INDEX_TEMPLATE_VERSION, ILM_TEMPLATE_VERSION_VARIABLE) + ); + @Override - protected List getComposableTemplateConfigs() { + protected Map getComposableTemplateConfigs() { if (this.ilmHistoryEnabled) { - return Collections.singletonList(TEMPLATE_ILM_HISTORY); + return COMPOSABLE_INDEX_TEMPLATE_CONFIGS; } else { - return Collections.emptyList(); + return Map.of(); } } + private static final List LIFECYCLE_POLICIES = List.of( + new LifecyclePolicyConfig(ILM_POLICY_NAME, "/ilm-history-ilm-policy.json").load( + new NamedXContentRegistry(IndexLifecycle.NAMED_X_CONTENT_ENTRIES) + ) + ); + @Override - protected List getPolicyConfigs() { - if (this.ilmHistoryEnabled) { - return Collections.singletonList(ILM_HISTORY_POLICY); - } else { - return Collections.emptyList(); - } + protected List getPolicyConfigs() { + return this.ilmHistoryEnabled ? LIFECYCLE_POLICIES : Collections.emptyList(); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java index 3d5c6627dd767..806bdb3152cac 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java @@ -34,8 +34,8 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; import org.elasticsearch.xpack.ilm.LifecyclePolicySecurityClient; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.io.IOException; import java.time.Instant; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java index c62e799dc2a88..541ce4b4c8212 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java @@ -30,7 +30,7 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; import org.elasticsearch.xpack.core.slm.SnapshotRetentionConfiguration; import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.io.IOException; import java.time.Instant; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportExecuteSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportExecuteSnapshotLifecycleAction.java index bb85c836ba31a..9a3db431d93ab 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportExecuteSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/TransportExecuteSnapshotLifecycleAction.java @@ -24,9 +24,9 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotLifecycleAction; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; import org.elasticsearch.xpack.slm.SnapshotLifecycleService; import org.elasticsearch.xpack.slm.SnapshotLifecycleTask; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.util.Optional; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java similarity index 92% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java index 2b47244b790a2..cefe75d21f6b4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStore.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -20,12 +20,13 @@ import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentFactory; +import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; import java.io.IOException; import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.SLM_HISTORY_INDEX_ENABLED_SETTING; -import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.INDEX_TEMPLATE_VERSION; -import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.SLM_TEMPLATE_NAME; +import static org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry.INDEX_TEMPLATE_VERSION; +import static org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry.SLM_TEMPLATE_NAME; /** * Records Snapshot Lifecycle Management actions as represented by {@link SnapshotHistoryItem} into an index diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotLifecycleTemplateRegistry.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistry.java similarity index 77% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotLifecycleTemplateRegistry.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistry.java index 2e29a56295625..dd785a525efde 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotLifecycleTemplateRegistry.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistry.java @@ -5,10 +5,11 @@ * 2.0. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; @@ -18,6 +19,7 @@ import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; +import org.elasticsearch.xpack.ilm.IndexLifecycle; import java.util.Collections; import java.util.List; @@ -52,18 +54,6 @@ protected boolean requiresMasterNode() { return true; } - public static final IndexTemplateConfig TEMPLATE_SLM_HISTORY = new IndexTemplateConfig( - SLM_TEMPLATE_NAME, - "/slm-history.json", - INDEX_TEMPLATE_VERSION, - SLM_TEMPLATE_VERSION_VARIABLE - ); - - public static final LifecyclePolicyConfig SLM_HISTORY_POLICY = new LifecyclePolicyConfig( - SLM_POLICY_NAME, - "/slm-history-ilm-policy.json" - ); - private final boolean slmHistoryEnabled; public SnapshotLifecycleTemplateRegistry( @@ -77,20 +67,30 @@ public SnapshotLifecycleTemplateRegistry( slmHistoryEnabled = SLM_HISTORY_INDEX_ENABLED_SETTING.get(nodeSettings); } + public static final Map COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates( + new IndexTemplateConfig(SLM_TEMPLATE_NAME, "/slm-history.json", INDEX_TEMPLATE_VERSION, SLM_TEMPLATE_VERSION_VARIABLE) + ); + @Override - protected List getComposableTemplateConfigs() { + protected Map getComposableTemplateConfigs() { if (slmHistoryEnabled == false) { - return Collections.emptyList(); + return Map.of(); } - return Collections.singletonList(TEMPLATE_SLM_HISTORY); + return COMPOSABLE_INDEX_TEMPLATE_CONFIGS; } + private static final List LIFECYCLE_POLICIES = List.of( + new LifecyclePolicyConfig(SLM_POLICY_NAME, "/slm-history-ilm-policy.json").load( + new NamedXContentRegistry(IndexLifecycle.NAMED_X_CONTENT_ENTRIES) + ) + ); + @Override - protected List getPolicyConfigs() { + protected List getPolicyConfigs() { if (slmHistoryEnabled == false) { return Collections.emptyList(); } - return Collections.singletonList(SLM_HISTORY_POLICY); + return LIFECYCLE_POLICIES; } @Override @@ -99,14 +99,14 @@ protected String getOrigin() { } public boolean validate(ClusterState state) { - boolean allTemplatesPresent = getComposableTemplateConfigs().stream() - .map(IndexTemplateConfig::getTemplateName) + boolean allTemplatesPresent = getComposableTemplateConfigs().keySet() + .stream() .allMatch(name -> state.metadata().templatesV2().containsKey(name)); Optional> maybePolicies = Optional.ofNullable( state.metadata().custom(IndexLifecycleMetadata.TYPE) ).map(IndexLifecycleMetadata::getPolicies); - Set policyNames = getPolicyConfigs().stream().map(LifecyclePolicyConfig::getPolicyName).collect(Collectors.toSet()); + Set policyNames = getPolicyConfigs().stream().map(LifecyclePolicy::getName).collect(Collectors.toSet()); boolean allPoliciesPresent = maybePolicies.map(policies -> policies.keySet().containsAll(policyNames)).orElse(false); return allTemplatesPresent && allPoliciesPresent; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/package-info.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/package-info.java index 2c9530646d6b2..6c8c84bebb3ea 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/package-info.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/package-info.java @@ -37,4 +37,4 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java index a53890f48a46f..3b5e67efaff7b 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/history/ILMHistoryStoreTests.java @@ -43,11 +43,9 @@ import org.junit.Before; import java.io.IOException; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; import java.util.stream.IntStream; import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_HISTORY_INDEX_ENABLED_SETTING; @@ -74,13 +72,12 @@ public void setup() { client, NamedXContentRegistry.EMPTY ); - Map templates = registry.getComposableTemplateConfigs() - .stream() - .collect(Collectors.toMap(IndexTemplateConfig::getTemplateName, this::parseIndexTemplate)); ClusterState state = clusterService.state(); ClusterServiceUtils.setState( clusterService, - ClusterState.builder(state).metadata(Metadata.builder(state.metadata()).indexTemplates(templates)).build() + ClusterState.builder(state) + .metadata(Metadata.builder(state.metadata()).indexTemplates(registry.getComposableTemplateConfigs())) + .build() ); historyStore = new ILMHistoryStore(Settings.EMPTY, client, clusterService, threadPool); } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java index be4e04fa9130e..b904f83e8324b 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java @@ -41,7 +41,7 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.io.IOException; import java.time.ZoneId; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionServiceTests.java index 151930827b08a..b6ade9c5c3069 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionServiceTests.java @@ -21,8 +21,8 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.scheduler.SchedulerEngine; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; import org.elasticsearch.xpack.core.watcher.watch.ClockMock; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.util.Collections; import java.util.HashSet; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java index 5de5706a5c27e..d743d1cdd945a 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java @@ -37,7 +37,7 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; import org.elasticsearch.xpack.core.slm.SnapshotRetentionConfiguration; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.time.ZoneOffset; import java.util.ArrayList; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStoreTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java similarity index 90% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStoreTests.java rename to x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java index 65d0d4681d59a..8f499ef93acab 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryStoreTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; import org.elasticsearch.action.admin.indices.create.CreateIndexAction; import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; @@ -14,7 +14,6 @@ import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.metadata.Metadata; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; @@ -23,22 +22,18 @@ import org.elasticsearch.test.ESTestCase; import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; -import org.elasticsearch.xcontent.DeprecationHandler; -import org.elasticsearch.xcontent.NamedXContentRegistry; -import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; +import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; import org.junit.After; import org.junit.Before; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import static org.elasticsearch.xpack.core.ilm.GenerateSnapshotNameStep.generateSnapshotName; import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.SLM_HISTORY_INDEX_ENABLED_SETTING; -import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; -import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.TEMPLATE_SLM_HISTORY; +import static org.elasticsearch.xpack.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.core.IsEqual.equalTo; @@ -51,20 +46,13 @@ public class SnapshotHistoryStoreTests extends ESTestCase { private ClusterService clusterService; @Before - public void setup() throws IOException { + public void setup() { threadPool = new TestThreadPool(this.getClass().getName()); client = new SnapshotLifecycleTemplateRegistryTests.VerifyingClient(threadPool); clusterService = ClusterServiceUtils.createClusterService(threadPool); - ComposableIndexTemplate template = ComposableIndexTemplate.parse( - JsonXContent.jsonXContent.createParser( - NamedXContentRegistry.EMPTY, - DeprecationHandler.THROW_UNSUPPORTED_OPERATION, - TEMPLATE_SLM_HISTORY.loadBytes() - ) - ); ClusterState state = clusterService.state(); Metadata.Builder metadataBuilder = Metadata.builder(state.getMetadata()) - .indexTemplates(Map.of(TEMPLATE_SLM_HISTORY.getTemplateName(), template)); + .indexTemplates(SnapshotLifecycleTemplateRegistry.COMPOSABLE_INDEX_TEMPLATE_CONFIGS); ClusterServiceUtils.setState(clusterService, ClusterState.builder(state).metadata(metadataBuilder).build()); historyStore = new SnapshotHistoryStore(Settings.EMPTY, client, clusterService); clusterService.stop(); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotLifecycleTemplateRegistryTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistryTests.java similarity index 96% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotLifecycleTemplateRegistryTests.java rename to x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistryTests.java index 8146a990de481..9f3628630dced 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotLifecycleTemplateRegistryTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotLifecycleTemplateRegistryTests.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; import org.elasticsearch.Version; import org.elasticsearch.action.ActionListener; @@ -60,9 +60,10 @@ import java.util.stream.Collectors; import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.SLM_HISTORY_INDEX_ENABLED_SETTING; -import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.INDEX_TEMPLATE_VERSION; -import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.SLM_POLICY_NAME; -import static org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry.SLM_TEMPLATE_NAME; +import static org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry.INDEX_TEMPLATE_VERSION; +import static org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry.SLM_POLICY_NAME; +import static org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry.SLM_TEMPLATE_NAME; +import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasSize; @@ -115,7 +116,7 @@ public void testDisabledDoesNotAddTemplates() { client, xContentRegistry ); - assertThat(disabledRegistry.getComposableTemplateConfigs(), hasSize(0)); + assertThat(disabledRegistry.getComposableTemplateConfigs(), anEmptyMap()); assertThat(disabledRegistry.getPolicyConfigs(), hasSize(0)); } @@ -177,10 +178,7 @@ public void testPolicyAlreadyExists() { DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build(); Map policyMap = new HashMap<>(); - List policies = registry.getPolicyConfigs() - .stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); + List policies = registry.getPolicyConfigs(); assertThat(policies, hasSize(1)); LifecyclePolicy policy = policies.get(0); policyMap.put(policy.getName(), policy); @@ -207,10 +205,7 @@ public void testPolicyAlreadyExistsButDiffers() throws IOException { Map policyMap = new HashMap<>(); String policyStr = "{\"phases\":{\"delete\":{\"min_age\":\"1m\",\"actions\":{\"delete\":{}}}}}"; - List policies = registry.getPolicyConfigs() - .stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); + List policies = registry.getPolicyConfigs(); assertThat(policies, hasSize(1)); LifecyclePolicy policy = policies.get(0); diff --git a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java index 6fa2f0cf86f4b..cda0ca6f2d6b5 100644 --- a/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java +++ b/x-pack/plugin/ml/qa/native-multi-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/ml/integration/MlNativeIntegTestCase.java @@ -83,13 +83,13 @@ import org.elasticsearch.xpack.core.ml.notifications.NotificationsIndex; import org.elasticsearch.xpack.core.security.SecurityField; import org.elasticsearch.xpack.core.security.authc.TokenMetadata; -import org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry; import org.elasticsearch.xpack.datastreams.DataStreamsPlugin; import org.elasticsearch.xpack.ilm.IndexLifecycle; import org.elasticsearch.xpack.ml.LocalStateMachineLearning; import org.elasticsearch.xpack.ml.autoscaling.MlScalingReason; import org.elasticsearch.xpack.ml.inference.ModelAliasMetadata; import org.elasticsearch.xpack.ml.inference.allocation.TrainedModelAllocationMetadata; +import org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry; import org.elasticsearch.xpack.transform.Transform; import java.io.IOException; 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 005f332923a1e..06cd1d2d029e3 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 @@ -8,11 +8,13 @@ import org.elasticsearch.Version; import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ml.MlStatsIndex; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndex; import org.elasticsearch.xpack.core.ml.job.persistence.AnomalyDetectorsIndexFields; @@ -21,8 +23,6 @@ import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; -import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,19 +36,9 @@ public class MlIndexTemplateRegistry extends IndexTemplateRegistry { private static final String INDEX_LIFECYCLE_NAME = "xpack.ml.index.lifecycle.name"; private static final String INDEX_LIFECYCLE_ROLLOVER_ALIAS = "xpack.ml.index.lifecycle.rollover_alias"; - private static final IndexTemplateConfig ANOMALY_DETECTION_RESULTS_TEMPLATE = anomalyDetectionResultsTemplate(); - - private static final IndexTemplateConfig ANOMALY_DETECTION_STATE_TEMPLATE = stateTemplate(); - public static final IndexTemplateConfig NOTIFICATIONS_TEMPLATE = notificationsTemplate(); - private static final IndexTemplateConfig STATS_TEMPLATE = statsTemplate(); - private static final String ML_SIZE_BASED_ILM_POLICY_NAME = "ml-size-based-ilm-policy"; - private static final LifecyclePolicyConfig ML_SIZE_BASED_ILM_POLICY = new LifecyclePolicyConfig( - ML_SIZE_BASED_ILM_POLICY_NAME, - ROOT_RESOURCE_PATH + "size_based_ilm_policy.json" - ); private static IndexTemplateConfig stateTemplate() { Map variables = new HashMap<>(); @@ -109,8 +99,6 @@ private static IndexTemplateConfig statsTemplate() { ); } - private final List templatesToUse; - public MlIndexTemplateRegistry( Settings nodeSettings, ClusterService clusterService, @@ -119,12 +107,6 @@ public MlIndexTemplateRegistry( NamedXContentRegistry xContentRegistry ) { super(nodeSettings, clusterService, threadPool, client, xContentRegistry); - templatesToUse = Arrays.asList( - ANOMALY_DETECTION_RESULTS_TEMPLATE, - ANOMALY_DETECTION_STATE_TEMPLATE, - NOTIFICATIONS_TEMPLATE, - STATS_TEMPLATE - ); } @Override @@ -132,14 +114,27 @@ protected boolean requiresMasterNode() { return true; } + private static final Map COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates( + anomalyDetectionResultsTemplate(), + stateTemplate(), + NOTIFICATIONS_TEMPLATE, + statsTemplate() + ); + @Override - protected List getComposableTemplateConfigs() { - return templatesToUse; + protected Map getComposableTemplateConfigs() { + return COMPOSABLE_INDEX_TEMPLATE_CONFIGS; } + private static final List LIFECYCLE_POLICIES = List.of( + new LifecyclePolicyConfig(ML_SIZE_BASED_ILM_POLICY_NAME, ROOT_RESOURCE_PATH + "size_based_ilm_policy.json").load( + LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY + ) + ); + @Override - protected List getPolicyConfigs() { - return Collections.singletonList(ML_SIZE_BASED_ILM_POLICY); + protected List getPolicyConfigs() { + return LIFECYCLE_POLICIES; } @Override diff --git a/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java b/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java index c35e6f0cf8fac..a0d608acd6be0 100644 --- a/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java +++ b/x-pack/plugin/stack/src/main/java/org/elasticsearch/xpack/stack/StackTemplateRegistry.java @@ -10,20 +10,28 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.client.Client; +import org.elasticsearch.cluster.metadata.ComponentTemplate; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xcontent.NamedXContentRegistry; +import org.elasticsearch.xcontent.XContentParserConfiguration; +import org.elasticsearch.xcontent.json.JsonXContent; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; -import java.util.Arrays; +import java.io.IOException; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; +import java.util.stream.Stream; public class StackTemplateRegistry extends IndexTemplateRegistry { private static final Logger logger = LogManager.getLogger(StackTemplateRegistry.class); @@ -46,13 +54,6 @@ public class StackTemplateRegistry extends IndexTemplateRegistry { // General mappings conventions for any data that ends up in a data stream public static final String DATA_STREAMS_MAPPINGS_COMPONENT_TEMPLATE_NAME = "data-streams-mappings"; - public static final IndexTemplateConfig DATA_STREAMS_MAPPINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - DATA_STREAMS_MAPPINGS_COMPONENT_TEMPLATE_NAME, - "/data-streams-mappings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - ////////////////////////////////////////////////////////// // Built in ILM policies for users to use ////////////////////////////////////////////////////////// @@ -62,27 +63,6 @@ public class StackTemplateRegistry extends IndexTemplateRegistry { public static final String ILM_180_DAYS_POLICY_NAME = "180-days-default"; public static final String ILM_365_DAYS_POLICY_NAME = "365-days-default"; - public static final LifecyclePolicyConfig ILM_7_DAYS_POLICY = new LifecyclePolicyConfig( - ILM_7_DAYS_POLICY_NAME, - "/" + ILM_7_DAYS_POLICY_NAME + ".json" - ); - public static final LifecyclePolicyConfig ILM_30_DAYS_POLICY = new LifecyclePolicyConfig( - ILM_30_DAYS_POLICY_NAME, - "/" + ILM_30_DAYS_POLICY_NAME + ".json" - ); - public static final LifecyclePolicyConfig ILM_90_DAYS_POLICY = new LifecyclePolicyConfig( - ILM_90_DAYS_POLICY_NAME, - "/" + ILM_90_DAYS_POLICY_NAME + ".json" - ); - public static final LifecyclePolicyConfig ILM_180_DAYS_POLICY = new LifecyclePolicyConfig( - ILM_180_DAYS_POLICY_NAME, - "/" + ILM_180_DAYS_POLICY_NAME + ".json" - ); - public static final LifecyclePolicyConfig ILM_365_DAYS_POLICY = new LifecyclePolicyConfig( - ILM_365_DAYS_POLICY_NAME, - "/" + ILM_365_DAYS_POLICY_NAME + ".json" - ); - ////////////////////////////////////////////////////////// // Logs components (for matching logs-*-* indices) ////////////////////////////////////////////////////////// @@ -91,26 +71,6 @@ public class StackTemplateRegistry extends IndexTemplateRegistry { public static final String LOGS_ILM_POLICY_NAME = "logs"; public static final String LOGS_INDEX_TEMPLATE_NAME = "logs"; - public static final IndexTemplateConfig LOGS_MAPPINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - LOGS_MAPPINGS_COMPONENT_TEMPLATE_NAME, - "/logs-mappings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public static final IndexTemplateConfig LOGS_SETTINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - LOGS_SETTINGS_COMPONENT_TEMPLATE_NAME, - "/logs-settings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public static final LifecyclePolicyConfig LOGS_ILM_POLICY = new LifecyclePolicyConfig(LOGS_ILM_POLICY_NAME, "/logs-policy.json"); - public static final IndexTemplateConfig LOGS_INDEX_TEMPLATE = new IndexTemplateConfig( - LOGS_INDEX_TEMPLATE_NAME, - "/logs-template.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - ////////////////////////////////////////////////////////// // Metrics components (for matching metric-*-* indices) ////////////////////////////////////////////////////////// @@ -119,29 +79,6 @@ public class StackTemplateRegistry extends IndexTemplateRegistry { public static final String METRICS_ILM_POLICY_NAME = "metrics"; public static final String METRICS_INDEX_TEMPLATE_NAME = "metrics"; - public static final IndexTemplateConfig METRICS_MAPPINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - METRICS_MAPPINGS_COMPONENT_TEMPLATE_NAME, - "/metrics-mappings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public static final IndexTemplateConfig METRICS_SETTINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - METRICS_SETTINGS_COMPONENT_TEMPLATE_NAME, - "/metrics-settings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public static final LifecyclePolicyConfig METRICS_ILM_POLICY = new LifecyclePolicyConfig( - METRICS_ILM_POLICY_NAME, - "/metrics-policy.json" - ); - public static final IndexTemplateConfig METRICS_INDEX_TEMPLATE = new IndexTemplateConfig( - METRICS_INDEX_TEMPLATE_NAME, - "/metrics-template.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - ////////////////////////////////////////////////////////// // Synthetics components (for matching synthetics-*-* indices) ////////////////////////////////////////////////////////// @@ -150,29 +87,6 @@ public class StackTemplateRegistry extends IndexTemplateRegistry { public static final String SYNTHETICS_ILM_POLICY_NAME = "synthetics"; public static final String SYNTHETICS_INDEX_TEMPLATE_NAME = "synthetics"; - public static final IndexTemplateConfig SYNTHETICS_MAPPINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - SYNTHETICS_MAPPINGS_COMPONENT_TEMPLATE_NAME, - "/synthetics-mappings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public static final IndexTemplateConfig SYNTHETICS_SETTINGS_COMPONENT_TEMPLATE = new IndexTemplateConfig( - SYNTHETICS_SETTINGS_COMPONENT_TEMPLATE_NAME, - "/synthetics-settings.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public static final LifecyclePolicyConfig SYNTHETICS_ILM_POLICY = new LifecyclePolicyConfig( - SYNTHETICS_ILM_POLICY_NAME, - "/synthetics-policy.json" - ); - public static final IndexTemplateConfig SYNTHETICS_INDEX_TEMPLATE = new IndexTemplateConfig( - SYNTHETICS_INDEX_TEMPLATE_NAME, - "/synthetics-template.json", - REGISTRY_VERSION, - TEMPLATE_VERSION_VARIABLE - ); - public StackTemplateRegistry( Settings nodeSettings, ClusterService clusterService, @@ -197,54 +111,114 @@ private void updateEnabledSetting(boolean newValue) { } else { logger.info( "stack composable templates [{}] and component templates [{}] will not be installed or reinstalled", - getComposableTemplateConfigs().stream().map(IndexTemplateConfig::getTemplateName).collect(Collectors.joining(",")), - getComponentTemplateConfigs().stream().map(IndexTemplateConfig::getTemplateName).collect(Collectors.joining(",")) + String.join(",", getComposableTemplateConfigs().keySet()), + String.join(",", getComponentTemplateConfigs().keySet()) ); this.stackTemplateEnabled = false; } } + private static final List LIFECYCLE_POLICY_CONFIGS = Stream.of( + new LifecyclePolicyConfig(LOGS_ILM_POLICY_NAME, "/logs-policy.json"), + new LifecyclePolicyConfig(METRICS_ILM_POLICY_NAME, "/metrics-policy.json"), + new LifecyclePolicyConfig(SYNTHETICS_ILM_POLICY_NAME, "/synthetics-policy.json"), + new LifecyclePolicyConfig(ILM_7_DAYS_POLICY_NAME, "/" + ILM_7_DAYS_POLICY_NAME + ".json"), + new LifecyclePolicyConfig(ILM_30_DAYS_POLICY_NAME, "/" + ILM_30_DAYS_POLICY_NAME + ".json"), + new LifecyclePolicyConfig(ILM_90_DAYS_POLICY_NAME, "/" + ILM_90_DAYS_POLICY_NAME + ".json"), + new LifecyclePolicyConfig(ILM_180_DAYS_POLICY_NAME, "/" + ILM_180_DAYS_POLICY_NAME + ".json"), + new LifecyclePolicyConfig(ILM_365_DAYS_POLICY_NAME, "/" + ILM_365_DAYS_POLICY_NAME + ".json") + ).map(config -> config.load(LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY)).collect(Collectors.toUnmodifiableList()); + @Override - protected List getPolicyConfigs() { + protected List getPolicyConfigs() { if (stackTemplateEnabled) { - return Arrays.asList( - LOGS_ILM_POLICY, - METRICS_ILM_POLICY, - SYNTHETICS_ILM_POLICY, - ILM_7_DAYS_POLICY, - ILM_30_DAYS_POLICY, - ILM_90_DAYS_POLICY, - ILM_180_DAYS_POLICY, - ILM_365_DAYS_POLICY - ); + return LIFECYCLE_POLICY_CONFIGS; } else { return Collections.emptyList(); } } + private static final Map COMPONENT_TEMPLATE_CONFIGS; + + static { + final Map componentTemplates = new HashMap<>(); + for (IndexTemplateConfig config : List.of( + new IndexTemplateConfig( + DATA_STREAMS_MAPPINGS_COMPONENT_TEMPLATE_NAME, + "/data-streams-mappings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + LOGS_MAPPINGS_COMPONENT_TEMPLATE_NAME, + "/logs-mappings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + LOGS_SETTINGS_COMPONENT_TEMPLATE_NAME, + "/logs-settings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + METRICS_MAPPINGS_COMPONENT_TEMPLATE_NAME, + "/metrics-mappings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + METRICS_SETTINGS_COMPONENT_TEMPLATE_NAME, + "/metrics-settings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + SYNTHETICS_MAPPINGS_COMPONENT_TEMPLATE_NAME, + "/synthetics-mappings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ), + new IndexTemplateConfig( + SYNTHETICS_SETTINGS_COMPONENT_TEMPLATE_NAME, + "/synthetics-settings.json", + REGISTRY_VERSION, + TEMPLATE_VERSION_VARIABLE + ) + )) { + try { + componentTemplates.put( + config.getTemplateName(), + ComponentTemplate.parse(JsonXContent.jsonXContent.createParser(XContentParserConfiguration.EMPTY, config.loadBytes())) + ); + } catch (IOException e) { + throw new AssertionError(e); + } + } + COMPONENT_TEMPLATE_CONFIGS = Map.copyOf(componentTemplates); + } + @Override - protected List getComponentTemplateConfigs() { + protected Map getComponentTemplateConfigs() { if (stackTemplateEnabled) { - return Arrays.asList( - DATA_STREAMS_MAPPINGS_COMPONENT_TEMPLATE, - LOGS_MAPPINGS_COMPONENT_TEMPLATE, - LOGS_SETTINGS_COMPONENT_TEMPLATE, - METRICS_MAPPINGS_COMPONENT_TEMPLATE, - METRICS_SETTINGS_COMPONENT_TEMPLATE, - SYNTHETICS_MAPPINGS_COMPONENT_TEMPLATE, - SYNTHETICS_SETTINGS_COMPONENT_TEMPLATE - ); + return COMPONENT_TEMPLATE_CONFIGS; } else { - return Collections.emptyList(); + return Map.of(); } } + private static final Map COMPOSABLE_INDEX_TEMPLATE_CONFIGS = parseComposableTemplates( + new IndexTemplateConfig(LOGS_INDEX_TEMPLATE_NAME, "/logs-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE), + new IndexTemplateConfig(METRICS_INDEX_TEMPLATE_NAME, "/metrics-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE), + new IndexTemplateConfig(SYNTHETICS_INDEX_TEMPLATE_NAME, "/synthetics-template.json", REGISTRY_VERSION, TEMPLATE_VERSION_VARIABLE) + ); + @Override - protected List getComposableTemplateConfigs() { + protected Map getComposableTemplateConfigs() { if (stackTemplateEnabled) { - return Arrays.asList(LOGS_INDEX_TEMPLATE, METRICS_INDEX_TEMPLATE, SYNTHETICS_INDEX_TEMPLATE); + return COMPOSABLE_INDEX_TEMPLATE_CONFIGS; } else { - return Collections.emptyList(); + return Map.of(); } } diff --git a/x-pack/plugin/stack/src/test/java/org/elasticsearch/xpack/stack/StackTemplateRegistryTests.java b/x-pack/plugin/stack/src/test/java/org/elasticsearch/xpack/stack/StackTemplateRegistryTests.java index 27db7aeadb7a5..52c8be8814128 100644 --- a/x-pack/plugin/stack/src/test/java/org/elasticsearch/xpack/stack/StackTemplateRegistryTests.java +++ b/x-pack/plugin/stack/src/test/java/org/elasticsearch/xpack/stack/StackTemplateRegistryTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.action.admin.indices.template.put.PutComposableIndexTemplateAction; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.cluster.ClusterChangedEvent; -import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.block.ClusterBlocks; @@ -27,7 +26,6 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.TriFunction; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; import org.elasticsearch.test.ClusterServiceUtils; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.client.NoOpClient; @@ -37,25 +35,19 @@ import org.elasticsearch.xcontent.NamedXContentRegistry; import org.elasticsearch.xcontent.ParseField; import org.elasticsearch.xcontent.XContentParser; +import org.elasticsearch.xcontent.XContentParserConfiguration; import org.elasticsearch.xcontent.XContentType; import org.elasticsearch.xpack.core.ilm.DeleteAction; -import org.elasticsearch.xpack.core.ilm.ForceMergeAction; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleType; import org.elasticsearch.xpack.core.ilm.OperationMode; -import org.elasticsearch.xpack.core.ilm.RolloverAction; -import org.elasticsearch.xpack.core.ilm.ShrinkAction; -import org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType; import org.elasticsearch.xpack.core.ilm.action.PutLifecycleAction; import org.junit.After; import org.junit.Before; import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -63,6 +55,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; +import static org.hamcrest.Matchers.anEmptyMap; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; @@ -74,7 +67,6 @@ public class StackTemplateRegistryTests extends ESTestCase { private StackTemplateRegistry registry; - private NamedXContentRegistry xContentRegistry; private ClusterService clusterService; private ThreadPool threadPool; private VerifyingClient client; @@ -84,22 +76,7 @@ public void createRegistryAndClient() { threadPool = new TestThreadPool(this.getClass().getName()); client = new VerifyingClient(threadPool); clusterService = ClusterServiceUtils.createClusterService(threadPool); - List entries = new ArrayList<>(ClusterModule.getNamedXWriteables()); - entries.addAll( - Arrays.asList( - new NamedXContentRegistry.Entry( - LifecycleType.class, - new ParseField(TimeseriesLifecycleType.TYPE), - (p) -> TimeseriesLifecycleType.INSTANCE - ), - new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse), - new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse), - new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse), - new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse) - ) - ); - xContentRegistry = new NamedXContentRegistry(entries); - registry = new StackTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, xContentRegistry); + registry = new StackTemplateRegistry(Settings.EMPTY, clusterService, threadPool, client, NamedXContentRegistry.EMPTY); } @After @@ -111,9 +88,15 @@ public void tearDown() throws Exception { public void testDisabledDoesNotAddTemplates() { Settings settings = Settings.builder().put(StackTemplateRegistry.STACK_TEMPLATES_ENABLED.getKey(), false).build(); - StackTemplateRegistry disabledRegistry = new StackTemplateRegistry(settings, clusterService, threadPool, client, xContentRegistry); - assertThat(disabledRegistry.getComponentTemplateConfigs(), hasSize(0)); - assertThat(disabledRegistry.getComposableTemplateConfigs(), hasSize(0)); + StackTemplateRegistry disabledRegistry = new StackTemplateRegistry( + settings, + clusterService, + threadPool, + client, + NamedXContentRegistry.EMPTY + ); + assertThat(disabledRegistry.getComponentTemplateConfigs(), anEmptyMap()); + assertThat(disabledRegistry.getComposableTemplateConfigs(), anEmptyMap()); assertThat(disabledRegistry.getPolicyConfigs(), hasSize(0)); } @@ -190,10 +173,7 @@ public void testPolicyAlreadyExists() { DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build(); Map policyMap = new HashMap<>(); - List policies = registry.getPolicyConfigs() - .stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); + List policies = registry.getPolicyConfigs(); assertThat(policies, hasSize(8)); policies.forEach(p -> policyMap.put(p.getName(), p)); @@ -219,10 +199,7 @@ public void testPolicyAlreadyExistsButDiffers() throws IOException { Map policyMap = new HashMap<>(); String policyStr = "{\"phases\":{\"delete\":{\"min_age\":\"1m\",\"actions\":{\"delete\":{}}}}}"; - List policies = registry.getPolicyConfigs() - .stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); + List policies = registry.getPolicyConfigs(); assertThat(policies, hasSize(8)); policies.forEach(p -> policyMap.put(p.getName(), p)); @@ -240,7 +217,20 @@ public void testPolicyAlreadyExistsButDiffers() throws IOException { try ( XContentParser parser = XContentType.JSON.xContent() - .createParser(xContentRegistry, LoggingDeprecationHandler.THROW_UNSUPPORTED_OPERATION, policyStr) + .createParser( + XContentParserConfiguration.EMPTY.withRegistry( + new NamedXContentRegistry( + List.of( + new NamedXContentRegistry.Entry( + LifecycleAction.class, + new ParseField(DeleteAction.NAME), + DeleteAction::parse + ) + ) + ) + ), + policyStr + ) ) { LifecyclePolicy different = LifecyclePolicy.parse(parser, policies.get(0).getName()); policyMap.put(policies.get(0).getName(), different); diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java index e3e29cd5ccb82..c552f8ac15552 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistry.java @@ -8,10 +8,12 @@ import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.metadata.ComposableIndexTemplate; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xcontent.NamedXContentRegistry; +import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.template.IndexTemplateConfig; import org.elasticsearch.xpack.core.template.IndexTemplateRegistry; import org.elasticsearch.xpack.core.template.LifecyclePolicyConfig; @@ -20,31 +22,15 @@ import java.util.Collections; import java.util.List; +import java.util.Map; import static org.elasticsearch.xpack.core.ClientHelper.WATCHER_ORIGIN; public class WatcherIndexTemplateRegistry extends IndexTemplateRegistry { public static final String WATCHER_TEMPLATE_VERSION_VARIABLE = "xpack.watcher.template.version"; - public static final IndexTemplateConfig TEMPLATE_CONFIG_WATCH_HISTORY = new IndexTemplateConfig( - WatcherIndexTemplateRegistryField.HISTORY_TEMPLATE_NAME, - "/watch-history.json", - WatcherIndexTemplateRegistryField.INDEX_TEMPLATE_VERSION, - WATCHER_TEMPLATE_VERSION_VARIABLE - ); - public static final IndexTemplateConfig TEMPLATE_CONFIG_WATCH_HISTORY_NO_ILM = new IndexTemplateConfig( - WatcherIndexTemplateRegistryField.HISTORY_TEMPLATE_NAME_NO_ILM, - "/watch-history-no-ilm.json", - WatcherIndexTemplateRegistryField.INDEX_TEMPLATE_VERSION, - WATCHER_TEMPLATE_VERSION_VARIABLE - ); - public static final LifecyclePolicyConfig POLICY_WATCH_HISTORY = new LifecyclePolicyConfig( - "watch-history-ilm-policy", - "/watch-history-ilm-policy.json" - ); - - private final List templatesToUse; + private final boolean ilmManagementEnabled; public WatcherIndexTemplateRegistry( Settings nodeSettings, @@ -54,26 +40,44 @@ public WatcherIndexTemplateRegistry( NamedXContentRegistry xContentRegistry ) { super(nodeSettings, clusterService, threadPool, client, xContentRegistry); - boolean ilmManagementEnabled = Watcher.USE_ILM_INDEX_MANAGEMENT.get(nodeSettings); - templatesToUse = Collections.singletonList( - ilmManagementEnabled ? TEMPLATE_CONFIG_WATCH_HISTORY : TEMPLATE_CONFIG_WATCH_HISTORY_NO_ILM - ); + ilmManagementEnabled = Watcher.USE_ILM_INDEX_MANAGEMENT.get(nodeSettings); } + private static final Map TEMPLATES_WATCH_HISTORY = parseComposableTemplates( + new IndexTemplateConfig( + WatcherIndexTemplateRegistryField.HISTORY_TEMPLATE_NAME, + "/watch-history.json", + WatcherIndexTemplateRegistryField.INDEX_TEMPLATE_VERSION, + WATCHER_TEMPLATE_VERSION_VARIABLE + ) + ); + + private static final Map TEMPLATES_WATCH_HISTORY_NO_ILM = parseComposableTemplates( + new IndexTemplateConfig( + WatcherIndexTemplateRegistryField.HISTORY_TEMPLATE_NAME_NO_ILM, + "/watch-history-no-ilm.json", + WatcherIndexTemplateRegistryField.INDEX_TEMPLATE_VERSION, + WATCHER_TEMPLATE_VERSION_VARIABLE + ) + ); + @Override - protected List getComposableTemplateConfigs() { - return templatesToUse; + protected Map getComposableTemplateConfigs() { + return ilmManagementEnabled ? TEMPLATES_WATCH_HISTORY : TEMPLATES_WATCH_HISTORY_NO_ILM; } + private static final List LIFECYCLE_POLICIES = List.of( + new LifecyclePolicyConfig("watch-history-ilm-policy", "/watch-history-ilm-policy.json").load( + LifecyclePolicyConfig.DEFAULT_X_CONTENT_REGISTRY + ) + ); + /** * If Watcher is configured not to use ILM, we don't return a policy. */ @Override - protected List getPolicyConfigs() { - if (Watcher.USE_ILM_INDEX_MANAGEMENT.get(settings) == false) { - return Collections.emptyList(); - } - return Collections.singletonList(POLICY_WATCH_HISTORY); + protected List getPolicyConfigs() { + return Watcher.USE_ILM_INDEX_MANAGEMENT.get(settings) == false ? Collections.emptyList() : LIFECYCLE_POLICIES; } @Override diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistryTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistryTests.java index 048b1ab5babc9..c5a68cfbc1aa5 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistryTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/support/WatcherIndexTemplateRegistryTests.java @@ -186,10 +186,7 @@ public void testPolicyAlreadyExists() { DiscoveryNodes nodes = DiscoveryNodes.builder().localNodeId("node").masterNodeId("node").add(node).build(); Map policyMap = new HashMap<>(); - List policies = registry.getPolicyConfigs() - .stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); + List policies = registry.getPolicyConfigs(); assertThat(policies, hasSize(1)); LifecyclePolicy policy = policies.get(0); policyMap.put(policy.getName(), policy); @@ -220,10 +217,7 @@ public void testPolicyAlreadyExistsButDiffers() throws IOException { Map policyMap = new HashMap<>(); String policyStr = "{\"phases\":{\"delete\":{\"min_age\":\"1m\",\"actions\":{\"delete\":{}}}}}"; - List policies = registry.getPolicyConfigs() - .stream() - .map(policyConfig -> policyConfig.load(xContentRegistry)) - .collect(Collectors.toList()); + List policies = registry.getPolicyConfigs(); assertThat(policies, hasSize(1)); LifecyclePolicy policy = policies.get(0); try ( From ee27934de4bf3c0da55d86260fe3821b2536b521 Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Fri, 29 Oct 2021 17:52:56 +0200 Subject: [PATCH 2/3] fix test compile --- x-pack/plugin/ilm/qa/multi-node/build.gradle | 1 + .../org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/build.gradle b/x-pack/plugin/ilm/qa/multi-node/build.gradle index cf314f88f5841..4139f24fa4983 100644 --- a/x-pack/plugin/ilm/qa/multi-node/build.gradle +++ b/x-pack/plugin/ilm/qa/multi-node/build.gradle @@ -5,6 +5,7 @@ apply plugin: 'elasticsearch.internal-java-rest-test' dependencies { javaRestTestImplementation(testArtifact(project(xpackModule('core')))) + javaRestTestImplementation project(xpackModule('ilm')) javaRestTestImplementation project(":client:rest-high-level") } diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java index 6d4f96193144b..957a60781ea8f 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java @@ -55,7 +55,7 @@ import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex; import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.CREATE_OPERATION; import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.DELETE_OPERATION; -import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; +import static org.elasticsearch.xpack.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; From 6f4ff7d508c306536a4cf87d72a59f07c9117fcd Mon Sep 17 00:00:00 2001 From: Armin Braun Date: Fri, 29 Oct 2021 18:02:54 +0200 Subject: [PATCH 3/3] fix compile --- .../xpack/slm/SnapshotLifecycleRestIT.java | 4 ++-- .../elasticsearch/xpack/slm/SnapshotLifecycleTask.java | 2 +- .../elasticsearch/xpack/slm/SnapshotRetentionTask.java | 2 +- .../xpack}/slm/history/SnapshotHistoryItem.java | 2 +- .../xpack/slm/history/SnapshotHistoryStore.java | 1 - .../elasticsearch/xpack}/slm/history/package-info.java | 10 +++++----- .../xpack/slm/SnapshotLifecycleTaskTests.java | 2 +- .../xpack/slm/SnapshotRetentionTaskTests.java | 2 +- .../xpack}/slm/history/SnapshotHistoryItemTests.java | 2 +- .../xpack/slm/history/SnapshotHistoryStoreTests.java | 1 - 10 files changed, 13 insertions(+), 15 deletions(-) rename x-pack/plugin/{core/src/main/java/org/elasticsearch/xpack/core => ilm/src/main/java/org/elasticsearch/xpack}/slm/history/SnapshotHistoryItem.java (99%) rename x-pack/plugin/{core/src/main/java/org/elasticsearch/xpack/core => ilm/src/main/java/org/elasticsearch/xpack}/slm/history/package-info.java (64%) rename x-pack/plugin/{core/src/test/java/org/elasticsearch/xpack/core => ilm/src/test/java/org/elasticsearch/xpack}/slm/history/SnapshotHistoryItemTests.java (99%) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java index 957a60781ea8f..d207c383d652c 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/slm/SnapshotLifecycleRestIT.java @@ -53,8 +53,8 @@ import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder; import static org.elasticsearch.xpack.TimeSeriesRestDriver.createComposableTemplate; import static org.elasticsearch.xpack.TimeSeriesRestDriver.getStepKeyForIndex; -import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.CREATE_OPERATION; -import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.DELETE_OPERATION; +import static org.elasticsearch.xpack.slm.history.SnapshotHistoryItem.CREATE_OPERATION; +import static org.elasticsearch.xpack.slm.history.SnapshotHistoryItem.DELETE_OPERATION; import static org.elasticsearch.xpack.slm.history.SnapshotHistoryStore.SLM_HISTORY_DATA_STREAM; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java index 806bdb3152cac..1f08ca62e67cd 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTask.java @@ -33,8 +33,8 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecycleMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; import org.elasticsearch.xpack.ilm.LifecyclePolicySecurityClient; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryItem; import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.io.IOException; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java index 541ce4b4c8212..696338ebbd0a6 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/SnapshotRetentionTask.java @@ -29,7 +29,7 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; import org.elasticsearch.xpack.core.slm.SnapshotRetentionConfiguration; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryItem; import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.io.IOException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryItem.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryItem.java similarity index 99% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryItem.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryItem.java index 7c4c5ac1b56ad..38c0225668538 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryItem.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryItem.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.Strings; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java index cefe75d21f6b4..5776e45ac6d8a 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStore.java @@ -20,7 +20,6 @@ import org.elasticsearch.xcontent.ToXContent; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentFactory; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; import java.io.IOException; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/package-info.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/package-info.java similarity index 64% rename from x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/package-info.java rename to x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/package-info.java index f612b1e7f4cb6..f02ac859715c2 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/slm/history/package-info.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/history/package-info.java @@ -8,17 +8,17 @@ /** * This package contains the utility classes used to persist SLM policy execution results to an internal index. * - *

The {@link org.elasticsearch.xpack.core.slm.history.SnapshotLifecycleTemplateRegistry} class is registered as a + *

The {@link org.elasticsearch.xpack.slm.history.SnapshotLifecycleTemplateRegistry} class is registered as a * cluster state listener when the ILM plugin starts up. It executes only on the elected master node, and ensures that a template is * configured for the SLM history index, as well as an ILM policy (since the two are always enabled in lock step). * - *

The {@link org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem} is used to encapsulate historical + *

The {@link org.elasticsearch.xpack.slm.history.SnapshotHistoryItem} is used to encapsulate historical * information about a snapshot policy execution. This contains more data than the * {@link org.elasticsearch.xpack.core.slm.SnapshotInvocationRecord} since it is a more complete history record * stored on disk instead of a low surface area status entry. * - *

The {@link org.elasticsearch.xpack.core.slm.history.SnapshotHistoryStore} manages the persistence of the previously - * mentioned {@link org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem}. It simply does an asynchronous put + *

The {@link org.elasticsearch.xpack.slm.history.SnapshotHistoryStore} manages the persistence of the previously + * mentioned {@link org.elasticsearch.xpack.slm.history.SnapshotHistoryItem}. It simply does an asynchronous put * operation against the SLM history internal index. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java index b904f83e8324b..e830f87a7773f 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotLifecycleTaskTests.java @@ -40,7 +40,7 @@ import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicyMetadata; import org.elasticsearch.xpack.core.slm.SnapshotLifecycleStats; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; +import org.elasticsearch.xpack.slm.history.SnapshotHistoryItem; import org.elasticsearch.xpack.slm.history.SnapshotHistoryStore; import java.io.IOException; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java index d743d1cdd945a..d387087dba10a 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/SnapshotRetentionTaskTests.java @@ -58,7 +58,7 @@ import java.util.function.Supplier; import java.util.stream.Collectors; -import static org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem.DELETE_OPERATION; +import static org.elasticsearch.xpack.slm.history.SnapshotHistoryItem.DELETE_OPERATION; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.empty; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryItemTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryItemTests.java similarity index 99% rename from x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryItemTests.java rename to x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryItemTests.java index e34a8612e5526..1feb4e6fd9fea 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/slm/history/SnapshotHistoryItemTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryItemTests.java @@ -5,7 +5,7 @@ * 2.0. */ -package org.elasticsearch.xpack.core.slm.history; +package org.elasticsearch.xpack.slm.history; import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.test.AbstractSerializingTestCase; diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java index 8f499ef93acab..118e0632982ed 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/slm/history/SnapshotHistoryStoreTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.threadpool.TestThreadPool; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.core.slm.SnapshotLifecyclePolicy; -import org.elasticsearch.xpack.core.slm.history.SnapshotHistoryItem; import org.junit.After; import org.junit.Before;