Github user neykov commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/763#discussion_r35308359
--- Diff:
software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java
---
@@ -749,17 +791,70 @@ public String toString() {
return new StopMachineDetails<Integer>("No machine
decommissioning necessary - not a machine ("+machine+")", 0);
}
+ clearEntityLocationAttributes(machine);
try {
- entity().removeLocations(ImmutableList.of(machine));
- entity().setAttribute(Attributes.HOSTNAME, null);
- entity().setAttribute(Attributes.ADDRESS, null);
- entity().setAttribute(Attributes.SUBNET_HOSTNAME, null);
- entity().setAttribute(Attributes.SUBNET_ADDRESS, null);
- if (provisioner != null)
provisioner.release((MachineLocation)machine);
+ provisioner.release((MachineLocation)machine);
} catch (Throwable t) {
throw Exceptions.propagate(t);
}
return new StopMachineDetails<Integer>("Decommissioned "+machine,
1);
}
+ /**
+ * Suspend the {@link MachineLocation} the entity is provisioned at.
+ * <p>
+ * Expects the entity's {@link SoftwareProcess#PROVISIONING_LOCATION
provisioner} to be capable of
+ * {@link SuspendsMachines suspending machines}.
+ *
+ * @throws java.lang.UnsupportedOperationException if the entity's
provisioner cannot suspend machines.
+ * @see brooklyn.location.MachineManagementMixins.SuspendsMachines
+ */
+ protected StopMachineDetails<Integer> suspendAnyProvisionedMachines() {
+ @SuppressWarnings("unchecked")
+ MachineProvisioningLocation<MachineLocation> provisioner =
entity().getAttribute(SoftwareProcess.PROVISIONING_LOCATION);
+
+ if (Iterables.isEmpty(entity().getLocations())) {
+ log.debug("No machine decommissioning necessary for " +
entity() + " - no locations");
+ return new StopMachineDetails<>("No machine suspend necessary
- no locations", 0);
+ }
+
+ // Only release this machine if we ourselves provisioned it (e.g.
it might be running other services)
+ if (provisioner == null) {
+ log.debug("No machine decommissioning necessary for " +
entity() + " - did not provision");
+ return new StopMachineDetails<>("No machine suspend necessary
- did not provision", 0);
+ }
+
+ Location machine = getLocation(null);
+ if (!(machine instanceof MachineLocation)) {
+ log.debug("No decommissioning necessary for " + entity() + " -
not a machine location (" + machine + ")");
+ return new StopMachineDetails<>("No machine suspend necessary
- not a machine (" + machine + ")", 0);
+ }
+
+ if (!(provisioner instanceof SuspendsMachines)) {
+ log.debug("Location provisioner ({}) cannot suspend machines",
provisioner);
+ throw new UnsupportedOperationException("Location provisioner
cannot suspend machines: " + provisioner);
+ }
+
+ clearEntityLocationAttributes(machine);
+ try {
+
SuspendsMachines.class.cast(provisioner).suspendMachine(MachineLocation.class.cast(machine));
+ } catch (Throwable t) {
--- End diff --
Don't see what the point of the catch is here. Yes it's like this in the
analogous stop method, but still...
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---