added rawState to RunningInstance

This commit is contained in:
Adrian Cole 2012-06-04 13:36:05 -07:00
parent 9bf92e0403
commit ef31f5114d
25 changed files with 253 additions and 157 deletions

View File

@ -127,6 +127,7 @@ public class EC2ImageParser implements Function<org.jclouds.ec2.domain.Image, Im
}
builder.operatingSystem(osBuilder.build());
builder.status(toPortableImageStatus.get(from.getImageState()));
builder.backendStatus(from.getRawState());
return builder.build();
}

View File

@ -115,6 +115,7 @@ public class RunningInstanceToNodeMetadata implements Function<RunningInstance,
builder.hostname(instance.getPrivateDnsName().replaceAll("\\..*", ""));
addCredentialsForInstance(builder, instance);
builder.status(instanceToNodeStatus.get(instance.getInstanceState()));
builder.backendStatus(instance.getRawState());
// collect all ip addresses into one bundle in case the api mistakenly put a private address
// into the public address field

View File

@ -47,6 +47,7 @@ public class Image implements Comparable<Image> {
private final String imageLocation;
private final String imageOwnerId;
private final ImageState imageState;
private final String rawState;
private final ImageType imageType;
private final boolean isPublic;
@Nullable
@ -73,10 +74,11 @@ public class Image implements Comparable<Image> {
}
public Image(String region, Architecture architecture, @Nullable String name, @Nullable String description,
String imageId, String imageLocation, String imageOwnerId, ImageState imageState, ImageType imageType,
boolean isPublic, Iterable<String> productCodes, @Nullable String kernelId, @Nullable String platform,
@Nullable String ramdiskId, RootDeviceType rootDeviceType, @Nullable String rootDeviceName,
Map<String, EbsBlockDevice> ebsBlockDevices, VirtualizationType virtualizationType, Hypervisor hypervisor) {
String imageId, String imageLocation, String imageOwnerId, ImageState imageState, String rawState,
ImageType imageType, boolean isPublic, Iterable<String> productCodes, @Nullable String kernelId,
@Nullable String platform, @Nullable String ramdiskId, RootDeviceType rootDeviceType,
@Nullable String rootDeviceName, Map<String, EbsBlockDevice> ebsBlockDevices,
VirtualizationType virtualizationType, Hypervisor hypervisor) {
this.region = checkNotNull(region, "region");
this.architecture = architecture;
this.imageId = checkNotNull(imageId, "imageId");
@ -86,6 +88,7 @@ public class Image implements Comparable<Image> {
this.imageLocation = checkNotNull(imageLocation, "imageLocation");
this.imageOwnerId = checkNotNull(imageOwnerId, "imageOwnerId");
this.imageState = checkNotNull(imageState, "imageState");
this.rawState = checkNotNull(rawState, "rawState");
this.imageType = checkNotNull(imageType, "imageType");
this.isPublic = isPublic;
this.kernelId = kernelId;
@ -260,6 +263,13 @@ public class Image implements Comparable<Image> {
return imageState;
}
/**
* raw form of {@link #getImageState()} as taken directly from the api response xml document/
*/
public String getRawState() {
return rawState;
}
/**
* The type of image (machine, kernel, or ramdisk).
*/
@ -345,7 +355,6 @@ public class Image implements Comparable<Image> {
result = prime * result + ((imageId == null) ? 0 : imageId.hashCode());
result = prime * result + ((imageLocation == null) ? 0 : imageLocation.hashCode());
result = prime * result + ((imageOwnerId == null) ? 0 : imageOwnerId.hashCode());
result = prime * result + ((imageState == null) ? 0 : imageState.hashCode());
result = prime * result + ((imageType == null) ? 0 : imageType.hashCode());
result = prime * result + (isPublic ? 1231 : 1237);
result = prime * result + ((kernelId == null) ? 0 : kernelId.hashCode());
@ -400,11 +409,6 @@ public class Image implements Comparable<Image> {
return false;
} else if (!imageOwnerId.equals(other.imageOwnerId))
return false;
if (imageState == null) {
if (other.imageState != null)
return false;
} else if (!imageState.equals(other.imageState))
return false;
if (imageType == null) {
if (other.imageType != null)
return false;
@ -469,7 +473,7 @@ public class Image implements Comparable<Image> {
public String toString() {
return "Image [architecture=" + architecture + ", description=" + description + ", ebsBlockDevices="
+ ebsBlockDevices + ", imageId=" + imageId + ", imageLocation=" + imageLocation + ", imageOwnerId="
+ imageOwnerId + ", imageState=" + imageState + ", imageType=" + imageType + ", isPublic=" + isPublic
+ imageOwnerId + ", imageState=" + rawState + ", imageType=" + imageType + ", isPublic=" + isPublic
+ ", kernelId=" + kernelId + ", name=" + name + ", platform=" + platform + ", productCodes="
+ productCodes + ", ramdiskId=" + ramdiskId + ", region=" + region + ", rootDeviceName="
+ rootDeviceName + ", rootDeviceType=" + rootDeviceType + ", virtualizationType=" + virtualizationType

View File

@ -50,6 +50,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
protected String imageId;
protected String instanceId;
protected InstanceState instanceState;
protected String rawState;
protected String instanceType;
protected String ipAddress;
protected String kernelId;
@ -106,7 +107,12 @@ public class RunningInstance implements Comparable<RunningInstance> {
this.instanceState = instanceState;
return this;
}
public Builder rawState(String rawState) {
this.rawState = rawState;
return this;
}
public Builder instanceType(String instanceType) {
this.instanceType = instanceType;
return this;
@ -190,9 +196,9 @@ public class RunningInstance implements Comparable<RunningInstance> {
public RunningInstance build() {
return new RunningInstance(region, groupIds, amiLaunchIndex, dnsName, imageId, instanceId, instanceState,
instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone, virtualizationType,
platform, privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType, rootDeviceName,
ebsBlockDevices);
rawState, instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone,
virtualizationType, platform, privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType,
rootDeviceName, ebsBlockDevices);
}
public String getDnsName() {
@ -221,6 +227,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
protected final String imageId;
protected final String instanceId;
protected final InstanceState instanceState;
protected final String rawState;
protected final String instanceType;
@Nullable
protected final String ipAddress;
@ -251,7 +258,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
}
protected RunningInstance(String region, Iterable<String> groupIds, @Nullable String amiLaunchIndex,
@Nullable String dnsName, String imageId, String instanceId, InstanceState instanceState,
@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,
@Nullable String privateDnsName, @Nullable String privateIpAddress, @Nullable String ramdiskId,
@ -263,6 +270,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
this.imageId = imageId; // nullable on runinstances.
this.instanceId = checkNotNull(instanceId, "instanceId");
this.instanceState = checkNotNull(instanceState, "instanceState");
this.rawState = checkNotNull(rawState, "rawState");
this.instanceType = checkNotNull(instanceType, "instanceType");
this.ipAddress = ipAddress;
this.kernelId = kernelId;
@ -327,7 +335,14 @@ public class RunningInstance implements Comparable<RunningInstance> {
public InstanceState getInstanceState() {
return instanceState;
}
/**
* The current state of the instance, as returned literally from the input XML
*/
public String getRawState() {
return rawState;
}
/**
* The instance type.
*/
@ -577,7 +592,7 @@ public class RunningInstance implements Comparable<RunningInstance> {
@Override
public String toString() {
return "[region=" + region + ", availabilityZone=" + availabilityZone + ", instanceId=" + instanceId
+ ", instanceState=" + instanceState + ", instanceType=" + instanceType + ", virtualizationType="
+ ", 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="

View File

@ -122,7 +122,11 @@ public abstract class BaseReservationHandler<T> extends HandlerForGeneratedReque
} else if (equalsOrSuffix(qName, "instanceId")) {
builder.instanceId(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "name")) {
builder.instanceState(InstanceState.fromValue(currentOrNull(currentText)));
String rawState = currentOrNull(currentText);
if (rawState != null) {
builder.rawState(rawState);
builder.instanceState(InstanceState.fromValue(rawState));
}
} else if (equalsOrSuffix(qName, "instanceType")) {
builder.instanceType(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "ipAddress")) {

View File

@ -18,6 +18,8 @@
*/
package org.jclouds.ec2.xml;
import static org.jclouds.util.SaxUtils.currentOrNull;
import java.util.Map;
import java.util.Set;
@ -27,12 +29,12 @@ import javax.inject.Inject;
import org.jclouds.aws.util.AWSUtils;
import org.jclouds.ec2.domain.Hypervisor;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.Image.ImageState;
import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.location.Region;
import org.jclouds.logging.Logger;
@ -72,6 +74,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
private String imageLocation;
private String imageOwnerId;
private ImageState imageState;
private String rawState;
private ImageType imageType;
private boolean isPublic;
private String kernelId;
@ -124,8 +127,9 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
} else if (qName.equals("imageOwnerId")) {
imageOwnerId = currentText.toString().trim();
} else if (qName.equals("imageState")) {
imageState = ImageState.fromValue(currentText.toString().trim());
// eucalyptus
rawState = currentOrNull(currentText);
imageState = ImageState.fromValue(rawState);
// eucalyptus
} else if (qName.equals("imageType") || qName.equals("type")) {
imageType = ImageType.fromValue(currentText.toString().trim());
} else if (qName.equals("isPublic")) {
@ -169,8 +173,8 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
if (region == null)
region = defaultRegion.get();
contents.add(new Image(region, architecture, this.name, description, imageId, imageLocation,
imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId,
rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor));
imageOwnerId, imageState, rawState, imageType, isPublic, productCodes, kernelId, platform,
ramdiskId, rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor));
} catch (NullPointerException e) {
logger.warn(e, "malformed image: %s", imageId);
}
@ -181,6 +185,7 @@ public class DescribeImagesResponseHandler extends ParseSax.HandlerForGeneratedR
this.imageLocation = null;
this.imageOwnerId = null;
this.imageState = null;
this.rawState = null;
this.imageType = null;
this.isPublic = false;
this.kernelId = null;

View File

@ -27,6 +27,7 @@ import org.jclouds.compute.config.BaseComputeServiceContextModule;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.domain.OsFamily;
import org.jclouds.compute.domain.Image.Status;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location;
import org.jclouds.domain.LocationBuilder;
@ -58,16 +59,18 @@ public class EC2ImageParserTest {
public void testParseAmznImage() {
Set<org.jclouds.compute.domain.Image> result = convertImages("/amzn_images.xml");
for (org.jclouds.compute.domain.Image image : result)
assertEquals(image.getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
for (org.jclouds.compute.domain.Image image : result) {
assertEquals(image.getStatus(), Status.AVAILABLE);
assertEquals(image.getBackendStatus(), "available");
}
assertEquals(Iterables.get(result, 0), new ImageBuilder().operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
"137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build()).description("Amazon")
.defaultCredentials(new LoginCredentials("ec2-user", false)).id("us-east-1/ami-82e4b5c7").name(
"amzn-ami-0.9.7-beta.i386-ebs").providerId("ami-82e4b5c7").location(defaultLocation)
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status(
org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
Status.AVAILABLE).build());
assertEquals(Iterables.get(result, 3), new ImageBuilder().operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).arch("paravirtual").version("").description(
@ -76,8 +79,7 @@ public class EC2ImageParserTest {
.id("us-east-1/ami-f2e4b5b7").providerId("ami-f2e4b5b7").name("amzn-ami-0.9.7-beta.x86_64-S3").location(
defaultLocation)
.userMetadata(ImmutableMap.of("owner", "137112412989", "rootDeviceType", "ebs")).status(
org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
;
Status.AVAILABLE).build());
}
static Location defaultLocation = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1").description(

View File

@ -62,7 +62,7 @@ import com.google.inject.name.Names;
/**
* @author Adrian Cole
*/
@Test(groups = "unit")
@Test(groups = "unit", testName = "RunningInstanceToNodeMetadataTest")
public class RunningInstanceToNodeMetadataTest {
public void testAllStatesCovered() {
@ -76,27 +76,27 @@ public class RunningInstanceToNodeMetadataTest {
@Test
public void testPrivateIpAddressIncorrectlyInPublicAddressFieldGoesToPrivateAddressCollection() {
RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).region("us-east-1").ipAddress("10.1.1.1").build();
.instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").ipAddress("10.1.1.1").build();
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
assertEquals(parser.apply(instance), new NodeMetadataBuilder().status(Status.RUNNING).publicAddresses(
assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").publicAddresses(
ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.1.1.1")).id("us-east-1/id").imageId(
"us-east-1/image").providerId("id").build());
"us-east-1/image").providerId("id").build().toString());
}
@Test
public void testPublicIpAddressIncorrectlyInPrivateAddressFieldGoesToPublicAddressCollection() {
RunningInstance instance = RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).region("us-east-1").privateIpAddress("1.1.1.1").build();
.instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").privateIpAddress("1.1.1.1").build();
RunningInstanceToNodeMetadata parser = createNodeParser(ImmutableSet.<Hardware> of(), ImmutableSet
.<Location> of(), ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
assertEquals(parser.apply(instance), new NodeMetadataBuilder().status(Status.RUNNING).privateAddresses(
assertEquals(parser.apply(instance).toString(), new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").privateAddresses(
ImmutableSet.<String> of()).publicAddresses(ImmutableSet.of("1.1.1.1")).id("us-east-1/id").imageId(
"us-east-1/image").providerId("id").build());
"us-east-1/image").providerId("id").build().toString());
}
static Location provider = new LocationBuilder().scope(LocationScope.REGION).id("us-east-1")
@ -114,11 +114,11 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(
parser.apply(server),
new NodeMetadataBuilder().status(Status.RUNNING).hostname("ip-10-243-42-70")
parser.apply(server).toString(),
new NodeMetadataBuilder().status(Status.RUNNING).backendStatus("running").hostname("ip-10-243-42-70")
.publicAddresses(ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70"))
.publicAddresses(ImmutableSet.of("174.129.81.68")).credentials(creds)
.imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build());
.imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f").build().toString());
}
@Test
@ -128,11 +128,11 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(parser.apply(server),
new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING)
assertEquals(parser.apply(server).toString(),
new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running")
.publicAddresses(ImmutableSet.<String> of()).privateAddresses(ImmutableSet.of("10.243.42.70"))
.publicAddresses(ImmutableSet.of("174.129.81.68")).imageId("us-east-1/ami-82e4b5c7")
.id("us-east-1/i-0799056f").providerId("i-0799056f").build());
.id("us-east-1/i-0799056f").providerId("i-0799056f").build().toString());
}
@Test
@ -141,12 +141,12 @@ public class RunningInstanceToNodeMetadataTest {
ImmutableSet.<Image> of(), ImmutableMap.<String, Credentials> of());
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
NodeMetadata expected = new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING)
NodeMetadata expected = new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running")
.privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68"))
.imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f")
.location(provider).build();
assertEquals(parser.apply(server), expected);
assertEquals(parser.apply(server).toString(), expected.toString());
}
@Test
@ -157,9 +157,9 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(
parser.apply(server),
parser.apply(server).toString(),
new NodeMetadataBuilder()
.status(Status.RUNNING)
.status(Status.RUNNING).backendStatus("running")
.hostname("ip-10-243-42-70")
.privateAddresses(ImmutableSet.of("10.243.42.70"))
.publicAddresses(ImmutableSet.of("174.129.81.68"))
@ -167,7 +167,7 @@ public class RunningInstanceToNodeMetadataTest {
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual")
.description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build())
.id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build());
.id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build().toString());
}
@Test
@ -179,10 +179,10 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(
parser.apply(server),
parser.apply(server).toString(),
new NodeMetadataBuilder()
.hostname("ip-10-243-42-70")
.status(Status.RUNNING)
.status(Status.RUNNING).backendStatus("running")
.privateAddresses(ImmutableSet.of("10.243.42.70"))
.publicAddresses(ImmutableSet.of("174.129.81.68"))
.imageId("us-east-1/ami-82e4b5c7")
@ -190,7 +190,7 @@ public class RunningInstanceToNodeMetadataTest {
.operatingSystem(
new OperatingSystem.Builder().family(OsFamily.UNRECOGNIZED).version("").arch("paravirtual")
.description("137112412989/amzn-ami-0.9.7-beta.i386-ebs").is64Bit(false).build())
.id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build());
.id("us-east-1/i-0799056f").providerId("i-0799056f").location(provider).build().toString());
}
@Test
@ -215,24 +215,24 @@ public class RunningInstanceToNodeMetadataTest {
RunningInstance server = firstInstanceFromResource("/describe_instances_running.xml");
assertEquals(
parser.apply(server),
new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING)
parser.apply(server).toString(),
new NodeMetadataBuilder().hostname("ip-10-243-42-70").status(Status.RUNNING).backendStatus("running")
.privateAddresses(ImmutableSet.of("10.243.42.70")).publicAddresses(ImmutableSet.of("174.129.81.68"))
.imageId("us-east-1/ami-82e4b5c7").id("us-east-1/i-0799056f").providerId("i-0799056f")
.hardware(m1_small().build()).location(provider).build());
.hardware(m1_small().build()).location(provider).build().toString());
}
@Test
public void testGroupNameIsSetWhenCustomKeyNameIsSetAndSecurityGroupIsGenerated() {
checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).region("us-east-1").keyName("custom-key")
.instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").keyName("custom-key")
.groupId("jclouds#groupname").build());
}
@Test
public void testGroupNameIsSetWhenCustomSecurityGroupIsSetAndKeyNameIsGenerated() {
checkGroupName(RunningInstance.builder().instanceId("id").imageId("image").instanceType("m1.small")
.instanceState(InstanceState.RUNNING).region("us-east-1").groupId("custom-sec")
.instanceState(InstanceState.RUNNING).rawState("running").region("us-east-1").groupId("custom-sec")
.keyName("jclouds#groupname#23").build());
}

