You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2017/11/10 10:59:26 UTC

[10/11] brooklyn-server git commit: add transition sensor

add transition sensor


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/32c1771f
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/32c1771f
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/32c1771f

Branch: refs/heads/master
Commit: 32c1771f3388fcaf3c6af842818b8ed4a3b29ed7
Parents: 3312386
Author: Alex Heneveld <al...@cloudsoftcorp.com>
Authored: Fri Nov 10 04:16:46 2017 +0000
Committer: Alex Heneveld <al...@cloudsoftcorp.com>
Committed: Fri Nov 10 04:16:46 2017 +0000

----------------------------------------------------------------------
 .../policy/failover/ElectPrimaryEffector.java    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/32c1771f/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryEffector.java
----------------------------------------------------------------------
diff --git a/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryEffector.java b/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryEffector.java
index decf96f..c85fba9 100644
--- a/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryEffector.java
+++ b/policy/src/main/java/org/apache/brooklyn/policy/failover/ElectPrimaryEffector.java
@@ -28,6 +28,7 @@ import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntityInitializer;
 import org.apache.brooklyn.api.entity.Group;
 import org.apache.brooklyn.api.mgmt.Task;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.effector.EffectorBody;
 import org.apache.brooklyn.core.effector.EffectorTasks.EffectorBodyTaskFactory;
@@ -75,6 +76,20 @@ public class ElectPrimaryEffector implements EntityInitializer, ElectPrimaryConf
     
     public static final Effector<Object> EFFECTOR = Effectors.effector(Object.class, "electPrimary").
         description("Scan to detect whether there is or should be a new primary").buildAbstract();
+
+    public static class PrimaryTransition {
+        public final Entity oldPrimary;
+        public final Entity newPrimary;
+        
+        public PrimaryTransition(Entity currentActive, Entity newPrimary) {
+            this.oldPrimary = currentActive;
+            this.newPrimary = newPrimary;
+        }
+    }
+    
+    public static final AttributeSensor<PrimaryTransition> PRIMARY_TRANSITION = Sensors.newSensor(
+        PrimaryTransition.class, "primary.transition", 
+        "Indicates primary is transitioning, cleared when completed");
     
     private final ConfigBag paramsCreationTime;
     
@@ -153,6 +168,7 @@ public class ElectPrimaryEffector implements EntityInitializer, ElectPrimaryConf
 //                    * set the local entity to the RUNNING state
                 
                 ServiceNotUpLogic.updateNotUpIndicator(entity(), "primary", "Invoking promotion/demotion effectors");
+                entity().sensors().set(PRIMARY_TRANSITION, new PrimaryTransition(currentActive, newPrimary));
                 boolean wasRunning = entity().sensors().get(Attributes.SERVICE_STATE_ACTUAL) == Lifecycle.RUNNING;
                 if (wasRunning) {
                     log.debug("Transititioning "+entity()+" to starting while promoting/demoting");
@@ -169,6 +185,9 @@ public class ElectPrimaryEffector implements EntityInitializer, ElectPrimaryConf
                     ServiceNotUpLogic.clearNotUpIndicator(entity(), "primary");
                     if (wasRunning) ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
                     
+                    entity().sensors().set(PRIMARY_TRANSITION, null);
+                    entity().sensors().remove(PRIMARY_TRANSITION);
+                    
                 } catch (Exception e) {
                     Exceptions.propagateIfFatal(e);
                     log.debug("Error promoting/demoting primary for "+entity()+" (rethrowing): "+e);