Watcher: Deguice WatcherClientModule, HistoryModule & InputModule (elastic/elasticsearch#4024)
Original commit: elastic/x-pack-elasticsearch@202d94dd96
This commit is contained in:
parent
b0dc931091
commit
743458705a
|
@ -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<? extends XPackFeatureSet> featureSet) {
|
||||
binder.bind(featureSet).asEagerSingleton();
|
||||
Multibinder<XPackFeatureSet> featureSetBinder = Multibinder.newSetBinder(binder, XPackFeatureSet.class);
|
||||
|
|
|
@ -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<Object> createComponents(Clock clock, ScriptService scriptService, InternalClient internalClient,
|
||||
SearchRequestParsers searchRequestParsers, XPackLicenseState licenseState,
|
||||
HttpClient httpClient, Collection<Object> components) {
|
||||
HttpClient httpClient, HttpRequestTemplate.Parser httpTemplateParser,
|
||||
Collection<Object> components) {
|
||||
final Map<String, ConditionFactory> 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<String, InputFactory> 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> T getService(Class<T> serviceClass, Collection<Object> 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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<String, Class<? extends InputFactory>> parsers = new HashMap<>();
|
||||
|
||||
public void registerInput(String type, Class<? extends InputFactory> parserType) {
|
||||
parsers.put(type, parserType);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
MapBinder<String, InputFactory> 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<String, Class<? extends InputFactory>> entry : parsers.entrySet()) {
|
||||
bind(entry.getValue()).asEagerSingleton();
|
||||
parsersBinder.addBinding(entry.getKey()).to(entry.getValue());
|
||||
}
|
||||
|
||||
bind(InputRegistry.class).asEagerSingleton();
|
||||
}
|
||||
}
|
|
@ -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<String, InputFactory> factories;
|
||||
|
||||
@Inject
|
||||
public InputRegistry(Settings settings, Map<String, InputFactory> factories) {
|
||||
Map<String, InputFactory> map = new HashMap<>(factories);
|
||||
map.put(ChainInput.TYPE, new ChainInputFactory(settings, this));
|
||||
|
|
|
@ -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<ChainInput, ChainInput.Resul
|
|||
|
||||
private final InputRegistry inputRegistry;
|
||||
|
||||
@Inject
|
||||
public ChainInputFactory(Settings settings, InputRegistry inputRegistry) {
|
||||
super(Loggers.getLogger(ExecutableChainInput.class, settings));
|
||||
this.inputRegistry = inputRegistry;
|
||||
|
|
|
@ -5,14 +5,13 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.watcher.input.http;
|
||||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||
import org.elasticsearch.xpack.watcher.input.InputFactory;
|
||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||
import org.elasticsearch.xpack.watcher.input.InputFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
|
@ -22,7 +21,6 @@ public final class HttpInputFactory extends InputFactory<HttpInput, HttpInput.Re
|
|||
private final TextTemplateEngine templateEngine;
|
||||
private final HttpRequestTemplate.Parser requestTemplateParser;
|
||||
|
||||
@Inject
|
||||
public HttpInputFactory(Settings settings, HttpClient httpClient, TextTemplateEngine templateEngine,
|
||||
HttpRequestTemplate.Parser requestTemplateParser) {
|
||||
super(Loggers.getLogger(ExecutableHttpInput.class, settings));
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.watcher.input.none;
|
||||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -15,7 +14,6 @@ import java.io.IOException;
|
|||
|
||||
public class NoneInputFactory extends InputFactory<NoneInput, NoneInput.Result, ExecutableNoneInput> {
|
||||
|
||||
@Inject
|
||||
public NoneInputFactory(Settings settings) {
|
||||
super(Loggers.getLogger(ExecutableNoneInput.class, settings));
|
||||
}
|
||||
|
|
|
@ -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<SearchInput, SearchInput.Re
|
|||
private final ParseFieldMatcher parseFieldMatcher;
|
||||
private final WatcherSearchTemplateService searchTemplateService;
|
||||
|
||||
@Inject
|
||||
public SearchInputFactory(Settings settings, InternalClient client,
|
||||
SearchRequestParsers searchRequestParsers, ScriptService scriptService) {
|
||||
this(settings, new WatcherClientProxy(settings, client), searchRequestParsers, scriptService);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
*/
|
||||
package org.elasticsearch.xpack.watcher.input.simple;
|
||||
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
|
@ -15,7 +14,6 @@ import java.io.IOException;
|
|||
|
||||
public class SimpleInputFactory extends InputFactory<SimpleInput, SimpleInput.Result, ExecutableSimpleInput> {
|
||||
|
||||
@Inject
|
||||
public SimpleInputFactory(Settings settings) {
|
||||
super(Loggers.getLogger(ExecutableSimpleInput.class, settings));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue