Remove obsolete Condition.Builder (elastic/elasticsearch#3781)
Condition.Builder simply forwards to the condition constructors and can be removed. Original commit: elastic/x-pack-elasticsearch@8c82efeb23
This commit is contained in:
parent
70e1fc0447
commit
ee520c3c70
|
@ -59,10 +59,6 @@ public class WatchSourceBuilder implements ToXContent {
|
|||
return this;
|
||||
}
|
||||
|
||||
public WatchSourceBuilder condition(Condition.Builder condition) {
|
||||
return condition(condition.build());
|
||||
}
|
||||
|
||||
public WatchSourceBuilder condition(Condition condition) {
|
||||
this.condition = condition;
|
||||
return this;
|
||||
|
@ -94,8 +90,8 @@ public class WatchSourceBuilder implements ToXContent {
|
|||
return addAction(id, null, transform.build(), action.build());
|
||||
}
|
||||
|
||||
public WatchSourceBuilder addAction(String id, Condition.Builder condition, Action.Builder action) {
|
||||
return addAction(id, null, condition.build(), null, action.build());
|
||||
public WatchSourceBuilder addAction(String id, Condition condition, Action.Builder action) {
|
||||
return addAction(id, null, condition, null, action.build());
|
||||
}
|
||||
|
||||
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Transform.Builder transform, Action.Builder action) {
|
||||
|
@ -107,9 +103,9 @@ public class WatchSourceBuilder implements ToXContent {
|
|||
return this;
|
||||
}
|
||||
|
||||
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Condition.Builder condition, Transform.Builder transform,
|
||||
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Condition condition, Transform.Builder transform,
|
||||
Action.Builder action) {
|
||||
return addAction(id, throttlePeriod, condition.build(), transform.build(), action.build());
|
||||
return addAction(id, throttlePeriod, condition, transform.build(), action.build());
|
||||
}
|
||||
|
||||
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Condition condition, Transform transform, Action action) {
|
||||
|
|
|
@ -76,11 +76,6 @@ public interface Condition extends ToXContent {
|
|||
protected abstract XContentBuilder typeXContent(XContentBuilder builder, Params params) throws IOException;
|
||||
}
|
||||
|
||||
interface Builder<C extends Condition> {
|
||||
|
||||
C build();
|
||||
}
|
||||
|
||||
interface Field {
|
||||
ParseField TYPE = new ParseField("type");
|
||||
ParseField STATUS = new ParseField("status");
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
package org.elasticsearch.xpack.watcher.condition;
|
||||
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.compare.array.ArrayCompareCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.never.NeverCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
|
||||
public final class ConditionBuilders {
|
||||
|
||||
private ConditionBuilders() {
|
||||
}
|
||||
|
||||
public static AlwaysCondition.Builder alwaysCondition() {
|
||||
return AlwaysCondition.Builder.INSTANCE;
|
||||
}
|
||||
|
||||
public static NeverCondition.Builder neverCondition() {
|
||||
return NeverCondition.Builder.INSTANCE;
|
||||
}
|
||||
|
||||
public static ScriptCondition.Builder scriptCondition(String script) {
|
||||
return scriptCondition(new Script(script));
|
||||
}
|
||||
|
||||
public static ScriptCondition.Builder scriptCondition(Script script) {
|
||||
return ScriptCondition.builder(script);
|
||||
}
|
||||
|
||||
public static CompareCondition.Builder compareCondition(String path, CompareCondition.Op op, Object value) {
|
||||
return CompareCondition.builder(path, op, value);
|
||||
}
|
||||
|
||||
public static ArrayCompareCondition.Builder arrayCompareCondition(String arrayPath, String path, ArrayCompareCondition.Op op,
|
||||
Object value, ArrayCompareCondition .Quantifier quantifier) {
|
||||
return ArrayCompareCondition.builder(arrayPath, path, op, value, quantifier);
|
||||
}
|
||||
}
|
|
@ -86,11 +86,4 @@ public class ConditionRegistry {
|
|||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
public static void writeResult(Condition.Result result, XContentBuilder builder, ToXContent.Params params) throws IOException {
|
||||
builder.startObject()
|
||||
.field(Condition.Field.MET.getPreferredName(), result.met())
|
||||
.field(result.type(), result, params)
|
||||
.endObject();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,13 +53,4 @@ public class AlwaysCondition implements Condition {
|
|||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder implements Condition.Builder<AlwaysCondition> {
|
||||
|
||||
public static final Builder INSTANCE = new Builder();
|
||||
|
||||
public AlwaysCondition build() {
|
||||
return AlwaysCondition.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -220,27 +220,6 @@ public class CompareCondition implements Condition {
|
|||
}
|
||||
}
|
||||
|
||||
public static Builder builder(String path, Op op, Object value) {
|
||||
return new Builder(path, op, value);
|
||||
}
|
||||
|
||||
public static class Builder implements Condition.Builder<CompareCondition> {
|
||||
|
||||
private String path;
|
||||
private Op op;
|
||||
private Object value;
|
||||
|
||||
public Builder(String path, Op op, Object value) {
|
||||
this.path = path;
|
||||
this.op = op;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public CompareCondition build() {
|
||||
return new CompareCondition(path, op, value);
|
||||
}
|
||||
}
|
||||
|
||||
interface Field extends Condition.Field {
|
||||
ParseField RESOLVED_VALUES = new ParseField("resolved_values");
|
||||
}
|
||||
|
|
|
@ -330,30 +330,6 @@ public class ArrayCompareCondition implements Condition {
|
|||
}
|
||||
}
|
||||
|
||||
public static Builder builder(String arrayPath, String path, Op op, Object value, Quantifier quantifier) {
|
||||
return new Builder(arrayPath, path, op, value, quantifier);
|
||||
}
|
||||
|
||||
public static class Builder implements Condition.Builder<ArrayCompareCondition> {
|
||||
private String arrayPath;
|
||||
private String path;
|
||||
private Op op;
|
||||
private Object value;
|
||||
private Quantifier quantifier;
|
||||
|
||||
private Builder(String arrayPath, String path, Op op, Object value, Quantifier quantifier) {
|
||||
this.arrayPath = arrayPath;
|
||||
this.path = path;
|
||||
this.op = op;
|
||||
this.value = value;
|
||||
this.quantifier = quantifier;
|
||||
}
|
||||
|
||||
public ArrayCompareCondition build() {
|
||||
return new ArrayCompareCondition(arrayPath, path, op, value, quantifier);
|
||||
}
|
||||
}
|
||||
|
||||
interface Field {
|
||||
ParseField PATH = new ParseField("path");
|
||||
ParseField VALUE = new ParseField("value");
|
||||
|
|
|
@ -53,13 +53,4 @@ public class NeverCondition implements Condition {
|
|||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder implements Condition.Builder<NeverCondition> {
|
||||
|
||||
public static final Builder INSTANCE = new Builder();
|
||||
|
||||
public NeverCondition build() {
|
||||
return NeverCondition.INSTANCE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,10 +69,6 @@ public class ScriptCondition implements Condition {
|
|||
}
|
||||
}
|
||||
|
||||
public static Builder builder(Script script) {
|
||||
return new Builder(script);
|
||||
}
|
||||
|
||||
public static class Result extends Condition.Result {
|
||||
|
||||
static final Result MET = new Result(true);
|
||||
|
@ -87,18 +83,4 @@ public class ScriptCondition implements Condition {
|
|||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Builder implements Condition.Builder<ScriptCondition> {
|
||||
|
||||
private final Script script;
|
||||
|
||||
private Builder(Script script) {
|
||||
this.script = script;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ScriptCondition build() {
|
||||
return new ScriptCondition(script);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.common.settings.Settings;
|
|||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -30,7 +31,6 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.emailAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -75,7 +75,7 @@ public class EmailSecretsIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2020")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_email", emailAction(
|
||||
EmailTemplate.builder()
|
||||
.from("_from")
|
||||
|
|
|
@ -25,7 +25,6 @@ import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.searchTransform;
|
||||
|
@ -62,7 +61,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(templateRequest(new SearchSourceBuilder(), "events")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.transform(searchTransform(templateRequest(new SearchSourceBuilder(), "events")))
|
||||
.addAction("_id", indexAction("actions", "action"))
|
||||
.defaultThrottlePeriod(TimeValue.timeValueSeconds(30)))
|
||||
|
@ -136,7 +135,7 @@ public class TimeThrottleIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("1s")))
|
||||
.input(searchInput(templateRequest(new SearchSourceBuilder(), "events")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.transform(searchTransform(templateRequest(new SearchSourceBuilder(), "events")))
|
||||
.addAction("_id", indexAction("actions", "action")))
|
||||
.get();
|
||||
|
|
|
@ -49,7 +49,6 @@ import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.emailAction
|
|||
import static org.elasticsearch.xpack.notification.email.DataAttachment.JSON;
|
||||
import static org.elasticsearch.xpack.notification.email.DataAttachment.YAML;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -189,7 +188,7 @@ public class EmailAttachmentTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchSourceBuilder = watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.addAction("_email", emailAction(emailBuilder).setAuthentication(USERNAME, PASSWORD.toCharArray())
|
||||
.setAttachments(emailAttachments));
|
||||
logger.info("TMP WATCHSOURCE {}", watchSourceBuilder.build().getBytes().utf8ToString());
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.common.util.Callback;
|
|||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.xpack.ssl.SSLService;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionBuilders;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.history.WatchRecord;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.common.http.Scheme;
|
||||
|
@ -32,7 +33,6 @@ import java.nio.file.Path;
|
|||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.xContentSource;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -92,7 +92,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", ActionBuilders.webhookAction(builder)))
|
||||
.get();
|
||||
|
||||
|
@ -135,7 +135,7 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", ActionBuilders.webhookAction(builder)))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.common.util.Callback;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionBuilders;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.history.WatchRecord;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
||||
|
@ -29,7 +30,6 @@ import java.net.BindException;
|
|||
|
||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.xContentSource;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -77,7 +77,7 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", ActionBuilders.webhookAction(builder)))
|
||||
.get();
|
||||
|
||||
|
@ -122,7 +122,7 @@ public class WebhookIntegrationTests extends AbstractWatcherIntegrationTestCase
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", ActionBuilders.webhookAction(builder)))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
|||
import org.elasticsearch.xpack.watcher.actions.logging.LoggingAction;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.never.NeverCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.xpack.watcher.history.WatchRecord;
|
||||
|
@ -56,8 +57,6 @@ import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.neverCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -124,7 +123,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(conditionAlwaysTrue ? alwaysCondition() : neverCondition())
|
||||
.condition(conditionAlwaysTrue ? AlwaysCondition.INSTANCE : NeverCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
|
||||
ManualExecutionContext.Builder ctxBuilder;
|
||||
|
@ -207,7 +206,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
|
||||
ExecuteWatchRequestBuilder builder = watcherClient().prepareExecuteWatch()
|
||||
|
@ -230,7 +229,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
|
||||
try {
|
||||
|
@ -249,7 +248,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
|
||||
try {
|
||||
|
@ -310,7 +309,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(neverCondition())
|
||||
.condition(NeverCondition.INSTANCE)
|
||||
.defaultThrottlePeriod(new TimeValue(1, TimeUnit.HOURS))
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
watcherClient().putWatch(new PutWatchRequest("_id", watchBuilder)).actionGet();
|
||||
|
@ -329,7 +328,7 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
|||
watchBuilder = watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.defaultThrottlePeriod(new TimeValue(1, TimeUnit.HOURS))
|
||||
.addAction("log", loggingAction("foobar"));
|
||||
watcherClient().putWatch(new PutWatchRequest("_id", watchBuilder)).actionGet();
|
||||
|
|
|
@ -16,7 +16,10 @@ import org.elasticsearch.search.SearchHit;
|
|||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.condition.Condition;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.never.NeverCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.watcher.input.Input;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -31,10 +34,6 @@ import java.util.function.Function;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.neverCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -48,13 +47,13 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
|
||||
private final Input input = simpleInput("key", 15).build();
|
||||
|
||||
private final Condition.Builder scriptConditionPasses = mockScriptCondition("return true;");
|
||||
private final Condition.Builder compareConditionPasses = compareCondition("ctx.payload.key", CompareCondition.Op.GTE, 15);
|
||||
private final Condition.Builder conditionPasses = randomFrom(alwaysCondition(), scriptConditionPasses, compareConditionPasses);
|
||||
private final Condition scriptConditionPasses = mockScriptCondition("return true;");
|
||||
private final Condition compareConditionPasses = new CompareCondition("ctx.payload.key", CompareCondition.Op.GTE, 15);
|
||||
private final Condition conditionPasses = randomFrom(AlwaysCondition.INSTANCE, scriptConditionPasses, compareConditionPasses);
|
||||
|
||||
private final Condition.Builder scriptConditionFails = mockScriptCondition("return false;");
|
||||
private final Condition.Builder compareConditionFails = compareCondition("ctx.payload.key", CompareCondition.Op.LT, 15);
|
||||
private final Condition.Builder conditionFails = randomFrom(neverCondition(), scriptConditionFails, compareConditionFails);
|
||||
private final Condition scriptConditionFails = mockScriptCondition("return false;");
|
||||
private final Condition compareConditionFails = new CompareCondition("ctx.payload.key", CompareCondition.Op.LT, 15);
|
||||
private final Condition conditionFails = randomFrom(NeverCondition.INSTANCE, scriptConditionFails, compareConditionFails);
|
||||
|
||||
@Override
|
||||
protected List<Class<? extends Plugin>> pluginTypes() {
|
||||
|
@ -97,15 +96,15 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
public void testActionConditionWithHardFailures() throws Exception {
|
||||
final String id = "testActionConditionWithHardFailures";
|
||||
|
||||
final Condition.Builder scriptConditionFailsHard = mockScriptCondition("throw new IllegalStateException('failed');");
|
||||
final List<Condition.Builder> actionConditionsWithFailure =
|
||||
Lists.newArrayList(scriptConditionFailsHard, conditionPasses, alwaysCondition());
|
||||
final Condition scriptConditionFailsHard = mockScriptCondition("throw new IllegalStateException('failed');");
|
||||
final List<Condition> actionConditionsWithFailure =
|
||||
Lists.newArrayList(scriptConditionFailsHard, conditionPasses, AlwaysCondition.INSTANCE);
|
||||
|
||||
Collections.shuffle(actionConditionsWithFailure, random());
|
||||
|
||||
final int failedIndex = actionConditionsWithFailure.indexOf(scriptConditionFailsHard);
|
||||
|
||||
putAndTriggerWatch(id, input, actionConditionsWithFailure.toArray(new Condition.Builder[actionConditionsWithFailure.size()]));
|
||||
putAndTriggerWatch(id, input, actionConditionsWithFailure.toArray(new Condition[actionConditionsWithFailure.size()]));
|
||||
|
||||
flush();
|
||||
|
||||
|
@ -131,7 +130,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
assertThat(condition, nullValue());
|
||||
assertThat(logging, nullValue());
|
||||
} else {
|
||||
assertThat(condition.get("type"), is(actionConditionsWithFailure.get(i).build().type()));
|
||||
assertThat(condition.get("type"), is(actionConditionsWithFailure.get(i).type()));
|
||||
|
||||
assertThat(action.get("status"), is("success"));
|
||||
assertThat(condition.get("met"), is(true));
|
||||
|
@ -144,13 +143,13 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testActionConditionWithFailures() throws Exception {
|
||||
final String id = "testActionConditionWithFailures";
|
||||
final List<Condition.Builder> actionConditionsWithFailure = Lists.newArrayList(conditionFails, conditionPasses, alwaysCondition());
|
||||
final List<Condition> actionConditionsWithFailure = Lists.newArrayList(conditionFails, conditionPasses, AlwaysCondition.INSTANCE);
|
||||
|
||||
Collections.shuffle(actionConditionsWithFailure, random());
|
||||
|
||||
final int failedIndex = actionConditionsWithFailure.indexOf(conditionFails);
|
||||
|
||||
putAndTriggerWatch(id, input, actionConditionsWithFailure.toArray(new Condition.Builder[actionConditionsWithFailure.size()]));
|
||||
putAndTriggerWatch(id, input, actionConditionsWithFailure.toArray(new Condition[actionConditionsWithFailure.size()]));
|
||||
|
||||
flush();
|
||||
|
||||
|
@ -169,7 +168,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
final Map<String, Object> logging = (Map<String, Object>)action.get("logging");
|
||||
|
||||
assertThat(action.get("id"), is("action" + i));
|
||||
assertThat(condition.get("type"), is(actionConditionsWithFailure.get(i).build().type()));
|
||||
assertThat(condition.get("type"), is(actionConditionsWithFailure.get(i).type()));
|
||||
|
||||
if (i == failedIndex) {
|
||||
assertThat(action.get("status"), is("condition_failed"));
|
||||
|
@ -188,15 +187,15 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
@SuppressWarnings("unchecked")
|
||||
public void testActionCondition() throws Exception {
|
||||
final String id = "testActionCondition";
|
||||
final List<Condition.Builder> actionConditions = Lists.newArrayList(conditionPasses);
|
||||
final List<Condition> actionConditions = Lists.newArrayList(conditionPasses);
|
||||
|
||||
if (randomBoolean()) {
|
||||
actionConditions.add(alwaysCondition());
|
||||
actionConditions.add(AlwaysCondition.INSTANCE);
|
||||
}
|
||||
|
||||
Collections.shuffle(actionConditions, random());
|
||||
|
||||
putAndTriggerWatch(id, input, actionConditions.toArray(new Condition.Builder[actionConditions.size()]));
|
||||
putAndTriggerWatch(id, input, actionConditions.toArray(new Condition[actionConditions.size()]));
|
||||
|
||||
flush();
|
||||
|
||||
|
@ -216,7 +215,7 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
|
||||
assertThat(action.get("id"), is("action" + i));
|
||||
assertThat(action.get("status"), is("success"));
|
||||
assertThat(condition.get("type"), is(actionConditions.get(i).build().type()));
|
||||
assertThat(condition.get("type"), is(actionConditions.get(i).type()));
|
||||
assertThat(condition.get("met"), is(true));
|
||||
assertThat(action.get("reason"), nullValue());
|
||||
assertThat(logging.get("logged_text"), is(Integer.toString(i)));
|
||||
|
@ -245,8 +244,8 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
* @param input The input to use for the Watch
|
||||
* @param actionConditions The conditions to add to the Watch
|
||||
*/
|
||||
private void putAndTriggerWatch(final String id, final Input input, final Condition.Builder... actionConditions) {
|
||||
WatchSourceBuilder source = watchBuilder().trigger(schedule(interval("5s"))).input(input).condition(alwaysCondition());
|
||||
private void putAndTriggerWatch(final String id, final Input input, final Condition... actionConditions) {
|
||||
WatchSourceBuilder source = watchBuilder().trigger(schedule(interval("5s"))).input(input).condition(AlwaysCondition.INSTANCE);
|
||||
|
||||
for (int i = 0; i < actionConditions.length; ++i) {
|
||||
source.addAction("action" + i, actionConditions[i], loggingAction(Integer.toString(i)));
|
||||
|
@ -265,9 +264,9 @@ public class HistoryActionConditionTests extends AbstractWatcherIntegrationTestC
|
|||
* @param inlineScript The script to "compile" and run
|
||||
* @return Never {@code null}
|
||||
*/
|
||||
private static Condition.Builder mockScriptCondition(String inlineScript) {
|
||||
private static Condition mockScriptCondition(String inlineScript) {
|
||||
Script script = new Script(inlineScript, ScriptService.ScriptType.INLINE, MockScriptPlugin.NAME, null, null);
|
||||
return scriptCondition(script);
|
||||
return new ScriptCondition(script);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.search.aggregations.Aggregations;
|
|||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.xpack.notification.email.EmailTemplate;
|
||||
import org.elasticsearch.xpack.notification.email.support.EmailServer;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
@ -22,7 +23,6 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.emailAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -85,7 +85,7 @@ public class HistoryTemplateEmailMappingsTests extends AbstractWatcherIntegratio
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_email", emailAction(EmailTemplate.builder()
|
||||
.from("from@example.com")
|
||||
.to("to1@example.com", "to2@example.com")
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.elasticsearch.ElasticsearchException;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -25,7 +26,6 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.webhookAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -76,7 +76,7 @@ public class HistoryTemplateHttpMappingsTests extends AbstractWatcherIntegration
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(httpInput(HttpRequestTemplate.builder("localhost", webPort).path("/input/path")))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_webhook", webhookAction(HttpRequestTemplate.builder("localhost", webPort)
|
||||
.path("/webhook/path")
|
||||
.body("_body"))))
|
||||
|
|
|
@ -10,6 +10,7 @@ import org.elasticsearch.action.search.SearchType;
|
|||
import org.elasticsearch.common.bytes.BytesArray;
|
||||
import org.elasticsearch.search.aggregations.Aggregations;
|
||||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -19,7 +20,6 @@ import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -57,7 +57,7 @@ public class HistoryTemplateSearchInputMappingsTests extends AbstractWatcherInte
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(request))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("logger", loggingAction("indexed")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.carrotsearch.hppc.cursors.ObjectObjectCursor;
|
|||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||
import org.elasticsearch.cluster.metadata.MappingMetaData;
|
||||
import org.elasticsearch.common.collect.ImmutableOpenMap;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
@ -19,7 +20,6 @@ import java.util.Map;
|
|||
import static org.elasticsearch.common.xcontent.support.XContentMapValues.extractValue;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -44,7 +44,7 @@ public class HistoryTemplateTimeMappingsTests extends AbstractWatcherIntegration
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logging", loggingAction("foobar")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRespon
|
|||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
@ -21,7 +22,6 @@ import java.util.function.Function;
|
|||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.scriptTransform;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -84,7 +84,7 @@ public class HistoryTemplateTransformMappingsTests extends AbstractWatcherIntegr
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("_id1").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.transform(scriptTransform("return [ 'key' : 'value1' ];"))
|
||||
.addAction("logger", scriptTransform("return [ 'key' : 'value2' ];"), loggingAction("indexed")))
|
||||
.get();
|
||||
|
@ -96,7 +96,7 @@ public class HistoryTemplateTransformMappingsTests extends AbstractWatcherIntegr
|
|||
putWatchResponse = watcherClient().preparePutWatch("_id2").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.transform(scriptTransform("return [ 'key' : [ 'key1' : 'value1' ] ];"))
|
||||
.addAction("logger", scriptTransform("return [ 'key' : [ 'key1' : 'value2' ] ];"), loggingAction("indexed")))
|
||||
.get();
|
||||
|
|
|
@ -13,11 +13,13 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
||||
import org.elasticsearch.xpack.watcher.actions.ExecutableActions;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||
import org.elasticsearch.xpack.watcher.input.InputFactory;
|
||||
|
@ -42,7 +44,6 @@ import static java.util.Collections.emptyMap;
|
|||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.chainInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
|
@ -152,7 +153,7 @@ public class ChainInputTests extends ESTestCase {
|
|||
watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(chainedInputBuilder)
|
||||
.condition(scriptCondition("ctx.payload.hits.total == 1"))
|
||||
.condition(new ScriptCondition(new Script("ctx.payload.hits.total == 1")))
|
||||
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched"))
|
||||
.toXContent(builder, ToXContent.EMPTY_PARAMS);
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.xContentSource;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -73,7 +72,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.path("/index/_search")
|
||||
.body(jsonBuilder().startObject().field("size", 1).endObject().string())
|
||||
.auth(securityEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null)))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")))
|
||||
.get();
|
||||
|
||||
|
@ -92,7 +91,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.input(httpInput(HttpRequestTemplate.builder(address.getHostString(), address.getPort())
|
||||
.path("/_cluster/stats")
|
||||
.auth(securityEnabled() ? new BasicAuth("test", "changeme".toCharArray()) : null)))
|
||||
.condition(compareCondition("ctx.payload.nodes.count.total", CompareCondition.Op.GTE, 1L))
|
||||
.condition(new CompareCondition("ctx.payload.nodes.count.total", CompareCondition.Op.GTE, 1L))
|
||||
.addAction("_id", loggingAction("watch [{{ctx.watch_id}}] matched")))
|
||||
.get();
|
||||
|
||||
|
@ -127,7 +126,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(10, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(httpInput(requestBuilder).extractKeys("hits.total"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.get();
|
||||
|
||||
// in this watcher the condition will fail, because max_score isn't extracted, only total:
|
||||
|
@ -135,7 +134,7 @@ public class HttpInputIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(10, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(httpInput(requestBuilder).extractKeys("hits.total"))
|
||||
.condition(compareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0L)))
|
||||
.get();
|
||||
|
||||
if (timeWarped()) {
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.watcher.support;
|
|||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
import org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule;
|
||||
|
@ -19,7 +20,6 @@ import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
|||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
|
@ -45,7 +45,7 @@ public class DynamicIndexNameIntegrationTests extends AbstractWatcherIntegration
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("dynamic_index", indexAction("<idx-{now}>", "type")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -11,11 +11,13 @@ import org.elasticsearch.common.logging.Loggers;
|
|||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.node.MockNode;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.Watcher;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchRequest;
|
||||
import org.elasticsearch.xpack.watcher.trigger.ScheduleTriggerEngineMock;
|
||||
import org.elasticsearch.xpack.watcher.trigger.TriggerModule;
|
||||
|
@ -28,7 +30,6 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
|
@ -81,7 +82,7 @@ public class WatcherExecutorServiceBenchmark {
|
|||
PutWatchRequest putAlertRequest = new PutWatchRequest(name, new WatchSourceBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(templateRequest(new SearchSourceBuilder(), "test")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0")));
|
||||
.condition(new ScriptCondition(new Script("ctx.payload.hits.total > 0"))));
|
||||
putAlertRequest.setId(name);
|
||||
watcherClient.putWatch(putAlertRequest).actionGet();
|
||||
}
|
||||
|
@ -123,7 +124,7 @@ public class WatcherExecutorServiceBenchmark {
|
|||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(templateRequest(new SearchSourceBuilder(), "test"))
|
||||
.extractKeys("hits.total"))
|
||||
.condition(scriptCondition("1 == 1"))
|
||||
.condition(new ScriptCondition(new Script("1 == 1")))
|
||||
.addAction("_id", indexAction("index", "type")));
|
||||
putAlertRequest.setId(name);
|
||||
watcherClient.putWatch(putAlertRequest).actionGet();
|
||||
|
@ -167,7 +168,7 @@ public class WatcherExecutorServiceBenchmark {
|
|||
PutWatchRequest putAlertRequest = new PutWatchRequest(name, new WatchSourceBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(httpInput(HttpRequestTemplate.builder("localhost", 9200)))
|
||||
.condition(scriptCondition("ctx.payload.tagline == \"You Know, for Search\"")));
|
||||
.condition(new ScriptCondition(new Script("ctx.payload.tagline == \"You Know, for Search\""))));
|
||||
putAlertRequest.setId(name);
|
||||
watcherClient.putWatch(putAlertRequest).actionGet();
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.xpack.watcher.actions.ActionBuilders;
|
|||
import org.elasticsearch.xpack.watcher.actions.logging.LoggingLevel;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.xpack.support.clock.Clock;
|
||||
import org.elasticsearch.xpack.watcher.watch.WatchStore;
|
||||
|
@ -46,7 +47,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
import static org.elasticsearch.search.aggregations.AggregationBuilders.histogram;
|
||||
import static org.elasticsearch.search.aggregations.AggregationBuilders.percentiles;
|
||||
import static org.elasticsearch.search.aggregations.AggregationBuilders.terms;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -110,7 +110,7 @@ public class WatcherScheduleEngineBenchmark {
|
|||
.setSource(new WatchSourceBuilder()
|
||||
.trigger(schedule(interval(interval + "s")))
|
||||
.input(searchInput(templateRequest(new SearchSourceBuilder(), "test")))
|
||||
.condition(scriptCondition("ctx.payload.hits.total > 0"))
|
||||
.condition(new ScriptCondition(new Script("ctx.payload.hits.total > 0")))
|
||||
.addAction("logging", ActionBuilders.loggingAction("test").setLevel(LoggingLevel.TRACE))
|
||||
.buildAsBytes(XContentType.JSON)
|
||||
).get();
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
|||
import org.elasticsearch.xpack.support.clock.SystemClock;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
|
@ -39,8 +40,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitC
|
|||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
|
@ -74,7 +73,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.addAction("_logger", loggingAction("_logging")
|
||||
.setCategory("_category")))
|
||||
.get();
|
||||
|
@ -93,7 +92,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.get();
|
||||
timeWarp().scheduler().trigger("_name");
|
||||
// The watch's condition won't meet because there is no data that matches with the query
|
||||
|
@ -119,7 +118,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/1 * * * * ? 2020")))
|
||||
.input(searchInput(searchRequest))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.get();
|
||||
assertThat(indexResponse.isCreated(), is(true));
|
||||
DeleteWatchResponse deleteWatchResponse = watcherClient.prepareDeleteWatch("_name").get();
|
||||
|
@ -178,7 +177,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.addAction("_id", indexAction("idx", "action"));
|
||||
|
||||
watcherClient().preparePutWatch("_name")
|
||||
.setSource(source.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.setSource(source.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.get();
|
||||
|
||||
timeWarp().clock().fastForwardSeconds(5);
|
||||
|
@ -186,7 +185,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
assertWatchWithMinimumPerformedActionsCount("_name", 0, false);
|
||||
|
||||
watcherClient().preparePutWatch("_name")
|
||||
.setSource(source.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0L)))
|
||||
.setSource(source.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0L)))
|
||||
.get();
|
||||
|
||||
timeWarp().clock().fastForwardSeconds(5);
|
||||
|
@ -197,7 +196,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient().preparePutWatch("_name")
|
||||
.setSource(source
|
||||
.trigger(schedule(Schedules.cron("0/1 * * * * ? 2020")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 0L)))
|
||||
.get();
|
||||
|
||||
timeWarp().clock().fastForwardSeconds(5);
|
||||
|
@ -274,14 +273,14 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(request).extractKeys("hits.total"))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L)))
|
||||
.get();
|
||||
// in this watcher the condition will fail, because max_score isn't extracted, only total:
|
||||
watcherClient.preparePutWatch("_name2")
|
||||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(searchInput(request).extractKeys("hits.total"))
|
||||
.condition(compareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.max_score", CompareCondition.Op.GTE, 0L)))
|
||||
.get();
|
||||
|
||||
timeWarp().scheduler().trigger("_name1");
|
||||
|
@ -303,7 +302,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(-5, IntervalSchedule.Interval.Unit.SECONDS)))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logger", loggingAction("executed!")))
|
||||
.get();
|
||||
fail("put watch should have failed");
|
||||
|
@ -316,7 +315,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(hourly().minutes(-10).build()))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logger", loggingAction("executed!")))
|
||||
.get();
|
||||
fail("put watch should have failed");
|
||||
|
@ -329,7 +328,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(daily().atRoundHour(-10).build()))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logger", loggingAction("executed!")))
|
||||
.get();
|
||||
fail("put watch should have failed");
|
||||
|
@ -343,7 +342,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(weekly().time(WeekTimes.builder().atRoundHour(-10).build()).build()))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logger", loggingAction("executed!")))
|
||||
.get();
|
||||
fail("put watch should have failed");
|
||||
|
@ -357,7 +356,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(monthly().time(MonthTimes.builder().atRoundHour(-10).build()).build()))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logger", loggingAction("executed!")))
|
||||
.get();
|
||||
fail("put watch should have failed");
|
||||
|
@ -378,7 +377,7 @@ public class BasicWatcherTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GTE, 3L)))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GTE, 3L)))
|
||||
.get();
|
||||
|
||||
logger.info("created watch [{}] at [{}]", watchName, SystemClock.INSTANCE.nowUTC());
|
||||
|
|
|
@ -39,8 +39,6 @@ import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -222,7 +220,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0 0/5 * * * ? 2050")))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.buildAsBytes(XContentType.JSON)
|
||||
)
|
||||
.setWaitForActiveShards(ActiveShardCount.ALL)
|
||||
|
@ -253,7 +251,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient().preparePutWatch(watchId).setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2050")))
|
||||
.input(searchInput(request))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", indexAction("output", "test"))
|
||||
.defaultThrottlePeriod(TimeValue.timeValueMillis(0))
|
||||
).get();
|
||||
|
@ -306,7 +304,7 @@ public class BootStrapTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient().preparePutWatch(watchId).setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2050")))
|
||||
.input(searchInput(request))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", indexAction("output", "test"))
|
||||
.defaultThrottlePeriod(TimeValue.timeValueMillis(0))
|
||||
).get();
|
||||
|
|
|
@ -9,8 +9,10 @@ import org.elasticsearch.action.search.SearchResponse;
|
|||
import org.elasticsearch.common.xcontent.support.XContentMapValues;
|
||||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.MockScriptPlugin;
|
||||
import org.elasticsearch.script.Script;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.ObjectPath;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -24,7 +26,6 @@ import java.util.function.Function;
|
|||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.scriptTransform;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -120,7 +121,8 @@ public class ExecutionVarsIntegrationTests extends AbstractWatcherIntegrationTes
|
|||
PutWatchResponse putWatchResponse = watcherClient.preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/1 * * * * ?")))
|
||||
.input(simpleInput("value", 5))
|
||||
.condition(scriptCondition("ctx.vars.condition_value = ctx.payload.value + 5; return ctx.vars.condition_value > 5;"))
|
||||
.condition(new ScriptCondition(
|
||||
new Script("ctx.vars.condition_value = ctx.payload.value + 5; return ctx.vars.condition_value > 5;")))
|
||||
.transform(scriptTransform("ctx.vars.watch_transform_value = ctx.vars.condition_value + 5; return ctx.payload;"))
|
||||
.addAction(
|
||||
"a1",
|
||||
|
@ -182,7 +184,8 @@ public class ExecutionVarsIntegrationTests extends AbstractWatcherIntegrationTes
|
|||
PutWatchResponse putWatchResponse = watcherClient.preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/1 * * * * ? 2020")))
|
||||
.input(simpleInput("value", 5))
|
||||
.condition(scriptCondition("ctx.vars.condition_value = ctx.payload.value + 5; return ctx.vars.condition_value > 5;"))
|
||||
.condition(new ScriptCondition(
|
||||
new Script("ctx.vars.condition_value = ctx.payload.value + 5; return ctx.vars.condition_value > 5;")))
|
||||
.transform(scriptTransform("ctx.vars.watch_transform_value = ctx.vars.condition_value + 5; return ctx.payload;"))
|
||||
.addAction(
|
||||
"a1",
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.xpack.notification.hipchat.HipChatMessage;
|
|||
import org.elasticsearch.xpack.notification.hipchat.HipChatService;
|
||||
import org.elasticsearch.xpack.notification.hipchat.SentMessages;
|
||||
import org.elasticsearch.xpack.watcher.actions.hipchat.HipChatAction;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
||||
|
@ -22,7 +23,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.hipchatAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -155,7 +155,7 @@ public class HipChatServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("10m")))
|
||||
.input(simpleInput("ref", "HipChatServiceTests#testWatchWithHipChatAction"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("hipchat", actionBuilder))
|
||||
.execute().get();
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ import org.elasticsearch.xpack.common.http.auth.basic.ApplicableBasicAuth;
|
|||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
||||
import org.elasticsearch.xpack.security.crypto.CryptoService;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -34,7 +35,6 @@ import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
|||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.webhookAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -88,7 +88,7 @@ public class HttpSecretsIntegrationTests extends AbstractWatcherIntegrationTestC
|
|||
.input(httpInput(HttpRequestTemplate.builder(webServer.getHostName(), webServer.getPort())
|
||||
.path("/")
|
||||
.auth(new BasicAuth(USERNAME, PASSWORD.toCharArray()))))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_logging", loggingAction("executed")))
|
||||
.get();
|
||||
|
||||
|
@ -149,7 +149,7 @@ public class HttpSecretsIntegrationTests extends AbstractWatcherIntegrationTestC
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 * ? 2020")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_webhook", webhookAction(HttpRequestTemplate.builder(webServer.getHostName(), webServer.getPort())
|
||||
.path("/")
|
||||
.auth(new BasicAuth(USERNAME, PASSWORD.toCharArray())))))
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.elasticsearch.xpack.watcher.WatcherService;
|
|||
import org.elasticsearch.xpack.watcher.WatcherState;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilders;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.compare.CompareCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionService;
|
||||
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
|
||||
|
@ -38,8 +39,6 @@ import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
|||
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
|
@ -92,7 +91,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchSource = watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L));
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L));
|
||||
|
||||
// we first need to make sure the license is enabled, otherwise all APIs will be blocked
|
||||
ensureLicenseEnabled();
|
||||
|
@ -150,7 +149,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchSource = WatchSourceBuilders.watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput("key", "value"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", loggingAction("executed!"));
|
||||
|
||||
watcherClient().preparePutWatch("_watch_id")
|
||||
|
@ -201,7 +200,7 @@ public class NoMasterNodeTests extends AbstractWatcherIntegrationTestCase {
|
|||
WatchSourceBuilder watchSource = watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L));
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L));
|
||||
watcherClient().preparePutWatch(watchName).setSource(watchSource).get();
|
||||
}
|
||||
ensureGreen();
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.xpack.notification.pagerduty.IncidentEventContext;
|
|||
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyAccount;
|
||||
import org.elasticsearch.xpack.notification.pagerduty.PagerDutyService;
|
||||
import org.elasticsearch.xpack.notification.pagerduty.SentEvent;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
import org.elasticsearch.xpack.watcher.watch.Payload;
|
||||
|
@ -24,7 +25,6 @@ import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.pagerDutyAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -82,7 +82,7 @@ public class PagerDutyServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("10m")))
|
||||
.input(simpleInput("ref", "testWatchWithPagerDutyAction()"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("pd", actionBuilder))
|
||||
.execute().get();
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.xpack.notification.slack.SlackService;
|
|||
import org.elasticsearch.xpack.notification.slack.message.Attachment;
|
||||
import org.elasticsearch.xpack.notification.slack.message.SlackMessage;
|
||||
import org.elasticsearch.xpack.watcher.actions.slack.SlackAction;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
import org.joda.time.DateTime;
|
||||
|
@ -23,7 +24,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.slackAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -87,7 +87,7 @@ public class SlackServiceTests extends AbstractWatcherIntegrationTestCase {
|
|||
PutWatchResponse putWatchResponse = watcherClient().preparePutWatch("1").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("10m")))
|
||||
.input(simpleInput("ref", "testWatchWithSlackAction()"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("slack", actionBuilder))
|
||||
.execute().get();
|
||||
|
||||
|
|
|
@ -37,7 +37,6 @@ import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.transform.TransformBuilders.searchTransform;
|
||||
|
@ -74,7 +73,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(templateRequest(searchSource(), "events")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.transform(searchTransform(templateRequest(searchSource(), "events")))
|
||||
.addAction("_a1", indexAction("actions", "action1"))
|
||||
.addAction("_a2", indexAction("actions", "action2"))
|
||||
|
@ -148,7 +147,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(templateRequest(searchSource(), "events")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.transform(searchTransform(templateRequest(searchSource(), "events")))
|
||||
.addAction("_a1", indexAction("actions", "action1"))
|
||||
.addAction("_a2", indexAction("actions", "action2"))
|
||||
|
@ -229,7 +228,7 @@ public class WatchAckTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(templateRequest(searchSource(), "events")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.GT, 0L))
|
||||
.transform(searchTransform(templateRequest(searchSource(), "events")))
|
||||
.addAction("_id", indexAction("actions", "action")))
|
||||
.get();
|
||||
|
|
|
@ -31,7 +31,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -55,7 +54,7 @@ public class WatchMetadataTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? *")))
|
||||
.input(searchInput(templateRequest(searchSource().query(matchAllQuery()), "my-index")))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.metadata(metadata))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.elasticsearch.script.Script;
|
|||
import org.elasticsearch.script.ScriptService;
|
||||
import org.elasticsearch.script.ScriptService.ScriptType;
|
||||
import org.elasticsearch.xpack.XPackPlugin;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.support.search.WatcherSearchTemplateRequest;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
@ -38,7 +39,6 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcke
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
|
@ -141,7 +141,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.transform(scriptTransform(script))
|
||||
.addAction("_id", indexAction("output1", "type")))
|
||||
.get();
|
||||
|
@ -151,7 +151,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", scriptTransform(script), indexAction("output2", "type")))
|
||||
.get();
|
||||
assertThat(putWatchResponse.isCreated(), is(true));
|
||||
|
@ -235,7 +235,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.transform(chainTransform(scriptTransform(script1), scriptTransform(script2)))
|
||||
.addAction("_id", indexAction("output1", "type")))
|
||||
.get();
|
||||
|
@ -245,7 +245,7 @@ public class TransformIntegrationTests extends AbstractWatcherIntegrationTestCas
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5s")))
|
||||
.input(simpleInput(MapBuilder.<String, Object>newMapBuilder().put("key1", 10).put("key2", 10)))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_id", chainTransform(scriptTransform(script1), scriptTransform(script2)),
|
||||
indexAction("output2", "type")))
|
||||
.get();
|
||||
|
|
|
@ -15,6 +15,7 @@ import org.elasticsearch.common.xcontent.ToXContent;
|
|||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -28,7 +29,6 @@ import java.util.concurrent.TimeUnit;
|
|||
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.indexAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -51,7 +51,7 @@ public class ActivateWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval("1s")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_a1", indexAction("actions", "action1"))
|
||||
.defaultThrottlePeriod(new TimeValue(0, TimeUnit.SECONDS)))
|
||||
.get();
|
||||
|
@ -108,7 +108,7 @@ public class ActivateWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0 0 0 1 1 ? 2050"))) // some time in 2050
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_a1", indexAction("actions", "action1"))
|
||||
.defaultThrottlePeriod(new TimeValue(0, TimeUnit.SECONDS)))
|
||||
.get();
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.elasticsearch.action.ActionRequestValidationException;
|
|||
import org.elasticsearch.action.ListenableActionFuture;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.history.HistoryStore;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.ObjectPath;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
|
@ -28,7 +29,6 @@ import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
|
|||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.httpInput;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -45,7 +45,7 @@ public class DeleteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
PutWatchResponse putResponse = watcherClient().preparePutWatch("_name").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5m")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_action1", loggingAction("anything")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.watcher.transport.action.delete;
|
|||
import org.elasticsearch.plugins.Plugin;
|
||||
import org.elasticsearch.script.SleepScriptEngine;
|
||||
import org.elasticsearch.test.junit.annotations.TestLogging;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.delete.DeleteWatchResponse;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
@ -19,7 +20,6 @@ import java.util.List;
|
|||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.scriptCondition;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
@ -48,7 +48,7 @@ public class ForceDeleteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
public void testForceDeleteLongRunningWatch() throws Exception {
|
||||
PutWatchResponse putResponse = watcherClient().preparePutWatch("_name").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("3s")))
|
||||
.condition(scriptCondition(SleepScriptEngine.sleepScript(5000)))
|
||||
.condition(new ScriptCondition(SleepScriptEngine.sleepScript(5000)))
|
||||
.addAction("_action1", loggingAction("executed action: {{ctx.id}}")))
|
||||
.get();
|
||||
assertThat(putResponse.getId(), equalTo("_name"));
|
||||
|
|
|
@ -9,6 +9,8 @@ import org.elasticsearch.action.ActionRequestValidationException;
|
|||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.condition.never.NeverCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ActionExecutionMode;
|
||||
import org.elasticsearch.xpack.watcher.execution.Wid;
|
||||
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
|
||||
|
@ -31,8 +33,6 @@ import java.util.Map;
|
|||
import static java.util.Collections.singletonMap;
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.neverCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -76,7 +76,7 @@ public class ExecuteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("_text")))
|
||||
.get();
|
||||
|
||||
|
@ -117,7 +117,7 @@ public class ExecuteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("_text")))
|
||||
.get();
|
||||
|
||||
|
@ -173,7 +173,7 @@ public class ExecuteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("_text")))
|
||||
.get();
|
||||
|
||||
|
@ -216,7 +216,7 @@ public class ExecuteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(neverCondition())
|
||||
.condition(NeverCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("_text")))
|
||||
.get();
|
||||
|
||||
|
@ -261,7 +261,7 @@ public class ExecuteWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
.trigger(schedule(interval("1s"))) // run every second so we can ack it
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.defaultThrottlePeriod(TimeValue.timeValueMillis(0))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("_text")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ package org.elasticsearch.xpack.watcher.transport.action.execute;
|
|||
|
||||
import org.apache.lucene.util.LuceneTestCase.BadApple;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.Wid;
|
||||
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
|
@ -20,7 +21,6 @@ import java.util.Map;
|
|||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.cron;
|
||||
|
@ -43,7 +43,7 @@ public class ExecuteWatchWithDateMathTests extends AbstractWatcherIntegrationTes
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("0/5 * * * * ? 2099")))
|
||||
.input(simpleInput("foo", "bar"))
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("log", loggingAction("_text")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
package org.elasticsearch.xpack.watcher.transport.action.get;
|
||||
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchRequest;
|
||||
|
@ -16,7 +17,6 @@ import java.util.Map;
|
|||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -32,7 +32,7 @@ public class GetWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
PutWatchResponse putResponse = watcherClient().preparePutWatch("_name").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("5m")))
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_action1", loggingAction("{{ctx.watch_id}}")))
|
||||
.get();
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@ package org.elasticsearch.xpack.watcher.transport.action.put;
|
|||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.xpack.watcher.client.WatchSourceBuilder;
|
||||
import org.elasticsearch.xpack.watcher.condition.always.AlwaysCondition;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.put.PutWatchResponse;
|
||||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.alwaysCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.Schedules.interval;
|
||||
|
@ -33,7 +33,7 @@ public class PutWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
source.input(simpleInput());
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
source.condition(alwaysCondition());
|
||||
source.condition(AlwaysCondition.INSTANCE);
|
||||
}
|
||||
if (randomBoolean()) {
|
||||
source.addAction("_action1", loggingAction("{{ctx.watch_id}}"));
|
||||
|
@ -51,7 +51,7 @@ public class PutWatchTests extends AbstractWatcherIntegrationTestCase {
|
|||
try {
|
||||
watcherClient().preparePutWatch("_name").setSource(watchBuilder()
|
||||
.input(simpleInput())
|
||||
.condition(alwaysCondition())
|
||||
.condition(AlwaysCondition.INSTANCE)
|
||||
.addAction("_action1", loggingAction("{{ctx.watch_id}}")))
|
||||
.get();
|
||||
fail("Expected IllegalStateException");
|
||||
|
|
|
@ -12,7 +12,7 @@ import org.elasticsearch.script.SleepScriptEngine;
|
|||
import org.elasticsearch.test.ESIntegTestCase;
|
||||
import org.elasticsearch.xpack.watcher.WatcherState;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionBuilders;
|
||||
import org.elasticsearch.xpack.watcher.condition.ConditionBuilders;
|
||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||
import org.elasticsearch.xpack.watcher.execution.ExecutionPhase;
|
||||
import org.elasticsearch.xpack.watcher.execution.QueuedWatch;
|
||||
import org.elasticsearch.xpack.watcher.input.InputBuilders;
|
||||
|
@ -63,7 +63,7 @@ public class SlowWatchStatsTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient().preparePutWatch("_id").setSource(watchBuilder()
|
||||
.trigger(schedule(interval("1s")))
|
||||
.input(InputBuilders.simpleInput("key", "value"))
|
||||
.condition(ConditionBuilders.scriptCondition(SleepScriptEngine.sleepScript(10000)))
|
||||
.condition(new ScriptCondition(SleepScriptEngine.sleepScript(10000)))
|
||||
.addAction("_action", ActionBuilders.loggingAction("hello {{ctx.watch_id}}!"))
|
||||
).get();
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class SlowWatchStatsTests extends AbstractWatcherIntegrationTestCase {
|
|||
watcherClient().preparePutWatch("_id" + i).setSource(watchBuilder()
|
||||
.trigger(schedule(interval("1s")))
|
||||
.input(InputBuilders.simpleInput("key", "value"))
|
||||
.condition(ConditionBuilders.scriptCondition(SleepScriptEngine.sleepScript(10000)))
|
||||
.condition(new ScriptCondition(SleepScriptEngine.sleepScript(10000)))
|
||||
.addAction("_action", ActionBuilders.loggingAction("hello {{ctx.watch_id}}!"))
|
||||
).get();
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@ import static org.elasticsearch.index.query.QueryBuilders.termQuery;
|
|||
import static org.elasticsearch.search.builder.SearchSourceBuilder.searchSource;
|
||||
import static org.elasticsearch.test.ESIntegTestCase.Scope.TEST;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.compareCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.searchInput;
|
||||
import static org.elasticsearch.xpack.watcher.test.WatcherTestUtils.templateRequest;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
|
@ -60,7 +59,7 @@ public class WatcherStatsTests extends AbstractWatcherIntegrationTestCase {
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(cron("* * * * * ? *")))
|
||||
.input(searchInput(request))
|
||||
.condition(compareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
.condition(new CompareCondition("ctx.payload.hits.total", CompareCondition.Op.EQ, 1L))
|
||||
)
|
||||
.get();
|
||||
|
||||
|
|
|
@ -8,13 +8,13 @@ package org.elasticsearch.xpack.watcher.watch;
|
|||
import org.elasticsearch.action.get.GetResponse;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.xpack.watcher.client.WatcherClient;
|
||||
import org.elasticsearch.xpack.watcher.condition.never.NeverCondition;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.XContentSource;
|
||||
import org.elasticsearch.xpack.watcher.test.AbstractWatcherIntegrationTestCase;
|
||||
import org.elasticsearch.xpack.watcher.transport.actions.get.GetWatchResponse;
|
||||
|
||||
import static org.elasticsearch.xpack.watcher.actions.ActionBuilders.loggingAction;
|
||||
import static org.elasticsearch.xpack.watcher.client.WatchSourceBuilders.watchBuilder;
|
||||
import static org.elasticsearch.xpack.watcher.condition.ConditionBuilders.neverCondition;
|
||||
import static org.elasticsearch.xpack.watcher.input.InputBuilders.simpleInput;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.TriggerBuilders.schedule;
|
||||
import static org.elasticsearch.xpack.watcher.trigger.schedule.IntervalSchedule.Interval.Unit.SECONDS;
|
||||
|
@ -35,7 +35,7 @@ public class WatchStatusIntegrationTests extends AbstractWatcherIntegrationTestC
|
|||
.setSource(watchBuilder()
|
||||
.trigger(schedule(interval(5, SECONDS)))
|
||||
.input(simpleInput())
|
||||
.condition(neverCondition())
|
||||
.condition(NeverCondition.INSTANCE)
|
||||
.addAction("_logger", loggingAction("logged text")))
|
||||
.get();
|
||||
timeWarp().scheduler().trigger("_name");
|
||||
|
|
Loading…
Reference in New Issue