Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 771b4e1
Author: jaymode <jay@elastic.co>
Date:   Thu Feb 6 14:41:36 2020 -0700

    fix duplicated api

commit 94f1124
Author: jaymode <jay@elastic.co>
Date:   Thu Feb 6 14:24:01 2020 -0700

    update javadoc

commit 7c14750
Merge: 171e368 f21b641
Author: jaymode <jay@elastic.co>
Date:   Thu Feb 6 14:21:00 2020 -0700

    Merge branch 'master' into rest_handler_safe_register

commit 171e368
Author: jaymode <jay@elastic.co>
Date:   Thu Feb 6 14:20:28 2020 -0700

    refactor to routes

commit 263e2d2
Author: jaymode <jay@elastic.co>
Date:   Wed Feb 5 11:44:24 2020 -0700

    fix inference api

commit 9167512
Author: jaymode <jay@elastic.co>
Date:   Wed Feb 5 10:51:34 2020 -0700

    fixes

commit 2a1d841
Author: jaymode <jay@elastic.co>
Date:   Tue Feb 4 21:18:39 2020 -0700

    RestHandlers declare handled methods and paths

    This commit changes how RestHandlers are registered with the
    RestController so that a RestHandler no longer needs to register itself
    with the RestController. Instead the RestHandler interface has new
    methods which when called provide information about the method and path
    combinations that are handled by the handler including any deprecated
    and/or replaced combinations.

    This change also makes the publication of RestHandlers safe since they
    no longer publish a reference to themselves within their constructors.

    Closes elastic#51622
  • Loading branch information
jaymode committed Feb 6, 2020
1 parent f21b641 commit be64008
Show file tree
Hide file tree
Showing 371 changed files with 3,909 additions and 2,047 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(
new RestNoopBulkAction(restController),
new RestNoopSearchAction(restController));
new RestNoopBulkAction(),
new RestNoopSearchAction());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,28 @@
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;

import java.io.IOException;
import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.POST;
import static org.elasticsearch.rest.RestRequest.Method.PUT;
import static org.elasticsearch.rest.RestStatus.OK;

