Removes unused stepsRegistry from move to step task

This commit is contained in:
Colin Goodheart-Smithe 2018-06-14 13:47:16 +01:00
parent 2f00ef777f
commit 7412943f60
No known key found for this signature in database
GPG Key ID: F975E7BDD739B3C7
3 changed files with 8 additions and 32 deletions

View File

@ -264,7 +264,7 @@ public class IndexLifecycleRunner {
logger.debug("moveToStep[" + policy + "] [" + index.getName() + "]" + currentStepKey + " -> " logger.debug("moveToStep[" + policy + "] [" + index.getName() + "]" + currentStepKey + " -> "
+ nextStepKey); + nextStepKey);
clusterService.submitStateUpdateTask("ILM", new MoveToNextStepUpdateTask(index, policy, currentStepKey, clusterService.submitStateUpdateTask("ILM", new MoveToNextStepUpdateTask(index, policy, currentStepKey,
nextStepKey, nowSupplier, stepRegistry, newState -> runPolicy(newState.getMetaData().index(index), newState))); nextStepKey, nowSupplier, newState -> runPolicy(newState.getMetaData().index(index), newState)));
} }
private void moveToErrorStep(Index index, String policy, StepKey currentStepKey, Exception e) { private void moveToErrorStep(Index index, String policy, StepKey currentStepKey, Exception e) {

View File

@ -22,17 +22,15 @@ public class MoveToNextStepUpdateTask extends ClusterStateUpdateTask {
private final Step.StepKey nextStepKey; private final Step.StepKey nextStepKey;
private final Listener listener; private final Listener listener;
private final LongSupplier nowSupplier; private final LongSupplier nowSupplier;
private final PolicyStepsRegistry policyStepsRegistry;
public MoveToNextStepUpdateTask(Index index, String policy, Step.StepKey currentStepKey, Step.StepKey nextStepKey, public MoveToNextStepUpdateTask(Index index, String policy, Step.StepKey currentStepKey, Step.StepKey nextStepKey,
LongSupplier nowSupplier, PolicyStepsRegistry policyStepsRegistry, Listener listener) { LongSupplier nowSupplier, Listener listener) {
this.index = index; this.index = index;
this.policy = policy; this.policy = policy;
this.currentStepKey = currentStepKey; this.currentStepKey = currentStepKey;
this.nextStepKey = nextStepKey; this.nextStepKey = nextStepKey;
this.nowSupplier = nowSupplier; this.nowSupplier = nowSupplier;
this.listener = listener; this.listener = listener;
this.policyStepsRegistry = policyStepsRegistry;
} }
Index getIndex() { Index getIndex() {

View File

@ -16,15 +16,9 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index; import org.elasticsearch.index.Index;
import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings;
import org.elasticsearch.xpack.core.indexlifecycle.MockStep;
import org.elasticsearch.xpack.core.indexlifecycle.Step;
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
import org.junit.Before; import org.junit.Before;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.equalTo;
public class MoveToNextStepUpdateTaskTests extends ESTestCase { public class MoveToNextStepUpdateTaskTests extends ESTestCase {
@ -32,7 +26,6 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
String policy; String policy;
ClusterState clusterState; ClusterState clusterState;
Index index; Index index;
PolicyStepsRegistry stepsRegistry;
@Before @Before
public void setupClusterState() { public void setupClusterState() {
@ -47,15 +40,6 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
.put(IndexMetaData.builder(indexMetadata)) .put(IndexMetaData.builder(indexMetadata))
.build(); .build();
clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build(); clusterState = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build();
Step currentStep = new MockStep(new StepKey("current-phase", "current-action", "current-name"), null);
Step nextStep = new MockStep(new StepKey("next-phase", "next-action", "next-name"), null);
Map<StepKey, Step> stepMap = new HashMap<>();
stepMap.put(currentStep.getKey(), currentStep);
stepMap.put(nextStep.getKey(), nextStep);
Map<String, Map<Step.StepKey, Step>> policyMap = Collections.singletonMap(policy, stepMap);
stepsRegistry = new PolicyStepsRegistry(null, null, policyMap);
} }
public void testExecuteSuccessfullyMoved() { public void testExecuteSuccessfullyMoved() {
@ -67,8 +51,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
SetOnce<Boolean> changed = new SetOnce<>(); SetOnce<Boolean> changed = new SetOnce<>();
MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true); MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true);
MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, nextStepKey, () -> now, MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, nextStepKey, () -> now, listener);
stepsRegistry, listener);
ClusterState newState = task.execute(clusterState); ClusterState newState = task.execute(clusterState);
StepKey actualKey = IndexLifecycleRunner.getCurrentStepKey(newState.metaData().index(index).getSettings()); StepKey actualKey = IndexLifecycleRunner.getCurrentStepKey(newState.metaData().index(index).getSettings());
assertThat(actualKey, equalTo(nextStepKey)); assertThat(actualKey, equalTo(nextStepKey));
@ -86,8 +69,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
setStateToKey(notCurrentStepKey); setStateToKey(notCurrentStepKey);
MoveToNextStepUpdateTask.Listener listener = (c) -> { MoveToNextStepUpdateTask.Listener listener = (c) -> {
}; };
MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, null, () -> now, MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, null, () -> now, listener);
stepsRegistry, listener);
ClusterState newState = task.execute(clusterState); ClusterState newState = task.execute(clusterState);
assertSame(newState, clusterState); assertSame(newState, clusterState);
} }
@ -98,8 +80,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
setStateToKey(currentStepKey); setStateToKey(currentStepKey);
setStatePolicy("not-" + policy); setStatePolicy("not-" + policy);
MoveToNextStepUpdateTask.Listener listener = (c) -> {}; MoveToNextStepUpdateTask.Listener listener = (c) -> {};
MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, null, () -> now, MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, null, () -> now, listener);
stepsRegistry, listener);
ClusterState newState = task.execute(clusterState); ClusterState newState = task.execute(clusterState);
assertSame(newState, clusterState); assertSame(newState, clusterState);
} }
@ -113,8 +94,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
SetOnce<Boolean> changed = new SetOnce<>(); SetOnce<Boolean> changed = new SetOnce<>();
MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true); MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true);
MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, invalidNextStep, () -> now, MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, invalidNextStep, () -> now, listener);
stepsRegistry, listener);
ClusterState newState = task.execute(clusterState); ClusterState newState = task.execute(clusterState);
StepKey actualKey = IndexLifecycleRunner.getCurrentStepKey(newState.metaData().index(index).getSettings()); StepKey actualKey = IndexLifecycleRunner.getCurrentStepKey(newState.metaData().index(index).getSettings());
assertThat(actualKey, equalTo(invalidNextStep)); assertThat(actualKey, equalTo(invalidNextStep));
@ -131,8 +111,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
setStateToKey(currentStepKey); setStateToKey(currentStepKey);
SetOnce<Boolean> changed = new SetOnce<>(); SetOnce<Boolean> changed = new SetOnce<>();
MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true); MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true);
MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, null, () -> now, MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, null, () -> now, listener);
stepsRegistry, listener);
task.clusterStateProcessed("source", clusterState, clusterState); task.clusterStateProcessed("source", clusterState, clusterState);
assertNull(changed.get()); assertNull(changed.get());
} }
@ -146,8 +125,7 @@ public class MoveToNextStepUpdateTaskTests extends ESTestCase {
SetOnce<Boolean> changed = new SetOnce<>(); SetOnce<Boolean> changed = new SetOnce<>();
MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true); MoveToNextStepUpdateTask.Listener listener = (c) -> changed.set(true);
MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, nextStepKey, () -> now, MoveToNextStepUpdateTask task = new MoveToNextStepUpdateTask(index, policy, currentStepKey, nextStepKey, () -> now, listener);
stepsRegistry, listener);
Exception expectedException = new RuntimeException(); Exception expectedException = new RuntimeException();
ElasticsearchException exception = expectThrows(ElasticsearchException.class, ElasticsearchException exception = expectThrows(ElasticsearchException.class,
() -> task.onFailure(randomAlphaOfLength(10), expectedException)); () -> task.onFailure(randomAlphaOfLength(10), expectedException));