Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A16441817A for ; Thu, 23 Jul 2015 10:25:16 +0000 (UTC) Received: (qmail 45910 invoked by uid 500); 23 Jul 2015 10:25:16 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 45871 invoked by uid 500); 23 Jul 2015 10:25:16 -0000 Mailing-List: contact dev-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 dev@brooklyn.incubator.apache.org Received: (qmail 45858 invoked by uid 99); 23 Jul 2015 10:25:16 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Jul 2015 10:25:16 +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 C60131A76F1 for ; Thu, 23 Jul 2015 10:25:15 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 0.991 X-Spam-Level: X-Spam-Status: No, score=0.991 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-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 rahWxvTjh72Y for ; Thu, 23 Jul 2015 10:25:06 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with SMTP id 3414120F46 for ; Thu, 23 Jul 2015 10:25:06 +0000 (UTC) Received: (qmail 45842 invoked by uid 99); 23 Jul 2015 10:25:05 -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, 23 Jul 2015 10:25:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B17E1E3AA9; Thu, 23 Jul 2015 10:25:05 +0000 (UTC) From: neykov To: dev@brooklyn.incubator.apache.org Reply-To: dev@brooklyn.incubator.apache.org References: In-Reply-To: Subject: [GitHub] incubator-brooklyn pull request: Support suspending machines Content-Type: text/plain Message-Id: <20150723102505.B17E1E3AA9@git1-us-west.apache.org> Date: Thu, 23 Jul 2015 10:25:05 +0000 (UTC) Github user neykov commented on a diff in the pull request: https://github.com/apache/incubator-brooklyn/pull/763#discussion_r35308236 --- Diff: software/base/src/main/java/brooklyn/entity/software/MachineLifecycleEffectorTasks.java --- @@ -749,17 +791,70 @@ public String toString() { return new StopMachineDetails("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("Decommissioned "+machine, 1); } + /** + * Suspend the {@link MachineLocation} the entity is provisioned at. + *

+ * 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 suspendAnyProvisionedMachines() { + @SuppressWarnings("unchecked") + MachineProvisioningLocation 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)); --- End diff -- What's the advantage of calling `.cast` on the class rather than doing an old school cast? I thought the only usage is when one has an instance of the class in a variable (so it's dynamic). --- 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 infrastructure@apache.org or file a JIRA ticket with INFRA. ---