Skip to content

Commit 2ccd9c9

Browse files
committed
Watcher: cleanup ensureWatchExists use (#31926)
Previously, the ensureWatchExists was overridable. This commit makes it final so that it cannot be overridden, and cleans up some redundant code in the process.
1 parent 7128bf4 commit 2ccd9c9

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/watcher/execution/WatchExecutionContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Watch watch() {
8181
return watch;
8282
}
8383

84-
public void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
84+
public final void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
8585
if (watch == null) {
8686
watch = supplier.get();
8787
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/execution/ManualExecutionContext.java

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
package org.elasticsearch.xpack.watcher.execution;
77

8-
import org.elasticsearch.common.CheckedSupplier;
98
import org.elasticsearch.common.unit.TimeValue;
109
import org.elasticsearch.xpack.core.watcher.actions.Action;
1110
import org.elasticsearch.xpack.core.watcher.actions.ActionWrapper;
@@ -29,18 +28,19 @@ public class ManualExecutionContext extends WatchExecutionContext {
2928
private final Map<String, ActionExecutionMode> actionModes;
3029
private final boolean recordExecution;
3130
private final boolean knownWatch;
32-
private final Watch watch;
3331

3432
ManualExecutionContext(Watch watch, boolean knownWatch, DateTime executionTime, ManualTriggerEvent triggerEvent,
3533
TimeValue defaultThrottlePeriod, Input.Result inputResult, Condition.Result conditionResult,
36-
Map<String, ActionExecutionMode> actionModes, boolean recordExecution) {
34+
Map<String, ActionExecutionMode> actionModes, boolean recordExecution) throws Exception {
3735

3836
super(watch.id(), executionTime, triggerEvent, defaultThrottlePeriod);
3937

4038
this.actionModes = actionModes;
4139
this.recordExecution = recordExecution;
4240
this.knownWatch = knownWatch;
43-
this.watch = watch;
41+
42+
// set the watch early to ensure calls to watch() below succeed.
43+
super.ensureWatchExists(() -> watch);
4444

4545
if (inputResult != null) {
4646
onInputResult(inputResult);
@@ -66,12 +66,6 @@ public class ManualExecutionContext extends WatchExecutionContext {
6666
}
6767
}
6868

69-
// a noop operation, as the watch is already loaded via ctor
70-
@Override
71-
public void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
72-
super.ensureWatchExists(() -> watch);
73-
}
74-
7569
@Override
7670
public boolean knownWatch() {
7771
return knownWatch;
@@ -107,11 +101,6 @@ public final boolean recordExecution() {
107101
return recordExecution;
108102
}
109103

110-
@Override
111-
public Watch watch() {
112-
return watch;
113-
}
114-
115104
public static Builder builder(Watch watch, boolean knownWatch, ManualTriggerEvent event, TimeValue defaultThrottlePeriod) {
116105
return new Builder(watch, knownWatch, event, defaultThrottlePeriod);
117106
}
@@ -173,7 +162,7 @@ public Builder withCondition(Condition.Result conditionResult) {
173162
return this;
174163
}
175164

176-
public ManualExecutionContext build() {
165+
public ManualExecutionContext build() throws Exception {
177166
if (executionTime == null) {
178167
executionTime = DateTime.now(DateTimeZone.UTC);
179168
}

0 commit comments

Comments
 (0)