From fc596fb5ce141dfbe2d287536bcde7f40390e8c1 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 31 Oct 2010 11:38:01 -0700 Subject: [PATCH] suspend/resume --- .../aws/ec2/compute/EC2ComputeService.java | 11 +- .../EC2BindComputeStrategiesByClass.java | 14 ++ .../src/main/clojure/org/jclouds/compute.clj | 24 ++++ .../src/main/clojure/org/jclouds/modules.clj | 4 + .../org/jclouds/compute/ComputeService.java | 135 ++++++++++-------- .../compute/ComputeServiceAdapter.java | 8 +- .../config/BindComputeStrategiesByClass.java | 16 +++ .../config/ComputeServiceTimeoutsModule.java | 10 ++ ...StandaloneComputeServiceContextModule.java | 20 ++- .../compute/internal/BaseComputeService.java | 74 +++++++++- .../compute/predicates/NodeRunning.java | 34 +---- .../reference/ComputeServiceConstants.java | 7 +- .../AdaptingComputeServiceStrategies.java | 38 ++++- .../config/StubComputeServiceAdapter.java | 26 ++++ .../jclouds/compute/util/ComputeUtils.java | 4 +- .../compute/BaseComputeServiceLiveTest.java | 27 +++- .../org/jclouds/compute/ComputeTestUtils.java | 14 +- .../org/jclouds/compute/RunScriptData.java | 12 +- .../StubComputeServiceIntegrationTest.java | 47 +++--- .../test/resources/initscript_with_java.sh | 12 +- .../test/resources/initscript_with_jboss.sh | 2 +- compute/src/test/resources/runscript.sh | 2 +- .../GoGridBindComputeStrategiesByClass.java | 16 ++- .../strategy/GoGridRebootNodeStrategy.java | 67 --------- .../gogrid/GoGridLiveTestDisabled.java | 2 +- ...udServersBindComputeStrategiesByClass.java | 16 ++- .../CloudServersRebootNodeStrategy.java | 53 ------- .../CloudServersComputeServiceLiveTest.java | 5 + ...muHostingBindComputeStrategiesByClass.java | 16 ++- .../RimuHostingRebootNodeStrategy.java | 53 ------- .../LibvirtComputeServiceAdapter.java | 18 +++ .../jclouds/servermanager/ServerManager.java | 6 + .../ServerManagerComputeServiceAdapter.java | 11 ++ ...SlicehostBindComputeStrategiesByClass.java | 16 ++- .../strategy/SlicehostRebootNodeStrategy.java | 52 ------- .../VCloudBindComputeStrategiesByClass.java | 16 ++- ...udExpressBindComputeStrategiesByClass.java | 16 ++- .../VCloudExpressRebootNodeStrategy.java | 61 -------- .../strategy/VCloudRebootNodeStrategy.java | 61 -------- 39 files changed, 518 insertions(+), 508 deletions(-) delete mode 100644 gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridRebootNodeStrategy.java delete mode 100644 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersRebootNodeStrategy.java delete mode 100644 rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingRebootNodeStrategy.java delete mode 100644 slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostRebootNodeStrategy.java delete mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java delete mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java index cc5bdd1d6d..79584776ce 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2ComputeService.java @@ -56,6 +56,8 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; @@ -82,16 +84,19 @@ public class EC2ComputeService extends BaseComputeService { @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, + ResumeNodeStrategy startNodeStrategy, SuspendNodeStrategy stopNodeStrategy, Provider templateBuilderProvider, Provider templateOptionsProvider, @Named("NODE_RUNNING") Predicate nodeRunning, - @Named("NODE_TERMINATED") Predicate nodeTerminated, ComputeUtils utils, Timeouts timeouts, + @Named("NODE_TERMINATED") Predicate nodeTerminated, + @Named("NODE_SUSPENDED") Predicate nodeSuspended, ComputeUtils utils, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, EC2Client ec2Client, Map credentialsMap, @Named("SECURITY") Map securityGroupMap, @Named("PLACEMENT") Map placementGroupMap, @Named("DELETED") Predicate placementGroupDeleted) { super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, - runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, templateBuilderProvider, - templateOptionsProvider, nodeRunning, nodeTerminated, utils, timeouts, executor); + runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, startNodeStrategy, + stopNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, + nodeSuspended, utils, timeouts, executor); this.ec2Client = ec2Client; this.credentialsMap = credentialsMap; this.securityGroupMap = securityGroupMap; diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2BindComputeStrategiesByClass.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2BindComputeStrategiesByClass.java index 44a62e4651..3f59584b6f 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2BindComputeStrategiesByClass.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2BindComputeStrategiesByClass.java @@ -24,6 +24,8 @@ import org.jclouds.aws.ec2.compute.strategy.EC2GetNodeMetadataStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2ListNodesStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RebootNodeStrategy; import org.jclouds.aws.ec2.compute.strategy.EC2RunNodesAndAddToSetStrategy; +import org.jclouds.aws.ec2.compute.strategy.EC2ResumeNodeStrategy; +import org.jclouds.aws.ec2.compute.strategy.EC2SuspendNodeStrategy; import org.jclouds.compute.config.BindComputeStrategiesByClass; import org.jclouds.compute.strategy.AddNodeWithTagStrategy; import org.jclouds.compute.strategy.DestroyNodeStrategy; @@ -31,6 +33,8 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; /** * @author Adrian Cole @@ -76,4 +80,14 @@ public class EC2BindComputeStrategiesByClass extends BindComputeStrategiesByClas return EC2RebootNodeStrategy.class; } + @Override + protected Class defineStartNodeStrategy() { + return EC2ResumeNodeStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return EC2SuspendNodeStrategy.class; + } + } \ No newline at end of file diff --git a/compute/src/main/clojure/org/jclouds/compute.clj b/compute/src/main/clojure/org/jclouds/compute.clj index 9e81de94ae..0ee451a81a 100644 --- a/compute/src/main/clojure/org/jclouds/compute.clj +++ b/compute/src/main/clojure/org/jclouds/compute.clj @@ -234,6 +234,30 @@ See http://code.google.com/p/jclouds for details." ([id #^ComputeService compute] (.getNodeMetadata compute id))) +(defn suspend-nodes-with-tag + "Reboot all the nodes with the given tag." + ([tag] (suspend-nodes-with-tag tag *compute*)) + ([#^String tag #^ComputeService compute] + (.suspendNodesMatching compute (NodePredicates/withTag tag)))) + +(defn suspend-node + "Suspend a node, given its id." + ([id] (suspend-node id *compute*)) + ([id #^ComputeService compute] + (.suspendNode compute id))) + +(defn resume-nodes-with-tag + "Suspend all the nodes with the given tag." + ([tag] (resume-nodes-with-tag tag *compute*)) + ([#^String tag #^ComputeService compute] + (.resumeNodesMatching compute (NodePredicates/withTag tag)))) + +(defn resume-node + "Resume a node, given its id." + ([id] (resume-node id *compute*)) + ([id #^ComputeService compute] + (.resumeNode compute id))) + (defn reboot-nodes-with-tag "Reboot all the nodes with the given tag." ([tag] (reboot-nodes-with-tag tag *compute*)) diff --git a/compute/src/main/clojure/org/jclouds/modules.clj b/compute/src/main/clojure/org/jclouds/modules.clj index b9d524e265..a8d3ceda81 100644 --- a/compute/src/main/clojure/org/jclouds/modules.clj +++ b/compute/src/main/clojure/org/jclouds/modules.clj @@ -52,6 +52,10 @@ (^void destroyNode [this ^String id] ()) (^void rebootNode [this ^String id] + ()) + (^void suspendNode [this ^String id] + ()) + (^void resumeNode [this ^String id] ())))) (defn compute-context [^RestContextSpec spec] diff --git a/compute/src/main/java/org/jclouds/compute/ComputeService.java b/compute/src/main/java/org/jclouds/compute/ComputeService.java index 5d640b7e6e..5df136488f 100755 --- a/compute/src/main/java/org/jclouds/compute/ComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeService.java @@ -63,52 +63,48 @@ public interface ComputeService { TemplateOptions templateOptions(); /** - * The list hardware profiles command shows you the options including virtual cpu count, - * memory, and disks. cpu count is not a portable quantity across clouds, as - * they are measured differently. However, it is a good indicator of relative - * speed within a cloud. memory is measured in megabytes and disks in - * gigabytes. + * The list hardware profiles command shows you the options including virtual cpu count, memory, + * and disks. cpu count is not a portable quantity across clouds, as they are measured + * differently. However, it is a good indicator of relative speed within a cloud. memory is + * measured in megabytes and disks in gigabytes. * - * @return a map of hardware profiles by ID, conceding that in some clouds the "id" is - * not used. + * @return a map of hardware profiles by ID, conceding that in some clouds the "id" is not used. */ Set listHardwareProfiles(); /** - * Images define the operating system and metadata related to a node. In some - * clouds, Images are bound to a specific region, and their identifiers are - * different across these regions. For this reason, you should consider - * matching image requirements like operating system family with - * TemplateBuilder as opposed to choosing an image explicitly. The - * getImages() command returns a map of images by id. + * Images define the operating system and metadata related to a node. In some clouds, Images are + * bound to a specific region, and their identifiers are different across these regions. For this + * reason, you should consider matching image requirements like operating system family with + * TemplateBuilder as opposed to choosing an image explicitly. The getImages() command returns a + * map of images by id. */ Set listImages(); /** - * all nodes available to the current user by id. If possible, the returned - * set will include {@link NodeMetadata} objects. + * all nodes available to the current user by id. If possible, the returned set will include + * {@link NodeMetadata} objects. */ Set listNodes(); /** - * The list locations command returns all the valid locations for nodes. A - * location has a scope, which is typically region or zone. A region is a - * general area, like eu-west, where a zone is similar to a datacenter. If a - * location has a parent, that implies it is within that location. For - * example a location can be a rack, whose parent is likely to be a zone. + * The list locations command returns all the valid locations for nodes. A location has a scope, + * which is typically region or zone. A region is a general area, like eu-west, where a zone is + * similar to a datacenter. If a location has a parent, that implies it is within that location. + * For example a location can be a rack, whose parent is likely to be a zone. */ Set listAssignableLocations(); /** * - * The compute api treats nodes as a group based on a tag you specify. Using - * this tag, you can choose to operate one or many nodes as a logical unit - * without regard to the implementation details of the cloud. + * The compute api treats nodes as a group based on a tag you specify. Using this tag, you can + * choose to operate one or many nodes as a logical unit without regard to the implementation + * details of the cloud. *

* - * The set that is returned will include credentials you can use to ssh into - * the nodes. The "key" part of the credentials is either a password or a - * private key. You have to inspect the value to determine this. + * The set that is returned will include credentials you can use to ssh into the nodes. The "key" + * part of the credentials is either a password or a private key. You have to inspect the value + * to determine this. * *

     * if (node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"))
@@ -116,11 +112,11 @@ public interface ComputeService {
     * 
* *

- * Note. if all you want to do is execute a script at bootup, you should - * consider use of the runscript option. + * Note. if all you want to do is execute a script at bootup, you should consider use of the + * runscript option. *

- * If resources such as security groups are needed, they will be reused or - * created for you. Inbound port 22 will always be opened up. + * If resources such as security groups are needed, they will be reused or created for you. + * Inbound port 22 will always be opened up. * * @param tag * - common identifier to group nodes by, cannot contain hyphens @@ -131,38 +127,65 @@ public interface ComputeService { * @return all of the nodes the api was able to launch in a running state. * * @throws RunNodesException - * when there's a problem applying options to nodes. Note that - * successful and failed nodes are a part of this exception, so be - * sure to inspect this carefully. + * when there's a problem applying options to nodes. Note that successful and failed + * nodes are a part of this exception, so be sure to inspect this carefully. */ Set runNodesWithTag(String tag, int count, Template template) throws RunNodesException; /** - * Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except - * that the template is default, equivalent to {@code - * templateBuilder().any().options(templateOptions)}. + * Like {@link ComputeService#runNodesWithTag(String,int,Template)}, except that the template is + * default, equivalent to {@code templateBuilder().any().options(templateOptions)}. */ Set runNodesWithTag(String tag, int count, TemplateOptions templateOptions) - throws RunNodesException; + throws RunNodesException; /** - * Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, - * except that the options are default, as specified in - * {@link ComputeService#templateOptions}. + * Like {@link ComputeService#runNodesWithTag(String,int,TemplateOptions)}, except that the + * options are default, as specified in {@link ComputeService#templateOptions}. */ Set runNodesWithTag(String tag, int count) throws RunNodesException; /** - * destroy the node, given its id. If it is the only node in a tag set, the - * dependent resources will also be destroyed. + * resume the node from {@link org.jclouds.compute.domain.NodeState#SUSPENDED suspended} state, + * given its id. + */ + void resumeNode(String id); + + /** + * nodes matching the filter are treated as a logical set. Using the resume command, you can save + * time by resumeing the nodes in parallel. + * + * @throws UnsupportedOperationException + * if the underlying provider doesn't support suspend/resume + */ + void resumeNodesMatching(Predicate filter); + + /** + * suspend the node, given its id. This will result in + * {@link org.jclouds.compute.domain.NodeState#SUSPENDED suspended} state. + * + * @throws UnsupportedOperationException + * if the underlying provider doesn't support suspend/resume + */ + void suspendNode(String id); + + /** + * nodes matching the filter are treated as a logical set. Using the suspend command, you can + * save time by suspending the nodes in parallel. + * + */ + void suspendNodesMatching(Predicate filter); + + /** + * destroy the node, given its id. If it is the only node in a tag set, the dependent resources + * will also be destroyed. */ void destroyNode(String id); /** - * nodes matching the filter are treated as a logical set. Using the delete - * command, you can save time by removing the nodes in parallel. When the - * last node in a set is destroyed, any indirect resources it uses, such as - * keypairs, are also destroyed. + * nodes matching the filter are treated as a logical set. Using the delete command, you can save + * time by removing the nodes in parallel. When the last node in a set is destroyed, any indirect + * resources it uses, such as keypairs, are also destroyed. * * @return list of nodes destroyed */ @@ -174,8 +197,8 @@ public interface ComputeService { void rebootNode(String id); /** - * nodes matching the filter are treated as a logical set. Using this - * command, you can save time by rebooting the nodes in parallel. + * nodes matching the filter are treated as a logical set. Using this command, you can save time + * by rebooting the nodes in parallel. */ void rebootNodesMatching(Predicate filter); @@ -185,8 +208,8 @@ public interface ComputeService { NodeMetadata getNodeMetadata(String id); /** - * get all nodes including details such as image and ip addresses even if it - * incurs extra requests to the service. + * get all nodes including details such as image and ip addresses even if it incurs extra + * requests to the service. * * @param filter * how to select the nodes you are interested in details on. @@ -196,24 +219,22 @@ public interface ComputeService { /** * Runs the script without any additional options * - * @see #runScriptOnNodesMatching(Predicate, Payload, + * @see #runScriptOnNodesMatching(Predicate, Payload, * org.jclouds.compute.options.RunScriptOptions) * @see org.jclouds.compute.predicates.NodePredicates#runningWithTag(String) */ Map runScriptOnNodesMatching(Predicate filter, Payload runScript) - throws RunScriptOnNodesException; + throws RunScriptOnNodesException; /** * Run the script on all nodes with the specific tag. * * @param filter - * Predicate-based filter to define on which nodes the script is to - * be executed + * Predicate-based filter to define on which nodes the script is to be executed * @param runScript * payload containing the script to run * @param options - * nullable options to how to run the script, whether to override - * credentials + * nullable options to how to run the script, whether to override credentials * @return map with node identifiers and corresponding responses * @throws RunScriptOnNodesException * if anything goes wrong during script execution @@ -222,6 +243,6 @@ public interface ComputeService { * @see org.jclouds.io.Payloads */ Map runScriptOnNodesMatching(Predicate filter, - Payload runScript, RunScriptOptions options) throws RunScriptOnNodesException; + Payload runScript, RunScriptOptions options) throws RunScriptOnNodesException; } diff --git a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java index 075f9ca51a..bf13254eaa 100644 --- a/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/ComputeServiceAdapter.java @@ -50,10 +50,10 @@ public interface ComputeServiceAdapter { * @param name * unique supplied name for the node, which has the tag encoded into it. * @param template - * includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to start + * includes {@code imageId}, {@code locationId}, and {@code hardwareId} used to resume * the instance. * @param credentialStore - * once the node is started, its login user and password must be stored keyed on + * once the node is resumeed, its login user and password must be stored keyed on * {@code node#id}. * @return library-native representation of a node. * @@ -94,6 +94,10 @@ public interface ComputeServiceAdapter { void rebootNode(String id); + void resumeNode(String id); + + void suspendNode(String id); + Iterable listNodes(); } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/config/BindComputeStrategiesByClass.java b/compute/src/main/java/org/jclouds/compute/config/BindComputeStrategiesByClass.java index 98e09c682c..0e3264fa39 100644 --- a/compute/src/main/java/org/jclouds/compute/config/BindComputeStrategiesByClass.java +++ b/compute/src/main/java/org/jclouds/compute/config/BindComputeStrategiesByClass.java @@ -25,6 +25,8 @@ import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.impl.EncodeTagIntoNameRunNodesAndAddToSetStrategy; import com.google.inject.AbstractModule; @@ -42,6 +44,8 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule { bindListNodesStrategy(defineListNodesStrategy()); bindGetNodeMetadataStrategy(defineGetNodeMetadataStrategy()); bindRebootNodeStrategy(defineRebootNodeStrategy()); + bindStartNodeStrategy(defineStartNodeStrategy()); + bindStopNodeStrategy(defineStopNodeStrategy()); bindDestroyNodeStrategy(defineDestroyNodeStrategy()); } @@ -64,6 +68,14 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule { bind(RebootNodeStrategy.class).to(clazz).in(Scopes.SINGLETON); } + protected void bindStartNodeStrategy(Class clazz) { + bind(ResumeNodeStrategy.class).to(clazz).in(Scopes.SINGLETON); + } + + protected void bindStopNodeStrategy(Class clazz) { + bind(SuspendNodeStrategy.class).to(clazz).in(Scopes.SINGLETON); + } + protected void bindGetNodeMetadataStrategy(Class clazz) { bind(GetNodeMetadataStrategy.class).to(clazz).in(Scopes.SINGLETON); } @@ -85,6 +97,10 @@ public abstract class BindComputeStrategiesByClass extends AbstractModule { protected abstract Class defineRebootNodeStrategy(); + protected abstract Class defineStartNodeStrategy(); + + protected abstract Class defineStopNodeStrategy(); + protected abstract Class defineGetNodeMetadataStrategy(); protected abstract Class defineListNodesStrategy(); diff --git a/compute/src/main/java/org/jclouds/compute/config/ComputeServiceTimeoutsModule.java b/compute/src/main/java/org/jclouds/compute/config/ComputeServiceTimeoutsModule.java index 9b1bb1e3cc..6ce5b875e7 100644 --- a/compute/src/main/java/org/jclouds/compute/config/ComputeServiceTimeoutsModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/ComputeServiceTimeoutsModule.java @@ -26,6 +26,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.predicates.NodeRunning; +import org.jclouds.compute.predicates.NodeSuspended; import org.jclouds.compute.predicates.NodeTerminated; import org.jclouds.compute.predicates.ScriptStatusReturnsZero; import org.jclouds.compute.predicates.ScriptStatusReturnsZero.CommandUsingClient; @@ -58,6 +59,15 @@ public class ComputeServiceTimeoutsModule extends AbstractModule { return timeouts.nodeTerminated == 0 ? stateTerminated : new RetryablePredicate(stateTerminated, timeouts.nodeTerminated); } + + + @Provides + @Singleton + @Named("NODE_SUSPENDED") + protected Predicate serverSuspended(NodeSuspended stateSuspended, Timeouts timeouts) { + return timeouts.nodeSuspended == 0 ? stateSuspended : new RetryablePredicate(stateSuspended, + timeouts.nodeSuspended); + } @Provides @Singleton diff --git a/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java b/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java index 04b17ba9e0..d9788657d5 100644 --- a/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java +++ b/compute/src/main/java/org/jclouds/compute/config/StandaloneComputeServiceContextModule.java @@ -38,6 +38,8 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.strategy.impl.AdaptingComputeServiceStrategies; import org.jclouds.compute.suppliers.DefaultLocationSupplier; import org.jclouds.domain.Location; @@ -82,7 +84,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideHardware(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -96,7 +98,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideImages(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -115,7 +117,7 @@ public class StandaloneComputeServiceContextModule extends BaseCompu @Provides @Singleton protected Supplier> provideLocations(final ComputeServiceAdapter adapter, - Function transformer) { + Function transformer) { return new TransformingSetSupplier(new Supplier>() { @Override @@ -156,6 +158,18 @@ public class StandaloneComputeServiceContextModule extends BaseCompu return in; } + @Provides + @Singleton + protected ResumeNodeStrategy defineStartNodeStrategy(AdaptingComputeServiceStrategies in) { + return in; + } + + @Provides + @Singleton + protected SuspendNodeStrategy defineStopNodeStrategy(AdaptingComputeServiceStrategies in) { + return in; + } + // enum singleton pattern public static enum IdentityFunction implements Function { INSTANCE; diff --git a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java index 8dad50f92e..422887ab6f 100755 --- a/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java +++ b/compute/src/main/java/org/jclouds/compute/internal/BaseComputeService.java @@ -74,7 +74,9 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; @@ -111,10 +113,13 @@ public class BaseComputeService implements ComputeService { protected final RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy; protected final RebootNodeStrategy rebootNodeStrategy; protected final DestroyNodeStrategy destroyNodeStrategy; + protected final ResumeNodeStrategy resumeNodeStrategy; + protected final SuspendNodeStrategy suspendNodeStrategy; protected final Provider templateBuilderProvider; protected final Provider templateOptionsProvider; protected final Predicate nodeRunning; protected final Predicate nodeTerminated; + protected final Predicate nodeSuspended; protected final ComputeUtils utils; protected final Timeouts timeouts; protected final ExecutorService executor; @@ -126,9 +131,11 @@ public class BaseComputeService implements ComputeService { @Memoized Supplier> locations, ListNodesStrategy listNodesStrategy, GetNodeMetadataStrategy getNodeMetadataStrategy, RunNodesAndAddToSetStrategy runNodesAndAddToSetStrategy, RebootNodeStrategy rebootNodeStrategy, DestroyNodeStrategy destroyNodeStrategy, + ResumeNodeStrategy resumeNodeStrategy, SuspendNodeStrategy suspendNodeStrategy, Provider templateBuilderProvider, Provider templateOptionsProvider, @Named("NODE_RUNNING") Predicate nodeRunning, - @Named("NODE_TERMINATED") Predicate nodeTerminated, ComputeUtils utils, Timeouts timeouts, + @Named("NODE_TERMINATED") Predicate nodeTerminated, + @Named("NODE_SUSPENDED") Predicate nodeSuspended, ComputeUtils utils, Timeouts timeouts, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor) { this.context = checkNotNull(context, "context"); this.credentialStore = checkNotNull(credentialStore, "credentialStore"); @@ -139,11 +146,14 @@ public class BaseComputeService implements ComputeService { this.getNodeMetadataStrategy = checkNotNull(getNodeMetadataStrategy, "getNodeMetadataStrategy"); this.runNodesAndAddToSetStrategy = checkNotNull(runNodesAndAddToSetStrategy, "runNodesAndAddToSetStrategy"); this.rebootNodeStrategy = checkNotNull(rebootNodeStrategy, "rebootNodeStrategy"); + this.resumeNodeStrategy = checkNotNull(resumeNodeStrategy, "resumeNodeStrategy"); + this.suspendNodeStrategy = checkNotNull(suspendNodeStrategy, "suspendNodeStrategy"); this.destroyNodeStrategy = checkNotNull(destroyNodeStrategy, "destroyNodeStrategy"); this.templateBuilderProvider = checkNotNull(templateBuilderProvider, "templateBuilderProvider"); this.templateOptionsProvider = checkNotNull(templateOptionsProvider, "templateOptionsProvider"); this.nodeRunning = checkNotNull(nodeRunning, "nodeRunning"); this.nodeTerminated = checkNotNull(nodeTerminated, "nodeTerminated"); + this.nodeSuspended = checkNotNull(nodeSuspended, "nodeSuspended"); this.utils = checkNotNull(utils, "utils"); this.timeouts = checkNotNull(timeouts, "timeouts"); this.executor = checkNotNull(executor, "executor"); @@ -174,7 +184,7 @@ public class BaseComputeService implements ComputeService { Set nodes = newHashSet(); Map badNodes = newLinkedHashMap(); Map> responses = runNodesAndAddToSetStrategy.execute(tag, count, template, nodes, badNodes); - Map executionExceptions = awaitCompletion(responses, executor, null, logger, "starting nodes"); + Map executionExceptions = awaitCompletion(responses, executor, null, logger, "resumeing nodes"); for (NodeMetadata node : concat(nodes, badNodes.keySet())) if (node.getCredentials() != null) credentialStore.put("node#" + node.getId(), node.getCredentials()); @@ -357,6 +367,66 @@ public class BaseComputeService implements ComputeService { logger.debug("<< rebooted"); } + /** + * {@inheritDoc} + */ + @Override + public void resumeNode(String id) { + checkNotNull(id, "id"); + logger.debug(">> resumeing node(%s)", id); + NodeMetadata node = resumeNodeStrategy.resumeNode(id); + boolean successful = nodeRunning.apply(node); + logger.debug("<< resumeed node(%s) success(%s)", id, successful); + } + + /** + * {@inheritDoc} + */ + @Override + public void resumeNodesMatching(Predicate filter) { + logger.debug(">> resumeing nodes matching(%s)", filter); + transformParallel(nodesMatchingFilterAndNotTerminated(filter), new Function>() { + // TODO use native async + @Override + public Future apply(NodeMetadata from) { + resumeNode(from.getId()); + return immediateFuture(null); + } + + }, executor, null, logger, "resumeing nodes"); + logger.debug("<< resumeed"); + } + + /** + * {@inheritDoc} + */ + @Override + public void suspendNode(String id) { + checkNotNull(id, "id"); + logger.debug(">> suspendping node(%s)", id); + NodeMetadata node = suspendNodeStrategy.suspendNode(id); + boolean successful = nodeSuspended.apply(node); + logger.debug("<< suspendped node(%s) success(%s)", id, successful); + } + + /** + * {@inheritDoc} + */ + @Override + public void suspendNodesMatching(Predicate filter) { + logger.debug(">> suspending nodes matching(%s)", filter); + transformParallel(nodesMatchingFilterAndNotTerminated(filter), new Function>() { + // TODO use native async + @Override + public Future apply(NodeMetadata from) { + suspendNode(from.getId()); + return immediateFuture(null); + } + + }, executor, null, logger, "suspending nodes"); + logger.debug("<< suspended"); + } + /** * {@inheritDoc} */ diff --git a/compute/src/main/java/org/jclouds/compute/predicates/NodeRunning.java b/compute/src/main/java/org/jclouds/compute/predicates/NodeRunning.java index eb320ba808..f48692525b 100644 --- a/compute/src/main/java/org/jclouds/compute/predicates/NodeRunning.java +++ b/compute/src/main/java/org/jclouds/compute/predicates/NodeRunning.java @@ -19,52 +19,24 @@ package org.jclouds.compute.predicates; -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.annotation.Resource; import javax.inject.Singleton; import org.jclouds.compute.ComputeService; -import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; -import org.jclouds.logging.Logger; -import com.google.common.base.Predicate; import com.google.inject.Inject; /** * - * Tests to see if a node is active. + * Tests to see if a node is running. * * @author Adrian Cole */ @Singleton -public class NodeRunning implements Predicate { - - private final ComputeService client; - - @Resource - protected Logger logger = Logger.NULL; +public class NodeRunning extends NodePresentAndInIntendedState { @Inject public NodeRunning(ComputeService client) { - this.client = client; - } - - public boolean apply(NodeMetadata node) { - logger.trace("looking for state on node %s", checkNotNull(node, "node")); - node = refresh(node); - if (node == null) - return false; - logger.trace("%s: looking for node state %s: currently: %s", - node.getId(), NodeState.RUNNING, node.getState()); - if (node.getState() == NodeState.ERROR) - throw new IllegalStateException("node " + node.getId() - + " in location " + node.getLocation() + " is in error state"); - return node.getState() == NodeState.RUNNING; - } - - private NodeMetadata refresh(NodeMetadata node) { - return client.getNodeMetadata(node.getId()); + super(NodeState.RUNNING, client); } } diff --git a/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java b/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java index 34981fd8b7..e9c9395c89 100644 --- a/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java +++ b/compute/src/main/java/org/jclouds/compute/reference/ComputeServiceConstants.java @@ -34,6 +34,7 @@ public interface ComputeServiceConstants { public static final String LOCAL_PARTITION_GB_PATTERN = "disk_drive/%s/gb"; public static final String PROPERTY_TIMEOUT_NODE_TERMINATED = "jclouds.compute.timeout.node-terminated"; public static final String PROPERTY_TIMEOUT_NODE_RUNNING = "jclouds.compute.timeout.node-running"; + public static final String PROPERTY_TIMEOUT_NODE_SUSPENDED = "jclouds.compute.timeout.node-suspended"; public static final String PROPERTY_TIMEOUT_SCRIPT_COMPLETE = "jclouds.compute.timeout.script-complete"; public static final String PROPERTY_TIMEOUT_PORT_OPEN = "jclouds.compute.timeout.port-open"; /** @@ -51,7 +52,11 @@ public interface ComputeServiceConstants { @Inject(optional = true) @Named(PROPERTY_TIMEOUT_NODE_RUNNING) public long nodeRunning = 1200 * 1000; - + + @Inject(optional = true) + @Named(PROPERTY_TIMEOUT_NODE_SUSPENDED) + public long nodeSuspended = 30 * 1000; + @Inject(optional = true) @Named(PROPERTY_TIMEOUT_SCRIPT_COMPLETE) public long scriptComplete = 600 * 1000; diff --git a/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java b/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java index c819bfd317..28cd081ce5 100644 --- a/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java +++ b/compute/src/main/java/org/jclouds/compute/strategy/impl/AdaptingComputeServiceStrategies.java @@ -41,6 +41,8 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.domain.Credentials; import org.jclouds.logging.Logger; @@ -54,7 +56,7 @@ import com.google.common.collect.Iterables; */ @Singleton public class AdaptingComputeServiceStrategies implements AddNodeWithTagStrategy, DestroyNodeStrategy, - GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy { + GetNodeMetadataStrategy, ListNodesStrategy, RebootNodeStrategy, ResumeNodeStrategy, SuspendNodeStrategy { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) protected Logger logger = Logger.NULL; @@ -65,7 +67,7 @@ public class AdaptingComputeServiceStrategies implements AddNodeWith @Inject public AdaptingComputeServiceStrategies(Map credentialStore, - ComputeServiceAdapter client, Function nodeMetadataAdapter) { + ComputeServiceAdapter client, Function nodeMetadataAdapter) { this.credentialStore = checkNotNull(credentialStore, "credentialStore"); this.client = checkNotNull(client, "client"); this.nodeMetadataAdapter = checkNotNull(nodeMetadataAdapter, "nodeMetadataAdapter"); @@ -101,6 +103,34 @@ public class AdaptingComputeServiceStrategies implements AddNodeWith return node; } + @Override + public NodeMetadata resumeNode(String id) { + + NodeMetadata node = getNode(id); + if (node == null || node.getState() == NodeState.TERMINATED || node.getState() == NodeState.RUNNING) + return node; + + logger.debug(">> resuming node(%s)", id); + client.resumeNode(id); + logger.debug("<< resumed node(%s)", id); + + return node; + } + + @Override + public NodeMetadata suspendNode(String id) { + + NodeMetadata node = getNode(id); + if (node == null || node.getState() == NodeState.TERMINATED || node.getState() == NodeState.SUSPENDED) + return node; + + logger.debug(">> suspending node(%s)", id); + client.suspendNode(id); + logger.debug("<< suspended node(%s)", id); + + return node; + } + @Override public NodeMetadata destroyNode(String id) { @@ -124,8 +154,8 @@ public class AdaptingComputeServiceStrategies implements AddNodeWith checkState(name != null && name.indexOf(tag) != -1, "name should have %s encoded into it", tag); logger.debug(">> instantiating node location(%s) name(%s) image(%s) hardware(%s)", - template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware() - .getProviderId()); + template.getLocation().getId(), name, template.getImage().getProviderId(), template.getHardware() + .getProviderId()); N from = client.runNodeWithTagAndNameAndStoreCredentials(tag, name, template, credentialStore); NodeMetadata node = nodeMetadataAdapter.apply(from); diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java index d9c8c54aab..2d8066c3f7 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceAdapter.java @@ -175,4 +175,30 @@ public class StubComputeServiceAdapter implements JCloudsNativeComputeServiceAda StubComputeServiceDependenciesModule.setState(node, NodeState.PENDING, 0); StubComputeServiceDependenciesModule.setState(node, NodeState.RUNNING, 50); } + + @Override + public void resumeNode(String id) { + NodeMetadata node = nodes.get(id); + if (node == null) + throw new ResourceNotFoundException("node not found: " + id); + if (node.getState() == NodeState.RUNNING) + return; + if (node.getState() != NodeState.SUSPENDED) + throw new IllegalStateException("to resume a node, it must be in suspended state, not: " + node.getState()); + StubComputeServiceDependenciesModule.setState(node, NodeState.PENDING, 0); + StubComputeServiceDependenciesModule.setState(node, NodeState.RUNNING, 50); + } + + @Override + public void suspendNode(String id) { + NodeMetadata node = nodes.get(id); + if (node == null) + throw new ResourceNotFoundException("node not found: " + id); + if (node.getState() == NodeState.SUSPENDED) + return; + if (node.getState() != NodeState.RUNNING) + throw new IllegalStateException("to suspend a node, it must be in running state, not: " + node.getState()); + StubComputeServiceDependenciesModule.setState(node, NodeState.PENDING, 0); + StubComputeServiceDependenciesModule.setState(node, NodeState.SUSPENDED, 50); + } } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java index 7424444238..8c54977605 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -138,10 +138,10 @@ public class ComputeUtils { "node didn't achieve the state running on node %s within %d seconds, final state: %s", node.getId(), timeouts.nodeRunning / 1000, node.getState())); List bootstrap = newArrayList(); - if (options.getRunScript() != null) - bootstrap.add(options.getRunScript()); if (options.getPublicKey() != null) bootstrap.add(new AuthorizeRSAPublicKey(options.getPublicKey())); + if (options.getRunScript() != null) + bootstrap.add(options.getRunScript()); if (options.getPrivateKey() != null) bootstrap.add(new InstallRSAPrivateKey(options.getPrivateKey())); if (bootstrap.size() >= 1) diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index d36a6a7f46..82e1d840b0 100755 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -83,7 +83,9 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Function; +import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Iterables; import com.google.inject.Guice; import com.google.inject.Module; @@ -388,6 +390,28 @@ public abstract class BaseComputeServiceLiveTest { testGet(); } + @Test(enabled = true, dependsOnMethods = "testReboot") + public void testSuspendResume() throws Exception { + client.suspendNodesMatching(withTag(tag)); + Set stoppedNodes = refreshNodes(); + + assert Iterables.all(stoppedNodes, new Predicate() { + + @Override + public boolean apply(NodeMetadata input) { + return input.getState() == NodeState.SUSPENDED; + } + + }) : nodes; + + client.resumeNodesMatching(withTag(tag)); + testGet(); + } + + private Set refreshNodes() { + return filter(client.listNodesDetailsMatching(all()), and(withTag(tag), not(TERMINATED))); + } + @Test(enabled = true) public void testCreateAndRunAService() throws Exception { @@ -572,7 +596,8 @@ public abstract class BaseComputeServiceLiveTest { ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); ExecResponse exec = ssh.exec("java -version"); - assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec; + assert exec.getError().indexOf("1.6") != -1 || exec.getOutput().indexOf("1.6") != -1 : exec + "\n" + + ssh.exec("cat /tmp/bootstrap/stdout.log /tmp/bootstrap/stderr.log"); } finally { if (ssh != null) ssh.disconnect(); diff --git a/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java b/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java index 5677de6da3..bb8463df8f 100644 --- a/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java +++ b/compute/src/test/java/org/jclouds/compute/ComputeTestUtils.java @@ -34,7 +34,6 @@ import java.util.concurrent.TimeoutException; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.predicates.OperatingSystemPredicates; import org.jclouds.rest.HttpClient; import org.jclouds.scriptbuilder.domain.Statement; @@ -49,14 +48,7 @@ import com.google.common.io.Files; */ public class ComputeTestUtils { public static Statement buildScript(OperatingSystem os) { - if (OperatingSystemPredicates.supportsApt().apply(os)) - return RunScriptData.APT_RUN_SCRIPT; - else if (OperatingSystemPredicates.supportsYum().apply(os)) - return RunScriptData.YUM_RUN_SCRIPT; - else if (OperatingSystemPredicates.supportsZypper().apply(os)) - return RunScriptData.ZYPPER_RUN_SCRIPT; - else - throw new IllegalArgumentException("don't know how to handle" + os.toString()); + return RunScriptData.installJavaAndCurl(os); } public static Map setupKeyPair() throws FileNotFoundException, IOException { @@ -69,8 +61,8 @@ public class ComputeTestUtils { checkSecretKeyFile(secretKeyFile); String secret = Files.toString(new File(secretKeyFile), Charsets.UTF_8); assert secret.startsWith("-----BEGIN RSA PRIVATE KEY-----") : "invalid key:\n" + secret; - return ImmutableMap. of("private", secret, "public", - Files.toString(new File(secretKeyFile + ".pub"), Charsets.UTF_8)); + return ImmutableMap. of("private", secret, "public", Files.toString(new File(secretKeyFile + + ".pub"), Charsets.UTF_8)); } public static void checkSecretKeyFile(String secretKeyFile) throws FileNotFoundException { diff --git a/compute/src/test/java/org/jclouds/compute/RunScriptData.java b/compute/src/test/java/org/jclouds/compute/RunScriptData.java index af134b0f6d..f09d10b758 100644 --- a/compute/src/test/java/org/jclouds/compute/RunScriptData.java +++ b/compute/src/test/java/org/jclouds/compute/RunScriptData.java @@ -70,7 +70,8 @@ public class RunScriptData { // just in case iptables are being used, try to open 8080 exec("iptables -I INPUT 1 -p tcp --dport 8080 -j ACCEPT"),// // TODO gogrid rules only allow ports 22, 3389, 80 and 443. - // the above rule will be ignored, so we have to apply this directly + // the above rule will be ignored, so we have to apply this + // directly exec("iptables -I RH-Firewall-1-INPUT 1 -p tcp --dport 8080 -j ACCEPT"),// exec("iptables-save"),// extractTargzIntoDirectory( @@ -84,8 +85,15 @@ public class RunScriptData { return toReturn; } + public static String aptInstall = "apt-get install -f -y -qq --force-yes"; + + public static String installAfterUpdatingIfNotPresent(String cmd) { + String aptInstallCmd = aptInstall + " " + cmd; + return String.format("which %s || (%s || (apt-get update && %s))", cmd, aptInstallCmd, aptInstallCmd); + } + public static final Statement APT_RUN_SCRIPT = newStatementList(// - exec("which curl || apt-get install -f -y -qq --force-yes curl"),// + exec(installAfterUpdatingIfNotPresent("curl")),// exec("(which java && java -fullversion 2>&1|egrep -q 1.6 ) ||"),// execHttpResponse(URI.create("http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install")),// exec(new StringBuilder()// diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index 63cde85bde..1880b4277a 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -121,48 +121,48 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes SshClient client5 = createMock(SshClient.class); expect(factory.create(new IPSocket("144.175.1.1", 22), new Credentials("root", "password1"))).andReturn( - client1); + client1); runScriptAndService(client1, 1); expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "password2"))).andReturn( - client2).times(2); + client2).times(2); expect(factory.create(new IPSocket("144.175.1.2", 22), new Credentials("root", "romeo"))).andThrow( - new SshException("Auth fail")); + new SshException("Auth fail")); client2.connect(); try { runScript(client2, "runScriptWithCreds", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class - .getResourceAsStream("/runscript.sh")), 2); + .getResourceAsStream("/runscript.sh")), 2); } catch (IOException e) { Throwables.propagate(e); } client2.disconnect(); expect(factory.create(new IPSocket("144.175.1.3", 22), new Credentials("root", "password3"))).andReturn( - client3).times(2); + client3).times(2); expect(factory.create(new IPSocket("144.175.1.4", 22), new Credentials("root", "password4"))).andReturn( - client4).times(2); + client4).times(2); expect(factory.create(new IPSocket("144.175.1.5", 22), new Credentials("root", "password5"))).andReturn( - client5).times(2); + client5).times(2); runScriptAndInstallSsh(client3, "bootstrap", 3); runScriptAndInstallSsh(client4, "bootstrap", 4); runScriptAndInstallSsh(client5, "bootstrap", 5); expect( - factory.create(eq(new IPSocket("144.175.1.1", 22)), - eq(new Credentials("root", keyPair.get("private"))))).andReturn(client1); + factory.create(eq(new IPSocket("144.175.1.1", 22)), eq(new Credentials("root", keyPair + .get("private"))))).andReturn(client1); expect( - factory.create(eq(new IPSocket("144.175.1.2", 22)), - eq(new Credentials("root", keyPair.get("private"))))).andReturn(client2); + factory.create(eq(new IPSocket("144.175.1.2", 22)), eq(new Credentials("root", keyPair + .get("private"))))).andReturn(client2); expect( - factory.create(eq(new IPSocket("144.175.1.3", 22)), - eq(new Credentials("root", keyPair.get("private"))))).andReturn(client3); + factory.create(eq(new IPSocket("144.175.1.3", 22)), eq(new Credentials("root", keyPair + .get("private"))))).andReturn(client3); expect( - factory.create(eq(new IPSocket("144.175.1.4", 22)), - eq(new Credentials("root", keyPair.get("private"))))).andReturn(client4); + factory.create(eq(new IPSocket("144.175.1.4", 22)), eq(new Credentials("root", keyPair + .get("private"))))).andReturn(client4); expect( - factory.create(eq(new IPSocket("144.175.1.5", 22)), - eq(new Credentials("root", keyPair.get("private"))))).andReturn(client5); + factory.create(eq(new IPSocket("144.175.1.5", 22)), eq(new Credentials("root", keyPair + .get("private"))))).andReturn(client5); helloAndJava(client2); helloAndJava(client3); @@ -184,7 +184,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes try { runScript(client, "jboss", Utils.toStringAndClose(StubComputeServiceIntegrationTest.class - .getResourceAsStream("/initscript_with_jboss.sh")), nodeId); + .getResourceAsStream("/initscript_with_jboss.sh")), nodeId); } catch (IOException e) { Throwables.propagate(e); } @@ -198,7 +198,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes try { runScript(client, scriptName, Utils.toStringAndClose(StubComputeServiceIntegrationTest.class - .getResourceAsStream("/initscript_with_java.sh")), nodeId); + .getResourceAsStream("/initscript_with_java.sh")), nodeId); } catch (IOException e) { Throwables.propagate(e); } @@ -251,7 +251,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes public void testAssignability() throws Exception { @SuppressWarnings("unused") RestContext, ConcurrentMap> stubContext = new ComputeServiceContextFactory() - .createContext(provider, identity, credential).getProviderSpecificContext(); + .createContext(provider, identity, credential).getProviderSpecificContext(); } private static class PayloadEquals implements IArgumentMatcher, Serializable { @@ -298,7 +298,7 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes return false; PayloadEquals other = (PayloadEquals) o; return this.expected == null && other.expected == null || this.expected != null - && this.expected.equals(other.expected); + && this.expected.equals(other.expected); } @Override @@ -361,6 +361,11 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes super.testReboot(); } + @Test(enabled = true, dependsOnMethods = "testReboot") + public void testSuspendResume() throws Exception { + super.testSuspendResume(); + } + @Test(enabled = true, dependsOnMethods = { "testImagesCache" }) public void testTemplateMatch() throws Exception { super.testTemplateMatch(); diff --git a/compute/src/test/resources/initscript_with_java.sh b/compute/src/test/resources/initscript_with_java.sh index c86087e78d..a3a361c7dc 100644 --- a/compute/src/test/resources/initscript_with_java.sh +++ b/compute/src/test/resources/initscript_with_java.sh @@ -76,17 +76,17 @@ END_OF_SCRIPT # add desired commands from the user cat >> $INSTANCE_HOME/bootstrap.sh <<'END_OF_SCRIPT' cd $INSTANCE_HOME -which curl || apt-get install -f -y -qq --force-yes curl -(which java && java -fullversion 2>&1|egrep -q 1.6 ) || -curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) -echo nameserver 208.67.222.222 >> /etc/resolv.conf -rm -rf /var/cache/apt /usr/lib/vmware-tools -echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc mkdir -p ~/.ssh cat >> ~/.ssh/authorized_keys <<'END_OF_FILE' ssh-rsa END_OF_FILE chmod 600 ~/.ssh/authorized_keys +which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl)) +(which java && java -fullversion 2>&1|egrep -q 1.6 ) || +curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) +echo nameserver 208.67.222.222 >> /etc/resolv.conf +rm -rf /var/cache/apt /usr/lib/vmware-tools +echo "export PATH=\"\$JAVA_HOME/bin/:\$PATH\"" >> /root/.bashrc mkdir -p ~/.ssh rm ~/.ssh/id_rsa cat >> ~/.ssh/id_rsa <<'END_OF_FILE' diff --git a/compute/src/test/resources/initscript_with_jboss.sh b/compute/src/test/resources/initscript_with_jboss.sh index 71d5e47a03..929a1954ae 100644 --- a/compute/src/test/resources/initscript_with_jboss.sh +++ b/compute/src/test/resources/initscript_with_jboss.sh @@ -63,7 +63,7 @@ init) ssh-rsa END_OF_FILE chmod 600 ~/.ssh/authorized_keys - which curl || apt-get install -f -y -qq --force-yes curl + which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl)) (which java && java -fullversion 2>&1|egrep -q 1.6 ) || curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) echo nameserver 208.67.222.222 >> /etc/resolv.conf diff --git a/compute/src/test/resources/runscript.sh b/compute/src/test/resources/runscript.sh index fb453fe339..eebf9a7237 100644 --- a/compute/src/test/resources/runscript.sh +++ b/compute/src/test/resources/runscript.sh @@ -76,7 +76,7 @@ END_OF_SCRIPT # add desired commands from the user cat >> $INSTANCE_HOME/runScriptWithCreds.sh <<'END_OF_SCRIPT' cd $INSTANCE_HOME -which curl || apt-get install -f -y -qq --force-yes curl +which curl || (apt-get install -f -y -qq --force-yes curl || (apt-get update && apt-get install -f -y -qq --force-yes curl)) (which java && java -fullversion 2>&1|egrep -q 1.6 ) || curl -X GET -s --retry 20 http://whirr.s3.amazonaws.com/0.2.0-incubating-SNAPSHOT/sun/java/install |(bash) echo nameserver 208.67.222.222 >> /etc/resolv.conf diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridBindComputeStrategiesByClass.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridBindComputeStrategiesByClass.java index e403aba469..e850f1ec5d 100644 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridBindComputeStrategiesByClass.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/compute/config/GoGridBindComputeStrategiesByClass.java @@ -25,11 +25,13 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.gogrid.compute.strategy.GoGridAddNodeWithTagStrategy; import org.jclouds.gogrid.compute.strategy.GoGridDestroyNodeStrategy; import org.jclouds.gogrid.compute.strategy.GoGridGetNodeMetadataStrategy; +import org.jclouds.gogrid.compute.strategy.GoGridLifeCycleStrategy; import org.jclouds.gogrid.compute.strategy.GoGridListNodesStrategy; -import org.jclouds.gogrid.compute.strategy.GoGridRebootNodeStrategy; /** * @@ -59,6 +61,16 @@ public class GoGridBindComputeStrategiesByClass extends BindComputeStrategiesByC @Override protected Class defineRebootNodeStrategy() { - return GoGridRebootNodeStrategy.class; + return GoGridLifeCycleStrategy.class; + } + + @Override + protected Class defineStartNodeStrategy() { + return GoGridLifeCycleStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return GoGridLifeCycleStrategy.class; } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridRebootNodeStrategy.java b/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridRebootNodeStrategy.java deleted file mode 100644 index 024c8af271..0000000000 --- a/gogrid/src/main/java/org/jclouds/gogrid/compute/strategy/GoGridRebootNodeStrategy.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.gogrid.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.gogrid.GoGridClient; -import org.jclouds.gogrid.domain.PowerCommand; -import org.jclouds.gogrid.domain.Server; -import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; -import org.jclouds.predicates.RetryablePredicate; - -import com.google.common.collect.Iterables; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class GoGridRebootNodeStrategy implements RebootNodeStrategy { - private final GoGridClient client; - private final RetryablePredicate serverLatestJobCompleted; - private final RetryablePredicate serverLatestJobCompletedShort; - private final GetNodeMetadataStrategy getNode; - - @Inject - protected GoGridRebootNodeStrategy(GoGridClient client, GetNodeMetadataStrategy getNode, Timeouts timeouts) { - this.client = client; - this.serverLatestJobCompleted = new RetryablePredicate(new ServerLatestJobCompleted(client - .getJobServices()), timeouts.nodeRunning * 9l / 10l); - this.serverLatestJobCompletedShort = new RetryablePredicate(new ServerLatestJobCompleted(client - .getJobServices()), timeouts.nodeRunning * 1l / 10l); - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String id) { - Server server = Iterables.getOnlyElement(client.getServerServices().getServersById(new Long(id))); - client.getServerServices().power(server.getName(), PowerCommand.RESTART); - serverLatestJobCompleted.apply(server); - client.getServerServices().power(server.getName(), PowerCommand.START); - serverLatestJobCompletedShort.apply(server); - return getNode.getNode(id); - } -} \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java index 9e85005fe0..16ef3dea14 100644 --- a/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java @@ -82,7 +82,7 @@ import com.google.inject.Module; * * @author Oleksiy Yarmula */ -@Test(enabled = false, groups = "live", testName = "gogrid.GoGridLiveTest") +@Test(enabled = true, groups = "live", testName = "gogrid.GoGridLiveTest") public class GoGridLiveTestDisabled { private GoGridClient client; diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java index 961129181c..ac7835a81b 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersBindComputeStrategiesByClass.java @@ -25,11 +25,13 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersAddNodeWithTagStrategy; import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersDestroyNodeStrategy; import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersGetNodeMetadataStrategy; import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersListNodesStrategy; -import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersRebootNodeStrategy; +import org.jclouds.rackspace.cloudservers.compute.strategy.CloudServersLifeCycleStrategy; /** * @@ -60,6 +62,16 @@ public class CloudServersBindComputeStrategiesByClass extends BindComputeStrateg @Override protected Class defineRebootNodeStrategy() { - return CloudServersRebootNodeStrategy.class; + return CloudServersLifeCycleStrategy.class; + } + + @Override + protected Class defineStartNodeStrategy() { + return CloudServersLifeCycleStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return CloudServersLifeCycleStrategy.class; } } \ No newline at end of file diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersRebootNodeStrategy.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersRebootNodeStrategy.java deleted file mode 100644 index ef7287d206..0000000000 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/strategy/CloudServersRebootNodeStrategy.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.rackspace.cloudservers.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.rackspace.cloudservers.CloudServersClient; -import org.jclouds.rackspace.cloudservers.domain.RebootType; - -/** - * @author Adrian Cole - */ -@Singleton -public class CloudServersRebootNodeStrategy implements RebootNodeStrategy { - private final CloudServersClient client; - private final GetNodeMetadataStrategy getNode; - - @Inject - protected CloudServersRebootNodeStrategy(CloudServersClient client, GetNodeMetadataStrategy getNode) { - this.client = client; - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String id) { - int serverId = Integer.parseInt(id); - // if false server wasn't around in the first place - client.rebootServer(serverId, RebootType.HARD); - return getNode.getNode(id); - } - -} \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java index 635880da38..6c669adf78 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -77,4 +77,9 @@ public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTe } } + @Test(expectedExceptions = UnsupportedOperationException.class) + public void testSuspendResume() throws Exception { + super.testSuspendResume(); + } + } \ No newline at end of file diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingBindComputeStrategiesByClass.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingBindComputeStrategiesByClass.java index f3fd9bd44a..aa1790a9a2 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingBindComputeStrategiesByClass.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/config/RimuHostingBindComputeStrategiesByClass.java @@ -6,11 +6,13 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingAddNodeWithTagStrategy; import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingDestroyNodeStrategy; import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingGetNodeMetadataStrategy; +import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingLifeCycleStrategy; import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingListNodesStrategy; -import org.jclouds.rimuhosting.miro.compute.strategy.RimuHostingRebootNodeStrategy; public class RimuHostingBindComputeStrategiesByClass extends BindComputeStrategiesByClass { @Override @@ -35,6 +37,16 @@ public class RimuHostingBindComputeStrategiesByClass extends BindComputeStrategi @Override protected Class defineRebootNodeStrategy() { - return RimuHostingRebootNodeStrategy.class; + return RimuHostingLifeCycleStrategy.class; + } + + @Override + protected Class defineStartNodeStrategy() { + return RimuHostingLifeCycleStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return RimuHostingLifeCycleStrategy.class; } } \ No newline at end of file diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingRebootNodeStrategy.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingRebootNodeStrategy.java deleted file mode 100644 index 7be53cac56..0000000000 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/strategy/RimuHostingRebootNodeStrategy.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.rimuhosting.miro.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.rimuhosting.miro.RimuHostingClient; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class RimuHostingRebootNodeStrategy implements RebootNodeStrategy { - private final RimuHostingClient client; - private final GetNodeMetadataStrategy getNode; - - @Inject - protected RimuHostingRebootNodeStrategy(RimuHostingClient client, GetNodeMetadataStrategy getNode) { - this.client = client; - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String id) { - Long serverId = Long.parseLong(id); - // if false server wasn't around in the first place - client.restartServer(serverId).getState(); - return getNode.getNode(id); - } - -} \ No newline at end of file diff --git a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java index 9e14ac8d20..01fe6b481f 100644 --- a/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java +++ b/sandbox/libvirt/src/main/java/org/jclouds/libvirt/compute/strategy/LibvirtComputeServiceAdapter.java @@ -285,4 +285,22 @@ public class LibvirtComputeServiceAdapter implements ComputeServiceAdapter defineRebootNodeStrategy() { - return SlicehostRebootNodeStrategy.class; + return SlicehostLifeCycleStrategy.class; + } + + @Override + protected Class defineStartNodeStrategy() { + return SlicehostLifeCycleStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return SlicehostLifeCycleStrategy.class; } } \ No newline at end of file diff --git a/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostRebootNodeStrategy.java b/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostRebootNodeStrategy.java deleted file mode 100644 index 7cc5bec0a6..0000000000 --- a/slicehost/src/main/java/org/jclouds/slicehost/compute/strategy/SlicehostRebootNodeStrategy.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.slicehost.compute.strategy; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.slicehost.SlicehostClient; - -/** - * - * @author Adrian Cole - */ -@Singleton -public class SlicehostRebootNodeStrategy implements RebootNodeStrategy { - private final SlicehostClient client; - private final GetNodeMetadataStrategy getNode; - - @Inject - protected SlicehostRebootNodeStrategy(SlicehostClient client, GetNodeMetadataStrategy getNode) { - this.client = client; - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String id) { - int sliceId = Integer.parseInt(id); - client.hardRebootSlice(sliceId); - return getNode.getNode(id); - } - -} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java index f522687df4..83e89e4344 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudBindComputeStrategiesByClass.java @@ -24,11 +24,13 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudAddNodeWithTagStrategy; import org.jclouds.vcloud.compute.strategy.VCloudDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudListNodesStrategy; -import org.jclouds.vcloud.compute.strategy.VCloudRebootNodeStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudLifeCycleStrategy; /** * @author Adrian Cole */ @@ -55,6 +57,16 @@ public class VCloudBindComputeStrategiesByClass extends CommonVCloudBindComputeS @Override protected Class defineRebootNodeStrategy() { - return VCloudRebootNodeStrategy.class; + return VCloudLifeCycleStrategy.class; + } + + @Override + protected Class defineStartNodeStrategy() { + return VCloudLifeCycleStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return VCloudLifeCycleStrategy.class; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressBindComputeStrategiesByClass.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressBindComputeStrategiesByClass.java index 9db991f7a6..65039af16a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressBindComputeStrategiesByClass.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudExpressBindComputeStrategiesByClass.java @@ -24,11 +24,13 @@ import org.jclouds.compute.strategy.DestroyNodeStrategy; import org.jclouds.compute.strategy.GetNodeMetadataStrategy; import org.jclouds.compute.strategy.ListNodesStrategy; import org.jclouds.compute.strategy.RebootNodeStrategy; +import org.jclouds.compute.strategy.ResumeNodeStrategy; +import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressAddNodeWithTagStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressDestroyNodeStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressGetNodeMetadataStrategy; import org.jclouds.vcloud.compute.strategy.VCloudExpressListNodesStrategy; -import org.jclouds.vcloud.compute.strategy.VCloudExpressRebootNodeStrategy; +import org.jclouds.vcloud.compute.strategy.VCloudExpressLifeCycleStrategy; /** * @author Adrian Cole @@ -57,6 +59,16 @@ public class VCloudExpressBindComputeStrategiesByClass extends CommonVCloudBindC @Override protected Class defineRebootNodeStrategy() { - return VCloudExpressRebootNodeStrategy.class; + return VCloudExpressLifeCycleStrategy.class; + } + + @Override + protected Class defineStartNodeStrategy() { + return VCloudExpressLifeCycleStrategy.class; + } + + @Override + protected Class defineStopNodeStrategy() { + return VCloudExpressLifeCycleStrategy.class; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java deleted file mode 100644 index 8252b662b9..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudExpressRebootNodeStrategy.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.vcloud.compute.strategy; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.vcloud.VCloudExpressClient; -import org.jclouds.vcloud.domain.Task; - -import com.google.common.base.Predicate; - -/** - * @author Adrian Cole - */ -@Singleton -public class VCloudExpressRebootNodeStrategy implements RebootNodeStrategy { - private final VCloudExpressClient client; - protected final Predicate taskTester; - protected final GetNodeMetadataStrategy getNode; - - @Inject - protected VCloudExpressRebootNodeStrategy(VCloudExpressClient client, Predicate taskTester, - GetNodeMetadataStrategy getNode) { - this.client = client; - this.taskTester = taskTester; - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String in) { - URI id = URI.create(checkNotNull(in, "node.id")); - Task task = client.resetVApp(id); - taskTester.apply(task.getHref()); - return getNode.getNode(in); - } -} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java deleted file mode 100644 index fc7effdc6c..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/strategy/VCloudRebootNodeStrategy.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * - * Copyright (C) 2010 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ==================================================================== - */ - -package org.jclouds.vcloud.compute.strategy; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.strategy.GetNodeMetadataStrategy; -import org.jclouds.compute.strategy.RebootNodeStrategy; -import org.jclouds.vcloud.VCloudClient; -import org.jclouds.vcloud.domain.Task; - -import com.google.common.base.Predicate; - -/** - * @author Adrian Cole - */ -@Singleton -public class VCloudRebootNodeStrategy implements RebootNodeStrategy { - private final VCloudClient client; - protected final Predicate taskTester; - protected final GetNodeMetadataStrategy getNode; - - @Inject - protected VCloudRebootNodeStrategy(VCloudClient client, Predicate taskTester, - GetNodeMetadataStrategy getNode) { - this.client = client; - this.taskTester = taskTester; - this.getNode = getNode; - } - - @Override - public NodeMetadata rebootNode(String in) { - URI id = URI.create(checkNotNull(in, "node.id")); - Task task = client.resetVAppOrVm(id); - taskTester.apply(task.getHref()); - return getNode.getNode(in); - } -} \ No newline at end of file