Watcher: Ensure watch status needs to be udpated on unmet condition (elastic/elasticsearch#2863)
Background: When a watch has been acked, but the condition evaluates to false again, the watch must be marked as dirty - which means it needs to be persisted to the watches index - so in case of a master node switch this information is not lost. This commit fixes the setting of the `dirty` field in the watch status, in case the condition is not met, but some actions have been acked. Original commit: elastic/x-pack-elasticsearch@1a55a45b14
This commit is contained in:
parent
d33e639d4c
commit
f02a9cdc35
|
@ -16,10 +16,10 @@ import org.elasticsearch.common.io.stream.Streamable;
|
|||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.xpack.support.clock.SystemClock;
|
||||
import org.elasticsearch.xpack.watcher.actions.Action;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||
import org.elasticsearch.xpack.watcher.actions.throttler.AckThrottler;
|
||||
import org.elasticsearch.xpack.support.clock.SystemClock;
|
||||
import org.elasticsearch.xpack.watcher.support.xcontent.WatcherXContentParser;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeZone;
|
||||
|
@ -156,7 +156,7 @@ public class WatchStatus implements ToXContent, Streamable {
|
|||
dirty = true;
|
||||
} else {
|
||||
for (ActionStatus status : actions.values()) {
|
||||
status.resetAckStatus(timestamp);
|
||||
dirty |= status.resetAckStatus(timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* 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.watch;
|
||||
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus;
|
||||
import org.elasticsearch.xpack.watcher.actions.ActionStatus.AckStatus.State;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.joda.time.DateTime.now;
|
||||
|
||||
public class WatchStatusTests extends ESTestCase {
|
||||
|
||||
public void testThatWatchStatusDirtyOnConditionCheck() throws Exception {
|
||||
// no actions, met condition
|
||||
WatchStatus status = new WatchStatus(now(), new HashMap<>());
|
||||
status.onCheck(true, now());
|
||||
assertThat(status.dirty(), is(true));
|
||||
|
||||
// no actions, unmet condition
|
||||
status = new WatchStatus(now(), new HashMap<>());
|
||||
status.onCheck(false, now());
|
||||
assertThat(status.dirty(), is(false));
|
||||
|
||||
// actions, no action with reset ack status, unmet condition
|
||||
Map<String, ActionStatus > actions = new HashMap<>();
|
||||
actions.put(randomAsciiOfLength(10), new ActionStatus(now()));
|
||||
status = new WatchStatus(now(), actions);
|
||||
status.onCheck(false, now());
|
||||
assertThat(status.dirty(), is(false));
|
||||
|
||||
// actions, one action with state other than AWAITS_SUCCESSFUL_EXECUTION, unmet condition
|
||||
actions.clear();
|
||||
ActionStatus.AckStatus ackStatus = new ActionStatus.AckStatus(now(), randomFrom(State.ACKED, State.ACKABLE));
|
||||
actions.put(randomAsciiOfLength(10), new ActionStatus(ackStatus, null, null, null));
|
||||
actions.put(randomAsciiOfLength(11), new ActionStatus(now()));
|
||||
status = new WatchStatus(now(), actions);
|
||||
status.onCheck(false, now());
|
||||
assertThat(status.dirty(), is(true));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue