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:27 UTC

[1/9] brooklyn-server git commit: BROOKLYN-325 Set starting/stopping entity on fire on rebind

Repository: brooklyn-server
Updated Branches:
  refs/heads/master aca3a4997 -> 211694966


BROOKLYN-325 Set starting/stopping entity on fire on rebind


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

Branch: refs/heads/master
Commit: 001b02cdaeb5f6686ba57dc81cb0e30d4fc34dd7
Parents: 1db462a
Author: Ivana Yovcheva <iv...@gmail.com>
Authored: Fri Sep 23 04:38:46 2016 +0200
Committer: Ivana Yovcheva <iv...@gmail.com>
Committed: Fri Sep 23 10:23:13 2016 +0200

----------------------------------------------------------------------
 .../software/base/SoftwareProcessImpl.java      |  9 ++
 ...ftwareProcessRebindNotRunningEntityTest.java | 98 ++++++++++++++++++++
 2 files changed, 107 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/001b02cd/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 0d4dbda..dbcfec6 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
@@ -25,6 +25,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.Date;
 import java.util.concurrent.Callable;
 import java.util.concurrent.TimeUnit;
 
@@ -440,12 +441,20 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements Soft
         //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);
+            }
             LOG.warn("On rebind of {}, not calling software process rebind hooks because expected state is {}", this, expectedState);
             return;
         }
 
         Lifecycle actualState = getAttribute(SERVICE_STATE_ACTUAL);
         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 });
         }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/001b02cd/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
new file mode 100644
index 0000000..3fb2188
--- /dev/null
+++ b/software/base/src/test/java/org/apache/brooklyn/entity/software/base/SoftwareProcessRebindNotRunningEntityTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.brooklyn.entity.software.base;
+
+import com.google.common.collect.ImmutableList;
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.core.entity.EntityAsserts;
+import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
+import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.test.Asserts;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.util.Date;
+import java.util.List;
+
+public class SoftwareProcessRebindNotRunningEntityTest extends BrooklynAppUnitTestSupport {
+
+    private List<LocalhostMachineProvisioningLocation> locations;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        super.setUp();
+        locations =  ImmutableList.of(app.newLocalhostProvisioningLocation());
+    }
+
+    //TODO cover more cases and all entity states
+
+    @Test
+    public void testRebindAfterStarting() {
+        MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class));
+        entity.start(locations); //FIXME - NPE
+        //TODO find better solution to rebind starting app than only setting its attributes
+        ((MyServiceImpl) entity).setAttribute(entity.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(Lifecycle.ON_FIRE, new Date()));
+        ((MyServiceImpl) entity).setAttribute(entity.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+        ((MyServiceImpl) entity).rebind();
+
+        assertEntityIsOnFire(entity);
+    }
+
+    @Test
+    public void testRebindAfterStopping() {
+
+    }
+
+    @Test
+    public void testRebindRunningEntity() {
+        MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class));
+        entity.start(locations);
+        ((MyServiceImpl) entity).rebind();
+        assertEntityIsRunning(entity);
+    }
+
+    //TODO - more precise assert?
+    protected void assertEntityIsOnFire(MyService entity) {
+        EntityAsserts.assertAttributeEquals(entity, entity.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        //TODO assert SERVICE_STATE_EXPECTED
+    }
+
+    protected void assertEntityIsRunning(MyService entity) {
+        Asserts.assertTrue(((MyServiceImpl) entity).getDriver().isRunning());
+    }
+
+    //TODO
+    @ImplementedBy(MyServiceImpl.class)
+    public interface MyService extends SoftwareProcess {
+    }
+
+    public static class MyServiceImpl extends SoftwareProcessImpl implements MyService {
+        public MyServiceImpl() {}
+        public MyServiceImpl(Entity parent) { super(parent); }
+
+        @Override
+        public Class getDriverInterface() {
+            return null;
+        }
+    }
+}
\ No newline at end of file


[9/9] brooklyn-server git commit: This closes #356

Posted by al...@apache.org.
This closes #356


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

Branch: refs/heads/master
Commit: 211694966c2696604b32f45919ed387dffd97798
Parents: aca3a49 9b88108
Author: Aled Sage <al...@gmail.com>
Authored: Fri Sep 30 10:00:11 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Fri Sep 30 10:00:11 2016 +0100

----------------------------------------------------------------------
 .../JcloudsRebindWithExternalConfigTest.java    |   5 +-
 .../brooklyn/camp/brooklyn/RebindOsgiTest.java  |   5 +-
 .../entity/lifecycle/ServiceStateLogic.java     |  33 +-
 .../AbstractBrooklynObjectRebindSupport.java    |   8 +-
 .../mgmt/rebind/BasicEntityRebindSupport.java   |  18 +
 .../core/mgmt/rebind/RebindCatalogItemTest.java |   4 +-
 ...talogWhenCatalogPersistenceDisabledTest.java |   4 +-
 .../core/mgmt/rebind/RebindOptions.java         |   7 +
 .../core/mgmt/rebind/RebindTestFixture.java     |  45 +++
 .../core/mgmt/rebind/RebindTestUtils.java       |  17 +-
 .../core/internal/ssh/RecordingSshTool.java     |   9 +-
 .../software/base/SoftwareProcessImpl.java      |   8 +-
 ...ClockerDynamicLocationPatternRebindTest.java |   5 +-
 ...ftwareProcessRebindNotRunningEntityTest.java | 385 +++++++++++++++++++
 14 files changed, 522 insertions(+), 31 deletions(-)
----------------------------------------------------------------------



[7/9] brooklyn-server git commit: Merge pull request #5 from aledsage/iyovcheva-aled/rebind-entity-starting-2

Posted by al...@apache.org.
Merge pull request #5 from aledsage/iyovcheva-aled/rebind-entity-starting-2

Set on-fire in BasicEntityRebindSupport

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

