From 1bb7b53f267c715235faac04f64e82132ef81843 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Thu, 2 Aug 2018 09:51:08 -0600 Subject: [PATCH] Make index.lifecycle.name setting internal (#32518) This commit makes the `index.lifecycle.name` setting internal an index, this means that the policy can only be set on the index creation, or with the specialized `RestSetIndexLifecyclePolicy` action. Relates to #29823 --- .../core/indexlifecycle/LifecycleSettings.java | 2 +- .../TimeSeriesLifecycleActionsIT.java | 17 +++++++++++------ .../test/index_lifecycle/10_basic.yml | 4 +--- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java index 6d7fd01b008..4354c96325e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java @@ -29,7 +29,7 @@ public class LifecycleSettings { public static final Setting LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL, TimeValue.timeValueSeconds(3), Setting.Property.Dynamic, Setting.Property.NodeScope); public static final Setting 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 LIFECYCLE_PHASE_SETTING = Setting.simpleString(LIFECYCLE_PHASE, Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex); public static final Setting LIFECYCLE_ACTION_SETTING = Setting.simpleString(LIFECYCLE_ACTION, diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java index 593949c050e..a4ad7a820da 100644 --- a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java @@ -51,13 +51,18 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 settings = getOnlyIndexSettings(index); assertThat(getStepKey(settings), equalTo(TerminalPolicyStep.KEY)); @@ -69,7 +74,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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))); } @@ -77,7 +82,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 settings = getOnlyIndexSettings(index); assertThat(getStepKey(settings), equalTo(TerminalPolicyStep.KEY)); @@ -111,7 +116,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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)); @@ -126,7 +131,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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 settings = getOnlyIndexSettings(index); @@ -143,7 +148,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { 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)); diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml index c12c2ff6bc7..8527501713f 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml @@ -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