diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java index 731999357f..a134ec036e 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadata.java @@ -196,7 +196,7 @@ public class RunningInstanceToNodeMetadata implements Function * @author Adrian Cole */ -public class Reservation extends LinkedHashSet implements Comparable>, - Set { +public class Reservation extends ForwardingSet implements Comparable>{ + + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return Reservation. builder().fromReservation(this); + } + + public static class Builder { + private String region; + private String ownerId; + private String requesterId; + private String reservationId; + + private ImmutableSet.Builder instances = ImmutableSet. builder(); + private ImmutableSet.Builder groupNames = ImmutableSet. builder(); + + /** + * @see Reservation#getRegion() + */ + public Builder region(String region) { + this.region = region; + return this; + } + + /** + * @see Reservation#getOwnerId() + */ + public Builder ownerId(String ownerId) { + this.ownerId = ownerId; + return this; + } + + /** + * @see Reservation#getRequesterId() + */ + public Builder requesterId(String requesterId) { + this.requesterId = requesterId; + return this; + } + + /** + * @see Reservation#getReservationId() + */ + public Builder reservationId(String reservationId) { + this.reservationId = reservationId; + return this; + } + + /** + * @see Reservation#iterator + */ + public Builder instance(T instance) { + this.instances.add(checkNotNull(instance, "instance")); + return this; + } + + /** + * @see Reservation#iterator + */ + public Builder instances(Set instances) { + this.instances.addAll(checkNotNull(instances, "instances")); + return this; + } + + /** + * @see Reservation#getGroupNames() + */ + public Builder groupName(String groupName) { + this.groupNames.add(checkNotNull(groupName, "groupName")); + return this; + } + + /** + * @see Reservation#getGroupNames() + */ + public Builder groupNames(Iterable groupNames) { + this.groupNames = ImmutableSet. builder().addAll(checkNotNull(groupNames, "groupNames")); + return this; + } + + public Reservation build() { + return new Reservation(region, groupNames.build(), instances.build(), ownerId, requesterId, reservationId); + } + + public Builder fromReservation(Reservation in) { + return region(in.region).ownerId(in.ownerId).requesterId(in.requesterId).reservationId(in.reservationId) + .instances(in).groupNames(in.groupNames); + } + } - /** The serialVersionUID */ - private static final long serialVersionUID = -9051777593518861395L; private final String region; - private final Set groupIds = Sets.newLinkedHashSet(); + private final ImmutableSet groupNames; + private final ImmutableSet instances; @Nullable private final String ownerId; @Nullable @@ -48,16 +140,21 @@ public class Reservation extends LinkedHashSet imp @Nullable private final String reservationId; - public Reservation(String region, Iterable groupIds, Iterable instances, @Nullable String ownerId, + public Reservation(String region, Iterable groupNames, Iterable instances, @Nullable String ownerId, @Nullable String requesterId, @Nullable String reservationId) { this.region = checkNotNull(region, "region"); - Iterables.addAll(this.groupIds, checkNotNull(groupIds, "groupIds")); - Iterables.addAll(this, checkNotNull(instances, "instances")); + this.groupNames = ImmutableSet.copyOf(checkNotNull(groupNames, "groupNames")); + this.instances = ImmutableSet.copyOf(checkNotNull(instances, "instances")); this.ownerId = ownerId; this.requesterId = requesterId; this.reservationId = reservationId; } + @Override + protected Set delegate() { + return instances; + } + /** * Instances are tied to Availability Zones. However, the instance ID is tied to the Region. */ @@ -65,15 +162,19 @@ public class Reservation extends LinkedHashSet imp return region; } - public int compareTo(Reservation o) { - return (this == o) ? 0 : getReservationId().compareTo(o.getReservationId()); + /** + * @see #getGroupNames() + */ + @Deprecated + public Set getGroupIds() { + return groupNames; } - + /** * Names of the security groups. */ - public Set getGroupIds() { - return groupIds; + public Set getGroupNames() { + return groupNames; } /** @@ -84,7 +185,8 @@ public class Reservation extends LinkedHashSet imp } /** - * ID of the requester. + * The ID of the requester that launched the instances on your behalf (for example, AWS + * Management Console or Auto Scaling). */ public String getRequesterId() { return requesterId; @@ -99,51 +201,34 @@ public class Reservation extends LinkedHashSet imp @Override public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode()); - result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode()); - result = prime * result + ((region == null) ? 0 : region.hashCode()); - result = prime * result + ((requesterId == null) ? 0 : requesterId.hashCode()); - result = prime * result + ((reservationId == null) ? 0 : reservationId.hashCode()); - return result; + return Objects.hashCode(region, reservationId, super.hashCode()); } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) + if (obj == null || getClass() != obj.getClass()) return false; - if (getClass() != obj.getClass()) - return false; - Reservation other = (Reservation) obj; - if (groupIds == null) { - if (other.groupIds != null) - return false; - } else if (!groupIds.equals(other.groupIds)) - return false; - if (ownerId == null) { - if (other.ownerId != null) - return false; - } else if (!ownerId.equals(other.ownerId)) - return false; - if (region == null) { - if (other.region != null) - return false; - } else if (!region.equals(other.region)) - return false; - if (requesterId == null) { - if (other.requesterId != null) - return false; - } else if (!requesterId.equals(other.requesterId)) - return false; - if (reservationId == null) { - if (other.reservationId != null) - return false; - } else if (!reservationId.equals(other.reservationId)) - return false; - return true; + @SuppressWarnings("unchecked") + Reservation that = Reservation.class.cast(obj); + return super.equals(that) && Objects.equal(this.region, that.region) + && Objects.equal(this.reservationId, that.reservationId); + } + + /** + * {@inheritDoc} + */ + @Override + public String toString() { + return Objects.toStringHelper(this).omitNullValues().add("region", region).add("reservationId", reservationId) + .add("requesterId", requesterId).add("instances", instances).add("groupNames", groupNames).toString(); + } + + @Override + public int compareTo(Reservation other) { + return ComparisonChain.start().compare(region, other.region) + .compare(reservationId, other.reservationId, Ordering.natural().nullsLast()).result(); } } diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java index 0a11cb68ba..a1573793f0 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java @@ -26,9 +26,13 @@ import java.util.Set; import org.jclouds.javax.annotation.Nullable; +import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; +import com.google.common.collect.ComparisonChain; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; +import com.google.common.collect.Ordering; import com.google.common.collect.Sets; /** @@ -44,7 +48,7 @@ public class RunningInstance implements Comparable { public static class Builder { protected String region; - protected Set groupIds = Sets.newLinkedHashSet(); + protected Set groupNames = Sets.newLinkedHashSet(); protected String amiLaunchIndex; protected String dnsName; protected String imageId; @@ -72,14 +76,14 @@ public class RunningInstance implements Comparable { return this; } - public Builder groupIds(Iterable groupIds) { - this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds")); + public Builder groupNames(Iterable groupNames) { + this.groupNames = ImmutableSet.copyOf(checkNotNull(groupNames, "groupNames")); return this; } - public Builder groupId(String groupId) { - if (groupId != null) - this.groupIds.add(groupId); + public Builder groupName(String groupName) { + if (groupName != null) + this.groupNames.add(groupName); return this; } @@ -195,7 +199,7 @@ public class RunningInstance implements Comparable { } public RunningInstance build() { - return new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId, instanceId, instanceState, + return new RunningInstance(region, groupNames, amiLaunchIndex, dnsName, imageId, instanceId, instanceState, rawState, instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone, virtualizationType, platform, privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType, rootDeviceName, ebsBlockDevices); @@ -220,7 +224,7 @@ public class RunningInstance implements Comparable { } protected final String region; - protected final Set groupIds; + protected final Set groupNames; protected final String amiLaunchIndex; @Nullable protected final String dnsName; @@ -253,11 +257,7 @@ public class RunningInstance implements Comparable { protected final String rootDeviceName; protected final Map ebsBlockDevices; - public int compareTo(RunningInstance o) { - return (this == o) ? 0 : getId().compareTo(o.getId()); - } - - protected RunningInstance(String region, Iterable groupIds, @Nullable String amiLaunchIndex, + protected RunningInstance(String region, Iterable groupNames, @Nullable String amiLaunchIndex, @Nullable String dnsName, String imageId, String instanceId, InstanceState instanceState, String rawState, String instanceType, @Nullable String ipAddress, @Nullable String kernelId, @Nullable String keyName, Date launchTime, String availabilityZone, String virtualizationType, @Nullable String platform, @@ -286,7 +286,7 @@ public class RunningInstance implements Comparable { this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType for %s/%s", region, instanceId); this.rootDeviceName = rootDeviceName; this.ebsBlockDevices = ImmutableMap.copyOf(checkNotNull(ebsBlockDevices, "ebsBlockDevices for %s/%s", region, instanceId)); - this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds for %s/%s", region, instanceId)); + this.groupNames = ImmutableSet.copyOf(checkNotNull(groupNames, "groupNames for %s/%s", region, instanceId)); } /** @@ -443,160 +443,55 @@ public class RunningInstance implements Comparable { return ebsBlockDevices; } + /** + * @see #getGroupNames() + */ + @Deprecated + public Set getGroupIds() { + return getGroupNames(); + } + /** * Names of the security groups. */ - public Set getGroupIds() { - return groupIds; + public Set getGroupNames() { + return groupNames; } + @Override + public int compareTo(RunningInstance other) { + return ComparisonChain.start().compare(region, other.region).compare(instanceId, other.instanceId, Ordering.natural().nullsLast()).result(); + } + @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((amiLaunchIndex == null) ? 0 : amiLaunchIndex.hashCode()); - result = prime * result + ((availabilityZone == null) ? 0 : availabilityZone.hashCode()); - result = prime * result + ((dnsName == null) ? 0 : dnsName.hashCode()); - result = prime * result + ((ebsBlockDevices == null) ? 0 : ebsBlockDevices.hashCode()); - result = prime * result + ((groupIds == null) ? 0 : groupIds.hashCode()); - result = prime * result + ((imageId == null) ? 0 : imageId.hashCode()); - result = prime * result + ((instanceId == null) ? 0 : instanceId.hashCode()); - result = prime * result + ((instanceType == null) ? 0 : instanceType.hashCode()); - result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode()); - result = prime * result + ((kernelId == null) ? 0 : kernelId.hashCode()); - result = prime * result + ((keyName == null) ? 0 : keyName.hashCode()); - result = prime * result + ((launchTime == null) ? 0 : launchTime.hashCode()); - result = prime * result + ((platform == null) ? 0 : platform.hashCode()); - result = prime * result + ((privateDnsName == null) ? 0 : privateDnsName.hashCode()); - result = prime * result + ((privateIpAddress == null) ? 0 : privateIpAddress.hashCode()); - result = prime * result + ((ramdiskId == null) ? 0 : ramdiskId.hashCode()); - result = prime * result + ((region == null) ? 0 : region.hashCode()); - result = prime * result + ((rootDeviceName == null) ? 0 : rootDeviceName.hashCode()); - result = prime * result + ((rootDeviceType == null) ? 0 : rootDeviceType.hashCode()); - result = prime * result + ((virtualizationType == null) ? 0 : virtualizationType.hashCode()); - return result; + return Objects.hashCode(region, instanceId); } @Override public boolean equals(Object obj) { if (this == obj) return true; - if (obj == null) + if (obj == null || getClass() != obj.getClass()) return false; - if (getClass() != obj.getClass()) - return false; - RunningInstance other = (RunningInstance) obj; - if (amiLaunchIndex == null) { - if (other.amiLaunchIndex != null) - return false; - } else if (!amiLaunchIndex.equals(other.amiLaunchIndex)) - return false; - if (availabilityZone == null) { - if (other.availabilityZone != null) - return false; - } else if (!availabilityZone.equals(other.availabilityZone)) - return false; - if (dnsName == null) { - if (other.dnsName != null) - return false; - } else if (!dnsName.equals(other.dnsName)) - return false; - if (ebsBlockDevices == null) { - if (other.ebsBlockDevices != null) - return false; - } else if (!ebsBlockDevices.equals(other.ebsBlockDevices)) - return false; - if (groupIds == null) { - if (other.groupIds != null) - return false; - } else if (!groupIds.equals(other.groupIds)) - return false; - if (imageId == null) { - if (other.imageId != null) - return false; - } else if (!imageId.equals(other.imageId)) - return false; - if (instanceId == null) { - if (other.instanceId != null) - return false; - } else if (!instanceId.equals(other.instanceId)) - return false; - if (instanceType == null) { - if (other.instanceType != null) - return false; - } else if (!instanceType.equals(other.instanceType)) - return false; - if (ipAddress == null) { - if (other.ipAddress != null) - return false; - } else if (!ipAddress.equals(other.ipAddress)) - return false; - if (kernelId == null) { - if (other.kernelId != null) - return false; - } else if (!kernelId.equals(other.kernelId)) - return false; - if (keyName == null) { - if (other.keyName != null) - return false; - } else if (!keyName.equals(other.keyName)) - return false; - if (launchTime == null) { - if (other.launchTime != null) - return false; - } else if (!launchTime.equals(other.launchTime)) - return false; - if (platform == null) { - if (other.platform != null) - return false; - } else if (!platform.equals(other.platform)) - return false; - if (privateDnsName == null) { - if (other.privateDnsName != null) - return false; - } else if (!privateDnsName.equals(other.privateDnsName)) - return false; - if (privateIpAddress == null) { - if (other.privateIpAddress != null) - return false; - } else if (!privateIpAddress.equals(other.privateIpAddress)) - return false; - if (ramdiskId == null) { - if (other.ramdiskId != null) - return false; - } else if (!ramdiskId.equals(other.ramdiskId)) - return false; - if (region == null) { - if (other.region != null) - return false; - } else if (!region.equals(other.region)) - return false; - if (rootDeviceName == null) { - if (other.rootDeviceName != null) - return false; - } else if (!rootDeviceName.equals(other.rootDeviceName)) - return false; - if (rootDeviceType == null) { - if (other.rootDeviceType != null) - return false; - } else if (!rootDeviceType.equals(other.rootDeviceType)) - return false; - if (virtualizationType == null) { - if (other.virtualizationType != null) - return false; - } else if (!virtualizationType.equals(other.virtualizationType)) - return false; - return true; + RunningInstance that = RunningInstance.class.cast(obj); + return Objects.equal(this.region, that.region) && Objects.equal(this.instanceId, that.instanceId); + } + + protected ToStringHelper string() { + return Objects.toStringHelper(this).omitNullValues().add("region", region) + .add("availabilityZone", availabilityZone).add("id", instanceId).add("state", rawState) + .add("type", instanceType).add("virtualizationType", virtualizationType).add("imageId", imageId) + .add("ipAddress", ipAddress).add("dnsName", dnsName).add("privateIpAddress", privateIpAddress) + .add("privateDnsName", privateDnsName).add("keyName", keyName).add("groupNames", groupNames) + .add("platform", platform).add("launchTime", launchTime).add("rootDeviceName", rootDeviceName) + .add("rootDeviceType", rootDeviceType).add("ebsBlockDevices", ebsBlockDevices); } @Override public String toString() { - return "[region=" + region + ", availabilityZone=" + availabilityZone + ", instanceId=" + instanceId - + ", instanceState=" + rawState + ", instanceType=" + instanceType + ", virtualizationType=" - + virtualizationType + ", imageId=" + imageId + ", ipAddress=" + ipAddress + ", dnsName=" + dnsName - + ", privateIpAddress=" + privateIpAddress + ", privateDnsName=" + privateDnsName + ", keyName=" - + keyName + ", groupIds=" + groupIds + ", platform=" + platform + ", launchTime=" + launchTime + ", rootDeviceName=" - + rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", ebsBlockDevices=" + ebsBlockDevices + "]"; + return string().toString(); } + } 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 33cb755acd..56ef8201a5 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 @@ -80,7 +80,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque private String deviceName; // reservation stuff - private Set groupIds = Sets.newLinkedHashSet(); + private Set groupNames = Sets.newLinkedHashSet(); private String ownerId; private String requesterId; private String reservationId; @@ -111,7 +111,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque } else if (equalsOrSuffix(qName, "groupSet")) { inGroupSet = false; } else if (equalsOrSuffix(qName, "groupId")) { - groupIds.add(currentOrNull(currentText)); + groupNames.add(currentOrNull(currentText)); } else if (equalsOrSuffix(qName, "ownerId")) { ownerId = currentOrNull(currentText); } else if (equalsOrSuffix(qName, "requesterId")) { @@ -210,7 +210,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque } builder.region((region == null) ? defaultRegion.get() : region); - builder.groupIds(groupIds); + builder.groupNames(groupNames); } protected Builder builder() { @@ -229,9 +229,9 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null; if (region == null) region = defaultRegion.get(); - Reservation info = new Reservation(region, groupIds, instances, + Reservation info = new Reservation(region, groupNames, instances, ownerId, requesterId, reservationId); - this.groupIds = Sets.newLinkedHashSet(); + this.groupNames = Sets.newLinkedHashSet(); this.instances = Sets.newLinkedHashSet(); this.ownerId = null; this.requesterId = 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 b204a073ef..f8ae751245 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 @@ -151,7 +151,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { 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#" + group + "#" + assertEquals(Sets.newTreeSet(instance.getGroupNames()), ImmutableSortedSet. of("jclouds#" + group + "#" + instance.getRegion(), group)); // make sure our dummy group has no rules diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java index f677c320d6..75e5016c55 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/functions/RunningInstanceToNodeMetadataTest.java @@ -241,13 +241,13 @@ public class RunningInstanceToNodeMetadataTest { public void testGroupNameIsSetWhenCustomKeyNameIsSetAndSecurityGroupIsGenerated() { checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").keyName("custom-key") - .groupId("jclouds#groupname").build()); + .groupName("jclouds#groupname").build()); } @Test public void testGroupNameIsSetWhenCustomSecurityGroupIsSetAndKeyNameIsGenerated() { checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small") - .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").groupId("custom-sec") + .instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").groupName("custom-sec") .keyName("jclouds#groupname#23").build()); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java index ebdeba4a9f..24376d88cb 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/DescribeInstancesResponseHandlerTest.java @@ -70,7 +70,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> contents = ImmutableSet.of(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of(new RunningInstance.Builder().region( - defaultRegion).groupId("adriancole.ec2ingress").amiLaunchIndex("0").dnsName( + defaultRegion).groupName("adriancole.ec2ingress").amiLaunchIndex("0").dnsName( "ec2-174-129-81-68.compute-1.amazonaws.com").imageId("ami-82e4b5c7").instanceId("i-0799056f") .instanceState(InstanceState.RUNNING).rawState("running").instanceType(InstanceType.M1_SMALL) .ipAddress("174.129.81.68").kernelId("aki-a71cf9ce").keyName("adriancole.ec21").launchTime( @@ -83,7 +83,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> result = parseRunningInstances("/describe_instances_running.xml"); - assertEquals(result, contents); + assertEquals(result.toString(), contents.toString()); assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING); assertEquals(get(get(result, 0), 0).getRawState(), "running"); @@ -91,7 +91,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { public void testApplyInputStream() { Set> contents = ImmutableSet.of(new Reservation(defaultRegion, - ImmutableSet.of("default"), ImmutableSet.of(new RunningInstance.Builder().region(defaultRegion).groupId( + ImmutableSet.of("default"), ImmutableSet.of(new RunningInstance.Builder().region(defaultRegion).groupName( "default").amiLaunchIndex("23").dnsName("ec2-72-44-33-4.compute-1.amazonaws.com").imageId( "ami-6ea54007").instanceId("i-28a64341").instanceState(InstanceState.RUNNING).rawState( "running").instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName( @@ -101,7 +101,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { "10-251-50-132.ec2.internal")// product codes // ImmutableSet.of("774F4FF8") .ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE).build(), - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("23") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("23") .dnsName("ec2-72-44-33-6.compute-1.amazonaws.com").imageId("ami-6ea54007").instanceId( "i-28a64435").instanceState(InstanceState.RUNNING).rawState("running") .instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName( @@ -116,7 +116,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> result = parseRunningInstances("/describe_instances.xml"); - assertEquals(result, contents); + assertEquals(result.toString(), contents.toString()); assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING); assertEquals(get(get(result, 0), 0).getRawState(), "running"); @@ -126,7 +126,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> contents = ImmutableSet.of(new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), ImmutableSet.of(new RunningInstance.Builder().region( - defaultRegion).groupId("adriancole.ec2ebsingress").amiLaunchIndex("0").dnsName( + defaultRegion).groupName("adriancole.ec2ebsingress").amiLaunchIndex("0").dnsName( "ec2-75-101-203-146.compute-1.amazonaws.com").imageId("ami-849875ed").instanceId("i-e564438d") .instanceState(InstanceState.RUNNING).rawState("running").instanceType(InstanceType.M1_SMALL) .ipAddress("75.101.203.146").kernelId("aki-a71cf9ce") @@ -145,7 +145,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest { Set> result = parseRunningInstances("/describe_instances_ebs.xml"); - assertEquals(result, contents); + assertEquals(result.toString(), contents.toString()); assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING); assertEquals(get(get(result, 0), 0).getRawState(), "running"); } diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java index 0b23ebf203..1b37c5396e 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java @@ -65,19 +65,19 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { Reservation expected = new Reservation(defaultRegion, ImmutableSet .of("default"), ImmutableSet.of( - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("0") .imageId("ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, .availabilityZone("us-east-1b").build(), - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("1") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("1") .imageId("ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, .availabilityZone("us-east-1b").build(), - new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("2") + new RunningInstance.Builder().region(defaultRegion).groupName("default").amiLaunchIndex("2") .imageId("ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))// MonitoringState.ENABLED, @@ -96,9 +96,9 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { InputStream is = getClass().getResourceAsStream("/run_instances_cloudbridge.xml"); Reservation expected = new Reservation(defaultRegion, ImmutableSet - .of("default"), ImmutableSet.of( + .of("jclouds#greenqloud-computeblock"), ImmutableSet.of( - new RunningInstance.Builder().region(defaultRegion).groupId("jclouds#greenqloud-computeblock").amiLaunchIndex("0") + new RunningInstance.Builder().region(defaultRegion).groupName("jclouds#greenqloud-computeblock").amiLaunchIndex("0") .imageId("qmi-9ac92558").instanceId("i-01b0dac3").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("jclouds#greenqloud-computeblock#35") .launchTime(dateService.iso8601DateParse("2012-06-15T19:06:35.000+00:00")) diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java index 9cb43cb319..06605b208f 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/domain/AWSRunningInstance.java @@ -31,7 +31,7 @@ import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.javax.annotation.Nullable; -import com.google.common.base.Objects; +import com.google.common.base.Objects.ToStringHelper; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; @@ -241,13 +241,13 @@ public class AWSRunningInstance extends RunningInstance { } @Override - public Builder groupId(String groupId) { - return Builder.class.cast(super.groupId(groupId)); + public Builder groupName(String groupName) { + return Builder.class.cast(super.groupName(groupName)); } @Override - public Builder groupIds(Iterable groupIds) { - return Builder.class.cast(super.groupIds(groupIds)); + public Builder groupNames(Iterable groupNames) { + return Builder.class.cast(super.groupNames(groupNames)); } @Override @@ -364,74 +364,10 @@ public class AWSRunningInstance extends RunningInstance { } @Override - public int hashCode() { - final int prime = 31; - int result = super.hashCode(); - result = prime * result + ((placementGroup == null) ? 0 : placementGroup.hashCode()); - result = prime * result + ((productCodes == null) ? 0 : productCodes.hashCode()); - result = prime * result + ((spotInstanceRequestId == null) ? 0 : spotInstanceRequestId.hashCode()); - result = prime * result + ((subnetId == null) ? 0 : subnetId.hashCode()); - result = prime * result + ((vpcId == null) ? 0 : vpcId.hashCode()); - result = prime * result + ((hypervisor == null) ? 0 : hypervisor.hashCode()); - result = prime * result + ((tags == null) ? 0 : tags.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; - AWSRunningInstance other = (AWSRunningInstance) obj; - if (placementGroup == null) { - if (other.placementGroup != null) - return false; - } else if (!placementGroup.equals(other.placementGroup)) - return false; - if (productCodes == null) { - if (other.productCodes != null) - return false; - } else if (!productCodes.equals(other.productCodes)) - return false; - if (spotInstanceRequestId == null) { - if (other.spotInstanceRequestId != null) - return false; - } else if (!spotInstanceRequestId.equals(other.spotInstanceRequestId)) - return false; - if (subnetId == null) { - if (other.subnetId != null) - return false; - } else if (!subnetId.equals(other.subnetId)) - return false; - if (vpcId == null) { - if (other.vpcId != null) - return false; - } else if (!vpcId.equals(other.vpcId)) - return false; - if (tags == null) { - if (other.tags != null) - return false; - } else if (!tags.equals(other.tags)) - return false; - if (!Objects.equal(hypervisor, other.hypervisor)) - return false; - return true; - } - - @Override - public String toString() { - return "[region=" + region + ", availabilityZone=" + availabilityZone + ", instanceId=" + instanceId - + ", instanceState=" + rawState + ", instanceType=" + instanceType + ", virtualizationType=" - + virtualizationType + ", imageId=" + imageId + ", ipAddress=" + ipAddress + ", dnsName=" + dnsName - + ", privateIpAddress=" + privateIpAddress + ", privateDnsName=" + privateDnsName + ", keyName=" - + keyName + ", platform=" + platform + ", launchTime=" + launchTime + ", rootDeviceName=" - + rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", ebsBlockDevices=" + ebsBlockDevices - + ", monitoringState=" + monitoringState + ", placementGroup=" + placementGroup + ", productCodes=" - + productCodes + ", spotInstanceRequestId=" + spotInstanceRequestId + ", subnetId=" + subnetId - + ", hypervisor=" + hypervisor + ", vpcId=" + vpcId + ", tags=" + tags + "]"; + protected ToStringHelper string() { + return super.string().add("monitoringState", monitoringState).add("placementGroup", placementGroup) + .add("subnetId", subnetId).add("spotInstanceRequestId", spotInstanceRequestId).add("vpcId", vpcId) + .add("hypervisor", hypervisor).add("tags", tags); } } diff --git a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java index 5c7fe7d352..854000b8d1 100644 --- a/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java +++ b/providers/aws-ec2/src/main/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstance.java @@ -52,7 +52,7 @@ public class SpotInstanceRequestToAWSRunningInstance implements Function of("jclouds#" + group, group)); + assertEquals(newTreeSet(instance.getGroupNames()), ImmutableSortedSet. of("jclouds#" + group, group)); // make sure our dummy group has no rules SecurityGroup secgroup = getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(instance diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java index 9d52e60397..3a2fc7726c 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/compute/IncidentalResourcesGetCleanedUpLiveTest.java @@ -117,8 +117,8 @@ public class IncidentalResourcesGetCleanedUpLiveTest extends BaseComputeServiceC assertNotNull(instance1.getKeyName()); assertEquals(instance1.getRegion(), instance2.getRegion(), "Nodes are not in the same region"); assertEquals(instance1.getKeyName(), instance2.getKeyName(), "Nodes do not have same key-pair name"); - assertEquals(instance1.getGroupIds(), instance2.getGroupIds(), "Nodes are not in the same group"); - assertEquals(instance1.getGroupIds(), ImmutableSet.of(expectedSecurityGroupName), "Nodes are not in the expected security group"); + assertEquals(instance1.getGroupNames(), instance2.getGroupNames(), "Nodes are not in the same group"); + assertEquals(instance1.getGroupNames(), ImmutableSet.of(expectedSecurityGroupName), "Nodes are not in the expected security group"); // Assert a single key-pair and security group has been created String expectedKeyPairName = instance1.getKeyName(); diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java index 4324994036..76c1ce9df7 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/functions/SpotInstanceRequestToAWSRunningInstanceTest.java @@ -66,7 +66,7 @@ public class SpotInstanceRequestToAWSRunningInstanceTest { AWSRunningInstance.builder().region("us-east-1").instanceId("sir-228e6406") .spotInstanceRequestId("sir-228e6406").instanceState(InstanceState.PENDING) .rawState("open").imageId("ami-595a0a1c") - .groupId("default").instanceType("m1.large") + .groupName("default").instanceType("m1.large") .tag("foo", "bar") .tag("empty", "") .hypervisor(Hypervisor.XEN) diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java new file mode 100644 index 0000000000..646853fcfd --- /dev/null +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/parse/DescribeInstancesResponseTest.java @@ -0,0 +1,114 @@ +/** + * Licensed to jclouds, Inc. (jclouds) under one or more + * contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. jclouds 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.aws.ec2.parse; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.util.Set; + +import org.jclouds.aws.ec2.domain.AWSRunningInstance; +import org.jclouds.aws.ec2.domain.MonitoringState; +import org.jclouds.aws.ec2.xml.AWSDescribeInstancesResponseHandler; +import org.jclouds.date.DateService; +import org.jclouds.ec2.domain.Attachment; +import org.jclouds.ec2.domain.BlockDevice; +import org.jclouds.ec2.domain.Hypervisor; +import org.jclouds.ec2.domain.InstanceState; +import org.jclouds.ec2.domain.Reservation; +import org.jclouds.ec2.domain.RootDeviceType; +import org.jclouds.ec2.domain.RunningInstance; +import org.jclouds.ec2.xml.BaseEC2HandlerTest; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of {@code AWSDescribeInstancesResponseHandler} + * + * @author Adrian Cole + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "AWSDescribeInstancesResponseHandlerTest") +public class DescribeInstancesResponseTest extends BaseEC2HandlerTest { + + private DateService dateService; + + @BeforeTest + @Override + protected void setUpInjector() { + super.setUpInjector(); + dateService = injector.getInstance(DateService.class); + assert dateService != null; + } + + public void test() { + InputStream is = getClass().getResourceAsStream("/describe_instances_pending.xml"); + + Set> expected = expected(); + + AWSDescribeInstancesResponseHandler handler = injector.getInstance(AWSDescribeInstancesResponseHandler.class); + Set> result = factory.create(handler).parse(is); + + assertEquals(result.toString(), expected.toString()); + + } + + public Set> expected() { + return ImmutableSet.of(Reservation.builder() + .region(defaultRegion) + .reservationId("r-3f056a58") + .ownerId("095072994936") +// sg-f788299f + .groupName("launchpad_sec_group") +// sg-7e512116 + .groupName("jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae") + .instance(AWSRunningInstance.builder() + .region(defaultRegion) + .instanceId("i-32451248") + .imageId("ami-bf8131d6") + .rawState("pending") + .instanceState(InstanceState.PENDING) + .privateDnsName("ip-10-194-149-220.ec2.internal") + .dnsName("ec2-23-20-17-42.compute-1.amazonaws.com") + .keyName("jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae#105") + .amiLaunchIndex("0") + .instanceType("c1.medium") + .launchTime(dateService.iso8601DateParse("2012-09-14T20:01:34.000Z")) + .availabilityZone("us-east-1d") +// .tenancy("default") + .kernelId("aki-825ea7eb") + .monitoringState(MonitoringState.DISABLED) + .privateIpAddress("10.194.149.220") + .ipAddress("23.20.17.42") + .securityGroupIdToName("sg-f788299f", "launchpad_sec_group") + .securityGroupIdToName("sg-7e512116", "jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae") +// .architecture("x86_64") + .rootDeviceType(RootDeviceType.EBS) + .rootDeviceName("/dev/sda1") + .device("/dev/sda1", new BlockDevice("vol-b2beb3c9", Attachment.Status.ATTACHING, dateService.iso8601DateParse("2012-09-14T20:01:37.000Z"), true)) + .virtualizationType("paravirtual") + .tag("Name", "4c858090-f66c-4225-aa57-6fcaa42198ae-32451248") + .hypervisor(Hypervisor.XEN) + .build()).build()); + } + +} diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java index 25aa26bc7c..c247bf23a0 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSDescribeInstancesResponseHandlerTest.java @@ -31,7 +31,6 @@ import org.jclouds.ec2.domain.Attachment; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.Hypervisor; import org.jclouds.ec2.domain.InstanceState; -import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; @@ -71,44 +70,13 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest assert dateService != null; } - public void testWhenRunning() throws UnknownHostException { - - Set> contents = ImmutableSet.of( - new Reservation(defaultRegion, ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of( - new AWSRunningInstance.Builder() - .region(defaultRegion) - .groupId("adriancole.ec2ingress") - .amiLaunchIndex("0") - .dnsName("ec2-174-129-81-68.compute-1.amazonaws.com") - .imageId("ami-82e4b5c7") - .instanceId("i-0799056f") - .instanceState(InstanceState.RUNNING) - .rawState("running") - .instanceType(InstanceType.M1_SMALL) - .ipAddress("174.129.81.68") - .kernelId("aki-a71cf9ce") - .keyName("adriancole.ec21") - .launchTime(dateService.iso8601DateParse("2009-11-09T03:00:34.000Z")) - .monitoringState(MonitoringState.DISABLED) - .availabilityZone("us-east-1c") - .virtualizationType("paravirtual") - .privateDnsName("ip-10-243-42-70.ec2.internal") - .privateIpAddress("10.243.42.70") - .ramdiskId("ari-a51cf9cc") - .rootDeviceType(RootDeviceType.INSTANCE_STORE) - .hypervisor(Hypervisor.XEN) - .build()), - "993194456877", null, "r-a3c508cb")); - - Set> result = parseAWSRunningInstances("/describe_instances_running.xml"); - - assertEquals(result.toString(), contents.toString()); - } public void testWhenRunningLatest() throws UnknownHostException { - Set> contents = ImmutableSet.of(new Reservation( - defaultRegion, ImmutableSet.of("jclouds#ec2-s#us-east-1"), ImmutableSet.of( - new AWSRunningInstance.Builder() + Set> contents = ImmutableSet.of(Reservation.builder() + .region(defaultRegion) + .reservationId("r-0f4c2160") + .groupName("jclouds#zkclustertest#us-east-1") + .instance(AWSRunningInstance.builder() .region(defaultRegion) .instanceId("i-911444f0") .imageId("ami-63be790a") @@ -135,8 +103,8 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest new BlockDevice("vol-5829fc32", Attachment.Status.ATTACHED, dateService .iso8601DateParse("2011-08-16T13:41:19.000Z"), true)) .hypervisor(Hypervisor.XEN) - .virtualizationType("paravirtual").build(),// - new AWSRunningInstance.Builder() + .virtualizationType("paravirtual").build()) + .instance(AWSRunningInstance.builder() .region(defaultRegion) .instanceId("i-931444f2") .imageId("ami-63be790a") @@ -162,7 +130,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest new BlockDevice("vol-5029fc3a", Attachment.Status.ATTACHED, dateService .iso8601DateParse("2011-08-16T13:41:19.000Z"), true)) .hypervisor(Hypervisor.XEN) - .virtualizationType("paravirtual").build()), defaultRegion, defaultRegion, defaultRegion)); + .virtualizationType("paravirtual").build()).build()); Set> result = parseAWSRunningInstances("/describe_instances_latest.xml"); @@ -175,76 +143,6 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest parseAWSRunningInstances("/describe_instances_3.xml"); } - public void testApplyInputStream() { - Set> contents = ImmutableSet.of(new Reservation( - defaultRegion, ImmutableSet.of("default"), ImmutableSet.of( - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("23") - .dnsName("ec2-72-44-33-4.compute-1.amazonaws.com").imageId("ami-6ea54007") - .instanceId("i-28a64341").instanceState(InstanceState.RUNNING).rawState("running") - .instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name") - .launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")) - .monitoringState(MonitoringState.DISABLED).availabilityZone("us-east-1b") - .virtualizationType("paravirtual").privateDnsName("10-251-50-132.ec2.internal") - .productCode("774F4FF8").ramdiskId("ari-badbad00") - .hypervisor(Hypervisor.XEN) - .rootDeviceType(RootDeviceType.INSTANCE_STORE).build(), - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("23") - .dnsName("ec2-72-44-33-6.compute-1.amazonaws.com").imageId("ami-6ea54007") - .instanceId("i-28a64435").instanceState(InstanceState.RUNNING).rawState("running") - .instanceType(InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name") - .launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z")) - .monitoringState(MonitoringState.DISABLED).availabilityZone("us-east-1b") - .virtualizationType("paravirtual").privateDnsName("10-251-50-134.ec2.internal") - .productCode("774F4FF8").ramdiskId("ari-badbad00") - .hypervisor(Hypervisor.XEN) - .rootDeviceType(RootDeviceType.INSTANCE_STORE).build()), "UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", - null, "r-44a5402d")); - - Set> result = parseAWSRunningInstances("/describe_instances.xml"); - - assertEquals(result.toString(), contents.toString()); - } - - public void testEBS() throws UnknownHostException { - - Set> contents = ImmutableSet.of(new Reservation( - defaultRegion, ImmutableSet.of("adriancole.ec2ebsingress"), ImmutableSet - .of(new AWSRunningInstance.Builder() - .region(defaultRegion) - .groupId("adriancole.ec2ebsingress") - .amiLaunchIndex("0") - .dnsName("ec2-75-101-203-146.compute-1.amazonaws.com") - .imageId("ami-849875ed") - .instanceId("i-e564438d") - .instanceState(InstanceState.RUNNING) - .rawState("running") - .instanceType(InstanceType.M1_SMALL) - .ipAddress("75.101.203.146") - .kernelId("aki-a71cf9ce") - .keyName("adriancole.ec2ebs1") - .launchTime(dateService.iso8601DateParse("2009-12-30T04:06:23.000Z")) - .monitoringState(MonitoringState.DISABLED) - .availabilityZone("us-east-1b") - .placementGroup("placement") - .virtualizationType("hvm") - .privateDnsName("domU-12-31-39-09-CE-53.compute-1.internal") - .privateIpAddress("10.210.209.157") - .ramdiskId("ari-a51cf9cc") - .hypervisor(Hypervisor.XEN) - .rootDeviceType(RootDeviceType.EBS) - .rootDeviceName("/dev/sda1") - .hypervisor(Hypervisor.XEN) - .device( - "/dev/sda1", - new BlockDevice("vol-dc6ca8b5", Attachment.Status.ATTACHED, dateService - .iso8601DateParse("2009-12-30T04:06:29.000Z"), true)).build()), "993194456877", - null, "r-596dd731")); - - Set> result = parseAWSRunningInstances("/describe_instances_ebs.xml"); - - assertEquals(result.toString(), contents.toString()); - } - static ParseSax>> createParser() { Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() { diff --git a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java index 09547f97e9..73d4a37eaa 100644 --- a/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java +++ b/providers/aws-ec2/src/test/java/org/jclouds/aws/ec2/xml/AWSRunInstancesResponseHandlerTest.java @@ -44,7 +44,6 @@ import org.testng.annotations.Test; import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.TypeLiteral; @@ -82,28 +81,25 @@ public class AWSRunInstancesResponseHandlerTest extends BaseEC2HandlerTest { InputStream is = getClass().getResourceAsStream("/run_instances.xml"); - Reservation expected = new Reservation(defaultRegion, - ImmutableSet.of("default"), ImmutableSet.of( - - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0").imageId( + Reservation expected = Reservation.builder() + .region(defaultRegion) + .instance(AWSRunningInstance.builder().region(defaultRegion).groupName("default").amiLaunchIndex("0").imageId( "ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).hypervisor(Hypervisor.XEN) - .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build(), - - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("1").imageId( + .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) + .instance(AWSRunningInstance.builder().region(defaultRegion).groupName("default").amiLaunchIndex("1").imageId( "ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).hypervisor(Hypervisor.XEN) - .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build(), - - new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("2").imageId( + .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) + .instance(AWSRunningInstance.builder().region(defaultRegion).groupName("default").amiLaunchIndex("2").imageId( "ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).rawState( "pending").instanceType(InstanceType.M1_SMALL).keyName("example-key-name").launchTime( dateService.iso8601DateParse("2007-08-07T11:51:50.000Z")).hypervisor(Hypervisor.XEN) .monitoringState(MonitoringState.ENABLED).availabilityZone("us-east-1b").build()) - - , "AIDADH4IGTRXXKCD", null, "r-47a5402e"); + .ownerId("AIDADH4IGTRXXKCD") + .reservationId("r-47a5402e").build(); AWSRunInstancesResponseHandler handler = injector.getInstance(AWSRunInstancesResponseHandler.class); addDefaultRegionToHandler(handler); diff --git a/providers/aws-ec2/src/test/resources/describe_instances_pending.xml b/providers/aws-ec2/src/test/resources/describe_instances_pending.xml new file mode 100644 index 0000000000..92f9f4ebe4 --- /dev/null +++ b/providers/aws-ec2/src/test/resources/describe_instances_pending.xml @@ -0,0 +1,82 @@ + + + dcd37ecf-e5b6-462b-99a8-112427b3e3a2 + + + r-3f056a58 + 095072994936 + + + sg-f788299f + launchpad_sec_group + + + sg-7e512116 + jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae + + + + + i-32451248 + ami-bf8131d6 + + 0 + pending + + ip-10-194-149-220.ec2.internal + ec2-23-20-17-42.compute-1.amazonaws.com + + jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae#105 + 0 + + c1.medium + 2012-09-14T20:01:34.000Z + + us-east-1d + + default + + aki-825ea7eb + + disabled + + 10.194.149.220 + 23.20.17.42 + + + sg-f788299f + launchpad_sec_group + + + sg-7e512116 + jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae + + + x86_64 + ebs + /dev/sda1 + + + /dev/sda1 + + vol-b2beb3c9 + attaching + 2012-09-14T20:01:37.000Z + true + + + + paravirtual + + + + Name + 4c858090-f66c-4225-aa57-6fcaa42198ae-32451248 + + + xen + + + + + \ No newline at end of file