mirror of https://github.com/apache/jclouds.git
cleaned ec2 instance type
This commit is contained in:
parent
7a3318d1ca
commit
0b31622267
|
@ -196,7 +196,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
|
|||
|
||||
@VisibleForTesting
|
||||
String getGroupForInstance(final RunningInstance instance) {
|
||||
String group = parseGroupFrom(instance, instance.getGroupIds());
|
||||
String group = parseGroupFrom(instance, instance.getGroupNames());
|
||||
if(group == null && instance.getKeyName() != null) {
|
||||
// when not using a generated security group, e.g. in VPC, try from key:
|
||||
group = parseGroupFrom(instance, Sets.newHashSet(instance.getKeyName()));
|
||||
|
|
|
@ -20,27 +20,119 @@ package org.jclouds.ec2.domain;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ComparisonChain;
|
||||
import com.google.common.collect.ForwardingSet;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Ordering;
|
||||
|
||||
/**
|
||||
*
|
||||
* @see <a href="http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-ReservationInfoType.html"
|
||||
* @see <a href=
|
||||
* "http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-ItemType-ReservationInfoType.html"
|
||||
* />
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Reservation<T extends RunningInstance> extends LinkedHashSet<T> implements Comparable<Reservation<T>>,
|
||||
Set<T> {
|
||||
public class Reservation<T extends RunningInstance> extends ForwardingSet<T> implements Comparable<Reservation<T>>{
|
||||
|
||||
public static <T extends RunningInstance> Builder<T> builder() {
|
||||
return new Builder<T>();
|
||||
}
|
||||
|
||||
public Builder<T> toBuilder() {
|
||||
return Reservation.<T> builder().fromReservation(this);
|
||||
}
|
||||
|
||||
public static class Builder<T extends RunningInstance> {
|
||||
private String region;
|
||||
private String ownerId;
|
||||
private String requesterId;
|
||||
private String reservationId;
|
||||
|
||||
private ImmutableSet.Builder<T> instances = ImmutableSet.<T> builder();
|
||||
private ImmutableSet.Builder<String> groupNames = ImmutableSet.<String> builder();
|
||||
|
||||
/**
|
||||
* @see Reservation#getRegion()
|
||||
*/
|
||||
public Builder<T> region(String region) {
|
||||
this.region = region;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#getOwnerId()
|
||||
*/
|
||||
public Builder<T> ownerId(String ownerId) {
|
||||
this.ownerId = ownerId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#getRequesterId()
|
||||
*/
|
||||
public Builder<T> requesterId(String requesterId) {
|
||||
this.requesterId = requesterId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#getReservationId()
|
||||
*/
|
||||
public Builder<T> reservationId(String reservationId) {
|
||||
this.reservationId = reservationId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#iterator
|
||||
*/
|
||||
public Builder<T> instance(T instance) {
|
||||
this.instances.add(checkNotNull(instance, "instance"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#iterator
|
||||
*/
|
||||
public Builder<T> instances(Set<T> instances) {
|
||||
this.instances.addAll(checkNotNull(instances, "instances"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#getGroupNames()
|
||||
*/
|
||||
public Builder<T> groupName(String groupName) {
|
||||
this.groupNames.add(checkNotNull(groupName, "groupName"));
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see Reservation#getGroupNames()
|
||||
*/
|
||||
public Builder<T> groupNames(Iterable<String> groupNames) {
|
||||
this.groupNames = ImmutableSet.<String> builder().addAll(checkNotNull(groupNames, "groupNames"));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Reservation<T> build() {
|
||||
return new Reservation<T>(region, groupNames.build(), instances.build(), ownerId, requesterId, reservationId);
|
||||
}
|
||||
|
||||
public Builder<T> fromReservation(Reservation<T> 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<String> groupIds = Sets.newLinkedHashSet();
|
||||
private final ImmutableSet<String> groupNames;
|
||||
private final ImmutableSet<T> instances;
|
||||
@Nullable
|
||||
private final String ownerId;
|
||||
@Nullable
|
||||
|
@ -48,16 +140,21 @@ public class Reservation<T extends RunningInstance> extends LinkedHashSet<T> imp
|
|||
@Nullable
|
||||
private final String reservationId;
|
||||
|
||||
public Reservation(String region, Iterable<String> groupIds, Iterable<T> instances, @Nullable String ownerId,
|
||||
public Reservation(String region, Iterable<String> groupNames, Iterable<T> 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<T> 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<T extends RunningInstance> extends LinkedHashSet<T> imp
|
|||
return region;
|
||||
}
|
||||
|
||||
public int compareTo(Reservation<T> o) {
|
||||
return (this == o) ? 0 : getReservationId().compareTo(o.getReservationId());
|
||||
/**
|
||||
* @see #getGroupNames()
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<String> getGroupIds() {
|
||||
return groupNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the security groups.
|
||||
*/
|
||||
public Set<String> getGroupIds() {
|
||||
return groupIds;
|
||||
public Set<String> getGroupNames() {
|
||||
return groupNames;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +185,8 @@ public class Reservation<T extends RunningInstance> extends LinkedHashSet<T> 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<T extends RunningInstance> extends LinkedHashSet<T> 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<T> 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<T> other) {
|
||||
return ComparisonChain.start().compare(region, other.region)
|
||||
.compare(reservationId, other.reservationId, Ordering.natural().nullsLast()).result();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<RunningInstance> {
|
|||
|
||||
public static class Builder {
|
||||
protected String region;
|
||||
protected Set<String> groupIds = Sets.newLinkedHashSet();
|
||||
protected Set<String> groupNames = Sets.newLinkedHashSet();
|
||||
protected String amiLaunchIndex;
|
||||
protected String dnsName;
|
||||
protected String imageId;
|
||||
|
@ -72,14 +76,14 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder groupIds(Iterable<String> groupIds) {
|
||||
this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds"));
|
||||
public Builder groupNames(Iterable<String> 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<RunningInstance> {
|
|||
}
|
||||
|
||||
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<RunningInstance> {
|
|||
}
|
||||
|
||||
protected final String region;
|
||||
protected final Set<String> groupIds;
|
||||
protected final Set<String> groupNames;
|
||||
protected final String amiLaunchIndex;
|
||||
@Nullable
|
||||
protected final String dnsName;
|
||||
|
@ -253,11 +257,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
|
|||
protected final String rootDeviceName;
|
||||
protected final Map<String, BlockDevice> ebsBlockDevices;
|
||||
|
||||
public int compareTo(RunningInstance o) {
|
||||
return (this == o) ? 0 : getId().compareTo(o.getId());
|
||||
}
|
||||
|
||||
protected RunningInstance(String region, Iterable<String> groupIds, @Nullable String amiLaunchIndex,
|
||||
protected RunningInstance(String region, Iterable<String> 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<RunningInstance> {
|
|||
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<RunningInstance> {
|
|||
return ebsBlockDevices;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getGroupNames()
|
||||
*/
|
||||
@Deprecated
|
||||
public Set<String> getGroupIds() {
|
||||
return getGroupNames();
|
||||
}
|
||||
|
||||
/**
|
||||
* Names of the security groups.
|
||||
*/
|
||||
public Set<String> getGroupIds() {
|
||||
return groupIds;
|
||||
public Set<String> 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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -80,7 +80,7 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
|
|||
private String deviceName;
|
||||
|
||||
// reservation stuff
|
||||
private Set<String> groupIds = Sets.newLinkedHashSet();
|
||||
private Set<String> groupNames = Sets.newLinkedHashSet();
|
||||
private String ownerId;
|
||||
private String requesterId;
|
||||
private String reservationId;
|
||||
|
@ -111,7 +111,7 @@ public abstract class BaseReservationHandler<T> 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<T> 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<T> extends HandlerForGeneratedReque
|
|||
String region = getRequest() != null ? AWSUtils.findRegionInArgsOrNull(getRequest()) : null;
|
||||
if (region == null)
|
||||
region = defaultRegion.get();
|
||||
Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, groupIds, instances,
|
||||
Reservation<? extends RunningInstance> info = new Reservation<RunningInstance>(region, groupNames, instances,
|
||||
ownerId, requesterId, reservationId);
|
||||
this.groupIds = Sets.newLinkedHashSet();
|
||||
this.groupNames = Sets.newLinkedHashSet();
|
||||
this.instances = Sets.newLinkedHashSet();
|
||||
this.ownerId = null;
|
||||
this.requesterId = null;
|
||||
|
|
|
@ -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.<String> of("jclouds#" + group + "#"
|
||||
assertEquals(Sets.newTreeSet(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group + "#"
|
||||
+ instance.getRegion(), group));
|
||||
|
||||
// make sure our dummy group has no rules
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
|
||||
Set<Reservation<RunningInstance>> contents = ImmutableSet.of(new Reservation<RunningInstance>(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<Reservation<? extends RunningInstance>> 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<Reservation<RunningInstance>> contents = ImmutableSet.of(new Reservation<RunningInstance>(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<Reservation<? extends RunningInstance>> 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<Reservation<RunningInstance>> contents = ImmutableSet.of(new Reservation<RunningInstance>(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<Reservation<? extends RunningInstance>> 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");
|
||||
}
|
||||
|
|
|
@ -65,19 +65,19 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
|
|||
Reservation<? extends RunningInstance> expected = new Reservation<RunningInstance>(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<? extends RunningInstance> expected = new Reservation<RunningInstance>(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"))
|
||||
|
|
|
@ -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<String> groupIds) {
|
||||
return Builder.class.cast(super.groupIds(groupIds));
|
||||
public Builder groupNames(Iterable<String> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ public class SpotInstanceRequestToAWSRunningInstance implements Function<SpotIns
|
|||
builder.availabilityZone(spec.getAvailabilityZone());
|
||||
// TODO convert
|
||||
// builder.devices(spec.getBlockDeviceMappings());
|
||||
builder.groupIds(spec.getSecurityGroupNames());
|
||||
builder.groupNames(spec.getSecurityGroupNames());
|
||||
builder.imageId(spec.getImageId());
|
||||
builder.instanceType(spec.getInstanceType());
|
||||
builder.kernelId(spec.getKernelId());
|
||||
|
|
|
@ -187,7 +187,7 @@ public class AWSEC2ComputeServiceLiveTest extends EC2ComputeServiceLiveTest {
|
|||
}
|
||||
|
||||
// make sure we made our dummy group and also let in the user's group
|
||||
assertEquals(newTreeSet(instance.getGroupIds()), ImmutableSortedSet.<String> of("jclouds#" + group, group));
|
||||
assertEquals(newTreeSet(instance.getGroupNames()), ImmutableSortedSet.<String> of("jclouds#" + group, group));
|
||||
|
||||
// make sure our dummy group has no rules
|
||||
SecurityGroup secgroup = getOnlyElement(securityGroupClient.describeSecurityGroupsInRegion(instance
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<Reservation<AWSRunningInstance>> expected = expected();
|
||||
|
||||
AWSDescribeInstancesResponseHandler handler = injector.getInstance(AWSDescribeInstancesResponseHandler.class);
|
||||
Set<Reservation<? extends RunningInstance>> result = factory.create(handler).parse(is);
|
||||
|
||||
assertEquals(result.toString(), expected.toString());
|
||||
|
||||
}
|
||||
|
||||
public Set<Reservation<AWSRunningInstance>> expected() {
|
||||
return ImmutableSet.of(Reservation.<AWSRunningInstance>builder()
|
||||
.region(defaultRegion)
|
||||
.reservationId("r-3f056a58")
|
||||
.ownerId("095072994936")
|
||||
// <groupId>sg-f788299f</groupId>
|
||||
.groupName("launchpad_sec_group")
|
||||
// <groupId>sg-7e512116</groupId>
|
||||
.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());
|
||||
}
|
||||
|
||||
}
|
|
@ -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<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(
|
||||
new Reservation<AWSRunningInstance>(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<Reservation<? extends RunningInstance>> result = parseAWSRunningInstances("/describe_instances_running.xml");
|
||||
|
||||
assertEquals(result.toString(), contents.toString());
|
||||
}
|
||||
|
||||
public void testWhenRunningLatest() throws UnknownHostException {
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(new Reservation<AWSRunningInstance>(
|
||||
defaultRegion, ImmutableSet.of("jclouds#ec2-s#us-east-1"), ImmutableSet.of(
|
||||
new AWSRunningInstance.Builder()
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(Reservation.<AWSRunningInstance>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<Reservation<? extends RunningInstance>> result = parseAWSRunningInstances("/describe_instances_latest.xml");
|
||||
|
||||
|
@ -175,76 +143,6 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
|
|||
parseAWSRunningInstances("/describe_instances_3.xml");
|
||||
}
|
||||
|
||||
public void testApplyInputStream() {
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(new Reservation<AWSRunningInstance>(
|
||||
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<Reservation<? extends RunningInstance>> result = parseAWSRunningInstances("/describe_instances.xml");
|
||||
|
||||
assertEquals(result.toString(), contents.toString());
|
||||
}
|
||||
|
||||
public void testEBS() throws UnknownHostException {
|
||||
|
||||
Set<Reservation<AWSRunningInstance>> contents = ImmutableSet.of(new Reservation<AWSRunningInstance>(
|
||||
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<Reservation<? extends RunningInstance>> result = parseAWSRunningInstances("/describe_instances_ebs.xml");
|
||||
|
||||
assertEquals(result.toString(), contents.toString());
|
||||
}
|
||||
|
||||
static ParseSax<Set<Reservation<? extends RunningInstance>>> createParser() {
|
||||
Injector injector = Guice.createInjector(new SaxParserModule(), new AbstractModule() {
|
||||
|
||||
|
|
|
@ -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<? extends AWSRunningInstance> expected = new Reservation<AWSRunningInstance>(defaultRegion,
|
||||
ImmutableSet.of("default"), ImmutableSet.of(
|
||||
|
||||
new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0").imageId(
|
||||
Reservation<? extends AWSRunningInstance> expected = Reservation.<AWSRunningInstance>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);
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<DescribeInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>dcd37ecf-e5b6-462b-99a8-112427b3e3a2</requestId>
|
||||
<reservationSet>
|
||||
<item>
|
||||
<reservationId>r-3f056a58</reservationId>
|
||||
<ownerId>095072994936</ownerId>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>sg-f788299f</groupId>
|
||||
<groupName>launchpad_sec_group</groupName>
|
||||
</item>
|
||||
<item>
|
||||
<groupId>sg-7e512116</groupId>
|
||||
<groupName>jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<instancesSet>
|
||||
<item>
|
||||
<instanceId>i-32451248</instanceId>
|
||||
<imageId>ami-bf8131d6</imageId>
|
||||
<instanceState>
|
||||
<code>0</code>
|
||||
<name>pending</name>
|
||||
</instanceState>
|
||||
<privateDnsName>ip-10-194-149-220.ec2.internal</privateDnsName>
|
||||
<dnsName>ec2-23-20-17-42.compute-1.amazonaws.com</dnsName>
|
||||
<reason/>
|
||||
<keyName>jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae#105</keyName>
|
||||
<amiLaunchIndex>0</amiLaunchIndex>
|
||||
<productCodes/>
|
||||
<instanceType>c1.medium</instanceType>
|
||||
<launchTime>2012-09-14T20:01:34.000Z</launchTime>
|
||||
<placement>
|
||||
<availabilityZone>us-east-1d</availabilityZone>
|
||||
<groupName/>
|
||||
<tenancy>default</tenancy>
|
||||
</placement>
|
||||
<kernelId>aki-825ea7eb</kernelId>
|
||||
<monitoring>
|
||||
<state>disabled</state>
|
||||
</monitoring>
|
||||
<privateIpAddress>10.194.149.220</privateIpAddress>
|
||||
<ipAddress>23.20.17.42</ipAddress>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupId>sg-f788299f</groupId>
|
||||
<groupName>launchpad_sec_group</groupName>
|
||||
</item>
|
||||
<item>
|
||||
<groupId>sg-7e512116</groupId>
|
||||
<groupName>jclouds#4c858090-f66c-4225-aa57-6fcaa42198ae</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<architecture>x86_64</architecture>
|
||||
<rootDeviceType>ebs</rootDeviceType>
|
||||
<rootDeviceName>/dev/sda1</rootDeviceName>
|
||||
<blockDeviceMapping>
|
||||
<item>
|
||||
<deviceName>/dev/sda1</deviceName>
|
||||
<ebs>
|
||||
<volumeId>vol-b2beb3c9</volumeId>
|
||||
<status>attaching</status>
|
||||
<attachTime>2012-09-14T20:01:37.000Z</attachTime>
|
||||
<deleteOnTermination>true</deleteOnTermination>
|
||||
</ebs>
|
||||
</item>
|
||||
</blockDeviceMapping>
|
||||
<virtualizationType>paravirtual</virtualizationType>
|
||||
<clientToken/>
|
||||
<tagSet>
|
||||
<item>
|
||||
<key>Name</key>
|
||||
<value>4c858090-f66c-4225-aa57-6fcaa42198ae-32451248</value>
|
||||
</item>
|
||||
</tagSet>
|
||||
<hypervisor>xen</hypervisor>
|
||||
</item>
|
||||
</instancesSet>
|
||||
</item>
|
||||
</reservationSet>
|
||||
</DescribeInstancesResponse>
|
Loading…
Reference in New Issue