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.
This commit is contained in:
Michael Basnight 2018-07-13 11:12:03 -05:00 committed by GitHub
parent 82cdb574cf
commit c1a81e552f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 17 deletions

View File

@ -82,7 +82,7 @@ public abstract class WatchExecutionContext {
return watch;
}
public void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
public final void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
if (watch == null) {
watch = supplier.get();
}

View File

@ -5,7 +5,6 @@
*/
package org.elasticsearch.xpack.watcher.execution;
import org.elasticsearch.common.CheckedSupplier;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.xpack.core.watcher.actions.Action;
import org.elasticsearch.xpack.core.watcher.actions.ActionWrapper;
@ -29,18 +28,19 @@ public class ManualExecutionContext extends WatchExecutionContext {
private final Map<String, ActionExecutionMode> actionModes;
private final boolean recordExecution;
private final boolean knownWatch;
private final Watch watch;
ManualExecutionContext(Watch watch, boolean knownWatch, DateTime executionTime, ManualTriggerEvent triggerEvent,
TimeValue defaultThrottlePeriod, Input.Result inputResult, Condition.Result conditionResult,
Map<String, ActionExecutionMode> actionModes, boolean recordExecution) {
Map<String, ActionExecutionMode> actionModes, boolean recordExecution) throws Exception {
super(watch.id(), executionTime, triggerEvent, defaultThrottlePeriod);
this.actionModes = actionModes;
this.recordExecution = recordExecution;
this.knownWatch = knownWatch;
this.watch = watch;
// set the watch early to ensure calls to watch() below succeed.
super.ensureWatchExists(() -> watch);
if (inputResult != null) {
onInputResult(inputResult);
@ -66,12 +66,6 @@ public class ManualExecutionContext extends WatchExecutionContext {
}
}
// a noop operation, as the watch is already loaded via ctor
@Override
public void ensureWatchExists(CheckedSupplier<Watch, Exception> supplier) throws Exception {
super.ensureWatchExists(() -> watch);
}
@Override
public boolean knownWatch() {
return knownWatch;
@ -107,11 +101,6 @@ public class ManualExecutionContext extends WatchExecutionContext {
return recordExecution;
}
@Override
public Watch watch() {
return watch;
}
public static Builder builder(Watch watch, boolean knownWatch, ManualTriggerEvent event, TimeValue defaultThrottlePeriod) {
return new Builder(watch, knownWatch, event, defaultThrottlePeriod);
}
@ -173,7 +162,7 @@ public class ManualExecutionContext extends WatchExecutionContext {
return this;
}
public ManualExecutionContext build() {
public ManualExecutionContext build() throws Exception {
if (executionTime == null) {
executionTime = DateTime.now(DateTimeZone.UTC);
}