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 0eceed67c4f7..2013b0d6680a 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 class NoopPlugin extends Plugin implements ActionPlugin { 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 ffc94a350785..389656ed0775 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.index.shard.ShardId; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; -import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; import org.elasticsearch.rest.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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_noop_bulk"), + new Route(PUT, "/_noop_bulk"), + new Route(POST, "/{index}/_noop_bulk"), + new Route(PUT, "/{index}/_noop_bulk"))); } @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 5271380bdfc1..cfc58b3aac94 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 @@ package org.elasticsearch.plugin.noop.action.search; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_noop_search"), + new Route(POST, "/_noop_search"), + new Route(GET, "/{index}/_noop_search"), + new Route(POST, "/{index}/_noop_search"))); } @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 35a4c76dd4a1..25ae529a2b2b 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.io.stream.StreamOutput; 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 @@ public class GrokProcessorGetAction extends ActionType routes() { + return singletonList(new Route(GET, "/_ingest/processor/grok")); } @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 b37e5d13e460..d4293c50e14a 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 class IngestCommonPlugin extends Plugin implements ActionPlugin, IngestPl 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 42c140cada0a..edbff8eb8b79 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 class MustachePlugin extends Plugin implements ScriptPlugin, ActionPlugin 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 c6baa257a786..70e41f8596d0 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 @@ package org.elasticsearch.script.mustache; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_msearch/template"), + new Route(POST, "/_msearch/template"), + new Route(GET, "/{index}/_msearch/template"), + new Route(POST, "/{index}/_msearch/template"))); } @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 767f6e95c1f7..320c6c582c8f 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 @@ package org.elasticsearch.script.mustache; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_render/template"), + new Route(POST, "/_render/template"), + new Route(GET, "/_render/template/{id}"), + new Route(POST, "/_render/template/{id}"))); } @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 4ce457c1a22e..70a87f3d20c2 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.action.search.SearchRequest; 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.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; @@ -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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_search/template"), + new Route(POST, "/_search/template"), + new Route(GET, "/{index}/_search/template"), + new Route(POST, "/{index}/_search/template"))); } @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 974cdefd529b..f65b3c2aa79a 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 final class PainlessPlugin extends Plugin implements ScriptPlugin, Extens 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 9075b9e030df..d670d9e35aaa 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.common.xcontent.XContentBuilder; 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.Map; 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 @@ public class PainlessContextAction extends ActionType routes() { + return singletonList(new Route(GET, "/_scripts/painless/_context")); } @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 b6bb1a842640..73847385d5ef 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.query.QueryShardContext; 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.threadpool.ThreadPool; 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 @@ public class PainlessExecuteAction extends ActionType routes() { + return unmodifiableList(asList( + new Route(GET, "/_scripts/painless/_execute"), + new Route(POST, "/_scripts/painless/_execute"))); } @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 48b429737810..9f21a6065900 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 org.elasticsearch.rest.RestHandler; 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 85e9e656808e..fc1f9f9f53cd 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/" + ENDPOINT), + new Route(POST, "/" + ENDPOINT), + new Route(GET, "/{index}/" + ENDPOINT), + new Route(POST, "/{index}/" + ENDPOINT))); } @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 fefee4f348b3..c0e6a55ec9c1 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 class ReindexPlugin extends Plugin implements ActionPlugin { 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 95fab3dd44db..94d6fc0b3937 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 routes() { + return singletonList(new Route(POST, "/{index}/_delete_by_query")); } @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 516d47b83580..1677fbd7c612 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 @@ package org.elasticsearch.index.reindex; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ public class RestReindexAction extends AbstractBaseReindexRestHandler { - public RestReindexAction(RestController controller) { + public RestReindexAction() { super(ReindexAction.INSTANCE); - controller.registerHandler(POST, "/_reindex", this); + } + + @Override + public List routes() { + return singletonList(new Route(POST, "/_reindex")); } @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 cdd29a89b92c..a89546efc27d 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 @@ package org.elasticsearch.index.reindex; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_update_by_query/{taskId}/_rethrottle"), + new Route(POST, "/_delete_by_query/{taskId}/_rethrottle"), + new Route(POST, "/_reindex/{taskId}/_rethrottle"))); } @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 5927aca9bb1e..0af069997d59 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 @@ package org.elasticsearch.index.reindex; 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.io.IOException; 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 routes() { + return singletonList(new Route(POST, "/{index}/_update_by_query")); } @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 ebfc117ec04e..cb8217b78ef3 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 79cb1a6f76de..1a8e2485529f 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 @@ package org.elasticsearch.example.resthandler; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ public class ExampleCatAction extends AbstractCatAction { - ExampleCatAction(final RestController controller) { - controller.registerHandler(GET, "/_cat/example", this); - controller.registerHandler(POST, "/_cat/example", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/example"), + new Route(POST, "/_cat/example"))); } @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 725049c797e1..420a58302f35 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 class ExampleRestHandlerPlugin extends Plugin implements ActionPlugin { 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 8b7093515cd7..29c81c1a39c0 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 class DieWithDignityPlugin extends Plugin implements ActionPlugin { 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 8f43d6790843..190a6929b1c3 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 @@ package org.elasticsearch; 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 routes() { + return singletonList(new Route(GET, "/_die_with_dignity")); } @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 a864bde42b28..29ea6af514e4 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.XContentBuilder; 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(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT, deprecationLogger)); } @Override @@ -78,6 +84,11 @@ public class TestDeprecationHeaderRestAction extends BaseRestHandler { return "test_deprecation_header_action"; } + @Override + public List routes() { + 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 a264227999ed..81faab828930 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 0f9b6f4db19d..a869276fdac1 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 c51947f7328c..d69beb337438 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 @@ package org.elasticsearch.http; 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 routes() { + return singletonList(new Route(GET, "/_protected")); } @Override diff --git a/server/src/main/java/org/elasticsearch/action/ActionModule.java b/server/src/main/java/org/elasticsearch/action/ActionModule.java index 064b28808dc3..62c265bc17a7 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.RestDeleteAction; 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 @@ public class ActionModule extends AbstractModule { 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 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(restController)); - registerHandler.accept(new RestGetSettingsAction(restController)); + registerHandler.accept(new RestUpdateSettingsAction()); + registerHandler.accept(new RestGetSettingsAction()); - registerHandler.accept(new RestAnalyzeAction(restController)); - registerHandler.accept(new RestGetIndexTemplateAction(restController)); - registerHandler.accept(new RestPutIndexTemplateAction(restController)); - registerHandler.accept(new RestDeleteIndexTemplateAction(restController)); + registerHandler.accept(new RestAnalyzeAction()); + registerHandler.accept(new RestGetIndexTemplateAction()); + registerHandler.accept(new RestPutIndexTemplateAction()); + registerHandler.accept(new RestDeleteIndexTemplateAction()); - registerHandler.accept(new RestPutMappingAction(restController)); - registerHandler.accept(new RestGetMappingAction(restController)); - registerHandler.accept(new RestGetFieldMappingAction(restController)); + registerHandler.accept(new RestPutMappingAction()); + registerHandler.accept(new RestGetMappingAction()); + registerHandler.accept(new RestGetFieldMappingAction()); - 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 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(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 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(restController)); - registerHandler.accept(new RestSearchScrollAction(restController)); - registerHandler.accept(new RestClearScrollAction(restController)); - registerHandler.accept(new RestMultiSearchAction(settings, restController)); + registerHandler.accept(new RestSearchAction()); + registerHandler.accept(new RestSearchScrollAction()); + registerHandler.accept(new RestClearScrollAction()); + registerHandler.accept(new RestMultiSearchAction(settings)); - registerHandler.accept(new RestValidateQueryAction(restController)); + registerHandler.accept(new RestValidateQueryAction()); - registerHandler.accept(new RestExplainAction(restController)); + registerHandler.accept(new RestExplainAction()); - registerHandler.accept(new RestRecoveryAction(restController)); + registerHandler.accept(new RestRecoveryAction()); - registerHandler.accept(new RestReloadSecureSettingsAction(restController)); + 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 abf27b662bb7..5e18a9162f1d 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 class MapBuilder { 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 5d33e5551462..f2fd12bfa79c 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 abstract class BaseRestHandler implements RestHandler { */ public abstract String getName(); + /** + * {@inheritDoc} + */ + @Override + public abstract List routes(); + @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 aa39ccdc4659..6a16007465c5 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 class RestController implements HttpServerTransport.Dispatcher { * @param deprecationMessage The message to log and send as a header in the response * @param logger The existing deprecation logger to use */ - public void registerAsDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, + protected void registerAsDeprecatedHandler(RestRequest.Method method, String path, RestHandler handler, String deprecationMessage, DeprecationLogger logger) { assert (handler instanceof DeprecationRestHandler) == false; @@ -128,7 +128,7 @@ public class RestController implements HttpServerTransport.Dispatcher { * @param deprecatedPath Deprecated 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 class RestController implements HttpServerTransport.Dispatcher { * @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 class RestController implements HttpServerTransport.Dispatcher { (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.routes().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 605dd41078a5..ab7b468f7576 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 @@ public interface RestHandler { default boolean allowsUnsafeBuffers() { return false; } + + /** + * The list of {@link Route}s that this RestHandler is responsible for handling. + */ + default List routes() { + 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(Method method, String path) { + 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(Method method, String path, String deprecationMessage, DeprecationLogger logger) { + super(method, path); + 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(method, path); + 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 613729f8904a..6d868dd0d1bc 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_field_caps"), + new Route(POST, "/_field_caps"), + new Route(GET, "/{index}/_field_caps"), + new Route(POST, "/{index}/_field_caps"))); } @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 e776a6ad08a7..f5a433cd57e7 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.client.node.NodeClient; 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 routes() { + 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 018392bb05ad..4384d0d9dadf 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.client.node.NodeClient; 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 routes() { + return singletonList(new Route(POST, "/_cluster/voting_config_exclusions/{node_name}")); + } + @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 2dd98bfb9a50..99321627cf7f 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.client.node.NodeClient; 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 @@ import static org.elasticsearch.rest.action.admin.cluster.RestListTasksAction.li 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 class RestCancelTasksAction extends BaseRestHandler { return "cancel_tasks_action"; } + @Override + public List routes() { + return unmodifiableList(asList(new Route(POST, "/_tasks/_cancel"), + new Route(POST, "/_tasks/{task_id}/_cancel"))); + } + @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 3eca34ff2d3d..3e9d8e46022a 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ public class RestCleanupRepositoryAction extends BaseRestHandler { - public RestCleanupRepositoryAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/_cleanup", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_snapshot/{repository}/_cleanup")); } @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 8d9a2121b814..67c6a4e5d988 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.ClearVotingConfigExc 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 routes() { + return singletonList(new Route(DELETE, "/_cluster/voting_config_exclusions")); } @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 99d0f00d0967..d8a3b81d8c2f 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.XContentBuilder; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/allocation/explain"), + new Route(POST, "/_cluster/allocation/explain"))); } @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 0a4d5b4e897f..03064337b393 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.ToXContent; 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 routes() { + return singletonList(new Route(GET, "/_cluster/settings")); + } @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 63c6bc4c92c0..99ac7d440815 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.cluster.health.ClusterHealthStatus; 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 routes() { + return unmodifiableList(asList(new Route(GET, "/_cluster/health"), + new Route(GET, "/_cluster/health/{index}"))); } @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 30799cb0552c..c5a60cf7b6b5 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.settings.SettingsFilter; 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.io.IOException; 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 routes() { + return singletonList(new Route(POST, "/_cluster/reroute")); } @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 188691dacf5e..3660450457cb 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.Requests; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_search_shards"), + new Route(POST, "/_search_shards"), + new Route(GET, "/{index}/_search_shards"), + new Route(POST, "/{index}/_search_shards"))); } @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 9838cc26625f..1c68d2d5147d 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.settings.SettingsFilter; 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.io.IOException; 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 class RestClusterStateAction extends BaseRestHandler { return "cluster_state_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/state"), + new Route(GET, "/_cluster/state/{metric}"), + new Route(GET, "/_cluster/state/{metric}/{indices}"))); + } + @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 c7bfc640e76b..9edaa4b2f1be 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/stats"), + new Route(GET, "/_cluster/stats/nodes/{nodeId}"))); } @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 35874f12d5fe..3558da8ee081 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.client.node.NodeClient; 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 routes() { + return singletonList(new Route(PUT, "/_cluster/settings")); } @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 185a1659738f..2f56b0b10e2e 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; */ 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 routes() { + return unmodifiableList(asList( + new Route(PUT, "/_snapshot/{repository}/{snapshot}"), + new Route(POST, "/_snapshot/{repository}/{snapshot}"))); } @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 81914718b07d..95f635d1728a 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE; */ public class RestDeleteRepositoryAction extends BaseRestHandler { - public RestDeleteRepositoryAction(RestController controller) { - controller.registerHandler(DELETE, "/_snapshot/{repository}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_snapshot/{repository}")); } @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 81a3ddd31c59..f74fc73c1f32 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE; */ public class RestDeleteSnapshotAction extends BaseRestHandler { - public RestDeleteSnapshotAction(RestController controller) { - controller.registerHandler(DELETE, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List routes() { + return singletonList(new Route(DELETE, "/_snapshot/{repository}/{snapshot}")); } @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 a0258974cfc4..efd18f641553 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return singletonList(new Route(DELETE, "/_scripts/{id}")); } @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 5b39a7e6df34..572cb96cc096 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.Strings; 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 class RestGetRepositoriesAction extends BaseRestHandler { return "get_repositories_action"; } + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_snapshot"), + new Route(GET, "/_snapshot/{repository}"))); + } + @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 9a40225b769b..e7c0b65e3b58 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return singletonList(new Route(GET, "/_script_context")); } @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 c9246b910cf4..d40bbeb0b8df 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return singletonList(new Route(GET, "/_script_language")); } @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 f47ddefa8f67..1c90bb79f32f 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.action.admin.cluster.snapshots.get.GetSnapshotsRequest; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ public class RestGetSnapshotsAction extends BaseRestHandler { - public RestGetSnapshotsAction(RestController controller) { - controller.registerHandler(GET, "/_snapshot/{repository}/{snapshot}", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_snapshot/{repository}/{snapshot}")); } @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 f87c6f513b79..48407c7b5d53 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return singletonList(new Route(GET, "/_scripts/{id}")); } @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 f0ca02f43bc3..6eded15a253b 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.action.admin.cluster.node.tasks.get.GetTaskRequest; 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 routes() { + return singletonList(new Route(GET, "/_tasks/{task_id}")); } @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 4627b853ac71..b6c9fad9fdef 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.common.xcontent.XContentBuilder; 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.rest.action.RestToXContentListener; 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 routes() { + return singletonList(new Route(GET, "/_tasks")); } @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 07b85266d9d8..5aeefa934d02 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.Strings; 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); - - 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cluster/nodes/hotthreads"), + new Route(GET, "/_cluster/nodes/hot_threads"), + new Route(GET, "/_cluster/nodes/{nodeId}/hotthreads"), + new Route(GET, "/_cluster/nodes/{nodeId}/hot_threads"), + new Route(GET, "/_nodes/hotthreads"), + new Route(GET, "/_nodes/hot_threads"), + new Route(GET, "/_nodes/{nodeId}/hotthreads"), + new Route(GET, "/_nodes/{nodeId}/hot_threads"))); } @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 ab39c4408f21..4b42516ef06b 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.Settings; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_nodes"), + // this endpoint is used for metrics, not for node IDs, like /_nodes/fs + new Route(GET, "/_nodes/{nodeId}"), + new Route(GET, "/_nodes/{nodeId}/{metrics}"), + // added this endpoint to be aligned with stats + new Route(GET, "/_nodes/{nodeId}/info/{metrics}"))); + } + @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 f8127b32db0a..6eb834c3234c 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.action.admin.indices.stats.CommonStatsFlags.Flag; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_nodes/stats"), + new Route(GET, "/_nodes/{nodeId}/stats"), + new Route(GET, "/_nodes/stats/{metric}"), + new Route(GET, "/_nodes/{nodeId}/stats/{metric}"), + new Route(GET, "/_nodes/stats/{metric}/{index_metric}"), + new Route(GET, "/_nodes/{nodeId}/stats/{metric}/{index_metric}"))); } 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 f1a3b15d8b65..0e8b6370f9a1 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.NodesUsageRequest; 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.RestActions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_nodes/usage"), + new Route(GET, "/_nodes/{nodeId}/usage"), + new Route(GET, "/_nodes/usage/{metric}"), + new Route(GET, "/_nodes/{nodeId}/usage/{metric}"))); } @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 dbf03e35130c..05265f77f85a 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return singletonList(new Route(GET, "/_cluster/pending_tasks")); } @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 150296d65aea..f76d97e0296b 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.action.admin.cluster.repositories.put.PutRepositoryRequ 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 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; */ public class RestPutRepositoryAction extends BaseRestHandler { - public RestPutRepositoryAction(RestController controller) { - controller.registerHandler(PUT, "/_snapshot/{repository}", this); - controller.registerHandler(POST, "/_snapshot/{repository}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_snapshot/{repository}"), + new Route(PUT, "/_snapshot/{repository}"))); } @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 2e316abc1429..499fd1b91f29 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_scripts/{id}"), + new Route(PUT, "/_scripts/{id}"), + new Route(POST, "/_scripts/{id}/{context}"), + new Route(PUT, "/_scripts/{id}/{context}"))); } @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 e5f85c569ee6..209e0ef7d335 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.ObjectParser; 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.RestActions; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_nodes/reload_secure_settings"), + new Route(POST, "/_nodes/{nodeId}/reload_secure_settings"))); + } + @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 a49f6d1319ba..e12d930c5bf2 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.RemoteInfoAction; 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 routes() { + return singletonList(new Route(GET, "_remote/info")); } @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 fb47e928ab87..d94c2e0285cd 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ public class RestRestoreSnapshotAction extends BaseRestHandler { - public RestRestoreSnapshotAction(RestController controller) { - controller.registerHandler(POST, "/_snapshot/{repository}/{snapshot}/_restore", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_snapshot/{repository}/{snapshot}/_restore")); } @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 f8347d38cd57..19328f2eff2c 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.action.admin.cluster.snapshots.status.SnapshotsStatusRe 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_snapshot/{repository}/{snapshot}/_status"), + new Route(GET, "/_snapshot/{repository}/_status"), + new Route(GET, "/_snapshot/_status"))); } @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 be69e73275c8..ad796897c8a8 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 @@ package org.elasticsearch.rest.action.admin.cluster; 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 routes() { + return singletonList(new Route(POST, "/_snapshot/{repository}/_verify")); } @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 af9bfbfe595d..15d34a91d9d1 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.client.node.NodeClient; 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 class RestAnalyzeAction extends BaseRestHandler { 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_analyze"), + new Route(POST, "/_analyze"), + new Route(GET, "/{index}/_analyze"), + new Route(POST, "/{index}/_analyze"))); } @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 bc2fed911b3a..fd6979c92e29 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_cache/clear"), + new Route(POST, "/{index}/_cache/clear"))); } @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 3f26b1978372..5d3a186b8cb4 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_close"), + new Route(POST, "/{index}/_close"))); } @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 a43c508f7487..59156c70502e 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.LoggingDeprecationHandler; 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 routes() { + return singletonList(new Route(PUT, "/{index}")); } @Override @@ -79,7 +83,7 @@ public class RestCreateIndexAction extends BaseRestHandler { 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 b0d02cd19b7e..a82370e89af8 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(DELETE, "/"), + new Route(DELETE, "/{index}"))); } @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 c0679bb35624..a92bee023452 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 @@ package org.elasticsearch.rest.action.admin.indices; 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 routes() { + return singletonList(new Route(DELETE, "/_template/{name}")); } @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 f9d614e9b991..d22dcb91d1a9 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_flush"), + new Route(POST, "/_flush"), + new Route(GET, "/{index}/_flush"), + new Route(POST, "/{index}/_flush"))); } @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 e6f5ef549d1c..9cba54ed7724 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_forcemerge"), + new Route(POST, "/{index}/_forcemerge"))); } @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 3379ab009573..f05554322aa7 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.ToXContent; 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.Set; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.HEAD; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_alias"), + new Route(GET, "/_aliases"), + new Route(GET, "/_alias/{name}"), + new Route(HEAD, "/_alias/{name}"), + new Route(GET, "/{index}/_alias"), + new Route(HEAD, "/{index}/_alias"), + new Route(GET, "/{index}/_alias/{name}"), + new Route(HEAD, "/{index}/_alias/{name}"))); } @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 d4a5a0cb5814..807ff220ff8e 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.Strings; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_mapping/field/{fields}"), + new Route(GET, "/{index}/_mapping/field/{fields}"))); } @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 0c99ccef08e8..767c5fa3e923 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.client.node.NodeClient; 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 @@ import static org.elasticsearch.rest.RestStatus.OK; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_template"), + new Route(GET, "/_template/{name}"), + new Route(HEAD, "/_template/{name}"))); } @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 e39ff1cf7017..fff606e8b922 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.client.node.NodeClient; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.HEAD; */ public class RestGetIndicesAction extends BaseRestHandler { - public RestGetIndicesAction(final RestController controller) { - controller.registerHandler(GET, "/{index}", this); - controller.registerHandler(HEAD, "/{index}", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}"), + new Route(HEAD, "/{index}"))); } @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 f42099e4219a..55b255ca7b63 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.Strings; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_mapping"), + new Route(GET, "/_mappings"), + new Route(GET, "/{index}/_mapping"), + new Route(GET, "/{index}/_mappings"))); } @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 c7b9cc485d3c..20058c812b94 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_settings"), + new Route(GET, "/_settings/{name}"), + new Route(GET, "/{index}/_settings"), + new Route(GET, "/{index}/_settings/{name}"), + new Route(GET, "/{index}/_setting/{name}"))); } @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 91442bb2fb9e..ff454ee5354c 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.action.admin.indices.alias.IndicesAliasesRequest.AliasA 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 routes() { + return unmodifiableList(asList( + new Route(DELETE, "/{index}/_alias/{name}"), + new Route(DELETE, "/{index}/_aliases/{name}"))); } @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 3c51c9111f2a..fb6bede4e0ae 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_alias/{name}"), + new Route(PUT, "/{index}/_alias/{name}"), + new Route(POST, "/_alias/{name}"), + new Route(PUT, "/_alias/{name}"), + new Route(POST, "/{index}/_aliases/{name}"), + new Route(PUT, "/{index}/_aliases/{name}"), + new Route(POST, "/_aliases/{name}"), + new Route(PUT, "/_aliases/{name}"), + new Route(PUT, "/{index}/_alias"), + new Route(PUT, "/{index}/_aliases"), + new Route(PUT, "/_alias"))); } @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 d305c5ad3ca4..e49285774795 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.action.admin.indices.alias.IndicesAliasesRequest; 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 class RestIndicesAliasesAction extends BaseRestHandler { return "indices_aliases_action"; } - public RestIndicesAliasesAction(RestController controller) { - controller.registerHandler(POST, "/_aliases", this); + @Override + public List routes() { + return singletonList(new Route(POST, "/_aliases")); } @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 ed76c36dac34..e14a83bd3084 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_segments"), + new Route(GET, "/{index}/_segments"))); } @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 e214e7bbb341..39ff18cade94 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.Strings; 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 @@ import static org.elasticsearch.rest.RestStatus.OK; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_shard_stores"), + new Route(GET, "/{index}/_shard_stores"))); } @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 4562365c8abe..0b2cacc0f53a 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_stats"), + new Route(GET, "/_stats/{metric}"), + new Route(GET, "/{index}/_stats"), + new Route(GET, "/{index}/_stats/{metric}"))); } @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 8eb5c3a74bd7..5ffc29e26e11 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_open"), + new Route(POST, "/{index}/_open"))); } @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 68e62ac3c684..974602a9fcca 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_template/{name}"), + new Route(PUT, "/_template/{name}"))); } @Override @@ -48,7 +54,7 @@ public class RestPutIndexTemplateAction extends BaseRestHandler { 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 3e9f984f1517..c8f42975640a 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.Strings; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_mapping/"), + new Route(PUT, "/{index}/_mapping/"), + new Route(POST, "/{index}/_mappings/"), + new Route(PUT, "/{index}/_mappings/"))); } @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 38325a17f489..ac8744f39c70 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.action.support.IndicesOptions; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ public class RestRecoveryAction extends BaseRestHandler { - public RestRecoveryAction(RestController controller) { - controller.registerHandler(GET, "/_recovery", this); - controller.registerHandler(GET, "/{index}/_recovery", this); + @Override + public List routes() { + return unmodifiableList(asList( + new Route(GET, "/_recovery"), + new Route(GET, "/{index}/_recovery"))); } @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 5e89e16d068f..cae120e50bb4 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_refresh"), + new Route(POST, "/_refresh"), + new Route(GET, "/{index}/_refresh"), + new Route(POST, "/{index}/_refresh"))); } @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 291cf61caf7b..f26f2cab7989 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.admin.indices.shrink.ResizeType; 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 abstract class RestResizeHandler extends BaseRestHandler { 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_shrink/{target}"), + new Route(PUT, "/{index}/_shrink/{target}"))); } @Override @@ -72,9 +79,11 @@ public abstract class RestResizeHandler extends BaseRestHandler { 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_split/{target}"), + new Route(PUT, "/{index}/_split/{target}"))); } @Override @@ -91,9 +100,11 @@ public abstract class RestResizeHandler extends BaseRestHandler { 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_clone/{target}"), + new Route(PUT, "/{index}/_clone/{target}"))); } @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 d90f0d7e23f1..580daa864c39 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.admin.indices.rollover.RolloverRequest; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_rollover"), + new Route(POST, "/{index}/_rollover/{new_index}"))); } @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 d775189af48e..638db99538ce 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.common.xcontent.XContentBuilder; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_flush/synced"), + new Route(POST, "/_flush/synced"), + new Route(GET, "/{index}/_flush/synced"), + new Route(POST, "/{index}/_flush/synced"))); } @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 e26bf9f318e5..4db753985056 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(PUT, "/{index}/_settings"), + new Route(PUT, "/_settings"))); } @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 f63fe49ec6e9..769832e7e3e8 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.client.node.NodeClient; 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(POST, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger), + new DeprecatedRoute(POST, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger))); + } + + @Override + public List routes() { + 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 1eb09b31ce26..30d07283e466 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.client.node.NodeClient; 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(GET, "/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger), + new DeprecatedRoute(GET, "/{index}/_upgrade", UPGRADE_API_DEPRECATION_MESSAGE, deprecationLogger))); + } + + @Override + public List routes() { + 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 d176dad12e19..68be9cba956d 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.common.xcontent.XContentBuilder; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_validate/query"), + new Route(POST, "/_validate/query"), + new Route(GET, "/{index}/_validate/query"), + new Route(POST, "/{index}/_validate/query"))); } @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 4fd43becf431..cc96487fd45d 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/aliases"), + new Route(GET, "/_cat/aliases/{alias}"))); } @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 1f30fb917ea2..1c81d24c21e2 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.cluster.routing.ShardRouting; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/allocation"), + new Route(GET, "/_cat/allocation/{nodes}"))); } @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 fe5f7b8127c5..c545a1bd2f38 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 class RestCatAction extends BaseRestHandler { HELP = sb.toString(); } + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat")); + } + @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 d16e17e937ec..9e29b17070cc 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.ByteSizeValue; 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.Comparator; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/recovery"), + new Route(GET, "/_cat/recovery/{index}"))); } @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 7b7742972eac..fada1e5d3564 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.client.node.NodeClient; 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.rest.action.RestResponseListener; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/count"), + new Route(GET, "/_cat/count/{index}"))); } @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 2eb83151953f..cc7e16b2ea39 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.action.admin.cluster.node.stats.NodesStatsResponse; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/fielddata"), + new Route(GET, "/_cat/fielddata/{fields}"))); } @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 5e896f210f66..7e859ac0f21a 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.ClusterHealthRequest; 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 routes() { + return singletonList(new Route(GET, "/_cat/health")); } @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 5a50b0ff04ce..d122bc7bd269 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.settings.Settings; 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 org.elasticsearch.rest.action.RestResponseListener; 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.function.Function; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/indices"), + new Route(GET, "/_cat/indices/{index}"))); } @Override @@ -234,7 +237,7 @@ public class RestIndicesAction extends AbstractCatAction { 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 e50865af019c..18dea4625b6f 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.client.node.NodeClient; 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 routes() { + return singletonList(new Route(GET, "/_cat/master")); } @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 efae10a6aa25..dcb75b22e647 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.DiscoveryNode; 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 routes() { + return singletonList(new Route(GET, "/_cat/nodeattrs")); } @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 ac26c4338500..a80390a0a04f 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.JvmInfo; 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.rest.action.RestResponseListener; 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 routes() { + return singletonList(new Route(GET, "/_cat/nodes")); } @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 84bd87981536..f3071839612e 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.action.admin.cluster.tasks.PendingClusterTasksResponse; 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 routes() { + return singletonList(new Route(GET, "/_cat/pending_tasks")); } @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 eb6a6fc4b8ff..9a50deee98c8 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.DiscoveryNode; 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 routes() { + return singletonList(new Route(GET, "/_cat/plugins")); } @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 f77f9bf100bd..e9a5bd6b3aac 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.action.admin.cluster.repositories.get.GetRepositoriesRe 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ public class RestRepositoriesAction extends AbstractCatAction { - public RestRepositoriesAction(RestController controller) { - controller.registerHandler(GET, "/_cat/repositories", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_cat/repositories")); } @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 c51fa593f3b5..3c63f7bbdbf3 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.cluster.node.DiscoveryNodes; 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 org.elasticsearch.rest.action.RestResponseListener; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/segments"), + new Route(GET, "/_cat/segments/{index}"))); } @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 847b1a773e52..9a321476efda 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.seqno.SeqNoStats; 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.rest.action.RestResponseListener; 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 routes() { + return unmodifiableList(asList(new Route(GET, "/_cat/shards"), + new Route(GET, "/_cat/shards/{index}"))); } @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 94361b90eb8c..257bf5c1a220 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.Strings; 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.List; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/snapshots"), + new Route(GET, "/_cat/snapshots/{repository}"))); } @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 b6d5eb549bfa..2868d16d682f 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.Strings; 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.List; 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 routes() { + return singletonList(new Route(GET, "/_cat/tasks")); + } + @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 c8da4648e2ac..fb9946d5acfe 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.IndexTemplateMetaData; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/templates"), + new Route(GET, "/_cat/templates/{name}"))); } @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 571767affd0c..caaaeba07b96 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.DiscoveryNode; 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 org.elasticsearch.threadpool.ThreadPoolStats; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_cat/thread_pool"), + new Route(GET, "/_cat/thread_pool/{thread_pool_patterns}"))); } @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 db925cd663ff..b9a36d181b3a 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.Requests; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_bulk"), + new Route(PUT, "/_bulk"), + new Route(POST, "/{index}/_bulk"), + new Route(PUT, "/{index}/_bulk"))); + } + @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 bf7cd0d8da6e..8e46244101e7 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.action.support.ActiveShardCount; 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 routes() { + return singletonList(new Route(DELETE, "/{index}/_doc/{id}")); } @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 d90431d2c0cd..54f1f954f816 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.client.node.NodeClient; 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.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.HEAD; import static org.elasticsearch.rest.RestStatus.NOT_FOUND; @@ -41,16 +43,18 @@ import static org.elasticsearch.rest.RestStatus.OK; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_doc/{id}"), + new Route(HEAD, "/{index}/_doc/{id}"))); + } + @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 c9cb5a5fb0f5..72bc4538cbbe 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.common.xcontent.XContentHelper; 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 org.elasticsearch.search.fetch.subphase.FetchSourceContext; 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 @@ import static org.elasticsearch.rest.RestStatus.OK; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_source/{id}"), + new Route(HEAD, "/{index}/_source/{id}"))); } @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 03ae85e380e8..ef52af60e6ef 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_doc/{id}"), + new Route(PUT, "/{index}/_doc/{id}"))); } @Override @@ -59,20 +54,25 @@ public class RestIndexAction extends BaseRestHandler { 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_create/{id}"), + new Route(PUT, "/{index}/_create/{id}"))); + } + @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 @@ public class RestIndexAction extends BaseRestHandler { } } - 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 class RestIndexAction extends BaseRestHandler { return "document_create_action"; } + @Override + public List routes() { + return singletonList(new Route(POST, "/{index}/_doc")); + } + @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 class RestIndexAction extends BaseRestHandler { // 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 7b1cb4aaaeba..c9fd67d67815 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.Strings; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_mget"), + new Route(POST, "/_mget"), + new Route(GET, "/{index}/_mget"), + new Route(POST, "/{index}/_mget"))); + } + @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 8d1b6c96b1d4..504620a58f7e 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.action.termvectors.TermVectorsRequest; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_mtermvectors"), + new Route(POST, "/_mtermvectors"), + new Route(GET, "/{index}/_mtermvectors"), + new Route(POST, "/{index}/_mtermvectors"))); } @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 66afda4879e3..b9c2e12cbf0c 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.Strings; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_termvectors"), + new Route(POST, "/{index}/_termvectors"), + new Route(GET, "/{index}/_termvectors/{id}"), + new Route(POST, "/{index}/_termvectors/{id}"))); } @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 82bcf1ffbaed..2ef58e23e159 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.action.update.UpdateRequest; 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 routes() { + return singletonList(new Route(POST, "/{index}/_update/{id}")); } @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 dea61df609a9..2956811e26fe 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 @@ package org.elasticsearch.rest.action.ingest; 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 routes() { + return singletonList(new Route(DELETE, "/_ingest/pipeline/{id}")); } @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 751b9ee68894..1e4e016027b8 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.action.ingest.GetPipelineRequest; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_ingest/pipeline"), + new Route(GET, "/_ingest/pipeline/{id}"))); } @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 3b1861c14f59..b1fb8086e065 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.bytes.BytesReference; 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 routes() { + return singletonList(new Route(PUT, "/_ingest/pipeline/{id}")); } @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 6b8d6c3ccc4c..1ac0bdd6fcd5 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.bytes.BytesReference; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_ingest/pipeline/{id}/_simulate"), + new Route(POST, "/_ingest/pipeline/{id}/_simulate"), + new Route(GET, "/_ingest/pipeline/_simulate"), + new Route(POST, "/_ingest/pipeline/_simulate"))); } @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 a8c69867a57f..90e8f95227ce 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.action.search.ClearScrollRequest; 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 routes() { + return unmodifiableList(asList( + new Route(DELETE, "/_search/scroll"), + new Route(DELETE, "/_search/scroll/{scroll_id}"))); } @Override @@ -47,7 +51,7 @@ public class RestClearScrollAction extends BaseRestHandler { 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 bed40bffd5e8..cc3211d2bf21 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.common.xcontent.XContentBuilder; 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.rest.action.RestBuilderListener; 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 @@ import static org.elasticsearch.search.internal.SearchContext.DEFAULT_TERMINATE_ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_count"), + new Route(POST, "/_count"), + new Route(GET, "/{index}/_count"), + new Route(POST, "/{index}/_count"))); } @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 5613540edad8..9ee2a4ee79e2 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.client.node.NodeClient; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_explain/{id}"), + new Route(POST, "/{index}/_explain/{id}"))); } @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 e0752d41926a..6966e67edeac 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.XContent; 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.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; @@ -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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_msearch"), + new Route(POST, "/_msearch"), + new Route(GET, "/{index}/_msearch"), + new Route(POST, "/{index}/_msearch"))); + } + @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 5bdc0f3fffad..782c613a3627 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.Strings; 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.io.IOException; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_search"), + new Route(POST, "/_search"), + new Route(GET, "/{index}/_search"), + new Route(POST, "/{index}/_search"))); + } + @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 0b49048dee90..6060574a7dbc 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 @@ package org.elasticsearch.rest.action.search; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_search/scroll"), + new Route(POST, "/_search/scroll"), + new Route(GET, "/_search/scroll/{scroll_id}"), + new Route(POST, "/_search/scroll/{scroll_id}"))); + } + @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 df0c77c96ea1..1d2c67d6d2b0 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 class ActionModuleTests extends ESTestCase { 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 routes() { + return singletonList(new Route(Method.GET, "/")); + } + })); assertThat(e.getMessage(), startsWith("Cannot replace existing handler for [/] for method: GET")); } @@ -123,7 +132,7 @@ public class ActionModuleTests extends ESTestCase { 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 class ActionModuleTests extends ESTestCase { public void testPluginCanRegisterRestHandler() { class FakeHandler implements RestHandler { - FakeHandler(RestController restController) { - restController.registerHandler(Method.GET, "/_dummy", this); + @Override + public List routes() { + return singletonList(new Route(Method.GET, "/_dummy")); } + @Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { } @@ -154,7 +165,7 @@ public class ActionModuleTests extends ESTestCase { 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 class ActionModuleTests extends ESTestCase { 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 routes() { + return singletonList(new Route(Method.GET, "/_dummy")); + } + })); 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 919b3935a7f4..322b8a61fcce 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 66badef0cefc..c412af527507 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 org.elasticsearch.test.rest.FakeRestRequest; 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 @@ public class BaseRestHandlerTests extends ESTestCase { public String getName() { return "test_one_unconsumed_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -81,6 +87,11 @@ public class BaseRestHandlerTests extends ESTestCase { public String getName() { return "test_multiple_unconsumed_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -117,6 +128,11 @@ public class BaseRestHandlerTests extends ESTestCase { public String getName() { return "test_unconsumed_did_you_mean_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -160,6 +176,11 @@ public class BaseRestHandlerTests extends ESTestCase { public String getName() { return "test_unconsumed_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -183,6 +204,11 @@ public class BaseRestHandlerTests extends ESTestCase { public String getName() { return "test_default_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -218,6 +244,11 @@ public class BaseRestHandlerTests extends ESTestCase { public String getName() { return "test_cat_response_action"; } + + @Override + public List routes() { + return Collections.emptyList(); + } }; final HashMap params = new HashMap<>(); @@ -249,6 +280,10 @@ public class BaseRestHandlerTests extends ESTestCase { return "test_consumed_body"; } + @Override + public List routes() { + return Collections.emptyList(); + } }; try (XContentBuilder builder = JsonXContent.contentBuilder().startObject().endObject()) { @@ -274,6 +309,10 @@ public class BaseRestHandlerTests extends ESTestCase { return "test_unconsumed_body"; } + @Override + public List routes() { + return Collections.emptyList(); + } }; final RestRequest request = new FakeRestRequest.Builder(xContentRegistry()).build(); @@ -295,6 +334,10 @@ public class BaseRestHandlerTests extends ESTestCase { return "test_unconsumed_body"; } + @Override + public List routes() { + 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 702d0db964f0..2973765beee3 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 class RestControllerTests extends ESTestCase { 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 c68649792234..538c57b035e0 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 93203b774ec3..aa4fe725e0e0 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 3956178587dd..8c3c9ae03cb2 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.XContentFactory; 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 java.io.IOException; 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 class RestAnalyzeActionTests extends ESTestCase { } 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 bdd3892e3813..6c6e2c3d4b1f 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 bd7fb60b3d56..4813e11e15bf 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 @@ public class RestValidateQueryActionTests extends AbstractSearchTestCase { 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 22beda1cc6ee..258844f36b71 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 class RestCatRecoveryActionTests extends ESTestCase { 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 776129eb1d56..aad58e50d69c 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 class RestIndicesActionTests extends ESTestCase { } 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 38c483746836..3903a4d6b43f 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.ClusterState; 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 b19c8c6412ab..fabd9e36051f 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.client.node.NodeClient; 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 class RestBulkActionTests extends ESTestCase { 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 924ead60c331..38a3fdf1af61 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 6fe27322fcd8..84bc5f3bef34 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.cluster.service.ClusterService; 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 @@ import static org.mockito.Mockito.when; 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 b5104bb4cfc0..92776d6ccc08 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 8642b2648146..03e9a242d35c 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.action.search.ClearScrollRequest; 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 @@ import static org.mockito.Mockito.verify; 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 class RestClearScrollActionTests extends ESTestCase { 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 b90b01d4b7b0..6c58d32b8b8b 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.action.search.SearchScrollRequest; 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 @@ import static org.mockito.Mockito.verify; 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 class RestSearchScrollActionTests extends ESTestCase { 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 ab5aebe853b9..f574deee87fc 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.node.Node; 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.lessThan; 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 class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest ).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 class DedicatedClusterSnapshotRestoreIT extends AbstractSnapshotIntegTest 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 5a38ca8ca4eb..cfba6390bfb0 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.ESTestCase; 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 class UsageServiceTests extends ESTestCase { return name; } + @Override + public List routes() { + return Collections.emptyList(); + } + @Override protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) { return channel -> { diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java index 92d5ef0afcea..4f1f64f89e46 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/Autoscaling.java @@ -96,7 +96,7 @@ public class Autoscaling extends Plugin implements ActionPlugin { final Supplier nodesInCluster ) { if (enabled) { - return List.of(new RestGetAutoscalingDecisionHandler(controller)); + return List.of(new RestGetAutoscalingDecisionHandler()); } else { return List.of(); } diff --git a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java index e8f9674ae6d5..aeef9884295d 100644 --- a/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java +++ b/x-pack/plugin/autoscaling/src/main/java/org/elasticsearch/xpack/autoscaling/rest/RestGetAutoscalingDecisionHandler.java @@ -8,15 +8,19 @@ package org.elasticsearch.xpack.autoscaling.rest; 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.autoscaling.action.GetAutoscalingDecisionAction; +import java.util.List; + +import static org.elasticsearch.rest.RestRequest.Method.GET; + public class RestGetAutoscalingDecisionHandler extends BaseRestHandler { - public RestGetAutoscalingDecisionHandler(final RestController controller) { - controller.registerHandler(RestRequest.Method.GET, "/_autoscaling/decision", this); + @Override + public List routes() { + return List.of(new Route(GET, "/_autoscaling/decision")); } @Override 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 0fd087a47c44..67907181699f 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 class Ccr extends Plugin implements ActionPlugin, PersistentTaskPlugin, E 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 08353212c2bf..e320595690a2 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(GET, "/_ccr/stats")); } @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 ae63d2004a61..853b8f7d6da1 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(DELETE, "/_ccr/auto_follow/{name}")); } @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 86aba9d31a33..e9763a43a7b0 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(GET, "/{index}/_ccr/info")); } @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 31c2f5daac8e..2eed47b0a7ab 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(GET, "/{index}/_ccr/stats")); } @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 de749cde8218..bb8246a7a780 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(POST, "/{index}/_ccr/forget_follower")); } @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 0a7393dc8fcb..7a7454c02fe1 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_ccr/auto_follow/{name}"), + new Route(GET, "/_ccr/auto_follow"))); } @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 abfca00da5cb..04d6747a78aa 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(POST, "/_ccr/auto_follow/{name}/pause")); } @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 ef80fe1d3652..2bfec8f87e28 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(POST, "/{index}/_ccr/pause_follow")); } @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 076c3cfb18ee..5593aa7ac615 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(PUT, "/_ccr/auto_follow/{name}")); } @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 8ad2002a0c4b..9ee161555bdc 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.action.support.ActiveShardCount; 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 routes() { + return singletonList(new Route(PUT, "/{index}/_ccr/follow")); } @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 89f3f65fca7d..e20c038dff1e 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(POST, "/_ccr/auto_follow/{name}/resume")); } @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 29dcd029e990..146700888cfc 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(POST, "/{index}/_ccr/resume_follow")); } @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 99a7ddac0da7..0effd10b7f19 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 @@ package org.elasticsearch.xpack.ccr.rest; 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 routes() { + return singletonList(new Route(POST, "/{index}/_ccr/unfollow")); } @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 3ff79251cafe..3ac7cfff9490 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 class Licensing implements ActionPlugin { 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 383c31c332e3..0addc72d201d 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 @@ package org.elasticsearch.license; 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 routes() { + return singletonList(new Route(DELETE, "/_license")); } @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 70dbe93bfb0f..baf17b2cd75a 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 @@ package org.elasticsearch.license; 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 routes() { + return singletonList(new Route(GET, "/_license/basic_status")); } @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 99ef7e4ec2c8..33b013954be9 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.common.xcontent.XContentBuilder; 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 routes() { + return singletonList(new Route(GET, "/_license")); } @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 cac4a7d3d6d5..ea90b85f15e6 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 @@ package org.elasticsearch.license; 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 routes() { + return singletonList(new Route(GET, "/_license/trial_status")); } @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 6d3a82cfeadc..2346e143cc7e 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 @@ package org.elasticsearch.license; 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 routes() { + return singletonList(new Route(POST, "/_license/start_basic")); } @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 0e79d306f1dd..b9ecb91c9eb2 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.client.node.NodeClient; 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 routes() { + return singletonList(new Route(POST, "/_license/start_trial")); } @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 bac9946d0579..4634a56c66f9 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 @@ package org.elasticsearch.license; 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 routes() { // TODO: remove POST endpoint? - controller.registerHandler(POST, "/_license", this); - controller.registerHandler(PUT, "/_license", this); + return unmodifiableList(asList( + new Route(POST, "/_license"), + new Route(PUT, "/_license"))); } @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 9a2d5fd65eb6..7f85b8fe6c36 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 class XPackPlugin extends XPackClientPlugin implements ExtensiblePlugin, 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 e3641f079f32..8d118960ed1f 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.action.support.IndicesOptions; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_reload_search_analyzers"), + new Route(POST, "/{index}/_reload_search_analyzers"))); } @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 2da02fc111aa..6d83cd97e0df 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 @@ package org.elasticsearch.xpack.core.rest.action; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_xpack"), + new Route(HEAD, "/_xpack"))); } @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 56eaae48460d..86bfd8f5241f 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.unit.TimeValue; 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.XPackUsageRequestBuilder; 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 routes() { + return singletonList(new Route(GET, "/_xpack/usage")); } @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 d00bba383e90..3f6348b0b6ac 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.client.node.NodeClient; 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.rest.action.RestBuilderListener; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ public class RestGetCertificateInfoAction extends BaseRestHandler { - public RestGetCertificateInfoAction(RestController controller) { - controller.registerHandler(GET, "/_ssl/certificates", this); + @Override + public List routes() { + return singletonList(new Route(GET, "/_ssl/certificates")); } @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 c473e74db0eb..6d17f634c9a7 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 class Deprecation extends Plugin implements ActionPlugin { 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 065a40b46e8a..1070d90d233e 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_migration/deprecations"), + new Route(GET, "/{index}/_migration/deprecations"))); } @Override @@ -33,7 +36,7 @@ public class RestDeprecationInfoAction extends BaseRestHandler { @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 54dd0b219a7b..20281a3933bf 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 class EnrichPlugin extends Plugin implements SystemIndexPlugin, IngestPlu } 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 01c23d91fed2..c8ff6fa5337d 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 @@ package org.elasticsearch.xpack.enrich.rest; 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 routes() { + return singletonList(new Route(DELETE, "/_enrich/policy/{name}")); } @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 586e1c255dd7..4b74bcd3a64c 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 @@ package org.elasticsearch.xpack.enrich.rest; 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 routes() { + return singletonList(new Route(GET, "/_enrich/_stats")); } @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 087117a6c1a4..c6515876a761 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 @@ package org.elasticsearch.xpack.enrich.rest; 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 routes() { + return unmodifiableList( + asList(new Route(POST, "/_enrich/policy/{name}/_execute"), new Route(PUT, "/_enrich/policy/{name}/_execute")) + ); } @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 3a279a49fa49..06e516592f7f 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 @@ package org.elasticsearch.xpack.enrich.rest; 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 routes() { + return unmodifiableList(asList(new Route(GET, "/_enrich/policy/{name}"), new Route(GET, "/_enrich/policy"))); } @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 38d36447d8ee..8750891d34db 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 @@ package org.elasticsearch.xpack.enrich.rest; 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 routes() { + return singletonList(new Route(PUT, "/_enrich/policy/{name}")); } @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 cc651e701418..4ea4624a56c7 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 @@ -111,6 +111,6 @@ public class EqlPlugin extends Plugin implements ActionPlugin { if (isEnabled(settings) == false) { return Collections.emptyList(); } - return Arrays.asList(new RestEqlSearchAction(restController), new RestEqlStatsAction(restController)); + return Arrays.asList(new RestEqlSearchAction(), new RestEqlStatsAction()); } -} \ 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 8a46ba44185d..c81b1b031946 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.common.Strings; -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.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.RestRequest; +import org.elasticsearch.rest.RestResponse; +import org.elasticsearch.rest.RestStatus; 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 routes() { + return unmodifiableList(asList( + new Route(GET, SEARCH_PATH), + new Route(POST, SEARCH_PATH))); } @Override diff --git a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlStatsAction.java b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlStatsAction.java index c147f95b9fee..cea859c35999 100644 --- a/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlStatsAction.java +++ b/x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlStatsAction.java @@ -8,16 +8,23 @@ package org.elasticsearch.xpack.eql.plugin; 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 java.util.Collections; +import java.util.List; + import static org.elasticsearch.rest.RestRequest.Method.GET; public class RestEqlStatsAction extends BaseRestHandler { - protected RestEqlStatsAction(RestController controller) { - controller.registerHandler(GET, "/_eql/stats", this); + protected RestEqlStatsAction() { + + } + + @Override + public List routes() { + return Collections.singletonList(new Route(GET, "/_eql/stats")); } @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 89b5fa7adccb..018f684c6389 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 class FrozenIndices extends Plugin implements ActionPlugin, EnginePlugin 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 4bc113449c34..96cde5f4e3a2 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/{index}/_freeze"), + new Route(POST, "/{index}/_unfreeze"))); } @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 b918f6e5dde8..e8c6223e504a 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 class Graph extends Plugin implements ActionPlugin { 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 cf0dbfeb0d64..e84b2441d6bb 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.GraphExploreRequest.TermBoost; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/{index}/_graph/explore"), + new Route(POST, "/{index}/_graph/explore"))); } @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 96e9a49bc925..951571b99240 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 class IndexLifecycle extends Plugin implements ActionPlugin { 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 999eaafdb03b..e2155b0b1698 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return singletonList(new Route(DELETE, "/_ilm/policy/{name}")); } @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 d8fb12775520..68b843794274 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.action.support.IndicesOptions; 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 routes() { + return singletonList(new Route(GET, "/{index}/_ilm/explain")); } @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 794de5d57634..df4af5ff5895 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_ilm/policy"), + new Route(GET, "/_ilm/policy/{name}"))); } @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 5ff3c046321e..1eb822ba765c 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return singletonList(new Route(GET, "/_ilm/status")); } @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 44a765b0c6aa..0f072787d3f5 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return singletonList(new Route(POST, "/_ilm/move/{name}")); } @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 5e357c9535ef..9f2f199ca602 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return singletonList(new Route(PUT, "/_ilm/policy/{name}")); } @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 7bca784878b4..b10b2e4e282f 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.action.support.IndicesOptions; 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 routes() { + return singletonList(new Route(POST, "/{index}/_ilm/remove")); } @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 e14e1dac049b..765ba44d1ffd 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.action.support.IndicesOptions; 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 routes() { + return singletonList(new Route(POST, "/{index}/_ilm/retry")); } @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 b240a5e274e0..f60ae2297d7f 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return singletonList(new Route(POST, "/_ilm/start")); } @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 3843d4da773a..8b748ee677ff 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 @@ package org.elasticsearch.xpack.ilm.action; 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 routes() { + return singletonList(new Route(POST, "/_ilm/stop")); } @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 658816d2bab8..fad46639bcc0 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(DELETE, "/_slm/policy/{name}")); } @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 72eceee0f8ec..093c52ffbe3c 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_slm/policy/{name}/_execute"), + new Route(PUT, "/_slm/policy/{name}/_execute"))); } @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 8bf2e3e870e1..326ee5294e52 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(POST, "/_slm/_execute_retention")); } @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 26f3197a7612..f728fb314ddc 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(GET, "/_slm/status")); } @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 cd2e67bb732a..6b7841802599 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_slm/policy"), + new Route(GET, "/_slm/policy/{name}"))); } @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 b8629c2db576..688c271a1654 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(GET, "/_slm/stats")); } @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 a5183739f3f5..c4416c2eb6d6 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(PUT, "/_slm/policy/{name}")); } @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 87dc7d2bb227..da71efbe504b 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(POST, "/_slm/start")); } @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 ac74b37d5875..1a0af84c31f7 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 @@ package org.elasticsearch.xpack.slm.action; 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 routes() { + return singletonList(new Route(POST, "/_slm/stop")); } @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 5469da943f27..d82fd9b8384b 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 class MachineLearning extends Plugin implements SystemIndexPlugin, Analys 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 d3f024e27e85..11ca99d9d3a5 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.apache.logging.log4j.LogManager; 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 routes() { + 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 b0e564095ec4..94e7ffc15c66 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.client.node.NodeClient; 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 org.elasticsearch.xpack.ml.filestructurefinder.FileStructureFinderManager 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 routes() { + 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 1d775d156ede..c29b3ad68501 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.apache.logging.log4j.LogManager; 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 routes() { + 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 1d8d28a4d448..31bc22e99c40 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.apache.logging.log4j.LogManager; 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 routes() { + 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 95ec620e0177..58f5fff7b44a 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.apache.logging.log4j.LogManager; 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.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.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 routes() { + 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 da30978461d9..9fbc3b3ba50f 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.apache.logging.log4j.LogManager; 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.core.ml.calendars.ScheduledEvent; 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 routes() { + 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 213d3f712f96..61fbda4f3f2a 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.apache.logging.log4j.LogManager; 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.core.ml.job.config.Job; 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 routes() { + 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 c299d23ac58f..c3baeebfbee9 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 46e4d23cd684..eb2e74b309b1 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.Strings; 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.core.ml.calendars.Calendar; 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 routes() { + 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 5ad91ffd92fc..dfab91e85cb8 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.client.node.NodeClient; 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.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.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 routes() { + 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 553bb81cbf90..caba1a115cf7 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.client.node.NodeClient; 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 routes() { + 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 ce47bc3a53a1..4c8709742aa5 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.apache.logging.log4j.LogManager; 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.core.ml.job.config.Job; 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 routes() { + 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 2af29f9b30f8..6617c8046fa3 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.cluster.node.DiscoveryNode; 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.action.GetDatafeedsStatsAction; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "_cat/ml/datafeeds/{" + DatafeedConfig.ID.getPreferredName() + "}"), + new Route(GET, "_cat/ml/datafeeds"))); } @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 feda7a9479d0..55bd15aaf80b 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.Strings; 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.ModelSizeSta 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 routes() { + return unmodifiableList(asList( + new Route(GET, "_cat/ml/anomaly_detectors/{" + Job.ID.getPreferredName() + "}"), + new Route(GET, "_cat/ml/anomaly_detectors"))); } @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 0617ba8ab3ef..d827f4830a7b 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.Strings; 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.Set; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "_cat/ml/trained_models"), + new Route(GET, "_cat/ml/trained_models/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}"))); } @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 000b92426d88..e692688e30c9 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.apache.logging.log4j.LogManager; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 65866074dfad..3a617808d4fd 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.client.node.NodeClient; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 1ed7ce33ef88..19a4de3dd140 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.apache.logging.log4j.LogManager; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 6088f42f2d30..85b28bbc1438 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.apache.logging.log4j.LogManager; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 12e8863f6812..bff6f803ffbd 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.client.node.NodeClient; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 3dbe4ceb1005..2e61d71b29ca 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.XContentBuilder; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 f1cc37e61a88..efbc6d01a895 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.XContentBuilder; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 b36eb5e0078f..6c4e03f39f96 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.client.node.NodeClient; 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.core.ml.datafeed.DatafeedConfig; 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 routes() { + 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 9e78a7cd9f21..3b898e870ad4 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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.core.ml.dataframe.DataFrameAnalyticsConfig; 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 routes() { + return singletonList( + new Route(DELETE, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}")); } @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 b991fec70e58..73d2506f3713 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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 routes() { + return singletonList(new Route(POST, MachineLearning.BASE_PATH + "data_frame/_evaluate")); } @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 b16bf7b3efbf..1d5f99aaf10c 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.action.ActionListener; 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.io.IOException; 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 routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics/_explain"), + new Route(POST, MachineLearning.BASE_PATH + "data_frame/analytics/_explain"), + new Route( + GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain"), + new Route(POST, + MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_explain"))); } @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 3c959056b2a5..639adbc375a3 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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.core.ml.dataframe.DataFrameAnalyticsConfig; 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 routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics"), + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}"))); } @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 44d43153e75b..793f41796cc5 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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.core.ml.dataframe.DataFrameAnalyticsConfig; 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 routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "data_frame/analytics/_stats"), + new Route( + GET, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stats"))); } @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 11a25e76a6c1..c8983271153e 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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.core.ml.dataframe.DataFrameAnalyticsConfig; 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 routes() { + return singletonList( + new Route(PUT, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}")); } @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 df98e7bc402f..9bc6ad6b4ea0 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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.core.ml.dataframe.DataFrameAnalyticsConfig; 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 routes() { + return singletonList( + new Route( + POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_start")); } @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 aadc11a659d5..2787aad91579 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 @@ package org.elasticsearch.xpack.ml.rest.dataframe; 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.core.ml.dataframe.DataFrameAnalyticsConfig; 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 routes() { + return singletonList( + new Route( + POST, MachineLearning.BASE_PATH + "data_frame/analytics/{" + DataFrameAnalyticsConfig.ID.getPreferredName() + "}/_stop")); } @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 cee574586614..bb94ffcda4fa 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.apache.logging.log4j.LogManager; 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.core.ml.action.DeleteFilterAction.Request; 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 routes() { + 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 558da54b7f37..421af0bdee60 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.client.node.NodeClient; 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.core.ml.job.config.MlFilter; 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 routes() { + 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 b902c0998538..85a01ac0edf0 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.client.node.NodeClient; 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.core.ml.job.config.MlFilter; 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 routes() { + 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 b9c544f30c21..6bf83acdc5e8 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.client.node.NodeClient; 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.core.ml.job.config.MlFilter; 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 routes() { + 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 e9675be4d29f..e0e2b3f3d20a 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 @@ package org.elasticsearch.xpack.ml.rest.inference; 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.core.ml.inference.TrainedModelConfig; 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 routes() { + return singletonList( + new Route(DELETE, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}")); } @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 4d818f974f74..8c783dbb609f 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.client.node.NodeClient; 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.core.ml.inference.TrainedModelConfig; 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 routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}"), + new Route(GET, MachineLearning.BASE_PATH + "inference"))); } @Override @@ -49,7 +50,7 @@ public class RestGetTrainedModelsAction extends BaseRestHandler { 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 100c8cfa2f92..a035a67022bc 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.client.node.NodeClient; 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.core.ml.inference.TrainedModelConfig; 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 routes() { + return unmodifiableList(asList( + new Route(GET, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}/_stats"), + new Route(GET, MachineLearning.BASE_PATH + MachineLearning.BASE_PATH + "inference/_stats"))); } @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 cb3f4e0eddee..54f0f8476bdf 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 @@ package org.elasticsearch.xpack.ml.rest.inference; 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.core.ml.inference.TrainedModelConfig; 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 routes() { + return singletonList( + new Route(PUT, MachineLearning.BASE_PATH + "inference/{" + TrainedModelConfig.MODEL_ID.getPreferredName() + "}")); } @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 9e8a2eaf7a35..0b8ed5a9e379 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 61b15f7794cd..093b062dda12 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.client.node.NodeClient; 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.core.ml.job.results.Forecast; 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 routes() { + return singletonList( + new Route(DELETE, MachineLearning.BASE_PATH + "anomaly_detectors/{" + Job.ID.getPreferredName() + "}/_forecast/")); + } + + @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 9f8aed81b6b1..03515a40a7cc 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.logging.DeprecationLogger; 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.core.ml.job.config.Job; 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 routes() { + 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 a1e6d09285a1..17c3ef60144e 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 12c508daceec..5d0aee2f4db3 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 16b540d04fdd..caf3402db061 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.cluster.metadata.MetaData; 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.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; @@ -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 routes() { + 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 5c9bc4840022..b980646a0454 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.cluster.metadata.MetaData; 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.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; @@ -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 routes() { + 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 4e6b02049be5..21b30539ade3 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.unit.TimeValue; 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.core.ml.job.config.Job; 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 routes() { + 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 b3e57ca5855a..26d79114fa4b 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.apache.logging.log4j.LogManager; 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.core.ml.job.config.Job; 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 routes() { + 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 a237a8b18745..a3e69048f72c 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 fe0e29cde490..20667e299e49 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 7ea082f9fd12..75fb5b474b51 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.apache.logging.log4j.LogManager; 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 routes() { + 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 2b2ef21442fa..24b9e32492a4 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.client.node.NodeClient; 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.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; @@ -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 routes() { + 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 33b31af99526..2fe0c0eecd01 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.client.node.NodeClient; 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.core.ml.job.config.Job; 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 routes() { + 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 e1cd0b2d2f5f..1a3b43a03b34 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.client.node.NodeClient; 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.core.ml.job.process.autodetect.state.ModelSnapsho 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 routes() { + 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 8bb423199fe5..ecf94c1fe222 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.Strings; 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.core.ml.job.results.Result; 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 routes() { + 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 e2e069efd76f..55a4fbffd73b 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.client.node.NodeClient; 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.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; @@ -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 routes() { + 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 a1ac9671b3be..639ba3f17f3e 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.client.node.NodeClient; 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.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,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 routes() { + 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 0b7763a8bf61..541fac368e17 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.client.node.NodeClient; 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.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 RestGetOverallBucketsAction extends BaseRestHandler { private static final DeprecationLogger deprecationLogger = new DeprecationLogger(LogManager.getLogger(RestGetOverallBucketsAction.class)); - public RestGetOverallBucketsAction(RestController controller) { + @Override + public List routes() { + 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 0ce2b5e70991..738da300e7d1 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.client.node.NodeClient; 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 routes() { + 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 3cf5f89f9199..07dda46e4ca4 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.client.node.NodeClient; 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 routes() { + 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 9f16162d1726..aa96b3c591f6 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.client.node.NodeClient; 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 routes() { + 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 e36b8a6aaa33..533da79aeb6f 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 @@ package org.elasticsearch.xpack.ml.rest.datafeeds; 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 @@ import static org.mockito.Mockito.mock; 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 c0981d17f177..309b8b25cdd3 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 class Monitoring extends Plugin implements ActionPlugin, ReloadablePlugin 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 f72871fb055c..1382e27c8ef1 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.common.xcontent.XContentBuilder; 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.action.MonitoringBulkResponse; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_monitoring/bulk"), + new Route(PUT, "/_monitoring/bulk"))); } @Override @@ -108,7 +109,7 @@ public class RestMonitoringBulkAction extends BaseRestHandler { * @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 4f83898e48a6..8abbaad59748 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.XContentBuilder; 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 @@ import static org.mockito.Mockito.when; 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 f5ed5b86e7fc..4ffe0ea3e417 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 class Rollup extends Plugin implements ActionPlugin, PersistentTaskPlugin } 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 83e1b53cb1a4..e8a1d2928d72 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return singletonList(new Route(DELETE, "/_rollup/job/{id}")); } @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 2c30efb5d833..c31a433b93ab 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return singletonList(new Route(GET, "/_rollup/data/{id}")); } @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 a4675bfa7f2e..ed136df98b65 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.client.node.NodeClient; 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 routes() { + return singletonList(new Route(GET, "/{index}/_rollup/data")); } @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 cefa90266ea6..b6d18eb83d66 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return singletonList(new Route(GET, "/_rollup/job/{id}")); } @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 4f1f2a1a4d5d..f945055efd82 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return singletonList(new Route(PUT, "/_rollup/job/{id}")); } @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 6a6aefd9c296..bc6e27501adc 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "_rollup_search"), + new Route(POST, "_rollup_search"), + new Route(GET, "{index}/_rollup_search"), + new Route(POST, "{index}/_rollup_search"))); } @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 8f11802addad..5704e8417aea 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return singletonList(new Route(POST, "/_rollup/job/{id}/_start")); } @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 0d41893f9d6d..b82865d5e724 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 @@ package org.elasticsearch.xpack.rollup.rest; 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 routes() { + return singletonList(new Route(POST, "/_rollup/job/{id}/_stop")); } @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 0d2b06b1d425..94ff13e8d3ff 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 @@ -766,40 +766,40 @@ public class Security extends Plugin implements SystemIndexPlugin, IngestPlugin, 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 4131d1e73588..62cf944819a2 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.authc.AuthenticationService; 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 class SecurityRestFilter implements RestHandler { return restHandler.allowsUnsafeBuffers(); } + @Override + public List routes() { + return restHandler.routes(); + } + + @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 09f0679378c5..33dcc311c488 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.ToXContent; 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.action.user.AuthenticateResponse; 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 routes() { + 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 c63d965a3b7c..4dea0899f83f 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.LogManager; 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 routes() { + return singletonList(new Route(POST, "/_security/delegate_pki")); } @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 b75de301e7e4..af90797184db 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.action.support.WriteRequest; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_security/api_key"), + new Route(PUT, "/_security/api_key"))); } @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 ca0795247844..74bf64ba4daf 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.settings.Settings; 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.GetApiKeyRequest; 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 routes() { + return singletonList(new Route(GET, "/_security/api_key")); } @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 057993288767..86064b953d00 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.XContentBuilder; 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.InvalidateApiKeyRequest; 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 routes() { + return singletonList(new Route(DELETE, "/_security/api_key")); } @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 c3734f37d1a5..d2efb784a76e 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 @@ package org.elasticsearch.xpack.security.rest.action.oauth2; 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.common.xcontent.XContentParser; 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 org.elasticsearch.xpack.security.authc.kerberos.KerberosAuthenticationTok 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 routes() { + 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 cb72e53bcc8d..26caf487950d 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.XContentBuilder; 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.InvalidateTokenRequest 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 routes() { + 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 d820fb7a88b4..a297b2f7cd6b 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.XContentBuilder; 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.OpenIdConnectAuthentica 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 routes() { + return singletonList(new Route(POST, "/_security/oidc/authenticate")); } @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 e098e14c423b..f9485f91beba 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.XContentBuilder; 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.OpenIdConnectLogoutRequ 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 routes() { + return singletonList(new Route(POST, "/_security/oidc/logout")); } @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 c86da0ed4edc..d38febbbc33e 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.XContentBuilder; 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.OpenIdConnectPrepareAut 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 routes() { + return singletonList(new Route(POST, "/_security/oidc/prepare")); } @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 41758aa26016..bcf9b9c09ae5 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.settings.Settings; 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.io.IOException; 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 routes() { + 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 15f4612d9042..a57b226c3156 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.settings.Settings; 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.core.security.action.privilege.GetBuiltinPrivileg 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 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; */ 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 routes() { + return singletonList(new Route(GET, "/_security/privilege/_builtin")); } @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 7a5261c42bc9..d667832c38b7 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.util.set.Sets; 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 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.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 routes() { + 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 082751affb8b..46c0ce4c744b 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.settings.Settings; 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.core.security.authz.privilege.ApplicationPrivileg 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 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; 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 routes() { + 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 e1590c39fe90..579a98973daa 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.client.node.NodeClient; 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 routes() { + 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 0fd15051e823..caaf5286b597 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.client.node.NodeClient; 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 routes() { + 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 957cac123486..0c7899309aa6 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.settings.Settings; 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.core.security.action.role.DeleteRoleResponse; 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 routes() { + 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 a5141f25f37a..3f34b3f60931 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.settings.Settings; 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.core.security.authz.RoleDescriptor; 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 routes() { + 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 e8b2e6a77838..dd9e86602992 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.settings.Settings; 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.core.security.action.role.PutRoleResponse; 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 routes() { + 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 a2383534115c..97c134791c8a 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.settings.Settings; 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.core.security.action.rolemapping.DeleteRoleMappin 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 routes() { + 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 aeac89e8ffb9..6ea486de1d76 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.settings.Settings; 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.core.security.authc.support.mapper.ExpressionRole 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 routes() { + 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 532a12644a7b..e7ce839a2c36 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.settings.Settings; 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.core.security.action.rolemapping.PutRoleMappingRe 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 routes() { + 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 486e749ca6a2..6986e8446476 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.XContentBuilder; 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 org.elasticsearch.xpack.core.security.action.saml.SamlAuthenticateRespons 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; /** * 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 @@ public class RestSamlAuthenticateAction extends SamlBaseRestHandler implements R 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 routes() { + 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 4fe8e7ac5b25..0d5c0e3a027d 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.XContentBuilder; 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.SamlInvalidateSessionAc 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 routes() { + 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 3a584664073b..0e947c9eb038 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.XContentBuilder; 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.SamlLogoutAction; 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 routes() { + 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 b227f2c767f6..13d2f771ce61 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.XContentBuilder; 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.SamlPrepareAuthenticati 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 routes() { + 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 4f1d3c237755..fb185dc963db 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.settings.Settings; 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.core.security.user.User; 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 routes() { + 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 bc0eb728c6bf..1b18f2f08591 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.settings.Settings; 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.core.security.action.user.DeleteUserResponse; 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 routes() { + 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 02bfc7ff96c1..3c8db810f45a 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.common.xcontent.XContentBuilder; 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 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.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 routes() { + 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 eef11d478ca6..3dbe2823416b 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.settings.Settings; 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.core.security.user.User; 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 routes() { + 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 3c589e7220aa..ed4cfa3a00d1 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.XContentBuilder; 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.core.security.user.User; 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 routes() { + 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 39cd5f35fa54..6fa47e73feb0 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.util.set.Sets; 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.core.security.rest.RestRequestFilter; 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 routes() { + 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 b13f0b328d99..5eadd3b8ec9c 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.settings.Settings; 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.core.security.action.user.SetEnabledResponse; 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 routes() { + 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 class RestSetEnabledAction extends SecurityBaseRestHandler { @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 4b40d165b5e4..000061600241 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.FakeRestChannel; 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 class SecurityBaseRestHandlerTests extends ESTestCase { return "test_xpack_security_base_action"; } + @Override + public List routes() { + 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 3f9b743c8e78..e51a4bfe09eb 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 @@ package org.elasticsearch.xpack.security.rest.action.apikey; 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.env.Environment; 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 @@ import static org.mockito.Mockito.when; 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 @@ public class RestCreateApiKeyActionTests extends ESTestCase { } } }) { - final RestCreateApiKeyAction restCreateApiKeyAction = new RestCreateApiKeyAction(Settings.EMPTY, mockRestController, - mockLicenseState); + final RestCreateApiKeyAction restCreateApiKeyAction = new RestCreateApiKeyAction(Settings.EMPTY, mockLicenseState); restCreateApiKeyAction.handleRequest(restRequest, restChannel, client); final RestResponse restResponse = responseSetOnce.get(); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java index d1046a175670..14d6555194c7 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestGetApiKeyActionTests.java @@ -22,7 +22,6 @@ import org.elasticsearch.env.Environment; 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.RestStatus; import org.elasticsearch.test.ESTestCase; @@ -46,7 +45,6 @@ import static org.mockito.Mockito.when; public class RestGetApiKeyActionTests extends ESTestCase { private final XPackLicenseState mockLicenseState = mock(XPackLicenseState.class); - private final RestController mockRestController = mock(RestController.class); private Settings settings = null; private ThreadPool threadPool = null; @@ -114,7 +112,7 @@ public class RestGetApiKeyActionTests extends ESTestCase { } } }) { - final RestGetApiKeyAction restGetApiKeyAction = new RestGetApiKeyAction(Settings.EMPTY, mockRestController, mockLicenseState); + final RestGetApiKeyAction restGetApiKeyAction = new RestGetApiKeyAction(Settings.EMPTY, mockLicenseState); restGetApiKeyAction.handleRequest(restRequest, restChannel, client); @@ -182,7 +180,7 @@ public class RestGetApiKeyActionTests extends ESTestCase { } } }) { - final RestGetApiKeyAction restGetApiKeyAction = new RestGetApiKeyAction(Settings.EMPTY, mockRestController, mockLicenseState); + final RestGetApiKeyAction restGetApiKeyAction = new RestGetApiKeyAction(Settings.EMPTY, mockLicenseState); restGetApiKeyAction.handleRequest(restRequest, restChannel, client); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java index 51f700ba4400..48ef745a5c4a 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/apikey/RestInvalidateApiKeyActionTests.java @@ -22,7 +22,6 @@ import org.elasticsearch.env.Environment; 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.RestStatus; import org.elasticsearch.test.ESTestCase; @@ -42,7 +41,6 @@ import static org.mockito.Mockito.when; public class RestInvalidateApiKeyActionTests extends ESTestCase { private final XPackLicenseState mockLicenseState = mock(XPackLicenseState.class); - private final RestController mockRestController = mock(RestController.class); private Settings settings = null; private ThreadPool threadPool = null; @@ -106,8 +104,7 @@ public class RestInvalidateApiKeyActionTests extends ESTestCase { } } }) { - final RestInvalidateApiKeyAction restInvalidateApiKeyAction = new RestInvalidateApiKeyAction(Settings.EMPTY, mockRestController, - mockLicenseState); + final RestInvalidateApiKeyAction restInvalidateApiKeyAction = new RestInvalidateApiKeyAction(Settings.EMPTY, mockLicenseState); restInvalidateApiKeyAction.handleRequest(restRequest, restChannel, client); @@ -168,8 +165,7 @@ public class RestInvalidateApiKeyActionTests extends ESTestCase { } } }) { - final RestInvalidateApiKeyAction restInvalidateApiKeyAction = new RestInvalidateApiKeyAction(Settings.EMPTY, mockRestController, - mockLicenseState); + final RestInvalidateApiKeyAction restInvalidateApiKeyAction = new RestInvalidateApiKeyAction(Settings.EMPTY, mockLicenseState); restInvalidateApiKeyAction.handleRequest(restRequest, restChannel, client); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/saml/SamlBaseRestHandlerTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/saml/SamlBaseRestHandlerTests.java index 2e4d5dcd401f..b7ab884ce42b 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/saml/SamlBaseRestHandlerTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/rest/action/saml/SamlBaseRestHandlerTests.java @@ -17,6 +17,9 @@ import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.xpack.core.XPackSettings; import org.hamcrest.Matchers; +import java.util.Collections; +import java.util.List; + import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.instanceOf; @@ -51,6 +54,11 @@ public class SamlBaseRestHandlerTests extends ESTestCase { return "saml_test"; } + @Override + public List routes() { + 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 16c9218058f1..fd2418c09f7d 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.settings.Settings; 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 d0173479f37d..50561f427b9b 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.XContentType; 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 class RestHasPrivilegesActionTests extends ESTestCase { 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 88713eb4a8fa..b9d8c94c76ab 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 @@ package org.elasticsearch.xpack.sql.plugin; 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.action.SqlClearCursorRequest; 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 routes() { + return singletonList(new Route(POST, Protocol.CLEAR_CURSOR_REST_ENDPOINT)); } @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 f275475530ad..c5af7b3a86c0 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.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; @@ -25,15 +24,20 @@ import org.elasticsearch.xpack.sql.proto.Protocol; 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 routes() { + return unmodifiableList(asList( + new Route(GET, Protocol.SQL_QUERY_REST_ENDPOINT), + new Route(POST, Protocol.SQL_QUERY_REST_ENDPOINT))); } @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 8bb6c3328b38..01c3ec8be9e0 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 @@ package org.elasticsearch.xpack.sql.plugin; 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 routes() { + return singletonList(new Route(GET, Protocol.SQL_STATS_REST_ENDPOINT)); } @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 b445789422e6..d059055feb22 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 @@ package org.elasticsearch.xpack.sql.plugin; 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.action.SqlTranslateRequest; 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 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; */ 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 routes() { + return unmodifiableList(asList( + new Route(GET, Protocol.SQL_TRANSLATE_REST_ENDPOINT), + new Route(POST, Protocol.SQL_TRANSLATE_REST_ENDPOINT))); } @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 dbe14f99f336..db9c0246210c 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 class SqlPlugin extends Plugin implements ActionPlugin { 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 99a46a02d41d..8c71f0b9c6e6 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 class Transform extends Plugin implements SystemIndexPlugin, PersistentTa } 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 d6dbe7e468a3..da60f8e040ee 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return singletonList(new Route(DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID)); } @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 23484f0e9408..58670d10dce2 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return unmodifiableList(asList( + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS), + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID))); } @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 662f9840d026..fa4d2364437f 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return unmodifiableList(asList( + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS + "_stats"), + new Route(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stats"))); } @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 114c88b761c6..f5c0fe1808c2 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS + "_preview")); } @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 b61d81fb6e13..06bb43ee3cd8 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return singletonList(new Route(PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID)); } @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 ac6bb368cffa..bf791c217910 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_start")); } @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 85d138bfc37f..4ed3f03648cc 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_stop")); } @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 563c97864130..08ac7566ff46 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 @@ package org.elasticsearch.xpack.transform.rest.action; 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 routes() { + return singletonList(new Route(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID + "_update")); } @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 94d4b5c65433..7340c6581165 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.apache.logging.log4j.LogManager; 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.TransformMessages; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(DELETE, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + 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 ca92942a52dd..0f47320688df 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.apache.logging.log4j.LogManager; 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.TransformMessages; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED, + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger), + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + 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 b444ea3beef1..9b34769ca0e6 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.apache.logging.log4j.LogManager; 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.TransformMessages; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return unmodifiableList(asList( + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_stats", + TransformMessages.REST_DEPRECATED_ENDPOINT, deprecationLogger), + new DeprecatedRoute(GET, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stats", + 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 8c0a994ebbef..97f66c29c272 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.client.node.NodeClient; 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.PreviewTransformAction; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_DEPRECATED + "_preview", + 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 aeac2c91be2f..9ceb7da78a70 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.client.node.NodeClient; 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.PutTransformAction; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(PUT, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED, + 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 796c9833222a..322b5f3eb450 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.action.support.master.AcknowledgedRequest; 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.TransformMessages; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_start", + 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 2a43df2a7f94..b308fc98015f 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.client.node.NodeClient; 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.TransformMessages; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_stop", + 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 5be2586f955e..ff9752f7767d 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.client.node.NodeClient; 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.UpdateTransformAction; 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 routes() { + return Collections.emptyList(); + } + + @Override + public List deprecatedRoutes() { + return singletonList(new DeprecatedRoute(POST, TransformField.REST_BASE_PATH_TRANSFORMS_BY_ID_DEPRECATED + "_update", + 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 36891461c270..7672cf71f65d 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.NamedXContentRegistry; 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 @@ import static org.mockito.Mockito.mock; 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 d00915f12ad6..b7646930322f 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.pagerduty.PagerDutyService; 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 class Watcher extends Plugin implements SystemIndexPlugin, ScriptPlugin, 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 f016f253583a..5ce678ac33ab 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.client.node.NodeClient; 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.AckWatchReques 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 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; */ 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_watcher/watch/{id}/_ack"), + new Route(PUT, "/_watcher/watch/{id}/_ack"), + new Route(POST, "/_watcher/watch/{id}/_ack/{actions}"), + new Route(PUT, "/_watcher/watch/{id}/_ack/{actions}"))); } @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 0317854d88b0..7bfdb5e726c8 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.client.node.NodeClient; 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.ActivateW 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 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; */ 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_watcher/watch/{id}/_activate"), + new Route(PUT, "/_watcher/watch/{id}/_activate"))); } @Override @@ -58,9 +59,13 @@ public class RestActivateWatchAction extends BaseRestHandler { }); } - private static class DeactivateRestHandler extends BaseRestHandler { + public static class DeactivateRestHandler extends BaseRestHandler { - DeactivateRestHandler() { + @Override + public List routes() { + return unmodifiableList(asList( + new Route(POST, "/_watcher/watch/{id}/_deactivate"), + new Route(PUT, "/_watcher/watch/{id}/_deactivate"))); } @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 dd33b79365d4..332fb8140aa3 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.DeleteWatchRequest; 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 routes() { + return singletonList(new Route(DELETE, "/_watcher/watch/{id}")); } @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 a42161aafc30..14e841d23e85 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.XContentBuilder; 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.transport.actions.execute.ExecuteWat 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 @@ import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_watcher/watch/{id}/_execute"), + new Route(PUT, "/_watcher/watch/{id}/_execute"), + new Route(POST, "/_watcher/watch/_execute"), + new Route(PUT, "/_watcher/watch/_execute"))); } @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 1001c8181467..0a3a4f576dae 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.client.node.NodeClient; 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.GetWatchAction 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 routes() { + return singletonList(new Route(GET, "/_watcher/watch/{id}")); } @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 2240c789c53f..5cf1ca6ee4c3 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.PutWatchRequest; 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.security.rest.RestRequestFilter; 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 @@ import static org.elasticsearch.rest.RestStatus.OK; 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 routes() { + return unmodifiableList(asList( + new Route(POST, "/_watcher/watch/{id}"), + new Route(PUT, "/_watcher/watch/{id}"))); } @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 c59cdffdcb96..991b72469412 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 @@ package org.elasticsearch.xpack.watcher.rest.action; 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 routes() { + return singletonList(new Route(POST, "/_watcher/_start")); } @Override @@ -34,9 +36,11 @@ public class RestWatchServiceAction extends BaseRestHandler { 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 routes() { + return singletonList(new Route(POST, "/_watcher/_stop")); } @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 60a0e0fb9fcd..2c3319b92c98 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.client.node.NodeClient; 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 routes() { + return unmodifiableList(asList( + new Route(GET, "/_watcher/stats"), + new Route(GET, "/_watcher/stats/{metric}"))); } @Override