remove `type` config from LifecyclePolicy JSON (#32660)

Since there is only one production policy, Timeseries, there
is no reason to expose the `type` argument to the user.
This commit is contained in:
Tal Levy 2018-08-15 14:47:22 -07:00 committed by GitHub
parent d1ab5dd650
commit 4baa721459
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 203 additions and 149 deletions

View File

@ -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" +

View File

@ -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<LifecyclePolicy>
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<LifecyclePolicy, String> PARSER = new ConstructingObjectParser<>("lifecycle_policy", false,
(a, name) -> {
LifecycleType type = (LifecycleType) a[0];
List<Phase> phases = (List<Phase>) a[1];
List<Phase> phases = (List<Phase>) a[0];
Map<String, Phase> 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<LifecyclePolicy>
* a {@link Map} of {@link Phase}s which make up this
* {@link LifecyclePolicy}.
*/
public LifecyclePolicy(LifecycleType type, String name, Map<String, Phase> 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<String, Phase> phases) {
this(TimeseriesLifecycleType.INSTANCE, name, phases);
}
/**
@ -94,6 +82,21 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy>
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<String, Phase> 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<LifecyclePolicy>
@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<LifecyclePolicy>
// 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<LifecyclePolicy>
}
}
}
private StepKey getNextAfterStep(String currentPhaseName) {
String nextPhaseName = type.getNextPhaseName(currentPhaseName, phases);
if (nextPhaseName == null) {
@ -335,7 +337,7 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy>
return false;
}
LifecyclePolicy other = (LifecyclePolicy) obj;
return Objects.equals(name, other.name) &&
return Objects.equals(name, other.name) &&
Objects.equals(phases, other.phases);
}

View File

@ -28,10 +28,13 @@ public class LifecyclePolicyMetadata extends AbstractDiffable<LifecyclePolicyMet
public static final ParseField HEADERS = new ParseField("headers");
@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<LifecyclePolicyMetadata, String> PARSER = new ConstructingObjectParser<>("policy_metadata",
a -> new LifecyclePolicyMetadata((LifecyclePolicy) a[0], (Map<String, String>) a[1]));
a -> {
LifecyclePolicy policy = (LifecyclePolicy) a[0];
return new LifecyclePolicyMetadata(policy, (Map<String, String>) 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<LifecyclePolicyMet
private final LifecyclePolicy policy;
private final Map<String, String> headers;
public LifecyclePolicyMetadata(LifecyclePolicy policy, Map<String, String> 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<LifecyclePolicyMet
public Map<String, String> getHeaders() {
return headers;
}
public LifecyclePolicy getPolicy() {
return policy;
}
public String getName() {
return policy.getName();
}
@ -78,12 +81,12 @@ public class LifecyclePolicyMetadata extends AbstractDiffable<LifecyclePolicyMet
policy.writeTo(out);
out.writeGenericValue(headers);
}
@Override
public int hashCode() {
return Objects.hash(policy, headers);
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
@ -94,7 +97,7 @@ public class LifecyclePolicyMetadata extends AbstractDiffable<LifecyclePolicyMet
}
LifecyclePolicyMetadata other = (LifecyclePolicyMetadata) obj;
return Objects.equals(policy, other.policy) &&
Objects.equals(headers, other.headers);
Objects.equals(headers, other.headers);
}
}

View File

@ -51,7 +51,7 @@ public class PutLifecycleAction extends Action<PutLifecycleAction.Response> {
private static final ConstructingObjectParser<Request, String> 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;

View File

@ -34,16 +34,32 @@ public class LifecyclePolicyMetadataTests extends AbstractSerializingTestCase<Li
@Override
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(
Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new),
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, (in) -> 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<NamedXContentRegistry.Entry> 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<Li
for (int i = 0; i < numberHeaders; i++) {
headers.put(randomAlphaOfLength(10), randomAlphaOfLength(10));
}
return new LifecyclePolicyMetadata(LifecyclePolicyTests.randomTestLifecyclePolicy(lifecycleName), headers);
return new LifecyclePolicyMetadata(LifecyclePolicyTests.randomTimeseriesLifecyclePolicy(lifecycleName), headers);
}
@Override
@ -73,7 +89,7 @@ public class LifecyclePolicyMetadataTests extends AbstractSerializingTestCase<Li
Map<String, String> 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:

View File

@ -50,7 +50,6 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(
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),
@ -154,14 +153,14 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
name = name + randomAlphaOfLengthBetween(1, 5);
break;
case 1:
String phaseName = randomValueOtherThanMany(phases::containsKey, () -> 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<LifecycleP
return LifecyclePolicy::new;
}
public void testDefaultLifecycleType() {
LifecyclePolicy policy = new LifecyclePolicy(null, randomAlphaOfLength(10), Collections.emptyMap());
assertSame(TimeseriesLifecycleType.INSTANCE, policy.getType());
}
public void testFirstAndLastSteps() {
Client client = mock(Client.class);
LongSupplier nowSupplier = () -> 0L;

View File

@ -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<GetLifecycleAction.Response> {
@Override
protected Response createTestInstance() {
String randomPrefix = randomAlphaOfLength(5);
List<LifecyclePolicy> 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<GetLif
protected NamedWriteableRegistry getNamedWriteableRegistry() {
return new NamedWriteableRegistry(
Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new),
Arrays.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, MockAction.NAME, MockAction::new),
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, in -> TestLifecycleType.INSTANCE)));
}
@ -47,12 +48,12 @@ public class GetLifecycleResponseTests extends AbstractStreamableTestCase<GetLif
List<LifecyclePolicy> 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);
}

View File

@ -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<PutLifecycleAction.Request> {
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<NamedXContentRegistry.Entry> 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<String, Phase> 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);
}
}

View File

@ -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<String, Phase> phases) {
return new LifecyclePolicy(TestLifecycleType.INSTANCE, policyName, phases);
}
public static LifecyclePolicy newLockableLifecyclePolicy(String policyName, Map<String, Phase> phases) {
return new LifecyclePolicy(LockableLifecycleType.INSTANCE, policyName, phases);
}
public static LifecyclePolicy randomTimeseriesLifecyclePolicy(String policyName) {
return LifecyclePolicyTests.randomTimeseriesLifecyclePolicy(policyName);
}
}

View File

@ -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<String, LifecyclePolicyMetadata> policyMap = new HashMap<>();
policyMap.put(mixedPolicyName, new LifecyclePolicyMetadata(mixedPolicy, Collections.emptyMap()));

View File

@ -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<String, LifecycleAction> actions = Collections.singletonMap(ObservableAction.NAME, new ObservableAction(steps, true));
Map<String, Phase> 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 {

View File

@ -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<MetaData.Custom> {
@Override
protected IndexLifecycleMetadata createTestInstance() {
return createTestInstance(randomInt(5), randomFrom(OperationMode.values()));
int numPolicies = randomIntBetween(1, 5);
Map<String, LifecyclePolicyMetadata> 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<NamedXContentRegistry.Entry> 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);
}

View File

@ -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<LifecyclePolicyMetadata> 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())

View File

@ -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<String, LifecyclePolicyMetadata> 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<String, LifecyclePolicyMetadata> 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<String, LifecyclePolicyMetadata> policyMap = new TreeMap<>();
policyMap.put(policyName, new LifecyclePolicyMetadata(policy, Collections.emptyMap()));
Index index = new Index(randomAlphaOfLengthBetween(1, 20), randomAlphaOfLengthBetween(1, 20));

View File

@ -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(

View File

@ -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" }

View File

@ -10,7 +10,6 @@ setup:
body: |
{
"policy": {
"type": "timeseries",
"phases": {
"warm": {
"after": "1000s",

View File

@ -11,7 +11,6 @@ setup:
body: |
{
"policy": {
"type": "timeseries",
"phases": {
"warm": {
"after": "1000s",

View File

@ -10,7 +10,6 @@ setup:
body: |
{
"policy": {
"type": "timeseries",
"phases": {
"warm": {
"after": "1000s",

View File

@ -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",

View File

@ -17,7 +17,6 @@ setup:
body: |
{
"policy": {
"type": "timeseries",
"phases": {
"warm": {
"after": "10s",

View File

@ -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",