diff --git a/src/main/java/com/microsoft/dhalion/api/IHealthPolicy.java b/src/main/java/com/microsoft/dhalion/api/IHealthPolicy.java index 1b1157e..e1d32b0 100644 --- a/src/main/java/com/microsoft/dhalion/api/IHealthPolicy.java +++ b/src/main/java/com/microsoft/dhalion/api/IHealthPolicy.java @@ -68,6 +68,15 @@ public interface IHealthPolicy { */ Collection executeResolvers(Collection diagnosis); + /** + * Invoked in the event that the policy should be overridden, this method executes one {@link IResolver} to fix a + * single identified issue. + * + * @param resolver a resolver to be executed + * @return actions executed to mitigate health issues + */ + Collection executeResolver(IResolver resolver); + /** * @return the remaining delay before re-execution of this policy */ diff --git a/src/main/java/com/microsoft/dhalion/api/IResolver.java b/src/main/java/com/microsoft/dhalion/api/IResolver.java index 118d4f9..b9476eb 100644 --- a/src/main/java/com/microsoft/dhalion/api/IResolver.java +++ b/src/main/java/com/microsoft/dhalion/api/IResolver.java @@ -34,6 +34,15 @@ default Collection getActionTypes() { default void initialize(ExecutionContext context) { } + /** + * Triggers execution of {@link Action}s which are expected to improved system health. + * + * @return all the actions executed by this resolver + */ + default Collection resolve() { + throw new UnsupportedOperationException(); + } + /** * Triggers execution of {@link Action}s which are expected to improved system health. * diff --git a/src/main/java/com/microsoft/dhalion/events/EventDispatcher.java b/src/main/java/com/microsoft/dhalion/events/EventDispatcher.java index 8b0318b..87f3d5f 100644 --- a/src/main/java/com/microsoft/dhalion/events/EventDispatcher.java +++ b/src/main/java/com/microsoft/dhalion/events/EventDispatcher.java @@ -15,7 +15,7 @@ public class EventDispatcher implements EventHandler { public synchronized void addHandler(EventHandler handler) { if (handlers.contains(handler)) { - throw new IllegalArgumentException("Duplicate hanlder registration"); + throw new IllegalArgumentException("Duplicate handler registration"); } handlers.add(handler); } diff --git a/src/main/java/com/microsoft/dhalion/policy/HealthPolicyImpl.java b/src/main/java/com/microsoft/dhalion/policy/HealthPolicyImpl.java index c9d40e9..c376b72 100644 --- a/src/main/java/com/microsoft/dhalion/policy/HealthPolicyImpl.java +++ b/src/main/java/com/microsoft/dhalion/policy/HealthPolicyImpl.java @@ -165,6 +165,24 @@ public Collection executeResolvers(Collection diagnosis) { return actions; } + @Override + public Collection executeResolver(IResolver resolver) { + if (oneTimeDelay != null && !oneTimeDelay.isAfter(clock.now())) { + // reset one time delay timestamp + oneTimeDelay = null; + } + + Collection actions = new ArrayList<>(); + if (!resolvers.contains(resolver)) { + return actions; + } + + actions = resolver.resolve(); + + lastExecutionTimestamp = clock.now(); + return actions; + } + @Override public Duration getDelay() { long delay;