You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sj...@apache.org on 2015/07/30 22:00:22 UTC
[05/11] incubator-brooklyn git commit: Adds suspend and resume
interfaces to MachineManagementMixins.
Adds suspend and resume interfaces to MachineManagementMixins.
And uses them in JcloudsLocation.
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/415d0834
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/415d0834
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/415d0834
Branch: refs/heads/master
Commit: 415d08349cfd8ffb2848cf89f97fc693346f4444
Parents: e761f42
Author: Sam Corbett <sa...@cloudsoftcorp.com>
Authored: Tue Jul 21 12:00:44 2015 +0100
Committer: Sam Corbett <sa...@cloudsoftcorp.com>
Committed: Wed Jul 29 16:59:17 2015 +0100
----------------------------------------------------------------------
.../location/MachineManagementMixins.java | 45 +++++++++++++++++---
.../location/jclouds/JcloudsLocation.java | 36 +++++++++++++++-
2 files changed, 73 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/415d0834/api/src/main/java/brooklyn/location/MachineManagementMixins.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/brooklyn/location/MachineManagementMixins.java b/api/src/main/java/brooklyn/location/MachineManagementMixins.java
index 77ffea5..99038ba 100644
--- a/api/src/main/java/brooklyn/location/MachineManagementMixins.java
+++ b/api/src/main/java/brooklyn/location/MachineManagementMixins.java
@@ -20,18 +20,28 @@ package brooklyn.location;
import java.util.Map;
+import com.google.common.annotations.Beta;
+
+/**
+ * Defines mixins for interesting locations.
+ */
public class MachineManagementMixins {
- public interface RichMachineProvisioningLocation<T extends MachineLocation> extends MachineProvisioningLocation<T>, ListsMachines, GivesMachineMetadata, KillsMachines {}
-
+ public interface RichMachineProvisioningLocation<T extends MachineLocation> extends
+ MachineProvisioningLocation<T>, ListsMachines, GivesMachineMetadata, KillsMachines {}
+
public interface ListsMachines {
- /** returns map of machine ID to metadata record for all machines known in a given cloud location */
+ /**
+ * @return A map of machine ID to metadata record for all machines known in a given cloud location.
+ */
Map<String,MachineMetadata> listMachines();
}
public interface GivesMachineMetadata {
- /** returns the MachineMetadata for a given (brooklyn) machine location instance,
- * or null if not matched */
+ /**
+ * @return the {@link MachineMetadata} for a given (brooklyn) machine location instance,
+ * or null if not matched.
+ */
MachineMetadata getMachineMetadata(MachineLocation location);
}
@@ -55,5 +65,28 @@ public class MachineManagementMixins {
/** original metadata object, if available; e.g. ComputeMetadata when using jclouds */
Object getOriginalMetadata();
}
-
+
+ /**
+ * Implement to indicate that a location can suspend and resume machines.
+ */
+ @Beta
+ public interface SuspendResumeLocation extends SuspendsMachines, ResumesMachines {};
+
+
+ @Beta
+ public interface SuspendsMachines {
+ /**
+ * Suspend the indicated machine.
+ */
+ void suspendMachine(MachineLocation location);
+ }
+
+ @Beta
+ public interface ResumesMachines {
+ /**
+ * Resume the indicated machine.
+ */
+ void resumeMachine(MachineLocation location);
+ }
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/415d0834/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index c7d9f95..4916de5 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -126,6 +126,7 @@ import brooklyn.location.MachineLocation;
import brooklyn.location.MachineLocationCustomizer;
import brooklyn.location.MachineManagementMixins.MachineMetadata;
import brooklyn.location.MachineManagementMixins.RichMachineProvisioningLocation;
+import brooklyn.location.MachineManagementMixins.SuspendsMachines;
import brooklyn.location.NoMachinesAvailableException;
import brooklyn.location.access.PortForwardManager;
import brooklyn.location.access.PortMapping;
@@ -187,7 +188,9 @@ import io.cloudsoft.winrm4j.pywinrm.WinRMFactory;
* Configuration flags are defined in {@link JcloudsLocationConfig}.
*/
@SuppressWarnings("serial")
-public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation implements JcloudsLocationConfig, RichMachineProvisioningLocation<MachineLocation>, LocationWithObjectStore {
+public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation implements
+ JcloudsLocationConfig, RichMachineProvisioningLocation<MachineLocation>,
+ LocationWithObjectStore, SuspendsMachines {
// TODO After converting from Groovy to Java, this is now very bad code! It relies entirely on putting
// things into and taking them out of maps; it's not type-safe, and it's thus very error-prone.
@@ -1023,6 +1026,35 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
}
}
+ // ------------- suspend and resume ------------------------------------
+
+ /**
+ * Suspends the given location.
+ * <p>
+ * Note that this method does <b>not</b> call the lifecycle methods of any
+ * {@link #getCustomizers(ConfigBag) customizers} attached to this location.
+ */
+ @Override
+ public void suspendMachine(MachineLocation rawLocation) {
+ String instanceId = vmInstanceIds.remove(rawLocation);
+ if (instanceId == null) {
+ LOG.info("Attempt to suspend unknown machine " + rawLocation + " in " + this);
+ throw new IllegalArgumentException("Unknown machine " + rawLocation);
+ }
+ LOG.info("Suspending machine {} in {}, instance id {}", new Object[]{rawLocation, this, instanceId});
+ Exception toThrow = null;
+ try {
+ getComputeService().suspendNode(instanceId);
+ } catch (Exception e) {
+ toThrow = e;
+ LOG.error("Problem suspending machine " + rawLocation + " in " + this + ", instance id " + instanceId, e);
+ }
+ removeChild(rawLocation);
+ if (toThrow != null) {
+ throw Exceptions.propagate(toThrow);
+ }
+ }
+
// ------------- constructing the template, etc ------------------------
private static interface CustomizeTemplateBuilder {
@@ -2159,7 +2191,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
throw new IllegalArgumentException("Unknown machine "+rawMachine);
}
JcloudsMachineLocation machine = (JcloudsMachineLocation) rawMachine;
-
+
LOG.info("Releasing machine {} in {}, instance id {}", new Object[] {machine, this, instanceId});
Exception tothrow = null;