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 @@ -30,7 +30,7 @@ public class LifecycleSettings {
public static final Setting<TimeValue> LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL,
TimeValue.timeValueSeconds(3), 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.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_PHASE_SETTING = Setting.simpleString(LIFECYCLE_PHASE,
Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex);
public static final Setting<String> LIFECYCLE_ACTION_SETTING = Setting.simpleString(LIFECYCLE_ACTION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ public void refreshIndex() {
policy = randomAlphaOfLength(5);
}

public static void updatePolicy(String indexName, String policy) throws IOException {
Request request = new Request("PUT", "/" + indexName + "/_lifecycle/" + policy);
client().performRequest(request);
}

public void testAllocate() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
String allocateNodeName = "node-" + randomFrom(0, 1);
AllocateAction allocateAction = new AllocateAction(null, null, singletonMap("_name", allocateNodeName));
createNewSingletonPolicy(randomFrom("warm", "cold"), allocateAction);
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
updatePolicy(index, policy);
assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(index);
assertThat(getStepKey(settings), equalTo(TerminalPolicyStep.KEY));
Expand All @@ -69,15 +74,15 @@ public void testDelete() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
createNewSingletonPolicy("delete", new DeleteAction());
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
updatePolicy(index, policy);
assertBusy(() -> assertFalse(indexExists(index)));
}

public void testReadOnly() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
createNewSingletonPolicy("warm", new ReadOnlyAction());
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
updatePolicy(index, policy);
assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(index);
assertThat(getStepKey(settings), equalTo(TerminalPolicyStep.KEY));
Expand Down Expand Up @@ -111,7 +116,7 @@ public void testForceMergeAction() throws Exception {
assertThat(numSegments.get(), greaterThan(1));

createNewSingletonPolicy("warm", new ForceMergeAction(1));
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
updatePolicy(index, policy);

assertBusy(() -> {
assertThat(getStepKey(getOnlyIndexSettings(index)), equalTo(TerminalPolicyStep.KEY));
Expand All @@ -126,7 +131,7 @@ public void testReplicasAction() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numReplicas));
createNewSingletonPolicy(randomFrom("warm", "cold"), new ReplicasAction(finalNumReplicas));
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
updatePolicy(index, policy);

assertBusy(() -> {
Map<String, Object> settings = getOnlyIndexSettings(index);
Expand All @@ -143,7 +148,7 @@ public void testShrinkAction() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
createNewSingletonPolicy("warm", new ShrinkAction(expectedFinalShards));
updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy));
updatePolicy(index, policy);
assertBusy(() -> {
assertTrue(indexExists(shrunkenIndex));
assertTrue(aliasExists(shrunkenIndex, index));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@ setup:
- match: { error.root_cause.0.reason: "Cannot delete policy [my_timeseries_lifecycle]. It is being used by at least one index [my_timeseries_index]" }

- do:
indices.put_settings:
xpack.index_lifecycle.remove_policy:
index: my_timeseries_index
body:
index.lifecycle.name: ""

- do:
acknowledge: true
Expand Down