diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java index 4ec351b8ee6..03dedea4aaa 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/Monitoring.java @@ -9,7 +9,6 @@ import org.elasticsearch.action.ActionModule; import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.network.NetworkModule; -import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.marvel.action.MonitoringBulkAction; @@ -20,9 +19,7 @@ import org.elasticsearch.marvel.agent.exporter.ExporterModule; import org.elasticsearch.marvel.cleaner.CleanerService; import org.elasticsearch.marvel.client.MonitoringClientModule; import org.elasticsearch.marvel.rest.action.RestMonitoringBulkAction; -import org.elasticsearch.marvel.support.init.proxy.MonitoringClientProxy; import org.elasticsearch.xpack.XPackPlugin; -import org.elasticsearch.xpack.common.init.LazyInitializationModule; import java.util.ArrayList; import java.util.Arrays; @@ -80,9 +77,6 @@ public class Monitoring { CleanerService.class); } - public void onModule(SettingsModule module) { - } - public void onModule(ActionModule module) { if (enabled && tribeNode == false) { module.registerAction(MonitoringBulkAction.INSTANCE, TransportMonitoringBulkAction.class); @@ -95,12 +89,6 @@ public class Monitoring { } } - public void onModule(LazyInitializationModule module) { - if (enabled && tribeNode == false) { - module.registerLazyInitializable(MonitoringClientProxy.class); - } - } - public static boolean enabled(Settings settings) { return MonitoringSettings.ENABLED.get(settings); } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalBulk.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalBulk.java index 84e51538398..0402c447c15 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalBulk.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalBulk.java @@ -16,7 +16,7 @@ import org.elasticsearch.marvel.agent.exporter.ExportException; import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.agent.resolver.ResolversRegistry; -import org.elasticsearch.marvel.support.init.proxy.MonitoringClientProxy; +import org.elasticsearch.xpack.common.init.proxy.ClientProxy; import java.util.Arrays; import java.util.Collection; @@ -28,13 +28,13 @@ import java.util.Collection; public class LocalBulk extends ExportBulk { private final ESLogger logger; - private final MonitoringClientProxy client; + private final ClientProxy client; private final ResolversRegistry resolvers; private BulkRequestBuilder requestBuilder; - public LocalBulk(String name, ESLogger logger, MonitoringClientProxy client, ResolversRegistry resolvers) { + public LocalBulk(String name, ESLogger logger, ClientProxy client, ResolversRegistry resolvers) { super(name); this.logger = logger; this.client = client; diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java index 9412156ca7d..709e55c4901 100644 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java +++ b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/agent/exporter/local/LocalExporter.java @@ -30,7 +30,8 @@ import org.elasticsearch.marvel.agent.exporter.MonitoringDoc; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolver; import org.elasticsearch.marvel.agent.resolver.ResolversRegistry; import org.elasticsearch.marvel.cleaner.CleanerService; -import org.elasticsearch.marvel.support.init.proxy.MonitoringClientProxy; +import org.elasticsearch.xpack.common.init.proxy.ClientProxy; +import org.elasticsearch.xpack.security.InternalClient; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; @@ -50,14 +51,14 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle public static final String TYPE = "local"; - private final MonitoringClientProxy client; + private final ClientProxy client; private final ClusterService clusterService; private final ResolversRegistry resolvers; private final CleanerService cleanerService; private final AtomicReference state = new AtomicReference<>(State.INITIALIZED); - public LocalExporter(Exporter.Config config, MonitoringClientProxy client, + public LocalExporter(Exporter.Config config, ClientProxy client, ClusterService clusterService, CleanerService cleanerService) { super(TYPE, config); this.client = client; @@ -303,14 +304,14 @@ public class LocalExporter extends Exporter implements ClusterStateListener, Cle public static class Factory extends Exporter.Factory { - private final MonitoringClientProxy client; + private final ClientProxy client; private final ClusterService clusterService; private final CleanerService cleanerService; @Inject - public Factory(MonitoringClientProxy client, ClusterService clusterService, CleanerService cleanerService) { + public Factory(InternalClient client, ClusterService clusterService, CleanerService cleanerService) { super(TYPE, true); - this.client = client; + this.client = new ClientProxy(client); this.clusterService = clusterService; this.cleanerService = cleanerService; } diff --git a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/support/init/proxy/MonitoringClientProxy.java b/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/support/init/proxy/MonitoringClientProxy.java deleted file mode 100644 index c38d84ac5ba..00000000000 --- a/elasticsearch/x-pack/marvel/src/main/java/org/elasticsearch/marvel/support/init/proxy/MonitoringClientProxy.java +++ /dev/null @@ -1,22 +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.support.init.proxy; - -import org.elasticsearch.client.Client; -import org.elasticsearch.xpack.security.InternalClient; -import org.elasticsearch.xpack.common.init.proxy.ClientProxy; - -public class MonitoringClientProxy extends ClientProxy { - - /** - * Creates a proxy to the given internal client (can be used for testing) - */ - public static MonitoringClientProxy of(Client client) { - MonitoringClientProxy proxy = new MonitoringClientProxy(); - proxy.client = client instanceof InternalClient ? (InternalClient) client : new InternalClient.Insecure(client); - return proxy; - } -} diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java index c9c2ef39aba..42dc9074729 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/ExportersTests.java @@ -19,8 +19,8 @@ import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.marvel.MonitoredSystem; import org.elasticsearch.marvel.agent.exporter.local.LocalExporter; import org.elasticsearch.marvel.cleaner.CleanerService; -import org.elasticsearch.marvel.support.init.proxy.MonitoringClientProxy; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.init.proxy.ClientProxy; import org.junit.Before; import java.util.ArrayList; @@ -69,7 +69,7 @@ public class ExportersTests extends ESTestCase { clusterService = mock(ClusterService.class); // we always need to have the local exporter as it serves as the default one - factories.put(LocalExporter.TYPE, new LocalExporter.Factory(MonitoringClientProxy.of(client), clusterService, + factories.put(LocalExporter.TYPE, new LocalExporter.Factory(ClientProxy.fromClient(client), clusterService, mock(CleanerService.class))); clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(MonitoringSettings.COLLECTORS, MonitoringSettings.INTERVAL, MonitoringSettings.EXPORTERS_SETTINGS))); diff --git a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java index 5aafcd04f46..6d69e5150aa 100644 --- a/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java +++ b/elasticsearch/x-pack/marvel/src/test/java/org/elasticsearch/marvel/agent/resolver/cluster/ClusterStatsResolverTests.java @@ -31,7 +31,7 @@ import org.elasticsearch.index.fielddata.FieldDataStats; import org.elasticsearch.index.shard.ShardId; import org.elasticsearch.index.shard.ShardPath; import org.elasticsearch.indices.NodeIndicesStats; -import org.elasticsearch.ingest.core.IngestInfo; +import org.elasticsearch.ingest.IngestInfo; import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsMonitoringDoc; import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils; import org.elasticsearch.marvel.agent.resolver.MonitoringIndexNameResolverTestCase; diff --git a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/InternalClient.java b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/InternalClient.java index f9c21d6ba3d..6236e810346 100644 --- a/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/InternalClient.java +++ b/elasticsearch/x-pack/security/src/main/java/org/elasticsearch/xpack/security/InternalClient.java @@ -14,30 +14,29 @@ import org.elasticsearch.action.ActionResponse; import org.elasticsearch.client.Client; import org.elasticsearch.client.FilterClient; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.xpack.security.authc.AuthenticationService; import org.elasticsearch.xpack.security.user.XPackUser; +import org.elasticsearch.threadpool.ThreadPool; import java.io.IOException; /** * */ -public abstract class InternalClient extends FilterClient { +public interface InternalClient extends Client { - protected InternalClient(Client in) { - super(in); - } /** * An insecured internal client, baseically simply delegates to the normal ES client * without doing anything extra. */ - public static class Insecure extends InternalClient { + class Insecure extends FilterClient implements InternalClient { @Inject - public Insecure(Client in) { - super(in); + public Insecure(Settings settings, ThreadPool threadPool, Client in) { + super(settings, threadPool, in); } } @@ -45,13 +44,13 @@ public abstract class InternalClient extends FilterClient { * A secured internal client that binds the internal XPack user to the current * execution context, before the action is executed. */ - public static class Secure extends InternalClient { + class Secure extends FilterClient implements InternalClient { - private AuthenticationService authcService; + private final AuthenticationService authcService; @Inject - public Secure(Client in, AuthenticationService authcService) { - super(in); + public Secure(Settings settings, ThreadPool threadPool, Client in, AuthenticationService authcService) { + super(settings, threadPool, in); this.authcService = authcService; } diff --git a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java index c658447ee43..1aca5c15fb8 100644 --- a/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java +++ b/elasticsearch/x-pack/security/src/test/java/org/elasticsearch/xpack/security/audit/index/IndexAuditTrailMutedTests.java @@ -10,6 +10,8 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionRequest; import org.elasticsearch.action.ActionRequestBuilder; import org.elasticsearch.action.ActionResponse; +import org.elasticsearch.client.Client; +import org.elasticsearch.client.FilterClient; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.inject.util.Providers; @@ -62,14 +64,18 @@ public class IndexAuditTrailMutedTests extends ESTestCase { threadPool = new TestThreadPool("index audit trail tests"); transportClient = TransportClient.builder().settings(Settings.EMPTY).build(); clientCalled = new AtomicBoolean(false); - client = new InternalClient(transportClient) { + class IClient extends FilterClient implements InternalClient { + IClient(Client transportClient){ + super(transportClient); + } @Override protected , Response extends ActionResponse, RequestBuilder extends ActionRequestBuilder> void doExecute( Action action, Request request, ActionListener listener) { clientCalled.set(true); } - }; + } + client = new IClient(transportClient); messageEnqueued = new AtomicBoolean(false); } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 968df5ddd7c..e16a01d9c39 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -16,7 +16,6 @@ import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.settings.SettingsModule; import org.elasticsearch.env.Environment; import org.elasticsearch.index.IndexModule; import org.elasticsearch.license.plugin.Licensing; @@ -25,7 +24,6 @@ import org.elasticsearch.marvel.MonitoringSettings; import org.elasticsearch.plugins.Plugin; import org.elasticsearch.plugins.ScriptPlugin; import org.elasticsearch.script.ScriptContext; -import org.elasticsearch.script.ScriptModule; import org.elasticsearch.xpack.security.Security; import org.elasticsearch.xpack.security.authc.AuthenticationModule; import org.elasticsearch.threadpool.ExecutorBuilder; @@ -35,8 +33,6 @@ import org.elasticsearch.xpack.action.XPackInfoAction; import org.elasticsearch.xpack.action.XPackUsageAction; import org.elasticsearch.xpack.common.ScriptServiceProxy; import org.elasticsearch.xpack.common.http.HttpClientModule; -import org.elasticsearch.xpack.common.init.LazyInitializationModule; -import org.elasticsearch.xpack.common.init.LazyInitializationService; import org.elasticsearch.xpack.common.secret.SecretModule; import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtensionsService; @@ -135,7 +131,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin { @Override public Collection nodeModules() { ArrayList modules = new ArrayList<>(); - modules.add(new LazyInitializationModule()); modules.add(new ClockModule()); modules.addAll(notification.nodeModules()); modules.addAll(licensing.nodeModules()); @@ -155,10 +150,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin { @Override public Collection> nodeServices() { ArrayList> services = new ArrayList<>(); - // the initialization service must be first in the list - // as other services may depend on one of the initialized - // constructs - services.add(LazyInitializationService.class); services.addAll(notification.nodeServices()); services.addAll(licensing.nodeServices()); services.addAll(security.nodeServices()); @@ -252,11 +243,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin { graph.onIndexModule(module); } - public void onModule(LazyInitializationModule module) { - monitoring.onModule(module); - watcher.onModule(module); - } - public static void bindFeatureSet(Binder binder, Class featureSet) { binder.bind(featureSet).asEagerSingleton(); Multibinder featureSetBinder = Multibinder.newSetBinder(binder, XPackFeatureSet.class); diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java deleted file mode 100644 index cc578d52213..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializable.java +++ /dev/null @@ -1,17 +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.xpack.common.init; - -import org.elasticsearch.common.inject.Injector; - -public interface LazyInitializable { - - /** - * This method is called once all objects have been constructed and - * the @{link LazyInitializationService} has been started. - */ - void init(Injector injector); -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java deleted file mode 100644 index 7c7db7bcd0f..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationModule.java +++ /dev/null @@ -1,39 +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.xpack.common.init; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.Multibinder; - -import java.util.HashSet; -import java.util.Set; - -/** - * A module to lazy initialize objects and avoid circular dependency injection issues. - * - * Objects that use the {@link org.elasticsearch.client.ElasticsearchClient} and that are also injected in transport actions provoke - * a circular dependency injection issues with Guice. Using proxies with lazy initialization is a way to solve this issue. - * - * The proxies are initialized by {@link LazyInitializationService}. - */ -public class LazyInitializationModule extends AbstractModule { - - private final Set> initializables = new HashSet<>(); - - @Override - protected void configure() { - Multibinder mbinder = Multibinder.newSetBinder(binder(), LazyInitializable.class); - for (Class initializable : initializables) { - bind(initializable).asEagerSingleton(); - mbinder.addBinding().to(initializable); - } - bind(LazyInitializationService.class).asEagerSingleton(); - } - - public void registerLazyInitializable(Class lazyTypeClass) { - initializables.add(lazyTypeClass); - } -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.java deleted file mode 100644 index d525e2beb74..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/LazyInitializationService.java +++ /dev/null @@ -1,46 +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.xpack.common.init; - -import org.elasticsearch.ElasticsearchException; -import org.elasticsearch.common.component.AbstractLifecycleComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.inject.Injector; -import org.elasticsearch.common.settings.Settings; - -import java.util.Set; - -/** - * A service to lazy initialize {@link LazyInitializable} constructs. - */ -public class LazyInitializationService extends AbstractLifecycleComponent { - - private final Injector injector; - private final Set initializables; - - @Inject - public LazyInitializationService(Settings settings, Injector injector, Set initializables) { - super(settings); - this.injector = injector; - this.initializables = initializables; - } - - @Override - protected void doStart() throws ElasticsearchException { - for (LazyInitializable initializable : initializables) { - logger.trace("lazy initialization of [{}]", initializable); - initializable.init(injector); - } - } - - @Override - protected void doStop() throws ElasticsearchException { - } - - @Override - protected void doClose() throws ElasticsearchException { - } -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java index 012ebb86a6b..be8e33d166d 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/init/proxy/ClientProxy.java @@ -11,22 +11,21 @@ import org.elasticsearch.action.bulk.BulkRequestBuilder; import org.elasticsearch.action.bulk.BulkResponse; import org.elasticsearch.client.AdminClient; import org.elasticsearch.client.Client; +import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Injector; import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.transport.TransportMessage; -import org.elasticsearch.xpack.common.init.LazyInitializable; /** * A lazily initialized proxy to an elasticsearch {@link Client}. Inject this proxy whenever a client * needs to injected to be avoid circular dependencies issues. */ -public class ClientProxy implements LazyInitializable { +public class ClientProxy { - protected InternalClient client; + protected final InternalClient client; - @Override - public void init(Injector injector) { - this.client = injector.getInstance(InternalClient.class); + public ClientProxy(InternalClient client) { + this.client = client; } public AdminClient admin() { @@ -44,4 +43,9 @@ public class ClientProxy implements LazyInitializable { protected M preProcess(M message) { return message; } + + public static InternalClient fromClient(Client client) { + return client instanceof InternalClient ? (InternalClient) client : + new InternalClient.Insecure(client.settings(), client.threadPool(), client); + } } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index aaaa604764f..fc8623e42fb 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -20,11 +20,9 @@ import org.elasticsearch.common.regex.Regex; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.EsExecutors; -import org.elasticsearch.script.ScriptModule; import org.elasticsearch.threadpool.ExecutorBuilder; import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.xpack.XPackPlugin; -import org.elasticsearch.xpack.common.init.LazyInitializationModule; import org.elasticsearch.xpack.watcher.actions.WatcherActionModule; import org.elasticsearch.xpack.watcher.client.WatcherClientModule; import org.elasticsearch.xpack.watcher.condition.ConditionModule; @@ -43,13 +41,10 @@ import org.elasticsearch.xpack.watcher.rest.action.RestHijackOperationAction; import org.elasticsearch.xpack.watcher.rest.action.RestPutWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestWatchServiceAction; import org.elasticsearch.xpack.watcher.rest.action.RestWatcherStatsAction; -import org.elasticsearch.xpack.common.ScriptServiceProxy; import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry; import org.elasticsearch.xpack.watcher.support.WatcherIndexTemplateRegistry.TemplateConfig; -import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.xpack.watcher.support.validation.WatcherSettingsValidation; import org.elasticsearch.xpack.watcher.transform.TransformModule; -import org.elasticsearch.xpack.watcher.transform.chain.ChainTransformFactory; import org.elasticsearch.xpack.watcher.transport.actions.ack.AckWatchAction; import org.elasticsearch.xpack.watcher.transport.actions.ack.TransportAckWatchAction; import org.elasticsearch.xpack.watcher.transport.actions.activate.ActivateWatchAction; @@ -207,14 +202,6 @@ public class Watcher { } } - public void onModule(LazyInitializationModule module) { - if (enabled) { - module.registerLazyInitializable(WatcherClientProxy.class); - module.registerLazyInitializable(ChainTransformFactory.class); - module.registerLazyInitializable(ChainInputFactory.class); - } - } - public static boolean enabled(Settings settings) { return XPackPlugin.featureEnabled(settings, NAME, true); } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionFactory.java index afc14658bb2..21682d9bb75 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/IndexActionFactory.java @@ -10,8 +10,8 @@ import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.watcher.actions.ActionFactory; -import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction; import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy; import java.io.IOException; @@ -25,8 +25,12 @@ public class IndexActionFactory extends ActionFactory> entry : parsers.entrySet()) { bind(entry.getValue()).asEagerSingleton(); parsersBinder.addBinding(entry.getKey()).to(entry.getValue()); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java index eaf14b4f74a..c83fb47b9f4 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java @@ -7,9 +7,14 @@ package org.elasticsearch.xpack.watcher.input; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.xpack.watcher.input.chain.ChainInput; +import org.elasticsearch.xpack.watcher.input.chain.ChainInputFactory; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; public class InputRegistry { @@ -17,8 +22,10 @@ public class InputRegistry { private final Map factories; @Inject - public InputRegistry(Map factories) { - this.factories = factories; + public InputRegistry(Settings settings, Map factories) { + Map map = new HashMap<>(factories); + map.put(ChainInput.TYPE, new ChainInputFactory(settings, this)); + this.factories = Collections.unmodifiableMap(map); } /** diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java index ca22975dd5a..3579d60c0f9 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java @@ -15,20 +15,19 @@ import org.elasticsearch.xpack.watcher.input.ExecutableInput; import org.elasticsearch.xpack.watcher.input.Input; import org.elasticsearch.xpack.watcher.input.InputFactory; import org.elasticsearch.xpack.watcher.input.InputRegistry; -import org.elasticsearch.xpack.common.init.LazyInitializable; import java.io.IOException; import java.util.ArrayList; import java.util.List; -public class ChainInputFactory extends InputFactory - implements LazyInitializable { +public class ChainInputFactory extends InputFactory { - private InputRegistry inputRegistry; + private final InputRegistry inputRegistry; @Inject - public ChainInputFactory(Settings settings) { + public ChainInputFactory(Settings settings, InputRegistry inputRegistry) { super(Loggers.getLogger(ExecutableChainInput.class, settings)); + this.inputRegistry = inputRegistry; } @Override @@ -51,13 +50,4 @@ public class ChainInputFactory extends InputFactory> entry : factories.entrySet()) { bind(entry.getValue()).asEagerSingleton(); mbinder.addBinding(entry.getKey()).to(entry.getValue()); diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformRegistry.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformRegistry.java index 948620410d2..59e7ca07542 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformRegistry.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/TransformRegistry.java @@ -7,9 +7,14 @@ package org.elasticsearch.xpack.watcher.transform; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; +import org.elasticsearch.xpack.watcher.transform.chain.ChainTransform; +import org.elasticsearch.xpack.watcher.transform.chain.ChainTransformFactory; import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; import java.util.Map; /** @@ -20,8 +25,10 @@ public class TransformRegistry { private final Map factories; @Inject - public TransformRegistry(Map factories) { - this.factories = factories; + public TransformRegistry(Settings settings, Map factories) { + Map map = new HashMap<>(factories); + map.put(ChainTransform.TYPE, new ChainTransformFactory(settings, this)); + this.factories = Collections.unmodifiableMap(map); } public TransformFactory factory(String type) { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformFactory.java index 294ece9df84..0ec022302d0 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformFactory.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.watcher.transform.chain; -import org.elasticsearch.common.inject.Injector; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; @@ -13,41 +12,16 @@ import org.elasticsearch.xpack.watcher.transform.ExecutableTransform; import org.elasticsearch.xpack.watcher.transform.Transform; import org.elasticsearch.xpack.watcher.transform.TransformFactory; import org.elasticsearch.xpack.watcher.transform.TransformRegistry; -import org.elasticsearch.xpack.common.init.LazyInitializable; import java.io.IOException; import java.util.ArrayList; -/** - * - */ -public class ChainTransformFactory extends TransformFactory implements - LazyInitializable { +public final class ChainTransformFactory extends TransformFactory { - private TransformRegistry registry; + private final TransformRegistry registry; - // used by guice - public ChainTransformFactory(Settings settings) { + public ChainTransformFactory(Settings settings, TransformRegistry registry) { super(Loggers.getLogger(ExecutableChainTransform.class, settings)); - } - - // used for tests - public ChainTransformFactory(TransformRegistry registry) { - super(Loggers.getLogger(ExecutableChainTransform.class)); - this.registry = registry; - } - - // used for tests - public ChainTransformFactory() { - super(Loggers.getLogger(ExecutableChainTransform.class)); - } - - @Override - public void init(Injector injector) { - init(injector.getInstance(TransformRegistry.class)); - } - - public void init(TransformRegistry registry) { this.registry = registry; } diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/SearchTransformFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/SearchTransformFactory.java index b99044c649e..8f7cf903af2 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/SearchTransformFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/transform/search/SearchTransformFactory.java @@ -17,6 +17,7 @@ import org.elasticsearch.index.query.QueryParseContext; import org.elasticsearch.indices.query.IndicesQueriesRegistry; import org.elasticsearch.search.aggregations.AggregatorParsers; import org.elasticsearch.search.suggest.Suggesters; +import org.elasticsearch.xpack.security.InternalClient; import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.xpack.watcher.transform.TransformFactory; @@ -33,6 +34,10 @@ public class SearchTransformFactory extends TransformFactory factories = new HashMap<>(); factories.put("simple", new SimpleInputFactory(Settings.EMPTY)); - InputRegistry inputRegistry = new InputRegistry(factories); - ChainInputFactory chainInputFactory = new ChainInputFactory(Settings.EMPTY); - chainInputFactory.init(inputRegistry); + InputRegistry inputRegistry = new InputRegistry(Settings.EMPTY, factories); + ChainInputFactory chainInputFactory = new ChainInputFactory(Settings.EMPTY, inputRegistry); factories.put("chain", chainInputFactory); XContentParser parser = XContentFactory.xContent(builder.bytes()).createParser(builder.bytes()); diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java index 321bd567875..4fa70235414 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/transform/chain/ChainTransformTests.java @@ -7,6 +7,7 @@ package org.elasticsearch.xpack.watcher.transform.chain; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; @@ -111,9 +112,10 @@ public class ChainTransformTests extends ESTestCase { } public void testParser() throws Exception { - TransformRegistry registry = new TransformRegistry(singletonMap("named", new NamedExecutableTransform.Factory(logger))); + TransformRegistry registry = new TransformRegistry(Settings.EMPTY, + singletonMap("named", new NamedExecutableTransform.Factory(logger))); - ChainTransformFactory transformParser = new ChainTransformFactory(registry); + ChainTransformFactory transformParser = new ChainTransformFactory(Settings.EMPTY, registry); XContentBuilder builder = jsonBuilder().startArray() .startObject().startObject("named").field("name", "name1").endObject().endObject() diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java index 8c9429500b1..fa34ad8c6d6 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java @@ -356,10 +356,10 @@ public class WatchTests extends ESTestCase { QueryParser queryParser = MatchAllQueryBuilder::fromXContent; queryRegistry.register(queryParser, MatchAllQueryBuilder.QUERY_NAME_FIELD); parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, queryRegistry, null, null)); - return new InputRegistry(parsers); + return new InputRegistry(Settings.EMPTY, parsers); default: parsers.put(SimpleInput.TYPE, new SimpleInputFactory(settings)); - return new InputRegistry(parsers); + return new InputRegistry(Settings.EMPTY, parsers); } } @@ -424,12 +424,9 @@ public class WatchTests extends ESTestCase { QueryParser queryParser = MatchAllQueryBuilder::fromXContent; queryRegistry.register(queryParser, MatchAllQueryBuilder.QUERY_NAME_FIELD); Map factories = new HashMap<>(); - ChainTransformFactory parser = new ChainTransformFactory(); - factories.put(ChainTransform.TYPE, parser); factories.put(ScriptTransform.TYPE, new ScriptTransformFactory(settings, scriptService)); factories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, queryRegistry, null, null)); - TransformRegistry registry = new TransformRegistry(unmodifiableMap(factories)); - parser.init(registry); + TransformRegistry registry = new TransformRegistry(Settings.EMPTY, unmodifiableMap(factories)); return registry; }