diff --git a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java index faa8e6ef498..ad9064cf160 100644 --- a/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java +++ b/client/rest-high-level/src/test/java/org/elasticsearch/client/IndexLifecycleIT.java @@ -49,7 +49,6 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase { // TODO: NORELEASE convert this to using the high level client once there are APIs for it String jsonString = "{\n" + " \"policy\": {\n" + - " \"type\": \"timeseries\",\n" + " \"phases\": {\n" + " \"hot\": {\n" + " \"after\": \"60s\",\n" + @@ -110,14 +109,13 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase { assertThat(settingsResponse.getSetting("foo", "index.lifecycle.name"), equalTo(policy)); assertThat(settingsResponse.getSetting("baz", "index.lifecycle.name"), equalTo(policy)); } - + public void testStartStopILM() throws Exception { String policy = randomAlphaOfLength(10); // TODO: NORELEASE convert this to using the high level client once there are APIs for it String jsonString = "{\n" + " \"policy\": {\n" + - " \"type\": \"timeseries\",\n" + " \"phases\": {\n" + " \"hot\": {\n" + " \"actions\": {\n" + @@ -174,7 +172,7 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase { Response statusResponse = client().performRequest(statusReq); String statusResponseString = EntityUtils.toString(statusResponse.getEntity()); assertEquals("{\"operation_mode\":\"RUNNING\"}", statusResponseString); - + StopILMRequest stopReq = new StopILMRequest(); AcknowledgedResponse stopResponse = execute(stopReq, highLevelClient().indexLifecycle()::stopILM, highLevelClient().indexLifecycle()::stopILMAsync); @@ -186,7 +184,7 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase { statusResponseString = EntityUtils.toString(statusResponse.getEntity()); assertThat(statusResponseString, Matchers.anyOf(equalTo("{\"operation_mode\":\"STOPPING\"}"), equalTo("{\"operation_mode\":\"STOPPED\"}"))); - + StartILMRequest startReq = new StartILMRequest(); AcknowledgedResponse startResponse = execute(startReq, highLevelClient().indexLifecycle()::startILM, highLevelClient().indexLifecycle()::startILMAsync); @@ -205,7 +203,6 @@ public class IndexLifecycleIT extends ESRestHighLevelClientTestCase { // TODO: NORELEASE convert this to using the high level client once there are APIs for it String jsonString = "{\n" + " \"policy\": {\n" + - " \"type\": \"timeseries\",\n" + " \"phases\": {\n" + " \"hot\": {\n" + " \"actions\": {\n" + diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicy.java index 84cb1bb4189..e7b9301f47a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicy.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.xcontent.ConstructingObjectParser; -import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.common.xcontent.ToXContentObject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; @@ -45,19 +44,15 @@ public class LifecyclePolicy extends AbstractDiffable private static final Logger logger = ESLoggerFactory.getLogger(LifecyclePolicy.class); public static final ParseField PHASES_FIELD = new ParseField("phases"); - public static final ParseField TYPE_FIELD = new ParseField("type"); @SuppressWarnings("unchecked") public static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("lifecycle_policy", false, (a, name) -> { - LifecycleType type = (LifecycleType) a[0]; - List phases = (List) a[1]; + List phases = (List) a[0]; Map phaseMap = phases.stream().collect(Collectors.toMap(Phase::getName, Function.identity())); - return new LifecyclePolicy(type, name, phaseMap); + return new LifecyclePolicy(TimeseriesLifecycleType.INSTANCE, name, phaseMap); }); static { - PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), (p, c) -> p.namedObject(LifecycleType.class, p.text(), null), - TYPE_FIELD, ValueType.STRING); PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> Phase.parse(p, n), v -> { throw new IllegalArgumentException("ordered " + PHASES_FIELD.getPreferredName() + " are not supported"); }, PHASES_FIELD); @@ -74,15 +69,8 @@ public class LifecyclePolicy extends AbstractDiffable * a {@link Map} of {@link Phase}s which make up this * {@link LifecyclePolicy}. */ - public LifecyclePolicy(LifecycleType type, String name, Map phases) { - if (type == null) { - this.type = TimeseriesLifecycleType.INSTANCE; - } else { - this.type = type; - } - this.name = name; - this.phases = phases; - this.type.validate(phases.values()); + public LifecyclePolicy(String name, Map phases) { + this(TimeseriesLifecycleType.INSTANCE, name, phases); } /** @@ -94,6 +82,21 @@ public class LifecyclePolicy extends AbstractDiffable phases = Collections.unmodifiableMap(in.readMap(StreamInput::readString, Phase::new)); } + /** + * @param type + * the {@link LifecycleType} of the policy + * @param name + * the name of this {@link LifecyclePolicy} + * @param phases + * a {@link Map} of {@link Phase}s which make up this + * {@link LifecyclePolicy}. + */ + LifecyclePolicy(LifecycleType type, String name, Map phases) { + this.name = name; + this.phases = phases; + this.type = type; + this.type.validate(phases.values()); + } public static LifecyclePolicy parse(XContentParser parser, String name) { return PARSER.apply(parser, name); } @@ -130,7 +133,6 @@ public class LifecyclePolicy extends AbstractDiffable @Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(); - builder.field(TYPE_FIELD.getPreferredName(), type.getWriteableName()); builder.startObject(PHASES_FIELD.getPreferredName()); for (Phase phase : phases.values()) { builder.field(phase.getName(), phase); @@ -183,7 +185,7 @@ public class LifecyclePolicy extends AbstractDiffable // add `after` step for phase before next if (phase != null) { - // after step should have the name of the previous phase since the index is still in the + // after step should have the name of the previous phase since the index is still in the // previous phase until the after condition is reached Step.StepKey afterStepKey = new Step.StepKey(previousPhase.getName(), PhaseAfterStep.NAME, PhaseAfterStep.NAME); Step phaseAfterStep = new PhaseAfterStep(nowSupplier, phase.getAfter(), afterStepKey, lastStepKey); @@ -278,7 +280,7 @@ public class LifecyclePolicy extends AbstractDiffable } } } - + private StepKey getNextAfterStep(String currentPhaseName) { String nextPhaseName = type.getNextPhaseName(currentPhaseName, phases); if (nextPhaseName == null) { @@ -335,7 +337,7 @@ public class LifecyclePolicy extends AbstractDiffable return false; } LifecyclePolicy other = (LifecyclePolicy) obj; - return Objects.equals(name, other.name) && + return Objects.equals(name, other.name) && Objects.equals(phases, other.phases); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadata.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadata.java index ce3071147ae..ca2c5f1a535 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadata.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadata.java @@ -28,10 +28,13 @@ public class LifecyclePolicyMetadata extends AbstractDiffable PARSER = new ConstructingObjectParser<>("policy_metadata", - a -> new LifecyclePolicyMetadata((LifecyclePolicy) a[0], (Map) a[1])); + a -> { + LifecyclePolicy policy = (LifecyclePolicy) a[0]; + return new LifecyclePolicyMetadata(policy, (Map) a[1]); + }); static { - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> LifecyclePolicy.parse(p, c), POLICY); - PARSER.declareField(ConstructingObjectParser.constructorArg(), p -> p.mapStrings(), HEADERS, ValueType.OBJECT); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), LifecyclePolicy::parse, POLICY); + PARSER.declareField(ConstructingObjectParser.constructorArg(), XContentParser::mapStrings, HEADERS, ValueType.OBJECT); } public static LifecyclePolicyMetadata parse(XContentParser parser, String name) { @@ -40,12 +43,12 @@ public class LifecyclePolicyMetadata extends AbstractDiffable headers; - + public LifecyclePolicyMetadata(LifecyclePolicy policy, Map headers) { this.policy = policy; this.headers = headers; } - + @SuppressWarnings("unchecked") public LifecyclePolicyMetadata(StreamInput in) throws IOException { this.policy = new LifecyclePolicy(in); @@ -55,11 +58,11 @@ public class LifecyclePolicyMetadata extends AbstractDiffable getHeaders() { return headers; } - + public LifecyclePolicy getPolicy() { return policy; } - + public String getName() { return policy.getName(); } @@ -78,12 +81,12 @@ public class LifecyclePolicyMetadata extends AbstractDiffable { private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("put_lifecycle_request", a -> new Request((LifecyclePolicy) a[0])); static { - PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, name) -> LifecyclePolicy.parse(p, name), POLICY_FIELD); + PARSER.declareObject(ConstructingObjectParser.constructorArg(), LifecyclePolicy::parse, POLICY_FIELD); } private LifecyclePolicy policy; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadataTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadataTests.java index 1ace62dc26a..71118c62549 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadataTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyMetadataTests.java @@ -34,16 +34,32 @@ public class LifecyclePolicyMetadataTests extends AbstractSerializingTestCase
  • TestLifecycleType.INSTANCE))); + Arrays.asList( + new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new), + new NamedWriteableRegistry.Entry(LifecycleType.class, TimeseriesLifecycleType.TYPE, + (in) -> TimeseriesLifecycleType.INSTANCE), + new NamedWriteableRegistry.Entry(LifecycleAction.class, AllocateAction.NAME, AllocateAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ForceMergeAction.NAME, ForceMergeAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ReadOnlyAction.NAME, ReadOnlyAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, RolloverAction.NAME, RolloverAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ShrinkAction.NAME, ShrinkAction::new) + )); } @Override protected NamedXContentRegistry xContentRegistry() { List entries = new ArrayList<>(ClusterModule.getNamedXWriteables()); - entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(MockAction.NAME), MockAction::parse)); - entries.add(new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TestLifecycleType.TYPE), - (p) -> TestLifecycleType.INSTANCE)); + entries.addAll(Arrays.asList( + new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TimeseriesLifecycleType.TYPE), + (p) -> TimeseriesLifecycleType.INSTANCE), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(AllocateAction.NAME), AllocateAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse) + )); return new NamedXContentRegistry(entries); } @@ -59,7 +75,7 @@ public class LifecyclePolicyMetadataTests extends AbstractSerializingTestCase
  • headers = instance.getHeaders(); switch (between(0, 1)) { case 0: - policy = new LifecyclePolicy(TestLifecycleType.INSTANCE, policy.getName() + randomAlphaOfLengthBetween(1, 5), + policy = new LifecyclePolicy(TimeseriesLifecycleType.INSTANCE, policy.getName() + randomAlphaOfLengthBetween(1, 5), policy.getPhases()); break; case 1: diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTests.java index 21ca838fa4e..f739d7b5f71 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTests.java @@ -50,7 +50,6 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase TimeseriesLifecycleType.INSTANCE), new NamedWriteableRegistry.Entry(LifecycleAction.class, AllocateAction.NAME, AllocateAction::new), @@ -154,14 +153,14 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase randomFrom(TimeseriesLifecycleType.VALID_PHASES)); phases = new LinkedHashMap<>(phases); - String phaseName = randomAlphaOfLengthBetween(1, 10); phases.put(phaseName, new Phase(phaseName, TimeValue.timeValueSeconds(randomIntBetween(1, 1000)), Collections.emptyMap())); break; default: throw new AssertionError("Illegal randomisation branch"); } - return new LifecyclePolicy(TestLifecycleType.INSTANCE, name, phases); + return new LifecyclePolicy(TimeseriesLifecycleType.INSTANCE, name, phases); } @Override @@ -169,11 +168,6 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase 0L; diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetLifecycleResponseTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetLifecycleResponseTests.java index 74a225cb8c8..63d963d59da 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetLifecycleResponseTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/GetLifecycleResponseTests.java @@ -7,26 +7,27 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.test.AbstractStreamableTestCase; -import org.elasticsearch.xpack.core.indexlifecycle.DeleteAction; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType; +import org.elasticsearch.xpack.core.indexlifecycle.MockAction; import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; import org.elasticsearch.xpack.core.indexlifecycle.action.GetLifecycleAction.Response; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTests.randomTestLifecyclePolicy; + public class GetLifecycleResponseTests extends AbstractStreamableTestCase { - + @Override protected Response createTestInstance() { String randomPrefix = randomAlphaOfLength(5); List policies = new ArrayList<>(); for (int i = 0; i < randomIntBetween(0, 2); i++) { - policies.add(new LifecyclePolicy(TestLifecycleType.INSTANCE, randomPrefix + i, Collections.emptyMap())); + policies.add(randomTestLifecyclePolicy(randomPrefix + i)); } return new Response(policies); } @@ -38,7 +39,7 @@ public class GetLifecycleResponseTests extends AbstractStreamableTestCase TestLifecycleType.INSTANCE))); } @@ -47,12 +48,12 @@ public class GetLifecycleResponseTests extends AbstractStreamableTestCase policies = new ArrayList<>(response.getPolicies()); if (policies.size() > 0) { if (randomBoolean()) { - policies.add(new LifecyclePolicy(TestLifecycleType.INSTANCE, randomAlphaOfLength(2), Collections.emptyMap())); + policies.add(randomTestLifecyclePolicy(randomAlphaOfLength(5))); } else { policies.remove(policies.size() - 1); } } else { - policies.add(new LifecyclePolicy(TestLifecycleType.INSTANCE, randomAlphaOfLength(2), Collections.emptyMap())); + policies.add(randomTestLifecyclePolicy(randomAlphaOfLength(2))); } return new Response(policies); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutLifecycleRequestTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutLifecycleRequestTests.java index f4cd9686bc7..5df60a73331 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutLifecycleRequestTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/action/PutLifecycleRequestTests.java @@ -8,28 +8,29 @@ package org.elasticsearch.xpack.core.indexlifecycle.action; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; -import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.test.AbstractStreamableXContentTestCase; +import org.elasticsearch.xpack.core.indexlifecycle.AllocateAction; import org.elasticsearch.xpack.core.indexlifecycle.DeleteAction; +import org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; +import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTests; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType; -import org.elasticsearch.xpack.core.indexlifecycle.Phase; -import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; +import org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction; +import org.elasticsearch.xpack.core.indexlifecycle.RolloverAction; +import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction; +import org.elasticsearch.xpack.core.indexlifecycle.TimeseriesLifecycleType; import org.elasticsearch.xpack.core.indexlifecycle.action.PutLifecycleAction.Request; import org.junit.Before; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase { - + private String lifecycleName; @Before @@ -39,7 +40,7 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase @Override protected Request createTestInstance() { - return new Request(new LifecyclePolicy(TestLifecycleType.INSTANCE, lifecycleName, Collections.emptyMap())); + return new Request(LifecyclePolicyTests.randomTimeseriesLifecyclePolicy(lifecycleName)); } @Override @@ -52,18 +53,34 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase return PutLifecycleAction.Request.parseRequest(lifecycleName, parser); } + @Override protected NamedWriteableRegistry getNamedWriteableRegistry() { return new NamedWriteableRegistry( - Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new), - new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, in -> TestLifecycleType.INSTANCE))); + Arrays.asList( + new NamedWriteableRegistry.Entry(LifecycleType.class, TimeseriesLifecycleType.TYPE, + (in) -> TimeseriesLifecycleType.INSTANCE), + new NamedWriteableRegistry.Entry(LifecycleAction.class, AllocateAction.NAME, AllocateAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ForceMergeAction.NAME, ForceMergeAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ReadOnlyAction.NAME, ReadOnlyAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, RolloverAction.NAME, RolloverAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ShrinkAction.NAME, ShrinkAction::new) + )); } @Override protected NamedXContentRegistry xContentRegistry() { List entries = new ArrayList<>(ClusterModule.getNamedXWriteables()); - entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse)); - entries.add(new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TestLifecycleType.TYPE), - (p) -> TestLifecycleType.INSTANCE)); + entries.addAll(Arrays.asList( + new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TimeseriesLifecycleType.TYPE), + (p) -> TimeseriesLifecycleType.INSTANCE), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(AllocateAction.NAME), AllocateAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse) + )); return new NamedXContentRegistry(entries); } @@ -73,23 +90,10 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase @Override protected Request mutateInstance(Request request) { - LifecyclePolicy policy = request.getPolicy(); - String name = policy.getName(); - Map phases = policy.getPhases(); - switch (between(0, 1)) { - case 0: - name = name + randomAlphaOfLengthBetween(1, 5); - break; - case 1: - phases = new HashMap<>(phases); - String newPhaseName = randomAlphaOfLengthBetween(1, 10); - phases.put(name, new Phase(newPhaseName, TimeValue.timeValueSeconds(randomIntBetween(1, 1000)), - Collections.emptyMap())); - break; - default: - throw new AssertionError("Illegal randomisation branch"); - } - return new Request(new LifecyclePolicy(TestLifecycleType.INSTANCE, name, phases)); + String name = randomBoolean() ? lifecycleName : randomAlphaOfLength(5); + LifecyclePolicy policy = randomValueOtherThan(request.getPolicy(), + () -> LifecyclePolicyTests.randomTimeseriesLifecyclePolicy(name)); + return new Request(policy); } } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTestsUtils.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTestsUtils.java new file mode 100644 index 00000000000..3776363cf17 --- /dev/null +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/LifecyclePolicyTestsUtils.java @@ -0,0 +1,31 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ +package org.elasticsearch.xpack.core.indexlifecycle; + +import org.elasticsearch.xpack.indexlifecycle.LockableLifecycleType; + +import java.util.Map; + +/** + * This class is here for constructing instances of {@link LifecyclePolicy} that differs from + * the main {@link TimeseriesLifecycleType} one. Since the more generic constructor is package-private so + * that users are not exposed to {@link LifecycleType}, it is still useful to construct different ones for + * testing purposes + */ +public class LifecyclePolicyTestsUtils { + + public static LifecyclePolicy newTestLifecyclePolicy(String policyName, Map phases) { + return new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, phases); + } + + public static LifecyclePolicy newLockableLifecyclePolicy(String policyName, Map phases) { + return new LifecyclePolicy(LockableLifecycleType.INSTANCE, policyName, phases); + } + + public static LifecyclePolicy randomTimeseriesLifecyclePolicy(String policyName) { + return LifecyclePolicyTests.randomTimeseriesLifecyclePolicy(policyName); + } +} diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java index 56100d145ec..dcc88988184 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/ExecuteStepsUpdateTaskTests.java @@ -32,7 +32,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.Phase; import org.elasticsearch.xpack.core.indexlifecycle.Step; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep; -import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunnerTests.MockClusterStateActionStep; import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleRunnerTests.MockClusterStateWaitStep; import org.junit.Before; @@ -44,6 +43,7 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.sameInstance; @@ -84,11 +84,11 @@ public class ExecuteStepsUpdateTaskTests extends ESTestCase { new MockAction(Arrays.asList(firstStep, allClusterSecondStep)))); Phase invalidPhase = new Phase("invalid_phase", TimeValue.ZERO, Collections.singletonMap(MockAction.NAME, new MockAction(Arrays.asList(new MockClusterStateActionStep(firstStepKey, invalidStepKey))))); - LifecyclePolicy mixedPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, mixedPolicyName, + LifecyclePolicy mixedPolicy = newTestLifecyclePolicy(mixedPolicyName, Collections.singletonMap(mixedPhase.getName(), mixedPhase)); - LifecyclePolicy allClusterPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, allClusterPolicyName, + LifecyclePolicy allClusterPolicy = newTestLifecyclePolicy(allClusterPolicyName, Collections.singletonMap(allClusterPhase.getName(), allClusterPhase)); - LifecyclePolicy invalidPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, invalidPolicyName, + LifecyclePolicy invalidPolicy = newTestLifecyclePolicy(invalidPolicyName, Collections.singletonMap(invalidPhase.getName(), invalidPhase)); Map policyMap = new HashMap<>(); policyMap.put(mixedPolicyName, new LifecyclePolicyMetadata(mixedPolicy, Collections.emptyMap())); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationIT.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationIT.java index a29137d3577..74b9e27ada3 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationIT.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleInitialisationIT.java @@ -52,6 +52,7 @@ import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF import static org.elasticsearch.cluster.metadata.IndexMetaData.SETTING_NUMBER_OF_SHARDS; import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newLockableLifecyclePolicy; import static org.hamcrest.CoreMatchers.not; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.core.IsNull.nullValue; @@ -112,7 +113,7 @@ public class IndexLifecycleInitialisationIT extends ESIntegTestCase { steps.add(new ObservableClusterStateWaitStep(key, TerminalPolicyStep.KEY)); Map actions = Collections.singletonMap(ObservableAction.NAME, new ObservableAction(steps, true)); Map phases = Collections.singletonMap("mock", new Phase("mock", TimeValue.timeValueSeconds(0), actions)); - lifecyclePolicy = new LifecyclePolicy(LockableLifecycleType.INSTANCE, "test", phases); + lifecyclePolicy = newLockableLifecyclePolicy("test", phases); } public void testSingleNodeCluster() throws Exception { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java index db4e1bd3a43..978b75c96a3 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleMetadataTests.java @@ -18,7 +18,9 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.protocol.xpack.indexlifecycle.OperationMode; import org.elasticsearch.test.AbstractDiffableSerializationTestCase; +import org.elasticsearch.xpack.core.indexlifecycle.AllocateAction; import org.elasticsearch.xpack.core.indexlifecycle.DeleteAction; +import org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata; import org.elasticsearch.xpack.core.indexlifecycle.IndexLifecycleMetadata.IndexLifecycleMetadataDiff; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction; @@ -26,7 +28,10 @@ import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy; import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyMetadata; import org.elasticsearch.xpack.core.indexlifecycle.LifecycleType; import org.elasticsearch.xpack.core.indexlifecycle.Phase; -import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; +import org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction; +import org.elasticsearch.xpack.core.indexlifecycle.RolloverAction; +import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction; +import org.elasticsearch.xpack.core.indexlifecycle.TimeseriesLifecycleType; import java.io.IOException; import java.util.ArrayList; @@ -38,11 +43,20 @@ import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.randomTimeseriesLifecyclePolicy; + public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTestCase { @Override protected IndexLifecycleMetadata createTestInstance() { - return createTestInstance(randomInt(5), randomFrom(OperationMode.values())); + int numPolicies = randomIntBetween(1, 5); + Map policies = new HashMap<>(numPolicies); + for (int i = 0; i < numPolicies; i++) { + LifecyclePolicy policy = randomTimeseriesLifecyclePolicy(randomAlphaOfLength(4) + i); + policies.put(policy.getName(), new LifecyclePolicyMetadata(policy, Collections.emptyMap())); + } + return new IndexLifecycleMetadata(policies, randomFrom(OperationMode.values())); } @Override @@ -58,16 +72,31 @@ public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTe @Override protected NamedWriteableRegistry getNamedWriteableRegistry() { return new NamedWriteableRegistry( - Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new), - new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, (in) -> TestLifecycleType.INSTANCE))); + Arrays.asList( + new NamedWriteableRegistry.Entry(LifecycleType.class, TimeseriesLifecycleType.TYPE, + (in) -> TimeseriesLifecycleType.INSTANCE), + new NamedWriteableRegistry.Entry(LifecycleAction.class, AllocateAction.NAME, AllocateAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ForceMergeAction.NAME, ForceMergeAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ReadOnlyAction.NAME, ReadOnlyAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, RolloverAction.NAME, RolloverAction::new), + new NamedWriteableRegistry.Entry(LifecycleAction.class, ShrinkAction.NAME, ShrinkAction::new) + )); } @Override protected NamedXContentRegistry xContentRegistry() { List entries = new ArrayList<>(ClusterModule.getNamedXWriteables()); - entries.add(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse)); - entries.add(new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TestLifecycleType.TYPE), - (p) -> TestLifecycleType.INSTANCE)); + entries.addAll(Arrays.asList( + new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TimeseriesLifecycleType.TYPE), + (p) -> TimeseriesLifecycleType.INSTANCE), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(AllocateAction.NAME), AllocateAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ForceMergeAction.NAME), ForceMergeAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ReadOnlyAction.NAME), ReadOnlyAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(RolloverAction.NAME), RolloverAction::parse), + new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(ShrinkAction.NAME), ShrinkAction::parse) + )); return new NamedXContentRegistry(entries); } @@ -79,8 +108,7 @@ public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTe OperationMode mode = metadata.getOperationMode(); if (randomBoolean()) { String policyName = randomAlphaOfLength(10); - policies.put(policyName, new LifecyclePolicyMetadata( - new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, Collections.emptyMap()), Collections.emptyMap())); + policies.put(policyName, new LifecyclePolicyMetadata(randomTimeseriesLifecyclePolicy(policyName), Collections.emptyMap())); } else { mode = randomValueOtherThan(metadata.getOperationMode(), () -> randomFrom(OperationMode.values())); } @@ -120,8 +148,7 @@ public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTe phases.put(phaseName, new Phase(phaseName, after, actions)); } String policyName = randomAlphaOfLength(10); - policies.put(policyName, new LifecyclePolicyMetadata(new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, phases), - Collections.emptyMap())); + policies.put(policyName, new LifecyclePolicyMetadata(newTestLifecyclePolicy(policyName, phases), Collections.emptyMap())); } return new IndexLifecycleMetadata(policies, mode); } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java index 70f1c469bbd..603b13fca4c 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleRunnerTests.java @@ -42,7 +42,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.RolloverAction; import org.elasticsearch.xpack.core.indexlifecycle.Step; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep; -import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; import org.mockito.ArgumentMatcher; import org.mockito.Mockito; @@ -57,6 +56,7 @@ import java.util.SortedMap; import java.util.function.Function; import java.util.stream.Collectors; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Mockito.mock; @@ -863,7 +863,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { long now = randomNonNegativeLong(); String indexName = randomAlphaOfLength(10); String newPolicyName = "new_policy"; - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); StepKey currentStep = new StepKey("", "", ""); Settings.Builder indexSettingsBuilder = Settings.builder(); ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, Collections.emptyList()); @@ -883,8 +883,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy oldPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, oldPolicyName, Collections.emptyMap()); - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); StepKey currentStep = AbstractStepTestCase.randomStepKey(); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) .put(LifecycleSettings.LIFECYCLE_PHASE, currentStep.getPhase()) @@ -910,7 +910,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = new LifecyclePolicy(newPolicyName, Collections.emptyMap()); StepKey currentStep = new StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); LifecyclePolicy oldPolicy = createPolicy(oldPolicyName, null, currentStep); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) @@ -976,7 +976,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { actions.put(unsafeAction.getWriteableName(), unsafeAction); Phase phase = new Phase(currentStep.getPhase(), TimeValue.timeValueMillis(0), actions); phases.put(phase.getName(), phase); - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, phases); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, phases); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) .put(LifecycleSettings.LIFECYCLE_PHASE, currentStep.getPhase()) @@ -1019,15 +1019,14 @@ public class IndexLifecycleRunnerTests extends ESTestCase { Phase phase = new Phase(unsafeStep.getPhase(), TimeValue.timeValueMillis(0), actions); phases.put(phase.getName(), phase); } - LifecyclePolicy oldPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, phases); - return oldPolicy; + return newTestLifecyclePolicy(policyName, phases); } public void testCanUpdatePolicy() { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); StepKey currentStep = new StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); LifecyclePolicy oldPolicy = createPolicy(oldPolicyName, currentStep, null); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) @@ -1047,7 +1046,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); StepKey currentStep = new StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); LifecyclePolicy oldPolicy = createPolicy(oldPolicyName, null, currentStep); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) @@ -1101,7 +1100,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { actions.put(unsafeAction.getWriteableName(), unsafeAction); Phase phase = new Phase(currentStep.getPhase(), TimeValue.timeValueMillis(0), actions); phases.put(phase.getName(), phase); - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, phases); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, phases); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) .put(LifecycleSettings.LIFECYCLE_PHASE, currentStep.getPhase()) @@ -1120,8 +1119,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy oldPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, oldPolicyName, Collections.emptyMap()); - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); Settings.Builder indexSettingsBuilder = Settings.builder(); List policyMetadatas = new ArrayList<>(); policyMetadatas.add(new LifecyclePolicyMetadata(oldPolicy, Collections.emptyMap())); @@ -1136,8 +1135,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy oldPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, oldPolicyName, Collections.emptyMap()); - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); StepKey currentStep = new StepKey(randomAlphaOfLength(10), ShrinkAction.NAME, randomAlphaOfLength(10)); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, "different_policy") .put(LifecycleSettings.LIFECYCLE_PHASE, currentStep.getPhase()) @@ -1155,7 +1154,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { public void testCanUpdatePolicyMultipleIndexesUpdateAllowed() { String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); String index1Name = randomAlphaOfLength(10); StepKey currentStep1 = new StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); @@ -1208,7 +1207,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { public void testCanUpdatePolicyMultipleIndexesUpdateForbidden() { String oldPolicyName = "old_policy"; String newPolicyName = "new_policy"; - LifecyclePolicy newPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, newPolicyName, Collections.emptyMap()); + LifecyclePolicy newPolicy = newTestLifecyclePolicy(newPolicyName, Collections.emptyMap()); String index1Name = randomAlphaOfLength(10); StepKey currentStep1 = new StepKey(randomAlphaOfLength(10), MockAction.NAME, randomAlphaOfLength(10)); @@ -1297,7 +1296,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase { public void testRemovePolicyForIndexIndexDoesntExist() { String indexName = randomAlphaOfLength(10); String oldPolicyName = "old_policy"; - LifecyclePolicy oldPolicy = new LifecyclePolicy(TestLifecycleType.INSTANCE, oldPolicyName, Collections.emptyMap()); + LifecyclePolicy oldPolicy = newTestLifecyclePolicy(oldPolicyName, Collections.emptyMap()); StepKey currentStep = AbstractStepTestCase.randomStepKey(); Settings.Builder indexSettingsBuilder = Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, oldPolicyName) .put(LifecycleSettings.LIFECYCLE_PHASE, currentStep.getPhase()) diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java index 2d58afa0159..bba4acd92d0 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/IndexLifecycleServiceTests.java @@ -34,7 +34,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.MockAction; import org.elasticsearch.xpack.core.indexlifecycle.Phase; import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction; import org.elasticsearch.xpack.core.indexlifecycle.Step; -import org.elasticsearch.xpack.core.indexlifecycle.TestLifecycleType; import org.elasticsearch.xpack.core.scheduler.SchedulerEngine; import org.junit.After; import org.junit.Before; @@ -51,6 +50,7 @@ import java.util.concurrent.ExecutorService; import static org.elasticsearch.node.Node.NODE_MASTER_SETTING; import static org.elasticsearch.xpack.core.indexlifecycle.AbstractStepTestCase.randomStepKey; +import static org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicyTestsUtils.newTestLifecyclePolicy; import static org.hamcrest.Matchers.equalTo; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; @@ -284,8 +284,7 @@ public class IndexLifecycleServiceTests extends ESTestCase { new IndexLifecycleRunnerTests.MockClusterStateActionStep(randomStepKey(), randomStepKey()); MockAction mockAction = new MockAction(Collections.singletonList(mockStep)); Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction)); - LifecyclePolicy policy = new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, - Collections.singletonMap(phase.getName(), phase)); + LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase)); SortedMap policyMap = new TreeMap<>(); policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Collections.emptyMap())); Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); @@ -314,8 +313,7 @@ public class IndexLifecycleServiceTests extends ESTestCase { new IndexLifecycleRunnerTests.MockClusterStateActionStep(mockShrinkStep, randomStepKey()); MockAction mockAction = new MockAction(Collections.singletonList(mockStep)); Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction)); - LifecyclePolicy policy = new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, - Collections.singletonMap(phase.getName(), phase)); + LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase)); SortedMap policyMap = new TreeMap<>(); policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Collections.emptyMap())); Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); @@ -355,8 +353,7 @@ public class IndexLifecycleServiceTests extends ESTestCase { new IndexLifecycleRunnerTests.MockClusterStateActionStep(currentStepKey, randomStepKey()); MockAction mockAction = new MockAction(Collections.singletonList(mockStep)); Phase phase = new Phase("phase", TimeValue.ZERO, Collections.singletonMap("action", mockAction)); - LifecyclePolicy policy = new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, - Collections.singletonMap(phase.getName(), phase)); + LifecyclePolicy policy = newTestLifecyclePolicy(policyName, Collections.singletonMap(phase.getName(), phase)); SortedMap policyMap = new TreeMap<>(); policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Collections.emptyMap())); Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20)); diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java index dde30ca54e7..30737168c1f 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java @@ -27,7 +27,6 @@ import org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction; import org.elasticsearch.xpack.core.indexlifecycle.ShrinkAction; import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; import org.elasticsearch.xpack.core.indexlifecycle.TerminalPolicyStep; -import org.elasticsearch.xpack.core.indexlifecycle.TimeseriesLifecycleType; import org.junit.Before; import java.io.IOException; @@ -172,8 +171,7 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase { private void createNewSingletonPolicy(String phaseName, LifecycleAction action) throws IOException { Phase phase = new Phase(phaseName, TimeValue.ZERO, singletonMap(action.getWriteableName(), action)); - LifecyclePolicy lifecyclePolicy = - new LifecyclePolicy(TimeseriesLifecycleType.INSTANCE, policy, singletonMap(phase.getName(), phase)); + LifecyclePolicy lifecyclePolicy = new LifecyclePolicy(policy, singletonMap(phase.getName(), phase)); XContentBuilder builder = jsonBuilder(); lifecyclePolicy.toXContent(builder, null); final StringEntity entity = new StringEntity( diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/10_basic.yml index 8d7d4955c1c..85f44549d80 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/10_basic.yml @@ -23,7 +23,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "10s", @@ -47,7 +46,6 @@ setup: acknowledge: true ilm.get_lifecycle: lifecycle: "my_timeseries_lifecycle" - - match: { my_timeseries_lifecycle.type: "timeseries" } - match: { my_timeseries_lifecycle.phases.warm.after: "10s" } - match: { my_timeseries_lifecycle.phases.delete.after: "30s" } @@ -70,7 +68,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "10s", @@ -94,7 +91,6 @@ setup: acknowledge: true ilm.get_lifecycle: lifecycle: "my_timeseries_lifecycle" - - match: { my_timeseries_lifecycle.type: "timeseries" } - match: { my_timeseries_lifecycle.phases.warm.after: "10s" } - match: { my_timeseries_lifecycle.phases.delete.after: "30s" } @@ -120,7 +116,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "300s", @@ -144,7 +139,6 @@ setup: acknowledge: true ilm.get_lifecycle: lifecycle: "my_timeseries_lifecycle" - - match: { my_timeseries_lifecycle.type: "timeseries" } - match: { my_timeseries_lifecycle.phases.warm.after: "300s" } - match: { my_timeseries_lifecycle.phases.delete.after: "600s" } @@ -176,7 +170,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "10s", @@ -200,7 +193,6 @@ setup: acknowledge: true ilm.get_lifecycle: lifecycle: "my_timeseries_lifecycle" - - match: { my_timeseries_lifecycle.type: "timeseries" } - match: { my_timeseries_lifecycle.phases.warm.after: "10s" } - match: { my_timeseries_lifecycle.phases.delete.after: "30s" } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml index b05bd3a96b9..ac1afd9b968 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/20_move_to_step.yml @@ -10,7 +10,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s", diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/30_retry.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/30_retry.yml index 93e43e18b94..eeae6b05b04 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/30_retry.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/30_retry.yml @@ -11,7 +11,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s", diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml index 395aa33cec4..269dee13327 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/40_explain_lifecycle.yml @@ -10,7 +10,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s", diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/50_set_policy_for_index.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/50_set_policy_for_index.yml index d5c1bc1f88f..cd012e9afef 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/50_set_policy_for_index.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/50_set_policy_for_index.yml @@ -10,7 +10,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s", @@ -40,7 +39,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s", diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_operation_mode.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_operation_mode.yml index 9c4a9ce0745..6ef1bf0d859 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_operation_mode.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_operation_mode.yml @@ -17,7 +17,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "10s", diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_remove_policy_for_index.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_remove_policy_for_index.yml index f61b0289964..97ab6406324 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_remove_policy_for_index.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ilm/60_remove_policy_for_index.yml @@ -10,7 +10,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s", @@ -40,7 +39,6 @@ setup: body: | { "policy": { - "type": "timeseries", "phases": { "warm": { "after": "1000s",