This closes #422

Conflicts:
        
software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java


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

Branch: refs/heads/master
Commit: fe425079ff75fce5589188fc4546197bc3d0cfc3
Parents: 33f5c67 6ac2cd9
Author: Sam Corbett <[email protected]>
Authored: Sun Jan 18 10:23:13 2015 +0000
Committer: Sam Corbett <[email protected]>
Committed: Sun Jan 18 10:23:13 2015 +0000

----------------------------------------------------------------------
 .../brooklyn/entity/basic/SoftwareProcess.java  | 14 ++++
 .../software/MachineLifecycleEffectorTasks.java | 79 +++++++++++++------
 .../entity/basic/SoftwareProcessEntityTest.java | 81 ++++++++++++++++++--
 .../MachineLifecycleEffectorTasksTest.java      | 51 ++++++++++++
 4 files changed, 197 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fe425079/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
----------------------------------------------------------------------
diff --cc 
software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
index 2a7b19f,ecba2b3..5288951
--- 
a/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
+++ 
b/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
@@@ -531,18 -533,29 +534,32 @@@ public abstract class MachineLifecycleE
       * <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();
 +
          log.info("Stopping {} in {}", entity(), entity().getLocations());
  
-         Boolean isStopMachine = 
parameters.get(StopSoftwareParameters.STOP_MACHINE);
+         final boolean hasStopMachine = 
parameters.containsKey(StopSoftwareParameters.STOP_MACHINE);
+         final Boolean isStopMachine = 
parameters.get(StopSoftwareParameters.STOP_MACHINE);
  
-         if (isStopMachine==null)
-             isStopMachine = Boolean.TRUE;
+         final StopMode stopProcessMode = 
parameters.get(StopSoftwareParameters.STOP_PROCESS_MODE);
+ 
+         final boolean hasStopMachineMode = 
parameters.containsKey(StopSoftwareParameters.STOP_MACHINE_MODE);
+         StopMode stopMachineMode = 
parameters.get(StopSoftwareParameters.STOP_MACHINE_MODE);
+ 
+         if (hasStopMachine && isStopMachine != null) {
+             checkCompatibleMachineModes(isStopMachine, hasStopMachineMode, 
stopMachineMode);
+             if (isStopMachine) {
+                 stopMachineMode = StopMode.IF_NOT_STOPPED;
+             } else {
+                 stopMachineMode = StopMode.NEVER;
+             }
+         }
+ 
+         boolean isEntityStopped = 
entity().getAttribute(SoftwareProcess.SERVICE_STATE_ACTUAL)==Lifecycle.STOPPED;
  
          DynamicTasks.queue("pre-stop", new Callable<String>() { public String 
call() {
              if 
(entity().getAttribute(SoftwareProcess.SERVICE_STATE_ACTUAL)==Lifecycle.STOPPED)
 {
@@@ -623,14 -631,22 +640,30 @@@
          if (log.isDebugEnabled()) log.debug("Stopped software process entity 
"+entity());
      }
  
+     protected static boolean canStop(StopMode stopMode, boolean 
isEntityStopped) {
+         return stopMode == StopMode.ALWAYS ||
+                 stopMode == StopMode.IF_NOT_STOPPED && !isEntityStopped;
+     }
+ 
+     private void checkCompatibleMachineModes(Boolean isStopMachine, boolean 
hasStopMachineMode, StopMode stopMachineMode) {
+         if (hasStopMachineMode &&
+                 (isStopMachine && stopMachineMode != StopMode.IF_NOT_STOPPED 
||
+                  !isStopMachine && stopMachineMode != StopMode.NEVER)) {
+             throw new IllegalStateException("Incompatible values for " +
+                     StopSoftwareParameters.STOP_MACHINE.getName() + " (" + 
isStopMachine + ") and " +
+                     StopSoftwareParameters.STOP_MACHINE_MODE.getName() + " (" 
+ stopMachineMode + "). " +
+                     "Use only one of the parameters.");
+         }
+     }
+ 
 +    /** 
 +     * Override to check whether stop can be executed.
 +     * Throw if stop should be aborted.
 +     */
 +    protected void preStopConfirmCustom() {
 +        // nothing needed here
 +    }
 +
      protected void preStopCustom() {
          // nothing needed here
      }

Reply via email to