diff --git a/docs/changelog/83603.yaml b/docs/changelog/83603.yaml new file mode 100644 index 0000000000000..3c8626e621d93 --- /dev/null +++ b/docs/changelog/83603.yaml @@ -0,0 +1,6 @@ +pr: 83603 +summary: Cache ILM policy name on `IndexMetadata` +area: ILM+SLM +type: enhancement +issues: + - 83582 diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java index 31eaff551f18e..9b0169fe83c32 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/IndexMetadata.java @@ -547,6 +547,9 @@ public Iterator> settings() { private final int shardsPerNodeLimit; + @Nullable // if an index isn't managed by ilm, it won't have a policy + private final String lifecyclePolicyName; + private final LifecycleExecutionState lifecycleExecutionState; private final AutoExpandReplicas autoExpandReplicas; @@ -588,6 +591,7 @@ private IndexMetadata( final boolean ignoreDiskWatermarks, @Nullable final List tierPreference, final int shardsPerNodeLimit, + final String lifecyclePolicyName, final LifecycleExecutionState lifecycleExecutionState, final AutoExpandReplicas autoExpandReplicas, final boolean isSearchableSnapshot, @@ -632,6 +636,7 @@ private IndexMetadata( this.ignoreDiskWatermarks = ignoreDiskWatermarks; this.tierPreference = tierPreference; this.shardsPerNodeLimit = shardsPerNodeLimit; + this.lifecyclePolicyName = lifecyclePolicyName; this.lifecycleExecutionState = lifecycleExecutionState; this.autoExpandReplicas = autoExpandReplicas; this.isSearchableSnapshot = isSearchableSnapshot; @@ -677,6 +682,7 @@ IndexMetadata withMappingMetadata(MappingMetadata mapping) { this.ignoreDiskWatermarks, this.tierPreference, this.shardsPerNodeLimit, + this.lifecyclePolicyName, this.lifecycleExecutionState, this.autoExpandReplicas, this.isSearchableSnapshot, @@ -816,6 +822,14 @@ public List getTierPreference() { return tierPreference; } + /** + * Return the name of the Index Lifecycle Policy associated with this index, or null if it is not managed by ILM. + */ + @Nullable + public String getLifecyclePolicyName() { + return lifecyclePolicyName; + } + public LifecycleExecutionState getLifecycleExecutionState() { return lifecycleExecutionState; } @@ -864,6 +878,10 @@ public Index getResizeSourceIndex() { Property.PrivateIndex ); + // LIFECYCLE_NAME is here an as optimization, see LifecycleSettings.LIFECYCLE_NAME and + // LifecycleSettings.LIFECYCLE_NAME_SETTING for the 'real' version + public static final String LIFECYCLE_NAME = "index.lifecycle.name"; + ImmutableOpenMap getCustomData() { return this.customData; } @@ -1699,6 +1717,7 @@ public IndexMetadata build() { DiskThresholdDecider.SETTING_IGNORE_DISK_WATERMARKS.get(settings), tierPreference, ShardsLimitAllocationDecider.INDEX_TOTAL_SHARDS_PER_NODE_SETTING.get(settings), + settings.get(IndexMetadata.LIFECYCLE_NAME), // n.b. lookup by name to get null-if-not-present semantics lifecycleExecutionState, AutoExpandReplicas.SETTING.get(settings), isSearchableSnapshot, diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java index 697d307b523f0..0e406324c8f20 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/IndexMetadataTests.java @@ -467,6 +467,24 @@ public void testBuildsWithBrokenTierPreference() { expectThrows(IllegalArgumentException.class, indexMetadata::getTierPreference); } + public void testLifeCyclePolicyName() { + Settings.Builder settings = Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 8)) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT); + + IndexMetadata idxMeta1 = IndexMetadata.builder("test").settings(settings).build(); + + // null means no policy + assertNull(idxMeta1.getLifecyclePolicyName()); + + IndexMetadata idxMeta2 = IndexMetadata.builder(idxMeta1) + .settings(settings.put(IndexMetadata.LIFECYCLE_NAME, "some_policy").build()) + .build(); + + assertThat(idxMeta2.getLifecyclePolicyName(), equalTo("some_policy")); + } + private static Settings indexSettingsWithDataTier(String dataTier) { return Settings.builder() .put(IndexMetadata.SETTING_VERSION_CREATED, Version.CURRENT) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java index d20ad498259f8..e790aff389510 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckNotDataStreamWriteIndexStep.java @@ -60,7 +60,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) { return new Result(false, new Info(errorMessage)); } - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); IndexAbstraction indexAbstraction = clusterState.metadata().getIndicesLookup().get(indexName); assert indexAbstraction != null : "invalid cluster metadata. index [" + indexName + "] was not found"; IndexAbstraction.DataStream dataStream = indexAbstraction.getParentDataStream(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java index 77c214522117e..3c3f8d1b004e4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CheckTargetShardsCountStep.java @@ -52,7 +52,7 @@ public Result isConditionMet(Index index, ClusterState clusterState) { if (numberOfShards != null) { int sourceNumberOfShards = indexMetadata.getNumberOfShards(); if (sourceNumberOfShards % numberOfShards != 0) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); String errorMessage = String.format( Locale.ROOT, "lifecycle action of policy [%s] for index [%s] cannot make progress " diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java index 02ce5f8a72f32..5bb226eec936a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupShrinkIndexStep.java @@ -43,7 +43,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl if (currentClusterState.metadata().index(shrunkenIndexSource) == null) { // if the source index does not exist, we'll skip deleting the // (managed) shrunk index as that will cause data loss - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); logger.warn( "managed index [{}] as part of policy [{}] is a shrunk index and the source index [{}] does not exist " + "anymore. will skip the [{}] step", diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java index 881796ec228cf..c286c2131cec5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CleanupSnapshotStep.java @@ -58,7 +58,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl @Override public void onResponse(AcknowledgedResponse acknowledgedResponse) { if (acknowledgedResponse.isAcknowledged() == false) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); throw new ElasticsearchException( "cleanup snapshot step request for repository [" + repositoryName @@ -82,7 +82,7 @@ public void onFailure(Exception e) { listener.onResponse(null); } else { if (e instanceof RepositoryMissingException) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); listener.onFailure( new IllegalStateException( "repository [" diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java index 31da4e0973d1e..327df2149778f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/CreateSnapshotStep.java @@ -71,7 +71,7 @@ void createSnapshot(IndexMetadata indexMetadata, ActionListener listene final LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getLifecyclePolicyName(); final String snapshotRepository = lifecycleState.snapshotRepository(); if (Strings.hasText(snapshotRepository) == false) { listener.onFailure( diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java index f966f2c68f1da..7256e3fccdc65 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/DeleteStep.java @@ -32,7 +32,7 @@ public DeleteStep(StepKey key, StepKey nextStepKey, Client client) { @Override public void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentState, ActionListener listener) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); String indexName = indexMetadata.getIndex().getName(); IndexAbstraction indexAbstraction = currentState.metadata().getIndicesLookup().get(indexName); assert indexAbstraction != null : "invalid cluster metadata. index [" + indexName + "] was not found"; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java index b620cb3a1f50e..4b1a9b54b7b89 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeAction.java @@ -139,7 +139,7 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) IndexMetadata indexMetadata = clusterState.metadata().index(index); assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state"; if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); logger.warn( "[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. " + "Skipping this action", diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java index a19925672a09e..67b8786832730 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ForceMergeStep.java @@ -61,7 +61,7 @@ public void performAction( listener.onResponse(null); } else { DefaultShardOperationFailedException[] failures = response.getShardFailures(); - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); String errorMessage = String.format( Locale.ROOT, "index [%s] in policy [%s] encountered failures [%s] on step [%s]", diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java index 74d5ed1b4135a..67763e781e5a5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/FreezeAction.java @@ -73,7 +73,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { (index, clusterState) -> { IndexMetadata indexMetadata = clusterState.getMetadata().index(index); assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state"; - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { logger.warn( "[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. " diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java index 5d860163ddd40..d71ba55806ee7 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java @@ -59,7 +59,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { return clusterState; } - String policy = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); // validate that the snapshot repository exists -- because policies are refreshed on later retries, and because @@ -70,7 +70,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { "repository [" + snapshotRepository + "] is missing. [" - + policy + + policyName + "] policy for " + "index [" + index.getName() @@ -83,13 +83,13 @@ public ClusterState performAction(Index index, ClusterState clusterState) { newCustomData.setSnapshotRepository(snapshotRepository); if (lifecycleState.snapshotName() == null) { // generate and validate the snapshotName - String snapshotNamePrefix = ("<{now/d}-" + index.getName() + "-" + policy + ">").toLowerCase(Locale.ROOT); + String snapshotNamePrefix = ("<{now/d}-" + index.getName() + "-" + policyName + ">").toLowerCase(Locale.ROOT); String snapshotName = generateSnapshotName(snapshotNamePrefix); ActionRequestValidationException validationException = validateGeneratedSnapshotName(snapshotNamePrefix, snapshotName); if (validationException != null) { logger.warn( "unable to generate a snapshot name as part of policy [{}] for index [{}] due to [{}]", - policy, + policyName, index.getName(), validationException.getMessage() ); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java index 344ba79f113e1..96a8c6f8471a3 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateUniqueIndexNameStep.java @@ -82,13 +82,13 @@ public ClusterState performAction(Index index, ClusterState clusterState) { LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); Builder newCustomData = LifecycleExecutionState.builder(lifecycleState); - String policy = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); String generatedIndexName = generateValidIndexName(prefix, index.getName()); ActionRequestValidationException validationException = validateGeneratedIndexName(generatedIndexName, clusterState); if (validationException != null) { logger.warn( "unable to generate a valid index name as part of policy [{}] for index [{}] due to [{}]", - policy, + policyName, index.getName(), validationException.getMessage() ); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java index 79bbf6e58be50..7f9869d93c0d0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/InitializePolicyContextStep.java @@ -59,8 +59,8 @@ public ClusterState performAction(Index index, ClusterState clusterState) { ); } } catch (Exception e) { - String policy = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); - throw new InitializePolicyException(policy, index.getName(), e); + String policyName = indexMetadata.getLifecyclePolicyName(); + throw new InitializePolicyException(policyName, index.getName(), e); } ClusterState.Builder newClusterStateBuilder = ClusterState.builder(clusterState); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java index 9d319bd2e91fa..acfd016cb2383 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java @@ -290,6 +290,9 @@ public boolean isActionSafe(StepKey stepKey) { * @throws IllegalArgumentException if the name is invalid */ public static void validatePolicyName(String policy) { + if (Strings.isNullOrEmpty(policy)) { + throw new IllegalArgumentException("invalid policy name [" + policy + "]: must not be null or empty"); + } if (policy.contains(",")) { throw new IllegalArgumentException("invalid policy name [" + policy + "]: must not contain ','"); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java index 6534079aab675..dfecfa9a6f85a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyUtils.java @@ -123,7 +123,7 @@ public static ItemUsage calculateUsage( .indices() .values() .stream() - .filter(indexMetadata -> policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()))) + .filter(indexMetadata -> policyName.equals(indexMetadata.getLifecyclePolicyName())) .map(indexMetadata -> indexMetadata.getIndex().getName()) .collect(Collectors.toList()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java index e8519523a2126..4d1d89d3e644d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecycleSettings.java @@ -6,19 +6,18 @@ */ package org.elasticsearch.xpack.core.ilm; +import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.core.TimeValue; import org.elasticsearch.xpack.core.scheduler.CronSchedule; -import static org.elasticsearch.common.settings.Setting.timeSetting; - /** * Class encapsulating settings related to Index Lifecycle Management X-Pack Plugin */ public class LifecycleSettings { public static final String LIFECYCLE_POLL_INTERVAL = "indices.lifecycle.poll_interval"; - public static final String LIFECYCLE_NAME = "index.lifecycle.name"; + public static final String LIFECYCLE_NAME = IndexMetadata.LIFECYCLE_NAME; public static final String LIFECYCLE_INDEXING_COMPLETE = "index.lifecycle.indexing_complete"; public static final String LIFECYCLE_ORIGINATION_DATE = "index.lifecycle.origination_date"; public static final String LIFECYCLE_PARSE_ORIGINATION_DATE = "index.lifecycle.parse_origination_date"; @@ -35,7 +34,7 @@ public class LifecycleSettings { // already mounted as a searchable snapshot. Those ILM actions will check if the index has this setting name configured. public static final String SNAPSHOT_INDEX_NAME = "index.store.snapshot.index_name"; - public static final Setting LIFECYCLE_POLL_INTERVAL_SETTING = timeSetting( + public static final Setting LIFECYCLE_POLL_INTERVAL_SETTING = Setting.timeSetting( LIFECYCLE_POLL_INTERVAL, TimeValue.timeValueMinutes(10), TimeValue.timeValueSeconds(1), @@ -81,7 +80,7 @@ public class LifecycleSettings { // This setting configures how much time since step_time should ILM wait for a condition to be met. After the threshold wait time has // elapsed ILM will likely stop waiting and go to the next step. // Also see {@link org.elasticsearch.xpack.core.ilm.ClusterStateWaitUntilThresholdStep} - public static final Setting LIFECYCLE_STEP_WAIT_TIME_THRESHOLD_SETTING = timeSetting( + public static final Setting LIFECYCLE_STEP_WAIT_TIME_THRESHOLD_SETTING = Setting.timeSetting( LIFECYCLE_STEP_WAIT_TIME_THRESHOLD, TimeValue.timeValueHours(12), TimeValue.timeValueHours(1), @@ -114,7 +113,7 @@ public class LifecycleSettings { Setting.Property.Dynamic, Setting.Property.NodeScope ); - public static final Setting SLM_RETENTION_DURATION_SETTING = timeSetting( + public static final Setting SLM_RETENTION_DURATION_SETTING = Setting.timeSetting( SLM_RETENTION_DURATION, TimeValue.timeValueHours(1), TimeValue.timeValueMillis(500), diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java index deb7f91cb41ea..939d6936b2997 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MigrateAction.java @@ -109,7 +109,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { // partially mounted indices will already have data_frozen, and we don't want to change that if they do if (indexMetadata.isPartialSearchableSnapshot()) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); logger.debug( "[{}] action in policy [{}] is configured for index [{}] which is a partially mounted index. " + "skipping this action", diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java index ef92edee9d9a7..07943826971e1 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/MountSnapshotStep.java @@ -68,7 +68,7 @@ void performDuringNoSnapshot(IndexMetadata indexMetadata, ClusterState currentCl LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); final String snapshotRepository = lifecycleState.snapshotRepository(); if (Strings.hasText(snapshotRepository) == false) { listener.onFailure( diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java index fa15e596275e5..8d6479182d5fc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCacheManagement.java @@ -154,7 +154,7 @@ public static boolean updateIndicesForPolicy( .indices() .values() .stream() - .filter(meta -> newPolicy.getName().equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(meta.getSettings()))) + .filter(meta -> newPolicy.getName().equals(meta.getLifecyclePolicyName())) .filter(meta -> isIndexPhaseDefinitionUpdatable(xContentRegistry, client, meta, newPolicy.getPolicy(), licenseState)) .collect(Collectors.toList()); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java index d4608eb5a10e4..84c2d074b82fc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReplaceDataStreamBackingIndexStep.java @@ -69,7 +69,7 @@ public ClusterState performAction(Index index, ClusterState clusterState) { String originalIndex = index.getName(); String targetIndexName = targetIndexNameSupplier.apply(originalIndex, originalIndexMetadata.getLifecycleExecutionState()); - String policyName = originalIndexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = originalIndexMetadata.getLifecyclePolicyName(); IndexAbstraction indexAbstraction = clusterState.metadata().getIndicesLookup().get(index.getName()); assert indexAbstraction != null : "invalid cluster metadata. index [" + index.getName() + "] was not found"; IndexAbstraction.DataStream dataStream = indexAbstraction.getParentDataStream(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java index 2795cfd6c94a9..8e9569058eb64 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverStep.java @@ -64,7 +64,7 @@ public void performAction( "index [{}] is not the write index for data stream [{}]. skipping rollover for policy [{}]", indexName, dataStream.getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()) + indexMetadata.getLifecyclePolicyName() ); listener.onResponse(null); return; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java index 4934db547c26a..3ad55a2b15d24 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RollupStep.java @@ -45,7 +45,7 @@ public void performAction( ClusterStateObserver observer, ActionListener listener ) { - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getLifecyclePolicyName(); final String indexName = indexMetadata.getIndex().getName(); final LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); final String rollupIndexName = lifecycleState.rollupIndexName(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java index 28a6c8a266ac1..4ec758154f343 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java @@ -138,7 +138,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey, XPac IndexMetadata indexMetadata = clusterState.getMetadata().index(index); assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state"; - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) { // The index is already a searchable snapshot, let's see if the repository matches String repo = indexMetadata.getSettings().get(SEARCHABLE_SNAPSHOTS_REPOSITORY_NAME_SETTING_KEY); @@ -215,7 +215,7 @@ public List toSteps(Client client, String phase, StepKey nextStepKey, XPac waitForDataTierKey, (index, clusterState) -> { IndexMetadata indexMetadata = clusterState.getMetadata().index(index); - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); LifecycleExecutionState lifecycleExecutionState = indexMetadata.getLifecycleExecutionState(); if (lifecycleExecutionState.snapshotName() == null) { // No name exists, so it must be generated diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java index fc8e7dfd0539f..445c7f3f1bd45 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkAction.java @@ -171,7 +171,7 @@ public List toSteps(Client client, String phase, Step.StepKey nextStepKey) + "Skipping this action", ShrinkAction.NAME, indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()) + indexMetadata.getLifecyclePolicyName() ); return true; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java index 1fd5daba02518..1ed9615faa6db 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ShrinkStep.java @@ -70,19 +70,19 @@ public void performAction( "skipping [{}] step for index [{}] as part of policy [{}] as the shrunk index [{}] already exists", ShrinkStep.NAME, indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()), + indexMetadata.getLifecyclePolicyName(), shrunkenIndexName ); listener.onResponse(null); return; } - String lifecycle = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); Settings.Builder builder = Settings.builder(); // need to remove the single shard, allocation so replicas can be allocated builder.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, indexMetadata.getNumberOfReplicas()) - .put(LifecycleSettings.LIFECYCLE_NAME, lifecycle) + .put(LifecycleSettings.LIFECYCLE_NAME, policyName) .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", (String) null); if (numberOfShards != null) { builder.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java index b9f5b73d760a3..39d2ae4ddea11 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SwapAliasesAndDeleteSourceIndexStep.java @@ -55,7 +55,7 @@ public void performAction( IndexMetadata targetIndexMetadata = currentClusterState.metadata().index(targetIndexName); if (targetIndexMetadata == null) { - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); String errorMessage = String.format( Locale.ROOT, "target index [%s] doesn't exist. stopping execution of lifecycle [%s] for" + " index [%s]", diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java index 0b3b3b90f70b5..541148c8c566a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStep.java @@ -49,7 +49,7 @@ public void performAction( ClusterStateObserver observer, ActionListener listener ) { - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getLifecyclePolicyName(); final String indexName = indexMetadata.getIndex().getName(); final LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); final String rollupIndexName = lifecycleState.rollupIndexName(); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java index 1a1257746c819..bed56c3a24392 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForRolloverReadyStep.java @@ -76,7 +76,7 @@ public void evaluateCondition(Metadata metadata, Index index, Listener listener, "index [{}] is not the write index for data stream [{}]. skipping rollover for policy [{}]", index.getName(), dataStream.getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(metadata.index(index).getSettings()) + metadata.index(index).getLifecyclePolicyName() ); listener.onResponse(true, EmptyInfo.INSTANCE); return; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java index f6bfab071c12c..85e617202fb8a 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/CopySettingsStepTests.java @@ -77,6 +77,6 @@ public void testPerformAction() { ClusterState newClusterState = copySettingsStep.performAction(sourceIndexMetadata.getIndex(), clusterState); IndexMetadata newTargetIndexMetadata = newClusterState.metadata().index(targetIndex); - assertThat(newTargetIndexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME), is(policyName)); + assertThat(newTargetIndexMetadata.getLifecyclePolicyName(), is(policyName)); } } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java index afcf5f99b790b..a5bf70ff61dd0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicyTests.java @@ -430,6 +430,8 @@ public void testIsActionSafe() { } public void testValidatePolicyName() { + expectThrows(IllegalArgumentException.class, () -> LifecyclePolicy.validatePolicyName(null)); + expectThrows(IllegalArgumentException.class, () -> LifecyclePolicy.validatePolicyName("")); expectThrows( IllegalArgumentException.class, () -> LifecyclePolicy.validatePolicyName(randomAlphaOfLengthBetween(0, 10) + "," + randomAlphaOfLengthBetween(0, 10)) diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java index 3e19abb54ea26..da42b35e914f1 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/RollupStepTests.java @@ -95,7 +95,7 @@ public void testPerformActionFailureInvalidExecutionState() { .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); String indexName = indexMetadata.getIndex().getName(); RollupStep step = createRandomInstance(); step.performAction(indexMetadata, emptyClusterState(), null, new ActionListener<>() { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java index eecaa26f74eb7..005f255ba116b 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/UpdateRollupIndexPolicyStepTests.java @@ -133,7 +133,7 @@ public void testPerformActionFailureIllegalExecutionState() { .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); - String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + String policyName = indexMetadata.getLifecyclePolicyName(); String indexName = indexMetadata.getIndex().getName(); UpdateRollupIndexPolicyStep step = createRandomInstance(); step.performAction(indexMetadata, emptyClusterState(), null, new ActionListener<>() { diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 87c633ea0f060..f445db2053bbf 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -652,14 +652,14 @@ public void testDeletePolicyInUse() throws IOException { managedIndex1, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), originalPolicy) + .put(LifecycleSettings.LIFECYCLE_NAME, originalPolicy) ); createIndexWithSettings( client(), managedIndex2, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), originalPolicy) + .put(LifecycleSettings.LIFECYCLE_NAME, originalPolicy) ); createIndexWithSettings( client(), @@ -671,7 +671,7 @@ public void testDeletePolicyInUse() throws IOException { managedByOtherPolicyIndex, Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, randomIntBetween(1, 10)) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), otherPolicy) + .put(LifecycleSettings.LIFECYCLE_NAME, otherPolicy) ); Request deleteRequest = new Request("DELETE", "_ilm/policy/" + originalPolicy); @@ -739,7 +739,7 @@ public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception { Settings.builder() .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) - .put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), randomAlphaOfLengthBetween(5, 15)) + .put(LifecycleSettings.LIFECYCLE_NAME, randomAlphaOfLengthBetween(5, 15)) ); Request stopILMRequest = new Request("POST", "_ilm/stop"); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java index cac3d93a0924f..07d8b611e71d7 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/cluster/metadata/MetadataMigrateToDataTiersRoutingService.java @@ -32,7 +32,6 @@ 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.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.MigrateAction; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; @@ -350,7 +349,7 @@ private static void refreshCachedPhaseForPhasesWithoutAllocateAction( .indices() .values() .stream() - .filter(meta -> policyName.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(meta.getSettings()))) + .filter(meta -> policyName.equals(meta.getLifecyclePolicyName())) .collect(Collectors.toList()); for (IndexMetadata indexMetadata : managedIndices) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java index cb10c33071523..a0b3391c0958e 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java @@ -31,7 +31,6 @@ import org.elasticsearch.xpack.core.ilm.ClusterStateActionStep; import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep; import org.elasticsearch.xpack.core.ilm.ErrorStep; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep; import org.elasticsearch.xpack.core.ilm.Step; import org.elasticsearch.xpack.core.ilm.Step.StepKey; @@ -601,7 +600,7 @@ void registerSuccessfulOperation(IndexMetadata indexMetadata) { ilmHistoryStore.putAsync( ILMHistoryItem.success( indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()), + indexMetadata.getLifecyclePolicyName(), nowSupplier.getAsLong(), origination == null ? null : (nowSupplier.getAsLong() - origination), indexMetadata.getLifecycleExecutionState() @@ -621,7 +620,7 @@ void registerDeleteOperation(IndexMetadata metadataBeforeDeletion) { ilmHistoryStore.putAsync( ILMHistoryItem.success( metadataBeforeDeletion.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(metadataBeforeDeletion.getSettings()), + metadataBeforeDeletion.getLifecyclePolicyName(), nowSupplier.getAsLong(), origination == null ? null : (nowSupplier.getAsLong() - origination), LifecycleExecutionState.builder(metadataBeforeDeletion.getLifecycleExecutionState()) @@ -645,7 +644,7 @@ void registerFailedOperation(IndexMetadata indexMetadata, Exception failure) { ilmHistoryStore.putAsync( ILMHistoryItem.failure( indexMetadata.getIndex().getName(), - LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()), + indexMetadata.getLifecyclePolicyName(), nowSupplier.getAsLong(), origination == null ? null : (nowSupplier.getAsLong() - origination), indexMetadata.getLifecycleExecutionState(), diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java index b10c097d79e31..680e8998fe648 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java @@ -113,8 +113,7 @@ public IndexLifecycleService( } public void maybeRunAsyncAction(ClusterState clusterState, IndexMetadata indexMetadata, StepKey nextStepKey) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); - lifecycleRunner.maybeRunAsyncAction(clusterState, indexMetadata, policyName, nextStepKey); + lifecycleRunner.maybeRunAsyncAction(clusterState, indexMetadata, indexMetadata.getLifecyclePolicyName(), nextStepKey); } /** @@ -177,8 +176,8 @@ void onMaster(ClusterState clusterState) { // If we just became master, we need to kick off any async actions that // may have not been run due to master rollover for (IndexMetadata idxMeta : clusterState.metadata().indices().values()) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); - if (Strings.isNullOrEmpty(policyName) == false) { + String policyName = idxMeta.getLifecyclePolicyName(); + if (Strings.hasText(policyName)) { final LifecycleExecutionState lifecycleState = idxMeta.getLifecycleExecutionState(); StepKey stepKey = Step.getCurrentStepKey(lifecycleState); @@ -384,8 +383,8 @@ void triggerPolicies(ClusterState clusterState, boolean fromClusterStateChange) // managed by the Index Lifecycle Service they have a index.lifecycle.name setting // associated to a policy for (IndexMetadata idxMeta : clusterState.metadata().indices().values()) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()); - if (Strings.isNullOrEmpty(policyName) == false) { + String policyName = idxMeta.getLifecyclePolicyName(); + if (Strings.hasText(policyName)) { final LifecycleExecutionState lifecycleState = idxMeta.getLifecycleExecutionState(); StepKey stepKey = Step.getCurrentStepKey(lifecycleState); @@ -500,9 +499,7 @@ static Set indicesOnShuttingDownNodesInDangerousStep(ClusterState state, .indices() .stream() // Filter out to only consider managed indices - .filter( - indexToMetadata -> Strings.hasText(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexToMetadata.getValue().getSettings())) - ) + .filter(indexToMetadata -> Strings.hasText(indexToMetadata.getValue().getLifecyclePolicyName())) // Only look at indices in the shrink action .filter(indexToMetadata -> ShrinkAction.NAME.equals(indexToMetadata.getValue().getLifecycleExecutionState().action())) // Only look at indices on a step that may potentially be dangerous if we removed the node diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java index d348ef3eba9aa..bf81d3af7c02c 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java @@ -76,11 +76,10 @@ public static void validateTransition( PolicyStepsRegistry stepRegistry ) { String indexName = idxMeta.getIndex().getName(); - Settings indexSettings = idxMeta.getSettings(); - String indexPolicySetting = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings); + String policyName = idxMeta.getLifecyclePolicyName(); // policy could be updated in-between execution - if (Strings.isNullOrEmpty(indexPolicySetting)) { + if (Strings.isNullOrEmpty(policyName)) { throw new IllegalArgumentException("index [" + indexName + "] is not associated with an Index Lifecycle Policy"); } @@ -100,15 +99,9 @@ public static void validateTransition( // Always allow moving to the terminal step or to a step that's present in the cached phase, even if it doesn't exist in the policy if (isNewStepCached == false - && (stepRegistry.stepExists(indexPolicySetting, newStepKey) == false && newStepKey.equals(TerminalPolicyStep.KEY) == false)) { + && (stepRegistry.stepExists(policyName, newStepKey) == false && newStepKey.equals(TerminalPolicyStep.KEY) == false)) { throw new IllegalArgumentException( - "step [" - + newStepKey - + "] for index [" - + idxMeta.getIndex().getName() - + "] with policy [" - + indexPolicySetting - + "] does not exist" + "step [" + newStepKey + "] for index [" + idxMeta.getIndex().getName() + "] with policy [" + policyName + "] does not exist" ); } } @@ -137,13 +130,11 @@ static ClusterState moveClusterStateToStep( Step.StepKey currentStepKey = Step.getCurrentStepKey(idxMeta.getLifecycleExecutionState()); validateTransition(idxMeta, currentStepKey, newStepKey, stepRegistry); - Settings indexSettings = idxMeta.getSettings(); - String policy = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings); - logger.info("moving index [{}] from [{}] to [{}] in policy [{}]", index.getName(), currentStepKey, newStepKey, policy); + String policyName = idxMeta.getLifecyclePolicyName(); + logger.info("moving index [{}] from [{}] to [{}] in policy [{}]", index.getName(), currentStepKey, newStepKey, policyName); IndexLifecycleMetadata ilmMeta = state.metadata().custom(IndexLifecycleMetadata.TYPE); - LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas() - .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings())); + LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(idxMeta.getLifecyclePolicyName()); LifecycleExecutionState lifecycleState = idxMeta.getLifecycleExecutionState(); LifecycleExecutionState newLifecycleState = updateExecutionStateToStep( policyMetadata, @@ -170,8 +161,7 @@ static ClusterState moveClusterStateToErrorStep( ) throws IOException { IndexMetadata idxMeta = clusterState.getMetadata().index(index); IndexLifecycleMetadata ilmMeta = clusterState.metadata().custom(IndexLifecycleMetadata.TYPE); - LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas() - .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings())); + LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(idxMeta.getLifecyclePolicyName()); XContentBuilder causeXContentBuilder = JsonXContent.contentBuilder(); causeXContentBuilder.startObject(); ElasticsearchException.generateThrowableXContent(causeXContentBuilder, STACKTRACE_PARAMS, cause); @@ -245,8 +235,7 @@ static ClusterState moveClusterStateToPreviouslyFailedStep( IndexLifecycleTransition.validateTransition(indexMetadata, currentStepKey, nextStepKey, stepRegistry); IndexLifecycleMetadata ilmMeta = currentState.metadata().custom(IndexLifecycleMetadata.TYPE); - LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas() - .get(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings())); + LifecyclePolicyMetadata policyMetadata = ilmMeta.getPolicyMetadatas().get(indexMetadata.getLifecyclePolicyName()); Map policyPhases = policyMetadata.getPolicy().getPhases(); @@ -360,7 +349,7 @@ public static LifecycleExecutionState moveStateToNextActionAndUpdateCachedPhase( Client client, XPackLicenseState licenseState ) { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + String policyName = indexMetadata.getLifecyclePolicyName(); Step.StepKey currentStepKey = Step.getCurrentStepKey(existingState); if (currentStepKey == null) { logger.warn( diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java index 47c07319d5bc5..55623a20e4923 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleUsageTransportAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.xpack.core.ilm.IndexLifecycleFeatureSetUsage.ActionConfigStats; import org.elasticsearch.xpack.core.ilm.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.ilm.LifecycleAction; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.RolloverAction; import org.elasticsearch.xpack.core.ilm.SetPriorityAction; import org.elasticsearch.xpack.core.ilm.ShrinkAction; @@ -74,7 +73,7 @@ protected void masterOperation( if (lifecycleMetadata != null) { Map policyUsage = new HashMap<>(); metadata.indices().forEach(entry -> { - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(entry.value.getSettings()); + String policyName = entry.value.getLifecyclePolicyName(); Integer indicesManaged = policyUsage.get(policyName); if (indicesManaged == null) { indicesManaged = 1; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java index ae572d87ff2c1..c848300f8b3a6 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToErrorStepUpdateTask.java @@ -17,9 +17,7 @@ import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Step; import java.io.IOException; @@ -64,10 +62,8 @@ public ClusterState execute(ClusterState currentState) throws IOException { // Index must have been since deleted, ignore it return currentState; } - Settings indexSettings = idxMeta.getSettings(); LifecycleExecutionState indexILMData = idxMeta.getLifecycleExecutionState(); - if (policy.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings)) - && currentStepKey.equals(Step.getCurrentStepKey(indexILMData))) { + if (policy.equals(idxMeta.getLifecyclePolicyName()) && currentStepKey.equals(Step.getCurrentStepKey(indexILMData))) { return IndexLifecycleTransition.moveClusterStateToErrorStep(index, currentState, cause, nowSupplier, stepLookupFunction); } else { // either the policy has changed or the step is now diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java index 4e9b2e8e5e0dd..0cb2324797fef 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/MoveToNextStepUpdateTask.java @@ -12,9 +12,7 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Step; import java.util.Objects; @@ -54,10 +52,8 @@ public ClusterState doExecute(ClusterState currentState) { // Index must have been since deleted, ignore it return currentState; } - Settings indexSettings = indexMetadata.getSettings(); LifecycleExecutionState indexILMData = currentState.getMetadata().index(index).getLifecycleExecutionState(); - if (policy.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings)) - && currentStepKey.equals(Step.getCurrentStepKey(indexILMData))) { + if (policy.equals(indexMetadata.getLifecyclePolicyName()) && currentStepKey.equals(Step.getCurrentStepKey(indexILMData))) { logger.trace("moving [{}] to next step ({})", index.getName(), nextStepKey); return IndexLifecycleTransition.moveClusterStateToStep(index, currentState, nextStepKey, nowSupplier, stepRegistry, false); } else { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java index 33ad84b517189..e1ac188e9e2bb 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/PolicyStepsRegistry.java @@ -32,7 +32,6 @@ import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep; import org.elasticsearch.xpack.core.ilm.LifecyclePolicy; import org.elasticsearch.xpack.core.ilm.LifecyclePolicyMetadata; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Phase; import org.elasticsearch.xpack.core.ilm.PhaseCacheManagement; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; @@ -205,7 +204,7 @@ private List getAllStepsForIndex(ClusterState state, Index index) { throw new IllegalArgumentException("index " + index + " does not exist in the current cluster state"); } final IndexMetadata indexMetadata = metadata.index(index); - final String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + final String policyName = indexMetadata.getLifecyclePolicyName(); final LifecyclePolicyMetadata policyMetadata = lifecyclePolicyMap.get(policyName); if (policyMetadata == null) { throw new IllegalArgumentException("the policy [" + policyName + "] for index" + index + " does not exist"); @@ -320,7 +319,7 @@ public Step getStep(final IndexMetadata indexMetadata, final Step.StepKey stepKe } final String phase = stepKey.getPhase(); - final String policyName = indexMetadata.getSettings().get(LifecycleSettings.LIFECYCLE_NAME); + final String policyName = indexMetadata.getLifecyclePolicyName(); final Index index = indexMetadata.getIndex(); if (policyName == null) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java index 271507ab01e8d..5fa7f32e87451 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/SetStepInfoUpdateTask.java @@ -14,11 +14,9 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.metadata.LifecycleExecutionState; -import org.elasticsearch.common.settings.Settings; import org.elasticsearch.index.Index; import org.elasticsearch.xcontent.ToXContentObject; import org.elasticsearch.xcontent.XContentBuilder; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Step; import java.io.IOException; @@ -52,10 +50,8 @@ protected ClusterState doExecute(ClusterState currentState) throws IOException { // Index must have been since deleted, ignore it return currentState; } - Settings indexSettings = idxMeta.getSettings(); LifecycleExecutionState indexILMData = idxMeta.getLifecycleExecutionState(); - if (policy.equals(LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexSettings)) - && Objects.equals(currentStepKey, Step.getCurrentStepKey(indexILMData))) { + if (policy.equals(idxMeta.getLifecyclePolicyName()) && Objects.equals(currentStepKey, Step.getCurrentStepKey(indexILMData))) { return IndexLifecycleTransition.addStepInfoToClusterState(index, currentState, stepInfo); } else { // either the policy has changed or the step is now diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java index e55a0a3a10ae3..d87e2b603e8c4 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportDeleteLifecycleAction.java @@ -34,8 +34,6 @@ import java.util.TreeMap; import java.util.stream.Collectors; -import static org.elasticsearch.xpack.core.ilm.LifecycleSettings.LIFECYCLE_NAME_SETTING; - public class TransportDeleteLifecycleAction extends TransportMasterNodeAction { @Inject @@ -71,7 +69,7 @@ public ClusterState execute(ClusterState currentState) { .indices() .values() .stream() - .filter(idxMeta -> LIFECYCLE_NAME_SETTING.get(idxMeta.getSettings()).equals(policyToDelete)) + .filter(idxMeta -> policyToDelete.equals(idxMeta.getLifecyclePolicyName())) .map(idxMeta -> idxMeta.getIndex().getName()) .collect(Collectors.toList()); if (indicesUsingPolicy.isEmpty() == false) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java index c7939c4cf9ea3..6e43d64636e64 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; import org.elasticsearch.xpack.core.ilm.ExplainLifecycleResponse; import org.elasticsearch.xpack.core.ilm.IndexLifecycleExplainResponse; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.PhaseExecutionInfo; import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; import org.elasticsearch.xpack.ilm.IndexLifecycleService; @@ -114,7 +113,7 @@ static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse( ) throws IOException { Settings idxSettings = indexMetadata.getSettings(); LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState(); - String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(idxSettings); + String policyName = indexMetadata.getLifecyclePolicyName(); String currentPhase = lifecycleState.phase(); String stepInfo = lifecycleState.stepInfo(); BytesArray stepInfoBytes = null; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java index c15ecfc682ada..9fe5e45647166 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportMoveToStepAction.java @@ -26,7 +26,6 @@ import org.elasticsearch.tasks.Task; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TransportService; -import org.elasticsearch.xpack.core.ilm.LifecycleSettings; import org.elasticsearch.xpack.core.ilm.Step; import org.elasticsearch.xpack.core.ilm.action.MoveToStepAction; import org.elasticsearch.xpack.core.ilm.action.MoveToStepAction.Request; @@ -68,9 +67,11 @@ protected void masterOperation(Task task, Request request, ClusterState state, A return; } - final String policyName = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetadata.getSettings()); + final String policyName = indexMetadata.getLifecyclePolicyName(); if (policyName == null) { - listener.onFailure(new IllegalArgumentException("index [" + request.getIndex() + "] is not managed by ILM")); + listener.onFailure( + new IllegalArgumentException("index [" + request.getIndex() + "] is not associated with an Index Lifecycle Policy") + ); return; } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java index 79623d0abf662..234c07ffdc758 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleServiceTests.java @@ -158,7 +158,7 @@ public void testStoppedModeSkip() { ); Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); @@ -200,7 +200,7 @@ public void testRequestedStopOnShrink() { lifecycleState.setAction(mockShrinkStep.getAction()); lifecycleState.setStep(mockShrinkStep.getName()); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) @@ -260,7 +260,7 @@ private void verifyCanStopWithStep(String stoppableStep) { lifecycleState.setAction(mockShrinkStep.getAction()); lifecycleState.setStep(mockShrinkStep.getName()); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) @@ -314,7 +314,7 @@ public void testRequestedStopOnSafeAction() { lifecycleState.setAction(currentStepKey.getAction()); lifecycleState.setStep(currentStepKey.getName()); IndexMetadata indexMetadata = IndexMetadata.builder(index.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policyName)) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policyName)) .putCustom(ILM_CUSTOM_METADATA_KEY, lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) @@ -430,13 +430,13 @@ public void doTestExceptionStillProcessesOtherIndices(boolean useOnMaster) { ); IndexMetadata i1indexMetadata = IndexMetadata.builder(index1.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policy1)) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policy1)) .putCustom(ILM_CUSTOM_METADATA_KEY, i1lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) .build(); IndexMetadata i2indexMetadata = IndexMetadata.builder(index2.getName()) - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), policy1)) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, policy1)) .putCustom(ILM_CUSTOM_METADATA_KEY, i2lifecycleState.build().asMap()) .numberOfShards(randomIntBetween(1, 5)) .numberOfReplicas(randomIntBetween(0, 5)) @@ -535,7 +535,7 @@ public void testIndicesOnShuttingDownNodesInDangerousStep() { ); IndexMetadata nonDangerousIndex = IndexMetadata.builder("no_danger") - .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), "mypolicy")) + .settings(settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy")) .putCustom( ILM_CUSTOM_METADATA_KEY, LifecycleExecutionState.builder() @@ -550,7 +550,7 @@ public void testIndicesOnShuttingDownNodesInDangerousStep() { .build(); IndexMetadata dangerousIndex = IndexMetadata.builder("danger") .settings( - settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey(), "mypolicy") + settings(Version.CURRENT).put(LifecycleSettings.LIFECYCLE_NAME, "mypolicy") .put(IndexMetadata.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_id", "shutdown_node") ) .putCustom( diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java index 05f8d3139048c..323c6614d8c94 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransitionTests.java @@ -1195,8 +1195,12 @@ private ClusterState buildClusterState( public static void assertIndexNotManagedByILM(ClusterState clusterState, Index index) { Metadata metadata = clusterState.metadata(); assertNotNull(metadata); + IndexMetadata indexMetadata = metadata.getIndexSafe(index); assertNotNull(indexMetadata); + + assertNull(indexMetadata.getLifecyclePolicyName()); + Settings indexSettings = indexMetadata.getSettings(); assertNotNull(indexSettings); assertFalse(LifecycleSettings.LIFECYCLE_NAME_SETTING.exists(indexSettings));