public class RestNoopBulkAction extends BaseRestHandler {

public RestNoopBulkAction(RestController controller) {
controller.registerHandler(POST, "/_noop_bulk", this);
controller.registerHandler(PUT, "/_noop_bulk", this);
controller.registerHandler(POST, "/{index}/_noop_bulk", this);
controller.registerHandler(PUT, "/{index}/_noop_bulk", this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_noop_bulk", POST),
new Route("/_noop_bulk", PUT),
new Route("/{index}/_noop_bulk", POST),
new Route("/{index}/_noop_bulk", PUT)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,25 @@
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestStatusToXContentListener;

import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;

public class RestNoopSearchAction extends BaseRestHandler {

public RestNoopSearchAction(RestController controller) {
controller.registerHandler(GET, "/_noop_search", this);
controller.registerHandler(POST, "/_noop_search", this);
controller.registerHandler(GET, "/{index}/_noop_search", this);
controller.registerHandler(POST, "/{index}/_noop_search", this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_noop_search", GET),
new Route("/_noop_search", POST),
new Route("/{index}/_noop_search", GET),
new Route("/{index}/_noop_search", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import static java.util.Collections.singletonList;
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
import static org.elasticsearch.rest.RestRequest.Method.GET;

Expand Down Expand Up @@ -116,8 +117,10 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li
}

public static class RestAction extends BaseRestHandler {
RestAction(RestController controller) {
controller.registerHandler(GET, "/_ingest/processor/grok", this);

@Override
public List<Route> handledRoutes() {
return singletonList(new Route("/_ingest/processor/grok", GET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(new GrokProcessorGetAction.RestAction(restController));
return Collections.singletonList(new GrokProcessorGetAction.RestAction());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(
new RestSearchTemplateAction(restController),
new RestMultiSearchTemplateAction(settings, restController),
new RestRenderSearchTemplateAction(restController));
new RestSearchTemplateAction(),
new RestMultiSearchTemplateAction(settings),
new RestRenderSearchTemplateAction());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.rest.action.search.RestSearchAction;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;

Expand All @@ -43,21 +44,25 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler {

static {
final Set<String> responseParams = new HashSet<>(
Arrays.asList(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM)
asList(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM)
);
RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams);
}


private final boolean allowExplicitIndex;

public RestMultiSearchTemplateAction(Settings settings, RestController controller) {
public RestMultiSearchTemplateAction(Settings settings) {
this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings);
}

controller.registerHandler(GET, "/_msearch/template", this);
controller.registerHandler(POST, "/_msearch/template", this);
controller.registerHandler(GET, "/{index}/_msearch/template", this);
controller.registerHandler(POST, "/{index}/_msearch/template", this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_msearch/template", GET),
new Route("/_msearch/template", POST),
new Route("/{index}/_msearch/template", GET),
new Route("/{index}/_msearch/template", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,27 @@
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.ScriptType;

import java.io.IOException;
import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;

public class RestRenderSearchTemplateAction extends BaseRestHandler {

public RestRenderSearchTemplateAction(RestController controller) {
controller.registerHandler(GET, "/_render/template", this);
controller.registerHandler(POST, "/_render/template", this);
controller.registerHandler(GET, "/_render/template/{id}", this);
controller.registerHandler(POST, "/_render/template/{id}", this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_render/template", GET),
new Route("/_render/template", POST),
new Route("/_render/template/{id}", GET),
new Route("/_render/template/{id}", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
import org.elasticsearch.rest.action.search.RestSearchAction;
Expand All @@ -32,8 +31,11 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;

Expand All @@ -46,11 +48,13 @@ public class RestSearchTemplateAction extends BaseRestHandler {
RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams);
}

public RestSearchTemplateAction(RestController controller) {
controller.registerHandler(GET, "/_search/template", this);
controller.registerHandler(POST, "/_search/template", this);
controller.registerHandler(GET, "/{index}/_search/template", this);
controller.registerHandler(POST, "/{index}/_search/template", this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_search/template", GET),
new Route("/_search/template", POST),
new Route("/{index}/_search/template", GET),
new Route("/{index}/_search/template", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
List<RestHandler> handlers = new ArrayList<>();
handlers.add(new PainlessExecuteAction.RestAction(restController));
handlers.add(new PainlessContextAction.RestAction(restController));
handlers.add(new PainlessExecuteAction.RestAction());
handlers.add(new PainlessContextAction.RestAction());
return handlers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import org.elasticsearch.painless.PainlessScriptEngine;
import org.elasticsearch.painless.lookup.PainlessLookup;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.ScriptContext;
Expand All @@ -52,6 +51,7 @@
import java.util.Objects;
import java.util.stream.Collectors;

import static java.util.Collections.singletonList;
import static org.elasticsearch.rest.RestRequest.Method.GET;

/**
Expand Down Expand Up @@ -194,8 +194,9 @@ protected void doExecute(Task task, Request request, ActionListener<Response> li

public static class RestAction extends BaseRestHandler {

public RestAction(RestController controller) {
controller.registerHandler(GET, "/_scripts/painless/_context", this);
@Override
public List<Route> handledRoutes() {
return singletonList(new Route("/_scripts/painless/_context", GET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import org.elasticsearch.index.shard.ShardId;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.FilterScript;
Expand All @@ -81,9 +80,12 @@
import org.elasticsearch.transport.TransportService;

import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.action.ValidateActions.addValidationError;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;
Expand Down Expand Up @@ -564,9 +566,11 @@ private static Response prepareRamIndex(Request request,

public static class RestAction extends BaseRestHandler {

public RestAction(RestController controller) {
controller.registerHandler(GET, "/_scripts/painless/_execute", this);
controller.registerHandler(POST, "/_scripts/painless/_execute", this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/_scripts/painless/_execute", GET),
new Route("/_scripts/painless/_execute", POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;

Expand All @@ -50,7 +51,7 @@ public class RankEvalPlugin extends Plugin implements ActionPlugin {
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(new RestRankEvalAction(restController));
return Collections.singletonList(new RestRankEvalAction());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.action.RestToXContentListener;

import java.io.IOException;
import java.util.List;

import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static org.elasticsearch.rest.RestRequest.Method.GET;
import static org.elasticsearch.rest.RestRequest.Method.POST;

Expand Down Expand Up @@ -90,11 +92,13 @@ public class RestRankEvalAction extends BaseRestHandler {

public static String ENDPOINT = "_rank_eval";

public RestRankEvalAction(RestController controller) {
controller.registerHandler(GET, "/" + ENDPOINT, this);
controller.registerHandler(POST, "/" + ENDPOINT, this);
controller.registerHandler(GET, "/{index}/" + ENDPOINT, this);
controller.registerHandler(POST, "/{index}/" + ENDPOINT, this);
@Override
public List<Route> handledRoutes() {
return unmodifiableList(asList(
new Route("/" + ENDPOINT, GET),
new Route("/" + ENDPOINT, POST),
new Route("/{index}/" + ENDPOINT, GET),
new Route("/{index}/" + ENDPOINT, POST)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ public List<RestHandler> getRestHandlers(Settings settings, RestController restC
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(
new RestReindexAction(restController),
new RestUpdateByQueryAction(restController),
new RestDeleteByQueryAction(restController),
new RestRethrottleAction(restController, nodesInCluster));
new RestReindexAction(),
new RestUpdateByQueryAction(),
new RestDeleteByQueryAction(),
new RestRethrottleAction(nodesInCluster));
}

@Override
Expand Down
Loading

0 comments on commit be64008

Please sign in to comment.