[watcher] Rename `Template` to `TextTemplate`

We have different types of templates in watcher - http request template, email template, hipchat message template, and simple text template... to avoid confusion, and clean up the codebase, this commit renames the `Template` class to `TextTemplate` to better convey what this template is about.

Original commit: elastic/x-pack-elasticsearch@8e5202019c
This commit is contained in:
uboness 2015-08-25 14:42:19 +02:00
parent 693d16777c
commit 5b363f1041
52 changed files with 504 additions and 546 deletions

View File

@ -40,8 +40,8 @@ import org.elasticsearch.watcher.support.init.InitializingModule;
import org.elasticsearch.watcher.support.init.InitializingService;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.secret.SecretModule;
import org.elasticsearch.watcher.support.template.TemplateModule;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService;
import org.elasticsearch.watcher.support.text.TextTemplateModule;
import org.elasticsearch.watcher.support.text.xmustache.XMustacheScriptEngineService;
import org.elasticsearch.watcher.support.validation.WatcherSettingsValidation;
import org.elasticsearch.watcher.transform.TransformModule;
import org.elasticsearch.watcher.transport.actions.ack.AckWatchAction;
@ -105,7 +105,7 @@ public class WatcherPlugin extends Plugin {
new InitializingModule(),
new LicenseModule(),
new WatchModule(),
new TemplateModule(),
new TextTemplateModule(),
new HttpClientModule(),
new ClockModule(),
new WatcherClientModule(),

View File

@ -12,7 +12,7 @@ import org.elasticsearch.watcher.actions.index.IndexAction;
import org.elasticsearch.watcher.actions.logging.LoggingAction;
import org.elasticsearch.watcher.actions.webhook.WebhookAction;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
/**
*
@ -43,38 +43,38 @@ public final class ActionBuilders {
}
public static LoggingAction.Builder loggingAction(String text) {
return loggingAction(Template.inline(text));
return loggingAction(TextTemplate.inline(text));
}
public static LoggingAction.Builder loggingAction(Template.Builder text) {
public static LoggingAction.Builder loggingAction(TextTemplate.Builder text) {
return loggingAction(text.build());
}
public static LoggingAction.Builder loggingAction(Template text) {
public static LoggingAction.Builder loggingAction(TextTemplate text) {
return LoggingAction.builder(text);
}
public static HipChatAction.Builder hipchatAction(String message) {
return hipchatAction(Template.inline(message));
return hipchatAction(TextTemplate.inline(message));
}
public static HipChatAction.Builder hipchatAction(String account, String body) {
return hipchatAction(account, Template.inline(body));
return hipchatAction(account, TextTemplate.inline(body));
}
public static HipChatAction.Builder hipchatAction(Template.Builder body) {
public static HipChatAction.Builder hipchatAction(TextTemplate.Builder body) {
return hipchatAction(body.build());
}
public static HipChatAction.Builder hipchatAction(String account, Template.Builder body) {
public static HipChatAction.Builder hipchatAction(String account, TextTemplate.Builder body) {
return hipchatAction(account, body.build());
}
public static HipChatAction.Builder hipchatAction(Template body) {
public static HipChatAction.Builder hipchatAction(TextTemplate body) {
return hipchatAction(null, body);
}
public static HipChatAction.Builder hipchatAction(String account, Template body) {
public static HipChatAction.Builder hipchatAction(String account, TextTemplate body) {
return HipChatAction.builder(account, body);
}
}

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.ActionFactory;
import org.elasticsearch.watcher.actions.email.service.EmailService;
import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.io.IOException;
@ -22,11 +22,11 @@ import java.io.IOException;
public class EmailActionFactory extends ActionFactory<EmailAction, ExecutableEmailAction> {
private final EmailService emailService;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
private final HtmlSanitizer htmlSanitizer;
@Inject
public EmailActionFactory(Settings settings, EmailService emailService, TemplateEngine templateEngine, HtmlSanitizer htmlSanitizer) {
public EmailActionFactory(Settings settings, EmailService emailService, TextTemplateEngine templateEngine, HtmlSanitizer htmlSanitizer) {
super(Loggers.getLogger(ExecutableEmailAction.class, settings));
this.emailService = emailService;
this.templateEngine = templateEngine;

View File

@ -14,7 +14,7 @@ import org.elasticsearch.watcher.actions.email.service.EmailService;
import org.elasticsearch.watcher.actions.email.service.HtmlSanitizer;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.Variables;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.watch.Payload;
import java.util.HashMap;
@ -25,10 +25,10 @@ import java.util.Map;
public class ExecutableEmailAction extends ExecutableAction<EmailAction> {
final EmailService emailService;
final TemplateEngine templateEngine;
final TextTemplateEngine templateEngine;
final HtmlSanitizer htmlSanitizer;
public ExecutableEmailAction(EmailAction action, ESLogger logger, EmailService emailService, TemplateEngine templateEngine, HtmlSanitizer htmlSanitizer) {
public ExecutableEmailAction(EmailAction action, ESLogger logger, EmailService emailService, TextTemplateEngine templateEngine, HtmlSanitizer htmlSanitizer) {
super(action, logger);
this.emailService = emailService;
this.templateEngine = templateEngine;

View File

@ -10,8 +10,8 @@ import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import javax.mail.internet.AddressException;
import java.io.IOException;
@ -22,19 +22,19 @@ import java.util.*;
*/
public class EmailTemplate implements ToXContent {
final Template from;
final Template[] replyTo;
final Template priority;
final Template[] to;
final Template[] cc;
final Template[] bcc;
final Template subject;
final Template textBody;
final Template htmlBody;
final TextTemplate from;
final TextTemplate[] replyTo;
final TextTemplate priority;
final TextTemplate[] to;
final TextTemplate[] cc;
final TextTemplate[] bcc;
final TextTemplate subject;
final TextTemplate textBody;
final TextTemplate htmlBody;
public EmailTemplate(Template from, Template[] replyTo, Template priority, Template[] to,
Template[] cc, Template[] bcc, Template subject, Template textBody,
Template htmlBody) {
public EmailTemplate(TextTemplate from, TextTemplate[] replyTo, TextTemplate priority, TextTemplate[] to,
TextTemplate[] cc, TextTemplate[] bcc, TextTemplate subject, TextTemplate textBody,
TextTemplate htmlBody) {
this.from = from;
this.replyTo = replyTo;
this.priority = priority;
@ -46,43 +46,43 @@ public class EmailTemplate implements ToXContent {
this.htmlBody = htmlBody;
}
public Template from() {
public TextTemplate from() {
return from;
}
public Template[] replyTo() {
public TextTemplate[] replyTo() {
return replyTo;
}
public Template priority() {
public TextTemplate priority() {
return priority;
}
public Template[] to() {
public TextTemplate[] to() {
return to;
}
public Template[] cc() {
public TextTemplate[] cc() {
return cc;
}
public Template[] bcc() {
public TextTemplate[] bcc() {
return bcc;
}
public Template subject() {
public TextTemplate subject() {
return subject;
}
public Template textBody() {
public TextTemplate textBody() {
return textBody;
}
public Template htmlBody() {
public TextTemplate htmlBody() {
return htmlBody;
}
public Email.Builder render(TemplateEngine engine, Map<String, Object> model, HtmlSanitizer htmlSanitizer, Map<String, Attachment> attachments) throws AddressException {
public Email.Builder render(TextTemplateEngine engine, Map<String, Object> model, HtmlSanitizer htmlSanitizer, Map<String, Attachment> attachments) throws AddressException {
Email.Builder builder = Email.builder();
if (from != null) {
builder.from(engine.render(from, model));
@ -125,9 +125,9 @@ public class EmailTemplate implements ToXContent {
return builder;
}
private static Email.AddressList templatesToAddressList(TemplateEngine engine, Template[] templates, Map<String, Object> model) throws AddressException {
private static Email.AddressList templatesToAddressList(TextTemplateEngine engine, TextTemplate[] templates, Map<String, Object> model) throws AddressException {
List<Email.Address> addresses = new ArrayList<>(templates.length);
for (Template template : templates) {
for (TextTemplate template : templates) {
addresses.add(new Email.Address(engine.render(template, model)));
}
return new Email.AddressList(addresses);
@ -167,7 +167,7 @@ public class EmailTemplate implements ToXContent {
}
if (replyTo != null) {
builder.startArray(Email.Field.REPLY_TO.getPreferredName());
for (Template template : replyTo) {
for (TextTemplate template : replyTo) {
template.toXContent(builder, params);
}
builder.endArray();
@ -177,21 +177,21 @@ public class EmailTemplate implements ToXContent {
}
if (to != null) {
builder.startArray(Email.Field.TO.getPreferredName());
for (Template template : to) {
for (TextTemplate template : to) {
template.toXContent(builder, params);
}
builder.endArray();
}
if (cc != null) {
builder.startArray(Email.Field.CC.getPreferredName());
for (Template template : cc) {
for (TextTemplate template : cc) {
template.toXContent(builder, params);
}
builder.endArray();
}
if (bcc != null) {
builder.startArray(Email.Field.BCC.getPreferredName());
for (Template template : bcc) {
for (TextTemplate template : bcc) {
template.toXContent(builder, params);
}
builder.endArray();
@ -218,164 +218,164 @@ public class EmailTemplate implements ToXContent {
public static class Builder {
private Template from;
private Template[] replyTo;
private Template priority;
private Template[] to;
private Template[] cc;
private Template[] bcc;
private Template subject;
private Template textBody;
private Template htmlBody;
private TextTemplate from;
private TextTemplate[] replyTo;
private TextTemplate priority;
private TextTemplate[] to;
private TextTemplate[] cc;
private TextTemplate[] bcc;
private TextTemplate subject;
private TextTemplate textBody;
private TextTemplate htmlBody;
private Builder() {
}
public Builder from(String from) {
return from(Template.inline(from));
return from(TextTemplate.inline(from));
}
public Builder from(Template.Builder from) {
public Builder from(TextTemplate.Builder from) {
return from(from.build());
}
public Builder from(Template from) {
public Builder from(TextTemplate from) {
this.from = from;
return this;
}
public Builder replyTo(String... replyTo) {
Template[] templates = new Template[replyTo.length];
TextTemplate[] templates = new TextTemplate[replyTo.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = Template.defaultType(replyTo[i]).build();
templates[i] = TextTemplate.defaultType(replyTo[i]).build();
}
return replyTo(templates);
}
public Builder replyTo(Template.Builder... replyTo) {
Template[] templates = new Template[replyTo.length];
public Builder replyTo(TextTemplate.Builder... replyTo) {
TextTemplate[] templates = new TextTemplate[replyTo.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = replyTo[i].build();
}
return replyTo(templates);
}
public Builder replyTo(Template... replyTo) {
public Builder replyTo(TextTemplate... replyTo) {
this.replyTo = replyTo;
return this;
}
public Builder priority(Email.Priority priority) {
return priority(Template.inline(priority.name()));
return priority(TextTemplate.inline(priority.name()));
}
public Builder priority(Template.Builder priority) {
public Builder priority(TextTemplate.Builder priority) {
return priority(priority.build());
}
public Builder priority(Template priority) {
public Builder priority(TextTemplate priority) {
this.priority = priority;
return this;
}
public Builder to(String... to) {
Template[] templates = new Template[to.length];
TextTemplate[] templates = new TextTemplate[to.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = Template.defaultType(to[i]).build();
templates[i] = TextTemplate.defaultType(to[i]).build();
}
return to(templates);
}
public Builder to(Template.Builder... to) {
Template[] templates = new Template[to.length];
public Builder to(TextTemplate.Builder... to) {
TextTemplate[] templates = new TextTemplate[to.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = to[i].build();
}
return to(templates);
}
public Builder to(Template... to) {
public Builder to(TextTemplate... to) {
this.to = to;
return this;
}
public Builder cc(String... cc) {
Template[] templates = new Template[cc.length];
TextTemplate[] templates = new TextTemplate[cc.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = Template.defaultType(cc[i]).build();
templates[i] = TextTemplate.defaultType(cc[i]).build();
}
return cc(templates);
}
public Builder cc(Template.Builder... cc) {
Template[] templates = new Template[cc.length];
public Builder cc(TextTemplate.Builder... cc) {
TextTemplate[] templates = new TextTemplate[cc.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = cc[i].build();
}
return cc(templates);
}
public Builder cc(Template... cc) {
public Builder cc(TextTemplate... cc) {
this.cc = cc;
return this;
}
public Builder bcc(String... bcc) {
Template[] templates = new Template[bcc.length];
TextTemplate[] templates = new TextTemplate[bcc.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = Template.defaultType(bcc[i]).build();
templates[i] = TextTemplate.defaultType(bcc[i]).build();
}
return bcc(templates);
}
public Builder bcc(Template.Builder... bcc) {
Template[] templates = new Template[bcc.length];
public Builder bcc(TextTemplate.Builder... bcc) {
TextTemplate[] templates = new TextTemplate[bcc.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = bcc[i].build();
}
return bcc(templates);
}
public Builder bcc(Template... bcc) {
public Builder bcc(TextTemplate... bcc) {
this.bcc = bcc;
return this;
}
public Builder subject(String subject) {
return subject(Template.defaultType(subject));
return subject(TextTemplate.defaultType(subject));
}
public Builder subject(Template.Builder subject) {
public Builder subject(TextTemplate.Builder subject) {
return subject(subject.build());
}
public Builder subject(Template subject) {
public Builder subject(TextTemplate subject) {
this.subject = subject;
return this;
}
public Builder textBody(String text) {
return textBody(Template.defaultType(text));
return textBody(TextTemplate.defaultType(text));
}
public Builder textBody(Template.Builder text) {
public Builder textBody(TextTemplate.Builder text) {
return textBody(text.build());
}
public Builder textBody(Template text) {
public Builder textBody(TextTemplate text) {
this.textBody = text;
return this;
}
public Builder htmlBody(String html) {
return htmlBody(Template.defaultType(html));
return htmlBody(TextTemplate.defaultType(html));
}
public Builder htmlBody(Template.Builder html) {
public Builder htmlBody(TextTemplate.Builder html) {
return htmlBody(html.build());
}
public Builder htmlBody(Template html) {
public Builder htmlBody(TextTemplate html) {
this.htmlBody = html;
return this;
}
@ -391,54 +391,54 @@ public class EmailTemplate implements ToXContent {
public boolean handle(String fieldName, XContentParser parser) throws IOException {
if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.FROM)) {
builder.from(Template.parse(parser));
builder.from(TextTemplate.parse(parser));
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.REPLY_TO)) {
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
List<Template> templates = new ArrayList<>();
List<TextTemplate> templates = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
templates.add(Template.parse(parser));
templates.add(TextTemplate.parse(parser));
}
builder.replyTo(templates.toArray(new Template[templates.size()]));
builder.replyTo(templates.toArray(new TextTemplate[templates.size()]));
} else {
builder.replyTo(Template.parse(parser));
builder.replyTo(TextTemplate.parse(parser));
}
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.TO)) {
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
List<Template> templates = new ArrayList<>();
List<TextTemplate> templates = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
templates.add(Template.parse(parser));
templates.add(TextTemplate.parse(parser));
}
builder.to(templates.toArray(new Template[templates.size()]));
builder.to(templates.toArray(new TextTemplate[templates.size()]));
} else {
builder.to(Template.parse(parser));
builder.to(TextTemplate.parse(parser));
}
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.CC)) {
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
List<Template> templates = new ArrayList<>();
List<TextTemplate> templates = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
templates.add(Template.parse(parser));
templates.add(TextTemplate.parse(parser));
}
builder.cc(templates.toArray(new Template[templates.size()]));
builder.cc(templates.toArray(new TextTemplate[templates.size()]));
} else {
builder.cc(Template.parse(parser));
builder.cc(TextTemplate.parse(parser));
}
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.BCC)) {
if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
List<Template> templates = new ArrayList<>();
List<TextTemplate> templates = new ArrayList<>();
while (parser.nextToken() != XContentParser.Token.END_ARRAY) {
templates.add(Template.parse(parser));
templates.add(TextTemplate.parse(parser));
}
builder.bcc(templates.toArray(new Template[templates.size()]));
builder.bcc(templates.toArray(new TextTemplate[templates.size()]));
} else {
builder.bcc(Template.parse(parser));
builder.bcc(TextTemplate.parse(parser));
}
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.PRIORITY)) {
builder.priority(Template.parse(parser));
builder.priority(TextTemplate.parse(parser));
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.SUBJECT)) {
builder.subject(Template.parse(parser));
builder.subject(TextTemplate.parse(parser));
} else if (ParseFieldMatcher.STRICT.match(fieldName, Email.Field.BODY)) {
if (parser.currentToken() == XContentParser.Token.VALUE_STRING) {
builder.textBody(Template.parse(parser));
builder.textBody(TextTemplate.parse(parser));
} else if (parser.currentToken() == XContentParser.Token.START_OBJECT) {
XContentParser.Token token;
String currentFieldName = null;
@ -448,9 +448,9 @@ public class EmailTemplate implements ToXContent {
} else if (currentFieldName == null) {
throw new ElasticsearchParseException("could not parse email template. empty [{}] field", fieldName);
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Email.Field.BODY_TEXT)) {
builder.textBody(Template.parse(parser));
builder.textBody(TextTemplate.parse(parser));
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Email.Field.BODY_HTML)) {
builder.htmlBody(Template.parse(parser));
builder.htmlBody(TextTemplate.parse(parser));
} else {
throw new ElasticsearchParseException("could not parse email template. unknown field [{}.{}] field", fieldName, currentFieldName);
}

View File

@ -14,7 +14,7 @@ import org.elasticsearch.watcher.actions.hipchat.service.HipChatService;
import org.elasticsearch.watcher.actions.hipchat.service.SentMessages;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.Variables;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.watch.Payload;
import java.util.Map;
@ -24,10 +24,10 @@ import java.util.Map;
*/
public class ExecutableHipChatAction extends ExecutableAction<HipChatAction> {
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
private final HipChatService hipchatService;
public ExecutableHipChatAction(HipChatAction action, ESLogger logger, HipChatService hipchatService, TemplateEngine templateEngine) {
public ExecutableHipChatAction(HipChatAction action, ESLogger logger, HipChatService hipchatService, TextTemplateEngine templateEngine) {
super(action, logger);
this.hipchatService = hipchatService;
this.templateEngine = templateEngine;

View File

@ -14,7 +14,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.Action;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage;
import org.elasticsearch.watcher.actions.hipchat.service.SentMessages;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import javax.annotation.Nullable;
import java.io.IOException;
@ -100,7 +100,7 @@ public class HipChatAction implements Action {
return new HipChatAction(account, message);
}
public static Builder builder(String account, Template body) {
public static Builder builder(String account, TextTemplate body) {
return new Builder(account, body);
}
@ -168,18 +168,18 @@ public class HipChatAction implements Action {
final String account;
final HipChatMessage.Template.Builder messageBuilder;
public Builder(String account, Template body) {
public Builder(String account, TextTemplate body) {
this.account = account;
this.messageBuilder = new HipChatMessage.Template.Builder(body);
}
public Builder addRooms(org.elasticsearch.watcher.support.template.Template... rooms) {
public Builder addRooms(TextTemplate... rooms) {
messageBuilder.addRooms(rooms);
return this;
}
public Builder addRooms(org.elasticsearch.watcher.support.template.Template.Builder... rooms) {
org.elasticsearch.watcher.support.template.Template[] templates = new org.elasticsearch.watcher.support.template.Template[rooms.length];
public Builder addRooms(TextTemplate.Builder... rooms) {
TextTemplate[] templates = new TextTemplate[rooms.length];
for (int i = 0; i < rooms.length; i++) {
templates[i] = rooms[i].build();
}
@ -187,21 +187,21 @@ public class HipChatAction implements Action {
}
public Builder addRooms(String... rooms) {
org.elasticsearch.watcher.support.template.Template[] templates = new org.elasticsearch.watcher.support.template.Template[rooms.length];
TextTemplate[] templates = new TextTemplate[rooms.length];
for (int i = 0; i < rooms.length; i++) {
templates[i] = Template.inline(rooms[i]).build();
templates[i] = TextTemplate.inline(rooms[i]).build();
}
return addRooms(templates);
}
public Builder addUsers(org.elasticsearch.watcher.support.template.Template... users) {
public Builder addUsers(TextTemplate... users) {
messageBuilder.addUsers(users);
return this;
}
public Builder addUsers(org.elasticsearch.watcher.support.template.Template.Builder... users) {
org.elasticsearch.watcher.support.template.Template[] templates = new org.elasticsearch.watcher.support.template.Template[users.length];
public Builder addUsers(TextTemplate.Builder... users) {
TextTemplate[] templates = new TextTemplate[users.length];
for (int i = 0; i < users.length; i++) {
templates[i] = users[i].build();
}
@ -209,9 +209,9 @@ public class HipChatAction implements Action {
}
public Builder addUsers(String... users) {
org.elasticsearch.watcher.support.template.Template[] templates = new org.elasticsearch.watcher.support.template.Template[users.length];
TextTemplate[] templates = new TextTemplate[users.length];
for (int i = 0; i < users.length; i++) {
templates[i] = Template.inline(users[i]).build();
templates[i] = TextTemplate.inline(users[i]).build();
}
return addUsers(templates);
}
@ -226,12 +226,12 @@ public class HipChatAction implements Action {
return this;
}
public Builder setColor(org.elasticsearch.watcher.support.template.Template color) {
public Builder setColor(TextTemplate color) {
messageBuilder.setColor(color);
return this;
}
public Builder setColor(org.elasticsearch.watcher.support.template.Template.Builder color) {
public Builder setColor(TextTemplate.Builder color) {
return setColor(color.build());
}

View File

@ -13,7 +13,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.ActionFactory;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatService;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.io.IOException;
@ -22,11 +22,11 @@ import java.io.IOException;
*/
public class HipChatActionFactory extends ActionFactory<HipChatAction, ExecutableHipChatAction> {
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
private final HipChatService hipchatService;
@Inject
public HipChatActionFactory(Settings settings, TemplateEngine templateEngine, HipChatService hipchatService) {
public HipChatActionFactory(Settings settings, TextTemplateEngine templateEngine, HipChatService hipchatService) {
super(Loggers.getLogger(ExecutableHipChatAction.class, settings));
this.templateEngine = templateEngine;
this.hipchatService = hipchatService;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.io.IOException;
import java.util.Locale;
@ -55,7 +55,7 @@ public abstract class HipChatAccount {
public abstract void validateParsedTemplate(String watchId, String actionId, HipChatMessage.Template message) throws SettingsException;
public abstract HipChatMessage render(String watchId, String actionId, TemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model);
public abstract HipChatMessage render(String watchId, String actionId, TextTemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model);
public abstract SentMessages send(HipChatMessage message);

View File

@ -12,7 +12,8 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import javax.annotation.Nullable;
import java.io.IOException;
@ -135,20 +136,21 @@ public class HipChatMessage implements ToXContent {
public static class Template implements ToXContent {
final org.elasticsearch.watcher.support.template.Template body;
final @Nullable org.elasticsearch.watcher.support.template.Template[] rooms;
final @Nullable org.elasticsearch.watcher.support.template.Template[] users;
final TextTemplate body;
final @Nullable TextTemplate[] rooms;
final @Nullable TextTemplate[] users;
final @Nullable String from;
final @Nullable Format format;
final @Nullable org.elasticsearch.watcher.support.template.Template color;
final @Nullable
TextTemplate color;
final @Nullable Boolean notify;
public Template(org.elasticsearch.watcher.support.template.Template body,
org.elasticsearch.watcher.support.template.Template[] rooms,
org.elasticsearch.watcher.support.template.Template[] users,
public Template(TextTemplate body,
TextTemplate[] rooms,
TextTemplate[] users,
String from,
Format format,
org.elasticsearch.watcher.support.template.Template color,
TextTemplate color,
Boolean notify) {
this.rooms = rooms;
this.users = users;
@ -187,7 +189,7 @@ public class HipChatMessage implements ToXContent {
return result;
}
public HipChatMessage render(TemplateEngine engine, Map<String, Object> model) {
public HipChatMessage render(TextTemplateEngine engine, Map<String, Object> model) {
String body = engine.render(this.body, model);
String[] rooms = null;
if (this.rooms != null) {
@ -215,14 +217,14 @@ public class HipChatMessage implements ToXContent {
}
if (rooms != null && rooms.length > 0) {
builder.startArray(Field.ROOM.getPreferredName());
for (org.elasticsearch.watcher.support.template.Template room : rooms) {
for (TextTemplate room : rooms) {
room.toXContent(builder, params);
}
builder.endArray();
}
if (users != null && users.length > 0) {
builder.startArray(Field.USER.getPreferredName());
for (org.elasticsearch.watcher.support.template.Template user : users) {
for (TextTemplate user : users) {
user.toXContent(builder, params);
}
builder.endArray();
@ -241,11 +243,11 @@ public class HipChatMessage implements ToXContent {
}
public static Template parse(XContentParser parser) throws IOException {
org.elasticsearch.watcher.support.template.Template body = null;
org.elasticsearch.watcher.support.template.Template[] rooms = null;
org.elasticsearch.watcher.support.template.Template[] users = null;
TextTemplate body = null;
TextTemplate[] rooms = null;
TextTemplate[] users = null;
String from = null;
org.elasticsearch.watcher.support.template.Template color = null;
TextTemplate color = null;
Boolean notify = null;
HipChatMessage.Format messageFormat = null;
@ -257,44 +259,44 @@ public class HipChatMessage implements ToXContent {
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.FROM)) {
from = parser.text();
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.ROOM)) {
List<org.elasticsearch.watcher.support.template.Template> templates = new ArrayList<>();
List<TextTemplate> templates = new ArrayList<>();
if (token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
try {
templates.add(org.elasticsearch.watcher.support.template.Template.parse(parser));
templates.add(TextTemplate.parse(parser));
} catch (ElasticsearchParseException epe) {
throw new ElasticsearchParseException("failed to parse hipchat message. failed to parse [{}] field", epe, Field.ROOM.getPreferredName());
}
}
} else {
try {
templates.add(org.elasticsearch.watcher.support.template.Template.parse(parser));
templates.add(TextTemplate.parse(parser));
} catch (ElasticsearchParseException epe) {
throw new ElasticsearchParseException("failed to parse hipchat message. failed to parse [{}] field", epe, Field.ROOM.getPreferredName());
}
}
rooms = templates.toArray(new org.elasticsearch.watcher.support.template.Template[templates.size()]);
rooms = templates.toArray(new TextTemplate[templates.size()]);
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.USER)) {
List<org.elasticsearch.watcher.support.template.Template> templates = new ArrayList<>();
List<TextTemplate> templates = new ArrayList<>();
if (token == XContentParser.Token.START_ARRAY) {
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
try {
templates.add(org.elasticsearch.watcher.support.template.Template.parse(parser));
templates.add(TextTemplate.parse(parser));
} catch (ElasticsearchParseException epe) {
throw new ElasticsearchParseException("failed to parse hipchat message. failed to parse [{}] field", epe, Field.USER.getPreferredName());
}
}
} else {
try {
templates.add(org.elasticsearch.watcher.support.template.Template.parse(parser));
templates.add(TextTemplate.parse(parser));
} catch (ElasticsearchParseException epe) {
throw new ElasticsearchParseException("failed to parse hipchat message. failed to parse [{}] field", epe, Field.USER.getPreferredName());
}
}
users = templates.toArray(new org.elasticsearch.watcher.support.template.Template[templates.size()]);
users = templates.toArray(new TextTemplate[templates.size()]);
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.COLOR)) {
try {
color = org.elasticsearch.watcher.support.template.Template.parse(parser);
color = TextTemplate.parse(parser);
} catch (ElasticsearchParseException | IllegalArgumentException e) {
throw new ElasticsearchParseException("failed to parse hipchat message. failed to parse [{}] field", e, Field.COLOR.getPreferredName());
}
@ -306,7 +308,7 @@ public class HipChatMessage implements ToXContent {
}
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.BODY)) {
try {
body = org.elasticsearch.watcher.support.template.Template.parse(parser);
body = TextTemplate.parse(parser);
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("failed to parse hipchat message. failed to parse [{}] field", pe, Field.BODY.getPreferredName());
}
@ -330,24 +332,25 @@ public class HipChatMessage implements ToXContent {
public static class Builder {
final org.elasticsearch.watcher.support.template.Template body;
final List<org.elasticsearch.watcher.support.template.Template> rooms = new ArrayList<>();
final List<org.elasticsearch.watcher.support.template.Template> users = new ArrayList<>();
final TextTemplate body;
final List<TextTemplate> rooms = new ArrayList<>();
final List<TextTemplate> users = new ArrayList<>();
@Nullable String from;
@Nullable Format format;
@Nullable org.elasticsearch.watcher.support.template.Template color;
@Nullable
TextTemplate color;
@Nullable Boolean notify;
public Builder(org.elasticsearch.watcher.support.template.Template body) {
public Builder(TextTemplate body) {
this.body = body;
}
public Builder addRooms(org.elasticsearch.watcher.support.template.Template... rooms) {
public Builder addRooms(TextTemplate... rooms) {
this.rooms.addAll(Arrays.asList(rooms));
return this;
}
public Builder addUsers(org.elasticsearch.watcher.support.template.Template... users) {
public Builder addUsers(TextTemplate... users) {
this.users.addAll(Arrays.asList(users));
return this;
}
@ -362,7 +365,7 @@ public class HipChatMessage implements ToXContent {
return this;
}
public Builder setColor(org.elasticsearch.watcher.support.template.Template color) {
public Builder setColor(TextTemplate color) {
this.color = color;
return this;
}
@ -375,8 +378,8 @@ public class HipChatMessage implements ToXContent {
public Template build() {
return new Template(
body,
rooms.isEmpty() ? null : rooms.toArray(new org.elasticsearch.watcher.support.template.Template[rooms.size()]),
users.isEmpty() ? null : users.toArray(new org.elasticsearch.watcher.support.template.Template[users.size()]),
rooms.isEmpty() ? null : rooms.toArray(new TextTemplate[rooms.size()]),
users.isEmpty() ? null : users.toArray(new TextTemplate[users.size()]),
from,
format,
color,
@ -389,9 +392,9 @@ public class HipChatMessage implements ToXContent {
public enum Color implements ToXContent {
YELLOW, GREEN, RED, PURPLE, GRAY, RANDOM;
private final org.elasticsearch.watcher.support.template.Template template = org.elasticsearch.watcher.support.template.Template.inline(name()).build();
private final TextTemplate template = TextTemplate.inline(name()).build();
public org.elasticsearch.watcher.support.template.Template asTemplate() {
public TextTemplate asTemplate() {
return template;
}
@ -437,9 +440,9 @@ public class HipChatMessage implements ToXContent {
TEXT,
HTML;
private final org.elasticsearch.watcher.support.template.Template template = org.elasticsearch.watcher.support.template.Template.inline(name()).build();
private final TextTemplate template = TextTemplate.inline(name()).build();
public org.elasticsearch.watcher.support.template.Template asTemplate() {
public TextTemplate asTemplate() {
return template;
}

View File

@ -17,7 +17,7 @@ import org.elasticsearch.watcher.actions.hipchat.HipChatAction;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Color;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Format;
import org.elasticsearch.watcher.support.http.*;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import javax.annotation.Nullable;
import java.io.IOException;
@ -67,7 +67,7 @@ public class IntegrationAccount extends HipChatAccount {
}
@Override
public HipChatMessage render(String watchId, String actionId, TemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model) {
public HipChatMessage render(String watchId, String actionId, TextTemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model) {
String message = engine.render(template.body, model);
Color color = template.color != null ? Color.resolve(engine.render(template.color, model), defaults.color) : defaults.color;
Boolean notify = template.notify != null ? template.notify : defaults.notify;

View File

@ -17,7 +17,7 @@ import org.elasticsearch.watcher.actions.hipchat.HipChatAction;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Color;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Format;
import org.elasticsearch.watcher.support.http.*;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import javax.annotation.Nullable;
import java.io.IOException;
@ -52,7 +52,7 @@ public class UserAccount extends HipChatAccount {
}
@Override
public HipChatMessage render(String watchId, String actionId, TemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model) {
public HipChatMessage render(String watchId, String actionId, TextTemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model) {
String[] rooms = defaults.rooms;
if (template.rooms != null) {
rooms = new String[template.rooms.length];

View File

@ -13,7 +13,7 @@ import org.elasticsearch.watcher.actions.hipchat.HipChatAction;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Color;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage.Format;
import org.elasticsearch.watcher.support.http.*;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import javax.annotation.Nullable;
import java.io.IOException;
@ -51,7 +51,7 @@ public class V1Account extends HipChatAccount {
}
@Override
public HipChatMessage render(String watchId, String actionId, TemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model) {
public HipChatMessage render(String watchId, String actionId, TextTemplateEngine engine, HipChatMessage.Template template, Map<String, Object> model) {
String message = engine.render(template.body, model);
String[] rooms = defaults.rooms;
if (template.rooms != null) {

View File

@ -12,7 +12,7 @@ import org.elasticsearch.watcher.actions.Action;
import org.elasticsearch.watcher.actions.ExecutableAction;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.Variables;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.watch.Payload;
import java.util.Map;
@ -23,16 +23,16 @@ import java.util.Map;
public class ExecutableLoggingAction extends ExecutableAction<LoggingAction> {
private final ESLogger textLogger;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
ExecutableLoggingAction(LoggingAction action, ESLogger logger, Settings settings, TemplateEngine templateEngine) {
ExecutableLoggingAction(LoggingAction action, ESLogger logger, Settings settings, TextTemplateEngine templateEngine) {
super(action, logger);
this.textLogger = action.category != null ? Loggers.getLogger(action.category, settings) : logger;
this.templateEngine = templateEngine;
}
// for tests
ExecutableLoggingAction(LoggingAction action, ESLogger logger, ESLogger textLogger, TemplateEngine templateEngine) {
ExecutableLoggingAction(LoggingAction action, ESLogger logger, ESLogger textLogger, TextTemplateEngine templateEngine) {
super(action, logger);
this.textLogger = textLogger;
this.templateEngine = templateEngine;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.ParseFieldMatcher;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.Action;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import java.io.IOException;
import java.util.Locale;
@ -24,11 +24,11 @@ public class LoggingAction implements Action {
public static final String TYPE = "logging";
final Template text;
final TextTemplate text;
final @Nullable LoggingLevel level;
final @Nullable String category;
public LoggingAction(Template text, @Nullable LoggingLevel level, @Nullable String category) {
public LoggingAction(TextTemplate text, @Nullable LoggingLevel level, @Nullable String category) {
this.text = text;
this.level = level != null ? level : LoggingLevel.INFO;
this.category = category;
@ -73,7 +73,7 @@ public class LoggingAction implements Action {
public static LoggingAction parse(String watchId, String actionId, XContentParser parser) throws IOException {
String category = null;
LoggingLevel level = null;
Template text = null;
TextTemplate text = null;
String currentFieldName = null;
XContentParser.Token token;
@ -82,7 +82,7 @@ public class LoggingAction implements Action {
currentFieldName = parser.currentName();
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.TEXT)) {
try {
text = Template.parse(parser);
text = TextTemplate.parse(parser);
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("failed to parse [{}] action [{}/{}]. failed to parse [{}] field", pe, TYPE, watchId, actionId, Field.TEXT.getPreferredName());
}
@ -110,7 +110,7 @@ public class LoggingAction implements Action {
return new LoggingAction(text, level, category);
}
public static Builder builder(Template template) {
public static Builder builder(TextTemplate template) {
return new Builder(template);
}
@ -161,11 +161,11 @@ public class LoggingAction implements Action {
public static class Builder implements Action.Builder<LoggingAction> {
final Template text;
final TextTemplate text;
LoggingLevel level;
@Nullable String category;
private Builder(Template text) {
private Builder(TextTemplate text) {
this.text = text;
}

View File

@ -10,7 +10,7 @@ import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.ActionFactory;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.io.IOException;
@ -20,10 +20,10 @@ import java.io.IOException;
public class LoggingActionFactory extends ActionFactory<LoggingAction, ExecutableLoggingAction> {
private final Settings settings;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
@Inject
public LoggingActionFactory(Settings settings, TemplateEngine templateEngine) {
public LoggingActionFactory(Settings settings, TextTemplateEngine templateEngine) {
super(Loggers.getLogger(ExecutableLoggingAction.class, settings));
this.settings = settings;
this.templateEngine = templateEngine;

View File

@ -13,7 +13,7 @@ import org.elasticsearch.watcher.support.Variables;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.http.HttpRequest;
import org.elasticsearch.watcher.support.http.HttpResponse;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.watch.Payload;
import java.util.Map;
@ -23,9 +23,9 @@ import java.util.Map;
public class ExecutableWebhookAction extends ExecutableAction<WebhookAction> {
private final HttpClient httpClient;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
public ExecutableWebhookAction(WebhookAction action, ESLogger logger, HttpClient httpClient, TemplateEngine templateEngine) {
public ExecutableWebhookAction(WebhookAction action, ESLogger logger, HttpClient httpClient, TextTemplateEngine templateEngine) {
super(action, logger);
this.httpClient = httpClient;
this.templateEngine = templateEngine;

View File

@ -12,7 +12,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.watcher.actions.ActionFactory;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.io.IOException;
@ -23,11 +23,11 @@ public class WebhookActionFactory extends ActionFactory<WebhookAction, Executabl
private final HttpClient httpClient;
private final HttpRequestTemplate.Parser requestTemplateParser;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
@Inject
public WebhookActionFactory(Settings settings, HttpClient httpClient, HttpRequestTemplate.Parser requestTemplateParser,
TemplateEngine templateEngine) {
TextTemplateEngine templateEngine) {
super(Loggers.getLogger(ExecutableWebhookAction.class, settings));
this.httpClient = httpClient;

View File

@ -18,7 +18,7 @@ import org.elasticsearch.watcher.support.XContentFilterKeysUtils;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.http.HttpRequest;
import org.elasticsearch.watcher.support.http.HttpResponse;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.watch.Payload;
import java.util.Map;
@ -28,9 +28,9 @@ import java.util.Map;
public class ExecutableHttpInput extends ExecutableInput<HttpInput, HttpInput.Result> {
private final HttpClient client;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
public ExecutableHttpInput(HttpInput input, ESLogger logger, HttpClient client, TemplateEngine templateEngine) {
public ExecutableHttpInput(HttpInput input, ESLogger logger, HttpClient client, TextTemplateEngine templateEngine) {
super(input, logger);
this.client = client;
this.templateEngine = templateEngine;

View File

@ -13,7 +13,7 @@ import org.elasticsearch.watcher.input.InputFactory;
import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.http.HttpRequest;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.io.IOException;
@ -23,12 +23,12 @@ import java.io.IOException;
public final class HttpInputFactory extends InputFactory<HttpInput, HttpInput.Result, ExecutableHttpInput> {
private final HttpClient httpClient;
private final TemplateEngine templateEngine;
private final TextTemplateEngine templateEngine;
private final HttpRequest.Parser requestParser;
private final HttpRequestTemplate.Parser requestTemplateParser;
@Inject
public HttpInputFactory(Settings settings, HttpClient httpClient, TemplateEngine templateEngine, HttpRequest.Parser requestParser, HttpRequestTemplate.Parser requestTemplateParser) {
public HttpInputFactory(Settings settings, HttpClient httpClient, TextTemplateEngine templateEngine, HttpRequest.Parser requestParser, HttpRequestTemplate.Parser requestTemplateParser) {
super(Loggers.getLogger(ExecutableHttpInput.class, settings));
this.templateEngine = templateEngine;
this.httpClient = httpClient;

View File

@ -18,7 +18,7 @@ import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.*;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.watch.Payload;
import org.joda.time.DateTime;
@ -89,7 +89,7 @@ public final class WatcherUtils {
BytesReference templateSource = requestPrototype.templateSource();
try (XContentParser sourceParser = XContentFactory.xContent(templateSource).createParser(templateSource)) {
sourceParser.nextToken();
Template template = Template.parse(sourceParser);
TextTemplate template = TextTemplate.parse(sourceParser);
// Convert to the ES template format:
XContentBuilder builder = jsonBuilder();

View File

@ -19,8 +19,8 @@ import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.watcher.support.http.HttpRequest.Field;
import org.elasticsearch.watcher.support.http.auth.HttpAuth;
import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import java.io.IOException;
@ -35,24 +35,24 @@ public class HttpRequestTemplate implements ToXContent {
private final String host;
private final int port;
private final HttpMethod method;
private final Template path;
private final ImmutableMap<String, Template> params;
private final ImmutableMap<String, Template> headers;
private final TextTemplate path;
private final ImmutableMap<String, TextTemplate> params;
private final ImmutableMap<String, TextTemplate> headers;
private final HttpAuth auth;
private final Template body;
private final TextTemplate body;
private final @Nullable TimeValue connectionTimeout;
private final @Nullable TimeValue readTimeout;
public HttpRequestTemplate(String host, int port, @Nullable Scheme scheme, @Nullable HttpMethod method, @Nullable Template path,
Map<String, Template> params, Map<String, Template> headers, HttpAuth auth,
Template body, @Nullable TimeValue connectionTimeout, @Nullable TimeValue readTimeout) {
public HttpRequestTemplate(String host, int port, @Nullable Scheme scheme, @Nullable HttpMethod method, @Nullable TextTemplate path,
Map<String, TextTemplate> params, Map<String, TextTemplate> headers, HttpAuth auth,
TextTemplate body, @Nullable TimeValue connectionTimeout, @Nullable TimeValue readTimeout) {
this.host = host;
this.port = port;
this.scheme = scheme != null ? scheme :Scheme.HTTP;
this.method = method != null ? method : HttpMethod.GET;
this.path = path;
this.params = params != null ? ImmutableMap.copyOf(params) : ImmutableMap.<String, Template>of();
this.headers = headers != null ? ImmutableMap.copyOf(headers) : ImmutableMap.<String, Template>of();
this.params = params != null ? ImmutableMap.copyOf(params) : ImmutableMap.<String, TextTemplate>of();
this.headers = headers != null ? ImmutableMap.copyOf(headers) : ImmutableMap.<String, TextTemplate>of();
this.auth = auth;
this.body = body;
this.connectionTimeout = connectionTimeout;
@ -75,15 +75,15 @@ public class HttpRequestTemplate implements ToXContent {
return method;
}
public Template path() {
public TextTemplate path() {
return path;
}
public Map<String, Template> params() {
public Map<String, TextTemplate> params() {
return params;
}
public Map<String, Template> headers() {
public Map<String, TextTemplate> headers() {
return headers;
}
@ -91,7 +91,7 @@ public class HttpRequestTemplate implements ToXContent {
return auth;
}
public Template body() {
public TextTemplate body() {
return body;
}
@ -103,7 +103,7 @@ public class HttpRequestTemplate implements ToXContent {
return readTimeout;
}
public HttpRequest render(TemplateEngine engine, Map<String, Object> model) {
public HttpRequest render(TextTemplateEngine engine, Map<String, Object> model) {
HttpRequest.Builder request = HttpRequest.builder(host, port);
request.method(method);
request.scheme(scheme);
@ -112,7 +112,7 @@ public class HttpRequestTemplate implements ToXContent {
}
if (params != null && !params.isEmpty()) {
MapBuilder<String, String> mapBuilder = MapBuilder.newMapBuilder();
for (Map.Entry<String, Template> entry : params.entrySet()) {
for (Map.Entry<String, TextTemplate> entry : params.entrySet()) {
mapBuilder.put(entry.getKey(), engine.render(entry.getValue(), model));
}
request.setParams(mapBuilder.map());
@ -125,7 +125,7 @@ public class HttpRequestTemplate implements ToXContent {
// putting the content type first, so it can be overridden by custom headers
mapBuilder.put(HttpHeaders.Names.CONTENT_TYPE, body.getContentType().restContentType());
}
for (Map.Entry<String, Template> entry : headers.entrySet()) {
for (Map.Entry<String, TextTemplate> entry : headers.entrySet()) {
mapBuilder.put(entry.getKey(), engine.render(entry.getValue(), model));
}
request.setHeaders(mapBuilder.map());
@ -156,14 +156,14 @@ public class HttpRequestTemplate implements ToXContent {
}
if (this.params != null) {
builder.startObject(Field.PARAMS.getPreferredName());
for (Map.Entry<String, Template> entry : this.params.entrySet()) {
for (Map.Entry<String, TextTemplate> entry : this.params.entrySet()) {
builder.field(entry.getKey(), entry.getValue(), params);
}
builder.endObject();
}
if (headers != null) {
builder.startObject(Field.HEADERS.getPreferredName());
for (Map.Entry<String, Template> entry : headers.entrySet()) {
for (Map.Entry<String, TextTemplate> entry : headers.entrySet()) {
builder.field(entry.getKey(), entry.getValue(), params);
}
builder.endObject();
@ -300,16 +300,16 @@ public class HttpRequestTemplate implements ToXContent {
return builder.build();
}
private static Template parseFieldTemplate(String field, XContentParser parser) throws IOException {
private static TextTemplate parseFieldTemplate(String field, XContentParser parser) throws IOException {
try {
return Template.parse(parser);
return TextTemplate.parse(parser);
} catch (ElasticsearchParseException pe) {
throw new ElasticsearchParseException("could not parse http request template. could not parse value for [{}] field", pe, field);
}
}
private static Map<String, Template> parseFieldTemplates(String field, XContentParser parser) throws IOException {
Map<String, Template> templates = new HashMap<>();
private static Map<String, TextTemplate> parseFieldTemplates(String field, XContentParser parser) throws IOException {
Map<String, TextTemplate> templates = new HashMap<>();
String currentFieldName = null;
XContentParser.Token token;
@ -330,11 +330,11 @@ public class HttpRequestTemplate implements ToXContent {
private int port;
private Scheme scheme;
private HttpMethod method;
private Template path;
private final ImmutableMap.Builder<String, Template> params = ImmutableMap.builder();
private final ImmutableMap.Builder<String, Template> headers = ImmutableMap.builder();
private TextTemplate path;
private final ImmutableMap.Builder<String, TextTemplate> params = ImmutableMap.builder();
private final ImmutableMap.Builder<String, TextTemplate> headers = ImmutableMap.builder();
private HttpAuth auth;
private Template body;
private TextTemplate body;
private TimeValue connectionTimeout;
private TimeValue readTimeout;
@ -357,42 +357,42 @@ public class HttpRequestTemplate implements ToXContent {
}
public Builder path(String path) {
return path(Template.inline(path));
return path(TextTemplate.inline(path));
}
public Builder path(Template.Builder path) {
public Builder path(TextTemplate.Builder path) {
return path(path.build());
}
public Builder path(Template path) {
public Builder path(TextTemplate path) {
this.path = path;
return this;
}
public Builder putParams(Map<String, Template> params) {
public Builder putParams(Map<String, TextTemplate> params) {
this.params.putAll(params);
return this;
}
public Builder putParam(String key, Template.Builder value) {
public Builder putParam(String key, TextTemplate.Builder value) {
return putParam(key, value.build());
}
public Builder putParam(String key, Template value) {
public Builder putParam(String key, TextTemplate value) {
this.params.put(key, value);
return this;
}
public Builder putHeaders(Map<String, Template> headers) {
public Builder putHeaders(Map<String, TextTemplate> headers) {
this.headers.putAll(headers);
return this;
}
public Builder putHeader(String key, Template.Builder value) {
public Builder putHeader(String key, TextTemplate.Builder value) {
return putHeader(key, value.build());
}
public Builder putHeader(String key, Template value) {
public Builder putHeader(String key, TextTemplate value) {
this.headers.put(key, value);
return this;
}
@ -403,20 +403,20 @@ public class HttpRequestTemplate implements ToXContent {
}
public Builder body(String body) {
return body(Template.inline(body));
return body(TextTemplate.inline(body));
}
public Builder body(Template.Builder body) {
public Builder body(TextTemplate.Builder body) {
return body(body.build());
}
public Builder body(Template body) {
public Builder body(TextTemplate body) {
this.body = body;
return this;
}
public Builder body(XContentBuilder content) {
return body(Template.inline(content));
return body(TextTemplate.inline(content));
}
public Builder connectionTimeout(TimeValue timeout) {

View File

@ -1,45 +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.watcher.support.template;
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.script.ExecutableScript;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService;
import java.util.HashMap;
import java.util.Map;
/**
*
*/
public class MustacheTemplateEngine extends AbstractComponent implements TemplateEngine {
private final ScriptServiceProxy service;
@Inject
public MustacheTemplateEngine(Settings settings, ScriptServiceProxy service) {
super(settings);
this.service = service;
}
@Override
public String render(Template template, Map<String, Object> model) {
Map<String, Object> mergedModel = new HashMap<>();
mergedModel.putAll(template.getParams());
mergedModel.putAll(model);
String script = XMustacheScriptEngineService.prepareTemplate(template.getTemplate(), template.getContentType());
ExecutableScript executable = service.executable(new org.elasticsearch.script.Template(script, template.getType(), XMustacheScriptEngineService.NAME , template.getContentType(), mergedModel));
Object result = executable.run();
if (result instanceof BytesReference) {
return ((BytesReference) result).toUtf8();
}
return result.toString();
}
}

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template;
package org.elasticsearch.watcher.support.text;
import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.common.Nullable;
@ -20,18 +20,18 @@ import java.util.Map;
/**
*
*/
public class Template implements ToXContent {
public class TextTemplate implements ToXContent {
private final String template;
private final @Nullable XContentType contentType;
private final @Nullable ScriptType type;
private final @Nullable Map<String, Object> params;
Template(String template) {
TextTemplate(String template) {
this(template, null, null, null);
}
Template(String template, @Nullable XContentType contentType, @Nullable ScriptType type, @Nullable Map<String, Object> params) {
TextTemplate(String template, @Nullable XContentType contentType, @Nullable ScriptType type, @Nullable Map<String, Object> params) {
this.template = template;
this.contentType = contentType;
this.type = type;
@ -59,7 +59,7 @@ public class Template implements ToXContent {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Template template1 = (Template) o;
TextTemplate template1 = (TextTemplate) o;
if (!template.equals(template1.template)) return false;
if (contentType != template1.contentType) return false;
@ -104,10 +104,10 @@ public class Template implements ToXContent {
return builder.endObject();
}
public static Template parse(XContentParser parser) throws IOException {
public static TextTemplate parse(XContentParser parser) throws IOException {
XContentParser.Token token = parser.currentToken();
if (token.isValue()) {
return new Template(String.valueOf(parser.objectText()));
return new TextTemplate(String.valueOf(parser.objectText()));
}
if (token != XContentParser.Token.START_OBJECT) {
throw new ElasticsearchParseException("expected a string value or an object, but found [{}] instead", token);
@ -159,7 +159,7 @@ public class Template implements ToXContent {
throw new ElasticsearchParseException("expected one of [{}], [{}] or [{}] fields, but found none", Field.INLINE.getPreferredName(), Field.FILE.getPreferredName(), Field.ID.getPreferredName());
}
assert type != null : "if template is not null, type should definitely not be null";
return new Template(template, contentType, type, params);
return new TextTemplate(template, contentType, type, params);
}
public static Builder inline(XContentBuilder template) {
@ -198,7 +198,7 @@ public class Template implements ToXContent {
return (B) this;
}
public abstract Template build();
public abstract TextTemplate build();
public static class Inline extends Builder<Inline> {
@ -214,8 +214,8 @@ public class Template implements ToXContent {
}
@Override
public Template build() {
return new Template(template, contentType, type, params);
public TextTemplate build() {
return new TextTemplate(template, contentType, type, params);
}
}
@ -226,8 +226,8 @@ public class Template implements ToXContent {
}
@Override
public Template build() {
return new Template(template, null, type, params);
public TextTemplate build() {
return new TextTemplate(template, null, type, params);
}
}
@ -238,8 +238,8 @@ public class Template implements ToXContent {
}
@Override
public Template build() {
return new Template(template, null, type, params);
public TextTemplate build() {
return new TextTemplate(template, null, type, params);
}
}
@ -250,8 +250,8 @@ public class Template implements ToXContent {
}
@Override
public Template build() {
return new Template(template, null, type, params);
public TextTemplate build() {
return new TextTemplate(template, null, type, params);
}
}
}

View File

@ -3,15 +3,15 @@
* 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.watcher.support.template;
package org.elasticsearch.watcher.support.text;
import java.util.Map;
/**
*
*/
public interface TemplateEngine {
public interface TextTemplateEngine {
String render(Template template, Map<String, Object> model);
String render(TextTemplate template, Map<String, Object> model);
}

View File

@ -3,19 +3,19 @@
* 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.watcher.support.template;
package org.elasticsearch.watcher.support.text;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine;
import org.elasticsearch.watcher.support.text.xmustache.XMustacheTextTemplateEngine;
/**
*
*/
public class TemplateModule extends AbstractModule {
public class TextTemplateModule extends AbstractModule {
@Override
protected void configure() {
bind(XMustacheTemplateEngine.class).asEagerSingleton();
bind(TemplateEngine.class).to(XMustacheTemplateEngine.class);
bind(XMustacheTextTemplateEngine.class).asEagerSingleton();
bind(TextTemplateEngine.class).to(XMustacheTextTemplateEngine.class);
}
}

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template.xmustache;
package org.elasticsearch.watcher.support.text.xmustache;
import com.fasterxml.jackson.core.io.JsonStringEncoder;
import com.github.mustachejava.DefaultMustacheFactory;

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template.xmustache;
package org.elasticsearch.watcher.support.text.xmustache;
import com.github.mustachejava.Mustache;
import org.elasticsearch.common.Nullable;

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template.xmustache;
package org.elasticsearch.watcher.support.text.xmustache;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.component.AbstractComponent;
@ -11,8 +11,8 @@ import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import java.util.HashMap;
import java.util.Map;
@ -20,18 +20,18 @@ import java.util.Map;
/**
*
*/
public class XMustacheTemplateEngine extends AbstractComponent implements TemplateEngine {
public class XMustacheTextTemplateEngine extends AbstractComponent implements TextTemplateEngine {
private final ScriptServiceProxy service;
@Inject
public XMustacheTemplateEngine(Settings settings, ScriptServiceProxy service) {
public XMustacheTextTemplateEngine(Settings settings, ScriptServiceProxy service) {
super(settings);
this.service = service;
}
@Override
public String render(Template template, Map<String, Object> model) {
public String render(TextTemplate template, Map<String, Object> model) {
Map<String, Object> mergedModel = new HashMap<>();
mergedModel.putAll(template.getParams());
mergedModel.putAll(model);

View File

@ -20,8 +20,8 @@ import org.elasticsearch.watcher.actions.email.service.*;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.execution.Wid;
import org.elasticsearch.watcher.support.secret.Secret;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.support.xcontent.WatcherParams;
import org.elasticsearch.watcher.watch.Payload;
import org.joda.time.DateTime;
@ -57,23 +57,23 @@ public class EmailActionTests extends ESTestCase {
return new EmailSent(account, email);
}
};
TemplateEngine engine = mock(TemplateEngine.class);
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
EmailTemplate.Builder emailBuilder = EmailTemplate.builder();
Template subject = null;
TextTemplate subject = null;
if (randomBoolean()) {
subject = Template.inline("_subject").build();
subject = TextTemplate.inline("_subject").build();
emailBuilder.subject(subject);
}
Template textBody = null;
TextTemplate textBody = null;
if (randomBoolean()) {
textBody = Template.inline("_text_body").build();
textBody = TextTemplate.inline("_text_body").build();
emailBuilder.textBody(textBody);
}
Template htmlBody = null;
TextTemplate htmlBody = null;
if (randomBoolean()) {
htmlBody = Template.inline("_html_body").build();
htmlBody = TextTemplate.inline("_html_body").build();
emailBuilder.htmlBody(htmlBody);
}
EmailTemplate email = emailBuilder.build();
@ -145,7 +145,7 @@ public class EmailActionTests extends ESTestCase {
@Test
public void testParser() throws Exception {
TemplateEngine engine = mock(TemplateEngine.class);
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
EmailService emailService = mock(EmailService.class);
Profile profile = randomFrom(Profile.values());
@ -154,9 +154,9 @@ public class EmailActionTests extends ESTestCase {
Email.Address[] cc = rarely() ? null : Email.AddressList.parse(randomBoolean() ? "cc@domain" : "cc1@domain,cc2@domain").toArray();
Email.Address[] bcc = rarely() ? null : Email.AddressList.parse(randomBoolean() ? "bcc@domain" : "bcc1@domain,bcc2@domain").toArray();
Email.Address[] replyTo = rarely() ? null : Email.AddressList.parse(randomBoolean() ? "reply@domain" : "reply1@domain,reply2@domain").toArray();
Template subject = randomBoolean() ? Template.inline("_subject").build() : null;
Template textBody = randomBoolean() ? Template.inline("_text_body").build() : null;
Template htmlBody = randomBoolean() ? Template.inline("_text_html").build() : null;
TextTemplate subject = randomBoolean() ? TextTemplate.inline("_subject").build() : null;
TextTemplate textBody = randomBoolean() ? TextTemplate.inline("_text_body").build() : null;
TextTemplate htmlBody = randomBoolean() ? TextTemplate.inline("_text_html").build() : null;
DataAttachment dataAttachment = randomDataAttachment();
XContentBuilder builder = jsonBuilder().startObject()
.field("account", "_account")
@ -259,7 +259,7 @@ public class EmailActionTests extends ESTestCase {
assertThat(executable.action().getAuth(), notNullValue());
assertThat(executable.action().getAuth().user(), is("_user"));
assertThat(executable.action().getAuth().password(), is(new Secret("_passwd".toCharArray())));
assertThat(executable.action().getEmail().priority(), is(Template.defaultType(priority.name()).build()));
assertThat(executable.action().getEmail().priority(), is(TextTemplate.defaultType(priority.name()).build()));
if (to != null) {
assertThat(executable.action().getEmail().to(), arrayContainingInAnyOrder(addressesToTemplates(to)));
} else {
@ -282,10 +282,10 @@ public class EmailActionTests extends ESTestCase {
}
}
private static Template[] addressesToTemplates(Email.Address[] addresses) {
Template[] templates = new Template[addresses.length];
private static TextTemplate[] addressesToTemplates(Email.Address[] addresses) {
TextTemplate[] templates = new TextTemplate[addresses.length];
for (int i = 0; i < templates.length; i++) {
templates[i] = Template.defaultType(addresses[i].toString()).build();
templates[i] = TextTemplate.defaultType(addresses[i].toString()).build();
}
return templates;
}
@ -293,7 +293,7 @@ public class EmailActionTests extends ESTestCase {
@Test
public void testParser_SelfGenerated() throws Exception {
EmailService service = mock(EmailService.class);
TemplateEngine engine = mock(TemplateEngine.class);
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
EmailTemplate.Builder emailTemplate = EmailTemplate.builder();
if (randomBoolean()) {
@ -362,7 +362,7 @@ public class EmailActionTests extends ESTestCase {
@Test(expected = ElasticsearchParseException.class)
public void testParser_Invalid() throws Exception {
EmailService emailService = mock(EmailService.class);
TemplateEngine engine = mock(TemplateEngine.class);
TextTemplateEngine engine = mock(TextTemplateEngine.class);
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
XContentBuilder builder = jsonBuilder().startObject().field("unknown_field", "value");
XContentParser parser = JsonXContent.jsonXContent.createParser(builder.bytes());

View File

@ -11,8 +11,8 @@ import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.common.xcontent.json.JsonXContent;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.junit.Test;
import java.util.ArrayList;
@ -31,25 +31,25 @@ public class EmailTemplateTests extends ESTestCase {
@Test
public void testEmailTemplate_Parser_SelfGenerated() throws Exception {
Template from = randomFrom(Template.inline("from@from.com").build(), null);
List<Template> addresses = new ArrayList<>();
TextTemplate from = randomFrom(TextTemplate.inline("from@from.com").build(), null);
List<TextTemplate> addresses = new ArrayList<>();
for( int i = 0; i < randomIntBetween(1, 5); ++i){
addresses.add(Template.inline("address" + i + "@test.com").build());
addresses.add(TextTemplate.inline("address" + i + "@test.com").build());
}
Template[] possibleList = addresses.toArray(new Template[addresses.size()]);
Template[] replyTo = randomFrom(possibleList, null);
Template[] to = randomFrom(possibleList, null);
Template[] cc = randomFrom(possibleList, null);
Template[] bcc = randomFrom(possibleList, null);
Template priority = Template.inline(randomFrom(Email.Priority.values()).name()).build();
TextTemplate[] possibleList = addresses.toArray(new TextTemplate[addresses.size()]);
TextTemplate[] replyTo = randomFrom(possibleList, null);
TextTemplate[] to = randomFrom(possibleList, null);
TextTemplate[] cc = randomFrom(possibleList, null);
TextTemplate[] bcc = randomFrom(possibleList, null);
TextTemplate priority = TextTemplate.inline(randomFrom(Email.Priority.values()).name()).build();
Template subjectTemplate = Template.inline("Templated Subject {{foo}}").build();
TextTemplate subjectTemplate = TextTemplate.inline("Templated Subject {{foo}}").build();
String subject = "Templated Subject bar";
Template textBodyTemplate = Template.inline("Templated Body {{foo}}").build();
TextTemplate textBodyTemplate = TextTemplate.inline("Templated Body {{foo}}").build();
String textBody = "Templated Body bar";
Template htmlBodyTemplate = Template.inline("Templated Html Body <script>nefarious scripting</script>").build();
TextTemplate htmlBodyTemplate = TextTemplate.inline("Templated Html Body <script>nefarious scripting</script>").build();
String htmlBody = "Templated Html Body <script>nefarious scripting</script>";
String sanitizedHtmlBody = "Templated Html Body";
@ -79,11 +79,11 @@ public class EmailTemplateTests extends ESTestCase {
HtmlSanitizer htmlSanitizer = mock(HtmlSanitizer.class);
when(htmlSanitizer.sanitize(htmlBody)).thenReturn(sanitizedHtmlBody);
TemplateEngine templateEngine = mock(TemplateEngine.class);
TextTemplateEngine templateEngine = mock(TextTemplateEngine.class);
when(templateEngine.render(subjectTemplate, model)).thenReturn(subject);
when(templateEngine.render(textBodyTemplate, model)).thenReturn(textBody);
when(templateEngine.render(htmlBodyTemplate, model)).thenReturn(htmlBody);
for (Template possibleAddress : possibleList) {
for (TextTemplate possibleAddress : possibleList) {
when(templateEngine.render(possibleAddress, model)).thenReturn(possibleAddress.getTemplate());
}
if (from != null) {

View File

@ -16,8 +16,8 @@ import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatAccount;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatMessage;
import org.elasticsearch.watcher.actions.hipchat.service.HipChatService;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.junit.Before;
import org.junit.Test;
@ -38,7 +38,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
@Before
public void init() throws Exception {
hipchatService = mock(HipChatService.class);
factory = new HipChatActionFactory(Settings.EMPTY, mock(TemplateEngine.class), hipchatService);
factory = new HipChatActionFactory(Settings.EMPTY, mock(TextTemplateEngine.class), hipchatService);
}
@Test
@ -79,21 +79,21 @@ public class HipChatActionFactoryTests extends ESTestCase {
builder.field("account", accountName);
builder.startObject("message");
Template body = Template.inline("_body").build();
TextTemplate body = TextTemplate.inline("_body").build();
builder.field("body", body);
Template[] rooms = null;
TextTemplate[] rooms = null;
if (randomBoolean()) {
Template r1 = Template.inline("_r1").build();
Template r2 = Template.inline("_r2").build();
rooms = new Template[] { r1, r2 };
TextTemplate r1 = TextTemplate.inline("_r1").build();
TextTemplate r2 = TextTemplate.inline("_r2").build();
rooms = new TextTemplate[] { r1, r2 };
builder.array("room", r1, r2);
}
Template[] users = null;
TextTemplate[] users = null;
if (randomBoolean()) {
Template u1 = Template.inline("_u1").build();
Template u2 = Template.inline("_u2").build();
users = new Template[] { u1, u2 };
TextTemplate u1 = TextTemplate.inline("_u1").build();
TextTemplate u2 = TextTemplate.inline("_u2").build();
users = new TextTemplate[] { u1, u2 };
builder.array("user", u1, u2);
}
String from = null;
@ -106,9 +106,9 @@ public class HipChatActionFactoryTests extends ESTestCase {
format = randomFrom(HipChatMessage.Format.values());
builder.field("format", format.value());
}
Template color = null;
TextTemplate color = null;
if (randomBoolean()) {
color = Template.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
builder.field("color", color);
}
Boolean notify = null;
@ -138,7 +138,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
public void testParser_SelfGenerated() throws Exception {
String accountName = randomAsciiOfLength(10);
Template body = Template.inline("_body").build();
TextTemplate body = TextTemplate.inline("_body").build();
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
XContentBuilder builder = jsonBuilder().startObject();
@ -147,14 +147,14 @@ public class HipChatActionFactoryTests extends ESTestCase {
builder.field("body", body);
if (randomBoolean()) {
Template r1 = Template.inline("_r1").build();
Template r2 = Template.inline("_r2").build();
TextTemplate r1 = TextTemplate.inline("_r1").build();
TextTemplate r2 = TextTemplate.inline("_r2").build();
templateBuilder.addRooms(r1, r2);
builder.array("room", r1, r2);
}
if (randomBoolean()) {
Template u1 = Template.inline("_u1").build();
Template u2 = Template.inline("_u2").build();
TextTemplate u1 = TextTemplate.inline("_u1").build();
TextTemplate u2 = TextTemplate.inline("_u2").build();
templateBuilder.addUsers(u1, u2);
builder.array("user", u1, u2);
}
@ -169,7 +169,7 @@ public class HipChatActionFactoryTests extends ESTestCase {
builder.field("format", format.value());
}
if (randomBoolean()) {
Template color = Template.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
TextTemplate color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
templateBuilder.setColor(color);
builder.field("color", color);
}

View File

@ -23,8 +23,8 @@ import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.execution.Wid;
import org.elasticsearch.watcher.support.http.HttpRequest;
import org.elasticsearch.watcher.support.http.HttpResponse;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.watch.Payload;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
@ -58,9 +58,9 @@ public class HipChatActionTests extends ESTestCase {
public void testExecute() throws Exception {
final String accountName = "account1";
TemplateEngine templateEngine = mock(TemplateEngine.class);
TextTemplateEngine templateEngine = mock(TextTemplateEngine.class);
Template body = Template.inline("_body").build();
TextTemplate body = TextTemplate.inline("_body").build();
HipChatMessage.Template.Builder messageBuilder = new HipChatMessage.Template.Builder(body);
HipChatMessage.Template messageTemplate = messageBuilder.build();
@ -132,21 +132,21 @@ public class HipChatActionTests extends ESTestCase {
builder.field("account", accountName);
builder.startObject("message");
Template body = Template.inline("_body").build();
TextTemplate body = TextTemplate.inline("_body").build();
builder.field("body", body);
Template[] rooms = null;
TextTemplate[] rooms = null;
if (randomBoolean()) {
Template r1 = Template.inline("_r1").build();
Template r2 = Template.inline("_r2").build();
rooms = new Template[] { r1, r2 };
TextTemplate r1 = TextTemplate.inline("_r1").build();
TextTemplate r2 = TextTemplate.inline("_r2").build();
rooms = new TextTemplate[] { r1, r2 };
builder.array("room", r1, r2);
}
Template[] users = null;
TextTemplate[] users = null;
if (randomBoolean()) {
Template u1 = Template.inline("_u1").build();
Template u2 = Template.inline("_u2").build();
users = new Template[] { u1, u2 };
TextTemplate u1 = TextTemplate.inline("_u1").build();
TextTemplate u2 = TextTemplate.inline("_u2").build();
users = new TextTemplate[] { u1, u2 };
builder.array("user", u1, u2);
}
String from = null;
@ -159,9 +159,9 @@ public class HipChatActionTests extends ESTestCase {
format = randomFrom(HipChatMessage.Format.values());
builder.field("format", format.value());
}
Template color = null;
TextTemplate color = null;
if (randomBoolean()) {
color = Template.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
builder.field("color", color);
}
Boolean notify = null;
@ -191,7 +191,7 @@ public class HipChatActionTests extends ESTestCase {
public void testParser_SelfGenerated() throws Exception {
String accountName = randomAsciiOfLength(10);
Template body = Template.inline("_body").build();
TextTemplate body = TextTemplate.inline("_body").build();
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
XContentBuilder builder = jsonBuilder().startObject();
@ -200,14 +200,14 @@ public class HipChatActionTests extends ESTestCase {
builder.field("body", body);
if (randomBoolean()) {
Template r1 = Template.inline("_r1").build();
Template r2 = Template.inline("_r2").build();
TextTemplate r1 = TextTemplate.inline("_r1").build();
TextTemplate r2 = TextTemplate.inline("_r2").build();
templateBuilder.addRooms(r1, r2);
builder.array("room", r1, r2);
}
if (randomBoolean()) {
Template u1 = Template.inline("_u1").build();
Template u2 = Template.inline("_u2").build();
TextTemplate u1 = TextTemplate.inline("_u1").build();
TextTemplate u2 = TextTemplate.inline("_u2").build();
templateBuilder.addUsers(u1, u2);
builder.array("user", u1, u2);
}
@ -222,7 +222,7 @@ public class HipChatActionTests extends ESTestCase {
builder.field("format", format.value());
}
if (randomBoolean()) {
Template color = Template.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
TextTemplate color = TextTemplate.inline(randomFrom(HipChatMessage.Color.values()).value()).build();
templateBuilder.setColor(color);
builder.field("color", color);
}

View File

@ -11,7 +11,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.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.WatcherXContentUtils;
import org.junit.Test;
@ -166,24 +166,24 @@ public class HipChatMessageTests extends ESTestCase {
XContentBuilder jsonBuilder = jsonBuilder();
jsonBuilder.startObject();
Template body = Template.inline(randomAsciiOfLength(200)).build();
TextTemplate body = TextTemplate.inline(randomAsciiOfLength(200)).build();
jsonBuilder.field("body", body, ToXContent.EMPTY_PARAMS);
Template[] rooms = null;
TextTemplate[] rooms = null;
if (randomBoolean()) {
jsonBuilder.startArray("room");
rooms = new Template[randomIntBetween(1, 3)];
rooms = new TextTemplate[randomIntBetween(1, 3)];
for (int i = 0; i < rooms.length; i++) {
rooms[i] = Template.inline(randomAsciiOfLength(10)).build();
rooms[i] = TextTemplate.inline(randomAsciiOfLength(10)).build();
rooms[i].toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
}
jsonBuilder.endArray();
}
Template[] users = null;
TextTemplate[] users = null;
if (randomBoolean()) {
jsonBuilder.startArray("user");
users = new Template[randomIntBetween(1, 3)];
users = new TextTemplate[randomIntBetween(1, 3)];
for (int i = 0; i < users.length; i++) {
users[i] = Template.inline(randomAsciiOfLength(10)).build();
users[i] = TextTemplate.inline(randomAsciiOfLength(10)).build();
users[i].toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
}
jsonBuilder.endArray();
@ -193,9 +193,9 @@ public class HipChatMessageTests extends ESTestCase {
from = randomAsciiOfLength(10);
jsonBuilder.field("from", from);
}
Template color = null;
TextTemplate color = null;
if (randomBoolean()) {
color = Template.inline(randomAsciiOfLength(10)).build();
color = TextTemplate.inline(randomAsciiOfLength(10)).build();
jsonBuilder.field("color", color, ToXContent.EMPTY_PARAMS);
}
HipChatMessage.Format format = null;
@ -235,26 +235,26 @@ public class HipChatMessageTests extends ESTestCase {
@Test
public void testTemplate_ParseSelfGenerated() throws Exception {
Template body = Template.inline(randomAsciiOfLength(10)).build();
TextTemplate body = TextTemplate.inline(randomAsciiOfLength(10)).build();
HipChatMessage.Template.Builder templateBuilder = new HipChatMessage.Template.Builder(body);
if (randomBoolean()) {
int count = randomIntBetween(1, 3);
for (int i = 0; i < count; i++) {
templateBuilder.addRooms(Template.inline(randomAsciiOfLength(10)).build());
templateBuilder.addRooms(TextTemplate.inline(randomAsciiOfLength(10)).build());
}
}
if (randomBoolean()) {
int count = randomIntBetween(1, 3);
for (int i = 0; i < count; i++) {
templateBuilder.addUsers(Template.inline(randomAsciiOfLength(10)).build());
templateBuilder.addUsers(TextTemplate.inline(randomAsciiOfLength(10)).build());
}
}
if (randomBoolean()) {
templateBuilder.setFrom(randomAsciiOfLength(10));
}
if (randomBoolean()) {
templateBuilder.setColor(Template.inline(randomAsciiOfLength(5)).build());
templateBuilder.setColor(TextTemplate.inline(randomAsciiOfLength(5)).build());
}
if (randomBoolean()) {
templateBuilder.setFormat(randomFrom(HipChatMessage.Format.values()));

View File

@ -16,8 +16,8 @@ import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.actions.Action;
import org.elasticsearch.watcher.actions.email.service.Attachment;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.test.WatcherTestUtils;
import org.elasticsearch.watcher.watch.Payload;
import org.joda.time.DateTime;
@ -43,13 +43,13 @@ public class LoggingActionTests extends ESTestCase {
private ESLogger actionLogger;
private LoggingLevel level;
private TemplateEngine engine;
private TextTemplateEngine engine;
@Before
public void init() throws IOException {
actionLogger = mock(ESLogger.class);
level = randomFrom(LoggingLevel.values());
engine = mock(TemplateEngine.class);
engine = mock(TextTemplateEngine.class);
}
@Test
@ -76,7 +76,7 @@ public class LoggingActionTests extends ESTestCase {
.build();
String text = randomAsciiOfLength(10);
Template template = Template.inline(text).build();
TextTemplate template = TextTemplate.inline(text).build();
LoggingAction action = new LoggingAction(template, level, "_category");
ExecutableLoggingAction executable = new ExecutableLoggingAction(action, logger, actionLogger, engine);
when(engine.render(template, expectedModel)).thenReturn(text);
@ -98,7 +98,7 @@ public class LoggingActionTests extends ESTestCase {
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
String text = randomAsciiOfLength(10);
Template template = Template.inline(text).build();
TextTemplate template = TextTemplate.inline(text).build();
XContentBuilder builder = jsonBuilder().startObject();
builder.field("text", template);
@ -133,7 +133,7 @@ public class LoggingActionTests extends ESTestCase {
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
String text = randomAsciiOfLength(10);
Template template = Template.inline(text).build();
TextTemplate template = TextTemplate.inline(text).build();
String category = randomAsciiOfLength(10);
LoggingAction action = new LoggingAction(template, level, category);
ExecutableLoggingAction executable = new ExecutableLoggingAction(action, logger, settings, engine);
@ -154,7 +154,7 @@ public class LoggingActionTests extends ESTestCase {
LoggingActionFactory parser = new LoggingActionFactory(settings, engine);
String text = randomAsciiOfLength(10);
Template template = Template.inline(text).build();
TextTemplate template = TextTemplate.inline(text).build();
LoggingAction.Builder actionBuilder = loggingAction(template);
if (randomBoolean()) {
actionBuilder.setCategory(randomAsciiOfLength(10));

View File

@ -21,7 +21,7 @@ import org.elasticsearch.watcher.execution.ManualExecutionContext;
import org.elasticsearch.watcher.history.WatchRecord;
import org.elasticsearch.watcher.support.clock.SystemClock;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.ObjectPath;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.elasticsearch.watcher.transport.actions.execute.ExecuteWatchResponse;
@ -394,7 +394,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTests {
LOGGING {
@Override
public Action.Builder action() throws Exception {
Template.Builder templateBuilder = new Template.Builder.Inline("{{ctx.watch_id}}");
TextTemplate.Builder templateBuilder = new TextTemplate.Builder.Inline("{{ctx.watch_id}}");
return LoggingAction.builder(templateBuilder.build());
}

View File

@ -26,9 +26,9 @@ import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.secret.SecretService;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.support.text.xmustache.XMustacheTextTemplateEngine;
import org.elasticsearch.watcher.test.WatcherTestUtils;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent;
import org.elasticsearch.watcher.watch.Payload;
@ -64,10 +64,10 @@ public class WebhookActionTests extends ESTestCase {
private ThreadPool tp = null;
private ScriptServiceProxy scriptService;
private TemplateEngine templateEngine;
private TextTemplateEngine templateEngine;
private HttpAuthRegistry authRegistry;
private Template testBody;
private Template testPath;
private TextTemplate testBody;
private TextTemplate testPath;
static final String TEST_BODY_STRING = "ERROR HAPPENED";
static final String TEST_PATH_STRING = "/testPath";
@ -78,10 +78,10 @@ public class WebhookActionTests extends ESTestCase {
tp = new ThreadPool(ThreadPool.Names.SAME);
Settings settings = Settings.EMPTY;
scriptService = WatcherTestUtils.getScriptServiceProxy(tp);
templateEngine = new XMustacheTemplateEngine(settings, scriptService);
templateEngine = new XMustacheTextTemplateEngine(settings, scriptService);
SecretService secretService = mock(SecretService.class);
testBody = Template.inline(TEST_BODY_STRING).build();
testPath = Template.inline(TEST_PATH_STRING).build();
testBody = TextTemplate.inline(TEST_BODY_STRING).build();
testPath = TextTemplate.inline(TEST_PATH_STRING).build();
authRegistry = new HttpAuthRegistry(ImmutableMap.of("basic", (HttpAuthFactory) new BasicAuthFactory(secretService)));
}
@ -108,7 +108,7 @@ public class WebhookActionTests extends ESTestCase {
scenario.assertResult(httpClient, actionResult);
}
private HttpRequestTemplate getHttpRequestTemplate(HttpMethod method, String host, int port, Template path, Template body, Map<String, Template> params) {
private HttpRequestTemplate getHttpRequestTemplate(HttpMethod method, String host, int port, TextTemplate path, TextTemplate body, Map<String, TextTemplate> params) {
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder(host, port);
if (path != null) {
builder.path(path);
@ -127,8 +127,8 @@ public class WebhookActionTests extends ESTestCase {
@Test
public void testParser() throws Exception {
Template body = randomBoolean() ? Template.inline("_subject").build() : null;
Template path = Template.inline("_url").build();
TextTemplate body = randomBoolean() ? TextTemplate.inline("_subject").build() : null;
TextTemplate path = TextTemplate.inline("_url").build();
String host = "test.host";
HttpMethod method = randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT, HttpMethod.DELETE, HttpMethod.HEAD, null);
HttpRequestTemplate request = getHttpRequestTemplate(method, host, TEST_PORT, path, body, null);
@ -148,8 +148,8 @@ public class WebhookActionTests extends ESTestCase {
@Test
public void testParser_SelfGenerated() throws Exception {
Template body = randomBoolean() ? Template.inline("_body").build() : null;
Template path = Template.inline("_url").build();
TextTemplate body = randomBoolean() ? TextTemplate.inline("_body").build() : null;
TextTemplate path = TextTemplate.inline("_url").build();
String host = "test.host";
String watchId = "_watch";
String actionId = randomAsciiOfLength(5);
@ -175,8 +175,8 @@ public class WebhookActionTests extends ESTestCase {
@Test
public void testParser_Builder() throws Exception {
Template body = randomBoolean() ? Template.inline("_body").build() : null;
Template path = Template.inline("_url").build();
TextTemplate body = randomBoolean() ? TextTemplate.inline("_body").build() : null;
TextTemplate path = TextTemplate.inline("_url").build();
String host = "test.host";
String watchId = "_watch";
@ -230,11 +230,11 @@ public class WebhookActionTests extends ESTestCase {
String host = "testhost";
String path = randomFrom("{{ctx.execution_time}}", "{{ctx.trigger.scheduled_time}}", "{{ctx.trigger.triggered_time}}");
Map<String, Template> params = new HashMap<>();
params.put("foo", Template.inline(randomFrom("{{ctx.execution_time}}", "{{ctx.trigger.scheduled_time}}", "{{ctx.trigger.triggered_time}}")).build());
Map<String, TextTemplate> params = new HashMap<>();
params.put("foo", TextTemplate.inline(randomFrom("{{ctx.execution_time}}", "{{ctx.trigger.scheduled_time}}", "{{ctx.trigger.triggered_time}}")).build());
HttpMethod method = randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT);
HttpRequestTemplate request = getHttpRequestTemplate(method, host, TEST_PORT, Template.inline(path).build(), Template.inline(body).build(), params);
HttpRequestTemplate request = getHttpRequestTemplate(method, host, TEST_PORT, TextTemplate.inline(path).build(), TextTemplate.inline(body).build(), params);
String watchId = "_watch";
String actionId = randomAsciiOfLength(5);
@ -261,7 +261,7 @@ public class WebhookActionTests extends ESTestCase {
HttpClient httpClient = ExecuteScenario.Success.client();
HttpMethod method = HttpMethod.POST;
Template path = Template.defaultType("/test_{{ctx.watch_id}}").build();
TextTemplate path = TextTemplate.defaultType("/test_{{ctx.watch_id}}").build();
String host = "test.host";
HttpRequestTemplate requestTemplate = getHttpRequestTemplate(method, host, TEST_PORT, path, testBody, null);
WebhookAction action = new WebhookAction(requestTemplate);

View File

@ -21,7 +21,7 @@ import org.elasticsearch.watcher.support.http.HttpClient;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.http.Scheme;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.XContentSource;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.junit.After;
@ -86,8 +86,8 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
.scheme(Scheme.HTTPS)
.path(Template.inline("/test/{{ctx.watch_id}}").build())
.body(Template.inline("{{ctx.payload}}").build());
.path(TextTemplate.inline("/test/{{ctx.watch_id}}").build())
.body(TextTemplate.inline("{{ctx.payload}}").build());
watcherClient().preparePutWatch("_id")
.setSource(watchBuilder()
@ -130,8 +130,8 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
.scheme(Scheme.HTTPS)
.auth(new BasicAuth("_username", "_password".toCharArray()))
.path(Template.inline("/test/{{ctx.watch_id}}").build())
.body(Template.inline("{{ctx.payload}}").build());
.path(TextTemplate.inline("/test/{{ctx.watch_id}}").build())
.body(TextTemplate.inline("{{ctx.payload}}").build());
watcherClient().preparePutWatch("_id")
.setSource(watchBuilder()

View File

@ -19,7 +19,7 @@ import org.elasticsearch.watcher.actions.ActionBuilders;
import org.elasticsearch.watcher.history.WatchRecord;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.XContentSource;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.junit.After;
@ -70,10 +70,10 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTests {
public void testWebhook() throws Exception {
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
.path(Template.inline("/test/{{ctx.watch_id}}"))
.putParam("param1", Template.inline("value1"))
.putParam("watch_id", Template.inline("{{ctx.watch_id}}"))
.body(Template.inline("{{ctx.payload}}"));
.path(TextTemplate.inline("/test/{{ctx.watch_id}}"))
.putParam("param1", TextTemplate.inline("value1"))
.putParam("watch_id", TextTemplate.inline("{{ctx.watch_id}}"))
.body(TextTemplate.inline("{{ctx.payload}}"));
watcherClient().preparePutWatch("_id")
.setSource(watchBuilder()
@ -115,10 +115,10 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTests {
webServer.enqueue(new MockResponse().setResponseCode(200).setBody("body"));
HttpRequestTemplate.Builder builder = HttpRequestTemplate.builder("localhost", webPort)
.auth(new BasicAuth("_username", "_password".toCharArray()))
.path(Template.inline("/test/{{ctx.watch_id}}").build())
.putParam("param1", Template.inline("value1").build())
.putParam("watch_id", Template.inline("{{ctx.watch_id}}").build())
.body(Template.inline("{{ctx.payload}}").build());
.path(TextTemplate.inline("/test/{{ctx.watch_id}}").build())
.putParam("param1", TextTemplate.inline("value1").build())
.putParam("watch_id", TextTemplate.inline("{{ctx.watch_id}}").build())
.body(TextTemplate.inline("{{ctx.payload}}").build());
watcherClient().preparePutWatch("_id")
.setSource(watchBuilder()

View File

@ -15,7 +15,7 @@ import org.elasticsearch.watcher.client.WatcherClient;
import org.elasticsearch.watcher.history.HistoryStore;
import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.XContentSource;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.elasticsearch.watcher.transport.actions.put.PutWatchResponse;
@ -107,7 +107,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTests {
.field("query").value(termQuery("field", "value"))
.endObject();
HttpRequestTemplate.Builder requestBuilder = HttpRequestTemplate.builder(address.getHostString(), address.getPort())
.path(Template.inline("/idx/_search"))
.path(TextTemplate.inline("/idx/_search"))
.body(body);
if (shieldEnabled()) {
requestBuilder.auth(new BasicAuth("test", "changeme".toCharArray()));

View File

@ -33,8 +33,8 @@ import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.watcher.support.secret.SecretService;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent;
@ -63,12 +63,12 @@ public class HttpInputTests extends ESTestCase {
private HttpClient httpClient;
private HttpInputFactory httpParser;
private SecretService secretService;
private TemplateEngine templateEngine;
private TextTemplateEngine templateEngine;
@Before
public void init() throws Exception {
httpClient = mock(HttpClient.class);
templateEngine = mock(TemplateEngine.class);
templateEngine = mock(TextTemplateEngine.class);
secretService = mock(SecretService.class);
HttpAuthRegistry registry = new HttpAuthRegistry(ImmutableMap.<String, HttpAuthFactory>of("basic", new BasicAuthFactory(secretService)));
httpParser = new HttpInputFactory(Settings.EMPTY, httpClient, templateEngine, new HttpRequest.Parser(registry), new HttpRequestTemplate.Parser(registry));
@ -115,7 +115,7 @@ public class HttpInputTests extends ESTestCase {
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
when(templateEngine.render(eq(Template.inline("_body").build()), any(Map.class))).thenReturn("_body");
when(templateEngine.render(eq(TextTemplate.inline("_body").build()), any(Map.class))).thenReturn("_body");
Watch watch = new Watch("test-watch",
new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))),
@ -147,7 +147,7 @@ public class HttpInputTests extends ESTestCase {
String notJson = "This is not json";
HttpResponse response = new HttpResponse(123, notJson.getBytes(StandardCharsets.UTF_8));
when(httpClient.execute(any(HttpRequest.class))).thenReturn(response);
when(templateEngine.render(eq(Template.inline("_body").build()), any(Map.class))).thenReturn("_body");
when(templateEngine.render(eq(TextTemplate.inline("_body").build()), any(Map.class))).thenReturn("_body");
Watch watch = new Watch("test-watch",
new ScheduleTrigger(new IntervalSchedule(new IntervalSchedule.Interval(1, IntervalSchedule.Interval.Unit.MINUTES))),
new ExecutableSimpleInput(new SimpleInput(new Payload.Simple()), logger),
@ -174,16 +174,16 @@ public class HttpInputTests extends ESTestCase {
String host = randomAsciiOfLength(3);
int port = randomIntBetween(8000, 9000);
String path = randomAsciiOfLength(3);
Template pathTemplate = Template.inline(path).build();
TextTemplate pathTemplate = TextTemplate.inline(path).build();
String body = randomBoolean() ? randomAsciiOfLength(3) : null;
Map<String, Template> params = randomBoolean() ? new MapBuilder<String, Template>().put("a", Template.inline("b").build()).map() : null;
Map<String, Template> headers = randomBoolean() ? new MapBuilder<String, Template>().put("c", Template.inline("d").build()).map() : null;
Map<String, TextTemplate> params = randomBoolean() ? new MapBuilder<String, TextTemplate>().put("a", TextTemplate.inline("b").build()).map() : null;
Map<String, TextTemplate> headers = randomBoolean() ? new MapBuilder<String, TextTemplate>().put("c", TextTemplate.inline("d").build()).map() : null;
HttpAuth auth = randomBoolean() ? new BasicAuth("username", "password".toCharArray()) : null;
HttpRequestTemplate.Builder requestBuilder = HttpRequestTemplate.builder(host, port)
.scheme(scheme)
.method(httpMethod)
.path(pathTemplate)
.body(body != null ? Template.inline(body).build() : null)
.body(body != null ? TextTemplate.inline(body).build() : null)
.auth(auth);
if (params != null) {
@ -213,7 +213,7 @@ public class HttpInputTests extends ESTestCase {
assertThat(result.getRequest().method(), equalTo(httpMethod != null ? httpMethod : HttpMethod.GET)); // get is the default
assertThat(result.getRequest().host(), equalTo(host));
assertThat(result.getRequest().port(), equalTo(port));
assertThat(result.getRequest().path(), is(Template.inline(path).build()));
assertThat(result.getRequest().path(), is(TextTemplate.inline(path).build()));
assertThat(result.getExpectedResponseXContentType(), equalTo(expectedResponseXContentType));
if (expectedResponseXContentType != HttpContentType.TEXT && extractKeys != null) {
for (String key : extractKeys) {
@ -221,14 +221,14 @@ public class HttpInputTests extends ESTestCase {
}
}
if (params != null) {
assertThat(result.getRequest().params(), hasEntry(is("a"), is(Template.inline("b").build())));
assertThat(result.getRequest().params(), hasEntry(is("a"), is(TextTemplate.inline("b").build())));
}
if (headers != null) {
assertThat(result.getRequest().headers(), hasEntry(is("c"), is(Template.inline("d").build())));
assertThat(result.getRequest().headers(), hasEntry(is("c"), is(TextTemplate.inline("d").build())));
}
assertThat(result.getRequest().auth(), equalTo(auth));
if (body != null) {
assertThat(result.getRequest().body(), is(Template.inline(body).build()));
assertThat(result.getRequest().body(), is(TextTemplate.inline(body).build()));
} else {
assertThat(result.getRequest().body(), nullValue());
}

View File

@ -31,7 +31,7 @@ import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput;
import org.elasticsearch.watcher.input.simple.SimpleInput;
import org.elasticsearch.watcher.support.DynamicIndexName;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTrigger;
import org.elasticsearch.watcher.trigger.schedule.ScheduleTriggerEvent;
@ -150,7 +150,7 @@ public class SearchInputTests extends ESIntegTestCase {
params.put("seconds_param", "30s");
BytesReference templateSource = jsonBuilder()
.value(Template.inline(TEMPLATE_QUERY).params(params).build())
.value(TextTemplate.inline(TEMPLATE_QUERY).params(params).build())
.bytes();
SearchRequest request = client()
.prepareSearch()
@ -174,7 +174,7 @@ public class SearchInputTests extends ESIntegTestCase {
params.put("seconds_param", "30s");
BytesReference templateSource = jsonBuilder()
.value(Template.indexed("test-template").params(params).build())
.value(TextTemplate.indexed("test-template").params(params).build())
.bytes();
SearchRequest request = client()
.prepareSearch()
@ -195,7 +195,7 @@ public class SearchInputTests extends ESIntegTestCase {
params.put("seconds_param", "30s");
BytesReference templateSource = jsonBuilder()
.value(Template.file("test_disk_template").params(params).build())
.value(TextTemplate.file("test_disk_template").params(params).build())
.bytes();
SearchRequest request = client()
.prepareSearch()

View File

@ -20,7 +20,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.input.search.ExecutableSearchInput;
import org.elasticsearch.watcher.support.clock.SystemClock;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.joda.time.DateTime;
import org.junit.Test;
@ -118,10 +118,10 @@ public class WatcherUtilsTests extends ESTestCase {
}
}
String text = randomAsciiOfLengthBetween(1, 5);
Template template = randomFrom(
Template.inline(text).params(params).build(),
Template.file(text).params(params).build(),
Template.indexed(text).params(params).build()
TextTemplate template = randomFrom(
TextTemplate.inline(text).params(params).build(),
TextTemplate.file(text).params(params).build(),
TextTemplate.indexed(text).params(params).build()
);
expectedRequest.templateSource(jsonBuilder().startObject().field("template", template).endObject().string());
}
@ -203,10 +203,10 @@ public class WatcherUtilsTests extends ESTestCase {
}
}
String text = randomAsciiOfLengthBetween(1, 5);
Template template = randomFrom(
Template.inline(text).params(params).build(),
Template.file(text).params(params).build(),
Template.indexed(text).params(params).build()
TextTemplate template = randomFrom(
TextTemplate.inline(text).params(params).build(),
TextTemplate.file(text).params(params).build(),
TextTemplate.indexed(text).params(params).build()
);
builder.field("template", template);
templateSource = jsonBuilder().value(template).bytes();

View File

@ -18,8 +18,8 @@ import org.elasticsearch.watcher.support.http.auth.HttpAuthRegistry;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuth;
import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.watcher.support.secret.SecretService;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.jboss.netty.handler.codec.http.HttpHeaders;
import org.junit.Test;
@ -39,7 +39,7 @@ public class HttpRequestTemplateTests extends ESTestCase {
HttpRequestTemplate template = HttpRequestTemplate.builder("_host", 1234)
.body(XContentBuilder.builder(type.xContent()).startObject().endObject())
.build();
HttpRequest request = template.render(new MockTemplateEngine(), ImmutableMap.<String, Object>of());
HttpRequest request = template.render(new MockTextTemplateEngine(), ImmutableMap.<String, Object>of());
assertThat(request.headers, hasEntry(HttpHeaders.Names.CONTENT_TYPE, type.restContentType()));
}
@ -48,7 +48,7 @@ public class HttpRequestTemplateTests extends ESTestCase {
HttpRequestTemplate template = HttpRequestTemplate.builder("_host", 1234)
.body("_body")
.build();
HttpRequest request = template.render(new MockTemplateEngine(), ImmutableMap.<String, Object>of());
HttpRequest request = template.render(new MockTextTemplateEngine(), ImmutableMap.<String, Object>of());
assertThat(request.headers.size(), is(0));
}
@ -74,10 +74,10 @@ public class HttpRequestTemplateTests extends ESTestCase {
builder.auth(new BasicAuth("_username", "_password".toCharArray()));
}
if (randomBoolean()) {
builder.putParam("_key", Template.inline("_value"));
builder.putParam("_key", TextTemplate.inline("_value"));
}
if (randomBoolean()) {
builder.putHeader("_key", Template.inline("_value"));
builder.putHeader("_key", TextTemplate.inline("_value"));
}
long connectionTimeout = randomBoolean() ? 0 : randomIntBetween(5, 10);
if (connectionTimeout > 0) {
@ -101,9 +101,9 @@ public class HttpRequestTemplateTests extends ESTestCase {
assertThat(parsed, equalTo(template));
}
static class MockTemplateEngine implements TemplateEngine {
static class MockTextTemplateEngine implements TextTemplateEngine {
@Override
public String render(Template template, Map<String, Object> model) {
public String render(TextTemplate template, Map<String, Object> model) {
return template.getTemplate();
}
}

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template;
package org.elasticsearch.watcher.support.text;
import com.google.common.collect.ImmutableMap;
@ -17,7 +17,7 @@ import org.elasticsearch.script.ExecutableScript;
import org.elasticsearch.script.ScriptService.ScriptType;
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine;
import org.elasticsearch.watcher.support.text.xmustache.XMustacheTextTemplateEngine;
import org.junit.Before;
import org.junit.Test;
@ -32,10 +32,10 @@ import static org.mockito.Mockito.when;
/**
*
*/
public class TemplateTests extends ESTestCase {
public class TextTemplateTests extends ESTestCase {
private ScriptServiceProxy proxy;
private TemplateEngine engine;
private TextTemplateEngine engine;
private ExecutableScript script;
private final String lang = "xmustache";
@ -43,7 +43,7 @@ public class TemplateTests extends ESTestCase {
public void init() throws Exception {
proxy = mock(ScriptServiceProxy.class);
script = mock(ExecutableScript.class);
engine = new XMustacheTemplateEngine(Settings.EMPTY, proxy);
engine = new XMustacheTextTemplateEngine(Settings.EMPTY, proxy);
}
@Test
@ -57,7 +57,7 @@ public class TemplateTests extends ESTestCase {
when(proxy.executable(new org.elasticsearch.script.Template(templateText, type, lang, null, merged))).thenReturn(script);
when(script.run()).thenReturn("rendered_text");
Template template = templateBuilder(type, templateText).params(params).build();
TextTemplate template = templateBuilder(type, templateText).params(params).build();
assertThat(engine.render(template, model), is("rendered_text"));
}
@ -71,7 +71,7 @@ public class TemplateTests extends ESTestCase {
when(proxy.executable(new org.elasticsearch.script.Template(templateText, scriptType, lang, null, model))).thenReturn(script);
when(script.run()).thenReturn("rendered_text");
Template template = templateBuilder(scriptType, templateText).params(params).build();
TextTemplate template = templateBuilder(scriptType, templateText).params(params).build();
assertThat(engine.render(template, model), is("rendered_text"));
}
@ -83,14 +83,14 @@ public class TemplateTests extends ESTestCase {
when(proxy.executable(new org.elasticsearch.script.Template(templateText, ScriptType.INLINE, lang, null, model))).thenReturn(script);
when(script.run()).thenReturn("rendered_text");
Template template = new Template(templateText);
TextTemplate template = new TextTemplate(templateText);
assertThat(engine.render(template, model), is("rendered_text"));
}
@Test
public void testParser() throws Exception {
ScriptType type = randomScriptType();
Template template = templateBuilder(type, "_template").params(ImmutableMap.<String, Object>of("param_key", "param_val")).build();
TextTemplate template = templateBuilder(type, "_template").params(ImmutableMap.<String, Object>of("param_key", "param_val")).build();
XContentBuilder builder = jsonBuilder().startObject();
switch (type) {
case INLINE:
@ -107,20 +107,20 @@ public class TemplateTests extends ESTestCase {
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
Template parsed = Template.parse(parser);
TextTemplate parsed = TextTemplate.parse(parser);
assertThat(parsed, notNullValue());
assertThat(parsed, equalTo(template));
}
@Test
public void testParser_ParserSelfGenerated() throws Exception {
Template template = templateBuilder(randomScriptType(), "_template").params(ImmutableMap.<String, Object>of("param_key", "param_val")).build();
TextTemplate template = templateBuilder(randomScriptType(), "_template").params(ImmutableMap.<String, Object>of("param_key", "param_val")).build();
XContentBuilder builder = jsonBuilder().value(template);
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
Template parsed = Template.parse(parser);
TextTemplate parsed = TextTemplate.parse(parser);
assertThat(parsed, notNullValue());
assertThat(parsed, equalTo(template));
}
@ -133,7 +133,7 @@ public class TemplateTests extends ESTestCase {
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
Template.parse(parser);
TextTemplate.parse(parser);
fail("expected parse exception when encountering an unknown field");
}
@ -147,7 +147,7 @@ public class TemplateTests extends ESTestCase {
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
Template.parse(parser);
TextTemplate.parse(parser);
fail("expected parse exception when script type is unknown");
}
@ -160,15 +160,15 @@ public class TemplateTests extends ESTestCase {
BytesReference bytes = builder.bytes();
XContentParser parser = JsonXContent.jsonXContent.createParser(bytes);
parser.nextToken();
Template.parse(parser);
TextTemplate.parse(parser);
fail("expected parse exception when template text is missing");
}
private Template.Builder templateBuilder(ScriptType type, String text) {
private TextTemplate.Builder templateBuilder(ScriptType type, String text) {
switch (type) {
case INLINE: return Template.inline(text);
case FILE: return Template.file(text);
case INDEXED: return Template.indexed(text);
case INLINE: return TextTemplate.inline(text);
case FILE: return TextTemplate.file(text);
case INDEXED: return TextTemplate.indexed(text);
default:
throw illegalArgument("unsupported script type [{}]", type);
}

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template.xmustache;
package org.elasticsearch.watcher.support.text.xmustache;
import org.elasticsearch.common.bytes.BytesReference;

View File

@ -3,7 +3,7 @@
* 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.watcher.support.template.xmustache;
package org.elasticsearch.watcher.support.text.xmustache;
import com.google.common.collect.ImmutableList;

View File

@ -50,10 +50,10 @@ import org.elasticsearch.watcher.support.http.HttpRequestTemplate;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.secret.Secret;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheScriptEngineService;
import org.elasticsearch.watcher.support.template.xmustache.XMustacheTemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.support.text.xmustache.XMustacheScriptEngineService;
import org.elasticsearch.watcher.support.text.xmustache.XMustacheTextTemplateEngine;
import org.elasticsearch.watcher.support.xcontent.ObjectPath;
import org.elasticsearch.watcher.support.xcontent.XContentSource;
import org.elasticsearch.watcher.transform.search.ExecutableSearchTransform;
@ -182,12 +182,12 @@ public final class WatcherTestUtils {
HttpRequestTemplate.Builder httpRequest = HttpRequestTemplate.builder("localhost", 80);
httpRequest.method(HttpMethod.POST);
Template path = Template.inline("/foobarbaz/{{ctx.watch_id}}").build();
TextTemplate path = TextTemplate.inline("/foobarbaz/{{ctx.watch_id}}").build();
httpRequest.path(path);
Template body = Template.inline("{{ctx.watch_id}} executed with {{ctx.payload.response.hits.total_hits}} hits").build();
TextTemplate body = TextTemplate.inline("{{ctx.watch_id}} executed with {{ctx.payload.response.hits.total_hits}} hits").build();
httpRequest.body(body);
TemplateEngine engine = new XMustacheTemplateEngine(Settings.EMPTY, scriptService);
TextTemplateEngine engine = new XMustacheTextTemplateEngine(Settings.EMPTY, scriptService);
actions.add(new ActionWrapper("_webhook", new ExecutableWebhookAction(new WebhookAction(httpRequest.build()), logger, httpClient, engine)));
@ -199,7 +199,7 @@ public final class WatcherTestUtils {
.to(to)
.build();
TemplateEngine templateEngine = new XMustacheTemplateEngine(Settings.EMPTY, scriptService);
TextTemplateEngine templateEngine = new XMustacheTextTemplateEngine(Settings.EMPTY, scriptService);
Authentication auth = new Authentication("testname", new Secret("testpassword".toCharArray()));

View File

@ -21,7 +21,7 @@ import org.elasticsearch.watcher.client.WatcherClient;
import org.elasticsearch.watcher.condition.ConditionBuilders;
import org.elasticsearch.watcher.support.WatcherUtils;
import org.elasticsearch.watcher.support.clock.SystemClock;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.XContentSource;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.elasticsearch.watcher.transport.actions.delete.DeleteWatchResponse;
@ -311,7 +311,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTests {
refresh();
BytesReference templateSource = jsonBuilder()
.value(Template.indexed("my-template").build())
.value(TextTemplate.indexed("my-template").build())
.bytes();
SearchRequest searchRequest = newInputSearchRequest("events");
// TODO (2.0 upgrade): move back to BytesReference instead of coverting to a string

View File

@ -12,7 +12,7 @@ import org.elasticsearch.watcher.actions.logging.LoggingLevel;
import org.elasticsearch.watcher.condition.always.AlwaysCondition;
import org.elasticsearch.watcher.execution.ActionExecutionMode;
import org.elasticsearch.watcher.history.HistoryStore;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.xcontent.ObjectPath;
import org.elasticsearch.watcher.test.AbstractWatcherIntegrationTests;
import org.elasticsearch.watcher.test.WatcherTestUtils;
@ -83,7 +83,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTests {
metadata.put("foo", "bar");
metadata.put("logtext", "This is a test");
LoggingAction.Builder loggingAction = loggingAction(Template.inline("{{ctx.metadata.logtext}}"))
LoggingAction.Builder loggingAction = loggingAction(TextTemplate.inline("{{ctx.metadata.logtext}}"))
.setLevel(LoggingLevel.DEBUG)
.setCategory("test");

View File

@ -33,7 +33,7 @@ import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput;
import org.elasticsearch.watcher.input.simple.SimpleInput;
import org.elasticsearch.watcher.support.DynamicIndexName;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.transform.Transform;
import org.elasticsearch.watcher.transform.TransformBuilders;
import org.elasticsearch.watcher.trigger.schedule.IntervalSchedule;
@ -253,7 +253,7 @@ public class SearchTransformTests extends ESIntegTestCase {
builder.field("search_type", searchType.name());
}
if (templateName != null) {
Template template = Template.file(templateName).build();
TextTemplate template = TextTemplate.file(templateName).build();
builder.field("template", template);
}
@ -405,7 +405,7 @@ public class SearchTransformTests extends ESIntegTestCase {
params.put("seconds_param", "30s");
BytesReference templateSource = jsonBuilder()
.value(Template.inline(templateQuery).params(params).build())
.value(TextTemplate.inline(templateQuery).params(params).build())
.bytes();
SearchRequest request = client()
.prepareSearch()
@ -435,7 +435,7 @@ public class SearchTransformTests extends ESIntegTestCase {
params.put("seconds_param", "30s");
BytesReference templateSource = jsonBuilder()
.value(Template.indexed("test-script").params(params).build())
.value(TextTemplate.indexed("test-script").params(params).build())
.bytes();
SearchRequest request = client()
.prepareSearch()
@ -457,7 +457,7 @@ public class SearchTransformTests extends ESIntegTestCase {
params.put("seconds_param", "30s");
BytesReference templateSource = jsonBuilder()
.value(Template.file("test_disk_template").params(params).build())
.value(TextTemplate.file("test_disk_template").params(params).build())
.bytes();
SearchRequest request = client()
.prepareSearch()

View File

@ -73,8 +73,8 @@ import org.elasticsearch.watcher.support.http.auth.basic.BasicAuthFactory;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.watcher.support.init.proxy.ScriptServiceProxy;
import org.elasticsearch.watcher.support.secret.SecretService;
import org.elasticsearch.watcher.support.template.Template;
import org.elasticsearch.watcher.support.template.TemplateEngine;
import org.elasticsearch.watcher.support.text.TextTemplate;
import org.elasticsearch.watcher.support.text.TextTemplateEngine;
import org.elasticsearch.watcher.test.WatcherTestUtils;
import org.elasticsearch.watcher.transform.ExecutableTransform;
import org.elasticsearch.watcher.transform.TransformFactory;
@ -114,7 +114,7 @@ public class WatchTests extends ESTestCase {
private ClientProxy client;
private HttpClient httpClient;
private EmailService emailService;
private TemplateEngine templateEngine;
private TextTemplateEngine templateEngine;
private HtmlSanitizer htmlSanitizer;
private HttpAuthRegistry authRegistry;
private SecretService secretService;
@ -129,7 +129,7 @@ public class WatchTests extends ESTestCase {
client = mock(ClientProxy.class);
httpClient = mock(HttpClient.class);
emailService = mock(EmailService.class);
templateEngine = mock(TemplateEngine.class);
templateEngine = mock(TextTemplateEngine.class);
htmlSanitizer = mock(HtmlSanitizer.class);
secretService = mock(SecretService.class);
licenseService = mock(LicenseService.class);
@ -402,7 +402,7 @@ public class WatchTests extends ESTestCase {
if (randomBoolean()) {
HttpRequestTemplate httpRequest = HttpRequestTemplate.builder("test.host", randomIntBetween(8000, 9000))
.method(randomFrom(HttpMethod.GET, HttpMethod.POST, HttpMethod.PUT))
.path(Template.inline("_url").build())
.path(TextTemplate.inline("_url").build())
.build();
WebhookAction action = new WebhookAction(httpRequest);
list.add(new ActionWrapper("_webhook_" + randomAsciiOfLength(8), randomThrottler(), randomTransform(), new ExecutableWebhookAction(action, logger, httpClient, templateEngine)));