Umanage BrooklynNode only if machine is released.

Previous logic of looking at the effector paramaters wasn't working in all 
cases as IF_NOT_STOPPED depends on external factors. Instead check if the 
SshMachineLocation is still around.


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

Branch: refs/heads/master
Commit: 8343385f257d21021896db52fbbfe35c5f0e7243
Parents: 92951dc
Author: Svetoslav Neykov <[email protected]>
Authored: Fri Feb 27 17:08:46 2015 +0200
Committer: Svetoslav Neykov <[email protected]>
Committed: Thu Mar 19 16:01:29 2015 +0200

----------------------------------------------------------------------
 .../entity/brooklynnode/BrooklynNodeImpl.java         | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/8343385f/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
 
b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
index 2ac59de..952d32b 100644
--- 
a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
+++ 
b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
@@ -25,6 +25,7 @@ import java.util.concurrent.Callable;
 
 import javax.annotation.Nullable;
 
+import brooklyn.location.basic.Locations;
 import org.apache.http.HttpStatus;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -217,8 +218,7 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl 
implements BrooklynNod
     @Override
     protected void postStop() {
         super.postStop();
-        ConfigBag stopParameters = 
BrooklynTaskTags.getCurrentEffectorParameters();
-        if (isStopMachine(stopParameters)) {
+        if (isStopMachine()) {
             // Don't unmanage in entity's task context as it will self-cancel 
the task. Wait for the stop effector to complete.
             // If this is not enough (still getting Caused by: 
java.util.concurrent.CancellationException: null) then
             // we could search for the top most task with entity context == 
this and wait on it. Even stronger would be
@@ -228,9 +228,13 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl 
implements BrooklynNod
         }
     }
 
-    private boolean isStopMachine(ConfigBag stopParameters) {
-        return stopParameters == null ||
-                stopParameters.get(StopSoftwareParameters.STOP_MACHINE_MODE) 
!= StopMode.NEVER;
+    private boolean isStopMachine() {
+        // Don't rely on effector parameters, check if there is still a 
machine running.
+        // If the entity was previously stopped with 
STOP_MACHINE_MODE=StopMode.NEVER
+        // and a second time with STOP_MACHINE_MODE=StopMode.IF_NOT_STOPPED, 
then the
+        // machine is still running, but there is no deterministic way to 
infer this from
+        // the parameters alone.
+        return 
Locations.findUniqueSshMachineLocation(this.getLocations()).isAbsent();
     }
 
     private void queueShutdownTask() {

Reply via email to