Branch: refs/heads/master
Commit: 8fa71f7107767156382661c65de22f84d6b7b4d6
Parents: 2520f0d 4bba21d
Author: iyovcheva <iv...@gmail.com>
Authored: Thu Sep 29 17:11:17 2016 +0300
Committer: GitHub <no...@github.com>
Committed: Thu Sep 29 17:11:17 2016 +0300

----------------------------------------------------------------------
 .../JcloudsRebindWithExternalConfigTest.java    |  5 ++-
 .../brooklyn/camp/brooklyn/RebindOsgiTest.java  |  5 ++-
 .../entity/lifecycle/ServiceStateLogic.java     | 11 ++----
 .../AbstractBrooklynObjectRebindSupport.java    |  8 +++-
 .../mgmt/rebind/BasicEntityRebindSupport.java   | 14 +++++++
 .../core/mgmt/rebind/RebindIteration.java       |  4 --
 .../core/mgmt/rebind/RebindCatalogItemTest.java |  4 +-
 ...talogWhenCatalogPersistenceDisabledTest.java |  4 +-
 .../core/mgmt/rebind/RebindOptions.java         |  7 ++++
 .../core/mgmt/rebind/RebindTestFixture.java     | 41 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindTestUtils.java       | 17 ++++++--
 ...ClockerDynamicLocationPatternRebindTest.java |  5 ++-
 ...ftwareProcessRebindNotRunningEntityTest.java | 39 +++++++++++++++++++
 13 files changed, 139 insertions(+), 25 deletions(-)
----------------------------------------------------------------------



[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

Posted by al...@apache.org.
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) {


[2/9] brooklyn-server git commit: Add tests to SoftwareProcessRebindNotRunningEntityTest

Posted by al...@apache.org.
Add tests to SoftwareProcessRebindNotRunningEntityTest


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

Branch: refs/heads/master
Commit: 5d252d7ef1ec3f35ce874c05db95c9db2d9e2774
Parents: 001b02c
Author: Aled Sage <al...@gmail.com>
Authored: Mon Sep 26 22:13:38 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Sep 27 10:36:58 2016 +0100

----------------------------------------------------------------------
 .../core/mgmt/rebind/RebindTestFixture.java     |   4 +
 .../core/internal/ssh/RecordingSshTool.java     |   9 +-
 ...ftwareProcessRebindNotRunningEntityTest.java | 341 ++++++++++++++++---
 3 files changed, 310 insertions(+), 44 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5d252d7e/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index 819b8f0..9a81cea 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -147,6 +147,10 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
         return (newManagementContext != null) ? newManagementContext : origManagementContext;
     }
     
