From bdb8b6aa0d6a0592b5fce20637008718a5045252 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Fri, 24 Jan 2020 11:05:19 -0700 Subject: [PATCH] =?UTF-8?q?[7.x]=20Separate=20aliases=20used=20for=20tests?= =?UTF-8?q?=20in=20TimeSeriesLifecycleAc=E2=80=A6=20(#51432)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Separate aliases used for tests in TimeSeriesLifecycleActionsIT This is related to #51375 and hopes to help illuminate why some of those tests are failing. This commit switches the aliases used in the test to use a random alias name every time (since there were some complaints in the tests about aliases having more than one write index). With this we hope to determine the actual cause of the failure in the test. This also adds additional information to the exception returned when calling move-to-step with the incorrect current step. * Fix rest test --- .../ilm/TimeSeriesLifecycleActionsIT.java | 54 ++++++++++--------- .../test/ilm/20_move_to_step.yml | 2 +- .../xpack/ilm/IndexLifecycleTransition.java | 6 ++- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 0a8b3af9338..3eb7bd702be 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -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 { @@ -101,7 +103,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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); @@ -163,7 +165,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 @@ -243,7 +245,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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)); @@ -261,7 +263,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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" + @@ -276,7 +278,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { " {\n" + " \"add\": {\n" + " \"index\": \"" + originalIndex + "\",\n" + - " \"alias\": \"alias\",\n" + + " \"alias\": \"" + alias + "\",\n" + " \"is_write_index\": false\n" + " }\n" + " }\n" + @@ -785,7 +787,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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"); @@ -803,7 +805,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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); @@ -820,7 +822,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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")))); @@ -856,7 +858,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { .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")))); @@ -933,7 +935,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { } 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) ); @@ -992,7 +994,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 ); @@ -1027,7 +1029,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { " \"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); @@ -1045,7 +1047,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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" + @@ -1066,9 +1068,9 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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(); @@ -1088,7 +1090,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 ); @@ -1097,7 +1099,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 ); @@ -1160,7 +1162,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 ); @@ -1200,7 +1202,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { // 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" + @@ -1216,7 +1218,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 @@ -1258,7 +1260,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { " \"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); @@ -1411,7 +1413,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { " \"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); @@ -1593,7 +1595,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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); diff --git a/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml b/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml index 8b2c3ea0b53..ef5d1edeea3 100644 --- a/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml +++ b/x-pack/plugin/ilm/qa/rest/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml @@ -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: diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java index 0f6696b0be5..0f76cd1630e 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleTransition.java @@ -72,8 +72,10 @@ public final class IndexLifecycleTransition { } 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) {