Skip to content
Merged
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 @@ -178,15 +178,19 @@ public List<Step> toSteps(Client client, LongSupplier nowSupplier) {
// add steps for each phase, in reverse
while (phaseIterator.hasPrevious()) {

Phase previousPhase = phaseIterator.previous();

// add `after` step for phase before next
if (phase != null) {
Step.StepKey afterStepKey = new Step.StepKey(phase.getName(), "pre-" + lastStepKey.getAction(), "after");
// 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 = phaseIterator.previous();
phase = previousPhase;
List<LifecycleAction> orderedActions = type.getOrderedActions(phase);
ListIterator<LifecycleAction> actionIterator = orderedActions.listIterator(orderedActions.size());
// add steps for each action, in reverse
Expand All @@ -203,7 +207,8 @@ public List<Step> toSteps(Client client, LongSupplier nowSupplier) {
}

if (phase != null) {
Step.StepKey afterStepKey = new Step.StepKey(phase.getName(), "pre-" + lastStepKey.getAction(), "after");
// 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);
Copy link
Contributor

Choose a reason for hiding this comment

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

So, for documentation purposes, our phases are now

  1. new
  2. hot (optional)
  3. warm (optional)
  4. cold (optional)
  5. delete (optional)
  6. completed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, although we should be clear in the docs that new and completed are not real phases in the fact that you cannot add actions to them

Step phaseAfterStep = new PhaseAfterStep(nowSupplier, phase.getAfter(), afterStepKey, lastStepKey);
steps.add(phaseAfterStep);
lastStepKey = phaseAfterStep.getKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.function.LongSupplier;

public class PhaseAfterStep extends ClusterStateWaitStep {
public static final String NAME = "after";
private final TimeValue after;
private final LongSupplier nowSupplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void testToStepsWithOneStep() {
phases.put(firstPhase.getName(), firstPhase);
LifecyclePolicy policy = new LifecyclePolicy(TestLifecycleType.INSTANCE, lifecycleName, phases);
StepKey firstStepKey = InitializePolicyContextStep.KEY;
StepKey secondStepKey = new StepKey("test", "pre-test", "after");
StepKey secondStepKey = new StepKey("new", PhaseAfterStep.NAME, PhaseAfterStep.NAME);
List<Step> steps = policy.toSteps(client, nowSupplier);
assertThat(steps.size(), equalTo(4));
assertSame(steps.get(0).getKey(), firstStepKey);
Expand All @@ -151,10 +151,11 @@ public void testToStepsWithTwoPhases() {
Client client = mock(Client.class);
LongSupplier nowSupplier = () -> 0L;
MockStep secondActionStep = new MockStep(new StepKey("second_phase", "test2", "test"), TerminalPolicyStep.KEY);
MockStep secondAfter = new MockStep(new StepKey("second_phase", "pre-test2", "after"), secondActionStep.getKey());
MockStep secondAfter = new MockStep(new StepKey("first_phase", PhaseAfterStep.NAME, PhaseAfterStep.NAME),
secondActionStep.getKey());
MockStep firstActionAnotherStep = new MockStep(new StepKey("first_phase", "test", "bar"), secondAfter.getKey());
MockStep firstActionStep = new MockStep(new StepKey("first_phase", "test", "foo"), firstActionAnotherStep.getKey());
MockStep firstAfter = new MockStep(new StepKey("first_phase", "pre-test", "after"), firstActionStep.getKey());
MockStep firstAfter = new MockStep(new StepKey("new", PhaseAfterStep.NAME, PhaseAfterStep.NAME), firstActionStep.getKey());
MockStep init = new MockStep(InitializePolicyContextStep.KEY, firstAfter.getKey());

lifecycleName = randomAlphaOfLengthBetween(1, 20);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ teardown:
index: "my_index"
body:
current_step:
phase: "hot"
action: "pre-pre-readonly"
phase: "new"
action: "after"
name: "after"
next_step:
phase: "warm"
Expand Down Expand Up @@ -118,8 +118,8 @@ teardown:
index: my_index
- match: { my_index.settings.index.lifecycle.name: "my_moveable_timeseries_lifecycle" }
- match: { my_index.settings.index.lifecycle.step: "after" }
- match: { my_index.settings.index.lifecycle.action: "pre-pre-readonly" }
- match: { my_index.settings.index.lifecycle.phase: "hot" }
- match: { my_index.settings.index.lifecycle.action: "after" }
- match: { my_index.settings.index.lifecycle.phase: "new" }

---
"Test Invalid Move To Step With Invalid Next Step":
Expand All @@ -130,8 +130,8 @@ teardown:
index: "my_index"
body:
current_step:
phase: "hot"
action: "pre-pre-readonly"
phase: "new"
action: "after"
name: "after"
next_step:
phase: "invalid"
Expand All @@ -146,8 +146,8 @@ teardown:
index: my_index
- match: { my_index.settings.index.lifecycle.name: "my_moveable_timeseries_lifecycle" }
- match: { my_index.settings.index.lifecycle.step: "after" }
- match: { my_index.settings.index.lifecycle.action: "pre-pre-readonly" }
- match: { my_index.settings.index.lifecycle.phase: "hot" }
- match: { my_index.settings.index.lifecycle.action: "after" }
- match: { my_index.settings.index.lifecycle.phase: "new" }

---
"Test Invalid Move To Step With Invalid Policy":
Expand Down