cloudbridge exposes a slightly different xml format for RunningInstances

This commit is contained in:
Adrian Cole 2012-06-15 15:54:08 -04:00
parent 8a34254c8e
commit 69d7e1d585
4 changed files with 111 additions and 10 deletions

View File

@ -269,9 +269,9 @@ public class RunningInstance implements Comparable<RunningInstance> {
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<RunningInstance> {
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));
}
/**

View File

@ -72,7 +72,10 @@ public abstract class BaseReservationHandler<T> 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<T> extends HandlerForGeneratedReque
private Set<RunningInstance> 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<T> 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<T> extends HandlerForGeneratedReque
}
protected boolean endOfInstanceItem() {
return itemDepth <= 2 && inInstancesSet;
return itemDepth <= 2 && inInstancesSet && !inProductCodes && !inGroupSet;
}
public void characters(char ch[], int start, int length) {

View File

@ -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<? extends RunningInstance> expected = new Reservation<RunningInstance>(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<? extends RunningInstance> 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.<Object> of()).atLeastOnce();

View File

@ -0,0 +1,68 @@
<?xml version="1.0"?>
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2010-06-15/">
<requestId>56eeacd9-c790-45c3-85f3-e4380b55e1d8</requestId>
<reservationId>r-f847a6ca</reservationId>
<ownerId>55ed6530-9b32-48f1-acb7-6ec0d3255a65</ownerId>
<groupSet>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
</groupSet>
<instancesSet>
<item>
<instanceId>i-01b0dac3</instanceId>
<imageId>qmi-9ac92558</imageId>
<instanceState>
<code>0</code>
<name>pending</name>
</instanceState>
<privateDnsName/>
<dnsName/>
<reason/>
<keyName>jclouds#greenqloud-computeblock#35</keyName>
<amiLaunchIndex>0</amiLaunchIndex>
<productCodes>
<item>
<productCode/>
</item>
</productCodes>
<instanceType>m1.small</instanceType>
<launchTime>2012-06-15T19:06:35.000+00:00</launchTime>
<placement>
<availabilityZone>is-1a</availabilityZone>
</placement>
<kernelId/>
<ramdiskId/>
<platform/>
<monitoring>
<state>disabled</state>
</monitoring>
<subnetId/>
<vpcId/>
<privateIpAddress/>
<groupSet>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
<item>
<groupId>jclouds#greenqloud-computeblock</groupId>
</item>
</groupSet>
<stateReason>
<code>pending</code>
<message>pending</message>
</stateReason>
<architecture/>
<rootDeviceType>ebs</rootDeviceType>
<rootDeviceName/>
<blockDeviceMapping/>
<instanceLifecycle/>
<spotInstanceRequestId/>
<hypervisor>xen</hypervisor>
</item>
</instancesSet>
<requesterId/>
</RunInstancesResponse>