From 42076f89cedb6232ef5b007971f0e0941835bb70 Mon Sep 17 00:00:00 2001 From: Ryan Ernst Date: Wed, 3 Aug 2016 15:32:56 -0700 Subject: [PATCH] Internal: Deguice notification services This change removes guice from creating notification componenents. It also removes the Notification helper class, as it just makes looking at what stuff xpack adds more obfuscated. Original commit: elastic/x-pack-elasticsearch@69b8ea47354ead0b19bf206e469a23854731ed6e --- .../smoketest/WatcherTemplateIT.java | 5 +- .../org/elasticsearch/xpack/XPackPlugin.java | 64 +++++++++--- .../common/http/HttpRequestTemplate.java | 3 +- .../text/DefaultTextTemplateEngine.java | 97 ------------------- .../xpack/common/text/TextTemplateEngine.java | 90 +++++++++++++++-- .../xpack/common/text/TextTemplateModule.java | 20 ---- .../xpack/notification/Notification.java | 59 ----------- .../notification/NotificationModule.java | 51 ---------- .../notification/email/EmailService.java | 1 - .../attachment/EmailAttachmentsParser.java | 1 - .../HttpEmailAttachementParser.java | 8 +- .../notification/hipchat/HipChatService.java | 1 - .../hipchat/IntegrationAccount.java | 2 +- .../notification/hipchat/UserAccount.java | 2 +- .../xpack/notification/hipchat/V1Account.java | 2 +- .../pagerduty/PagerDutyService.java | 1 - .../notification/slack/SlackService.java | 1 - .../xpack/common/text/TextTemplateTests.java | 2 +- .../actions/email/EmailActionFactory.java | 2 +- .../actions/email/ExecutableEmailAction.java | 2 +- .../hipchat/ExecutableHipChatAction.java | 2 +- .../actions/hipchat/HipChatActionFactory.java | 2 +- .../logging/ExecutableLoggingAction.java | 2 +- .../actions/logging/LoggingActionFactory.java | 2 +- .../pagerduty/ExecutablePagerDutyAction.java | 2 +- .../pagerduty/PagerDutyActionFactory.java | 2 +- .../actions/slack/ExecutableSlackAction.java | 2 +- .../actions/slack/SlackActionFactory.java | 2 +- .../webhook/ExecutableWebhookAction.java | 2 +- .../actions/webhook/WebhookActionFactory.java | 2 +- .../watcher/input/http/HttpInputFactory.java | 2 +- .../script/MockMustacheScriptEngine.java | 4 +- .../actions/email/EmailActionTests.java | 2 +- .../hipchat/HipChatActionFactoryTests.java | 2 +- .../actions/hipchat/HipChatActionTests.java | 2 +- .../actions/logging/LoggingActionTests.java | 2 +- .../PagerDutyActionFactoryTests.java | 2 +- .../pagerduty/PagerDutyActionTests.java | 2 +- .../slack/SlackActionFactoryTests.java | 2 +- .../actions/slack/SlackActionTests.java | 2 +- .../actions/webhook/WebhookActionTests.java | 2 +- .../watcher/test/MockTextTemplateEngine.java | 7 +- 42 files changed, 175 insertions(+), 290 deletions(-) delete mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/DefaultTextTemplateEngine.java delete mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateModule.java delete mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/Notification.java delete mode 100644 elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/NotificationModule.java diff --git a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java index 5a652984247..17ee4d063d6 100644 --- a/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java +++ b/elasticsearch/qa/smoke-test-watcher-with-mustache/src/test/java/org/elasticsearch/smoketest/WatcherTemplateIT.java @@ -17,9 +17,8 @@ import org.elasticsearch.script.ScriptSettings; import org.elasticsearch.script.mustache.MustacheScriptEngineService; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.watcher.ResourceWatcherService; -import org.elasticsearch.xpack.common.text.DefaultTextTemplateEngine; -import org.elasticsearch.xpack.common.text.TextTemplate; import org.elasticsearch.xpack.common.text.TextTemplateEngine; +import org.elasticsearch.xpack.common.text.TextTemplate; import org.elasticsearch.xpack.watcher.support.WatcherScript; import org.junit.Before; import org.mockito.Mockito; @@ -52,7 +51,7 @@ public class WatcherTemplateIT extends ESTestCase { ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry); ScriptService scriptService = new ScriptService(setting, environment, resourceWatcherService, scriptEngineRegistry, registry, scriptSettings); - engine = new DefaultTextTemplateEngine(Settings.EMPTY, scriptService); + engine = new TextTemplateEngine(Settings.EMPTY, scriptService); } public void testEscaping() throws Exception { diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java index 91af5e1e75b..3daea04e9cd 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/XPackPlugin.java @@ -27,13 +27,13 @@ import org.elasticsearch.action.support.ActionFilter; import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.cluster.service.ClusterService; -import org.elasticsearch.common.component.LifecycleComponent; import org.elasticsearch.common.inject.Binder; import org.elasticsearch.common.inject.Module; import org.elasticsearch.common.inject.multibindings.Multibinder; import org.elasticsearch.common.inject.util.Providers; import org.elasticsearch.common.io.stream.NamedWriteableRegistry; import org.elasticsearch.common.network.NetworkModule; +import org.elasticsearch.common.settings.ClusterSettings; import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.env.Environment; @@ -62,7 +62,7 @@ import org.elasticsearch.xpack.common.http.auth.HttpAuthFactory; import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry; import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth; import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory; -import org.elasticsearch.xpack.common.text.TextTemplateModule; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.extensions.XPackExtension; import org.elasticsearch.xpack.extensions.XPackExtensionsService; import org.elasticsearch.xpack.graph.Graph; @@ -70,9 +70,17 @@ import org.elasticsearch.xpack.graph.GraphFeatureSet; import org.elasticsearch.xpack.monitoring.Monitoring; import org.elasticsearch.xpack.monitoring.MonitoringFeatureSet; import org.elasticsearch.xpack.monitoring.MonitoringSettings; -import org.elasticsearch.xpack.notification.Notification; import org.elasticsearch.xpack.notification.email.Account; +import org.elasticsearch.xpack.notification.email.EmailService; +import org.elasticsearch.xpack.notification.email.attachment.DataAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentParser; +import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; +import org.elasticsearch.xpack.notification.email.attachment.HttpEmailAttachementParser; import org.elasticsearch.xpack.notification.email.support.BodyPartSource; +import org.elasticsearch.xpack.notification.hipchat.HipChatService; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; +import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; +import org.elasticsearch.xpack.notification.slack.SlackService; import org.elasticsearch.xpack.rest.action.RestXPackInfoAction; import org.elasticsearch.xpack.rest.action.RestXPackUsageAction; import org.elasticsearch.xpack.security.InternalClient; @@ -137,7 +145,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I protected Monitoring monitoring; protected Watcher watcher; protected Graph graph; - protected Notification notification; public XPackPlugin(Settings settings) throws IOException { this.settings = settings; @@ -150,7 +157,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I this.monitoring = new Monitoring(settings, env, licenseState); this.watcher = new Watcher(settings); this.graph = new Graph(settings); - this.notification = new Notification(settings); // Check if the node is a transport client. if (transportClientMode == false) { this.extensionsService = new XPackExtensionsService(settings, resolveXPackExtensionsFile(env), getExtensions()); @@ -173,15 +179,12 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I public Collection createGuiceModules() { ArrayList modules = new ArrayList<>(); modules.add(b -> b.bind(Clock.class).toInstance(getClock())); - modules.addAll(notification.nodeModules()); modules.addAll(security.nodeModules()); modules.addAll(watcher.nodeModules()); modules.addAll(monitoring.nodeModules()); modules.addAll(graph.createGuiceModules()); - if (transportClientMode == false) { - modules.add(new TextTemplateModule()); - } else { + if (transportClientMode) { modules.add(b -> b.bind(XPackLicenseState.class).toProvider(Providers.of(null))); } return modules; @@ -208,8 +211,31 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService())); // TODO: add more auth types, or remove this indirection HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories); - components.add(new HttpRequestTemplate.Parser(httpAuthRegistry)); - components.add(new HttpClient(settings, httpAuthRegistry, env)); + HttpRequestTemplate.Parser httpTemplateParser = new HttpRequestTemplate.Parser(httpAuthRegistry); + components.add(httpTemplateParser); + final HttpClient httpClient = new HttpClient(settings, httpAuthRegistry, env); + components.add(httpClient); + + components.addAll(createNotificationComponents(clusterService.getClusterSettings(), httpClient, + httpTemplateParser, scriptService)); + + return components; + } + + private Collection createNotificationComponents(ClusterSettings clusterSettings, HttpClient httpClient, + HttpRequestTemplate.Parser httpTemplateParser, ScriptService scriptService) { + List components = new ArrayList<>(); + components.add(new EmailService(settings, security.getCryptoService(), clusterSettings)); + components.add(new HipChatService(settings, httpClient, clusterSettings)); + components.add(new SlackService(settings, httpClient, clusterSettings)); + components.add(new PagerDutyService(settings, httpClient, clusterSettings)); + + TextTemplateEngine textTemplateEngine = new TextTemplateEngine(settings, scriptService); + components.add(textTemplateEngine); + Map parsers = new HashMap<>(); + parsers.put(HttpEmailAttachementParser.TYPE, new HttpEmailAttachementParser(httpClient, httpTemplateParser, textTemplateEngine)); + parsers.put(DataAttachmentParser.TYPE, new DataAttachmentParser()); + components.add(new EmailAttachmentsParser(parsers)); return components; } @@ -245,7 +271,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I @Override public List> getSettings() { ArrayList> settings = new ArrayList<>(); - settings.addAll(notification.getSettings()); settings.addAll(security.getSettings()); settings.addAll(MonitoringSettings.getSettings()); settings.addAll(watcher.getSettings()); @@ -254,6 +279,12 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I // we add the `xpack.version` setting to all internal indices settings.add(Setting.simpleString("index.xpack.version", Setting.Property.IndexScope)); + // notification services + settings.add(SlackService.SLACK_ACCOUNT_SETTING); + settings.add(EmailService.EMAIL_ACCOUNT_SETTING); + settings.add(HipChatService.HIPCHAT_ACCOUNT_SETTING); + settings.add(PagerDutyService.PAGERDUTY_ACCOUNT_SETTING); + // http settings settings.add(Setting.simpleString("xpack.http.default_read_timeout", Setting.Property.NodeScope)); settings.add(Setting.simpleString("xpack.http.default_connection_timeout", Setting.Property.NodeScope)); @@ -265,7 +296,12 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I @Override public List getSettingsFilter() { List filters = new ArrayList<>(); - filters.addAll(notification.getSettingsFilter()); + filters.add("xpack.notification.email.account.*.smtp.password"); + filters.add("xpack.notification.slack.account.*.url"); + filters.add("xpack.notification.pagerduty.account.*.url"); + filters.add("xpack.notification.pagerduty." + PagerDutyAccount.SERVICE_KEY_SETTING); + filters.add("xpack.notification.pagerduty.account.*." + PagerDutyAccount.SERVICE_KEY_SETTING); + filters.add("xpack.notification.hipchat.account.*.auth_token"); filters.addAll(security.getSettingsFilter()); filters.addAll(MonitoringSettings.getSettingsFilter()); return filters; @@ -335,6 +371,8 @@ 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/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java index e514e969c0b..240bfc644c2 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/http/HttpRequestTemplate.java @@ -10,7 +10,6 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.MapBuilder; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; @@ -18,9 +17,9 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.rest.RestUtils; import org.elasticsearch.xpack.common.http.auth.HttpAuth; import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.jboss.netty.handler.codec.http.HttpHeaders; import java.io.IOException; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/DefaultTextTemplateEngine.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/DefaultTextTemplateEngine.java deleted file mode 100644 index 7e7778caf17..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/DefaultTextTemplateEngine.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.common.text; - -import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.component.AbstractComponent; -import org.elasticsearch.common.inject.Inject; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.xcontent.XContentType; -import org.elasticsearch.script.CompiledScript; -import org.elasticsearch.script.ExecutableScript; -import org.elasticsearch.script.Script; -import org.elasticsearch.script.ScriptService; -import org.elasticsearch.xpack.watcher.support.WatcherScript; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -public class DefaultTextTemplateEngine extends AbstractComponent implements TextTemplateEngine { - - private final ScriptService service; - - @Inject - public DefaultTextTemplateEngine(Settings settings, ScriptService service) { - super(settings); - this.service = service; - } - - @Override - public String render(TextTemplate template, Map model) { - if (template == null) { - return null; - } - - XContentType contentType = detectContentType(template); - Map compileParams = compileParams(contentType); - template = trimContentType(template); - - CompiledScript compiledScript = service.compile(convert(template, model), WatcherScript.CTX, compileParams); - ExecutableScript executable = service.executable(compiledScript, model); - Object result = executable.run(); - if (result instanceof BytesReference) { - return ((BytesReference) result).utf8ToString(); - } - return result.toString(); - } - - private TextTemplate trimContentType(TextTemplate textTemplate) { - String template = textTemplate.getTemplate(); - if (!template.startsWith("__")){ - return textTemplate; //Doesn't even start with __ so can't have a content type - } - // There must be a __= 0 && index < 12) { - if (template.length() == 6) { - template = ""; - } else { - template = template.substring(index + 4); - } - } - return new TextTemplate(template, textTemplate.getContentType(), textTemplate.getType(), textTemplate.getParams()); - } - - private XContentType detectContentType(TextTemplate textTemplate) { - String template = textTemplate.getTemplate(); - if (template.startsWith("__")) { - //There must be a __ model) { - Map mergedModel = new HashMap<>(); - mergedModel.putAll(textTemplate.getParams()); - mergedModel.putAll(model); - return new Script(textTemplate.getTemplate(), textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType()); - } - - private Map compileParams(XContentType contentType) { - if (contentType == XContentType.JSON) { - return Collections.singletonMap("content_type", "application/json"); - } else { - return Collections.singletonMap("content_type", "text/plain"); - } - } -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateEngine.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateEngine.java index a33718ac4dc..eb992d6cca7 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateEngine.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateEngine.java @@ -5,13 +5,91 @@ */ package org.elasticsearch.xpack.common.text; +import org.elasticsearch.common.bytes.BytesReference; +import org.elasticsearch.common.component.AbstractComponent; +import org.elasticsearch.common.inject.Inject; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.script.CompiledScript; +import org.elasticsearch.script.ExecutableScript; +import org.elasticsearch.script.Script; +import org.elasticsearch.script.ScriptService; +import org.elasticsearch.xpack.watcher.support.WatcherScript; + +import java.util.Collections; +import java.util.HashMap; import java.util.Map; -/** - * - */ -public interface TextTemplateEngine { +public class TextTemplateEngine extends AbstractComponent { - String render(TextTemplate template, Map model); + private final ScriptService service; + + public TextTemplateEngine(Settings settings, ScriptService service) { + super(settings); + this.service = service; + } + + public String render(TextTemplate template, Map model) { + if (template == null) { + return null; + } + + XContentType contentType = detectContentType(template); + Map compileParams = compileParams(contentType); + template = trimContentType(template); + + CompiledScript compiledScript = service.compile(convert(template, model), WatcherScript.CTX, compileParams); + ExecutableScript executable = service.executable(compiledScript, model); + Object result = executable.run(); + if (result instanceof BytesReference) { + return ((BytesReference) result).utf8ToString(); + } + return result.toString(); + } + + private TextTemplate trimContentType(TextTemplate textTemplate) { + String template = textTemplate.getTemplate(); + if (!template.startsWith("__")){ + return textTemplate; //Doesn't even start with __ so can't have a content type + } + // There must be a __= 0 && index < 12) { + if (template.length() == 6) { + template = ""; + } else { + template = template.substring(index + 4); + } + } + return new TextTemplate(template, textTemplate.getContentType(), textTemplate.getType(), textTemplate.getParams()); + } + + private XContentType detectContentType(TextTemplate textTemplate) { + String template = textTemplate.getTemplate(); + if (template.startsWith("__")) { + //There must be a __ model) { + Map mergedModel = new HashMap<>(); + mergedModel.putAll(textTemplate.getParams()); + mergedModel.putAll(model); + return new Script(textTemplate.getTemplate(), textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType()); + } + + private Map compileParams(XContentType contentType) { + if (contentType == XContentType.JSON) { + return Collections.singletonMap("content_type", "application/json"); + } else { + return Collections.singletonMap("content_type", "text/plain"); + } + } } - diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateModule.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateModule.java deleted file mode 100644 index bbf3a811cda..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/common/text/TextTemplateModule.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -package org.elasticsearch.xpack.common.text; - -import org.elasticsearch.common.inject.AbstractModule; - -/** - * - */ -public class TextTemplateModule extends AbstractModule { - - @Override - protected void configure() { - bind(DefaultTextTemplateEngine.class).asEagerSingleton(); - bind(TextTemplateEngine.class).to(DefaultTextTemplateEngine.class); - } -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/Notification.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/Notification.java deleted file mode 100644 index 50be8264663..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/Notification.java +++ /dev/null @@ -1,59 +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.notification; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -import org.elasticsearch.client.Client; -import org.elasticsearch.common.component.LifecycleComponent; -import org.elasticsearch.common.inject.Module; -import org.elasticsearch.common.settings.Setting; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.notification.email.EmailService; -import org.elasticsearch.xpack.notification.hipchat.HipChatService; -import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; -import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; -import org.elasticsearch.xpack.notification.slack.SlackService; - -public class Notification { - - private final boolean transportClient; - - public Notification(Settings settings) { - this.transportClient = "transport".equals(settings.get(Client.CLIENT_TYPE_SETTING_S.getKey())); - } - - public List> getSettings() { - return Arrays.asList(SlackService.SLACK_ACCOUNT_SETTING, - EmailService.EMAIL_ACCOUNT_SETTING, - HipChatService.HIPCHAT_ACCOUNT_SETTING, - PagerDutyService.PAGERDUTY_ACCOUNT_SETTING); - } - - public List getSettingsFilter() { - ArrayList settingsFilter = new ArrayList<>(); - settingsFilter.add("xpack.notification.email.account.*.smtp.password"); - settingsFilter.add("xpack.notification.slack.account.*.url"); - settingsFilter.add("xpack.notification.pagerduty.account.*.url"); - settingsFilter.add("xpack.notification.pagerduty." + PagerDutyAccount.SERVICE_KEY_SETTING); - settingsFilter.add("xpack.notification.pagerduty.account.*." + PagerDutyAccount.SERVICE_KEY_SETTING); - settingsFilter.add("xpack.notification.hipchat.account.*.auth_token"); - return settingsFilter; - } - - public Collection nodeModules() { - if (transportClient) { - return Collections.emptyList(); - } - List modules = new ArrayList<>(); - modules.add(new NotificationModule()); - return modules; - } -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/NotificationModule.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/NotificationModule.java deleted file mode 100644 index 156b2e867b5..00000000000 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/NotificationModule.java +++ /dev/null @@ -1,51 +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.notification; - -import org.elasticsearch.common.inject.AbstractModule; -import org.elasticsearch.common.inject.multibindings.MapBinder; -import org.elasticsearch.xpack.notification.email.EmailService; -import org.elasticsearch.xpack.notification.email.attachment.DataAttachmentParser; -import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentParser; -import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; -import org.elasticsearch.xpack.notification.email.attachment.HttpEmailAttachementParser; -import org.elasticsearch.xpack.notification.hipchat.HipChatService; -import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; -import org.elasticsearch.xpack.notification.slack.SlackService; - -import java.util.HashMap; -import java.util.Map; - -public class NotificationModule extends AbstractModule { - - private final Map> emailAttachmentParsers = new HashMap<>(); - - - public NotificationModule() { - registerEmailAttachmentParser(HttpEmailAttachementParser.TYPE, HttpEmailAttachementParser.class); - registerEmailAttachmentParser(DataAttachmentParser.TYPE, DataAttachmentParser.class); - } - - public void registerEmailAttachmentParser(String type, Class parserClass) { - emailAttachmentParsers.put(type, parserClass); - } - - @Override - protected void configure() { - bind(EmailService.class).asEagerSingleton(); - - MapBinder emailParsersBinder = MapBinder.newMapBinder(binder(), String.class, - EmailAttachmentParser.class); - for (Map.Entry> entry : emailAttachmentParsers.entrySet()) { - emailParsersBinder.addBinding(entry.getKey()).to(entry.getValue()).asEagerSingleton(); - } - bind(EmailAttachmentsParser.class).asEagerSingleton(); - - bind(HipChatService.class).asEagerSingleton(); - bind(SlackService.class).asEagerSingleton(); - bind(PagerDutyService.class).asEagerSingleton(); - } -} diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java index 81cb7bc0583..e70355537e8 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/EmailService.java @@ -27,7 +27,6 @@ public class EmailService extends AbstractComponent { private volatile Accounts accounts; - @Inject public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) { super(settings); this.cryptoService = cryptoService; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentsParser.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentsParser.java index 72c30e80f32..9640a67bc81 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentsParser.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/EmailAttachmentsParser.java @@ -19,7 +19,6 @@ public class EmailAttachmentsParser { private Map parsers; - @Inject public EmailAttachmentsParser(Map parsers) { this.parsers = Collections.unmodifiableMap(parsers); } diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParser.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParser.java index e0edeaefd93..d9118019eb3 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParser.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/email/attachment/HttpEmailAttachementParser.java @@ -5,13 +5,15 @@ */ package org.elasticsearch.xpack.notification.email.attachment; +import java.io.IOException; +import java.util.Map; + import org.elasticsearch.ElasticsearchException; import org.elasticsearch.ElasticsearchParseException; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.ParseFieldMatcher; import org.elasticsearch.common.Strings; import org.elasticsearch.common.bytes.BytesReference; -import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.xcontent.XContentParser; @@ -25,9 +27,6 @@ import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; import org.elasticsearch.xpack.watcher.watch.Payload; -import java.io.IOException; -import java.util.Map; - public class HttpEmailAttachementParser implements EmailAttachmentParser { public interface Fields { @@ -42,7 +41,6 @@ public class HttpEmailAttachementParser implements EmailAttachmentParser HIPCHAT_ACCOUNT_SETTING = Setting.groupSetting("xpack.notification.hipchat.", Setting.Property.Dynamic, Setting.Property.NodeScope); - @Inject public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { super(settings); this.httpClient = httpClient; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccount.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccount.java index 9aa77fae308..abcc9fa0324 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccount.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/IntegrationAccount.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.hipchat.HipChatAction; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format; @@ -22,7 +23,6 @@ import org.elasticsearch.xpack.common.http.HttpMethod; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; import org.elasticsearch.xpack.common.http.Scheme; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.io.IOException; import java.util.ArrayList; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java index 27cbd96d9f7..70da2a79b45 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/UserAccount.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.settings.SettingsException; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentHelper; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.hipchat.HipChatAction; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format; @@ -22,7 +23,6 @@ import org.elasticsearch.xpack.common.http.HttpMethod; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; import org.elasticsearch.xpack.common.http.Scheme; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.io.IOException; import java.util.ArrayList; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java index 413af47e155..39be8c5d4d4 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/hipchat/V1Account.java @@ -10,6 +10,7 @@ import org.elasticsearch.ExceptionsHelper; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.hipchat.HipChatAction; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format; @@ -18,7 +19,6 @@ import org.elasticsearch.xpack.common.http.HttpMethod; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; import org.elasticsearch.xpack.common.http.Scheme; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.util.ArrayList; import java.util.List; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java index 3a2e6728a10..b348625bbb3 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/pagerduty/PagerDutyService.java @@ -23,7 +23,6 @@ public class PagerDutyService extends AbstractComponent { private final HttpClient httpClient; private volatile PagerDutyAccounts accounts; - @Inject public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { super(settings); this.httpClient = httpClient; diff --git a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java index f93e91243f7..64554000fbb 100644 --- a/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java +++ b/elasticsearch/x-pack/src/main/java/org/elasticsearch/xpack/notification/slack/SlackService.java @@ -22,7 +22,6 @@ public class SlackService extends AbstractComponent { Setting.groupSetting("xpack.notification.slack.", Setting.Property.Dynamic, Setting.Property.NodeScope); private volatile SlackAccounts accounts; - @Inject public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) { super(settings); this.httpClient = httpClient; diff --git a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java index 7e441287762..af21576c6a3 100644 --- a/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java +++ b/elasticsearch/x-pack/src/test/java/org/elasticsearch/xpack/common/text/TextTemplateTests.java @@ -47,7 +47,7 @@ public class TextTemplateTests extends ESTestCase { public void init() throws Exception { service = mock(ScriptService.class); script = mock(ExecutableScript.class); - engine = new DefaultTextTemplateEngine(Settings.EMPTY, service); + engine = new TextTemplateEngine(Settings.EMPTY, service); } public void testRender() throws Exception { diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionFactory.java index 6c974e14c43..074823f9926 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionFactory.java @@ -9,8 +9,8 @@ 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.watcher.actions.ActionFactory; import org.elasticsearch.xpack.common.text.TextTemplateEngine; +import org.elasticsearch.xpack.watcher.actions.ActionFactory; import org.elasticsearch.xpack.notification.email.EmailService; import org.elasticsearch.xpack.notification.email.HtmlSanitizer; import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/ExecutableEmailAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/ExecutableEmailAction.java index dfb8aeb062c..9ec7056f657 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/ExecutableEmailAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/ExecutableEmailAction.java @@ -7,11 +7,11 @@ package org.elasticsearch.xpack.watcher.actions.email; import org.elasticsearch.ElasticsearchException; import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import org.elasticsearch.xpack.notification.email.Attachment; import org.elasticsearch.xpack.notification.email.DataAttachment; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/ExecutableHipChatAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/ExecutableHipChatAction.java index b609df24cab..2986a20c618 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/ExecutableHipChatAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/ExecutableHipChatAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.watcher.actions.hipchat; import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; @@ -14,7 +15,6 @@ import org.elasticsearch.xpack.notification.hipchat.HipChatService; import org.elasticsearch.xpack.notification.hipchat.SentMessages; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactory.java index 9ccc73986f5..13ca3f1ea9c 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactory.java @@ -10,10 +10,10 @@ 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.actions.ActionFactory; import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; import org.elasticsearch.xpack.notification.hipchat.HipChatService; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/ExecutableLoggingAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/ExecutableLoggingAction.java index c345829cf88..fc3051e7072 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/ExecutableLoggingAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/ExecutableLoggingAction.java @@ -8,11 +8,11 @@ package org.elasticsearch.xpack.watcher.actions.logging; import org.elasticsearch.common.logging.ESLogger; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionFactory.java index f7cb505129b..f2742174fa2 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionFactory.java @@ -9,8 +9,8 @@ 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.watcher.actions.ActionFactory; import org.elasticsearch.xpack.common.text.TextTemplateEngine; +import org.elasticsearch.xpack.watcher.actions.ActionFactory; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/ExecutablePagerDutyAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/ExecutablePagerDutyAction.java index 99e8fa2f942..bb8db884d11 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/ExecutablePagerDutyAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/ExecutablePagerDutyAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.watcher.actions.pagerduty; import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; @@ -14,7 +15,6 @@ import org.elasticsearch.xpack.notification.pagerduty.SentEvent; import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactory.java index 3b021fdb3ee..77573ec5840 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactory.java @@ -10,11 +10,11 @@ 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.actions.ActionFactory; import org.elasticsearch.xpack.watcher.actions.hipchat.ExecutableHipChatAction; import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/ExecutableSlackAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/ExecutableSlackAction.java index 6fcf20e08bc..ffeafc46024 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/ExecutableSlackAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/ExecutableSlackAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.watcher.actions.slack; import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.notification.slack.SentMessages; @@ -14,7 +15,6 @@ import org.elasticsearch.xpack.notification.slack.SlackService; import org.elasticsearch.xpack.notification.slack.message.SlackMessage; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.support.Variables; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactory.java index ff3c4fe67bc..3311eb73ee5 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactory.java @@ -10,11 +10,11 @@ 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.actions.ActionFactory; import org.elasticsearch.xpack.watcher.actions.hipchat.ExecutableHipChatAction; import org.elasticsearch.xpack.notification.slack.SlackAccount; import org.elasticsearch.xpack.notification.slack.SlackService; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/ExecutableWebhookAction.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/ExecutableWebhookAction.java index 71430679026..62a26122f01 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/ExecutableWebhookAction.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/ExecutableWebhookAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.watcher.actions.webhook; import org.elasticsearch.common.logging.ESLogger; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; @@ -13,7 +14,6 @@ import org.elasticsearch.xpack.watcher.support.Variables; import org.elasticsearch.xpack.common.http.HttpClient; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import java.util.Map; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionFactory.java index e656cd33ff2..c0a9d996416 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionFactory.java @@ -9,10 +9,10 @@ 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.actions.ActionFactory; import org.elasticsearch.xpack.common.http.HttpClient; import org.elasticsearch.xpack.common.http.HttpRequestTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/http/HttpInputFactory.java b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/http/HttpInputFactory.java index a143e75a2d0..1c6c49cd2b3 100644 --- a/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/http/HttpInputFactory.java +++ b/elasticsearch/x-pack/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/http/HttpInputFactory.java @@ -9,10 +9,10 @@ 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 java.io.IOException; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java index 85a2d9db356..7aa2b7fee93 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/script/MockMustacheScriptEngine.java @@ -6,7 +6,7 @@ package org.elasticsearch.script; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.xpack.common.text.DefaultTextTemplateEngine; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.util.Collections; import java.util.Map; @@ -14,7 +14,7 @@ import java.util.function.Function; /** * A mock script engine that registers itself under the 'mustache' name so that - * {@link DefaultTextTemplateEngine} + * {@link TextTemplateEngine} * uses it and adds validation that watcher tests don't rely on mustache templating/ */ public class MockMustacheScriptEngine extends MockScriptEngine { diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java index f3ab788e03c..ef697d1f66a 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailActionTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.execution.Wid; @@ -26,7 +27,6 @@ import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry; import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory; import org.elasticsearch.xpack.common.secret.Secret; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.support.xcontent.WatcherParams; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java index 01158e8ebf2..794483d59df 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionFactoryTests.java @@ -13,11 +13,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; import org.elasticsearch.xpack.notification.hipchat.HipChatService; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.junit.Before; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java index 2437045e550..bcc9f41da29 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/hipchat/HipChatActionTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.notification.hipchat.HipChatAccount; import org.elasticsearch.xpack.notification.hipchat.HipChatMessage; @@ -23,7 +24,6 @@ import org.elasticsearch.xpack.watcher.execution.Wid; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java index 67012ad850d..2da0f10c13d 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/logging/LoggingActionTests.java @@ -13,10 +13,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.test.WatcherTestUtils; import org.elasticsearch.xpack.watcher.watch.Payload; import org.elasticsearch.xpack.notification.email.Attachment; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java index c433293ac67..63e08e47728 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionFactoryTests.java @@ -11,9 +11,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount; import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.junit.Before; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java index f85cc709030..45fde4082c9 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/pagerduty/PagerDutyActionTests.java @@ -14,6 +14,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent; import org.elasticsearch.xpack.notification.pagerduty.IncidentEventContext; @@ -26,7 +27,6 @@ import org.elasticsearch.xpack.watcher.execution.Wid; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java index fbe0a70bbab..eeb196fc6f0 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionFactoryTests.java @@ -11,9 +11,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.notification.slack.SlackAccount; import org.elasticsearch.xpack.notification.slack.SlackService; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.junit.Before; import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java index 7ad499dbc47..916efde9075 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/slack/SlackActionTests.java @@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.notification.slack.SentMessages; import org.elasticsearch.xpack.notification.slack.SlackAccount; @@ -24,7 +25,6 @@ import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; import org.elasticsearch.xpack.watcher.execution.Wid; import org.elasticsearch.xpack.common.http.HttpRequest; import org.elasticsearch.xpack.common.http.HttpResponse; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.watch.Payload; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java index 644a9034a80..0d845d1b8b7 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookActionTests.java @@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.XContentParser; import org.elasticsearch.common.xcontent.json.JsonXContent; import org.elasticsearch.env.Environment; import org.elasticsearch.test.ESTestCase; +import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.Action.Result.Status; import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext; @@ -29,7 +30,6 @@ import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry; import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory; import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.common.text.TextTemplateEngine; import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateService; import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase; import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine; diff --git a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/MockTextTemplateEngine.java b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/MockTextTemplateEngine.java index dc93d146a85..68aff89f308 100644 --- a/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/MockTextTemplateEngine.java +++ b/elasticsearch/x-pack/watcher/src/test/java/org/elasticsearch/xpack/watcher/test/MockTextTemplateEngine.java @@ -5,12 +5,17 @@ */ package org.elasticsearch.xpack.watcher.test; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xpack.common.text.TextTemplate; import org.elasticsearch.xpack.common.text.TextTemplateEngine; import java.util.Map; -public class MockTextTemplateEngine implements TextTemplateEngine { +public class MockTextTemplateEngine extends TextTemplateEngine { + public MockTextTemplateEngine() { + super(Settings.EMPTY, null); + } + @Override public String render(TextTemplate template, Map model) { if (template == null ) {