Wire up postStop to be called, unmanage BrooklynNode on stop.

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

Branch: refs/heads/master
Commit: c2d91a118e90b7e00158eba19d0072821b0cf7a2
Parents: 810c118
Author: Svetoslav Neykov <[email protected]>
Authored: Fri Dec 12 15:25:36 2014 +0200
Committer: Svetoslav Neykov <[email protected]>
Committed: Wed Dec 17 15:29:47 2014 +0200

----------------------------------------------------------------------
 .../entity/brooklynnode/BrooklynNodeImpl.java        | 15 +++++++++++++++
 .../software/MachineLifecycleEffectorTasks.java      |  9 ++++++++-
 2 files changed, 23 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c2d91a11/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 acb99cf..4b94c4f 100644
--- 
a/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
+++ 
b/software/base/src/main/java/brooklyn/entity/brooklynnode/BrooklynNodeImpl.java
@@ -80,6 +80,12 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl 
implements BrooklynNod
         RendererHints.register(WEB_CONSOLE_URI, 
RendererHints.namedActionWithUrl());
     }
 
+    private class UnmanageThread extends Thread {
+        public void run() {
+            Entities.unmanage(BrooklynNodeImpl.this);
+        }
+    }
+
     private HttpFeed httpFeed;
     
     public BrooklynNodeImpl() {
@@ -132,6 +138,15 @@ public class BrooklynNodeImpl extends SoftwareProcessImpl 
implements BrooklynNod
             log.info("Skipping children.isEmpty check and shutdown call, 
because web-console not up for {}", this);
         }
     }
+    
+    @Override
+    protected void postStop() {
+        super.postStop();
+        //Don't unmanage in entity's task context as it will self-cancel the 
task.
+        //The external thread doesn't guarantee that the unmanage will be 
called *after* the stop effector completes.
+        //How to delay and make sure that we don't cancel the 
(almost-complete) stop effector?
+        new UnmanageThread().start();
+    }
 
     public static class DeployBlueprintEffectorBody extends 
EffectorBody<String> implements DeployBlueprintEffector {
         public static final Effector<String> DEPLOY_BLUEPRINT = 
Effectors.effector(BrooklynNode.DEPLOY_BLUEPRINT).impl(new 
DeployBlueprintEffectorBody()).build();

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c2d91a11/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
 
b/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
index 364d620..2a7b19f 100644
--- 
a/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
+++ 
b/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
@@ -97,6 +97,7 @@ import com.google.common.collect.Iterables;
  *  <li> {@link #preStartCustom(MachineLocation)}
  *  <li> {@link #postStartCustom()}
  *  <li> {@link #preStopCustom()}
+ *  <li> {@link #postStopCustom()}
  * </ul>
  * Note methods at this level typically look after the {@link 
Attributes#SERVICE_STATE} sensor.
  *
@@ -530,7 +531,8 @@ public abstract class MachineLifecycleEffectorTasks {
      * <p>
      * Aborts if already stopped, otherwise sets state {@link 
Lifecycle#STOPPING} then
      * invokes {@link #preStopCustom()}, {@link #stopProcessesAtMachine()}, 
then finally
-     * {@link #stopAnyProvisionedMachines()} and sets state {@link 
Lifecycle#STOPPED}
+     * {@link #stopAnyProvisionedMachines()} and sets state {@link 
Lifecycle#STOPPED}.
+     * If no errors were encountered call {@link #postStopCustom()} at the end.
      */
     public void stop(ConfigBag parameters) {
         preStopConfirmCustom();
@@ -613,6 +615,11 @@ public abstract class MachineLifecycleEffectorTasks {
         entity().setAttribute(SoftwareProcess.SERVICE_UP, false);
         ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED);
 
+        DynamicTasks.queue("post-stop", new Callable<Void>() { public Void 
call() {
+            postStopCustom();
+            return null;
+        }});
+
         if (log.isDebugEnabled()) log.debug("Stopped software process entity 
"+entity());
     }
 

Reply via email to