diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java index a1992315cd..0a11cb68ba 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/domain/RunningInstance.java @@ -269,9 +269,9 @@ public class RunningInstance implements Comparable { this.dnsName = dnsName; // nullable on runinstances. 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.instanceState = checkNotNull(instanceState, "instanceState for %s/%s", region, instanceId); + this.rawState = checkNotNull(rawState, "rawState for %s/%s", region, instanceId); + this.instanceType = checkNotNull(instanceType, "instanceType for %s/%s", region, instanceId); this.ipAddress = ipAddress; this.kernelId = kernelId; this.keyName = keyName; @@ -283,10 +283,10 @@ public class RunningInstance implements Comparable { this.privateIpAddress = privateIpAddress;// nullable on runinstances. this.ramdiskId = ramdiskId; this.reason = reason; - this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType"); + this.rootDeviceType = checkNotNull(rootDeviceType, "rootDeviceType for %s/%s", region, instanceId); this.rootDeviceName = rootDeviceName; - this.ebsBlockDevices = ImmutableMap.copyOf(checkNotNull(ebsBlockDevices, "ebsBlockDevices")); - this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds")); + this.ebsBlockDevices = ImmutableMap.copyOf(checkNotNull(ebsBlockDevices, "ebsBlockDevices for %s/%s", region, instanceId)); + this.groupIds = ImmutableSet.copyOf(checkNotNull(groupIds, "groupIds for %s/%s", region, instanceId)); } /** diff --git a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java index 38fe564f73..807d555bff 100644 --- a/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java +++ b/apis/ec2/src/main/java/org/jclouds/ec2/xml/BaseReservationHandler.java @@ -72,7 +72,10 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque protected Builder builder; protected int itemDepth; - boolean inInstancesSet; + protected boolean inInstancesSet; + protected boolean inProductCodes; + protected boolean inGroupSet; + // attachments private String volumeId; private Attachment.Status attachmentStatus; @@ -88,12 +91,17 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque private Set instances = Sets.newLinkedHashSet(); + public void startElement(String uri, String name, String qName, Attributes attrs) { if (equalsOrSuffix(qName, "item")) { itemDepth++; } else if (equalsOrSuffix(qName, "instancesSet")) { inInstancesSet = true; - } + } else if (equalsOrSuffix(qName, "productCodes")) { + inProductCodes = true; + } else if (equalsOrSuffix(qName, "groupSet")) { + inGroupSet = true; + } } public void endElement(String uri, String name, String qName) { @@ -102,6 +110,10 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque itemDepth--; } else if (equalsOrSuffix(qName, "instancesSet")) { inInstancesSet = false; + } else if (equalsOrSuffix(qName, "productCodes")) { + inProductCodes = false; + } else if (equalsOrSuffix(qName, "groupSet")) { + inGroupSet = false; } else if (equalsOrSuffix(qName, "groupId")) { groupIds.add(currentOrNull(currentText)); } else if (equalsOrSuffix(qName, "ownerId")) { @@ -219,7 +231,7 @@ public abstract class BaseReservationHandler extends HandlerForGeneratedReque } protected boolean endOfInstanceItem() { - return itemDepth <= 2 && inInstancesSet; + return itemDepth <= 2 && inInstancesSet && !inProductCodes && !inGroupSet; } public void characters(char ch[], int start, int length) { diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java index f52baaf6a4..16d597b68d 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/xml/RunInstancesResponseHandlerTest.java @@ -29,6 +29,7 @@ import org.jclouds.date.DateService; 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; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.internal.GeneratedHttpRequest; @@ -57,7 +58,7 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { assert dateService != null; } - public void testApplyInputStream() { + public void testEC2() { InputStream is = getClass().getResourceAsStream("/run_instances.xml"); @@ -90,6 +91,26 @@ public class RunInstancesResponseHandlerTest extends BaseEC2HandlerTest { assertEquals(result.toString(), expected.toString()); } + public void testCloudBridge() { + + InputStream is = getClass().getResourceAsStream("/run_instances_cloudbridge.xml"); + + Reservation expected = new Reservation(defaultRegion, ImmutableSet + .of("default"), ImmutableSet.of( + + new RunningInstance.Builder().region(defaultRegion).groupId("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")) + .rootDeviceType(RootDeviceType.EBS).availabilityZone("is-1a").build()) + , "56eeacd9-c790-45c3-85f3-e4380b55e1d8<", null, "r-f847a6ca"); + + RunInstancesResponseHandler handler = injector.getInstance(RunInstancesResponseHandler.class); + addDefaultRegionToHandler(handler); + Reservation result = factory.create(handler).parse(is); + assertEquals(result.toString(), expected.toString()); + } + private void addDefaultRegionToHandler(ParseSax.HandlerWithResult handler) { GeneratedHttpRequest request = createMock(GeneratedHttpRequest.class); expect(request.getArgs()).andReturn(ImmutableList. of()).atLeastOnce(); diff --git a/apis/ec2/src/test/resources/run_instances_cloudbridge.xml b/apis/ec2/src/test/resources/run_instances_cloudbridge.xml new file mode 100644 index 0000000000..37d5ae8800 --- /dev/null +++ b/apis/ec2/src/test/resources/run_instances_cloudbridge.xml @@ -0,0 +1,68 @@ + + + 56eeacd9-c790-45c3-85f3-e4380b55e1d8 + r-f847a6ca + 55ed6530-9b32-48f1-acb7-6ec0d3255a65 + + + jclouds#greenqloud-computeblock + + + jclouds#greenqloud-computeblock + + + + + i-01b0dac3 + qmi-9ac92558 + + 0 + pending + + + + + jclouds#greenqloud-computeblock#35 + 0 + + + + + + m1.small + 2012-06-15T19:06:35.000+00:00 + + is-1a + + + + + + disabled + + + + + + + jclouds#greenqloud-computeblock + + + jclouds#greenqloud-computeblock + + + + pending + pending + + + ebs + + + + + xen + + + + \ No newline at end of file