diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index b1eedc89a63..20401aff18d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -248,7 +248,7 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I components.addAll(notificationComponents); components.addAll(watcher.createComponents(getClock(), scriptService, internalClient, searchRequestParsers, licenseState, - httpClient, components)); + httpClient, httpTemplateParser, components)); // just create the reloader as it will pull all of the loaded ssl configurations and start watching them @@ -412,8 +412,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I security.onIndexModule(module); } - - public static void bindFeatureSet(Binder binder, Class featureSet) { binder.bind(featureSet).asEagerSingleton(); Multibinder featureSetBinder = Multibinder.newSetBinder(binder, XPackFeatureSet.class); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index ae76f8fd8b7..abfca711077 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -57,7 +57,7 @@ import org.elasticsearch.xpack.watcher.actions.slack.SlackAction; import org.elasticsearch.xpack.watcher.actions.slack.SlackActionFactory; import org.elasticsearch.xpack.watcher.actions.webhook.WebhookAction; import org.elasticsearch.xpack.watcher.actions.webhook.WebhookActionFactory; -import org.elasticsearch.xpack.watcher.client.WatcherClientModule; +import org.elasticsearch.xpack.watcher.client.WatcherClient; import org.elasticsearch.xpack.watcher.condition.AlwaysCondition; import org.elasticsearch.xpack.watcher.condition.ArrayCompareCondition; import org.elasticsearch.xpack.watcher.condition.CompareCondition; @@ -69,9 +69,19 @@ import org.elasticsearch.xpack.watcher.execution.ExecutionModule; import org.elasticsearch.xpack.watcher.execution.ExecutionService; import org.elasticsearch.xpack.watcher.execution.InternalWatchExecutor; import org.elasticsearch.xpack.watcher.execution.TriggeredWatchStore; -import org.elasticsearch.xpack.watcher.history.HistoryModule; import org.elasticsearch.xpack.watcher.history.HistoryStore; -import org.elasticsearch.xpack.watcher.input.InputModule; +import org.elasticsearch.xpack.watcher.input.InputFactory; +import org.elasticsearch.xpack.watcher.input.InputRegistry; +import org.elasticsearch.xpack.watcher.input.chain.ChainInput; +import org.elasticsearch.xpack.watcher.input.chain.ChainInputFactory; +import org.elasticsearch.xpack.watcher.input.http.HttpInput; +import org.elasticsearch.xpack.watcher.input.http.HttpInputFactory; +import org.elasticsearch.xpack.watcher.input.none.NoneInput; +import org.elasticsearch.xpack.watcher.input.none.NoneInputFactory; +import org.elasticsearch.xpack.watcher.input.search.SearchInput; +import org.elasticsearch.xpack.watcher.input.search.SearchInputFactory; +import org.elasticsearch.xpack.watcher.input.simple.SimpleInput; +import org.elasticsearch.xpack.watcher.input.simple.SimpleInputFactory; import org.elasticsearch.xpack.watcher.rest.action.RestAckWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestActivateWatchAction; import org.elasticsearch.xpack.watcher.rest.action.RestDeleteWatchAction; @@ -158,7 +168,8 @@ public class Watcher implements ActionPlugin, ScriptPlugin { public Collection createComponents(Clock clock, ScriptService scriptService, InternalClient internalClient, SearchRequestParsers searchRequestParsers, XPackLicenseState licenseState, - HttpClient httpClient, Collection components) { + HttpClient httpClient, HttpRequestTemplate.Parser httpTemplateParser, + Collection components) { final Map parsers = new HashMap<>(); parsers.put(AlwaysCondition.TYPE, (c, id, p, upgrade) -> AlwaysCondition.parse(id, p)); parsers.put(NeverCondition.TYPE, (c, id, p, upgrade) -> NeverCondition.parse(id, p)); @@ -190,7 +201,20 @@ public class Watcher implements ActionPlugin, ScriptPlugin { actionFactoryMap.put(PagerDutyAction.TYPE, new PagerDutyActionFactory(settings, templateEngine, getService(PagerDutyService.class, components))); final ActionRegistry registry = new ActionRegistry(actionFactoryMap, conditionRegistry, transformRegistry, clock, licenseState); - return Collections.singleton(registry); + + final Map inputFactories = new HashMap<>(); + inputFactories.put(SearchInput.TYPE, new SearchInputFactory(settings, internalClient, searchRequestParsers, scriptService)); + inputFactories.put(SimpleInput.TYPE, new SimpleInputFactory(settings)); + inputFactories.put(HttpInput.TYPE, new HttpInputFactory(settings, httpClient, templateEngine, httpTemplateParser)); + inputFactories.put(NoneInput.TYPE, new NoneInputFactory(settings)); + final InputRegistry inputRegistry = new InputRegistry(settings, inputFactories); + inputFactories.put(ChainInput.TYPE, new ChainInputFactory(settings, inputRegistry)); + + final WatcherClient watcherClient = new WatcherClient(internalClient); + + final HistoryStore historyStore = new HistoryStore(settings, internalClient); + + return Arrays.asList(registry, watcherClient, inputRegistry, historyStore); } private T getService(Class serviceClass, Collection services) { @@ -208,11 +232,8 @@ public class Watcher implements ActionPlugin, ScriptPlugin { modules.add(new WatcherModule(enabled, transportClient)); if (enabled && transportClient == false) { modules.add(new WatchModule()); - modules.add(new WatcherClientModule()); modules.add(new TriggerModule(settings)); modules.add(new ScheduleModule()); - modules.add(new InputModule()); - modules.add(new HistoryModule()); modules.add(new ExecutionModule()); } return modules; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatcherClientModule.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatcherClientModule.java deleted file mode 100644 index 36cadc6bdc6..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatcherClientModule.java +++ /dev/null @@ -1,16 +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.watcher.client; - -import org.elasticsearch.common.inject.AbstractModule; - -public class WatcherClientModule extends AbstractModule { - - @Override - protected void configure() { - bind(WatcherClient.class).asEagerSingleton(); - } -} diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryModule.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryModule.java deleted file mode 100644 index 10928810a96..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryModule.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.xpack.watcher.history; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.watcher.execution.InternalWatchExecutor; - -public class HistoryModule extends AbstractModule { - - public HistoryModule() { - } - - @Override - protected void configure() { - bind(HistoryStore.class).asEagerSingleton(); - } - -} diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java index 996b288e8f6..46570c36121 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/HistoryStore.java @@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.history; import org.elasticsearch.action.index.IndexRequest; import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; @@ -43,7 +42,6 @@ public class HistoryStore extends AbstractComponent { private final Lock stopLock = readWriteLock.writeLock(); private final AtomicBoolean started = new AtomicBoolean(false); - @Inject public HistoryStore(Settings settings, InternalClient client) { this(settings, new WatcherClientProxy(settings, client)); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputModule.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputModule.java deleted file mode 100644 index 98e1f4fc760..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputModule.java +++ /dev/null @@ -1,55 +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.watcher.input; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.MapBinder; -import org.elasticsearch.xpack.watcher.input.chain.ChainInput; -import org.elasticsearch.xpack.watcher.input.chain.ChainInputFactory; -import org.elasticsearch.xpack.watcher.input.http.HttpInput; -import org.elasticsearch.xpack.watcher.input.http.HttpInputFactory; -import org.elasticsearch.xpack.watcher.input.none.NoneInput; -import org.elasticsearch.xpack.watcher.input.none.NoneInputFactory; -import org.elasticsearch.xpack.watcher.input.search.SearchInput; -import org.elasticsearch.xpack.watcher.input.search.SearchInputFactory; -import org.elasticsearch.xpack.watcher.input.simple.SimpleInput; -import org.elasticsearch.xpack.watcher.input.simple.SimpleInputFactory; - -import java.util.HashMap; -import java.util.Map; - -public class InputModule extends AbstractModule { - - private final Map> parsers = new HashMap<>(); - - public void registerInput(String type, Class parserType) { - parsers.put(type, parserType); - } - - @Override - protected void configure() { - MapBinder parsersBinder = MapBinder.newMapBinder(binder(), String.class, InputFactory.class); - - bind(SearchInputFactory.class).asEagerSingleton(); - parsersBinder.addBinding(SearchInput.TYPE).to(SearchInputFactory.class); - - bind(SimpleInputFactory.class).asEagerSingleton(); - parsersBinder.addBinding(SimpleInput.TYPE).to(SimpleInputFactory.class); - - bind(HttpInputFactory.class).asEagerSingleton(); - parsersBinder.addBinding(HttpInput.TYPE).to(HttpInputFactory.class); - - bind(NoneInputFactory.class).asEagerSingleton(); - parsersBinder.addBinding(NoneInput.TYPE).to(NoneInputFactory.class); - - for (Map.Entry> entry : parsers.entrySet()) { - bind(entry.getValue()).asEagerSingleton(); - parsersBinder.addBinding(entry.getKey()).to(entry.getValue()); - } - - bind(InputRegistry.class).asEagerSingleton(); - } -} diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java index d28feb38828..769a9c7414d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java @@ -6,7 +6,6 @@ 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; @@ -21,7 +20,6 @@ public class InputRegistry { private final Map factories; - @Inject public InputRegistry(Settings settings, Map factories) { Map map = new HashMap<>(factories); map.put(ChainInput.TYPE, new ChainInputFactory(settings, this)); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java index 7d9d5104d06..3dcb50415c4 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.watcher.input.chain; import org.elasticsearch.common.collect.Tuple; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentParser; @@ -23,7 +22,6 @@ public class ChainInputFactory extends InputFactory { - @Inject public NoneInputFactory(Settings settings) { super(Loggers.getLogger(ExecutableNoneInput.class, settings)); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java index dcadcfc66d9..8ba670511b0 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/input/search/SearchInputFactory.java @@ -6,7 +6,6 @@ package org.elasticsearch.xpack.watcher.input.search; import org.elasticsearch.common.ParseFieldMatcher; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.unit.TimeValue; @@ -31,7 +30,6 @@ public class SearchInputFactory extends InputFactory { - @Inject public SimpleInputFactory(Settings settings) { super(Loggers.getLogger(ExecutableSimpleInput.class, settings)); }