Handle core moving some methods around

We're trying to move all the XContentParser creation into
`RestRequest`.

Original commit: elastic/x-pack-elasticsearch@87c05c4a9a
This commit is contained in:
Nik Everett 2016-12-07 19:09:25 -05:00
parent e321337d4c
commit f6cb60204a
3 changed files with 27 additions and 30 deletions

View File

@ -5,37 +5,34 @@
*/ */
package org.elasticsearch.xpack.graph.rest.action; package org.elasticsearch.xpack.graph.rest.action;
import static org.elasticsearch.rest.RestRequest.Method.GET; import org.elasticsearch.ElasticsearchParseException;
import static org.elasticsearch.rest.RestRequest.Method.POST; import org.elasticsearch.action.support.IndicesOptions;
import static org.elasticsearch.xpack.graph.action.GraphExploreAction.INSTANCE; import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.XPackClient;
import org.elasticsearch.xpack.graph.action.GraphExploreRequest;
import org.elasticsearch.xpack.graph.action.GraphExploreRequest.TermBoost;
import org.elasticsearch.xpack.graph.action.Hop;
import org.elasticsearch.xpack.graph.action.VertexRequest;
import org.elasticsearch.xpack.rest.XPackRestHandler;
import java.io.IOException; import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
import org.elasticsearch.ElasticsearchParseException; import static org.elasticsearch.rest.RestRequest.Method.GET;
import org.elasticsearch.action.support.IndicesOptions; import static org.elasticsearch.rest.RestRequest.Method.POST;
import org.elasticsearch.common.ParseField; import static org.elasticsearch.xpack.graph.action.GraphExploreAction.INSTANCE;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestActions;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.xpack.XPackClient;
import org.elasticsearch.xpack.graph.action.GraphExploreRequest;
import org.elasticsearch.xpack.graph.action.Hop;
import org.elasticsearch.xpack.graph.action.VertexRequest;
import org.elasticsearch.xpack.graph.action.GraphExploreRequest.TermBoost;
import org.elasticsearch.xpack.rest.XPackRestHandler;
/** /**
* @see GraphExploreRequest * @see GraphExploreRequest
@ -88,14 +85,13 @@ public class RestGraphAction extends XPackRestHandler {
if (request.hasParam(TIMEOUT_FIELD.getPreferredName())) { if (request.hasParam(TIMEOUT_FIELD.getPreferredName())) {
graphRequest.timeout(request.paramAsTime(TIMEOUT_FIELD.getPreferredName(), null)); graphRequest.timeout(request.paramAsTime(TIMEOUT_FIELD.getPreferredName(), null));
} }
if (!RestActions.hasBodyContent(request)) { if (false == request.hasContentOrSourceParam()) {
throw new ElasticsearchParseException("Body missing for graph request"); throw new ElasticsearchParseException("Body missing for graph request");
} }
BytesReference qBytes = RestActions.getRestContent(request);
Hop currentHop = graphRequest.createNextHop(null); Hop currentHop = graphRequest.createNextHop(null);
try(XContentParser parser = XContentFactory.xContent(qBytes).createParser(qBytes)) { try (XContentParser parser = request.contentOrSourceParamParser()) {
QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher); QueryParseContext context = new QueryParseContext(indicesQueriesRegistry, parser, parseFieldMatcher);
XContentParser.Token token = parser.nextToken(); XContentParser.Token token = parser.nextToken();

View File

@ -59,7 +59,7 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler {
throw new IllegalArgumentException("no [" + INTERVAL + "] for monitoring bulk request"); throw new IllegalArgumentException("no [" + INTERVAL + "] for monitoring bulk request");
} }
if (!RestActions.hasBodyContent(request)) { if (false == request.hasContentOrSourceParam()) {
throw new ElasticsearchParseException("no body content for monitoring bulk request"); throw new ElasticsearchParseException("no body content for monitoring bulk request");
} }

View File

@ -8,6 +8,7 @@ package org.elasticsearch.xpack.security.transport;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.DestructiveOperations; import org.elasticsearch.action.support.DestructiveOperations;
import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.common.CheckedConsumer;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.license.XPackLicenseState;
@ -213,7 +214,7 @@ public class SecurityServerTransportInterceptor implements TransportInterceptor
assert filter != null; assert filter != null;
final Thread executingThread = Thread.currentThread(); final Thread executingThread = Thread.currentThread();
ActionListener.CheckedConsumer<Void> consumer = (x) -> { CheckedConsumer<Void, Exception> consumer = (x) -> {
final Executor executor; final Executor executor;
if (executingThread == Thread.currentThread()) { if (executingThread == Thread.currentThread()) {
// only fork off if we get called on another thread this means we moved to // only fork off if we get called on another thread this means we moved to