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 @@ -79,11 +79,13 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {

private String index;
private String policy;
private String alias;

@Before
public void refreshIndex() {
index = randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
policy = randomAlphaOfLength(5);
index = "index-" + randomAlphaOfLength(10).toLowerCase(Locale.ROOT);
policy = "policy-" + randomAlphaOfLength(5);
alias = "alias-" + randomAlphaOfLength(5);
}

public static void updatePolicy(String indexName, String policy) throws IOException {
Expand All @@ -101,7 +103,7 @@ public void testFullPolicy() throws Exception {
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.routing.allocation.include._name", "integTest-0")
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));

// create policy
createFullPolicy(TimeValue.ZERO);
Expand Down Expand Up @@ -163,7 +165,7 @@ public void testMoveToRolloverStep() throws Exception {
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 4)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put("index.routing.allocation.include._name", "integTest-0")
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));

createFullPolicy(TimeValue.timeValueHours(10));
// update policy on index
Expand Down Expand Up @@ -243,7 +245,7 @@ public void testRolloverAction() throws Exception {
String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));

// create policy
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
Expand All @@ -261,7 +263,7 @@ public void testRolloverActionWithIndexingComplete() throws Exception {
String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));

Request updateSettingsRequest = new Request("PUT", "/" + originalIndex + "/_settings");
updateSettingsRequest.setJsonEntity("{\n" +
Expand All @@ -276,7 +278,7 @@ public void testRolloverActionWithIndexingComplete() throws Exception {
" {\n" +
" \"add\": {\n" +
" \"index\": \"" + originalIndex + "\",\n" +
" \"alias\": \"alias\",\n" +
" \"alias\": \"" + alias + "\",\n" +
" \"is_write_index\": false\n" +
" }\n" +
" }\n" +
Expand Down Expand Up @@ -352,7 +354,7 @@ public void testWaitForSnapshot() throws Exception {
request = new Request("DELETE", "/_snapshot/" + repo);
assertOK(client().performRequest(request));
}

public void testWaitForSnapshotSlmExecutedBefore() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
Expand Down Expand Up @@ -776,7 +778,7 @@ public void testRemoveAndReaddPolicy() throws Exception {
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));

// Index a document
index(client(), originalIndex, "_id", "foo", "bar");
Expand All @@ -794,7 +796,7 @@ public void testRemoveAndReaddPolicy() throws Exception {
addPolicyRequest.setJsonEntity("{\n" +
" \"settings\": {\n" +
" \"index.lifecycle.name\": \"" + policy + "\",\n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" +
"}");
client().performRequest(addPolicyRequest);
Expand All @@ -811,7 +813,7 @@ public void testMoveToInjectedStep() throws Exception {
createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 3)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias));

assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(new StepKey("new", "complete", "complete"))));

Expand Down Expand Up @@ -847,7 +849,7 @@ public void testMoveToStepRereadsPolicy() throws Exception {
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true);

assertBusy(() -> assertThat(getStepKeyForIndex("test-1"), equalTo(new StepKey("hot", "rollover", "check-rollover-ready"))));
Expand Down Expand Up @@ -924,7 +926,7 @@ public void testExplainFilters() throws Exception {
}

