Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RestHandlers declare handled routes #51950

Merged
merged 15 commits into from
Feb 10, 2020
  •  
  •  
  •  
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 @@ -27,29 +27,36 @@
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.Requests;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.index.shard.ShardId;
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.RestRequest.Method;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestBuilderListener;

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

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 Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_noop_bulk", unmodifiableList(asList(POST, PUT)))
.put("/{index}/_noop_bulk", unmodifiableList(asList(POST, PUT)))
.map());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or:

diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java
index d6c0ef736e3..b0d17af1846 100644
--- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java
+++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java
@@ -27,7 +27,6 @@ import org.elasticsearch.action.support.ActiveShardCount;
 import org.elasticsearch.action.update.UpdateResponse;
 import org.elasticsearch.client.Requests;
 import org.elasticsearch.client.node.NodeClient;
-import org.elasticsearch.common.collect.MapBuilder;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.rest.BaseRestHandler;
@@ -39,12 +38,9 @@ import org.elasticsearch.rest.RestResponse;
 import org.elasticsearch.rest.action.RestBuilderListener;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-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;
@@ -53,10 +49,9 @@ public class RestNoopBulkAction extends BaseRestHandler {
 
     @Override
     public Map<String, List<Method>> handledMethodsAndPaths() {
-        return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
-            .put("/_noop_bulk", unmodifiableList(asList(POST, PUT)))
-            .put("/{index}/_noop_bulk", unmodifiableList(asList(POST, PUT)))
-            .map());
+        return Map.of(
+            "/_noop_bulk", List.of(POST, PUT),
+            "/{index}/_noop_bulk", List.of(POST, PUT));
     }
 
     @Override

I had been working to remove uses of MapBuilder in master, in light of the new JDK APIs for map construction.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I wonder if we should take this farther, and instead of using a simple datatype we formalize the notion of a route and make that part of the API:

diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java
index d6c0ef736e3..1e70bc9f15b 100644
--- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java
+++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/bulk/RestNoopBulkAction.java
@@ -27,7 +27,6 @@ import org.elasticsearch.action.support.ActiveShardCount;
 import org.elasticsearch.action.update.UpdateResponse;
 import org.elasticsearch.client.Requests;
 import org.elasticsearch.client.node.NodeClient;
-import org.elasticsearch.common.collect.MapBuilder;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.index.shard.ShardId;
 import org.elasticsearch.rest.BaseRestHandler;
@@ -37,14 +36,12 @@ import org.elasticsearch.rest.RestRequest;
 import org.elasticsearch.rest.RestRequest.Method;
 import org.elasticsearch.rest.RestResponse;
 import org.elasticsearch.rest.action.RestBuilderListener;
+import org.elasticsearch.rest.action.Route;
 
 import java.io.IOException;
