Remove ExecutableActions in favor of List and Map (elastic/elasticsearch#3779)
ExecutableActions is really an unnecessary abstraction on top of List and Map. This commit remove the class and all its usage. Original commit: elastic/x-pack-elasticsearch@b938499fcf
This commit is contained in:
parent
6cbd5fec0d
commit
9c54173e74
|
@ -43,7 +43,7 @@ public class ActionRegistry {
|
||||||
return parsers.get(type);
|
return parsers.get(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutableActions parseActions(String watchId, XContentParser parser, boolean upgradeActionSource) throws IOException {
|
public List<ActionWrapper> parseActions(String watchId, XContentParser parser, boolean upgradeActionSource) throws IOException {
|
||||||
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
|
if (parser.currentToken() != XContentParser.Token.START_OBJECT) {
|
||||||
throw new ElasticsearchParseException("could not parse actions for watch [{}]. expected an object but found [{}] instead",
|
throw new ElasticsearchParseException("could not parse actions for watch [{}]. expected an object but found [{}] instead",
|
||||||
watchId, parser.currentToken());
|
watchId, parser.currentToken());
|
||||||
|
@ -64,7 +64,7 @@ public class ActionRegistry {
|
||||||
licenseState, upgradeActionSource));
|
licenseState, upgradeActionSource));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new ExecutableActions(actions);
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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<ActionWrapper>, ToXContent {
|
|
||||||
|
|
||||||
private final List<ActionWrapper> actions;
|
|
||||||
|
|
||||||
public ExecutableActions(List<ActionWrapper> actions) {
|
|
||||||
this.actions = actions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int count() {
|
|
||||||
return actions.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<ActionWrapper> 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<ActionWrapper.Result>, ToXContent {
|
|
||||||
|
|
||||||
private final Map<String, ActionWrapper.Result> results;
|
|
||||||
|
|
||||||
public Results(Map<String, ActionWrapper.Result> results) {
|
|
||||||
this.results = results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int count() {
|
|
||||||
return results.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<ActionWrapper.Result> 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -387,7 +387,7 @@ public class ExecutionService extends AbstractComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (conditionResult.met()) {
|
if (conditionResult.met()) {
|
||||||
if (watch.actions().count() > 0 && watch.transform() != null) {
|
if (watch.actions().size() > 0 && watch.transform() != null) {
|
||||||
ctx.beforeWatchTransform();
|
ctx.beforeWatchTransform();
|
||||||
Transform.Result transformResult = watch.transform().execute(ctx, ctx.payload());
|
Transform.Result transformResult = watch.transform().execute(ctx, ctx.payload());
|
||||||
ctx.onWatchTransformResult(transformResult);
|
ctx.onWatchTransformResult(transformResult);
|
||||||
|
|
|
@ -8,7 +8,6 @@ package org.elasticsearch.xpack.watcher.execution;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
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.condition.Condition;
|
||||||
import org.elasticsearch.xpack.watcher.history.WatchRecord;
|
import org.elasticsearch.xpack.watcher.history.WatchRecord;
|
||||||
import org.elasticsearch.xpack.watcher.input.Input;
|
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.elasticsearch.xpack.watcher.watch.Watch;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
@ -180,8 +180,8 @@ public abstract class WatchExecutionContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutableActions.Results actionsResults() {
|
public Map<String, ActionWrapper.Result> actionsResults() {
|
||||||
return new ExecutableActions.Results(actionsResults);
|
return Collections.unmodifiableMap(actionsResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
public WatchRecord abortBeforeExecution(ExecutionState state, String message) {
|
public WatchRecord abortBeforeExecution(ExecutionState state, String message) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import org.elasticsearch.common.Nullable;
|
||||||
import org.elasticsearch.common.ParseField;
|
import org.elasticsearch.common.ParseField;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
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.condition.Condition;
|
||||||
import org.elasticsearch.xpack.watcher.input.Input;
|
import org.elasticsearch.xpack.watcher.input.Input;
|
||||||
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
|
import org.elasticsearch.xpack.watcher.support.WatcherDateTimeUtils;
|
||||||
|
@ -17,6 +17,7 @@ import org.elasticsearch.xpack.watcher.transform.Transform;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WatchExecutionResult implements ToXContent {
|
public class WatchExecutionResult implements ToXContent {
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ public class WatchExecutionResult implements ToXContent {
|
||||||
@Nullable private final Input.Result inputResult;
|
@Nullable private final Input.Result inputResult;
|
||||||
@Nullable private final Condition.Result conditionResult;
|
@Nullable private final Condition.Result conditionResult;
|
||||||
@Nullable private final Transform.Result transformResult;
|
@Nullable private final Transform.Result transformResult;
|
||||||
private final ExecutableActions.Results actionsResults;
|
private final Map<String, ActionWrapper.Result> actionsResults;
|
||||||
|
|
||||||
public WatchExecutionResult(WatchExecutionContext context, long executionDurationMs) {
|
public WatchExecutionResult(WatchExecutionContext context, long executionDurationMs) {
|
||||||
this(context.executionTime(), executionDurationMs, context.inputResult(), context.conditionResult(), context.transformResult(),
|
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,
|
WatchExecutionResult(DateTime executionTime, long executionDurationMs, Input.Result inputResult, Condition.Result conditionResult,
|
||||||
@Nullable Transform.Result transformResult, ExecutableActions.Results actionsResults) {
|
@Nullable Transform.Result transformResult, Map<String, ActionWrapper.Result> actionsResults) {
|
||||||
this.executionTime = executionTime;
|
this.executionTime = executionTime;
|
||||||
this.inputResult = inputResult;
|
this.inputResult = inputResult;
|
||||||
this.conditionResult = conditionResult;
|
this.conditionResult = conditionResult;
|
||||||
|
@ -62,7 +63,7 @@ public class WatchExecutionResult implements ToXContent {
|
||||||
return transformResult;
|
return transformResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutableActions.Results actionsResults() {
|
public Map<String, ActionWrapper.Result> actionsResults() {
|
||||||
return actionsResults;
|
return actionsResults;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,7 +83,11 @@ public class WatchExecutionResult implements ToXContent {
|
||||||
if (transformResult != null) {
|
if (transformResult != null) {
|
||||||
builder.field(Transform.Field.TRANSFORM.getPreferredName(), transformResult, params);
|
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();
|
builder.endObject();
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,11 +11,11 @@ import org.elasticsearch.common.io.stream.Streamable;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableActions;
|
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.DateTimeZone;
|
import org.joda.time.DateTimeZone;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class WatchExecutionSnapshot implements Streamable, ToXContent {
|
public class WatchExecutionSnapshot implements Streamable, ToXContent {
|
||||||
|
|
||||||
|
@ -38,10 +38,10 @@ public class WatchExecutionSnapshot implements Streamable, ToXContent {
|
||||||
executionTime = context.executionTime();
|
executionTime = context.executionTime();
|
||||||
phase = context.executionPhase();
|
phase = context.executionPhase();
|
||||||
if (phase == ExecutionPhase.ACTIONS) {
|
if (phase == ExecutionPhase.ACTIONS) {
|
||||||
ExecutableActions.Results actionResults = context.actionsResults();
|
Map<String, ActionWrapper.Result> actionResults = context.actionsResults();
|
||||||
executedActions = new String[actionResults.count()];
|
executedActions = new String[actionResults.size()];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ActionWrapper.Result actionResult : actionResults) {
|
for (ActionWrapper.Result actionResult : actionResults.values()) {
|
||||||
executedActions[i++] = actionResult.id();
|
executedActions[i++] = actionResult.id();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,8 @@ import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.collect.MapBuilder;
|
import org.elasticsearch.common.collect.MapBuilder;
|
||||||
import org.elasticsearch.common.xcontent.ToXContent;
|
import org.elasticsearch.common.xcontent.ToXContent;
|
||||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
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.condition.Condition;
|
||||||
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
import org.elasticsearch.xpack.watcher.execution.ExecutionState;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
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 org.elasticsearch.xpack.watcher.watch.Watch;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -75,9 +78,9 @@ public abstract class WatchRecord implements ToXContent {
|
||||||
if (executionResult == null || executionResult.conditionResult() == null) {
|
if (executionResult == null || executionResult.conditionResult() == null) {
|
||||||
return ExecutionState.FAILED;
|
return ExecutionState.FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (executionResult.conditionResult().met()) {
|
if (executionResult.conditionResult().met()) {
|
||||||
if (executionResult.actionsResults().throttled()) {
|
final Collection<ActionWrapper.Result> values = executionResult.actionsResults().values();
|
||||||
|
if (values.stream().anyMatch((r) -> r.action().status() == Action.Result.Status.THROTTLED)) {
|
||||||
return ExecutionState.THROTTLED;
|
return ExecutionState.THROTTLED;
|
||||||
} else {
|
} else {
|
||||||
return ExecutionState.EXECUTED;
|
return ExecutionState.EXECUTED;
|
||||||
|
|
|
@ -26,7 +26,6 @@ import org.elasticsearch.xpack.watcher.Watcher;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionRegistry;
|
import org.elasticsearch.xpack.watcher.actions.ActionRegistry;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
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.ConditionRegistry;
|
||||||
import org.elasticsearch.xpack.watcher.condition.ExecutableCondition;
|
import org.elasticsearch.xpack.watcher.condition.ExecutableCondition;
|
||||||
import org.elasticsearch.xpack.watcher.condition.always.ExecutableAlwaysCondition;
|
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.TriggerEngine;
|
||||||
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
|
import org.elasticsearch.xpack.watcher.trigger.TriggerService;
|
||||||
import org.joda.time.DateTime;
|
import org.joda.time.DateTime;
|
||||||
import org.joda.time.PeriodType;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
|
@ -66,7 +65,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
private final ExecutableInput input;
|
private final ExecutableInput input;
|
||||||
private final ExecutableCondition condition;
|
private final ExecutableCondition condition;
|
||||||
@Nullable private final ExecutableTransform transform;
|
@Nullable private final ExecutableTransform transform;
|
||||||
private final ExecutableActions actions;
|
private final List<ActionWrapper> actions;
|
||||||
@Nullable private final TimeValue throttlePeriod;
|
@Nullable private final TimeValue throttlePeriod;
|
||||||
@Nullable private final Map<String, Object> metadata;
|
@Nullable private final Map<String, Object> metadata;
|
||||||
private final WatchStatus status;
|
private final WatchStatus status;
|
||||||
|
@ -76,7 +75,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
private transient long version = Versions.MATCH_ANY;
|
private transient long version = Versions.MATCH_ANY;
|
||||||
|
|
||||||
public Watch(String id, Trigger trigger, ExecutableInput input, ExecutableCondition condition, @Nullable ExecutableTransform transform,
|
public Watch(String id, Trigger trigger, ExecutableInput input, ExecutableCondition condition, @Nullable ExecutableTransform transform,
|
||||||
@Nullable TimeValue throttlePeriod, ExecutableActions actions, @Nullable Map<String, Object> metadata,
|
@Nullable TimeValue throttlePeriod, List<ActionWrapper> actions, @Nullable Map<String, Object> metadata,
|
||||||
WatchStatus status) {
|
WatchStatus status) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.trigger = trigger;
|
this.trigger = trigger;
|
||||||
|
@ -113,7 +112,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
return throttlePeriod;
|
return throttlePeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExecutableActions actions() {
|
public List<ActionWrapper> actions() {
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,7 +186,11 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
builder.timeValueField(Field.THROTTLE_PERIOD.getPreferredName(),
|
builder.timeValueField(Field.THROTTLE_PERIOD.getPreferredName(),
|
||||||
Field.THROTTLE_PERIOD_HUMAN.getPreferredName(), throttlePeriod);
|
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) {
|
if (metadata != null) {
|
||||||
builder.field(Field.METADATA.getPreferredName(), metadata);
|
builder.field(Field.METADATA.getPreferredName(), metadata);
|
||||||
}
|
}
|
||||||
|
@ -214,7 +217,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
private final CryptoService cryptoService;
|
private final CryptoService cryptoService;
|
||||||
private final ExecutableInput defaultInput;
|
private final ExecutableInput defaultInput;
|
||||||
private final ExecutableCondition defaultCondition;
|
private final ExecutableCondition defaultCondition;
|
||||||
private final ExecutableActions defaultActions;
|
private final List<ActionWrapper> defaultActions;
|
||||||
private final Clock clock;
|
private final Clock clock;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@ -231,7 +234,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
this.cryptoService = Watcher.ENCRYPT_SENSITIVE_DATA_SETTING.get(settings) ? cryptoService : null;
|
this.cryptoService = Watcher.ENCRYPT_SENSITIVE_DATA_SETTING.get(settings) ? cryptoService : null;
|
||||||
this.defaultInput = new ExecutableNoneInput(logger);
|
this.defaultInput = new ExecutableNoneInput(logger);
|
||||||
this.defaultCondition = new ExecutableAlwaysCondition(logger);
|
this.defaultCondition = new ExecutableAlwaysCondition(logger);
|
||||||
this.defaultActions = new ExecutableActions(Collections.emptyList());
|
this.defaultActions = Collections.emptyList();
|
||||||
this.clock = clock;
|
this.clock = clock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +289,7 @@ public class Watch implements TriggerEngine.Job, ToXContent {
|
||||||
Trigger trigger = null;
|
Trigger trigger = null;
|
||||||
ExecutableInput input = defaultInput;
|
ExecutableInput input = defaultInput;
|
||||||
ExecutableCondition condition = defaultCondition;
|
ExecutableCondition condition = defaultCondition;
|
||||||
ExecutableActions actions = defaultActions;
|
List<ActionWrapper> actions = defaultActions;
|
||||||
ExecutableTransform transform = null;
|
ExecutableTransform transform = null;
|
||||||
TimeValue throttlePeriod = null;
|
TimeValue throttlePeriod = null;
|
||||||
Map<String, Object> metatdata = null;
|
Map<String, Object> metatdata = null;
|
||||||
|
|
|
@ -127,7 +127,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
|
||||||
|
|
||||||
ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
||||||
WatchRecord watchRecord = executionService().execute(ctx);
|
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())) {
|
if (ackingActions.contains(result.id())) {
|
||||||
assertThat(result.action().status(), equalTo(Action.Result.Status.THROTTLED));
|
assertThat(result.action().status(), equalTo(Action.Result.Status.THROTTLED));
|
||||||
} else {
|
} else {
|
||||||
|
@ -157,12 +157,12 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
|
||||||
ManualExecutionContext ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
ManualExecutionContext ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
||||||
WatchRecord watchRecord = executionService().execute(ctx);
|
WatchRecord watchRecord = executionService().execute(ctx);
|
||||||
long firstExecution = System.currentTimeMillis();
|
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));
|
assertThat(actionResult.action().status(), equalTo(Action.Result.Status.SIMULATED));
|
||||||
}
|
}
|
||||||
ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
||||||
watchRecord = executionService().execute(ctx);
|
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));
|
assertThat(actionResult.action().status(), equalTo(Action.Result.Status.THROTTLED));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +175,7 @@ public class ActionThrottleTests extends AbstractWatcherIntegrationTestCase {
|
||||||
public void run() {
|
public void run() {
|
||||||
ManualExecutionContext ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
ManualExecutionContext ctx = getManualExecutionContext(new TimeValue(0, TimeUnit.SECONDS));
|
||||||
WatchRecord watchRecord = executionService().execute(ctx);
|
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())) {
|
if ("ten_sec_throttle".equals(actionResult.id())) {
|
||||||
assertThat(actionResult.action().status(), equalTo(Action.Result.Status.SIMULATED));
|
assertThat(actionResult.action().status(), equalTo(Action.Result.Status.SIMULATED));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -19,7 +19,6 @@ import org.elasticsearch.xpack.watcher.actions.Action;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
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.ActionThrottler;
|
||||||
import org.elasticsearch.xpack.watcher.actions.throttler.Throttler;
|
import org.elasticsearch.xpack.watcher.actions.throttler.Throttler;
|
||||||
import org.elasticsearch.xpack.watcher.condition.Condition;
|
import org.elasticsearch.xpack.watcher.condition.Condition;
|
||||||
|
@ -168,14 +167,13 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
||||||
|
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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())));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC())));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.execute(context);
|
WatchRecord watchRecord = executionService.execute(context);
|
||||||
|
@ -248,14 +246,12 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
||||||
|
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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())));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC())));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.execute(context);
|
WatchRecord watchRecord = executionService.execute(context);
|
||||||
|
@ -263,7 +259,7 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
assertThat(watchRecord.result().conditionResult(), nullValue());
|
assertThat(watchRecord.result().conditionResult(), nullValue());
|
||||||
assertThat(watchRecord.result().transformResult(), nullValue());
|
assertThat(watchRecord.result().transformResult(), nullValue());
|
||||||
assertThat(watchRecord.result().actionsResults(), notNullValue());
|
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(historyStore, times(1)).put(watchRecord);
|
||||||
verify(releasable, times(1)).close();
|
verify(releasable, times(1)).close();
|
||||||
|
@ -315,14 +311,12 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
||||||
|
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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())));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC())));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.execute(context);
|
WatchRecord watchRecord = executionService.execute(context);
|
||||||
|
@ -330,7 +324,7 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
assertThat(watchRecord.result().conditionResult(), is(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), is(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), nullValue());
|
assertThat(watchRecord.result().transformResult(), nullValue());
|
||||||
assertThat(watchRecord.result().actionsResults(), notNullValue());
|
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(historyStore, times(1)).put(watchRecord);
|
||||||
verify(releasable, times(1)).close();
|
verify(releasable, times(1)).close();
|
||||||
|
@ -381,14 +375,12 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
||||||
|
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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())));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC())));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.execute(context);
|
WatchRecord watchRecord = executionService.execute(context);
|
||||||
|
@ -396,7 +388,7 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
assertThat(watchRecord.result().conditionResult(), is(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), is(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), is(watchTransformResult));
|
assertThat(watchRecord.result().transformResult(), is(watchTransformResult));
|
||||||
assertThat(watchRecord.result().actionsResults(), notNullValue());
|
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(historyStore, times(1)).put(watchRecord);
|
||||||
verify(releasable, times(1)).close();
|
verify(releasable, times(1)).close();
|
||||||
|
@ -461,14 +453,13 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
||||||
|
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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())));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(clock.nowUTC())));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.execute(context);
|
WatchRecord watchRecord = executionService.execute(context);
|
||||||
|
@ -476,7 +467,7 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
assertThat(watchRecord.result().conditionResult(), is(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), is(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), is(watchTransformResult));
|
assertThat(watchRecord.result().transformResult(), is(watchTransformResult));
|
||||||
assertThat(watchRecord.result().actionsResults(), notNullValue());
|
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").condition(), is(actionConditionResult));
|
||||||
assertThat(watchRecord.result().actionsResults().get("_action").transform(), is(actionTransformResult));
|
assertThat(watchRecord.result().actionsResults().get("_action").transform(), is(actionTransformResult));
|
||||||
assertThat(watchRecord.result().actionsResults().get("_action").action().status(), is(Action.Result.Status.FAILURE));
|
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);
|
when(action.execute("_action", context, payload)).thenReturn(actionResult);
|
||||||
|
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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)));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now)));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.executeInner(context);
|
WatchRecord watchRecord = executionService.executeInner(context);
|
||||||
|
@ -591,20 +580,18 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
ExecutableAction action = mock(ExecutableAction.class);
|
ExecutableAction action = mock(ExecutableAction.class);
|
||||||
when(action.type()).thenReturn("_type");
|
when(action.type()).thenReturn("_type");
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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)));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now)));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.executeInner(context);
|
WatchRecord watchRecord = executionService.executeInner(context);
|
||||||
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
||||||
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), nullValue());
|
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");
|
ActionWrapper.Result result = watchRecord.result().actionsResults().get("_action");
|
||||||
assertThat(result, notNullValue());
|
assertThat(result, notNullValue());
|
||||||
assertThat(result.id(), is("_action"));
|
assertThat(result.id(), is("_action"));
|
||||||
|
@ -654,20 +641,18 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
ExecutableAction action = mock(ExecutableAction.class);
|
ExecutableAction action = mock(ExecutableAction.class);
|
||||||
when(action.type()).thenReturn("_type");
|
when(action.type()).thenReturn("_type");
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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)));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now)));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.executeInner(context);
|
WatchRecord watchRecord = executionService.executeInner(context);
|
||||||
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
||||||
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), nullValue());
|
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");
|
ActionWrapper.Result result = watchRecord.result().actionsResults().get("_action");
|
||||||
assertThat(result, notNullValue());
|
assertThat(result, notNullValue());
|
||||||
assertThat(result.id(), is("_action"));
|
assertThat(result.id(), is("_action"));
|
||||||
|
@ -711,20 +696,18 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
when(action.type()).thenReturn("_type");
|
when(action.type()).thenReturn("_type");
|
||||||
when(action.logger()).thenReturn(logger);
|
when(action.logger()).thenReturn(logger);
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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)));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now)));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.executeInner(context);
|
WatchRecord watchRecord = executionService.executeInner(context);
|
||||||
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
||||||
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), nullValue());
|
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");
|
ActionWrapper.Result result = watchRecord.result().actionsResults().get("_action");
|
||||||
assertThat(result, notNullValue());
|
assertThat(result, notNullValue());
|
||||||
assertThat(result.id(), is("_action"));
|
assertThat(result.id(), is("_action"));
|
||||||
|
@ -759,21 +742,20 @@ public class ExecutionServiceTests extends ESTestCase {
|
||||||
ExecutableTransform actionTransform = mock(ExecutableTransform.class);
|
ExecutableTransform actionTransform = mock(ExecutableTransform.class);
|
||||||
ExecutableAction action = mock(ExecutableAction.class);
|
ExecutableAction action = mock(ExecutableAction.class);
|
||||||
ActionWrapper actionWrapper = new ActionWrapper("_action", throttler, actionCondition, actionTransform, action);
|
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)));
|
WatchStatus watchStatus = new WatchStatus(clock.nowUTC(), singletonMap("_action", new ActionStatus(now)));
|
||||||
|
|
||||||
when(watch.input()).thenReturn(input);
|
when(watch.input()).thenReturn(input);
|
||||||
when(watch.condition()).thenReturn(condition);
|
when(watch.condition()).thenReturn(condition);
|
||||||
when(watch.transform()).thenReturn(watchTransform);
|
when(watch.transform()).thenReturn(watchTransform);
|
||||||
when(watch.actions()).thenReturn(actions);
|
when(watch.actions()).thenReturn(Arrays.asList(actionWrapper));
|
||||||
when(watch.status()).thenReturn(watchStatus);
|
when(watch.status()).thenReturn(watchStatus);
|
||||||
|
|
||||||
WatchRecord watchRecord = executionService.executeInner(context);
|
WatchRecord watchRecord = executionService.executeInner(context);
|
||||||
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
assertThat(watchRecord.result().inputResult(), sameInstance(inputResult));
|
||||||
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
assertThat(watchRecord.result().conditionResult(), sameInstance(conditionResult));
|
||||||
assertThat(watchRecord.result().transformResult(), nullValue());
|
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(condition, times(1)).execute(context);
|
||||||
verify(watchTransform, never()).execute(context, payload);
|
verify(watchTransform, never()).execute(context, payload);
|
||||||
|
|
|
@ -170,9 +170,9 @@ public class ManualExecutionTests extends AbstractWatcherIntegrationTestCase {
|
||||||
assertThat("the expected count of history records should be [" + expectedCount + "]", newRecordCount, equalTo(expectedCount));
|
assertThat("the expected count of history records should be [" + expectedCount + "]", newRecordCount, equalTo(expectedCount));
|
||||||
|
|
||||||
if (ignoreCondition) {
|
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) {
|
} 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) {
|
if ((ignoreCondition || conditionAlwaysTrue) && action == null) {
|
||||||
|
|
|
@ -17,7 +17,6 @@ import org.elasticsearch.script.Script;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
import org.elasticsearch.xpack.common.http.HttpRequestTemplate;
|
||||||
import org.elasticsearch.xpack.common.http.auth.basic.BasicAuth;
|
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.always.ExecutableAlwaysCondition;
|
||||||
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
import org.elasticsearch.xpack.watcher.condition.script.ScriptCondition;
|
||||||
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
||||||
|
@ -175,7 +174,7 @@ public class ChainInputTests extends ESTestCase {
|
||||||
new ExecutableAlwaysCondition(logger),
|
new ExecutableAlwaysCondition(logger),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
new ExecutableActions(new ArrayList<>()),
|
new ArrayList<>(),
|
||||||
null,
|
null,
|
||||||
new WatchStatus(new DateTime(0, UTC), emptyMap()));
|
new WatchStatus(new DateTime(0, UTC), emptyMap()));
|
||||||
WatchExecutionContext ctx = new TriggeredExecutionContext(watch,
|
WatchExecutionContext ctx = new TriggeredExecutionContext(watch,
|
||||||
|
|
|
@ -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.http.auth.basic.BasicAuthFactory;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
import org.elasticsearch.xpack.common.text.TextTemplate;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplateEngine;
|
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.condition.always.ExecutableAlwaysCondition;
|
||||||
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
|
@ -309,7 +308,7 @@ public class HttpInputTests extends ESTestCase {
|
||||||
new ExecutableAlwaysCondition(logger),
|
new ExecutableAlwaysCondition(logger),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
new ExecutableActions(new ArrayList<>()),
|
new ArrayList<>(),
|
||||||
null,
|
null,
|
||||||
new WatchStatus(new DateTime(0, UTC), emptyMap()));
|
new WatchStatus(new DateTime(0, UTC), emptyMap()));
|
||||||
return new TriggeredExecutionContext(watch,
|
return new TriggeredExecutionContext(watch,
|
||||||
|
|
|
@ -40,7 +40,6 @@ import org.elasticsearch.xpack.notification.email.HtmlSanitizer;
|
||||||
import org.elasticsearch.xpack.notification.email.Profile;
|
import org.elasticsearch.xpack.notification.email.Profile;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
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.EmailAction;
|
||||||
import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction;
|
import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction;
|
||||||
import org.elasticsearch.xpack.watcher.actions.webhook.ExecutableWebhookAction;
|
import org.elasticsearch.xpack.watcher.actions.webhook.ExecutableWebhookAction;
|
||||||
|
@ -236,7 +235,7 @@ public final class WatcherTestUtils {
|
||||||
new ExecutableAlwaysCondition(logger),
|
new ExecutableAlwaysCondition(logger),
|
||||||
new ExecutableSearchTransform(searchTransform, logger, client, searchTemplateService, null),
|
new ExecutableSearchTransform(searchTransform, logger, client, searchTemplateService, null),
|
||||||
new TimeValue(0),
|
new TimeValue(0),
|
||||||
new ExecutableActions(actions),
|
actions,
|
||||||
metadata,
|
metadata,
|
||||||
new WatchStatus(now, statuses));
|
new WatchStatus(now, statuses));
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,6 @@ import org.elasticsearch.search.SearchRequestParsers;
|
||||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
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.condition.always.ExecutableAlwaysCondition;
|
||||||
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
|
@ -87,7 +86,7 @@ public class SearchInputTests extends ESIntegTestCase {
|
||||||
new ExecutableAlwaysCondition(logger),
|
new ExecutableAlwaysCondition(logger),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
new ExecutableActions(new ArrayList<>()),
|
new ArrayList<>(),
|
||||||
null,
|
null,
|
||||||
new WatchStatus(new DateTime(0, UTC), emptyMap())),
|
new WatchStatus(new DateTime(0, UTC), emptyMap())),
|
||||||
new DateTime(0, UTC),
|
new DateTime(0, UTC),
|
||||||
|
@ -119,7 +118,7 @@ public class SearchInputTests extends ESIntegTestCase {
|
||||||
new ExecutableAlwaysCondition(logger),
|
new ExecutableAlwaysCondition(logger),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
new ExecutableActions(new ArrayList<>()),
|
new ArrayList<>(),
|
||||||
null,
|
null,
|
||||||
new WatchStatus(new DateTime(0, UTC), emptyMap())),
|
new WatchStatus(new DateTime(0, UTC), emptyMap())),
|
||||||
new DateTime(0, UTC),
|
new DateTime(0, UTC),
|
||||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
|
||||||
import org.elasticsearch.xpack.common.text.TextTemplate;
|
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.condition.always.ExecutableAlwaysCondition;
|
||||||
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.TriggeredExecutionContext;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
|
@ -262,7 +261,7 @@ public class SearchTransformTests extends ESIntegTestCase {
|
||||||
new ExecutableAlwaysCondition(logger),
|
new ExecutableAlwaysCondition(logger),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
new ExecutableActions(new ArrayList<>()),
|
new ArrayList<>(),
|
||||||
null,
|
null,
|
||||||
new WatchStatus( new DateTime(40000, UTC), emptyMap())),
|
new WatchStatus( new DateTime(40000, UTC), emptyMap())),
|
||||||
new DateTime(60000, UTC),
|
new DateTime(60000, UTC),
|
||||||
|
|
|
@ -34,7 +34,6 @@ import org.elasticsearch.search.internal.InternalSearchHits;
|
||||||
import org.elasticsearch.test.ESTestCase;
|
import org.elasticsearch.test.ESTestCase;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ExecutableAction;
|
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.always.ExecutableAlwaysCondition;
|
||||||
import org.elasticsearch.xpack.watcher.condition.never.ExecutableNeverCondition;
|
import org.elasticsearch.xpack.watcher.condition.never.ExecutableNeverCondition;
|
||||||
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
import org.elasticsearch.xpack.watcher.execution.WatchExecutionContext;
|
||||||
|
@ -286,7 +285,7 @@ public class WatchStoreTests extends ESTestCase {
|
||||||
ExecutableAction action = mock(ExecutableAction.class);
|
ExecutableAction action = mock(ExecutableAction.class);
|
||||||
when(actionWrapper.action()).thenReturn(action);
|
when(actionWrapper.action()).thenReturn(action);
|
||||||
when(action.type()).thenReturn(randomFrom("a", "b", "c"));
|
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
|
// random transform, not always set
|
||||||
Transform mockTransform = mock(Transform.class);
|
Transform mockTransform = mock(Transform.class);
|
||||||
|
|
|
@ -44,7 +44,6 @@ import org.elasticsearch.xpack.watcher.actions.ActionFactory;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionRegistry;
|
import org.elasticsearch.xpack.watcher.actions.ActionRegistry;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||||
import org.elasticsearch.xpack.watcher.actions.ActionWrapper;
|
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.EmailAction;
|
||||||
import org.elasticsearch.xpack.watcher.actions.email.EmailActionFactory;
|
import org.elasticsearch.xpack.watcher.actions.email.EmailActionFactory;
|
||||||
import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction;
|
import org.elasticsearch.xpack.watcher.actions.email.ExecutableEmailAction;
|
||||||
|
@ -191,7 +190,7 @@ public class WatchTests extends ESTestCase {
|
||||||
|
|
||||||
ExecutableTransform transform = randomTransform();
|
ExecutableTransform transform = randomTransform();
|
||||||
|
|
||||||
ExecutableActions actions = randomActions();
|
List<ActionWrapper> actions = randomActions();
|
||||||
ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry);
|
ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry);
|
||||||
|
|
||||||
Map<String, Object> metadata = singletonMap("_key", "_val");
|
Map<String, Object> metadata = singletonMap("_key", "_val");
|
||||||
|
@ -237,7 +236,7 @@ public class WatchTests extends ESTestCase {
|
||||||
|
|
||||||
TransformRegistry transformRegistry = transformRegistry();
|
TransformRegistry transformRegistry = transformRegistry();
|
||||||
|
|
||||||
ExecutableActions actions = randomActions();
|
List<ActionWrapper> actions = randomActions();
|
||||||
ActionRegistry actionRegistry = registry(actions,conditionRegistry, transformRegistry);
|
ActionRegistry actionRegistry = registry(actions,conditionRegistry, transformRegistry);
|
||||||
|
|
||||||
|
|
||||||
|
@ -264,8 +263,7 @@ public class WatchTests extends ESTestCase {
|
||||||
ConditionRegistry conditionRegistry = conditionRegistry();
|
ConditionRegistry conditionRegistry = conditionRegistry();
|
||||||
InputRegistry inputRegistry = registry(new ExecutableNoneInput(logger).type());
|
InputRegistry inputRegistry = registry(new ExecutableNoneInput(logger).type());
|
||||||
TransformRegistry transformRegistry = transformRegistry();
|
TransformRegistry transformRegistry = transformRegistry();
|
||||||
ExecutableActions actions = new ExecutableActions(Collections.emptyList());
|
ActionRegistry actionRegistry = registry(Collections.emptyList(), conditionRegistry, transformRegistry);
|
||||||
ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry);
|
|
||||||
|
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||||
builder.startObject();
|
builder.startObject();
|
||||||
|
@ -282,7 +280,7 @@ public class WatchTests extends ESTestCase {
|
||||||
assertThat(watch.condition(), instanceOf(ExecutableAlwaysCondition.class));
|
assertThat(watch.condition(), instanceOf(ExecutableAlwaysCondition.class));
|
||||||
assertThat(watch.transform(), nullValue());
|
assertThat(watch.transform(), nullValue());
|
||||||
assertThat(watch.actions(), notNullValue());
|
assertThat(watch.actions(), notNullValue());
|
||||||
assertThat(watch.actions().count(), is(0));
|
assertThat(watch.actions().size(), is(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testParseWatch_verifyScriptLangDefault() throws Exception {
|
public void testParseWatch_verifyScriptLangDefault() throws Exception {
|
||||||
|
@ -294,8 +292,7 @@ public class WatchTests extends ESTestCase {
|
||||||
ConditionRegistry conditionRegistry = conditionRegistry();
|
ConditionRegistry conditionRegistry = conditionRegistry();
|
||||||
InputRegistry inputRegistry = registry(SearchInput.TYPE);
|
InputRegistry inputRegistry = registry(SearchInput.TYPE);
|
||||||
TransformRegistry transformRegistry = transformRegistry();
|
TransformRegistry transformRegistry = transformRegistry();
|
||||||
ExecutableActions actions = new ExecutableActions(Collections.emptyList());
|
ActionRegistry actionRegistry = registry(Collections.emptyList(), conditionRegistry, transformRegistry);
|
||||||
ActionRegistry actionRegistry = registry(actions, conditionRegistry, transformRegistry);
|
|
||||||
Watch.Parser watchParser = new Watch.Parser(settings, conditionRegistry, triggerService, transformRegistry, actionRegistry,
|
Watch.Parser watchParser = new Watch.Parser(settings, conditionRegistry, triggerService, transformRegistry, actionRegistry,
|
||||||
inputRegistry, null, SystemClock.INSTANCE);
|
inputRegistry, null, SystemClock.INSTANCE);
|
||||||
|
|
||||||
|
@ -508,7 +505,7 @@ public class WatchTests extends ESTestCase {
|
||||||
return new TransformRegistry(Settings.EMPTY, unmodifiableMap(factories));
|
return new TransformRegistry(Settings.EMPTY, unmodifiableMap(factories));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ExecutableActions randomActions() {
|
private List<ActionWrapper> randomActions() {
|
||||||
List<ActionWrapper> list = new ArrayList<>();
|
List<ActionWrapper> list = new ArrayList<>();
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
EmailAction action = new EmailAction(EmailTemplate.builder().build(), null, null, Profile.STANDARD,
|
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(),
|
list.add(new ActionWrapper("_webhook_" + randomAsciiOfLength(8), randomThrottler(), randomCondition(), randomTransform(),
|
||||||
new ExecutableWebhookAction(action, logger, httpClient, templateEngine)));
|
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<ActionWrapper> actions, ConditionRegistry conditionRegistry, TransformRegistry transformRegistry) {
|
||||||
Map<String, ActionFactory> parsers = new HashMap<>();
|
Map<String, ActionFactory> parsers = new HashMap<>();
|
||||||
for (ActionWrapper action : actions) {
|
for (ActionWrapper action : actions) {
|
||||||
switch (action.action().type()) {
|
switch (action.action().type()) {
|
||||||
|
|
Loading…
Reference in New Issue