From e0128daf9ae033ea04f5c646e2972f405ff8706e Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Tue, 18 Aug 2015 18:33:46 -0700 Subject: [PATCH] Remove uses of SpawnModules SpawnModules will be going away very soon as part of elastic/elasticsearchelastic/elasticsearch#12783. This change removes its use from all x-plugins. Most spawnmodules uses here were to either collect a number of modules into one (so the modules were just moved up into the plugin itself), or to spawn a module which interacted with an extension point from ES. This change moves those, as well as most uses of PreProcessModule, to use onModule. Original commit: elastic/x-pack-elasticsearch@6430e353799e762c8c6602f39bce4cf5fc773d48 --- .../elasticsearch/marvel/MarvelModule.java | 35 ----- .../elasticsearch/marvel/MarvelPlugin.java | 13 +- ...lSettingsModule.java => MarvelModule.java} | 4 +- .../marvel/MarvelPluginClientTests.java | 2 +- .../shield/ShieldDisabledModule.java | 14 +- .../elasticsearch/shield/ShieldModule.java | 37 +---- .../elasticsearch/shield/ShieldPlugin.java | 88 +++++++++++- .../shield/action/ShieldActionModule.java | 34 +---- .../shield/rest/ShieldRestModule.java | 15 +- .../shield/support/AbstractShieldModule.java | 14 -- .../transport/ShieldTransportModule.java | 32 +---- .../ShieldNettyHttpServerTransportModule.java | 34 ----- .../netty/ShieldNettyTransportModule.java | 34 ----- .../watcher/TransportClientWatcherModule.java | 28 ---- .../elasticsearch/watcher/WatcherModule.java | 47 +----- .../elasticsearch/watcher/WatcherPlugin.java | 102 ++++++++++++- ...onModule.java => WatcherActionModule.java} | 2 +- .../watcher/rest/WatcherRestModule.java | 38 ----- .../support/http/HttpClientModule.java | 24 ++-- .../watcher/support/http/auth/AuthModule.java | 28 ---- .../support/template/TemplateModule.java | 15 +- .../watcher/trigger/TriggerModule.java | 7 +- .../actions/ActionErrorIntegrationTests.java | 2 +- .../watcher/test/TimeWarpedWatcherPlugin.java | 136 ++++++++---------- .../WatcherExecutorServiceBenchmark.java | 42 ++---- 25 files changed, 292 insertions(+), 535 deletions(-) delete mode 100644 marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java rename marvel/src/main/java/org/elasticsearch/marvel/agent/settings/{MarvelSettingsModule.java => MarvelModule.java} (74%) delete mode 100644 shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportModule.java delete mode 100644 shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyTransportModule.java delete mode 100644 watcher/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java rename watcher/src/main/java/org/elasticsearch/watcher/actions/{ActionModule.java => WatcherActionModule.java} (97%) delete mode 100644 watcher/src/main/java/org/elasticsearch/watcher/rest/WatcherRestModule.java delete mode 100644 watcher/src/main/java/org/elasticsearch/watcher/support/http/auth/AuthModule.java diff --git a/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java b/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java deleted file mode 100644 index 5de06d388c3..00000000000 --- a/marvel/src/main/java/org/elasticsearch/marvel/MarvelModule.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.marvel; - -import com.google.common.collect.ImmutableList; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.SpawnModules; -import org.elasticsearch.marvel.agent.AgentService; -import org.elasticsearch.marvel.agent.collector.CollectorModule; -import org.elasticsearch.marvel.agent.exporter.ExporterModule; -import org.elasticsearch.marvel.agent.renderer.RendererModule; -import org.elasticsearch.marvel.agent.settings.MarvelSettingsModule; -import org.elasticsearch.marvel.license.LicenseModule; - -public class MarvelModule extends AbstractModule implements SpawnModules { - - @Override - protected void configure() { - bind(AgentService.class).asEagerSingleton(); - } - - @Override - public Iterable spawnModules() { - return ImmutableList.of( - new MarvelSettingsModule(), - new LicenseModule(), - new CollectorModule(), - new ExporterModule(), - new RendererModule()); - } -} diff --git a/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java b/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java index ca91a92515e..7204625217e 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/MarvelPlugin.java @@ -15,13 +15,19 @@ import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.marvel.agent.AgentService; +import org.elasticsearch.marvel.agent.collector.CollectorModule; +import org.elasticsearch.marvel.agent.exporter.ExporterModule; import org.elasticsearch.marvel.agent.exporter.HttpESExporter; +import org.elasticsearch.marvel.agent.renderer.RendererModule; +import org.elasticsearch.marvel.agent.settings.MarvelModule; +import org.elasticsearch.marvel.license.LicenseModule; import org.elasticsearch.marvel.agent.settings.MarvelSetting; import org.elasticsearch.marvel.agent.settings.MarvelSettings; import org.elasticsearch.marvel.license.LicenseService; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.tribe.TribeService; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -57,7 +63,12 @@ public class MarvelPlugin extends Plugin { if (!enabled) { return Collections.emptyList(); } - return Collections.singletonList(new MarvelModule()); + return Arrays.asList( + new MarvelModule(), + new LicenseModule(), + new CollectorModule(), + new ExporterModule(), + new RendererModule()); } @Override diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsModule.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelModule.java similarity index 74% rename from marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsModule.java rename to marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelModule.java index 84a5187fc23..e8e9887d409 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelSettingsModule.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/settings/MarvelModule.java @@ -6,11 +6,13 @@ package org.elasticsearch.marvel.agent.settings; import org.elasticsearch.common.inject.AbstractModule; +import org.elasticsearch.marvel.agent.AgentService; -public class MarvelSettingsModule extends AbstractModule { +public class MarvelModule extends AbstractModule { @Override protected void configure() { bind(MarvelSettings.class).asEagerSingleton(); + bind(AgentService.class).asEagerSingleton(); } } diff --git a/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java b/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java index 06aa8e4a9b9..8cb8c012844 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/MarvelPluginClientTests.java @@ -39,7 +39,7 @@ public class MarvelPluginClientTests extends ESTestCase { MarvelPlugin plugin = new MarvelPlugin(settings); assertThat(plugin.isEnabled(), is(true)); Collection modules = plugin.nodeModules(); - assertThat(modules.size(), is(1)); + assertThat(modules.size(), is(5)); } } diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java b/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java index 54f65f89e86..2d1f1f2f482 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldDisabledModule.java @@ -5,16 +5,12 @@ */ package org.elasticsearch.shield; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestModule; import org.elasticsearch.shield.license.LicenseService; -import org.elasticsearch.shield.rest.action.RestShieldInfoAction; import org.elasticsearch.shield.support.AbstractShieldModule; -public class ShieldDisabledModule extends AbstractShieldModule implements PreProcessModule { +public class ShieldDisabledModule extends AbstractShieldModule { public ShieldDisabledModule(Settings settings) { super(settings); @@ -28,12 +24,4 @@ public class ShieldDisabledModule extends AbstractShieldModule implements PrePro bind(LicenseService.class).toProvider(Providers.of(null)); } } - - @Override - public void processModule(Module module) { - if (module instanceof RestModule) { - //we want to expose the shield rest action even when the plugin is disabled - ((RestModule) module).addRestAction(RestShieldInfoAction.class); - } - } } diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java b/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java index b8c68961d23..8ba2d49c146 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldModule.java @@ -5,53 +5,18 @@ */ package org.elasticsearch.shield; -import com.google.common.collect.ImmutableList; -import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.action.ShieldActionModule; -import org.elasticsearch.shield.audit.AuditTrailModule; -import org.elasticsearch.shield.authc.AuthenticationModule; -import org.elasticsearch.shield.authz.AuthorizationModule; -import org.elasticsearch.shield.crypto.CryptoModule; -import org.elasticsearch.shield.license.LicenseModule; -import org.elasticsearch.shield.rest.ShieldRestModule; -import org.elasticsearch.shield.ssl.SSLModule; import org.elasticsearch.shield.support.AbstractShieldModule; -import org.elasticsearch.shield.transport.ShieldTransportModule; /** * */ -public class ShieldModule extends AbstractShieldModule.Spawn { +public class ShieldModule extends AbstractShieldModule { public ShieldModule(Settings settings) { super(settings); } - @Override - public Iterable spawnModules(boolean clientMode) { - assert shieldEnabled : "this module should get loaded only when shield is enabled"; - - // spawn needed parts in client mode - if (clientMode) { - return ImmutableList.of( - new ShieldActionModule(settings), - new ShieldTransportModule(settings), - new SSLModule(settings)); - } - - return ImmutableList.of( - new LicenseModule(settings), - new CryptoModule(settings), - new AuthenticationModule(settings), - new AuthorizationModule(settings), - new AuditTrailModule(settings), - new ShieldRestModule(settings), - new ShieldActionModule(settings), - new ShieldTransportModule(settings), - new SSLModule(settings)); - } - @Override protected void configure(boolean clientMode) { if (!clientMode) { diff --git a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java index 3a96029a516..14bef7a2ed4 100644 --- a/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java +++ b/shield/src/main/java/org/elasticsearch/shield/ShieldPlugin.java @@ -6,6 +6,7 @@ package org.elasticsearch.shield; import com.google.common.collect.ImmutableList; +import org.elasticsearch.action.ActionModule; import org.elasticsearch.client.Client; import org.elasticsearch.client.support.Headers; import org.elasticsearch.cluster.ClusterModule; @@ -14,16 +15,38 @@ import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; +import org.elasticsearch.http.HttpServerModule; +import org.elasticsearch.rest.RestModule; +import org.elasticsearch.shield.action.ShieldActionFilter; +import org.elasticsearch.shield.action.ShieldActionModule; +import org.elasticsearch.shield.action.authc.cache.ClearRealmCacheAction; +import org.elasticsearch.shield.action.authc.cache.TransportClearRealmCacheAction; +import org.elasticsearch.shield.audit.AuditTrailModule; +import org.elasticsearch.shield.authc.AuthenticationModule; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.shield.authc.Realms; import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.UsernamePasswordToken; +import org.elasticsearch.shield.authz.AuthorizationModule; import org.elasticsearch.shield.authz.store.FileRolesStore; +import org.elasticsearch.shield.crypto.CryptoModule; import org.elasticsearch.shield.crypto.InternalCryptoService; +import org.elasticsearch.shield.license.LicenseModule; import org.elasticsearch.shield.license.LicenseService; +import org.elasticsearch.shield.rest.ShieldRestModule; +import org.elasticsearch.shield.rest.action.RestShieldInfoAction; +import org.elasticsearch.shield.rest.action.authc.cache.RestClearRealmCacheAction; +import org.elasticsearch.shield.ssl.SSLModule; +import org.elasticsearch.shield.transport.ShieldClientTransportService; +import org.elasticsearch.shield.transport.ShieldServerTransportService; +import org.elasticsearch.shield.transport.ShieldTransportModule; import org.elasticsearch.shield.transport.filter.IPFilter; +import org.elasticsearch.shield.transport.netty.ShieldNettyHttpServerTransport; +import org.elasticsearch.shield.transport.netty.ShieldNettyTransport; +import org.elasticsearch.transport.TransportModule; import java.nio.file.Path; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -59,15 +82,31 @@ public class ShieldPlugin extends Plugin { @Override public Collection nodeModules() { - return enabled ? - Collections.singletonList(new ShieldModule(settings)) : - Collections.singletonList(new ShieldDisabledModule(settings)); + if (enabled == false) { + return Collections.singletonList(new ShieldDisabledModule(settings)); + } else if (clientMode) { + return Arrays.asList( + new ShieldTransportModule(settings), + new SSLModule(settings)); + } else { + return Arrays.asList( + new ShieldModule(settings), + new LicenseModule(settings), + new CryptoModule(settings), + new AuthenticationModule(settings), + new AuthorizationModule(settings), + new AuditTrailModule(settings), + new ShieldRestModule(settings), + new ShieldActionModule(settings), + new ShieldTransportModule(settings), + new SSLModule(settings)); + } } @Override public Collection> nodeServices() { ImmutableList.Builder> builder = ImmutableList.builder(); - if (enabled && !clientMode) { + if (enabled && clientMode == false) { builder.add(LicenseService.class).add(InternalCryptoService.class).add(FileRolesStore.class).add(Realms.class).add(IPFilter.class); } return builder.build(); @@ -75,7 +114,7 @@ public class ShieldPlugin extends Plugin { @Override public Settings additionalSettings() { - if (!enabled) { + if (enabled == false) { return Settings.EMPTY; } @@ -93,6 +132,45 @@ public class ShieldPlugin extends Plugin { clusterDynamicSettingsModule.registerClusterDynamicSetting(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING, Validator.EMPTY); } + public void onModule(ActionModule module) { + if (enabled == false) { + return; + } + // registering the security filter only for nodes + if (clientMode == false) { + module.registerFilter(ShieldActionFilter.class); + } + + // registering all shield actions + module.registerAction(ClearRealmCacheAction.INSTANCE, TransportClearRealmCacheAction.class); + } + + public void onModule(TransportModule module) { + if (enabled == false) { + return; + } + module.setTransport(ShieldNettyTransport.class, ShieldPlugin.NAME); + if (clientMode) { + module.setTransportService(ShieldClientTransportService.class, ShieldPlugin.NAME); + } else { + module.setTransportService(ShieldServerTransportService.class, ShieldPlugin.NAME); + } + } + + public void onModule(HttpServerModule module) { + if (enabled && clientMode == false) { + module.setHttpServerTransport(ShieldNettyHttpServerTransport.class, ShieldPlugin.NAME); + } + } + + public void onModule(RestModule module) { + if (enabled && clientMode == false) { + module.addRestAction(RestClearRealmCacheAction.class); + } + // we want to expose the shield rest action even when the plugin is disabled + module.addRestAction(RestShieldInfoAction.class); + } + private void addUserSettings(Settings.Builder settingsBuilder) { String authHeaderSettingName = Headers.PREFIX + "." + UsernamePasswordToken.BASIC_AUTH_HEADER; if (settings.get(authHeaderSettingName) != null) { diff --git a/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionModule.java b/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionModule.java index b6d0a13c358..8f5797b8314 100644 --- a/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/action/ShieldActionModule.java @@ -5,43 +5,19 @@ */ package org.elasticsearch.shield.action; -import org.elasticsearch.action.ActionModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.action.authc.cache.ClearRealmCacheAction; -import org.elasticsearch.shield.action.authc.cache.TransportClearRealmCacheAction; import org.elasticsearch.shield.support.AbstractShieldModule; -/** - * - */ -public class ShieldActionModule extends AbstractShieldModule implements PreProcessModule { +public class ShieldActionModule extends AbstractShieldModule.Node { public ShieldActionModule(Settings settings) { super(settings); } @Override - public void processModule(Module module) { - if (module instanceof ActionModule) { - - // registering the security filter only for nodes - if (!clientMode) { - ((ActionModule) module).registerFilter(ShieldActionFilter.class); - } - - // registering all shield actions - ((ActionModule) module).registerAction(ClearRealmCacheAction.INSTANCE, TransportClearRealmCacheAction.class); - } - } - - @Override - protected void configure(boolean clientMode) { - if (!clientMode) { - bind(ShieldActionMapper.class).asEagerSingleton(); - // we need to ensure that there's only a single instance of this filter. - bind(ShieldActionFilter.class).asEagerSingleton(); - } + protected void configureNode() { + bind(ShieldActionMapper.class).asEagerSingleton(); + // we need to ensure that there's only a single instance of this filter. + bind(ShieldActionFilter.class).asEagerSingleton(); } } diff --git a/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestModule.java b/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestModule.java index 62245d7c067..f04692d426a 100644 --- a/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/rest/ShieldRestModule.java @@ -5,18 +5,13 @@ */ package org.elasticsearch.shield.rest; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.rest.RestModule; -import org.elasticsearch.shield.rest.action.RestShieldInfoAction; -import org.elasticsearch.shield.rest.action.authc.cache.RestClearRealmCacheAction; import org.elasticsearch.shield.support.AbstractShieldModule; /** * */ -public class ShieldRestModule extends AbstractShieldModule.Node implements PreProcessModule { +public class ShieldRestModule extends AbstractShieldModule.Node { public ShieldRestModule(Settings settings) { super(settings); @@ -26,12 +21,4 @@ public class ShieldRestModule extends AbstractShieldModule.Node implements PrePr protected void configureNode() { bind(ShieldRestFilter.class).asEagerSingleton(); } - - @Override - public void processModule(Module module) { - if (module instanceof RestModule) { - ((RestModule) module).addRestAction(RestShieldInfoAction.class); - ((RestModule) module).addRestAction(RestClearRealmCacheAction.class); - } - } } diff --git a/shield/src/main/java/org/elasticsearch/shield/support/AbstractShieldModule.java b/shield/src/main/java/org/elasticsearch/shield/support/AbstractShieldModule.java index 98e38ad9a65..444d0506e98 100644 --- a/shield/src/main/java/org/elasticsearch/shield/support/AbstractShieldModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/support/AbstractShieldModule.java @@ -34,20 +34,6 @@ public abstract class AbstractShieldModule extends AbstractModule { protected abstract void configure(boolean clientMode); - public static abstract class Spawn extends AbstractShieldModule implements SpawnModules { - - protected Spawn(Settings settings) { - super(settings); - } - - @Override - public final Iterable spawnModules() { - return spawnModules(clientMode); - } - - public abstract Iterable spawnModules(boolean clientMode); - } - public static abstract class Node extends AbstractShieldModule { protected Node(Settings settings) { diff --git a/shield/src/main/java/org/elasticsearch/shield/transport/ShieldTransportModule.java b/shield/src/main/java/org/elasticsearch/shield/transport/ShieldTransportModule.java index 05fa1084469..cacbce6a034 100644 --- a/shield/src/main/java/org/elasticsearch/shield/transport/ShieldTransportModule.java +++ b/shield/src/main/java/org/elasticsearch/shield/transport/ShieldTransportModule.java @@ -5,50 +5,20 @@ */ package org.elasticsearch.shield.transport; -import com.google.common.collect.ImmutableList; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.ShieldPlugin; import org.elasticsearch.shield.support.AbstractShieldModule; import org.elasticsearch.shield.transport.filter.IPFilter; -import org.elasticsearch.shield.transport.netty.ShieldNettyHttpServerTransportModule; -import org.elasticsearch.shield.transport.netty.ShieldNettyTransportModule; -import org.elasticsearch.transport.TransportModule; /** * */ -public class ShieldTransportModule extends AbstractShieldModule.Spawn implements PreProcessModule { +public class ShieldTransportModule extends AbstractShieldModule { public ShieldTransportModule(Settings settings) { super(settings); } - @Override - public Iterable spawnModules(boolean clientMode) { - - if (clientMode) { - return ImmutableList.of(new ShieldNettyTransportModule(settings)); - } - - return ImmutableList.of( - new ShieldNettyHttpServerTransportModule(settings), - new ShieldNettyTransportModule(settings)); - } - - @Override - public void processModule(Module module) { - if (module instanceof TransportModule) { - if (clientMode) { - ((TransportModule) module).setTransportService(ShieldClientTransportService.class, ShieldPlugin.NAME); - } else { - ((TransportModule) module).setTransportService(ShieldServerTransportService.class, ShieldPlugin.NAME); - } - } - } - @Override protected void configure(boolean clientMode) { if (clientMode) { diff --git a/shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportModule.java b/shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportModule.java deleted file mode 100644 index 089bb009350..00000000000 --- a/shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyHttpServerTransportModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.shield.transport.netty; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.http.HttpServerModule; -import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.shield.support.AbstractShieldModule; - -/** - * - */ -public class ShieldNettyHttpServerTransportModule extends AbstractShieldModule implements PreProcessModule { - - public ShieldNettyHttpServerTransportModule(Settings settings) { - super(settings); - } - - @Override - public void processModule(Module module) { - if (module instanceof HttpServerModule) { - ((HttpServerModule) module).setHttpServerTransport(ShieldNettyHttpServerTransport.class, ShieldPlugin.NAME); - } - } - - @Override - protected void configure(boolean clientMode) { - } -} \ No newline at end of file diff --git a/shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyTransportModule.java b/shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyTransportModule.java deleted file mode 100644 index b3091f3db82..00000000000 --- a/shield/src/main/java/org/elasticsearch/shield/transport/netty/ShieldNettyTransportModule.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.shield.transport.netty; - -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.shield.ShieldPlugin; -import org.elasticsearch.shield.support.AbstractShieldModule; -import org.elasticsearch.transport.TransportModule; - -/** - * - */ -public class ShieldNettyTransportModule extends AbstractShieldModule implements PreProcessModule { - - public ShieldNettyTransportModule(Settings settings) { - super(settings); - } - - @Override - public void processModule(Module module) { - if (module instanceof TransportModule) { - ((TransportModule) module).setTransport(ShieldNettyTransport.class, ShieldPlugin.NAME); - } - } - - @Override - protected void configure(boolean clientMode) {} - -} \ No newline at end of file diff --git a/watcher/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java b/watcher/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java deleted file mode 100644 index ae4d7dd5b94..00000000000 --- a/watcher/src/main/java/org/elasticsearch/watcher/TransportClientWatcherModule.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.watcher; - - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.SpawnModules; -import org.elasticsearch.watcher.transport.WatcherTransportModule; - -import java.util.Collections; - - -public class TransportClientWatcherModule extends AbstractModule implements SpawnModules { - - @Override - public Iterable spawnModules() { - return Collections.singleton(new WatcherTransportModule()); - } - - @Override - protected void configure() { - } - -} diff --git a/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java b/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java index bdd6010f482..6f6d3dc8d08 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/WatcherModule.java @@ -7,36 +7,14 @@ package org.elasticsearch.watcher; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.watcher.actions.ActionModule; -import org.elasticsearch.watcher.client.WatcherClientModule; -import org.elasticsearch.watcher.condition.ConditionModule; -import org.elasticsearch.watcher.execution.ExecutionModule; -import org.elasticsearch.watcher.history.HistoryModule; -import org.elasticsearch.watcher.input.InputModule; -import org.elasticsearch.watcher.license.LicenseModule; -import org.elasticsearch.watcher.rest.WatcherRestModule; -import org.elasticsearch.watcher.shield.WatcherShieldModule; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; -import org.elasticsearch.watcher.support.clock.ClockModule; -import org.elasticsearch.watcher.support.http.HttpClientModule; -import org.elasticsearch.watcher.support.init.InitializingModule; -import org.elasticsearch.watcher.support.secret.SecretModule; -import org.elasticsearch.watcher.support.template.TemplateModule; import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation; -import org.elasticsearch.watcher.transform.TransformModule; -import org.elasticsearch.watcher.transport.WatcherTransportModule; -import org.elasticsearch.watcher.trigger.TriggerModule; -import org.elasticsearch.watcher.watch.WatchModule; - -import java.util.Arrays; -public class WatcherModule extends AbstractModule implements SpawnModules { +public class WatcherModule extends AbstractModule { public static final String HISTORY_TEMPLATE_NAME = "watch_history"; public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches"; @@ -54,29 +32,6 @@ public class WatcherModule extends AbstractModule implements SpawnModules { this.settings = settings; } - @Override - public Iterable spawnModules() { - return Arrays.asList( - new InitializingModule(), - new LicenseModule(), - new WatchModule(), - new TemplateModule(), - new HttpClientModule(), - new ClockModule(), - new WatcherClientModule(), - new TransformModule(), - new WatcherRestModule(), - new TriggerModule(settings), - new WatcherTransportModule(), - new ConditionModule(), - new InputModule(), - new ActionModule(), - new HistoryModule(), - new ExecutionModule(), - new WatcherShieldModule(settings), - new SecretModule(settings)); - } - @Override protected void configure() { bind(WatcherLifeCycleService.class).asEagerSingleton(); diff --git a/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java b/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java index a78fefdeb25..568fd7521db 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/WatcherPlugin.java @@ -6,6 +6,7 @@ package org.elasticsearch.watcher; import com.google.common.collect.ImmutableList; +import org.elasticsearch.action.ActionModule; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.metadata.MetaData; @@ -13,17 +14,60 @@ import org.elasticsearch.cluster.settings.Validator; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.rest.RestModule; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.script.ScriptModule; +import org.elasticsearch.watcher.actions.WatcherActionModule; import org.elasticsearch.watcher.actions.email.service.InternalEmailService; +import org.elasticsearch.watcher.client.WatcherClientModule; +import org.elasticsearch.watcher.condition.ConditionModule; +import org.elasticsearch.watcher.execution.ExecutionModule; import org.elasticsearch.watcher.history.HistoryModule; +import org.elasticsearch.watcher.input.InputModule; +import org.elasticsearch.watcher.license.LicenseModule; import org.elasticsearch.watcher.license.LicenseService; +import org.elasticsearch.watcher.rest.action.RestAckWatchAction; +import org.elasticsearch.watcher.rest.action.RestDeleteWatchAction; +import org.elasticsearch.watcher.rest.action.RestExecuteWatchAction; +import org.elasticsearch.watcher.rest.action.RestGetWatchAction; +import org.elasticsearch.watcher.rest.action.RestHijackOperationAction; +import org.elasticsearch.watcher.rest.action.RestPutWatchAction; +import org.elasticsearch.watcher.rest.action.RestWatchServiceAction; +import org.elasticsearch.watcher.rest.action.RestWatcherInfoAction; +import org.elasticsearch.watcher.rest.action.RestWatcherStatsAction; +import org.elasticsearch.watcher.shield.WatcherShieldModule; import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; +import org.elasticsearch.watcher.support.clock.ClockModule; import org.elasticsearch.watcher.support.http.HttpClient; +import org.elasticsearch.watcher.support.http.HttpClientModule; +import org.elasticsearch.watcher.support.init.InitializingModule; import org.elasticsearch.watcher.support.init.InitializingService; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.support.secret.SecretModule; +import org.elasticsearch.watcher.support.template.TemplateModule; +import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService; import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation; +import org.elasticsearch.watcher.transform.TransformModule; +import org.elasticsearch.watcher.transport.WatcherTransportModule; +import org.elasticsearch.watcher.transport.actions.ack.AckWatchAction; +import org.elasticsearch.watcher.transport.actions.ack.TransportAckWatchAction; +import org.elasticsearch.watcher.transport.actions.delete.DeleteWatchAction; +import org.elasticsearch.watcher.transport.actions.delete.TransportDeleteWatchAction; +import org.elasticsearch.watcher.transport.actions.execute.ExecuteWatchAction; +import org.elasticsearch.watcher.transport.actions.execute.TransportExecuteWatchAction; +import org.elasticsearch.watcher.transport.actions.get.GetWatchAction; +import org.elasticsearch.watcher.transport.actions.get.TransportGetWatchAction; +import org.elasticsearch.watcher.transport.actions.put.PutWatchAction; +import org.elasticsearch.watcher.transport.actions.put.TransportPutWatchAction; +import org.elasticsearch.watcher.transport.actions.service.TransportWatcherServiceAction; +import org.elasticsearch.watcher.transport.actions.service.WatcherServiceAction; +import org.elasticsearch.watcher.transport.actions.stats.TransportWatcherStatsAction; +import org.elasticsearch.watcher.transport.actions.stats.WatcherStatsAction; +import org.elasticsearch.watcher.trigger.TriggerModule; +import org.elasticsearch.watcher.trigger.schedule.ScheduleModule; +import org.elasticsearch.watcher.watch.WatchModule; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -58,15 +102,32 @@ public class WatcherPlugin extends Plugin { @Override public Collection nodeModules() { - if (!enabled) { - return ImmutableList.of(); + if (enabled == false) { + return Collections.emptyList(); + } else if (transportClient == false){ + return Arrays.asList( + new WatcherModule(settings), + new InitializingModule(), + new LicenseModule(), + new WatchModule(), + new TemplateModule(), + new HttpClientModule(), + new ClockModule(), + new WatcherClientModule(), + new TransformModule(), + new TriggerModule(settings), + new ScheduleModule(), + new ConditionModule(), + new InputModule(), + new WatcherActionModule(), + new HistoryModule(), + new ExecutionModule(), + new WatcherShieldModule(settings), + new SecretModule(settings)); } - return transportClient ? - Collections.singletonList(new TransportClientWatcherModule()) : - Collections.singletonList(new WatcherModule(settings)); + return Collections.emptyList(); } - @Override public Collection> nodeServices() { if (!enabled || transportClient) { @@ -97,6 +158,9 @@ public class WatcherPlugin extends Plugin { public void onModule(ScriptModule module) { module.registerScriptContext(ScriptServiceProxy.INSTANCE); + if (enabled && transportClient == false) { + module.addScriptEngine(XMustacheScriptEngineService.class); + } } public void onModule(ClusterModule module) { @@ -105,6 +169,32 @@ public class WatcherPlugin extends Plugin { } } + public void onModule(RestModule module) { + if (enabled && transportClient == false) { + module.addRestAction(RestPutWatchAction.class); + module.addRestAction(RestDeleteWatchAction.class); + module.addRestAction(RestWatcherStatsAction.class); + module.addRestAction(RestWatcherInfoAction.class); + module.addRestAction(RestGetWatchAction.class); + module.addRestAction(RestWatchServiceAction.class); + module.addRestAction(RestAckWatchAction.class); + module.addRestAction(RestExecuteWatchAction.class); + module.addRestAction(RestHijackOperationAction.class); + } + } + + public void onModule(ActionModule module) { + if (enabled) { + module.registerAction(PutWatchAction.INSTANCE, TransportPutWatchAction.class); + module.registerAction(DeleteWatchAction.INSTANCE, TransportDeleteWatchAction.class); + module.registerAction(GetWatchAction.INSTANCE, TransportGetWatchAction.class); + module.registerAction(WatcherStatsAction.INSTANCE, TransportWatcherStatsAction.class); + module.registerAction(AckWatchAction.INSTANCE, TransportAckWatchAction.class); + module.registerAction(WatcherServiceAction.INSTANCE, TransportWatcherServiceAction.class); + module.registerAction(ExecuteWatchAction.INSTANCE, TransportExecuteWatchAction.class); + } + } + public static boolean watcherEnabled(Settings settings) { return settings.getAsBoolean(ENABLED_SETTING, true); } diff --git a/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionModule.java b/watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java similarity index 97% rename from watcher/src/main/java/org/elasticsearch/watcher/actions/ActionModule.java rename to watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java index 0cab60ef466..d2647dbc0ab 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/actions/ActionModule.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/actions/WatcherActionModule.java @@ -24,7 +24,7 @@ import java.util.Map; /** */ -public class ActionModule extends AbstractModule { +public class WatcherActionModule extends AbstractModule { private final Map> parsers = new HashMap<>(); diff --git a/watcher/src/main/java/org/elasticsearch/watcher/rest/WatcherRestModule.java b/watcher/src/main/java/org/elasticsearch/watcher/rest/WatcherRestModule.java deleted file mode 100644 index 34df9a3b34c..00000000000 --- a/watcher/src/main/java/org/elasticsearch/watcher/rest/WatcherRestModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.watcher.rest; - -import org.elasticsearch.watcher.rest.action.*; -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; -import org.elasticsearch.rest.RestModule; - -/** - * - */ -public class WatcherRestModule extends AbstractModule implements PreProcessModule { - - @Override - public void processModule(Module module) { - if (module instanceof RestModule) { - RestModule restModule = (RestModule) module; - restModule.addRestAction(RestPutWatchAction.class); - restModule.addRestAction(RestDeleteWatchAction.class); - restModule.addRestAction(RestWatcherStatsAction.class); - restModule.addRestAction(RestWatcherInfoAction.class); - restModule.addRestAction(RestGetWatchAction.class); - restModule.addRestAction(RestWatchServiceAction.class); - restModule.addRestAction(RestAckWatchAction.class); - restModule.addRestAction(RestExecuteWatchAction.class); - restModule.addRestAction(RestHijackOperationAction.class); - } - } - - @Override - protected void configure() { - } -} diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java index 5441f423878..c97d5f45996 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/support/http/HttpClientModule.java @@ -6,27 +6,29 @@ package org.elasticsearch.watcher.support.http; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.SpawnModules; -import org.elasticsearch.watcher.support.http.auth.AuthModule; - -import java.util.Collections; +import org.elasticsearch.common.inject.multibindings.MapBinder; +import org.elasticsearch.watcher.support.http.auth.HttpAuthFactory; +import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry; +import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth; +import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory; /** */ -public class HttpClientModule extends AbstractModule implements SpawnModules { - - @Override - public Iterable spawnModules() { - return Collections.singletonList(new AuthModule()); - } +public class HttpClientModule extends AbstractModule { @Override protected void configure() { bind(HttpRequestTemplate.Parser.class).asEagerSingleton(); bind(HttpRequest.Parser.class).asEagerSingleton(); bind(HttpClient.class).asEagerSingleton(); + + MapBinder parsersBinder = MapBinder.newMapBinder(binder(), String.class, HttpAuthFactory.class); + + bind(BasicAuthFactory.class).asEagerSingleton(); + parsersBinder.addBinding(BasicAuth.TYPE).to(BasicAuthFactory.class); + + bind(HttpAuthRegistry.class).asEagerSingleton(); } } diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/http/auth/AuthModule.java b/watcher/src/main/java/org/elasticsearch/watcher/support/http/auth/AuthModule.java deleted file mode 100644 index 91fb4de34cf..00000000000 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/http/auth/AuthModule.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.watcher.support.http.auth; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.MapBinder; -import org.elasticsearch.watcher.support.http.auth.basic.ApplicableBasicAuth; -import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth; -import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory; - -/** - */ -public class AuthModule extends AbstractModule { - - @Override - protected void configure() { - - MapBinder parsersBinder = MapBinder.newMapBinder(binder(), String.class, HttpAuthFactory.class); - - bind(BasicAuthFactory.class).asEagerSingleton(); - parsersBinder.addBinding(BasicAuth.TYPE).to(BasicAuthFactory.class); - - bind(HttpAuthRegistry.class).asEagerSingleton(); - } -} diff --git a/watcher/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java b/watcher/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java index 773a2feeef9..eb8dd26f25d 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/support/template/TemplateModule.java @@ -6,25 +6,12 @@ package org.elasticsearch.watcher.support.template; import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.inject.PreProcessModule; -import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptModule; -import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; -import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService; import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine; /** * */ -public class TemplateModule extends AbstractModule implements PreProcessModule { - - @Override - public void processModule(Module module) { - if (module instanceof ScriptModule) { - ((ScriptModule) module).addScriptEngine(XMustacheScriptEngineService.class); - } - } +public class TemplateModule extends AbstractModule { @Override protected void configure() { diff --git a/watcher/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java b/watcher/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java index a9f0b080603..e8922a44a16 100644 --- a/watcher/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java +++ b/watcher/src/main/java/org/elasticsearch/watcher/trigger/TriggerModule.java @@ -20,7 +20,7 @@ import java.util.Set; /** * */ -public class TriggerModule extends AbstractModule implements SpawnModules { +public class TriggerModule extends AbstractModule { private final Settings settings; private final Set> engines = new HashSet<>(); @@ -39,11 +39,6 @@ public class TriggerModule extends AbstractModule implements SpawnModules { registerEngine(ManualTriggerEngine.class); } - @Override - public Iterable spawnModules() { - return Collections.singleton(new ScheduleModule()); - } - @Override protected void configure() { diff --git a/watcher/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java b/watcher/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java index 2953c5f6e41..3228970c2f1 100644 --- a/watcher/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java +++ b/watcher/src/test/java/org/elasticsearch/watcher/actions/ActionErrorIntegrationTests.java @@ -128,7 +128,7 @@ public class ActionErrorIntegrationTests extends AbstractWatcherIntegrationTests return name(); } - public void onModule(ActionModule module) { + public void onModule(WatcherActionModule module) { module.registerAction(ErrorAction.TYPE, ErrorAction.Factory.class); } } diff --git a/watcher/src/test/java/org/elasticsearch/watcher/test/TimeWarpedWatcherPlugin.java b/watcher/src/test/java/org/elasticsearch/watcher/test/TimeWarpedWatcherPlugin.java index 20edfd86934..c0ad25f6ec3 100644 --- a/watcher/src/test/java/org/elasticsearch/watcher/test/TimeWarpedWatcherPlugin.java +++ b/watcher/src/test/java/org/elasticsearch/watcher/test/TimeWarpedWatcherPlugin.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.watcher.test; -import com.google.common.collect.ImmutableList; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; @@ -18,13 +17,13 @@ import org.elasticsearch.watcher.support.clock.Clock; import org.elasticsearch.watcher.support.clock.ClockMock; import org.elasticsearch.watcher.support.clock.ClockModule; import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; +import org.elasticsearch.watcher.test.bench.WatcherExecutorServiceBenchmark; import org.elasticsearch.watcher.trigger.ScheduleTriggerEngineMock; import org.elasticsearch.watcher.trigger.TriggerModule; import org.elasticsearch.watcher.trigger.manual.ManualTriggerEngine; import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; @@ -45,94 +44,71 @@ public class TimeWarpedWatcherPlugin extends WatcherPlugin { if (!enabled) { return super.nodeModules(); } - return Collections.singletonList(new WatcherModule(settings)); + List modules = new ArrayList<>(super.nodeModules()); + for (int i = 0; i < modules.size(); ++i) { + Module module = modules.get(i); + if (module instanceof TriggerModule) { + // replacing scheduler module so we'll + // have control on when it fires a job + modules.set(i, new MockTriggerModule(settings)); + } else if (module instanceof ClockModule) { + // replacing the clock module so we'll be able + // to control time in tests + modules.set(i, new MockClockModule()); + } else if (module instanceof ExecutionModule) { + // replacing the execution module so all the watches will be + // executed on the same thread as the trigger engine + modules.set(i, new MockExecutionModule()); + } + } + return modules; } - /** - * - */ - public static class WatcherModule extends org.elasticsearch.watcher.WatcherModule { - public WatcherModule(Settings settings) { + public static class MockTriggerModule extends TriggerModule { + + public MockTriggerModule(Settings settings) { super(settings); } @Override - public Iterable spawnModules() { - List modules = new ArrayList<>(); - for (Module module : super.spawnModules()) { - - if (module instanceof TriggerModule) { - // replacing scheduler module so we'll - // have control on when it fires a job - modules.add(new MockTriggerModule(settings)); - - } else if (module instanceof ClockModule) { - // replacing the clock module so we'll be able - // to control time in tests - modules.add(new MockClockModule()); - - } else if (module instanceof ExecutionModule) { - // replacing the execution module so all the watches will be - // executed on the same thread as the trigger engine - modules.add(new MockExecutionModule()); - - } else { - modules.add(module); - } - } - return modules; - } - - public static class MockTriggerModule extends TriggerModule { - - public MockTriggerModule(Settings settings) { - super(settings); - } - - @Override - protected void registerStandardEngines() { - registerEngine(ScheduleTriggerEngineMock.class); - registerEngine(ManualTriggerEngine.class); - } - } - - public static class MockClockModule extends ClockModule { - @Override - protected void configure() { - bind(ClockMock.class).asEagerSingleton(); - bind(Clock.class).to(ClockMock.class); - } - } - - public static class MockExecutionModule extends ExecutionModule { - - public MockExecutionModule() { - super(SameThreadExecutor.class, SyncTriggerListener.class); - } - - public static class SameThreadExecutor implements WatchExecutor { - - @Override - public BlockingQueue queue() { - return new ArrayBlockingQueue<>(1); - } - - @Override - public long largestPoolSize() { - return 1; - } - - @Override - public void execute(Runnable runnable) { - runnable.run(); - } - } + protected void registerStandardEngines() { + registerEngine(ScheduleTriggerEngineMock.class); + registerEngine(ManualTriggerEngine.class); } } - public void onModule(ScriptModule module) { - module.registerScriptContext(ScriptServiceProxy.INSTANCE); + public static class MockClockModule extends ClockModule { + @Override + protected void configure() { + bind(ClockMock.class).asEagerSingleton(); + bind(Clock.class).to(ClockMock.class); + } + } + + public static class MockExecutionModule extends ExecutionModule { + + public MockExecutionModule() { + super(SameThreadExecutor.class, SyncTriggerListener.class); + } + + public static class SameThreadExecutor implements WatchExecutor { + + @Override + public BlockingQueue queue() { + return new ArrayBlockingQueue<>(1); + } + + @Override + public long largestPoolSize() { + return 1; + } + + @Override + public void execute(Runnable runnable) { + runnable.run(); + } + } } } diff --git a/watcher/src/test/java/org/elasticsearch/watcher/test/bench/WatcherExecutorServiceBenchmark.java b/watcher/src/test/java/org/elasticsearch/watcher/test/bench/WatcherExecutorServiceBenchmark.java index 31affce8e1c..5dc9c0a6b5d 100644 --- a/watcher/src/test/java/org/elasticsearch/watcher/test/bench/WatcherExecutorServiceBenchmark.java +++ b/watcher/src/test/java/org/elasticsearch/watcher/test/bench/WatcherExecutorServiceBenchmark.java @@ -213,43 +213,29 @@ public class WatcherExecutorServiceBenchmark { @Override public Collection nodeModules() { - return Collections.singletonList(new WatcherModule(settings)); + List modules = new ArrayList<>(super.nodeModules()); + for (int i = 0; i < modules.size(); ++i) { + Module module = modules.get(i); + if (module instanceof TriggerModule) { + // replacing scheduler module so we'll + // have control on when it fires a job + modules.set(i, new MockTriggerModule(settings)); + } + } + return modules; } - public static class WatcherModule extends org.elasticsearch.watcher.WatcherModule { + public static class MockTriggerModule extends TriggerModule { - public WatcherModule(Settings settings) { + public MockTriggerModule(Settings settings) { super(settings); } @Override - public Iterable spawnModules() { - List modules = new ArrayList<>(); - for (Module module : super.spawnModules()) { - if (module instanceof TriggerModule) { - // replacing scheduler module so we'll - // have control on when it fires a job - modules.add(new MockTriggerModule(settings)); - - } else { - modules.add(module); - } - } - return modules; + protected void registerStandardEngines() { + registerEngine(ScheduleTriggerEngineMock.class); } - public static class MockTriggerModule extends TriggerModule { - - public MockTriggerModule(Settings settings) { - super(settings); - } - - @Override - protected void registerStandardEngines() { - registerEngine(ScheduleTriggerEngineMock.class); - } - - } } }