From ee520c3c703437968f1b254ae96bf9f091c2abce Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Mon, 17 Oct 2016 22:45:42 +0200 Subject: [PATCH] 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@8c82efeb23a56ab6c93bc27962a75109280b7aa3 --- .../watcher/client/WatchSourceBuilder.java | 12 ++--- .../xpack/watcher/condition/Condition.java | 5 -- .../watcher/condition/ConditionBuilders.java | 44 ---------------- .../watcher/condition/ConditionRegistry.java | 7 --- .../condition/always/AlwaysCondition.java | 9 ---- .../condition/compare/CompareCondition.java | 21 -------- .../compare/array/ArrayCompareCondition.java | 24 --------- .../condition/never/NeverCondition.java | 9 ---- .../condition/script/ScriptCondition.java | 18 ------- .../email/EmailSecretsIntegrationTests.java | 4 +- .../actions/TimeThrottleIntegrationTests.java | 5 +- .../actions/email/EmailAttachmentTests.java | 3 +- .../webhook/WebhookHttpsIntegrationTests.java | 6 +-- .../webhook/WebhookIntegrationTests.java | 6 +-- .../execution/ManualExecutionTests.java | 15 +++--- .../history/HistoryActionConditionTests.java | 51 +++++++++---------- .../HistoryTemplateEmailMappingsTests.java | 4 +- .../HistoryTemplateHttpMappingsTests.java | 4 +- ...storyTemplateSearchInputMappingsTests.java | 4 +- .../HistoryTemplateTimeMappingsTests.java | 4 +- ...HistoryTemplateTransformMappingsTests.java | 6 +-- .../watcher/input/chain/ChainInputTests.java | 5 +- .../input/http/HttpInputIntegrationTests.java | 9 ++-- .../DynamicIndexNameIntegrationTests.java | 4 +- .../WatcherExecutorServiceBenchmark.java | 9 ++-- .../bench/WatcherScheduleEngineBenchmark.java | 4 +- .../test/integration/BasicWatcherTests.java | 31 ++++++----- .../test/integration/BootStrapTests.java | 8 ++- .../ExecutionVarsIntegrationTests.java | 9 ++-- .../test/integration/HipChatServiceTests.java | 4 +- .../HttpSecretsIntegrationTests.java | 6 +-- .../test/integration/NoMasterNodeTests.java | 9 ++-- .../integration/PagerDutyServiceTests.java | 4 +- .../test/integration/SlackServiceTests.java | 4 +- .../test/integration/WatchAckTests.java | 7 ++- .../test/integration/WatchMetadataTests.java | 3 +- .../transform/TransformIntegrationTests.java | 10 ++-- .../action/activate/ActivateWatchTests.java | 6 +-- .../action/delete/DeleteWatchTests.java | 4 +- .../action/delete/ForceDeleteWatchTests.java | 4 +- .../action/execute/ExecuteWatchTests.java | 14 ++--- .../ExecuteWatchWithDateMathTests.java | 4 +- .../transport/action/get/GetWatchTests.java | 4 +- .../transport/action/put/PutWatchTests.java | 6 +-- .../action/stats/SlowWatchStatsTests.java | 6 +-- .../action/stats/WatcherStatsTests.java | 3 +- .../watch/WatchStatusIntegrationTests.java | 4 +- 47 files changed, 147 insertions(+), 295 deletions(-) delete mode 100644 elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionBuilders.java diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatchSourceBuilder.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatchSourceBuilder.java index 090804a22b2..eaf1d3ad352 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatchSourceBuilder.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/client/WatchSourceBuilder.java @@ -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) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/Condition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/Condition.java index 4b3e67cc6e5..3d81ec8c930 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/Condition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/Condition.java @@ -76,11 +76,6 @@ public interface Condition extends ToXContent { protected abstract XContentBuilder typeXContent(XContentBuilder builder, Params params) throws IOException; } - interface Builder { - - C build(); - } - interface Field { ParseField TYPE = new ParseField("type"); ParseField STATUS = new ParseField("status"); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionBuilders.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionBuilders.java deleted file mode 100644 index 41845ced491..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionBuilders.java +++ /dev/null @@ -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); - } -} diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java index cecce51af50..a44715c4f53 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/ConditionRegistry.java @@ -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(); - } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/always/AlwaysCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/always/AlwaysCondition.java index dba05654bfc..40ae9e2069f 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/always/AlwaysCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/always/AlwaysCondition.java @@ -53,13 +53,4 @@ public class AlwaysCondition implements Condition { return builder; } } - - public static class Builder implements Condition.Builder { - - public static final Builder INSTANCE = new Builder(); - - public AlwaysCondition build() { - return AlwaysCondition.INSTANCE; - } - } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/CompareCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/CompareCondition.java index 7b8033760df..aac9b1a278e 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/CompareCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/CompareCondition.java @@ -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 { - - 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"); } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/array/ArrayCompareCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/array/ArrayCompareCondition.java index 7ebece922d3..9e62f9ee9b1 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/array/ArrayCompareCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/compare/array/ArrayCompareCondition.java @@ -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 { - 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"); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/never/NeverCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/never/NeverCondition.java index 19540cf863c..f614aea10a4 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/never/NeverCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/never/NeverCondition.java @@ -53,13 +53,4 @@ public class NeverCondition implements Condition { return builder; } } - - public static class Builder implements Condition.Builder { - - public static final Builder INSTANCE = new Builder(); - - public NeverCondition build() { - return NeverCondition.INSTANCE; - } - } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/script/ScriptCondition.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/script/ScriptCondition.java index 46ff0aa8f9d..4b32d8efe84 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/script/ScriptCondition.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/condition/script/ScriptCondition.java @@ -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 { - - private final Script script; - - private Builder(Script script) { - this.script = script; - } - - @Override - public ScriptCondition build() { - return new ScriptCondition(script); - } - } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java index 6a80a44352e..03d0d8e5baa 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/notification/email/EmailSecretsIntegrationTests.java @@ -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") diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java index 23b419a1684..0ae77de7eef 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/TimeThrottleIntegrationTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailAttachmentTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailAttachmentTests.java index 9c6795a1778..b052ed605bb 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailAttachmentTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/email/EmailAttachmentTests.java @@ -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()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java index cc0aa1efdd4..a9167558542 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookHttpsIntegrationTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java index 5dcce5de64f..0c54692bdbe 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/webhook/WebhookIntegrationTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java index 4a91ba36dd5..51bf299acec 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java index 89542bff733..cc60d05fa2e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryActionConditionTests.java @@ -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> 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 actionConditionsWithFailure = - Lists.newArrayList(scriptConditionFailsHard, conditionPasses, alwaysCondition()); + final Condition scriptConditionFailsHard = mockScriptCondition("throw new IllegalStateException('failed');"); + final List 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 actionConditionsWithFailure = Lists.newArrayList(conditionFails, conditionPasses, alwaysCondition()); + final List 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 logging = (Map)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 actionConditions = Lists.newArrayList(conditionPasses); + final List 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); } } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java index d68f4857de2..b915a05cef5 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateEmailMappingsTests.java @@ -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") diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java index 167e1a53a99..81dd65da8ee 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateHttpMappingsTests.java @@ -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")))) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java index 5569620f5cc..eef85fbc85a 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateSearchInputMappingsTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java index 185cec03b8e..c1620f797b7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTimeMappingsTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTransformMappingsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTransformMappingsTests.java index 327d4145daf..5649afd378e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTransformMappingsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/history/HistoryTemplateTransformMappingsTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java index 1efb0e27a49..bd85a35932e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputTests.java @@ -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); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java index 015403044f7..d2ce711a689 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputIntegrationTests.java @@ -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()) { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java index 8e3de1da447..dbf654d950a 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/support/DynamicIndexNameIntegrationTests.java @@ -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("", "type"))) .get(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java index 92773b5f600..eb80263f55d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherExecutorServiceBenchmark.java @@ -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(); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java index 3e1d4bcb636..537543563e1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/bench/WatcherScheduleEngineBenchmark.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java index 55f3b8cf043..05db0745b94 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BasicWatcherTests.java @@ -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()); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java index 74b36ec3ce4..ed565e650d9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/BootStrapTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java index c24e7f23c46..03d45bff3ce 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/ExecutionVarsIntegrationTests.java @@ -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", diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HipChatServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HipChatServiceTests.java index d0a03c5ffa2..3011f9923a3 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HipChatServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HipChatServiceTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java index 92c5b8758f1..a9a04b8d1e9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/HttpSecretsIntegrationTests.java @@ -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()))))) diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java index d1b18a3438d..928225248d5 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/NoMasterNodeTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/PagerDutyServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/PagerDutyServiceTests.java index a2dae9eef1e..44a81f0085d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/PagerDutyServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/PagerDutyServiceTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SlackServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SlackServiceTests.java index bdea9cef903..b5582777ecb 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SlackServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SlackServiceTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java index 197edcb1652..9e1b7b4d76b 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchAckTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java index b618026b3bd..db954e87470 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/WatchMetadataTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java index a5cdd38f358..9eb280ea4b9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transform/TransformIntegrationTests.java @@ -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.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.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.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.newMapBuilder().put("key1", 10).put("key2", 10))) - .condition(alwaysCondition()) + .condition(AlwaysCondition.INSTANCE) .addAction("_id", chainTransform(scriptTransform(script1), scriptTransform(script2)), indexAction("output2", "type"))) .get(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java index 8c8f7a86292..a596f617baf 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/activate/ActivateWatchTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java index 5cdaa54a839..d52ab567bfe 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/DeleteWatchTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/ForceDeleteWatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/ForceDeleteWatchTests.java index 6cd8250de85..c5e50734273 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/ForceDeleteWatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/delete/ForceDeleteWatchTests.java @@ -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")); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java index ad9667b8c71..e594ca62ec2 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchWithDateMathTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchWithDateMathTests.java index 3eeaf78c64c..a8ce18346a9 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchWithDateMathTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchWithDateMathTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java index ee1132d90c7..196162e6a9e 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/get/GetWatchTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/put/PutWatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/put/PutWatchTests.java index 59ee43969df..b16ebb337f7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/put/PutWatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/put/PutWatchTests.java @@ -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"); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/SlowWatchStatsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/SlowWatchStatsTests.java index a4d05811d59..2f1293c12a4 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/SlowWatchStatsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/SlowWatchStatsTests.java @@ -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(); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java index 8b1a3b91692..4327072342d 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/transport/action/stats/WatcherStatsTests.java @@ -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(); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java index 6c2f86e6f0c..32b404a63be 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStatusIntegrationTests.java @@ -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");