Merge pull request elastic/elasticsearch#3032 from rjernst/deguice16
Internal: Deguice notification services Original commit: elastic/x-pack-elasticsearch@9739742373
This commit is contained in:
commit
0039f9a2b2
|
@ -17,9 +17,8 @@ import org.elasticsearch.script.ScriptSettings;
|
||||||
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
import org.elasticsearch.script.mustache.MustacheScriptEngineService;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.watcher.ResourceWatcherService;
|
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.TextTemplateEngine;
|
||||||
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.watcher.support.WatcherScript;
|
import org.elasticsearch.xpack.watcher.support.WatcherScript;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
@ -52,7 +51,7 @@ public class WatcherTemplateIT extends ESTestCase {
|
||||||
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry);
|
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, registry);
|
||||||
ScriptService scriptService = new ScriptService(setting, environment, resourceWatcherService, scriptEngineRegistry,
|
ScriptService scriptService = new ScriptService(setting, environment, resourceWatcherService, scriptEngineRegistry,
|
||||||
registry, scriptSettings);
|
registry, scriptSettings);
|
||||||
engine = new DefaultTextTemplateEngine(Settings.EMPTY, scriptService);
|
engine = new TextTemplateEngine(Settings.EMPTY, scriptService);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testEscaping() throws Exception {
|
public void testEscaping() throws Exception {
|
||||||
|
|
|
@ -27,13 +27,13 @@ import org.elasticsearch.action.support.ActionFilter;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.transport.TransportClient;
|
import org.elasticsearch.client.transport.TransportClient;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.component.LifecycleComponent;
|
|
||||||
import org.elasticsearch.common.inject.Binder;
|
import org.elasticsearch.common.inject.Binder;
|
||||||
import org.elasticsearch.common.inject.Module;
|
import org.elasticsearch.common.inject.Module;
|
||||||
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
import org.elasticsearch.common.inject.multibindings.Multibinder;
|
||||||
import org.elasticsearch.common.inject.util.Providers;
|
import org.elasticsearch.common.inject.util.Providers;
|
||||||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
|
||||||
import org.elasticsearch.common.network.NetworkModule;
|
import org.elasticsearch.common.network.NetworkModule;
|
||||||
|
import org.elasticsearch.common.settings.ClusterSettings;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.env.Environment;
|
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.HttpAuthRegistry;
|
||||||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
||||||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory;
|
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.XPackExtension;
|
||||||
import org.elasticsearch.xpack.extensions.XPackExtensionsService;
|
import org.elasticsearch.xpack.extensions.XPackExtensionsService;
|
||||||
import org.elasticsearch.xpack.graph.Graph;
|
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.Monitoring;
|
||||||
import org.elasticsearch.xpack.monitoring.MonitoringFeatureSet;
|
import org.elasticsearch.xpack.monitoring.MonitoringFeatureSet;
|
||||||
import org.elasticsearch.xpack.monitoring.MonitoringSettings;
|
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.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.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.RestXPackInfoAction;
|
||||||
import org.elasticsearch.xpack.rest.action.RestXPackUsageAction;
|
import org.elasticsearch.xpack.rest.action.RestXPackUsageAction;
|
||||||
import org.elasticsearch.xpack.security.InternalClient;
|
import org.elasticsearch.xpack.security.InternalClient;
|
||||||
|
@ -137,7 +145,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
|
||||||
protected Monitoring monitoring;
|
protected Monitoring monitoring;
|
||||||
protected Watcher watcher;
|
protected Watcher watcher;
|
||||||
protected Graph graph;
|
protected Graph graph;
|
||||||
protected Notification notification;
|
|
||||||
|
|
||||||
public XPackPlugin(Settings settings) throws IOException {
|
public XPackPlugin(Settings settings) throws IOException {
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
|
@ -150,7 +157,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
|
||||||
this.monitoring = new Monitoring(settings, env, licenseState);
|
this.monitoring = new Monitoring(settings, env, licenseState);
|
||||||
this.watcher = new Watcher(settings);
|
this.watcher = new Watcher(settings);
|
||||||
this.graph = new Graph(settings);
|
this.graph = new Graph(settings);
|
||||||
this.notification = new Notification(settings);
|
|
||||||
// Check if the node is a transport client.
|
// Check if the node is a transport client.
|
||||||
if (transportClientMode == false) {
|
if (transportClientMode == false) {
|
||||||
this.extensionsService = new XPackExtensionsService(settings, resolveXPackExtensionsFile(env), getExtensions());
|
this.extensionsService = new XPackExtensionsService(settings, resolveXPackExtensionsFile(env), getExtensions());
|
||||||
|
@ -173,15 +179,12 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
|
||||||
public Collection<Module> createGuiceModules() {
|
public Collection<Module> createGuiceModules() {
|
||||||
ArrayList<Module> modules = new ArrayList<>();
|
ArrayList<Module> modules = new ArrayList<>();
|
||||||
modules.add(b -> b.bind(Clock.class).toInstance(getClock()));
|
modules.add(b -> b.bind(Clock.class).toInstance(getClock()));
|
||||||
modules.addAll(notification.nodeModules());
|
|
||||||
modules.addAll(security.nodeModules());
|
modules.addAll(security.nodeModules());
|
||||||
modules.addAll(watcher.nodeModules());
|
modules.addAll(watcher.nodeModules());
|
||||||
modules.addAll(monitoring.nodeModules());
|
modules.addAll(monitoring.nodeModules());
|
||||||
modules.addAll(graph.createGuiceModules());
|
modules.addAll(graph.createGuiceModules());
|
||||||
|
|
||||||
if (transportClientMode == false) {
|
if (transportClientMode) {
|
||||||
modules.add(new TextTemplateModule());
|
|
||||||
} else {
|
|
||||||
modules.add(b -> b.bind(XPackLicenseState.class).toProvider(Providers.of(null)));
|
modules.add(b -> b.bind(XPackLicenseState.class).toProvider(Providers.of(null)));
|
||||||
}
|
}
|
||||||
return modules;
|
return modules;
|
||||||
|
@ -208,8 +211,31 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
|
||||||
httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService()));
|
httpAuthFactories.put(BasicAuth.TYPE, new BasicAuthFactory(security.getCryptoService()));
|
||||||
// TODO: add more auth types, or remove this indirection
|
// TODO: add more auth types, or remove this indirection
|
||||||
HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories);
|
HttpAuthRegistry httpAuthRegistry = new HttpAuthRegistry(httpAuthFactories);
|
||||||
components.add(new HttpRequestTemplate.Parser(httpAuthRegistry));
|
HttpRequestTemplate.Parser httpTemplateParser = new HttpRequestTemplate.Parser(httpAuthRegistry);
|
||||||
components.add(new HttpClient(settings, httpAuthRegistry, env));
|
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<Object> createNotificationComponents(ClusterSettings clusterSettings, HttpClient httpClient,
|
||||||
|
HttpRequestTemplate.Parser httpTemplateParser, ScriptService scriptService) {
|
||||||
|
List<Object> 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<String, EmailAttachmentParser> 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;
|
return components;
|
||||||
}
|
}
|
||||||
|
@ -245,7 +271,6 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
|
||||||
@Override
|
@Override
|
||||||
public List<Setting<?>> getSettings() {
|
public List<Setting<?>> getSettings() {
|
||||||
ArrayList<Setting<?>> settings = new ArrayList<>();
|
ArrayList<Setting<?>> settings = new ArrayList<>();
|
||||||
settings.addAll(notification.getSettings());
|
|
||||||
settings.addAll(security.getSettings());
|
settings.addAll(security.getSettings());
|
||||||
settings.addAll(MonitoringSettings.getSettings());
|
settings.addAll(MonitoringSettings.getSettings());
|
||||||
settings.addAll(watcher.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
|
// we add the `xpack.version` setting to all internal indices
|
||||||
settings.add(Setting.simpleString("index.xpack.version", Setting.Property.IndexScope));
|
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
|
// http settings
|
||||||
settings.add(Setting.simpleString("xpack.http.default_read_timeout", Setting.Property.NodeScope));
|
settings.add(Setting.simpleString("xpack.http.default_read_timeout", Setting.Property.NodeScope));
|
||||||
settings.add(Setting.simpleString("xpack.http.default_connection_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
|
@Override
|
||||||
public List<String> getSettingsFilter() {
|
public List<String> getSettingsFilter() {
|
||||||
List<String> filters = new ArrayList<>();
|
List<String> 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(security.getSettingsFilter());
|
||||||
filters.addAll(MonitoringSettings.getSettingsFilter());
|
filters.addAll(MonitoringSettings.getSettingsFilter());
|
||||||
return filters;
|
return filters;
|
||||||
|
@ -335,6 +371,8 @@ public class XPackPlugin extends Plugin implements ScriptPlugin, ActionPlugin, I
|
||||||
security.onIndexModule(module);
|
security.onIndexModule(module);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void bindFeatureSet(Binder binder, Class<? extends XPackFeatureSet> featureSet) {
|
public static void bindFeatureSet(Binder binder, Class<? extends XPackFeatureSet> featureSet) {
|
||||||
binder.bind(featureSet).asEagerSingleton();
|
binder.bind(featureSet).asEagerSingleton();
|
||||||
Multibinder<XPackFeatureSet> featureSetBinder = Multibinder.newSetBinder(binder, XPackFeatureSet.class);
|
Multibinder<XPackFeatureSet> featureSetBinder = Multibinder.newSetBinder(binder, XPackFeatureSet.class);
|
||||||
|
|
|
@ -10,7 +10,6 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
|
@ -18,9 +17,9 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.rest.RestUtils;
|
import org.elasticsearch.rest.RestUtils;
|
||||||
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
|
import org.elasticsearch.xpack.common.http.auth.HttpAuth;
|
||||||
import org.elasticsearch.xpack.common.http.auth.HttpAuthRegistry;
|
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.watcher.support.WatcherDateTimeUtils;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
import org.jboss.netty.handler.codec.http.HttpHeaders;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -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<String, Object> model) {
|
|
||||||
if (template == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
XContentType contentType = detectContentType(template);
|
|
||||||
Map<String, String> 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 __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
|
||||||
int index = template.indexOf("__::", 3);
|
|
||||||
// Assume that the content type name is less than 10 characters long otherwise we may falsely detect strings that start with '__
|
|
||||||
// and have '__::' somewhere in the content
|
|
||||||
if (index >= 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 __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
|
||||||
int endOfContentName = template.indexOf("__::", 3);
|
|
||||||
if (endOfContentName != -1) {
|
|
||||||
return XContentType.fromMediaTypeOrFormat(template.substring(2, endOfContentName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Script convert(TextTemplate textTemplate, Map<String, Object> model) {
|
|
||||||
Map<String, Object> mergedModel = new HashMap<>();
|
|
||||||
mergedModel.putAll(textTemplate.getParams());
|
|
||||||
mergedModel.putAll(model);
|
|
||||||
return new Script(textTemplate.getTemplate(), textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> compileParams(XContentType contentType) {
|
|
||||||
if (contentType == XContentType.JSON) {
|
|
||||||
return Collections.singletonMap("content_type", "application/json");
|
|
||||||
} else {
|
|
||||||
return Collections.singletonMap("content_type", "text/plain");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,13 +5,91 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.common.text;
|
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;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
public class TextTemplateEngine extends AbstractComponent {
|
||||||
*
|
|
||||||
*/
|
|
||||||
public interface TextTemplateEngine {
|
|
||||||
|
|
||||||
String render(TextTemplate template, Map<String, Object> model);
|
private final ScriptService service;
|
||||||
|
|
||||||
|
public TextTemplateEngine(Settings settings, ScriptService service) {
|
||||||
|
super(settings);
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String render(TextTemplate template, Map<String, Object> model) {
|
||||||
|
if (template == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
XContentType contentType = detectContentType(template);
|
||||||
|
Map<String, String> 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 __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
||||||
|
int index = template.indexOf("__::", 3);
|
||||||
|
// Assume that the content type name is less than 10 characters long otherwise we may falsely detect strings that start with '__
|
||||||
|
// and have '__::' somewhere in the content
|
||||||
|
if (index >= 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 __<content_type__:: prefix so the minimum length before detecting '__::' is 3
|
||||||
|
int endOfContentName = template.indexOf("__::", 3);
|
||||||
|
if (endOfContentName != -1) {
|
||||||
|
return XContentType.fromMediaTypeOrFormat(template.substring(2, endOfContentName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Script convert(TextTemplate textTemplate, Map<String, Object> model) {
|
||||||
|
Map<String, Object> mergedModel = new HashMap<>();
|
||||||
|
mergedModel.putAll(textTemplate.getParams());
|
||||||
|
mergedModel.putAll(model);
|
||||||
|
return new Script(textTemplate.getTemplate(), textTemplate.getType(), "mustache", mergedModel, textTemplate.getContentType());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> compileParams(XContentType contentType) {
|
||||||
|
if (contentType == XContentType.JSON) {
|
||||||
|
return Collections.singletonMap("content_type", "application/json");
|
||||||
|
} else {
|
||||||
|
return Collections.singletonMap("content_type", "text/plain");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<Setting<?>> getSettings() {
|
|
||||||
return Arrays.asList(SlackService.SLACK_ACCOUNT_SETTING,
|
|
||||||
EmailService.EMAIL_ACCOUNT_SETTING,
|
|
||||||
HipChatService.HIPCHAT_ACCOUNT_SETTING,
|
|
||||||
PagerDutyService.PAGERDUTY_ACCOUNT_SETTING);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getSettingsFilter() {
|
|
||||||
ArrayList<String> 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<? extends Module> nodeModules() {
|
|
||||||
if (transportClient) {
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
List<Module> modules = new ArrayList<>();
|
|
||||||
modules.add(new NotificationModule());
|
|
||||||
return modules;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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<String, Class<? extends EmailAttachmentParser>> emailAttachmentParsers = new HashMap<>();
|
|
||||||
|
|
||||||
|
|
||||||
public NotificationModule() {
|
|
||||||
registerEmailAttachmentParser(HttpEmailAttachementParser.TYPE, HttpEmailAttachementParser.class);
|
|
||||||
registerEmailAttachmentParser(DataAttachmentParser.TYPE, DataAttachmentParser.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerEmailAttachmentParser(String type, Class<? extends EmailAttachmentParser> parserClass) {
|
|
||||||
emailAttachmentParsers.put(type, parserClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(EmailService.class).asEagerSingleton();
|
|
||||||
|
|
||||||
MapBinder<String, EmailAttachmentParser> emailParsersBinder = MapBinder.newMapBinder(binder(), String.class,
|
|
||||||
EmailAttachmentParser.class);
|
|
||||||
for (Map.Entry<String, Class<? extends EmailAttachmentParser>> 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();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -27,7 +27,6 @@ public class EmailService extends AbstractComponent {
|
||||||
|
|
||||||
private volatile Accounts accounts;
|
private volatile Accounts accounts;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) {
|
public EmailService(Settings settings, @Nullable CryptoService cryptoService, ClusterSettings clusterSettings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.cryptoService = cryptoService;
|
this.cryptoService = cryptoService;
|
||||||
|
|
|
@ -19,7 +19,6 @@ public class EmailAttachmentsParser {
|
||||||
|
|
||||||
private Map<String, EmailAttachmentParser> parsers;
|
private Map<String, EmailAttachmentParser> parsers;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public EmailAttachmentsParser(Map<String, EmailAttachmentParser> parsers) {
|
public EmailAttachmentsParser(Map<String, EmailAttachmentParser> parsers) {
|
||||||
this.parsers = Collections.unmodifiableMap(parsers);
|
this.parsers = Collections.unmodifiableMap(parsers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,15 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.notification.email.attachment;
|
package org.elasticsearch.xpack.notification.email.attachment;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.ParseFieldMatcher;
|
import org.elasticsearch.common.ParseFieldMatcher;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.bytes.BytesReference;
|
import org.elasticsearch.common.bytes.BytesReference;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
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.support.Variables;
|
||||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class HttpEmailAttachementParser implements EmailAttachmentParser<HttpRequestAttachment> {
|
public class HttpEmailAttachementParser implements EmailAttachmentParser<HttpRequestAttachment> {
|
||||||
|
|
||||||
public interface Fields {
|
public interface Fields {
|
||||||
|
@ -42,7 +41,6 @@ public class HttpEmailAttachementParser implements EmailAttachmentParser<HttpReq
|
||||||
private final TextTemplateEngine templateEngine;
|
private final TextTemplateEngine templateEngine;
|
||||||
private final ESLogger logger;
|
private final ESLogger logger;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public HttpEmailAttachementParser(HttpClient httpClient, HttpRequestTemplate.Parser requestTemplateParser,
|
public HttpEmailAttachementParser(HttpClient httpClient, HttpRequestTemplate.Parser requestTemplateParser,
|
||||||
TextTemplateEngine templateEngine) {
|
TextTemplateEngine templateEngine) {
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
|
|
|
@ -22,7 +22,6 @@ public class HipChatService extends AbstractComponent {
|
||||||
public static final Setting<Settings> HIPCHAT_ACCOUNT_SETTING =
|
public static final Setting<Settings> HIPCHAT_ACCOUNT_SETTING =
|
||||||
Setting.groupSetting("xpack.notification.hipchat.", Setting.Property.Dynamic, Setting.Property.NodeScope);
|
Setting.groupSetting("xpack.notification.hipchat.", Setting.Property.Dynamic, Setting.Property.NodeScope);
|
||||||
|
|
||||||
@Inject
|
|
||||||
public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
public HipChatService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.common.settings.SettingsException;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
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.watcher.actions.hipchat.HipChatAction;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format;
|
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.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.http.Scheme;
|
import org.elasticsearch.xpack.common.http.Scheme;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.common.settings.SettingsException;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentHelper;
|
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.watcher.actions.hipchat.HipChatAction;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format;
|
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.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.http.Scheme;
|
import org.elasticsearch.xpack.common.http.Scheme;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.ExceptionsHelper;
|
||||||
import org.elasticsearch.common.Nullable;
|
import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.watcher.actions.hipchat.HipChatAction;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Color;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage.Format;
|
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.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.http.Scheme;
|
import org.elasticsearch.xpack.common.http.Scheme;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
|
@ -23,7 +23,6 @@ public class PagerDutyService extends AbstractComponent {
|
||||||
private final HttpClient httpClient;
|
private final HttpClient httpClient;
|
||||||
private volatile PagerDutyAccounts accounts;
|
private volatile PagerDutyAccounts accounts;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
public PagerDutyService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
|
|
|
@ -22,7 +22,6 @@ public class SlackService extends AbstractComponent {
|
||||||
Setting.groupSetting("xpack.notification.slack.", Setting.Property.Dynamic, Setting.Property.NodeScope);
|
Setting.groupSetting("xpack.notification.slack.", Setting.Property.Dynamic, Setting.Property.NodeScope);
|
||||||
private volatile SlackAccounts accounts;
|
private volatile SlackAccounts accounts;
|
||||||
|
|
||||||
@Inject
|
|
||||||
public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
public SlackService(Settings settings, HttpClient httpClient, ClusterSettings clusterSettings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
this.httpClient = httpClient;
|
this.httpClient = httpClient;
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class TextTemplateTests extends ESTestCase {
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
service = mock(ScriptService.class);
|
service = mock(ScriptService.class);
|
||||||
script = mock(ExecutableScript.class);
|
script = mock(ExecutableScript.class);
|
||||||
engine = new DefaultTextTemplateEngine(Settings.EMPTY, service);
|
engine = new TextTemplateEngine(Settings.EMPTY, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testRender() throws Exception {
|
public void testRender() throws Exception {
|
||||||
|
|
|
@ -9,8 +9,8 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionFactory;
|
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
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.EmailService;
|
||||||
import org.elasticsearch.xpack.notification.email.HtmlSanitizer;
|
import org.elasticsearch.xpack.notification.email.HtmlSanitizer;
|
||||||
import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser;
|
import org.elasticsearch.xpack.notification.email.attachment.EmailAttachmentsParser;
|
||||||
|
|
|
@ -7,11 +7,11 @@ package org.elasticsearch.xpack.watcher.actions.email;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchException;
|
import org.elasticsearch.ElasticsearchException;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
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.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.support.Variables;
|
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.watcher.watch.Payload;
|
||||||
import org.elasticsearch.xpack.notification.email.Attachment;
|
import org.elasticsearch.xpack.notification.email.Attachment;
|
||||||
import org.elasticsearch.xpack.notification.email.DataAttachment;
|
import org.elasticsearch.xpack.notification.email.DataAttachment;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.xpack.watcher.actions.hipchat;
|
package org.elasticsearch.xpack.watcher.actions.hipchat;
|
||||||
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
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.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
|
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.notification.hipchat.SentMessages;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.support.Variables;
|
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.watcher.watch.Payload;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -10,10 +10,10 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
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.ActionFactory;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatService;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatService;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,11 @@ package org.elasticsearch.xpack.watcher.actions.logging;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.support.Variables;
|
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.watcher.watch.Payload;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -9,8 +9,8 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionFactory;
|
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||||
|
import org.elasticsearch.xpack.watcher.actions.ActionFactory;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.xpack.watcher.actions.pagerduty;
|
package org.elasticsearch.xpack.watcher.actions.pagerduty;
|
||||||
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
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.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
||||||
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount;
|
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.notification.pagerduty.IncidentEvent;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.support.Variables;
|
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.watcher.watch.Payload;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -10,11 +10,11 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
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.ActionFactory;
|
||||||
import org.elasticsearch.xpack.watcher.actions.hipchat.ExecutableHipChatAction;
|
import org.elasticsearch.xpack.watcher.actions.hipchat.ExecutableHipChatAction;
|
||||||
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount;
|
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount;
|
||||||
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService;
|
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.xpack.watcher.actions.slack;
|
package org.elasticsearch.xpack.watcher.actions.slack;
|
||||||
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
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.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
||||||
import org.elasticsearch.xpack.notification.slack.SentMessages;
|
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.notification.slack.message.SlackMessage;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.support.Variables;
|
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.watcher.watch.Payload;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -10,11 +10,11 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
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.ActionFactory;
|
||||||
import org.elasticsearch.xpack.watcher.actions.hipchat.ExecutableHipChatAction;
|
import org.elasticsearch.xpack.watcher.actions.hipchat.ExecutableHipChatAction;
|
||||||
import org.elasticsearch.xpack.notification.slack.SlackAccount;
|
import org.elasticsearch.xpack.notification.slack.SlackAccount;
|
||||||
import org.elasticsearch.xpack.notification.slack.SlackService;
|
import org.elasticsearch.xpack.notification.slack.SlackService;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
package org.elasticsearch.xpack.watcher.actions.webhook;
|
package org.elasticsearch.xpack.watcher.actions.webhook;
|
||||||
|
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
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.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
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.HttpClient;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequest;
|
import org.elasticsearch.xpack.common.http.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
|
@ -9,10 +9,10 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
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.ActionFactory;
|
||||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,10 @@ import org.elasticsearch.common.inject.Inject;
|
||||||
import org.elasticsearch.common.logging.Loggers;
|
import org.elasticsearch.common.logging.Loggers;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
|
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||||
import org.elasticsearch.xpack.watcher.input.InputFactory;
|
import org.elasticsearch.xpack.watcher.input.InputFactory;
|
||||||
import org.elasticsearch.xpack.common.http.HttpClient;
|
import org.elasticsearch.xpack.common.http.HttpClient;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
package org.elasticsearch.script;
|
package org.elasticsearch.script;
|
||||||
|
|
||||||
import org.elasticsearch.common.settings.Settings;
|
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.Collections;
|
||||||
import java.util.Map;
|
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
|
* 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/
|
* uses it and adds validation that watcher tests don't rely on mustache templating/
|
||||||
*/
|
*/
|
||||||
public class MockMustacheScriptEngine extends MockScriptEngine {
|
public class MockMustacheScriptEngine extends MockScriptEngine {
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.execution.Wid;
|
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.http.auth.basic.BasicAuthFactory;
|
||||||
import org.elasticsearch.xpack.common.secret.Secret;
|
import org.elasticsearch.xpack.common.secret.Secret;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
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.support.xcontent.WatcherParams;
|
||||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||||
import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine;
|
import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine;
|
||||||
|
|
|
@ -13,11 +13,11 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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.HipChatAccount;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatService;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatService;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
|
import org.elasticsearch.xpack.notification.hipchat.HipChatAccount;
|
||||||
import org.elasticsearch.xpack.notification.hipchat.HipChatMessage;
|
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.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
|
@ -13,10 +13,10 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
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.test.WatcherTestUtils;
|
||||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||||
import org.elasticsearch.xpack.notification.email.Attachment;
|
import org.elasticsearch.xpack.notification.email.Attachment;
|
||||||
|
|
|
@ -11,9 +11,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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.PagerDutyAccount;
|
||||||
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService;
|
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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;
|
||||||
import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent;
|
import org.elasticsearch.xpack.notification.pagerduty.IncidentEvent;
|
||||||
import org.elasticsearch.xpack.notification.pagerduty.IncidentEventContext;
|
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.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
|
@ -11,9 +11,9 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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.SlackAccount;
|
||||||
import org.elasticsearch.xpack.notification.slack.SlackService;
|
import org.elasticsearch.xpack.notification.slack.SlackService;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
|
||||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||||
|
|
|
@ -13,6 +13,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.common.xcontent.XContentParser;
|
import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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;
|
||||||
import org.elasticsearch.xpack.notification.slack.SentMessages;
|
import org.elasticsearch.xpack.notification.slack.SentMessages;
|
||||||
import org.elasticsearch.xpack.notification.slack.SlackAccount;
|
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.watcher.execution.Wid;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequest;
|
import org.elasticsearch.xpack.common.http.HttpRequest;
|
||||||
import org.elasticsearch.xpack.common.http.HttpResponse;
|
import org.elasticsearch.xpack.common.http.HttpResponse;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
|
||||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
|
||||||
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
import org.elasticsearch.common.xcontent.json.JsonXContent;
|
||||||
import org.elasticsearch.env.Environment;
|
import org.elasticsearch.env.Environment;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
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;
|
||||||
import org.elasticsearch.xpack.watcher.actions.Action.Result.Status;
|
import org.elasticsearch.xpack.watcher.actions.Action.Result.Status;
|
||||||
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
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.common.http.auth.basic.BasicAuthFactory;
|
||||||
import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy;
|
import org.elasticsearch.xpack.watcher.support.init.proxy.WatcherClientProxy;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
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.support.search.WatcherSearchTemplateService;
|
||||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||||
import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine;
|
import org.elasticsearch.xpack.watcher.test.MockTextTemplateEngine;
|
||||||
|
|
|
@ -5,12 +5,17 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.xpack.watcher.test;
|
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.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MockTextTemplateEngine implements TextTemplateEngine {
|
public class MockTextTemplateEngine extends TextTemplateEngine {
|
||||||
|
public MockTextTemplateEngine() {
|
||||||
|
super(Settings.EMPTY, null);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String render(TextTemplate template, Map<String, Object> model) {
|
public String render(TextTemplate template, Map<String, Object> model) {
|
||||||
if (template == null ) {
|
if (template == null ) {
|
||||||
|
|
Loading…
Reference in New Issue