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 2016/09/30 09:00:30 UTC

[4/9] brooklyn-server git commit: BROOKLYN-325 on rebind set on fire parent app when its sensor is starting/stopping, not only child entities

BROOKLYN-325 on rebind set on fire parent app when its sensor is starting/stopping, not only child entities


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

Branch: refs/heads/master
Commit: 2520f0d0aa73d63169305543c4e9f104b17e16e3
Parents: 5906fb3
Author: Ivana Yovcheva <iv...@gmail.com>
Authored: Wed Sep 28 18:53:20 2016 +0300
Committer: Ivana Yovcheva <iv...@gmail.com>
Committed: Wed Sep 28 19:40:52 2016 +0300

----------------------------------------------------------------------
 .../entity/lifecycle/ServiceStateLogic.java     | 36 ++++++++++++++------
 .../core/mgmt/rebind/RebindIteration.java       |  9 ++++-
 .../software/base/SoftwareProcessImpl.java      | 15 ++------
 ...ftwareProcessRebindNotRunningEntityTest.java | 31 ++++++++---------
 4 files changed, 51 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2520f0d0/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
index e6ad754..1b76059 100644
--- a/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
+++ b/core/src/main/java/org/apache/brooklyn/core/entity/lifecycle/ServiceStateLogic.java
@@ -153,6 +153,26 @@ public class ServiceStateLogic {
     }
     
     public static void setExpectedState(Entity entity, Lifecycle state) {
+        waitForServiceUpIfStateIsRunning(entity, state);
+        ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state, new Date()));
+        
+        Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.enrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
+        if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState) {
+            ((ComputeServiceState)enricher.get()).onEvent(null);
+        }
+    }
+    public static Lifecycle getExpectedState(Entity entity) {
+        Transition expected = entity.getAttribute(Attributes.SERVICE_STATE_EXPECTED);
+        if (expected==null) return null;
+        return expected.getState();
+    }
+
+    public static void setActualState(Entity entity, Lifecycle state) {
+        waitForServiceUpIfStateIsRunning(entity, state);
+        ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_ACTUAL, state);
+    }
+
+    private static void waitForServiceUpIfStateIsRunning(Entity entity, Lifecycle state) {
         if (state==Lifecycle.RUNNING) {
             Boolean up = ((EntityInternal)entity).getAttribute(Attributes.SERVICE_UP);
             if (!Boolean.TRUE.equals(up) && !Boolean.TRUE.equals(Entities.isReadOnly(entity))) {
@@ -167,22 +187,16 @@ public class ServiceStateLogic {
                     log.debug("Had to wait "+Duration.of(timer)+" for "+entity+" "+Attributes.SERVICE_UP+" to be true before setting "+state);
                 } else {
                     log.warn("Service is not up when setting "+state+" on "+entity+"; delayed "+Duration.of(timer)+" "
-                        + "but "+Attributes.SERVICE_UP+" did not recover from "+up+"; not-up-indicators="+entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
+                            + "but "+Attributes.SERVICE_UP+" did not recover from "+up+"; not-up-indicators="+entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
                 }
             }
         }
-        ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state, new Date()));
-        
-        Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.enrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG);
-        if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState) {
-            ((ComputeServiceState)enricher.get()).onEvent(null);
-        }
     }
-    public static Lifecycle getExpectedState(Entity entity) {
-        Transition expected = entity.getAttribute(Attributes.SERVICE_STATE_EXPECTED);
-        if (expected==null) return null;
-        return expected.getState();
+
+    public static Lifecycle getActualState(Entity entity) {
+        return entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL);
     }
