diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java index 7edde1b9fc6..431e5f885d8 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ActionRegistry.java @@ -43,7 +43,7 @@ public class ActionRegistry { return parsers.get(type); } - public ExecutableActions parseActions(String watchId, XContentParser parser, boolean upgradeActionSource) throws IOException { + public List parseActions(String watchId, XContentParser parser, boolean upgradeActionSource) throws IOException { if (parser.currentToken() != XContentParser.Token.START_OBJECT) { throw new ElasticsearchParseException("could not parse actions for watch [{}]. expected an object but found [{}] instead", watchId, parser.currentToken()); @@ -64,7 +64,7 @@ public class ActionRegistry { licenseState, upgradeActionSource)); } } - return new ExecutableActions(actions); + return actions; } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ExecutableActions.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ExecutableActions.java deleted file mode 100644 index 0425804abcf..00000000000 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/actions/ExecutableActions.java +++ /dev/null @@ -1,113 +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.actions; - -import org.elasticsearch.common.xcontent.ToXContent; -import org.elasticsearch.common.xcontent.XContentBuilder; - -import java.io.IOException; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -public class ExecutableActions implements Iterable, ToXContent { - - private final List actions; - - public ExecutableActions(List actions) { - this.actions = actions; - } - - public int count() { - return actions.size(); - } - - @Override - public Iterator iterator() { - return actions.iterator(); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startObject(); - for (ActionWrapper action : actions) { - builder.field(action.id(), action, params); - } - return builder.endObject(); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - ExecutableActions actions1 = (ExecutableActions) o; - - if (!actions.equals(actions1.actions)) return false; - - return true; - } - - @Override - public int hashCode() { - return actions.hashCode(); - } - - public static class Results implements Iterable, ToXContent { - - private final Map results; - - public Results(Map results) { - this.results = results; - } - - public int count() { - return results.size(); - } - - @Override - public Iterator iterator() { - return results.values().iterator(); - } - - public ActionWrapper.Result get(String id) { - return results.get(id); - } - - public boolean throttled() { - for (ActionWrapper.Result result : results.values()) { - if (result.action().status() == Action.Result.Status.THROTTLED) { - return true; - } - } - return false; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - Results results1 = (Results) o; - - return results.equals(results1.results); - } - - @Override - public int hashCode() { - return results.hashCode(); - } - - @Override - public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { - builder.startArray(); - for (ActionWrapper.Result result : results.values()) { - result.toXContent(builder, params); - } - return builder.endArray(); - } - } -} diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java index 99220255f7d..fa7f1a81fcc 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/ExecutionService.java @@ -387,7 +387,7 @@ public class ExecutionService extends AbstractComponent { } if (conditionResult.met()) { - if (watch.actions().count() > 0 && watch.transform() != null) { + if (watch.actions().size() > 0 && watch.transform() != null) { ctx.beforeWatchTransform(); Transform.Result transformResult = watch.transform().execute(ctx, ctx.payload()); ctx.onWatchTransformResult(transformResult); diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java index ef9a2627f54..0f81351c714 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionContext.java @@ -8,7 +8,6 @@ package org.elasticsearch.xpack.watcher.execution; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.util.concurrent.ConcurrentCollections; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.condition.Condition; import org.elasticsearch.xpack.watcher.history.WatchRecord; import org.elasticsearch.xpack.watcher.input.Input; @@ -18,6 +17,7 @@ import org.elasticsearch.xpack.watcher.watch.Payload; import org.elasticsearch.xpack.watcher.watch.Watch; import org.joda.time.DateTime; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ConcurrentMap; @@ -180,8 +180,8 @@ public abstract class WatchExecutionContext { } } - public ExecutableActions.Results actionsResults() { - return new ExecutableActions.Results(actionsResults); + public Map actionsResults() { + return Collections.unmodifiableMap(actionsResults); } public WatchRecord abortBeforeExecution(ExecutionState state, String message) { diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionResult.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionResult.java index e6733f19e76..12456ce873d 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionResult.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionResult.java @@ -9,7 +9,7 @@ import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; +import org.elasticsearch.xpack.watcher.actions.ActionWrapper; import org.elasticsearch.xpack.watcher.condition.Condition; import org.elasticsearch.xpack.watcher.input.Input; import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils; @@ -17,6 +17,7 @@ import org.elasticsearch.xpack.watcher.transform.Transform; import org.joda.time.DateTime; import java.io.IOException; +import java.util.Map; public class WatchExecutionResult implements ToXContent { @@ -25,7 +26,7 @@ public class WatchExecutionResult implements ToXContent { @Nullable private final Input.Result inputResult; @Nullable private final Condition.Result conditionResult; @Nullable private final Transform.Result transformResult; - private final ExecutableActions.Results actionsResults; + private final Map actionsResults; public WatchExecutionResult(WatchExecutionContext context, long executionDurationMs) { this(context.executionTime(), executionDurationMs, context.inputResult(), context.conditionResult(), context.transformResult(), @@ -33,7 +34,7 @@ public class WatchExecutionResult implements ToXContent { } WatchExecutionResult(DateTime executionTime, long executionDurationMs, Input.Result inputResult, Condition.Result conditionResult, - @Nullable Transform.Result transformResult, ExecutableActions.Results actionsResults) { + @Nullable Transform.Result transformResult, Map actionsResults) { this.executionTime = executionTime; this.inputResult = inputResult; this.conditionResult = conditionResult; @@ -62,7 +63,7 @@ public class WatchExecutionResult implements ToXContent { return transformResult; } - public ExecutableActions.Results actionsResults() { + public Map actionsResults() { return actionsResults; } @@ -82,7 +83,11 @@ public class WatchExecutionResult implements ToXContent { if (transformResult != null) { builder.field(Transform.Field.TRANSFORM.getPreferredName(), transformResult, params); } - builder.field(Field.ACTIONS.getPreferredName(), actionsResults, params); + builder.startArray(Field.ACTIONS.getPreferredName()); + for (ActionWrapper.Result result : actionsResults.values()) { + result.toXContent(builder, params); + } + builder.endArray(); builder.endObject(); return builder; } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionSnapshot.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionSnapshot.java index fbf29f3e48a..f5912775121 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionSnapshot.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/execution/WatchExecutionSnapshot.java @@ -11,11 +11,11 @@ import org.elasticsearch.common.io.stream.Streamable; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.joda.time.DateTime; import org.joda.time.DateTimeZone; import java.io.IOException; +import java.util.Map; public class WatchExecutionSnapshot implements Streamable, ToXContent { @@ -38,10 +38,10 @@ public class WatchExecutionSnapshot implements Streamable, ToXContent { executionTime = context.executionTime(); phase = context.executionPhase(); if (phase == ExecutionPhase.ACTIONS) { - ExecutableActions.Results actionResults = context.actionsResults(); - executedActions = new String[actionResults.count()]; + Map actionResults = context.actionsResults(); + executedActions = new String[actionResults.size()]; int i = 0; - for (ActionWrapper.Result actionResult : actionResults) { + for (ActionWrapper.Result actionResult : actionResults.values()) { executedActions[i++] = actionResult.id(); } } diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/WatchRecord.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/WatchRecord.java index 7629e69421b..b0ed4711baa 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/WatchRecord.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/history/WatchRecord.java @@ -12,6 +12,8 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.collect.MapBuilder; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.xpack.watcher.actions.Action; +import org.elasticsearch.xpack.watcher.actions.ActionWrapper; import org.elasticsearch.xpack.watcher.condition.Condition; import org.elasticsearch.xpack.watcher.execution.ExecutionState; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; @@ -23,6 +25,7 @@ import org.elasticsearch.xpack.watcher.trigger.TriggerEvent; import org.elasticsearch.xpack.watcher.watch.Watch; import java.io.IOException; +import java.util.Collection; import java.util.Collections; import java.util.Map; import java.util.Objects; @@ -75,9 +78,9 @@ public abstract class WatchRecord implements ToXContent { if (executionResult == null || executionResult.conditionResult() == null) { return ExecutionState.FAILED; } - if (executionResult.conditionResult().met()) { - if (executionResult.actionsResults().throttled()) { + final Collection values = executionResult.actionsResults().values(); + if (values.stream().anyMatch((r) -> r.action().status() == Action.Result.Status.THROTTLED)) { return ExecutionState.THROTTLED; } else { return ExecutionState.EXECUTED; diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/watch/Watch.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/watch/Watch.java index a92e9d6ab61..4192ec962fb 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/watch/Watch.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/watcher/watch/Watch.java @@ -26,7 +26,6 @@ import org.elasticsearch.xpack.watcher.Watcher; import org.elasticsearch.xpack.watcher.actions.ActionRegistry; import org.elasticsearch.xpack.watcher.actions.ActionStatus; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.condition.ConditionRegistry; import org.elasticsearch.xpack.watcher.condition.ExecutableCondition; import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition; @@ -42,11 +41,11 @@ import org.elasticsearch.xpack.watcher.trigger.Trigger; import org.elasticsearch.xpack.watcher.trigger.TriggerEngine; import org.elasticsearch.xpack.watcher.trigger.TriggerService; import org.joda.time.DateTime; -import org.joda.time.PeriodType; import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; @@ -66,7 +65,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { private final ExecutableInput input; private final ExecutableCondition condition; @Nullable private final ExecutableTransform transform; - private final ExecutableActions actions; + private final List actions; @Nullable private final TimeValue throttlePeriod; @Nullable private final Map metadata; private final WatchStatus status; @@ -76,7 +75,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { private transient long version = Versions.MATCH_ANY; public Watch(String id, Trigger trigger, ExecutableInput input, ExecutableCondition condition, @Nullable ExecutableTransform transform, - @Nullable TimeValue throttlePeriod, ExecutableActions actions, @Nullable Map metadata, + @Nullable TimeValue throttlePeriod, List actions, @Nullable Map metadata, WatchStatus status) { this.id = id; this.trigger = trigger; @@ -113,7 +112,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { return throttlePeriod; } - public ExecutableActions actions() { + public List actions() { return actions; } @@ -187,7 +186,11 @@ public class Watch implements TriggerEngine.Job, ToXContent { builder.timeValueField(Field.THROTTLE_PERIOD.getPreferredName(), Field.THROTTLE_PERIOD_HUMAN.getPreferredName(), throttlePeriod); } - builder.field(Field.ACTIONS.getPreferredName(), actions, params); + builder.startObject(Field.ACTIONS.getPreferredName()); + for (ActionWrapper action : actions) { + builder.field(action.id(), action, params); + } + builder.endObject(); if (metadata != null) { builder.field(Field.METADATA.getPreferredName(), metadata); } @@ -214,7 +217,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { private final CryptoService cryptoService; private final ExecutableInput defaultInput; private final ExecutableCondition defaultCondition; - private final ExecutableActions defaultActions; + private final List defaultActions; private final Clock clock; @Inject @@ -231,7 +234,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { this.cryptoService = Watcher.ENCRYPT_SENSITIVE_DATA_SETTING.get(settings) ? cryptoService : null; this.defaultInput = new ExecutableNoneInput(logger); this.defaultCondition = new ExecutableAlwaysCondition(logger); - this.defaultActions = new ExecutableActions(Collections.emptyList()); + this.defaultActions = Collections.emptyList(); this.clock = clock; } @@ -286,7 +289,7 @@ public class Watch implements TriggerEngine.Job, ToXContent { Trigger trigger = null; ExecutableInput input = defaultInput; ExecutableCondition condition = defaultCondition; - ExecutableActions actions = defaultActions; + List actions = defaultActions; ExecutableTransform transform = null; TimeValue throttlePeriod = null; Map metatdata = null; diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java index 6f49045c88c..7c57bff8e45 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/actions/throttler/ActionThrottleTests.java @@ -127,7 +127,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase { ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS)); WatchRecord watchRecord = executionService().execute(ctx); - for (ActionWrapper.Result result : watchRecord.result().actionsResults()) { + for (ActionWrapper.Result result : watchRecord.result().actionsResults().values()) { if (ackingActions.contains(result.id())) { assertThat(result.action().status(), equalTo(Action.Result.Status.THROTTLED)); } else { @@ -157,12 +157,12 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase { ManualExecutionContext ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS)); WatchRecord watchRecord = executionService().execute(ctx); long firstExecution = System.currentTimeMillis(); - for(ActionWrapper.Result actionResult : watchRecord.result().actionsResults()) { + for(ActionWrapper.Result actionResult : watchRecord.result().actionsResults().values()) { assertThat(actionResult.action().status(), equalTo(Action.Result.Status.SIMULATED)); } ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS)); watchRecord = executionService().execute(ctx); - for(ActionWrapper.Result actionResult : watchRecord.result().actionsResults()) { + for(ActionWrapper.Result actionResult : watchRecord.result().actionsResults().values()) { assertThat(actionResult.action().status(), equalTo(Action.Result.Status.THROTTLED)); } @@ -175,7 +175,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase { public void run() { ManualExecutionContext ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS)); WatchRecord watchRecord = executionService().execute(ctx); - for (ActionWrapper.Result actionResult : watchRecord.result().actionsResults()) { + for (ActionWrapper.Result actionResult : watchRecord.result().actionsResults().values()) { if ("ten_sec_throttle".equals(actionResult.id())) { assertThat(actionResult.action().status(), equalTo(Action.Result.Status.SIMULATED)); } else { diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java index 22c2b130c33..3edd5a517e1 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/execution/ExecutionServiceTests.java @@ -19,7 +19,6 @@ import org.elasticsearch.xpack.watcher.actions.Action; import org.elasticsearch.xpack.watcher.actions.ActionStatus; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.actions.throttler.ActionThrottler; import org.elasticsearch.xpack.watcher.actions.throttler.Throttler; import org.elasticsearch.xpack.watcher.condition.Condition; @@ -168,14 +167,13 @@ public class ExecutionServiceTests extends ESTestCase { when(action.execute("_action", context, payload)).thenReturn(actionResult); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC()))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.execute(context); @@ -248,14 +246,12 @@ public class ExecutionServiceTests extends ESTestCase { when(action.execute("_action", context, payload)).thenReturn(actionResult); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC()))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.execute(context); @@ -263,7 +259,7 @@ public class ExecutionServiceTests extends ESTestCase { assertThat(watchRecord.result().conditionResult(), nullValue()); assertThat(watchRecord.result().transformResult(), nullValue()); assertThat(watchRecord.result().actionsResults(), notNullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(0)); + assertThat(watchRecord.result().actionsResults().size(), is(0)); verify(historyStore, times(1)).put(watchRecord); verify(releasable, times(1)).close(); @@ -315,14 +311,12 @@ public class ExecutionServiceTests extends ESTestCase { when(action.execute("_action", context, payload)).thenReturn(actionResult); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC()))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.execute(context); @@ -330,7 +324,7 @@ public class ExecutionServiceTests extends ESTestCase { assertThat(watchRecord.result().conditionResult(), is(conditionResult)); assertThat(watchRecord.result().transformResult(), nullValue()); assertThat(watchRecord.result().actionsResults(), notNullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(0)); + assertThat(watchRecord.result().actionsResults().size(), is(0)); verify(historyStore, times(1)).put(watchRecord); verify(releasable, times(1)).close(); @@ -381,14 +375,12 @@ public class ExecutionServiceTests extends ESTestCase { when(action.execute("_action", context, payload)).thenReturn(actionResult); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC()))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.execute(context); @@ -396,7 +388,7 @@ public class ExecutionServiceTests extends ESTestCase { assertThat(watchRecord.result().conditionResult(), is(conditionResult)); assertThat(watchRecord.result().transformResult(), is(watchTransformResult)); assertThat(watchRecord.result().actionsResults(), notNullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(0)); + assertThat(watchRecord.result().actionsResults().size(), is(0)); verify(historyStore, times(1)).put(watchRecord); verify(releasable, times(1)).close(); @@ -461,14 +453,13 @@ public class ExecutionServiceTests extends ESTestCase { when(action.execute("_action", context, payload)).thenReturn(actionResult); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC()))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.execute(context); @@ -476,7 +467,7 @@ public class ExecutionServiceTests extends ESTestCase { assertThat(watchRecord.result().conditionResult(), is(conditionResult)); assertThat(watchRecord.result().transformResult(), is(watchTransformResult)); assertThat(watchRecord.result().actionsResults(), notNullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(1)); + assertThat(watchRecord.result().actionsResults().size(), is(1)); assertThat(watchRecord.result().actionsResults().get("_action").condition(), is(actionConditionResult)); assertThat(watchRecord.result().actionsResults().get("_action").transform(), is(actionTransformResult)); assertThat(watchRecord.result().actionsResults().get("_action").action().status(), is(Action.Result.Status.FAILURE)); @@ -542,14 +533,12 @@ public class ExecutionServiceTests extends ESTestCase { when(action.execute("_action", context, payload)).thenReturn(actionResult); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.executeInner(context); @@ -591,20 +580,18 @@ public class ExecutionServiceTests extends ESTestCase { ExecutableAction action = mock(ExecutableAction.class); when(action.type()).thenReturn("_type"); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.executeInner(context); assertThat(watchRecord.result().inputResult(), sameInstance(inputResult)); assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult)); assertThat(watchRecord.result().transformResult(), nullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(1)); + assertThat(watchRecord.result().actionsResults().size(), is(1)); ActionWrapper.Result result = watchRecord.result().actionsResults().get("_action"); assertThat(result, notNullValue()); assertThat(result.id(), is("_action")); @@ -654,20 +641,18 @@ public class ExecutionServiceTests extends ESTestCase { ExecutableAction action = mock(ExecutableAction.class); when(action.type()).thenReturn("_type"); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.executeInner(context); assertThat(watchRecord.result().inputResult(), sameInstance(inputResult)); assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult)); assertThat(watchRecord.result().transformResult(), nullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(1)); + assertThat(watchRecord.result().actionsResults().size(), is(1)); ActionWrapper.Result result = watchRecord.result().actionsResults().get("_action"); assertThat(result, notNullValue()); assertThat(result.id(), is("_action")); @@ -711,20 +696,18 @@ public class ExecutionServiceTests extends ESTestCase { when(action.type()).thenReturn("_type"); when(action.logger()).thenReturn(logger); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); - WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.executeInner(context); assertThat(watchRecord.result().inputResult(), sameInstance(inputResult)); assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult)); assertThat(watchRecord.result().transformResult(), nullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(1)); + assertThat(watchRecord.result().actionsResults().size(), is(1)); ActionWrapper.Result result = watchRecord.result().actionsResults().get("_action"); assertThat(result, notNullValue()); assertThat(result.id(), is("_action")); @@ -759,21 +742,20 @@ public class ExecutionServiceTests extends ESTestCase { ExecutableTransform actionTransform = mock(ExecutableTransform.class); ExecutableAction action = mock(ExecutableAction.class); ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action); - ExecutableActions actions = new ExecutableActions(Arrays.asList(actionWrapper)); WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now))); when(watch.input()).thenReturn(input); when(watch.condition()).thenReturn(condition); when(watch.transform()).thenReturn(watchTransform); - when(watch.actions()).thenReturn(actions); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); when(watch.status()).thenReturn(watchStatus); WatchRecord watchRecord = executionService.executeInner(context); assertThat(watchRecord.result().inputResult(), sameInstance(inputResult)); assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult)); assertThat(watchRecord.result().transformResult(), nullValue()); - assertThat(watchRecord.result().actionsResults().count(), is(0)); + assertThat(watchRecord.result().actionsResults().size(), is(0)); verify(condition, times(1)).execute(context); verify(watchTransform, never()).execute(context, payload); 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 51bf299acec..4b514887af8 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 @@ -170,9 +170,9 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase { assertThat("the expected count of history records should be [" + expectedCount + "]", newRecordCount, equalTo(expectedCount)); if (ignoreCondition) { - assertThat("The action should have run", watchRecord.result().actionsResults().count(), equalTo(1)); + assertThat("The action should have run", watchRecord.result().actionsResults().size(), equalTo(1)); } else if (!conditionAlwaysTrue) { - assertThat("The action should not have run", watchRecord.result().actionsResults().count(), equalTo(0)); + assertThat("The action should not have run", watchRecord.result().actionsResults().size(), equalTo(0)); } if ((ignoreCondition || conditionAlwaysTrue) && action == null) { 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 bd85a35932e..d3b9b7970bf 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 @@ -17,7 +17,6 @@ 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; @@ -175,7 +174,7 @@ public class ChainInputTests extends ESTestCase { new ExecutableAlwaysCondition(logger), null, null, - new ExecutableActions(new ArrayList<>()), + new ArrayList<>(), null, new WatchStatus(new DateTime(0, UTC), emptyMap())); WatchExecutionContext ctx = new TriggeredExecutionContext(watch, diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java index 668270898f1..9a72aa91526 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/input/http/HttpInputTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth; import org.elasticsearch.xpack.common.http.auth.basic.BasicAuthFactory; import org.elasticsearch.xpack.common.text.TextTemplate; import org.elasticsearch.xpack.common.text.TextTemplateEngine; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition; import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; @@ -309,7 +308,7 @@ public class HttpInputTests extends ESTestCase { new ExecutableAlwaysCondition(logger), null, null, - new ExecutableActions(new ArrayList<>()), + new ArrayList<>(), null, new WatchStatus(new DateTime(0, UTC), emptyMap())); return new TriggeredExecutionContext(watch, diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java index 1bdb2e941d8..0c5130fd290 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/WatcherTestUtils.java @@ -40,7 +40,6 @@ import org.elasticsearch.xpack.notification.email.HtmlSanitizer; import org.elasticsearch.xpack.notification.email.Profile; import org.elasticsearch.xpack.watcher.actions.ActionStatus; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.actions.email.EmailAction; import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction; import org.elasticsearch.xpack.watcher.actions.webhook.ExecutableWebhookAction; @@ -236,7 +235,7 @@ public final class WatcherTestUtils { new ExecutableAlwaysCondition(logger), new ExecutableSearchTransform(searchTransform, logger, client, searchTemplateService, null), new TimeValue(0), - new ExecutableActions(actions), + actions, metadata, new WatchStatus(now, statuses)); } diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java index ade75ead221..80e8afeec47 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchInputTests.java @@ -22,7 +22,6 @@ import org.elasticsearch.search.SearchRequestParsers; import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition; import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; @@ -87,7 +86,7 @@ public class SearchInputTests extends ESIntegTestCase { new ExecutableAlwaysCondition(logger), null, null, - new ExecutableActions(new ArrayList<>()), + new ArrayList<>(), null, new WatchStatus(new DateTime(0, UTC), emptyMap())), new DateTime(0, UTC), @@ -119,7 +118,7 @@ public class SearchInputTests extends ESIntegTestCase { new ExecutableAlwaysCondition(logger), null, null, - new ExecutableActions(new ArrayList<>()), + new ArrayList<>(), null, new WatchStatus(new DateTime(0, UTC), emptyMap())), new DateTime(0, UTC), diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java index 0a43d05fa66..f0f41d27cfa 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/test/integration/SearchTransformTests.java @@ -27,7 +27,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.ESIntegTestCase.ClusterScope; import org.elasticsearch.xpack.common.text.TextTemplate; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition; import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; @@ -262,7 +261,7 @@ public class SearchTransformTests extends ESIntegTestCase { new ExecutableAlwaysCondition(logger), null, null, - new ExecutableActions(new ArrayList<>()), + new ArrayList<>(), null, new WatchStatus( new DateTime(40000, UTC), emptyMap())), new DateTime(60000, UTC), diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStoreTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStoreTests.java index 06ab49cd227..bdfa3b9652c 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStoreTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchStoreTests.java @@ -34,7 +34,6 @@ import org.elasticsearch.search.internal.InternalSearchHits; import org.elasticsearch.test.ESTestCase; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; import org.elasticsearch.xpack.watcher.actions.ExecutableAction; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition; import org.elasticsearch.xpack.watcher.condition.never.ExecutableNeverCondition; import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext; @@ -286,7 +285,7 @@ public class WatchStoreTests extends ESTestCase { ExecutableAction action = mock(ExecutableAction.class); when(actionWrapper.action()).thenReturn(action); when(action.type()).thenReturn(randomFrom("a", "b", "c")); - when(watch.actions()).thenReturn(new ExecutableActions(Arrays.asList(actionWrapper))); + when(watch.actions()).thenReturn(Arrays.asList(actionWrapper)); // random transform, not always set Transform mockTransform = mock(Transform.class); diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java index 6a95bc9b246..0bf93f36eb7 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/watcher/watch/WatchTests.java @@ -44,7 +44,6 @@ import org.elasticsearch.xpack.watcher.actions.ActionFactory; import org.elasticsearch.xpack.watcher.actions.ActionRegistry; import org.elasticsearch.xpack.watcher.actions.ActionStatus; import org.elasticsearch.xpack.watcher.actions.ActionWrapper; -import org.elasticsearch.xpack.watcher.actions.ExecutableActions; import org.elasticsearch.xpack.watcher.actions.email.EmailAction; import org.elasticsearch.xpack.watcher.actions.email.EmailActionFactory; import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction; @@ -191,7 +190,7 @@ public class WatchTests extends ESTestCase { ExecutableTransform transform = randomTransform(); - ExecutableActions actions = randomActions(); + List actions = randomActions(); ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry); Map metadata = singletonMap("_key", "_val"); @@ -237,7 +236,7 @@ public class WatchTests extends ESTestCase { TransformRegistry transformRegistry = transformRegistry(); - ExecutableActions actions = randomActions(); + List actions = randomActions(); ActionRegistry actionRegistry = registry(actions,conditionRegistry, transformRegistry); @@ -264,8 +263,7 @@ public class WatchTests extends ESTestCase { ConditionRegistry conditionRegistry = conditionRegistry(); InputRegistry inputRegistry = registry(new ExecutableNoneInput(logger).type()); TransformRegistry transformRegistry = transformRegistry(); - ExecutableActions actions = new ExecutableActions(Collections.emptyList()); - ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry); + ActionRegistry actionRegistry = registry(Collections.emptyList(), conditionRegistry, transformRegistry); XContentBuilder builder = XContentFactory.jsonBuilder(); builder.startObject(); @@ -282,7 +280,7 @@ public class WatchTests extends ESTestCase { assertThat(watch.condition(), instanceOf(ExecutableAlwaysCondition.class)); assertThat(watch.transform(), nullValue()); assertThat(watch.actions(), notNullValue()); - assertThat(watch.actions().count(), is(0)); + assertThat(watch.actions().size(), is(0)); } public void testParseWatch_verifyScriptLangDefault() throws Exception { @@ -294,8 +292,7 @@ public class WatchTests extends ESTestCase { ConditionRegistry conditionRegistry = conditionRegistry(); InputRegistry inputRegistry = registry(SearchInput.TYPE); TransformRegistry transformRegistry = transformRegistry(); - ExecutableActions actions = new ExecutableActions(Collections.emptyList()); - ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry); + ActionRegistry actionRegistry = registry(Collections.emptyList(), conditionRegistry, transformRegistry); Watch.Parser watchParser = new Watch.Parser(settings, conditionRegistry, triggerService, transformRegistry, actionRegistry, inputRegistry, null, SystemClock.INSTANCE); @@ -508,7 +505,7 @@ public class WatchTests extends ESTestCase { return new TransformRegistry(Settings.EMPTY, unmodifiableMap(factories)); } - private ExecutableActions randomActions() { + private List randomActions() { List list = new ArrayList<>(); if (randomBoolean()) { EmailAction action = new EmailAction(EmailTemplate.builder().build(), null, null, Profile.STANDARD, @@ -532,10 +529,10 @@ public class WatchTests extends ESTestCase { list.add(new ActionWrapper("_webhook_" + randomAsciiOfLength(8), randomThrottler(), randomCondition(), randomTransform(), new ExecutableWebhookAction(action, logger, httpClient, templateEngine))); } - return new ExecutableActions(list); + return list; } - private ActionRegistry registry(ExecutableActions actions, ConditionRegistry conditionRegistry, TransformRegistry transformRegistry) { + private ActionRegistry registry(List actions, ConditionRegistry conditionRegistry, TransformRegistry transformRegistry) { Map parsers = new HashMap<>(); for (ActionWrapper action : actions) { switch (action.action().type()) {