diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java index 7bdebb0ea44ca..5b6e700c77c4e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleType.java @@ -154,11 +154,20 @@ public List getOrderedPhases(Map phases) { } public static boolean shouldInjectMigrateStepForPhase(Phase phase) { + if (ALLOWED_ACTIONS.containsKey(phase.getName()) == false) { + return false; + } + // searchable snapshots automatically set their own allocation rules, no need to configure them with a migrate step. if (phase.getActions().get(SearchableSnapshotAction.NAME) != null) { return false; } + // do not inject if MigrateAction is not supported for this phase (such as hot, frozen, delete phase) + if (ALLOWED_ACTIONS.get(phase.getName()).contains(MigrateAction.NAME) == false) { + return false; + } + // if the user configured the {@link MigrateAction} already we won't automatically configure it if (phase.getActions().get(MigrateAction.NAME) != null) { return false; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java index 4a025171da1c0..9d1168c122b29 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/TimeseriesLifecycleTypeTests.java @@ -843,6 +843,29 @@ public void testShouldMigrateDataToTiers() { assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false)); } + { + // not inject in hot phase + Phase phase = new Phase(HOT_PHASE, TimeValue.ZERO, Collections.emptyMap()); + assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false)); + } + + { + // not inject in frozen phase + Phase phase = new Phase(FROZEN_PHASE, TimeValue.ZERO, Collections.emptyMap()); + assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false)); + } + + { + // not inject in delete phase + Phase phase = new Phase(DELETE_PHASE, TimeValue.ZERO, Collections.emptyMap()); + assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false)); + } + + { + // return false for invalid phase + Phase phase = new Phase(HOT_PHASE + randomAlphaOfLength(5), TimeValue.ZERO, Collections.emptyMap()); + assertThat(TimeseriesLifecycleType.shouldInjectMigrateStepForPhase(phase), is(false)); + } } public void testValidatingSearchableSnapshotRepos() {