* nodes: - * cluster-1: - * id: cluster-1 - * description: xyz - * hostname: cluster-1.mydomain.com - * os_arch: x86 - * os_family: linux - * os_name: redhat - * os_version: 5.3 - * group: hadoop - * tags: - * - vanilla - * username: kelvin - * credential: password_or_rsa_in_base64 - * sudo_password: password_in_base64 + * - id: cluster-1: + * name: cluster-1 + * description: xyz + * hostname: cluster-1.mydomain.com + * os_arch: x86 + * os_family: linux + * os_description: redhat + * os_version: 5.3 + * group: hadoop + * tags: + * - vanilla + * username: kelvin + * credential: password_or_rsa + * or + * credential_url: password_or_rsa_file ex. resource:///id_rsa will get the classpath /id_rsa; file://path/to/id_rsa + * sudo_password: password ** * @author Kelvin Kakugawa @@ -65,7 +69,7 @@ public class NodesFromYaml implements Function
*
* @author Adrian Cole
- * @see
*/
@@ -93,22 +92,6 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
return getFirstFormOrNull("SecurityGroup.1");
}
- /**
- * Specifies the name of an existing placement group you want to launch the instance into (for
- * cluster compute instances).
- *
- * @param placementGroup
- * name of an existing placement group
- */
- public RunInstancesOptions inPlacementGroup(String placementGroup) {
- formParameters.put("Placement.GroupName", checkNotNull(placementGroup, "placementGroup"));
- return this;
- }
-
- String getPlacementGroup() {
- return getFirstFormOrNull("Placement.GroupName");
- }
-
/**
* Unencoded data
*/
@@ -163,58 +146,34 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
return getFirstFormOrNull("RamdiskId");
}
- /**
- * Enables monitoring for the instance.
- */
- public RunInstancesOptions enableMonitoring() {
- formParameters.put("Monitoring.Enabled", "true");
- return this;
- }
-
- String getMonitoringEnabled() {
- return getFirstFormOrNull("Monitoring.Enabled");
- }
-
- /**
- * Specifies the subnet ID within which to launch the instance(s) for Amazon Virtual Private
- * Cloud.
- */
- public RunInstancesOptions withSubnetId(String subnetId) {
- formParameters.put("SubnetId", checkNotNull(subnetId, "subnetId"));
- return this;
- }
-
- String getSubnetId() {
- return getFirstFormOrNull("SubnetId");
- }
-
/**
* Specifies the Block Device Mapping for the instance
- *
+ *
*/
-
- public RunInstancesOptions withBlockDeviceMappings(Set extends BlockDeviceMapping> mappings) {
- int i = 1;
- for(BlockDeviceMapping mapping: mappings)
- {
- checkNotNull(mapping.getDeviceName(), "deviceName");
- formParameters.put(String.format("BlockDeviceMapping.%d.DeviceName", i), mapping.getDeviceName());
- if(mapping.getVirtualName() != null)
- formParameters.put(String.format("BlockDeviceMapping.%d.VirtualName", i), mapping.getVirtualName());
- if(mapping.getEbsSnapshotId() != null)
- formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.SnapshotId", i), mapping.getEbsSnapshotId());
- if(mapping.getEbsVolumeSize() != null)
- formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.VolumeSize", i), String.valueOf(mapping.getEbsVolumeSize()));
- if(mapping.getEbsNoDevice() != null)
- formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.NoDevice", i), String.valueOf(mapping.getEbsNoDevice()));
- if(mapping.getEbsDeleteOnTermination() != null)
- formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.DeleteOnTermination", i), String.valueOf(mapping.getEbsDeleteOnTermination()));
-
- i++;
- }
- return this;
- }
+ public RunInstancesOptions withBlockDeviceMappings(Set extends BlockDeviceMapping> mappings) {
+ int i = 1;
+ for (BlockDeviceMapping mapping : checkNotNull(mappings, "mappings")) {
+ checkNotNull(mapping.getDeviceName(), "deviceName");
+ formParameters.put(String.format("BlockDeviceMapping.%d.DeviceName", i), mapping.getDeviceName());
+ if (mapping.getVirtualName() != null)
+ formParameters.put(String.format("BlockDeviceMapping.%d.VirtualName", i), mapping.getVirtualName());
+ if (mapping.getEbsSnapshotId() != null)
+ formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.SnapshotId", i), mapping.getEbsSnapshotId());
+ if (mapping.getEbsVolumeSize() != null)
+ formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.VolumeSize", i), String.valueOf(mapping
+ .getEbsVolumeSize()));
+ if (mapping.getEbsNoDevice() != null)
+ formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.NoDevice", i), String.valueOf(mapping
+ .getEbsNoDevice()));
+ if (mapping.getEbsDeleteOnTermination() != null)
+ formParameters.put(String.format("BlockDeviceMapping.%d.Ebs.DeleteOnTermination", i), String
+ .valueOf(mapping.getEbsDeleteOnTermination()));
+
+ i++;
+ }
+ return this;
+ }
public static class Builder {
/**
@@ -233,14 +192,6 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
return options.withSecurityGroup(securityGroup);
}
- /**
- * @see RunInstancesOptions#inPlacementGroup(String)
- */
- public static RunInstancesOptions inPlacementGroup(String placementGroup) {
- RunInstancesOptions options = new RunInstancesOptions();
- return options.inPlacementGroup(placementGroup);
- }
-
/**
* @see RunInstancesOptions#withUserData(byte [])
*/
@@ -265,22 +216,6 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
return options.withKernelId(kernelId);
}
- /**
- * @see RunInstancesOptions#enableMonitoring()
- */
- public static RunInstancesOptions enableMonitoring() {
- RunInstancesOptions options = new RunInstancesOptions();
- return options.enableMonitoring();
- }
-
- /**
- * @see RunInstancesOptions#withSubnetId(String)
- */
- public static RunInstancesOptions withSubnetId(String subnetId) {
- RunInstancesOptions options = new RunInstancesOptions();
- return options.withSubnetId(subnetId);
- }
-
/**
* @see RunInstancesOptions#withRamdisk(String)
*/
@@ -288,7 +223,7 @@ public class RunInstancesOptions extends BaseEC2RequestOptions {
RunInstancesOptions options = new RunInstancesOptions();
return options.withRamdisk(ramdiskId);
}
-
+
/**
* @see RunInstancesOptions#withBlockDeviceMappings(Set mappings)
*/
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/reference/EC2Constants.java b/apis/ec2/src/main/java/org/jclouds/ec2/reference/EC2Constants.java
index f54a5d63f1..f51281f681 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/reference/EC2Constants.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/reference/EC2Constants.java
@@ -26,19 +26,11 @@ import org.jclouds.compute.ComputeService;
*
* @author Adrian Cole
*/
-public interface EC2Constants{
+public interface EC2Constants {
/**
* Listing the universe of amis is extremely expensive. set this to a comma separated value of
* the ami owners you wish to use in {@link ComputeService}
*/
public static final String PROPERTY_EC2_AMI_OWNERS = "jclouds.ec2.ami-owners";
- public static final String PROPERTY_ELB_ENDPOINT = "jclouds.elb.endpoint";
-
- /**
- * amis that work on the cluster instance type
- *
- * @see InstanceType.CC1_4XLARGE
- */
- public static final String PROPERTY_EC2_CC_AMIs = "jclouds.ec2.cc-amis";
}
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIAsyncClient.java b/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIAsyncClient.java
index 39253ff9ee..d86528fbbe 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIAsyncClient.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIAsyncClient.java
@@ -32,12 +32,11 @@ import javax.ws.rs.Path;
import org.jclouds.aws.filters.FormSigner;
import org.jclouds.ec2.EC2AsyncClient;
-import org.jclouds.ec2.binders.BindProductCodesToIndexedFormParams;
import org.jclouds.ec2.binders.BindUserGroupsToIndexedFormParams;
import org.jclouds.ec2.binders.BindUserIdsToIndexedFormParams;
import org.jclouds.ec2.domain.Image;
-import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.Permission;
+import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.options.CreateImageOptions;
import org.jclouds.ec2.options.DescribeImagesOptions;
import org.jclouds.ec2.options.RegisterImageBackedByEbsOptions;
@@ -46,7 +45,6 @@ import org.jclouds.ec2.xml.BlockDeviceMappingHandler;
import org.jclouds.ec2.xml.DescribeImagesResponseHandler;
import org.jclouds.ec2.xml.ImageIdHandler;
import org.jclouds.ec2.xml.PermissionHandler;
-import org.jclouds.ec2.xml.ProductCodesHandler;
import org.jclouds.location.functions.RegionToEndpointOrProviderIfNull;
import org.jclouds.rest.annotations.BinderParam;
import org.jclouds.rest.annotations.EndpointParam;
@@ -79,7 +77,8 @@ public interface AMIAsyncClient {
@XMLResponseParser(DescribeImagesResponseHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
ListenableFuture> describeImagesInRegion(
- @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region, DescribeImagesOptions... options);
+ @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
+ DescribeImagesOptions... options);
/**
* @see AMIClient#createImageInRegion
@@ -88,7 +87,8 @@ public interface AMIAsyncClient {
@Path("/")
@FormParams(keys = ACTION, values = "CreateImage")
@XMLResponseParser(ImageIdHandler.class)
- ListenableFuture createImageInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
+ ListenableFuture createImageInRegion(
+ @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("Name") String name, @FormParam("InstanceId") String instanceId, CreateImageOptions... options);
/**
@@ -97,7 +97,8 @@ public interface AMIAsyncClient {
@POST
@Path("/")
@FormParams(keys = ACTION, values = "DeregisterImage")
- ListenableFuture deregisterImageInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
+ ListenableFuture deregisterImageInRegion(
+ @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("ImageId") String imageId);
/**
@@ -173,17 +174,6 @@ public interface AMIAsyncClient {
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("ImageId") String imageId);
- /**
- * @see AMIClient#getProductCodesForImageInRegion
- */
- @POST
- @Path("/")
- @FormParams(keys = { ACTION, "Attribute" }, values = { "DescribeImageAttribute", "productCodes" })
- @XMLResponseParser(ProductCodesHandler.class)
- ListenableFuture> getProductCodesForImageInRegion(
- @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
- @FormParam("ImageId") String imageId);
-
/**
* @see AMIClient#getBlockDeviceMappingsForImageInRegion
*/
@@ -194,27 +184,4 @@ public interface AMIAsyncClient {
ListenableFuture> getBlockDeviceMappingsForImageInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@FormParam("ImageId") String imageId);
-
- /**
- * @see AMIClient#addProductCodesToImageInRegion
- */
- @POST
- @Path("/")
- @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifyImageAttribute", "add",
- "productCodes" })
- ListenableFuture addProductCodesToImageInRegion(@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
- @BinderParam(BindProductCodesToIndexedFormParams.class) Iterable productCodes,
- @FormParam("ImageId") String imageId);
-
- /**
- * @see AMIClient#removeProductCodesToImageInRegion
- */
- @POST
- @Path("/")
- @FormParams(keys = { ACTION, "OperationType", "Attribute" }, values = { "ModifyImageAttribute", "remove",
- "productCodes" })
- ListenableFuture removeProductCodesFromImageInRegion(
- @EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
- @BinderParam(BindProductCodesToIndexedFormParams.class) Iterable productCodes,
- @FormParam("ImageId") String imageId);
}
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIClient.java b/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIClient.java
index 9e621fcbc2..29d1b5aadb 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIClient.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/services/AMIClient.java
@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
+import org.jclouds.concurrent.Timeout;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.Permission;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
@@ -32,7 +33,6 @@ import org.jclouds.ec2.options.CreateImageOptions;
import org.jclouds.ec2.options.DescribeImagesOptions;
import org.jclouds.ec2.options.RegisterImageBackedByEbsOptions;
import org.jclouds.ec2.options.RegisterImageOptions;
-import org.jclouds.concurrent.Timeout;
/**
* Provides access to EC2 via their REST API.
@@ -60,22 +60,6 @@ public interface AMIClient {
@Timeout(duration = 300, timeUnit = TimeUnit.SECONDS)
Set extends Image> describeImagesInRegion(@Nullable String region, DescribeImagesOptions... options);
- /**
- * Returns the Product Codes of an image.
- *
- * @param region
- * AMIs are tied to the Region where its files are located within Amazon S3.
- * @param imageId
- * The ID of the AMI for which an attribute will be described
- * @see #describeImages
- * @see #modifyImageAttribute
- * @see #resetImageAttribute
- * @see
- * @see DescribeImagesOptions
- */
- Set getProductCodesForImageInRegion(@Nullable String region, String imageId);
-
/**
* Returns a map of device name to block device for the image.
*
@@ -114,8 +98,7 @@ public interface AMIClient {
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateImage.html"
* />
*/
- String createImageInRegion(@Nullable String region, String name, String instanceId,
- CreateImageOptions... options);
+ String createImageInRegion(@Nullable String region, String name, String instanceId, CreateImageOptions... options);
/**
*
@@ -201,7 +184,7 @@ public interface AMIClient {
*/
String registerUnixImageBackedByEbsInRegion(@Nullable String region, String name, String ebsSnapshotId,
RegisterImageBackedByEbsOptions... options);
-
+
/**
* Returns the {@link Permission}s of an image.
*
@@ -276,40 +259,4 @@ public interface AMIClient {
void removeLaunchPermissionsFromImageInRegion(@Nullable String region, Iterable userIds,
Iterable userGroups, String imageId);
- /**
- * Adds {@code productCode}s to an AMI.
- *
- * @param region
- * AMIs are tied to the Region where its files are located within Amazon S3.
- * @param productCodes
- * Product Codes
- * @param imageId
- * The AMI ID.
- *
- * @see #removeProductCodesFromImage
- * @see #describeImageAttribute
- * @see #resetImageAttribute
- * @see
- */
- void addProductCodesToImageInRegion(@Nullable String region, Iterable productCodes, String imageId);
-
- /**
- * Removes {@code productCode}s from an AMI.
- *
- * @param region
- * AMIs are tied to the Region where its files are located within Amazon S3.
- * @param productCodes
- * Product Codes
- * @param imageId
- * The AMI ID.
- *
- * @see #addProductCodesToImage
- * @see #describeImageAttribute
- * @see #resetImageAttribute
- * @see
- */
- void removeProductCodesFromImageInRegion(@Nullable String region, Iterable productCodes,
- String imageId);
}
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/services/InstanceAsyncClient.java b/apis/ec2/src/main/java/org/jclouds/ec2/services/InstanceAsyncClient.java
index cecacd6ecc..b30afddbf7 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/services/InstanceAsyncClient.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/services/InstanceAsyncClient.java
@@ -83,7 +83,7 @@ public interface InstanceAsyncClient {
@FormParams(keys = ACTION, values = "DescribeInstances")
@XMLResponseParser(DescribeInstancesResponseHandler.class)
@ExceptionParser(ReturnEmptySetOnNotFoundOr404.class)
- ListenableFuture>> describeInstancesInRegion(
+ ListenableFuture extends Set extends Reservation extends RunningInstance>>> describeInstancesInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@BinderParam(BindInstanceIdsToIndexedFormParams.class) String... instanceIds);
@@ -94,7 +94,7 @@ public interface InstanceAsyncClient {
@Path("/")
@FormParams(keys = ACTION, values = "RunInstances")
@XMLResponseParser(RunInstancesResponseHandler.class)
- ListenableFuture> runInstancesInRegion(
+ ListenableFuture extends Reservation extends RunningInstance>> runInstancesInRegion(
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
@Nullable @BinderParam(IfNotNullBindAvailabilityZoneToFormParam.class) String nullableAvailabilityZone,
@FormParam("ImageId") String imageId, @FormParam("MinCount") int minCount,
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java
index 6a60ae61b2..04c4af953d 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java
@@ -20,28 +20,27 @@
package org.jclouds.ec2.xml;
import java.util.Date;
-import java.util.Map;
import java.util.Set;
import javax.annotation.Resource;
import javax.inject.Inject;
+import org.jclouds.aws.util.AWSUtils;
+import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.Attachment;
import org.jclouds.ec2.domain.BlockDevice;
import org.jclouds.ec2.domain.InstanceState;
-import org.jclouds.ec2.domain.MonitoringState;
import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.aws.util.AWSUtils;
-import org.jclouds.date.DateService;
+import org.jclouds.ec2.domain.RunningInstance.Builder;
import org.jclouds.http.functions.ParseSax.HandlerForGeneratedRequestWithResult;
import org.jclouds.location.Region;
import org.jclouds.logging.Logger;
import org.xml.sax.Attributes;
-import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
+import com.google.inject.Provider;
/**
*
@@ -49,75 +48,49 @@ import com.google.common.collect.Sets;
*/
public abstract class BaseReservationHandler extends HandlerForGeneratedRequestWithResult {
- protected final DateService dateService;
-
- protected final String defaultRegion;
-
- @Inject
- public BaseReservationHandler(DateService dateService, @Region String defaultRegion) {
- this.dateService = dateService;
- this.defaultRegion = defaultRegion;
- }
-
@Resource
protected Logger logger = Logger.NULL;
- private StringBuilder currentText = new StringBuilder();
- private Set groupIds = Sets.newLinkedHashSet();
- private Set instances = Sets.newLinkedHashSet();
- private String ownerId;
- private String requesterId;
- private String reservationId;
- private String amiLaunchIndex;
- private String dnsName;
- private String imageId;
- private String instanceId;
- private InstanceState instanceState;
- private String instanceType;
- private String ipAddress;
- private String kernelId;
- private String keyName;
- private Date launchTime;
- private MonitoringState monitoringState;
- private String availabilityZone;
- private String placementGroup;
- private String virtualizationType = "paravirtual";
- private String platform;
- private String privateDnsName;
- private String privateIpAddress;
- private Set productCodes = Sets.newHashSet();
- private String ramdiskId;
- private String reason;
- private String spotInstanceRequestId;
- private String subnetId;
- private String vpcId;
- protected boolean inInstances;
- protected boolean inProductCodes;
- protected boolean inGroups;
- protected boolean inMonitoring;
- private boolean inBlockDeviceMapping;
- private Map ebsBlockDevices = Maps.newHashMap();
+ protected final DateService dateService;
+ protected final String defaultRegion;
+ protected final Provider builderProvider;
+ @Inject
+ public BaseReservationHandler(DateService dateService, @Region String defaultRegion,
+ Provider builderProvider) {
+ this.dateService = dateService;
+ this.defaultRegion = defaultRegion;
+ this.builderProvider = builderProvider;
+ this.builder = builderProvider.get();
+ }
+
+ protected StringBuilder currentText = new StringBuilder();
+
+ protected Builder builder;
+
+ protected int itemDepth;
+ boolean inInstancesSet;
+ // attachments
private String volumeId;
private Attachment.Status attachmentStatus;
private Date attachTime;
private boolean deleteOnTermination;
- private RootDeviceType rootDeviceType = RootDeviceType.INSTANCE_STORE;
private String deviceName;
- private String rootDeviceName;
+
+ // reservation stuff
+ private Set groupIds = Sets.newLinkedHashSet();
+ private String ownerId;
+ private String requesterId;
+ private String reservationId;
+
+ private Set instances = Sets.newLinkedHashSet();
public void startElement(String uri, String name, String qName, Attributes attrs) {
- if (qName.equals("instancesSet")) {
- inInstances = true;
- } else if (qName.equals("productCodesSet")) {
- inProductCodes = true;
- } else if (qName.equals("groupSet")) {
- inGroups = true;
- } else if (qName.equals("blockDeviceMapping")) {
- inBlockDeviceMapping = true;
+ if (qName.equals("item")) {
+ itemDepth++;
+ } else if (qName.equals("instancesSet")) {
+ inInstancesSet = true;
}
- if (qName.equals("monitoring"))
- inMonitoring = true;
}
protected String currentOrNull() {
@@ -126,7 +99,12 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque
}
public void endElement(String uri, String name, String qName) {
- if (qName.equals("groupId")) {
+ if (qName.equals("item")) {
+ inItem();
+ itemDepth--;
+ } else if (qName.equals("instancesSet")) {
+ inInstancesSet = false;
+ } else if (qName.equals("groupId")) {
groupIds.add(currentOrNull());
} else if (qName.equals("ownerId")) {
ownerId = currentOrNull();
@@ -135,83 +113,51 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque
} else if (qName.equals("reservationId")) {
reservationId = currentOrNull();
} else if (qName.equals("amiLaunchIndex")) {
- amiLaunchIndex = currentOrNull();
+ builder.amiLaunchIndex(currentOrNull());
} else if (qName.equals("dnsName")) {
- dnsName = currentOrNull();
+ String dnsName = currentOrNull();
// Eucalyptus
- if ("0.0.0.0".equals(dnsName))
- dnsName = null;
+ if (!"0.0.0.0".equals(dnsName))
+ builder.dnsName(dnsName);
} else if (qName.equals("imageId")) {
- imageId = currentOrNull();
+ builder.imageId(currentOrNull());
} else if (qName.equals("instanceId")) {
- instanceId = currentOrNull();
+ builder.instanceId(currentOrNull());
} else if (qName.equals("name")) {
- String state = currentOrNull();
- if (state != null) {
- // Nova
- if ("shutdown".equalsIgnoreCase(state))
- instanceState = InstanceState.TERMINATED;
- else
- instanceState = InstanceState.fromValue(state);
- }
+ builder.instanceState(InstanceState.fromValue(currentOrNull()));
} else if (qName.equals("instanceType")) {
- instanceType = currentOrNull();
+ builder.instanceType(currentOrNull());
} else if (qName.equals("ipAddress")) {
- ipAddress = currentOrNull();
+ builder.ipAddress(currentOrNull());
} else if (qName.equals("kernelId")) {
- kernelId = currentOrNull();
+ builder.kernelId(currentOrNull());
} else if (qName.equals("keyName")) {
- keyName = currentOrNull();
+ builder.keyName(currentOrNull());
} else if (qName.equals("launchTime")) {
- try {
- launchTime = dateService.iso8601DateParse(currentOrNull());
- } catch (RuntimeException e) {
- // Eucalyptus
- launchTime = dateService.iso8601SecondsDateParse(currentOrNull());
- }
- } else if (qName.equals("state") && inMonitoring) {
- monitoringState = MonitoringState.fromValue(currentOrNull());
+ builder.launchTime(parseDate());
} else if (qName.equals("availabilityZone")) {
- availabilityZone = currentOrNull();
- } else if (qName.equals("groupName")) {
- placementGroup = currentOrNull();
+ builder.availabilityZone(currentOrNull());
} else if (qName.equals("virtualizationType")) {
- virtualizationType = currentOrNull();
+ builder.virtualizationType(currentOrNull());
} else if (qName.equals("platform")) {
- platform = currentOrNull();
+ builder.platform(currentOrNull());
} else if (qName.equals("privateDnsName")) {
- privateDnsName = currentOrNull();
+ String privateDnsName = currentOrNull();
// Eucalyptus
- if ("0.0.0.0".equals(privateDnsName))
- privateDnsName = null;
+ if (!"0.0.0.0".equals(privateDnsName))
+ builder.privateDnsName(privateDnsName);
} else if (qName.equals("privateIpAddress")) {
- privateIpAddress = currentOrNull();
+ builder.privateIpAddress(currentOrNull());
} else if (qName.equals("ramdiskId")) {
- ramdiskId = currentOrNull();
+ builder.ramdiskId(currentOrNull());
} else if (qName.equals("reason")) {
- reason = currentOrNull();
- } else if (qName.equals("subnetId")) {
- subnetId = currentOrNull();
- } else if (qName.equals("spotInstanceRequestId")) {
- spotInstanceRequestId = currentOrNull();
- } else if (qName.equals("vpcId")) {
- vpcId = currentOrNull();
- } else if (qName.equals("productCode")) {
- productCodes.add(currentOrNull());
- } else if (qName.equals("productCodesSet")) {
- inProductCodes = false;
- } else if (qName.equals("instancesSet")) {
- inInstances = false;
- } else if (qName.equals("groupSet")) {
- inGroups = false;
- } else if (qName.equals("monitoring")) {
- inMonitoring = false;
- } else if (qName.equals("blockDeviceMapping")) {
- inBlockDeviceMapping = false;
+ builder.reason(currentOrNull());
+ } else if (qName.equals("rootDeviceType")) {
+ builder.rootDeviceType(RootDeviceType.fromValue(currentOrNull()));
+ } else if (qName.equals("rootDeviceName")) {
+ builder.rootDeviceName(currentOrNull());
} else if (qName.equals("deviceName")) {
deviceName = currentOrNull();
- } else if (qName.equals("rootDeviceType")) {
- rootDeviceType = RootDeviceType.fromValue(currentOrNull());
} else if (qName.equals("volumeId")) {
volumeId = currentOrNull();
} else if (qName.equals("status")) {
@@ -220,72 +166,60 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque
attachTime = dateService.iso8601DateParse(currentText.toString().trim());
} else if (qName.equals("deleteOnTermination")) {
deleteOnTermination = Boolean.parseBoolean(currentText.toString().trim());
- } else if (qName.equals("rootDeviceName")) {
- rootDeviceName = currentOrNull();
- } else if (qName.equals("item")) {
- inItem();
- }
- currentText = new StringBuilder();
- }
-
- protected void inItem() {
- if (inBlockDeviceMapping) {
- ebsBlockDevices.put(deviceName, new BlockDevice(volumeId, attachmentStatus, attachTime,
- deleteOnTermination));
+ } else if (qName.equals("ebs")) {
+ builder.device(deviceName, new BlockDevice(volumeId, attachmentStatus, attachTime, deleteOnTermination));
this.deviceName = null;
this.volumeId = null;
this.attachmentStatus = null;
this.attachTime = null;
this.deleteOnTermination = true;
- } else if (inInstances && !inProductCodes && !inBlockDeviceMapping) {
- String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
+ }
+ currentText = new StringBuilder();
+ }
+ protected Date parseDate() {
+ try {
+ return dateService.iso8601DateParse(currentOrNull());
+ } catch (RuntimeException e) {
// Eucalyptus
- if (ipAddress == null && dnsName != null && dnsName.matches(".*[0-9]$")) {
- ipAddress = dnsName;
- dnsName = null;
- }
-
- if (privateIpAddress == null && privateDnsName != null && privateDnsName.matches(".*[0-9]$")) {
- privateIpAddress = privateDnsName;
- privateDnsName = null;
- }
- if (region == null)
- region = defaultRegion;
- instances.add(new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId, instanceId,
- instanceState, instanceType, ipAddress, kernelId, keyName, launchTime, monitoringState,
- availabilityZone, placementGroup, virtualizationType, platform, privateDnsName, privateIpAddress,
- productCodes, ramdiskId, reason, subnetId, spotInstanceRequestId, vpcId, rootDeviceType, rootDeviceName,
- ebsBlockDevices));
- this.amiLaunchIndex = null;
- this.dnsName = null;
- this.imageId = null;
- this.instanceId = null;
- this.instanceState = null;
- this.instanceType = null;
- this.ipAddress = null;
- this.kernelId = null;
- this.keyName = null;
- this.launchTime = null;
- this.monitoringState = null;
- this.availabilityZone = null;
- this.placementGroup = null;
- this.virtualizationType = "paravirtual";
- this.platform = null;
- this.privateDnsName = null;
- this.privateIpAddress = null;
- this.productCodes = Sets.newHashSet();
- this.ramdiskId = null;
- this.reason = null;
- this.subnetId = null;
- this.spotInstanceRequestId = null;
- this.vpcId = null;
- this.rootDeviceType = RootDeviceType.INSTANCE_STORE;
- this.rootDeviceName = null;
- this.ebsBlockDevices = Maps.newHashMap();
+ return dateService.iso8601SecondsDateParse(currentOrNull());
}
}
+ protected void inItem() {
+ if (endOfInstanceItem()) {
+ refineBuilderBeforeAddingInstance();
+ instances.add(builder.build());
+ builder = builderProvider.get();
+ }
+ }
+
+ protected void refineBuilderBeforeAddingInstance() {
+ String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
+
+ // Eucalyptus
+ if (builder.getIpAddress() == null && builder.getDnsName() != null && builder.getDnsName().matches(".*[0-9]$")) {
+ builder.ipAddress(builder.getDnsName());
+ builder.dnsName(null);
+ }
+ if (builder.getPrivateIpAddress() == null && builder.getPrivateDnsName() != null
+ && builder.getPrivateDnsName().matches(".*[0-9]$")) {
+ builder.privateIpAddress(builder.getPrivateDnsName());
+ builder.privateDnsName(null);
+ }
+
+ builder.region((region == null) ? defaultRegion : region);
+ builder.groupIds(groupIds);
+ }
+
+ protected Builder builder() {
+ return builder;
+ }
+
+ protected boolean endOfInstanceItem() {
+ return itemDepth <= 2 && inInstancesSet;
+ }
+
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
@@ -295,7 +229,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque
if (region == null)
region = defaultRegion;
Reservation extends RunningInstance> info = new Reservation(region, groupIds, instances,
- ownerId, requesterId, reservationId);
+ ownerId, requesterId, reservationId);
this.groupIds = Sets.newLinkedHashSet();
this.instances = Sets.newLinkedHashSet();
this.ownerId = null;
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandler.java
index 57fc65e789..a63eb307e4 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandler.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandler.java
@@ -23,12 +23,13 @@ import java.util.Set;
import javax.inject.Inject;
+import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.date.DateService;
import org.jclouds.location.Region;
import com.google.common.collect.Sets;
+import com.google.inject.Provider;
/**
* Parses the following XML document:
@@ -43,8 +44,9 @@ public class DescribeInstancesResponseHandler extends
private Set> reservations = Sets.newLinkedHashSet();
@Inject
- DescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion) {
- super(dateService, defaultRegion);
+ DescribeInstancesResponseHandler(DateService dateService, @Region String defaultRegion,
+ Provider builderProvider) {
+ super(dateService, defaultRegion, builderProvider);
}
@Override
@@ -52,9 +54,13 @@ public class DescribeInstancesResponseHandler extends
return reservations;
}
+ protected boolean endOfReservationItem() {
+ return itemDepth == 1;
+ }
+
@Override
protected void inItem() {
- if (!inInstances && !inProductCodes && !inGroups) {
+ if (endOfReservationItem()) {
reservations.add(super.newReservation());
} else {
super.inItem();
diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/RunInstancesResponseHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/RunInstancesResponseHandler.java
index 5188ae029c..ab776e81f7 100644
--- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/RunInstancesResponseHandler.java
+++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/RunInstancesResponseHandler.java
@@ -21,11 +21,13 @@ package org.jclouds.ec2.xml;
import javax.inject.Inject;
+import org.jclouds.date.DateService;
import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance;
-import org.jclouds.date.DateService;
import org.jclouds.location.Region;
+import com.google.inject.Provider;
+
/**
* Parses the following XML document:
*
@@ -37,8 +39,9 @@ import org.jclouds.location.Region;
public class RunInstancesResponseHandler extends BaseReservationHandler> {
@Inject
- RunInstancesResponseHandler(DateService dateService, @Region String defaultRegion) {
- super(dateService, defaultRegion);
+ RunInstancesResponseHandler(DateService dateService, @Region String defaultRegion,
+ Provider builderProvider) {
+ super(dateService, defaultRegion, builderProvider);
}
@Override
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/EC2AsyncClientTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/EC2AsyncClientTest.java
index 52bf7daaa8..ae90573c74 100644
--- a/apis/ec2/src/test/java/org/jclouds/ec2/EC2AsyncClientTest.java
+++ b/apis/ec2/src/test/java/org/jclouds/ec2/EC2AsyncClientTest.java
@@ -49,9 +49,7 @@ public class EC2AsyncClientTest extends BaseEC2AsyncClientTest {
assert syncClient.getElasticIPAddressServices() != null;
assert syncClient.getInstanceServices() != null;
assert syncClient.getKeyPairServices() != null;
- assert syncClient.getMonitoringServices() != null;
assert syncClient.getSecurityGroupServices() != null;
- assert syncClient.getPlacementGroupServices() != null;
assert syncClient.getWindowsServices() != null;
}
@@ -63,9 +61,7 @@ public class EC2AsyncClientTest extends BaseEC2AsyncClientTest {
assert asyncClient.getElasticIPAddressServices() != null;
assert asyncClient.getInstanceServices() != null;
assert asyncClient.getKeyPairServices() != null;
- assert asyncClient.getMonitoringServices() != null;
assert asyncClient.getSecurityGroupServices() != null;
- assert asyncClient.getPlacementGroupServices() != null;
assert asyncClient.getWindowsServices() != null;
}
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java
index 61d4ed91c5..1c7f95a671 100644
--- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java
+++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java
@@ -21,7 +21,9 @@ package org.jclouds.ec2.compute;
import static org.jclouds.compute.util.ComputeServiceUtils.getCores;
import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+import java.util.Map;
import java.util.Set;
import org.jclouds.compute.BaseComputeServiceLiveTest;
@@ -31,18 +33,26 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.domain.Credentials;
+import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationScope;
import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.compute.options.EC2TemplateOptions;
+import org.jclouds.ec2.domain.BlockDevice;
+import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.IpProtocol;
import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.ec2.domain.SecurityGroup;
+import org.jclouds.ec2.domain.Snapshot;
+import org.jclouds.ec2.domain.Volume;
+import org.jclouds.ec2.services.ElasticBlockStoreClient;
import org.jclouds.ec2.services.InstanceClient;
import org.jclouds.ec2.services.KeyPairClient;
import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.Test;
+import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -68,7 +78,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
public void testImagesResolveCorrectly() {
Template defaultTemplate = client.templateBuilder().build();
assertEquals(defaultTemplate.getImage().getId(), defaultTemplate.getImage().getLocation().getId() + "/"
- + defaultTemplate.getImage().getProviderId());
+ + defaultTemplate.getImage().getProviderId());
Template byId = client.templateBuilder().imageId(defaultTemplate.getImage().getId()).build();
assertEquals(byId.getImage(), defaultTemplate.getImage());
}
@@ -89,37 +99,34 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
@Test(enabled = true, dependsOnMethods = "testCompareSizes")
public void testExtendedOptionsAndLogin() throws Exception {
SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getSecurityGroupServices();
+ .getSecurityGroupServices();
KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getKeyPairServices();
+ .getKeyPairServices();
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getInstanceServices();
+ .getInstanceServices();
- String tag = this.tag + "o";
+ String group = this.group + "o";
TemplateOptions options = client.templateOptions();
-// Date before = new Date();
-
- options.as(EC2TemplateOptions.class).securityGroups(tag);
- options.as(EC2TemplateOptions.class).keyPair(tag);
- options.as(EC2TemplateOptions.class).enableMonitoring();
+ options.as(EC2TemplateOptions.class).securityGroups(group);
+ options.as(EC2TemplateOptions.class).keyPair(group);
String startedId = null;
try {
- cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
+ cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
// create a security group that allows ssh in so that our scripts later
// will work
- securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
- securityGroupClient.authorizeSecurityGroupIngressInRegion(null, tag, IpProtocol.TCP, 22, 22, "0.0.0.0/0");
+ securityGroupClient.createSecurityGroupInRegion(null, group, group);
+ securityGroupClient.authorizeSecurityGroupIngressInRegion(null, group, IpProtocol.TCP, 22, 22, "0.0.0.0/0");
// create a keypair to pass in as well
- KeyPair result = keyPairClient.createKeyPairInRegion(null, tag);
+ KeyPair result = keyPairClient.createKeyPairInRegion(null, group);
- Set extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
+ Set extends NodeMetadata> nodes = client.createNodesInGroup(group, 1, options);
NodeMetadata first = Iterables.get(nodes, 0);
assert first.getCredentials() != null : first;
assert first.getCredentials().identity != null : first;
@@ -128,181 +135,123 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest {
RunningInstance instance = getInstance(instanceClient, startedId);
- assertEquals(instance.getKeyName(), tag);
-// checkMonitoringEnabled(before, instance);
+ assertEquals(instance.getKeyName(), group);
// make sure we made our dummy group and also let in the user's group
- assertEquals(Sets.newTreeSet(instance.getGroupIds()),
- ImmutableSortedSet. of("jclouds#" + tag + "#" + instance.getRegion(), tag));
+ assertEquals(Sets.newTreeSet(instance.getGroupIds()), ImmutableSortedSet. of("jclouds#" + group + "#"
+ + instance.getRegion(), group));
// make sure our dummy group has no rules
- SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
- "jclouds#" + tag + "#" + instance.getRegion()));
- assert group.getIpPermissions().size() == 0 : group;
+ SecurityGroup secgroup = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
+ "jclouds#" + group + "#" + instance.getRegion()));
+ assert secgroup.getIpPermissions().size() == 0 : secgroup;
// try to run a script with the original keyPair
- runScriptWithCreds(tag, first.getOperatingSystem(),
- new Credentials(first.getCredentials().identity, result.getKeyMaterial()));
+ runScriptWithCreds(group, first.getOperatingSystem(), new Credentials(first.getCredentials().identity, result
+ .getKeyMaterial()));
} finally {
- client.destroyNodesMatching(NodePredicates.withTag(tag));
+ client.destroyNodesMatching(NodePredicates.inGroup(group));
if (startedId != null) {
// ensure we didn't delete these resources!
- assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1);
- assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, tag).size(), 1);
+ assertEquals(keyPairClient.describeKeyPairsInRegion(null, group).size(), 1);
+ assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, group).size(), 1);
}
- cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
+ cleanupExtendedStuff(securityGroupClient, keyPairClient, group);
}
}
-// private void checkMonitoringEnabled(Date before, RunningInstance instance) {
-// assertEquals(instance.getMonitoringState(), MonitoringState.ENABLED);
-//
-// RestContext monitoringContext = new RestContextFactory().createContext(
-// "cloudwatch", identity, credential, ImmutableSet. of(new Log4JLoggingModule()));
-//
-// try {
-// Set datapoints = monitoringContext.getApi().getMetricStatisticsInRegion(instance.getRegion(),
-// "CPUUtilization", before, new Date(), 60, "Average");
-// assert datapoints != null;
-// } finally {
-// monitoringContext.close();
-// }
-// }
-
- @Test(enabled = true, dependsOnMethods = "testCompareSizes")
- public void testExtendedOptionsNoKeyPair() throws Exception {
- SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getSecurityGroupServices();
-
- KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getKeyPairServices();
+ /**
+ * Note we cannot use the micro size as it has no ephemeral space.
+ */
+ @Test(enabled = true)
+ public void testMapEBS() throws Exception {
InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getInstanceServices();
+ .getInstanceServices();
- String tag = this.tag + "k";
+ ElasticBlockStoreClient ebsClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
+ .getElasticBlockStoreServices();
- TemplateOptions options = client.templateOptions();
+ String group = this.group + "e";
+ int volumeSize = 8;
- options.as(EC2TemplateOptions.class).securityGroups(tag);
- options.as(EC2TemplateOptions.class).noKeyPair();
+ Location zone = Iterables.find(context.getComputeService().listAssignableLocations(), new Predicate() {
+
+ @Override
+ public boolean apply(Location arg0) {
+ return arg0.getScope() == LocationScope.ZONE;
+ }
+
+ });
+
+ // create volume only to make a snapshot
+ Volume volume = ebsClient.createVolumeInAvailabilityZone(zone.getId(), 4);
+ Snapshot snapshot = ebsClient.createSnapshotInRegion(volume.getRegion(), volume.getId());
+ ebsClient.deleteVolumeInRegion(volume.getRegion(), volume.getId());
+
+ Template template = context.getComputeService().templateBuilder().locationId(volume.getRegion()).hardwareId(
+ InstanceType.M1_SMALL).imageDescriptionMatches(".*ebs.*").build();
+
+ template.getOptions().as(EC2TemplateOptions.class)//
+ // .unmapDeviceNamed("/dev/foo)
+ .mapEphemeralDeviceToDeviceName("/dev/sdm", "ephemeral0")//
+ .mapNewVolumeToDeviceName("/dev/sdn", volumeSize, true)//
+ .mapEBSSnapshotToDeviceName("/dev/sdo", snapshot.getId(), volumeSize, true);
- String startedId = null;
try {
- cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
+ NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(group, 1, template));
- // create the security group
- securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
+ // TODO figure out how to validate the ephemeral drive. perhaps with df -k?
- Set extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
- Credentials creds = nodes.iterator().next().getCredentials();
- assert creds == null;
+ Map devices = instanceClient.getBlockDeviceMappingForInstanceInRegion(node.getLocation()
+ .getParent().getId(), node.getProviderId());
- startedId = Iterables.getOnlyElement(nodes).getProviderId();
+ BlockDevice device = devices.get("/dev/sdn");
+ // check delete on termination
+ assertTrue(device.isDeleteOnTermination());
- RunningInstance instance = getInstance(instanceClient, startedId);
+ volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
+ device.getVolumeId()));
+ // check volume size
+ assertEquals(volumeSize, volume.getSize());
- assertEquals(instance.getKeyName(), null);
+ device = devices.get("/dev/sdo");
+ // check delete on termination
+ assertTrue(device.isDeleteOnTermination());
- // make sure we made our dummy group and also let in the user's group
- assertEquals(Sets.newTreeSet(instance.getGroupIds()),
- ImmutableSortedSet. of(tag, String.format("jclouds#%s#%s", tag, instance.getRegion())));
-
- // make sure our dummy group has no rules
- SecurityGroup group = Iterables.getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(null,
- String.format("jclouds#%s#%s", tag, instance.getRegion())));
- assert group.getIpPermissions().size() == 0 : group;
+ volume = Iterables.getOnlyElement(ebsClient.describeVolumesInRegion(node.getLocation().getParent().getId(),
+ device.getVolumeId()));
+ // check volume size
+ assertEquals(volumeSize, volume.getSize());
+ // check volume's snapshot id
+ assertEquals(snapshot.getId(), volume.getSnapshotId());
} finally {
- client.destroyNodesMatching(NodePredicates.withTag(tag));
- if (startedId != null) {
- // ensure we didn't delete these resources!
- assertEquals(securityGroupClient.describeSecurityGroupsInRegion(null, tag).size(), 1);
- }
- cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
+ client.destroyNodesMatching(NodePredicates.inGroup(group));
+ ebsClient.deleteSnapshotInRegion(snapshot.getRegion(), snapshot.getId());
}
}
- @Test(enabled = true, dependsOnMethods = "testCompareSizes")
- public void testExtendedOptionsWithSubnetId() throws Exception {
-
- String subnetId = System.getProperty("test.subnetId");
- if (subnetId == null) {
- // Skip test and return
- return;
- }
- SecurityGroupClient securityGroupClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getSecurityGroupServices();
-
- KeyPairClient keyPairClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getKeyPairServices();
-
- InstanceClient instanceClient = EC2Client.class.cast(context.getProviderSpecificContext().getApi())
- .getInstanceServices();
-
- String tag = this.tag + "g";
-
- TemplateOptions options = client.templateOptions();
-
- // options.as(EC2TemplateOptions.class).securityGroups(tag);
- options.as(EC2TemplateOptions.class).keyPair(tag);
- options.as(EC2TemplateOptions.class).subnetId(subnetId);
-
- String startedId = null;
- String nodeId = null;
- try {
- cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
-
- // create the security group
- // securityGroupClient.createSecurityGroupInRegion(null, tag, tag);
-
- // create a keypair to pass in as well
- keyPairClient.createKeyPairInRegion(null, tag);
-
- Set extends NodeMetadata> nodes = client.runNodesWithTag(tag, 1, options);
-
- NodeMetadata first = Iterables.get(nodes, 0);
- assert first.getCredentials() != null : first;
- assert first.getCredentials().identity != null : first;
-
- startedId = Iterables.getOnlyElement(nodes).getProviderId();
- nodeId = Iterables.getOnlyElement(nodes).getId();
-
- RunningInstance instance = getInstance(instanceClient, startedId);
-
- assertEquals(instance.getSubnetId(), subnetId);
-
- } finally {
- if (nodeId != null)
- client.destroyNode(nodeId);
- if (startedId != null) {
- // ensure we didn't delete these resources!
- assertEquals(keyPairClient.describeKeyPairsInRegion(null, tag).size(), 1);
- }
- cleanupExtendedStuff(securityGroupClient, keyPairClient, tag);
- }
- }
-
- private RunningInstance getInstance(InstanceClient instanceClient, String id) {
+ protected RunningInstance getInstance(InstanceClient instanceClient, String id) {
RunningInstance instance = Iterables.getOnlyElement(Iterables.getOnlyElement(instanceClient
- .describeInstancesInRegion(null, id)));
+ .describeInstancesInRegion(null, id)));
return instance;
}
- private void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String tag)
- throws InterruptedException {
+ protected void cleanupExtendedStuff(SecurityGroupClient securityGroupClient, KeyPairClient keyPairClient, String group)
+ throws InterruptedException {
try {
- for (SecurityGroup group : securityGroupClient.describeSecurityGroupsInRegion(null))
- if (group.getName().startsWith("jclouds#" + tag) || group.getName().equals(tag)) {
- securityGroupClient.deleteSecurityGroupInRegion(null, group.getName());
+ for (SecurityGroup secgroup : securityGroupClient.describeSecurityGroupsInRegion(null))
+ if (secgroup.getName().startsWith("jclouds#" + group) || secgroup.getName().equals(group)) {
+ securityGroupClient.deleteSecurityGroupInRegion(null, secgroup.getName());
}
} catch (Exception e) {
}
try {
for (KeyPair pair : keyPairClient.describeKeyPairsInRegion(null))
- if (pair.getKeyName().startsWith("jclouds#" + tag) || pair.getKeyName().equals(tag)) {
+ if (pair.getKeyName().startsWith("jclouds#" + group) || pair.getKeyName().equals(group)) {
keyPairClient.deleteKeyPairInRegion(null, pair.getKeyName());
}
} catch (Exception e) {
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceTest.java
deleted file mode 100644
index 5e61476aea..0000000000
--- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceTest.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- *
- * Copyright (C) 2010 Cloud Conscious, LLC.
- *
- * ====================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-
-package org.jclouds.ec2.compute;
-
-import static org.easymock.EasyMock.expect;
-import static org.easymock.classextension.EasyMock.createMock;
-import static org.easymock.classextension.EasyMock.replay;
-import static org.easymock.classextension.EasyMock.verify;
-
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-
-import javax.inject.Provider;
-
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
-import org.jclouds.compute.strategy.DestroyNodeStrategy;
-import org.jclouds.compute.strategy.GetNodeMetadataStrategy;
-import org.jclouds.compute.strategy.InitializeRunScriptOnNodeOrPlaceInBadMap;
-import org.jclouds.compute.strategy.ListNodesStrategy;
-import org.jclouds.compute.strategy.RebootNodeStrategy;
-import org.jclouds.compute.strategy.ResumeNodeStrategy;
-import org.jclouds.compute.strategy.RunNodesAndAddToSetStrategy;
-import org.jclouds.compute.strategy.SuspendNodeStrategy;
-import org.jclouds.ec2.EC2Client;
-import org.jclouds.ec2.services.PlacementGroupClient;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-
-/**
- * @author Adrian Cole
- */
-@Test(groups = "unit")
-public class EC2ComputeServiceTest {
-
- @SuppressWarnings( { "unchecked" })
- public void testUnsupportedOperationOkForPlacementGroups() {
- EC2Client client = createMock(EC2Client.class);
- EC2ComputeService service = new EC2ComputeService(createMock(ComputeServiceContext.class), createMock(Map.class),
- createMock(Supplier.class), createMock(Supplier.class), createMock(Supplier.class),
- createMock(ListNodesStrategy.class), createMock(GetNodeMetadataStrategy.class),
- createMock(RunNodesAndAddToSetStrategy.class), createMock(RebootNodeStrategy.class),
- createMock(DestroyNodeStrategy.class), createMock(ResumeNodeStrategy.class),
- createMock(SuspendNodeStrategy.class), createMock(Provider.class), createMock(Provider.class),
- createMock(Predicate.class), createMock(Predicate.class), createMock(Predicate.class),
- createMock(InitializeRunScriptOnNodeOrPlaceInBadMap.Factory.class),
- createMock(Timeouts.class), createMock(ExecutorService.class), client, createMock(Map.class),
- createMock(Map.class), createMock(Map.class), createMock(Predicate.class));
-
- PlacementGroupClient placementClient = createMock(PlacementGroupClient.class);
-
- // setup expectations
- expect(client.getPlacementGroupServices()).andReturn(placementClient).atLeastOnce();
- expect(placementClient.describePlacementGroupsInRegion("us-west-1", "jclouds#tag#us-west-1")).andThrow(
- new UnsupportedOperationException());
-
- // replay mocks
- replay(client);
- replay(placementClient);
- // run
- service.deletePlacementGroup("us-west-1", "tag");
-
- // verify mocks
- verify(client);
- verify(placementClient);
-
- }
-}
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java
index 0a379d03bd..a5b3b0e463 100644
--- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java
+++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2TemplateBuilderTest.java
@@ -51,8 +51,8 @@ import org.jclouds.compute.domain.internal.TemplateBuilderImpl;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location;
+import org.jclouds.domain.LocationBuilder;
import org.jclouds.domain.LocationScope;
-import org.jclouds.domain.internal.LocationImpl;
import org.testng.annotations.Test;
import com.google.common.base.Function;
@@ -71,7 +71,8 @@ import com.google.common.collect.ImmutableSet;
* @author Oleksiy Yarmula
*/
public class EC2TemplateBuilderTest {
- private static final Location location = new LocationImpl(LocationScope.REGION, "us-east-1", "us east", null);
+ private static final Location location = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
+ .description("us-east-1").build();
public static final Hardware CC1_4XLARGE = cc1_4xlarge().location(location).supportsImageIds("us-east-1/cc-image")
.build();
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateTagLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java
similarity index 92%
rename from apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateTagLiveTest.java
rename to apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java
index b60e820ea8..504d3654ae 100644
--- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateTagLiveTest.java
+++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/TestCanRecreateGroupLiveTest.java
@@ -46,7 +46,7 @@ import com.google.inject.Module;
* @author Adrian Cole
*/
@Test(groups = "live")
-public class TestCanRecreateTagLiveTest {
+public class TestCanRecreateGroupLiveTest {
private ComputeServiceContext context;
protected String provider = "ec2";
@@ -85,21 +85,21 @@ public class TestCanRecreateTagLiveTest {
ImmutableSet. of(new Log4JLoggingModule(), new JschSshClientModule()), overrides);
}
- public void testCanRecreateTag() throws Exception {
+ public void testCanRecreateGroup() throws Exception {
String tag = PREFIX + "recreate";
- context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
+ context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
try {
Template template = context.getComputeService().templateBuilder().locationId("us-west-1").build();
- context.getComputeService().runNodesWithTag(tag, 1, template);
- context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
- context.getComputeService().runNodesWithTag(tag, 1, template);
+ context.getComputeService().createNodesInGroup(tag, 1, template);
+ context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
+ context.getComputeService().createNodesInGroup(tag, 1, template);
} catch (RunNodesException e) {
System.err.println(e.getNodeErrors().keySet());
Throwables.propagate(e);
} finally {
- context.getComputeService().destroyNodesMatching(NodePredicates.withTag(tag));
+ context.getComputeService().destroyNodesMatching(NodePredicates.inGroup(tag));
}
}
diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/CredentialsForInstanceTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/CredentialsForInstanceTest.java
deleted file mode 100644
index 4a41652874..0000000000
--- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/CredentialsForInstanceTest.java
+++ /dev/null
@@ -1,833 +0,0 @@
-/**
- *
- * Copyright (C) 2010 Cloud Conscious, LLC.
- *
- * ====================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ====================================================================
- */
-
-package org.jclouds.ec2.compute.functions;
-
-import org.jclouds.date.DateService;
-import org.jclouds.date.internal.SimpleDateFormatDateService;
-import org.testng.annotations.Test;
-
-/**
- * @author Adrian Cole
- */
-@Test(groups = "unit")
-public class CredentialsForInstanceTest {
-
- DateService dateService = new SimpleDateFormatDateService();
-
-// @SuppressWarnings({ "unchecked" })
-// @Test
-// public void testApplyWithEBSWhenBootIsInstanceStoreAndAvailabilityZoneNotFound() throws UnknownHostException {
-// EC2Client client = createMock(EC2Client.class);
-// AMIClient amiClient = createMock(AMIClient.class);
-// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
-// Map credentialsMap = createMock(Map.class);
-// ConcurrentMap imageMap = createMock(ConcurrentMap.class);
-// @Memoized Supplier> hardwares = Suppliers.> ofInstance(ImmutableSet
-// . of(m1_small().build()));
-// PopulateDefaultLoginCredentialsForImageStrategy credentialProvider = createMock(PopulateDefaultLoginCredentialsForImageStrategy.class);
-// RunningInstance instance = createMock(RunningInstance.class);
-// Image image = createMock(Image.class);
-//
-// expect(instance.getId()).andReturn("i-3d640055").atLeastOnce();
-// expect(instance.getGroupIds()).andReturn(ImmutableSet.of("default")).atLeastOnce();
-// expect(instance.getKeyName()).andReturn("jclouds#tag#us-east-1#50").atLeastOnce();
-// expect(instance.getInstanceState()).andReturn(InstanceState.RUNNING);
-//
-// Location location = new LocationImpl(LocationScope.ZONE, "us-east-1d", "description", null);
-// @Memoized Supplier> locations = Suppliers.> ofInstance(ImmutableSet
-// . of(location));
-// org.jclouds.compute.domain.Image jcImage = createMock(org.jclouds.compute.domain.Image.class);
-//
-// expect(instance.getIpAddress()).andReturn("174.129.1.50");
-// expect(instance.getPrivateIpAddress()).andReturn("10.202.117.241");
-//
-// expect(instance.getRegion()).andReturn(Region.US_EAST_1).atLeastOnce();
-//
-// expect(jcImage.getOperatingSystem()).andReturn(createMock(OperatingSystem.class)).atLeastOnce();
-//
-// expect(instance.getImageId()).andReturn("ami-1515f07c").atLeastOnce();
-// expect(imageMap.get(new RegionAndName(Region.US_EAST_1, "ami-1515f07c"))).andReturn(jcImage);
-//
-// expect(amiClient.describeImagesInRegion(Region.US_EAST_1, imageIds("ami-1515f07c"))).andReturn(
-// (Set) ImmutableSet. of(image));
-//
-// expect(credentialProvider.execute(image)).andReturn(new Credentials("user", "pass"));
-//
-// expect(credentialsMap.get(new RegionAndName(Region.US_EAST_1, "jclouds#tag#us-east-1#50"))).andReturn(
-// new KeyPair(Region.US_EAST_1, "jclouds#tag#us-east-1#50", "keyFingerprint", "pass"));
-//
-// expect(instance.getAvailabilityZone()).andReturn(AvailabilityZone.US_EAST_1A).atLeastOnce();
-//
-// expect(instance.getInstanceType()).andReturn(InstanceType.M1_SMALL).atLeastOnce();
-// expect(instance.getEbsBlockDevices()).andReturn(
-// ImmutableMap. of(
-// "/dev/sdg",
-// new EbsBlockDevice("vol-1f20d376", Attachment.Status.ATTACHED, dateService
-// .iso8601DateParse("2009-12-11T16:32:46.000Z"), false),
-// "/dev/sdj",
-// new EbsBlockDevice("vol-c0eb78aa", Attachment.Status.ATTACHED, dateService
-// .iso8601DateParse("2010-06-17T10:43:28.000Z"), false)));
-// expect(instance.getRootDeviceType()).andReturn(RootDeviceType.INSTANCE_STORE);
-// expect(instance.getRootDeviceName()).andReturn(null).atLeastOnce();
-//
-// replay(imageMap);
-// replay(client);
-// replay(amiClient);
-// replay(credentialsMap);
-// replay(credentialProvider);
-// replay(instance);
-// replay(jcImage);
-//
-// Function parser = new CredentialsForInstance(client, credentialsMap,
-// credentialProvider, imageMap, locations, hardwares);
-//
-// NodeMetadata metadata = parser.apply(instance);
-//
-// assertEquals(metadata.getTag(), "NOTAG#i-3d640055");
-// assertEquals(metadata.getLocation(), null);
-// assertEquals(metadata.getImageId(), "us-east-1/ami-1515f07c");
-// assertEquals(metadata.getHardware().getId(), "m1.small");
-// assertEquals(metadata.getHardware().getName(), "m1.small");
-// assertEquals(metadata.getHardware().getProviderId(), "m1.small");
-// assertEquals(metadata.getHardware().getProcessors(), ImmutableList. of(new Processor(1.0, 1.0)));
-// assertEquals(metadata.getHardware().getRam(), 1740);
-// assertEquals(metadata.getHardware().getVolumes(),
-// ImmutableList. of(new VolumeImpl(null, Volume.Type.LOCAL, 10.0f, "/dev/sda1", true, false),//
-// new VolumeImpl(null, Volume.Type.LOCAL, 150.0f, "/dev/sda2", false, false),//
-// new VolumeImpl("vol-1f20d376", Volume.Type.SAN, null, "/dev/sdg", false, true),//
-// new VolumeImpl("vol-c0eb78aa", Volume.Type.SAN, null, "/dev/sdj", false, true)));
-//
-// assertEquals(metadata.getCredentials(), new Credentials("user", "pass"));
-//
-// verify(imageMap);
-// verify(jcImage);
-// verify(client);
-// verify(amiClient);
-// verify(credentialsMap);
-// verify(credentialProvider);
-// verify(instance);
-//
-// }
-//
-// @SuppressWarnings({ "unchecked" })
-// @Test
-// public void testApplyForNovaWhereNullAvailabilityZoneIpAddressNoGroups() throws UnknownHostException {
-// EC2Client client = createMock(EC2Client.class);
-// AMIClient amiClient = createMock(AMIClient.class);
-// expect(client.getAMIServices()).andReturn(amiClient).atLeastOnce();
-// Map credentialsMap = createMock(Map.class);
-// ConcurrentMap imageMap = createMock(ConcurrentMap.class);
-// @Memoized Supplier