-import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 
-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;
@@ -52,11 +49,10 @@ import static org.elasticsearch.rest.RestStatus.OK;
 public class RestNoopBulkAction extends BaseRestHandler {
 
     @Override
-    public Map<String, List<Method>> handledMethodsAndPaths() {
-        return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
-            .put("/_noop_bulk", unmodifiableList(asList(POST, PUT)))
-            .put("/{index}/_noop_bulk", unmodifiableList(asList(POST, PUT)))
-            .map());
+    public List<Route> handledMethodsAndPaths() {
+        return List.of(
+            new Route("/_noop_bulk", List.of(POST, PUT)),
+            new Route("/{index}/_noop_bulk", List.of(POST, PUT)));
     }
 
     @Override
diff --git a/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java b/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java
index 26ba8aa27fb..66d65b0b70e 100644
--- a/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java
+++ b/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java
@@ -28,6 +28,7 @@ import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.common.settings.Setting.Property;
 import org.elasticsearch.plugins.ActionPlugin;
 import org.elasticsearch.rest.RestRequest.Method;
+import org.elasticsearch.rest.action.Route;
 import org.elasticsearch.rest.action.admin.cluster.RestNodesUsageAction;
 
 import java.io.IOException;
@@ -74,7 +75,7 @@ public abstract class BaseRestHandler implements RestHandler {
      * {@inheritDoc}
      */
     @Override
-    public abstract Map<String, List<Method>> handledMethodsAndPaths();
+    public abstract List<Route> handledMethodsAndPaths();
 
     @Override
     public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception {
diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java
index 239f89c5c20..9bf52ced99d 100644
--- a/server/src/main/java/org/elasticsearch/rest/RestController.java
+++ b/server/src/main/java/org/elasticsearch/rest/RestController.java
@@ -160,8 +160,8 @@ public class RestController implements HttpServerTransport.Dispatcher {
      * and {@code path} combinations.
      */
     public void registerHandler(RestHandler restHandler) {
-        restHandler.handledMethodsAndPaths().forEach((path, methods) ->
-            methods.forEach(method -> registerHandler(method, path, restHandler)));
+        restHandler.handledMethodsAndPaths().forEach(route ->
+            route.methods().forEach(method -> registerHandler(method, route.path(), restHandler)));
         restHandler.deprecatedHandledMethodsAndPaths().forEach(api -> api.getMethods().forEach(method ->
             registerAsDeprecatedHandler(method, api.getPath(), restHandler, api.getDeprecationMessage(), api.getLogger())));
         restHandler.replacedMethodsAndPaths().forEach(api -> registerWithDeprecatedHandler(api.getMethod(), api.getPath(), restHandler,
diff --git a/server/src/main/java/org/elasticsearch/rest/RestHandler.java b/server/src/main/java/org/elasticsearch/rest/RestHandler.java
index 5f0862ed80e..6504656ee3c 100644
--- a/server/src/main/java/org/elasticsearch/rest/RestHandler.java
+++ b/server/src/main/java/org/elasticsearch/rest/RestHandler.java
@@ -23,6 +23,7 @@ import org.elasticsearch.client.node.NodeClient;
 import org.elasticsearch.common.logging.DeprecationLogger;
 import org.elasticsearch.common.xcontent.XContent;
 import org.elasticsearch.rest.RestRequest.Method;
+import org.elasticsearch.rest.action.Route;
 
 import java.util.Collections;
 import java.util.List;
@@ -69,8 +70,8 @@ public interface RestHandler {
     /**
      * The map of {@code path} to {@code methods} that this RestHandler is responsible for handling.
      */
-    default Map<String, List<Method>> handledMethodsAndPaths() {
-        return Collections.emptyMap();
+    default List<Route> handledMethodsAndPaths() {
+        return List.of();
     }
 
     /**
diff --git a/server/src/main/java/org/elasticsearch/rest/action/Route.java b/server/src/main/java/org/elasticsearch/rest/action/Route.java
index d42b4fb851a..05e38fdce74 100644
--- a/server/src/main/java/org/elasticsearch/rest/action/Route.java
+++ b/server/src/main/java/org/elasticsearch/rest/action/Route.java
@@ -1,4 +1,26 @@
 package org.elasticsearch.rest.action;
 
+import org.elasticsearch.rest.RestRequest;
+
+import java.util.List;
+
 public class Route {
+
+    private final String path;
+
+    public String path() {
+        return path;
+    }
+
+    private List<RestRequest.Method> methods;
+
+    public List<RestRequest.Method> methods() {
+        return methods;
+    }
+
+    public Route(final String path, final List<RestRequest.Method> methods) {
+        this.path = path;
+        this.methods = methods;
+    }
+
 }

This is close to what you have done with deprecated routes, but I think we should take it the whole way and cover all routes. Then a DeprecatedRoute is a Route with some additional fields, etc.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestRequest.Method;
import org.elasticsearch.rest.action.RestStatusToXContentListener;

import java.util.Collections;
import java.util.List;
import java.util.Map;

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 Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_noop_search", unmodifiableList(asList(GET, POST)))
.put("/{index}/_noop_search", unmodifiableList(asList(GET, POST)))
.map());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,18 @@
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.RestRequest.Method;
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 java.util.Collections.singletonMap;
import static org.elasticsearch.ingest.common.IngestCommonPlugin.GROK_PATTERNS;
import static org.elasticsearch.rest.RestRequest.Method.GET;

Expand Down Expand Up @@ -116,8 +119,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 Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_ingest/processor/grok", singletonList(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 @@ -20,20 +20,24 @@
package org.elasticsearch.script.mustache;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
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.RestRequest.Method;
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.Map;
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 +47,24 @@ 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 Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_msearch/template", unmodifiableList(asList(GET, POST)))
.put("/{index}/_msearch/template", unmodifiableList(asList(GET, POST)))
.map());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,32 @@
package org.elasticsearch.script.mustache;

import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
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.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.ScriptType;

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

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 Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_render/template", unmodifiableList(asList(GET, POST)))
.put("/_render/template/{id}", unmodifiableList(asList(GET, POST)))
.map());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,24 @@

import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.collect.MapBuilder;
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.RestRequest.Method;
import org.elasticsearch.rest.action.RestStatusToXContentListener;
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.Map;
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 +51,12 @@ 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 Map<String, List<Method>> handledMethodsAndPaths() {
return Collections.unmodifiableMap(MapBuilder.<String, List<Method>>newMapBuilder()
.put("/_search/template", unmodifiableList(asList(GET, POST)))
.put("/{index}/_search/template", unmodifiableList(asList(GET, POST)))
.map());
}

@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,8 +37,8 @@
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.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.ScriptContext;
import org.elasticsearch.tasks.Task;
Expand All @@ -52,6 +52,8 @@
import java.util.Objects;
import java.util.stream.Collectors;

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

/**
Expand Down Expand Up @@ -194,8 +196,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 Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_scripts/painless/_context", singletonList(GET));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@
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.RestRequest.Method;
import org.elasticsearch.rest.action.RestToXContentListener;
import org.elasticsearch.script.FilterScript;
import org.elasticsearch.script.ScoreScript;
Expand All @@ -81,9 +81,13 @@
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.singletonMap;
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 +568,9 @@ 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 Map<String, List<Method>> handledMethodsAndPaths() {
return singletonMap("/_scripts/painless/_execute", unmodifiableList(asList(GET, 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
Loading