Use the XContentRegistry provided by the parser
This commit is contained in:
parent
c4621d9dc7
commit
57c343bc21
|
@ -10,12 +10,10 @@ import org.elasticsearch.cluster.AbstractDiffable;
|
||||||
import org.elasticsearch.cluster.Diffable;
|
import org.elasticsearch.cluster.Diffable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -48,18 +46,17 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy>
|
||||||
public static final ParseField TYPE_FIELD = new ParseField("type");
|
public static final ParseField TYPE_FIELD = new ParseField("type");
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static ConstructingObjectParser<LifecyclePolicy, Tuple<String, NamedXContentRegistry>> PARSER = new ConstructingObjectParser<>(
|
public static ConstructingObjectParser<LifecyclePolicy, String> PARSER = new ConstructingObjectParser<>("lifecycle_policy", false,
|
||||||
"lifecycle_policy", false, (a, c) -> {
|
(a, name) -> {
|
||||||
String name = c.v1();
|
|
||||||
LifecycleType type = (LifecycleType) a[0];
|
LifecycleType type = (LifecycleType) a[0];
|
||||||
List<Phase> phases = (List<Phase>) a[1];
|
List<Phase> phases = (List<Phase>) a[1];
|
||||||
Map<String, Phase> phaseMap = phases.stream().collect(Collectors.toMap(Phase::getName, Function.identity()));
|
Map<String, Phase> phaseMap = phases.stream().collect(Collectors.toMap(Phase::getName, Function.identity()));
|
||||||
return new LifecyclePolicy(type, name, phaseMap);
|
return new LifecyclePolicy(type, name, phaseMap);
|
||||||
});
|
});
|
||||||
static {
|
static {
|
||||||
PARSER.declareField(constructorArg(), (p, c) -> c.v2().parseNamedObject(LifecycleType.class, p.text(), p, null), TYPE_FIELD,
|
PARSER.declareField(constructorArg(), (p, c) -> p.namedObject(LifecycleType.class, p.text(), null), TYPE_FIELD,
|
||||||
ValueType.STRING);
|
ValueType.STRING);
|
||||||
PARSER.declareNamedObjects(constructorArg(), (p, c, n) -> Phase.parse(p, new Tuple<>(n, c.v2())), v -> {
|
PARSER.declareNamedObjects(constructorArg(), (p, c, n) -> Phase.parse(p, n), v -> {
|
||||||
throw new IllegalArgumentException("ordered " + PHASES_FIELD.getPreferredName() + " are not supported");
|
throw new IllegalArgumentException("ordered " + PHASES_FIELD.getPreferredName() + " are not supported");
|
||||||
}, PHASES_FIELD);
|
}, PHASES_FIELD);
|
||||||
}
|
}
|
||||||
|
@ -91,8 +88,8 @@ public class LifecyclePolicy extends AbstractDiffable<LifecyclePolicy>
|
||||||
phases = Collections.unmodifiableMap(in.readMap(StreamInput::readString, Phase::new));
|
phases = Collections.unmodifiableMap(in.readMap(StreamInput::readString, Phase::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LifecyclePolicy parse(XContentParser parser, Tuple<String, NamedXContentRegistry> context) {
|
public static LifecyclePolicy parse(XContentParser parser, String name) {
|
||||||
return PARSER.apply(parser, context);
|
return PARSER.apply(parser, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -8,14 +8,12 @@ package org.elasticsearch.xpack.indexlifecycle;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.Writeable;
|
import org.elasticsearch.common.io.stream.Writeable;
|
||||||
import org.elasticsearch.common.logging.ESLoggerFactory;
|
import org.elasticsearch.common.logging.ESLoggerFactory;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -43,20 +41,20 @@ public class Phase implements ToXContentObject, Writeable {
|
||||||
public static final ParseField ACTIONS_FIELD = new ParseField("actions");
|
public static final ParseField ACTIONS_FIELD = new ParseField("actions");
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static final ConstructingObjectParser<Phase, Tuple<String, NamedXContentRegistry>> PARSER = new ConstructingObjectParser<>(
|
private static final ConstructingObjectParser<Phase, String> PARSER = new ConstructingObjectParser<>("phase", false,
|
||||||
"phase", false, (a, c) -> new Phase(c.v1(), (TimeValue) a[0],
|
(a, name) -> new Phase(name, (TimeValue) a[0],
|
||||||
convertListToMapValues(LifecycleAction::getWriteableName, (List<LifecycleAction>) a[1])));
|
convertListToMapValues(LifecycleAction::getWriteableName, (List<LifecycleAction>) a[1])));
|
||||||
static {
|
static {
|
||||||
PARSER.declareField(ConstructingObjectParser.constructorArg(),
|
PARSER.declareField(ConstructingObjectParser.constructorArg(),
|
||||||
(p, c) -> TimeValue.parseTimeValue(p.text(), AFTER_FIELD.getPreferredName()), AFTER_FIELD, ValueType.VALUE);
|
(p, c) -> TimeValue.parseTimeValue(p.text(), AFTER_FIELD.getPreferredName()), AFTER_FIELD, ValueType.VALUE);
|
||||||
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(),
|
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(),
|
||||||
(p, c, n) -> c.v2().parseNamedObject(LifecycleAction.class, n, p, c.v2()), v -> {
|
(p, c, n) -> p.namedObject(LifecycleAction.class, n, null), v -> {
|
||||||
throw new IllegalArgumentException("ordered " + ACTIONS_FIELD.getPreferredName() + " are not supported");
|
throw new IllegalArgumentException("ordered " + ACTIONS_FIELD.getPreferredName() + " are not supported");
|
||||||
}, ACTIONS_FIELD);
|
}, ACTIONS_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Phase parse(XContentParser parser, Tuple<String, NamedXContentRegistry> context) {
|
public static Phase parse(XContentParser parser, String name) {
|
||||||
return PARSER.apply(parser, context);
|
return PARSER.apply(parser, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
|
|
@ -13,11 +13,9 @@ import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||||
import org.elasticsearch.client.ElasticsearchClient;
|
import org.elasticsearch.client.ElasticsearchClient;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
||||||
import org.elasticsearch.common.xcontent.ToXContentObject;
|
import org.elasticsearch.common.xcontent.ToXContentObject;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -106,10 +104,10 @@ public class PutLifecycleAction extends Action<PutLifecycleAction.Request, PutLi
|
||||||
public static class Request extends AcknowledgedRequest<Request> implements ToXContentObject {
|
public static class Request extends AcknowledgedRequest<Request> implements ToXContentObject {
|
||||||
|
|
||||||
public static final ParseField POLICY_FIELD = new ParseField("policy");
|
public static final ParseField POLICY_FIELD = new ParseField("policy");
|
||||||
private static final ConstructingObjectParser<Request, Tuple<String, NamedXContentRegistry>> PARSER =
|
private static final ConstructingObjectParser<Request, String> PARSER =
|
||||||
new ConstructingObjectParser<>("put_lifecycle_request", a -> new Request((LifecyclePolicy) a[0]));
|
new ConstructingObjectParser<>("put_lifecycle_request", a -> new Request((LifecyclePolicy) a[0]));
|
||||||
static {
|
static {
|
||||||
PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, c) -> LifecyclePolicy.parse(p, c), POLICY_FIELD);
|
PARSER.declareObject(ConstructingObjectParser.constructorArg(), (p, name) -> LifecyclePolicy.parse(p, name), POLICY_FIELD);
|
||||||
}
|
}
|
||||||
|
|
||||||
private LifecyclePolicy policy;
|
private LifecyclePolicy policy;
|
||||||
|
@ -130,8 +128,8 @@ public class PutLifecycleAction extends Action<PutLifecycleAction.Request, PutLi
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Request parseRequest(String name, XContentParser parser, NamedXContentRegistry namedXContentRegistry) {
|
public static Request parseRequest(String name, XContentParser parser) {
|
||||||
return PARSER.apply(parser, new Tuple<>(name, namedXContentRegistry));
|
return PARSER.apply(parser, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -14,11 +14,9 @@ import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -36,11 +34,11 @@ public class IndexLifecycleMetadata implements MetaData.Custom {
|
||||||
public static final ParseField POLICIES_FIELD = new ParseField("policies");
|
public static final ParseField POLICIES_FIELD = new ParseField("policies");
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static final ConstructingObjectParser<IndexLifecycleMetadata, NamedXContentRegistry> PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<IndexLifecycleMetadata, Void> PARSER = new ConstructingObjectParser<>(
|
||||||
TYPE, a -> new IndexLifecycleMetadata(
|
TYPE, a -> new IndexLifecycleMetadata(
|
||||||
ObjectParserUtils.convertListToMapValues(LifecyclePolicy::getName, (List<LifecyclePolicy>) a[0])));
|
ObjectParserUtils.convertListToMapValues(LifecyclePolicy::getName, (List<LifecyclePolicy>) a[0])));
|
||||||
static {
|
static {
|
||||||
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> LifecyclePolicy.parse(p, new Tuple<>(n, c)),
|
PARSER.declareNamedObjects(ConstructingObjectParser.constructorArg(), (p, c, n) -> LifecyclePolicy.parse(p, n),
|
||||||
v -> {
|
v -> {
|
||||||
throw new IllegalArgumentException("ordered " + POLICIES_FIELD.getPreferredName() + " are not supported");
|
throw new IllegalArgumentException("ordered " + POLICIES_FIELD.getPreferredName() + " are not supported");
|
||||||
}, POLICIES_FIELD);
|
}, POLICIES_FIELD);
|
||||||
|
|
|
@ -33,8 +33,7 @@ public class RestPutLifecycleAction extends BaseRestHandler {
|
||||||
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
|
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
|
||||||
String lifecycleName = restRequest.param("name");
|
String lifecycleName = restRequest.param("name");
|
||||||
XContentParser parser = restRequest.contentParser();
|
XContentParser parser = restRequest.contentParser();
|
||||||
PutLifecycleAction.Request putLifecycleRequest = PutLifecycleAction.Request.parseRequest(lifecycleName, parser,
|
PutLifecycleAction.Request putLifecycleRequest = PutLifecycleAction.Request.parseRequest(lifecycleName, parser);
|
||||||
restRequest.getXContentRegistry());
|
|
||||||
putLifecycleRequest.timeout(restRequest.paramAsTime("timeout", putLifecycleRequest.timeout()));
|
putLifecycleRequest.timeout(restRequest.paramAsTime("timeout", putLifecycleRequest.timeout()));
|
||||||
putLifecycleRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", putLifecycleRequest.masterNodeTimeout()));
|
putLifecycleRequest.masterNodeTimeout(restRequest.paramAsTime("master_timeout", putLifecycleRequest.masterNodeTimeout()));
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.xpack.indexlifecycle;
|
package org.elasticsearch.xpack.indexlifecycle;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
import org.elasticsearch.cluster.Diff;
|
import org.elasticsearch.cluster.Diff;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
import org.elasticsearch.cluster.metadata.MetaData.Custom;
|
||||||
|
@ -17,9 +18,9 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.test.AbstractDiffableSerializationTestCase;
|
import org.elasticsearch.test.AbstractDiffableSerializationTestCase;
|
||||||
import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata.IndexLifecycleMetadataDiff;
|
import org.elasticsearch.xpack.indexlifecycle.IndexLifecycleMetadata.IndexLifecycleMetadataDiff;
|
||||||
import org.junit.Before;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -30,17 +31,6 @@ import java.util.TreeMap;
|
||||||
|
|
||||||
public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTestCase<MetaData.Custom> {
|
public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTestCase<MetaData.Custom> {
|
||||||
|
|
||||||
private NamedXContentRegistry registry;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
List<NamedXContentRegistry.Entry> entries = Arrays
|
|
||||||
.asList(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
|
|
||||||
new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TestLifecycleType.TYPE),
|
|
||||||
(p) -> TestLifecycleType.INSTANCE));
|
|
||||||
registry = new NamedXContentRegistry(entries);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IndexLifecycleMetadata createTestInstance() {
|
protected IndexLifecycleMetadata createTestInstance() {
|
||||||
int numPolicies = randomInt(5);
|
int numPolicies = randomInt(5);
|
||||||
|
@ -65,7 +55,7 @@ public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTe
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected IndexLifecycleMetadata doParseInstance(XContentParser parser) throws IOException {
|
protected IndexLifecycleMetadata doParseInstance(XContentParser parser) throws IOException {
|
||||||
return IndexLifecycleMetadata.PARSER.apply(parser, registry);
|
return IndexLifecycleMetadata.PARSER.apply(parser, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -80,6 +70,15 @@ public class IndexLifecycleMetadataTests extends AbstractDiffableSerializationTe
|
||||||
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, (in) -> TestLifecycleType.INSTANCE)));
|
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, (in) -> TestLifecycleType.INSTANCE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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));
|
||||||
|
return new NamedXContentRegistry(entries);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected MetaData.Custom mutateInstance(MetaData.Custom instance) {
|
protected MetaData.Custom mutateInstance(MetaData.Custom instance) {
|
||||||
IndexLifecycleMetadata metadata = (IndexLifecycleMetadata) instance;
|
IndexLifecycleMetadata metadata = (IndexLifecycleMetadata) instance;
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.indexlifecycle;
|
package org.elasticsearch.xpack.indexlifecycle;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
@ -16,6 +16,7 @@ import org.elasticsearch.test.AbstractSerializingTestCase;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -34,11 +35,10 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
|
||||||
private Phase secondPhase;
|
private Phase secondPhase;
|
||||||
private Phase thirdPhase;
|
private Phase thirdPhase;
|
||||||
private LifecyclePolicy policy;
|
private LifecyclePolicy policy;
|
||||||
private NamedXContentRegistry registry;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LifecyclePolicy doParseInstance(XContentParser parser) throws IOException {
|
protected LifecyclePolicy doParseInstance(XContentParser parser) throws IOException {
|
||||||
return LifecyclePolicy.parse(parser, new Tuple<String, NamedXContentRegistry>(lifecycleName, registry));
|
return LifecyclePolicy.parse(parser, lifecycleName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,6 +48,15 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
|
||||||
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, (in) -> TestLifecycleType.INSTANCE)));
|
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, (in) -> TestLifecycleType.INSTANCE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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));
|
||||||
|
return new NamedXContentRegistry(entries);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LifecyclePolicy createTestInstance() {
|
protected LifecyclePolicy createTestInstance() {
|
||||||
int numberPhases = randomInt(5);
|
int numberPhases = randomInt(5);
|
||||||
|
@ -91,11 +100,6 @@ public class LifecyclePolicyTests extends AbstractSerializingTestCase<LifecycleP
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setupPolicy() {
|
public void setupPolicy() {
|
||||||
List<NamedXContentRegistry.Entry> entries = Arrays
|
|
||||||
.asList(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
|
|
||||||
new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TestLifecycleType.TYPE),
|
|
||||||
(p) -> TestLifecycleType.INSTANCE));
|
|
||||||
registry = new NamedXContentRegistry(entries);
|
|
||||||
indexName = randomAlphaOfLengthBetween(1, 20);
|
indexName = randomAlphaOfLengthBetween(1, 20);
|
||||||
lifecycleName = randomAlphaOfLengthBetween(1, 20);
|
lifecycleName = randomAlphaOfLengthBetween(1, 20);
|
||||||
Map<String, Phase> phases = new LinkedHashMap<>();
|
Map<String, Phase> phases = new LinkedHashMap<>();
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.indexlifecycle;
|
package org.elasticsearch.xpack.indexlifecycle;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.collect.Tuple;
|
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
import org.elasticsearch.common.io.stream.Writeable.Reader;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
@ -24,15 +24,10 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PhaseTests extends AbstractSerializingTestCase<Phase> {
|
public class PhaseTests extends AbstractSerializingTestCase<Phase> {
|
||||||
|
|
||||||
private NamedXContentRegistry registry;
|
|
||||||
private String phaseName;
|
private String phaseName;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
List<NamedXContentRegistry.Entry> entries = Arrays
|
|
||||||
.asList(new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse));
|
|
||||||
registry = new NamedXContentRegistry(entries);
|
|
||||||
phaseName = randomAlphaOfLength(20); // NORELEASE we need to randomise the phase name rather
|
phaseName = randomAlphaOfLength(20); // NORELEASE we need to randomise the phase name rather
|
||||||
// than use the same name for all instances
|
// than use the same name for all instances
|
||||||
}
|
}
|
||||||
|
@ -49,8 +44,7 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Phase doParseInstance(XContentParser parser) throws IOException {
|
protected Phase doParseInstance(XContentParser parser) throws IOException {
|
||||||
|
return Phase.parse(parser, phaseName);
|
||||||
return Phase.parse(parser, new Tuple<>(phaseName, registry));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,6 +57,13 @@ public class PhaseTests extends AbstractSerializingTestCase<Phase> {
|
||||||
.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::new)));
|
.asList(new NamedWriteableRegistry.Entry(LifecycleAction.class, DeleteAction.NAME, DeleteAction::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));
|
||||||
|
return new NamedXContentRegistry(entries);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Phase mutateInstance(Phase instance) throws IOException {
|
protected Phase mutateInstance(Phase instance) throws IOException {
|
||||||
String name = instance.getName();
|
String name = instance.getName();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.indexlifecycle.action;
|
package org.elasticsearch.xpack.indexlifecycle.action;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
@ -21,6 +22,7 @@ import org.elasticsearch.xpack.indexlifecycle.TestLifecycleType;
|
||||||
import org.elasticsearch.xpack.indexlifecycle.action.PutLifecycleAction.Request;
|
import org.elasticsearch.xpack.indexlifecycle.action.PutLifecycleAction.Request;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -29,16 +31,10 @@ import java.util.Map;
|
||||||
|
|
||||||
public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase<PutLifecycleAction.Request> {
|
public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase<PutLifecycleAction.Request> {
|
||||||
|
|
||||||
private NamedXContentRegistry registry;
|
|
||||||
private String lifecycleName;
|
private String lifecycleName;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
List<NamedXContentRegistry.Entry> entries = Arrays.asList(
|
|
||||||
new NamedXContentRegistry.Entry(LifecycleAction.class, new ParseField(DeleteAction.NAME), DeleteAction::parse),
|
|
||||||
new NamedXContentRegistry.Entry(LifecycleType.class, new ParseField(TestLifecycleType.TYPE),
|
|
||||||
(p) -> TestLifecycleType.INSTANCE));
|
|
||||||
registry = new NamedXContentRegistry(entries);
|
|
||||||
lifecycleName = randomAlphaOfLength(20); // NORELEASE we need to randomise the lifecycle name rather
|
lifecycleName = randomAlphaOfLength(20); // NORELEASE we need to randomise the lifecycle name rather
|
||||||
// than use the same name for all instances
|
// than use the same name for all instances
|
||||||
}
|
}
|
||||||
|
@ -55,7 +51,7 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Request doParseInstance(XContentParser parser) {
|
protected Request doParseInstance(XContentParser parser) {
|
||||||
return PutLifecycleAction.Request.parseRequest(lifecycleName, parser, registry);
|
return PutLifecycleAction.Request.parseRequest(lifecycleName, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected NamedWriteableRegistry getNamedWriteableRegistry() {
|
protected NamedWriteableRegistry getNamedWriteableRegistry() {
|
||||||
|
@ -64,6 +60,15 @@ public class PutLifecycleRequestTests extends AbstractStreamableXContentTestCase
|
||||||
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, in -> TestLifecycleType.INSTANCE)));
|
new NamedWriteableRegistry.Entry(LifecycleType.class, TestLifecycleType.TYPE, in -> TestLifecycleType.INSTANCE)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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));
|
||||||
|
return new NamedXContentRegistry(entries);
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean supportsUnknownFields() {
|
protected boolean supportsUnknownFields() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue