From aa41f4512b163ad6286ed86ca39444e0234f8abb Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Fri, 22 Jan 2010 20:39:23 +0000 Subject: [PATCH] Issue 130: added rackspace and cleaned up builder concepts git-svn-id: http://jclouds.googlecode.com/svn/trunk@2721 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../aws/ec2/compute/EC2ComputeService.java | 14 +- .../EC2ComputeServiceContextModule.java | 16 +- .../ec2/compute/{ => domain}/EC2Image.java | 28 +-- .../aws/ec2/compute/{ => domain}/EC2Size.java | 2 +- .../compute/EC2ComputeServiceLiveTest.java | 4 +- .../internal/BaseBlobIntegrationTest.java | 4 +- .../org/jclouds/compute/domain/Image.java | 8 +- .../jclouds/compute/domain/NodeMetadata.java | 4 - .../org/jclouds/compute/domain/NodeState.java | 10 +- .../{OperatingSystem.java => OsFamily.java} | 4 +- .../compute/domain/TemplateBuilder.java | 6 +- .../internal/CreateNodeResponseImpl.java | 6 +- .../compute/domain/internal/ImageImpl.java | 10 +- .../domain/internal/NodeMetadataImpl.java | 30 +-- .../compute/internal/TemplateBuilderImpl.java | 38 +-- .../jclouds/compute/util/ComputeUtils.java | 55 +++++ compute/src/main/resources/compute.properties | 2 + .../compute/BaseComputeServiceLiveTest.java | 23 +- .../cloudfiles/CloudFilesClient.java | 2 +- .../ParseObjectInfoListFromJsonResponse.java | 2 +- .../binders/BindRebootTypeToJsonPayload.java | 4 +- .../compute/CloudServersComputeService.java | 220 ++++++++++++++++++ ...udServersComputeServiceContextBuilder.java | 81 +++++++ ...udServersComputeServiceContextFactory.java | 69 ++++++ ...oudServersComputeServiceContextModule.java | 137 +++++++++++ .../compute/domain/CloudServersImage.java | 154 ++++++++++++ .../compute/domain/CloudServersSize.java | 72 ++++++ .../config/CloudServersContextModule.java | 19 ++ .../ParseInetAddressListFromJsonResponse.java | 4 +- .../cloudservers/predicates/ServerActive.java | 49 ++++ .../RackspaceAuthenticationRestModule.java | 47 +++- .../rackspace/filters/AddTimestampQuery.java | 8 +- .../filters/AuthenticateRequest.java | 46 +--- .../cloudservers/CloudServersClientTest.java | 27 ++- .../BindRebootTypeToJsonPayloadTest.java | 4 +- .../CloudServersComputeServiceLiveTest.java | 66 ++++++ .../cloudservers/compute/PropertiesTest.java | 53 +++++ .../filters/AddTimestampQueryTest.java | 8 +- rackspace/src/test/resources/log4j.xml | 149 +++++++----- .../compute/RimuHostingComputeService.java | 16 +- .../RimuHostingComputeServiceLiveTest.java | 4 +- .../antcontrib/samples/cargooverssh/build.xml | 4 +- tools/antcontrib/samples/compute/build.xml | 1 + .../ant/taskdefs/compute/ComputeTask.java | 7 +- .../taskdefs/compute/ComputeTaskUtils.java | 4 +- .../vcloud/compute/VCloudComputeService.java | 63 +---- .../VCloudComputeServiceContextModule.java | 6 +- .../compute/VCloudComputeClientLiveTest.java | 12 +- .../HostingDotComVCloudComputeService.java | 6 +- ...tingDotComVCloudComputeClientLiveTest.java | 6 +- ...ingDotComVCloudComputeServiceLiveTest.java | 4 +- .../compute/TerremarkVCloudComputeClient.java | 10 +- .../TerremarkVCloudComputeService.java | 17 +- .../TerremarkVCloudComputeClientLiveTest.java | 14 +- ...TerremarkVCloudComputeServiceLiveTest.java | 4 +- 55 files changed, 1308 insertions(+), 355 deletions(-) rename aws/core/src/main/java/org/jclouds/aws/ec2/compute/{ => domain}/EC2Image.java (83%) rename aws/core/src/main/java/org/jclouds/aws/ec2/compute/{ => domain}/EC2Size.java (98%) rename compute/src/main/java/org/jclouds/compute/domain/{OperatingSystem.java => OsFamily.java} (94%) create mode 100644 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeService.java create mode 100755 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextBuilder.java create mode 100755 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextFactory.java create mode 100755 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java create mode 100644 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersImage.java create mode 100644 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersSize.java create mode 100644 rackspace/src/main/java/org/jclouds/rackspace/cloudservers/predicates/ServerActive.java create mode 100644 rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java create mode 100644 rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/PropertiesTest.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 cd7f2f356a..49c20f06b6 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 @@ -36,6 +36,8 @@ import javax.inject.Singleton; import org.jclouds.aws.AWSResponseException; import org.jclouds.aws.domain.Region; import org.jclouds.aws.ec2.EC2Client; +import org.jclouds.aws.ec2.compute.domain.EC2Image; +import org.jclouds.aws.ec2.compute.domain.EC2Size; import org.jclouds.aws.ec2.domain.InstanceState; import org.jclouds.aws.ec2.domain.IpProtocol; import org.jclouds.aws.ec2.domain.KeyPair; @@ -46,7 +48,6 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.CreateNodeResponse; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.LoginType; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.Size; @@ -146,9 +147,9 @@ public class EC2ComputeService implements ComputeService { : ImmutableSet. of(runningInstance.getPrivateIpAddress()); return new CreateNodeResponseImpl(runningInstance.getId(), name, runningInstance.getRegion() .toString(), null, ImmutableMap. of(), instanceToNodeState - .get(runningInstance.getInstanceState()), publicAddresses, privateAddresses, 22, - LoginType.SSH, - new Credentials("root", keyPair.getKeyMaterial()), ImmutableMap. of()); + .get(runningInstance.getInstanceState()), publicAddresses, privateAddresses, + new Credentials("root", keyPair.getKeyMaterial()), ImmutableMap + . of()); } private KeyPair createKeyPairInRegion(Region region, String name) { @@ -213,9 +214,8 @@ public class EC2ComputeService implements ComputeService { return new NodeMetadataImpl(from.getId(), from.getKeyName(), from.getRegion().toString(), null, ImmutableMap. of(), instanceToNodeState.get(from .getInstanceState()), nullSafeSet(from.getIpAddress()), nullSafeSet(from - .getPrivateIpAddress()), 22, LoginType.SSH, ImmutableMap - . of("availabilityZone", from.getAvailabilityZone() - .toString())); + .getPrivateIpAddress()), ImmutableMap. of( + "availabilityZone", from.getAvailabilityZone().toString())); } Set nullSafeSet(InetAddress in) { diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java index 75d677ca62..c8e3c0e9ef 100755 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/config/EC2ComputeServiceContextModule.java @@ -37,13 +37,13 @@ import org.jclouds.aws.ec2.EC2; import org.jclouds.aws.ec2.EC2AsyncClient; import org.jclouds.aws.ec2.EC2Client; import org.jclouds.aws.ec2.compute.EC2ComputeService; -import org.jclouds.aws.ec2.compute.EC2Image; -import org.jclouds.aws.ec2.compute.EC2Size; +import org.jclouds.aws.ec2.compute.domain.EC2Image; +import org.jclouds.aws.ec2.compute.domain.EC2Size; import org.jclouds.aws.ec2.config.EC2ContextModule; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.internal.ComputeServiceContextImpl; import org.jclouds.compute.reference.ComputeServiceConstants; @@ -108,21 +108,21 @@ public class EC2ComputeServiceContextModule extends EC2ContextModule { for (final Region region : regionMap.keySet()) { for (final org.jclouds.aws.ec2.domain.Image from : sync.getAMIServices() .describeImagesInRegion(region, ownedBy("063491364108"))) { - OperatingSystem os = null; - String osVersion = ""; + OsFamily os = null; + String osDescription = ""; String version = ""; Matcher matcher = ALESTIC_PATTERN.matcher(from.getImageLocation()); if (matcher.find()) { try { - os = OperatingSystem.fromValue(matcher.group(1)); - osVersion = matcher.group(2); + os = OsFamily.fromValue(matcher.group(1)); + osDescription = matcher.group(2); version = matcher.group(3); } catch (IllegalArgumentException e) { holder.logger.debug("<< didn't match os(%s)", matcher.group(1)); } } - images.add(new EC2Image(from, os, osVersion, version)); + images.add(new EC2Image(from, os, osDescription, version)); } } holder.logger.debug("<< images(%d)", images.size()); diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2Image.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Image.java similarity index 83% rename from aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2Image.java rename to aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Image.java index 2b2c673fb9..138bdd55b6 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2Image.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Image.java @@ -21,11 +21,11 @@ * under the License. * ==================================================================== */ -package org.jclouds.aws.ec2.compute; +package org.jclouds.aws.ec2.compute.domain; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; /** * @@ -33,15 +33,15 @@ import org.jclouds.compute.domain.OperatingSystem; */ public class EC2Image implements Image { private final org.jclouds.aws.ec2.domain.Image image; - private final OperatingSystem os; - private final String osVersion; + private final OsFamily os; + private final String osDescription; private final String version; - public EC2Image(org.jclouds.aws.ec2.domain.Image image, OperatingSystem os, String osVersion, + public EC2Image(org.jclouds.aws.ec2.domain.Image image, OsFamily os, String osDescription, String version) { this.image = image; this.os = os; - this.osVersion = osVersion; + this.osDescription = osDescription; this.version = version; } @@ -67,13 +67,13 @@ public class EC2Image implements Image { } @Override - public OperatingSystem getOperatingSystem() { + public OsFamily getOsFamily() { return os; } @Override - public String getOperatingSystemVersion() { - return osVersion; + public String getOsDescription() { + return osDescription; } @Override @@ -91,7 +91,7 @@ public class EC2Image implements Image { int result = 1; result = prime * result + ((image == null) ? 0 : image.hashCode()); result = prime * result + ((os == null) ? 0 : os.hashCode()); - result = prime * result + ((osVersion == null) ? 0 : osVersion.hashCode()); + result = prime * result + ((osDescription == null) ? 0 : osDescription.hashCode()); result = prime * result + ((version == null) ? 0 : version.hashCode()); return result; } @@ -115,10 +115,10 @@ public class EC2Image implements Image { return false; } else if (!os.equals(other.os)) return false; - if (osVersion == null) { - if (other.osVersion != null) + if (osDescription == null) { + if (other.osDescription != null) return false; - } else if (!osVersion.equals(other.osVersion)) + } else if (!osDescription.equals(other.osDescription)) return false; if (version == null) { if (other.version != null) @@ -132,7 +132,7 @@ public class EC2Image implements Image { public String toString() { return "[id=" + getId() + ", version=" + version + ", location=" + getLocation() + ", architecture=" + getArchitecture() + ", operatingSystem=" - + getOperatingSystem() + ", operatingSystemVersion=" + getOperatingSystemVersion() + + getOsFamily() + ", operatingSystemVersion=" + getOsDescription() + ", description=" + getDescription() + "]"; } diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2Size.java b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java similarity index 98% rename from aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2Size.java rename to aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java index 56dc5c9779..ca7ca6e77d 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/compute/EC2Size.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/compute/domain/EC2Size.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.aws.ec2.compute; +package org.jclouds.aws.ec2.compute.domain; import org.jclouds.aws.ec2.domain.InstanceType; import org.jclouds.compute.domain.Architecture; diff --git a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java index e9d96b97a5..3ebe3bbf4e 100644 --- a/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/ec2/compute/EC2ComputeServiceLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.aws.ec2.compute; -import static org.jclouds.compute.domain.OperatingSystem.UBUNTU; +import static org.jclouds.compute.domain.OsFamily.UBUNTU; import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.domain.Template; @@ -42,7 +42,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { } protected Template buildTemplate(TemplateBuilder templateBuilder) { - return templateBuilder.os(UBUNTU).smallest().build(); + return templateBuilder.osFamily(UBUNTU).smallest().build(); } @Override diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index a6ed10fd0d..98802fc04b 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -35,6 +35,8 @@ import java.io.UnsupportedEncodingException; import java.util.Date; import java.util.SortedSet; +import javax.ws.rs.core.MediaType; + import org.jclouds.blobstore.ContainerNotFoundException; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; @@ -321,7 +323,7 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { Blob object = context.getBlobStore().newBlob(key); object.setPayload(TEST_STRING); - object.getMetadata().setContentType("text/plain"); + object.getMetadata().setContentType(MediaType.TEXT_PLAIN); object.getMetadata().setSize(new Long(TEST_STRING.length())); // NOTE all metadata in jclouds comes out as lowercase, in an effort to normalize the // providers. diff --git a/compute/src/main/java/org/jclouds/compute/domain/Image.java b/compute/src/main/java/org/jclouds/compute/domain/Image.java index 6082c3415b..ecd727badb 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/Image.java +++ b/compute/src/main/java/org/jclouds/compute/domain/Image.java @@ -44,13 +44,13 @@ public interface Image { /** * Operating System */ - OperatingSystem getOperatingSystem(); + OsFamily getOsFamily(); /** - * Version of the operating system + * Description of the operating system including the version. */ - String getOperatingSystemVersion(); - + String getOsDescription(); + /** * Version of the image */ diff --git a/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java b/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java index b7a5f8e9c2..451dafa5d9 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java +++ b/compute/src/main/java/org/jclouds/compute/domain/NodeMetadata.java @@ -32,10 +32,6 @@ public interface NodeMetadata extends ComputeMetadata { SortedSet getPublicAddresses(); SortedSet getPrivateAddresses(); - - int getLoginPort(); - - LoginType getLoginType(); /** * Other variables present that the provider supports diff --git a/compute/src/main/java/org/jclouds/compute/domain/NodeState.java b/compute/src/main/java/org/jclouds/compute/domain/NodeState.java index c3537bb055..7d832aa200 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/NodeState.java +++ b/compute/src/main/java/org/jclouds/compute/domain/NodeState.java @@ -39,6 +39,14 @@ public enum NodeState { /** * The node is available for requests */ - RUNNING; + RUNNING, + /** + * There is an error on the node + */ + ERROR, + /** + * The state of the node is unknown. + */ + UNKNOWN; } \ No newline at end of file diff --git a/compute/src/main/java/org/jclouds/compute/domain/OperatingSystem.java b/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java similarity index 94% rename from compute/src/main/java/org/jclouds/compute/domain/OperatingSystem.java rename to compute/src/main/java/org/jclouds/compute/domain/OsFamily.java index b680a1b439..586b93cdb3 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/OperatingSystem.java +++ b/compute/src/main/java/org/jclouds/compute/domain/OsFamily.java @@ -32,7 +32,7 @@ import com.google.common.base.CaseFormat; * * @author Adrian Cole */ -public enum OperatingSystem { +public enum OsFamily { CENTOS, RHEL, FEDORA, DEBIAN, UBUNTU, JEOS, WINDOWS; public String value() { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_HYPHEN, name()); @@ -43,7 +43,7 @@ public enum OperatingSystem { return value(); } - public static OperatingSystem fromValue(String operatingSystem) { + public static OsFamily fromValue(String operatingSystem) { return valueOf(CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_UNDERSCORE, checkNotNull( operatingSystem, "region"))); } diff --git a/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java b/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java index b838da926c..6cb2b96bea 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java +++ b/compute/src/main/java/org/jclouds/compute/domain/TemplateBuilder.java @@ -67,7 +67,7 @@ public interface TemplateBuilder { /** * Configure this template to use a specific operating system image. */ - TemplateBuilder os(OperatingSystem os); + TemplateBuilder osFamily(OsFamily os); /** * Configure this template to start in a specific location @@ -92,10 +92,10 @@ public interface TemplateBuilder { TemplateBuilder sizeId(String sizeId); /** - * Configure this template to have an operating system version that matches the regular + * Configure this template to have an operating system description that matches the regular * expression */ - TemplateBuilder osVersionMatches(String osVersionRegex); + TemplateBuilder osDescriptionMatches(String osDescriptionRegex); /** * Configure this template to have an image version that matches the regular expression diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/CreateNodeResponseImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/CreateNodeResponseImpl.java index 57003f4a70..caab3b91d2 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/CreateNodeResponseImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/CreateNodeResponseImpl.java @@ -23,7 +23,6 @@ import java.net.URI; import java.util.Map; import org.jclouds.compute.domain.CreateNodeResponse; -import org.jclouds.compute.domain.LoginType; import org.jclouds.compute.domain.NodeState; import org.jclouds.domain.Credentials; @@ -41,9 +40,8 @@ public class CreateNodeResponseImpl extends NodeMetadataImpl implements CreateNo public CreateNodeResponseImpl(String id, String name, String location, URI uri, Map userMetadata, NodeState state, Iterable publicAddresses, Iterable privateAddresses, - int loginPort, LoginType loginType, Credentials credentials, Map extra) { - super(id, name, location, uri, userMetadata, state, publicAddresses, privateAddresses, - loginPort, loginType, extra); + Credentials credentials, Map extra) { + super(id, name, location, uri, userMetadata, state, publicAddresses, privateAddresses, extra); this.credentials = credentials; } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java index 5a7af607e4..7287ba9e22 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/ImageImpl.java @@ -25,7 +25,7 @@ package org.jclouds.compute.domain.internal; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; /** * @author Adrian Cole @@ -35,7 +35,7 @@ public class ImageImpl implements Image { private final String id; private final String description; private final String version; - private final OperatingSystem operatingSystem; + private final OsFamily operatingSystem; private final String operatingSystemVersion; private final String location; private final Architecture architecture; @@ -56,7 +56,7 @@ public class ImageImpl implements Image { return result; } - public ImageImpl(String id, String description, String version, OperatingSystem operatingSystem, + public ImageImpl(String id, String description, String version, OsFamily operatingSystem, String operatingSystemVersion, String location, Architecture architecture) { this.id = id; this.description = description; @@ -140,7 +140,7 @@ public class ImageImpl implements Image { * {@inheritDoc} */ @Override - public OperatingSystem getOperatingSystem() { + public OsFamily getOsFamily() { return operatingSystem; } @@ -172,7 +172,7 @@ public class ImageImpl implements Image { * {@inheritDoc} */ @Override - public String getOperatingSystemVersion() { + public String getOsDescription() { return operatingSystemVersion; } diff --git a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java index 7f6bf213e9..6f32685d6a 100644 --- a/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java +++ b/compute/src/main/java/org/jclouds/compute/domain/internal/NodeMetadataImpl.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.SortedSet; import org.jclouds.compute.domain.ComputeType; -import org.jclouds.compute.domain.LoginType; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; @@ -53,19 +52,15 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat private final SortedSet publicAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR); private final SortedSet privateAddresses = Sets.newTreeSet(ADDRESS_COMPARATOR); private final Map extra = Maps.newLinkedHashMap(); - private final int loginPort; - private final LoginType loginType; public NodeMetadataImpl(String id, String name, String location, URI uri, Map userMetadata, NodeState state, Iterable publicAddresses, Iterable privateAddresses, - int loginPort, LoginType loginType, Map extra) { + Map extra) { super(ComputeType.NODE, id, name, location, uri, userMetadata); this.state = state; Iterables.addAll(this.publicAddresses, publicAddresses); Iterables.addAll(this.privateAddresses, privateAddresses); - this.loginPort = loginPort; - this.loginType = loginType; this.extra.putAll(extra); } @@ -83,20 +78,6 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat return privateAddresses; } - /** - * {@inheritDoc} - */ - public int getLoginPort() { - return loginPort; - } - - /** - * {@inheritDoc} - */ - public LoginType getLoginType() { - return loginType; - } - /** * {@inheritDoc} */ @@ -125,8 +106,6 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat final int prime = 31; int result = super.hashCode(); result = prime * result + ((extra == null) ? 0 : extra.hashCode()); - result = prime * result + loginPort; - result = prime * result + ((loginType == null) ? 0 : loginType.hashCode()); result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode()); result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode()); result = prime * result + ((state == null) ? 0 : state.hashCode()); @@ -147,13 +126,6 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat return false; } else if (!extra.equals(other.extra)) return false; - if (loginPort != other.loginPort) - return false; - if (loginType == null) { - if (other.loginType != null) - return false; - } else if (!loginType.equals(other.loginType)) - return false; if (privateAddresses == null) { if (other.privateAddresses != null) return false; diff --git a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java index fc48b8a211..60270ff04b 100644 --- a/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java +++ b/compute/src/main/java/org/jclouds/compute/internal/TemplateBuilderImpl.java @@ -9,7 +9,7 @@ import javax.inject.Named; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; @@ -40,12 +40,12 @@ public class TemplateBuilderImpl implements TemplateBuilder { private final Set images; private final Set sizes; private String location; - private OperatingSystem os; + private OsFamily os; private Architecture arch; private String imageId; private String sizeId; - private String osVersion; + private String osDescription; private String imageVersion; private String imageDescription; @@ -94,7 +94,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { public boolean apply(Image input) { boolean returnVal = true; if (os != null) - returnVal = os.equals(input.getOperatingSystem()); + returnVal = os.equals(input.getOsFamily()); return returnVal; } @@ -110,15 +110,15 @@ public class TemplateBuilderImpl implements TemplateBuilder { } }; - private final Predicate osVersionPredicate = new Predicate() { + private final Predicate osDescriptionPredicate = new Predicate() { @Override public boolean apply(Image input) { boolean returnVal = true; - if (osVersion != null) { - if (input.getOperatingSystemVersion() == null) + if (osDescription != null) { + if (input.getOsDescription() == null) returnVal = false; else - returnVal = input.getOperatingSystemVersion().matches(osVersion); + returnVal = input.getOsDescription().matches(osDescription); } return returnVal; } @@ -166,7 +166,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { }; private final Predicate imagePredicate = Predicates.and(imageIdPredicate, - locationPredicate, osPredicate, imageArchPredicate, osVersionPredicate, + locationPredicate, osPredicate, imageArchPredicate, osDescriptionPredicate, imageVersionPredicate, imageDescriptionPredicate); private final Predicate sizeArchPredicate = new Predicate() { @@ -208,8 +208,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { }; static final Ordering DEFAULT_IMAGE_ORDERING = new Ordering() { public int compare(Image left, Image right) { - return ComparisonChain.start().compare(left.getOperatingSystemVersion(), - right.getOperatingSystemVersion()).compare(left.getVersion(), right.getVersion()) + return ComparisonChain.start().compare(left.getOsDescription(), + right.getOsDescription()).compare(left.getVersion(), right.getVersion()) .result(); } }; @@ -241,10 +241,10 @@ public class TemplateBuilderImpl implements TemplateBuilder { public TemplateBuilder fromImage(Image image) { if (image.getLocation() != null) this.location = image.getLocation(); - if (image.getOperatingSystem() != null) - this.os = image.getOperatingSystem(); - if (image.getOperatingSystemVersion() != null) - this.osVersion = image.getOperatingSystemVersion(); + if (image.getOsFamily() != null) + this.os = image.getOsFamily(); + if (image.getOsDescription() != null) + this.osDescription = image.getOsDescription(); if (image.getVersion() != null) this.imageVersion = image.getVersion(); if (image.getArchitecture() != null) @@ -292,7 +292,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { * {@inheritDoc} */ @Override - public TemplateBuilder os(OperatingSystem os) { + public TemplateBuilder osFamily(OsFamily os) { this.os = os; return this; } @@ -387,8 +387,8 @@ public class TemplateBuilderImpl implements TemplateBuilder { * {@inheritDoc} */ @Override - public TemplateBuilder osVersionMatches(String osVersionRegex) { - this.osVersion = osVersionRegex; + public TemplateBuilder osDescriptionMatches(String osDescriptionRegex) { + this.osDescription = osDescriptionRegex; return this; } @@ -406,7 +406,7 @@ public class TemplateBuilderImpl implements TemplateBuilder { return "[arch=" + arch + ", biggest=" + biggest + ", fastest=" + fastest + ", imageDescription=" + imageDescription + ", imageId=" + imageId + ", imageVersion=" + imageVersion + ", location=" + location + ", minCores=" - + minCores + ", minRam=" + minRam + ", os=" + os + ", osVersion=" + osVersion + + minCores + ", minRam=" + minRam + ", os=" + os + ", osDescription=" + osDescription + ", sizeId=" + sizeId + "]"; } 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 cf030a982c..6ccfd5a006 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeUtils.java @@ -18,17 +18,41 @@ */ package org.jclouds.compute.util; +import static com.google.common.base.Preconditions.checkState; + +import java.io.ByteArrayInputStream; +import java.net.InetSocketAddress; + +import javax.annotation.Resource; +import javax.inject.Named; + import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.CreateNodeResponse; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.logging.Logger; +import org.jclouds.ssh.SshClient; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.inject.Inject; /** * * @author Adrian Cole */ public class ComputeUtils { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + @Inject(optional = true) + private SshClient.Factory sshFactory; + private final Predicate socketTester; + + @Inject + public ComputeUtils(Predicate socketTester) { + this.socketTester = socketTester; + } + public static Iterable filterByName( Iterable nodes, final String name) { return Iterables.filter(nodes, new Predicate() { @@ -39,6 +63,37 @@ public class ComputeUtils { }); } + public void runScriptOnNode(CreateNodeResponse node, byte[] script) { + checkState(this.sshFactory != null, "runScript requested, but no SshModule configured"); + + InetSocketAddress socket = new InetSocketAddress(node.getPublicAddresses().last(), 22); + socketTester.apply(socket); + SshClient ssh = isKeyAuth(node) ? sshFactory.create(socket, node.getCredentials().account, + node.getCredentials().key.getBytes()) : sshFactory.create(socket, node + .getCredentials().account, node.getCredentials().key); + try { + ssh.connect(); + String scriptName = node.getId() + ".sh"; + ssh.put(scriptName, new ByteArrayInputStream(script)); + ssh.exec("chmod 755 " + scriptName); + if (node.getCredentials().account.equals("root")) { + logger.debug(">> running %s as %s", scriptName, node.getCredentials().account); + logger.debug("<< complete(%d)", ssh.exec("./" + scriptName).getExitCode()); + } else if (isKeyAuth(node)) { + logger.debug(">> running sudo %s as %s", scriptName, node.getCredentials().account); + logger.debug("<< complete(%d)", ssh.exec("sudo ./" + scriptName).getExitCode()); + } else { + logger.debug(">> running sudo -S %s as %s", scriptName, node.getCredentials().account); + logger.debug("<< complete(%d)", ssh.exec( + String.format("echo %s|sudo -S ./%s", node.getCredentials().key, scriptName)) + .getExitCode()); + } + } finally { + if (ssh != null) + ssh.disconnect(); + } + } + public static boolean isKeyAuth(CreateNodeResponse createdNode) { return createdNode.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"); } diff --git a/compute/src/main/resources/compute.properties b/compute/src/main/resources/compute.properties index e021ed996f..3fd89ae306 100644 --- a/compute/src/main/resources/compute.properties +++ b/compute/src/main/resources/compute.properties @@ -24,5 +24,7 @@ hostingdotcom.contextbuilder=org.jclouds.vcloud.hostingdotcom.compute.HostingDot hostingdotcom.propertiesbuilder=org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudPropertiesBuilder ec2.contextbuilder=org.jclouds.aws.ec2.compute.EC2ComputeServiceContextBuilder ec2.propertiesbuilder=org.jclouds.aws.ec2.EC2PropertiesBuilder +cloudservers.contextbuilder=org.jclouds.rackspace.cloudservers.compute.CloudServersComputeServiceContextBuilder +cloudservers.propertiesbuilder=org.jclouds.rackspace.RackspacePropertiesBuilder # example of where to change your endpoint # ec2.endpoint=https://ec2.us-west-1.amazonaws.com \ No newline at end of file diff --git a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java index 190c8a1e3a..4cc3cbf587 100644 --- a/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/BaseComputeServiceLiveTest.java @@ -33,9 +33,8 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.CreateNodeResponse; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.LoginType; import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; @@ -45,7 +44,6 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.scriptbuilder.ScriptBuilder; -import org.jclouds.scriptbuilder.domain.OsFamily; import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.ssh.ExecResponse; import org.jclouds.ssh.SshClient; @@ -101,13 +99,13 @@ public abstract class BaseComputeServiceLiveTest { } private boolean canRunScript(Template template) { - return template.getImage().getOperatingSystem() == OperatingSystem.UBUNTU - || template.getImage().getOperatingSystem() == OperatingSystem.JEOS; + return template.getImage().getOsFamily() == OsFamily.UBUNTU + || template.getImage().getOsFamily() == OsFamily.JEOS; } abstract protected Module getSshModule(); - @Test(enabled = false) + @Test(enabled = true) public void testCreate() throws Exception { try { client.destroyNode(Iterables.find(client.listNodes(), new Predicate() { @@ -133,11 +131,9 @@ public abstract class BaseComputeServiceLiveTest { .addStatement(Statements.exec("apt-get install -y openjdk-6-jdk"))// .addStatement(Statements.exec("wget -qO/usr/bin/runurl run.alestic.com/runurl"))// .addStatement(Statements.exec("chmod 755 /usr/bin/runurl"))// - .build(OsFamily.UNIX).getBytes()); + .build(org.jclouds.scriptbuilder.domain.OsFamily.UNIX).getBytes()); node = client.runNode(nodeName, template, options); assertNotNull(node.getId()); - assertEquals(node.getLoginPort(), 22); - assertEquals(node.getLoginType(), LoginType.SSH); assertNotNull(node.getName()); assertEquals(node.getPublicAddresses().size(), 1); assertNotNull(node.getCredentials()); @@ -148,12 +144,10 @@ public abstract class BaseComputeServiceLiveTest { protected abstract Template buildTemplate(TemplateBuilder templateBuilder); - @Test(enabled = false, dependsOnMethods = "testCreate") + @Test(enabled = true, dependsOnMethods = "testCreate") public void testGet() throws Exception { NodeMetadata metadata = client.getNodeMetadata(node); assertEquals(metadata.getId(), node.getId()); - assertEquals(metadata.getLoginPort(), node.getLoginPort()); - assertEquals(metadata.getLoginType(), node.getLoginType()); assertEquals(metadata.getName(), node.getName()); assertEquals(metadata.getPrivateAddresses(), node.getPrivateAddresses()); assertEquals(metadata.getPublicAddresses(), node.getPublicAddresses()); @@ -176,7 +170,7 @@ public abstract class BaseComputeServiceLiveTest { public void testListSizes() throws Exception { for (Size size : client.listSizes()) { - assert size.getCores() > 0; + assert size.getCores() > 0 : size; } } @@ -193,8 +187,7 @@ public abstract class BaseComputeServiceLiveTest { } private void doCheckKey() throws IOException { - InetSocketAddress socket = new InetSocketAddress(node.getPublicAddresses().last(), node - .getLoginPort()); + InetSocketAddress socket = new InetSocketAddress(node.getPublicAddresses().last(), 22); socketTester.apply(socket); SshClient ssh = node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----") ? sshFactory .create(socket, node.getCredentials().account, node.getCredentials().key.getBytes()) diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java index b8975ba60e..80ce19b0f6 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/CloudFilesClient.java @@ -59,7 +59,7 @@ public interface CloudFilesClient { * Determine the number of Containers within the account and the total bytes stored. Since the * storage system is designed to store large amounts of data, care should be taken when * representing the total bytes response as an integer; when possible, convert it to a 64-bit - * unsigned integer if your platform supports that primitive type. + * unsigned integer if your platform supports that primitive flavor. */ AccountMetadata getAccountStatistics(); diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java index d42fff547a..d62a134e6f 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudfiles/functions/ParseObjectInfoListFromJsonResponse.java @@ -145,7 +145,7 @@ public class ParseObjectInfoListFromJsonResponse extends @Override public String toString() { - return "ObjectInfoImpl [bytes=" + bytes + ", content_type=" + content_type + ", hash=" + return "ObjectInfoImpl [bytes=" + bytes + ", content_flavor=" + content_type + ", hash=" + hash + ", last_modified=" + last_modified.getTime() + ", name=" + name + "]"; } } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayload.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayload.java index ae4f8bb8fd..56423b14b6 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayload.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayload.java @@ -44,7 +44,7 @@ public class BindRebootTypeToJsonPayload extends BindToJsonPayload { @Override public void bindToRequest(HttpRequest request, Object toBind) { checkArgument(toBind instanceof RebootType, "this binder is only valid for RebootTypes!"); - super.bindToRequest(request, ImmutableMap.of("reboot", ImmutableMap.of("type", - checkNotNull(toBind, "type")))); + super.bindToRequest(request, ImmutableMap.of("reboot", ImmutableMap.of("flavor", + checkNotNull(toBind, "flavor")))); } } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeService.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeService.java new file mode 100644 index 0000000000..59b05856cb --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeService.java @@ -0,0 +1,220 @@ +/** + * + * Copyright (C) 2009 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; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; +import java.util.Set; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Provider; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.domain.ComputeMetadata; +import org.jclouds.compute.domain.ComputeType; +import org.jclouds.compute.domain.CreateNodeResponse; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.domain.NodeState; +import org.jclouds.compute.domain.Size; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.domain.internal.CreateNodeResponseImpl; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; +import org.jclouds.compute.options.RunNodeOptions; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeUtils; +import org.jclouds.domain.Credentials; +import org.jclouds.domain.ResourceLocation; +import org.jclouds.logging.Logger; +import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rackspace.cloudservers.compute.domain.CloudServersImage; +import org.jclouds.rackspace.cloudservers.compute.domain.CloudServersSize; +import org.jclouds.rackspace.cloudservers.domain.Server; +import org.jclouds.rackspace.cloudservers.domain.ServerStatus; +import org.jclouds.rackspace.cloudservers.options.ListOptions; + +import com.google.common.base.Function; +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +@Singleton +public class CloudServersComputeService implements ComputeService { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + private final org.jclouds.rackspace.cloudservers.CloudServersClient client; + protected final Provider> images; + protected final Provider> sizes; + protected final Provider templateBuilderProvider; + private final String location; + private final ComputeUtils utils; + private final Predicate serverActive; + private final ServerToNodeMetadata serverToNodeMetadata; + + @Inject + public CloudServersComputeService(CloudServersClient client, + Provider templateBuilderProvider, @ResourceLocation String location, + Provider> images, Provider> sizes, + ComputeUtils utils, Predicate serverActive, + ServerToNodeMetadata serverToNodeMetadata) { + this.location = location; + this.client = client; + this.images = images; + this.sizes = sizes; + this.utils = utils; + this.templateBuilderProvider = templateBuilderProvider; + this.serverActive = serverActive; + this.serverToNodeMetadata = serverToNodeMetadata; + } + + private static Map instanceToNodeState = ImmutableMap + . builder().put(ServerStatus.ACTIVE, NodeState.RUNNING)// + .put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)// + .put(ServerStatus.DELETED, NodeState.TERMINATED)// + .put(ServerStatus.QUEUE_RESIZE, NodeState.PENDING)// + .put(ServerStatus.PREP_RESIZE, NodeState.PENDING)// + .put(ServerStatus.RESIZE, NodeState.PENDING)// + .put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)// + .put(ServerStatus.QUEUE_MOVE, NodeState.PENDING)// + .put(ServerStatus.PREP_MOVE, NodeState.PENDING)// + .put(ServerStatus.MOVE, NodeState.PENDING)// + .put(ServerStatus.VERIFY_MOVE, NodeState.PENDING)// + .put(ServerStatus.RESCUE, NodeState.PENDING)// + .put(ServerStatus.ERROR, NodeState.ERROR)// + .put(ServerStatus.BUILD, NodeState.PENDING)// + .put(ServerStatus.RESTORING, NodeState.PENDING)// + .put(ServerStatus.PASSWORD, NodeState.PENDING)// + .put(ServerStatus.REBUILD, NodeState.PENDING)// + .put(ServerStatus.DELETE_IP, NodeState.PENDING)// + .put(ServerStatus.SHARE_IP_NO_CONFIG, NodeState.PENDING)// + .put(ServerStatus.SHARE_IP, NodeState.PENDING)// + .put(ServerStatus.REBOOT, NodeState.PENDING)// + .put(ServerStatus.HARD_REBOOT, NodeState.PENDING)// + .put(ServerStatus.UNKNOWN, NodeState.UNKNOWN).build(); + + @Override + public CreateNodeResponse runNode(String name, Template template) { + return this.runNode(name, template, RunNodeOptions.NONE); + } + + @Override + public CreateNodeResponse runNode(String name, Template template, RunNodeOptions options) { + checkArgument(template.getImage() instanceof CloudServersImage, + "unexpected image type. should be CloudServersImage, was: " + + template.getImage().getClass()); + CloudServersImage cloudServersImage = CloudServersImage.class.cast(template.getImage()); + checkArgument(template.getSize() instanceof CloudServersSize, + "unexpected size type. should be CloudServersSize, was: " + + template.getSize().getClass()); + CloudServersSize cloudServersSize = CloudServersSize.class.cast(template.getSize()); + + logger.debug(">> running instance location(%s) image(%s) flavor(%s)", location, + cloudServersImage.getId(), template.getSize().getId()); + + Server server = client.createServer(name, cloudServersImage.getImage().getId(), + cloudServersSize.getFlavor().getId()); + + CreateNodeResponse node = new CreateNodeResponseImpl(server.getId() + "", name, location, + null, server.getMetadata(), NodeState.RUNNING, server.getAddresses() + .getPublicAddresses(), server.getAddresses().getPrivateAddresses(), + new Credentials("root", server.getAdminPass()), ImmutableMap. of()); + logger.debug("<< started instance(%s)", server.getId()); + serverActive.apply(server); + logger.debug("<< running instance(%s)", server.getId()); + if (options.getRunScript() != null) { + utils.runScriptOnNode(node, options.getRunScript()); + } + return node; + } + + @Override + public NodeMetadata getNodeMetadata(ComputeMetadata node) { + checkArgument(node.getType() == ComputeType.NODE, "this is only valid for nodes, not " + + node.getType()); + checkNotNull(node.getId(), "node.id"); + return serverToNodeMetadata.apply(client.getServer(Integer.parseInt(node.getId()))); + } + + @Singleton + private static class ServerToNodeMetadata implements Function { + private final String location; + + @SuppressWarnings("unused") + @Inject + ServerToNodeMetadata(@ResourceLocation String location) { + this.location = location; + } + + @Override + public NodeMetadata apply(Server from) { + return new NodeMetadataImpl(from.getId() + "", from.getName(), location, null, from + .getMetadata(), instanceToNodeState.get(from.getStatus()), from.getAddresses() + .getPublicAddresses(), from.getAddresses().getPrivateAddresses(), ImmutableMap + . of()); + } + } + + @Override + public Set listNodes() { + logger.debug(">> listing servers"); + Set servers = Sets.newHashSet(); + Iterables.addAll(servers, Iterables.transform(client.listServers(ListOptions.Builder + .withDetails()), serverToNodeMetadata)); + logger.debug("<< list(%d)", servers.size()); + return servers; + } + + @Override + public void destroyNode(ComputeMetadata node) { + checkArgument(node.getType() == ComputeType.NODE, "this is only valid for nodes, not " + + node.getType()); + checkNotNull(node.getId(), "node.id"); + + logger.debug(">> terminating instance(%s)", node.getId()); + boolean success = client.deleteServer(Integer.parseInt(node.getId())); + logger.debug("<< terminated instance(%s) success(%s)", node.getId(), success); + } + + @Override + public Set listSizes() { + return sizes.get(); + } + + @Override + public Set listImages() { + return images.get(); + } + + @Override + public TemplateBuilder templateBuilder() { + return templateBuilderProvider.get(); + } + +} \ No newline at end of file diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextBuilder.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextBuilder.java new file mode 100755 index 0000000000..a479cd8af6 --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextBuilder.java @@ -0,0 +1,81 @@ +/** + * + * Copyright (C) 2009 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; + +import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutorService; + +import org.jclouds.compute.ComputeServiceContextBuilder; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; +import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rackspace.cloudservers.compute.config.CloudServersComputeServiceContextModule; +import org.jclouds.rackspace.cloudservers.config.CloudServersRestClientModule; +import org.jclouds.rackspace.config.RackspaceAuthenticationRestModule; + +import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Creates {@link CloudServersComputeServiceContext} or {@link Injector} instances based on the most commonly + * requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see CloudServersComputeServiceContext + */ +public class CloudServersComputeServiceContextBuilder extends + ComputeServiceContextBuilder { + + public CloudServersComputeServiceContextBuilder(Properties props) { + super(new TypeLiteral() { + }, new TypeLiteral() { + }, props); + } + + @Override + public CloudServersComputeServiceContextBuilder withExecutorService(ExecutorService service) { + return (CloudServersComputeServiceContextBuilder) super.withExecutorService(service); + } + + @Override + public CloudServersComputeServiceContextBuilder withModules(Module... modules) { + return (CloudServersComputeServiceContextBuilder) super.withModules(modules); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new RackspaceAuthenticationRestModule()); + modules.add(new CloudServersComputeServiceContextModule()); + } + + @Override + protected void addClientModule(List modules) { + modules.add(new CloudServersRestClientModule()); + } + +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextFactory.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextFactory.java new file mode 100755 index 0000000000..02fe554260 --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceContextFactory.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2009 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; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rackspace.RackspacePropertiesBuilder; + +import com.google.inject.Module; + +/** + * Creates {@link CloudServersComputeServiceContext} instances based on the most commonly requested + * arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see CloudServersComputeServiceContext + */ +public class CloudServersComputeServiceContextFactory { + public static ComputeServiceContext createContext(Properties properties, Module... modules) { + return new CloudServersComputeServiceContextBuilder(new RackspacePropertiesBuilder(properties).build()) + .withModules(modules).buildComputeServiceContext(); + } + + public static ComputeServiceContext createContext(String user, + String password, Module... modules) { + return new CloudServersComputeServiceContextBuilder(new RackspacePropertiesBuilder(user, + password).build()).withModules(modules).buildComputeServiceContext(); + } + + public static ComputeServiceContext createContext(Properties properties, String user, + String password, Module... modules) { + return new CloudServersComputeServiceContextBuilder(new RackspacePropertiesBuilder(properties) + .withCredentials(user, password).build()).withModules(modules) + .buildComputeServiceContext(); + } + + public static ComputeServiceContext createContext(URI endpoint, String user, + String password, Module... modules) { + return new CloudServersComputeServiceContextBuilder(new RackspacePropertiesBuilder(user, + password).withEndpoint(endpoint).build()).withModules(modules) + .buildComputeServiceContext(); + } +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java new file mode 100755 index 0000000000..d7d2acab2f --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/config/CloudServersComputeServiceContextModule.java @@ -0,0 +1,137 @@ +/** + * + * Copyright (C) 2009 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.config; + +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeoutException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.annotation.Resource; +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.compute.domain.Architecture; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.OsFamily; +import org.jclouds.compute.domain.Size; +import org.jclouds.compute.internal.ComputeServiceContextImpl; +import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.domain.ResourceLocation; +import org.jclouds.logging.Logger; +import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; +import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rackspace.cloudservers.compute.CloudServersComputeService; +import org.jclouds.rackspace.cloudservers.compute.domain.CloudServersImage; +import org.jclouds.rackspace.cloudservers.compute.domain.CloudServersSize; +import org.jclouds.rackspace.cloudservers.config.CloudServersContextModule; +import org.jclouds.rackspace.cloudservers.domain.Flavor; +import org.jclouds.rackspace.cloudservers.options.ListOptions; +import org.jclouds.rest.RestContext; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; +import com.google.inject.Provides; + +/** + * Configures the {@link CloudServersComputeServiceContext}; requires + * {@link CloudServersComputeService} bound. + * + * @author Adrian Cole + */ +public class CloudServersComputeServiceContextModule extends CloudServersContextModule { + + @Override + protected void configure() { + super.configure(); + bind(ComputeService.class).to(CloudServersComputeService.class).asEagerSingleton(); + } + + @Provides + @Singleton + ComputeServiceContext provideContext(ComputeService computeService, + RestContext context) { + return new ComputeServiceContextImpl( + computeService, context); + } + + @Provides + @Singleton + @ResourceLocation + String getRegion() { + return "default"; + } + + @Provides + @Singleton + protected Set provideSizes(CloudServersClient sync, Set images, + LogHolder holder, ExecutorService executor) throws InterruptedException, + TimeoutException, ExecutionException { + final Set sizes = Sets.newHashSet(); + holder.logger.debug(">> providing sizes"); + for (final Flavor from : sync.listFlavors(ListOptions.Builder.withDetails())) { + sizes.add(new CloudServersSize(from, from.getId() + "", from.getDisk() / 10, + from .getRam(), from.getDisk(), ImmutableSet. of(Architecture.X86_32, + Architecture.X86_64))); + } + holder.logger.debug("<< sizes(%d)", sizes.size()); + return sizes; + } + + private static class LogHolder { + @Resource + @Named(ComputeServiceConstants.COMPUTE_LOGGER) + protected Logger logger = Logger.NULL; + } + + public static final Pattern RACKSPACE_PATTERN = Pattern.compile("(([^ ]*) .*)"); + + @Provides + @Singleton + protected Set provideImages(final CloudServersClient sync, + @ResourceLocation String location, LogHolder holder) throws InterruptedException, + ExecutionException, TimeoutException { + final Set images = Sets.newHashSet(); + holder.logger.debug(">> providing images"); + for (final org.jclouds.rackspace.cloudservers.domain.Image from : sync + .listImages(ListOptions.Builder.withDetails())) { + OsFamily os = null; + Architecture arch = Architecture.X86_64; + String osDescription = ""; + String version = ""; + + Matcher matcher = RACKSPACE_PATTERN.matcher(from.getName()); + if (matcher.find()) { + try { + os = OsFamily.fromValue(matcher.group(2).toLowerCase()); + osDescription = matcher.group(1); + } catch (IllegalArgumentException e) { + holder.logger.debug("<< didn't match os(%s)", matcher.group(2)); + } + } + images.add(new CloudServersImage(from, location, arch, os, osDescription, version)); + } + holder.logger.debug("<< images(%d)", images.size()); + return images; + } +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersImage.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersImage.java new file mode 100644 index 0000000000..f408312a40 --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersImage.java @@ -0,0 +1,154 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.domain; + +import org.jclouds.compute.domain.Architecture; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.OsFamily; + +/** + * + * @author Adrian Cole + */ +public class CloudServersImage implements Image { + private final org.jclouds.rackspace.cloudservers.domain.Image image; + private final String location; + private final Architecture architecture; + private final OsFamily os; + private final String osDescription; + private final String version; + + public CloudServersImage(org.jclouds.rackspace.cloudservers.domain.Image image, String location, + Architecture architecture, OsFamily os, String osDescription, String version) { + this.location = location; + this.architecture = architecture; + this.image = image; + this.os = os; + this.osDescription = osDescription; + this.version = version; + } + + @Override + public Architecture getArchitecture() { + return architecture; + } + + @Override + public String getDescription() { + return getImage().getName(); + } + + @Override + public String getId() { + return getImage().getId()+""; + } + + @Override + public String getLocation() { + return location; + } + + @Override + public OsFamily getOsFamily() { + return os; + } + + @Override + public String getOsDescription() { + return osDescription; + } + + @Override + public String getVersion() { + return version; + } + + public org.jclouds.rackspace.cloudservers.domain.Image getImage() { + return image; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((architecture == null) ? 0 : architecture.hashCode()); + result = prime * result + ((image == null) ? 0 : image.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((os == null) ? 0 : os.hashCode()); + result = prime * result + ((osDescription == null) ? 0 : osDescription.hashCode()); + result = prime * result + ((version == null) ? 0 : version.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CloudServersImage other = (CloudServersImage) obj; + if (architecture == null) { + if (other.architecture != null) + return false; + } else if (!architecture.equals(other.architecture)) + return false; + if (image == null) { + if (other.image != null) + return false; + } else if (!image.equals(other.image)) + return false; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + return false; + if (os == null) { + if (other.os != null) + return false; + } else if (!os.equals(other.os)) + return false; + if (osDescription == null) { + if (other.osDescription != null) + return false; + } else if (!osDescription.equals(other.osDescription)) + return false; + if (version == null) { + if (other.version != null) + return false; + } else if (!version.equals(other.version)) + return false; + return true; + } + + @Override + public String toString() { + return "[id=" + getId() + ", version=" + version + ", location=" + getLocation() + + ", architecture=" + getArchitecture() + ", operatingSystem=" + + getOsFamily() + ", operatingSystemVersion=" + getOsDescription() + + ", description=" + getDescription() + "]"; + } + +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersSize.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersSize.java new file mode 100644 index 0000000000..0bcc180b54 --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/compute/domain/CloudServersSize.java @@ -0,0 +1,72 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.domain; + +import org.jclouds.compute.domain.Architecture; +import org.jclouds.compute.domain.internal.SizeImpl; +import org.jclouds.rackspace.cloudservers.domain.Flavor; + +/** + * + * @author Adrian Cole + */ +public class CloudServersSize extends SizeImpl { + private final Flavor flavor; + + public CloudServersSize(Flavor flavor, String id, int cores, int ram, int disk, + Iterable supportedArchitectures) { + super(id, cores, ram, disk, supportedArchitectures); + this.flavor = flavor; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = super.hashCode(); + result = prime * result + ((flavor == null) ? 0 : flavor.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (!super.equals(obj)) + return false; + if (getClass() != obj.getClass()) + return false; + CloudServersSize other = (CloudServersSize) obj; + if (flavor == null) { + if (other.flavor != null) + return false; + } else if (!flavor.equals(other.flavor)) + return false; + return true; + } + + public Flavor getFlavor() { + return flavor; + } + +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/config/CloudServersContextModule.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/config/CloudServersContextModule.java index 7551d1ddc2..a1402db998 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/config/CloudServersContextModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/config/CloudServersContextModule.java @@ -18,20 +18,27 @@ */ package org.jclouds.rackspace.cloudservers.config; +import java.net.InetSocketAddress; import java.net.URI; +import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.http.RequiresHttp; import org.jclouds.lifecycle.Closer; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.predicates.SocketOpen; import org.jclouds.rackspace.CloudServers; import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rackspace.cloudservers.domain.Server; +import org.jclouds.rackspace.cloudservers.predicates.ServerActive; import org.jclouds.rackspace.reference.RackspaceConstants; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; +import com.google.common.base.Predicate; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -42,6 +49,18 @@ public class CloudServersContextModule extends AbstractModule { protected void configure() { } + @Provides + @Singleton + protected Predicate instanceStateRunning(ServerActive stateRunning) { + return new RetryablePredicate(stateRunning, 600, 2, TimeUnit.SECONDS); + } + + @Provides + @Singleton + protected Predicate socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 1, TimeUnit.SECONDS); + } + @Provides @Singleton RestContext provideContext(Closer closer, diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponse.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponse.java index cec0e23890..5f00dcd3f5 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponse.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/functions/ParseInetAddressListFromJsonResponse.java @@ -49,11 +49,11 @@ public class ParseInetAddressListFromJsonResponse extends ParseJson> addressMap; public List apply(InputStream stream) { - Type type = new TypeToken>>() { + Type flavor = new TypeToken>>() { }.getType(); try { Map> map = gson.fromJson(new InputStreamReader(stream, "UTF-8"), - type); + flavor); return map.values().iterator().next(); } catch (UnsupportedEncodingException e) { throw new RuntimeException("jclouds requires UTF-8 encoding", e); diff --git a/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/predicates/ServerActive.java b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/predicates/ServerActive.java new file mode 100644 index 0000000000..4b586be5f2 --- /dev/null +++ b/rackspace/src/main/java/org/jclouds/rackspace/cloudservers/predicates/ServerActive.java @@ -0,0 +1,49 @@ +package org.jclouds.rackspace.cloudservers.predicates; + +import javax.annotation.Resource; +import javax.inject.Singleton; + +import org.jclouds.logging.Logger; +import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rackspace.cloudservers.domain.Server; +import org.jclouds.rackspace.cloudservers.domain.ServerStatus; +import org.jclouds.rest.ResourceNotFoundException; + +import com.google.common.base.Predicate; +import com.google.inject.Inject; + +/** + * + * Tests to see if a task succeeds. + * + * @author Adrian Cole + */ +@Singleton +public class ServerActive implements Predicate { + + private final CloudServersClient client; + + @Resource + protected Logger logger = Logger.NULL; + + @Inject + public ServerActive(CloudServersClient client) { + this.client = client; + } + + public boolean apply(Server server) { + logger.trace("looking for state on server %s", server); + try { + server = refresh(server); + logger.trace("%s: looking for server state %s: currently: %s", server.getId(), + ServerStatus.ACTIVE, server.getStatus()); + return server.getStatus() == ServerStatus.ACTIVE; + } catch (ResourceNotFoundException e) { + return false; + } + } + + private Server refresh(Server server) { + return client.getServer(server.getId()); + } +} diff --git a/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationRestModule.java b/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationRestModule.java index 02bdb60c68..10a53fb49b 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationRestModule.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/config/RackspaceAuthenticationRestModule.java @@ -23,6 +23,7 @@ import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSP import static org.jclouds.rackspace.reference.RackspaceConstants.PROPERTY_RACKSPACE_USER; import java.net.URI; +import java.util.Date; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -30,6 +31,8 @@ import java.util.concurrent.TimeoutException; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.concurrent.ExpirableSupplier; +import org.jclouds.date.TimeStamp; import org.jclouds.http.RequiresHttp; import org.jclouds.rackspace.Authentication; import org.jclouds.rackspace.CloudFiles; @@ -39,6 +42,8 @@ import org.jclouds.rackspace.RackspaceAuthentication; import org.jclouds.rackspace.RackspaceAuthentication.AuthenticationResponse; import org.jclouds.rest.RestClientFactory; +import com.google.common.base.Supplier; +import com.google.common.base.Throwables; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -54,6 +59,39 @@ public class RackspaceAuthenticationRestModule extends AbstractModule { protected void configure() { } + /** + * borrowing concurrency code to ensure that caching takes place properly + */ + @Provides + @Singleton + @Authentication + Supplier provideAuthenticationTokenCache(final RestClientFactory factory, + @Named(PROPERTY_RACKSPACE_USER) final String user, + @Named(PROPERTY_RACKSPACE_KEY) final String key) { + return new ExpirableSupplier(new Supplier() { + public String get() { + try { + return factory.create(RackspaceAuthentication.class).authenticate(user, key).get(30, + TimeUnit.SECONDS).getAuthToken(); + } catch (Exception e) { + Throwables.propagateIfPossible(e); + throw new RuntimeException("Error logging in", e); + } + } + }, 23, TimeUnit.HOURS); + } + + @Provides + @Singleton + @TimeStamp + Supplier provideCacheBusterDate() { + return new ExpirableSupplier(new Supplier() { + public Date get() { + return new Date(); + } + }, 1, TimeUnit.SECONDS); + } + @Provides @Singleton @Authentication @@ -70,15 +108,6 @@ public class RackspaceAuthenticationRestModule extends AbstractModule { TimeUnit.SECONDS); } - @Provides - @Authentication - protected String provideAuthenticationToken(RestClientFactory factory, - @Named(PROPERTY_RACKSPACE_USER) String user, @Named(PROPERTY_RACKSPACE_KEY) String key) - throws InterruptedException, ExecutionException, TimeoutException { - return factory.create(RackspaceAuthentication.class).authenticate(user, key).get(30, - TimeUnit.SECONDS).getAuthToken(); - } - @Provides @Singleton @CloudFiles diff --git a/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java b/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java index 03bc6bd09c..beaf0ae384 100644 --- a/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/filters/AddTimestampQuery.java @@ -21,14 +21,16 @@ package org.jclouds.rackspace.filters; import java.util.Date; import javax.inject.Inject; -import javax.inject.Provider; import javax.inject.Singleton; +import org.jclouds.date.TimeStamp; import org.jclouds.http.HttpException; import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequestFilter; import org.jclouds.rest.internal.GeneratedHttpRequest; +import com.google.common.base.Supplier; + /** * Adds a timestamp to the query line so that cache is invalidated. * @@ -37,10 +39,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest; */ @Singleton public class AddTimestampQuery implements HttpRequestFilter { - private final Provider dateProvider; + private final Supplier dateProvider; @Inject - public AddTimestampQuery(Provider dateProvider) { + public AddTimestampQuery(@TimeStamp Supplier dateProvider) { this.dateProvider = dateProvider; } diff --git a/rackspace/src/main/java/org/jclouds/rackspace/filters/AuthenticateRequest.java b/rackspace/src/main/java/org/jclouds/rackspace/filters/AuthenticateRequest.java index 49011be581..7df3a32dc1 100755 --- a/rackspace/src/main/java/org/jclouds/rackspace/filters/AuthenticateRequest.java +++ b/rackspace/src/main/java/org/jclouds/rackspace/filters/AuthenticateRequest.java @@ -19,11 +19,8 @@ package org.jclouds.rackspace.filters; import java.util.Collections; -import java.util.concurrent.atomic.AtomicLong; -import java.util.concurrent.atomic.AtomicReference; import javax.inject.Inject; -import javax.inject.Provider; import javax.inject.Singleton; import org.jclouds.http.HttpException; @@ -32,6 +29,8 @@ import org.jclouds.http.HttpRequestFilter; import org.jclouds.rackspace.Authentication; import org.jclouds.rackspace.reference.RackspaceHeaders; +import com.google.common.base.Supplier; + /** * Signs the Rackspace request. This will update the Authentication Token before 24 hours is up. * @@ -41,51 +40,16 @@ import org.jclouds.rackspace.reference.RackspaceHeaders; @Singleton public class AuthenticateRequest implements HttpRequestFilter { - private final Provider authTokenProvider; - - public final long BILLION = 1000000000; - public final long MINUTES = 60 * BILLION; - public final long HOURS = 60 * MINUTES; - - private final AtomicReference authToken; - private final AtomicLong trigger = new AtomicLong(0); - - /** - * Start the time update service. Rackspace clocks need to be 24 hours of the auth token. This is - * not performed per-request, as creation of the token is a slow, synchronized command. - */ - synchronized void updateIfTimeOut() { - - if (trigger.get() - System.nanoTime() <= 0) { - createNewToken(); - } - - } - - // this is a hotspot when submitted concurrently, so be lazy. - // rackspace is ok with up to 23:59 off their time, so let's - // be as lazy as possible. - public String createNewToken() { - authToken.set(authTokenProvider.get()); - trigger.set(System.nanoTime() + System.nanoTime() + 23 * HOURS); - return authToken.get(); - - } - - public String getAuthToken() { - updateIfTimeOut(); - return authToken.get(); - } + private final Supplier authTokenProvider; @Inject - public AuthenticateRequest(@Authentication Provider authTokenProvider) { + public AuthenticateRequest(@Authentication Supplier authTokenProvider) { this.authTokenProvider = authTokenProvider; - authToken = new AtomicReference(); } public void filter(HttpRequest request) throws HttpException { request.getHeaders().replaceValues(RackspaceHeaders.AUTH_TOKEN, - Collections.singletonList(getAuthToken())); + Collections.singletonList(authTokenProvider.get())); } } \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java index 08dcc048f6..5ca36e28f3 100755 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/CloudServersClientTest.java @@ -18,7 +18,6 @@ */ package org.jclouds.rackspace.cloudservers; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withFile; import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withMetadata; import static org.jclouds.rackspace.cloudservers.options.CreateServerOptions.Builder.withSharedIpGroup; @@ -41,6 +40,7 @@ import javax.ws.rs.core.HttpHeaders; import javax.ws.rs.core.MediaType; import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.date.TimeStamp; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.functions.ReturnTrueIf2xx; @@ -74,7 +74,9 @@ import org.jclouds.rest.internal.RestAnnotationProcessor; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.base.Supplier; import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.Executors; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -917,7 +919,7 @@ public class CloudServersClientTest { + "")); assertEquals(httpMethod.getHeaders().get(HttpHeaders.CONTENT_TYPE), Collections .singletonList(MediaType.APPLICATION_JSON)); - assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", httpMethod.getPayload().getRawContent()); + assertEquals("{\"reboot\":{\"flavor\":\"HARD\"}}", httpMethod.getPayload().getRawContent()); assertEquals(processor .createExceptionParserOrThrowResourceNotFoundOn404IfNoAnnotation(method).getClass(), ReturnFalseOn404.class); @@ -1007,10 +1009,25 @@ public class CloudServersClientTest { @SuppressWarnings("unused") @Provides @Authentication - public String getAuthToken() { - return "testtoken"; + public Supplier getAuthToken() { + return new Supplier() { + public String get() { + return "testtoken"; + } + }; } - }, new RestModule(), new ExecutorServiceModule(sameThreadExecutor()), + + @SuppressWarnings("unused") + @Provides + @TimeStamp + public Supplier getDate() { + return new Supplier() { + public Date get() { + return new Date(); + } + }; + } + }, new RestModule(), new ExecutorServiceModule(Executors.sameThreadExecutor()), new JavaUrlHttpCommandExecutorServiceModule()); processor = injector.getInstance(Key .get(new TypeLiteral>() { diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayloadTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayloadTest.java index bc934544ba..593c74a412 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayloadTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/binders/BindRebootTypeToJsonPayloadTest.java @@ -66,7 +66,7 @@ public class BindRebootTypeToJsonPayloadTest { injector.injectMembers(binder); HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); binder.bindToRequest(request, RebootType.HARD); - assertEquals("{\"reboot\":{\"type\":\"HARD\"}}", request.getPayload().getRawContent()); + assertEquals("{\"reboot\":{\"flavor\":\"HARD\"}}", request.getPayload().getRawContent()); } @Test @@ -75,7 +75,7 @@ public class BindRebootTypeToJsonPayloadTest { injector.injectMembers(binder); HttpRequest request = new HttpRequest(HttpMethod.POST, URI.create("http://localhost")); binder.bindToRequest(request, RebootType.SOFT); - assertEquals("{\"reboot\":{\"type\":\"SOFT\"}}", request.getPayload().getRawContent()); + assertEquals("{\"reboot\":{\"flavor\":\"SOFT\"}}", request.getPayload().getRawContent()); } @Test(expectedExceptions = { NullPointerException.class, IllegalStateException.class }) 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 new file mode 100644 index 0000000000..6172856b97 --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/CloudServersComputeServiceLiveTest.java @@ -0,0 +1,66 @@ +/** + * + * Copyright (C) 2009 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; + +import static org.jclouds.compute.domain.OsFamily.UBUNTU; + +import org.jclouds.compute.BaseComputeServiceLiveTest; +import org.jclouds.compute.ComputeServiceContextFactory; +import org.jclouds.compute.domain.Template; +import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.rackspace.cloudservers.CloudServersAsyncClient; +import org.jclouds.rackspace.cloudservers.CloudServersClient; +import org.jclouds.rest.RestContext; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * Generally disabled, as it incurs higher fees. + * + * @author Adrian Cole + */ +@Test(groups = "live", enabled = true, sequential = true, testName = "cloudservers.CloudServersComputeServiceLiveTest") +public class CloudServersComputeServiceLiveTest extends BaseComputeServiceLiveTest { + + @BeforeClass + @Override + public void setServiceDefaults() { + service = "cloudservers"; + } + + protected Template buildTemplate(TemplateBuilder templateBuilder) { + return templateBuilder.osFamily(UBUNTU).osDescriptionMatches(".*9.10.*").smallest().build(); + } + + @Override + protected JschSshClientModule getSshModule() { + return new JschSshClientModule(); + } + + public void testAssignability() throws Exception { + @SuppressWarnings("unused") + RestContext tmContext = new ComputeServiceContextFactory() + .createContext(service, user, password).getProviderSpecificContext(); + + CloudServersComputeService.class.cast(client); + } +} \ No newline at end of file diff --git a/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/PropertiesTest.java b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/PropertiesTest.java new file mode 100644 index 0000000000..e3b7404e8a --- /dev/null +++ b/rackspace/src/test/java/org/jclouds/rackspace/cloudservers/compute/PropertiesTest.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2009 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; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.util.Properties; + +import org.jclouds.rackspace.RackspacePropertiesBuilder; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.common.io.Resources; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "compute.PropertiesTest") +public class PropertiesTest { + private Properties properties; + + @BeforeTest + public void setUp() throws IOException { + properties = new Properties(); + properties.load(Resources.newInputStreamSupplier(Resources.getResource("compute.properties")) + .getInput()); + } + + public void testRackspace() { + assertEquals(properties.getProperty("cloudservers.contextbuilder"), + CloudServersComputeServiceContextBuilder.class.getName()); + assertEquals(properties.getProperty("cloudservers.propertiesbuilder"), + RackspacePropertiesBuilder.class.getName()); + } + +} diff --git a/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java b/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java index 6c75925a48..ceb6449618 100644 --- a/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java +++ b/rackspace/src/test/java/org/jclouds/rackspace/filters/AddTimestampQueryTest.java @@ -23,11 +23,11 @@ import static org.easymock.classextension.EasyMock.replay; import java.util.Date; -import javax.inject.Provider; - import org.jclouds.rest.internal.GeneratedHttpRequest; import org.testng.annotations.Test; +import com.google.common.base.Supplier; + /** * * @author Adrian Cole @@ -39,7 +39,7 @@ public class AddTimestampQueryTest { @Test public void testApplySetsKey() { final Date date = new Date(); - Provider dateProvider = new Provider() { + Supplier dateSupplier = new Supplier() { @Override public Date get() { @@ -51,7 +51,7 @@ public class AddTimestampQueryTest { request.addQueryParam("now", date.getTime() + ""); replay(request); - AddTimestampQuery filter = new AddTimestampQuery(dateProvider); + AddTimestampQuery filter = new AddTimestampQuery(dateSupplier); filter.filter(request); } diff --git a/rackspace/src/test/resources/log4j.xml b/rackspace/src/test/resources/log4j.xml index 8178a9f5dc..7946a5c3cc 100755 --- a/rackspace/src/test/resources/log4j.xml +++ b/rackspace/src/test/resources/log4j.xml @@ -1,32 +1,31 @@ - + 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. + ==================================================================== + --> - + + debug="false"> @@ -43,52 +42,76 @@ - - - - + + + + - - + + - + - - - + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + - - + + + + + + - - + + @@ -97,13 +120,17 @@ - - - - - - - + + + + + + + + + + + \ No newline at end of file diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeService.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeService.java index 59af5a594f..b46c06af35 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeService.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeService.java @@ -37,10 +37,9 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.CreateNodeResponse; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.LoginType; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; @@ -77,9 +76,8 @@ public class RimuHostingComputeService implements ComputeService { this.rhClient = rhClient; } - private Map imageNameMap = ImmutableMap - . builder().put(OperatingSystem.CENTOS, "centos53").put( - OperatingSystem.UBUNTU, "ubuntu904").build(); + private Map imageNameMap = ImmutableMap. builder().put( + OsFamily.CENTOS, "centos53").put(OsFamily.UBUNTU, "ubuntu904").build(); // private Map profileNameMap = ImmutableMap. builder().put( // Profile.SMALLEST, "MIRO1B").build(); @@ -92,15 +90,15 @@ public class RimuHostingComputeService implements ComputeService { @Override public CreateNodeResponse runNode(String name, Template template, RunNodeOptions options) { NewServerResponse serverResponse = rhClient.createServer(name, checkNotNull(imageNameMap - .get(template.getImage().getOperatingSystem()), "os not supported: " - + template.getImage().getOperatingSystem()), "MIRO1B"); + .get(template.getImage().getOsFamily()), "os not supported: " + + template.getImage().getOsFamily()), "MIRO1B"); return new CreateNodeResponseImpl(serverResponse.getServer().getId().toString(), serverResponse.getServer().getName(), "default", null, ImmutableMap . of(), NodeState.RUNNING,// TODO need a real state! getPublicAddresses(serverResponse.getServer()), ImmutableList. of(), - 22, LoginType.SSH, new Credentials("root", serverResponse.getNewInstanceRequest() - .getCreateOptions().getPassword()), ImmutableMap. of()); + new Credentials("root", serverResponse.getNewInstanceRequest().getCreateOptions() + .getPassword()), ImmutableMap. of()); } @VisibleForTesting diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java index 7995f849ec..1c171e05f7 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/compute/RimuHostingComputeServiceLiveTest.java @@ -18,7 +18,7 @@ */ package org.jclouds.rimuhosting.miro.compute; -import static org.jclouds.compute.domain.OperatingSystem.JEOS; +import static org.jclouds.compute.domain.OsFamily.JEOS; import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.domain.Template; @@ -39,7 +39,7 @@ public class RimuHostingComputeServiceLiveTest extends BaseComputeServiceLiveTes } protected Template buildTemplate(TemplateBuilder templateBuilder) { - return templateBuilder.os(JEOS).osVersionMatches(".*9.04.*").smallest().build(); + return templateBuilder.osFamily(JEOS).osDescriptionMatches(".*9.04.*").smallest().build(); } @Override diff --git a/tools/antcontrib/samples/cargooverssh/build.xml b/tools/antcontrib/samples/cargooverssh/build.xml index f54f87a21a..21d83efefd 100644 --- a/tools/antcontrib/samples/cargooverssh/build.xml +++ b/tools/antcontrib/samples/cargooverssh/build.xml @@ -46,7 +46,7 @@ - + @@ -57,7 +57,7 @@ - + diff --git a/tools/antcontrib/samples/compute/build.xml b/tools/antcontrib/samples/compute/build.xml index 25e0db1f9a..b9cdf78a91 100644 --- a/tools/antcontrib/samples/compute/build.xml +++ b/tools/antcontrib/samples/compute/build.xml @@ -34,6 +34,7 @@ + diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java index c23e316e7e..764bfcb401 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTask.java @@ -163,10 +163,9 @@ public class ComputeTask extends Task { } private void logNodeDetails(CreateNodeResponse createdNode) { - log(String.format(" id=%s, name=%s, connection=%s://%s:%s@%s:%d", createdNode.getId(), - createdNode.getName(), createdNode.getLoginType().toString().toLowerCase(), - createdNode.getCredentials().account, createdNode.getCredentials().key, createdNode - .getPublicAddresses().first().getHostAddress(), createdNode.getLoginPort())); + log(String.format(" id=%s, name=%s, connection=%s:%s@%s", createdNode.getId(), createdNode + .getName(), createdNode.getCredentials().account, createdNode.getCredentials().key, + createdNode.getPublicAddresses().first().getHostAddress())); } private void addNodeDetailsAsProjectProperties(CreateNodeResponse createdNode) { diff --git a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java index 9403372758..6c5aa42295 100644 --- a/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java +++ b/tools/antcontrib/src/main/java/org/jclouds/tools/ant/taskdefs/compute/ComputeTaskUtils.java @@ -35,7 +35,7 @@ import org.apache.tools.ant.Project; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.ComputeServiceContextFactory; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.RunNodeOptions; @@ -94,7 +94,7 @@ public class ComputeTaskUtils { TemplateBuilder templateBuilder = computeService.templateBuilder(); if (nodeElement.getLocation() != null && !"".equals(nodeElement.getLocation())) templateBuilder.location(nodeElement.getLocation()); - templateBuilder.os(OperatingSystem.valueOf(nodeElement.getOs())); + templateBuilder.osFamily(OsFamily.valueOf(nodeElement.getOs())); addSizeFromElementToTemplate(nodeElement, templateBuilder); return templateBuilder.build(); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java index 8bd362d51c..55e6e7acf0 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/VCloudComputeService.java @@ -23,9 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.processorCount; -import java.io.ByteArrayInputStream; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.util.Map; import java.util.Set; @@ -39,7 +37,6 @@ import org.jclouds.compute.domain.ComputeMetadata; import org.jclouds.compute.domain.ComputeType; import org.jclouds.compute.domain.CreateNodeResponse; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.LoginType; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.Size; @@ -49,9 +46,9 @@ import org.jclouds.compute.domain.internal.CreateNodeResponseImpl; import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.options.RunNodeOptions; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeUtils; import org.jclouds.domain.Credentials; import org.jclouds.logging.Logger; -import org.jclouds.ssh.SshClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.NamedResource; @@ -78,10 +75,8 @@ public class VCloudComputeService implements ComputeService, VCloudComputeClient protected final Provider> images; protected final Provider> sizes; protected final Provider templateBuilderProvider; - private final Predicate taskTester; - @Inject(optional = true) - private SshClient.Factory sshFactory; - private Predicate socketTester; + protected final ComputeUtils utils; + protected final Predicate taskTester; protected static final Map vAppStatusToNodeState = ImmutableMap . builder().put(VAppStatus.OFF, NodeState.TERMINATED).put( @@ -93,13 +88,13 @@ public class VCloudComputeService implements ComputeService, VCloudComputeClient public VCloudComputeService(VCloudClient client, Provider templateBuilderProvider, Provider> images, Provider> sizes, - Predicate successTester, Predicate socketTester) { + ComputeUtils utils, Predicate successTester) { this.taskTester = successTester; this.client = client; this.images = images; this.sizes = sizes; this.templateBuilderProvider = templateBuilderProvider; - this.socketTester = socketTester; + this.utils = utils; } @Override @@ -117,54 +112,18 @@ public class VCloudComputeService implements ComputeService, VCloudComputeClient VApp vApp = client.getVApp(metaMap.get("id")); CreateNodeResponse node = newCreateNodeResponse(template, metaMap, vApp); if (options.getRunScript() != null) { - checkState(this.sshFactory != null, "runScript requested, but no SshModule configured"); - runScriptOnNode(node, options.getRunScript()); + utils.runScriptOnNode(node, options.getRunScript()); } return node; } - private void runScriptOnNode(CreateNodeResponse node, byte[] script) { - InetSocketAddress socket = new InetSocketAddress(node.getPublicAddresses().last(), node - .getLoginPort()); - socketTester.apply(socket); - SshClient ssh = isKeyBasedAuth(node) ? sshFactory.create(socket, - node.getCredentials().account, node.getCredentials().key.getBytes()) : sshFactory - .create(socket, node.getCredentials().account, node.getCredentials().key); - try { - ssh.connect(); - String scriptName = node.getId() + ".sh"; - ssh.put(scriptName, new ByteArrayInputStream(script)); - ssh.exec("chmod 755 " + scriptName); - if (node.getCredentials().account.equals("root")) { - logger.debug(">> running %s as %s", scriptName, node.getCredentials().account); - logger.debug("<< complete(%d)", ssh.exec("./" + scriptName).getExitCode()); - } else if (isKeyBasedAuth(node)) { - logger.debug(">> running sudo %s as %s", scriptName, node.getCredentials().account); - logger.debug("<< complete(%d)", ssh.exec("sudo ./" + scriptName).getExitCode()); - } else { - logger.debug(">> running sudo -S %s as %s", scriptName, node.getCredentials().account); - logger.debug("<< complete(%d)", ssh.exec( - String.format("echo %s|sudo -S ./%s", node.getCredentials().key, scriptName)) - .getExitCode()); - } - } finally { - if (ssh != null) - ssh.disconnect(); - } - } - - private boolean isKeyBasedAuth(CreateNodeResponse node) { - return node.getCredentials().key.startsWith("-----BEGIN RSA PRIVATE KEY-----"); - } - protected CreateNodeResponse newCreateNodeResponse(Template template, Map metaMap, VApp vApp) { return new CreateNodeResponseImpl(vApp.getId(), vApp.getName(), template.getImage() .getLocation(), vApp.getLocation(), ImmutableMap. of(), vAppStatusToNodeState.get(vApp.getStatus()), getPublicAddresses(vApp.getId()), - getPrivateAddresses(vApp.getId()), 22, LoginType.SSH, new Credentials(metaMap - .get("username"), metaMap.get("password")), ImmutableMap - . of()); + getPrivateAddresses(vApp.getId()), new Credentials(metaMap.get("username"), metaMap + .get("password")), ImmutableMap. of()); } @Override @@ -175,12 +134,12 @@ public class VCloudComputeService implements ComputeService, VCloudComputeClient node.getId(), "node.id")); } - private NodeMetadata getNodeMetadataByIdInVDC(String vDCId, String id) { + protected NodeMetadata getNodeMetadataByIdInVDC(String vDCId, String id) { VApp vApp = client.getVApp(id); return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vDCId, vApp.getLocation(), ImmutableMap. of(), vAppStatusToNodeState.get(vApp.getStatus()), - vApp.getNetworkToAddresses().values(), ImmutableSet. of(), 22, - LoginType.SSH, ImmutableMap. of()); + vApp.getNetworkToAddresses().values(), ImmutableSet. of(), ImmutableMap + . of()); } @Override diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java index 45e1fd271d..694027ab23 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java @@ -33,7 +33,7 @@ import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceContext; import org.jclouds.compute.domain.Architecture; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.internal.ImageImpl; import org.jclouds.compute.domain.internal.SizeImpl; @@ -120,8 +120,8 @@ public class VCloudComputeServiceContextModule extends VCloudContextModule { responses.add(executor.submit(new Callable() { @Override public Void call() throws Exception { - OperatingSystem myOs = null; - for (OperatingSystem os : OperatingSystem.values()) { + OsFamily myOs = null; + for (OsFamily os : OsFamily.values()) { if (resource.getName().toLowerCase().replaceAll("\\s", "").indexOf( os.toString()) != -1) { myOs = os; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java index 81ab2afcb2..acda3746c9 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/compute/VCloudComputeClientLiveTest.java @@ -28,7 +28,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.VCloudClient; @@ -73,14 +73,14 @@ public class VCloudComputeClientLiveTest { } } - protected Map expectationMap; + protected Map expectationMap; protected Predicate addressTester; @Test(enabled = true) public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, IOException { - OperatingSystem toTest = OperatingSystem.CENTOS; + OsFamily toTest = OsFamily.CENTOS; String serverName = getCompatibleServerName(toTest); int processorCount = 1; @@ -98,7 +98,7 @@ public class VCloudComputeClientLiveTest { assertEquals(vApp.getStatus(), VAppStatus.ON); } - private String getCompatibleServerName(OperatingSystem toTest) { + private String getCompatibleServerName(OsFamily toTest) { String serverName = CaseFormat.UPPER_UNDERSCORE .to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, toTest.toString().length() <= 15 ? toTest.toString().length() : 14); @@ -149,8 +149,8 @@ public class VCloudComputeClientLiveTest { client = injector.getInstance(VCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { })); - expectationMap = ImmutableMap. builder().put( - OperatingSystem.CENTOS, + expectationMap = ImmutableMap. builder().put( + OsFamily.CENTOS, new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); service = "vcloudtest"; templateId = "3"; diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java index 341669f76b..f2e07be352 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java @@ -2,7 +2,6 @@ package org.jclouds.vcloud.hostingdotcom.compute; import static com.google.common.base.Preconditions.checkState; -import java.net.InetSocketAddress; import java.util.Map; import java.util.Set; @@ -13,6 +12,7 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.util.ComputeUtils; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.compute.VCloudComputeService; import org.jclouds.vcloud.domain.VApp; @@ -31,8 +31,8 @@ public class HostingDotComVCloudComputeService extends VCloudComputeService { HostingDotComVCloudComputeService(VCloudClient client, Provider templateBuilderProvider, Provider> images, Provider> sizes, - Predicate successTester, Predicate socketTester) { - super(client, templateBuilderProvider, images, sizes, successTester, socketTester); + Predicate successTester, ComputeUtils utils) { + super(client, templateBuilderProvider, images, sizes, utils, successTester); } @Override diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java index 3d766ec4f0..7911b8efba 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java @@ -22,7 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.InetAddress; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.compute.VCloudComputeClientLiveTest; @@ -57,8 +57,8 @@ public class HostingDotComVCloudComputeClientLiveTest extends VCloudComputeClien client = injector.getInstance(HostingDotComVCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { })); - expectationMap = ImmutableMap. builder().put( - OperatingSystem.CENTOS, + expectationMap = ImmutableMap. builder().put( + OsFamily.CENTOS, new Expectation(4194304 / 2 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).build(); service = "vcloudtest"; templateId = "3"; diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java index 3c2c1ea73f..2f26b8fa96 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeServiceLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.hostingdotcom.compute; -import static org.jclouds.compute.domain.OperatingSystem.CENTOS; +import static org.jclouds.compute.domain.OsFamily.CENTOS; import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.domain.Template; @@ -42,7 +42,7 @@ public class HostingDotComVCloudComputeServiceLiveTest extends BaseComputeServic } protected Template buildTemplate(TemplateBuilder templateBuilder) { - return templateBuilder.os(CENTOS).smallest().build(); + return templateBuilder.osFamily(CENTOS).smallest().build(); } @Override diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index bbaa4af91c..4820457db3 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -31,7 +31,7 @@ import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.logging.Logger; import org.jclouds.vcloud.domain.Task; @@ -68,13 +68,13 @@ public class TerremarkVCloudComputeClient { this.taskTester = successTester; } - private Map imageCatalogIdMap = ImmutableMap - . builder().put(OperatingSystem.CENTOS, "6").put( - OperatingSystem.RHEL, "8").put(OperatingSystem.UBUNTU, "10").build(); + private Map imageCatalogIdMap = ImmutableMap + . builder().put(OsFamily.CENTOS, "6").put( + OsFamily.RHEL, "8").put(OsFamily.UBUNTU, "10").build(); // .put( OperatingSystem.UBUNTU_JEOS_90, "11").put(OperatingSystem.WEBAPPVM_93, "29") - public String start(String name, OperatingSystem image, int minCores, int minMegs, + public String start(String name, OsFamily image, int minCores, int minMegs, Map properties) { checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); return start(name, imageCatalogIdMap.get(image), minCores, minMegs, properties); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java index e7ebfac5db..6fc56120fd 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java @@ -21,7 +21,6 @@ package org.jclouds.vcloud.terremark.compute; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.util.Map; import java.util.Set; import java.util.SortedSet; @@ -33,9 +32,12 @@ import javax.inject.Provider; import javax.inject.Singleton; import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Size; import org.jclouds.compute.domain.TemplateBuilder; +import org.jclouds.compute.domain.internal.NodeMetadataImpl; import org.jclouds.compute.reference.ComputeServiceConstants; +import org.jclouds.compute.util.ComputeUtils; import org.jclouds.logging.Logger; import org.jclouds.vcloud.compute.VCloudComputeService; import org.jclouds.vcloud.domain.VApp; @@ -64,8 +66,8 @@ public class TerremarkVCloudComputeService extends VCloudComputeService { public TerremarkVCloudComputeService(TerremarkVCloudClient client, Provider templateBuilderProvider, Provider> images, Provider> sizes, - Predicate successTester, Predicate socketTester) { - super(client, templateBuilderProvider, images, sizes, successTester, socketTester); + Predicate successTester, ComputeUtils utils) { + super(client, templateBuilderProvider, images, sizes, utils, successTester); this.client = client; } @@ -85,6 +87,15 @@ public class TerremarkVCloudComputeService extends VCloudComputeService { return response; } + @Override + protected NodeMetadata getNodeMetadataByIdInVDC(String vDCId, String id) { + VApp vApp = client.getVApp(id); + return new NodeMetadataImpl(vApp.getId(), vApp.getName(), vDCId, vApp.getLocation(), + ImmutableMap. of(), vAppStatusToNodeState.get(vApp.getStatus()), + getPublicAddresses(id), vApp.getNetworkToAddresses().values(), ImmutableMap + . of()); + } + public InetAddress createPublicAddressMappedToPorts(String vAppId, int... ports) { VApp vApp = client.getVApp(vAppId); PublicIpAddress ip = null; diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java index 4f3369f43b..453d1eacba 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java @@ -27,7 +27,7 @@ import java.util.Map; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeoutException; -import org.jclouds.compute.domain.OperatingSystem; +import org.jclouds.compute.domain.OsFamily; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.vcloud.domain.ResourceType; @@ -73,12 +73,12 @@ public class TerremarkVCloudComputeClientLiveTest { } } - private Map expectationMap = ImmutableMap - . builder().put(OperatingSystem.CENTOS, + private Map expectationMap = ImmutableMap + . builder().put(OsFamily.CENTOS, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)")).put( - OperatingSystem.RHEL, + OsFamily.RHEL, new Expectation(10485760, "Red Hat Enterprise Linux 5 (64-bit)")).put( - OperatingSystem.UBUNTU, new Expectation(4194304, "Ubuntu Linux (64-bit)")) + OsFamily.UBUNTU, new Expectation(4194304, "Ubuntu Linux (64-bit)")) .build(); // .put(OperatingSystem.UBUNTU, new Expectation(4194304, "Ubuntu Linux (32-bit)")) private Predicate addressTester; @@ -86,7 +86,7 @@ public class TerremarkVCloudComputeClientLiveTest { @Test public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, IOException { - OperatingSystem toTest = OperatingSystem.CENTOS; + OsFamily toTest = OsFamily.CENTOS; String serverName = getCompatibleServerName(toTest); int processorCount = 1; @@ -102,7 +102,7 @@ public class TerremarkVCloudComputeClientLiveTest { assertEquals(vApp.getStatus(), VAppStatus.ON); } - private String getCompatibleServerName(OperatingSystem toTest) { + private String getCompatibleServerName(OsFamily toTest) { String serverName = CaseFormat.UPPER_UNDERSCORE .to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, toTest.toString().length() <= 15 ? toTest.toString().length() : 14); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java index fc72d54bc1..25b05b7637 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeServiceLiveTest.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.terremark.compute; -import static org.jclouds.compute.domain.OperatingSystem.JEOS; +import static org.jclouds.compute.domain.OsFamily.UBUNTU; import org.jclouds.compute.BaseComputeServiceLiveTest; import org.jclouds.compute.ComputeServiceContextFactory; @@ -49,7 +49,7 @@ public class TerremarkVCloudComputeServiceLiveTest extends BaseComputeServiceLiv } protected Template buildTemplate(TemplateBuilder templateBuilder) { - return templateBuilder.os(JEOS).osVersionMatches(".*9.04.*").smallest().build(); + return templateBuilder.osFamily(UBUNTU).smallest().build(); } @Override