+    protected T app() {
+        return (newApp != null) ? newApp : origApp;
+    }
+    
     public static void waitForTaskCountToBecome(final ManagementContext mgmt, final int allowedMax) {
         waitForTaskCountToBecome(mgmt, allowedMax, false);
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5d252d7e/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/RecordingSshTool.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/RecordingSshTool.java b/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/RecordingSshTool.java
index 2ac8acf..04e78cf 100644
--- a/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/RecordingSshTool.java
+++ b/core/src/test/java/org/apache/brooklyn/util/core/internal/ssh/RecordingSshTool.java
@@ -72,7 +72,7 @@ public class RecordingSshTool implements SshTool {
     }
 
     public interface CustomResponseGenerator {
-        public CustomResponse generate(ExecParams execParams);
+        public CustomResponse generate(ExecParams execParams) throws Exception;
     }
 
     public static class CustomResponse {
@@ -225,7 +225,12 @@ public class RecordingSshTool implements SshTool {
             for (Entry<String, CustomResponseGenerator> entry : customResponses.entrySet()) {
                 if (cmd.matches(entry.getKey())) {
                     CustomResponseGenerator responseGenerator = entry.getValue();
-                    CustomResponse response = responseGenerator.generate(new ExecParams(props, commands, env));
+                    CustomResponse response;
+                    try {
+                        response = responseGenerator.generate(new ExecParams(props, commands, env));
+                    } catch (Exception e) {
+                        throw Exceptions.propagate(e);
+                    }
                     writeCustomResponseStreams(props, response);
                     return response.exitCode;
                 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5d252d7e/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 3fb2188..f318d0e 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
@@ -16,83 +16,340 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.brooklyn.entity.software.base;
 
-import com.google.common.collect.ImmutableList;
-import org.apache.brooklyn.api.entity.Entity;
+import static org.testng.Assert.assertTrue;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
 import org.apache.brooklyn.api.entity.EntitySpec;
-import org.apache.brooklyn.api.entity.ImplementedBy;
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.location.MachineLocation;
+import org.apache.brooklyn.api.location.MachineProvisioningLocation;
+import org.apache.brooklyn.api.location.NoMachinesAvailableException;
+import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.ConfigKeys;
+import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
-import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
-import org.apache.brooklyn.location.localhost.LocalhostMachineProvisioningLocation;
+import org.apache.brooklyn.core.entity.trait.Startable;
+import org.apache.brooklyn.core.location.AbstractLocation;
+import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.apache.brooklyn.location.byon.FixedListMachineProvisioningLocation;
+import org.apache.brooklyn.location.ssh.SshMachineLocation;
 import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool;
+import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.CustomResponse;
+import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.CustomResponseGenerator;
+import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecParams;
+import org.apache.brooklyn.util.exceptions.Exceptions;
+import org.apache.brooklyn.util.time.Duration;
+import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 
-import java.util.Date;
-import java.util.List;
+import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.reflect.TypeToken;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.MoreExecutors;
 
-public class SoftwareProcessRebindNotRunningEntityTest extends BrooklynAppUnitTestSupport {
+public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixtureWithApp {
 
-    private List<LocalhostMachineProvisioningLocation> locations;
+    // TODO We'd like to record the fact that we were starting or stopping, rather than just say "on-fire".
+    // For example, we can use the Attributes.SERVICE_NOT_UP_INDICATORS to say what went wrong.
+    
+    // TODO If we fail during provisioningLocation.obtain() or provisioningLocation.release(), then we
+    // 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;
+    private FixedListMachineProvisioningLocation<?> locationProvisioner;
+    
+    // We track the latches, so we can countDown() them all to unblock them. Otherwise they can
+    // interfere with tearDown by blocking threads.
+    // TODO Longer term, we should investigate/fix that so tearDown finishes promptly no matter what!
+    private List<CountDownLatch> latches;
+    
     @BeforeMethod(alwaysRun=true)
+    @Override
     public void setUp() throws Exception {
         super.setUp();
-        locations =  ImmutableList.of(app.newLocalhostProvisioningLocation());
+
+        latches = Lists.newCopyOnWriteArrayList();
+        
+        machineSpec = LocationSpec.create(SshMachineLocation.class)
+                .configure("address", "1.2.3.4")
+                .configure(SshMachineLocation.SSH_TOOL_CLASS, RecordingSshTool.class.getName());
+        
+        locationProvisioner = app().getManagementContext().getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class)
+                .configure(FixedListMachineProvisioningLocation.MACHINE_SPECS, ImmutableList.<LocationSpec<? extends MachineLocation>>of(
+                        machineSpec)));
+
+        executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
+        
+        RecordingSshTool.clear();
     }
 
-    //TODO cover more cases and all entity states
+    @AfterMethod(alwaysRun=true)
+    @Override
+    public void tearDown() throws Exception {
+        try {
+            for (CountDownLatch latch : latches) {
+                while (latch.getCount() > 0) {
+                    latch.countDown();
+                }
+            }
+            super.tearDown();
+            if (executor != null) executor.shutdownNow();
+        } finally {
+            RecordingSshTool.clear();
+        }
+    }
+
+    @Override
+    protected TestApplication createApp() {
+        return mgmt().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
+    }
+
+    @Test
+    public void testRebindWhileWaitingForCheckRunning() throws Exception {
+        final CountDownLatch checkRunningCalledLatch = newLatch(1);
+        RecordingSshTool.setCustomResponse(".*myCheckRunning.*", new CustomResponseGenerator() {
+            @Override
+            public CustomResponse generate(ExecParams execParams) {
+                checkRunningCalledLatch.countDown();
+                return new CustomResponse(1, "", "");
+            }});
+        
+        VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch")
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning"));
+        
+        startAsync(app(), ImmutableList.of(locationProvisioner));
+        awaitOrFail(checkRunningCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT);
+
+        EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+
+        TestApplication newApp = rebind();
+        final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
+
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+    }
+
+    @Test
+    public void testRebindWhileLaunching() throws Exception {
+        final CountDownLatch launchCalledLatch = newLatch(1);
+        final CountDownLatch launchBlockedLatch = newLatch(1);
+        RecordingSshTool.setCustomResponse(".*myLaunch.*", new CustomResponseGenerator() {
+            @Override
+            public CustomResponse generate(ExecParams execParams) throws Exception {
+                launchCalledLatch.countDown();
+                launchBlockedLatch.await();
+                return new CustomResponse(0, "", "");
+            }});
+        
+        VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch")
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning"));
+        
+        startAsync(app(), ImmutableList.of(locationProvisioner));
+        awaitOrFail(launchCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT);
+
+        EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+
+        TestApplication newApp = rebind();
+        final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
+
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
+    }
 
     @Test
-    public void testRebindAfterStarting() {
-        MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class));
-        entity.start(locations); //FIXME - NPE
-        //TODO find better solution to rebind starting app than only setting its attributes
-        ((MyServiceImpl) entity).setAttribute(entity.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(Lifecycle.ON_FIRE, new Date()));
-        ((MyServiceImpl) entity).setAttribute(entity.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
-        ((MyServiceImpl) entity).rebind();
-
-        assertEntityIsOnFire(entity);
+    public void testRebindWhileStoppingProcess() throws Exception {
+        final CountDownLatch stopCalledLatch = newLatch(1);
+        final CountDownLatch stopBlockedLatch = newLatch(1);
+        RecordingSshTool.setCustomResponse(".*myStop.*", new CustomResponseGenerator() {
+            @Override
+            public CustomResponse generate(ExecParams execParams) throws Exception {
+                stopCalledLatch.countDown();
+                stopBlockedLatch.await();
+                return new CustomResponse(0, "", "");
+            }});
+        
+        VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch")
+                .configure(VanillaSoftwareProcess.STOP_COMMAND, "myStop")
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning"));
+        app().start(ImmutableList.of(locationProvisioner));
+        
+        stopAsync(entity);
+        awaitOrFail(stopCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT);
+
+        EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPING);
+
+        TestApplication newApp = rebind();
+        final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
+
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
     }
 
     @Test
-    public void testRebindAfterStopping() {
+    public void testRebindWhileProvisioning() throws Exception {
+        final CountDownLatch obtainCalledLatch = newLatch(1);
+        final CountDownLatch obtainBlockedLatch = newLatch(1);
+        MyProvisioningLocation blockingProvisioner = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
+                .configure(MyProvisioningLocation.OBTAIN_CALLED_LATCH, obtainCalledLatch)
+                .configure(MyProvisioningLocation.OBTAIN_BLOCKED_LATCH, obtainBlockedLatch)
+                .configure(MyProvisioningLocation.MACHINE_SPEC, machineSpec));
+        
+        VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch")
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning"));
+        
+        startAsync(app(), ImmutableList.of(blockingProvisioner));
+        awaitOrFail(obtainCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT);
+
+        EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+
+        TestApplication newApp = rebind();
+        final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
 
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
     }
 
     @Test
-    public void testRebindRunningEntity() {
-        MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class));
-        entity.start(locations);
-        ((MyServiceImpl) entity).rebind();
-        assertEntityIsRunning(entity);
+    public void testRebindWhileTerminatingVm() throws Exception {
+        final CountDownLatch releaseCalledLatch = newLatch(1);
+        final CountDownLatch obtainBlockedLatch = newLatch(1);
+        MyProvisioningLocation blockingProvisioner = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
+                .configure(MyProvisioningLocation.RELEASE_CALLED_LATCH, releaseCalledLatch)
+                .configure(MyProvisioningLocation.RELEASE_BLOCKED_LATCH, obtainBlockedLatch)
+                .configure(MyProvisioningLocation.MACHINE_SPEC, machineSpec));
+        
+        VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch")
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning"));
+        
+        app().start(ImmutableList.of(blockingProvisioner));
+        
+        stopAsync(entity);
+        awaitOrFail(releaseCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT);
+
+        EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPING);
+
+        TestApplication newApp = rebind();
+        final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
+
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
+        EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_UP, false);
     }
 