createIndexWithSettings(goodIndex, Settings.builder()
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
);
Expand Down Expand Up @@ -983,7 +985,7 @@ public void testILMRolloverRetriesOnReadOnlyBlock() throws Exception {
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias")
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put("index.blocks.read_only", true),
true
);
Expand Down Expand Up @@ -1018,7 +1020,7 @@ public void testILMRolloverOnManuallyRolledIndex() throws Exception {
" \"number_of_shards\": 1,\n" +
" \"number_of_replicas\": 0,\n" +
" \"index.lifecycle.name\": \"" + policy + "\", \n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" +
"}");
client().performRequest(createIndexTemplate);
Expand All @@ -1036,7 +1038,7 @@ public void testILMRolloverOnManuallyRolledIndex() throws Exception {
client().performRequest(refreshOriginalIndex);

// Manual rollover
Request rolloverRequest = new Request("POST", "/alias/_rollover");
Request rolloverRequest = new Request("POST", "/" + alias + "/_rollover");
rolloverRequest.setJsonEntity("{\n" +
" \"conditions\": {\n" +
" \"max_docs\": \"1\"\n" +
Expand All @@ -1057,9 +1059,9 @@ public void testILMRolloverOnManuallyRolledIndex() throws Exception {
assertBusy(() -> assertTrue((boolean) explainIndex(secondIndex).getOrDefault("managed", true)));

// index some documents to trigger an ILM rollover
index(client(), "alias", "1", "foo", "bar");
index(client(), "alias", "2", "foo", "bar");
index(client(), "alias", "3", "foo", "bar");
index(client(), alias, "1", "foo", "bar");
index(client(), alias, "2", "foo", "bar");
index(client(), alias, "3", "foo", "bar");
Request refreshSecondIndex = new Request("POST", "/" + secondIndex + "/_refresh");
client().performRequest(refreshSecondIndex).getStatusLine();

Expand All @@ -1079,7 +1081,7 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
rolledIndex,
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
false
);

Expand All @@ -1088,7 +1090,7 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true
);

Expand Down Expand Up @@ -1151,7 +1153,7 @@ public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing(
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true
);

Expand Down Expand Up @@ -1191,7 +1193,7 @@ public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing(

// manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index
// will have rollover information now
Request rolloverRequest = new Request("POST", "/alias/_rollover");
Request rolloverRequest = new Request("POST", "/" + alias + "/_rollover");
rolloverRequest.setJsonEntity("{\n" +
" \"conditions\": {\n" +
" \"max_docs\": \"1\"\n" +
Expand All @@ -1207,7 +1209,7 @@ public void testWaitForActiveShardsStep() throws Exception {
String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias),
true);

// create policy
Expand Down Expand Up @@ -1249,7 +1251,7 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
" \"number_of_shards\": 1,\n" +
" \"number_of_replicas\": 0,\n" +
" \"index.lifecycle.name\": \"" + policy+ "\",\n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" +
"}");
client().performRequest(createIndexTemplate);
Expand Down Expand Up @@ -1402,7 +1404,7 @@ public void testRefreshablePhaseJson() throws Exception {
" \"number_of_shards\": 1,\n" +
" \"number_of_replicas\": 0,\n" +
" \"index.lifecycle.name\": \"" + policy+ "\",\n" +
" \"index.lifecycle.rollover_alias\": \"alias\"\n" +
" \"index.lifecycle.rollover_alias\": \"" + alias + "\"\n" +
" }\n" +
"}");
client().performRequest(createIndexTemplate);
Expand Down Expand Up @@ -1584,7 +1586,7 @@ private void createIndexWithSettings(String index, Settings.Builder settings, bo
writeIndexSnippet = "\"is_write_index\": true";
}
request.setJsonEntity("{\n \"settings\": " + Strings.toString(settings.build())
+ ", \"aliases\" : { \"alias\": { " + writeIndexSnippet + " } } }");
+ ", \"aliases\" : { \"" + alias + "\": { " + writeIndexSnippet + " } } }");
client().performRequest(request);
// wait for the shards to initialize
ensureGreen(index);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ teardown:
action: "forcemerge"
name: "forcemerge"
- match: { error.root_cause.0.type: "illegal_argument_exception" }
- match: { error.root_cause.0.reason: "index [my_index] is not on current step [{\"phase\":\"warm\",\"action\":\"forcemerge\",\"name\":\"forcemerge\"}]" }
- match: { error.root_cause.0.reason: "index [my_index] is not on current step [{\"phase\":\"warm\",\"action\":\"forcemerge\",\"name\":\"forcemerge\"}], currently: [{\"phase\":\"new\",\"action\":\"complete\",\"name\":\"complete\"}]" }


- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ public static void validateTransition(IndexMetaData idxMeta, Step.StepKey curren
}

LifecycleExecutionState lifecycleState = LifecycleExecutionState.fromIndexMetadata(idxMeta);
if (currentStepKey != null && currentStepKey.equals(LifecycleExecutionState.getCurrentStepKey(lifecycleState)) == false) {
throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey + "]");
Step.StepKey realKey = LifecycleExecutionState.getCurrentStepKey(lifecycleState);
if (currentStepKey != null && currentStepKey.equals(realKey) == false) {
throw new IllegalArgumentException("index [" + indexName + "] is not on current step [" + currentStepKey +
"], currently: [" + realKey + "]");
}

if (stepRegistry.stepExists(indexPolicySetting, newStepKey) == false) {
Expand Down