Logging: Drop remaining Settings log ctor (#34149)

Drops the last logging constructor that takes `Settings` because it is
no longer needed.

Watcher goes through a lot of effort to pass `Settings` to `Logger`
constructors and dropping `Settings` from all of those calls allowed us
to remove quite a bit of log-based ceremony from watcher.
This commit is contained in:
Nik Everett 2018-10-04 09:18:04 -04:00 committed by GitHub
parent ef5007b6d8
commit ab8a5563f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 157 additions and 224 deletions

View File

@ -28,7 +28,6 @@ import org.apache.logging.log4j.core.config.Configuration;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.LoggerConfig;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.shard.ShardId;
@ -65,16 +64,6 @@ public class Loggers {
return getLogger(clazz, asArrayList(Loggers.SPACE, index.getName(), prefixes).toArray(new String[0]));
}
/**
* Get a logger.
* @deprecated prefer {@link #getLogger(Class, String...)} or {@link LogManager#getLogger}
* as the Settings is no longer needed
*/
@Deprecated
public static Logger getLogger(Class<?> clazz, Settings settings, String... prefixes) {
return ESLoggerFactory.getLogger(formatPrefix(prefixes), clazz);
}
public static Logger getLogger(Class<?> clazz, String... prefixes) {
return ESLoggerFactory.getLogger(formatPrefix(prefixes), clazz);
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.core.watcher.input;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.Nullable;
import org.elasticsearch.common.xcontent.ToXContentObject;
import org.elasticsearch.common.xcontent.XContentBuilder;
@ -17,11 +16,9 @@ import java.io.IOException;
public abstract class ExecutableInput<I extends Input, R extends Input.Result> implements ToXContentObject {
protected final I input;
protected final Logger logger;
protected ExecutableInput(I input, Logger logger) {
protected ExecutableInput(I input) {
this.input = input;
this.logger = logger;
}
/**

View File

@ -311,32 +311,32 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin, Reloa
final ConditionRegistry conditionRegistry = new ConditionRegistry(Collections.unmodifiableMap(parsers), getClock());
final Map<String, TransformFactory> transformFactories = new HashMap<>();
transformFactories.put(ScriptTransform.TYPE, new ScriptTransformFactory(settings, scriptService));
transformFactories.put(ScriptTransform.TYPE, new ScriptTransformFactory(scriptService));
transformFactories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, xContentRegistry, scriptService));
final TransformRegistry transformRegistry = new TransformRegistry(Collections.unmodifiableMap(transformFactories));
// actions
final Map<String, ActionFactory> actionFactoryMap = new HashMap<>();
actionFactoryMap.put(EmailAction.TYPE, new EmailActionFactory(settings, emailService, templateEngine, emailAttachmentsParser));
actionFactoryMap.put(WebhookAction.TYPE, new WebhookActionFactory(settings, httpClient, templateEngine));
actionFactoryMap.put(WebhookAction.TYPE, new WebhookActionFactory(httpClient, templateEngine));
actionFactoryMap.put(IndexAction.TYPE, new IndexActionFactory(settings, client));
actionFactoryMap.put(LoggingAction.TYPE, new LoggingActionFactory(templateEngine));
actionFactoryMap.put(HipChatAction.TYPE, new HipChatActionFactory(settings, templateEngine, hipChatService));
actionFactoryMap.put(JiraAction.TYPE, new JiraActionFactory(settings, templateEngine, jiraService));
actionFactoryMap.put(SlackAction.TYPE, new SlackActionFactory(settings, templateEngine, slackService));
actionFactoryMap.put(PagerDutyAction.TYPE, new PagerDutyActionFactory(settings, templateEngine, pagerDutyService));
actionFactoryMap.put(HipChatAction.TYPE, new HipChatActionFactory(templateEngine, hipChatService));
actionFactoryMap.put(JiraAction.TYPE, new JiraActionFactory(templateEngine, jiraService));
actionFactoryMap.put(SlackAction.TYPE, new SlackActionFactory(templateEngine, slackService));
actionFactoryMap.put(PagerDutyAction.TYPE, new PagerDutyActionFactory(templateEngine, pagerDutyService));
final ActionRegistry registry = new ActionRegistry(actionFactoryMap, conditionRegistry, transformRegistry, getClock(),
getLicenseState());
// inputs
final Map<String, InputFactory> inputFactories = new HashMap<>();
inputFactories.put(SearchInput.TYPE, new SearchInputFactory(settings, client, xContentRegistry, scriptService));
inputFactories.put(SimpleInput.TYPE, new SimpleInputFactory(settings));
inputFactories.put(SimpleInput.TYPE, new SimpleInputFactory());
inputFactories.put(HttpInput.TYPE, new HttpInputFactory(settings, httpClient, templateEngine));
inputFactories.put(NoneInput.TYPE, new NoneInputFactory(settings));
inputFactories.put(TransformInput.TYPE, new TransformInputFactory(settings, transformRegistry));
final InputRegistry inputRegistry = new InputRegistry(settings, inputFactories);
inputFactories.put(ChainInput.TYPE, new ChainInputFactory(settings, inputRegistry));
inputFactories.put(NoneInput.TYPE, new NoneInputFactory());
inputFactories.put(TransformInput.TYPE, new TransformInputFactory(transformRegistry));
final InputRegistry inputRegistry = new InputRegistry(inputFactories);
inputFactories.put(ChainInput.TYPE, new ChainInputFactory(inputRegistry));
bulkProcessor = BulkProcessor.builder(ClientHelper.clientWithOrigin(client, WATCHER_ORIGIN), new BulkProcessor.Listener() {
@Override
@ -438,7 +438,7 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin, Reloa
}
protected Consumer<Iterable<TriggerEvent>> getTriggerEngineListener(ExecutionService executionService) {
return new AsyncTriggerEventConsumer(settings, executionService);
return new AsyncTriggerEventConsumer(executionService);
}
@Override

View File

@ -5,7 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.actions.email;
import org.elasticsearch.common.logging.Loggers;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.actions.ActionFactory;
@ -25,7 +25,7 @@ public class EmailActionFactory extends ActionFactory {
public EmailActionFactory(Settings settings, EmailService emailService, TextTemplateEngine templateEngine,
EmailAttachmentsParser emailAttachmentsParser) {
super(Loggers.getLogger(ExecutableEmailAction.class, settings));
super(LogManager.getLogger(ExecutableEmailAction.class));
this.emailService = emailService;
this.templateEngine = templateEngine;
this.htmlSanitizer = new HtmlSanitizer(settings);

View File

@ -5,8 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.actions.hipchat;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.actions.ActionFactory;
import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine;
@ -20,8 +19,8 @@ public class HipChatActionFactory extends ActionFactory {
private final TextTemplateEngine templateEngine;
private final HipChatService hipchatService;
public HipChatActionFactory(Settings settings, TextTemplateEngine templateEngine, HipChatService hipchatService) {
super(Loggers.getLogger(ExecutableHipChatAction.class, settings));
public HipChatActionFactory(TextTemplateEngine templateEngine, HipChatService hipchatService) {
super(LogManager.getLogger(ExecutableHipChatAction.class));
this.templateEngine = templateEngine;
this.hipchatService = hipchatService;
}

View File

@ -5,8 +5,8 @@
*/
package org.elasticsearch.xpack.watcher.actions.index;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
@ -21,7 +21,7 @@ public class IndexActionFactory extends ActionFactory {
private final TimeValue bulkDefaultTimeout;
public IndexActionFactory(Settings settings, Client client) {
super(Loggers.getLogger(IndexActionFactory.class, settings));
super(LogManager.getLogger(IndexActionFactory.class));
this.client = client;
this.indexDefaultTimeout = settings.getAsTime("xpack.watcher.actions.index.default_timeout", TimeValue.timeValueSeconds(30));
this.bulkDefaultTimeout = settings.getAsTime("xpack.watcher.actions.bulk.default_timeout", TimeValue.timeValueMinutes(1));

View File

@ -5,8 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.actions.jira;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.actions.ActionFactory;
import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine;
@ -19,8 +18,8 @@ public class JiraActionFactory extends ActionFactory {
private final TextTemplateEngine templateEngine;
private final JiraService jiraService;
public JiraActionFactory(Settings settings, TextTemplateEngine templateEngine, JiraService jiraService) {
super(Loggers.getLogger(ExecutableJiraAction.class, settings));
public JiraActionFactory(TextTemplateEngine templateEngine, JiraService jiraService) {
super(LogManager.getLogger(ExecutableJiraAction.class));
this.templateEngine = templateEngine;
this.jiraService = jiraService;
}

View File

@ -5,8 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.actions.pagerduty;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.actions.ActionFactory;
import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine;
@ -19,8 +18,8 @@ public class PagerDutyActionFactory extends ActionFactory {
private final TextTemplateEngine templateEngine;
private final PagerDutyService pagerDutyService;
public PagerDutyActionFactory(Settings settings, TextTemplateEngine templateEngine, PagerDutyService pagerDutyService) {
super(Loggers.getLogger(ExecutablePagerDutyAction.class, settings));
public PagerDutyActionFactory(TextTemplateEngine templateEngine, PagerDutyService pagerDutyService) {
super(LogManager.getLogger(ExecutablePagerDutyAction.class));
this.templateEngine = templateEngine;
this.pagerDutyService = pagerDutyService;
}

View File

@ -5,8 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.actions.slack;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.actions.ActionFactory;
import org.elasticsearch.xpack.watcher.common.text.TextTemplateEngine;
@ -18,8 +17,8 @@ public class SlackActionFactory extends ActionFactory {
private final TextTemplateEngine templateEngine;
private final SlackService slackService;
public SlackActionFactory(Settings settings, TextTemplateEngine templateEngine, SlackService slackService) {
super(Loggers.getLogger(ExecutableSlackAction.class, settings));
public SlackActionFactory(TextTemplateEngine templateEngine, SlackService slackService) {
super(LogManager.getLogger(ExecutableSlackAction.class));
this.templateEngine = templateEngine;
this.slackService = slackService;
}

View File

@ -5,8 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.actions.webhook;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.actions.ActionFactory;
import org.elasticsearch.xpack.watcher.common.http.HttpClient;
@ -19,9 +18,8 @@ public class WebhookActionFactory extends ActionFactory {
private final HttpClient httpClient;
private final TextTemplateEngine templateEngine;
public WebhookActionFactory(Settings settings, HttpClient httpClient, TextTemplateEngine templateEngine) {
super(Loggers.getLogger(ExecutableWebhookAction.class, settings));
public WebhookActionFactory(HttpClient httpClient, TextTemplateEngine templateEngine) {
super(LogManager.getLogger(ExecutableWebhookAction.class));
this.httpClient = httpClient;
this.templateEngine = templateEngine;
}

View File

@ -6,10 +6,9 @@
package org.elasticsearch.xpack.watcher.execution;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent;
import java.util.function.Consumer;
@ -17,12 +16,10 @@ import java.util.function.Consumer;
import static java.util.stream.StreamSupport.stream;
public class AsyncTriggerEventConsumer implements Consumer<Iterable<TriggerEvent>> {
private final Logger logger;
private static final Logger logger = LogManager.getLogger(SyncTriggerEventConsumer.class);
private final ExecutionService executionService;
public AsyncTriggerEventConsumer(Settings settings, ExecutionService executionService) {
this.logger = Loggers.getLogger(SyncTriggerEventConsumer.class, settings);
public AsyncTriggerEventConsumer(ExecutionService executionService) {
this.executionService = executionService;
}

View File

@ -6,10 +6,9 @@
package org.elasticsearch.xpack.watcher.execution;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent;
import java.util.function.Consumer;
@ -17,12 +16,11 @@ import java.util.function.Consumer;
import static java.util.stream.StreamSupport.stream;
public class SyncTriggerEventConsumer implements Consumer<Iterable<TriggerEvent>> {
private static final Logger logger = LogManager.getLogger(SyncTriggerEventConsumer.class);
private final ExecutionService executionService;
private final Logger logger;
public SyncTriggerEventConsumer(Settings settings, ExecutionService executionService) {
this.logger = Loggers.getLogger(SyncTriggerEventConsumer.class, settings);
public SyncTriggerEventConsumer(ExecutionService executionService) {
this.executionService = executionService;
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.core.watcher.input.Input;
@ -16,13 +15,6 @@ import java.io.IOException;
* Parses xcontent to a concrete input of the same type.
*/
public abstract class InputFactory<I extends Input, R extends Input.Result, E extends ExecutableInput<I, R>> {
protected final Logger inputLogger;
public InputFactory(Logger inputLogger) {
this.inputLogger = inputLogger;
}
/**
* @return The type of the input
*/

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.watcher.input;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.watcher.input.chain.ChainInput;
@ -21,9 +20,9 @@ public class InputRegistry {
private final Map<String, InputFactory> factories;
public InputRegistry(Settings settings, Map<String, InputFactory> factories) {
public InputRegistry(Map<String, InputFactory> factories) {
Map<String, InputFactory> map = new HashMap<>(factories);
map.put(ChainInput.TYPE, new ChainInputFactory(settings, this));
map.put(ChainInput.TYPE, new ChainInputFactory(this));
this.factories = Collections.unmodifiableMap(map);
}

View File

@ -6,8 +6,6 @@
package org.elasticsearch.xpack.watcher.input.chain;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.core.watcher.input.Input;
@ -22,8 +20,7 @@ public class ChainInputFactory extends InputFactory<ChainInput, ChainInput.Resul
private final InputRegistry inputRegistry;
public ChainInputFactory(Settings settings, InputRegistry inputRegistry) {
super(Loggers.getLogger(ExecutableChainInput.class, settings));
public ChainInputFactory(InputRegistry inputRegistry) {
this.inputRegistry = inputRegistry;
}
@ -45,6 +42,6 @@ public class ChainInputFactory extends InputFactory<ChainInput, ChainInput.Resul
executableInputs.add(new Tuple<>(tuple.v1(), executableInput));
}
return new ExecutableChainInput(input, executableInputs, inputLogger);
return new ExecutableChainInput(input, executableInputs);
}
}

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.watcher.input.chain;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
@ -20,11 +21,12 @@ import java.util.Map;
import static org.elasticsearch.xpack.watcher.input.chain.ChainInput.TYPE;
public class ExecutableChainInput extends ExecutableInput<ChainInput,ChainInput.Result> {
private static final Logger logger = LogManager.getLogger(ExecutableChainInput.class);
private List<Tuple<String, ExecutableInput>> inputs;
public ExecutableChainInput(ChainInput input, List<Tuple<String, ExecutableInput>> inputs, Logger logger) {
super(input, logger);
public ExecutableChainInput(ChainInput input, List<Tuple<String, ExecutableInput>> inputs) {
super(input);
this.inputs = inputs;
}

View File

@ -7,6 +7,7 @@ package org.elasticsearch.xpack.watcher.input.http;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -31,12 +32,13 @@ import java.util.Map;
import static org.elasticsearch.xpack.watcher.input.http.HttpInput.TYPE;
public class ExecutableHttpInput extends ExecutableInput<HttpInput, HttpInput.Result> {
private static final Logger logger = LogManager.getLogger(ExecutableHttpInput.class);
private final HttpClient client;
private final TextTemplateEngine templateEngine;
public ExecutableHttpInput(HttpInput input, Logger logger, HttpClient client, TextTemplateEngine templateEngine) {
super(input, logger);
public ExecutableHttpInput(HttpInput input, HttpClient client, TextTemplateEngine templateEngine) {
super(input);
this.client = client;
this.templateEngine = templateEngine;
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input.http;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.common.http.HttpClient;
@ -20,7 +19,6 @@ public final class HttpInputFactory extends InputFactory<HttpInput, HttpInput.Re
private final TextTemplateEngine templateEngine;
public HttpInputFactory(Settings settings, HttpClient httpClient, TextTemplateEngine templateEngine) {
super(Loggers.getLogger(ExecutableHttpInput.class, settings));
this.templateEngine = templateEngine;
this.httpClient = httpClient;
}
@ -37,6 +35,6 @@ public final class HttpInputFactory extends InputFactory<HttpInput, HttpInput.Re
@Override
public ExecutableHttpInput createExecutable(HttpInput input) {
return new ExecutableHttpInput(input, inputLogger, httpClient, templateEngine);
return new ExecutableHttpInput(input, httpClient, templateEngine);
}
}

View File

@ -5,8 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input.none;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.core.watcher.input.none.NoneInput;
@ -14,8 +12,8 @@ import org.elasticsearch.xpack.core.watcher.watch.Payload;
public class ExecutableNoneInput extends ExecutableInput<NoneInput, NoneInput.Result> {
public ExecutableNoneInput(Logger logger) {
super(NoneInput.INSTANCE, logger);
public ExecutableNoneInput() {
super(NoneInput.INSTANCE);
}
@Override

View File

@ -5,8 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input.none;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.core.watcher.input.none.NoneInput;
import org.elasticsearch.xpack.watcher.input.InputFactory;
@ -14,11 +12,6 @@ import org.elasticsearch.xpack.watcher.input.InputFactory;
import java.io.IOException;
public class NoneInputFactory extends InputFactory<NoneInput, NoneInput.Result, ExecutableNoneInput> {
public NoneInputFactory(Settings settings) {
super(Loggers.getLogger(ExecutableNoneInput.class, settings));
}
@Override
public String type() {
return NoneInput.TYPE;
@ -31,6 +24,6 @@ public class NoneInputFactory extends InputFactory<NoneInput, NoneInput.Result,
@Override
public ExecutableNoneInput createExecutable(NoneInput input) {
return new ExecutableNoneInput(inputLogger);
return new ExecutableNoneInput();
}
}

View File

@ -6,6 +6,7 @@
package org.elasticsearch.xpack.watcher.input.search;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
@ -39,13 +40,15 @@ public class ExecutableSearchInput extends ExecutableInput<SearchInput, SearchIn
public static final SearchType DEFAULT_SEARCH_TYPE = SearchType.QUERY_THEN_FETCH;
private static final Logger logger = LogManager.getLogger(ExecutableSearchInput.class);
private final Client client;
private final WatcherSearchTemplateService searchTemplateService;
private final TimeValue timeout;
public ExecutableSearchInput(SearchInput input, Logger logger, Client client, WatcherSearchTemplateService searchTemplateService,
public ExecutableSearchInput(SearchInput input, Client client, WatcherSearchTemplateService searchTemplateService,
TimeValue defaultTimeout) {
super(input, logger);
super(input);
this.client = client;
this.searchTemplateService = searchTemplateService;
this.timeout = input.getTimeout() != null ? input.getTimeout() : defaultTimeout;

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.watcher.input.search;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -25,7 +24,6 @@ public class SearchInputFactory extends InputFactory<SearchInput, SearchInput.Re
public SearchInputFactory(Settings settings, Client client, NamedXContentRegistry xContentRegistry,
ScriptService scriptService) {
super(Loggers.getLogger(ExecutableSearchInput.class, settings));
this.client = client;
this.defaultTimeout = settings.getAsTime("xpack.watcher.input.search.default_timeout", TimeValue.timeValueMinutes(1));
this.searchTemplateService = new WatcherSearchTemplateService(settings, scriptService, xContentRegistry);
@ -43,6 +41,6 @@ public class SearchInputFactory extends InputFactory<SearchInput, SearchInput.Re
@Override
public ExecutableSearchInput createExecutable(SearchInput input) {
return new ExecutableSearchInput(input, inputLogger, client, searchTemplateService, defaultTimeout);
return new ExecutableSearchInput(input, client, searchTemplateService, defaultTimeout);
}
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input.simple;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.core.watcher.watch.Payload;
@ -15,8 +14,8 @@ import org.elasticsearch.xpack.core.watcher.watch.Payload;
*/
public class ExecutableSimpleInput extends ExecutableInput<SimpleInput, SimpleInput.Result> {
public ExecutableSimpleInput(SimpleInput input, Logger logger) {
super(input, logger);
public ExecutableSimpleInput(SimpleInput input) {
super(input);
}
@Override

View File

@ -5,19 +5,12 @@
*/
package org.elasticsearch.xpack.watcher.input.simple;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.xpack.watcher.input.InputFactory;
import java.io.IOException;
public class SimpleInputFactory extends InputFactory<SimpleInput, SimpleInput.Result, ExecutableSimpleInput> {
public SimpleInputFactory(Settings settings) {
super(Loggers.getLogger(ExecutableSimpleInput.class, settings));
}
@Override
public String type() {
return SimpleInput.TYPE;
@ -30,6 +23,6 @@ public class SimpleInputFactory extends InputFactory<SimpleInput, SimpleInput.Re
@Override
public ExecutableSimpleInput createExecutable(SimpleInput input) {
return new ExecutableSimpleInput(input, inputLogger);
return new ExecutableSimpleInput(input);
}
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input.transform;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.xpack.core.watcher.execution.WatchExecutionContext;
import org.elasticsearch.xpack.core.watcher.input.ExecutableInput;
import org.elasticsearch.xpack.core.watcher.transform.ExecutableTransform;
@ -16,8 +15,8 @@ public final class ExecutableTransformInput extends ExecutableInput<TransformInp
private final ExecutableTransform executableTransform;
ExecutableTransformInput(TransformInput input, Logger logger, ExecutableTransform executableTransform) {
super(input, logger);
ExecutableTransformInput(TransformInput input, ExecutableTransform executableTransform) {
super(input);
this.executableTransform = executableTransform;
}

View File

@ -5,8 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.input.transform;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.XContentParserUtils;
import org.elasticsearch.xpack.core.watcher.transform.ExecutableTransform;
@ -31,8 +29,7 @@ public final class TransformInputFactory extends InputFactory<TransformInput, Tr
private final TransformRegistry transformRegistry;
public TransformInputFactory(Settings settings, TransformRegistry transformRegistry) {
super(Loggers.getLogger(ExecutableTransformInput.class, settings));
public TransformInputFactory(TransformRegistry transformRegistry) {
this.transformRegistry = transformRegistry;
}
@ -53,6 +50,6 @@ public final class TransformInputFactory extends InputFactory<TransformInput, Tr
Transform transform = input.getTransform();
TransformFactory factory = transformRegistry.factory(transform.type());
ExecutableTransform executableTransform = factory.createExecutable(transform);
return new ExecutableTransformInput(input, inputLogger, executableTransform);
return new ExecutableTransformInput(input, executableTransform);
}
}

View File

@ -5,8 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.transform.script;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.xpack.core.watcher.transform.TransformFactory;
@ -17,8 +16,8 @@ public class ScriptTransformFactory extends TransformFactory<ScriptTransform, Sc
private final ScriptService scriptService;
public ScriptTransformFactory(Settings settings, ScriptService scriptService) {
super(Loggers.getLogger(ExecutableScriptTransform.class, settings));
public ScriptTransformFactory(ScriptService scriptService) {
super(LogManager.getLogger(ExecutableScriptTransform.class));
this.scriptService = scriptService;
}

View File

@ -5,8 +5,8 @@
*/
package org.elasticsearch.xpack.watcher.transform.search;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
@ -24,7 +24,7 @@ public class SearchTransformFactory extends TransformFactory<SearchTransform, Se
private final WatcherSearchTemplateService searchTemplateService;
public SearchTransformFactory(Settings settings, Client client, NamedXContentRegistry xContentRegistry, ScriptService scriptService) {
super(Loggers.getLogger(ExecutableSearchTransform.class, settings));
super(LogManager.getLogger(ExecutableSearchTransform.class));
this.client = client;
this.defaultTimeout = settings.getAsTime("xpack.watcher.transform.search.default_timeout", TimeValue.timeValueMinutes(1));
this.searchTemplateService = new WatcherSearchTemplateService(settings, scriptService, xContentRegistry);

View File

@ -68,7 +68,7 @@ public class WatchParser extends AbstractComponent {
this.inputRegistry = inputRegistry;
this.cryptoService = cryptoService;
this.clock = clock;
this.defaultInput = new ExecutableNoneInput(logger);
this.defaultInput = new ExecutableNoneInput();
this.defaultCondition = InternalAlwaysCondition.INSTANCE;
this.defaultActions = Collections.emptyList();
}

View File

@ -231,7 +231,7 @@ public class WatcherServiceTests extends ESTestCase {
Watch watch = mock(Watch.class);
when(watch.trigger()).thenReturn(trigger);
when(watch.condition()).thenReturn(InternalAlwaysCondition.INSTANCE);
ExecutableNoneInput noneInput = new ExecutableNoneInput(logger);
ExecutableNoneInput noneInput = new ExecutableNoneInput();
when(watch.input()).thenReturn(noneInput);
triggerService.add(watch);

View File

@ -281,8 +281,7 @@ public class EmailActionTests extends ESTestCase {
XContentParser parser = createParser(JsonXContent.jsonXContent, bytes);
parser.nextToken();
ExecutableEmailAction executable = new EmailActionFactory(Settings.EMPTY, emailService, engine,
emailAttachmentParser)
ExecutableEmailAction executable = new EmailActionFactory(Settings.EMPTY, emailService, engine, emailAttachmentParser)
.parseExecutable(randomAlphaOfLength(8), randomAlphaOfLength(3), parser);
assertThat(executable, notNullValue());
@ -530,8 +529,8 @@ public class EmailActionTests extends ESTestCase {
parser.nextToken();
ExecutableEmailAction executableEmailAction = new EmailActionFactory(Settings.EMPTY, emailService, engine,
emailAttachmentsParser).parseExecutable(randomAlphaOfLength(3), randomAlphaOfLength(7), parser);
ExecutableEmailAction executableEmailAction = new EmailActionFactory(Settings.EMPTY, emailService, engine, emailAttachmentsParser)
.parseExecutable(randomAlphaOfLength(3), randomAlphaOfLength(7), parser);
DateTime now = DateTime.now(DateTimeZone.UTC);
Wid wid = new Wid(randomAlphaOfLength(5), now);

View File

@ -72,7 +72,7 @@ public class EmailMessageIdTests extends ESTestCase {
ExecutableEmailAction secondEmailAction = new ExecutableEmailAction(emailAction, logger, emailService, textTemplateEngine,
htmlSanitizer, Collections.emptyMap());
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
firstEmailAction.execute("my_first_action_id", ctx, Payload.EMPTY);
secondEmailAction.execute("my_second_action_id", ctx, Payload.EMPTY);

View File

@ -32,7 +32,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
@Before
public void init() throws Exception {
hipchatService = mock(HipChatService.class);
factory = new HipChatActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), hipchatService);
factory = new HipChatActionFactory(mock(TextTemplateEngine.class), hipchatService);
}
public void testParseAction() throws Exception {
@ -53,7 +53,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
public void testParseActionUnknownAccount() throws Exception {
hipchatService = new HipChatService(Settings.EMPTY, null, new ClusterSettings(Settings.EMPTY,
new HashSet<>(HipChatService.getSettings())));
factory = new HipChatActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), hipchatService);
factory = new HipChatActionFactory(mock(TextTemplateEngine.class), hipchatService);
HipChatAction action = hipchatAction("_unknown", "_body").build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = createParser(jsonBuilder);

View File

@ -31,7 +31,7 @@ public class PagerDutyActionFactoryTests extends ESTestCase {
@Before
public void init() throws Exception {
service = mock(PagerDutyService.class);
factory = new PagerDutyActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), service);
factory = new PagerDutyActionFactory(mock(TextTemplateEngine.class), service);
}
public void testParseAction() throws Exception {
@ -49,7 +49,7 @@ public class PagerDutyActionFactoryTests extends ESTestCase {
}
public void testParseActionUnknownAccount() throws Exception {
factory = new PagerDutyActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), new PagerDutyService(Settings.EMPTY, null,
factory = new PagerDutyActionFactory(mock(TextTemplateEngine.class), new PagerDutyService(Settings.EMPTY, null,
new ClusterSettings(Settings.EMPTY, new HashSet<>(PagerDutyService.getSettings()))));
PagerDutyAction action = triggerPagerDutyAction("_unknown", "_body").build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);

View File

@ -31,7 +31,7 @@ public class SlackActionFactoryTests extends ESTestCase {
@Before
public void init() throws Exception {
service = mock(SlackService.class);
factory = new SlackActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), service);
factory = new SlackActionFactory(mock(TextTemplateEngine.class), service);
}
public void testParseAction() throws Exception {
@ -50,7 +50,7 @@ public class SlackActionFactoryTests extends ESTestCase {
public void testParseActionUnknownAccount() throws Exception {
SlackService service = new SlackService(Settings.EMPTY, null, new ClusterSettings(Settings.EMPTY,
new HashSet<>(SlackService.getSettings())));
factory = new SlackActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), service);
factory = new SlackActionFactory(mock(TextTemplateEngine.class), service);
SlackAction action = slackAction("_unknown", createRandomTemplate()).build();
XContentBuilder jsonBuilder = jsonBuilder().value(action);
XContentParser parser = createParser(jsonBuilder);

View File

@ -208,7 +208,7 @@ public class WebhookActionTests extends ESTestCase {
}
private WebhookActionFactory webhookFactory(HttpClient client) {
return new WebhookActionFactory(Settings.EMPTY, client, templateEngine);
return new WebhookActionFactory(client, templateEngine);
}
public void testThatSelectingProxyWorks() throws Exception {

View File

@ -1015,7 +1015,7 @@ public class ExecutionServiceTests extends ESTestCase {
public void testUpdateWatchStatusDoesNotUpdateState() throws Exception {
WatchStatus status = new WatchStatus(DateTime.now(UTC), Collections.emptyMap());
Watch watch = new Watch("_id", new ManualTrigger(), new ExecutableNoneInput(logger), InternalAlwaysCondition.INSTANCE, null, null,
Watch watch = new Watch("_id", new ManualTrigger(), new ExecutableNoneInput(), InternalAlwaysCondition.INSTANCE, null, null,
Collections.emptyList(), null, status, 1L);
final AtomicBoolean assertionsTriggered = new AtomicBoolean(false);

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.watcher.input;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.ESTestCase;
@ -17,7 +16,7 @@ import static org.hamcrest.Matchers.containsString;
public class InputRegistryTests extends ESTestCase {
public void testParseEmptyInput() throws Exception {
InputRegistry registry = new InputRegistry(Settings.EMPTY, emptyMap());
InputRegistry registry = new InputRegistry(emptyMap());
XContentParser parser = createParser(jsonBuilder().startObject().endObject());
parser.nextToken();
try {
@ -29,7 +28,7 @@ public class InputRegistryTests extends ESTestCase {
}
public void testParseArrayInput() throws Exception {
InputRegistry registry = new InputRegistry(Settings.EMPTY, emptyMap());
InputRegistry registry = new InputRegistry(emptyMap());
XContentParser parser = createParser(jsonBuilder().startArray().endArray());
parser.nextToken();
try {

View File

@ -10,7 +10,6 @@ import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.collect.Tuple;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
@ -63,11 +62,11 @@ public class ChainInputTests extends ESTestCase {
*/
public void testThatExecutionWorks() throws Exception {
Map<String, InputFactory> factories = new HashMap<>();
factories.put("simple", new SimpleInputFactory(Settings.EMPTY));
factories.put("simple", new SimpleInputFactory());
// hackedy hack...
InputRegistry inputRegistry = new InputRegistry(Settings.EMPTY, factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(Settings.EMPTY, inputRegistry);
InputRegistry inputRegistry = new InputRegistry(factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(inputRegistry);
factories.put("chain", chainInputFactory);
XContentBuilder builder = jsonBuilder().startObject().startArray("inputs")
@ -88,7 +87,7 @@ public class ChainInputTests extends ESTestCase {
// now execute
ExecutableChainInput executableChainInput = chainInputFactory.createExecutable(chainInput);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
ChainInput.Result result = executableChainInput.execute(ctx, new Payload.Simple());
Payload payload = result.payload();
assertThat(payload.data(), hasKey("first"));
@ -117,10 +116,10 @@ public class ChainInputTests extends ESTestCase {
// parsing it back as well!
Map<String, InputFactory> factories = new HashMap<>();
factories.put("simple", new SimpleInputFactory(Settings.EMPTY));
factories.put("simple", new SimpleInputFactory());
InputRegistry inputRegistry = new InputRegistry(Settings.EMPTY, factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(Settings.EMPTY, inputRegistry);
InputRegistry inputRegistry = new InputRegistry(factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(inputRegistry);
factories.put("chain", chainInputFactory);
XContentParser parser = createParser(builder);
@ -177,10 +176,10 @@ public class ChainInputTests extends ESTestCase {
*/
public void testParsingShouldBeStrictWhenClosingInputs() throws Exception {
Map<String, InputFactory> factories = new HashMap<>();
factories.put("simple", new SimpleInputFactory(Settings.EMPTY));
factories.put("simple", new SimpleInputFactory());
InputRegistry inputRegistry = new InputRegistry(Settings.EMPTY, factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(Settings.EMPTY, inputRegistry);
InputRegistry inputRegistry = new InputRegistry(factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(inputRegistry);
factories.put("chain", chainInputFactory);
XContentBuilder builder = jsonBuilder().startObject().startArray("inputs").startObject()
@ -206,10 +205,10 @@ public class ChainInputTests extends ESTestCase {
*/
public void testParsingShouldBeStrictWhenStartingInputs() throws Exception {
Map<String, InputFactory> factories = new HashMap<>();
factories.put("simple", new SimpleInputFactory(Settings.EMPTY));
factories.put("simple", new SimpleInputFactory());
InputRegistry inputRegistry = new InputRegistry(Settings.EMPTY, factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(Settings.EMPTY, inputRegistry);
InputRegistry inputRegistry = new InputRegistry(factories);
ChainInputFactory chainInputFactory = new ChainInputFactory(inputRegistry);
factories.put("chain", chainInputFactory);
XContentBuilder builder = jsonBuilder().startObject().startArray("inputs")

View File

@ -32,7 +32,7 @@ public class ExecutableChainInputTests extends ESTestCase {
ChainInput chainInput = new ChainInput(Arrays.asList(new Tuple<>("whatever", new SimpleInput(Payload.EMPTY))));
Tuple<String, ExecutableInput> tuple = new Tuple<>("whatever", new FailingExecutableInput());
ExecutableChainInput executableChainInput = new ExecutableChainInput(chainInput, Arrays.asList(tuple), logger);
ExecutableChainInput executableChainInput = new ExecutableChainInput(chainInput, Arrays.asList(tuple));
ChainInput.Result result = executableChainInput.execute(ctx, Payload.EMPTY);
assertThat(result.status(), is(Status.SUCCESS));
}
@ -40,7 +40,7 @@ public class ExecutableChainInputTests extends ESTestCase {
private class FailingExecutableInput extends ExecutableInput<SimpleInput, Input.Result> {
protected FailingExecutableInput() {
super(new SimpleInput(Payload.EMPTY), ExecutableChainInputTests.this.logger);
super(new SimpleInput(Payload.EMPTY));
}
@Override

View File

@ -113,11 +113,11 @@ public class HttpInputTests extends ESTestCase {
break;
}
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
when(templateEngine.render(eq(new TextTemplate("_body")), any(Map.class))).thenReturn("_body");
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
assertThat(result.type(), equalTo(HttpInput.TYPE));
assertThat(result.payload().data(), hasEntry("key", "value"));
@ -130,13 +130,13 @@ public class HttpInputTests extends ESTestCase {
.method(HttpMethod.POST)
.body("_body");
HttpInput httpInput = InputBuilders.httpInput(request.build()).expectedResponseXContentType(HttpContentType.TEXT).build();
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
String notJson = "This is not json";
HttpResponse response = new HttpResponse(123, notJson.getBytes(StandardCharsets.UTF_8));
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
when(templateEngine.render(eq(new TextTemplate("_body")), any(Map.class))).thenReturn("_body");
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
assertThat(result.type(), equalTo(HttpInput.TYPE));
assertThat(result.payload().data().get("_value").toString(), equalTo(notJson));
@ -232,7 +232,7 @@ public class HttpInputTests extends ESTestCase {
HttpRequestTemplate.Builder request = HttpRequestTemplate.builder("localhost", 8080);
HttpInput httpInput = InputBuilders.httpInput(request.build()).build();
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
Map<String, String[]> responseHeaders = new HashMap<>();
responseHeaders.put(headerName, new String[] { headerValue });
@ -248,7 +248,7 @@ public class HttpInputTests extends ESTestCase {
when(templateEngine.render(eq(new TextTemplate("_body")), any(Map.class))).thenReturn("_body");
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
assertThat(result.type(), equalTo(HttpInput.TYPE));
@ -264,7 +264,7 @@ public class HttpInputTests extends ESTestCase {
public void testThatExpectedContentTypeOverridesReturnedContentType() throws Exception {
HttpRequestTemplate template = HttpRequestTemplate.builder("http:://127.0.0.1:12345").build();
HttpInput httpInput = new HttpInput(template, HttpContentType.TEXT, null);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
Map<String, String[]> headers = new HashMap<>(1);
String contentType = randomFrom("application/json", "application/json; charset=UTF-8", "text/html", "application/yaml",
@ -274,7 +274,7 @@ public class HttpInputTests extends ESTestCase {
HttpResponse httpResponse = new HttpResponse(200, body, headers);
when(httpClient.execute(any())).thenReturn(httpResponse);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, Payload.EMPTY);
assertThat(result.payload().data(), hasEntry("_value", body));
assertThat(result.payload().data(), not(hasKey("foo")));
@ -286,9 +286,9 @@ public class HttpInputTests extends ESTestCase {
HttpRequestTemplate.Builder request = HttpRequestTemplate.builder("localhost", 8080);
HttpInput httpInput = InputBuilders.httpInput(request.build()).build();
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
assertThat(result.statusCode, is(200));
assertThat(result.payload().data(), hasKey("_status_code"));
@ -303,9 +303,9 @@ public class HttpInputTests extends ESTestCase {
HttpRequestTemplate.Builder request = HttpRequestTemplate.builder("localhost", 8080);
HttpInput httpInput = InputBuilders.httpInput(request.build()).build();
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
assertThat(result.statusCode, is(200));
assertThat(result.payload().data(), not(hasKey("_value")));
@ -322,9 +322,9 @@ public class HttpInputTests extends ESTestCase {
HttpRequestTemplate.Builder request = HttpRequestTemplate.builder("localhost", 8080);
HttpInput httpInput = InputBuilders.httpInput(request.build()).build();
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, logger, httpClient, templateEngine);
ExecutableHttpInput input = new ExecutableHttpInput(httpInput, httpClient, templateEngine);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
HttpInput.Result result = input.execute(ctx, new Payload.Simple());
assertThat(result.getException(), is(notNullValue()));

View File

@ -6,7 +6,6 @@
package org.elasticsearch.xpack.watcher.input.simple;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.test.ESTestCase;
@ -29,7 +28,7 @@ public class SimpleInputTests extends ESTestCase {
Map<String, Object> data = new HashMap<>();
data.put("foo", "bar");
data.put("baz", new ArrayList<String>() );
ExecutableInput staticInput = new ExecutableSimpleInput(new SimpleInput(new Payload.Simple(data)), logger);
ExecutableInput staticInput = new ExecutableSimpleInput(new SimpleInput(new Payload.Simple(data)));
Input.Result staticResult = staticInput.execute(null, new Payload.Simple());
assertEquals(staticResult.payload().data().get("foo"), "bar");
@ -43,7 +42,7 @@ public class SimpleInputTests extends ESTestCase {
data.put("baz", new ArrayList<String>());
XContentBuilder jsonBuilder = jsonBuilder().map(data);
InputFactory parser = new SimpleInputFactory(Settings.builder().build());
InputFactory parser = new SimpleInputFactory();
XContentParser xContentParser = createParser(jsonBuilder);
xContentParser.nextToken();
ExecutableInput input = parser.parseExecutable("_id", xContentParser);
@ -59,7 +58,7 @@ public class SimpleInputTests extends ESTestCase {
public void testParserInvalid() throws Exception {
XContentBuilder jsonBuilder = jsonBuilder().value("just a string");
InputFactory parser = new SimpleInputFactory(Settings.builder().build());
InputFactory parser = new SimpleInputFactory();
XContentParser xContentParser = createParser(jsonBuilder);
xContentParser.nextToken();
try {

View File

@ -7,7 +7,6 @@ package org.elasticsearch.xpack.watcher.input.transform;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
@ -52,7 +51,7 @@ public class TransformInputTests extends ESTestCase {
TransformInput transformInput = new TransformInput(scriptTransform);
ExecutableTransform executableTransform = new ExecutableScriptTransform(scriptTransform, logger, scriptService);
ExecutableInput input = new ExecutableTransformInput(transformInput, logger, executableTransform);
ExecutableInput input = new ExecutableTransformInput(transformInput, executableTransform);
WatchExecutionContext ctx = WatcherTestUtils.mockExecutionContext("_id", Payload.EMPTY);
Input.Result result = input.execute(ctx, new Payload.Simple());
@ -62,9 +61,9 @@ public class TransformInputTests extends ESTestCase {
public void testParserValid() throws Exception {
Map<String, TransformFactory> transformFactories = Collections.singletonMap("script",
new ScriptTransformFactory(Settings.EMPTY, scriptService));
new ScriptTransformFactory(scriptService));
TransformRegistry registry = new TransformRegistry(transformFactories);
TransformInputFactory factory = new TransformInputFactory(Settings.EMPTY, registry);
TransformInputFactory factory = new TransformInputFactory(registry);
// { "script" : { "lang" : "mockscript", "source" : "1" } }
XContentBuilder builder = jsonBuilder().startObject().startObject("script")
@ -86,9 +85,9 @@ public class TransformInputTests extends ESTestCase {
XContentBuilder jsonBuilder = jsonBuilder().value("just a string");
Map<String, TransformFactory> transformFactories = Collections.singletonMap("script",
new ScriptTransformFactory(Settings.EMPTY, scriptService));
new ScriptTransformFactory(scriptService));
TransformRegistry registry = new TransformRegistry(transformFactories);
TransformInputFactory factory = new TransformInputFactory(Settings.EMPTY, registry);
TransformInputFactory factory = new TransformInputFactory(registry);
XContentParser parser = createParser(jsonBuilder);
parser.nextToken();
@ -105,9 +104,9 @@ public class TransformInputTests extends ESTestCase {
public void testTransformInputToXContentIsSameAsParsing() throws Exception {
Map<String, TransformFactory> transformFactories = Collections.singletonMap("script",
new ScriptTransformFactory(Settings.EMPTY, scriptService));
new ScriptTransformFactory(scriptService));
TransformRegistry registry = new TransformRegistry(transformFactories);
TransformInputFactory factory = new TransformInputFactory(Settings.EMPTY, registry);
TransformInputFactory factory = new TransformInputFactory(registry);
XContentBuilder jsonBuilder = jsonBuilder().startObject().startObject("script")
.field("source", "1")

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.watcher.test;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.XPackLicenseState;
import org.elasticsearch.threadpool.ThreadPool;
@ -30,13 +30,13 @@ import java.util.function.Consumer;
import java.util.stream.Stream;
public class TimeWarpedWatcher extends LocalStateCompositeXPackPlugin {
private static final Logger logger = LogManager.getLogger(TimeWarpedWatcher.class);
// use a single clock across all nodes using this plugin, this lets keep it static
private static final ClockMock clock = new ClockMock();
public TimeWarpedWatcher(final Settings settings, final Path configPath) throws Exception {
super(settings, configPath);
Logger logger = Loggers.getLogger(TimeWarpedWatcher.class, settings);
logger.info("using time warped watchers plugin");
TimeWarpedWatcher thisVar = this;
@ -69,7 +69,7 @@ public class TimeWarpedWatcher extends LocalStateCompositeXPackPlugin {
@Override
protected Consumer<Iterable<TriggerEvent>> getTriggerEngineListener(ExecutionService executionService){
return new SyncTriggerEventConsumer(settings, executionService);
return new SyncTriggerEventConsumer(executionService);
}
});
}

View File

@ -125,10 +125,10 @@ public final class WatcherTestUtils {
.buildMock();
}
public static WatchExecutionContext createWatchExecutionContext(Logger logger) throws Exception {
public static WatchExecutionContext createWatchExecutionContext() throws Exception {
Watch watch = new Watch("test-watch",
new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))),
new ExecutableSimpleInput(new SimpleInput(new Payload.Simple()), logger),
new ExecutableSimpleInput(new SimpleInput(new Payload.Simple())),
InternalAlwaysCondition.INSTANCE,
null,
null,
@ -175,7 +175,7 @@ public final class WatcherTestUtils {
return new Watch(
watchName,
new ScheduleTrigger(new CronSchedule("0/5 * * * * ? *")),
new ExecutableSimpleInput(new SimpleInput(new Payload.Simple(Collections.singletonMap("bar", "foo"))), logger),
new ExecutableSimpleInput(new SimpleInput(new Payload.Simple(Collections.singletonMap("bar", "foo")))),
InternalAlwaysCondition.INSTANCE,
new ExecutableSearchTransform(searchTransform, logger, client, searchTemplateService, TimeValue.timeValueMinutes(1)),
new TimeValue(0),

View File

@ -5,9 +5,7 @@
*/
package org.elasticsearch.xpack.watcher.test.bench;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.metrics.MeanMetric;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.xpack.core.watcher.trigger.TriggerEvent;
@ -33,9 +31,6 @@ import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interva
@SuppressForbidden(reason = "benchmark")
public class ScheduleEngineTriggerBenchmark {
private static final Logger logger = ESLoggerFactory.getLogger(ScheduleEngineTriggerBenchmark.class);
public static void main(String[] args) throws Exception {
int numWatches = 1000;
int interval = 2;
@ -61,7 +56,7 @@ public class ScheduleEngineTriggerBenchmark {
.build();
List<Watch> watches = new ArrayList<>(numWatches);
for (int i = 0; i < numWatches; i++) {
watches.add(new Watch("job_" + i, new ScheduleTrigger(interval(interval + "s")), new ExecutableNoneInput(logger),
watches.add(new Watch("job_" + i, new ScheduleTrigger(interval(interval + "s")), new ExecutableNoneInput(),
InternalAlwaysCondition.INSTANCE, null, null, Collections.emptyList(), null, null, 1L));
}
ScheduleRegistry scheduleRegistry = new ScheduleRegistry(emptySet());

View File

@ -5,8 +5,8 @@
*/
package org.elasticsearch.xpack.watcher.test.bench;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.node.MockNode;
@ -207,7 +207,7 @@ public class WatcherExecutorServiceBenchmark {
public BenchmarkWatcher(Settings settings) {
super(settings);
Loggers.getLogger(BenchmarkWatcher.class, settings).info("using watcher benchmark plugin");
LogManager.getLogger(BenchmarkWatcher.class).info("using watcher benchmark plugin");
}
@Override

View File

@ -101,9 +101,9 @@ public class SearchInputTests extends ESTestCase {
SearchSourceBuilder searchSourceBuilder = searchSource().query(boolQuery().must(matchQuery("event_type", "a")));
WatcherSearchTemplateRequest request = WatcherTestUtils.templateRequest(searchSourceBuilder);
ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null), logger,
ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null),
client, watcherSearchTemplateService(), TimeValue.timeValueMinutes(1));
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
SearchInput.Result result = searchInput.execute(ctx, new Payload.Simple());
@ -127,9 +127,9 @@ public class SearchInputTests extends ESTestCase {
SearchType searchType = getRandomSupportedSearchType();
WatcherSearchTemplateRequest request = WatcherTestUtils.templateRequest(searchSourceBuilder, searchType);
ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null), logger,
ExecutableSearchInput searchInput = new ExecutableSearchInput(new SearchInput(request, null, null, null),
client, watcherSearchTemplateService(), TimeValue.timeValueMinutes(1));
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
SearchInput.Result result = searchInput.execute(ctx, new Payload.Simple());
assertThat(result.status(), is(Input.Result.Status.SUCCESS));
@ -179,7 +179,7 @@ public class SearchInputTests extends ESTestCase {
assertThat(input.getRequest().getSearchSource(), is(BytesArray.EMPTY));
ExecutableSearchInput executableSearchInput = factory.createExecutable(input);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext(logger);
WatchExecutionContext ctx = WatcherTestUtils.createWatchExecutionContext();
SearchInput.Result result = executableSearchInput.execute(ctx, Payload.Simple.EMPTY);
assertThat(result.status(), is(Input.Result.Status.SUCCESS));
// no body in the search request

View File

@ -133,7 +133,7 @@ public class ScriptTransformTests extends ESTestCase {
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser);
ExecutableScriptTransform transform = new ScriptTransformFactory(service).parseExecutable("_id", parser);
Script script = new Script(type, type == ScriptType.STORED ? null : "_lang", "_script", singletonMap("key", "value"));
assertThat(transform.transform().getScript(), equalTo(script));
}
@ -144,7 +144,7 @@ public class ScriptTransformTests extends ESTestCase {
XContentParser parser = createParser(builder);
parser.nextToken();
ExecutableScriptTransform transform = new ScriptTransformFactory(Settings.EMPTY, service).parseExecutable("_id", parser);
ExecutableScriptTransform transform = new ScriptTransformFactory(service).parseExecutable("_id", parser);
assertEquals(new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, "_script", emptyMap()), transform.transform().getScript());
}
@ -155,7 +155,7 @@ public class ScriptTransformTests extends ESTestCase {
Collections.emptyList(), "whatever", "whatever");
when(scriptService.compile(anyObject(), eq(WatcherTransformScript.CONTEXT))).thenThrow(scriptException);
ScriptTransformFactory transformFactory = new ScriptTransformFactory(Settings.builder().build(), scriptService);
ScriptTransformFactory transformFactory = new ScriptTransformFactory(scriptService);
XContentBuilder builder = jsonBuilder().startObject()
.field(scriptTypeField(randomFrom(ScriptType.values())), "whatever")
@ -170,7 +170,7 @@ public class ScriptTransformTests extends ESTestCase {
}
public void testScriptConditionParserBadLang() throws Exception {
ScriptTransformFactory transformFactory = new ScriptTransformFactory(Settings.builder().build(), createScriptService());
ScriptTransformFactory transformFactory = new ScriptTransformFactory(createScriptService());
String script = "return true";
XContentBuilder builder = jsonBuilder().startObject()
.field(scriptTypeField(ScriptType.INLINE), script)

View File

@ -6,7 +6,7 @@
package org.elasticsearch.xpack.watcher.trigger;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.logging.Loggers;
import org.apache.logging.log4j.LogManager;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
@ -30,13 +30,12 @@ import java.util.concurrent.ConcurrentMap;
* jobCount.
*/
public class ScheduleTriggerEngineMock extends ScheduleTriggerEngine {
private static final Logger logger = LogManager.getLogger(ScheduleTriggerEngineMock.class);
private final Logger logger;
private final ConcurrentMap<String, Watch> watches = new ConcurrentHashMap<>();
public ScheduleTriggerEngineMock(Settings settings, ScheduleRegistry scheduleRegistry, Clock clock) {
super(settings, scheduleRegistry, clock);
this.logger = Loggers.getLogger(ScheduleTriggerEngineMock.class, settings);
}
@Override

View File

@ -144,7 +144,7 @@ public class TriggerServiceTests extends ESTestCase {
}
private void setInput(Watch watch) {
ExecutableNoneInput noneInput = new ExecutableNoneInput(logger);
ExecutableNoneInput noneInput = new ExecutableNoneInput();
when(watch.input()).thenReturn(noneInput);
}

View File

@ -255,7 +255,7 @@ public class TickerScheduleEngineTests extends ESTestCase {
}
private Watch createWatch(String name, Schedule schedule) {
return new Watch(name, new ScheduleTrigger(schedule), new ExecutableNoneInput(logger),
return new Watch(name, new ScheduleTrigger(schedule), new ExecutableNoneInput(),
InternalAlwaysCondition.INSTANCE, null, null,
Collections.emptyList(), null, null, Versions.MATCH_ANY);
}

View File

@ -298,7 +298,7 @@ public class WatchTests extends ESTestCase {
TriggerService triggerService = new TriggerService(Settings.EMPTY, singleton(triggerEngine));
ConditionRegistry conditionRegistry = conditionRegistry();
InputRegistry inputRegistry = registry(new ExecutableNoneInput(logger).type());
InputRegistry inputRegistry = registry(new ExecutableNoneInput().type());
TransformRegistry transformRegistry = transformRegistry();
ActionRegistry actionRegistry = registry(Collections.emptyList(), conditionRegistry, transformRegistry);
@ -509,10 +509,10 @@ public class WatchTests extends ESTestCase {
SearchInput searchInput = searchInput(WatcherTestUtils.templateRequest(searchSource(), "idx"))
.timeout(randomBoolean() ? null : timeValueSeconds(between(1, 10000)))
.build();
return new ExecutableSearchInput(searchInput, logger, client, searchTemplateService, null);
return new ExecutableSearchInput(searchInput, client, searchTemplateService, null);
default:
SimpleInput simpleInput = InputBuilders.simpleInput(singletonMap("_key", "_val")).build();
return new ExecutableSimpleInput(simpleInput, logger);
return new ExecutableSimpleInput(simpleInput);
}
}
@ -521,10 +521,10 @@ public class WatchTests extends ESTestCase {
switch (inputType) {
case SearchInput.TYPE:
parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, xContentRegistry(), scriptService));
return new InputRegistry(Settings.EMPTY, parsers);
return new InputRegistry(parsers);
default:
parsers.put(SimpleInput.TYPE, new SimpleInputFactory(settings));
return new InputRegistry(Settings.EMPTY, parsers);
parsers.put(SimpleInput.TYPE, new SimpleInputFactory());
return new InputRegistry(parsers);
}
}
@ -568,7 +568,7 @@ public class WatchTests extends ESTestCase {
private TransformRegistry transformRegistry() {
Map<String, TransformFactory> factories = new HashMap<>();
factories.put(ScriptTransform.TYPE, new ScriptTransformFactory(settings, scriptService));
factories.put(ScriptTransform.TYPE, new ScriptTransformFactory(scriptService));
factories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, xContentRegistry(), scriptService));
return new TransformRegistry(unmodifiableMap(factories));
}
@ -618,7 +618,7 @@ public class WatchTests extends ESTestCase {
parsers.put(IndexAction.TYPE, new IndexActionFactory(settings, client));
break;
case WebhookAction.TYPE:
parsers.put(WebhookAction.TYPE, new WebhookActionFactory(settings, httpClient, templateEngine));
parsers.put(WebhookAction.TYPE, new WebhookActionFactory(httpClient, templateEngine));
break;
case LoggingAction.TYPE:
parsers.put(LoggingAction.TYPE, new LoggingActionFactory(new MockTextTemplateEngine()));