Skip to content

Commit c009641

Browse files
committed
update to not throw exception when step not recognized in runner, but throw in action
1 parent c82a463 commit c009641

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ static ClusterState moveClusterStateToStep(String indexName, ClusterState curren
185185

186186
Step nextStep = stepRegistry.getStep(indexPolicySetting, nextStepKey);
187187
if (nextStep == null) {
188-
throw new IllegalArgumentException("step [" + nextStepKey + "] with policy [" + indexPolicySetting + "] does not exist");
188+
// stepRegistry may not be up-to-date with latest policies/steps in cluster-state
189+
return currentState;
189190
}
190191

191192
return IndexLifecycleRunner.moveClusterStateToNextStep(idxMeta.getIndex(), currentState, currentStepKey, nextStepKey, nowSupplier);

x-pack/plugin/index-lifecycle/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/TransportMoveToStepAction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ protected void masterOperation(Request request, ClusterState state, ActionListen
5858
new AckedClusterStateUpdateTask<Response>(request, listener) {
5959
@Override
6060
public ClusterState execute(ClusterState currentState) {
61-
return indexLifecycleService.moveClusterStateToStep(currentState, request.getIndex(), request.getCurrentStepKey(),
61+
ClusterState movedState = indexLifecycleService.moveClusterStateToStep(currentState, request.getIndex(), request.getCurrentStepKey(),
6262
request.getNextStepKey());
63+
if (currentState == movedState) {
64+
throw new IllegalArgumentException("next step [" + request.getNextStepKey() + "] is not recognized");
65+
}
66+
return movedState;
6367
}
6468

6569
@Override

x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -674,12 +674,9 @@ public void testValidatedMoveClusterStateToNextStepInvalidNextStep() {
674674
.put(LifecycleSettings.LIFECYCLE_ACTION, currentStepKey.getAction())
675675
.put(LifecycleSettings.LIFECYCLE_STEP, currentStepKey.getName());
676676
ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, Collections.emptyList());
677-
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class,
678-
() -> IndexLifecycleRunner.moveClusterStateToStep(indexName, clusterState, currentStepKey,
679-
nextStepKey, () -> now, stepRegistry));
680-
assertThat(exception.getMessage(),
681-
equalTo("step [{\"phase\":\"next_phase\",\"action\":\"next_action\",\"name\":\"next_step\"}] " +
682-
"with policy [my_policy] does not exist"));
677+
ClusterState newState = IndexLifecycleRunner.moveClusterStateToStep(indexName, clusterState, currentStepKey,
678+
nextStepKey, () -> now, stepRegistry);
679+
assertSame(newState, clusterState);
683680
}
684681

685682
public void testMoveClusterStateToErrorStep() throws IOException {

x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/20_move_to_step.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ teardown:
138138
action: "invalid"
139139
name: "invalid"
140140
- match: { error.root_cause.0.type: "illegal_argument_exception" }
141-
- match: { error.root_cause.0.reason: "step [{\"phase\":\"invalid\",\"action\":\"invalid\",\"name\":\"invalid\"}] with policy [my_moveable_timeseries_lifecycle] does not exist" }
141+
- match: { error.root_cause.0.reason: "next step [{\"phase\":\"invalid\",\"action\":\"invalid\",\"name\":\"invalid\"}] is not recognized" }
142142

143143
- do:
144144
acknowledge: true

0 commit comments

Comments
 (0)