Remove some more ParseFieldMatcher usages (#22571)
This commit is contained in:
parent
17342c403f
commit
0f7d52df68
|
@ -25,8 +25,6 @@ import org.elasticsearch.action.ActionRequestValidationException;
|
||||||
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
import org.elasticsearch.action.support.master.MasterNodeRequest;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
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.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
|
@ -41,8 +39,7 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
*/
|
*/
|
||||||
public class ClusterAllocationExplainRequest extends MasterNodeRequest<ClusterAllocationExplainRequest> {
|
public class ClusterAllocationExplainRequest extends MasterNodeRequest<ClusterAllocationExplainRequest> {
|
||||||
|
|
||||||
private static ObjectParser<ClusterAllocationExplainRequest, ParseFieldMatcherSupplier> PARSER = new ObjectParser(
|
private static ObjectParser<ClusterAllocationExplainRequest, Void> PARSER = new ObjectParser<>("cluster/allocation/explain");
|
||||||
"cluster/allocation/explain");
|
|
||||||
static {
|
static {
|
||||||
PARSER.declareString(ClusterAllocationExplainRequest::setIndex, new ParseField("index"));
|
PARSER.declareString(ClusterAllocationExplainRequest::setIndex, new ParseField("index"));
|
||||||
PARSER.declareInt(ClusterAllocationExplainRequest::setShard, new ParseField("shard"));
|
PARSER.declareInt(ClusterAllocationExplainRequest::setShard, new ParseField("shard"));
|
||||||
|
@ -225,7 +222,7 @@ public class ClusterAllocationExplainRequest extends MasterNodeRequest<ClusterAl
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClusterAllocationExplainRequest parse(XContentParser parser) throws IOException {
|
public static ClusterAllocationExplainRequest parse(XContentParser parser) throws IOException {
|
||||||
ClusterAllocationExplainRequest req = PARSER.parse(parser, new ClusterAllocationExplainRequest(), () -> ParseFieldMatcher.STRICT);
|
ClusterAllocationExplainRequest req = PARSER.parse(parser, new ClusterAllocationExplainRequest(), null);
|
||||||
Exception e = req.validate();
|
Exception e = req.validate();
|
||||||
if (e != null) {
|
if (e != null) {
|
||||||
throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request", e);
|
throw new ElasticsearchParseException("'index', 'shard', and 'primary' must be specified in allocation explain request", e);
|
||||||
|
|
|
@ -31,7 +31,6 @@ import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
|
||||||
import org.elasticsearch.cluster.node.DiscoveryNode;
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
|
||||||
|
@ -39,10 +38,10 @@ import org.elasticsearch.common.xcontent.NamedXContentRegistry;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.index.IndexNotFoundException;
|
import org.elasticsearch.index.IndexNotFoundException;
|
||||||
import org.elasticsearch.tasks.TaskResult;
|
|
||||||
import org.elasticsearch.tasks.Task;
|
import org.elasticsearch.tasks.Task;
|
||||||
import org.elasticsearch.tasks.TaskId;
|
import org.elasticsearch.tasks.TaskId;
|
||||||
import org.elasticsearch.tasks.TaskInfo;
|
import org.elasticsearch.tasks.TaskInfo;
|
||||||
|
import org.elasticsearch.tasks.TaskResult;
|
||||||
import org.elasticsearch.tasks.TaskResultsService;
|
import org.elasticsearch.tasks.TaskResultsService;
|
||||||
import org.elasticsearch.threadpool.ThreadPool;
|
import org.elasticsearch.threadpool.ThreadPool;
|
||||||
import org.elasticsearch.transport.TransportException;
|
import org.elasticsearch.transport.TransportException;
|
||||||
|
@ -251,7 +250,7 @@ public class TransportGetTaskAction extends HandledTransportAction<GetTaskReques
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
|
try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) {
|
||||||
TaskResult result = TaskResult.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
TaskResult result = TaskResult.PARSER.apply(parser, null);
|
||||||
listener.onResponse(new GetTaskResponse(result));
|
listener.onResponse(new GetTaskResponse(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,6 @@ import org.elasticsearch.cluster.metadata.AliasAction;
|
||||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||||
import org.elasticsearch.cluster.metadata.MetaData;
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||||
|
@ -42,6 +41,7 @@ import org.elasticsearch.common.xcontent.ObjectParser.ValueType;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentType;
|
import org.elasticsearch.common.xcontent.XContentType;
|
||||||
import org.elasticsearch.index.query.QueryBuilder;
|
import org.elasticsearch.index.query.QueryBuilder;
|
||||||
|
|
||||||
|
@ -118,8 +118,8 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
||||||
public static AliasActions removeIndex() {
|
public static AliasActions removeIndex() {
|
||||||
return new AliasActions(AliasActions.Type.REMOVE_INDEX);
|
return new AliasActions(AliasActions.Type.REMOVE_INDEX);
|
||||||
}
|
}
|
||||||
private static ObjectParser<AliasActions, ParseFieldMatcherSupplier> parser(String name, Supplier<AliasActions> supplier) {
|
private static ObjectParser<AliasActions, Void> parser(String name, Supplier<AliasActions> supplier) {
|
||||||
ObjectParser<AliasActions, ParseFieldMatcherSupplier> parser = new ObjectParser<>(name, supplier);
|
ObjectParser<AliasActions, Void> parser = new ObjectParser<>(name, supplier);
|
||||||
parser.declareString((action, index) -> {
|
parser.declareString((action, index) -> {
|
||||||
if (action.indices() != null) {
|
if (action.indices() != null) {
|
||||||
throw new IllegalArgumentException("Only one of [index] and [indices] is supported");
|
throw new IllegalArgumentException("Only one of [index] and [indices] is supported");
|
||||||
|
@ -147,7 +147,7 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final ObjectParser<AliasActions, ParseFieldMatcherSupplier> ADD_PARSER = parser("add", AliasActions::add);
|
private static final ObjectParser<AliasActions, Void> ADD_PARSER = parser("add", AliasActions::add);
|
||||||
static {
|
static {
|
||||||
ADD_PARSER.declareObject(AliasActions::filter, (parser, m) -> {
|
ADD_PARSER.declareObject(AliasActions::filter, (parser, m) -> {
|
||||||
try {
|
try {
|
||||||
|
@ -157,18 +157,17 @@ public class IndicesAliasesRequest extends AcknowledgedRequest<IndicesAliasesReq
|
||||||
}
|
}
|
||||||
}, new ParseField("filter"));
|
}, new ParseField("filter"));
|
||||||
// Since we need to support numbers AND strings here we have to use ValueType.INT.
|
// Since we need to support numbers AND strings here we have to use ValueType.INT.
|
||||||
ADD_PARSER.declareField(AliasActions::routing, p -> p.text(), new ParseField("routing"), ValueType.INT);
|
ADD_PARSER.declareField(AliasActions::routing, XContentParser::text, new ParseField("routing"), ValueType.INT);
|
||||||
ADD_PARSER.declareField(AliasActions::indexRouting, p -> p.text(), new ParseField("index_routing"), ValueType.INT);
|
ADD_PARSER.declareField(AliasActions::indexRouting, XContentParser::text, new ParseField("index_routing"), ValueType.INT);
|
||||||
ADD_PARSER.declareField(AliasActions::searchRouting, p -> p.text(), new ParseField("search_routing"), ValueType.INT);
|
ADD_PARSER.declareField(AliasActions::searchRouting, XContentParser::text, new ParseField("search_routing"), ValueType.INT);
|
||||||
}
|
}
|
||||||
private static final ObjectParser<AliasActions, ParseFieldMatcherSupplier> REMOVE_PARSER = parser("remove", AliasActions::remove);
|
private static final ObjectParser<AliasActions, Void> REMOVE_PARSER = parser("remove", AliasActions::remove);
|
||||||
private static final ObjectParser<AliasActions, ParseFieldMatcherSupplier> REMOVE_INDEX_PARSER = parser("remove_index",
|
private static final ObjectParser<AliasActions, Void> REMOVE_INDEX_PARSER = parser("remove_index", AliasActions::removeIndex);
|
||||||
AliasActions::removeIndex);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parser for any one {@link AliasAction}.
|
* Parser for any one {@link AliasAction}.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<AliasActions, ParseFieldMatcherSupplier> PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<AliasActions, Void> PARSER = new ConstructingObjectParser<>(
|
||||||
"alias_action", a -> {
|
"alias_action", a -> {
|
||||||
// Take the first action and complain if there are more than one actions
|
// Take the first action and complain if there are more than one actions
|
||||||
AliasActions action = null;
|
AliasActions action = null;
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.action.admin.indices.rollover;
|
package org.elasticsearch.action.admin.indices.rollover;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteable;
|
import org.elasticsearch.common.io.stream.NamedWriteable;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
|
@ -32,8 +31,7 @@ import java.util.Set;
|
||||||
*/
|
*/
|
||||||
public abstract class Condition<T> implements NamedWriteable {
|
public abstract class Condition<T> implements NamedWriteable {
|
||||||
|
|
||||||
public static ObjectParser<Set<Condition>, ParseFieldMatcherSupplier> PARSER =
|
public static ObjectParser<Set<Condition>, Void> PARSER = new ObjectParser<>("conditions", null);
|
||||||
new ObjectParser<>("conditions", null);
|
|
||||||
static {
|
static {
|
||||||
PARSER.declareString((conditions, s) ->
|
PARSER.declareString((conditions, s) ->
|
||||||
conditions.add(new MaxAgeCondition(TimeValue.parseTimeValue(s, MaxAgeCondition.NAME))),
|
conditions.add(new MaxAgeCondition(TimeValue.parseTimeValue(s, MaxAgeCondition.NAME))),
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.action.support.ActiveShardCount;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
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.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
@ -44,23 +43,19 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
*/
|
*/
|
||||||
public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest {
|
public class RolloverRequest extends AcknowledgedRequest<RolloverRequest> implements IndicesRequest {
|
||||||
|
|
||||||
public static final ObjectParser<RolloverRequest, ParseFieldMatcherSupplier> PARSER =
|
public static final ObjectParser<RolloverRequest, Void> PARSER = new ObjectParser<>("conditions", null);
|
||||||
new ObjectParser<>("conditions", null);
|
|
||||||
static {
|
static {
|
||||||
PARSER.declareField((parser, request, parseFieldMatcherSupplier) ->
|
PARSER.declareField((parser, request, context) -> Condition.PARSER.parse(parser, request.conditions, null),
|
||||||
Condition.PARSER.parse(parser, request.conditions, parseFieldMatcherSupplier),
|
|
||||||
new ParseField("conditions"), ObjectParser.ValueType.OBJECT);
|
new ParseField("conditions"), ObjectParser.ValueType.OBJECT);
|
||||||
PARSER.declareField((parser, request, parseFieldMatcherSupplier) ->
|
PARSER.declareField((parser, request, context) -> request.createIndexRequest.settings(parser.map()),
|
||||||
request.createIndexRequest.settings(parser.map()),
|
|
||||||
new ParseField("settings"), ObjectParser.ValueType.OBJECT);
|
new ParseField("settings"), ObjectParser.ValueType.OBJECT);
|
||||||
PARSER.declareField((parser, request, parseFieldMatcherSupplier) -> {
|
PARSER.declareField((parser, request, context) -> {
|
||||||
for (Map.Entry<String, Object> mappingsEntry : parser.map().entrySet()) {
|
for (Map.Entry<String, Object> mappingsEntry : parser.map().entrySet()) {
|
||||||
request.createIndexRequest.mapping(mappingsEntry.getKey(),
|
request.createIndexRequest.mapping(mappingsEntry.getKey(),
|
||||||
(Map<String, Object>) mappingsEntry.getValue());
|
(Map<String, Object>) mappingsEntry.getValue());
|
||||||
}
|
}
|
||||||
}, new ParseField("mappings"), ObjectParser.ValueType.OBJECT);
|
}, new ParseField("mappings"), ObjectParser.ValueType.OBJECT);
|
||||||
PARSER.declareField((parser, request, parseFieldMatcherSupplier) ->
|
PARSER.declareField((parser, request, context) -> request.createIndexRequest.aliases(parser.map()),
|
||||||
request.createIndexRequest.aliases(parser.map()),
|
|
||||||
new ParseField("aliases"), ObjectParser.ValueType.OBJECT);
|
new ParseField("aliases"), ObjectParser.ValueType.OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,6 @@ import org.elasticsearch.action.support.ActiveShardCount;
|
||||||
import org.elasticsearch.action.support.IndicesOptions;
|
import org.elasticsearch.action.support.IndicesOptions;
|
||||||
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
import org.elasticsearch.action.support.master.AcknowledgedRequest;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
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.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
|
@ -40,14 +39,11 @@ import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
*/
|
*/
|
||||||
public class ShrinkRequest extends AcknowledgedRequest<ShrinkRequest> implements IndicesRequest {
|
public class ShrinkRequest extends AcknowledgedRequest<ShrinkRequest> implements IndicesRequest {
|
||||||
|
|
||||||
public static final ObjectParser<ShrinkRequest, ParseFieldMatcherSupplier> PARSER =
|
public static final ObjectParser<ShrinkRequest, Void> PARSER = new ObjectParser<>("shrink_request", null);
|
||||||
new ObjectParser<>("shrink_request", null);
|
|
||||||
static {
|
static {
|
||||||
PARSER.declareField((parser, request, parseFieldMatcherSupplier) ->
|
PARSER.declareField((parser, request, context) -> request.getShrinkIndexRequest().settings(parser.map()),
|
||||||
request.getShrinkIndexRequest().settings(parser.map()),
|
|
||||||
new ParseField("settings"), ObjectParser.ValueType.OBJECT);
|
new ParseField("settings"), ObjectParser.ValueType.OBJECT);
|
||||||
PARSER.declareField((parser, request, parseFieldMatcherSupplier) ->
|
PARSER.declareField((parser, request, context) -> request.getShrinkIndexRequest().aliases(parser.map()),
|
||||||
request.getShrinkIndexRequest().aliases(parser.map()),
|
|
||||||
new ParseField("aliases"), ObjectParser.ValueType.OBJECT);
|
new ParseField("aliases"), ObjectParser.ValueType.OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.elasticsearch.cluster.routing;
|
||||||
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.UUIDs;
|
import org.elasticsearch.common.UUIDs;
|
||||||
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;
|
||||||
|
@ -48,7 +46,7 @@ public class AllocationId implements ToXContent, Writeable {
|
||||||
private static final String ID_KEY = "id";
|
private static final String ID_KEY = "id";
|
||||||
private static final String RELOCATION_ID_KEY = "relocation_id";
|
private static final String RELOCATION_ID_KEY = "relocation_id";
|
||||||
|
|
||||||
private static final ObjectParser<AllocationId.Builder, ParseFieldMatcherSupplier> ALLOCATION_ID_PARSER = new ObjectParser<>(
|
private static final ObjectParser<AllocationId.Builder, Void> ALLOCATION_ID_PARSER = new ObjectParser<>(
|
||||||
"allocationId");
|
"allocationId");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
@ -203,6 +201,6 @@ public class AllocationId implements ToXContent, Writeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AllocationId fromXContent(XContentParser parser) throws IOException {
|
public static AllocationId fromXContent(XContentParser parser) throws IOException {
|
||||||
return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder(), () -> ParseFieldMatcher.STRICT).build();
|
return ALLOCATION_ID_PARSER.parse(parser, new AllocationId.Builder(), null).build();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,6 @@ import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
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.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
|
@ -50,8 +49,8 @@ public abstract class AbstractAllocateAllocationCommand implements AllocationCom
|
||||||
private static final String SHARD_FIELD = "shard";
|
private static final String SHARD_FIELD = "shard";
|
||||||
private static final String NODE_FIELD = "node";
|
private static final String NODE_FIELD = "node";
|
||||||
|
|
||||||
protected static <T extends Builder<?>> ObjectParser<T, ParseFieldMatcherSupplier> createAllocateParser(String command) {
|
protected static <T extends Builder<?>> ObjectParser<T, Void> createAllocateParser(String command) {
|
||||||
ObjectParser<T, ParseFieldMatcherSupplier> parser = new ObjectParser<>(command);
|
ObjectParser<T, Void> parser = new ObjectParser<>(command);
|
||||||
parser.declareString(Builder::setIndex, new ParseField(INDEX_FIELD));
|
parser.declareString(Builder::setIndex, new ParseField(INDEX_FIELD));
|
||||||
parser.declareInt(Builder::setShard, new ParseField(SHARD_FIELD));
|
parser.declareInt(Builder::setShard, new ParseField(SHARD_FIELD));
|
||||||
parser.declareString(Builder::setNode, new ParseField(NODE_FIELD));
|
parser.declareString(Builder::setNode, new ParseField(NODE_FIELD));
|
||||||
|
|
|
@ -30,8 +30,6 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -49,8 +47,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation
|
||||||
public static final String NAME = "allocate_empty_primary";
|
public static final String NAME = "allocate_empty_primary";
|
||||||
public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME);
|
public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME);
|
||||||
|
|
||||||
private static final ObjectParser<Builder, ParseFieldMatcherSupplier> EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand
|
private static final ObjectParser<Builder, Void> EMPTY_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME);
|
||||||
.createAllocatePrimaryParser(NAME);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link AllocateEmptyPrimaryAllocationCommand}
|
* Creates a new {@link AllocateEmptyPrimaryAllocationCommand}
|
||||||
|
@ -83,7 +80,7 @@ public class AllocateEmptyPrimaryAllocationCommand extends BasePrimaryAllocation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder parse(XContentParser parser) throws IOException {
|
public Builder parse(XContentParser parser) throws IOException {
|
||||||
return EMPTY_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT);
|
return EMPTY_PRIMARY_PARSER.parse(parser, this, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,8 +28,6 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -46,8 +44,7 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation
|
||||||
public static final String NAME = "allocate_replica";
|
public static final String NAME = "allocate_replica";
|
||||||
public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME);
|
public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME);
|
||||||
|
|
||||||
private static final ObjectParser<AllocateReplicaAllocationCommand.Builder, ParseFieldMatcherSupplier> REPLICA_PARSER =
|
private static final ObjectParser<AllocateReplicaAllocationCommand.Builder, Void> REPLICA_PARSER = createAllocateParser(NAME);
|
||||||
createAllocateParser(NAME);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link AllocateReplicaAllocationCommand}
|
* Creates a new {@link AllocateReplicaAllocationCommand}
|
||||||
|
@ -80,7 +77,7 @@ public class AllocateReplicaAllocationCommand extends AbstractAllocateAllocation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder parse(XContentParser parser) throws IOException {
|
public Builder parse(XContentParser parser) throws IOException {
|
||||||
return REPLICA_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT);
|
return REPLICA_PARSER.parse(parser, this, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,8 +28,6 @@ import org.elasticsearch.cluster.routing.allocation.RerouteExplanation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
import org.elasticsearch.cluster.routing.allocation.RoutingAllocation;
|
||||||
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
import org.elasticsearch.cluster.routing.allocation.decider.Decision;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -46,8 +44,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation
|
||||||
public static final String NAME = "allocate_stale_primary";
|
public static final String NAME = "allocate_stale_primary";
|
||||||
public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME);
|
public static final ParseField COMMAND_NAME_FIELD = new ParseField(NAME);
|
||||||
|
|
||||||
private static final ObjectParser<Builder, ParseFieldMatcherSupplier> STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand
|
private static final ObjectParser<Builder, Void> STALE_PRIMARY_PARSER = BasePrimaryAllocationCommand.createAllocatePrimaryParser(NAME);
|
||||||
.createAllocatePrimaryParser(NAME);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new {@link AllocateStalePrimaryAllocationCommand}
|
* Creates a new {@link AllocateStalePrimaryAllocationCommand}
|
||||||
|
@ -81,7 +78,7 @@ public class AllocateStalePrimaryAllocationCommand extends BasePrimaryAllocation
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Builder parse(XContentParser parser) throws IOException {
|
public Builder parse(XContentParser parser) throws IOException {
|
||||||
return STALE_PRIMARY_PARSER.parse(parser, this, () -> ParseFieldMatcher.STRICT);
|
return STALE_PRIMARY_PARSER.parse(parser, this, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,8 +35,8 @@ public abstract class BasePrimaryAllocationCommand extends AbstractAllocateAlloc
|
||||||
|
|
||||||
private static final String ACCEPT_DATA_LOSS_FIELD = "accept_data_loss";
|
private static final String ACCEPT_DATA_LOSS_FIELD = "accept_data_loss";
|
||||||
|
|
||||||
protected static <T extends Builder<?>> ObjectParser<T, ParseFieldMatcherSupplier> createAllocatePrimaryParser(String command) {
|
protected static <T extends Builder<?>> ObjectParser<T, Void> createAllocatePrimaryParser(String command) {
|
||||||
ObjectParser<T, ParseFieldMatcherSupplier> parser = AbstractAllocateAllocationCommand.createAllocateParser(command);
|
ObjectParser<T, Void> parser = AbstractAllocateAllocationCommand.createAllocateParser(command);
|
||||||
parser.declareBoolean(Builder::setAcceptDataLoss, new ParseField(ACCEPT_DATA_LOSS_FIELD));
|
parser.declareBoolean(Builder::setAcceptDataLoss, new ParseField(ACCEPT_DATA_LOSS_FIELD));
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,6 @@ package org.elasticsearch.common.xcontent;
|
||||||
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -121,7 +120,7 @@ public final class ObjectParser<Value, Context> extends AbstractObjectParser<Val
|
||||||
/**
|
/**
|
||||||
* Parses a Value from the given {@link XContentParser}
|
* Parses a Value from the given {@link XContentParser}
|
||||||
* @param parser the parser to build a value from
|
* @param parser the parser to build a value from
|
||||||
* @param context must at least provide a {@link ParseFieldMatcher}
|
* @param context context needed for parsing
|
||||||
* @return a new value instance drawn from the provided value supplier on {@link #ObjectParser(String, Supplier)}
|
* @return a new value instance drawn from the provided value supplier on {@link #ObjectParser(String, Supplier)}
|
||||||
* @throws IOException if an IOException occurs.
|
* @throws IOException if an IOException occurs.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -20,8 +20,6 @@
|
||||||
package org.elasticsearch.env;
|
package org.elasticsearch.env;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
@ -70,8 +68,7 @@ public final class NodeMetaData {
|
||||||
return "node_id [" + nodeId + "]";
|
return "node_id [" + nodeId + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ObjectParser<Builder, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>("node_meta_data",
|
private static ObjectParser<Builder, Void> PARSER = new ObjectParser<>("node_meta_data", Builder::new);
|
||||||
Builder::new);
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
PARSER.declareString(Builder::setNodeId, new ParseField(NODE_ID_KEY));
|
PARSER.declareString(Builder::setNodeId, new ParseField(NODE_ID_KEY));
|
||||||
|
@ -110,7 +107,7 @@ public final class NodeMetaData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetaData fromXContent(XContentParser parser) throws IOException {
|
public NodeMetaData fromXContent(XContentParser parser) throws IOException {
|
||||||
return PARSER.apply(parser, () -> ParseFieldMatcher.STRICT).build();
|
return PARSER.apply(parser, null).build();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,6 @@ import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest;
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser;
|
||||||
|
@ -39,7 +37,7 @@ import java.io.IOException;
|
||||||
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
import static org.elasticsearch.rest.RestRequest.Method.POST;
|
||||||
|
|
||||||
public class RestIndicesAliasesAction extends BaseRestHandler {
|
public class RestIndicesAliasesAction extends BaseRestHandler {
|
||||||
static final ObjectParser<IndicesAliasesRequest, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>("aliases");
|
static final ObjectParser<IndicesAliasesRequest, Void> PARSER = new ObjectParser<>("aliases");
|
||||||
static {
|
static {
|
||||||
PARSER.declareObjectArray((request, actions) -> {
|
PARSER.declareObjectArray((request, actions) -> {
|
||||||
for (AliasActions action: actions) {
|
for (AliasActions action: actions) {
|
||||||
|
@ -60,7 +58,7 @@ public class RestIndicesAliasesAction extends BaseRestHandler {
|
||||||
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
|
indicesAliasesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", indicesAliasesRequest.masterNodeTimeout()));
|
||||||
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
|
indicesAliasesRequest.timeout(request.paramAsTime("timeout", indicesAliasesRequest.timeout()));
|
||||||
try (XContentParser parser = request.contentParser()) {
|
try (XContentParser parser = request.contentParser()) {
|
||||||
PARSER.parse(parser, indicesAliasesRequest, () -> ParseFieldMatcher.STRICT);
|
PARSER.parse(parser, indicesAliasesRequest, null);
|
||||||
}
|
}
|
||||||
if (indicesAliasesRequest.getAliasActions().isEmpty()) {
|
if (indicesAliasesRequest.getAliasActions().isEmpty()) {
|
||||||
throw new IllegalArgumentException("No action specified");
|
throw new IllegalArgumentException("No action specified");
|
||||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.rest.action.admin.indices;
|
||||||
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
|
||||||
import org.elasticsearch.action.support.ActiveShardCount;
|
import org.elasticsearch.action.support.ActiveShardCount;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.BaseRestHandler;
|
import org.elasticsearch.rest.BaseRestHandler;
|
||||||
|
@ -44,7 +43,7 @@ public class RestRolloverIndexAction extends BaseRestHandler {
|
||||||
@Override
|
@Override
|
||||||
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
|
||||||
RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index"));
|
RolloverRequest rolloverIndexRequest = new RolloverRequest(request.param("index"), request.param("new_index"));
|
||||||
request.applyContentParser(parser -> RolloverRequest.PARSER.parse(parser, rolloverIndexRequest, () -> ParseFieldMatcher.EMPTY));
|
request.applyContentParser(parser -> RolloverRequest.PARSER.parse(parser, rolloverIndexRequest, null));
|
||||||
rolloverIndexRequest.dryRun(request.paramAsBoolean("dry_run", false));
|
rolloverIndexRequest.dryRun(request.paramAsBoolean("dry_run", false));
|
||||||
rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout()));
|
rolloverIndexRequest.timeout(request.paramAsTime("timeout", rolloverIndexRequest.timeout()));
|
||||||
rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout()));
|
rolloverIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", rolloverIndexRequest.masterNodeTimeout()));
|
||||||
|
|
|
@ -23,7 +23,6 @@ import org.elasticsearch.action.admin.indices.shrink.ShrinkRequest;
|
||||||
import org.elasticsearch.action.admin.indices.shrink.ShrinkResponse;
|
import org.elasticsearch.action.admin.indices.shrink.ShrinkResponse;
|
||||||
import org.elasticsearch.action.support.ActiveShardCount;
|
import org.elasticsearch.action.support.ActiveShardCount;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -52,7 +51,7 @@ public class RestShrinkIndexAction extends BaseRestHandler {
|
||||||
throw new IllegalArgumentException("no source index");
|
throw new IllegalArgumentException("no source index");
|
||||||
}
|
}
|
||||||
ShrinkRequest shrinkIndexRequest = new ShrinkRequest(request.param("target"), request.param("index"));
|
ShrinkRequest shrinkIndexRequest = new ShrinkRequest(request.param("target"), request.param("index"));
|
||||||
request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, () -> ParseFieldMatcher.EMPTY));
|
request.applyContentParser(parser -> ShrinkRequest.PARSER.parse(parser, shrinkIndexRequest, null));
|
||||||
shrinkIndexRequest.timeout(request.paramAsTime("timeout", shrinkIndexRequest.timeout()));
|
shrinkIndexRequest.timeout(request.paramAsTime("timeout", shrinkIndexRequest.timeout()));
|
||||||
shrinkIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", shrinkIndexRequest.masterNodeTimeout()));
|
shrinkIndexRequest.masterNodeTimeout(request.paramAsTime("master_timeout", shrinkIndexRequest.masterNodeTimeout()));
|
||||||
shrinkIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
|
shrinkIndexRequest.setWaitForActiveShards(ActiveShardCount.parseString(request.param("wait_for_active_shards")));
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.search.aggregations.bucket.histogram;
|
package org.elasticsearch.search.aggregations.bucket.histogram;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
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;
|
||||||
|
@ -45,7 +44,7 @@ public class ExtendedBounds implements ToXContent, Writeable {
|
||||||
static final ParseField MIN_FIELD = new ParseField("min");
|
static final ParseField MIN_FIELD = new ParseField("min");
|
||||||
static final ParseField MAX_FIELD = new ParseField("max");
|
static final ParseField MAX_FIELD = new ParseField("max");
|
||||||
|
|
||||||
public static final ConstructingObjectParser<ExtendedBounds, ParseFieldMatcherSupplier> PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<ExtendedBounds, Void> PARSER = new ConstructingObjectParser<>(
|
||||||
"extended_bounds", a -> {
|
"extended_bounds", a -> {
|
||||||
assert a.length == 2;
|
assert a.length == 2;
|
||||||
Long min = null;
|
Long min = null;
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.tasks;
|
package org.elasticsearch.tasks;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -189,7 +188,7 @@ public final class TaskInfo implements Writeable, ToXContent {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ConstructingObjectParser<TaskInfo, ParseFieldMatcherSupplier> PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<TaskInfo, Void> PARSER = new ConstructingObjectParser<>(
|
||||||
"task_info", a -> {
|
"task_info", a -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
TaskId id = new TaskId((String) a[i++], (Long) a[i++]);
|
TaskId id = new TaskId((String) a[i++], (Long) a[i++]);
|
||||||
|
|
|
@ -171,7 +171,7 @@ public final class TaskResult implements Writeable, ToXContent {
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ConstructingObjectParser<TaskResult, ParseFieldMatcherSupplier> PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<TaskResult, Void> PARSER = new ConstructingObjectParser<>(
|
||||||
"stored_task_result", a -> {
|
"stored_task_result", a -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
boolean completed = (boolean) a[i++];
|
boolean completed = (boolean) a[i++];
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.action.admin.indices.alias;
|
package org.elasticsearch.action.admin.indices.alias;
|
||||||
|
|
||||||
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
import org.elasticsearch.action.admin.indices.alias.IndicesAliasesRequest.AliasActions;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -142,7 +141,7 @@ public class AliasActionsTests extends ESTestCase {
|
||||||
b.endObject();
|
b.endObject();
|
||||||
b = shuffleXContent(b, "filter");
|
b = shuffleXContent(b, "filter");
|
||||||
try (XContentParser parser = createParser(b)) {
|
try (XContentParser parser = createParser(b)) {
|
||||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
AliasActions action = AliasActions.PARSER.apply(parser, null);
|
||||||
assertEquals(AliasActions.Type.ADD, action.actionType());
|
assertEquals(AliasActions.Type.ADD, action.actionType());
|
||||||
assertThat(action.indices(), equalTo(indices));
|
assertThat(action.indices(), equalTo(indices));
|
||||||
assertThat(action.aliases(), equalTo(aliases));
|
assertThat(action.aliases(), equalTo(aliases));
|
||||||
|
@ -179,7 +178,7 @@ public class AliasActionsTests extends ESTestCase {
|
||||||
b.endObject();
|
b.endObject();
|
||||||
b = shuffleXContent(b);
|
b = shuffleXContent(b);
|
||||||
try (XContentParser parser = createParser(b)) {
|
try (XContentParser parser = createParser(b)) {
|
||||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
AliasActions action = AliasActions.PARSER.apply(parser, null);
|
||||||
assertEquals(AliasActions.Type.ADD, action.actionType());
|
assertEquals(AliasActions.Type.ADD, action.actionType());
|
||||||
assertThat(action.indices(), arrayContaining(index));
|
assertThat(action.indices(), arrayContaining(index));
|
||||||
assertThat(action.aliases(), arrayContaining(alias));
|
assertThat(action.aliases(), arrayContaining(alias));
|
||||||
|
@ -210,7 +209,7 @@ public class AliasActionsTests extends ESTestCase {
|
||||||
b.endObject();
|
b.endObject();
|
||||||
b = shuffleXContent(b);
|
b = shuffleXContent(b);
|
||||||
try (XContentParser parser = createParser(b)) {
|
try (XContentParser parser = createParser(b)) {
|
||||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
AliasActions action = AliasActions.PARSER.apply(parser, null);
|
||||||
assertEquals(AliasActions.Type.REMOVE, action.actionType());
|
assertEquals(AliasActions.Type.REMOVE, action.actionType());
|
||||||
assertThat(action.indices(), equalTo(indices));
|
assertThat(action.indices(), equalTo(indices));
|
||||||
assertThat(action.aliases(), equalTo(aliases));
|
assertThat(action.aliases(), equalTo(aliases));
|
||||||
|
@ -233,7 +232,7 @@ public class AliasActionsTests extends ESTestCase {
|
||||||
b.endObject();
|
b.endObject();
|
||||||
b = shuffleXContent(b);
|
b = shuffleXContent(b);
|
||||||
try (XContentParser parser = createParser(b)) {
|
try (XContentParser parser = createParser(b)) {
|
||||||
AliasActions action = AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
AliasActions action = AliasActions.PARSER.apply(parser, null);
|
||||||
assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType());
|
assertEquals(AliasActions.Type.REMOVE_INDEX, action.actionType());
|
||||||
assertArrayEquals(indices, action.indices());
|
assertArrayEquals(indices, action.indices());
|
||||||
assertThat(action.aliases(), arrayWithSize(0));
|
assertThat(action.aliases(), arrayWithSize(0));
|
||||||
|
@ -252,7 +251,7 @@ public class AliasActionsTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
b.endObject();
|
b.endObject();
|
||||||
try (XContentParser parser = createParser(b)) {
|
try (XContentParser parser = createParser(b)) {
|
||||||
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT));
|
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null));
|
||||||
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
||||||
assertEquals("Only one of [index] and [indices] is supported", e.getCause().getCause().getMessage());
|
assertEquals("Only one of [index] and [indices] is supported", e.getCause().getCause().getMessage());
|
||||||
}
|
}
|
||||||
|
@ -270,7 +269,7 @@ public class AliasActionsTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
b.endObject();
|
b.endObject();
|
||||||
try (XContentParser parser = createParser(b)) {
|
try (XContentParser parser = createParser(b)) {
|
||||||
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT));
|
Exception e = expectThrows(ParsingException.class, () -> AliasActions.PARSER.apply(parser, null));
|
||||||
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
assertThat(e.getCause().getCause(), instanceOf(IllegalArgumentException.class));
|
||||||
assertEquals("Only one of [alias] and [aliases] is supported", e.getCause().getCause().getMessage());
|
assertEquals("Only one of [alias] and [aliases] is supported", e.getCause().getCause().getMessage());
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
package org.elasticsearch.action.admin.indices.rollover;
|
package org.elasticsearch.action.admin.indices.rollover;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
|
@ -40,7 +39,7 @@ public class RolloverRequestTests extends ESTestCase {
|
||||||
.field("max_docs", 100)
|
.field("max_docs", 100)
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject();
|
.endObject();
|
||||||
RolloverRequest.PARSER.parse(createParser(builder), request, () -> ParseFieldMatcher.EMPTY);
|
RolloverRequest.PARSER.parse(createParser(builder), request, null);
|
||||||
Set<Condition> conditions = request.getConditions();
|
Set<Condition> conditions = request.getConditions();
|
||||||
assertThat(conditions.size(), equalTo(2));
|
assertThat(conditions.size(), equalTo(2));
|
||||||
for (Condition condition : conditions) {
|
for (Condition condition : conditions) {
|
||||||
|
@ -81,7 +80,7 @@ public class RolloverRequestTests extends ESTestCase {
|
||||||
.startObject("alias1").endObject()
|
.startObject("alias1").endObject()
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject();
|
.endObject();
|
||||||
RolloverRequest.PARSER.parse(createParser(builder), request, () -> ParseFieldMatcher.EMPTY);
|
RolloverRequest.PARSER.parse(createParser(builder), request, null);
|
||||||
Set<Condition> conditions = request.getConditions();
|
Set<Condition> conditions = request.getConditions();
|
||||||
assertThat(conditions.size(), equalTo(2));
|
assertThat(conditions.size(), equalTo(2));
|
||||||
assertThat(request.getCreateIndexRequest().mappings().size(), equalTo(1));
|
assertThat(request.getCreateIndexRequest().mappings().size(), equalTo(1));
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.elasticsearch.common.xcontent;
|
||||||
|
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser;
|
import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser;
|
||||||
|
@ -43,15 +41,13 @@ import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
|
||||||
public class ConstructingObjectParserTests extends ESTestCase {
|
public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
private static final ParseFieldMatcherSupplier MATCHER = () -> ParseFieldMatcher.STRICT;
|
|
||||||
|
|
||||||
public void testNullDeclares() {
|
public void testNullDeclares() {
|
||||||
ConstructingObjectParser<Void, ParseFieldMatcherSupplier> objectParser = new ConstructingObjectParser<>("foo", a -> null);
|
ConstructingObjectParser<Void, Void> objectParser = new ConstructingObjectParser<>("foo", a -> null);
|
||||||
Exception e = expectThrows(IllegalArgumentException.class,
|
Exception e = expectThrows(IllegalArgumentException.class,
|
||||||
() -> objectParser.declareField(null, (r, c) -> null, new ParseField("test"), ObjectParser.ValueType.STRING));
|
() -> objectParser.declareField(null, (r, c) -> null, new ParseField("test"), ObjectParser.ValueType.STRING));
|
||||||
assertEquals("[consumer] is required", e.getMessage());
|
assertEquals("[consumer] is required", e.getMessage());
|
||||||
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
||||||
(o, v) -> {}, (ContextParser<ParseFieldMatcherSupplier, Object>) null,
|
(o, v) -> {}, (ContextParser<Void, Object>) null,
|
||||||
new ParseField("test"), ObjectParser.ValueType.STRING));
|
new ParseField("test"), ObjectParser.ValueType.STRING));
|
||||||
assertEquals("[parser] is required", e.getMessage());
|
assertEquals("[parser] is required", e.getMessage());
|
||||||
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
||||||
|
@ -82,7 +78,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
builder = shuffleXContent(builder);
|
builder = shuffleXContent(builder);
|
||||||
BytesReference bytes = builder.bytes();
|
BytesReference bytes = builder.bytes();
|
||||||
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) {
|
try (XContentParser parser = createParser(JsonXContent.jsonXContent, bytes)) {
|
||||||
HasCtorArguments parsed = randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER);
|
HasCtorArguments parsed = randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null);
|
||||||
assertEquals(expected.animal, parsed.animal);
|
assertEquals(expected.animal, parsed.animal);
|
||||||
assertEquals(expected.vegetable, parsed.vegetable);
|
assertEquals(expected.vegetable, parsed.vegetable);
|
||||||
assertEquals(expected.mineral, parsed.mineral);
|
assertEquals(expected.mineral, parsed.mineral);
|
||||||
|
@ -102,9 +98,9 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
"{\n"
|
"{\n"
|
||||||
+ " \"mineral\": 1\n"
|
+ " \"mineral\": 1\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier> objectParser = randomBoolean() ? HasCtorArguments.PARSER
|
ConstructingObjectParser<HasCtorArguments, Void> objectParser = randomBoolean() ? HasCtorArguments.PARSER
|
||||||
: HasCtorArguments.PARSER_VEGETABLE_OPTIONAL;
|
: HasCtorArguments.PARSER_VEGETABLE_OPTIONAL;
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> objectParser.apply(parser, MATCHER));
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> objectParser.apply(parser, null));
|
||||||
if (objectParser == HasCtorArguments.PARSER) {
|
if (objectParser == HasCtorArguments.PARSER) {
|
||||||
assertEquals("Required [animal, vegetable]", e.getMessage());
|
assertEquals("Required [animal, vegetable]", e.getMessage());
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +113,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
"{\n"
|
"{\n"
|
||||||
+ " \"mineral\": 1\n"
|
+ " \"mineral\": 1\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, MATCHER);
|
HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, null);
|
||||||
assertEquals(1, parsed.mineral);
|
assertEquals(1, parsed.mineral);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +124,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"animal\": \"cat\"\n"
|
+ " \"animal\": \"cat\"\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||||
() -> HasCtorArguments.PARSER.apply(parser, MATCHER));
|
() -> HasCtorArguments.PARSER.apply(parser, null));
|
||||||
assertEquals("Required [vegetable]", e.getMessage());
|
assertEquals("Required [vegetable]", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,7 +136,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ "}");
|
+ "}");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
HasCtorArguments parsed = randomFrom(HasCtorArguments.PARSER_VEGETABLE_OPTIONAL, HasCtorArguments.PARSER_ALL_OPTIONAL).apply(parser,
|
HasCtorArguments parsed = randomFrom(HasCtorArguments.PARSER_VEGETABLE_OPTIONAL, HasCtorArguments.PARSER_ALL_OPTIONAL).apply(parser,
|
||||||
MATCHER);
|
null);
|
||||||
assertEquals(1, parsed.mineral);
|
assertEquals(1, parsed.mineral);
|
||||||
assertEquals("cat", parsed.animal);
|
assertEquals("cat", parsed.animal);
|
||||||
}
|
}
|
||||||
|
@ -153,7 +149,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ "}");
|
+ "}");
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
IllegalArgumentException e = expectThrows(IllegalArgumentException.class,
|
||||||
() -> randomFrom(HasCtorArguments.PARSER, HasCtorArguments.PARSER_VEGETABLE_OPTIONAL).apply(parser, MATCHER));
|
() -> randomFrom(HasCtorArguments.PARSER, HasCtorArguments.PARSER_VEGETABLE_OPTIONAL).apply(parser, null));
|
||||||
assertEquals("Required [animal]", e.getMessage());
|
assertEquals("Required [animal]", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,7 +159,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"mineral\": 1,\n"
|
+ " \"mineral\": 1,\n"
|
||||||
+ " \"vegetable\": 2\n"
|
+ " \"vegetable\": 2\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, MATCHER);
|
HasCtorArguments parsed = HasCtorArguments.PARSER_ALL_OPTIONAL.apply(parser, null);
|
||||||
assertEquals(1, parsed.mineral);
|
assertEquals(1, parsed.mineral);
|
||||||
assertEquals((Integer) 2, parsed.vegetable);
|
assertEquals((Integer) 2, parsed.vegetable);
|
||||||
}
|
}
|
||||||
|
@ -176,7 +172,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"vegetable\": 1,\n"
|
+ " \"vegetable\": 1,\n"
|
||||||
+ " \"vegetable\": 2\n"
|
+ " \"vegetable\": 2\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
Throwable e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER));
|
Throwable e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null));
|
||||||
assertEquals("[has_required_arguments] failed to parse field [vegetable]", e.getMessage());
|
assertEquals("[has_required_arguments] failed to parse field [vegetable]", e.getMessage());
|
||||||
e = e.getCause();
|
e = e.getCause();
|
||||||
assertThat(e, instanceOf(IllegalArgumentException.class));
|
assertThat(e, instanceOf(IllegalArgumentException.class));
|
||||||
|
@ -190,7 +186,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"vegetable\": 2,\n"
|
+ " \"vegetable\": 2,\n"
|
||||||
+ " \"a\": \"supercalifragilisticexpialidocious\"\n"
|
+ " \"a\": \"supercalifragilisticexpialidocious\"\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER));
|
ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null));
|
||||||
assertEquals("[has_required_arguments] failed to parse field [a]", e.getMessage());
|
assertEquals("[has_required_arguments] failed to parse field [a]", e.getMessage());
|
||||||
assertEquals(4, e.getLineNumber());
|
assertEquals(4, e.getLineNumber());
|
||||||
assertEquals("[a] must be less than 10 characters in length but was [supercalifragilisticexpialidocious]",
|
assertEquals("[a] must be less than 10 characters in length but was [supercalifragilisticexpialidocious]",
|
||||||
|
@ -204,7 +200,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"animal\": \"cat\"\n,"
|
+ " \"animal\": \"cat\"\n,"
|
||||||
+ " \"vegetable\": 2\n"
|
+ " \"vegetable\": 2\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, MATCHER));
|
ParsingException e = expectThrows(ParsingException.class, () -> randomFrom(HasCtorArguments.ALL_PARSERS).apply(parser, null));
|
||||||
assertEquals("[has_required_arguments] failed to parse field [vegetable]", e.getMessage());
|
assertEquals("[has_required_arguments] failed to parse field [vegetable]", e.getMessage());
|
||||||
assertEquals(4, e.getLineNumber());
|
assertEquals(4, e.getLineNumber());
|
||||||
e = (ParsingException) e.getCause();
|
e = (ParsingException) e.getCause();
|
||||||
|
@ -220,7 +216,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
public void testConstructorArgsMustBeConfigured() throws IOException {
|
public void testConstructorArgsMustBeConfigured() throws IOException {
|
||||||
class NoConstructorArgs {
|
class NoConstructorArgs {
|
||||||
}
|
}
|
||||||
ConstructingObjectParser<NoConstructorArgs, ParseFieldMatcherSupplier> parser = new ConstructingObjectParser<>(
|
ConstructingObjectParser<NoConstructorArgs, Void> parser = new ConstructingObjectParser<>(
|
||||||
"constructor_args_required", (a) -> new NoConstructorArgs());
|
"constructor_args_required", (a) -> new NoConstructorArgs());
|
||||||
try {
|
try {
|
||||||
parser.apply(createParser(JsonXContent.jsonXContent, "{}"), null);
|
parser.apply(createParser(JsonXContent.jsonXContent, "{}"), null);
|
||||||
|
@ -252,7 +248,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
fooSet = true;
|
fooSet = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstructingObjectParser<CalledOneTime, ParseFieldMatcherSupplier> parser = new ConstructingObjectParser<>("one_time_test",
|
ConstructingObjectParser<CalledOneTime, Void> parser = new ConstructingObjectParser<>("one_time_test",
|
||||||
(a) -> new CalledOneTime((String) a[0]));
|
(a) -> new CalledOneTime((String) a[0]));
|
||||||
parser.declareString(CalledOneTime::setFoo, new ParseField("foo"));
|
parser.declareString(CalledOneTime::setFoo, new ParseField("foo"));
|
||||||
parser.declareString(ctorArgOptional ? optionalConstructorArg() : constructorArg(), new ParseField("yeah"));
|
parser.declareString(ctorArgOptional ? optionalConstructorArg() : constructorArg(), new ParseField("yeah"));
|
||||||
|
@ -263,7 +259,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"yeah\": \"!\",\n"
|
+ " \"yeah\": \"!\",\n"
|
||||||
+ " \"foo\": \"foo\"\n"
|
+ " \"foo\": \"foo\"\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
CalledOneTime result = parser.apply(xcontent, MATCHER);
|
CalledOneTime result = parser.apply(xcontent, null);
|
||||||
assertTrue(result.fooSet);
|
assertTrue(result.fooSet);
|
||||||
|
|
||||||
// and ctor arg second just in case
|
// and ctor arg second just in case
|
||||||
|
@ -272,7 +268,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
+ " \"foo\": \"foo\",\n"
|
+ " \"foo\": \"foo\",\n"
|
||||||
+ " \"yeah\": \"!\"\n"
|
+ " \"yeah\": \"!\"\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
result = parser.apply(xcontent, MATCHER);
|
result = parser.apply(xcontent, null);
|
||||||
assertTrue(result.fooSet);
|
assertTrue(result.fooSet);
|
||||||
|
|
||||||
if (ctorArgOptional) {
|
if (ctorArgOptional) {
|
||||||
|
@ -281,7 +277,7 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
"{\n"
|
"{\n"
|
||||||
+ " \"foo\": \"foo\"\n"
|
+ " \"foo\": \"foo\"\n"
|
||||||
+ "}");
|
+ "}");
|
||||||
result = parser.apply(xcontent, MATCHER);
|
result = parser.apply(xcontent, null);
|
||||||
}
|
}
|
||||||
assertTrue(result.fooSet);
|
assertTrue(result.fooSet);
|
||||||
}
|
}
|
||||||
|
@ -298,10 +294,10 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
this.test = test;
|
this.test = test;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstructingObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ConstructingObjectParser<>("foo", true, a ->
|
ConstructingObjectParser<TestStruct, Void> objectParser = new ConstructingObjectParser<>("foo", true, a ->
|
||||||
new TestStruct((String) a[0]));
|
new TestStruct((String) a[0]));
|
||||||
objectParser.declareString(constructorArg(), new ParseField("test"));
|
objectParser.declareString(constructorArg(), new ParseField("test"));
|
||||||
TestStruct s = objectParser.apply(parser, MATCHER);
|
TestStruct s = objectParser.apply(parser, null);
|
||||||
assertEquals(s.test, "foo");
|
assertEquals(s.test, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -380,17 +376,15 @@ public class ConstructingObjectParserTests extends ESTestCase {
|
||||||
* It is normal just to declare a single PARSER but we use a couple of different parsers for testing so we have all of these. Don't
|
* It is normal just to declare a single PARSER but we use a couple of different parsers for testing so we have all of these. Don't
|
||||||
* this this style is normal just because it is in the test.
|
* this this style is normal just because it is in the test.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier> PARSER = buildParser(true, true);
|
public static final ConstructingObjectParser<HasCtorArguments, Void> PARSER = buildParser(true, true);
|
||||||
public static final ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier> PARSER_VEGETABLE_OPTIONAL = buildParser(
|
public static final ConstructingObjectParser<HasCtorArguments, Void> PARSER_VEGETABLE_OPTIONAL = buildParser(true, false);
|
||||||
true, false);
|
public static final ConstructingObjectParser<HasCtorArguments, Void> PARSER_ALL_OPTIONAL = buildParser(false, false);
|
||||||
public static final ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier> PARSER_ALL_OPTIONAL = buildParser(false,
|
public static final List<ConstructingObjectParser<HasCtorArguments, Void>> ALL_PARSERS = unmodifiableList(
|
||||||
false);
|
|
||||||
public static final List<ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier>> ALL_PARSERS = unmodifiableList(
|
|
||||||
Arrays.asList(PARSER, PARSER_VEGETABLE_OPTIONAL, PARSER_ALL_OPTIONAL));
|
Arrays.asList(PARSER, PARSER_VEGETABLE_OPTIONAL, PARSER_ALL_OPTIONAL));
|
||||||
|
|
||||||
private static ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier> buildParser(boolean animalRequired,
|
private static ConstructingObjectParser<HasCtorArguments, Void> buildParser(boolean animalRequired,
|
||||||
boolean vegetableRequired) {
|
boolean vegetableRequired) {
|
||||||
ConstructingObjectParser<HasCtorArguments, ParseFieldMatcherSupplier> parser = new ConstructingObjectParser<>(
|
ConstructingObjectParser<HasCtorArguments, Void> parser = new ConstructingObjectParser<>(
|
||||||
"has_required_arguments", a -> new HasCtorArguments((String) a[0], (Integer) a[1]));
|
"has_required_arguments", a -> new HasCtorArguments((String) a[0], (Integer) a[1]));
|
||||||
parser.declareString(animalRequired ? constructorArg() : optionalConstructorArg(), new ParseField("animal"));
|
parser.declareString(animalRequired ? constructorArg() : optionalConstructorArg(), new ParseField("animal"));
|
||||||
parser.declareInt(vegetableRequired ? constructorArg() : optionalConstructorArg(), new ParseField("vegetable"));
|
parser.declareInt(vegetableRequired ? constructorArg() : optionalConstructorArg(), new ParseField("vegetable"));
|
||||||
|
|
|
@ -19,8 +19,6 @@
|
||||||
package org.elasticsearch.common.xcontent;
|
package org.elasticsearch.common.xcontent;
|
||||||
|
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser;
|
import org.elasticsearch.common.xcontent.AbstractObjectParser.NoContextParser;
|
||||||
import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser;
|
import org.elasticsearch.common.xcontent.ObjectParser.NamedObjectParser;
|
||||||
|
@ -39,8 +37,6 @@ import static org.hamcrest.Matchers.hasSize;
|
||||||
|
|
||||||
public class ObjectParserTests extends ESTestCase {
|
public class ObjectParserTests extends ESTestCase {
|
||||||
|
|
||||||
private static final ParseFieldMatcherSupplier STRICT_PARSING = () -> ParseFieldMatcher.STRICT;
|
|
||||||
|
|
||||||
public void testBasics() throws IOException {
|
public void testBasics() throws IOException {
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||||
"{\n"
|
"{\n"
|
||||||
|
@ -60,13 +56,13 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
this.ints = ints;
|
this.ints = ints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
|
||||||
TestStruct s = new TestStruct();
|
TestStruct s = new TestStruct();
|
||||||
|
|
||||||
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
||||||
objectParser.declareInt(TestStruct::setTestNumber, new ParseField("test_number"));
|
objectParser.declareInt(TestStruct::setTestNumber, new ParseField("test_number"));
|
||||||
objectParser.declareIntArray(TestStruct::setInts, new ParseField("test_array"));
|
objectParser.declareIntArray(TestStruct::setInts, new ParseField("test_array"));
|
||||||
objectParser.parse(parser, s, STRICT_PARSING);
|
objectParser.parse(parser, s, null);
|
||||||
assertEquals(s.test, "foo");
|
assertEquals(s.test, "foo");
|
||||||
assertEquals(s.testNumber, 2);
|
assertEquals(s.testNumber, 2);
|
||||||
assertEquals(s.ints, Arrays.asList(1, 2, 3, 4));
|
assertEquals(s.ints, Arrays.asList(1, 2, 3, 4));
|
||||||
|
@ -77,12 +73,12 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNullDeclares() {
|
public void testNullDeclares() {
|
||||||
ObjectParser<Void, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<Void, Void> objectParser = new ObjectParser<>("foo");
|
||||||
Exception e = expectThrows(IllegalArgumentException.class,
|
Exception e = expectThrows(IllegalArgumentException.class,
|
||||||
() -> objectParser.declareField(null, (r, c) -> null, new ParseField("test"), ObjectParser.ValueType.STRING));
|
() -> objectParser.declareField(null, (r, c) -> null, new ParseField("test"), ObjectParser.ValueType.STRING));
|
||||||
assertEquals("[consumer] is required", e.getMessage());
|
assertEquals("[consumer] is required", e.getMessage());
|
||||||
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
||||||
(o, v) -> {}, (ContextParser<ParseFieldMatcherSupplier, Object>) null,
|
(o, v) -> {}, (ContextParser<Void, Object>) null,
|
||||||
new ParseField("test"), ObjectParser.ValueType.STRING));
|
new ParseField("test"), ObjectParser.ValueType.STRING));
|
||||||
assertEquals("[parser] is required", e.getMessage());
|
assertEquals("[parser] is required", e.getMessage());
|
||||||
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
e = expectThrows(IllegalArgumentException.class, () -> objectParser.declareField(
|
||||||
|
@ -99,17 +95,17 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
|
|
||||||
public void testObjectOrDefault() throws IOException {
|
public void testObjectOrDefault() throws IOException {
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : { \"test\": 2}}");
|
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : { \"test\": 2}}");
|
||||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
ObjectParser<StaticTestStruct, Void> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||||
objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test"));
|
objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test"));
|
||||||
objectParser.declareObjectOrDefault(StaticTestStruct::setObject, objectParser, StaticTestStruct::new, new ParseField("object"));
|
objectParser.declareObjectOrDefault(StaticTestStruct::setObject, objectParser, StaticTestStruct::new, new ParseField("object"));
|
||||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
StaticTestStruct s = objectParser.parse(parser, null);
|
||||||
assertEquals(s.object.test, 2);
|
assertEquals(s.object.test, 2);
|
||||||
parser = createParser(JsonXContent.jsonXContent, "{\"object\" : false }");
|
parser = createParser(JsonXContent.jsonXContent, "{\"object\" : false }");
|
||||||
s = objectParser.parse(parser, STRICT_PARSING);
|
s = objectParser.parse(parser, null);
|
||||||
assertNull(s.object);
|
assertNull(s.object);
|
||||||
|
|
||||||
parser = createParser(JsonXContent.jsonXContent, "{\"object\" : true }");
|
parser = createParser(JsonXContent.jsonXContent, "{\"object\" : true }");
|
||||||
s = objectParser.parse(parser, STRICT_PARSING);
|
s = objectParser.parse(parser, null);
|
||||||
assertNotNull(s.object);
|
assertNotNull(s.object);
|
||||||
assertEquals(s.object.test, 0);
|
assertEquals(s.object.test, 0);
|
||||||
|
|
||||||
|
@ -159,19 +155,14 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomParseFieldMatchSupplier implements ParseFieldMatcherSupplier {
|
class CustomParseContext {
|
||||||
|
|
||||||
public final ClassicParser parser;
|
public final ClassicParser parser;
|
||||||
|
|
||||||
CustomParseFieldMatchSupplier(ClassicParser parser) {
|
CustomParseContext(ClassicParser parser) {
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ParseFieldMatcher getParseFieldMatcher() {
|
|
||||||
return ParseFieldMatcher.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public URI parseURI(XContentParser parser) {
|
public URI parseURI(XContentParser parser) {
|
||||||
try {
|
try {
|
||||||
return this.parser.parseURI(parser);
|
return this.parser.parseURI(parser);
|
||||||
|
@ -182,10 +173,10 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
XContentParser parser = createParser(JsonXContent.jsonXContent,
|
||||||
"{\"url\" : { \"host\": \"http://foobar\", \"port\" : 80}, \"name\" : \"foobarbaz\"}");
|
"{\"url\" : { \"host\": \"http://foobar\", \"port\" : 80}, \"name\" : \"foobarbaz\"}");
|
||||||
ObjectParser<Foo, CustomParseFieldMatchSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<Foo, CustomParseContext> objectParser = new ObjectParser<>("foo");
|
||||||
objectParser.declareString(Foo::setName, new ParseField("name"));
|
objectParser.declareString(Foo::setName, new ParseField("name"));
|
||||||
objectParser.declareObjectOrDefault(Foo::setURI, (p, s) -> s.parseURI(p), () -> null, new ParseField("url"));
|
objectParser.declareObjectOrDefault(Foo::setURI, (p, s) -> s.parseURI(p), () -> null, new ParseField("url"));
|
||||||
Foo s = objectParser.parse(parser, new Foo(), new CustomParseFieldMatchSupplier(new ClassicParser()));
|
Foo s = objectParser.parse(parser, new Foo(), new CustomParseContext(new ClassicParser()));
|
||||||
assertEquals(s.uri.getHost(), "foobar");
|
assertEquals(s.uri.getHost(), "foobar");
|
||||||
assertEquals(s.uri.getPort(), 80);
|
assertEquals(s.uri.getPort(), 80);
|
||||||
assertEquals(s.name, "foobarbaz");
|
assertEquals(s.name, "foobarbaz");
|
||||||
|
@ -197,12 +188,12 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
public void setTest(int test) {
|
public void setTest(int test) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("the_parser");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("the_parser");
|
||||||
TestStruct s = new TestStruct();
|
TestStruct s = new TestStruct();
|
||||||
objectParser.declareInt(TestStruct::setTest, new ParseField("test"));
|
objectParser.declareInt(TestStruct::setTest, new ParseField("test"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
objectParser.parse(parser, s, STRICT_PARSING);
|
objectParser.parse(parser, s, null);
|
||||||
fail("numeric value expected");
|
fail("numeric value expected");
|
||||||
} catch (ParsingException ex) {
|
} catch (ParsingException ex) {
|
||||||
assertEquals(ex.getMessage(), "[the_parser] failed to parse field [test]");
|
assertEquals(ex.getMessage(), "[the_parser] failed to parse field [test]");
|
||||||
|
@ -211,7 +202,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
|
|
||||||
parser = createParser(JsonXContent.jsonXContent, "{\"not_supported_field\" : \"foo\"}");
|
parser = createParser(JsonXContent.jsonXContent, "{\"not_supported_field\" : \"foo\"}");
|
||||||
try {
|
try {
|
||||||
objectParser.parse(parser, s, STRICT_PARSING);
|
objectParser.parse(parser, s, null);
|
||||||
fail("field not supported");
|
fail("field not supported");
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
assertEquals(ex.getMessage(), "[the_parser] unknown field [not_supported_field], parser not found");
|
assertEquals(ex.getMessage(), "[the_parser] unknown field [not_supported_field], parser not found");
|
||||||
|
@ -222,11 +213,11 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
class TestStruct {
|
class TestStruct {
|
||||||
public String test;
|
public String test;
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
|
||||||
TestStruct s = new TestStruct();
|
TestStruct s = new TestStruct();
|
||||||
XContentParser parser = createParser(XContentType.JSON.xContent(), "{\"old_test\" : \"foo\"}");
|
XContentParser parser = createParser(XContentType.JSON.xContent(), "{\"old_test\" : \"foo\"}");
|
||||||
objectParser.declareField((i, v, c) -> v.test = i.text(), new ParseField("test", "old_test"), ObjectParser.ValueType.STRING);
|
objectParser.declareField((i, v, c) -> v.test = i.text(), new ParseField("test", "old_test"), ObjectParser.ValueType.STRING);
|
||||||
objectParser.parse(parser, s, () -> ParseFieldMatcher.EMPTY);
|
objectParser.parse(parser, s, null);
|
||||||
assertEquals("foo", s.test);
|
assertEquals("foo", s.test);
|
||||||
assertWarnings("Deprecated field [old_test] used, expected [test] instead");
|
assertWarnings("Deprecated field [old_test] used, expected [test] instead");
|
||||||
}
|
}
|
||||||
|
@ -236,12 +227,12 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
class TestStruct {
|
class TestStruct {
|
||||||
public String test;
|
public String test;
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
|
||||||
TestStruct s = new TestStruct();
|
TestStruct s = new TestStruct();
|
||||||
|
|
||||||
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("numeric_value"), ObjectParser.ValueType.FLOAT);
|
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("numeric_value"), ObjectParser.ValueType.FLOAT);
|
||||||
try {
|
try {
|
||||||
objectParser.parse(parser, s, STRICT_PARSING);
|
objectParser.parse(parser, s, null);
|
||||||
fail("wrong type - must be number");
|
fail("wrong type - must be number");
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
assertEquals(ex.getMessage(), "[foo] numeric_value doesn't support values of type: VALUE_BOOLEAN");
|
assertEquals(ex.getMessage(), "[foo] numeric_value doesn't support values of type: VALUE_BOOLEAN");
|
||||||
|
@ -254,40 +245,40 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
public int test;
|
public int test;
|
||||||
TestStruct object;
|
TestStruct object;
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
|
||||||
TestStruct s = new TestStruct();
|
TestStruct s = new TestStruct();
|
||||||
s.object = new TestStruct();
|
s.object = new TestStruct();
|
||||||
objectParser.declareField((i, c, x) -> c.test = i.intValue(), new ParseField("test"), ValueType.INT);
|
objectParser.declareField((i, c, x) -> c.test = i.intValue(), new ParseField("test"), ValueType.INT);
|
||||||
objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object, STRICT_PARSING), new ParseField("object"),
|
objectParser.declareField((i, c, x) -> objectParser.parse(parser, c.object, null), new ParseField("object"),
|
||||||
ValueType.OBJECT);
|
ValueType.OBJECT);
|
||||||
objectParser.parse(parser, s, STRICT_PARSING);
|
objectParser.parse(parser, s, null);
|
||||||
assertEquals(s.test, 1);
|
assertEquals(s.test, 1);
|
||||||
assertEquals(s.object.test, 2);
|
assertEquals(s.object.test, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseNestedShortcut() throws IOException {
|
public void testParseNestedShortcut() throws IOException {
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : 1, \"object\" : { \"test\": 2}}");
|
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : 1, \"object\" : { \"test\": 2}}");
|
||||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
ObjectParser<StaticTestStruct, Void> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||||
objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test"));
|
objectParser.declareInt(StaticTestStruct::setTest, new ParseField("test"));
|
||||||
objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object"));
|
objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object"));
|
||||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
StaticTestStruct s = objectParser.parse(parser, null);
|
||||||
assertEquals(s.test, 1);
|
assertEquals(s.test, 1);
|
||||||
assertEquals(s.object.test, 2);
|
assertEquals(s.object.test, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyObject() throws IOException {
|
public void testEmptyObject() throws IOException {
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : {}}");
|
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object\" : {}}");
|
||||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
ObjectParser<StaticTestStruct, Void> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||||
objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object"));
|
objectParser.declareObject(StaticTestStruct::setObject, objectParser, new ParseField("object"));
|
||||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
StaticTestStruct s = objectParser.parse(parser, null);
|
||||||
assertNotNull(s.object);
|
assertNotNull(s.object);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEmptyObjectInArray() throws IOException {
|
public void testEmptyObjectInArray() throws IOException {
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object_array\" : [{}]}");
|
XContentParser parser = createParser(JsonXContent.jsonXContent, "{\"object_array\" : [{}]}");
|
||||||
ObjectParser<StaticTestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
ObjectParser<StaticTestStruct, Void> objectParser = new ObjectParser<>("foo", StaticTestStruct::new);
|
||||||
objectParser.declareObjectArray(StaticTestStruct::setObjectArray, objectParser, new ParseField("object_array"));
|
objectParser.declareObjectArray(StaticTestStruct::setObjectArray, objectParser, new ParseField("object_array"));
|
||||||
StaticTestStruct s = objectParser.parse(parser, STRICT_PARSING);
|
StaticTestStruct s = objectParser.parse(parser, null);
|
||||||
assertNotNull(s.objectArray);
|
assertNotNull(s.objectArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,9 +313,9 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : \"FOO\" }");
|
XContentParser parser = createParser(JsonXContent.jsonXContent, "{ \"test\" : \"FOO\" }");
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
|
||||||
objectParser.declareString((struct, value) -> struct.set(TestEnum.valueOf(value)), new ParseField("test"));
|
objectParser.declareString((struct, value) -> struct.set(TestEnum.valueOf(value)), new ParseField("test"));
|
||||||
TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING);
|
TestStruct s = objectParser.parse(parser, new TestStruct(), null);
|
||||||
assertEquals(s.test, TestEnum.FOO);
|
assertEquals(s.test, TestEnum.FOO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +409,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
this.string_or_null = string_or_null;
|
this.string_or_null = string_or_null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo");
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo");
|
||||||
objectParser.declareInt(TestStruct::setInt_field, new ParseField("int_field"));
|
objectParser.declareInt(TestStruct::setInt_field, new ParseField("int_field"));
|
||||||
objectParser.declareIntArray(TestStruct::setInt_array_field, new ParseField("int_array_field"));
|
objectParser.declareIntArray(TestStruct::setInt_array_field, new ParseField("int_array_field"));
|
||||||
objectParser.declareLong(TestStruct::setLong_field, new ParseField("long_field"));
|
objectParser.declareLong(TestStruct::setLong_field, new ParseField("long_field"));
|
||||||
|
@ -432,7 +423,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
|
|
||||||
objectParser.declareStringOrNull(TestStruct::setString_or_null, new ParseField("string_or_null"));
|
objectParser.declareStringOrNull(TestStruct::setString_or_null, new ParseField("string_or_null"));
|
||||||
objectParser.declareBoolean(TestStruct::setNull_value, new ParseField("boolean_field"));
|
objectParser.declareBoolean(TestStruct::setNull_value, new ParseField("boolean_field"));
|
||||||
TestStruct parse = objectParser.parse(parser, new TestStruct(), STRICT_PARSING);
|
TestStruct parse = objectParser.parse(parser, new TestStruct(), null);
|
||||||
assertArrayEquals(parse.double_array_field.toArray(), Arrays.asList(2.1d).toArray());
|
assertArrayEquals(parse.double_array_field.toArray(), Arrays.asList(2.1d).toArray());
|
||||||
assertEquals(parse.double_field, 2.1d, 0.0d);
|
assertEquals(parse.double_field, 2.1d, 0.0d);
|
||||||
|
|
||||||
|
@ -461,7 +452,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
"{\"named\": {\n"
|
"{\"named\": {\n"
|
||||||
+ " \"a\": {}"
|
+ " \"a\": {}"
|
||||||
+ "}}");
|
+ "}}");
|
||||||
NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING);
|
NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null);
|
||||||
assertThat(h.named, hasSize(1));
|
assertThat(h.named, hasSize(1));
|
||||||
assertEquals("a", h.named.get(0).name);
|
assertEquals("a", h.named.get(0).name);
|
||||||
assertFalse(h.namedSuppliedInOrder);
|
assertFalse(h.namedSuppliedInOrder);
|
||||||
|
@ -472,7 +463,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
"{\"named\": [\n"
|
"{\"named\": [\n"
|
||||||
+ " {\"a\": {}}"
|
+ " {\"a\": {}}"
|
||||||
+ "]}");
|
+ "]}");
|
||||||
NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING);
|
NamedObjectHolder h = NamedObjectHolder.PARSER.apply(parser, null);
|
||||||
assertThat(h.named, hasSize(1));
|
assertThat(h.named, hasSize(1));
|
||||||
assertEquals("a", h.named.get(0).name);
|
assertEquals("a", h.named.get(0).name);
|
||||||
assertTrue(h.namedSuppliedInOrder);
|
assertTrue(h.namedSuppliedInOrder);
|
||||||
|
@ -483,7 +474,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
"{\"named\": [\n"
|
"{\"named\": [\n"
|
||||||
+ " {\"a\": {}, \"b\": {}}"
|
+ " {\"a\": {}, \"b\": {}}"
|
||||||
+ "]}");
|
+ "]}");
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING));
|
ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null));
|
||||||
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[named] can be a single object with any number of fields or an array where each entry is an object with a single field",
|
"[named] can be a single object with any number of fields or an array where each entry is an object with a single field",
|
||||||
|
@ -495,7 +486,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
"{\"named\": [\n"
|
"{\"named\": [\n"
|
||||||
+ " {}"
|
+ " {}"
|
||||||
+ "]}");
|
+ "]}");
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING));
|
ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null));
|
||||||
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[named] can be a single object with any number of fields or an array where each entry is an object with a single field",
|
"[named] can be a single object with any number of fields or an array where each entry is an object with a single field",
|
||||||
|
@ -507,7 +498,7 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
"{\"named\": [\n"
|
"{\"named\": [\n"
|
||||||
+ " \"junk\""
|
+ " \"junk\""
|
||||||
+ "]}");
|
+ "]}");
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, STRICT_PARSING));
|
ParsingException e = expectThrows(ParsingException.class, () -> NamedObjectHolder.PARSER.apply(parser, null));
|
||||||
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[named] can be a single object with any number of fields or an array where each entry is an object with a single field",
|
"[named] can be a single object with any number of fields or an array where each entry is an object with a single field",
|
||||||
|
@ -521,12 +512,12 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
+ "]}");
|
+ "]}");
|
||||||
|
|
||||||
// Create our own parser for this test so we can disable support for the "ordered" mode specified by the array above
|
// Create our own parser for this test so we can disable support for the "ordered" mode specified by the array above
|
||||||
ObjectParser<NamedObjectHolder, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("named_object_holder",
|
ObjectParser<NamedObjectHolder, Void> objectParser = new ObjectParser<>("named_object_holder",
|
||||||
NamedObjectHolder::new);
|
NamedObjectHolder::new);
|
||||||
objectParser.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, new ParseField("named"));
|
objectParser.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, new ParseField("named"));
|
||||||
|
|
||||||
// Now firing the xml through it fails
|
// Now firing the xml through it fails
|
||||||
ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, STRICT_PARSING));
|
ParsingException e = expectThrows(ParsingException.class, () -> objectParser.apply(parser, null));
|
||||||
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
assertEquals("[named_object_holder] failed to parse field [named]", e.getMessage());
|
||||||
assertEquals("[named] doesn't support arrays. Use a single object with multiple fields.", e.getCause().getMessage());
|
assertEquals("[named] doesn't support arrays. Use a single object with multiple fields.", e.getCause().getMessage());
|
||||||
}
|
}
|
||||||
|
@ -545,9 +536,9 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
class TestStruct {
|
class TestStruct {
|
||||||
public String test;
|
public String test;
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", true, null);
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo", true, null);
|
||||||
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
||||||
TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING);
|
TestStruct s = objectParser.parse(parser, new TestStruct(), null);
|
||||||
assertEquals(s.test, "foo");
|
assertEquals(s.test, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -569,9 +560,9 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
class TestStruct {
|
class TestStruct {
|
||||||
public String test;
|
public String test;
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", true, null);
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo", true, null);
|
||||||
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
||||||
TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING);
|
TestStruct s = objectParser.parse(parser, new TestStruct(), null);
|
||||||
assertEquals(s.test, "foo");
|
assertEquals(s.test, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -596,14 +587,14 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
class TestStruct {
|
class TestStruct {
|
||||||
public String test;
|
public String test;
|
||||||
}
|
}
|
||||||
ObjectParser<TestStruct, ParseFieldMatcherSupplier> objectParser = new ObjectParser<>("foo", true, null);
|
ObjectParser<TestStruct, Void> objectParser = new ObjectParser<>("foo", true, null);
|
||||||
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
objectParser.declareField((i, c, x) -> c.test = i.text(), new ParseField("test"), ObjectParser.ValueType.STRING);
|
||||||
TestStruct s = objectParser.parse(parser, new TestStruct(), STRICT_PARSING);
|
TestStruct s = objectParser.parse(parser, new TestStruct(), null);
|
||||||
assertEquals(s.test, "foo");
|
assertEquals(s.test, "foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
static class NamedObjectHolder {
|
static class NamedObjectHolder {
|
||||||
public static final ObjectParser<NamedObjectHolder, ParseFieldMatcherSupplier> PARSER = new ObjectParser<>("named_object_holder",
|
public static final ObjectParser<NamedObjectHolder, Void> PARSER = new ObjectParser<>("named_object_holder",
|
||||||
NamedObjectHolder::new);
|
NamedObjectHolder::new);
|
||||||
static {
|
static {
|
||||||
PARSER.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, NamedObjectHolder::keepNamedInOrder,
|
PARSER.declareNamedObjects(NamedObjectHolder::setNamed, NamedObject.PARSER, NamedObjectHolder::keepNamedInOrder,
|
||||||
|
@ -623,11 +614,11 @@ public class ObjectParserTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NamedObject {
|
public static class NamedObject {
|
||||||
public static final NamedObjectParser<NamedObject, ParseFieldMatcherSupplier> PARSER;
|
public static final NamedObjectParser<NamedObject, Void> PARSER;
|
||||||
static {
|
static {
|
||||||
ObjectParser<NamedObject, ParseFieldMatcherSupplier> parser = new ObjectParser<>("named");
|
ObjectParser<NamedObject, Void> parser = new ObjectParser<>("named");
|
||||||
parser.declareInt(NamedObject::setFoo, new ParseField("foo"));
|
parser.declareInt(NamedObject::setFoo, new ParseField("foo"));
|
||||||
PARSER = (XContentParser p, ParseFieldMatcherSupplier v, String name) -> parser.parse(p, new NamedObject(name), STRICT_PARSING);
|
PARSER = (XContentParser p, Void v, String name) -> parser.parse(p, new NamedObject(name), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.search.aggregations.bucket.histogram;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.StreamInput;
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||||||
|
@ -174,7 +173,7 @@ public class ExtendedBoundsTests extends ESTestCase {
|
||||||
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
|
assertThat(token, equalTo(XContentParser.Token.FIELD_NAME));
|
||||||
assertThat(in.currentName(), equalTo(ExtendedBounds.EXTENDED_BOUNDS_FIELD.getPreferredName()));
|
assertThat(in.currentName(), equalTo(ExtendedBounds.EXTENDED_BOUNDS_FIELD.getPreferredName()));
|
||||||
|
|
||||||
ExtendedBounds read = ExtendedBounds.PARSER.apply(in, () -> ParseFieldMatcher.STRICT);
|
ExtendedBounds read = ExtendedBounds.PARSER.apply(in, null);
|
||||||
assertEquals(orig, read);
|
assertEquals(orig, read);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("Error parsing [" + out.bytes().utf8ToString() + "]", e);
|
throw new Exception("Error parsing [" + out.bytes().utf8ToString() + "]", e);
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
package org.elasticsearch.tasks;
|
package org.elasticsearch.tasks;
|
||||||
|
|
||||||
import org.elasticsearch.client.Requests;
|
import org.elasticsearch.client.Requests;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
|
@ -67,7 +66,7 @@ public class TaskResultTests extends ESTestCase {
|
||||||
result.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
result.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||||
try (XContentBuilder shuffled = shuffleXContent(builder);
|
try (XContentBuilder shuffled = shuffleXContent(builder);
|
||||||
XContentParser parser = createParser(shuffled)) {
|
XContentParser parser = createParser(shuffled)) {
|
||||||
read = TaskResult.PARSER.apply(parser, () -> ParseFieldMatcher.STRICT);
|
read = TaskResult.PARSER.apply(parser, null);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new IOException("Error processing [" + result + "]", e);
|
throw new IOException("Error processing [" + result + "]", e);
|
||||||
|
|
|
@ -22,7 +22,6 @@ package org.elasticsearch.index.reindex;
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.action.search.SearchRequest;
|
import org.elasticsearch.action.search.SearchRequest;
|
||||||
import org.elasticsearch.client.node.NodeClient;
|
import org.elasticsearch.client.node.NodeClient;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.rest.RestController;
|
import org.elasticsearch.rest.RestController;
|
||||||
|
@ -66,7 +65,7 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
|
||||||
|
|
||||||
Map<String, Consumer<Object>> consumers = new HashMap<>();
|
Map<String, Consumer<Object>> consumers = new HashMap<>();
|
||||||
consumers.put("conflicts", o -> internal.setConflicts((String) o));
|
consumers.put("conflicts", o -> internal.setConflicts((String) o));
|
||||||
consumers.put("script", o -> internal.setScript(parseScript((Map<String, Object>)o, parseFieldMatcher)));
|
consumers.put("script", o -> internal.setScript(parseScript((Map<String, Object>)o)));
|
||||||
|
|
||||||
parseInternalRequest(internal, request, consumers);
|
parseInternalRequest(internal, request, consumers);
|
||||||
|
|
||||||
|
@ -75,7 +74,7 @@ public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler<Upda
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
static Script parseScript(Map<String, Object> config, ParseFieldMatcher parseFieldMatcher) {
|
private static Script parseScript(Map<String, Object> config) {
|
||||||
String script = null;
|
String script = null;
|
||||||
ScriptType type = null;
|
ScriptType type = null;
|
||||||
String lang = DEFAULT_SCRIPT_LANG;
|
String lang = DEFAULT_SCRIPT_LANG;
|
||||||
|
|
|
@ -21,7 +21,6 @@ package org.elasticsearch.index.reindex.remote;
|
||||||
|
|
||||||
import org.elasticsearch.Version;
|
import org.elasticsearch.Version;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
|
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
|
||||||
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
|
||||||
|
@ -55,7 +54,7 @@ final class RemoteResponseParsers {
|
||||||
/**
|
/**
|
||||||
* Parser for an individual {@code hit} element.
|
* Parser for an individual {@code hit} element.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<BasicHit, ParseFieldMatcherSupplier> HIT_PARSER =
|
public static final ConstructingObjectParser<BasicHit, Void> HIT_PARSER =
|
||||||
new ConstructingObjectParser<>("hit", true, a -> {
|
new ConstructingObjectParser<>("hit", true, a -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
String index = (String) a[i++];
|
String index = (String) a[i++];
|
||||||
|
@ -93,7 +92,7 @@ final class RemoteResponseParsers {
|
||||||
String routing;
|
String routing;
|
||||||
String parent;
|
String parent;
|
||||||
}
|
}
|
||||||
ObjectParser<Fields, ParseFieldMatcherSupplier> fieldsParser = new ObjectParser<>("fields", Fields::new);
|
ObjectParser<Fields, Void> fieldsParser = new ObjectParser<>("fields", Fields::new);
|
||||||
HIT_PARSER.declareObject((hit, fields) -> {
|
HIT_PARSER.declareObject((hit, fields) -> {
|
||||||
hit.setRouting(fields.routing);
|
hit.setRouting(fields.routing);
|
||||||
hit.setParent(fields.parent);
|
hit.setParent(fields.parent);
|
||||||
|
@ -106,7 +105,7 @@ final class RemoteResponseParsers {
|
||||||
/**
|
/**
|
||||||
* Parser for the {@code hits} element. Parsed to an array of {@code [total (Long), hits (List<Hit>)]}.
|
* Parser for the {@code hits} element. Parsed to an array of {@code [total (Long), hits (List<Hit>)]}.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<Object[], ParseFieldMatcherSupplier> HITS_PARSER =
|
public static final ConstructingObjectParser<Object[], Void> HITS_PARSER =
|
||||||
new ConstructingObjectParser<>("hits", true, a -> a);
|
new ConstructingObjectParser<>("hits", true, a -> a);
|
||||||
static {
|
static {
|
||||||
HITS_PARSER.declareLong(constructorArg(), new ParseField("total"));
|
HITS_PARSER.declareLong(constructorArg(), new ParseField("total"));
|
||||||
|
@ -116,7 +115,7 @@ final class RemoteResponseParsers {
|
||||||
/**
|
/**
|
||||||
* Parser for {@code failed} shards in the {@code _shards} elements.
|
* Parser for {@code failed} shards in the {@code _shards} elements.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<SearchFailure, ParseFieldMatcherSupplier> SEARCH_FAILURE_PARSER =
|
public static final ConstructingObjectParser<SearchFailure, Void> SEARCH_FAILURE_PARSER =
|
||||||
new ConstructingObjectParser<>("failure", true, a -> {
|
new ConstructingObjectParser<>("failure", true, a -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
String index = (String) a[i++];
|
String index = (String) a[i++];
|
||||||
|
@ -149,7 +148,7 @@ final class RemoteResponseParsers {
|
||||||
* Parser for the {@code _shards} element. Throws everything out except the errors array if there is one. If there isn't one then it
|
* Parser for the {@code _shards} element. Throws everything out except the errors array if there is one. If there isn't one then it
|
||||||
* parses to an empty list.
|
* parses to an empty list.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<List<Throwable>, ParseFieldMatcherSupplier> SHARDS_PARSER =
|
public static final ConstructingObjectParser<List<Throwable>, Void> SHARDS_PARSER =
|
||||||
new ConstructingObjectParser<>("_shards", true, a -> {
|
new ConstructingObjectParser<>("_shards", true, a -> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Throwable> failures = (List<Throwable>) a[0];
|
List<Throwable> failures = (List<Throwable>) a[0];
|
||||||
|
@ -160,7 +159,7 @@ final class RemoteResponseParsers {
|
||||||
SHARDS_PARSER.declareObjectArray(optionalConstructorArg(), SEARCH_FAILURE_PARSER, new ParseField("failures"));
|
SHARDS_PARSER.declareObjectArray(optionalConstructorArg(), SEARCH_FAILURE_PARSER, new ParseField("failures"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final ConstructingObjectParser<Response, ParseFieldMatcherSupplier> RESPONSE_PARSER =
|
public static final ConstructingObjectParser<Response, Void> RESPONSE_PARSER =
|
||||||
new ConstructingObjectParser<>("search_response", true, a -> {
|
new ConstructingObjectParser<>("search_response", true, a -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
Throwable catastrophicFailure = (Throwable) a[i++];
|
Throwable catastrophicFailure = (Throwable) a[i++];
|
||||||
|
@ -199,9 +198,9 @@ final class RemoteResponseParsers {
|
||||||
* Collects stuff about Throwables and attempts to rebuild them.
|
* Collects stuff about Throwables and attempts to rebuild them.
|
||||||
*/
|
*/
|
||||||
public static class ThrowableBuilder {
|
public static class ThrowableBuilder {
|
||||||
public static final BiFunction<XContentParser, ParseFieldMatcherSupplier, Throwable> PARSER;
|
public static final BiFunction<XContentParser, Void, Throwable> PARSER;
|
||||||
static {
|
static {
|
||||||
ObjectParser<ThrowableBuilder, ParseFieldMatcherSupplier> parser = new ObjectParser<>("reason", true, ThrowableBuilder::new);
|
ObjectParser<ThrowableBuilder, Void> parser = new ObjectParser<>("reason", true, ThrowableBuilder::new);
|
||||||
PARSER = parser.andThen(ThrowableBuilder::build);
|
PARSER = parser.andThen(ThrowableBuilder::build);
|
||||||
parser.declareString(ThrowableBuilder::setType, new ParseField("type"));
|
parser.declareString(ThrowableBuilder::setType, new ParseField("type"));
|
||||||
parser.declareString(ThrowableBuilder::setReason, new ParseField("reason"));
|
parser.declareString(ThrowableBuilder::setReason, new ParseField("reason"));
|
||||||
|
@ -265,10 +264,10 @@ final class RemoteResponseParsers {
|
||||||
/**
|
/**
|
||||||
* Parses the main action to return just the {@linkplain Version} that it returns. We throw everything else out.
|
* Parses the main action to return just the {@linkplain Version} that it returns. We throw everything else out.
|
||||||
*/
|
*/
|
||||||
public static final ConstructingObjectParser<Version, ParseFieldMatcherSupplier> MAIN_ACTION_PARSER = new ConstructingObjectParser<>(
|
public static final ConstructingObjectParser<Version, Void> MAIN_ACTION_PARSER = new ConstructingObjectParser<>(
|
||||||
"/", true, a -> (Version) a[0]);
|
"/", true, a -> (Version) a[0]);
|
||||||
static {
|
static {
|
||||||
ConstructingObjectParser<Version, ParseFieldMatcherSupplier> versionParser = new ConstructingObjectParser<>(
|
ConstructingObjectParser<Version, Void> versionParser = new ConstructingObjectParser<>(
|
||||||
"version", true, a -> Version.fromString((String) a[0]));
|
"version", true, a -> Version.fromString((String) a[0]));
|
||||||
versionParser.declareString(constructorArg(), new ParseField("number"));
|
versionParser.declareString(constructorArg(), new ParseField("number"));
|
||||||
MAIN_ACTION_PARSER.declareObject(constructorArg(), versionParser, new ParseField("version"));
|
MAIN_ACTION_PARSER.declareObject(constructorArg(), versionParser, new ParseField("version"));
|
||||||
|
|
|
@ -34,8 +34,6 @@ import org.elasticsearch.client.ResponseException;
|
||||||
import org.elasticsearch.client.ResponseListener;
|
import org.elasticsearch.client.ResponseListener;
|
||||||
import org.elasticsearch.client.RestClient;
|
import org.elasticsearch.client.RestClient;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
|
||||||
import org.elasticsearch.common.ParseFieldMatcherSupplier;
|
|
||||||
import org.elasticsearch.common.ParsingException;
|
import org.elasticsearch.common.ParsingException;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
|
@ -142,7 +140,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> void execute(String method, String uri, Map<String, String> params, HttpEntity entity,
|
private <T> void execute(String method, String uri, Map<String, String> params, HttpEntity entity,
|
||||||
BiFunction<XContentParser, ParseFieldMatcherSupplier, T> parser, Consumer<? super T> listener) {
|
BiFunction<XContentParser, Void, T> parser, Consumer<? super T> listener) {
|
||||||
// Preserve the thread context so headers survive after the call
|
// Preserve the thread context so headers survive after the call
|
||||||
ThreadContext.StoredContext ctx = threadPool.getThreadContext().newStoredContext();
|
ThreadContext.StoredContext ctx = threadPool.getThreadContext().newStoredContext();
|
||||||
class RetryHelper extends AbstractRunnable {
|
class RetryHelper extends AbstractRunnable {
|
||||||
|
@ -176,7 +174,7 @@ public class RemoteScrollableHitSource extends ScrollableHitSource {
|
||||||
// EMPTY is safe here because we don't call namedObject
|
// EMPTY is safe here because we don't call namedObject
|
||||||
try (XContentParser xContentParser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY,
|
try (XContentParser xContentParser = xContentType.xContent().createParser(NamedXContentRegistry.EMPTY,
|
||||||
content)) {
|
content)) {
|
||||||
parsedResponse = parser.apply(xContentParser, () -> ParseFieldMatcher.STRICT);
|
parsedResponse = parser.apply(xContentParser, null);
|
||||||
} catch (ParsingException e) {
|
} catch (ParsingException e) {
|
||||||
/* Because we're streaming the response we can't get a copy of it here. The best we can do is hint that it
|
/* Because we're streaming the response we can't get a copy of it here. The best we can do is hint that it
|
||||||
* is totally wrong and we're probably not talking to Elasticsearch. */
|
* is totally wrong and we're probably not talking to Elasticsearch. */
|
||||||
|
|
Loading…
Reference in New Issue