From d690c5f78999217243d344170c905a90eb072a2b Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Fri, 20 Jan 2017 11:49:20 -0500 Subject: [PATCH] Deguice rest handlers (elastic/elasticsearch#4598) Since some of the rest handlers depend on components constructed in `createComponents` we use `SetOnce` to save a reference to the components at the class level and reuse the reference in `initRestHandlers`. This does require that `initRestHandlers` is called after `createComponents` but I think that is fairly reasonable. Original commit: elastic/x-pack-elasticsearch@4fd87ad91158bf91438bcbbe5712da36f72c5d3c --- .../org/elasticsearch/license/Licensing.java | 23 +++++++---- .../license/RestDeleteLicenseAction.java | 3 -- .../license/RestPutLicenseAction.java | 3 -- .../org/elasticsearch/xpack/XPackPlugin.java | 30 +++++++++----- .../org/elasticsearch/xpack/graph/Graph.java | 13 +++++- .../graph/rest/action/RestGraphAction.java | 2 - .../xpack/monitoring/Monitoring.java | 19 ++++++--- .../rest/action/RestMonitoringBulkAction.java | 2 - .../rest/action/RestXPackInfoAction.java | 11 ++--- .../rest/action/RestXPackUsageAction.java | 3 -- .../xpack/security/Security.java | 40 ++++++++++++------- .../xpack/security/SecurityContext.java | 1 - .../rest/action/RestAuthenticateAction.java | 2 - .../realm/RestClearRealmCacheAction.java | 3 -- .../role/RestClearRolesCacheAction.java | 3 -- .../action/role/RestDeleteRoleAction.java | 3 -- .../rest/action/role/RestGetRolesAction.java | 3 -- .../rest/action/role/RestPutRoleAction.java | 3 -- .../action/user/RestChangePasswordAction.java | 2 - .../action/user/RestDeleteUserAction.java | 3 -- .../rest/action/user/RestGetUsersAction.java | 3 -- .../rest/action/user/RestPutUserAction.java | 3 -- .../action/user/RestSetEnabledAction.java | 3 -- .../elasticsearch/xpack/watcher/Watcher.java | 30 +++++++++----- .../rest/action/RestAckWatchAction.java | 3 -- .../rest/action/RestActivateWatchAction.java | 3 -- .../rest/action/RestDeleteWatchAction.java | 3 -- .../rest/action/RestExecuteWatchAction.java | 9 +---- .../rest/action/RestGetWatchAction.java | 3 -- .../action/RestHijackOperationAction.java | 2 - .../rest/action/RestPutWatchAction.java | 3 -- .../rest/action/RestWatchServiceAction.java | 3 -- .../rest/action/RestWatcherStatsAction.java | 3 -- .../action/RestExecuteWatchActionTests.java | 7 +--- 34 files changed, 112 insertions(+), 138 deletions(-) diff --git a/elasticsearch/src/main/java/org/elasticsearch/license/Licensing.java b/elasticsearch/src/main/java/org/elasticsearch/license/Licensing.java index a93d965d7f5..4be3c22c233 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/license/Licensing.java +++ b/elasticsearch/src/main/java/org/elasticsearch/license/Licensing.java @@ -8,21 +8,27 @@ package org.elasticsearch.license; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.NamedDiff; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.rest.RestController; 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; -import static java.util.Collections.emptyList; import static org.elasticsearch.xpack.XPackPlugin.isTribeNode; import static org.elasticsearch.xpack.XPackPlugin.transportClientMode; @@ -64,13 +70,16 @@ public class Licensing implements ActionPlugin { } @Override - public List> getRestHandlers() { - if (isTribeNode) { - return Collections.singletonList(RestGetLicenseAction.class); + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { + List handlers = new ArrayList<>(); + handlers.add(new RestGetLicenseAction(settings, restController)); + if (false == isTribeNode) { + handlers.add(new RestPutLicenseAction(settings, restController)); + handlers.add(new RestDeleteLicenseAction(settings, restController)); } - return Arrays.asList(RestPutLicenseAction.class, - RestGetLicenseAction.class, - RestDeleteLicenseAction.class); + return handlers; } public List> getSettings() { diff --git a/elasticsearch/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java b/elasticsearch/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java index f9c0b0ead2c..6bcd9a883a9 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/license/RestDeleteLicenseAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.license; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -18,8 +17,6 @@ import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.DELETE; public class RestDeleteLicenseAction extends XPackRestHandler { - - @Inject public RestDeleteLicenseAction(Settings settings, RestController controller) { super(settings); // @deprecated Remove deprecations in 6.0 diff --git a/elasticsearch/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java b/elasticsearch/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java index b2935cc6a02..2d0b6fffee0 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/license/RestPutLicenseAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.license; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -24,8 +23,6 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestPutLicenseAction extends XPackRestHandler { - - @Inject public RestPutLicenseAction(Settings settings, RestController controller) { super(settings); // @deprecated Remove deprecations in 6.0 diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 033bba48813..6316c164243 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -11,6 +11,8 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilter; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Module; @@ -19,8 +21,10 @@ import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; @@ -37,6 +41,7 @@ import org.elasticsearch.plugins.IngestPlugin; import org.elasticsearch.plugins.NetworkPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; +import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; @@ -387,15 +392,22 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I } @Override - public List> getRestHandlers() { - List> handlers = new ArrayList<>(); - handlers.add(RestXPackInfoAction.class); - handlers.add(RestXPackUsageAction.class); - handlers.addAll(licensing.getRestHandlers()); - handlers.addAll(monitoring.getRestHandlers()); - handlers.addAll(security.getRestHandlers()); - handlers.addAll(watcher.getRestHandlers()); - handlers.addAll(graph.getRestHandlers()); + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { + List handlers = new ArrayList<>(); + handlers.add(new RestXPackInfoAction(settings, restController)); + handlers.add(new RestXPackUsageAction(settings, restController)); + handlers.addAll(licensing.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, + indexNameExpressionResolver, nodesInCluster)); + handlers.addAll(monitoring.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, + indexNameExpressionResolver, nodesInCluster)); + handlers.addAll(security.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, + indexNameExpressionResolver, nodesInCluster)); + handlers.addAll(watcher.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, + indexNameExpressionResolver, nodesInCluster)); + handlers.addAll(graph.getRestHandlers(settings, restController, clusterSettings, indexScopedSettings, settingsFilter, + indexNameExpressionResolver, nodesInCluster)); return handlers; } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/Graph.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/Graph.java index 16ecb107b9e..e064744b774 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/Graph.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/Graph.java @@ -7,10 +7,16 @@ package org.elasticsearch.xpack.graph; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.common.inject.Module; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; +import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; @@ -21,6 +27,7 @@ import org.elasticsearch.xpack.graph.rest.action.RestGraphAction; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Supplier; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -50,10 +57,12 @@ public class Graph extends Plugin implements ActionPlugin { } @Override - public List> getRestHandlers() { + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { if (false == enabled) { return emptyList(); } - return singletonList(RestGraphAction.class); + return singletonList(new RestGraphAction(settings, restController)); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java index b9e5e0e466a..38aa85b8e72 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/graph/rest/action/RestGraphAction.java @@ -9,7 +9,6 @@ import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; @@ -56,7 +55,6 @@ public class RestGraphAction extends XPackRestHandler { public static final ParseField BOOST_FIELD = new ParseField("boost"); public static final ParseField TERM_FIELD = new ParseField("term"); - @Inject public RestGraphAction(Settings settings, RestController controller) { super(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java index 1b3fd93ae09..fa1765f54f0 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java @@ -7,18 +7,26 @@ package org.elasticsearch.xpack.monitoring; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.license.LicenseService; import org.elasticsearch.license.XPackLicenseState; +import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.rest.RestController; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.XPackSettings; import org.elasticsearch.xpack.monitoring.action.MonitoringBulkAction; import org.elasticsearch.xpack.monitoring.action.TransportMonitoringBulkAction; +import org.elasticsearch.xpack.monitoring.cleaner.CleanerService; import org.elasticsearch.xpack.monitoring.collector.Collector; import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStateCollector; import org.elasticsearch.xpack.monitoring.collector.cluster.ClusterStatsCollector; @@ -31,14 +39,10 @@ import org.elasticsearch.xpack.monitoring.exporter.Exporter; import org.elasticsearch.xpack.monitoring.exporter.Exporters; import org.elasticsearch.xpack.monitoring.exporter.http.HttpExporter; import org.elasticsearch.xpack.monitoring.exporter.local.LocalExporter; -import org.elasticsearch.xpack.monitoring.cleaner.CleanerService; import org.elasticsearch.xpack.monitoring.rest.action.RestMonitoringBulkAction; -import org.elasticsearch.plugins.ActionPlugin; -import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.ssl.SSLService; -import java.time.Clock; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -48,6 +52,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.function.Supplier; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; @@ -135,10 +140,12 @@ public class Monitoring implements ActionPlugin { } @Override - public List> getRestHandlers() { + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { if (false == enabled || tribeNode) { return emptyList(); } - return singletonList(RestMonitoringBulkAction.class); + return singletonList(new RestMonitoringBulkAction(settings, restController)); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java index 360121c0db9..4495856880c 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/monitoring/rest/action/RestMonitoringBulkAction.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring.rest.action; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; @@ -31,7 +30,6 @@ public class RestMonitoringBulkAction extends MonitoringRestHandler { public static final String MONITORING_VERSION = "system_api_version"; public static final String INTERVAL = "interval"; - @Inject public RestMonitoringBulkAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, URI_BASE + "/_bulk", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java index 741a060f1ad..b365a838e5c 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackInfoAction.java @@ -5,12 +5,9 @@ */ package org.elasticsearch.xpack.rest.action; -import java.io.IOException; -import java.util.EnumSet; - -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.license.XPackInfoResponse; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -18,16 +15,16 @@ import org.elasticsearch.rest.RestResponse; import org.elasticsearch.rest.action.RestBuilderListener; import org.elasticsearch.xpack.XPackClient; import org.elasticsearch.xpack.action.XPackInfoRequest; -import org.elasticsearch.license.XPackInfoResponse; import org.elasticsearch.xpack.rest.XPackRestHandler; +import java.io.IOException; +import java.util.EnumSet; + import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestRequest.Method.HEAD; import static org.elasticsearch.rest.RestStatus.OK; public class RestXPackInfoAction extends XPackRestHandler { - - @Inject public RestXPackInfoAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(HEAD, URI_BASE, this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackUsageAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackUsageAction.java index 0570b3ddf9a..41be0424383 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackUsageAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/rest/action/RestXPackUsageAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.rest.action; import org.elasticsearch.action.support.master.MasterNodeRequest; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; public class RestXPackUsageAction extends XPackRestHandler { - - @Inject public RestXPackUsageAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(GET, URI_BASE + "/usage", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java index 8bc1ed0cb6c..ebd26d98995 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -11,6 +11,8 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.action.support.ActionFilter; import org.elasticsearch.action.support.DestructiveOperations; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.Nullable; @@ -23,9 +25,12 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkService; import org.elasticsearch.common.regex.Regex; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.NamedXContentRegistry; @@ -38,6 +43,7 @@ import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.IngestPlugin; import org.elasticsearch.plugins.NetworkPlugin; +import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.Transport; @@ -169,6 +175,7 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin { private final SetOnce securityInterceptor = new SetOnce<>(); private final SetOnce ipFilter = new SetOnce<>(); private final SetOnce authcService = new SetOnce<>(); + private final SetOnce securityContext = new SetOnce<>(); public Security(Settings settings, Environment env, XPackLicenseState licenseState, SSLService sslService) throws IOException { this.settings = settings; @@ -241,8 +248,8 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin { } List components = new ArrayList<>(); - final SecurityContext securityContext = new SecurityContext(settings, threadPool.getThreadContext(), cryptoService); - components.add(securityContext); + securityContext.set(new SecurityContext(settings, threadPool.getThreadContext(), cryptoService)); + components.add(securityContext.get()); // realms construction final NativeUsersStore nativeUsersStore = new NativeUsersStore(settings, client); @@ -335,7 +342,7 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin { components.add(ipFilter.get()); DestructiveOperations destructiveOperations = new DestructiveOperations(settings, clusterService.getClusterSettings()); securityInterceptor.set(new SecurityServerTransportInterceptor(settings, threadPool, authcService.get(), authzService, licenseState, - sslService, securityContext, destructiveOperations)); + sslService, securityContext.get(), destructiveOperations)); return components; } @@ -500,21 +507,24 @@ public class Security implements ActionPlugin, IngestPlugin, NetworkPlugin { } @Override - public List> getRestHandlers() { + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { if (enabled == false) { return emptyList(); } - return Arrays.asList(RestAuthenticateAction.class, - RestClearRealmCacheAction.class, - RestClearRolesCacheAction.class, - RestGetUsersAction.class, - RestPutUserAction.class, - RestDeleteUserAction.class, - RestGetRolesAction.class, - RestPutRoleAction.class, - RestDeleteRoleAction.class, - RestChangePasswordAction.class, - RestSetEnabledAction.class); + return Arrays.asList( + new RestAuthenticateAction(settings, restController, securityContext.get(), licenseState), + new RestClearRealmCacheAction(settings, restController), + new RestClearRolesCacheAction(settings, restController), + new RestGetUsersAction(settings, restController), + new RestPutUserAction(settings, restController), + new RestDeleteUserAction(settings, restController), + new RestGetRolesAction(settings, restController), + new RestPutRoleAction(settings, restController), + new RestDeleteRoleAction(settings, restController), + new RestChangePasswordAction(settings, restController, securityContext.get()), + new RestSetEnabledAction(settings, restController)); } @Override diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/SecurityContext.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/SecurityContext.java index 7ca4f825dd9..1642aca357f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/SecurityContext.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/SecurityContext.java @@ -11,7 +11,6 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.util.concurrent.ThreadContext.StoredContext; import org.elasticsearch.node.Node; -import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.xpack.security.authc.Authentication; import org.elasticsearch.xpack.security.authc.AuthenticationService; import org.elasticsearch.xpack.security.crypto.CryptoService; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java index 4e0c18cd2fe..4a453813dfb 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/RestAuthenticateAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -35,7 +34,6 @@ public class RestAuthenticateAction extends BaseRestHandler { private final SecurityContext securityContext; private final XPackLicenseState licenseState; - @Inject public RestAuthenticateAction(Settings settings, RestController controller, SecurityContext securityContext, XPackLicenseState licenseState) { super(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java index 034fdddabf4..ecd94e40f8b 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/realm/RestClearRealmCacheAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.realm; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; @@ -20,8 +19,6 @@ import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestClearRealmCacheAction extends BaseRestHandler { - - @Inject public RestClearRealmCacheAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/_xpack/security/realm/{realms}/_clear_cache", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java index e7a69734393..827becffd84 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestClearRolesCacheAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.role; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.RestController; @@ -20,8 +19,6 @@ import java.io.IOException; import static org.elasticsearch.rest.RestRequest.Method.POST; public class RestClearRolesCacheAction extends BaseRestHandler { - - @Inject public RestClearRolesCacheAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/_xpack/security/role/{name}/_clear_cache", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java index 77fef1ad085..8968a8da015 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestDeleteRoleAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.role; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE; * Rest endpoint to delete a Role from the security index */ public class RestDeleteRoleAction extends BaseRestHandler { - - @Inject public RestDeleteRoleAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(DELETE, "/_xpack/security/role/{name}", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java index 7586be19808..aff141540ad 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestGetRolesAction.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.security.rest.action.role; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; * Rest endpoint to retrieve a Role from the security index */ public class RestGetRolesAction extends BaseRestHandler { - - @Inject public RestGetRolesAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(GET, "/_xpack/security/role/", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java index d8d9e789536..5f3cc0eebb4 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/role/RestPutRoleAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.role; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; * Rest endpoint to add a Role to the security index */ public class RestPutRoleAction extends BaseRestHandler { - - @Inject public RestPutRoleAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/_xpack/security/role/{name}", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java index 94f6124f21e..3af1688cc9a 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestChangePasswordAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.user; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -30,7 +29,6 @@ public class RestChangePasswordAction extends BaseRestHandler { private final SecurityContext securityContext; - @Inject public RestChangePasswordAction(Settings settings, RestController controller, SecurityContext securityContext) { super(settings); this.securityContext = securityContext; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java index 22d0da694c9..e0ecf501326 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestDeleteUserAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.user; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestRequest.Method.DELETE; * Rest action to delete a user from the security index */ public class RestDeleteUserAction extends BaseRestHandler { - - @Inject public RestDeleteUserAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(DELETE, "/_xpack/security/user/{username}", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java index bf4d7ded01a..47194db8d5e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestGetUsersAction.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.security.rest.action.user; import org.elasticsearch.client.node.NodeClient; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; * Rest action to retrieve a user from the security index */ public class RestGetUsersAction extends BaseRestHandler { - - @Inject public RestGetUsersAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(GET, "/_xpack/security/user/", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java index d71333412ba..572fb351d0c 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestPutUserAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.user; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; * Rest endpoint to add a User to the security index */ public class RestPutUserAction extends BaseRestHandler { - - @Inject public RestPutUserAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/_xpack/security/user/{username}", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java index 5e009077018..fad50a2bab2 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/security/rest/action/user/RestSetEnabledAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.security.rest.action.user; import org.elasticsearch.client.node.NodeClient; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BaseRestHandler; @@ -29,8 +28,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; * enabled or disabled. */ public class RestSetEnabledAction extends BaseRestHandler { - - @Inject public RestSetEnabledAction(Settings settings, RestController controller) { super(settings); controller.registerHandler(POST, "/_xpack/security/user/{username}/_enable", this); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 6a262cee8c1..74bcada4ae0 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -10,7 +10,9 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.NamedDiff; +import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; import org.elasticsearch.cluster.metadata.MetaData; +import org.elasticsearch.cluster.node.DiscoveryNodes; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.Booleans; import org.elasticsearch.common.ParseField; @@ -21,14 +23,18 @@ import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.regex.Regex; +import org.elasticsearch.common.settings.ClusterSettings; +import org.elasticsearch.common.settings.IndexScopedSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.settings.SettingsFilter; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.xcontent.NamedXContentRegistry; import org.elasticsearch.license.XPackLicenseState; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.ScriptPlugin; +import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.script.ScriptService; @@ -157,6 +163,7 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.function.Function; +import java.util.function.Supplier; import java.util.stream.Collectors; import static java.util.Collections.emptyList; @@ -419,19 +426,22 @@ public class Watcher implements ActionPlugin, ScriptPlugin { } @Override - public List> getRestHandlers() { + public List getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings, + IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver, + Supplier nodesInCluster) { if (false == enabled) { return emptyList(); } - return Arrays.asList(RestPutWatchAction.class, - RestDeleteWatchAction.class, - RestWatcherStatsAction.class, - RestGetWatchAction.class, - RestWatchServiceAction.class, - RestAckWatchAction.class, - RestActivateWatchAction.class, - RestExecuteWatchAction.class, - RestHijackOperationAction.class); + return Arrays.asList( + new RestPutWatchAction(settings, restController), + new RestDeleteWatchAction(settings, restController), + new RestWatcherStatsAction(settings, restController), + new RestGetWatchAction(settings, restController), + new RestWatchServiceAction(settings, restController), + new RestAckWatchAction(settings, restController), + new RestActivateWatchAction(settings, restController), + new RestExecuteWatchAction(settings, restController), + new RestHijackOperationAction(settings, restController)); } @Override diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java index 537eb61ca3d..323a3e0a340 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestAckWatchAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; @@ -30,8 +29,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; * The rest action to ack a watch */ public class RestAckWatchAction extends WatcherRestHandler { - - @Inject public RestAckWatchAction(Settings settings, RestController controller) { super(settings); // @deprecated Remove deprecations in 6.0 diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java index 0bb6bf51d1d..66f7e293c92 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestActivateWatchAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; @@ -30,8 +29,6 @@ import static org.elasticsearch.rest.RestRequest.Method.PUT; * The rest action to de/activate a watch */ public class RestActivateWatchAction extends WatcherRestHandler { - - @Inject public RestActivateWatchAction(Settings settings, RestController controller) { super(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java index f0f2bc768c2..b8059b5eb94 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestDeleteWatchAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; @@ -26,8 +25,6 @@ import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; public class RestDeleteWatchAction extends WatcherRestHandler { - - @Inject public RestDeleteWatchAction(Settings settings, RestController controller) { super(settings); // @deprecated Remove deprecations in 6.0 diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java index 1420933a934..c6c1a2695cd 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchAction.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.rest.action; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; @@ -25,7 +24,6 @@ import org.elasticsearch.xpack.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchRequest; import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchRequestBuilder; import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchResponse; -import org.elasticsearch.xpack.watcher.trigger.TriggerService; import java.io.IOException; @@ -35,13 +33,8 @@ import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction import static org.elasticsearch.xpack.watcher.rest.action.RestExecuteWatchAction.Field.RECORD_EXECUTION; public class RestExecuteWatchAction extends WatcherRestHandler { - - final TriggerService triggerService; - - @Inject - public RestExecuteWatchAction(Settings settings, RestController controller, TriggerService triggerService) { + public RestExecuteWatchAction(Settings settings, RestController controller) { super(settings); - this.triggerService = triggerService; // @deprecated Remove deprecations in 6.0 controller.registerWithDeprecatedHandler(POST, URI_BASE + "/watch/{id}/_execute", this, diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java index 27a20c83963..20d954308bd 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestGetWatchAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestStatus.NOT_FOUND; import static org.elasticsearch.rest.RestStatus.OK; public class RestGetWatchAction extends WatcherRestHandler { - - @Inject public RestGetWatchAction(Settings settings, RestController controller) { super(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestHijackOperationAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestHijackOperationAction.java index 4a5d9824e09..031130084fa 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestHijackOperationAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestHijackOperationAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; @@ -28,7 +27,6 @@ public class RestHijackOperationAction extends WatcherRestHandler { private static final String ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING = "xpack.watcher.index.rest.direct_access"; - @Inject public RestHijackOperationAction(Settings settings, RestController controller) { super(settings); if (!settings.getAsBoolean(ALLOW_DIRECT_ACCESS_TO_WATCH_INDEX_SETTING, false)) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java index 4d829d93c53..14858bbc1cf 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestPutWatchAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; @@ -27,8 +26,6 @@ import static org.elasticsearch.rest.RestStatus.CREATED; import static org.elasticsearch.rest.RestStatus.OK; public class RestPutWatchAction extends WatcherRestHandler { - - @Inject public RestPutWatchAction(Settings settings, RestController controller) { super(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java index c2646f2c3a7..ac617d0f975 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatchServiceAction.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.rest.action; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.rest.RestController; import org.elasticsearch.rest.RestRequest; @@ -20,8 +19,6 @@ import static org.elasticsearch.rest.RestRequest.Method.POST; import static org.elasticsearch.rest.RestRequest.Method.PUT; public class RestWatchServiceAction extends WatcherRestHandler { - - @Inject public RestWatchServiceAction(Settings settings, RestController controller) { super(settings); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java index d5adc8711f1..a4b2a6a873f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/rest/action/RestWatcherStatsAction.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.watcher.rest.action; import org.elasticsearch.common.Strings; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.rest.BytesRestResponse; @@ -26,8 +25,6 @@ import static org.elasticsearch.rest.RestRequest.Method.GET; import static org.elasticsearch.rest.RestStatus.OK; public class RestWatcherStatsAction extends WatcherRestHandler { - - @Inject public RestWatcherStatsAction(Settings settings, RestController controller) { super(settings); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java index 4e7a8b94294..b3941def528 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/rest/action/RestExecuteWatchActionTests.java @@ -9,13 +9,11 @@ import org.elasticsearch.client.Client; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.bytes.BytesReference; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestController; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.test.rest.FakeRestRequest; import org.elasticsearch.xpack.watcher.client.WatcherClient; import org.elasticsearch.xpack.watcher.transport.actions.execute.ExecuteWatchRequestBuilder; -import org.elasticsearch.xpack.watcher.trigger.TriggerService; import java.util.Arrays; @@ -27,8 +25,6 @@ public class RestExecuteWatchActionTests extends ESTestCase { private RestController restController = mock(RestController.class); private Client client = mock(Client.class); - private TriggerService triggerService = mock(TriggerService.class); - private RestChannel restChannel = mock(RestChannel.class); private WatcherClient watcherClient = mock(WatcherClient.class); public void testThatFlagsCanBeSpecifiedViaParameters() throws Exception { @@ -39,8 +35,7 @@ public class RestExecuteWatchActionTests extends ESTestCase { ExecuteWatchRequestBuilder builder = new ExecuteWatchRequestBuilder(client); when(watcherClient.prepareExecuteWatch()).thenReturn(builder); - RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController, - triggerService); + RestExecuteWatchAction restExecuteWatchAction = new RestExecuteWatchAction(Settings.EMPTY, restController); restExecuteWatchAction.doPrepareRequest(createFakeRestRequest(randomId, recordExecution, ignoreCondition, debugCondition), watcherClient);