View File

@ -18,6 +18,7 @@
*/
package org.jclouds.ec2.xml;
import static com.google.common.collect.Iterables.get;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
@ -26,12 +27,12 @@ import java.util.Set;
import org.jclouds.ec2.compute.functions.EC2ImageParserTest;
import org.jclouds.ec2.domain.Hypervisor;
import org.jclouds.ec2.domain.Image;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import org.jclouds.ec2.domain.Image.Architecture;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.Image.ImageState;
import org.jclouds.ec2.domain.Image.ImageType;
import org.jclouds.ec2.domain.RootDeviceType;
import org.jclouds.ec2.domain.VirtualizationType;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.SaxParserModule;
import org.jclouds.location.Region;
@ -52,50 +53,56 @@ import com.google.inject.TypeLiteral;
*
* @author Adrian Cole
*/
@Test(groups = "unit")
@Test(groups = "unit", testName = "DescribeImagesResponseHandlerTest")
public class DescribeImagesResponseHandlerTest {
public void testUNIX() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.I386, null, null, "ami-be3adfd7",
"ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532", ImageState.AVAILABLE,
"ec2-public-images/fedora-8-i386-base-v1.04.manifest.xml", "206029621532", ImageState.AVAILABLE, "available",
ImageType.MACHINE, false, Sets.<String> newHashSet("9961934F"), "aki-4438dd2d", null, "ari-4538dd2c",
RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),
VirtualizationType.PARAVIRTUAL, Hypervisor.XEN));
Set<Image> result = parseImages("/describe_images.xml");
assertEquals(result, contents);
assertEquals(result.toString(), contents.toString());
assertEquals(get(result, 0).getImageState(), ImageState.AVAILABLE);
assertEquals(get(result, 0).getRawState(), "available");
}
public void testWindows() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.X86_64, null, null, "ami-02eb086b",
"aws-solutions-amis/SqlSvrStd2003r2-x86_64-Win_SFWBasic5.1-v1.0.manifest.xml", "771350841976",
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet("5771E9A6"), null, "windows",
ImageState.AVAILABLE, "available", ImageType.MACHINE, true, Sets.<String> newHashSet("5771E9A6"), null, "windows",
null, RootDeviceType.INSTANCE_STORE, null, ImmutableMap.<String, EbsBlockDevice> of(),
VirtualizationType.PARAVIRTUAL, Hypervisor.XEN));
Set<Image> result = parseImages("/describe_images_windows.xml");
assertEquals(result, contents);
assertEquals(result.toString(), contents.toString());
assertEquals(get(result, 0).getImageState(), ImageState.AVAILABLE);
assertEquals(get(result, 0).getRawState(), "available");
}
public void testEBS() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.I386, "websrv_2009-12-10",
"Web Server AMI", "ami-246f8d4d", "706093390852/websrv_2009-12-10", "706093390852",
ImageState.AVAILABLE, ImageType.MACHINE, true, Sets.<String> newHashSet(), null, "windows", null,
ImageState.AVAILABLE, "available", ImageType.MACHINE, true, Sets.<String> newHashSet(), null, "windows", null,
RootDeviceType.EBS, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of("/dev/sda1",
new EbsBlockDevice("snap-d01272b9", 30, true), "xvdf", new EbsBlockDevice("snap-d31272ba", 250,
false)), VirtualizationType.HVM, Hypervisor.XEN));
Set<Image> result = parseImages("/describe_images_ebs.xml");
assertEquals(result, contents);
assertEquals(result.toString(), contents.toString());
assertEquals(get(result, 0).getImageState(), ImageState.AVAILABLE);
assertEquals(get(result, 0).getRawState(), "available");
}
public void testDiabloWithIncorrectDisplayNameField() {
Set<Image> contents = ImmutableSet.of(new Image("us-east-1", Architecture.X86_64, "CentOS 6.2 Server 64-bit 20120125", "", "ami-0000054e",
"local (CentOS 6.2 Server 64-bit 20120125)", "", ImageState.AVAILABLE,
"local (CentOS 6.2 Server 64-bit 20120125)", "", ImageState.AVAILABLE, "available",
ImageType.MACHINE, true, Sets.<String> newHashSet(), "aki-0000054c", null, "ari-0000054d",
RootDeviceType.INSTANCE_STORE, "/dev/sda1", ImmutableMap.<String, EbsBlockDevice> of(),
VirtualizationType.PARAVIRTUAL, Hypervisor.XEN));
@ -103,6 +110,8 @@ public class DescribeImagesResponseHandlerTest {
Set<Image> result = parseImages("/describe_images_nova.xml");
assertEquals(result.toString(), contents.toString());
assertEquals(get(result, 0).getImageState(), ImageState.AVAILABLE);
assertEquals(get(result, 0).getRawState(), "available");
}
static ParseSax<Set<Image>> createParser() {

View File

@ -41,6 +41,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableSet;
import static com.google.common.collect.Iterables.*;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@ -71,40 +72,44 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
ImmutableSet.of("adriancole.ec2ingress"), ImmutableSet.of(new RunningInstance.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).instanceType(InstanceType.M1_SMALL).ipAddress(
"174.129.81.68").kernelId("aki-a71cf9ce").keyName("adriancole.ec21").launchTime(
.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.DISABLED,
.availabilityZone("us-east-1c").virtualizationType("paravirtual")
.privateDnsName("ip-10-243-42-70.ec2.internal").privateIpAddress("10.243.42.70").ramdiskId(
.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).build()),
"993194456877", null, "r-a3c508cb"));
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/describe_instances_running.xml");
assertEquals(result, contents);
assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING);
assertEquals(get(get(result, 0), 0).getRawState(), "running");
}
public void testApplyInputStream() {
Set<Reservation<RunningInstance>> contents = ImmutableSet.of(new Reservation<RunningInstance>(defaultRegion,
ImmutableSet.of("default"), ImmutableSet.of(new RunningInstance.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).instanceType(
InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name").launchTime(
dateService.iso8601DateParse("2007-08-07T11:54:42.000Z"))
// MonitoringState.DISABLED,
.availabilityZone("us-east-1b").virtualizationType("paravirtual")
.privateDnsName("10-251-50-132.ec2.internal")// product codes
"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.DISABLED,
.availabilityZone("us-east-1b").virtualizationType("paravirtual").privateDnsName(
"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")
.dnsName("ec2-72-44-33-6.compute-1.amazonaws.com").imageId("ami-6ea54007").instanceId(
"i-28a64435").instanceState(InstanceState.RUNNING).instanceType(
InstanceType.M1_LARGE).kernelId("aki-ba3adfd3").keyName("example-key-name")
.launchTime(dateService.iso8601DateParse("2007-08-07T11:54:42.000Z"))
"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.DISABLED,
.availabilityZone("us-east-1b").virtualizationType("paravirtual")
.privateDnsName("10-251-50-134.ec2.internal")// product codes
.availabilityZone("us-east-1b").virtualizationType("paravirtual").privateDnsName(
"10-251-50-134.ec2.internal")// product codes
// ImmutableSet.of("774F4FF8")
.ramdiskId("ari-badbad00").rootDeviceType(RootDeviceType.INSTANCE_STORE).build()),
"UYY3TLBUXIEON5NQVUUX6OMPWBZIQNFM", null, "r-44a5402d"));
@ -112,6 +117,9 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/describe_instances.xml");
assertEquals(result, contents);
assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING);
assertEquals(get(get(result, 0), 0).getRawState(), "running");
}
public void testEBS() throws UnknownHostException {
@ -120,8 +128,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
ImmutableSet.of("adriancole.ec2ebsingress"), ImmutableSet.of(new RunningInstance.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).instanceType(InstanceType.M1_SMALL).ipAddress(
"75.101.203.146").kernelId("aki-a71cf9ce")
.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.DISABLED
@ -138,6 +146,8 @@ public class DescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest {
Set<Reservation<? extends RunningInstance>> result = parseRunningInstances("/describe_instances_ebs.xml");
assertEquals(result, contents);
assertEquals(get(get(result, 0), 0).getInstanceState(), InstanceState.RUNNING);
assertEquals(get(get(result, 0), 0).getRawState(), "running");
}
static ParseSax<Set<Reservation<? extends RunningInstance>>> createParser() {

View File

@ -65,20 +65,20 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
.of("default"), ImmutableSet.of(
new RunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0")
.imageId("ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING).instanceType(
InstanceType.M1_SMALL).keyName("example-key-name").launchTime(
.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")
.imageId("ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING).instanceType(
InstanceType.M1_SMALL).keyName("example-key-name").launchTime(
.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")
.imageId("ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING).instanceType(
InstanceType.M1_SMALL).keyName("example-key-name").launchTime(
.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,
.availabilityZone("us-east-1b").build())
@ -87,7 +87,7 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
RunInstancesResponseHandler handler = injector.getInstance(RunInstancesResponseHandler.class);
addDefaultRegionToHandler(handler);
Reservation<? extends RunningInstance> result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.toString(), expected.toString());
}
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {

View File

@ -76,6 +76,7 @@ public class NovaReviseParsedImageTest {
.providerId("ami-000004d6")
.location(defaultLocation)
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE)
.backendStatus("available")
.userMetadata(
ImmutableMap.of("owner", "", "rootDeviceType", "instance-store", "virtualizationType",
"paravirtual", "hypervisor", "xen")).build().toString());

View File

@ -159,7 +159,12 @@ public class AWSRunningInstance extends RunningInstance {
public Builder instanceState(InstanceState instanceState) {
return Builder.class.cast(super.instanceState(instanceState));
}
@Override
public Builder rawState(String rawState) {
return Builder.class.cast(super.rawState(rawState));
}
@Override
public Builder instanceType(String instanceType) {
return Builder.class.cast(super.instanceType(instanceType));
@ -248,7 +253,7 @@ public class AWSRunningInstance extends RunningInstance {
@Override
public AWSRunningInstance build() {
return new AWSRunningInstance(region, securityGroupIdToNames, amiLaunchIndex, dnsName, imageId, instanceId,
instanceState, instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone,
instanceState, rawState, instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone,
virtualizationType, platform, privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType,
rootDeviceName, ebsBlockDevices, monitoringState, placementGroup, productCodes, subnetId,
spotInstanceRequestId, vpcId, hypervisor, tags);
@ -271,15 +276,17 @@ public class AWSRunningInstance extends RunningInstance {
private final Map<String, String> tags;
protected AWSRunningInstance(String region, Map<String, String> securityGroupIdToNames, String amiLaunchIndex,
String dnsName, String imageId, String instanceId, InstanceState instanceState, String instanceType,
String ipAddress, String kernelId, String keyName, Date launchTime, String availabilityZone,
String virtualizationType, String platform, String privateDnsName, String privateIpAddress, String ramdiskId,
String reason, RootDeviceType rootDeviceType, String rootDeviceName, Map<String, BlockDevice> ebsBlockDevices,
MonitoringState monitoringState, String placementGroup, Iterable<String> productCodes, String subnetId,
String spotInstanceRequestId, String vpcId, Hypervisor hypervisor, Map<String, String> tags) {
String dnsName, String imageId, String instanceId, InstanceState instanceState, String rawState,
String instanceType, String ipAddress, String kernelId, String keyName, Date launchTime,
String availabilityZone, String virtualizationType, String platform, String privateDnsName,
String privateIpAddress, String ramdiskId, String reason, RootDeviceType rootDeviceType,
String rootDeviceName, Map<String, BlockDevice> ebsBlockDevices, MonitoringState monitoringState,
String placementGroup, Iterable<String> productCodes, String subnetId, String spotInstanceRequestId,
String vpcId, Hypervisor hypervisor, Map<String, String> tags) {
super(region, securityGroupIdToNames.values(), amiLaunchIndex, dnsName, imageId, instanceId, instanceState,
instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone, virtualizationType, platform,
privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType, rootDeviceName, ebsBlockDevices);
rawState, instanceType, ipAddress, kernelId, keyName, launchTime, availabilityZone, virtualizationType,
platform, privateDnsName, privateIpAddress, ramdiskId, reason, rootDeviceType, rootDeviceName,
ebsBlockDevices);
this.monitoringState = checkNotNull(monitoringState, "monitoringState");
this.placementGroup = placementGroup;
this.productCodes = ImmutableSet.copyOf(checkNotNull(productCodes, "productCodes"));
@ -417,7 +424,7 @@ public class AWSRunningInstance extends RunningInstance {
@Override
public String toString() {
return "[region=" + region + ", availabilityZone=" + availabilityZone + ", instanceId=" + instanceId
+ ", instanceState=" + instanceState + ", instanceType=" + instanceType + ", virtualizationType="
+ ", instanceState=" + rawState + ", instanceType=" + instanceType + ", virtualizationType="
+ virtualizationType + ", imageId=" + imageId + ", ipAddress=" + ipAddress + ", dnsName=" + dnsName
+ ", privateIpAddress=" + privateIpAddress + ", privateDnsName=" + privateDnsName + ", keyName="
+ keyName + ", platform=" + platform + ", launchTime=" + launchTime + ", rootDeviceName="

View File

@ -53,6 +53,7 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
private String id;
private float spotPrice;
private State state;
private String rawState;
private Type type;
private Date validFrom;
private Date validUntil;
@ -72,6 +73,7 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
this.id = null;
this.spotPrice = 0;
this.state = null;
this.rawState = null;
this.type = null;
this.validFrom = null;
this.validUntil = null;
@ -153,7 +155,12 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
this.state = state;
return this;
}
public Builder rawState(String rawState) {
this.rawState = rawState;
return this;
}
public Builder type(Type type) {
this.type = type;
return this;
@ -171,8 +178,8 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
public SpotInstanceRequest build() {
return new SpotInstanceRequest(region, availabilityZoneGroup, launchedAvailabilityZone, createTime, faultCode,
faultMessage, instanceId, launchGroup, launchSpecification, productDescription, id, spotPrice, state,
type, validFrom, validUntil, tags);
faultMessage, instanceId, launchGroup, launchSpecification, productDescription, id, spotPrice, state,
rawState, type, validFrom, validUntil, tags);
}
}
@ -231,15 +238,16 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
private final String id;
private final float spotPrice;
private final State state;
private final String rawState;
private final Type type;
private final Date validFrom;
private final Date validUntil;
private final Map<String, String> tags;
public SpotInstanceRequest(String region, String availabilityZoneGroup, @Nullable String launchedAvailabilityZone,
Date createTime, String faultCode, String faultMessage, String instanceId, String launchGroup,
LaunchSpecification launchSpecification, String productDescription, String id, float spotPrice, State state,
Type type, Date validFrom, Date validUntil, Map<String, String> tags) {
Date createTime, String faultCode, String faultMessage, String instanceId, String launchGroup,
LaunchSpecification launchSpecification, String productDescription, String id, float spotPrice,
State state, String rawState, Type type, Date validFrom, Date validUntil, Map<String, String> tags) {
this.region = checkNotNull(region, "region");
this.availabilityZoneGroup = availabilityZoneGroup;
this.launchedAvailabilityZone = launchedAvailabilityZone;
@ -253,6 +261,7 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
this.id = checkNotNull(id, "id");
this.spotPrice = spotPrice;
this.state = checkNotNull(state, "state");
this.rawState = checkNotNull(rawState, "rawState");
this.type = checkNotNull(type, "type");
this.validFrom = validFrom;
this.validUntil = validUntil;
@ -313,7 +322,11 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
public State getState() {
return state;
}
public String getRawState() {
return rawState;
}
public Type getType() {
return type;
}
@ -451,7 +464,7 @@ public class SpotInstanceRequest implements Comparable<SpotInstanceRequest> {
+ launchedAvailabilityZone + ", createTime=" + createTime + ", faultCode=" + faultCode + ", faultMessage="
+ faultMessage + ", instanceId=" + instanceId + ", launchGroup=" + launchGroup + ", launchSpecification="
+ launchSpecification + ", productDescription=" + productDescription + ", id=" + id + ", spotPrice="
+ spotPrice + ", state=" + state + ", type=" + type + ", validFrom=" + validFrom + ", validUntil="
+ spotPrice + ", state=" + rawState + ", type=" + type + ", validFrom=" + validFrom + ", validUntil="
+ validUntil + ", tags=" + tags + "]";
}

View File

@ -45,6 +45,7 @@ public class SpotInstanceRequestToAWSRunningInstance implements Function<SpotIns
builder.spotInstanceRequestId(request.getId());
builder.instanceId(request.getId());
builder.instanceState(InstanceState.PENDING);
builder.rawState(request.getRawState());
builder.region(request.getRegion());
builder.tags(request.getTags());
LaunchSpecification spec = request.getLaunchSpecification();

View File

@ -158,7 +158,9 @@ public abstract class BaseAWSReservationHandler<T> extends HandlerForGeneratedRe
} else if (equalsOrSuffix(qName, "instanceId")) {
builder.instanceId(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "name")) {
builder.instanceState(InstanceState.fromValue(currentOrNull(currentText)));
String rawState = currentOrNull(currentText);
builder.rawState(rawState);
builder.instanceState(InstanceState.fromValue(rawState));
} else if (equalsOrSuffix(qName, "instanceType")) {
builder.instanceType(currentOrNull(currentText));
} else if (equalsOrSuffix(qName, "ipAddress")) {

View File

@ -124,9 +124,11 @@ public class SpotInstanceHandler extends ParseSax.HandlerForGeneratedRequestWith
if (type != null)
builder.type(SpotInstanceRequest.Type.fromValue(type));
} else if (qName.equals("state")) {
String state = currentOrNull(currentText);
if (state != null)
builder.state(SpotInstanceRequest.State.fromValue(state));
String rawState = currentOrNull(currentText);
if (rawState != null) {
builder.rawState(rawState);
builder.state(SpotInstanceRequest.State.fromValue(rawState));
}
} else if (qName.equals("createTime")) {
String createTime = currentOrNull(currentText);
if (createTime != null)

View File

@ -88,6 +88,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
.instanceId("i-911444f0")
.imageId("ami-63be790a")
.instanceState(InstanceState.RUNNING)
.rawState("running")
.privateDnsName("ip-10-212-81-7.ec2.internal")
.dnsName("ec2-174-129-173-155.compute-1.amazonaws.com")
.keyName("jclouds#zkclustertest#23")
@ -113,6 +114,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
.instanceId("i-931444f2")
.imageId("ami-63be790a")
.instanceState(InstanceState.RUNNING)
.rawState("running")
.privateDnsName("ip-10-212-185-8.ec2.internal")
.dnsName("ec2-50-19-207-248.compute-1.amazonaws.com")
.keyName("jclouds#zkclustertest#23")
@ -136,6 +138,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
parser.apply(Iterables.get(contents, 0)).toString(),
new NodeMetadataBuilder()
.status(Status.RUNNING)
.backendStatus("running")
.group("zkclustertest")
.name("foo")
.hostname("ip-10-212-81-7")
@ -147,9 +150,10 @@ public class AWSRunningInstanceToNodeMetadataTest {
.tags(ImmutableSet.of("Empty"))
.userMetadata(ImmutableMap.of("Name", "foo")).build().toString());
assertEquals(
parser.apply(Iterables.get(contents, 1)),
parser.apply(Iterables.get(contents, 1)).toString(),
new NodeMetadataBuilder()
.status(Status.RUNNING)
.backendStatus("running")
.group("zkclustertest")
.hostname("ip-10-212-185-8")
.privateAddresses(ImmutableSet.of("10.212.185.8"))
@ -157,7 +161,7 @@ public class AWSRunningInstanceToNodeMetadataTest {
.imageId("us-east-1/ami-63be790a")
.id("us-east-1/i-931444f2")
.providerId("i-931444f2")
.build());
.build().toString());
}
protected AWSRunningInstanceToNodeMetadata createNodeParser(final ImmutableSet<Hardware> hardware,

View File

@ -75,6 +75,7 @@ public class AWSEC2ImageParserTest {
"virtualizationType", "paravirtual",
"hypervisor", "xen"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE)
.backendStatus("available")
.build());
assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
@ -88,7 +89,7 @@ public class AWSEC2ImageParserTest {
.defaultCredentials(new LoginCredentials("ubuntu", false)).id("us-east-1/ami-c0fa1ea9")
.providerId("ami-c0fa1ea9").location(defaultLocation).version("20080905")
.userMetadata(ImmutableMap.of("owner", "063491364108", "rootDeviceType", "instance-store"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build());
assertEquals(Iterables.get(result, 4).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
assertEquals(
@ -107,7 +108,7 @@ public class AWSEC2ImageParserTest {
"rootDeviceType", "ebs",
"virtualizationType", "paravirtual",
"hypervisor", "xen"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build());
assertEquals(Iterables.get(result, 6).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
}
@ -169,16 +170,16 @@ public class AWSEC2ImageParserTest {
.defaultCredentials(new LoginCredentials("root", false)).id("us-east-1/ami-ccb35ea5")
.providerId("ami-ccb35ea5").location(defaultLocation).version("4.4.10")
.userMetadata(ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build());
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build());
assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
assertEquals(
new Gson().toJson(Iterables.get(result, 1)),
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"status\":\"AVAILABLE\",\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"name\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");
"{\"operatingSystem\":{\"family\":\"UBUNTU\",\"arch\":\"paravirtual\",\"version\":\"9.10\",\"description\":\"411009282317/RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"is64Bit\":true},\"status\":\"AVAILABLE\",\"backendStatus\":\"available\",\"version\":\"4.5.3_EBS_Alpha\",\"description\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-c19db6b5\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-c19db6b5\",\"name\":\"RightImage_Ubuntu_9.10_x64_v4.5.3_EBS_Alpha\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"paravirtual\",\"hypervisor\":\"xen\"}}");
assertEquals(
new Gson().toJson(Iterables.get(result, 2)),
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"status\":\"AVAILABLE\",\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"name\":\"RightImage Windows_2003_i386_v5.4.3\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}");
"{\"operatingSystem\":{\"family\":\"WINDOWS\",\"arch\":\"hvm\",\"version\":\"2003\",\"description\":\"411009282317/RightImage Windows_2003_i386_v5.4.3\",\"is64Bit\":false},\"status\":\"AVAILABLE\",\"backendStatus\":\"available\",\"version\":\"5.4.3\",\"description\":\"Built by RightScale\",\"defaultCredentials\":{\"authenticateSudo\":false,\"identity\":\"root\"},\"id\":\"us-east-1/ami-710c2605\",\"type\":\"IMAGE\",\"tags\":[],\"providerId\":\"ami-710c2605\",\"name\":\"RightImage Windows_2003_i386_v5.4.3\",\"location\":{\"scope\":\"REGION\",\"id\":\"us-east-1\",\"description\":\"us-east-1\",\"iso3166Codes\":[],\"metadata\":{}},\"userMetadata\":{\"owner\":\"411009282317\",\"rootDeviceType\":\"ebs\",\"virtualizationType\":\"hvm\",\"hypervisor\":\"xen\"}}");
}
public void testParseAmznImage() {

View File

@ -103,7 +103,7 @@ public class AWSEC2ReviseParsedImageTest {
Map<String, Image.EbsBlockDevice> ebsBlockDevices = Collections.emptyMap();
VirtualizationType virtualizationType = VirtualizationType.HVM;
Hypervisor hypervisor = Hypervisor.XEN;
Image from = new Image(region, architecture, imageName, description, imageId, imageOwnerId + "/" + imageName, imageOwnerId, imageState, imageType, isPublic, productCodes, kernelId, platform, ramdiskId, rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor);
Image from = new Image(region, architecture, imageName, description, imageId, imageOwnerId + "/" + imageName, imageOwnerId, imageState, "available", imageType, isPublic, productCodes, kernelId, platform, ramdiskId, rootDeviceType, rootDeviceName, ebsBlockDevices, virtualizationType, hypervisor);
return from;
}
}

View File

@ -24,6 +24,8 @@ import org.jclouds.aws.ec2.domain.AWSRunningInstance;
import org.jclouds.aws.ec2.domain.LaunchSpecification;
import org.jclouds.aws.ec2.domain.MonitoringState;
import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
import org.jclouds.aws.ec2.domain.SpotInstanceRequest.State;
import org.jclouds.aws.ec2.domain.SpotInstanceRequest.Type;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.ec2.domain.Hypervisor;
import org.jclouds.ec2.domain.InstanceState;
@ -45,8 +47,9 @@ public class SpotInstanceRequestToAWSRunningInstanceTest {
.region("us-east-1")
.id("sir-228e6406")
.spotPrice(0.001f)
.type(SpotInstanceRequest.Type.ONE_TIME)
.state(SpotInstanceRequest.State.OPEN)
.type(Type.ONE_TIME)
.state(State.OPEN)
.rawState("open")
.launchSpecification(
LaunchSpecification.builder().imageId("ami-595a0a1c").securityGroupName("default")
.instanceType("m1.large").mapNewVolumeToDevice("/dev/sda1", 1, true)
@ -59,31 +62,32 @@ public class SpotInstanceRequestToAWSRunningInstanceTest {
.build();
assertEquals(
new SpotInstanceRequestToAWSRunningInstance().apply(input),
new SpotInstanceRequestToAWSRunningInstance().apply(input).toString(),
AWSRunningInstance.builder().region("us-east-1").instanceId("sir-228e6406")
.spotInstanceRequestId("sir-228e6406").instanceState(InstanceState.PENDING).imageId("ami-595a0a1c")
.spotInstanceRequestId("sir-228e6406").instanceState(InstanceState.PENDING)
.rawState("open").imageId("ami-595a0a1c")
.groupId("default").instanceType("m1.large")
.tag("foo", "bar")
.tag("empty", "")
.hypervisor(Hypervisor.XEN)
.monitoringState(MonitoringState.PENDING).build());
.monitoringState(MonitoringState.DISABLED).build().toString());
}
public void testConvertWhenNotOpenReturnsNull() {
assertEquals(
new SpotInstanceRequestToAWSRunningInstance().apply(SpotInstanceRequest.builder().region("us-east-1")
.id("sir-228e6406").type(SpotInstanceRequest.Type.ONE_TIME).state(SpotInstanceRequest.State.ACTIVE)
.id("sir-228e6406").type(Type.ONE_TIME).state(State.ACTIVE).rawState("active")
.build()), null);
assertEquals(
new SpotInstanceRequestToAWSRunningInstance().apply(SpotInstanceRequest.builder().region("us-east-1")
.id("sir-228e6406").type(SpotInstanceRequest.Type.ONE_TIME)
.state(SpotInstanceRequest.State.CANCELLED).build()), null);
.id("sir-228e6406").type(Type.ONE_TIME).rawState("one-time")
.state(State.CANCELLED).build()), null);
assertEquals(
new SpotInstanceRequestToAWSRunningInstance().apply(SpotInstanceRequest.builder().region("us-east-1")
.id("sir-228e6406").type(SpotInstanceRequest.Type.ONE_TIME)
.state(SpotInstanceRequest.State.UNRECOGNIZED).build()), null);
.id("sir-228e6406").type(Type.ONE_TIME).rawState("one-time")
.state(State.UNRECOGNIZED).build()), null);
}
}

View File

@ -83,6 +83,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
.imageId("ami-82e4b5c7")
.instanceId("i-0799056f")
.instanceState(InstanceState.RUNNING)
.rawState("running")
.instanceType(InstanceType.M1_SMALL)
.ipAddress("174.129.81.68")
.kernelId("aki-a71cf9ce")
@ -112,6 +113,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
.instanceId("i-911444f0")
.imageId("ami-63be790a")
.instanceState(InstanceState.RUNNING)
.rawState("running")
.privateDnsName("ip-10-212-81-7.ec2.internal")
.dnsName("ec2-174-129-173-155.compute-1.amazonaws.com")
.keyName("jclouds#zkclustertest#us-east-1#23")
@ -139,6 +141,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
.instanceId("i-931444f2")
.imageId("ami-63be790a")
.instanceState(InstanceState.RUNNING)
.rawState("running")
.privateDnsName("ip-10-212-185-8.ec2.internal")
.dnsName("ec2-50-19-207-248.compute-1.amazonaws.com")
.keyName("jclouds#zkclustertest#us-east-1#23")
@ -177,7 +180,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
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)
.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")
@ -187,7 +190,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
.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)
.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")
@ -214,6 +217,7 @@ public class AWSDescribeInstancesResponseHandlerTest extends BaseEC2HandlerTest
.imageId("ami-849875ed")
.instanceId("i-e564438d")
.instanceState(InstanceState.RUNNING)
.rawState("running")
.instanceType(InstanceType.M1_SMALL)
.ipAddress("75.101.203.146")
.kernelId("aki-a71cf9ce")

View File

@ -85,25 +85,22 @@ public class AWSRunInstancesResponseHandlerTest extends BaseEC2HandlerTest {
Reservation<? extends AWSRunningInstance> expected = new Reservation<AWSRunningInstance>(defaultRegion,
ImmutableSet.of("default"), ImmutableSet.of(
new AWSRunningInstance.Builder().region(defaultRegion).groupId("default").amiLaunchIndex("0")
.imageId("ami-60a54009").instanceId("i-2ba64342").instanceState(InstanceState.PENDING)
.instanceType(InstanceType.M1_SMALL).keyName("example-key-name")
.launchTime(dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))
.hypervisor(Hypervisor.XEN)
new AWSRunningInstance.Builder().region(defaultRegion).groupId("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("ami-60a54009").instanceId("i-2bc64242").instanceState(InstanceState.PENDING)
.instanceType(InstanceType.M1_SMALL).keyName("example-key-name")
.launchTime(dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))
.hypervisor(Hypervisor.XEN)
new AWSRunningInstance.Builder().region(defaultRegion).groupId("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("ami-60a54009").instanceId("i-2be64332").instanceState(InstanceState.PENDING)
.instanceType(InstanceType.M1_SMALL).keyName("example-key-name")
.launchTime(dateService.iso8601DateParse("2007-08-07T11:51:50.000Z"))
.hypervisor(Hypervisor.XEN)
new AWSRunningInstance.Builder().region(defaultRegion).groupId("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");

View File

@ -27,6 +27,8 @@ import java.io.InputStream;
import org.jclouds.aws.ec2.domain.LaunchSpecification;
import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
import org.jclouds.aws.ec2.domain.SpotInstanceRequest.State;
import org.jclouds.aws.ec2.domain.SpotInstanceRequest.Type;
import org.jclouds.date.DateService;
import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.ec2.xml.BaseEC2HandlerTest;
@ -81,8 +83,9 @@ public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
.region("us-east-1")
.id("sir-228e6406")
.spotPrice(0.001f)
.type(SpotInstanceRequest.Type.ONE_TIME)
.state(SpotInstanceRequest.State.OPEN)
.type(Type.ONE_TIME)
.state(State.OPEN)
.rawState("open")
.launchSpecification(
LaunchSpecification.builder().imageId("ami-595a0a1c").securityGroupIdToName("sg-83e1c4ea", "default")
.instanceType("m1.large").mapNewVolumeToDevice("/dev/sda1", 1, true)
@ -94,6 +97,9 @@ public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
addDefaultRegionToHandler(handler);
SpotInstanceRequest result = factory.create(handler).parse(is);
assertEquals(result.toString(), expected.toString());
assertEquals(result.getState(), State.OPEN);
assertEquals(result.getRawState(), "open");
}
public void testApplyInputStream1() {
@ -106,8 +112,9 @@ public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
.id("sir-1ede0012")
.instanceId("i-ef308e8e")
.spotPrice(0.300000f)
.type(SpotInstanceRequest.Type.ONE_TIME)
.state(SpotInstanceRequest.State.ACTIVE)
.type(Type.ONE_TIME)
.state(State.ACTIVE)
.rawState("active")
.launchedAvailabilityZone("us-east-1b")
.launchSpecification(
LaunchSpecification.builder().imageId("ami-8e1fece7")
@ -123,7 +130,9 @@ public class SpotInstanceHandlerTest extends BaseEC2HandlerTest {
SpotInstanceHandler handler = injector.getInstance(SpotInstanceHandler.class);
addDefaultRegionToHandler(handler);
SpotInstanceRequest result = factory.create(handler).parse(is);
assertEquals(result, expected);
assertEquals(result.toString(), expected.toString());
assertEquals(result.getState(), State.ACTIVE);
assertEquals(result.getRawState(), "active");
}
private void addDefaultRegionToHandler(ParseSax.HandlerWithResult<?> handler) {

View File

@ -76,7 +76,7 @@ public class EucalyptusPartnerCloudReviseParsedImageTest {
.userMetadata(
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType",
"paravirtual", "hypervisor", "xen"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build().toString());
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());
assertEquals(Iterables.get(result, 0).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
assertEquals(
@ -94,7 +94,7 @@ public class EucalyptusPartnerCloudReviseParsedImageTest {
.userMetadata(
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType",
"paravirtual", "hypervisor", "xen"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build().toString());
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());
assertEquals(Iterables.get(result, 1).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
assertEquals(
@ -112,7 +112,7 @@ public class EucalyptusPartnerCloudReviseParsedImageTest {
.userMetadata(
ImmutableMap.of("owner", "admin", "rootDeviceType", "instance-store", "virtualizationType",
"paravirtual", "hypervisor", "xen"))
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).build().toString());
.status(org.jclouds.compute.domain.Image.Status.AVAILABLE).backendStatus("available").build().toString());
assertEquals(Iterables.get(result, 2).getStatus(), org.jclouds.compute.domain.Image.Status.AVAILABLE);
}