From 672d91f2a4196da8b38900d29899aee9fdce4f23 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Wed, 29 Jun 2016 16:39:37 -0400 Subject: [PATCH] Move rest handler registration to ActionPlugin Original commit: elastic/x-pack-elasticsearch@b3bc7d4a9f0df9587ba5c83e90d481926cc84204 --- .../org/elasticsearch/xpack/graph/Graph.java | 18 +++++------ .../license/plugin/Licensing.java | 20 ++++++------ .../xpack/monitoring/Monitoring.java | 15 +++++---- .../collector/AbstractCollectorTestCase.java | 9 +++--- .../license/LicenseIntegrationTests.java | 8 ++--- .../xpack/security/Security.java | 28 ++++++++++------ .../integration/LicensingTests.java | 6 ++-- .../org/elasticsearch/xpack/XPackPlugin.java | 22 ++++++++----- .../elasticsearch/xpack/watcher/Watcher.java | 32 ++++++++++--------- 9 files changed, 90 insertions(+), 68 deletions(-) diff --git a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java index c4def4e65b8..bac749c7836 100644 --- a/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java +++ b/elasticsearch/x-pack/graph/src/main/java/org/elasticsearch/xpack/graph/Graph.java @@ -9,12 +9,11 @@ import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.ActionPlugin.ActionHandler; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.graph.action.GraphExploreAction; import org.elasticsearch.xpack.graph.action.TransportGraphExploreAction; @@ -57,19 +56,20 @@ public class Graph extends Plugin implements ActionPlugin { @Override public List, ? extends ActionResponse>> getActions() { - if (enabled) { - return singletonList(new ActionHandler<>(GraphExploreAction.INSTANCE, TransportGraphExploreAction.class)); + if (false == enabled) { + return emptyList(); } - return emptyList(); + return singletonList(new ActionHandler<>(GraphExploreAction.INSTANCE, TransportGraphExploreAction.class)); } - public void onModule(NetworkModule module) { - if (enabled && transportClientMode == false) { - module.registerRestHandler(RestGraphAction.class); + @Override + public List> getRestHandlers() { + if (false == enabled) { + return emptyList(); } + return singletonList(RestGraphAction.class); } - @Override public List> getSettings() { return Collections.singletonList(Setting.boolSetting(XPackPlugin.featureEnabledSetting(NAME), true, Setting.Property.NodeScope)); diff --git a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java index 3a8cb188966..b92bd35752d 100644 --- a/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java +++ b/elasticsearch/x-pack/license-plugin/src/main/java/org/elasticsearch/license/plugin/Licensing.java @@ -11,7 +11,6 @@ import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.plugin.action.delete.DeleteLicenseAction; @@ -26,6 +25,7 @@ import org.elasticsearch.license.plugin.rest.RestDeleteLicenseAction; import org.elasticsearch.license.plugin.rest.RestGetLicenseAction; import org.elasticsearch.license.plugin.rest.RestPutLicenseAction; import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.rest.RestHandler; import java.util.Arrays; import java.util.Collection; @@ -53,14 +53,6 @@ public class Licensing implements ActionPlugin { isTribeNode = isTribeNode(settings); } - public void onModule(NetworkModule module) { - if (isTransportClient == false && isTribeNode == false) { - module.registerRestHandler(RestPutLicenseAction.class); - module.registerRestHandler(RestGetLicenseAction.class); - module.registerRestHandler(RestDeleteLicenseAction.class); - } - } - @Override public List, ? extends ActionResponse>> getActions() { if (isTribeNode) { @@ -71,6 +63,16 @@ public class Licensing implements ActionPlugin { new ActionHandler<>(DeleteLicenseAction.INSTANCE, TransportDeleteLicenseAction.class)); } + @Override + public List> getRestHandlers() { + if (isTribeNode) { + return emptyList(); + } + return Arrays.asList(RestPutLicenseAction.class, + RestGetLicenseAction.class, + RestDeleteLicenseAction.class); + } + public Collection> nodeServices() { if (isTransportClient == false && isTribeNode == false) { return Collections.>singletonList(LicensesService.class); diff --git a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java index 3ca63653af9..e32e347ad11 100644 --- a/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java +++ b/elasticsearch/x-pack/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java @@ -21,6 +21,7 @@ import org.elasticsearch.xpack.monitoring.cleaner.CleanerService; import org.elasticsearch.xpack.monitoring.client.MonitoringClientModule; import org.elasticsearch.xpack.monitoring.rest.action.RestMonitoringBulkAction; import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.XPackPlugin; import java.util.ArrayList; @@ -84,16 +85,18 @@ public class Monitoring implements ActionPlugin { @Override public List, ? extends ActionResponse>> getActions() { - if (enabled && tribeNode == false) { - return singletonList(new ActionHandler<>(MonitoringBulkAction.INSTANCE, TransportMonitoringBulkAction.class)); + if (false == enabled || tribeNode) { + return emptyList(); } - return emptyList(); + return singletonList(new ActionHandler<>(MonitoringBulkAction.INSTANCE, TransportMonitoringBulkAction.class)); } - public void onModule(NetworkModule module) { - if (enabled && transportClientMode == false && tribeNode == false) { - module.registerRestHandler(RestMonitoringBulkAction.class); + @Override + public List> getRestHandlers() { + if (false == enabled || tribeNode) { + return emptyList(); } + return singletonList(RestMonitoringBulkAction.class); } public static boolean enabled(Settings settings) { diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java index bd79599f381..ba5a3578a0c 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/agent/collector/AbstractCollectorTestCase.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.monitoring.agent.collector; import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.SysGlobals; -import org.elasticsearch.action.ActionModule; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionResponse; import org.elasticsearch.cluster.block.ClusterBlocks; @@ -26,14 +25,13 @@ import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; import org.elasticsearch.license.plugin.core.LicensesManagerService; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.ActionPlugin.ActionHandler; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.xpack.monitoring.test.MonitoringIntegTestCase; -import org.elasticsearch.xpack.security.InternalClient; import org.junit.Before; import java.util.ArrayList; @@ -205,11 +203,12 @@ public abstract class AbstractCollectorTestCase extends MonitoringIntegTestCase } @Override - public void onModule(NetworkModule module) { + public List, ? extends ActionResponse>> getActions() { + return emptyList(); } @Override - public List, ? extends ActionResponse>> getActions() { + public List> getRestHandlers() { return emptyList(); } diff --git a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java index b741512f376..1b908ea82e2 100644 --- a/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java +++ b/elasticsearch/x-pack/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/license/LicenseIntegrationTests.java @@ -12,7 +12,6 @@ import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.license.core.License; import org.elasticsearch.license.plugin.Licensing; @@ -21,7 +20,7 @@ import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; import org.elasticsearch.license.plugin.core.LicensesManagerService; import org.elasticsearch.plugins.Plugin; -import org.elasticsearch.plugins.ActionPlugin.ActionHandler; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.monitoring.MonitoringLicensee; @@ -96,11 +95,12 @@ public class LicenseIntegrationTests extends MonitoringIntegTestCase { } @Override - public void onModule(NetworkModule module) { + public List, ? extends ActionResponse>> getActions() { + return emptyList(); } @Override - public List, ? extends ActionResponse>> getActions() { + public List> getRestHandlers() { return emptyList(); } diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java index 1c9e9a1d5a6..444c3186ab6 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/Security.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.index.IndexModule; import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.xpack.XPackPlugin; import org.elasticsearch.xpack.security.action.SecurityActionModule; import org.elasticsearch.xpack.security.action.filter.SecurityActionFilter; @@ -308,6 +309,23 @@ public class Security implements ActionPlugin { return emptyList(); } + @Override + public List> getRestHandlers() { + 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); + } + public void onModule(NetworkModule module) { if (transportClientMode) { @@ -321,16 +339,6 @@ public class Security implements ActionPlugin { if (enabled) { module.registerTransport(Security.NAME, SecurityNettyTransport.class); module.registerTransportService(Security.NAME, SecurityServerTransportService.class); - module.registerRestHandler(RestAuthenticateAction.class); - module.registerRestHandler(RestClearRealmCacheAction.class); - module.registerRestHandler(RestClearRolesCacheAction.class); - module.registerRestHandler(RestGetUsersAction.class); - module.registerRestHandler(RestPutUserAction.class); - module.registerRestHandler(RestDeleteUserAction.class); - module.registerRestHandler(RestGetRolesAction.class); - module.registerRestHandler(RestPutRoleAction.class); - module.registerRestHandler(RestDeleteRoleAction.class); - module.registerRestHandler(RestChangePasswordAction.class); module.registerHttpTransport(Security.NAME, SecurityNettyHttpServerTransport.class); } } diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java index 8888468d44f..177f67a5ac6 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/integration/LicensingTests.java @@ -32,6 +32,7 @@ import org.elasticsearch.license.plugin.Licensing; import org.elasticsearch.license.plugin.core.LicenseState; import org.elasticsearch.license.plugin.core.Licensee; import org.elasticsearch.license.plugin.core.LicenseeRegistry; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.rest.RestStatus; import org.elasticsearch.test.SecurityIntegTestCase; import org.elasticsearch.test.SecuritySettingsSource; @@ -272,11 +273,12 @@ public class LicensingTests extends SecurityIntegTestCase { } @Override - public void onModule(NetworkModule module) { + public List, ? extends ActionResponse>> getActions() { + return emptyList(); } @Override - public List, ? extends ActionResponse>> getActions() { + public List> getRestHandlers() { return emptyList(); } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 6878b68c678..a1046b1ce62 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -26,6 +26,7 @@ import org.elasticsearch.xpack.monitoring.MonitoringSettings; import org.elasticsearch.plugins.ActionPlugin; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.script.ScriptContext; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.xpack.action.TransportXPackInfoAction; @@ -212,15 +213,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { } public void onModule(NetworkModule module) { - if (!transportClientMode) { - module.registerRestHandler(RestXPackInfoAction.class); - module.registerRestHandler(RestXPackUsageAction.class); - } - licensing.onModule(module); - monitoring.onModule(module); security.onModule(module); - watcher.onModule(module); - graph.onModule(module); } @Override @@ -247,6 +240,19 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin { return filters; } + @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()); + return handlers; + } + public void onModule(AuthenticationModule module) { if (extensionsService != null) { extensionsService.onModule(module); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 5c0d6e0990d..3ec90aedeef 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -16,12 +16,12 @@ import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.LoggerMessageFormat; import org.elasticsearch.common.logging.Loggers; -import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.plugins.ActionPlugin; +import org.elasticsearch.rest.RestHandler; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.xpack.XPackPlugin; @@ -178,20 +178,6 @@ public class Watcher implements ActionPlugin { return Collections.emptyList(); } - public void onModule(NetworkModule module) { - if (enabled && transportClient == false) { - module.registerRestHandler(RestPutWatchAction.class); - module.registerRestHandler(RestDeleteWatchAction.class); - module.registerRestHandler(RestWatcherStatsAction.class); - module.registerRestHandler(RestGetWatchAction.class); - module.registerRestHandler(RestWatchServiceAction.class); - module.registerRestHandler(RestAckWatchAction.class); - module.registerRestHandler(RestActivateWatchAction.class); - module.registerRestHandler(RestExecuteWatchAction.class); - module.registerRestHandler(RestHijackOperationAction.class); - } - } - @Override public List, ? extends ActionResponse>> getActions() { if (false == enabled) { @@ -207,6 +193,22 @@ public class Watcher implements ActionPlugin { new ActionHandler<>(ExecuteWatchAction.INSTANCE, TransportExecuteWatchAction.class)); } + @Override + public List> getRestHandlers() { + 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); + } + public static boolean enabled(Settings settings) { return XPackPlugin.featureEnabled(settings, NAME, true); }