Return-Path: X-Original-To: apmail-brooklyn-commits-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C5A9618768 for ; Thu, 30 Jul 2015 20:00:49 +0000 (UTC) Received: (qmail 94859 invoked by uid 500); 30 Jul 2015 20:00:40 -0000 Delivered-To: apmail-brooklyn-commits-archive@brooklyn.apache.org Received: (qmail 94838 invoked by uid 500); 30 Jul 2015 20:00:40 -0000 Mailing-List: contact commits-help@brooklyn.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.incubator.apache.org Delivered-To: mailing list commits@brooklyn.incubator.apache.org Received: (qmail 94829 invoked by uid 99); 30 Jul 2015 20:00:40 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jul 2015 20:00:40 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id D5F101A8B51 for ; Thu, 30 Jul 2015 20:00:39 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-eu-west.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id V08uqFGzJGci for ; Thu, 30 Jul 2015 20:00:32 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-eu-west.apache.org (ASF Mail Server at mx1-eu-west.apache.org) with SMTP id 69EA834686 for ; Thu, 30 Jul 2015 20:00:19 +0000 (UTC) Received: (qmail 94220 invoked by uid 99); 30 Jul 2015 20:00:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 30 Jul 2015 20:00:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9BEA1E714C; Thu, 30 Jul 2015 20:00:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sjcorbett@apache.org To: commits@brooklyn.incubator.apache.org Date: Thu, 30 Jul 2015 20:00:23 -0000 Message-Id: <1bb4a698990b48099d4b369d9c320657@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [06/11] incubator-brooklyn git commit: No anonymous inner classes in classes extending MachineLifecycleEffectorTasks No anonymous inner classes in classes extending MachineLifecycleEffectorTasks Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/fcb1af0c Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/fcb1af0c Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/fcb1af0c Branch: refs/heads/master Commit: fcb1af0cbd7eb9799e48471e37934b046330baf3 Parents: f012c9c Author: Sam Corbett Authored: Tue Jul 28 13:46:32 2015 +0100 Committer: Sam Corbett Committed: Wed Jul 29 17:00:19 2015 +0100 ---------------------------------------------------------------------- .../SameServerDriverLifecycleEffectorTasks.java | 2 +- ...wareProcessDriverLifecycleEffectorTasks.java | 22 +- .../software/MachineLifecycleEffectorTasks.java | 359 +++++++++++-------- 3 files changed, 233 insertions(+), 150 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fcb1af0c/software/base/src/main/java/brooklyn/entity/basic/SameServerDriverLifecycleEffectorTasks.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/SameServerDriverLifecycleEffectorTasks.java b/software/base/src/main/java/brooklyn/entity/basic/SameServerDriverLifecycleEffectorTasks.java index bb3b1fd..8b64ddc 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/SameServerDriverLifecycleEffectorTasks.java +++ b/software/base/src/main/java/brooklyn/entity/basic/SameServerDriverLifecycleEffectorTasks.java @@ -84,7 +84,7 @@ public class SameServerDriverLifecycleEffectorTasks extends MachineLifecycleEffe value = maybeValue.isPresent() ? maybeValue.get() : null; } - Maybe maybePortRange = TypeCoercions.tryCoerce(value, new TypeToken() {}); + Maybe maybePortRange = TypeCoercions.tryCoerce(value, TypeToken.of(PortRange.class)); if (maybePortRange.isPresentAndNonNull()) { PortRange p = maybePortRange.get(); http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fcb1af0c/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessDriverLifecycleEffectorTasks.java ---------------------------------------------------------------------- diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessDriverLifecycleEffectorTasks.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessDriverLifecycleEffectorTasks.java index a315e84..2dcfa7e 100644 --- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessDriverLifecycleEffectorTasks.java +++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessDriverLifecycleEffectorTasks.java @@ -59,20 +59,30 @@ public class SoftwareProcessDriverLifecycleEffectorTasks extends MachineLifecycl return; } - DynamicTasks.queue("pre-restart", new Runnable() { public void run() { - preRestartCustom(); - }}); + DynamicTasks.queue("pre-restart", new PreRestartTask()); log.debug("restart of "+entity()+" appears to have driver and hostname - doing driver-level restart"); entity().getDriver().restart(); restartChildren(parameters); - DynamicTasks.queue("post-restart", new Runnable() { public void run() { + DynamicTasks.queue("post-restart", new PostRestartTask()); + } + + private class PreRestartTask implements Runnable { + @Override + public void run() { + preRestartCustom(); + } + } + + private class PostRestartTask implements Runnable { + @Override + public void run() { postStartCustom(); postRestartCustom(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); - }}); + } } @Override @@ -233,7 +243,7 @@ public class SoftwareProcessDriverLifecycleEffectorTasks extends MachineLifecycl if (childException!=null) throw new IllegalStateException(result+"; but error stopping child: "+childException, childException); - + return result; } http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/fcb1af0c/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 920e5b9..48bb6a4 100644 --- a/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java +++ b/software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java @@ -171,23 +171,26 @@ public abstract class MachineLifecycleEffectorTasks { * Calls {@link #start(Collection)} in this class. */ public EffectorBody newStartEffectorTask() { - return new EffectorBody() { - @Override - public Void call(ConfigBag parameters) { - Collection locations = null; + return new StartEffectorBody(); + } - Object locationsRaw = parameters.getStringKey(LOCATIONS.getName()); - locations = Locations.coerceToCollection(entity().getManagementContext(), locationsRaw); + private class StartEffectorBody extends EffectorBody { + @Override + public Void call(ConfigBag parameters) { + Collection locations = null; - if (locations==null) { - // null/empty will mean to inherit from parent - locations = Collections.emptyList(); - } + Object locationsRaw = parameters.getStringKey(LOCATIONS.getName()); + locations = Locations.coerceToCollection(entity().getManagementContext(), locationsRaw); - start(locations); - return null; + if (locations == null) { + // null/empty will mean to inherit from parent + locations = Collections.emptyList(); } - }; + + start(locations); + return null; + } + } /** @@ -196,13 +199,15 @@ public abstract class MachineLifecycleEffectorTasks { * @see {@link #newStartEffectorTask()} */ public EffectorBody newRestartEffectorTask() { - return new EffectorBody() { - @Override - public Void call(ConfigBag parameters) { - restart(parameters); - return null; - } - }; + return new RestartEffectorBody(); + } + + private class RestartEffectorBody extends EffectorBody { + @Override + public Void call(ConfigBag parameters) { + restart(parameters); + return null; + } } /** @@ -211,13 +216,15 @@ public abstract class MachineLifecycleEffectorTasks { * @see {@link #newStartEffectorTask()} */ public EffectorBody newStopEffectorTask() { - return new EffectorBody() { - @Override - public Void call(ConfigBag parameters) { - stop(parameters); - return null; - } - }; + return new StopEffectorBody(); + } + + private class StopEffectorBody extends EffectorBody { + @Override + public Void call(ConfigBag parameters) { + stop(parameters); + return null; + } } /** @@ -226,13 +233,15 @@ public abstract class MachineLifecycleEffectorTasks { * @see {@link #newStartEffectorTask()} */ public EffectorBody newSuspendEffectorTask() { - return new EffectorBody() { - @Override - public Void call(ConfigBag parameters) { - suspend(parameters); - return null; - } - }; + return new SuspendEffectorBody(); + } + + private class SuspendEffectorBody extends EffectorBody { + @Override + public Void call(ConfigBag parameters) { + suspend(parameters); + return null; + } } protected EntityInternal entity() { @@ -288,11 +297,19 @@ public abstract class MachineLifecycleEffectorTasks { final Supplier locationSF = locationS; preStartAtMachineAsync(locationSF); - DynamicTasks.queue("start (processes)", new Runnable() { public void run() { - startProcessesAtMachine(locationSF); - }}); + DynamicTasks.queue("start (processes)", new StartProcessesAtMachineTask(locationSF)); postStartAtMachineAsync(); - return; + } + + private class StartProcessesAtMachineTask implements Runnable { + private final Supplier machineSupplier; + private StartProcessesAtMachineTask(Supplier machineSupplier) { + this.machineSupplier = machineSupplier; + } + @Override + public void run() { + startProcessesAtMachine(machineSupplier); + } } /** @@ -300,62 +317,89 @@ public abstract class MachineLifecycleEffectorTasks { * and returns that machine. The task can be used as a supplier to subsequent methods. */ protected Task provisionAsync(final MachineProvisioningLocation location) { - return DynamicTasks.queue(Tasks.builder().name("provisioning ("+location.getDisplayName()+")").body( - new Callable() { - public MachineLocation call() throws Exception { - // Blocks if a latch was configured. - entity().getConfig(BrooklynConfigKeys.PROVISION_LATCH); - final Map flags = obtainProvisioningFlags(location); - if (!(location instanceof LocalhostMachineProvisioningLocation)) - log.info("Starting {}, obtaining a new location instance in {} with ports {}", new Object[] {entity(), location, flags.get("inboundPorts")}); - entity().setAttribute(SoftwareProcess.PROVISIONING_LOCATION, location); - MachineLocation machine; - try { - machine = Tasks.withBlockingDetails("Provisioning machine in "+location, new Callable() { - public MachineLocation call() throws NoMachinesAvailableException { - return location.obtain(flags); - }}); - if (machine == null) throw new NoMachinesAvailableException("Failed to obtain machine in "+location.toString()); - } catch (Exception e) { - throw Exceptions.propagate(e); - } + return DynamicTasks.queue(Tasks.builder().name("provisioning (" + location.getDisplayName() + ")").body( + new ProvisionMachineTask(location)).build()); + } - if (log.isDebugEnabled()) - log.debug("While starting {}, obtained new location instance {}", entity(), - (machine instanceof SshMachineLocation ? - machine+", details "+((SshMachineLocation)machine).getUser()+":"+Sanitizer.sanitize(((SshMachineLocation)machine).config().getLocalBag()) - : machine)); - return machine; - } - }).build()); + private class ProvisionMachineTask implements Callable { + final MachineProvisioningLocation location; + + private ProvisionMachineTask(MachineProvisioningLocation location) { + this.location = location; + } + + public MachineLocation call() throws Exception { + // Blocks if a latch was configured. + entity().getConfig(BrooklynConfigKeys.PROVISION_LATCH); + final Map flags = obtainProvisioningFlags(location); + if (!(location instanceof LocalhostMachineProvisioningLocation)) + log.info("Starting {}, obtaining a new location instance in {} with ports {}", new Object[]{entity(), location, flags.get("inboundPorts")}); + entity().setAttribute(SoftwareProcess.PROVISIONING_LOCATION, location); + MachineLocation machine; + try { + machine = Tasks.withBlockingDetails("Provisioning machine in " + location, new ObtainLocationTask(location, flags)); + if (machine == null) + throw new NoMachinesAvailableException("Failed to obtain machine in " + location.toString()); + } catch (Exception e) { + throw Exceptions.propagate(e); + } + + if (log.isDebugEnabled()) + log.debug("While starting {}, obtained new location instance {}", entity(), + (machine instanceof SshMachineLocation ? + machine + ", details " + ((SshMachineLocation) machine).getUser() + ":" + Sanitizer.sanitize(((SshMachineLocation) machine).config().getLocalBag()) + : machine)); + return machine; + } + } + + private static class ObtainLocationTask implements Callable { + final MachineProvisioningLocation location; + final Map flags; + + private ObtainLocationTask(MachineProvisioningLocation location, Map flags) { + this.flags = flags; + this.location = location; + } + + public MachineLocation call() throws NoMachinesAvailableException { + return location.obtain(flags); + } } /** Wraps a call to {@link #preStartCustom(MachineLocation)}, after setting the hostname and address. */ protected void preStartAtMachineAsync(final Supplier machineS) { - DynamicTasks.queue("pre-start", new Runnable() { public void run() { - MachineLocation machine = machineS.get(); + DynamicTasks.queue("pre-start", new PreStartTask(machineS.get())); + } + + private class PreStartTask implements Runnable { + final MachineLocation machine; + private PreStartTask(MachineLocation machine) { + this.machine = machine; + } + public void run() { log.info("Starting {} on machine {}", entity(), machine); Collection oldLocs = entity().getLocations(); if (!oldLocs.isEmpty()) { List oldSshLocs = ImmutableList.copyOf(Iterables.filter(oldLocs, MachineLocation.class)); if (!oldSshLocs.isEmpty()) { // check if existing locations are compatible - log.debug("Entity "+entity()+" had machine locations "+oldSshLocs+" when starting at "+machine+"; checking if they are compatible"); - for (MachineLocation oldLoc: oldSshLocs) { + log.debug("Entity " + entity() + " had machine locations " + oldSshLocs + " when starting at " + machine + "; checking if they are compatible"); + for (MachineLocation oldLoc : oldSshLocs) { // machines are deemed compatible if hostname and address are the same, or they are localhost // this allows a machine create by jclouds to then be defined with an ip-based spec if (!"localhost".equals(machine.getConfig(AbstractLocation.ORIGINAL_SPEC))) { checkLocationParametersCompatible(machine, oldLoc, "hostname", - oldLoc.getAddress().getHostName(), machine.getAddress().getHostName()); + oldLoc.getAddress().getHostName(), machine.getAddress().getHostName()); checkLocationParametersCompatible(machine, oldLoc, "address", - oldLoc.getAddress().getHostAddress(), machine.getAddress().getHostAddress()); + oldLoc.getAddress().getHostAddress(), machine.getAddress().getHostAddress()); } } - log.debug("Entity "+entity()+" old machine locations "+oldSshLocs+" were compatible, removing them to start at "+machine); + log.debug("Entity " + entity() + " old machine locations " + oldSshLocs + " were compatible, removing them to start at " + machine); entity().removeLocations(oldSshLocs); } } - entity().addLocations(ImmutableList.of((Location)machine)); + entity().addLocations(ImmutableList.of((Location) machine)); // elsewhere we rely on (public) hostname being set _after_ subnet_hostname // (to prevent the tiny possibility of races resulting in hostname being returned @@ -397,7 +441,7 @@ public abstract class MachineLifecycleEffectorTasks { } resolveOnBoxDir(entity(), machine); preStartCustom(machine); - }}); + } } /** @@ -480,9 +524,13 @@ public abstract class MachineLifecycleEffectorTasks { protected abstract String startProcessesAtMachine(final Supplier machineS); protected void postStartAtMachineAsync() { - DynamicTasks.queue("post-start", new Runnable() { public void run() { + DynamicTasks.queue("post-start", new PostStartTask()); + } + + private class PostStartTask implements Runnable { + public void run() { postStartCustom(); - }}); + } } /** @@ -515,7 +563,7 @@ public abstract class MachineLifecycleEffectorTasks { protected boolean getDefaultRestartStopsMachine() { return false; } - + /** * Default restart implementation for an entity. *

@@ -523,53 +571,54 @@ public abstract class MachineLifecycleEffectorTasks { */ public void restart(ConfigBag parameters) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING); - + RestartMachineMode isRestartMachine = parameters.get(RestartSoftwareParameters.RESTART_MACHINE_TYPED); - if (isRestartMachine==null) + if (isRestartMachine==null) isRestartMachine=RestartMachineMode.AUTO; - if (isRestartMachine==RestartMachineMode.AUTO) - isRestartMachine = getDefaultRestartStopsMachine() ? RestartMachineMode.TRUE : RestartMachineMode.FALSE; + if (isRestartMachine==RestartMachineMode.AUTO) + isRestartMachine = getDefaultRestartStopsMachine() ? RestartMachineMode.TRUE : RestartMachineMode.FALSE; - DynamicTasks.queue("pre-restart", new Runnable() { public void run() { - //Calling preStopCustom without a corresponding postStopCustom invocation - //doesn't look right so use a separate callback pair; Also depending on the arguments - //stop() could be called which will call the {pre,post}StopCustom on its own. - preRestartCustom(); - }}); + // Calling preStopCustom without a corresponding postStopCustom invocation + // doesn't look right so use a separate callback pair; Also depending on the arguments + // stop() could be called which will call the {pre,post}StopCustom on its own. + DynamicTasks.queue("pre-restart", new PreRestartTask()); if (isRestartMachine==RestartMachineMode.FALSE) { - DynamicTasks.queue("stopping (process)", new Callable() { public String call() { - DynamicTasks.markInessential(); - stopProcessesAtMachine(); - DynamicTasks.waitForLast(); - return "Stop of process completed with no errors."; - }}); + DynamicTasks.queue("stopping (process)", new StopProcessesAtMachineTask()); } else { - DynamicTasks.queue("stopping (machine)", new Callable() { public String call() { - DynamicTasks.markInessential(); - stop(ConfigBag.newInstance().configure(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.IF_NOT_STOPPED)); - DynamicTasks.waitForLast(); - return "Stop of machine completed with no errors."; - }}); + DynamicTasks.queue("stopping (machine)", new StopMachineTask()); } - DynamicTasks.queue("starting", new Runnable() { public void run() { - // startInLocations will look up the location, and provision a machine if necessary - // (if it remembered the provisioning location) - ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); - startInLocations(null); - }}); - + DynamicTasks.queue("starting", new StartInLocationsTask()); restartChildren(parameters); - - DynamicTasks.queue("post-restart", new Runnable() { public void run() { - postRestartCustom(); - }}); + DynamicTasks.queue("post-restart", new PostRestartTask()); DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); } + private class PreRestartTask implements Runnable { + @Override + public void run() { + preRestartCustom(); + } + } + private class PostRestartTask implements Runnable { + @Override + public void run() { + postRestartCustom(); + } + } + private class StartInLocationsTask implements Runnable { + @Override + public void run() { + // startInLocations will look up the location, and provision a machine if necessary + // (if it remembered the provisioning location) + ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); + startInLocations(null); + } + } + protected void restartChildren(ConfigBag parameters) { // TODO should we consult ChildStartableMode? @@ -577,12 +626,12 @@ public abstract class MachineLifecycleEffectorTasks { if (isRestartChildren==null || !isRestartChildren) { return; } - + if (isRestartChildren) { DynamicTasks.queue(StartableMethods.restartingChildren(entity(), parameters)); return; } - + throw new IllegalArgumentException("Invalid value '"+isRestartChildren+"' for "+RestartSoftwareParameters.RESTART_CHILDREN.getName()); } @@ -601,11 +650,7 @@ public abstract class MachineLifecycleEffectorTasks { * If no errors were encountered call {@link #postStopCustom()} at the end. */ public void stop(ConfigBag parameters) { - doStop(parameters, new Callable>() { - public StopMachineDetails call() { - return stopAnyProvisionedMachines(); - } - }); + doStop(parameters, new StopAnyProvisionedMachinesTask()); } /** @@ -613,12 +658,7 @@ public abstract class MachineLifecycleEffectorTasks { * {@link #stopAnyProvisionedMachines}. */ public void suspend(ConfigBag parameters) { - doStop(parameters, new Callable>() { - @Override - public StopMachineDetails call() throws Exception { - return suspendAnyProvisionedMachines(); - } - }); + doStop(parameters, new SuspendAnyProvisionedMachinesTask()); } protected void doStop(ConfigBag parameters, Callable> stopTask) { @@ -629,26 +669,12 @@ public abstract class MachineLifecycleEffectorTasks { StopMode stopMachineMode = getStopMachineMode(parameters); StopMode stopProcessMode = parameters.get(StopSoftwareParameters.STOP_PROCESS_MODE); - DynamicTasks.queue("pre-stop", new Callable() { public String call() { - if (entity().getAttribute(SoftwareProcess.SERVICE_STATE_ACTUAL)==Lifecycle.STOPPED) { - log.debug("Skipping stop of entity "+entity()+" when already stopped"); - return "Already stopped"; - } - ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING); - entity().setAttribute(SoftwareProcess.SERVICE_UP, false); - preStopCustom(); - return null; - }}); + DynamicTasks.queue("pre-stop", new PreStopCustomTask()); Maybe machine = Machines.findUniqueMachineLocation(entity().getLocations()); Task stoppingProcess = null; if (canStop(stopProcessMode, entity())) { - stoppingProcess = DynamicTasks.queue("stopping (process)", new Callable() { public String call() { - DynamicTasks.markInessential(); - stopProcessesAtMachine(); - DynamicTasks.waitForLast(); - return "Stop at machine completed with no errors."; - }}); + stoppingProcess = DynamicTasks.queue("stopping (process)", new StopProcessesAtMachineTask()); } Task> stoppingMachine = null; @@ -696,14 +722,61 @@ public abstract class MachineLifecycleEffectorTasks { entity().setAttribute(SoftwareProcess.SERVICE_UP, false); ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPED); - DynamicTasks.queue("post-stop", new Callable() { public Void call() { - postStopCustom(); - return null; - }}); + DynamicTasks.queue("post-stop", new PostStopCustomTask()); if (log.isDebugEnabled()) log.debug("Stopped software process entity "+entity()); } + private class StopAnyProvisionedMachinesTask implements Callable> { + public StopMachineDetails call() { + return stopAnyProvisionedMachines(); + } + } + + private class SuspendAnyProvisionedMachinesTask implements Callable> { + public StopMachineDetails call() { + return suspendAnyProvisionedMachines(); + } + } + + private class StopProcessesAtMachineTask implements Callable { + public String call() { + DynamicTasks.markInessential(); + stopProcessesAtMachine(); + DynamicTasks.waitForLast(); + return "Stop processes completed with no errors."; + } + } + + private class StopMachineTask implements Callable { + public String call() { + DynamicTasks.markInessential(); + stop(ConfigBag.newInstance().configure(StopSoftwareParameters.STOP_MACHINE_MODE, StopMode.IF_NOT_STOPPED)); + DynamicTasks.waitForLast(); + return "Stop of machine completed with no errors."; + } + } + + private class PreStopCustomTask implements Callable { + public String call() { + if (entity().getAttribute(SoftwareProcess.SERVICE_STATE_ACTUAL) == Lifecycle.STOPPED) { + log.debug("Skipping stop of entity " + entity() + " when already stopped"); + return "Already stopped"; + } + ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING); + entity().setAttribute(SoftwareProcess.SERVICE_UP, false); + preStopCustom(); + return null; + } + } + + private class PostStopCustomTask implements Callable { + public Void call() { + postStopCustom(); + return null; + } + } + public static StopMode getStopMachineMode(ConfigBag parameters) { @SuppressWarnings("deprecation") final boolean hasStopMachine = parameters.containsKey(StopSoftwareParameters.STOP_MACHINE);