55 */
66package org .elasticsearch .xpack .watcher .execution ;
77
8- import org .elasticsearch .common .CheckedSupplier ;
98import org .elasticsearch .common .unit .TimeValue ;
109import org .elasticsearch .xpack .core .watcher .actions .Action ;
1110import 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