-    //TODO - more precise assert?
-    protected void assertEntityIsOnFire(MyService entity) {
-        EntityAsserts.assertAttributeEquals(entity, entity.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);
-        //TODO assert SERVICE_STATE_EXPECTED
+    protected ListenableFuture<Void> startAsync(final Startable entity, final Collection<? extends Location> locs) {
+        return executor.submit(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                entity.start(locs);
+                return null;
+            }});
     }
 
-    protected void assertEntityIsRunning(MyService entity) {
-        Asserts.assertTrue(((MyServiceImpl) entity).getDriver().isRunning());
+    protected ListenableFuture<Void> stopAsync(final Startable entity) {
+        return executor.submit(new Callable<Void>() {
+            @Override public Void call() throws Exception {
+                entity.stop();
+                return null;
+            }});
     }
 
-    //TODO
-    @ImplementedBy(MyServiceImpl.class)
-    public interface MyService extends SoftwareProcess {
+    protected void awaitOrFail(CountDownLatch latch, Duration timeout) throws Exception {
+        boolean success = latch.await(timeout.toMilliseconds(), TimeUnit.MILLISECONDS);
+        assertTrue(success, "latch "+latch+" not satisfied in "+timeout);
+    }
+    
+    protected CountDownLatch newLatch(int count) {
+        CountDownLatch result = new CountDownLatch(count);
+        latches.add(result);
+        return result;
     }
 
-    public static class MyServiceImpl extends SoftwareProcessImpl implements MyService {
-        public MyServiceImpl() {}
-        public MyServiceImpl(Entity parent) { super(parent); }
+    public static class MyProvisioningLocation extends AbstractLocation implements MachineProvisioningLocation<SshMachineLocation> {
+        public static final ConfigKey<CountDownLatch> OBTAIN_CALLED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "obtainCalledLatch");
+        public static final ConfigKey<CountDownLatch> OBTAIN_BLOCKED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "obtainBlockedLatch");
+        public static final ConfigKey<CountDownLatch> RELEASE_CALLED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "releaseCalledLatch");
+        public static final ConfigKey<CountDownLatch> RELEASE_BLOCKED_LATCH = ConfigKeys.newConfigKey(CountDownLatch.class, "releaseBlockedLatch");
+        public static final ConfigKey<LocationSpec<SshMachineLocation>> MACHINE_SPEC = ConfigKeys.newConfigKey(
+                new TypeToken<LocationSpec<SshMachineLocation>>() {},
+                "machineSpec");
+
+        @Override
+        public MachineProvisioningLocation<SshMachineLocation> newSubLocation(Map<?, ?> newFlags) {
+            throw new UnsupportedOperationException();
+        }
+        
+        @Override
+        public SshMachineLocation obtain(Map<?,?> flags) throws NoMachinesAvailableException {
+            CountDownLatch calledLatch = config().get(OBTAIN_CALLED_LATCH);
+            CountDownLatch blockedLatch = config().get(OBTAIN_BLOCKED_LATCH);
+            LocationSpec<SshMachineLocation> machineSpec = config().get(MACHINE_SPEC);
+            
+            if (calledLatch != null) calledLatch.countDown();
+            try {
+                if (blockedLatch != null) blockedLatch.await();
+            } catch (InterruptedException e) {
+                throw Exceptions.propagate(e);
+            }
+            return getManagementContext().getLocationManager().createLocation(machineSpec);
+        }
+
+        @Override
+        public void release(SshMachineLocation machine) {
+            CountDownLatch calledLatch = config().get(RELEASE_CALLED_LATCH);
+            CountDownLatch blockedLatch = config().get(RELEASE_BLOCKED_LATCH);
+            
+            if (calledLatch != null) calledLatch.countDown();
+            try {
+                if (blockedLatch != null) blockedLatch.await();
+            } catch (InterruptedException e) {
+                throw Exceptions.propagate(e);
+            }
+        }
 
         @Override
-        public Class getDriverInterface() {
-            return null;
+        public Map getProvisioningFlags(Collection<String> tags) {
+            return Collections.emptyMap();
         }
     }
-}
\ No newline at end of file
+}


[6/9] brooklyn-server git commit: Test hot-standby in SoftwareProcessRebindNotRunningEntityTest

Posted by al...@apache.org.
Test hot-standby in SoftwareProcessRebindNotRunningEntityTest


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

Branch: refs/heads/master
Commit: 643b19bc8e82104d59c04214a232eca0606b0e83
Parents: 2520f0d
Author: Aled Sage <al...@gmail.com>
Authored: Thu Sep 29 13:58:38 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Sep 29 14:42:15 2016 +0100

----------------------------------------------------------------------
 .../JcloudsRebindWithExternalConfigTest.java    |  5 ++-
 .../brooklyn/camp/brooklyn/RebindOsgiTest.java  |  5 ++-
 .../core/mgmt/rebind/RebindCatalogItemTest.java |  4 +-
 ...talogWhenCatalogPersistenceDisabledTest.java |  4 +-
 .../core/mgmt/rebind/RebindOptions.java         |  7 ++++
 .../core/mgmt/rebind/RebindTestFixture.java     | 41 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindTestUtils.java       | 17 ++++++--
 ...ClockerDynamicLocationPatternRebindTest.java |  5 ++-
 ...ftwareProcessRebindNotRunningEntityTest.java | 39 +++++++++++++++++++
 9 files changed, 116 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
