diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java index 0eceed67c4f73..2013b0d6680a8 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/NoopPlugin.java @@ -55,7 +55,7 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { return Arrays.asList( - new RestNoopBulkAction(restController), - new RestNoopSearchAction(restController)); + new RestNoopBulkAction(), + new RestNoopSearchAction()); } } 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 ffc94a3507853..6333c7391f60e 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 @@ -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 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 diff --git a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java index 5271380bdfc16..15cb525d49a66 100644 --- a/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java +++ b/client/client-benchmark-noop-api-plugin/src/main/java/org/elasticsearch/plugin/noop/action/search/RestNoopSearchAction.java @@ -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 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 diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java index 35a4c76dd4a17..1e212b007bbb5 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/GrokProcessorGetAction.java @@ -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; @@ -116,8 +117,10 @@ protected void doExecute(Task task, Request request, ActionListener li } public static class RestAction extends BaseRestHandler { - RestAction(RestController controller) { - controller.registerHandler(GET, "/_ingest/processor/grok", this); + + @Override + public List handledRoutes() { + return singletonList(new Route("/_ingest/processor/grok", GET)); } @Override diff --git a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java index b37e5d13e4602..d4293c50e14a0 100644 --- a/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java +++ b/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/IngestCommonPlugin.java @@ -103,7 +103,7 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Arrays.asList(new GrokProcessorGetAction.RestAction(restController)); + return Collections.singletonList(new GrokProcessorGetAction.RestAction()); } @Override diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java index 42c140cada0a3..edbff8eb8b799 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java @@ -59,8 +59,8 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { return Arrays.asList( - new RestSearchTemplateAction(restController), - new RestMultiSearchTemplateAction(settings, restController), - new RestRenderSearchTemplateAction(restController)); + new RestSearchTemplateAction(), + new RestMultiSearchTemplateAction(settings), + new RestRenderSearchTemplateAction()); } } diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java index c6baa257a7869..6669132395b86 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java @@ -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; @@ -43,7 +44,7 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler { static { final Set 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); } @@ -51,13 +52,17 @@ public class RestMultiSearchTemplateAction extends BaseRestHandler { 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 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 diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java index 767f6e95c1f78..2a78684daede6 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestRenderSearchTemplateAction.java @@ -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 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 diff --git a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java index 4ce457c1a22e5..ea8f54a2b7ca4 100644 --- a/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java +++ b/modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java @@ -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; @@ -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; @@ -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 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 diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java index 974cdefd529be..f65b3c2aa79a1 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java @@ -155,8 +155,8 @@ public List getRestHandlers(Settings settings, RestController restC IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { List 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; } } diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java index 9075b9e030df8..7e77f484fe102 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessContextAction.java @@ -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; @@ -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; /** @@ -194,8 +194,9 @@ protected void doExecute(Task task, Request request, ActionListener li public static class RestAction extends BaseRestHandler { - public RestAction(RestController controller) { - controller.registerHandler(GET, "/_scripts/painless/_context", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_scripts/painless/_context", GET)); } @Override diff --git a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java index b6bb1a842640d..bf6cbee1cd7bb 100644 --- a/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java +++ b/modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java @@ -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; @@ -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; @@ -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 handledRoutes() { + return unmodifiableList(asList( + new Route("/_scripts/painless/_execute", GET), + new Route("/_scripts/painless/_execute", POST))); } @Override diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java index 48b4297378108..9f21a6065900e 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RankEvalPlugin.java @@ -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; @@ -50,7 +51,7 @@ public class RankEvalPlugin extends Plugin implements ActionPlugin { public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Arrays.asList(new RestRankEvalAction(restController)); + return Collections.singletonList(new RestRankEvalAction()); } @Override diff --git a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java index 85e9e656808e8..452425303a25e 100644 --- a/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java +++ b/modules/rank-eval/src/main/java/org/elasticsearch/index/rankeval/RestRankEvalAction.java @@ -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; @@ -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 handledRoutes() { + return unmodifiableList(asList( + new Route("/" + ENDPOINT, GET), + new Route("/" + ENDPOINT, POST), + new Route("/{index}/" + ENDPOINT, GET), + new Route("/{index}/" + ENDPOINT, POST))); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java index fefee4f348b3e..c0e6a55ec9c13 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/ReindexPlugin.java @@ -74,10 +74,10 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier 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 diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java index 95fab3dd44db3..162fcc4ae72f5 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestDeleteByQueryAction.java @@ -20,21 +20,26 @@ package org.elasticsearch.index.reindex; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import java.io.IOException; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.function.Consumer; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestDeleteByQueryAction extends AbstractBulkByQueryRestHandler { - public RestDeleteByQueryAction(RestController controller) { + public RestDeleteByQueryAction() { super(DeleteByQueryAction.INSTANCE); - controller.registerHandler(POST, "/{index}/_delete_by_query", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_delete_by_query", POST)); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java index 516d47b835803..e84034ee25d19 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestReindexAction.java @@ -21,11 +21,12 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -34,9 +35,13 @@ */ public class RestReindexAction extends AbstractBaseReindexRestHandler { - public RestReindexAction(RestController controller) { + public RestReindexAction() { super(ReindexAction.INSTANCE); - controller.registerHandler(POST, "/_reindex", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_reindex", POST)); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java index cdd29a89b92c8..40d9d1edadcad 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestRethrottleAction.java @@ -22,23 +22,30 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.tasks.TaskId; +import java.util.List; import java.util.function.Supplier; +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.action.admin.cluster.RestListTasksAction.listTasksResponseListener; public class RestRethrottleAction extends BaseRestHandler { private final Supplier nodesInCluster; - public RestRethrottleAction(RestController controller, Supplier nodesInCluster) { + public RestRethrottleAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; - controller.registerHandler(POST, "/_update_by_query/{taskId}/_rethrottle", this); - controller.registerHandler(POST, "/_delete_by_query/{taskId}/_rethrottle", this); - controller.registerHandler(POST, "/_reindex/{taskId}/_rethrottle", this); + } + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_update_by_query/{taskId}/_rethrottle", POST), + new Route("/_delete_by_query/{taskId}/_rethrottle", POST), + new Route("/_reindex/{taskId}/_rethrottle", POST))); } @Override diff --git a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java index 5927aca9bb1e1..42423cbfb8b46 100644 --- a/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java +++ b/modules/reindex/src/main/java/org/elasticsearch/index/reindex/RestUpdateByQueryAction.java @@ -22,7 +22,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.LoggingDeprecationHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.script.Script; import org.elasticsearch.script.ScriptType; @@ -31,16 +30,23 @@ import java.util.Collections; import java.util.HashMap; import java.util.Iterator; +import java.util.List; import java.util.Map; import java.util.function.Consumer; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.script.Script.DEFAULT_SCRIPT_LANG; public class RestUpdateByQueryAction extends AbstractBulkByQueryRestHandler { - public RestUpdateByQueryAction(RestController controller) { + + public RestUpdateByQueryAction() { super(UpdateByQueryAction.INSTANCE); - controller.registerHandler(POST, "/{index}/_update_by_query", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_update_by_query", POST)); } @Override diff --git a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java index ebfc117ec04ec..cb8217b78ef35 100644 --- a/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java +++ b/modules/reindex/src/test/java/org/elasticsearch/index/reindex/RestReindexActionTests.java @@ -38,7 +38,8 @@ public class RestReindexActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestReindexAction(controller()); + action = new RestReindexAction(); + controller().registerHandler(action); } public void testPipelineQueryParameterIsError() throws IOException { diff --git a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java index 79cb1a6f76ded..b29abf73f8a3c 100644 --- a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java +++ b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleCatAction.java @@ -21,11 +21,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Table; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.cat.AbstractCatAction; import org.elasticsearch.rest.action.cat.RestTable; +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; @@ -34,9 +37,11 @@ */ public class ExampleCatAction extends AbstractCatAction { - ExampleCatAction(final RestController controller) { - controller.registerHandler(GET, "/_cat/example", this); - controller.registerHandler(POST, "/_cat/example", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/example", GET), + new Route("/_cat/example", POST))); } @Override diff --git a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java index 725049c797e15..420a58302f35c 100644 --- a/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java +++ b/plugins/examples/rest-handler/src/main/java/org/elasticsearch/example/resthandler/ExampleRestHandlerPlugin.java @@ -46,6 +46,6 @@ public List getRestHandlers(final Settings settings, final IndexNameExpressionResolver indexNameExpressionResolver, final Supplier nodesInCluster) { - return singletonList(new ExampleCatAction(restController)); + return singletonList(new ExampleCatAction()); } } diff --git a/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java b/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java index 8b7093515cd71..29c81c1a39c0a 100644 --- a/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java +++ b/qa/die-with-dignity/src/main/java/org/elasticsearch/DieWithDignityPlugin.java @@ -49,7 +49,7 @@ public List getRestHandlers( final SettingsFilter settingsFilter, final IndexNameExpressionResolver indexNameExpressionResolver, final Supplier nodesInCluster) { - return Collections.singletonList(new RestDieWithDignityAction(restController)); + return Collections.singletonList(new RestDieWithDignityAction()); } } diff --git a/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java b/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java index 8f43d67908432..df370ccb55fc7 100644 --- a/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java +++ b/qa/die-with-dignity/src/main/java/org/elasticsearch/RestDieWithDignityAction.java @@ -21,13 +21,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestDieWithDignityAction extends BaseRestHandler { - RestDieWithDignityAction(final RestController restController) { - restController.registerHandler(RestRequest.Method.GET, "/_die_with_dignity", this); + RestDieWithDignityAction() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_die_with_dignity", GET)); } @Override diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java index a864bde42b281..c0010f00ec354 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationHeaderRestAction.java @@ -28,14 +28,17 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import java.io.IOException; +import java.util.Collections; import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + /** * Enables testing {@code DeprecationRestHandler} via integration tests by guaranteeing a deprecated REST endpoint. *

@@ -66,11 +69,14 @@ public class TestDeprecationHeaderRestAction extends BaseRestHandler { private final Settings settings; - public TestDeprecationHeaderRestAction(Settings settings, RestController controller) { + public TestDeprecationHeaderRestAction(Settings settings) { this.settings = settings; + } - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, "/_test_cluster/deprecated_settings", this, - DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List deprecatedRoutes() { + return singletonList( + new DeprecatedRoute("/_test_cluster/deprecated_settings", GET, DEPRECATED_ENDPOINT, deprecationLogger)); } @Override @@ -78,6 +84,11 @@ public String getName() { return "test_deprecation_header_action"; } + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + @SuppressWarnings("unchecked") // List casts @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java index a264227999eda..81faab8289301 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestDeprecationPlugin.java @@ -47,7 +47,7 @@ public class TestDeprecationPlugin extends Plugin implements ActionPlugin, Searc public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Collections.singletonList(new TestDeprecationHeaderRestAction(settings, restController)); + return Collections.singletonList(new TestDeprecationHeaderRestAction(settings)); } @Override diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java index 0f9b6f4db19dd..a869276fdac1e 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderPlugin.java @@ -40,6 +40,6 @@ public class TestResponseHeaderPlugin extends Plugin implements ActionPlugin { public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return singletonList(new TestResponseHeaderRestAction(restController)); + return singletonList(new TestResponseHeaderRestAction()); } } diff --git a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java index c51947f7328cb..752316b6b23c5 100644 --- a/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java +++ b/qa/smoke-test-http/src/test/java/org/elasticsearch/http/TestResponseHeaderRestAction.java @@ -21,15 +21,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class TestResponseHeaderRestAction extends BaseRestHandler { - public TestResponseHeaderRestAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_protected", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_protected", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 064b28808dc32..62c265bc17a78 100644 --- a/server/src/main/java/org/elasticsearch/action/ActionModule.java +++ b/server/src/main/java/org/elasticsearch/action/ActionModule.java @@ -322,6 +322,8 @@ import org.elasticsearch.rest.action.document.RestGetAction; import org.elasticsearch.rest.action.document.RestGetSourceAction; import org.elasticsearch.rest.action.document.RestIndexAction; +import org.elasticsearch.rest.action.document.RestIndexAction.AutoIdHandler; +import org.elasticsearch.rest.action.document.RestIndexAction.CreateHandler; import org.elasticsearch.rest.action.document.RestMultiGetAction; import org.elasticsearch.rest.action.document.RestMultiTermVectorsAction; import org.elasticsearch.rest.action.document.RestTermVectorsAction; @@ -565,148 +567,151 @@ private ActionFilters setupActionFilters(List actionPlugins) { public void initRestHandlers(Supplier nodesInCluster) { List catActions = new ArrayList<>(); - Consumer registerHandler = a -> { - if (a instanceof AbstractCatAction) { - catActions.add((AbstractCatAction) a); + Consumer registerHandler = handler -> { + if (handler instanceof AbstractCatAction) { + catActions.add((AbstractCatAction) handler); } + restController.registerHandler(handler); }; - registerHandler.accept(new RestAddVotingConfigExclusionAction(restController)); - registerHandler.accept(new RestClearVotingConfigExclusionsAction(restController)); - registerHandler.accept(new RestMainAction(restController)); - registerHandler.accept(new RestNodesInfoAction(restController, settingsFilter)); - registerHandler.accept(new RestRemoteClusterInfoAction(restController)); - registerHandler.accept(new RestNodesStatsAction(restController)); - registerHandler.accept(new RestNodesUsageAction(restController)); - registerHandler.accept(new RestNodesHotThreadsAction(restController)); - registerHandler.accept(new RestClusterAllocationExplainAction(restController)); - registerHandler.accept(new RestClusterStatsAction(restController)); - registerHandler.accept(new RestClusterStateAction(restController, settingsFilter)); - registerHandler.accept(new RestClusterHealthAction(restController)); - registerHandler.accept(new RestClusterUpdateSettingsAction(restController)); - registerHandler.accept(new RestClusterGetSettingsAction(settings, restController, clusterSettings, settingsFilter)); - registerHandler.accept(new RestClusterRerouteAction(restController, settingsFilter)); - registerHandler.accept(new RestClusterSearchShardsAction(restController)); - registerHandler.accept(new RestPendingClusterTasksAction(restController)); - registerHandler.accept(new RestPutRepositoryAction(restController)); - registerHandler.accept(new RestGetRepositoriesAction(restController, settingsFilter)); - registerHandler.accept(new RestDeleteRepositoryAction(restController)); - registerHandler.accept(new RestVerifyRepositoryAction(restController)); - registerHandler.accept(new RestCleanupRepositoryAction(restController)); - registerHandler.accept(new RestGetSnapshotsAction(restController)); - registerHandler.accept(new RestCreateSnapshotAction(restController)); - registerHandler.accept(new RestRestoreSnapshotAction(restController)); - registerHandler.accept(new RestDeleteSnapshotAction(restController)); - registerHandler.accept(new RestSnapshotsStatusAction(restController)); - registerHandler.accept(new RestGetIndicesAction(restController)); - registerHandler.accept(new RestIndicesStatsAction(restController)); - registerHandler.accept(new RestIndicesSegmentsAction(restController)); - registerHandler.accept(new RestIndicesShardStoresAction(restController)); - registerHandler.accept(new RestGetAliasesAction(restController)); - registerHandler.accept(new RestIndexDeleteAliasesAction(restController)); - registerHandler.accept(new RestIndexPutAliasAction(restController)); - registerHandler.accept(new RestIndicesAliasesAction(restController)); - registerHandler.accept(new RestCreateIndexAction(restController)); - registerHandler.accept(new RestResizeHandler.RestShrinkIndexAction(restController)); - registerHandler.accept(new RestResizeHandler.RestSplitIndexAction(restController)); - registerHandler.accept(new RestResizeHandler.RestCloneIndexAction(restController)); - registerHandler.accept(new RestRolloverIndexAction(restController)); - registerHandler.accept(new RestDeleteIndexAction(restController)); - registerHandler.accept(new RestCloseIndexAction(restController)); - registerHandler.accept(new RestOpenIndexAction(restController)); - - registerHandler.accept(new RestUpdateSettingsAction(restController)); - registerHandler.accept(new RestGetSettingsAction(restController)); - - registerHandler.accept(new RestAnalyzeAction(restController)); - registerHandler.accept(new RestGetIndexTemplateAction(restController)); - registerHandler.accept(new RestPutIndexTemplateAction(restController)); - registerHandler.accept(new RestDeleteIndexTemplateAction(restController)); - - registerHandler.accept(new RestPutMappingAction(restController)); - registerHandler.accept(new RestGetMappingAction(restController)); - registerHandler.accept(new RestGetFieldMappingAction(restController)); - - registerHandler.accept(new RestRefreshAction(restController)); - registerHandler.accept(new RestFlushAction(restController)); - registerHandler.accept(new RestSyncedFlushAction(restController)); - registerHandler.accept(new RestForceMergeAction(restController)); - registerHandler.accept(new RestUpgradeActionDeprecated(restController)); - registerHandler.accept(new RestUpgradeStatusActionDeprecated(restController)); - registerHandler.accept(new RestClearIndicesCacheAction(restController)); - - registerHandler.accept(new RestIndexAction(restController, clusterService)); - registerHandler.accept(new RestGetAction(restController)); - registerHandler.accept(new RestGetSourceAction(restController)); - registerHandler.accept(new RestMultiGetAction(settings, restController)); - registerHandler.accept(new RestDeleteAction(restController)); - registerHandler.accept(new RestCountAction(restController)); - registerHandler.accept(new RestTermVectorsAction(restController)); - registerHandler.accept(new RestMultiTermVectorsAction(restController)); - registerHandler.accept(new RestBulkAction(settings, restController)); - registerHandler.accept(new RestUpdateAction(restController)); - - registerHandler.accept(new RestSearchAction(restController)); - registerHandler.accept(new RestSearchScrollAction(restController)); - registerHandler.accept(new RestClearScrollAction(restController)); - registerHandler.accept(new RestMultiSearchAction(settings, restController)); - - registerHandler.accept(new RestValidateQueryAction(restController)); - - registerHandler.accept(new RestExplainAction(restController)); - - registerHandler.accept(new RestRecoveryAction(restController)); - - registerHandler.accept(new RestReloadSecureSettingsAction(restController)); + registerHandler.accept(new RestAddVotingConfigExclusionAction()); + registerHandler.accept(new RestClearVotingConfigExclusionsAction()); + registerHandler.accept(new RestMainAction()); + registerHandler.accept(new RestNodesInfoAction(settingsFilter)); + registerHandler.accept(new RestRemoteClusterInfoAction()); + registerHandler.accept(new RestNodesStatsAction()); + registerHandler.accept(new RestNodesUsageAction()); + registerHandler.accept(new RestNodesHotThreadsAction()); + registerHandler.accept(new RestClusterAllocationExplainAction()); + registerHandler.accept(new RestClusterStatsAction()); + registerHandler.accept(new RestClusterStateAction(settingsFilter)); + registerHandler.accept(new RestClusterHealthAction()); + registerHandler.accept(new RestClusterUpdateSettingsAction()); + registerHandler.accept(new RestClusterGetSettingsAction(settings, clusterSettings, settingsFilter)); + registerHandler.accept(new RestClusterRerouteAction(settingsFilter)); + registerHandler.accept(new RestClusterSearchShardsAction()); + registerHandler.accept(new RestPendingClusterTasksAction()); + registerHandler.accept(new RestPutRepositoryAction()); + registerHandler.accept(new RestGetRepositoriesAction(settingsFilter)); + registerHandler.accept(new RestDeleteRepositoryAction()); + registerHandler.accept(new RestVerifyRepositoryAction()); + registerHandler.accept(new RestCleanupRepositoryAction()); + registerHandler.accept(new RestGetSnapshotsAction()); + registerHandler.accept(new RestCreateSnapshotAction()); + registerHandler.accept(new RestRestoreSnapshotAction()); + registerHandler.accept(new RestDeleteSnapshotAction()); + registerHandler.accept(new RestSnapshotsStatusAction()); + registerHandler.accept(new RestGetIndicesAction()); + registerHandler.accept(new RestIndicesStatsAction()); + registerHandler.accept(new RestIndicesSegmentsAction()); + registerHandler.accept(new RestIndicesShardStoresAction()); + registerHandler.accept(new RestGetAliasesAction()); + registerHandler.accept(new RestIndexDeleteAliasesAction()); + registerHandler.accept(new RestIndexPutAliasAction()); + registerHandler.accept(new RestIndicesAliasesAction()); + registerHandler.accept(new RestCreateIndexAction()); + registerHandler.accept(new RestResizeHandler.RestShrinkIndexAction()); + registerHandler.accept(new RestResizeHandler.RestSplitIndexAction()); + registerHandler.accept(new RestResizeHandler.RestCloneIndexAction()); + registerHandler.accept(new RestRolloverIndexAction()); + registerHandler.accept(new RestDeleteIndexAction()); + registerHandler.accept(new RestCloseIndexAction()); + registerHandler.accept(new RestOpenIndexAction()); + + registerHandler.accept(new RestUpdateSettingsAction()); + registerHandler.accept(new RestGetSettingsAction()); + + registerHandler.accept(new RestAnalyzeAction()); + registerHandler.accept(new RestGetIndexTemplateAction()); + registerHandler.accept(new RestPutIndexTemplateAction()); + registerHandler.accept(new RestDeleteIndexTemplateAction()); + + registerHandler.accept(new RestPutMappingAction()); + registerHandler.accept(new RestGetMappingAction()); + registerHandler.accept(new RestGetFieldMappingAction()); + + registerHandler.accept(new RestRefreshAction()); + registerHandler.accept(new RestFlushAction()); + registerHandler.accept(new RestSyncedFlushAction()); + registerHandler.accept(new RestForceMergeAction()); + registerHandler.accept(new RestUpgradeActionDeprecated()); + registerHandler.accept(new RestUpgradeStatusActionDeprecated()); + registerHandler.accept(new RestClearIndicesCacheAction()); + + registerHandler.accept(new RestIndexAction()); + registerHandler.accept(new CreateHandler()); + registerHandler.accept(new AutoIdHandler(clusterService)); + registerHandler.accept(new RestGetAction()); + registerHandler.accept(new RestGetSourceAction()); + registerHandler.accept(new RestMultiGetAction(settings)); + registerHandler.accept(new RestDeleteAction()); + registerHandler.accept(new RestCountAction()); + registerHandler.accept(new RestTermVectorsAction()); + registerHandler.accept(new RestMultiTermVectorsAction()); + registerHandler.accept(new RestBulkAction(settings)); + registerHandler.accept(new RestUpdateAction()); + + registerHandler.accept(new RestSearchAction()); + registerHandler.accept(new RestSearchScrollAction()); + registerHandler.accept(new RestClearScrollAction()); + registerHandler.accept(new RestMultiSearchAction(settings)); + + registerHandler.accept(new RestValidateQueryAction()); + + registerHandler.accept(new RestExplainAction()); + + registerHandler.accept(new RestRecoveryAction()); + + registerHandler.accept(new RestReloadSecureSettingsAction()); // Scripts API - registerHandler.accept(new RestGetStoredScriptAction(restController)); - registerHandler.accept(new RestPutStoredScriptAction(restController)); - registerHandler.accept(new RestDeleteStoredScriptAction(restController)); - registerHandler.accept(new RestGetScriptContextAction(restController)); - registerHandler.accept(new RestGetScriptLanguageAction(restController)); + registerHandler.accept(new RestGetStoredScriptAction()); + registerHandler.accept(new RestPutStoredScriptAction()); + registerHandler.accept(new RestDeleteStoredScriptAction()); + registerHandler.accept(new RestGetScriptContextAction()); + registerHandler.accept(new RestGetScriptLanguageAction()); - registerHandler.accept(new RestFieldCapabilitiesAction(restController)); + registerHandler.accept(new RestFieldCapabilitiesAction()); // Tasks API - registerHandler.accept(new RestListTasksAction(restController, nodesInCluster)); - registerHandler.accept(new RestGetTaskAction(restController)); - registerHandler.accept(new RestCancelTasksAction(restController, nodesInCluster)); + registerHandler.accept(new RestListTasksAction(nodesInCluster)); + registerHandler.accept(new RestGetTaskAction()); + registerHandler.accept(new RestCancelTasksAction(nodesInCluster)); // Ingest API - registerHandler.accept(new RestPutPipelineAction(restController)); - registerHandler.accept(new RestGetPipelineAction(restController)); - registerHandler.accept(new RestDeletePipelineAction(restController)); - registerHandler.accept(new RestSimulatePipelineAction(restController)); + registerHandler.accept(new RestPutPipelineAction()); + registerHandler.accept(new RestGetPipelineAction()); + registerHandler.accept(new RestDeletePipelineAction()); + registerHandler.accept(new RestSimulatePipelineAction()); // CAT API - registerHandler.accept(new RestAllocationAction(restController)); - registerHandler.accept(new RestShardsAction(restController)); - registerHandler.accept(new RestMasterAction(restController)); - registerHandler.accept(new RestNodesAction(restController)); - registerHandler.accept(new RestTasksAction(restController, nodesInCluster)); - registerHandler.accept(new RestIndicesAction(restController)); - registerHandler.accept(new RestSegmentsAction(restController)); + registerHandler.accept(new RestAllocationAction()); + registerHandler.accept(new RestShardsAction()); + registerHandler.accept(new RestMasterAction()); + registerHandler.accept(new RestNodesAction()); + registerHandler.accept(new RestTasksAction(nodesInCluster)); + registerHandler.accept(new RestIndicesAction()); + registerHandler.accept(new RestSegmentsAction()); // Fully qualified to prevent interference with rest.action.count.RestCountAction - registerHandler.accept(new org.elasticsearch.rest.action.cat.RestCountAction(restController)); + registerHandler.accept(new org.elasticsearch.rest.action.cat.RestCountAction()); // Fully qualified to prevent interference with rest.action.indices.RestRecoveryAction - registerHandler.accept(new RestCatRecoveryAction(restController)); - registerHandler.accept(new RestHealthAction(restController)); - registerHandler.accept(new org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction(restController)); - registerHandler.accept(new RestAliasAction(restController)); - registerHandler.accept(new RestThreadPoolAction(restController)); - registerHandler.accept(new RestPluginsAction(restController)); - registerHandler.accept(new RestFielddataAction(restController)); - registerHandler.accept(new RestNodeAttrsAction(restController)); - registerHandler.accept(new RestRepositoriesAction(restController)); - registerHandler.accept(new RestSnapshotAction(restController)); - registerHandler.accept(new RestTemplatesAction(restController)); + registerHandler.accept(new RestCatRecoveryAction()); + registerHandler.accept(new RestHealthAction()); + registerHandler.accept(new org.elasticsearch.rest.action.cat.RestPendingClusterTasksAction()); + registerHandler.accept(new RestAliasAction()); + registerHandler.accept(new RestThreadPoolAction()); + registerHandler.accept(new RestPluginsAction()); + registerHandler.accept(new RestFielddataAction()); + registerHandler.accept(new RestNodeAttrsAction()); + registerHandler.accept(new RestRepositoriesAction()); + registerHandler.accept(new RestSnapshotAction()); + registerHandler.accept(new RestTemplatesAction()); for (ActionPlugin plugin : actionPlugins) { for (RestHandler handler : plugin.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, indexNameExpressionResolver, nodesInCluster)) { registerHandler.accept(handler); } } - registerHandler.accept(new RestCatAction(restController, catActions)); + registerHandler.accept(new RestCatAction(catActions)); } @Override diff --git a/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java b/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java index abf27b662bb7c..5e18a9162f1d8 100644 --- a/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java +++ b/server/src/main/java/org/elasticsearch/common/collect/MapBuilder.java @@ -33,7 +33,7 @@ public static MapBuilder newMapBuilder(Map map) { return new MapBuilder<>(map); } - private Map map = new HashMap<>(); + private final Map map; public MapBuilder() { this.map = new HashMap<>(); diff --git a/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java b/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java index 5d33e55514629..9eb0b98508852 100644 --- a/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/BaseRestHandler.java @@ -18,6 +18,7 @@ */ package org.elasticsearch.rest; + import org.apache.lucene.search.spell.LevenshteinDistance; import org.apache.lucene.util.CollectionUtil; import org.elasticsearch.client.node.NodeClient; @@ -67,6 +68,12 @@ public final long getUsageCount() { */ public abstract String getName(); + /** + * {@inheritDoc} + */ + @Override + public abstract List handledRoutes(); + @Override public final void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { // prepare the request for execution; has the side effect of touching the request parameters diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java index aa39ccdc4659c..4c9298dc52d69 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestController.java +++ b/server/src/main/java/org/elasticsearch/rest/RestController.java @@ -96,7 +96,7 @@ public RestController(Set headersToCopy, UnaryOperatorDeprecated path to handle (e.g., "/_optimize") * @param logger The existing deprecation logger to use */ - public void registerWithDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, + protected void registerWithDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, RestRequest.Method deprecatedMethod, String deprecatedPath, DeprecationLogger logger) { // e.g., [POST /_optimize] is deprecated! Use [POST /_forcemerge] instead. @@ -146,7 +146,7 @@ public void registerWithDeprecatedHandler(RestRequest.Method method, String path * @param handler The handler to actually execute * @param method GET, POST, etc. */ - public void registerHandler(RestRequest.Method method, String path, RestHandler handler) { + protected void registerHandler(RestRequest.Method method, String path, RestHandler handler) { if (handler instanceof BaseRestHandler) { usageService.addRestHandler((BaseRestHandler) handler); } @@ -155,6 +155,18 @@ public void registerHandler(RestRequest.Method method, String path, RestHandler (mHandlers, newMHandler) -> mHandlers.addMethods(maybeWrappedHandler, method)); } + /** + * Registers a REST handler with the controller. The REST handler declares the {@code method} + * and {@code path} combinations. + */ + public void registerHandler(final RestHandler restHandler) { + restHandler.handledRoutes().forEach(route -> registerHandler(route.getMethod(), route.getPath(), restHandler)); + restHandler.deprecatedRoutes().forEach(route -> + registerAsDeprecatedHandler(route.getMethod(), route.getPath(), restHandler, route.getDeprecationMessage(), route.getLogger())); + restHandler.replacedRoutes().forEach(route -> registerWithDeprecatedHandler(route.getMethod(), route.getPath(), + restHandler, route.getDeprecatedMethod(), route.getDeprecatedPath(), route.getLogger())); + } + @Override public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { if (request.rawPath().equals("/favicon.ico")) { diff --git a/server/src/main/java/org/elasticsearch/rest/RestHandler.java b/server/src/main/java/org/elasticsearch/rest/RestHandler.java index 605dd41078a54..cc0edc3097fb0 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/RestHandler.java @@ -20,7 +20,12 @@ package org.elasticsearch.rest; 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 java.util.Collections; +import java.util.List; /** * Handler for REST requests @@ -59,4 +64,101 @@ default boolean supportsContentStream() { default boolean allowsUnsafeBuffers() { return false; } + + /** + * The list of {@link Route}s that this RestHandler is responsible for handling. + */ + default List handledRoutes() { + return Collections.emptyList(); + } + + /** + * A list of routes handled by this RestHandler that are deprecated and do not have a direct + * replacement. If changing the {@code path} or {@code method} of a route, + * use {@link #replacedRoutes()}. + */ + default List deprecatedRoutes() { + return Collections.emptyList(); + } + + /** + * A list of routes handled by this RestHandler that have had their {@code path} and/or + * {@code method} changed. The pre-existing {@code route} will be registered + * as deprecated alongside the updated {@code route}. + */ + default List replacedRoutes() { + return Collections.emptyList(); + } + + class Route { + + private final String path; + private final Method method; + + public Route(String path, Method method) { + this.path = path; + this.method = method; + } + + public String getPath() { + return path; + } + + public Method getMethod() { + return method; + } + } + + /** + * Represents an API that has been deprecated and is slated for removal. + */ + class DeprecatedRoute extends Route { + + private final String deprecationMessage; + private final DeprecationLogger logger; + + public DeprecatedRoute(String path, Method method, String deprecationMessage, DeprecationLogger logger) { + super(path, method); + this.deprecationMessage = deprecationMessage; + this.logger = logger; + } + + public String getDeprecationMessage() { + return deprecationMessage; + } + + public DeprecationLogger getLogger() { + return logger; + } + } + + /** + * Represents an API that has had its {@code path} or {@code method} changed. Holds both the + * new and previous {@code path} and {@code method} combination. + */ + class ReplacedRoute extends Route { + + private final String deprecatedPath; + private final Method deprecatedMethod; + private final DeprecationLogger logger; + + public ReplacedRoute(Method method, String path, Method deprecatedMethod, String deprecatedPath, DeprecationLogger logger) { + super(path, method); + this.deprecatedMethod = deprecatedMethod; + this.deprecatedPath = deprecatedPath; + this.logger = logger; + } + + public String getDeprecatedPath() { + return deprecatedPath; + } + + public Method getDeprecatedMethod() { + return deprecatedMethod; + } + + public DeprecationLogger getLogger() { + return logger; + } + } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java b/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java index 613729f8904af..eb83a7c6de7a5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java @@ -24,21 +24,25 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; 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 RestFieldCapabilitiesAction extends BaseRestHandler { - public RestFieldCapabilitiesAction(RestController controller) { - controller.registerHandler(GET, "/_field_caps", this); - controller.registerHandler(POST, "/_field_caps", this); - controller.registerHandler(GET, "/{index}/_field_caps", this); - controller.registerHandler(POST, "/{index}/_field_caps", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_field_caps", GET), + new Route("/_field_caps", POST), + new Route("/{index}/_field_caps", GET), + new Route("/{index}/_field_caps", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java b/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java index e776a6ad08a7b..da86dfef1982f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/RestMainAction.java @@ -26,20 +26,25 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; 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.HEAD; public class RestMainAction extends BaseRestHandler { - public RestMainAction(RestController controller) { - controller.registerHandler(GET, "/", this); - controller.registerHandler(HEAD, "/", this); + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/", GET), + new Route("/", HEAD))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java index 018392bb05ad8..bea4dbfb1f21a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionAction.java @@ -25,25 +25,29 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.unit.TimeValue; 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.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestAddVotingConfigExclusionAction extends BaseRestHandler { private static final TimeValue DEFAULT_TIMEOUT = TimeValue.timeValueSeconds(30L); - public RestAddVotingConfigExclusionAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_cluster/voting_config_exclusions/{node_name}", this); - } - @Override public String getName() { return "add_voting_config_exclusions_action"; } + @Override + public List handledRoutes() { + return singletonList(new Route("/_cluster/voting_config_exclusions/{node_name}", POST)); + } + @Override protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { AddVotingConfigExclusionsRequest votingConfigExclusionsRequest = resolveVotingConfigExclusionsRequest(request); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java index 2dd98bfb9a506..75b2cb5f8d8f1 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCancelTasksAction.java @@ -24,13 +24,15 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.tasks.TaskId; import java.io.IOException; +import java.util.List; import java.util.function.Supplier; +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.action.admin.cluster.RestListTasksAction.listTasksResponseListener; @@ -38,10 +40,8 @@ public class RestCancelTasksAction extends BaseRestHandler { private final Supplier nodesInCluster; - public RestCancelTasksAction(RestController controller, Supplier nodesInCluster) { + public RestCancelTasksAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; - controller.registerHandler(POST, "/_tasks/_cancel", this); - controller.registerHandler(POST, "/_tasks/{task_id}/_cancel", this); } @Override @@ -49,6 +49,12 @@ public String getName() { return "cancel_tasks_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList(new Route("/_tasks/_cancel", POST), + new Route("/_tasks/{task_id}/_cancel", POST))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodes")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java index 3eca34ff2d3d5..aa4421ea75d72 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCleanupRepositoryAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.repositories.cleanup.CleanupRepositoryRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.cleanupRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -36,8 +37,9 @@ */ public class RestCleanupRepositoryAction extends BaseRestHandler { - public RestCleanupRepositoryAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/_cleanup", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_snapshot/{repository}/_cleanup", POST)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java index 8d9a2121b8149..d07c94a4a7563 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClearVotingConfigExclusionsAction.java @@ -23,16 +23,20 @@ import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestClearVotingConfigExclusionsAction extends BaseRestHandler { - public RestClearVotingConfigExclusionsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_cluster/voting_config_exclusions", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cluster/voting_config_exclusions", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java index 99d0f00d0967d..7a58e4cda682b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterAllocationExplainAction.java @@ -27,22 +27,29 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; 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.GET; +import static org.elasticsearch.rest.RestRequest.Method.POST; /** * Class handling cluster allocation explanation at the REST level */ public class RestClusterAllocationExplainAction extends BaseRestHandler { - public RestClusterAllocationExplainAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/allocation/explain", this); - controller.registerHandler(RestRequest.Method.POST, "/_cluster/allocation/explain", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cluster/allocation/explain", GET), + new Route("/_cluster/allocation/explain", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java index 0a4d5b4e897f0..14c348f5649de 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterGetSettingsAction.java @@ -32,29 +32,34 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; import java.util.Set; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestClusterGetSettingsAction extends BaseRestHandler { private final Settings settings; private final ClusterSettings clusterSettings; private final SettingsFilter settingsFilter; - public RestClusterGetSettingsAction(Settings settings, RestController controller, ClusterSettings clusterSettings, - SettingsFilter settingsFilter) { + public RestClusterGetSettingsAction(Settings settings, ClusterSettings clusterSettings, SettingsFilter settingsFilter) { this.settings = settings; this.clusterSettings = clusterSettings; - controller.registerHandler(RestRequest.Method.GET, "/_cluster/settings", this); this.settingsFilter = settingsFilter; } + @Override + public List handledRoutes() { + return singletonList(new Route("/_cluster/settings", GET)); + } @Override public String getName() { return "cluster_get_settings_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java index 63c6bc4c92c0b..613331f8fbd94 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterHealthAction.java @@ -27,22 +27,26 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Locale; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.clusterHealthRequest; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestClusterHealthAction extends BaseRestHandler { - public RestClusterHealthAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/health", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/health/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList(new Route("/_cluster/health", GET), + new Route("/_cluster/health/{index}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java index 30799cb0552c0..e33d950a0e8bd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterRerouteAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.xcontent.ObjectParser; import org.elasticsearch.common.xcontent.ObjectParser.ValueType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; @@ -39,8 +38,12 @@ import java.util.Collections; import java.util.EnumSet; import java.util.HashSet; +import java.util.List; import java.util.Set; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestClusterRerouteAction extends BaseRestHandler { private static final ObjectParser PARSER = new ObjectParser<>("cluster_reroute"); static { @@ -54,9 +57,13 @@ public class RestClusterRerouteAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestClusterRerouteAction(RestController controller, SettingsFilter settingsFilter) { + public RestClusterRerouteAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; - controller.registerHandler(RestRequest.Method.POST, "/_cluster/reroute", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_cluster/reroute", POST)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java index 188691dacf5e2..55969bc892015 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterSearchShardsAction.java @@ -25,22 +25,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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; public class RestClusterSearchShardsAction extends BaseRestHandler { - public RestClusterSearchShardsAction(RestController controller) { - controller.registerHandler(GET, "/_search_shards", this); - controller.registerHandler(POST, "/_search_shards", this); - controller.registerHandler(GET, "/{index}/_search_shards", this); - controller.registerHandler(POST, "/{index}/_search_shards", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_search_shards", GET), + new Route("/_search_shards", POST), + new Route("/{index}/_search_shards", GET), + new Route("/{index}/_search_shards", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java index 9838cc26625fa..de95a90fd2256 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStateAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -41,17 +40,18 @@ import java.util.Collections; import java.util.EnumSet; 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; + public class RestClusterStateAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestClusterStateAction(RestController controller, SettingsFilter settingsFilter) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/state", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/state/{metric}", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/state/{metric}/{indices}", this); - + public RestClusterStateAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; } @@ -60,6 +60,14 @@ public String getName() { return "cluster_state_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cluster/state", GET), + new Route("/_cluster/state/{metric}", GET), + new Route("/_cluster/state/{metric}/{indices}", GET))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final ClusterStateRequest clusterStateRequest = Requests.clusterStateRequest(); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java index c7bfc640e76b4..41aca857cfee8 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterStatsAction.java @@ -22,17 +22,23 @@ import org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest; 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.RestActions.NodesResponseRestListener; 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; public class RestClusterStatsAction extends BaseRestHandler { - public RestClusterStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/stats", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/stats/nodes/{nodeId}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cluster/stats", GET), + new Route("/_cluster/stats/nodes/{nodeId}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java index 35874f12d5fe1..614b22a201217 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestClusterUpdateSettingsAction.java @@ -25,21 +25,25 @@ import org.elasticsearch.common.settings.Settings; 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 java.util.Map; import java.util.Set; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + public class RestClusterUpdateSettingsAction extends BaseRestHandler { private static final String PERSISTENT = "persistent"; private static final String TRANSIENT = "transient"; - public RestClusterUpdateSettingsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_cluster/settings", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cluster/settings", PUT)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java index 185a1659738ff..840f9ea6a28dd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestCreateSnapshotAction.java @@ -22,12 +22,14 @@ import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; 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.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.client.Requests.createSnapshotRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -37,9 +39,11 @@ */ public class RestCreateSnapshotAction extends BaseRestHandler { - public RestCreateSnapshotAction(RestController controller) { - controller.registerHandler(PUT, "/_snapshot/{repository}/{snapshot}", this); - controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_snapshot/{repository}/{snapshot}", PUT), + new Route("/_snapshot/{repository}/{snapshot}", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java index 81914718b07df..ee79820d22129 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteRepositoryAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.repositories.delete.DeleteRepositoryRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.deleteRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -36,8 +37,9 @@ */ public class RestDeleteRepositoryAction extends BaseRestHandler { - public RestDeleteRepositoryAction(RestController controller) { - controller.registerHandler(DELETE, "/_snapshot/{repository}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_snapshot/{repository}", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java index 81a3ddd31c59a..8249d64f20bd5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteSnapshotAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.snapshots.delete.DeleteSnapshotRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.deleteSnapshotRequest; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -36,8 +37,9 @@ */ public class RestDeleteSnapshotAction extends BaseRestHandler { - public RestDeleteSnapshotAction(RestController controller) { - controller.registerHandler(DELETE, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_snapshot/{repository}/{snapshot}", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java index a0258974cfc41..8a93865857a19 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestDeleteStoredScriptAction.java @@ -21,18 +21,20 @@ import org.elasticsearch.action.admin.cluster.storedscripts.DeleteStoredScriptRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteStoredScriptAction extends BaseRestHandler { - public RestDeleteStoredScriptAction(RestController controller) { - controller.registerHandler(DELETE, "/_scripts/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_scripts/{id}", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java index 5b39a7e6df34f..82276f67c6aa3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetRepositoriesAction.java @@ -25,13 +25,15 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsFilter; 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 java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.getRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -42,9 +44,7 @@ public class RestGetRepositoriesAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestGetRepositoriesAction(RestController controller, SettingsFilter settingsFilter) { - controller.registerHandler(GET, "/_snapshot", this); - controller.registerHandler(GET, "/_snapshot/{repository}", this); + public RestGetRepositoriesAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; } @@ -53,6 +53,13 @@ public String getName() { return "get_repositories_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_snapshot", GET), + new Route("/_snapshot/{repository}", GET))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { final String[] repositories = request.paramAsStringArray("repository", Strings.EMPTY_ARRAY); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java index 9a40225b769ba..c0f1f0d30bf2e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptContextAction.java @@ -22,20 +22,21 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptContextAction; import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptContextRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; 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.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetScriptContextAction extends BaseRestHandler { - @Inject - public RestGetScriptContextAction(RestController controller) { - controller.registerHandler(GET, "/_script_context", this); + + @Override + public List handledRoutes() { + return singletonList(new Route("/_script_context", GET)); } @Override public String getName() { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java index c9246b910cf4f..707ebe463829c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetScriptLanguageAction.java @@ -22,20 +22,21 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptLanguageAction; import org.elasticsearch.action.admin.cluster.storedscripts.GetScriptLanguageRequest; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; 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.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetScriptLanguageAction extends BaseRestHandler { - @Inject - public RestGetScriptLanguageAction(RestController controller) { - controller.registerHandler(GET, "/_script_language", this); + + @Override + public List handledRoutes() { + return singletonList(new Route("/_script_language", GET)); } @Override public String getName() { diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java index f47ddefa8f67a..3bd8faa2cf8b5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetSnapshotsAction.java @@ -23,12 +23,13 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.Collections.singletonList; import static org.elasticsearch.client.Requests.getSnapshotsRequest; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -37,8 +38,9 @@ */ public class RestGetSnapshotsAction extends BaseRestHandler { - public RestGetSnapshotsAction(RestController controller) { - controller.registerHandler(GET, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_snapshot/{repository}/{snapshot}", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java index f87c6f513b79c..09059c218c760 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetStoredScriptAction.java @@ -21,18 +21,20 @@ import org.elasticsearch.action.admin.cluster.storedscripts.GetStoredScriptRequest; 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.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetStoredScriptAction extends BaseRestHandler { - public RestGetStoredScriptAction(RestController controller) { - controller.registerHandler(GET, "/_scripts/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_scripts/{id}", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java index f0ca02f43bc35..357f8342ab94c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestGetTaskAction.java @@ -23,19 +23,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; 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.TaskId; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetTaskAction extends BaseRestHandler { - public RestGetTaskAction(RestController controller) { - controller.registerHandler(GET, "/_tasks/{task_id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_tasks/{task_id}", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java index 4627b853ac714..2ab497a956a8e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestListTasksAction.java @@ -30,7 +30,6 @@ 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.RestStatus; @@ -39,8 +38,10 @@ import org.elasticsearch.tasks.TaskId; import java.io.IOException; +import java.util.List; import java.util.function.Supplier; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -48,9 +49,13 @@ public class RestListTasksAction extends BaseRestHandler { private final Supplier nodesInCluster; - public RestListTasksAction(RestController controller, Supplier nodesInCluster) { + public RestListTasksAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; - controller.registerHandler(GET, "/_tasks", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_tasks", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java index 07b85266d9d8c..ce4428d2da49c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesHotThreadsAction.java @@ -27,27 +27,32 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestResponseListener; 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; -public class RestNodesHotThreadsAction extends BaseRestHandler { - public RestNodesHotThreadsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/hot_threads", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/{nodeId}/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_cluster/nodes/{nodeId}/hot_threads", this); +public class RestNodesHotThreadsAction extends BaseRestHandler { - controller.registerHandler(RestRequest.Method.GET, "/_nodes/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_nodes/hot_threads", this); - controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/hotthreads", this); - controller.registerHandler(RestRequest.Method.GET, "/_nodes/{nodeId}/hot_threads", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cluster/nodes/hotthreads", GET), + new Route("/_cluster/nodes/hot_threads", GET), + new Route("/_cluster/nodes/{nodeId}/hotthreads", GET), + new Route("/_cluster/nodes/{nodeId}/hot_threads", GET), + new Route("/_nodes/hotthreads", GET), + new Route("/_nodes/hot_threads", GET), + new Route("/_nodes/{nodeId}/hotthreads", GET), + new Route("/_nodes/{nodeId}/hot_threads", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java index ab39c4408f212..ab1fa61e50f2a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesInfoAction.java @@ -26,13 +26,15 @@ import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import java.io.IOException; +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; public class RestNodesInfoAction extends BaseRestHandler { @@ -50,17 +52,21 @@ public class RestNodesInfoAction extends BaseRestHandler { private final SettingsFilter settingsFilter; - public RestNodesInfoAction(RestController controller, SettingsFilter settingsFilter) { - controller.registerHandler(GET, "/_nodes", this); - // this endpoint is used for metrics, not for node IDs, like /_nodes/fs - controller.registerHandler(GET, "/_nodes/{nodeId}", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/{metrics}", this); - // added this endpoint to be aligned with stats - controller.registerHandler(GET, "/_nodes/{nodeId}/info/{metrics}", this); - + public RestNodesInfoAction(SettingsFilter settingsFilter) { this.settingsFilter = settingsFilter; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_nodes", GET), + // this endpoint is used for metrics, not for node IDs, like /_nodes/fs + new Route("/_nodes/{nodeId}", GET), + new Route("/_nodes/{nodeId}/{metrics}", GET), + // added this endpoint to be aligned with stats + new Route("/_nodes/{nodeId}/info/{metrics}", GET))); + } + @Override public String getName() { return "nodes_info_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java index f8127b32db0a6..247530811ee32 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsAction.java @@ -25,34 +25,35 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.function.Consumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static java.util.Map.entry; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesStatsAction extends BaseRestHandler { - public RestNodesStatsAction(RestController controller) { - controller.registerHandler(GET, "/_nodes/stats", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/stats", this); - - controller.registerHandler(GET, "/_nodes/stats/{metric}", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/stats/{metric}", this); - - controller.registerHandler(GET, "/_nodes/stats/{metric}/{index_metric}", this); - - controller.registerHandler(GET, "/_nodes/{nodeId}/stats/{metric}/{index_metric}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_nodes/stats", GET), + new Route("/_nodes/{nodeId}/stats", GET), + new Route("/_nodes/stats/{metric}", GET), + new Route("/_nodes/{nodeId}/stats/{metric}", GET), + new Route("/_nodes/stats/{metric}/{index_metric}", GET), + new Route("/_nodes/{nodeId}/stats/{metric}/{index_metric}", GET))); } static final Map> METRICS = Map.ofEntries( diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java index f1a3b15d8b654..28a5dbc41a642 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestNodesUsageAction.java @@ -23,11 +23,9 @@ import org.elasticsearch.action.admin.cluster.node.usage.NodesUsageResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -35,20 +33,23 @@ import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +import java.util.List; import java.util.Locale; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesUsageAction extends BaseRestHandler { - @Inject - public RestNodesUsageAction(RestController controller) { - controller.registerHandler(GET, "/_nodes/usage", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/usage", this); - - controller.registerHandler(GET, "/_nodes/usage/{metric}", this); - controller.registerHandler(GET, "/_nodes/{nodeId}/usage/{metric}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_nodes/usage", GET), + new Route("/_nodes/{nodeId}/usage", GET), + new Route("/_nodes/usage/{metric}", GET), + new Route("/_nodes/{nodeId}/usage/{metric}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java index dbf03e35130c6..f4a5de4aec7b4 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPendingClusterTasksAction.java @@ -22,16 +22,20 @@ import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestPendingClusterTasksAction extends BaseRestHandler { - public RestPendingClusterTasksAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_cluster/pending_tasks", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cluster/pending_tasks", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java index 150296d65aea9..4dec6ae142314 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutRepositoryAction.java @@ -23,12 +23,14 @@ 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 java.io.IOException; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.putRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -38,9 +40,11 @@ */ public class RestPutRepositoryAction extends BaseRestHandler { - public RestPutRepositoryAction(RestController controller) { - controller.registerHandler(PUT, "/_snapshot/{repository}", this); - controller.registerHandler(POST, "/_snapshot/{repository}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_snapshot/{repository}", POST), + new Route("/_snapshot/{repository}", PUT))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java index 2e316abc14296..9100125c72754 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestPutStoredScriptAction.java @@ -23,23 +23,27 @@ import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.xcontent.XContentType; 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.StoredScriptSource; 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; public class RestPutStoredScriptAction extends BaseRestHandler { - public RestPutStoredScriptAction(RestController controller) { - controller.registerHandler(POST, "/_scripts/{id}", this); - controller.registerHandler(PUT, "/_scripts/{id}", this); - controller.registerHandler(POST, "/_scripts/{id}/{context}", this); - controller.registerHandler(PUT, "/_scripts/{id}/{context}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_scripts/{id}", POST), + new Route("/_scripts/{id}", PUT), + new Route("/_scripts/{id}/{context}", POST), + new Route("/_scripts/{id}/{context}", PUT))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java index e5f85c569ee6b..a15e62f703816 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestReloadSecureSettingsAction.java @@ -30,7 +30,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -38,7 +37,10 @@ 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; public final class RestReloadSecureSettingsAction extends BaseRestHandler { @@ -51,16 +53,18 @@ public final class RestReloadSecureSettingsAction extends BaseRestHandler { new ParseField("secure_settings_password")); } - public RestReloadSecureSettingsAction(RestController controller) { - controller.registerHandler(POST, "/_nodes/reload_secure_settings", this); - controller.registerHandler(POST, "/_nodes/{nodeId}/reload_secure_settings", this); - } - @Override public String getName() { return "nodes_reload_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_nodes/reload_secure_settings", POST), + new Route("/_nodes/{nodeId}/reload_secure_settings", POST))); + } + @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { final String[] nodesIds = Strings.splitStringByCommaToArray(request.param("nodeId")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java index a49f6d1319ba2..1d0d46ce525fd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRemoteClusterInfoAction.java @@ -23,16 +23,19 @@ import org.elasticsearch.action.admin.cluster.remote.RemoteInfoRequest; 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.RestToXContentListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public final class RestRemoteClusterInfoAction extends BaseRestHandler { - public RestRemoteClusterInfoAction(RestController controller) { - controller.registerHandler(GET, "_remote/info", this); + @Override + public List handledRoutes() { + return singletonList(new Route("_remote/info", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java index fb47e928ab87e..4276880a8a48e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestRestoreSnapshotAction.java @@ -22,12 +22,13 @@ import org.elasticsearch.action.admin.cluster.snapshots.restore.RestoreSnapshotRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.restoreSnapshotRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -36,8 +37,9 @@ */ public class RestRestoreSnapshotAction extends BaseRestHandler { - public RestRestoreSnapshotAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}/_restore", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_snapshot/{repository}/{snapshot}/_restore", POST)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java index f8347d38cd576..de29792d589b6 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestSnapshotsStatusAction.java @@ -23,12 +23,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.client.Requests.snapshotsStatusRequest; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -37,10 +39,12 @@ */ public class RestSnapshotsStatusAction extends BaseRestHandler { - public RestSnapshotsStatusAction(RestController controller) { - controller.registerHandler(GET, "/_snapshot/{repository}/{snapshot}/_status", this); - controller.registerHandler(GET, "/_snapshot/{repository}/_status", this); - controller.registerHandler(GET, "/_snapshot/_status", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_snapshot/{repository}/{snapshot}/_status", GET), + new Route("/_snapshot/{repository}/_status", GET), + new Route("/_snapshot/_status", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java index be69e73275c81..c2c557d58d03a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/cluster/RestVerifyRepositoryAction.java @@ -22,19 +22,21 @@ import org.elasticsearch.action.admin.cluster.repositories.verify.VerifyRepositoryRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.client.Requests.verifyRepositoryRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestVerifyRepositoryAction extends BaseRestHandler { - public RestVerifyRepositoryAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/_verify", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_snapshot/{repository}/_verify", POST)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java index af9bfbfe595dd..357aa0ee42c0e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeAction.java @@ -23,12 +23,14 @@ import org.elasticsearch.common.ParseField; 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; @@ -46,11 +48,13 @@ public static class Fields { public static final ParseField NORMALIZER = new ParseField("normalizer"); } - public RestAnalyzeAction(RestController controller) { - controller.registerHandler(GET, "/_analyze", this); - controller.registerHandler(GET, "/{index}/_analyze", this); - controller.registerHandler(POST, "/_analyze", this); - controller.registerHandler(POST, "/{index}/_analyze", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_analyze", GET), + new Route("/_analyze", POST), + new Route("/{index}/_analyze", GET), + new Route("/{index}/_analyze", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java index bc2fed911b3ac..c48e4bc882034 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestClearIndicesCacheAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.POST; public class RestClearIndicesCacheAction extends BaseRestHandler { - public RestClearIndicesCacheAction(RestController controller) { - controller.registerHandler(POST, "/_cache/clear", this); - controller.registerHandler(POST, "/{index}/_cache/clear", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cache/clear", POST), + new Route("/{index}/_cache/clear", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java index 3f26b1978372d..11cf94358c8ee 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCloseIndexAction.java @@ -25,17 +25,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.POST; public class RestCloseIndexAction extends BaseRestHandler { - public RestCloseIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_close", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_close", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_close", POST), + new Route("/{index}/_close", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java index a43c508f7487a..dea25679dee02 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestCreateIndexAction.java @@ -26,19 +26,23 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.mapper.MapperService; 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.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; +import static java.util.Collections.singletonMap; +import static org.elasticsearch.rest.RestRequest.Method.PUT; + public class RestCreateIndexAction extends BaseRestHandler { - public RestCreateIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}", PUT)); } @Override @@ -79,7 +83,7 @@ static Map prepareMappings(Map source) { throw new IllegalArgumentException("The mapping definition cannot be nested under a type"); } - newSource.put("mappings", Collections.singletonMap(MapperService.SINGLE_MAPPING_NAME, mappings)); + newSource.put("mappings", singletonMap(MapperService.SINGLE_MAPPING_NAME, mappings)); return newSource; } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java index b0d02cd19b7eb..ace876907af61 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexAction.java @@ -24,17 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.DELETE; public class RestDeleteIndexAction extends BaseRestHandler { - public RestDeleteIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/", this); - controller.registerHandler(RestRequest.Method.DELETE, "/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/", DELETE), + new Route("/{index}", DELETE))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java index c0679bb356249..44b231ce84f19 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestDeleteIndexTemplateAction.java @@ -21,16 +21,20 @@ import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteIndexTemplateAction extends BaseRestHandler { - public RestDeleteIndexTemplateAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_template/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_template/{name}", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java index f9d614e9b9912..99222bbd1cb3c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestFlushAction.java @@ -24,23 +24,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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; public class RestFlushAction extends BaseRestHandler { - public RestFlushAction(RestController controller) { - controller.registerHandler(POST, "/_flush", this); - controller.registerHandler(POST, "/{index}/_flush", this); - - controller.registerHandler(GET, "/_flush", this); - controller.registerHandler(GET, "/{index}/_flush", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_flush", GET), + new Route("/_flush", POST), + new Route("/{index}/_flush", GET), + new Route("/{index}/_flush", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java index e6f5ef549d1c0..10996ef7e9110 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestForceMergeAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.POST; public class RestForceMergeAction extends BaseRestHandler { - public RestForceMergeAction(final RestController controller) { - controller.registerHandler(POST, "/_forcemerge", this); - controller.registerHandler(POST, "/{index}/_forcemerge", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_forcemerge", POST), + new Route("/{index}/_forcemerge", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java index 3379ab009573f..13259b23bcc32 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetAliasesAction.java @@ -33,7 +33,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -47,6 +46,8 @@ import java.util.SortedSet; import java.util.TreeSet; +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.HEAD; @@ -55,15 +56,17 @@ */ public class RestGetAliasesAction extends BaseRestHandler { - public RestGetAliasesAction(final RestController controller) { - controller.registerHandler(GET, "/_alias", this); - controller.registerHandler(GET, "/_aliases", this); - controller.registerHandler(GET, "/_alias/{name}", this); - controller.registerHandler(HEAD, "/_alias/{name}", this); - controller.registerHandler(GET, "/{index}/_alias", this); - controller.registerHandler(HEAD, "/{index}/_alias", this); - controller.registerHandler(GET, "/{index}/_alias/{name}", this); - controller.registerHandler(HEAD, "/{index}/_alias/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_alias", GET), + new Route("/_aliases", GET), + new Route("/_alias/{name}", GET), + new Route("/_alias/{name}", HEAD), + new Route("/{index}/_alias", GET), + new Route("/{index}/_alias", HEAD), + new Route("/{index}/_alias/{name}", GET), + new Route("/{index}/_alias/{name}", HEAD))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java index d4a5a0cb58140..4762e3c022af8 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetFieldMappingAction.java @@ -28,24 +28,28 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import java.io.IOException; +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.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; public class RestGetFieldMappingAction extends BaseRestHandler { - public RestGetFieldMappingAction(RestController controller) { - controller.registerHandler(GET, "/_mapping/field/{fields}", this); - controller.registerHandler(GET, "/{index}/_mapping/field/{fields}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_mapping/field/{fields}", GET), + new Route("/{index}/_mapping/field/{fields}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java index 0c99ccef08e8c..a20b9cb3e2108 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndexTemplateAction.java @@ -25,14 +25,16 @@ import org.elasticsearch.common.Strings; 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.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; +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.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; @@ -43,10 +45,12 @@ */ public class RestGetIndexTemplateAction extends BaseRestHandler { - public RestGetIndexTemplateAction(final RestController controller) { - controller.registerHandler(GET, "/_template", this); - controller.registerHandler(GET, "/_template/{name}", this); - controller.registerHandler(HEAD, "/_template/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_template", GET), + new Route("/_template/{name}", GET), + new Route("/_template/{name}", HEAD))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java index e39ff1cf70170..4687bdff35936 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetIndicesAction.java @@ -26,13 +26,15 @@ import org.elasticsearch.common.Strings; 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 java.io.IOException; +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.HEAD; @@ -41,9 +43,11 @@ */ public class RestGetIndicesAction extends BaseRestHandler { - public RestGetIndicesAction(final RestController controller) { - controller.registerHandler(GET, "/{index}", this); - controller.registerHandler(HEAD, "/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}", GET), + new Route("/{index}", HEAD))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java index f42099e4219aa..33c5e1c0f5a52 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetMappingAction.java @@ -27,23 +27,27 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; 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.GET; public class RestGetMappingAction extends BaseRestHandler { - public RestGetMappingAction(final RestController controller) { - controller.registerHandler(GET, "/_mapping", this); - controller.registerHandler(GET, "/_mappings", this); - controller.registerHandler(GET, "/{index}/_mappings", this); - controller.registerHandler(GET, "/{index}/_mapping", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_mapping", GET), + new Route("/_mappings", GET), + new Route("/{index}/_mapping", GET), + new Route("/{index}/_mappings", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java index c7b9cc485d3ce..c16fa4400d0aa 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestGetSettingsAction.java @@ -24,22 +24,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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; public class RestGetSettingsAction extends BaseRestHandler { - public RestGetSettingsAction(RestController controller) { - controller.registerHandler(GET, "/_settings", this); - controller.registerHandler(GET, "/_settings/{name}", this); - controller.registerHandler(GET, "/{index}/_settings", this); - controller.registerHandler(GET, "/{index}/_settings/{name}", this); - controller.registerHandler(GET, "/{index}/_setting/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_settings", GET), + new Route("/_settings/{name}", GET), + new Route("/{index}/_settings", GET), + new Route("/{index}/_settings/{name}", GET), + new Route("/{index}/_setting/{name}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java index 91442bb2fb9e1..2f5035b7a01e1 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexDeleteAliasesAction.java @@ -23,19 +23,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.DELETE; public class RestIndexDeleteAliasesAction extends BaseRestHandler { - public RestIndexDeleteAliasesAction(RestController controller) { - controller.registerHandler(DELETE, "/{index}/_alias/{name}", this); - controller.registerHandler(DELETE, "/{index}/_aliases/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_alias/{name}", DELETE), + new Route("/{index}/_aliases/{name}", DELETE))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java index 3c51c9111f2ae..33e801fd94c8f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndexPutAliasAction.java @@ -24,32 +24,34 @@ 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 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; public class RestIndexPutAliasAction extends BaseRestHandler { - public RestIndexPutAliasAction(RestController controller) { - controller.registerHandler(PUT, "/{index}/_alias/{name}", this); - controller.registerHandler(PUT, "/_alias/{name}", this); - controller.registerHandler(PUT, "/{index}/_aliases/{name}", this); - controller.registerHandler(PUT, "/_aliases/{name}", this); - controller.registerHandler(PUT, "/{index}/_alias", this); - controller.registerHandler(PUT, "/_alias", this); - - controller.registerHandler(POST, "/{index}/_alias/{name}", this); - controller.registerHandler(POST, "/_alias/{name}", this); - controller.registerHandler(POST, "/{index}/_aliases/{name}", this); - controller.registerHandler(POST, "/_aliases/{name}", this); - controller.registerHandler(PUT, "/{index}/_aliases", this); - //we cannot add POST for "/_aliases" because this is the _aliases api already defined in RestIndicesAliasesAction + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_alias/{name}", POST), + new Route("/{index}/_alias/{name}", PUT), + new Route("/_alias/{name}", POST), + new Route("/_alias/{name}", PUT), + new Route("/{index}/_aliases/{name}", POST), + new Route("/{index}/_aliases/{name}", PUT), + new Route("/_aliases/{name}", POST), + new Route("/_aliases/{name}", PUT), + new Route("/{index}/_alias", PUT), + new Route("/{index}/_aliases", PUT), + new Route("/_alias", PUT))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java index d305c5ad3ca46..076acd43cae34 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesAliasesAction.java @@ -23,12 +23,13 @@ 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 java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestIndicesAliasesAction extends BaseRestHandler { @@ -38,8 +39,9 @@ public String getName() { return "indices_aliases_action"; } - public RestIndicesAliasesAction(RestController controller) { - controller.registerHandler(POST, "/_aliases", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_aliases", POST)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java index ed76c36dac34c..ceee6155f1a95 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesSegmentsAction.java @@ -24,19 +24,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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; public class RestIndicesSegmentsAction extends BaseRestHandler { - public RestIndicesSegmentsAction(RestController controller) { - controller.registerHandler(GET, "/_segments", this); - controller.registerHandler(GET, "/{index}/_segments", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_segments", GET), + new Route("/{index}/_segments", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java index e214e7bbb3411..67794e3f5b8f5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesShardStoresAction.java @@ -28,13 +28,15 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -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.GET; import static org.elasticsearch.rest.RestStatus.OK; @@ -43,9 +45,11 @@ */ public class RestIndicesShardStoresAction extends BaseRestHandler { - public RestIndicesShardStoresAction(RestController controller) { - controller.registerHandler(GET, "/_shard_stores", this); - controller.registerHandler(GET, "/{index}/_shard_stores", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_shard_stores", GET), + new Route("/{index}/_shard_stores", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java index 4562365c8abec..dcae0372613e1 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java @@ -26,28 +26,32 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.Collections; import java.util.HashMap; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.TreeSet; import java.util.function.Consumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestIndicesStatsAction extends BaseRestHandler { - public RestIndicesStatsAction(RestController controller) { - controller.registerHandler(GET, "/_stats", this); - controller.registerHandler(GET, "/_stats/{metric}", this); - controller.registerHandler(GET, "/{index}/_stats", this); - controller.registerHandler(GET, "/{index}/_stats/{metric}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_stats", GET), + new Route("/_stats/{metric}", GET), + new Route("/{index}/_stats", GET), + new Route("/{index}/_stats/{metric}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java index 8eb5c3a74bd73..16f65bc3b5df3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestOpenIndexAction.java @@ -25,17 +25,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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.POST; public class RestOpenIndexAction extends BaseRestHandler { - public RestOpenIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_open", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_open", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_open", POST), + new Route("/{index}/_open", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java index 68e62ac3c684f..a3a6dac7a5820 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutIndexTemplateAction.java @@ -24,19 +24,25 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.xcontent.XContentHelper; 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.Arrays; +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; + public class RestPutIndexTemplateAction extends BaseRestHandler { - public RestPutIndexTemplateAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_template/{name}", this); - controller.registerHandler(RestRequest.Method.POST, "/_template/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_template/{name}", POST), + new Route("/_template/{name}", PUT))); } @Override @@ -48,7 +54,7 @@ public String getName() { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name")); - putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY))); + putRequest.patterns(asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY))); putRequest.order(request.paramAsInt("order", putRequest.order())); putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout())); putRequest.create(request.paramAsBoolean("create", false)); diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java index 3e9f984f15170..de837f1fa9e97 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestPutMappingAction.java @@ -26,26 +26,28 @@ import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.index.mapper.MapperService; 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 java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.putMappingRequest; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutMappingAction extends BaseRestHandler { - public RestPutMappingAction(RestController controller) { - controller.registerHandler(PUT, "/{index}/_mapping/", this); - controller.registerHandler(POST, "/{index}/_mapping/", this); - - //register the same paths, but with plural form _mappings - controller.registerHandler(PUT, "/{index}/_mappings/", this); - controller.registerHandler(POST, "/{index}/_mappings/", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_mapping/", POST), + new Route("/{index}/_mapping/", PUT), + new Route("/{index}/_mappings/", POST), + new Route("/{index}/_mappings/", PUT))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java index 38325a17f489d..c908c143a2e22 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRecoveryAction.java @@ -24,12 +24,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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; /** @@ -37,9 +39,11 @@ */ public class RestRecoveryAction extends BaseRestHandler { - public RestRecoveryAction(RestController controller) { - controller.registerHandler(GET, "/_recovery", this); - controller.registerHandler(GET, "/{index}/_recovery", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_recovery", GET), + new Route("/{index}/_recovery", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java index 5e89e16d068fa..5f052cab74f93 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRefreshAction.java @@ -25,24 +25,27 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; 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; public class RestRefreshAction extends BaseRestHandler { - public RestRefreshAction(RestController controller) { - controller.registerHandler(POST, "/_refresh", this); - controller.registerHandler(POST, "/{index}/_refresh", this); - - controller.registerHandler(GET, "/_refresh", this); - controller.registerHandler(GET, "/{index}/_refresh", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_refresh", GET), + new Route("/_refresh", POST), + new Route("/{index}/_refresh", GET), + new Route("/{index}/_refresh", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java index 291cf61caf7b6..756d317979b53 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResizeHandler.java @@ -24,11 +24,16 @@ import org.elasticsearch.action.support.ActiveShardCount; 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.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.POST; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public abstract class RestResizeHandler extends BaseRestHandler { @@ -53,9 +58,11 @@ public final RestChannelConsumer prepareRequest(final RestRequest request, final public static class RestShrinkIndexAction extends RestResizeHandler { - public RestShrinkIndexAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_shrink/{target}", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_shrink/{target}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_shrink/{target}", POST), + new Route("/{index}/_shrink/{target}", PUT))); } @Override @@ -72,9 +79,11 @@ protected ResizeType getResizeType() { public static class RestSplitIndexAction extends RestResizeHandler { - public RestSplitIndexAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_split/{target}", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_split/{target}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_split/{target}", POST), + new Route("/{index}/_split/{target}", PUT))); } @Override @@ -91,9 +100,11 @@ protected ResizeType getResizeType() { public static class RestCloneIndexAction extends RestResizeHandler { - public RestCloneIndexAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_clone/{target}", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_clone/{target}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_clone/{target}", POST), + new Route("/{index}/_clone/{target}", PUT))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java index d90f0d7e23f19..e2e083a5f3aac 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestRolloverIndexAction.java @@ -23,17 +23,23 @@ import org.elasticsearch.action.support.ActiveShardCount; 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.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.POST; public class RestRolloverIndexAction extends BaseRestHandler { - - public RestRolloverIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_rollover/{new_index}", this); + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_rollover", POST), + new Route("/{index}/_rollover/{new_index}", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java index d775189af48e3..0fc8a9fbdedad 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestSyncedFlushAction.java @@ -31,14 +31,16 @@ 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.RestStatus; 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; @@ -47,12 +49,13 @@ public class RestSyncedFlushAction extends BaseRestHandler { private static final Logger logger = LogManager.getLogger(RestSyncedFlushAction.class); private static final DeprecationLogger DEPRECATION_LOGGER = new DeprecationLogger(logger); - public RestSyncedFlushAction(RestController controller) { - controller.registerHandler(POST, "/_flush/synced", this); - controller.registerHandler(POST, "/{index}/_flush/synced", this); - - controller.registerHandler(GET, "/_flush/synced", this); - controller.registerHandler(GET, "/{index}/_flush/synced", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_flush/synced", GET), + new Route("/_flush/synced", POST), + new Route("/{index}/_flush/synced", GET), + new Route("/{index}/_flush/synced", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java index e26bf9f318e5e..e313d6c920963 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpdateSettingsAction.java @@ -25,20 +25,25 @@ import org.elasticsearch.common.Strings; 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 java.io.IOException; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.client.Requests.updateSettingsRequest; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestUpdateSettingsAction extends BaseRestHandler { - public RestUpdateSettingsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_settings", this); - controller.registerHandler(RestRequest.Method.PUT, "/_settings", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_settings", PUT), + new Route("/_settings", PUT))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java index f63fe49ec6e91..962d74b8252bc 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeActionDeprecated.java @@ -26,12 +26,15 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; 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.Collections; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpgradeActionDeprecated extends BaseRestHandler { @@ -42,11 +45,16 @@ public class RestUpgradeActionDeprecated extends BaseRestHandler { public static final String UPGRADE_API_DEPRECATION_MESSAGE = "The _upgrade API is no longer useful and will be removed. Instead, see _reindex API."; - public RestUpgradeActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(POST, "/_upgrade", this, - UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger); - controller.registerAsDeprecatedHandler(POST, "/{index}/_upgrade", this, - UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger); + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute("/_upgrade", POST, UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger), + new DeprecatedRoute("/{index}/_upgrade", POST, UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger))); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusActionDeprecated.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusActionDeprecated.java index 1eb09b31ce26f..d9169efd7a8d5 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusActionDeprecated.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestUpgradeStatusActionDeprecated.java @@ -26,12 +26,15 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; 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.Collections; +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.action.admin.indices.RestUpgradeActionDeprecated.UPGRADE_API_DEPRECATION_MESSAGE; @@ -40,11 +43,16 @@ public class RestUpgradeStatusActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestUpgradeStatusActionDeprecated.class)); - public RestUpgradeStatusActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(GET, "/_upgrade", this, - UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger); - controller.registerAsDeprecatedHandler(GET, "/{index}/_upgrade", this, - UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger); + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute("/_upgrade", GET, UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger), + new DeprecatedRoute("/{index}/_upgrade", GET, UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger))); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java index d176dad12e198..203e20c0028d2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryAction.java @@ -30,24 +30,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.action.RestActions; 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; import static org.elasticsearch.rest.RestStatus.OK; public class RestValidateQueryAction extends BaseRestHandler { - public RestValidateQueryAction(RestController controller) { - controller.registerHandler(GET, "/_validate/query", this); - controller.registerHandler(POST, "/_validate/query", this); - controller.registerHandler(GET, "/{index}/_validate/query", this); - controller.registerHandler(POST, "/{index}/_validate/query", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_validate/query", GET), + new Route("/_validate/query", POST), + new Route("/{index}/_validate/query", GET), + new Route("/{index}/_validate/query", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java index 4fd43becf431b..805a41a5827c9 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAliasAction.java @@ -25,20 +25,23 @@ import org.elasticsearch.cluster.metadata.AliasMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestAliasAction extends AbstractCatAction { - public RestAliasAction(RestController controller) { - controller.registerHandler(GET, "/_cat/aliases", this); - controller.registerHandler(GET, "/_cat/aliases/{alias}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/aliases", GET), + new Route("/_cat/aliases/{alias}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java index 1f30fb917ea24..40005cc803f6e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestAllocationAction.java @@ -32,20 +32,25 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestAllocationAction extends AbstractCatAction { - public RestAllocationAction(RestController controller) { - controller.registerHandler(GET, "/_cat/allocation", this); - controller.registerHandler(GET, "/_cat/allocation/{nodes}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/allocation", GET), + new Route("/_cat/allocation/{nodes}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java index fe5f7b8127c5d..625797c8902e4 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatAction.java @@ -20,16 +20,15 @@ package org.elasticsearch.rest.action.cat; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import java.io.IOException; import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCatAction extends BaseRestHandler { @@ -38,9 +37,7 @@ public class RestCatAction extends BaseRestHandler { private static final String CAT_NL = CAT + "\n"; private final String HELP; - @Inject - public RestCatAction(RestController controller, List catActions) { - controller.registerHandler(GET, "/_cat", this); + public RestCatAction(List catActions) { StringBuilder sb = new StringBuilder(); sb.append(CAT_NL); for (AbstractCatAction catAction : catActions) { @@ -49,6 +46,11 @@ public RestCatAction(RestController controller, List catActio HELP = sb.toString(); } + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat", GET)); + } + @Override public String getName() { return "cat_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java index d16e17e937ece..19b54dec4de50 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCatRecoveryAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentElasticsearchExtension; import org.elasticsearch.indices.recovery.RecoveryState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -41,6 +40,8 @@ import java.util.List; import java.util.Locale; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -50,9 +51,11 @@ */ public class RestCatRecoveryAction extends AbstractCatAction { - public RestCatRecoveryAction(RestController restController) { - restController.registerHandler(GET, "/_cat/recovery", this); - restController.registerHandler(GET, "/_cat/recovery/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/recovery", GET), + new Route("/_cat/recovery/{index}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java index 7b7742972eac4..68fc996252f0b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java @@ -27,7 +27,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.index.query.QueryBuilder; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActions; @@ -35,13 +34,19 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; 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; public class RestCountAction extends AbstractCatAction { - public RestCountAction(RestController restController) { - restController.registerHandler(GET, "/_cat/count", this); - restController.registerHandler(GET, "/_cat/count/{index}", this); + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/count", GET), + new Route("/_cat/count/{index}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java index 2eb83151953fc..42d8eedee437c 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestFielddataAction.java @@ -26,11 +26,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -38,9 +41,11 @@ */ public class RestFielddataAction extends AbstractCatAction { - public RestFielddataAction(RestController controller) { - controller.registerHandler(GET, "/_cat/fielddata", this); - controller.registerHandler(GET, "/_cat/fielddata/{fields}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/fielddata", GET), + new Route("/_cat/fielddata/{fields}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java index 5e896f210f665..0adec09a4c2ec 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestHealthAction.java @@ -23,19 +23,21 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; import java.util.Locale; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestHealthAction extends AbstractCatAction { - public RestHealthAction(RestController controller) { - controller.registerHandler(GET, "/_cat/health", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/health", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java index 5a50b0ff04ce6..8c8e27635a339 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestIndicesAction.java @@ -43,7 +43,6 @@ import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.index.IndexSettings; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -51,10 +50,10 @@ import java.time.Instant; import java.time.ZoneOffset; import java.time.ZonedDateTime; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; @@ -62,6 +61,8 @@ import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.action.support.master.MasterNodeRequest.DEFAULT_MASTER_NODE_TIMEOUT; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -69,9 +70,11 @@ public class RestIndicesAction extends AbstractCatAction { private static final DateFormatter STRICT_DATE_TIME_FORMATTER = DateFormatter.forPattern("strict_date_time"); - public RestIndicesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/indices", this); - controller.registerHandler(GET, "/_cat/indices/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/indices", GET), + new Route("/_cat/indices/{index}", GET))); } @Override @@ -234,7 +237,7 @@ public void onFailure(final Exception e) { private static final Set RESPONSE_PARAMS; static { - final Set responseParams = new HashSet<>(Arrays.asList("local", "health")); + final Set responseParams = new HashSet<>(asList("local", "health")); responseParams.addAll(AbstractCatAction.RESPONSE_PARAMS); RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java index e50865af019c6..b127f25cd68d3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestMasterAction.java @@ -25,17 +25,20 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestMasterAction extends AbstractCatAction { - public RestMasterAction(RestController controller) { - controller.registerHandler(GET, "/_cat/master", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/master", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java index efae10a6aa256..71a39bef2ba40 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodeAttrsAction.java @@ -29,20 +29,22 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodeAttrsAction extends AbstractCatAction { - public RestNodeAttrsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/nodeattrs", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/nodeattrs", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java index ac26c43385004..53230d97d6bd2 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestNodesAction.java @@ -54,7 +54,6 @@ import org.elasticsearch.monitor.jvm.JvmStats; import org.elasticsearch.monitor.os.OsStats; import org.elasticsearch.monitor.process.ProcessStats; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -62,15 +61,18 @@ import org.elasticsearch.script.ScriptStats; import org.elasticsearch.search.suggest.completion.CompletionStats; +import java.util.List; import java.util.Locale; import java.util.stream.Collectors; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestNodesAction extends AbstractCatAction { - public RestNodesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/nodes", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/nodes", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java index 84bd87981536b..cd78abcf37d8f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPendingClusterTasksAction.java @@ -24,17 +24,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.service.PendingClusterTask; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestPendingClusterTasksAction extends AbstractCatAction { - public RestPendingClusterTasksAction(RestController controller) { - controller.registerHandler(GET, "/_cat/pending_tasks", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/pending_tasks", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java index eb6a6fc4b8ff8..841e1e98390c4 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestPluginsAction.java @@ -29,18 +29,21 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Table; import org.elasticsearch.plugins.PluginInfo; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestPluginsAction extends AbstractCatAction { - public RestPluginsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/plugins", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/plugins", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java index f77f9bf100bda..0e0dcfdfe5827 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestRepositoriesAction.java @@ -24,11 +24,13 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.cluster.metadata.RepositoryMetaData; import org.elasticsearch.common.Table; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -36,8 +38,9 @@ */ public class RestRepositoriesAction extends AbstractCatAction { - public RestRepositoriesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/repositories", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/repositories", GET)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java index c51fa593f3b5f..b604c6135e30b 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSegmentsAction.java @@ -31,7 +31,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.index.engine.Segment; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -40,13 +39,17 @@ 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; public class RestSegmentsAction extends AbstractCatAction { - public RestSegmentsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/segments", this); - controller.registerHandler(GET, "/_cat/segments/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/segments", GET), + new Route("/_cat/segments/{index}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java index 847b1a773e52a..6f07cd7f14b2f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestShardsAction.java @@ -45,7 +45,6 @@ import org.elasticsearch.index.shard.DocsStats; import org.elasticsearch.index.store.StoreStats; import org.elasticsearch.index.warmer.WarmerStats; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -53,16 +52,20 @@ import org.elasticsearch.search.suggest.completion.CompletionStats; import java.time.Instant; +import java.util.List; import java.util.Locale; import java.util.function.Function; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestShardsAction extends AbstractCatAction { - public RestShardsAction(RestController controller) { - controller.registerHandler(GET, "/_cat/shards", this); - controller.registerHandler(GET, "/_cat/shards/{index}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList(new Route("/_cat/shards", GET), + new Route("/_cat/shards/{index}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java index 94361b90eb8c4..104b043fdcc16 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestSnapshotAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -41,6 +40,8 @@ import java.util.Map; import java.util.concurrent.TimeUnit; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -48,9 +49,11 @@ */ public class RestSnapshotAction extends AbstractCatAction { - public RestSnapshotAction(RestController controller) { - controller.registerHandler(GET, "/_cat/snapshots", this); - controller.registerHandler(GET, "/_cat/snapshots/{repository}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/snapshots", GET), + new Route("/_cat/snapshots/{repository}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java index b6d5eb549bfa4..b5115962ab40a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTasksAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.time.DateFormatter; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -44,17 +43,22 @@ import java.util.Set; import java.util.function.Supplier; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.generateListTasksRequest; public class RestTasksAction extends AbstractCatAction { private final Supplier nodesInCluster; - public RestTasksAction(RestController controller, Supplier nodesInCluster) { - controller.registerHandler(GET, "/_cat/tasks", this); + public RestTasksAction(Supplier nodesInCluster) { this.nodesInCluster = nodesInCluster; } + @Override + public List handledRoutes() { + return singletonList(new Route("/_cat/tasks", GET)); + } + @Override public String getName() { return "cat_tasks_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java index c8da4648e2ac0..044c8c78cc239 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestTemplatesAction.java @@ -27,18 +27,23 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Table; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestTemplatesAction extends AbstractCatAction { - public RestTemplatesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/templates", this); - controller.registerHandler(GET, "/_cat/templates/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/templates", GET), + new Route("/_cat/templates/{name}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java b/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java index 571767affd0c0..d9c63e264c9a4 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/cat/RestThreadPoolAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.Table; import org.elasticsearch.common.regex.Regex; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActionListener; @@ -43,17 +42,22 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestThreadPoolAction extends AbstractCatAction { - public RestThreadPoolAction(RestController controller) { - controller.registerHandler(GET, "/_cat/thread_pool", this); - controller.registerHandler(GET, "/_cat/thread_pool/{thread_pool_patterns}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_cat/thread_pool", GET), + new Route("/_cat/thread_pool/{thread_pool_patterns}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java index db925cd663ff9..79d2708096cbd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestBulkAction.java @@ -26,13 +26,15 @@ 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.RestStatusToXContentListener; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; 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; @@ -49,15 +51,19 @@ public class RestBulkAction extends BaseRestHandler { private final boolean allowExplicitIndex; - public RestBulkAction(Settings settings, RestController controller) { - controller.registerHandler(POST, "/_bulk", this); - controller.registerHandler(PUT, "/_bulk", this); - controller.registerHandler(POST, "/{index}/_bulk", this); - controller.registerHandler(PUT, "/{index}/_bulk", this); - + public RestBulkAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_bulk", POST), + new Route("/_bulk", PUT), + new Route("/{index}/_bulk", POST), + new Route("/{index}/_bulk", PUT))); + } + @Override public String getName() { return "bulk_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java index bf7cd0d8da6e4..4cd8796e80c9f 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestDeleteAction.java @@ -24,19 +24,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteAction extends BaseRestHandler { - public RestDeleteAction(RestController controller) { - controller.registerHandler(DELETE, "/{index}/_doc/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_doc/{id}", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java index d90431d2c0cdb..67a5927f99f62 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetAction.java @@ -25,7 +25,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestActions; @@ -33,7 +32,10 @@ import org.elasticsearch.search.fetch.subphase.FetchSourceContext; 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.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; @@ -41,16 +43,18 @@ public class RestGetAction extends BaseRestHandler { - public RestGetAction(final RestController controller) { - controller.registerHandler(GET, "/{index}/_doc/{id}", this); - controller.registerHandler(HEAD, "/{index}/_doc/{id}", this); - } - @Override public String getName() { return "document_get_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_doc/{id}", GET), + new Route("/{index}/_doc/{id}", HEAD))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { GetRequest getRequest = new GetRequest(request.param("index"), request.param("id")); diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java index c9cb5a5fb0f5e..59fbef33a6ddf 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestGetSourceAction.java @@ -30,7 +30,6 @@ 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.RestResponseListener; @@ -38,7 +37,10 @@ import java.io.IOException; import java.io.InputStream; +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.HEAD; import static org.elasticsearch.rest.RestStatus.OK; @@ -48,9 +50,11 @@ */ public class RestGetSourceAction extends BaseRestHandler { - public RestGetSourceAction(final RestController controller) { - controller.registerHandler(GET, "/{index}/_source/{id}", this); - controller.registerHandler(HEAD, "/{index}/_source/{id}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_source/{id}", GET), + new Route("/{index}/_source/{id}", HEAD))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java index 03ae85e380e82..11128bcf2046d 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestIndexAction.java @@ -26,32 +26,27 @@ import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; +import java.util.List; import java.util.Locale; +import static java.util.Arrays.asList; +import static java.util.Collections.singletonList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestIndexAction extends BaseRestHandler { - private final ClusterService clusterService; - - public RestIndexAction(RestController controller, ClusterService clusterService) { - this.clusterService = clusterService; - - AutoIdHandler autoIdHandler = new AutoIdHandler(); - controller.registerHandler(POST, "/{index}/_doc", autoIdHandler); // auto id creation - controller.registerHandler(PUT, "/{index}/_doc/{id}", this); - controller.registerHandler(POST, "/{index}/_doc/{id}", this); - - CreateHandler createHandler = new CreateHandler(); - controller.registerHandler(PUT, "/{index}/_create/{id}", createHandler); - controller.registerHandler(POST, "/{index}/_create/{id}/", createHandler); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_doc/{id}", POST), + new Route("/{index}/_doc/{id}", PUT))); } @Override @@ -59,20 +54,25 @@ public String getName() { return "document_index_action"; } - final class CreateHandler extends BaseRestHandler { - protected CreateHandler() { - } + public static final class CreateHandler extends RestIndexAction { @Override public String getName() { return "document_create_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_create/{id}", POST), + new Route("/{index}/_create/{id}", PUT))); + } + @Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { validateOpType(request.params().get("op_type")); request.params().put("op_type", "create"); - return RestIndexAction.this.prepareRequest(request, client); + return super.prepareRequest(request, client); } void validateOpType(String opType) { @@ -82,8 +82,12 @@ void validateOpType(String opType) { } } - final class AutoIdHandler extends BaseRestHandler { - protected AutoIdHandler() { + public static final class AutoIdHandler extends RestIndexAction { + + private final ClusterService clusterService; + + public AutoIdHandler(ClusterService clusterService) { + this.clusterService = clusterService; } @Override @@ -91,6 +95,11 @@ public String getName() { return "document_create_action"; } + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_doc", POST)); + } + @Override public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient client) throws IOException { assert request.params().get("id") == null : "non-null id: " + request.params().get("id"); @@ -98,7 +107,7 @@ public RestChannelConsumer prepareRequest(RestRequest request, final NodeClient // default to op_type create request.params().put("op_type", "create"); } - return RestIndexAction.this.prepareRequest(request, client); + return super.prepareRequest(request, client); } } diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java index 7b1cb4aaaeba5..48fd1ac3d35d3 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiGetAction.java @@ -25,13 +25,15 @@ import org.elasticsearch.common.settings.Settings; 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.search.fetch.subphase.FetchSourceContext; 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; @@ -39,15 +41,19 @@ public class RestMultiGetAction extends BaseRestHandler { private final boolean allowExplicitIndex; - public RestMultiGetAction(Settings settings, RestController controller) { - controller.registerHandler(GET, "/_mget", this); - controller.registerHandler(POST, "/_mget", this); - controller.registerHandler(GET, "/{index}/_mget", this); - controller.registerHandler(POST, "/{index}/_mget", this); - + public RestMultiGetAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_mget", GET), + new Route("/_mget", POST), + new Route("/{index}/_mget", GET), + new Route("/{index}/_mget", POST))); + } + @Override public String getName() { return "document_mget_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java index 8d1b6c96b1d47..0edf24547cebd 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestMultiTermVectorsAction.java @@ -24,22 +24,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; 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; public class RestMultiTermVectorsAction extends BaseRestHandler { - public RestMultiTermVectorsAction(RestController controller) { - controller.registerHandler(GET, "/_mtermvectors", this); - controller.registerHandler(POST, "/_mtermvectors", this); - controller.registerHandler(GET, "/{index}/_mtermvectors", this); - controller.registerHandler(POST, "/{index}/_mtermvectors", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_mtermvectors", GET), + new Route("/_mtermvectors", POST), + new Route("/{index}/_mtermvectors", GET), + new Route("/{index}/_mtermvectors", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java index 66afda4879e35..566b988ec9266 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestTermVectorsAction.java @@ -25,15 +25,17 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestToXContentListener; import java.io.IOException; 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; @@ -43,11 +45,13 @@ */ public class RestTermVectorsAction extends BaseRestHandler { - public RestTermVectorsAction(RestController controller) { - controller.registerHandler(GET, "/{index}/_termvectors", this); - controller.registerHandler(POST, "/{index}/_termvectors", this); - controller.registerHandler(GET, "/{index}/_termvectors/{id}", this); - controller.registerHandler(POST, "/{index}/_termvectors/{id}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_termvectors", GET), + new Route("/{index}/_termvectors", POST), + new Route("/{index}/_termvectors/{id}", GET), + new Route("/{index}/_termvectors/{id}", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java b/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java index 82bcf1ffbaedb..de744f255cc8a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/document/RestUpdateAction.java @@ -26,20 +26,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.index.VersionType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpdateAction extends BaseRestHandler { - public RestUpdateAction(RestController controller) { - controller.registerHandler(POST, "/{index}/_update/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_update/{id}", POST)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java index dea61df609a92..0849a9b4bd661 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestDeletePipelineAction.java @@ -22,15 +22,19 @@ import org.elasticsearch.action.ingest.DeletePipelineRequest; 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.RestToXContentListener; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeletePipelineAction extends BaseRestHandler { - public RestDeletePipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_ingest/pipeline/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ingest/pipeline/{id}", DELETE)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java index 751b9ee68894a..e23af78a01c22 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestGetPipelineAction.java @@ -23,17 +23,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; 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; public class RestGetPipelineAction extends BaseRestHandler { - public RestGetPipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline", this); - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/{id}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_ingest/pipeline", GET), + new Route("/_ingest/pipeline/{id}", GET))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java index 3b1861c14f591..ea4cd85c5c429 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestPutPipelineAction.java @@ -25,17 +25,21 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.xcontent.XContentType; 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.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutPipelineAction extends BaseRestHandler { - public RestPutPipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_ingest/pipeline/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ingest/pipeline/{id}", PUT)); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java index 6b8d6c3ccc4cd..dfe5de212d38e 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/ingest/RestSimulatePipelineAction.java @@ -25,19 +25,26 @@ import org.elasticsearch.common.collect.Tuple; import org.elasticsearch.common.xcontent.XContentType; 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; public class RestSimulatePipelineAction extends BaseRestHandler { - public RestSimulatePipelineAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ingest/pipeline/{id}/_simulate", this); - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/{id}/_simulate", this); - controller.registerHandler(RestRequest.Method.POST, "/_ingest/pipeline/_simulate", this); - controller.registerHandler(RestRequest.Method.GET, "/_ingest/pipeline/_simulate", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_ingest/pipeline/{id}/_simulate", GET), + new Route("/_ingest/pipeline/{id}/_simulate", POST), + new Route("/_ingest/pipeline/_simulate", GET), + new Route("/_ingest/pipeline/_simulate", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java index a8c69867a57fd..97a413c1584ef 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestClearScrollAction.java @@ -23,19 +23,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import java.io.IOException; -import java.util.Arrays; +import java.util.List; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestClearScrollAction extends BaseRestHandler { - public RestClearScrollAction(RestController controller) { - controller.registerHandler(DELETE, "/_search/scroll", this); - controller.registerHandler(DELETE, "/_search/scroll/{scroll_id}", this); + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_search/scroll", DELETE), + new Route("/_search/scroll/{scroll_id}", DELETE))); } @Override @@ -47,7 +51,7 @@ public String getName() { public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String scrollIds = request.param("scroll_id"); ClearScrollRequest clearRequest = new ClearScrollRequest(); - clearRequest.setScrollIds(Arrays.asList(Strings.splitStringByCommaToArray(scrollIds))); + clearRequest.setScrollIds(asList(Strings.splitStringByCommaToArray(scrollIds))); request.withContentOrSourceParamParserOrNull((xContentParser -> { if (xContentParser != null) { // NOTE: if rest request with xcontent body has request parameters, values parsed from request body have the precedence diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java index bed40bffd5e8e..c1fe8edafc958 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestActions; @@ -36,7 +35,10 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; 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; import static org.elasticsearch.rest.action.RestActions.buildBroadcastShardsHeader; @@ -44,11 +46,13 @@ public class RestCountAction extends BaseRestHandler { - public RestCountAction(RestController controller) { - controller.registerHandler(POST, "/_count", this); - controller.registerHandler(GET, "/_count", this); - controller.registerHandler(POST, "/{index}/_count", this); - controller.registerHandler(GET, "/{index}/_count", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_count", GET), + new Route("/_count", POST), + new Route("/{index}/_count", GET), + new Route("/{index}/_count", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java index 5613540edad8e..5299a9fde31ce 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestExplainAction.java @@ -24,14 +24,16 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.search.fetch.subphase.FetchSourceContext; 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; @@ -40,9 +42,11 @@ */ public class RestExplainAction extends BaseRestHandler { - public RestExplainAction(RestController controller) { - controller.registerHandler(GET, "/{index}/_explain/{id}", this); - controller.registerHandler(POST, "/{index}/_explain/{id}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_explain/{id}", GET), + new Route("/{index}/_explain/{id}", POST))); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java index e0752d41926a8..0e20ff4f0bb4a 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java @@ -32,7 +32,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.search.builder.SearchSourceBuilder; @@ -44,6 +43,8 @@ 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; @@ -60,15 +61,19 @@ public class RestMultiSearchAction extends BaseRestHandler { private final boolean allowExplicitIndex; - public RestMultiSearchAction(Settings settings, RestController controller) { - controller.registerHandler(GET, "/_msearch", this); - controller.registerHandler(POST, "/_msearch", this); - controller.registerHandler(GET, "/{index}/_msearch", this); - controller.registerHandler(POST, "/{index}/_msearch", this); - + public RestMultiSearchAction(Settings settings) { this.allowExplicitIndex = MULTI_ALLOW_EXPLICIT_INDEX.get(settings); } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_msearch", GET), + new Route("/_msearch", POST), + new Route("/{index}/_msearch", GET), + new Route("/{index}/_msearch", POST))); + } + @Override public String getName() { return "msearch_action"; diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java index 5bdc0f3fffadf..c646fa36c3306 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java @@ -28,7 +28,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.index.query.QueryBuilder; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.rest.action.RestCancellableNodeClient; @@ -46,9 +45,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.function.IntConsumer; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -68,18 +70,20 @@ public class RestSearchAction extends BaseRestHandler { RESPONSE_PARAMS = Collections.unmodifiableSet(responseParams); } - public RestSearchAction(RestController controller) { - controller.registerHandler(GET, "/_search", this); - controller.registerHandler(POST, "/_search", this); - controller.registerHandler(GET, "/{index}/_search", this); - controller.registerHandler(POST, "/{index}/_search", this); - } - @Override public String getName() { return "search_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_search", GET), + new Route("/_search", POST), + new Route("/{index}/_search", GET), + new Route("/{index}/_search", POST))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { SearchRequest searchRequest = new SearchRequest(); diff --git a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java index 0b49048dee906..81e8561e14c00 100644 --- a/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java +++ b/server/src/main/java/org/elasticsearch/rest/action/search/RestSearchScrollAction.java @@ -22,15 +22,17 @@ import org.elasticsearch.action.search.SearchScrollRequest; 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 org.elasticsearch.search.Scroll; import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Set; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -38,18 +40,20 @@ public class RestSearchScrollAction extends BaseRestHandler { private static final Set RESPONSE_PARAMS = Collections.singleton(RestSearchAction.TOTAL_HITS_AS_INT_PARAM); - public RestSearchScrollAction(RestController controller) { - controller.registerHandler(GET, "/_search/scroll", this); - controller.registerHandler(POST, "/_search/scroll", this); - controller.registerHandler(GET, "/_search/scroll/{scroll_id}", this); - controller.registerHandler(POST, "/_search/scroll/{scroll_id}", this); - } - @Override public String getName() { return "search_scroll_action"; } + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_search/scroll", GET), + new Route("/_search/scroll", POST), + new Route("/_search/scroll/{scroll_id}", GET), + new Route("/_search/scroll/{scroll_id}", POST))); + } + @Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { String scrollId = request.param("scroll_id"); diff --git a/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java b/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java index df0c77c96ea19..247da38d09fc9 100644 --- a/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java +++ b/server/src/test/java/org/elasticsearch/action/ActionModuleTests.java @@ -113,7 +113,16 @@ public void testSetupRestHandlerContainsKnownBuiltin() { actionModule.initRestHandlers(null); // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail Exception e = expectThrows(IllegalArgumentException.class, () -> - actionModule.getRestController().registerHandler(Method.GET, "/", null)); + actionModule.getRestController().registerHandler(new RestHandler() { + @Override + public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/", Method.GET)); + } + })); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET")); } @@ -123,7 +132,7 @@ public void testPluginCantOverwriteBuiltinRestHandler() throws IOException { public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return singletonList(new RestMainAction(restController)); + return singletonList(new RestMainAction()); } }; SettingsModule settings = new SettingsModule(Settings.EMPTY); @@ -142,9 +151,11 @@ public List getRestHandlers(Settings settings, RestController restC public void testPluginCanRegisterRestHandler() { class FakeHandler implements RestHandler { - FakeHandler(RestController restController) { - restController.registerHandler(Method.GET, "/_dummy", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_dummy", Method.GET)); } + @Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { } @@ -154,7 +165,7 @@ public void handleRequest(RestRequest request, RestChannel channel, NodeClient c public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return singletonList(new FakeHandler(restController)); + return singletonList(new FakeHandler()); } }; @@ -168,7 +179,16 @@ public List getRestHandlers(Settings settings, RestController restC actionModule.initRestHandlers(null); // At this point the easiest way to confirm that a handler is loaded is to try to register another one on top of it and to fail Exception e = expectThrows(IllegalArgumentException.class, () -> - actionModule.getRestController().registerHandler(Method.GET, "/_dummy", null)); + actionModule.getRestController().registerHandler(new RestHandler() { + @Override + public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_dummy", Method.GET)); + } + })); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/_dummy] for method: GET")); } finally { threadPool.shutdown(); diff --git a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java index 919b3935a7f45..322b8a61fcce3 100644 --- a/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java +++ b/server/src/test/java/org/elasticsearch/action/admin/indices/forcemerge/RestForceMergeActionTests.java @@ -44,7 +44,7 @@ public class RestForceMergeActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestForceMergeAction(controller()); + controller().registerHandler(new RestForceMergeAction()); } public void testBodyRejection() throws Exception { diff --git a/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java b/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java index 66badef0cefc5..7f9ab8ac1c32b 100644 --- a/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/BaseRestHandlerTests.java @@ -33,6 +33,7 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; @@ -55,6 +56,11 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli public String getName() { return "test_one_unconsumed_response_action"; } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -81,6 +87,11 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli public String getName() { return "test_multiple_unconsumed_response_action"; } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -117,6 +128,11 @@ protected Set responseParams() { public String getName() { return "test_unconsumed_did_you_mean_response_action"; } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -160,6 +176,11 @@ protected Set responseParams() { public String getName() { return "test_unconsumed_response_action"; } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -183,6 +204,11 @@ protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient cli public String getName() { return "test_default_response_action"; } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -218,6 +244,11 @@ protected Table getTableWithHeader(RestRequest request) { public String getName() { return "test_cat_response_action"; } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -249,6 +280,10 @@ public String getName() { return "test_consumed_body"; } + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; try (XContentBuilder builder = JsonXContent.contentBuilder().startObject().endObject()) { @@ -274,6 +309,10 @@ public String getName() { return "test_unconsumed_body"; } + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).build(); @@ -295,6 +334,10 @@ public String getName() { return "test_unconsumed_body"; } + @Override + public List handledRoutes() { + return Collections.emptyList(); + } }; try (XContentBuilder builder = JsonXContent.contentBuilder().startObject().endObject()) { diff --git a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java index 702d0db964f03..2973765beee32 100644 --- a/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java +++ b/server/src/test/java/org/elasticsearch/rest/RestControllerTests.java @@ -250,27 +250,6 @@ public void testRestHandlerWrapper() throws Exception { assertFalse(handlerCalled.get()); } - /** - * Useful for testing with deprecation handler. - */ - private static class FakeRestHandler implements RestHandler { - private final boolean canTripCircuitBreaker; - - private FakeRestHandler(boolean canTripCircuitBreaker) { - this.canTripCircuitBreaker = canTripCircuitBreaker; - } - - @Override - public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { - //no op - } - - @Override - public boolean canTripCircuitBreaker() { - return canTripCircuitBreaker; - } - } - public void testDispatchRequestAddsAndFreesBytesOnSuccess() { int contentLength = BREAKER_LIMIT.bytesAsInt(); String content = randomAlphaOfLength((int) Math.round(contentLength / inFlightRequestsBreaker.getOverhead())); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java index c686497922346..538c57b035e01 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestAddVotingConfigExclusionActionTests.java @@ -34,7 +34,8 @@ public class RestAddVotingConfigExclusionActionTests extends RestActionTestCase @Before public void setupAction() { - action = new RestAddVotingConfigExclusionAction(controller()); + action = new RestAddVotingConfigExclusionAction(); + controller().registerHandler(action); } public void testResolveVotingConfigExclusionsRequest() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java index 93203b774ec36..aa4fe725e0e03 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/cluster/RestNodesStatsActionTests.java @@ -20,14 +20,11 @@ package org.elasticsearch.rest.action.admin.cluster; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; -import org.elasticsearch.usage.UsageService; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Set; @@ -43,9 +40,7 @@ public class RestNodesStatsActionTests extends ESTestCase { @Override public void setUp() throws Exception { super.setUp(); - UsageService usageService = new UsageService(); - action = new RestNodesStatsAction( - new RestController(Collections.emptySet(), null, null, null, usageService)); + action = new RestNodesStatsAction(); } public void testUnrecognizedMetric() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java index 3956178587dd0..8c3c9ae03cb2b 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestAnalyzeActionTests.java @@ -24,7 +24,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.index.analysis.NameOrDefinition; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -34,7 +33,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; -import static org.mockito.Mockito.mock; public class RestAnalyzeActionTests extends ESTestCase { @@ -94,7 +92,7 @@ public void testParseXContentForAnalyzeRequestWithCustomFilters() throws Excepti } public void testParseXContentForAnalyzeRequestWithInvalidJsonThrowsException() { - RestAnalyzeAction action = new RestAnalyzeAction(mock(RestController.class)); + RestAnalyzeAction action = new RestAnalyzeAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build(); IOException e = expectThrows(IOException.class, () -> action.handleRequest(request, null, null)); diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java index bdd3892e38131..6c6e2c3d4b1f0 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsActionTests.java @@ -20,14 +20,11 @@ package org.elasticsearch.rest.action.admin.indices; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; -import org.elasticsearch.usage.UsageService; import java.io.IOException; -import java.util.Collections; import java.util.HashMap; import static org.hamcrest.CoreMatchers.containsString; @@ -41,9 +38,7 @@ public class RestIndicesStatsActionTests extends ESTestCase { @Override public void setUp() throws Exception { super.setUp(); - UsageService usageService = new UsageService(); - action = new RestIndicesStatsAction( - new RestController(Collections.emptySet(), null, null, null, usageService)); + action = new RestIndicesStatsAction(); } public void testUnrecognizedMetric() throws IOException { diff --git a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java index bd7fb60b3d567..4813e11e15bfc 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/admin/indices/RestValidateQueryActionTests.java @@ -59,7 +59,7 @@ public class RestValidateQueryActionTests extends AbstractSearchTestCase { private static UsageService usageService = new UsageService(); private static RestController controller = new RestController(emptySet(), null, client, new NoneCircuitBreakerService(), usageService); - private static RestValidateQueryAction action = new RestValidateQueryAction(controller); + private static RestValidateQueryAction action = new RestValidateQueryAction(); /** * Configures {@link NodeClient} to stub {@link ValidateQueryAction} transport action. @@ -81,6 +81,7 @@ protected void doExecute(Task task, ActionRequest request, ActionListener listen actions.put(ValidateQueryAction.INSTANCE, transportAction); client.initialize(actions, taskManager, () -> "local", null); + controller.registerHandler(action); } @AfterClass diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestCatRecoveryActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestCatRecoveryActionTests.java index 22beda1cc6eec..258844f36b71c 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestCatRecoveryActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestCatRecoveryActionTests.java @@ -57,7 +57,8 @@ public void testRestRecoveryAction() { final Settings settings = Settings.EMPTY; UsageService usageService = new UsageService(); final RestController restController = new RestController(Collections.emptySet(), null, null, null, usageService); - final RestCatRecoveryAction action = new RestCatRecoveryAction(restController); + final RestCatRecoveryAction action = new RestCatRecoveryAction(); + restController.registerHandler(action); final int totalShards = randomIntBetween(1, 32); final int successfulShards = Math.max(0, totalShards - randomIntBetween(1, 2)); final int failedShards = totalShards - successfulShards; diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java index 776129eb1d56a..aad58e50d69c9 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestIndicesActionTests.java @@ -128,7 +128,8 @@ public void testBuildTable() { } final RestController restController = new RestController(Collections.emptySet(), null, null, null, new UsageService()); - final RestIndicesAction action = new RestIndicesAction(restController); + final RestIndicesAction action = new RestIndicesAction(); + restController.registerHandler(action); final Table table = action.buildTable(new FakeRestRequest(), indicesSettings, indicesHealths, indicesStats, indicesMetaDatas); // now, verify the table is correct diff --git a/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java index 38c4837468362..3903a4d6b43f2 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/cat/RestNodesActionTests.java @@ -29,11 +29,9 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.threadpool.TestThreadPool; -import org.elasticsearch.usage.UsageService; import org.junit.Before; import java.util.Collections; @@ -50,9 +48,7 @@ public class RestNodesActionTests extends ESTestCase { @Before public void setUpAction() { - UsageService usageService = new UsageService(); - action = new RestNodesAction( - new RestController(Collections.emptySet(), null, null, null, usageService)); + action = new RestNodesAction(); } public void testBuildTableDoesNotThrowGivenNullNodeInfoAndStats() { diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java index b19c8c6412abc..fabd9e36051f8 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestBulkActionTests.java @@ -19,8 +19,6 @@ package org.elasticsearch.rest.action.document; -import java.util.HashMap; -import java.util.Map; import org.elasticsearch.Version; import org.elasticsearch.action.bulk.BulkRequest; import org.elasticsearch.action.update.UpdateRequest; @@ -28,13 +26,15 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.hamcrest.CustomMatcher; import org.mockito.Mockito; +import java.util.HashMap; +import java.util.Map; + import static org.mockito.Matchers.any; import static org.mockito.Matchers.argThat; import static org.mockito.Mockito.mock; @@ -48,7 +48,7 @@ public void testBulkPipelineUpsert() throws Exception { final NodeClient mockClient = mock(NodeClient.class); final Map params = new HashMap<>(); params.put("pipeline", "timestamps"); - new RestBulkAction(settings(Version.CURRENT).build(), mock(RestController.class)) + new RestBulkAction(settings(Version.CURRENT).build()) .handleRequest( new FakeRestRequest.Builder( xContentRegistry()).withPath("my_index/_bulk").withParams(params) diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java index 924ead60c3315..38a3fdf1af617 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestGetSourceActionTests.java @@ -46,7 +46,7 @@ public class RestGetSourceActionTests extends RestActionTestCase { @Before public void setUpAction() { - new RestGetSourceAction(controller()); + controller().registerHandler(new RestGetSourceAction()); } @AfterClass diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java index 6fe27322fcd85..84bc5f3bef340 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestIndexActionTests.java @@ -31,6 +31,8 @@ import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestRequest; +import org.elasticsearch.rest.action.document.RestIndexAction.AutoIdHandler; +import org.elasticsearch.rest.action.document.RestIndexAction.CreateHandler; import org.elasticsearch.test.VersionUtils; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.test.rest.RestActionTestCase; @@ -47,18 +49,19 @@ public class RestIndexActionTests extends RestActionTestCase { - private RestIndexAction action; private final AtomicReference clusterStateSupplier = new AtomicReference<>(); @Before public void setUpAction() { ClusterService clusterService = mock(ClusterService.class); when(clusterService.state()).thenAnswer(invocationOnMock -> clusterStateSupplier.get()); - action = new RestIndexAction(controller(), clusterService); + controller().registerHandler(new RestIndexAction()); + controller().registerHandler(new CreateHandler()); + controller().registerHandler(new AutoIdHandler(clusterService)); } public void testCreateOpTypeValidation() { - RestIndexAction.CreateHandler create = action.new CreateHandler(); + RestIndexAction.CreateHandler create = new CreateHandler(); String opType = randomFrom("CREATE", null); create.validateOpType(opType); diff --git a/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java b/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java index b5104bb4cfc00..92776d6ccc08f 100644 --- a/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java +++ b/server/src/test/java/org/elasticsearch/rest/action/document/RestUpdateActionTests.java @@ -41,7 +41,8 @@ public class RestUpdateActionTests extends RestActionTestCase { @Before public void setUpAction() { - action = new RestUpdateAction(controller()); + action = new RestUpdateAction(); + controller().registerHandler(action); } public void testUpdateDocVersion() { diff --git a/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java b/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java index 8642b2648146e..03e9a242d35c0 100644 --- a/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java +++ b/server/src/test/java/org/elasticsearch/search/scroll/RestClearScrollActionTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.search.RestClearScrollAction; import org.elasticsearch.test.ESTestCase; @@ -44,7 +43,7 @@ public class RestClearScrollActionTests extends ESTestCase { public void testParseClearScrollRequestWithInvalidJsonThrowsException() throws Exception { - RestClearScrollAction action = new RestClearScrollAction(mock(RestController.class)); + RestClearScrollAction action = new RestClearScrollAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build(); Exception e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, null)); @@ -55,7 +54,7 @@ public void testBodyParamsOverrideQueryStringParams() throws Exception { NodeClient nodeClient = mock(NodeClient.class); doNothing().when(nodeClient).searchScroll(any(), any()); - RestClearScrollAction action = new RestClearScrollAction(mock(RestController.class)); + RestClearScrollAction action = new RestClearScrollAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withParams(Collections.singletonMap("scroll_id", "QUERY_STRING")) .withContent(new BytesArray("{\"scroll_id\": [\"BODY\"]}"), XContentType.JSON).build(); diff --git a/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java b/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java index b90b01d4b7b02..6c58d32b8b8bb 100644 --- a/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java +++ b/server/src/test/java/org/elasticsearch/search/scroll/RestSearchScrollActionTests.java @@ -23,7 +23,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.search.RestSearchScrollAction; import org.elasticsearch.test.ESTestCase; @@ -44,7 +43,7 @@ public class RestSearchScrollActionTests extends ESTestCase { public void testParseSearchScrollRequestWithInvalidJsonThrowsException() throws Exception { - RestSearchScrollAction action = new RestSearchScrollAction(mock(RestController.class)); + RestSearchScrollAction action = new RestSearchScrollAction(); RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withContent(new BytesArray("{invalid_json}"), XContentType.JSON).build(); Exception e = expectThrows(IllegalArgumentException.class, () -> action.prepareRequest(request, null)); @@ -55,7 +54,7 @@ public void testBodyParamsOverrideQueryStringParams() throws Exception { NodeClient nodeClient = mock(NodeClient.class); doNothing().when(nodeClient).searchScroll(any(), any()); - RestSearchScrollAction action = new RestSearchScrollAction(mock(RestController.class)); + RestSearchScrollAction action = new RestSearchScrollAction(); Map params = new HashMap<>(); params.put("scroll_id", "QUERY_STRING"); params.put("scroll", "1000m"); diff --git a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java index ab5aebe853b9e..f574deee87fce 100644 --- a/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java +++ b/server/src/test/java/org/elasticsearch/snapshots/DedicatedClusterSnapshotRestoreIT.java @@ -71,7 +71,6 @@ import org.elasticsearch.plugins.Plugin; import org.elasticsearch.repositories.RepositoryMissingException; import org.elasticsearch.rest.AbstractRestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -120,7 +119,6 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; -import static org.mockito.Mockito.mock; @ClusterScope(scope = Scope.TEST, numDataNodes = 0) public class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTestCase { @@ -766,8 +764,7 @@ public void testThatSensitiveRepositorySettingsAreNotExposed() throws Exception ).get(); NodeClient nodeClient = internalCluster().getInstance(NodeClient.class); - RestGetRepositoriesAction getRepoAction = new RestGetRepositoriesAction(mock(RestController.class), - internalCluster().getInstance(SettingsFilter.class)); + RestGetRepositoriesAction getRepoAction = new RestGetRepositoriesAction(internalCluster().getInstance(SettingsFilter.class)); RestRequest getRepoRequest = new FakeRestRequest(); getRepoRequest.params().put("repository", "test-repo"); final CountDownLatch getRepoLatch = new CountDownLatch(1); @@ -789,8 +786,7 @@ public void sendResponse(RestResponse response) { throw getRepoError.get(); } - RestClusterStateAction clusterStateAction = new RestClusterStateAction(mock(RestController.class), - internalCluster().getInstance(SettingsFilter.class)); + RestClusterStateAction clusterStateAction = new RestClusterStateAction(internalCluster().getInstance(SettingsFilter.class)); RestRequest clusterStateRequest = new FakeRestRequest(); final CountDownLatch clusterStateLatch = new CountDownLatch(1); final AtomicReference clusterStateError = new AtomicReference<>(); diff --git a/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java b/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java index 5a38ca8ca4ebd..845851b3e3516 100644 --- a/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java +++ b/server/src/test/java/org/elasticsearch/usage/UsageServiceTests.java @@ -30,6 +30,8 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.net.InetAddress; +import java.util.Collections; +import java.util.List; import java.util.Map; import static org.hamcrest.Matchers.equalTo; @@ -100,6 +102,11 @@ public String getName() { return name; } + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { return channel -> { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java index 0fd087a47c44e..67907181699ff 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/Ccr.java @@ -257,22 +257,22 @@ public List getRestHandlers(Settings settings, RestController restC return Arrays.asList( // stats API - new RestFollowStatsAction(restController), - new RestCcrStatsAction(restController), - new RestFollowInfoAction(restController), + new RestFollowStatsAction(), + new RestCcrStatsAction(), + new RestFollowInfoAction(), // follow APIs - new RestPutFollowAction(restController), - new RestResumeFollowAction(restController), - new RestPauseFollowAction(restController), - new RestUnfollowAction(restController), + new RestPutFollowAction(), + new RestResumeFollowAction(), + new RestPauseFollowAction(), + new RestUnfollowAction(), // auto-follow APIs - new RestDeleteAutoFollowPatternAction(restController), - new RestPutAutoFollowPatternAction(restController), - new RestGetAutoFollowPatternAction(restController), - new RestPauseAutoFollowPatternAction(restController), - new RestResumeAutoFollowPatternAction(restController), + new RestDeleteAutoFollowPatternAction(), + new RestPutAutoFollowPatternAction(), + new RestGetAutoFollowPatternAction(), + new RestPauseAutoFollowPatternAction(), + new RestResumeAutoFollowPatternAction(), // forget follower API - new RestForgetFollowerAction(restController)); + new RestForgetFollowerAction()); } public List getNamedWriteables() { diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java index 08353212c2bf7..7c41f5d7b2410 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestCcrStatsAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.CcrStatsAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestCcrStatsAction extends BaseRestHandler { - public RestCcrStatsAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ccr/stats", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ccr/stats", GET)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java index ae63d2004a616..5519f281fa6d1 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestDeleteAutoFollowPatternAction.java @@ -7,17 +7,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; import static org.elasticsearch.xpack.core.ccr.action.DeleteAutoFollowPatternAction.INSTANCE; public class RestDeleteAutoFollowPatternAction extends BaseRestHandler { - public RestDeleteAutoFollowPatternAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_ccr/auto_follow/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ccr/auto_follow/{name}", DELETE)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java index 86aba9d31a33b..ebad7c2e7016b 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowInfoAction.java @@ -9,15 +9,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.FollowInfoAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestFollowInfoAction extends BaseRestHandler { - public RestFollowInfoAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_ccr/info", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/info", GET)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java index 31c2f5daac8e6..26bc2edc220bc 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestFollowStatsAction.java @@ -9,15 +9,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.FollowStatsAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestFollowStatsAction extends BaseRestHandler { - public RestFollowStatsAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_ccr/stats", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/stats", GET)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java index de749cde82189..20eed34c6f3de 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestForgetFollowerAction.java @@ -9,20 +9,22 @@ 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.xpack.core.ccr.action.ForgetFollowerAction; import org.elasticsearch.xpack.core.ccr.action.ForgetFollowerAction.Request; import java.io.IOException; -import java.util.Objects; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestForgetFollowerAction extends BaseRestHandler { - public RestForgetFollowerAction(final RestController restController) { - Objects.requireNonNull(restController); - restController.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/forget_follower", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/forget_follower", POST)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java index 0a7393dc8fcba..67e5c8b1b49d5 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestGetAutoFollowPatternAction.java @@ -7,18 +7,24 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.GetAutoFollowPatternAction.Request; +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.xpack.core.ccr.action.GetAutoFollowPatternAction.INSTANCE; public class RestGetAutoFollowPatternAction extends BaseRestHandler { - public RestGetAutoFollowPatternAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ccr/auto_follow/{name}", this); - controller.registerHandler(RestRequest.Method.GET, "/_ccr/auto_follow", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_ccr/auto_follow/{name}", GET), + new Route("/_ccr/auto_follow", GET))); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java index abfca00da5cb1..a1adb12ad6c57 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseAutoFollowPatternAction.java @@ -7,17 +7,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.INSTANCE; public class RestPauseAutoFollowPatternAction extends BaseRestHandler { - public RestPauseAutoFollowPatternAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ccr/auto_follow/{name}/pause", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ccr/auto_follow/{name}/pause", POST)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java index ef80fe1d36523..7cee2e1320170 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPauseFollowAction.java @@ -7,17 +7,21 @@ 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.RestToXContentListener; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.PauseFollowAction.INSTANCE; import static org.elasticsearch.xpack.core.ccr.action.PauseFollowAction.Request; public class RestPauseFollowAction extends BaseRestHandler { - public RestPauseFollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/pause_follow", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/pause_follow", POST)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java index 076c3cfb18ee7..e4ec9887607f5 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutAutoFollowPatternAction.java @@ -8,19 +8,22 @@ 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.xpack.core.ccr.action.PutAutoFollowPatternAction.Request; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.xpack.core.ccr.action.PutAutoFollowPatternAction.INSTANCE; public class RestPutAutoFollowPatternAction extends BaseRestHandler { - public RestPutAutoFollowPatternAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_ccr/auto_follow/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ccr/auto_follow/{name}", PUT)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java index 8ad2002a0c4b4..86b90ca9ab97e 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestPutFollowAction.java @@ -9,19 +9,22 @@ 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 java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.xpack.core.ccr.action.PutFollowAction.INSTANCE; import static org.elasticsearch.xpack.core.ccr.action.PutFollowAction.Request; public class RestPutFollowAction extends BaseRestHandler { - public RestPutFollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/{index}/_ccr/follow", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/follow", PUT)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java index 89f3f65fca7d3..a31660bbd1172 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeAutoFollowPatternAction.java @@ -7,17 +7,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.Request; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.ActivateAutoFollowPatternAction.INSTANCE; public class RestResumeAutoFollowPatternAction extends BaseRestHandler { - public RestResumeAutoFollowPatternAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ccr/auto_follow/{name}/resume", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ccr/auto_follow/{name}/resume", POST)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java index 29dcd029e990e..8a3f05636dba6 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestResumeFollowAction.java @@ -8,19 +8,22 @@ 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 java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.INSTANCE; import static org.elasticsearch.xpack.core.ccr.action.ResumeFollowAction.Request; public class RestResumeFollowAction extends BaseRestHandler { - public RestResumeFollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/resume_follow", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/resume_follow", POST)); } @Override diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java index 99a7ddac0da7b..e3498d70a01ba 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/rest/RestUnfollowAction.java @@ -8,17 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ccr.action.UnfollowAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.xpack.core.ccr.action.UnfollowAction.INSTANCE; public class RestUnfollowAction extends BaseRestHandler { - public RestUnfollowAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ccr/unfollow", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ccr/unfollow", POST)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java index 3ff79251cafe8..3ac7cfff9490e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/Licensing.java @@ -74,13 +74,13 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { List handlers = new ArrayList<>(); - handlers.add(new RestGetLicenseAction(restController)); - handlers.add(new RestPutLicenseAction(restController)); - handlers.add(new RestDeleteLicenseAction(restController)); - handlers.add(new RestGetTrialStatus(restController)); - handlers.add(new RestGetBasicStatus(restController)); - handlers.add(new RestPostStartTrialLicense(restController)); - handlers.add(new RestPostStartBasicLicense(restController)); + handlers.add(new RestGetLicenseAction()); + handlers.add(new RestPutLicenseAction()); + handlers.add(new RestDeleteLicenseAction()); + handlers.add(new RestGetTrialStatus()); + handlers.add(new RestGetBasicStatus()); + handlers.add(new RestPostStartTrialLicense()); + handlers.add(new RestPostStartBasicLicense()); return handlers; } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java index 383c31c332e32..58351c3704793 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java @@ -9,18 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.protocol.xpack.license.DeleteLicenseRequest; 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.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteLicenseAction extends BaseRestHandler { - RestDeleteLicenseAction(RestController controller) { - controller.registerHandler(DELETE, "/_license", this); + RestDeleteLicenseAction() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_license", DELETE)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java index 70dbe93bfb0fb..ddafdca84a6ba 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetBasicStatus.java @@ -8,16 +8,21 @@ 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.RestToXContentListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetBasicStatus extends BaseRestHandler { - RestGetBasicStatus(RestController controller) { - controller.registerHandler(GET, "/_license/basic_status", this); + RestGetBasicStatus() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_license/basic_status", GET)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java index 99ef7e4ec2c82..edba7c14729ae 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetLicenseAction.java @@ -14,15 +14,16 @@ import org.elasticsearch.protocol.xpack.license.GetLicenseRequest; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -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.HashMap; +import java.util.List; import java.util.Map; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; @@ -31,8 +32,11 @@ public class RestGetLicenseAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetLicenseAction.class)); - RestGetLicenseAction(RestController controller) { - controller.registerHandler(GET, "/_license", this); + RestGetLicenseAction() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_license", GET)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java index cac4a7d3d6d52..bd0584ae39285 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestGetTrialStatus.java @@ -8,16 +8,21 @@ 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.RestToXContentListener; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetTrialStatus extends BaseRestHandler { - RestGetTrialStatus(RestController controller) { - controller.registerHandler(GET, "/_license/trial_status", this); + RestGetTrialStatus() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_license/trial_status", GET)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java index 6d3a82cfeadce..40d58a215ff2c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartBasicLicense.java @@ -8,18 +8,22 @@ 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.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPostStartBasicLicense extends BaseRestHandler { - RestPostStartBasicLicense(RestController controller) { - controller.registerHandler(POST, "/_license/start_basic", this); + RestPostStartBasicLicense() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_license/start_basic", POST)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java index 0e79d306f1dd5..7753acd330686 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPostStartTrialLicense.java @@ -10,20 +10,24 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -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 java.util.Map; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPostStartTrialLicense extends BaseRestHandler { - RestPostStartTrialLicense(RestController controller) { - controller.registerHandler(POST, "/_license/start_trial", this); + RestPostStartTrialLicense() {} + + @Override + public List handledRoutes() { + return singletonList(new Route("/_license/start_trial", POST)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java index bac9946d05797..21827743bc563 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java @@ -8,21 +8,27 @@ 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.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.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutLicenseAction extends BaseRestHandler { - RestPutLicenseAction(RestController controller) { + RestPutLicenseAction() {} + + @Override + public List handledRoutes() { // TODO: remove POST endpoint? - controller.registerHandler(POST, "/_license", this); - controller.registerHandler(PUT, "/_license", this); + return unmodifiableList(asList( + new Route("/_license", POST), + new Route("/_license", PUT))); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java index 9a2d5fd65eb6d..7f85b8fe6c365 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackPlugin.java @@ -288,9 +288,9 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { List handlers = new ArrayList<>(); - handlers.add(new RestXPackInfoAction(restController)); - handlers.add(new RestXPackUsageAction(restController)); - handlers.add(new RestReloadAnalyzersAction(restController)); + handlers.add(new RestXPackInfoAction()); + handlers.add(new RestXPackUsageAction()); + handlers.add(new RestReloadAnalyzersAction()); handlers.addAll(licensing.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, indexNameExpressionResolver, nodesInCluster)); return handlers; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java index e3641f079f321..04c74e354b8b0 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestReloadAnalyzersAction.java @@ -9,18 +9,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.ReloadAnalyzerAction; import org.elasticsearch.xpack.core.action.ReloadAnalyzersRequest; 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 RestReloadAnalyzersAction extends BaseRestHandler { - public RestReloadAnalyzersAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_reload_search_analyzers", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_reload_search_analyzers", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_reload_search_analyzers", GET), + new Route("/{index}/_reload_search_analyzers", POST))); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java index 2da02fc111aaa..0ea34bc6ae43c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackInfoAction.java @@ -8,21 +8,26 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.protocol.xpack.XPackInfoRequest; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.XPackInfoRequestBuilder; import java.io.IOException; import java.util.EnumSet; +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.HEAD; public class RestXPackInfoAction extends BaseRestHandler { - public RestXPackInfoAction(RestController controller) { - controller.registerHandler(HEAD, "/_xpack", this); - controller.registerHandler(GET, "/_xpack", this); + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_xpack", GET), + new Route("/_xpack", HEAD))); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java index 56eaae48460d5..4b89d4789583c 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/rest/action/RestXPackUsageAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; @@ -20,14 +19,17 @@ import org.elasticsearch.xpack.core.action.XPackUsageResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; public class RestXPackUsageAction extends BaseRestHandler { - public RestXPackUsageAction(RestController controller) { - controller.registerHandler(GET, "/_xpack/usage", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_xpack/usage", GET)); } @Override diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java index d00bba383e90d..e5efc7f17010d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/rest/RestGetCertificateInfoAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -17,6 +16,9 @@ import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction; import org.elasticsearch.xpack.core.ssl.action.GetCertificateInfoAction.Response; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -25,8 +27,9 @@ */ public class RestGetCertificateInfoAction extends BaseRestHandler { - public RestGetCertificateInfoAction(RestController controller) { - controller.registerHandler(GET, "/_ssl/certificates", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ssl/certificates", GET)); } @Override diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java index c473e74db0eb4..6d17f634c9a78 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/Deprecation.java @@ -44,6 +44,6 @@ public List getRestHandlers(Settings settings, RestController restC Supplier nodesInCluster) { - return Collections.singletonList(new RestDeprecationInfoAction(restController)); + return Collections.singletonList(new RestDeprecationInfoAction()); } } diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java index 065a40b46e8a5..dd8a4757f40dd 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/RestDeprecationInfoAction.java @@ -5,25 +5,28 @@ */ package org.elasticsearch.xpack.deprecation; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction; import org.elasticsearch.xpack.core.deprecation.DeprecationInfoAction.Request; 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; public class RestDeprecationInfoAction extends BaseRestHandler { - private static final Logger logger = LogManager.getLogger(RestDeprecationInfoAction.class); - public RestDeprecationInfoAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_migration/deprecations", this); - controller.registerHandler(RestRequest.Method.GET, "/{index}/_migration/deprecations", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_migration/deprecations", GET), + new Route("/{index}/_migration/deprecations", GET))); } @Override @@ -33,7 +36,7 @@ public String getName() { @Override public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException { - if (request.method().equals(RestRequest.Method.GET)) { + if (request.method().equals(GET)) { return handleGet(request, client); } else { throw new IllegalArgumentException("illegal method [" + request.method() + "] for request [" + request.path() + "]"); diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java index 54dd0b219a7b7..20281a3933bf4 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/EnrichPlugin.java @@ -176,11 +176,11 @@ public List getRestHandlers( } return List.of( - new RestGetEnrichPolicyAction(restController), - new RestDeleteEnrichPolicyAction(restController), - new RestPutEnrichPolicyAction(restController), - new RestExecuteEnrichPolicyAction(restController), - new RestEnrichStatsAction(restController) + new RestGetEnrichPolicyAction(), + new RestDeleteEnrichPolicyAction(), + new RestPutEnrichPolicyAction(), + new RestExecuteEnrichPolicyAction(), + new RestEnrichStatsAction() ); } diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java index 01c23d91fed24..cc42d96763944 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestDeleteEnrichPolicyAction.java @@ -7,17 +7,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.DeleteEnrichPolicyAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteEnrichPolicyAction extends BaseRestHandler { - public RestDeleteEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_enrich/policy/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_enrich/policy/{name}", DELETE)); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java index 586e1c255dd7c..01ac4eb751e58 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestEnrichStatsAction.java @@ -7,17 +7,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.EnrichStatsAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestEnrichStatsAction extends BaseRestHandler { - public RestEnrichStatsAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_enrich/_stats", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_enrich/_stats", GET)); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java index 087117a6c1a45..63066d1b56bf7 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestExecuteEnrichPolicyAction.java @@ -7,18 +7,25 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.ExecuteEnrichPolicyAction; 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; public class RestExecuteEnrichPolicyAction extends BaseRestHandler { - public RestExecuteEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_enrich/policy/{name}/_execute", this); - controller.registerHandler(RestRequest.Method.POST, "/_enrich/policy/{name}/_execute", this); + @Override + public List handledRoutes() { + return unmodifiableList( + asList(new Route("/_enrich/policy/{name}/_execute", POST), new Route("/_enrich/policy/{name}/_execute", PUT)) + ); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java index 3a279a49fa49c..c2f5ca9fd6adf 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestGetEnrichPolicyAction.java @@ -8,18 +8,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.enrich.action.GetEnrichPolicyAction; 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; public class RestGetEnrichPolicyAction extends BaseRestHandler { - public RestGetEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_enrich/policy/{name}", this); - controller.registerHandler(RestRequest.Method.GET, "/_enrich/policy", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList(new Route("/_enrich/policy/{name}", GET), new Route("/_enrich/policy", GET))); } @Override diff --git a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java index 38d36447d8ee1..c2d2c3dce61c6 100644 --- a/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java +++ b/x-pack/plugin/enrich/src/main/java/org/elasticsearch/xpack/enrich/rest/RestPutEnrichPolicyAction.java @@ -8,17 +8,21 @@ 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.xpack.core.enrich.action.PutEnrichPolicyAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutEnrichPolicyAction extends BaseRestHandler { - public RestPutEnrichPolicyAction(final RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_enrich/policy/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_enrich/policy/{name}", PUT)); } @Override diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java index abed7c607acfd..1d9bbe75956e7 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java @@ -104,6 +104,6 @@ public List getRestHandlers(Settings settings, if (isEnabled(settings) == false) { return Collections.emptyList(); } - return Arrays.asList(new RestEqlSearchAction(restController)); + return Collections.singletonList(new RestEqlSearchAction()); } } \ No newline at end of file diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java index 8a46ba44185de..2091bc21365f0 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java @@ -5,34 +5,37 @@ */ package org.elasticsearch.xpack.eql.plugin; +import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; +import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; - -import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.common.xcontent.XContentParser; -import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.action.RestResponseListener; import org.elasticsearch.xpack.eql.action.EqlSearchAction; import org.elasticsearch.xpack.eql.action.EqlSearchRequest; import org.elasticsearch.xpack.eql.action.EqlSearchResponse; 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 RestEqlSearchAction extends BaseRestHandler { private static final String SEARCH_PATH = "/{index}/_eql/search"; - public RestEqlSearchAction(RestController controller) { - controller.registerHandler(GET, SEARCH_PATH, this); - controller.registerHandler(POST, SEARCH_PATH, this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(SEARCH_PATH, GET), + new Route(SEARCH_PATH, POST))); } @Override diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java index 89b5fa7adccb2..018f684c6389d 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/FrozenIndices.java @@ -74,6 +74,6 @@ public List getRestHandlers(Settings settings, RestController restC IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, Supplier nodesInCluster) { - return Collections.singletonList(new RestFreezeIndexAction(restController)); + return Collections.singletonList(new RestFreezeIndexAction()); } } diff --git a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java index 4bc113449c34a..558df47869290 100644 --- a/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java +++ b/x-pack/plugin/frozen-indices/src/main/java/org/elasticsearch/xpack/frozen/rest/action/RestFreezeIndexAction.java @@ -11,16 +11,23 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.protocol.xpack.frozen.FreezeRequest; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.frozen.action.FreezeIndexAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public final class RestFreezeIndexAction extends BaseRestHandler { - public RestFreezeIndexAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_freeze", this); - controller.registerHandler(RestRequest.Method.POST, "/{index}/_unfreeze", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_freeze", POST), + new Route("/{index}/_unfreeze", POST))); } @Override diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java index b918f6e5dde80..e8c6223e504a1 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java @@ -60,6 +60,6 @@ public List getRestHandlers(Settings settings, RestController restC if (false == enabled) { return emptyList(); } - return singletonList(new RestGraphAction(restController)); + return singletonList(new RestGraphAction()); } } diff --git a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index cf0dbfeb0d646..b4dd46c404507 100644 --- a/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/x-pack/plugin/graph/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -18,15 +18,17 @@ import org.elasticsearch.protocol.xpack.graph.Hop; import org.elasticsearch.protocol.xpack.graph.VertexRequest; 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.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.index.query.AbstractQueryBuilder.parseInnerQueryBuilder; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -56,9 +58,11 @@ public class RestGraphAction extends BaseRestHandler { public static final ParseField BOOST_FIELD = new ParseField("boost"); public static final ParseField TERM_FIELD = new ParseField("term"); - public RestGraphAction(RestController controller) { - controller.registerHandler(GET, "/{index}/_graph/explore", this); - controller.registerHandler(POST, "/{index}/_graph/explore", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/{index}/_graph/explore", GET), + new Route("/{index}/_graph/explore", POST))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java index 96e9a49bc9254..951571b992409 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycle.java @@ -241,29 +241,29 @@ public List getRestHandlers(Settings settings, RestController restC List handlers = new ArrayList<>(); if (ilmEnabled) { handlers.addAll(Arrays.asList( - new RestPutLifecycleAction(restController), - new RestGetLifecycleAction(restController), - new RestDeleteLifecycleAction(restController), - new RestExplainLifecycleAction(restController), - new RestRemoveIndexLifecyclePolicyAction(restController), - new RestMoveToStepAction(restController), - new RestRetryAction(restController), - new RestStopAction(restController), - new RestStartILMAction(restController), - new RestGetStatusAction(restController) + new RestPutLifecycleAction(), + new RestGetLifecycleAction(), + new RestDeleteLifecycleAction(), + new RestExplainLifecycleAction(), + new RestRemoveIndexLifecyclePolicyAction(), + new RestMoveToStepAction(), + new RestRetryAction(), + new RestStopAction(), + new RestStartILMAction(), + new RestGetStatusAction() )); } if (slmEnabled) { handlers.addAll(Arrays.asList( - new RestPutSnapshotLifecycleAction(restController), - new RestDeleteSnapshotLifecycleAction(restController), - new RestGetSnapshotLifecycleAction(restController), - new RestExecuteSnapshotLifecycleAction(restController), - new RestGetSnapshotLifecycleStatsAction(restController), - new RestExecuteSnapshotRetentionAction(restController), - new RestStopSLMAction(restController), - new RestStartSLMAction(restController), - new RestGetSLMStatusAction(restController) + new RestPutSnapshotLifecycleAction(), + new RestDeleteSnapshotLifecycleAction(), + new RestGetSnapshotLifecycleAction(), + new RestExecuteSnapshotLifecycleAction(), + new RestGetSnapshotLifecycleStatsAction(), + new RestExecuteSnapshotRetentionAction(), + new RestStopSLMAction(), + new RestStartSLMAction(), + new RestGetSLMStatusAction() )); } return handlers; diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java index 999eaafdb03bf..5602686d44af7 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestDeleteLifecycleAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.DeleteLifecycleAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteLifecycleAction extends BaseRestHandler { - public RestDeleteLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_ilm/policy/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ilm/policy/{name}", DELETE)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java index d8fb127755208..da838842b6b88 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestExplainLifecycleAction.java @@ -10,16 +10,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.ExplainLifecycleRequest; import org.elasticsearch.xpack.core.ilm.action.ExplainLifecycleAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestExplainLifecycleAction extends BaseRestHandler { - public RestExplainLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/{index}/_ilm/explain", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ilm/explain", GET)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java index 794de5d576347..333e90cc53ce0 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetLifecycleAction.java @@ -9,16 +9,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.GetLifecycleAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetLifecycleAction extends BaseRestHandler { - public RestGetLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ilm/policy", this); - controller.registerHandler(RestRequest.Method.GET, "/_ilm/policy/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_ilm/policy", GET), + new Route("/_ilm/policy/{name}", GET))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java index 5ff3c046321e7..41b92b5ae608a 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestGetStatusAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.GetStatusAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetStatusAction extends BaseRestHandler { - public RestGetStatusAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_ilm/status", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ilm/status", GET)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java index 44a765b0c6aa8..6ffc34f84bbae 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestMoveToStepAction.java @@ -10,17 +10,21 @@ 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.xpack.core.ilm.action.MoveToStepAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestMoveToStepAction extends BaseRestHandler { - public RestMoveToStepAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST,"/_ilm/move/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ilm/move/{name}", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java index 5e357c9535efd..1181e99bd7edf 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestPutLifecycleAction.java @@ -9,17 +9,21 @@ 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.xpack.core.ilm.action.PutLifecycleAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutLifecycleAction extends BaseRestHandler { - public RestPutLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_ilm/policy/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ilm/policy/{name}", PUT)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java index 7bca784878b49..27b0dea7b4a8b 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRemoveIndexLifecyclePolicyAction.java @@ -10,15 +10,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.RemoveIndexLifecyclePolicyAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestRemoveIndexLifecyclePolicyAction extends BaseRestHandler { - public RestRemoveIndexLifecyclePolicyAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ilm/remove", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ilm/remove", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java index e14e1dac049b2..55ce43f3283b2 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestRetryAction.java @@ -11,15 +11,20 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.action.RetryAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestRetryAction extends BaseRestHandler { - public RestRetryAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/{index}/_ilm/retry", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_ilm/retry", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java index b240a5e274e05..bed7a4fae38f2 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStartILMAction.java @@ -8,16 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.StartILMRequest; import org.elasticsearch.xpack.core.ilm.action.StartILMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartILMAction extends BaseRestHandler { - public RestStartILMAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ilm/start", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ilm/start", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java index 3843d4da773a6..fe5f12d40fb55 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/RestStopAction.java @@ -8,16 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ilm.StopILMRequest; import org.elasticsearch.xpack.core.ilm.action.StopILMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopAction extends BaseRestHandler { - public RestStopAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_ilm/stop", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_ilm/stop", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java index 658816d2bab82..c2cb848f7615c 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestDeleteSnapshotLifecycleAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.DeleteSnapshotLifecycleAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteSnapshotLifecycleAction extends BaseRestHandler { - public RestDeleteSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, "/_slm/policy/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/policy/{name}", DELETE)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java index 72eceee0f8ecc..e5f6bd7e9355b 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotLifecycleAction.java @@ -8,16 +8,24 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotLifecycleAction; +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; + public class RestExecuteSnapshotLifecycleAction extends BaseRestHandler { - public RestExecuteSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}/_execute", this); - controller.registerHandler(RestRequest.Method.POST, "/_slm/policy/{name}/_execute", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_slm/policy/{name}/_execute", POST), + new Route("/_slm/policy/{name}/_execute", PUT))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java index 8bf2e3e870e1d..1acb00c2b0574 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestExecuteSnapshotRetentionAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.ExecuteSnapshotRetentionAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestExecuteSnapshotRetentionAction extends BaseRestHandler { - public RestExecuteSnapshotRetentionAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_slm/_execute_retention", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/_execute_retention", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java index 26f3197a76125..32c99b3e57a67 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSLMStatusAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.GetSLMStatusAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetSLMStatusAction extends BaseRestHandler { - public RestGetSLMStatusAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_slm/status", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/status", GET)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java index cd2e67bb732a1..ab7325083fee8 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleAction.java @@ -9,16 +9,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleAction; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetSnapshotLifecycleAction extends BaseRestHandler { - public RestGetSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_slm/policy", this); - controller.registerHandler(RestRequest.Method.GET, "/_slm/policy/{name}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_slm/policy", GET), + new Route("/_slm/policy/{name}", GET))); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java index b8629c2db5760..bd1506fd5152f 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestGetSnapshotLifecycleStatsAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.GetSnapshotLifecycleStatsAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetSnapshotLifecycleStatsAction extends BaseRestHandler { - public RestGetSnapshotLifecycleStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_slm/stats", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/stats", GET)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java index a5183739f3f5b..dcf649324992e 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestPutSnapshotLifecycleAction.java @@ -9,17 +9,21 @@ 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.xpack.core.slm.action.PutSnapshotLifecycleAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutSnapshotLifecycleAction extends BaseRestHandler { - public RestPutSnapshotLifecycleAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, "/_slm/policy/{name}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/policy/{name}", PUT)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java index 87dc7d2bb2279..5d3f77f654732 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStartSLMAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.StartSLMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartSLMAction extends BaseRestHandler { - public RestStartSLMAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_slm/start", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/start", POST)); } @Override diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java index ac74b37d58751..d09e33821e771 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/slm/action/RestStopSLMAction.java @@ -8,15 +8,20 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.slm.action.StopSLMAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopSLMAction extends BaseRestHandler { - public RestStopSLMAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, "/_slm/stop", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_slm/stop", POST)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java index 5469da943f272..d82fd9b8384b2 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/MachineLearning.java @@ -715,68 +715,68 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } return Arrays.asList( - new RestGetJobsAction(restController), - new RestGetJobStatsAction(restController), - new RestMlInfoAction(restController), - new RestPutJobAction(restController), - new RestPostJobUpdateAction(restController), - new RestDeleteJobAction(restController), - new RestOpenJobAction(restController), - new RestGetFiltersAction(restController), - new RestPutFilterAction(restController), - new RestUpdateFilterAction(restController), - new RestDeleteFilterAction(restController), - new RestGetInfluencersAction(restController), - new RestGetRecordsAction(restController), - new RestGetBucketsAction(restController), - new RestGetOverallBucketsAction(restController), - new RestPostDataAction(restController), - new RestCloseJobAction(restController), - new RestFlushJobAction(restController), - new RestValidateDetectorAction(restController), - new RestValidateJobConfigAction(restController), - new RestGetCategoriesAction(restController), - new RestGetModelSnapshotsAction(restController), - new RestRevertModelSnapshotAction(restController), - new RestUpdateModelSnapshotAction(restController), - new RestGetDatafeedsAction(restController), - new RestGetDatafeedStatsAction(restController), - new RestPutDatafeedAction(restController), - new RestUpdateDatafeedAction(restController), - new RestDeleteDatafeedAction(restController), - new RestPreviewDatafeedAction(restController), - new RestStartDatafeedAction(restController), - new RestStopDatafeedAction(restController), - new RestDeleteModelSnapshotAction(restController), - new RestDeleteExpiredDataAction(restController), - new RestForecastJobAction(restController), - new RestDeleteForecastAction(restController), - new RestGetCalendarsAction(restController), - new RestPutCalendarAction(restController), - new RestDeleteCalendarAction(restController), - new RestDeleteCalendarEventAction(restController), - new RestDeleteCalendarJobAction(restController), - new RestPutCalendarJobAction(restController), - new RestGetCalendarEventsAction(restController), - new RestPostCalendarEventAction(restController), - new RestFindFileStructureAction(restController), - new RestSetUpgradeModeAction(restController), - new RestGetDataFrameAnalyticsAction(restController), - new RestGetDataFrameAnalyticsStatsAction(restController), - new RestPutDataFrameAnalyticsAction(restController), - new RestDeleteDataFrameAnalyticsAction(restController), - new RestStartDataFrameAnalyticsAction(restController), - new RestStopDataFrameAnalyticsAction(restController), - new RestEvaluateDataFrameAction(restController), - new RestExplainDataFrameAnalyticsAction(restController), - new RestGetTrainedModelsAction(restController), - new RestDeleteTrainedModelAction(restController), - new RestGetTrainedModelsStatsAction(restController), - new RestPutTrainedModelAction(restController), + new RestGetJobsAction(), + new RestGetJobStatsAction(), + new RestMlInfoAction(), + new RestPutJobAction(), + new RestPostJobUpdateAction(), + new RestDeleteJobAction(), + new RestOpenJobAction(), + new RestGetFiltersAction(), + new RestPutFilterAction(), + new RestUpdateFilterAction(), + new RestDeleteFilterAction(), + new RestGetInfluencersAction(), + new RestGetRecordsAction(), + new RestGetBucketsAction(), + new RestGetOverallBucketsAction(), + new RestPostDataAction(), + new RestCloseJobAction(), + new RestFlushJobAction(), + new RestValidateDetectorAction(), + new RestValidateJobConfigAction(), + new RestGetCategoriesAction(), + new RestGetModelSnapshotsAction(), + new RestRevertModelSnapshotAction(), + new RestUpdateModelSnapshotAction(), + new RestGetDatafeedsAction(), + new RestGetDatafeedStatsAction(), + new RestPutDatafeedAction(), + new RestUpdateDatafeedAction(), + new RestDeleteDatafeedAction(), + new RestPreviewDatafeedAction(), + new RestStartDatafeedAction(), + new RestStopDatafeedAction(), + new RestDeleteModelSnapshotAction(), + new RestDeleteExpiredDataAction(), + new RestForecastJobAction(), + new RestDeleteForecastAction(), + new RestGetCalendarsAction(), + new RestPutCalendarAction(), + new RestDeleteCalendarAction(), + new RestDeleteCalendarEventAction(), + new RestDeleteCalendarJobAction(), + new RestPutCalendarJobAction(), + new RestGetCalendarEventsAction(), + new RestPostCalendarEventAction(), + new RestFindFileStructureAction(), + new RestSetUpgradeModeAction(), + new RestGetDataFrameAnalyticsAction(), + new RestGetDataFrameAnalyticsStatsAction(), + new RestPutDataFrameAnalyticsAction(), + new RestDeleteDataFrameAnalyticsAction(), + new RestStartDataFrameAnalyticsAction(), + new RestStopDataFrameAnalyticsAction(), + new RestEvaluateDataFrameAction(), + new RestExplainDataFrameAnalyticsAction(), + new RestGetTrainedModelsAction(), + new RestDeleteTrainedModelAction(), + new RestGetTrainedModelsStatsAction(), + new RestPutTrainedModelAction(), // CAT Handlers - new RestCatJobsAction(restController), - new RestCatTrainedModelsAction(restController), - new RestCatDatafeedsAction(restController) + new RestCatJobsAction(), + new RestCatTrainedModelsAction(), + new RestCatDatafeedsAction() ); } diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java index d3f024e27e854..ccb49fe564fb1 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestDeleteExpiredDataAction.java @@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -24,11 +25,19 @@ public class RestDeleteExpiredDataAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteExpiredDataAction.class)); - public RestDeleteExpiredDataAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "_delete_expired_data", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "_delete_expired_data", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "_delete_expired_data", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java index b0e564095ec46..6aa6a9c95eeb6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestFindFileStructureAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.FindFileStructureAction; @@ -21,6 +20,7 @@ import java.io.IOException; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -33,11 +33,19 @@ public class RestFindFileStructureAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestFindFileStructureAction.class)); - public RestFindFileStructureAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "find_file_structure", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "find_file_structure", + POST, MachineLearning.PRE_V7_BASE_PATH + "find_file_structure", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java index 1d775d156edea..8f1704eabae30 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestMlInfoAction.java @@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.MlInfoAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -24,11 +25,19 @@ public class RestMlInfoAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestMlInfoAction.class)); - public RestMlInfoAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "info", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "info", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "info", + GET, MachineLearning.PRE_V7_BASE_PATH + "info", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java index 1d8d28a4d448b..fc74b37debb6a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/RestSetUpgradeModeAction.java @@ -9,13 +9,14 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.SetUpgradeModeAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -24,11 +25,19 @@ public class RestSetUpgradeModeAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSetUpgradeModeAction.class)); - public RestSetUpgradeModeAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "set_upgrade_mode", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "set_upgrade_mode", + POST, MachineLearning.PRE_V7_BASE_PATH + "set_upgrade_mode", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java index 95ec620e0177a..d33200757e61d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteCalendarAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -25,11 +26,18 @@ public class RestDeleteCalendarAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarAction.class)); - public RestDeleteCalendarAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java index da30978461d9b..00191d34d02f3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarEventAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteCalendarEventAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,13 +27,20 @@ public class RestDeleteCalendarEventAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarEventAction.class)); - public RestDeleteCalendarEventAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + - ScheduledEvent.EVENT_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + - ScheduledEvent.EVENT_ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + + ScheduledEvent.EVENT_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events/{" + + ScheduledEvent.EVENT_ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java index 213d3f712f961..8d43a580b1b32 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestDeleteCalendarJobAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateCalendarJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,13 +27,20 @@ public class RestDeleteCalendarJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteCalendarJobAction.class)); - public RestDeleteCalendarJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + + Job.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + + Job.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java index c299d23ac58fe..50926b5b2db08 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarEventsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.action.util.PageParams; @@ -20,6 +19,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -28,11 +29,18 @@ public class RestGetCalendarEventsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCalendarEventsAction.class)); - public RestGetCalendarEventsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", + GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java index 46e4d23cd6846..d2d9dc07505db 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestGetCalendarsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.action.util.PageParams; @@ -20,6 +19,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -29,22 +31,24 @@ public class RestGetCalendarsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCalendarsAction.class)); - public RestGetCalendarsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "calendars/", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "calendars/", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "calendars/", + GET, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "calendars/", + POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java index 5ad91ffd92fc2..e670695c8822e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPostCalendarEventAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.PostCalendarEventsAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,18 @@ public class RestPostCalendarEventAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostCalendarEventAction.class)); - public RestPostCalendarEventAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", + POST, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/events", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java index 553bb81cbf900..0d2d2c57ff075 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarAction.java @@ -10,15 +10,15 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.ml.MachineLearning; import org.elasticsearch.xpack.core.ml.action.PutCalendarAction; import org.elasticsearch.xpack.core.ml.calendars.Calendar; +import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -27,11 +27,18 @@ public class RestPutCalendarAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutCalendarAction.class)); - public RestPutCalendarAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java index ce47bc3a53a1d..03de5130b63ce 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/calendar/RestPutCalendarJobAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.UpdateCalendarJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,13 +27,22 @@ public class RestPutCalendarJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutCalendarJobAction.class)); - public RestPutCalendarJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + - Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, + MachineLearning.BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + Job.ID.getPreferredName() + "}", + PUT, + MachineLearning.PRE_V7_BASE_PATH + "calendars/{" + Calendar.ID.getPreferredName() + "}/jobs/{" + + Job.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java index 2af29f9b30f89..7009de7cd3181 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatDatafeedsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -20,13 +19,19 @@ import org.elasticsearch.xpack.core.ml.datafeed.DatafeedConfig; import org.elasticsearch.xpack.core.ml.datafeed.DatafeedTimingStats; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCatDatafeedsAction extends AbstractCatAction { - public RestCatDatafeedsAction(RestController controller) { - controller.registerHandler(GET, "_cat/ml/datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this); - controller.registerHandler(GET, "_cat/ml/datafeeds", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("_cat/ml/datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", GET), + new Route("_cat/ml/datafeeds", GET))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java index feda7a9479d06..d82d50428f192 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatJobsAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -25,13 +24,19 @@ import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.TimingStats; import org.elasticsearch.xpack.core.ml.stats.ForecastStats; +import java.util.List; + +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestCatJobsAction extends AbstractCatAction { - public RestCatJobsAction(RestController controller) { - controller.registerHandler(GET, "_cat/ml/anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this); - controller.registerHandler(GET, "_cat/ml/anomaly_detectors", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("_cat/ml/anomaly_detectors/{" + Job.ID.getPreferredName() + "}", GET), + new Route("_cat/ml/anomaly_detectors", GET))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java index 0617ba8ab3ef3..80dde77a7ab87 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/cat/RestCatTrainedModelsAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.Table; import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.unit.TimeValue; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestResponseListener; @@ -38,14 +37,18 @@ import java.util.function.Function; import java.util.stream.Collectors; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; public class RestCatTrainedModelsAction extends AbstractCatAction { - public RestCatTrainedModelsAction(RestController controller) { - controller.registerHandler(GET, "_cat/ml/trained_models/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", this); - controller.registerHandler(GET, "_cat/ml/trained_models", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("_cat/ml/trained_models", GET), + new Route("_cat/ml/trained_models/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", GET))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java index 000b92426d887..28805d91c76c8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestDeleteDatafeedAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.CloseJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,11 +27,18 @@ public class RestDeleteDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteDatafeedAction.class)); - public RestDeleteDatafeedAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java index 65866074dfadf..0cd9a0b5a7fcd 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedStatsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetDatafeedsStatsAction; @@ -18,6 +17,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -26,14 +28,21 @@ public class RestGetDatafeedStatsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetDatafeedStatsAction.class)); - public RestGetDatafeedStatsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/_stats", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stats", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/_stats", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java index 1ed7ce33ef887..f4d6a155a8809 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestGetDatafeedsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetDatafeedsAction; @@ -17,6 +16,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -25,14 +27,20 @@ public class RestGetDatafeedsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetDatafeedsAction.class)); - public RestGetDatafeedsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java index 6088f42f2d304..a006d1e662768 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPreviewDatafeedAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PreviewDatafeedAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -25,11 +26,19 @@ public class RestPreviewDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPreviewDatafeedAction.class)); - public RestPreviewDatafeedAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", + GET, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_preview", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java index 12e8863f68124..d80dfa77b68b5 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestPutDatafeedAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.PutDatafeedAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,11 +27,19 @@ public class RestPutDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutDatafeedAction.class)); - public RestPutDatafeedAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java index 3dbe4ceb10055..26ba61ff7a53e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -34,11 +35,19 @@ public class RestStartDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestStartDatafeedAction.class)); - public RestStartDatafeedAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", + POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_start", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java index f1cc37e61a88d..a511af60c903f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStopDatafeedAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -32,11 +33,19 @@ public class RestStopDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestStopDatafeedAction.class)); - public RestStopDatafeedAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", + POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_stop", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java index b36eb5e0078f8..fac6596e69b76 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestUpdateDatafeedAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.UpdateDatafeedAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestUpdateDatafeedAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestUpdateDatafeedAction.class)); - public RestUpdateDatafeedAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java index 9e78a7cd9f214..a28aca5fa8c63 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestDeleteDataFrameAnalyticsAction.java @@ -7,7 +7,6 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteDataFrameAnalyticsAction; @@ -15,12 +14,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteDataFrameAnalyticsAction extends BaseRestHandler { - public RestDeleteDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", this); + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", DELETE)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java index b991fec70e581..344a34f3dbe72 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestEvaluateDataFrameAction.java @@ -7,18 +7,22 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.EvaluateDataFrameAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestEvaluateDataFrameAction extends BaseRestHandler { - public RestEvaluateDataFrameAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/_evaluate", this); + @Override + public List handledRoutes() { + return singletonList(new Route(MachineLearning.BASE_PATH + "data_frame/_evaluate", POST)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java index b16bf7b3efbf1..0795672c0991e 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestExplainDataFrameAnalyticsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.ExplainDataFrameAnalyticsAction; @@ -23,15 +22,22 @@ import java.util.List; import java.util.stream.Collectors; +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 RestExplainDataFrameAnalyticsAction extends BaseRestHandler { - public RestExplainDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/_explain", this); - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/_explain", this); - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain", this); - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/_explain", GET), + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/_explain", POST), + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain", + GET), + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain", + POST))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java index 3c959056b2a5a..e0b0075aad2a9 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -17,13 +16,19 @@ import org.elasticsearch.xpack.ml.MachineLearning; 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; public class RestGetDataFrameAnalyticsAction extends BaseRestHandler { - public RestGetDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics", this); - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics", GET), + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", GET))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java index 44d43153e75b6..c3d418fc0c40d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestGetDataFrameAnalyticsStatsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -17,13 +16,20 @@ import org.elasticsearch.xpack.ml.MachineLearning; 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; public class RestGetDataFrameAnalyticsStatsAction extends BaseRestHandler { - public RestGetDataFrameAnalyticsStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/_stats", this); - controller.registerHandler(RestRequest.Method.GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stats", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/_stats", GET), + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stats", + GET))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java index 11a25e76a6c11..13ef23240b80a 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestPutDataFrameAnalyticsAction.java @@ -8,7 +8,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.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutDataFrameAnalyticsAction; @@ -16,12 +15,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutDataFrameAnalyticsAction extends BaseRestHandler { - public RestPutDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", this); + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}", PUT)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java index df98e7bc402f1..f099002925e5f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStartDataFrameAnalyticsAction.java @@ -8,7 +8,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction; @@ -16,12 +15,18 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStartDataFrameAnalyticsAction extends BaseRestHandler { - public RestStartDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_start", this); + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_start", + POST)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java index aadc11a659d56..5260359b57653 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/dataframe/RestStopDataFrameAnalyticsAction.java @@ -7,7 +7,6 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.StopDataFrameAnalyticsAction; @@ -15,12 +14,18 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStopDataFrameAnalyticsAction extends BaseRestHandler { - public RestStopDataFrameAnalyticsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" - + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stop", this); + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stop", + POST)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java index cee5745866148..4820c92e8632c 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestDeleteFilterAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteFilterAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -25,11 +26,19 @@ public class RestDeleteFilterAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteFilterAction.class)); - public RestDeleteFilterAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + Request.FILTER_ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java index 558da54b7f374..7dc21a4bf65f3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestGetFiltersAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -27,14 +29,22 @@ public class RestGetFiltersAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetFiltersAction.class)); - public RestGetFiltersAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "filters/", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "filters/", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "filters/", + GET, MachineLearning.PRE_V7_BASE_PATH + "filters/", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java index b902c09985382..627947529bc59 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestPutFilterAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.PutFilterAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,11 +27,19 @@ public class RestPutFilterAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutFilterAction.class)); - public RestPutFilterAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java index b9c544f30c217..2a9607af5f557 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/filter/RestUpdateFilterAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.UpdateFilterAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestUpdateFilterAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestUpdateFilterAction.class)); - public RestUpdateFilterAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "filters/{" + MlFilter.ID.getPreferredName() + "}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java index e9675be4d29fd..2709b1ad7cbb1 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestDeleteTrainedModelAction.java @@ -7,7 +7,6 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteTrainedModelAction; @@ -15,14 +14,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteTrainedModelAction extends BaseRestHandler { - public RestDeleteTrainedModelAction(RestController controller) { - controller.registerHandler( - DELETE, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", this); + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", DELETE)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java index 4d818f974f74e..15292373baeb1 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -18,20 +17,22 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; 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.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; public class RestGetTrainedModelsAction extends BaseRestHandler { - public RestGetTrainedModelsAction(RestController controller) { - controller.registerHandler( - GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", this); - controller.registerHandler(GET, MachineLearning.BASE_PATH + "inference", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", GET), + new Route(MachineLearning.BASE_PATH + "inference", GET))); } @Override @@ -49,7 +50,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient GetTrainedModelsAction.Request.INCLUDE_MODEL_DEFINITION.getPreferredName(), false ); - List tags = Arrays.asList(restRequest.paramAsStringArray(TrainedModelConfig.TAGS.getPreferredName(), Strings.EMPTY_ARRAY)); + List tags = asList(restRequest.paramAsStringArray(TrainedModelConfig.TAGS.getPreferredName(), Strings.EMPTY_ARRAY)); GetTrainedModelsAction.Request request = new GetTrainedModelsAction.Request(modelId, includeModelDefinition, tags); if (restRequest.hasParam(PageParams.FROM.getPreferredName()) || restRequest.hasParam(PageParams.SIZE.getPreferredName())) { request.setPageParams(new PageParams(restRequest.paramAsInt(PageParams.FROM.getPreferredName(), PageParams.DEFAULT_FROM), diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java index 100c8cfa2f922..d97fae9f664cc 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestGetTrainedModelsStatsAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -18,16 +17,20 @@ import org.elasticsearch.xpack.ml.MachineLearning; 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.xpack.core.ml.action.GetTrainedModelsAction.Request.ALLOW_NO_MATCH; public class RestGetTrainedModelsStatsAction extends BaseRestHandler { - public RestGetTrainedModelsStatsAction(RestController controller) { - controller.registerHandler( - GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}/_stats", this); - controller.registerHandler(GET, MachineLearning.BASE_PATH + "inference/_stats", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}/_stats", GET), + new Route(MachineLearning.BASE_PATH + MachineLearning.BASE_PATH + "inference/_stats", GET))); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java index cb3f4e0eddee2..ba536ede14709 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/inference/RestPutTrainedModelAction.java @@ -8,7 +8,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.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.PutTrainedModelAction; @@ -16,13 +15,17 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutTrainedModelAction extends BaseRestHandler { - public RestPutTrainedModelAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, - MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", - this); + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}", PUT)); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java index 9e8a2eaf7a35a..36cd8198458b8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestCloseJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.CloseJobAction; @@ -19,6 +18,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -27,11 +28,18 @@ public class RestCloseJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestCloseJobAction.class)); - public RestCloseJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_close", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java index 61b15f7794cd5..be227b8f5ac1f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteForecastAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.DeleteForecastAction; @@ -19,7 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteForecastAction extends BaseRestHandler { @@ -27,16 +28,21 @@ public class RestDeleteForecastAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteForecastAction.class)); - public RestDeleteForecastAction(RestController controller) { + @Override + public List handledRoutes() { + return singletonList( + new Route(MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast/", DELETE)); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", deprecationLogger); - controller.registerHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/_forecast/", this); + return singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/_forecast/{" + Forecast.FORECAST_ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java index 9f8aed81b6b1b..7ada56b25b7cf 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestDeleteJobAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; @@ -23,6 +22,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -31,11 +32,18 @@ public class RestDeleteJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteJobAction.class)); - public RestDeleteJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java index a1e6d09285a1c..c105bc11ea0ca 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestFlushJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.FlushJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -32,11 +33,19 @@ public class RestFlushJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestFlushJobAction.class)); - public RestFlushJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_flush", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java index 12c508daceecd..c144c50f74ec3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestForecastJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.ForecastJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestForecastJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestForecastJobAction.class)); - public RestForecastJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java index 16b540d04fdd8..21b9b72c2c104 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobStatsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetJobsStatsAction; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -27,14 +29,21 @@ public class RestGetJobStatsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetJobStatsAction.class)); - public RestGetJobStatsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/_stats", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_stats", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_stats", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/_stats", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_stats", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java index 5c9bc48400226..3b5eb4ec58bd5 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestGetJobsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.ml.action.GetJobsAction; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -27,14 +29,21 @@ public class RestGetJobsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetJobsAction.class)); - public RestGetJobsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java index 4e6b02049be59..0f044c67853b6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestOpenJobAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,6 +22,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -31,11 +32,19 @@ public class RestOpenJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestOpenJobAction.class)); - public RestOpenJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_open", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java index b3e57ca5855a5..0af9a7c47ef80 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostDataAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestStatusToXContentListener; import org.elasticsearch.xpack.core.ml.action.PostDataAction; @@ -17,6 +16,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,11 +29,19 @@ public class RestPostDataAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostDataAction.class)); - public RestPostDataAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_data", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java index a237a8b187459..ffa0637d6ae62 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPostJobUpdateAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.UpdateJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -26,11 +27,19 @@ public class RestPostJobUpdateAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPostJobUpdateAction.class)); - public RestPostJobUpdateAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java index fe0e29cde490c..4fbfc8d2aab88 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/job/RestPutJobAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.PutJobAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -26,11 +27,19 @@ public class RestPutJobAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutJobAction.class)); - public RestPutJobAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", this, - PUT, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(PUT, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + PUT, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java index 7ea082f9fd12f..8cb3c1c808da3 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestDeleteModelSnapshotAction.java @@ -9,15 +9,16 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; -import org.elasticsearch.xpack.ml.MachineLearning; import org.elasticsearch.xpack.core.ml.action.DeleteModelSnapshotAction; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.ModelSnapshotField; +import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -26,13 +27,21 @@ public class RestDeleteModelSnapshotAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteModelSnapshotAction.class)); - public RestDeleteModelSnapshotAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", this, - DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + - "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", + DELETE, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID.getPreferredName() + "}", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java index 2b2ef21442fa6..41da39b956b5d 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestGetModelSnapshotsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.action.util.PageParams; @@ -20,6 +19,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -39,31 +41,36 @@ public class RestGetModelSnapshotsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetModelSnapshotsAction.class)); - public RestGetModelSnapshotsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", deprecationLogger); - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", deprecationLogger); - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots", deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + Request.SNAPSHOT_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java index 33b31af99526b..4f5167250e4af 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestRevertModelSnapshotAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.RevertModelSnapshotAction; @@ -18,6 +17,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,13 +29,22 @@ public class RestRevertModelSnapshotAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestRevertModelSnapshotAction.class)); - public RestRevertModelSnapshotAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + - RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + - RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + + RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/model_snapshots/{" + + RevertModelSnapshotAction.Request.SNAPSHOT_ID.getPreferredName() + "}/_revert", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java index e1cd0b2d2f5f7..9bdf2a2083f20 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/modelsnapshots/RestUpdateModelSnapshotAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.UpdateModelSnapshotAction; @@ -19,6 +18,8 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -27,13 +28,21 @@ public class RestUpdateModelSnapshotAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestUpdateModelSnapshotAction.class)); - public RestUpdateModelSnapshotAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" - + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + + Job.ID.getPreferredName() + "}/model_snapshots/{" + ModelSnapshotField.SNAPSHOT_ID +"}/_update", + deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java index 8bb423199fe57..ddda3ef19bc4f 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetBucketsAction.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.action.util.PageParams; @@ -21,6 +20,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -30,29 +32,36 @@ public class RestGetBucketsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetBucketsAction.class)); - public RestGetBucketsAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() - + "}/results/buckets", deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets/{" + Result.TIMESTAMP.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/buckets", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java index e2e069efd76fd..ce1db9d42ebe5 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetCategoriesAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.action.util.PageParams; @@ -20,6 +19,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -29,29 +31,35 @@ public class RestGetCategoriesAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetCategoriesAction.class)); - public RestGetCategoriesAction(RestController controller) { - // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" - + Request.CATEGORY_ID.getPreferredName() + "}", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", - deprecationLogger); + @Override + public List replacedRoutes() { + // TODO: remove deprecated endpoint in 8.0.0 + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" + + Request.CATEGORY_ID.getPreferredName() + "}", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories/{" + + Request.CATEGORY_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/categories/{" + Request.CATEGORY_ID.getPreferredName() + "}", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + + "}/results/categories/{" + Request.CATEGORY_ID.getPreferredName() + "}", + deprecationLogger), + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/categories", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java index a1ac9671b3bed..c0e1515c62c15 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetInfluencersAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.action.util.PageParams; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,19 +30,24 @@ public class RestGetInfluencersAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetInfluencersAction.class)); - public RestGetInfluencersAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - deprecationLogger); - // endpoints that support body parameters must also accept POST - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", - deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/influencers", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java index 0b7763a8bf61d..40f6fa7c72104 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetOverallBucketsAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.GetOverallBucketsAction; @@ -19,6 +18,9 @@ import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,18 +30,24 @@ public class RestGetOverallBucketsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetOverallBucketsAction.class)); - public RestGetOverallBucketsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", - deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/overall_buckets", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java index 0ce2b5e709917..3318a577d7d01 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/results/RestGetRecordsAction.java @@ -10,15 +10,17 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.action.util.PageParams; +import org.elasticsearch.xpack.core.ml.action.GetRecordsAction; import org.elasticsearch.xpack.core.ml.job.config.Job; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -28,18 +30,24 @@ public class RestGetRecordsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetRecordsAction.class)); - public RestGetRecordsAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - this, - GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", - deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute( + GET, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + GET, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + deprecationLogger), + new ReplacedRoute( + POST, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/results/records", + deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java index 3cf5f89f91991..f67022ef4bcd8 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateDetectorAction.java @@ -10,13 +10,14 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.ValidateDetectorAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -25,11 +26,18 @@ public class RestValidateDetectorAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestValidateDetectorAction.class)); - public RestValidateDetectorAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate/detector", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate/detector", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate/detector", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate/detector", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java index 9f16162d17264..4480c3fde28d6 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/rest/validate/RestValidateJobConfigAction.java @@ -10,13 +10,14 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.ml.action.ValidateJobConfigAction; import org.elasticsearch.xpack.ml.MachineLearning; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -25,11 +26,18 @@ public class RestValidateJobConfigAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestValidateJobConfigAction.class)); - public RestValidateJobConfigAction(RestController controller) { + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate", this, - POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, MachineLearning.BASE_PATH + "anomaly_detectors/_validate", + POST, MachineLearning.PRE_V7_BASE_PATH + "anomaly_detectors/_validate", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java index e36b8a6aaa33c..533da79aeb6fc 100644 --- a/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java +++ b/x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/rest/datafeeds/RestStartDatafeedActionTests.java @@ -8,7 +8,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.xcontent.NamedXContentRegistry; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -21,8 +20,7 @@ public class RestStartDatafeedActionTests extends ESTestCase { public void testPrepareRequest() throws Exception { - RestStartDatafeedAction action = new RestStartDatafeedAction( - mock(RestController.class)); + RestStartDatafeedAction action = new RestStartDatafeedAction(); Map params = new HashMap<>(); params.put("start", "not-a-date"); diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java index c0981d17f177c..309b8b25cdd35 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java @@ -151,7 +151,7 @@ public List getRestHandlers(Settings settings, RestController restC if (false == enabled) { return emptyList(); } - return singletonList(new RestMonitoringBulkAction(restController)); + return singletonList(new RestMonitoringBulkAction()); } @Override diff --git a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java index f72871fb055c1..db372c5fcaa84 100644 --- a/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java +++ b/x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java @@ -12,7 +12,6 @@ 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; @@ -22,11 +21,12 @@ import org.elasticsearch.xpack.core.monitoring.exporter.MonitoringTemplateUtils; import java.io.IOException; -import java.util.Arrays; import java.util.List; import java.util.Map; +import static java.util.Arrays.asList; import static java.util.Collections.emptyList; +import static java.util.Collections.unmodifiableList; import static org.elasticsearch.common.unit.TimeValue.parseTimeValue; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -36,21 +36,22 @@ public class RestMonitoringBulkAction extends BaseRestHandler { public static final String MONITORING_ID = "system_id"; public static final String MONITORING_VERSION = "system_api_version"; public static final String INTERVAL = "interval"; - private final Map> supportedApiVersions; - public RestMonitoringBulkAction(RestController controller) { - controller.registerHandler(POST, "/_monitoring/bulk", this); - controller.registerHandler(PUT, "/_monitoring/bulk", this); + private static final List ALL_VERSIONS = asList( + MonitoringTemplateUtils.TEMPLATE_VERSION, + MonitoringTemplateUtils.OLD_TEMPLATE_VERSION + ); - final List allVersions = Arrays.asList( - MonitoringTemplateUtils.TEMPLATE_VERSION, - MonitoringTemplateUtils.OLD_TEMPLATE_VERSION - ); + private static final Map> SUPPORTED_API_VERSIONS = Map.of( + MonitoredSystem.KIBANA, ALL_VERSIONS, + MonitoredSystem.LOGSTASH, ALL_VERSIONS, + MonitoredSystem.BEATS, ALL_VERSIONS); - supportedApiVersions = Map.of( - MonitoredSystem.KIBANA, allVersions, - MonitoredSystem.LOGSTASH, allVersions, - MonitoredSystem.BEATS, allVersions); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_monitoring/bulk", POST), + new Route("/_monitoring/bulk", PUT))); } @Override @@ -108,7 +109,7 @@ public boolean supportsContentStream() { * @return true if supported, false otherwise */ private boolean isSupportedSystemVersion(final MonitoredSystem system, final String version) { - final List monitoredSystem = supportedApiVersions.getOrDefault(system, emptyList()); + final List monitoredSystem = SUPPORTED_API_VERSIONS.getOrDefault(system, emptyList()); return monitoredSystem.contains(version); } diff --git a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java index 4f83898e48a66..8abbaad59748e 100644 --- a/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java +++ b/x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkActionTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -38,9 +37,7 @@ public class RestMonitoringBulkActionTests extends ESTestCase { - private final RestController controller = mock(RestController.class); - - private final RestMonitoringBulkAction action = new RestMonitoringBulkAction(controller); + private final RestMonitoringBulkAction action = new RestMonitoringBulkAction(); public void testGetName() { // Are you sure that you want to change the name? diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java index f5ed5b86e7fc2..4ffe0ea3e417a 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/Rollup.java @@ -119,14 +119,14 @@ public List getRestHandlers(Settings settings, RestController restC } return Arrays.asList( - new RestRollupSearchAction(restController), - new RestPutRollupJobAction(restController), - new RestStartRollupJobAction(restController), - new RestStopRollupJobAction(restController), - new RestDeleteRollupJobAction(restController), - new RestGetRollupJobsAction(restController), - new RestGetRollupCapsAction(restController), - new RestGetRollupIndexCapsAction(restController) + new RestRollupSearchAction(), + new RestPutRollupJobAction(), + new RestStartRollupJobAction(), + new RestStopRollupJobAction(), + new RestDeleteRollupJobAction(), + new RestGetRollupJobsAction(), + new RestGetRollupCapsAction(), + new RestGetRollupIndexCapsAction() ); } diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java index 83e1b53cb1a4b..12fec56c5f22d 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestDeleteRollupJobAction.java @@ -9,20 +9,23 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.DeleteRollupJobAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteRollupJobAction extends BaseRestHandler { public static final ParseField ID = new ParseField("id"); - public RestDeleteRollupJobAction(RestController controller) { - controller.registerHandler(DELETE, "/_rollup/job/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_rollup/job/{id}", DELETE)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java index 2c30efb5d833e..5ae833455b6f4 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupCapsAction.java @@ -9,19 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.GetRollupCapsAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetRollupCapsAction extends BaseRestHandler { public static final ParseField ID = new ParseField("id"); - public RestGetRollupCapsAction(RestController controller) { - controller.registerHandler(GET, "/_rollup/data/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_rollup/data/{id}", GET)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java index a4675bfa7f2e4..54671b329a1c7 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupIndexCapsAction.java @@ -11,19 +11,22 @@ import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.GetRollupIndexCapsAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetRollupIndexCapsAction extends BaseRestHandler { static final ParseField INDEX = new ParseField("index"); - public RestGetRollupIndexCapsAction(RestController controller) { - controller.registerHandler(GET, "/{index}/_rollup/data", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/{index}/_rollup/data", GET)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java index cefa90266ea6b..c89cba0e98dec 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestGetRollupJobsAction.java @@ -9,19 +9,22 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.GetRollupJobsAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestGetRollupJobsAction extends BaseRestHandler { public static final ParseField ID = new ParseField("id"); - public RestGetRollupJobsAction(RestController controller) { - controller.registerHandler(GET, "/_rollup/job/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_rollup/job/{id}", GET)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java index 4f1f2a1a4d5dd..0ca31c0440897 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestPutRollupJobAction.java @@ -8,19 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.action.PutRollupJobAction; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutRollupJobAction extends BaseRestHandler { - public RestPutRollupJobAction(RestController controller) { - controller.registerHandler(PUT, "/_rollup/job/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_rollup/job/{id}", PUT)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java index 6a6aefd9c296c..a42e4c13609d9 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestRollupSearchAction.java @@ -8,24 +8,31 @@ 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.RestToXContentListener; import org.elasticsearch.rest.action.search.RestSearchAction; import org.elasticsearch.xpack.core.rollup.action.RollupSearchAction; import java.io.IOException; +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; + public class RestRollupSearchAction extends BaseRestHandler { private static final Set RESPONSE_PARAMS = Set.of(RestSearchAction.TYPED_KEYS_PARAM, RestSearchAction.TOTAL_HITS_AS_INT_PARAM); - public RestRollupSearchAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "_rollup_search", this); - controller.registerHandler(RestRequest.Method.POST, "_rollup_search", this); - controller.registerHandler(RestRequest.Method.GET, "{index}/_rollup_search", this); - controller.registerHandler(RestRequest.Method.POST, "{index}/_rollup_search", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("_rollup_search", GET), + new Route("_rollup_search", POST), + new Route("{index}/_rollup_search", GET), + new Route("{index}/_rollup_search", POST))); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java index 8f11802addadf..0b65188f97f2d 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStartRollupJobAction.java @@ -8,18 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StartRollupJobAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStartRollupJobAction extends BaseRestHandler { - public RestStartRollupJobAction(RestController controller) { - controller.registerHandler(POST, "/_rollup/job/{id}/_start", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_rollup/job/{id}/_start", POST)); } @Override diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java index 0d41893f9d6d2..940c9b6ad5ae4 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/rest/RestStopRollupJobAction.java @@ -9,18 +9,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.rollup.RollupField; import org.elasticsearch.xpack.core.rollup.action.StopRollupJobAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestStopRollupJobAction extends BaseRestHandler { - public RestStopRollupJobAction(RestController controller) { - controller.registerHandler(POST, "/_rollup/job/{id}/_stop", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_rollup/job/{id}/_stop", POST)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java index 3a82a7d0d9f31..54371201c8686 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -767,40 +767,40 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } return Arrays.asList( - new RestAuthenticateAction(settings, restController, securityContext.get(), getLicenseState()), - new RestClearRealmCacheAction(settings, restController, getLicenseState()), - new RestClearRolesCacheAction(settings, restController, getLicenseState()), - new RestGetUsersAction(settings, restController, getLicenseState()), - new RestPutUserAction(settings, restController, getLicenseState()), - new RestDeleteUserAction(settings, restController, getLicenseState()), - new RestGetRolesAction(settings, restController, getLicenseState()), - new RestPutRoleAction(settings, restController, getLicenseState()), - new RestDeleteRoleAction(settings, restController, getLicenseState()), - new RestChangePasswordAction(settings, restController, securityContext.get(), getLicenseState()), - new RestSetEnabledAction(settings, restController, getLicenseState()), - new RestHasPrivilegesAction(settings, restController, securityContext.get(), getLicenseState()), - new RestGetUserPrivilegesAction(settings, restController, securityContext.get(), getLicenseState()), - new RestGetRoleMappingsAction(settings, restController, getLicenseState()), - new RestPutRoleMappingAction(settings, restController, getLicenseState()), - new RestDeleteRoleMappingAction(settings, restController, getLicenseState()), - new RestGetTokenAction(settings, restController, getLicenseState()), - new RestInvalidateTokenAction(settings, restController, getLicenseState()), - new RestGetCertificateInfoAction(restController), - new RestSamlPrepareAuthenticationAction(settings, restController, getLicenseState()), - new RestSamlAuthenticateAction(settings, restController, getLicenseState()), - new RestSamlLogoutAction(settings, restController, getLicenseState()), - new RestSamlInvalidateSessionAction(settings, restController, getLicenseState()), - new RestOpenIdConnectPrepareAuthenticationAction(settings, restController, getLicenseState()), - new RestOpenIdConnectAuthenticateAction(settings, restController, getLicenseState()), - new RestOpenIdConnectLogoutAction(settings, restController, getLicenseState()), - new RestGetBuiltinPrivilegesAction(settings, restController, getLicenseState()), - new RestGetPrivilegesAction(settings, restController, getLicenseState()), - new RestPutPrivilegesAction(settings, restController, getLicenseState()), - new RestDeletePrivilegesAction(settings, restController, getLicenseState()), - new RestCreateApiKeyAction(settings, restController, getLicenseState()), - new RestInvalidateApiKeyAction(settings, restController, getLicenseState()), - new RestGetApiKeyAction(settings, restController, getLicenseState()), - new RestDelegatePkiAuthenticationAction(settings, restController, getLicenseState()) + new RestAuthenticateAction(settings, securityContext.get(), getLicenseState()), + new RestClearRealmCacheAction(settings, getLicenseState()), + new RestClearRolesCacheAction(settings, getLicenseState()), + new RestGetUsersAction(settings, getLicenseState()), + new RestPutUserAction(settings, getLicenseState()), + new RestDeleteUserAction(settings, getLicenseState()), + new RestGetRolesAction(settings, getLicenseState()), + new RestPutRoleAction(settings, getLicenseState()), + new RestDeleteRoleAction(settings, getLicenseState()), + new RestChangePasswordAction(settings, securityContext.get(), getLicenseState()), + new RestSetEnabledAction(settings, getLicenseState()), + new RestHasPrivilegesAction(settings, securityContext.get(), getLicenseState()), + new RestGetUserPrivilegesAction(settings, securityContext.get(), getLicenseState()), + new RestGetRoleMappingsAction(settings, getLicenseState()), + new RestPutRoleMappingAction(settings, getLicenseState()), + new RestDeleteRoleMappingAction(settings, getLicenseState()), + new RestGetTokenAction(settings, getLicenseState()), + new RestInvalidateTokenAction(settings, getLicenseState()), + new RestGetCertificateInfoAction(), + new RestSamlPrepareAuthenticationAction(settings, getLicenseState()), + new RestSamlAuthenticateAction(settings, getLicenseState()), + new RestSamlLogoutAction(settings, getLicenseState()), + new RestSamlInvalidateSessionAction(settings, getLicenseState()), + new RestOpenIdConnectPrepareAuthenticationAction(settings, getLicenseState()), + new RestOpenIdConnectAuthenticateAction(settings, getLicenseState()), + new RestOpenIdConnectLogoutAction(settings, getLicenseState()), + new RestGetBuiltinPrivilegesAction(settings, getLicenseState()), + new RestGetPrivilegesAction(settings, getLicenseState()), + new RestPutPrivilegesAction(settings, getLicenseState()), + new RestDeletePrivilegesAction(settings, getLicenseState()), + new RestCreateApiKeyAction(settings, getLicenseState()), + new RestInvalidateApiKeyAction(settings, getLicenseState()), + new RestGetApiKeyAction(settings, getLicenseState()), + new RestDelegatePkiAuthenticationAction(settings, getLicenseState()) ); } diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java index 4131d1e735883..3eae11bbfc94e 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/SecurityRestFilter.java @@ -24,6 +24,7 @@ import org.elasticsearch.xpack.security.transport.SSLEngineUtils; import java.io.IOException; +import java.util.List; public class SecurityRestFilter implements RestHandler { @@ -91,6 +92,21 @@ public boolean allowsUnsafeBuffers() { return restHandler.allowsUnsafeBuffers(); } + @Override + public List handledRoutes() { + return restHandler.handledRoutes(); + } + + @Override + public List deprecatedRoutes() { + return restHandler.deprecatedRoutes(); + } + + @Override + public List replacedRoutes() { + return restHandler.replacedRoutes(); + } + private RestRequest maybeWrapRestRequest(RestRequest restRequest) throws IOException { if (restHandler instanceof RestRequestFilter) { return ((RestRequestFilter)restHandler).getFilteredRequest(restRequest); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java index 09f0679378c54..d6542348b7457 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,6 +24,8 @@ import org.elasticsearch.xpack.core.security.user.User; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -33,14 +34,21 @@ public class RestAuthenticateAction extends SecurityBaseRestHandler { private final SecurityContext securityContext; private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestAuthenticateAction.class)); - public RestAuthenticateAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestAuthenticateAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/_authenticate", this, - GET, "/_xpack/security/_authenticate", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(GET, "/_security/_authenticate", GET, + "/_xpack/security/_authenticate", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java index c63d965a3b7c6..36e85676d2c31 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/RestDelegatePkiAuthenticationAction.java @@ -10,25 +10,26 @@ import org.apache.logging.log4j.Logger; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.LicenseUtils; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.BytesRestResponse; +import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationAction; import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationRequest; -import org.elasticsearch.xpack.security.action.TransportDelegatePkiAuthenticationAction; -import org.elasticsearch.xpack.security.authc.Realms; import org.elasticsearch.xpack.core.security.action.DelegatePkiAuthenticationResponse; import org.elasticsearch.xpack.core.security.authc.pki.PkiRealmSettings; -import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.security.action.TransportDelegatePkiAuthenticationAction; +import org.elasticsearch.xpack.security.authc.Realms; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -40,9 +41,13 @@ public final class RestDelegatePkiAuthenticationAction extends SecurityBaseRestH protected Logger logger = LogManager.getLogger(RestDelegatePkiAuthenticationAction.class); - public RestDelegatePkiAuthenticationAction(Settings settings, RestController controller, XPackLicenseState xPackLicenseState) { + public RestDelegatePkiAuthenticationAction(Settings settings, XPackLicenseState xPackLicenseState) { super(settings, xPackLicenseState); - controller.registerHandler(POST, "/_security/delegate_pki", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/delegate_pki", POST)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java index b75de301e7e4a..f4a75b61f4356 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyAction.java @@ -10,13 +10,18 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.security.action.CreateApiKeyRequest; import org.elasticsearch.xpack.core.security.action.CreateApiKeyRequestBuilder; 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; /** * Rest action to create an API key @@ -28,10 +33,15 @@ public final class RestCreateApiKeyAction extends ApiKeyBaseRestHandler { * @param licenseState the license state that will be used to determine if * security is licensed */ - public RestCreateApiKeyAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestCreateApiKeyAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(RestRequest.Method.POST, "/_security/api_key", this); - controller.registerHandler(RestRequest.Method.PUT, "/_security/api_key", this); + } + + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_security/api_key", POST), + new Route("/_security/api_key", PUT))); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java index ca07952478444..05f1fe0040ed2 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,15 +21,23 @@ import org.elasticsearch.xpack.core.security.action.GetApiKeyResponse; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.GET; /** * Rest action to get one or more API keys information. */ public final class RestGetApiKeyAction extends ApiKeyBaseRestHandler { - public RestGetApiKeyAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetApiKeyAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(RestRequest.Method.GET, "/_security/api_key", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/api_key", GET)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java index 0579932887677..9ac2d17ff16ef 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.InvalidateApiKeyResponse; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; /** * Rest action to invalidate one or more API keys @@ -43,9 +46,13 @@ public final class RestInvalidateApiKeyAction extends ApiKeyBaseRestHandler { PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), new ParseField("owner")); } - public RestInvalidateApiKeyAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestInvalidateApiKeyAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(RestRequest.Method.DELETE, "/_security/api_key", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/api_key", DELETE)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java index c3734f37d1a54..6b2da8e9b5d3a 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestGetTokenAction.java @@ -8,9 +8,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.elasticsearch.ElasticsearchSecurityException; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequestValidationException; +import org.elasticsearch.action.ActionType; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.logging.DeprecationLogger; @@ -23,7 +23,6 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.xpack.core.security.action.token.CreateTokenAction; @@ -34,6 +33,7 @@ import java.io.IOException; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Locale; @@ -65,12 +65,21 @@ public final class RestGetTokenAction extends TokenBaseRestHandler { PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), new ParseField("refresh_token")); } - public RestGetTokenAction(Settings settings, RestController controller, XPackLicenseState xPackLicenseState) { + public RestGetTokenAction(Settings settings, XPackLicenseState xPackLicenseState) { super(settings, xPackLicenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/oauth2/token", this, - POST, "/_xpack/security/oauth2/token", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/oauth2/token", POST, "/_xpack/security/oauth2/token", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java index cb72e53bcc8d3..7e6696c0bb472 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oauth2/RestInvalidateTokenAction.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +25,8 @@ import org.elasticsearch.xpack.core.security.action.token.InvalidateTokenResponse; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -63,12 +64,21 @@ public final class RestInvalidateTokenAction extends TokenBaseRestHandler { PARSER.declareString(ConstructingObjectParser.optionalConstructorArg(), new ParseField("username")); } - public RestInvalidateTokenAction(Settings settings, RestController controller, XPackLicenseState xPackLicenseState) { + public RestInvalidateTokenAction(Settings settings, XPackLicenseState xPackLicenseState) { super(settings, xPackLicenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/oauth2/token", this, - DELETE, "/_xpack/security/oauth2/token", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, "/_security/oauth2/token", DELETE, "/_xpack/security/oauth2/token", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java index d820fb7a88b47..c09b7bcfa326d 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectAuthenticateAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,7 +24,9 @@ import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectAuthenticateResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -44,9 +45,13 @@ public class RestOpenIdConnectAuthenticateAction extends OpenIdConnectBaseRestHa PARSER.declareStringOrNull(OpenIdConnectAuthenticateRequest::setRealm, new ParseField("realm")); } - public RestOpenIdConnectAuthenticateAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestOpenIdConnectAuthenticateAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(POST, "/_security/oidc/authenticate", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/oidc/authenticate", POST)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java index e098e14c423b8..b590c6b4f95c1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectLogoutAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,7 +22,9 @@ import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectLogoutResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -40,9 +41,13 @@ public class RestOpenIdConnectLogoutAction extends OpenIdConnectBaseRestHandler PARSER.declareString(OpenIdConnectLogoutRequest::setRefreshToken, new ParseField("refresh_token")); } - public RestOpenIdConnectLogoutAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestOpenIdConnectLogoutAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(POST, "/_security/oidc/logout", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/oidc/logout", POST)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java index c86da0ed4edc9..2cf4adcb209c8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/oidc/RestOpenIdConnectPrepareAuthenticationAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,7 +24,9 @@ import org.elasticsearch.xpack.core.security.action.oidc.OpenIdConnectPrepareAuthenticationResponse; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -45,9 +46,13 @@ public class RestOpenIdConnectPrepareAuthenticationAction extends OpenIdConnectB PARSER.declareString(OpenIdConnectPrepareAuthenticationRequest::setNonce, new ParseField("nonce")); } - public RestOpenIdConnectPrepareAuthenticationAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestOpenIdConnectPrepareAuthenticationAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler(POST, "/_security/oidc/prepare", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/oidc/prepare", POST)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java index 41758aa26016f..27e567e7875f6 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestDeletePrivilegesAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,6 +24,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -36,12 +36,20 @@ public class RestDeletePrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeletePrivilegesAction.class)); - public RestDeletePrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeletePrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/privilege/{application}/{privilege}", this, - DELETE, "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(DELETE, "/_security/privilege/{application}/{privilege}", DELETE, + "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java index 15f4612d90429..83286bb329c79 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -21,7 +20,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; /** @@ -29,10 +30,13 @@ */ public class RestGetBuiltinPrivilegesAction extends SecurityBaseRestHandler { - public RestGetBuiltinPrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetBuiltinPrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); - controller.registerHandler( - GET, "/_security/privilege/_builtin", this); + } + + @Override + public List handledRoutes() { + return singletonList(new Route("/_security/privilege/_builtin", GET)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java index 7a5261c42bc93..a797822a3e542 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetPrivilegesAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -27,6 +26,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -40,18 +40,25 @@ public class RestGetPrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetPrivilegesAction.class)); - public RestGetPrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetPrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/privilege/", this, - GET, "/_xpack/security/privilege/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/privilege/{application}", this, - GET, "/_xpack/security/privilege/{application}", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/privilege/{application}/{privilege}", this, - GET, "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/privilege/", GET, "/_xpack/security/privilege/", deprecationLogger), + new ReplacedRoute(GET, "/_security/privilege/{application}", + GET, "/_xpack/security/privilege/{application}", deprecationLogger), + new ReplacedRoute(GET, "/_security/privilege/{application}/{privilege}", + GET, "/_xpack/security/privilege/{application}/{privilege}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java index 082751affb8b5..cd3999e6b300a 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestPutPrivilegesAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,7 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -38,15 +38,22 @@ public class RestPutPrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutPrivilegesAction.class)); - public RestPutPrivilegesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutPrivilegesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - PUT, "/_security/privilege/", this, - PUT, "/_xpack/security/privilege/", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/privilege/", this, - POST, "/_xpack/security/privilege/", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(PUT, "/_security/privilege/", PUT, "/_xpack/security/privilege/", deprecationLogger), + new ReplacedRoute(POST, "/_security/privilege/", POST, "/_xpack/security/privilege/", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java index e1590c39fe90e..035c9aa3c0766 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java @@ -10,25 +10,37 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import org.elasticsearch.xpack.core.security.action.realm.ClearRealmCacheAction; import org.elasticsearch.xpack.core.security.action.realm.ClearRealmCacheRequest; import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; public final class RestClearRealmCacheAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestClearRealmCacheAction.class)); - public RestClearRealmCacheAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestClearRealmCacheAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/realm/{realms}/_clear_cache", this, - POST, "/_xpack/security/realm/{realms}/_clear_cache", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/realm/{realms}/_clear_cache", + POST, "/_xpack/security/realm/{realms}/_clear_cache", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java index 0fd15051e8231..1ea1378014457 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java @@ -10,25 +10,35 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions.NodesResponseRestListener; import org.elasticsearch.xpack.core.security.action.role.ClearRolesCacheAction; import org.elasticsearch.xpack.core.security.action.role.ClearRolesCacheRequest; import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; public final class RestClearRolesCacheAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestClearRolesCacheAction.class)); - public RestClearRolesCacheAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestClearRolesCacheAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/role/{name}/_clear_cache", this, - POST, "/_xpack/security/role/{name}/_clear_cache", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(POST, "/_security/role/{name}/_clear_cache", POST, + "/_xpack/security/role/{name}/_clear_cache", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java index 957cac123486c..cd631f126d010 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -32,12 +33,20 @@ public class RestDeleteRoleAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteRoleAction.class)); - public RestDeleteRoleAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeleteRoleAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/role/{name}", this, - DELETE, "/_xpack/security/role/{name}", deprecationLogger); + return Collections.singletonList(new ReplacedRoute(DELETE, "/_security/role/{name}", DELETE, + "/_xpack/security/role/{name}", deprecationLogger)); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java index a5141f25f37a1..aed1718c8f419 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -34,15 +36,22 @@ public class RestGetRolesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetRolesAction.class)); - public RestGetRolesAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetRolesAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/role/", this, - GET, "/_xpack/security/role/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/role/{name}", this, - GET, "/_xpack/security/role/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/role/", GET, "/_xpack/security/role/", deprecationLogger), + new ReplacedRoute(GET, "/_security/role/{name}", GET, "/_xpack/security/role/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java index e8b2e6a778386..01379ff578a69 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -33,15 +35,22 @@ public class RestPutRoleAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutRoleAction.class)); - public RestPutRoleAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutRoleAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/role/{name}", this, - POST, "/_xpack/security/role/{name}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/role/{name}", this, - PUT, "/_xpack/security/role/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/role/{name}", POST, "/_xpack/security/role/{name}", deprecationLogger), + new ReplacedRoute(PUT, "/_security/role/{name}", PUT, "/_xpack/security/role/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java index a2383534115cc..a889ae1625c58 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestDeleteRoleMappingAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -33,12 +34,21 @@ public class RestDeleteRoleMappingAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteRoleMappingAction.class)); - public RestDeleteRoleMappingAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeleteRoleMappingAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/role_mapping/{name}", this, - DELETE, "/_xpack/security/role_mapping/{name}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, "/_security/role_mapping/{name}", DELETE, "/_xpack/security/role_mapping/{name}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java index aeac89e8ffb9a..74831b725cff8 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestGetRoleMappingsAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,6 +22,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -33,15 +35,22 @@ public class RestGetRoleMappingsAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetRoleMappingsAction.class)); - public RestGetRoleMappingsAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetRoleMappingsAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/role_mapping/", this, - GET, "/_xpack/security/role_mapping/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/role_mapping/{name}", this, - GET, "/_xpack/security/role_mapping/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/role_mapping/", GET, "/_xpack/security/role_mapping/", deprecationLogger), + new ReplacedRoute(GET, "/_security/role_mapping/{name}", GET, "/_xpack/security/role_mapping/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java index 532a12644a7bd..1e442e31493d0 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/rolemapping/RestPutRoleMappingAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -35,15 +37,22 @@ public class RestPutRoleMappingAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutRoleMappingAction.class)); - public RestPutRoleMappingAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutRoleMappingAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/role_mapping/{name}", this, - POST, "/_xpack/security/role_mapping/{name}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/role_mapping/{name}", this, - PUT, "/_xpack/security/role_mapping/{name}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/role_mapping/{name}", POST, "/_xpack/security/role_mapping/{name}", deprecationLogger), + new ReplacedRoute(PUT, "/_security/role_mapping/{name}", PUT, "/_xpack/security/role_mapping/{name}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java index 486e749ca6a27..2bee3f877d7be 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlAuthenticateAction.java @@ -17,8 +17,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; -import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -28,6 +26,7 @@ import java.io.IOException; import java.util.Base64; +import java.util.Collections; import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -35,7 +34,7 @@ /** * A REST handler that attempts to authenticate a user based on the provided SAML response/assertion. */ -public class RestSamlAuthenticateAction extends SamlBaseRestHandler implements RestHandler { +public class RestSamlAuthenticateAction extends SamlBaseRestHandler { private static final Logger logger = LogManager.getLogger(); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); @@ -63,13 +62,22 @@ void setIds(List ids) { PARSER.declareStringOrNull(Input::setRealm, new ParseField("realm")); } - public RestSamlAuthenticateAction(Settings settings, RestController controller, - XPackLicenseState licenseState) { + public RestSamlAuthenticateAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/authenticate", this, - POST, "/_xpack/security/saml/authenticate", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/authenticate", + POST, "/_xpack/security/saml/authenticate", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java index 4fe8e7ac5b256..e9301da6fb239 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlInvalidateSessionAction.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.xpack.security.rest.action.saml; -import java.io.IOException; - import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; @@ -17,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.saml.SamlInvalidateSessionRequest; import org.elasticsearch.xpack.core.security.action.saml.SamlInvalidateSessionResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -45,12 +46,22 @@ public class RestSamlInvalidateSessionAction extends SamlBaseRestHandler { PARSER.declareString(SamlInvalidateSessionRequest::setRealmName, new ParseField("realm")); } - public RestSamlInvalidateSessionAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSamlInvalidateSessionAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/invalidate", this, - POST, "/_xpack/security/saml/invalidate", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/invalidate", + POST, "/_xpack/security/saml/invalidate", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java index 3a584664073b9..2479f8469a74c 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlLogoutAction.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.xpack.security.rest.action.saml; -import java.io.IOException; - import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; @@ -17,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.saml.SamlLogoutRequest; import org.elasticsearch.xpack.core.security.action.saml.SamlLogoutResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -44,12 +45,22 @@ public class RestSamlLogoutAction extends SamlBaseRestHandler { PARSER.declareString(SamlLogoutRequest::setRefreshToken, new ParseField("refresh_token")); } - public RestSamlLogoutAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSamlLogoutAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/logout", this, - POST, "/_xpack/security/saml/logout", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/logout", + POST, "/_xpack/security/saml/logout", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java index b227f2c767f67..a0fe86827b49d 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/saml/RestSamlPrepareAuthenticationAction.java @@ -5,8 +5,6 @@ */ package org.elasticsearch.xpack.security.rest.action.saml; -import java.io.IOException; - import org.apache.logging.log4j.LogManager; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.ParseField; @@ -17,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,6 +23,10 @@ import org.elasticsearch.xpack.core.security.action.saml.SamlPrepareAuthenticationRequest; import org.elasticsearch.xpack.core.security.action.saml.SamlPrepareAuthenticationResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.POST; /** @@ -47,12 +48,22 @@ public class RestSamlPrepareAuthenticationAction extends SamlBaseRestHandler { PARSER.declareString(SamlPrepareAuthenticationRequest::setRelayState, new ParseField("relay_state")); } - public RestSamlPrepareAuthenticationAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSamlPrepareAuthenticationAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/saml/prepare", this, - POST, "/_xpack/security/saml/prepare", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(POST, "/_security/saml/prepare", + POST, "/_xpack/security/saml/prepare", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java index 4f1d3c2377555..08f8224073d47 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -28,7 +27,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -40,24 +41,30 @@ public class RestChangePasswordAction extends SecurityBaseRestHandler implements private final SecurityContext securityContext; private final Hasher passwordHasher; - public RestChangePasswordAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestChangePasswordAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings)); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_password", this, - POST, "/_xpack/security/user/{username}/_password", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}/_password", this, - PUT, "/_xpack/security/user/{username}/_password", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/_password", this, - POST, "/_xpack/security/user/_password", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/_password", this, - PUT, "/_xpack/security/user/_password", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(PUT, "/_security/user/{username}/_password", + PUT, "/_xpack/security/user/{username}/_password", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/{username}/_password", + POST, "/_xpack/security/user/{username}/_password", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/_password", + PUT, "/_xpack/security/user/_password", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/_password", + POST, "/_xpack/security/user/_password", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java index bc0eb728c6bf6..0544cde8c583d 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,8 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.DELETE; @@ -32,12 +33,21 @@ public class RestDeleteUserAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestDeleteUserAction.class)); - public RestDeleteUserAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestDeleteUserAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - DELETE, "/_security/user/{username}", this, - DELETE, "/_xpack/security/user/{username}", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(DELETE, "/_security/user/{username}", DELETE, "/_xpack/security/user/{username}", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java index 02bfc7ff96c16..a25c76c83bc5d 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.license.XPackLicenseState; 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.RestStatus; @@ -31,6 +30,7 @@ import java.io.IOException; import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -43,14 +43,22 @@ public class RestGetUserPrivilegesAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetUserPrivilegesAction.class)); - public RestGetUserPrivilegesAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestGetUserPrivilegesAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/user/_privileges", this, - GET, "/_xpack/security/user/_privileges", deprecationLogger); + return Collections.singletonList( + new ReplacedRoute(GET, "/_security/user/_privileges", GET, "/_xpack/security/user/_privileges", deprecationLogger) + ); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java index eef11d478ca65..a06f4ad836cf1 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -24,6 +23,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; @@ -34,15 +36,22 @@ public class RestGetUsersAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetUsersAction.class)); - public RestGetUsersAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestGetUsersAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/user/", this, - GET, "/_xpack/security/user/", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/user/{username}", this, - GET, "/_xpack/security/user/{username}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/user/", GET, "/_xpack/security/user/", deprecationLogger), + new ReplacedRoute(GET, "/_security/user/{username}", GET, "/_xpack/security/user/{username}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java index 3c589e7220aa7..0c6fabbb5c332 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesAction.java @@ -17,7 +17,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -30,6 +29,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -43,23 +45,29 @@ public class RestHasPrivilegesAction extends SecurityBaseRestHandler { private final SecurityContext securityContext; private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestHasPrivilegesAction.class)); - public RestHasPrivilegesAction(Settings settings, RestController controller, SecurityContext securityContext, - XPackLicenseState licenseState) { + public RestHasPrivilegesAction(Settings settings, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings, licenseState); this.securityContext = securityContext; + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - GET, "/_security/user/{username}/_has_privileges", this, - GET, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_has_privileges", this, - POST, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger); - controller.registerWithDeprecatedHandler( - GET, "/_security/user/_has_privileges", this, - GET, "/_xpack/security/user/_has_privileges", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/_has_privileges", this, - POST, "/_xpack/security/user/_has_privileges", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(GET, "/_security/user/{username}/_has_privileges", + GET, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/{username}/_has_privileges", + POST, "/_xpack/security/user/{username}/_has_privileges", deprecationLogger), + new ReplacedRoute(GET, "/_security/user/_has_privileges", + GET, "/_xpack/security/user/_has_privileges", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/_has_privileges", + POST, "/_xpack/security/user/_has_privileges", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java index 39cd5f35fa54b..5e17552ab6d33 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -26,7 +25,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Set; import static org.elasticsearch.rest.RestRequest.Method.POST; @@ -40,16 +41,25 @@ public class RestPutUserAction extends SecurityBaseRestHandler implements RestRe private final Hasher passwordHasher; private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestPutUserAction.class)); - public RestPutUserAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestPutUserAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); passwordHasher = Hasher.resolve(XPackSettings.PASSWORD_HASHING_ALGORITHM.get(settings)); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}", this, - POST, "/_xpack/security/user/{username}", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}", this, - PUT, "/_xpack/security/user/{username}", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/user/{username}", + POST, "/_xpack/security/user/{username}", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/{username}", + PUT, "/_xpack/security/user/{username}", deprecationLogger) + )); } @Override diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java index b13f0b328d993..b818a69384757 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -22,6 +21,9 @@ import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler; import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; @@ -34,21 +36,28 @@ public class RestSetEnabledAction extends SecurityBaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestSetEnabledAction.class)); - public RestSetEnabledAction(Settings settings, RestController controller, XPackLicenseState licenseState) { + public RestSetEnabledAction(Settings settings, XPackLicenseState licenseState) { super(settings, licenseState); + } + + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List replacedRoutes() { // TODO: remove deprecated endpoint in 8.0.0 - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_enable", this, - POST, "/_xpack/security/user/{username}/_enable", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}/_enable", this, - PUT, "/_xpack/security/user/{username}/_enable", deprecationLogger); - controller.registerWithDeprecatedHandler( - POST, "/_security/user/{username}/_disable", this, - POST, "/_xpack/security/user/{username}/_disable", deprecationLogger); - controller.registerWithDeprecatedHandler( - PUT, "/_security/user/{username}/_disable", this, - PUT, "/_xpack/security/user/{username}/_disable", deprecationLogger); + return Collections.unmodifiableList(Arrays.asList( + new ReplacedRoute(POST, "/_security/user/{username}/_enable", + POST, "/_xpack/security/user/{username}/_enable", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/{username}/_enable", + PUT, "/_xpack/security/user/{username}/_enable", deprecationLogger), + new ReplacedRoute(POST, "/_security/user/{username}/_disable", + POST, "/_xpack/security/user/{username}/_disable", deprecationLogger), + new ReplacedRoute(PUT, "/_security/user/{username}/_disable", + PUT, "/_xpack/security/user/{username}/_disable", deprecationLogger) + )); } @Override @@ -58,6 +67,7 @@ public String getName() { @Override public RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) throws IOException { + // TODO consider splitting up enable and disable to have their own rest handler final boolean enabled = request.path().endsWith("_enable"); assert enabled || request.path().endsWith("_disable"); final String username = request.param("username"); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java index 4b40d165b5e49..f0557fd68a079 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/SecurityBaseRestHandlerTests.java @@ -15,6 +15,8 @@ import org.elasticsearch.test.rest.FakeRestRequest; import java.io.IOException; +import java.util.Collections; +import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import static org.mockito.Mockito.mock; @@ -39,6 +41,11 @@ public String getName() { return "test_xpack_security_base_action"; } + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) throws IOException { return channel -> { diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java index 3f9b743c8e788..e51a4bfe09ebe 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestCreateApiKeyActionTests.java @@ -8,10 +8,10 @@ import org.apache.lucene.util.SetOnce; import org.elasticsearch.ElasticsearchSecurityException; -import org.elasticsearch.action.ActionType; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.action.ActionType; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.settings.SecureString; @@ -22,7 +22,6 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.AbstractRestChannel; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.test.ESTestCase; @@ -42,7 +41,6 @@ public class RestCreateApiKeyActionTests extends ESTestCase { private final XPackLicenseState mockLicenseState = mock(XPackLicenseState.class); - private final RestController mockRestController = mock(RestController.class); private Settings settings = null; private ThreadPool threadPool = null; @@ -98,8 +96,7 @@ void doExecute(ActionType action, Request request, ActionListener action, Request request, ActionListener action, Request request, ActionListener action, Request request, ActionListener action, Request request, ActionListener handledRoutes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) { return null; diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java index 16c9218058f1c..fd2418c09f7dc 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUserPrivilegesActionTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.license.XPackLicenseState; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestChannel; @@ -41,8 +40,8 @@ public class RestGetUserPrivilegesActionTests extends ESTestCase { public void testBasicLicense() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); - final RestGetUserPrivilegesAction action = new RestGetUserPrivilegesAction(Settings.EMPTY, mock(RestController.class), - mock(SecurityContext.class), licenseState); + final RestGetUserPrivilegesAction action = + new RestGetUserPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); when(licenseState.isSecurityAvailable()).thenReturn(false); final FakeRestRequest request = new FakeRestRequest(); final FakeRestChannel channel = new FakeRestChannel(request, true, 1); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java index d0173479f37d6..50561f427b9b8 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/user/RestHasPrivilegesActionTests.java @@ -13,7 +13,6 @@ import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.ESTestCase; @@ -39,7 +38,7 @@ public class RestHasPrivilegesActionTests extends ESTestCase { public void testBodyConsumed() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); final RestHasPrivilegesAction action = - new RestHasPrivilegesAction(Settings.EMPTY, mock(RestController.class), mock(SecurityContext.class), licenseState); + new RestHasPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); try (XContentBuilder bodyBuilder = JsonXContent.contentBuilder().startObject().endObject()) { final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) .withPath("/_security/user/_has_privileges/") @@ -52,8 +51,8 @@ public void testBodyConsumed() throws Exception { public void testBasicLicense() throws Exception { final XPackLicenseState licenseState = mock(XPackLicenseState.class); - final RestHasPrivilegesAction action = new RestHasPrivilegesAction(Settings.EMPTY, mock(RestController.class), - mock(SecurityContext.class), licenseState); + final RestHasPrivilegesAction action = + new RestHasPrivilegesAction(Settings.EMPTY, mock(SecurityContext.class), licenseState); when(licenseState.isSecurityAvailable()).thenReturn(false); try (XContentBuilder bodyBuilder = JsonXContent.contentBuilder().startObject().endObject()) { final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()) diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java index 88713eb4a8fae..f0be77701ea27 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlClearCursorAction.java @@ -9,7 +9,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.RestToXContentListener; import org.elasticsearch.xpack.sql.action.SqlClearCursorAction; @@ -17,13 +16,16 @@ import org.elasticsearch.xpack.sql.proto.Protocol; import java.io.IOException; +import java.util.List; +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestSqlClearCursorAction extends BaseRestHandler { - public RestSqlClearCursorAction(RestController controller) { - controller.registerHandler(POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT, this); + @Override + public List handledRoutes() { + return singletonList(new Route(Protocol.CLEAR_CURSOR_REST_ENDPOINT, POST)); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java index f275475530ad4..0659d59c4e2a6 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -25,15 +24,20 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +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 RestSqlQueryAction extends BaseRestHandler { - public RestSqlQueryAction(RestController controller) { - controller.registerHandler(GET, Protocol.SQL_QUERY_REST_ENDPOINT, this); - controller.registerHandler(POST, Protocol.SQL_QUERY_REST_ENDPOINT, this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(Protocol.SQL_QUERY_REST_ENDPOINT, GET), + new Route(Protocol.SQL_QUERY_REST_ENDPOINT, POST))); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java index 8bb6c3328b382..3324d3058a81a 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlStatsAction.java @@ -8,17 +8,20 @@ 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.RestActions; import org.elasticsearch.xpack.sql.proto.Protocol; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestSqlStatsAction extends BaseRestHandler { - protected RestSqlStatsAction(RestController controller) { - controller.registerHandler(GET, Protocol.SQL_STATS_REST_ENDPOINT, this); + @Override + public List handledRoutes() { + return singletonList(new Route(Protocol.SQL_STATS_REST_ENDPOINT, GET)); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java index b445789422e6e..540028c4351ac 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java @@ -8,7 +8,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.RestToXContentListener; import org.elasticsearch.xpack.sql.action.SqlTranslateAction; @@ -16,7 +15,10 @@ import org.elasticsearch.xpack.sql.proto.Protocol; 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; @@ -25,9 +27,11 @@ */ public class RestSqlTranslateAction extends BaseRestHandler { - public RestSqlTranslateAction(RestController controller) { - controller.registerHandler(GET, Protocol.SQL_TRANSLATE_REST_ENDPOINT, this); - controller.registerHandler(POST, Protocol.SQL_TRANSLATE_REST_ENDPOINT, this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(Protocol.SQL_TRANSLATE_REST_ENDPOINT, GET), + new Route(Protocol.SQL_TRANSLATE_REST_ENDPOINT, POST))); } @Override diff --git a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java index dbe14f99f3365..db9c0246210cd 100644 --- a/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java +++ b/x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java @@ -115,10 +115,10 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } - return Arrays.asList(new RestSqlQueryAction(restController), - new RestSqlTranslateAction(restController), - new RestSqlClearCursorAction(restController), - new RestSqlStatsAction(restController)); + return Arrays.asList(new RestSqlQueryAction(), + new RestSqlTranslateAction(), + new RestSqlClearCursorAction(), + new RestSqlStatsAction()); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java index 99a46a02d41d5..8c71f0b9c6e65 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java @@ -162,24 +162,24 @@ public List getRestHandlers( } return Arrays.asList( - new RestPutTransformAction(restController), - new RestStartTransformAction(restController), - new RestStopTransformAction(restController), - new RestDeleteTransformAction(restController), - new RestGetTransformAction(restController), - new RestGetTransformStatsAction(restController), - new RestPreviewTransformAction(restController), - new RestUpdateTransformAction(restController), + new RestPutTransformAction(), + new RestStartTransformAction(), + new RestStopTransformAction(), + new RestDeleteTransformAction(), + new RestGetTransformAction(), + new RestGetTransformStatsAction(), + new RestPreviewTransformAction(), + new RestUpdateTransformAction(), // deprecated endpoints, to be removed for 8.0.0 - new RestPutTransformActionDeprecated(restController), - new RestStartTransformActionDeprecated(restController), - new RestStopTransformActionDeprecated(restController), - new RestDeleteTransformActionDeprecated(restController), - new RestGetTransformActionDeprecated(restController), - new RestGetTransformStatsActionDeprecated(restController), - new RestPreviewTransformActionDeprecated(restController), - new RestUpdateTransformActionDeprecated(restController) + new RestPutTransformActionDeprecated(), + new RestStartTransformActionDeprecated(), + new RestStopTransformActionDeprecated(), + new RestDeleteTransformActionDeprecated(), + new RestGetTransformActionDeprecated(), + new RestGetTransformStatsActionDeprecated(), + new RestPreviewTransformActionDeprecated(), + new RestUpdateTransformActionDeprecated() ); } diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java index d6dbe7e468a3e..f984fe071e5d4 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformAction.java @@ -8,16 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.DeleteTransformAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteTransformAction extends BaseRestHandler { - public RestDeleteTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, this); + @Override + public List handledRoutes() { + return singletonList(new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, DELETE)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java index 23484f0e9408f..dca3534832cb1 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformAction.java @@ -8,20 +8,26 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.GetTransformAction; +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.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformAction extends BaseRestHandler { - public RestGetTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS, this); - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(TransformField.REST_BASE_PATH_TRANSFORMS, GET), + new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, GET))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java index 662f9840d0267..772b6d8600a82 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestGetTransformStatsAction.java @@ -8,20 +8,26 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction; +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.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformStatsAction extends BaseRestHandler { - public RestGetTransformStatsAction(RestController controller) { - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS + "_stats", this); - controller.registerHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stats", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route(TransformField.REST_BASE_PATH_TRANSFORMS + "_stats", GET), + new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stats", GET))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java index 114c88b761c65..442d88865f89a 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPreviewTransformAction.java @@ -9,18 +9,22 @@ 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.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.PreviewTransformAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPreviewTransformAction extends BaseRestHandler { - public RestPreviewTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS + "_preview", this); + @Override + public List handledRoutes() { + return singletonList(new Route(TransformField.REST_BASE_PATH_TRANSFORMS + "_preview", POST)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java index b61d81fb6e132..91d6c5f5160b4 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestPutTransformAction.java @@ -9,18 +9,22 @@ 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.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.PutTransformAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutTransformAction extends BaseRestHandler { - public RestPutTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, this); + @Override + public List handledRoutes() { + return singletonList(new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID, PUT)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java index ac6bb368cffab..de44180a83e8e 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStartTransformAction.java @@ -9,16 +9,21 @@ import org.elasticsearch.action.support.master.AcknowledgedRequest; 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.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.StartTransformAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartTransformAction extends BaseRestHandler { - public RestStartTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_start", this); + @Override + public List handledRoutes() { + return singletonList(new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_start", POST)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java index 85d138bfc37fd..edfbadd5f8697 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestStopTransformAction.java @@ -8,16 +8,21 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.StopTransformAction; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopTransformAction extends BaseRestHandler { - public RestStopTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stop", this); + @Override + public List handledRoutes() { + return singletonList(new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stop", POST)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java index 563c978641303..cbfe87749eef5 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/RestUpdateTransformAction.java @@ -9,18 +9,22 @@ 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.xpack.core.transform.TransformField; import org.elasticsearch.xpack.core.transform.action.UpdateTransformAction; import java.io.IOException; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpdateTransformAction extends BaseRestHandler { - public RestUpdateTransformAction(RestController controller) { - controller.registerHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_update", this); + @Override + public List handledRoutes() { + return singletonList(new Route(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_update", POST)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java index 94d4b5c65433b..0f60faa0a0799 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestDeleteTransformActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -18,14 +17,26 @@ import org.elasticsearch.xpack.core.transform.action.DeleteTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.DeleteTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.DELETE; + public class RestDeleteTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestDeleteTransformActionDeprecated.class)); - public RestDeleteTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + DELETE, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java index ca92942a52dd1..2a9ac6566d01b 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,12 @@ import org.elasticsearch.xpack.core.transform.action.GetTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.GetTransformActionDeprecated; +import java.util.Collections; +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.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformActionDeprecated extends BaseRestHandler { @@ -26,11 +31,18 @@ public class RestGetTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestGetTransformActionDeprecated.class)); - public RestGetTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED, GET, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger), + new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, GET, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java index b444ea3beef14..68b795c5754e4 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestGetTransformStatsActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.action.util.PageParams; @@ -19,6 +18,12 @@ import org.elasticsearch.xpack.core.transform.action.GetTransformStatsAction; import org.elasticsearch.xpack.core.transform.action.compat.GetTransformStatsActionDeprecated; +import java.util.Collections; +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.xpack.core.transform.TransformField.ALLOW_NO_MATCH; public class RestGetTransformStatsActionDeprecated extends BaseRestHandler { @@ -26,12 +31,18 @@ public class RestGetTransformStatsActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestGetTransformStatsActionDeprecated.class)); - public RestGetTransformStatsActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_stats", - this, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); - controller.registerAsDeprecatedHandler(RestRequest.Method.GET, - TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stats", this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_stats", GET, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger), + new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stats", GET, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger))); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java index 8c0a994ebbeff..c6691b59b58fa 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPreviewTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.transform.TransformField; @@ -20,15 +19,26 @@ import org.elasticsearch.xpack.core.transform.action.compat.PreviewTransformActionDeprecated; import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestPreviewTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestPreviewTransformActionDeprecated.class)); - public RestPreviewTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_preview", - this, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_preview", + POST, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java index aeac2c91be2f9..9159c284d109f 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestPutTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.transform.TransformField; @@ -20,15 +19,26 @@ import org.elasticsearch.xpack.core.transform.action.compat.PutTransformActionDeprecated; import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestPutTransformActionDeprecated.class)); - public RestPutTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, this, - TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, PUT, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java index 796c9833222aa..c665c4ca991e4 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStartTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -19,15 +18,26 @@ import org.elasticsearch.xpack.core.transform.action.StartTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.StartTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStartTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestStartTransformActionDeprecated.class)); - public RestStartTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, - TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_start", this, TransformMessages.REST_DEPRECATED_ENDPOINT, - deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_start", + POST, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java index 2a43df2a7f94d..3335a41d00298 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestStopTransformActionDeprecated.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestToXContentListener; import org.elasticsearch.xpack.core.transform.TransformField; @@ -18,14 +17,26 @@ import org.elasticsearch.xpack.core.transform.action.StopTransformAction; import org.elasticsearch.xpack.core.transform.action.compat.StopTransformActionDeprecated; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; + public class RestStopTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestStopTransformActionDeprecated.class)); - public RestStopTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stop", - this, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stop", POST, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java index 5be2586f955e8..63a68f71a8ac5 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/rest/action/compat/RestUpdateTransformActionDeprecated.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.logging.DeprecationLogger; 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.xpack.core.transform.TransformField; @@ -20,16 +19,26 @@ import org.elasticsearch.xpack.core.transform.action.compat.UpdateTransformActionDeprecated; import java.io.IOException; +import java.util.Collections; +import java.util.List; + +import static java.util.Collections.singletonList; +import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestUpdateTransformActionDeprecated extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger( LogManager.getLogger(RestUpdateTransformActionDeprecated.class)); - public RestUpdateTransformActionDeprecated(RestController controller) { - controller.registerAsDeprecatedHandler(RestRequest.Method.POST, - TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_update", this, TransformMessages.REST_DEPRECATED_ENDPOINT, - deprecationLogger); + @Override + public List handledRoutes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_update", + POST, TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger)); } @Override diff --git a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java index 36891461c2702..7672cf71f65d3 100644 --- a/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java +++ b/x-pack/plugin/transform/src/test/java/org/elasticsearch/xpack/transform/rest/action/RestDeleteTransformActionTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.common.xcontent.json.JsonXContent; -import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; @@ -22,8 +21,7 @@ public class RestDeleteTransformActionTests extends ESTestCase { public void testBodyRejection() throws Exception { - final RestDeleteTransformAction handler = new RestDeleteTransformAction( - mock(RestController.class)); + final RestDeleteTransformAction handler = new RestDeleteTransformAction(); try (XContentBuilder builder = JsonXContent.contentBuilder()) { builder.startObject(); { diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index d00915f12ad61..b7646930322f7 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -137,6 +137,7 @@ import org.elasticsearch.xpack.watcher.notification.slack.SlackService; import org.elasticsearch.xpack.watcher.rest.action.RestAckWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestActivateWatchAction; +import org.elasticsearch.xpack.watcher.rest.action.RestActivateWatchAction.DeactivateRestHandler; import org.elasticsearch.xpack.watcher.rest.action.RestDeleteWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestGetWatchAction; @@ -557,14 +558,16 @@ public List getRestHandlers(Settings settings, RestController restC return emptyList(); } return Arrays.asList( - new RestPutWatchAction(restController), - new RestDeleteWatchAction(restController), - new RestWatcherStatsAction(restController), - new RestGetWatchAction(restController), - new RestWatchServiceAction(restController), - new RestAckWatchAction(restController), - new RestActivateWatchAction(restController), - new RestExecuteWatchAction(restController)); + new RestPutWatchAction(), + new RestDeleteWatchAction(), + new RestWatcherStatsAction(), + new RestGetWatchAction(), + new RestWatchServiceAction(), + new RestWatchServiceAction.StopRestHandler(), + new RestAckWatchAction(), + new RestActivateWatchAction(), + new DeactivateRestHandler(), + new RestExecuteWatchAction()); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java index f016f253583aa..04dba0903a860 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -21,6 +20,10 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.ack.AckWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.WatchField; +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; @@ -29,11 +32,13 @@ */ public class RestAckWatchAction extends BaseRestHandler { - public RestAckWatchAction(RestController controller) { - controller.registerHandler(POST, "/_watcher/watch/{id}/_ack", this); - controller.registerHandler(PUT, "/_watcher/watch/{id}/_ack", this); - controller.registerHandler(POST, "/_watcher/watch/{id}/_ack/{actions}", this); - controller.registerHandler(PUT, "/_watcher/watch/{id}/_ack/{actions}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_watcher/watch/{id}/_ack", POST), + new Route("/_watcher/watch/{id}/_ack", PUT), + new Route("/_watcher/watch/{id}/_ack/{actions}", POST), + new Route("/_watcher/watch/{id}/_ack/{actions}", PUT))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java index 0317854d88b0f..066f82e24f4a4 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -21,6 +20,10 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.activate.ActivateWatchResponse; import org.elasticsearch.xpack.core.watcher.watch.WatchField; +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; @@ -29,13 +32,11 @@ */ public class RestActivateWatchAction extends BaseRestHandler { - public RestActivateWatchAction(RestController controller) { - controller.registerHandler(POST, "/_watcher/watch/{id}/_activate", this); - controller.registerHandler(PUT, "/_watcher/watch/{id}/_activate", this); - - final DeactivateRestHandler deactivateRestHandler = new DeactivateRestHandler(); - controller.registerHandler(POST, "/_watcher/watch/{id}/_deactivate", deactivateRestHandler); - controller.registerHandler(PUT, "/_watcher/watch/{id}/_deactivate", deactivateRestHandler); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_watcher/watch/{id}/_activate", POST), + new Route("/_watcher/watch/{id}/_activate", PUT))); } @Override @@ -58,9 +59,13 @@ public RestResponse buildResponse(ActivateWatchResponse response, XContentBuilde }); } - private static class DeactivateRestHandler extends BaseRestHandler { + public static class DeactivateRestHandler extends BaseRestHandler { - DeactivateRestHandler() { + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_watcher/watch/{id}/_deactivate", POST), + new Route("/_watcher/watch/{id}/_deactivate", PUT))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java index dd33b79365d49..47c2e9c01641c 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java @@ -12,21 +12,24 @@ import org.elasticsearch.protocol.xpack.watcher.DeleteWatchResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.rest.action.RestBuilderListener; import org.elasticsearch.xpack.core.watcher.transport.actions.delete.DeleteWatchAction; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.DELETE; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; public class RestDeleteWatchAction extends BaseRestHandler { - public RestDeleteWatchAction(RestController controller) { - controller.registerHandler(DELETE, "/_watcher/watch/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_watcher/watch/{id}", DELETE)); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java index a42161aafc301..df1bcf54d4431 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java @@ -15,7 +15,6 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -30,11 +29,12 @@ import org.elasticsearch.xpack.core.watcher.watch.WatchField; import java.io.IOException; -import java.util.Arrays; import java.util.Collections; 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.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction.Field.IGNORE_CONDITION; @@ -42,17 +42,19 @@ public class RestExecuteWatchAction extends BaseRestHandler implements RestRequestFilter { - private static final List RESERVED_FIELD_NAMES = Arrays.asList(WatchField.TRIGGER.getPreferredName(), + private static final List RESERVED_FIELD_NAMES = asList(WatchField.TRIGGER.getPreferredName(), WatchField.INPUT.getPreferredName(), WatchField.CONDITION.getPreferredName(), WatchField.ACTIONS.getPreferredName(), WatchField.TRANSFORM.getPreferredName(), WatchField.THROTTLE_PERIOD.getPreferredName(), WatchField.THROTTLE_PERIOD_HUMAN.getPreferredName(), WatchField.METADATA.getPreferredName(), WatchField.STATUS.getPreferredName()); - public RestExecuteWatchAction(RestController controller) { - controller.registerHandler(POST, "/_watcher/watch/{id}/_execute", this); - controller.registerHandler(PUT, "/_watcher/watch/{id}/_execute", this); - controller.registerHandler(POST, "/_watcher/watch/_execute", this); - controller.registerHandler(PUT, "/_watcher/watch/_execute", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_watcher/watch/{id}/_execute", POST), + new Route("/_watcher/watch/{id}/_execute", PUT), + new Route("/_watcher/watch/_execute", POST), + new Route("/_watcher/watch/_execute", PUT))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java index 1001c8181467a..e4a287431b663 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -19,14 +18,18 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchRequest; import org.elasticsearch.xpack.core.watcher.transport.actions.get.GetWatchResponse; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; public class RestGetWatchAction extends BaseRestHandler { - public RestGetWatchAction(RestController controller) { - controller.registerHandler(GET, "/_watcher/watch/{id}", this); + @Override + public List handledRoutes() { + return singletonList(new Route("/_watcher/watch/{id}", GET)); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java index 2240c789c53f2..068cf945a9253 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java @@ -14,7 +14,6 @@ import org.elasticsearch.protocol.xpack.watcher.PutWatchResponse; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.RestStatus; @@ -23,8 +22,11 @@ import org.elasticsearch.xpack.core.watcher.transport.actions.put.PutWatchAction; import java.util.Collections; +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.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; import static org.elasticsearch.rest.RestStatus.CREATED; @@ -32,9 +34,11 @@ public class RestPutWatchAction extends BaseRestHandler implements RestRequestFilter { - public RestPutWatchAction(RestController controller) { - controller.registerHandler(POST, "/_watcher/watch/{id}", this); - controller.registerHandler(PUT, "/_watcher/watch/{id}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_watcher/watch/{id}", POST), + new Route("/_watcher/watch/{id}", PUT))); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java index c59cdffdcb96c..c061feced4afe 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java @@ -8,19 +8,21 @@ 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.RestToXContentListener; import org.elasticsearch.xpack.core.watcher.transport.actions.service.WatcherServiceAction; import org.elasticsearch.xpack.core.watcher.transport.actions.service.WatcherServiceRequest; +import java.util.List; + +import static java.util.Collections.singletonList; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestWatchServiceAction extends BaseRestHandler { - public RestWatchServiceAction(RestController controller) { - controller.registerHandler(POST, "/_watcher/_start", this); - controller.registerHandler(POST, "/_watcher/_stop", new StopRestHandler()); + @Override + public List handledRoutes() { + return singletonList(new Route("/_watcher/_start", POST)); } @Override @@ -34,9 +36,11 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client client.execute(WatcherServiceAction.INSTANCE, new WatcherServiceRequest().start(), new RestToXContentListener<>(channel)); } - private static class StopRestHandler extends BaseRestHandler { + public static class StopRestHandler extends BaseRestHandler { - StopRestHandler() { + @Override + public List handledRoutes() { + return singletonList(new Route("/_watcher/_stop", POST)); } @Override diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java index 60a0e0fb9fcdd..641f4b36e371c 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java @@ -12,24 +12,28 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.logging.DeprecationLogger; import org.elasticsearch.rest.BaseRestHandler; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.action.RestActions; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsAction; import org.elasticsearch.xpack.core.watcher.transport.actions.stats.WatcherStatsRequest; import java.util.Collections; +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; public class RestWatcherStatsAction extends BaseRestHandler { private static final Logger logger = LogManager.getLogger(RestWatcherStatsAction.class); private static final DeprecationLogger deprecationLogger = new DeprecationLogger(logger); - public RestWatcherStatsAction(RestController controller) { - controller.registerHandler(GET, "/_watcher/stats", this); - controller.registerHandler(GET, "/_watcher/stats/{metric}", this); + @Override + public List handledRoutes() { + return unmodifiableList(asList( + new Route("/_watcher/stats", GET), + new Route("/_watcher/stats/{metric}", GET))); } @Override