+
     public static boolean isExpectedState(Entity entity, Lifecycle state) {
         return getExpectedState(entity)==state;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2520f0d0/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index 4aee9a8..5d4685e 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -69,6 +69,8 @@ import org.apache.brooklyn.core.enricher.AbstractEnricher;
 import org.apache.brooklyn.core.entity.AbstractApplication;
 import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.entity.EntityInternal;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
+import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
 import org.apache.brooklyn.core.feed.AbstractFeed;
 import org.apache.brooklyn.core.location.AbstractLocation;
 import org.apache.brooklyn.core.location.internal.LocationInternal;
@@ -687,8 +689,13 @@ public abstract class RebindIteration {
         Set<String> oldEntities = Sets.newLinkedHashSet(entityManager.getEntityIds());
         for (Entity entity: rebindContext.getEntities()) {
             ManagementTransitionMode oldMode = updateTransitionMode(entityManager, entity);
-            if (oldMode!=null)
+            if (oldMode!=null) {
                 oldEntities.remove(entity.getId());
+            }
+
+            if (ServiceStateLogic.getExpectedState(entity) == Lifecycle.STARTING || ServiceStateLogic.getExpectedState(entity) == Lifecycle.STOPPING) {
+                ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE);
+            }
         }
         List<Application> apps = Lists.newArrayList();
         for (String rootId : getMementoRootEntities()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2520f0d0/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
index dbcfec6..6f88f6c 100644
--- a/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/org/apache/brooklyn/entity/software/base/SoftwareProcessImpl.java
@@ -439,27 +439,18 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft
     public void rebind() {
         //SERVICE_STATE_ACTUAL might be ON_FIRE due to a temporary condition (problems map non-empty)
         //Only if the expected state is ON_FIRE then the entity has permanently failed.
-        Transition expectedState = getAttribute(SERVICE_STATE_EXPECTED);
-        if (expectedState == null || expectedState.getState() != Lifecycle.RUNNING) {
-            //FIXME does not set on fire root application
-            if (expectedState.getState() == Lifecycle.STARTING || expectedState.getState() == Lifecycle.STOPPING) {
-                setAttribute(SERVICE_STATE_EXPECTED, new Lifecycle.Transition(Lifecycle.ON_FIRE, new Date()));
-                setAttribute(SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-            }
+        Lifecycle expectedState = ServiceStateLogic.getExpectedState(this);
+        if (expectedState == null || expectedState != Lifecycle.RUNNING) {
             LOG.warn("On rebind of {}, not calling software process rebind hooks because expected state is {}", this, expectedState);
             return;
         }
 
-        Lifecycle actualState = getAttribute(SERVICE_STATE_ACTUAL);
+        Lifecycle actualState = ServiceStateLogic.getActualState(this);
         if (actualState == null || actualState != Lifecycle.RUNNING) {
-            if (expectedState.getState() == Lifecycle.STARTING || expectedState.getState() == Lifecycle.STOPPING) {
-                setAttribute(SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-            }
             LOG.warn("Rebinding entity {}, even though actual state is {}. Expected state is {}", new Object[] { this, actualState, expectedState });
         }
 
         // e.g. rebinding to a running instance
-        // FIXME For rebind, what to do about things in STARTING or STOPPING state?
         // FIXME What if location not set?
         LOG.info("Rebind {} connecting to pre-running service", this);
         

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2520f0d0/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
index f318d0e..d118629 100644
--- a/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
@@ -75,22 +75,6 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
     // should tell the user that a VM might have started being provisioned but been forgotten about; or
     // that termination of the VM may or may not have completed.
     // We could use the Attributes.SERVICE_NOT_UP_INDICATORS to achieve that.
-    
-    // TODO Parent app should go on-fire after restart, but it doesn't - it continues saying "starting".
-    // We probably need to set the "service.state.expected" to on-fire on the parent as well (i.e. for 
-    // more things than just SoftwareProcess).
-    //    Sensor: service.notUp.indicators (java.util.Map) = {service.state=Application starting, service-lifecycle-indicators-from-children-and-members=VanillaSoftwareProcessImpl{id=nyijf1980z} is not up}
-    //    Sensor: entity.id (java.lang.String) = nz6qobkstx
-    //    Sensor: application.id (java.lang.String) = nz6qobkstx
-    //    Sensor: catalog.id (java.lang.String) = null
-    //    Sensor: service.isUp (java.lang.Boolean) = false
-    //    Sensor: service.problems (java.util.Map) = {service-lifecycle-indicators-from-children-and-members=Required entity not healthy: VanillaSoftwareProcessImpl{id=nyijf1980z}}
-    //    Sensor: service.state (org.apache.brooklyn.core.entity.lifecycle.Lifecycle) = starting
-    //    Sensor: service.state.expected (org.apache.brooklyn.core.entity.lifecycle.Lifecycle$Transition) = starting @ 1474967564852 / Tue Sep 27 10:12:44 BST 2016
-    //
-    // In each test, we should add at the end:
-    //   EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-    //   EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
 
     private ListeningExecutorService executor;
     private LocationSpec<SshMachineLocation> machineSpec;
@@ -166,6 +150,9 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
 
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
     }
 
     @Test
@@ -194,6 +181,9 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
 
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
     }
 
     @Test
@@ -224,6 +214,9 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
 
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
     }
 
     @Test
@@ -249,6 +242,9 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
 
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
     }
 
     @Test
@@ -276,6 +272,9 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
 
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
         EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
     }
 
     protected ListenableFuture<Void> startAsync(final Startable entity, final Collection<? extends Location> locs) {