diff --git a/plugin/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java b/plugin/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java index ec0c7ff7e98..b23ebc6c157 100644 --- a/plugin/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java +++ b/plugin/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java @@ -141,9 +141,7 @@ public abstract class WatchExecutionContext { public void onConditionResult(Condition.Result conditionResult) { assert !phase.sealed(); this.conditionResult = conditionResult; - if (recordExecution()) { - watch.status().onCheck(conditionResult.met(), executionTime); - } + watch.status().onCheck(conditionResult.met(), executionTime); } public Condition.Result conditionResult() { @@ -175,9 +173,7 @@ public abstract class WatchExecutionContext { public void onActionResult(ActionWrapper.Result result) { assert !phase.sealed(); actionsResults.put(result.id(), result); - if (recordExecution()) { - watch.status().onActionResult(result.id(), executionTime, result.action()); - } + watch.status().onActionResult(result.id(), executionTime, result.action()); } public Map actionsResults() { diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java index bd96904640b..3a74335ab2f 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionTests.java @@ -35,6 +35,7 @@ import org.joda.time.DateTimeZone; import java.time.Clock; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.function.Function; @@ -145,6 +146,13 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase { assertThat(response.getStatus().actionStatus("log").ackStatus().state(), is(ActionStatus.AckStatus.State.AWAITS_SUCCESSFUL_EXECUTION)); } + } else { + String ackState = executeWatchResponse.getRecordSource().getValue("_status.actions.log.ack.state"); + if (ignoreCondition || conditionAlwaysTrue) { + assertThat(ackState, is(ActionStatus.AckStatus.State.ACKABLE.toString().toLowerCase(Locale.ROOT))); + } else { + assertThat(ackState, is(ActionStatus.AckStatus.State.AWAITS_SUCCESSFUL_EXECUTION.toString().toLowerCase(Locale.ROOT))); + } } } diff --git a/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java b/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java index 42f30b8be81..b4ed1e2ab59 100644 --- a/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java +++ b/plugin/src/test/java/org/elasticsearch/xpack/watcher/transport/action/execute/ExecuteWatchTests.java @@ -81,6 +81,7 @@ public class ExecuteWatchTests extends AbstractWatcherIntegrationTestCase { assertValue(record, "result.actions.0.type", is("logging")); assertValue(record, "result.actions.0.status", is("success")); assertValue(record, "result.actions.0.logging.logged_text", is("_text")); + assertValue(record, "_status.actions.log.ack.state", is("ackable")); } public void testExecuteCustomTriggerData() throws Exception { diff --git a/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yaml b/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yaml index 02ea0ddc576..ff1035daebc 100644 --- a/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yaml +++ b/plugin/src/test/resources/rest-api-spec/test/watcher/execute_watch/10_basic.yaml @@ -32,7 +32,7 @@ teardown: "actions": { "log" : { "logging" : { - "text" : "execute_watch/10.yaml payload: {{ctx.payload}}" + "text" : "execute_watch/10.yaml payload" } } } @@ -57,6 +57,43 @@ teardown: - match: { watch_record.trigger_event.manual.schedule.scheduled_time: "2000-12-12T12:12:12.120Z" } - match: { watch_record.state: "executed" } - match: { watch_record._status.state.active: true } + - match: { watch_record._status.actions.log.ack.state: "ackable" } + +--- +"Test execute watch API with user supplied watch" + + - do: + xpack.watcher.execute_watch: + id: "test_watch" + body: > + { + "watch" : { + "trigger": { + "schedule" : { "cron" : "0 0 0 1 * ? 2099" } + }, + "input": { + "simple": { + "foo": "bar" + } + }, + "condition": { + "always": {} + }, + "actions": { + "log" : { + "logging" : { + "text" : "execute_watch/10.yaml payload" + } + } + } + } + } + + - match: { watch_record.watch_id: "test_watch" } + - match: { watch_record.trigger_event.type: "manual" } + - match: { watch_record.state: "executed" } + - match: { watch_record._status.state.active: true } + - match: { watch_record._status.actions.log.ack.state: "ackable" } --- "Execute unknown watch results in 404":