Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ public void testExplainLifecycle() throws Exception {
GetSettingsResponse settingsResponse = highLevelClient().indices().getSettings(getSettingsRequest, RequestOptions.DEFAULT);
assertThat(settingsResponse.getSetting("foo", "index.lifecycle.name"), equalTo(policy));
assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policy));
assertThat(settingsResponse.getSetting("foo", "index.lifecycle.phase"), equalTo("hot"));
assertThat(settingsResponse.getSetting("baz", "index.lifecycle.phase"), equalTo("hot"));
assertThat(settingsResponse.getSetting("foo", "index.lifecycle.next_phase"), equalTo("hot"));
assertThat(settingsResponse.getSetting("baz", "index.lifecycle.next_phase"), equalTo("hot"));
});

ExplainLifecycleRequest req = new ExplainLifecycleRequest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import org.elasticsearch.index.Index;

public final class InitializePolicyContextStep extends ClusterStateActionStep {
public static final StepKey KEY = new StepKey("new", "init", "init");
public static final String INITIALIZATION_PHASE = "new";
public static final StepKey KEY = new StepKey(INITIALIZATION_PHASE, "init", "init");

public InitializePolicyContextStep(Step.StepKey key, StepKey nextStepKey) {
super(key, nextStepKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.LongSupplier;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -165,10 +164,9 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
*
* @param client The Elasticsearch Client to use during execution of {@link AsyncActionStep}
* and {@link AsyncWaitStep} steps.
* @param nowSupplier The supplier of the current time for {@link PhaseAfterStep} steps.
* @return The list of {@link Step} objects in order of their execution.
*/
public List<Step> toSteps(Client client, LongSupplier nowSupplier) {
public List<Step> toSteps(Client client) {
List<Step> steps = new ArrayList<>();
List<Phase> orderedPhases = type.getOrderedPhases(phases);
ListIterator<Phase> phaseIterator = orderedPhases.listIterator(orderedPhases.size());
Expand All @@ -183,16 +181,6 @@ public List<Step> toSteps(Client client, LongSupplier nowSupplier) {

Phase previousPhase = phaseIterator.previous();

// add `after` step for phase before next
if (phase != null) {
// after step should have the name of the previous phase since the index is still in the
// previous phase until the after condition is reached
Step.StepKey afterStepKey = new Step.StepKey(previousPhase.getName(), PhaseAfterStep.NAME, PhaseAfterStep.NAME);
Step phaseAfterStep = new PhaseAfterStep(nowSupplier, phase.getAfter(), afterStepKey, lastStepKey);
steps.add(phaseAfterStep);
lastStepKey = phaseAfterStep.getKey();
}

phase = previousPhase;
List<LifecycleAction> orderedActions = type.getOrderedActions(phase);
ListIterator<LifecycleAction> actionIterator = orderedActions.listIterator(orderedActions.size());
Expand All @@ -209,14 +197,6 @@ public List<Step> toSteps(Client client, LongSupplier nowSupplier) {
}
}

if (phase != null) {
// The very first after step is in a phase before the hot phase so call this "new"
Step.StepKey afterStepKey = new Step.StepKey("new", PhaseAfterStep.NAME, PhaseAfterStep.NAME);
Step phaseAfterStep = new PhaseAfterStep(nowSupplier, phase.getAfter(), afterStepKey, lastStepKey);
steps.add(phaseAfterStep);
lastStepKey = phaseAfterStep.getKey();
}

// init step so that policy is guaranteed to have
steps.add(new InitializePolicyContextStep(InitializePolicyContextStep.KEY, lastStepKey));

Expand All @@ -240,10 +220,10 @@ public boolean isActionSafe(StepKey stepKey) {
return action.isSafeAction();
} else {
throw new IllegalArgumentException("Action [" + stepKey.getAction() + "] in phase [" + stepKey.getPhase()
+ "] does not exist in policy [" + name + "]");
+ "] does not exist in policy [" + name + "]");
}
} else {
throw new IllegalArgumentException("Phase [" + stepKey.getPhase() + "] does not exist in policy [" + name + "]");
throw new IllegalArgumentException("Phase [" + stepKey.getPhase() + "] does not exist in policy [" + name + "]");
}
}

Expand All @@ -256,9 +236,7 @@ public boolean isActionSafe(StepKey stepKey) {
public StepKey getNextValidStep(StepKey stepKey) {
Phase phase = phases.get(stepKey.getPhase());
if (phase == null) {
// Phase doesn't exist so find the after step for the previous
// available phase
return getAfterStepBeforePhase(stepKey.getPhase());
throw new IllegalArgumentException("unable to find next valid step after " + stepKey + " for policy " + name);
} else {
// Phase exists so check if the action exists
LifecycleAction action = phase.getActions().get(stepKey.getAction());
Expand All @@ -281,41 +259,10 @@ public StepKey getNextValidStep(StepKey stepKey) {
}
}

private StepKey getNextAfterStep(String currentPhaseName) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the removal of these as a followup to #33037 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

String nextPhaseName = type.getNextPhaseName(currentPhaseName, phases);
if (nextPhaseName == null) {
// We don't have a next phase after this one so there is no after
// step to move to. Instead we need to go to the terminal step as
// there are no more steps we should execute
return TerminalPolicyStep.KEY;
} else {
return new StepKey(currentPhaseName, PhaseAfterStep.NAME, PhaseAfterStep.NAME);
}
}

private StepKey getAfterStepBeforePhase(String currentPhaseName) {
String nextPhaseName = type.getNextPhaseName(currentPhaseName, phases);
if (nextPhaseName == null) {
// We don't have a next phase after this one so the next step is the
// TerminalPolicyStep
return TerminalPolicyStep.KEY;
} else {
String prevPhaseName = type.getPreviousPhaseName(currentPhaseName, phases);
if (prevPhaseName == null) {
// no previous phase available so go to the
// InitializePolicyContextStep
return InitializePolicyContextStep.KEY;
}
return new StepKey(prevPhaseName, PhaseAfterStep.NAME, PhaseAfterStep.NAME);
}
}

private StepKey getFirstStepInNextAction(String currentActionName, Phase phase) {
String nextActionName = type.getNextActionName(currentActionName, phase);
if (nextActionName == null) {
// The current action is the last in this phase so we need to find
// the next after step
return getNextAfterStep(phase.getName());
return TerminalPolicyStep.KEY;
} else {
LifecycleAction nextAction = phase.getActions().get(nextActionName);
// Return the first stepKey for nextAction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,36 @@
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_PHASE = "index.lifecycle.phase";
public static final String LIFECYCLE_ACTION = "index.lifecycle.action";
public static final String LIFECYCLE_STEP = "index.lifecycle.step";
public static final String LIFECYCLE_NEXT_PHASE = "index.lifecycle.next_phase";
public static final String LIFECYCLE_NEXT_ACTION = "index.lifecycle.next_action";
public static final String LIFECYCLE_NEXT_STEP = "index.lifecycle.next_step";
public static final String LIFECYCLE_CURRENT_PHASE = "index.lifecycle.current_phase";
public static final String LIFECYCLE_CURRENT_ACTION = "index.lifecycle.current_action";
public static final String LIFECYCLE_CURRENT_STEP = "index.lifecycle.current_step";
public static final String LIFECYCLE_INDEX_CREATION_DATE = "index.lifecycle.date";
public static final String LIFECYCLE_PHASE_TIME = "index.lifecycle.phase_time";
public static final String LIFECYCLE_ACTION_TIME = "index.lifecycle.action_time";
public static final String LIFECYCLE_STEP_TIME = "index.lifecycle.step_time";
public static final String LIFECYCLE_FAILED_STEP = "index.lifecycle.failed_step";
public static final String LIFECYCLE_STEP_INFO = "index.lifecycle.step_info";
public static final String LIFECYCLE_SKIP = "index.lifecycle.skip";
public static final String LIFECYCLE_FORCED_PHASE = "index.lifecycle.forced_phase";

public static final Setting<TimeValue> LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL,
TimeValue.timeValueMinutes(10), Setting.Property.Dynamic, Setting.Property.NodeScope);
public static final Setting<String> LIFECYCLE_NAME_SETTING = Setting.simpleString(LIFECYCLE_NAME,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_PHASE_SETTING = Setting.simpleString(LIFECYCLE_PHASE,
public static final Setting<String> LIFECYCLE_NEXT_PHASE_SETTING = Setting.simpleString(LIFECYCLE_NEXT_PHASE,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_ACTION_SETTING = Setting.simpleString(LIFECYCLE_ACTION,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_STEP_SETTING = Setting.simpleString(LIFECYCLE_STEP,
public static final Setting<String> LIFECYCLE_NEXT_ACTION_SETTING = Setting.simpleString(LIFECYCLE_NEXT_ACTION,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_NEXT_STEP_SETTING = Setting.simpleString(LIFECYCLE_NEXT_STEP,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_CURRENT_PHASE_SETTING = Setting.simpleString(LIFECYCLE_CURRENT_PHASE,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_CURRENT_ACTION_SETTING = Setting.simpleString(LIFECYCLE_CURRENT_ACTION,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_CURRENT_STEP_SETTING = Setting.simpleString(LIFECYCLE_CURRENT_STEP,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_FAILED_STEP_SETTING = Setting.simpleString(LIFECYCLE_FAILED_STEP,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
Expand All @@ -49,4 +59,6 @@ public class LifecycleSettings {
Setting.Property.IndexScope, Setting.Property.NotCopyableOnResize, Setting.Property.InternalIndex);
public static final Setting<Boolean> LIFECYCLE_SKIP_SETTING = Setting.boolSetting(LIFECYCLE_SKIP, false,
Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<String> LIFECYCLE_FORCED_PHASE_SETTING = Setting.simpleString(LIFECYCLE_FORCED_PHASE,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,18 @@ public void performAction(IndexMetaData indexMetaData, ClusterState currentState
"] is missing setting[" + LifecycleSettings.LIFECYCLE_INDEX_CREATION_DATE);
}
String lifecycle = LifecycleSettings.LIFECYCLE_NAME_SETTING.get(indexMetaData.getSettings());
String phase = LifecycleSettings.LIFECYCLE_PHASE_SETTING.get(indexMetaData.getSettings());
String action = LifecycleSettings.LIFECYCLE_ACTION_SETTING.get(indexMetaData.getSettings());
String phase = LifecycleSettings.LIFECYCLE_NEXT_PHASE_SETTING.get(indexMetaData.getSettings());
String action = LifecycleSettings.LIFECYCLE_NEXT_ACTION_SETTING.get(indexMetaData.getSettings());

Settings relevantTargetSettings = Settings.builder()
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numberOfShards)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, indexMetaData.getNumberOfReplicas())
.put(LifecycleSettings.LIFECYCLE_INDEX_CREATION_DATE, lifecycleDate)
.put(LifecycleSettings.LIFECYCLE_NAME, lifecycle)
.put(LifecycleSettings.LIFECYCLE_PHASE, phase)
.put(LifecycleSettings.LIFECYCLE_ACTION, action)
.put(LifecycleSettings.LIFECYCLE_STEP, ShrunkenIndexCheckStep.NAME) // skip source-index steps
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", (String) null) // need to remove the single shard
.put(LifecycleSettings.LIFECYCLE_NEXT_PHASE, phase)
.put(LifecycleSettings.LIFECYCLE_NEXT_ACTION, action)
.put(LifecycleSettings.LIFECYCLE_NEXT_STEP, ShrunkenIndexCheckStep.NAME) // skip source-index steps
.put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", (String) null) // need to remove the single shard
// allocation so replicas can be allocated
.build();
String shrunkenIndexName = shrunkIndexPrefix + indexMetaData.getIndex().getName();
Expand All @@ -76,7 +76,7 @@ public void performAction(IndexMetaData indexMetaData, ClusterState currentState
public int hashCode() {
return Objects.hash(super.hashCode(), numberOfShards, shrunkIndexPrefix);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
Expand All @@ -86,8 +86,8 @@ public boolean equals(Object obj) {
return false;
}
ShrinkStep other = (ShrinkStep) obj;
return super.equals(obj) &&
Objects.equals(numberOfShards, other.numberOfShards) &&
return super.equals(obj) &&
Objects.equals(numberOfShards, other.numberOfShards) &&
Objects.equals(shrunkIndexPrefix, other.shrunkIndexPrefix);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
package org.elasticsearch.xpack.core.indexlifecycle;

public class TerminalPolicyStep extends Step {
public static final StepKey KEY = new StepKey("completed", "completed", "completed");
public static final String TERMINAL_PHASE = "completed";
public static final StepKey KEY = new StepKey(TERMINAL_PHASE, "completed", "completed");
public static final TerminalPolicyStep INSTANCE = new TerminalPolicyStep(KEY, null);

TerminalPolicyStep(StepKey key, StepKey nextStepKey) {
Expand Down
Loading