index 4d6064f..160a9c2 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/JcloudsRebindWithExternalConfigTest.java
@@ -26,6 +26,7 @@ import java.util.Map;
 import org.apache.brooklyn.api.entity.Application;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.camp.brooklyn.spi.creation.CampTypePlanTransformer;
 import org.apache.brooklyn.core.config.external.InPlaceExternalConfigSupplier;
 import org.apache.brooklyn.core.entity.trait.Startable;
@@ -105,11 +106,11 @@ public class JcloudsRebindWithExternalConfigTest extends JcloudsRebindStubTest {
     }
 
     @Override
-    protected LocalManagementContext createNewManagementContext(final File mementoDir) {
+    protected LocalManagementContext createNewManagementContext(final File mementoDir, final HighAvailabilityMode haMode) {
         newLauncher = new BrooklynCampPlatformLauncherNoServer() {
             @Override
             protected LocalManagementContext newMgmtContext() {
-                return JcloudsRebindWithExternalConfigTest.super.createNewManagementContext(mementoDir);
+                return JcloudsRebindWithExternalConfigTest.super.createNewManagementContext(mementoDir, haMode);
             }
         };
         newLauncher.launch();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
index b4310e8..5d7bd0f 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/RebindOsgiTest.java
@@ -28,6 +28,7 @@ import java.util.List;
 
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.core.catalog.internal.CatalogUtils;
 import org.apache.brooklyn.core.config.ConfigKeys;
@@ -90,8 +91,8 @@ public class RebindOsgiTest extends AbstractYamlRebindTest {
     }
     
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir) {
-        LocalManagementContext result = super.createNewManagementContext(mementoDir);
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode haMode) {
+        LocalManagementContext result = super.createNewManagementContext(mementoDir, haMode);
         for (String bundleUrl : bundleUrlsToInstallOnRebind) {
             try {
                 installBundle(result, bundleUrl);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
index 26e1a93..624e733 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogItemTest.java
@@ -29,6 +29,7 @@ import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.catalog.CatalogItem.CatalogItemType;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.api.typereg.RegisteredType;
 import org.apache.brooklyn.core.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.catalog.internal.BasicBrooklynCatalog;
@@ -92,12 +93,13 @@ public class RebindCatalogItemTest extends RebindTestFixtureWithApp {
     }
 
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir) {
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode haMode) {
         BrooklynProperties properties = BrooklynProperties.Factory.newDefault();
         properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, "classpath://brooklyn/entity/rebind/rebind-catalog-item-test-catalog.xml");
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .properties(properties)
                 .forLive(useLiveManagementContext())
+                .haMode(haMode)
                 .emptyCatalog(useEmptyCatalog())
                 .buildUnstarted();
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
index 65cd1da..70d5a16 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindCatalogWhenCatalogPersistenceDisabledTest.java
@@ -24,6 +24,7 @@ import java.io.File;
 
 import org.apache.brooklyn.api.catalog.CatalogItem;
 import org.apache.brooklyn.api.entity.EntitySpec;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.core.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
@@ -68,12 +69,13 @@ public class RebindCatalogWhenCatalogPersistenceDisabledTest extends RebindTestF
     }
 
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir) {
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode haMode) {
         BrooklynProperties properties = BrooklynProperties.Factory.newDefault();
         properties.put(BrooklynServerConfig.BROOKLYN_CATALOG_URL, TEST_CATALOG);
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .properties(properties)
                 .forLive(useLiveManagementContext())
+                .haMode(haMode)
                 .buildUnstarted();
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
index eea64d6..618a906 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindOptions.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.core.mgmt.rebind;
 import java.io.File;
 
 import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.api.mgmt.rebind.RebindExceptionHandler;
 import org.apache.brooklyn.api.mgmt.rebind.mementos.BrooklynMementoPersister;
 import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
@@ -41,6 +42,7 @@ public class RebindOptions {
     public Function<BrooklynMementoPersister, Void> stateTransformer;
     public ClassLoader classLoader;
     public PersistenceObjectStore objectStore;
+    public HighAvailabilityMode haMode;
     
     public static RebindOptions create() {
         return new RebindOptions();
@@ -57,6 +59,7 @@ public class RebindOptions {
         result.stateTransformer(options.stateTransformer);
         result.classLoader(options.classLoader);
         result.objectStore(options.objectStore);
+        result.haMode(options.haMode);
         return result;
     }
     public RebindOptions checkSerializable(boolean val) {
@@ -99,4 +102,8 @@ public class RebindOptions {
         this.objectStore = val;
         return this;
     }
+    public RebindOptions haMode(HighAvailabilityMode val) {
+        this.haMode = val;
+        return this;
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
index 9a81cea..5af282b 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestFixture.java
@@ -43,6 +43,7 @@ import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
 import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
 import org.apache.brooklyn.core.mgmt.persist.PersistMode;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
@@ -102,6 +103,7 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
 
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .persistPeriodMillis(getPersistPeriodMillis())
+                .haMode(getHaMode())
                 .forLive(useLiveManagementContext())
                 .enablePersistenceBackups(enablePersistenceBackups())
                 .emptyCatalog(useEmptyCatalog())
@@ -110,6 +112,10 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
                 .buildStarted();
     }
 
+    protected HighAvailabilityMode getHaMode() {
+        return HighAvailabilityMode.DISABLED;
+    }
+    
     protected boolean enablePersistenceBackups() {
         return true;
     }
@@ -121,9 +127,14 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
     
     /** @return An unstarted management context using the specified mementoDir (or default if null) */
     protected LocalManagementContext createNewManagementContext(File mementoDir) {
+        return createNewManagementContext(mementoDir, getHaMode());
+    }
+    
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode haMode) {
         if (mementoDir==null) mementoDir = this.mementoDir;
         return RebindTestUtils.managementContextBuilder(mementoDir, classLoader)
                 .forLive(useLiveManagementContext())
+                .haMode(haMode)
                 .emptyCatalog(useEmptyCatalog())
                 .properties(createBrooklynProperties())
                 .enableOsgi(useOsgi())
@@ -286,6 +297,36 @@ public abstract class RebindTestFixture<T extends StartableApplication> {
         return newApp;
     }
 
+    protected T hotStandby() throws Exception {
+        return hotStandby(RebindOptions.create());
+    }
+
+    protected T hotStandby(RebindOptions options) throws Exception {
+        if (newApp != null || newManagementContext != null) {
+            throw new IllegalStateException("already rebound - use switchOriginalToNewManagementContext() if you are trying to rebind multiple times");
+        }
+        if (options.haMode != null && options.haMode != HighAvailabilityMode.HOT_STANDBY) {
+            throw new IllegalStateException("hotStandby called, but with HA Mode set to "+options.haMode);
+        }
+        if (options.terminateOrigManagementContext) {
+            throw new IllegalStateException("hotStandby called with terminateOrigManagementContext==true");
+        }
+        
+        options = RebindOptions.create(options);
+        options.terminateOrigManagementContext(false);
+        if (options.haMode == null) options.haMode(HighAvailabilityMode.HOT_STANDBY);
+        if (options.classLoader == null) options.classLoader(classLoader);
+        if (options.mementoDir == null) options.mementoDir(mementoDir);
+        if (options.origManagementContext == null) options.origManagementContext(origManagementContext);
+        if (options.newManagementContext == null) options.newManagementContext(createNewManagementContext(options.mementoDir, options.haMode));
+        
+        RebindTestUtils.waitForPersisted(origApp);
+        
+        newManagementContext = options.newManagementContext;
+        newApp = (T) RebindTestUtils.rebind(options);
+        return newApp;
+    }
+
     /**
      * Dumps out the persisted mementos that are at the given directory.
      * 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
index ad2bdf8..af3a5e4 100644
--- a/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
+++ b/core/src/test/java/org/apache/brooklyn/core/mgmt/rebind/RebindTestUtils.java
@@ -44,6 +44,7 @@ import org.apache.brooklyn.core.mgmt.ha.ManagementPlaneSyncRecordPersisterToObje
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
 import org.apache.brooklyn.core.mgmt.persist.BrooklynMementoPersisterToObjectStore;
+import org.apache.brooklyn.core.mgmt.persist.BrooklynPersistenceUtils;
 import org.apache.brooklyn.core.mgmt.persist.FileBasedObjectStore;
 import org.apache.brooklyn.core.mgmt.persist.PersistMode;
 import org.apache.brooklyn.core.mgmt.persist.PersistenceObjectStore;
@@ -150,6 +151,7 @@ public class RebindTestUtils {
         BrooklynProperties properties;
         PersistenceObjectStore objectStore;
         Duration persistPeriod = Duration.millis(100);
+        HighAvailabilityMode haMode;
         boolean forLive;
         boolean enableOsgi = false;
         boolean emptyCatalog;
@@ -205,6 +207,11 @@ public class RebindTestUtils {
             return this;
         }
 
+        public ManagementContextBuilder haMode(HighAvailabilityMode val) {
+            this.haMode = val;
+            return this;
+        }
+
         public LocalManagementContext buildUnstarted() {
             LocalManagementContext unstarted;
             BrooklynProperties properties = this.properties != null
@@ -225,7 +232,7 @@ public class RebindTestUtils {
             }
             
             objectStore.injectManagementContext(unstarted);
-            objectStore.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.DISABLED);
+            objectStore.prepareForSharedUse(PersistMode.AUTO, (haMode == null ? HighAvailabilityMode.DISABLED : haMode));
             BrooklynMementoPersisterToObjectStore newPersister = new BrooklynMementoPersisterToObjectStore(
                     objectStore, 
                     unstarted.getBrooklynProperties(), 
@@ -394,6 +401,7 @@ public class RebindTestUtils {
         ManagementContextInternal origManagementContext = (ManagementContextInternal) options.origManagementContext;
         ManagementContextInternal newManagementContext = (ManagementContextInternal) options.newManagementContext;
         PersistenceObjectStore objectStore = options.objectStore;
+        HighAvailabilityMode haMode = (options.haMode == null ? HighAvailabilityMode.DISABLED : options.haMode);
         RebindExceptionHandler exceptionHandler = options.exceptionHandler;
         boolean hasPersister = newManagementContext != null && newManagementContext.getRebindManager().getPersister() != null;
         boolean checkSerializable = options.checkSerializable;
@@ -412,7 +420,7 @@ public class RebindTestUtils {
                 objectStore = new FileBasedObjectStore(checkNotNull(mementoDir, "mementoDir and objectStore must not both be null"));
             }
             objectStore.injectManagementContext(newManagementContext);
-            objectStore.prepareForSharedUse(PersistMode.AUTO, HighAvailabilityMode.DISABLED);
+            objectStore.prepareForSharedUse(PersistMode.AUTO, haMode);
             
             BrooklynMementoPersisterToObjectStore newPersister = new BrooklynMementoPersisterToObjectStore(
                     objectStore,
@@ -443,7 +451,10 @@ public class RebindTestUtils {
             stateTransformer.apply(persister);
         }
         
-        List<Application> newApps = newManagementContext.getRebindManager().rebind(classLoader, exceptionHandler, ManagementNodeState.MASTER);
+        List<Application> newApps = newManagementContext.getRebindManager().rebind(
+                classLoader, 
+                exceptionHandler, 
+                (haMode == HighAvailabilityMode.DISABLED) ? ManagementNodeState.MASTER : ManagementNodeState.of(haMode).get());
         newManagementContext.getRebindManager().startPersistence();
         return newApps;
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
----------------------------------------------------------------------
diff --git a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
index 6ccd86c..288bd5e 100644
--- a/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
+++ b/software/base/src/test/java/org/apache/brooklyn/core/location/dynamic/clocker/ClockerDynamicLocationPatternRebindTest.java
@@ -29,6 +29,7 @@ import java.util.Map;
 import org.apache.brooklyn.api.entity.Entity;
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
 import org.apache.brooklyn.core.entity.Entities;
 import org.apache.brooklyn.core.location.BasicLocationRegistry;
@@ -56,8 +57,8 @@ public class ClockerDynamicLocationPatternRebindTest extends RebindTestFixtureWi
     }
     
     @Override
-    protected LocalManagementContext createNewManagementContext(File mementoDir) {
-        LocalManagementContext result = super.createNewManagementContext(mementoDir);
+    protected LocalManagementContext createNewManagementContext(File mementoDir, HighAvailabilityMode haMode) {
+        LocalManagementContext result = super.createNewManagementContext(mementoDir, haMode);
         StubResolver stubResolver = new StubResolver();
         ((BasicLocationRegistry)result.getLocationRegistry()).registerResolver(stubResolver);
         return result;

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/643b19bc/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 d118629..0e38e3f 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
@@ -18,6 +18,7 @@
  */
 package org.apache.brooklyn.entity.software.base;
 
+import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
 
 import java.util.Collection;
@@ -35,6 +36,7 @@ import org.apache.brooklyn.api.location.LocationSpec;
 import org.apache.brooklyn.api.location.MachineLocation;
 import org.apache.brooklyn.api.location.MachineProvisioningLocation;
 import org.apache.brooklyn.api.location.NoMachinesAvailableException;
+import org.apache.brooklyn.api.mgmt.ha.HighAvailabilityMode;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.Attributes;
@@ -126,6 +128,11 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         return mgmt().getEntityManager().createEntity(EntitySpec.create(TestApplication.class));
     }
 
+    @Override
+    protected HighAvailabilityMode getHaMode() {
+        return HighAvailabilityMode.MASTER;
+    }
+
     @Test
     public void testRebindWhileWaitingForCheckRunning() throws Exception {
         final CountDownLatch checkRunningCalledLatch = newLatch(1);
@@ -277,6 +284,38 @@ public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixture
         EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_UP, false);
     }
 
+    @Test
+    public void testLaunchHotStandbyWhileEntityStarting() throws Exception {
+        final CountDownLatch launchCalledLatch = newLatch(1);
+        final CountDownLatch launchBlockedLatch = newLatch(1);
+        RecordingSshTool.setCustomResponse(".*myLaunch.*", new CustomResponseGenerator() {
+            @Override
+            public CustomResponse generate(ExecParams execParams) throws Exception {
+                launchCalledLatch.countDown();
+                launchBlockedLatch.await();
+                return new CustomResponse(0, "", "");
+            }});
+        
+        VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
+                .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch")
+                .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning"));
+        
+        startAsync(app(), ImmutableList.of(locationProvisioner));
+        awaitOrFail(launchCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT);
+
+        EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+
+        // Check that the read-only hot standby does not overwrite the entity's state; it should still say "STARTING"
+        TestApplication newApp = hotStandby();
+        final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class));
+
+        EntityAsserts.assertAttributeEqualsContinually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+        assertEquals(newEntity.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STARTING);
+        
+        EntityAsserts.assertAttributeEqualsEventually(newApp, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING);
+        assertEquals(newApp.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STARTING);
+    }
+
     protected ListenableFuture<Void> startAsync(final Startable entity, final Collection<? extends Location> locs) {
         return executor.submit(new Callable<Void>() {
             @Override public Void call() throws Exception {


[5/9] brooklyn-server git commit: BROOKLYN-325: on rebind, set starting/stopping entity on-fire

Posted by al...@apache.org.
BROOKLYN-325: on rebind, set starting/stopping entity on-fire 

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

Branch: refs/heads/master
Commit: 4bba21dd87e37c9cc7919630c8446b2f33c79c94
Parents: 643b19b
Author: Aled Sage <al...@gmail.com>
Authored: Thu Sep 29 14:23:46 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Sep 29 14:42:15 2016 +0100

----------------------------------------------------------------------
 .../core/entity/lifecycle/ServiceStateLogic.java      | 11 +++--------
 .../rebind/AbstractBrooklynObjectRebindSupport.java   |  8 ++++++--
 .../core/mgmt/rebind/BasicEntityRebindSupport.java    | 14 ++++++++++++++
 .../brooklyn/core/mgmt/rebind/RebindIteration.java    |  4 ----
 4 files changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4bba21dd/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 1b76059..df45d51 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
@@ -37,7 +37,6 @@ import org.apache.brooklyn.api.sensor.EnricherSpec.ExtensibleEnricherSpec;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.api.sensor.SensorEvent;
 import org.apache.brooklyn.api.sensor.SensorEventListener;
-import org.apache.brooklyn.config.ConfigInheritance;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.BrooklynLogging;
 import org.apache.brooklyn.core.BrooklynLogging.LoggingLevel;
@@ -153,7 +152,7 @@ public class ServiceStateLogic {
     }
     
     public static void setExpectedState(Entity entity, Lifecycle state) {
-        waitForServiceUpIfStateIsRunning(entity, state);
+        waitBrieflyForServiceUpIfStateIsRunning(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);
@@ -161,18 +160,14 @@ public class ServiceStateLogic {
             ((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) {
+    private static void waitBrieflyForServiceUpIfStateIsRunning(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))) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4bba21dd/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/AbstractBrooklynObjectRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/AbstractBrooklynObjectRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/AbstractBrooklynObjectRebindSupport.java
index 114a455..2dd9700 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/AbstractBrooklynObjectRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/AbstractBrooklynObjectRebindSupport.java
@@ -66,7 +66,7 @@ public abstract class AbstractBrooklynObjectRebindSupport<T extends Memento> imp
         
         doReconstruct(rebindContext, memento);
         if (!rebindContext.isReadOnly(instance))
-            instance.rebind();
+            instanceRebind(instance);
     }
 
     protected abstract void addConfig(RebindContext rebindContext, T memento);
@@ -101,6 +101,10 @@ public abstract class AbstractBrooklynObjectRebindSupport<T extends Memento> imp
         }
     }
 
+    protected void instanceRebind(AbstractBrooklynObject instance) {
+        instance.rebind();
+    }
+    
     @Override
     public void addPolicies(RebindContext rebindContext, T Memento) {
         throw new UnsupportedOperationException();
@@ -115,7 +119,7 @@ public abstract class AbstractBrooklynObjectRebindSupport<T extends Memento> imp
     public void addFeeds(RebindContext rebindContext, T Memento) {
         throw new UnsupportedOperationException();
     }
-
+    
     /**
      * For overriding, to give custom reconstruct behaviour.
      * 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4bba21dd/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
index 370173f..91a8d1b 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
@@ -34,14 +34,18 @@ import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.enricher.AbstractEnricher;
 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.mgmt.rebind.dto.MementosGenerators;
+import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
 import org.apache.brooklyn.core.policy.AbstractPolicy;
 import org.apache.brooklyn.entity.group.AbstractGroupImpl;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 
 public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSupport<EntityMemento> {
@@ -233,4 +237,14 @@ public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSuppor
             }
         }
     }
+    
+    protected void instanceRebind(AbstractBrooklynObject instance) {
+        Preconditions.checkState(instance == entity, "Expected %s and %s to match, but different objects", instance, entity);
+        Lifecycle expectedState = ServiceStateLogic.getExpectedState(entity);
+        if (expectedState == Lifecycle.STARTING || expectedState == Lifecycle.STOPPING) {
+            LOG.warn("Entity "+entity);
+            ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE);
+        }
+        super.instanceRebind(instance);
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/4bba21dd/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 5d4685e..ccd3fe1 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
@@ -692,10 +692,6 @@ public abstract class RebindIteration {
             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()) {


[8/9] brooklyn-server git commit: BROOKLYN-325 Additional logging

Posted by al...@apache.org.
BROOKLYN-325 Additional logging


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

Branch: refs/heads/master
Commit: 9b88108d23ed8fca2f959a79ac1879ac1b6571c7
Parents: 8fa71f7
Author: Ivana Yovcheva <iv...@gmail.com>
Authored: Thu Sep 29 17:54:29 2016 +0300
Committer: Ivana Yovcheva <iv...@gmail.com>
Committed: Fri Sep 30 10:47:47 2016 +0300

----------------------------------------------------------------------
 .../brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java  | 8 ++++++--
 .../apache/brooklyn/core/mgmt/rebind/RebindIteration.java    | 5 +----
 .../base/SoftwareProcessRebindNotRunningEntityTest.java      | 8 --------
 3 files changed, 7 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b88108d/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
index 91a8d1b..5c284bf 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/BasicEntityRebindSupport.java
@@ -33,6 +33,7 @@ import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.enricher.AbstractEnricher;
 import org.apache.brooklyn.core.entity.AbstractEntity;
+import org.apache.brooklyn.core.entity.Attributes;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.entity.lifecycle.Lifecycle;
 import org.apache.brooklyn.core.entity.lifecycle.ServiceStateLogic;
@@ -41,6 +42,7 @@ import org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators;
 import org.apache.brooklyn.core.objs.AbstractBrooklynObject;
 import org.apache.brooklyn.core.policy.AbstractPolicy;
 import org.apache.brooklyn.entity.group.AbstractGroupImpl;
+import org.apache.brooklyn.entity.stock.BasicApplication;
 import org.apache.brooklyn.util.exceptions.Exceptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -237,12 +239,14 @@ public class BasicEntityRebindSupport extends AbstractBrooklynObjectRebindSuppor
             }
         }
     }
-    
+
+    @Override
     protected void instanceRebind(AbstractBrooklynObject instance) {
         Preconditions.checkState(instance == entity, "Expected %s and %s to match, but different objects", instance, entity);
         Lifecycle expectedState = ServiceStateLogic.getExpectedState(entity);
         if (expectedState == Lifecycle.STARTING || expectedState == Lifecycle.STOPPING) {
-            LOG.warn("Entity "+entity);
+            LOG.warn("Entity {} goes on-fire because it was in state {} on rebind", entity, expectedState);
+            LOG.warn("not-up-indicators={}", entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS));
             ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE);
         }
         super.instanceRebind(instance);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b88108d/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 ccd3fe1..4aee9a8 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,8 +69,6 @@ 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;
@@ -689,9 +687,8 @@ 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());
-            }
         }
         List<Application> apps = Lists.newArrayList();
         for (String rootId : getMementoRootEntities()) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/9b88108d/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 0e38e3f..f7e02b9 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
@@ -70,14 +70,6 @@ import com.google.common.util.concurrent.MoreExecutors;
 
 public class SoftwareProcessRebindNotRunningEntityTest extends RebindTestFixtureWithApp {
 
-    // TODO We'd like to record the fact that we were starting or stopping, rather than just say "on-fire".
-    // For example, we can use the Attributes.SERVICE_NOT_UP_INDICATORS to say what went wrong.
-    
-    // TODO If we fail during provisioningLocation.obtain() or provisioningLocation.release(), then we
-    // 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.
-
     private ListeningExecutorService executor;
     private LocationSpec<SshMachineLocation> machineSpec;
     private FixedListMachineProvisioningLocation<?> locationProvisioner;


[3/9] brooklyn-server git commit: Merge pull request #4 from aledsage/iyovcheva-aled/rebind-entity-starting

Posted by al...@apache.org.
Merge pull request #4 from aledsage/iyovcheva-aled/rebind-entity-starting

Add tests to SoftwareProcessRebindNotRunningEntityTest

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

Branch: refs/heads/master
Commit: 5906fb30604979bb524cfc61ea4c376492d5112a
Parents: 001b02c 5d252d7
Author: iyovcheva <iv...@gmail.com>
Authored: Wed Sep 28 10:22:19 2016 +0200
Committer: GitHub <no...@github.com>
Committed: Wed Sep 28 10:22:19 2016 +0200

----------------------------------------------------------------------
 .../core/mgmt/rebind/RebindTestFixture.java     |   4 +
 .../core/internal/ssh/RecordingSshTool.java     |   9 +-
 ...ftwareProcessRebindNotRunningEntityTest.java | 341 ++++++++++++++++---
 3 files changed, 310 insertions(+), 44 deletions(-)
----------------------------------------------------------------------