Merge pull request elastic/elasticsearch#472 from rjernst/despawn

Remove uses of SpawnModules

Original commit: elastic/x-pack-elasticsearch@09b719e9c0
This commit is contained in:
Ryan Ernst 2015-08-19 08:56:43 -07:00
commit 804cf68031
25 changed files with 292 additions and 535 deletions

View File

@ -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<? extends Module> spawnModules() {
return ImmutableList.of(
new MarvelSettingsModule(),
new LicenseModule(),
new CollectorModule(),
new ExporterModule(),
new RendererModule());
}
}

View File

@ -15,13 +15,19 @@ import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.AgentService; 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.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.MarvelSetting;
import org.elasticsearch.marvel.agent.settings.MarvelSettings; import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.license.LicenseService; import org.elasticsearch.marvel.license.LicenseService;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.tribe.TribeService; import org.elasticsearch.tribe.TribeService;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -57,7 +63,12 @@ public class MarvelPlugin extends Plugin {
if (!enabled) { if (!enabled) {
return Collections.emptyList(); return Collections.emptyList();
} }
return Collections.<Module>singletonList(new MarvelModule()); return Arrays.<Module>asList(
new MarvelModule(),
new LicenseModule(),
new CollectorModule(),
new ExporterModule(),
new RendererModule());
} }
@Override @Override

View File

@ -6,11 +6,13 @@
package org.elasticsearch.marvel.agent.settings; package org.elasticsearch.marvel.agent.settings;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.marvel.agent.AgentService;
public class MarvelSettingsModule extends AbstractModule { public class MarvelModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
bind(MarvelSettings.class).asEagerSingleton(); bind(MarvelSettings.class).asEagerSingleton();
bind(AgentService.class).asEagerSingleton();
} }
} }

View File

@ -39,7 +39,7 @@ public class MarvelPluginClientTests extends ESTestCase {
MarvelPlugin plugin = new MarvelPlugin(settings); MarvelPlugin plugin = new MarvelPlugin(settings);
assertThat(plugin.isEnabled(), is(true)); assertThat(plugin.isEnabled(), is(true));
Collection<Module> modules = plugin.nodeModules(); Collection<Module> modules = plugin.nodeModules();
assertThat(modules.size(), is(1)); assertThat(modules.size(), is(5));
} }
} }

View File

@ -5,16 +5,12 @@
*/ */
package org.elasticsearch.shield; 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.inject.util.Providers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.shield.license.LicenseService; import org.elasticsearch.shield.license.LicenseService;
import org.elasticsearch.shield.rest.action.RestShieldInfoAction;
import org.elasticsearch.shield.support.AbstractShieldModule; import org.elasticsearch.shield.support.AbstractShieldModule;
public class ShieldDisabledModule extends AbstractShieldModule implements PreProcessModule { public class ShieldDisabledModule extends AbstractShieldModule {
public ShieldDisabledModule(Settings settings) { public ShieldDisabledModule(Settings settings) {
super(settings); super(settings);
@ -28,12 +24,4 @@ public class ShieldDisabledModule extends AbstractShieldModule implements PrePro
bind(LicenseService.class).toProvider(Providers.<LicenseService>of(null)); bind(LicenseService.class).toProvider(Providers.<LicenseService>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);
}
}
} }

View File

@ -5,53 +5,18 @@
*/ */
package org.elasticsearch.shield; 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.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.support.AbstractShieldModule;
import org.elasticsearch.shield.transport.ShieldTransportModule;
/** /**
* *
*/ */
public class ShieldModule extends AbstractShieldModule.Spawn { public class ShieldModule extends AbstractShieldModule {
public ShieldModule(Settings settings) { public ShieldModule(Settings settings) {
super(settings); super(settings);
} }
@Override
public Iterable<? extends Module> 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.<Module>of(
new ShieldActionModule(settings),
new ShieldTransportModule(settings),
new SSLModule(settings));
}
return ImmutableList.<Module>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 @Override
protected void configure(boolean clientMode) { protected void configure(boolean clientMode) {
if (!clientMode) { if (!clientMode) {

View File

@ -6,6 +6,7 @@
package org.elasticsearch.shield; package org.elasticsearch.shield;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.ActionModule;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.client.support.Headers; import org.elasticsearch.client.support.Headers;
import org.elasticsearch.cluster.ClusterModule; 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.inject.Module;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment; 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.plugins.Plugin;
import org.elasticsearch.shield.authc.Realms; import org.elasticsearch.shield.authc.Realms;
import org.elasticsearch.shield.authc.support.SecuredString; import org.elasticsearch.shield.authc.support.SecuredString;
import org.elasticsearch.shield.authc.support.UsernamePasswordToken; import org.elasticsearch.shield.authc.support.UsernamePasswordToken;
import org.elasticsearch.shield.authz.AuthorizationModule;
import org.elasticsearch.shield.authz.store.FileRolesStore; import org.elasticsearch.shield.authz.store.FileRolesStore;
import org.elasticsearch.shield.crypto.CryptoModule;
import org.elasticsearch.shield.crypto.InternalCryptoService; import org.elasticsearch.shield.crypto.InternalCryptoService;
import org.elasticsearch.shield.license.LicenseModule;
import org.elasticsearch.shield.license.LicenseService; 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.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.nio.file.Path;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -59,15 +82,31 @@ public class ShieldPlugin extends Plugin {
@Override @Override
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
return enabled ? if (enabled == false) {
Collections.<Module>singletonList(new ShieldModule(settings)) : return Collections.<Module>singletonList(new ShieldDisabledModule(settings));
Collections.<Module>singletonList(new ShieldDisabledModule(settings)); } else if (clientMode) {
return Arrays.<Module>asList(
new ShieldTransportModule(settings),
new SSLModule(settings));
} else {
return Arrays.<Module>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 @Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
ImmutableList.Builder<Class<? extends LifecycleComponent>> builder = ImmutableList.builder(); ImmutableList.Builder<Class<? extends LifecycleComponent>> 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); builder.add(LicenseService.class).add(InternalCryptoService.class).add(FileRolesStore.class).add(Realms.class).add(IPFilter.class);
} }
return builder.build(); return builder.build();
@ -75,7 +114,7 @@ public class ShieldPlugin extends Plugin {
@Override @Override
public Settings additionalSettings() { public Settings additionalSettings() {
if (!enabled) { if (enabled == false) {
return Settings.EMPTY; return Settings.EMPTY;
} }
@ -93,6 +132,45 @@ public class ShieldPlugin extends Plugin {
clusterDynamicSettingsModule.registerClusterDynamicSetting(IPFilter.IP_FILTER_ENABLED_HTTP_SETTING, Validator.EMPTY); 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) { private void addUserSettings(Settings.Builder settingsBuilder) {
String authHeaderSettingName = Headers.PREFIX + "." + UsernamePasswordToken.BASIC_AUTH_HEADER; String authHeaderSettingName = Headers.PREFIX + "." + UsernamePasswordToken.BASIC_AUTH_HEADER;
if (settings.get(authHeaderSettingName) != null) { if (settings.get(authHeaderSettingName) != null) {

View File

@ -5,43 +5,19 @@
*/ */
package org.elasticsearch.shield.action; 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.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; import org.elasticsearch.shield.support.AbstractShieldModule;
/** public class ShieldActionModule extends AbstractShieldModule.Node {
*
*/
public class ShieldActionModule extends AbstractShieldModule implements PreProcessModule {
public ShieldActionModule(Settings settings) { public ShieldActionModule(Settings settings) {
super(settings); super(settings);
} }
@Override @Override
public void processModule(Module module) { protected void configureNode() {
if (module instanceof ActionModule) { bind(ShieldActionMapper.class).asEagerSingleton();
// we need to ensure that there's only a single instance of this filter.
// registering the security filter only for nodes bind(ShieldActionFilter.class).asEagerSingleton();
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();
}
} }
} }

View File

@ -5,18 +5,13 @@
*/ */
package org.elasticsearch.shield.rest; 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.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; import org.elasticsearch.shield.support.AbstractShieldModule;
/** /**
* *
*/ */
public class ShieldRestModule extends AbstractShieldModule.Node implements PreProcessModule { public class ShieldRestModule extends AbstractShieldModule.Node {
public ShieldRestModule(Settings settings) { public ShieldRestModule(Settings settings) {
super(settings); super(settings);
@ -26,12 +21,4 @@ public class ShieldRestModule extends AbstractShieldModule.Node implements PrePr
protected void configureNode() { protected void configureNode() {
bind(ShieldRestFilter.class).asEagerSingleton(); bind(ShieldRestFilter.class).asEagerSingleton();
} }
@Override
public void processModule(Module module) {
if (module instanceof RestModule) {
((RestModule) module).addRestAction(RestShieldInfoAction.class);
((RestModule) module).addRestAction(RestClearRealmCacheAction.class);
}
}
} }

View File

@ -34,20 +34,6 @@ public abstract class AbstractShieldModule extends AbstractModule {
protected abstract void configure(boolean clientMode); 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<? extends Module> spawnModules() {
return spawnModules(clientMode);
}
public abstract Iterable<? extends Module> spawnModules(boolean clientMode);
}
public static abstract class Node extends AbstractShieldModule { public static abstract class Node extends AbstractShieldModule {
protected Node(Settings settings) { protected Node(Settings settings) {

View File

@ -5,50 +5,20 @@
*/ */
package org.elasticsearch.shield.transport; 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.inject.util.Providers;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.shield.ShieldPlugin;
import org.elasticsearch.shield.support.AbstractShieldModule; import org.elasticsearch.shield.support.AbstractShieldModule;
import org.elasticsearch.shield.transport.filter.IPFilter; 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) { public ShieldTransportModule(Settings settings) {
super(settings); super(settings);
} }
@Override
public Iterable<? extends Module> 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 @Override
protected void configure(boolean clientMode) { protected void configure(boolean clientMode) {
if (clientMode) { if (clientMode) {

View File

@ -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) {
}
}

View File

@ -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) {}
}

View File

@ -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<? extends Module> spawnModules() {
return Collections.singleton(new WatcherTransportModule());
}
@Override
protected void configure() {
}
}

View File

@ -7,36 +7,14 @@ package org.elasticsearch.watcher;
import org.elasticsearch.common.inject.AbstractModule; 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.inject.multibindings.Multibinder;
import org.elasticsearch.common.settings.Settings; 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;
import org.elasticsearch.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; 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.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 HISTORY_TEMPLATE_NAME = "watch_history";
public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches"; public static final String TRIGGERED_TEMPLATE_NAME = "triggered_watches";
@ -54,29 +32,6 @@ public class WatcherModule extends AbstractModule implements SpawnModules {
this.settings = settings; this.settings = settings;
} }
@Override
public Iterable<? extends Module> 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 @Override
protected void configure() { protected void configure() {
bind(WatcherLifeCycleService.class).asEagerSingleton(); bind(WatcherLifeCycleService.class).asEagerSingleton();

View File

@ -6,6 +6,7 @@
package org.elasticsearch.watcher; package org.elasticsearch.watcher;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import org.elasticsearch.action.ActionModule;
import org.elasticsearch.client.Client; import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterModule;
import org.elasticsearch.cluster.metadata.MetaData; 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.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.rest.RestModule;
import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptModule; import org.elasticsearch.script.ScriptModule;
import org.elasticsearch.watcher.actions.WatcherActionModule;
import org.elasticsearch.watcher.actions.email.service.InternalEmailService; 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.history.HistoryModule;
import org.elasticsearch.watcher.input.InputModule;
import org.elasticsearch.watcher.license.LicenseModule;
import org.elasticsearch.watcher.license.LicenseService; 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.WatcherIndexTemplateRegistry.TemplateConfig;
import org.elasticsearch.watcher.support.clock.ClockModule;
import org.elasticsearch.watcher.support.http.HttpClient; 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.InitializingService;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; 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.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.Collection;
import java.util.Collections; import java.util.Collections;
@ -58,15 +102,32 @@ public class WatcherPlugin extends Plugin {
@Override @Override
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
if (!enabled) { if (enabled == false) {
return ImmutableList.of(); return Collections.emptyList();
} else if (transportClient == false){
return Arrays.<Module>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 ? return Collections.emptyList();
Collections.<Module>singletonList(new TransportClientWatcherModule()) :
Collections.<Module>singletonList(new WatcherModule(settings));
} }
@Override @Override
public Collection<Class<? extends LifecycleComponent>> nodeServices() { public Collection<Class<? extends LifecycleComponent>> nodeServices() {
if (!enabled || transportClient) { if (!enabled || transportClient) {
@ -97,6 +158,9 @@ public class WatcherPlugin extends Plugin {
public void onModule(ScriptModule module) { public void onModule(ScriptModule module) {
module.registerScriptContext(ScriptServiceProxy.INSTANCE); module.registerScriptContext(ScriptServiceProxy.INSTANCE);
if (enabled && transportClient == false) {
module.addScriptEngine(XMustacheScriptEngineService.class);
}
} }
public void onModule(ClusterModule module) { 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) { public static boolean watcherEnabled(Settings settings) {
return settings.getAsBoolean(ENABLED_SETTING, true); return settings.getAsBoolean(ENABLED_SETTING, true);
} }

View File

@ -24,7 +24,7 @@ import java.util.Map;
/** /**
*/ */
public class ActionModule extends AbstractModule { public class WatcherActionModule extends AbstractModule {
private final Map<String, Class<? extends ActionFactory>> parsers = new HashMap<>(); private final Map<String, Class<? extends ActionFactory>> parsers = new HashMap<>();

View File

@ -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() {
}
}

View File

@ -6,27 +6,29 @@
package org.elasticsearch.watcher.support.http; package org.elasticsearch.watcher.support.http;
import org.elasticsearch.common.inject.AbstractModule; import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.multibindings.MapBinder;
import org.elasticsearch.common.inject.SpawnModules; import org.elasticsearch.watcher.support.http.auth.HttpAuthFactory;
import org.elasticsearch.watcher.support.http.auth.AuthModule; import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
import java.util.Collections; import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
/** /**
*/ */
public class HttpClientModule extends AbstractModule implements SpawnModules { public class HttpClientModule extends AbstractModule {
@Override
public Iterable<? extends Module> spawnModules() {
return Collections.singletonList(new AuthModule());
}
@Override @Override
protected void configure() { protected void configure() {
bind(HttpRequestTemplate.Parser.class).asEagerSingleton(); bind(HttpRequestTemplate.Parser.class).asEagerSingleton();
bind(HttpRequest.Parser.class).asEagerSingleton(); bind(HttpRequest.Parser.class).asEagerSingleton();
bind(HttpClient.class).asEagerSingleton(); bind(HttpClient.class).asEagerSingleton();
MapBinder<String, HttpAuthFactory> parsersBinder = MapBinder.newMapBinder(binder(), String.class, HttpAuthFactory.class);
bind(BasicAuthFactory.class).asEagerSingleton();
parsersBinder.addBinding(BasicAuth.TYPE).to(BasicAuthFactory.class);
bind(HttpAuthRegistry.class).asEagerSingleton();
} }
} }

View File

@ -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<String, HttpAuthFactory> parsersBinder = MapBinder.newMapBinder(binder(), String.class, HttpAuthFactory.class);
bind(BasicAuthFactory.class).asEagerSingleton();
parsersBinder.addBinding(BasicAuth.TYPE).to(BasicAuthFactory.class);
bind(HttpAuthRegistry.class).asEagerSingleton();
}
}

View File

@ -6,25 +6,12 @@
package org.elasticsearch.watcher.support.template; package org.elasticsearch.watcher.support.template;
import org.elasticsearch.common.inject.AbstractModule; 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; import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine;
/** /**
* *
*/ */
public class TemplateModule extends AbstractModule implements PreProcessModule { public class TemplateModule extends AbstractModule {
@Override
public void processModule(Module module) {
if (module instanceof ScriptModule) {
((ScriptModule) module).addScriptEngine(XMustacheScriptEngineService.class);
}
}
@Override @Override
protected void configure() { protected void configure() {

View File

@ -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 Settings settings;
private final Set<Class<? extends TriggerEngine>> engines = new HashSet<>(); private final Set<Class<? extends TriggerEngine>> engines = new HashSet<>();
@ -39,11 +39,6 @@ public class TriggerModule extends AbstractModule implements SpawnModules {
registerEngine(ManualTriggerEngine.class); registerEngine(ManualTriggerEngine.class);
} }
@Override
public Iterable<? extends Module> spawnModules() {
return Collections.singleton(new ScheduleModule());
}
@Override @Override
protected void configure() { protected void configure() {

View File

@ -128,7 +128,7 @@ public class ActionErrorIntegrationTests extends AbstractWatcherIntegrationTests
return name(); return name();
} }
public void onModule(ActionModule module) { public void onModule(WatcherActionModule module) {
module.registerAction(ErrorAction.TYPE, ErrorAction.Factory.class); module.registerAction(ErrorAction.TYPE, ErrorAction.Factory.class);
} }
} }

View File

@ -5,7 +5,6 @@
*/ */
package org.elasticsearch.watcher.test; package org.elasticsearch.watcher.test;
import com.google.common.collect.ImmutableList;
import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings; 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.ClockMock;
import org.elasticsearch.watcher.support.clock.ClockModule; import org.elasticsearch.watcher.support.clock.ClockModule;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy; 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.ScheduleTriggerEngineMock;
import org.elasticsearch.watcher.trigger.TriggerModule; import org.elasticsearch.watcher.trigger.TriggerModule;
import org.elasticsearch.watcher.trigger.manual.ManualTriggerEngine; import org.elasticsearch.watcher.trigger.manual.ManualTriggerEngine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue; import java.util.concurrent.BlockingQueue;
@ -45,94 +44,71 @@ public class TimeWarpedWatcherPlugin extends WatcherPlugin {
if (!enabled) { if (!enabled) {
return super.nodeModules(); return super.nodeModules();
} }
return Collections.<Module>singletonList(new WatcherModule(settings)); List<Module> 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); super(settings);
} }
@Override @Override
public Iterable<? extends Module> spawnModules() { protected void registerStandardEngines() {
List<Module> modules = new ArrayList<>(); registerEngine(ScheduleTriggerEngineMock.class);
for (Module module : super.spawnModules()) { registerEngine(ManualTriggerEngine.class);
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<Runnable> queue() {
return new ArrayBlockingQueue<>(1);
}
@Override
public long largestPoolSize() {
return 1;
}
@Override
public void execute(Runnable runnable) {
runnable.run();
}
}
} }
} }
public void onModule(ScriptModule module) { public static class MockClockModule extends ClockModule {
module.registerScriptContext(ScriptServiceProxy.INSTANCE); @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<Runnable> queue() {
return new ArrayBlockingQueue<>(1);
}
@Override
public long largestPoolSize() {
return 1;
}
@Override
public void execute(Runnable runnable) {
runnable.run();
}
}
} }
} }

View File

@ -213,43 +213,29 @@ public class WatcherExecutorServiceBenchmark {
@Override @Override
public Collection<Module> nodeModules() { public Collection<Module> nodeModules() {
return Collections.<Module>singletonList(new WatcherModule(settings)); List<Module> 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); super(settings);
} }
@Override @Override
public Iterable<? extends Module> spawnModules() { protected void registerStandardEngines() {
List<Module> modules = new ArrayList<>(); registerEngine(ScheduleTriggerEngineMock.class);
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;
} }
public static class MockTriggerModule extends TriggerModule {
public MockTriggerModule(Settings settings) {
super(settings);
}
@Override
protected void registerStandardEngines() {
registerEngine(ScheduleTriggerEngineMock.class);
}
}
} }
} }