Issue 112: normalized object model

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2651 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-14 03:49:24 +00:00
parent e330360f64
commit 5ecf38f542
32 changed files with 632 additions and 1414 deletions

View File

@ -21,8 +21,11 @@ package org.jclouds.vcloud.domain;
import java.net.InetAddress;
import java.util.Set;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap;
import com.google.inject.ImplementedBy;
/**
* A virtual application (vApp) is a software solution, packaged in OVF containing one or more
@ -31,7 +34,9 @@ import com.google.common.collect.Multimap;
*
* @author Adrian Cole
*/
@ImplementedBy(VAppImpl.class)
public interface VApp extends NamedResource {
NamedResource getVDC();
VAppStatus getStatus();

View File

@ -44,6 +44,7 @@ public class VAppImpl implements VApp {
private final String id;
private final String name;
private final URI location;
private final NamedResource vDC;
private final VAppStatus status;
private final Long size;
private final ListMultimap<String, InetAddress> networkToAddresses;
@ -55,7 +56,7 @@ public class VAppImpl implements VApp {
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public VAppImpl(String id, String name, URI location, VAppStatus status, Long size,
public VAppImpl(String id, String name, URI location, VAppStatus status, Long size, NamedResource vDC,
ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, VirtualSystem system,
Set<ResourceAllocation> resourceAllocations) {
@ -64,6 +65,7 @@ public class VAppImpl implements VApp {
this.location = location;
this.status = status;
this.size = size;
this.vDC = vDC;
this.networkToAddresses = networkToAddresses;
this.operatingSystemDescription = operatingSystemDescription;
this.system = system;
@ -101,96 +103,107 @@ public class VAppImpl implements VApp {
return resourceAllocationByType;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime
* result
+ ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
result = prime
* result
+ ((operatingSystemDescription == null) ? 0
: operatingSystemDescription.hashCode());
result = prime
* result
+ ((resourceAllocationByType == null) ? 0
: resourceAllocationByType.hashCode());
result = prime
* result
+ ((resourceAllocations == null) ? 0 : resourceAllocations
.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((system == null) ? 0 : system.hashCode());
return result;
}
public NamedResource getVDC() {
return vDC;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VAppImpl other = (VAppImpl) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (networkToAddresses == null) {
if (other.networkToAddresses != null)
return false;
} else if (!networkToAddresses.equals(other.networkToAddresses))
return false;
if (operatingSystemDescription == null) {
if (other.operatingSystemDescription != null)
return false;
} else if (!operatingSystemDescription
.equals(other.operatingSystemDescription))
return false;
if (resourceAllocationByType == null) {
if (other.resourceAllocationByType != null)
return false;
} else if (!resourceAllocationByType.equals(other.resourceAllocationByType))
return false;
if (resourceAllocations == null) {
if (other.resourceAllocations != null)
return false;
} else if (!resourceAllocations.equals(other.resourceAllocations))
return false;
if (size == null) {
if (other.size != null)
return false;
} else if (!size.equals(other.size))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (system == null) {
if (other.system != null)
return false;
} else if (!system.equals(other.system))
return false;
return true;
}
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime
* result
+ ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
result = prime
* result
+ ((operatingSystemDescription == null) ? 0
: operatingSystemDescription.hashCode());
result = prime
* result
+ ((resourceAllocationByType == null) ? 0
: resourceAllocationByType.hashCode());
result = prime
* result
+ ((resourceAllocations == null) ? 0 : resourceAllocations
.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode());
result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((system == null) ? 0 : system.hashCode());
result = prime * result + ((vDC == null) ? 0 : vDC.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VAppImpl other = (VAppImpl) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (location == null) {
if (other.location != null)
return false;
} else if (!location.equals(other.location))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (networkToAddresses == null) {
if (other.networkToAddresses != null)
return false;
} else if (!networkToAddresses.equals(other.networkToAddresses))
return false;
if (operatingSystemDescription == null) {
if (other.operatingSystemDescription != null)
return false;
} else if (!operatingSystemDescription
.equals(other.operatingSystemDescription))
return false;
if (resourceAllocationByType == null) {
if (other.resourceAllocationByType != null)
return false;
} else if (!resourceAllocationByType
.equals(other.resourceAllocationByType))
return false;
if (resourceAllocations == null) {
if (other.resourceAllocations != null)
return false;
} else if (!resourceAllocations.equals(other.resourceAllocations))
return false;
if (size == null) {
if (other.size != null)
return false;
} else if (!size.equals(other.size))
return false;
if (status == null) {
if (other.status != null)
return false;
} else if (!status.equals(other.status))
return false;
if (system == null) {
if (other.system != null)
return false;
} else if (!system.equals(other.system))
return false;
if (vDC == null) {
if (other.vDC != null)
return false;
} else if (!vDC.equals(other.vDC))
return false;
return true;
}
public String getId() {
return id;
@ -210,11 +223,13 @@ public boolean equals(Object obj) {
@Override
public String toString() {
return "VAppImpl [id=" + id + ", location=" + location + ", name=" + name
+ ", networkToAddresses=" + networkToAddresses + ", operatingSystemDescription="
+ operatingSystemDescription + ", resourceAllocationByType="
+ resourceAllocationByType + ", resourceAllocations=" + resourceAllocations
+ ", size=" + size + ", status=" + status + ", system=" + system + "]";
return "[id=" + id + ", location=" + location + ", name=" + name
+ ", networkToAddresses=" + networkToAddresses
+ ", operatingSystemDescription=" + operatingSystemDescription
+ ", resourceAllocationByType=" + resourceAllocationByType
+ ", resourceAllocations=" + resourceAllocations + ", size=" + size
+ ", status=" + status + ", system=" + system + ", vDC=" + vDC
+ "]";
}
@Override

View File

@ -28,6 +28,7 @@ import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VApp;
@ -72,9 +73,10 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
protected String id;
protected URI location;
protected Long size;
protected NamedResource vDC;
public VApp getResult() {
return new VAppImpl(id, name, location, status, size, networkToAddresses,
return new VAppImpl(id, name, location, status, size, vDC, networkToAddresses,
operatingSystemDescription, system, allocations);
}
@ -88,6 +90,10 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
if (attributes.getIndex("size") != -1)
size = new Long(attributes.getValue(attributes.getIndex("size")));
} else if (qName.equals("Link")) {
if (attributes.getValue(attributes.getIndex("type")).equals(VCloudMediaType.VDC_XML)) {
vDC = Utils.newNamedResource(attributes);
}
} else if (qName.equals("OperatingSystemSection")) {
inOs = true;
} else if (qName.equals("NetworkConnection")) {

View File

@ -56,7 +56,7 @@ public class VCloudComputeClient {
}
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UBUNTU_90, "10").put(
Image.CENTOS_53, "1").put(Image.RHEL_53, "8").put(Image.UBUNTU_90, "10").put(
Image.UBUNTU_JEOS_90, "11").build();
public Map<String, String> start(String name, Image image, int minCores, int minMegs,

View File

@ -51,7 +51,7 @@ import com.google.inject.internal.ImmutableMap;
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest")
@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest")
public class VCloudComputeClientLiveTest {
VCloudComputeClient client;
VCloudClient tmClient;
@ -59,7 +59,7 @@ public class VCloudComputeClientLiveTest {
private String id;
private InetAddress privateAddress;
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
public static final String PREFIX = (System.getProperty("user.name") + "-vcloud").replaceAll("\\.","");
private static class Expectation {
final long hardDisk;
@ -103,8 +103,8 @@ public class VCloudComputeClientLiveTest {
private String getCompatibleServerName(Image toTest) {
String serverName = CaseFormat.UPPER_UNDERSCORE
.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0,
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
.to(CaseFormat.LOWER_CAMEL, toTest.toString()).substring(0,
toTest.toString().length()-1 <= 15 ? toTest.toString().length()-1 : 14);
return serverName;
}

View File

@ -32,10 +32,12 @@ import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ListMultimap;
@ -46,8 +48,7 @@ import com.google.common.collect.ListMultimap;
*/
@Test(groups = "unit", testName = "vcloud.VAppHandlerTest")
public class VAppHandlerTest extends BaseHandlerTest {
// TODO why does this fail?
@Test(enabled = false)
@Test(enabled=false)
public void testHosting() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml");
@ -77,11 +78,26 @@ public class VAppHandlerTest extends BaseHandlerTest {
VApp expects = new VAppImpl("188849-74", "188849-74", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-74"), VAppStatus.ON,
new Long(20971520), networkToAddresses, null, system, resourceAllocations);
new Long(20971520),null,
networkToAddresses, null, system, resourceAllocations);
assertEquals(result, expects);
}
public void testInstantiated() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/instantiatedvapp.xml");
VApp result = factory.create(
injector.getInstance(VAppHandler.class)).parse(is);
VApp expects = new VAppImpl("10", "centos53", URI
.create("http://10.150.4.49/api/v0.8/vApp/10"),
VAppStatus.RESOLVED, 123456789l, new NamedResourceImpl("4", null,
"application/vnd.vmware.vcloud.vdc+xml", URI
.create("http://10.150.4.49/api/v0.8/vdc/4")),
ImmutableListMultimap.<String, InetAddress> of(),
null, null, ImmutableSet.<ResourceAllocation>of());
assertEquals(result, expects);
}
// TODO why does this fail?
@Test(enabled = false)
public void testDefault() throws UnknownHostException {
@ -114,7 +130,10 @@ public class VAppHandlerTest extends BaseHandlerTest {
VApp expects = new VAppImpl("4", "Oracle", URI
.create("http://10.150.4.49/api/v0.8/vApp/4"), VAppStatus.ON,
new Long(104857), networkToAddresses, "Other Linux (32-bit)", system, resourceAllocations);
new Long(104857), new NamedResourceImpl("32", null,
"application/vnd.vmware.vcloud.vdc+xml", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")),
networkToAddresses, "Other Linux (32-bit)", system, resourceAllocations);
assertEquals(result, expects);

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="http://10.150.4.49/api/v0.8/vApp/10" type="application/vnd.vmware.vcloud.vApp+xml"
name="centos53" status="1"
size="123456789" xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="up"
href="http://10.150.4.49/api/v0.8/vdc/4"
type="application/vnd.vmware.vcloud.vdc+xml"/>
</VApp>

View File

@ -1,149 +1,153 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="http://10.150.4.49/api/v0.8/vApp/4" type="application/vnd.vmware.vcloud.vApp+xml"
name="Oracle" status="4"
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://10.150.4.49/api/v0.8/vcloud/vApp.xsd"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns="http://www.vmware.com/vcloud/v0.8"
xmlns:vmw="http://www.vmware.com/schema/ovf"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" size="104857">
<Link rel="up" href="http://10.150.4.49/api/v0.8/vdc/4" type="application/vnd.vmware.vcloud.vdc+xml" />
<OperatingSystemSection d2p1:id="36"
xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:d2p1="http://schemas.dmtf.org/ovf/envelope/1">
<Info>The kind of installed guest operating system</Info>
<Description>Other Linux (32-bit)</Description>
</OperatingSystemSection>
<VirtualHardwareSection xmlns="http://schemas.dmtf.org/ovf/envelope/1">
<Info>Virtual hardware</Info>
<Link rel="edit" href="http://10.150.4.49/api/v0.8/vApp/4"
type="application/vnd.vmware.ovf.virtualHardwareSection+xml" />
<System>
<vssd:AutomaticRecoveryAction xsi:nil="true" />
<vssd:AutomaticShutdownAction xsi:nil="true" />
<vssd:AutomaticStartupAction xsi:nil="true" />
<vssd:AutomaticStartupActionDelay
xsi:nil="true" />
<vssd:AutomaticStartupActionSequenceNumber
xsi:nil="true" />
<vssd:Caption xsi:nil="true" />
<vssd:ConfigurationDataRoot xsi:nil="true" />
<vssd:ConfigurationFile xsi:nil="true" />
<vssd:ConfigurationID xsi:nil="true" />
<vssd:CreationTime xsi:nil="true" />
<vssd:Description xsi:nil="true" />
<vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
<vssd:InstanceID>0</vssd:InstanceID>
<vssd:LogDataRoot xsi:nil="true" />
<vssd:RecoveryFile xsi:nil="true" />
<vssd:SnapshotDataRoot xsi:nil="true" />
<vssd:SuspendDataRoot xsi:nil="true" />
<vssd:SwapFileDataRoot xsi:nil="true" />
<vssd:VirtualSystemIdentifier>Oracle</vssd:VirtualSystemIdentifier>
<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>
</System>
<Item>
<rasd:Address xsi:nil="true" />
<rasd:AddressOnParent xsi:nil="true" />
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent xsi:nil="true" />
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType xsi:nil="true" />
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>count</rasd:VirtualQuantityUnits>
<rasd:Weight xsi:nil="true" />
</Item>
<Item>
<rasd:Address xsi:nil="true" />
<rasd:AddressOnParent xsi:nil="true" />
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description>Memory Size</rasd:Description>
<rasd:ElementName>16MB of memory</rasd:ElementName>
<rasd:InstanceID>2</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent xsi:nil="true" />
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType xsi:nil="true" />
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>16</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>byte * 2^20</rasd:VirtualQuantityUnits>
<rasd:Weight xsi:nil="true" />
</Item>
<Item>
<rasd:Address>0</rasd:Address>
<rasd:AddressOnParent xsi:nil="true" />
<rasd:AllocationUnits xsi:nil="true" />
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description>SCSI Controller</rasd:Description>
<rasd:ElementName>SCSI Controller 0</rasd:ElementName>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent xsi:nil="true" />
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>
<rasd:ResourceType>6</rasd:ResourceType>
<rasd:VirtualQuantity xsi:nil="true" />
<rasd:VirtualQuantityUnits xsi:nil="true" />
<rasd:Weight xsi:nil="true" />
</Item>
<Item>
<rasd:AddressOnParent>7</rasd:AddressOnParent>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Connection connected="true">Internal</rasd:Connection>
<rasd:Description>PCNet32 ethernet adapter on "Internal" network
</rasd:Description>
<rasd:ElementName>Network Adapter 1</rasd:ElementName>
<rasd:InstanceID>8</rasd:InstanceID>
<rasd:ResourceSubType>PCNet32</rasd:ResourceSubType>
<rasd:ResourceType>10</rasd:ResourceType>
</Item>
<Item>
<rasd:Address xsi:nil="true" />
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AllocationUnits xsi:nil="true" />
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description xsi:nil="true" />
<rasd:ElementName>Hard Disk 1</rasd:ElementName>
<rasd:HostResource>104857</rasd:HostResource>
<rasd:InstanceID>9</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent>3</rasd:Parent>
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType xsi:nil="true" />
<rasd:ResourceType>17</rasd:ResourceType>
<rasd:VirtualQuantity>104857</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits xsi:nil="true" />
<rasd:Weight xsi:nil="true" />
</Item>
</VirtualHardwareSection>
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="http://10.150.4.49/api/v0.8/vApp/10" type="application/vnd.vmware.vcloud.vApp+xml"
name="centos53" status="4"
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://10.150.4.49/api/v0.8/vcloud/vApp.xsd"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"
xmlns="http://www.vmware.com/vcloud/v0.8"
xmlns:vmw="http://www.vmware.com/schema/ovf"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" size="104857">
<Link rel="up"
href="http://10.150.4.49/api/v0.8/vdc/4"
type="application/vnd.vmware.vcloud.vdc+xml"/>
<NetworkConnectionSection xmlns="http://schemas.dmtf.org/ovf/envelope/1"
xmlns:ovf="http://www.vmware.com/vcloud/v0.8">
<ovf:NetworkConnection Network="Public Network">
<ovf:IpAddress>10.150.4.93</ovf:IpAddress>
</ovf:NetworkConnection>
</NetworkConnectionSection>
<OperatingSystemSection d2p1:id="36" xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:d2p1="http://schemas.dmtf.org/ovf/envelope/1">
<Info>The kind of installed guest operating system</Info>
<Description>Other Linux (32-bit)</Description>
</OperatingSystemSection>
<VirtualHardwareSection xmlns="http://schemas.dmtf.org/ovf/envelope/1">
<Info>Virtual hardware</Info>
<Link rel="edit" href="http://10.150.4.49/api/v0.8/vApp/10" type="application/vnd.vmware.ovf.virtualHardwareSection+xml"/>
<System>
<vssd:AutomaticRecoveryAction xsi:nil="true" />
<vssd:AutomaticShutdownAction xsi:nil="true" />
<vssd:AutomaticStartupAction xsi:nil="true" />
<vssd:AutomaticStartupActionDelay xsi:nil="true" />
<vssd:AutomaticStartupActionSequenceNumber xsi:nil="true" />
<vssd:Caption xsi:nil="true" />
<vssd:ConfigurationDataRoot xsi:nil="true" />
<vssd:ConfigurationFile xsi:nil="true" />
<vssd:ConfigurationID xsi:nil="true" />
<vssd:CreationTime xsi:nil="true" />
<vssd:Description xsi:nil="true" />
<vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
<vssd:InstanceID>0</vssd:InstanceID>
<vssd:LogDataRoot xsi:nil="true" />
<vssd:RecoveryFile xsi:nil="true" />
<vssd:SnapshotDataRoot xsi:nil="true" />
<vssd:SuspendDataRoot xsi:nil="true" />
<vssd:SwapFileDataRoot xsi:nil="true" />
<vssd:VirtualSystemIdentifier>centos53</vssd:VirtualSystemIdentifier>
<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>
</System>
<Item>
<rasd:Address xsi:nil="true" />
<rasd:AddressOnParent xsi:nil="true" />
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent xsi:nil="true" />
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType xsi:nil="true" />
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>count</rasd:VirtualQuantityUnits>
<rasd:Weight xsi:nil="true" />
</Item>
<Item>
<rasd:Address xsi:nil="true" />
<rasd:AddressOnParent xsi:nil="true" />
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description>Memory Size</rasd:Description>
<rasd:ElementName>16MB of memory</rasd:ElementName>
<rasd:InstanceID>2</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent xsi:nil="true" />
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType xsi:nil="true" />
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>16</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>byte * 2^20</rasd:VirtualQuantityUnits>
<rasd:Weight xsi:nil="true" />
</Item>
<Item>
<rasd:Address>0</rasd:Address>
<rasd:AddressOnParent xsi:nil="true" />
<rasd:AllocationUnits xsi:nil="true" />
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description>SCSI Controller</rasd:Description>
<rasd:ElementName>SCSI Controller 0</rasd:ElementName>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent xsi:nil="true" />
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>
<rasd:ResourceType>6</rasd:ResourceType>
<rasd:VirtualQuantity xsi:nil="true" />
<rasd:VirtualQuantityUnits xsi:nil="true" />
<rasd:Weight xsi:nil="true" />
</Item>
<Item>
<rasd:AddressOnParent>7</rasd:AddressOnParent>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Connection connected="true">Internal</rasd:Connection>
<rasd:Description>PCNet32 ethernet adapter on "Internal" network</rasd:Description>
<rasd:ElementName>Network Adapter 1</rasd:ElementName>
<rasd:InstanceID>8</rasd:InstanceID>
<rasd:ResourceSubType>PCNet32</rasd:ResourceSubType>
<rasd:ResourceType>10</rasd:ResourceType>
</Item>
<Item>
<rasd:Address xsi:nil="true" />
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:AllocationUnits xsi:nil="true" />
<rasd:AutomaticAllocation xsi:nil="true" />
<rasd:AutomaticDeallocation xsi:nil="true" />
<rasd:Caption xsi:nil="true" />
<rasd:ConsumerVisibility xsi:nil="true" />
<rasd:Description xsi:nil="true" />
<rasd:ElementName>Hard Disk 1</rasd:ElementName>
<rasd:HostResource>104857</rasd:HostResource>
<rasd:InstanceID>9</rasd:InstanceID>
<rasd:Limit xsi:nil="true" />
<rasd:MappingBehavior xsi:nil="true" />
<rasd:OtherResourceType xsi:nil="true" />
<rasd:Parent>3</rasd:Parent>
<rasd:PoolID xsi:nil="true" />
<rasd:Reservation xsi:nil="true" />
<rasd:ResourceSubType xsi:nil="true" />
<rasd:ResourceType>17</rasd:ResourceType>
<rasd:VirtualQuantity>104857</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits xsi:nil="true" />
<rasd:Weight xsi:nil="true" />
</Item>
</VirtualHardwareSection>
</VApp>

View File

@ -19,11 +19,13 @@
package org.jclouds.vcloud.hostingdotcom.config;
import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.vcloud.VCloudAsyncClient;
@ -31,7 +33,9 @@ import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient;
import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Predicate;
import com.google.inject.Provides;
/**
@ -71,5 +75,9 @@ public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule
protected URI provideDefaultNetwork(VCloudAsyncClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
@Override
protected Predicate<String> successTester(TaskSuccess success) {
return new RetryablePredicate<String>(success, 45, 10, TimeUnit.MINUTES);
}
}

View File

@ -22,6 +22,7 @@ import java.net.InetAddress;
import java.net.URI;
import java.util.Set;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
@ -45,10 +46,10 @@ public class HostingDotComVAppImpl extends VAppImpl implements HostingDotComVApp
private static final long serialVersionUID = 8464716396538298809L;
public HostingDotComVAppImpl(String id, String name, URI location, VAppStatus status, Long size,
ListMultimap<String, InetAddress> networkToAddresses,
NamedResource vDC, ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, VirtualSystem system,
Set<ResourceAllocation> resourceAllocations, String username, String password) {
super(id, name, location, status, size, networkToAddresses, operatingSystemDescription,
super(id, name, location, status, size, vDC, networkToAddresses, operatingSystemDescription,
system, resourceAllocations);
this.username = username;
this.password = password;

View File

@ -43,7 +43,7 @@ public class HostingDotComVAppHandler extends VAppHandler {
}
public HostingDotComVApp getResult() {
return new HostingDotComVAppImpl(id, name, location, status, size, networkToAddresses,
return new HostingDotComVAppImpl(id, name, location, status, size, vDC, networkToAddresses,
operatingSystemDescription, system, allocations, username, password);
}

View File

@ -53,7 +53,7 @@ import com.google.inject.internal.ImmutableMap;
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest")
@Test(groups = "live", enabled = false, sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest")
public class HostingDotComVCloudComputeClientLiveTest {
HostingDotComVCloudComputeClient client;
HostingDotComVCloudClient tmClient;

View File

@ -28,6 +28,7 @@ import java.net.UnknownHostException;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import org.testng.annotations.Test;
@ -51,7 +52,10 @@ public class HostingDotComVAppHandlerTest extends BaseHandlerTest {
HostingDotComVApp expects = new HostingDotComVAppImpl("188849-33", "188849-33", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-33"),
VAppStatus.RESOLVED, null, ImmutableListMultimap.<String, InetAddress> of(),
VAppStatus.RESOLVED, null, new NamedResourceImpl("188849", null,
"application/vnd.vmware.vcloud.vdc+xml", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")),
ImmutableListMultimap.<String, InetAddress> of(),
null, null, ImmutableSortedSet.<ResourceAllocation> of(), "root", "meatisyummy");
assertEquals(result, expects);

View File

@ -48,6 +48,7 @@ import org.jclouds.rest.functions.InetAddressToHostAddress;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.CatalogIdToUri;
@ -66,7 +67,6 @@ import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.functions.ParseTaskFromLocationHeader;
import org.jclouds.vcloud.terremark.functions.ReturnVoidOnDeleteDefaultIp;
@ -80,9 +80,9 @@ import org.jclouds.vcloud.terremark.xml.IpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import com.google.common.util.concurrent.ListenableFuture;
@ -134,10 +134,10 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@Path("/vdc/{vDCId}/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(TerremarkVAppHandler.class)
@XMLResponseParser(VAppHandler.class)
@MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlPayload.class)
@Override
ListenableFuture<? extends TerremarkVApp> instantiateVAppTemplateInVDC(
ListenableFuture<? extends VApp> instantiateVAppTemplateInVDC(
@PathParam("vDCId") String vDCId, @MapPayloadParam("name") String appName,
@MapPayloadParam("template") @ParamParser(CatalogIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
@ -315,17 +315,6 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@Path("/nodeServices/{nodeId}")
ListenableFuture<Void> deleteNode(@PathParam("nodeId") int nodeId);
/**
* @see TerremarkVCloudClient#getVApp
*/
@GET
@Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}")
@XMLResponseParser(TerremarkVAppHandler.class)
@Override
ListenableFuture<? extends TerremarkVApp> getVApp(@PathParam("vAppId") String vAppId);
/**
* @see TerremarkVCloudClient#configureVApp
*/
@ -337,7 +326,7 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@MapBinder(BindVAppConfigurationToXmlPayload.class)
@ResponseParser(ParseTaskFromLocationHeader.class)
ListenableFuture<? extends Task> configureVApp(
@PathParam("vAppId") @ParamParser(VAppId.class) TerremarkVApp vApp,
@PathParam("vAppId") @ParamParser(VAppId.class) VApp vApp,
VAppConfiguration configuration);
/**

View File

@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.terremark.domain.ComputeOptions;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService;
@ -35,7 +35,6 @@ import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@ -50,13 +49,6 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudClient {
@Override
TerremarkVApp instantiateVAppTemplateInVDC(String vDCId, String appName, String templateId,
InstantiateVAppTemplateOptions... options);
@Override
TerremarkVApp getVApp(String vAppId);
/**
* This call returns the compute options for the vApp. The compute options are the CPU and memory
* configurations supported by Terremark and by the guest operating system of the vApp. This call
@ -159,6 +151,6 @@ public interface TerremarkVCloudClient extends VCloudClient {
* @param configuration(s) to change
* @return task of configuration change
*/
Task configureVApp(TerremarkVApp vApp, VAppConfiguration configuration);
Task configureVApp(VApp vApp, VAppConfiguration configuration);
}

View File

@ -39,8 +39,8 @@ import org.jclouds.rest.binders.BindToStringPayload;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import com.google.common.collect.Iterables;
@ -77,7 +77,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
TerremarkVApp vApp = checkNotNull(findVAppInArgsOrNull(gRequest), "vApp");
VApp vApp = checkNotNull(findVAppInArgsOrNull(gRequest), "vApp");
checkArgument(vApp.getStatus() == VAppStatus.OFF, "vApp must be off!");
VAppConfiguration configuration = checkNotNull(findConfigInArgsOrNull(gRequest), "config");
@ -93,7 +93,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
}
protected String generateXml(TerremarkVApp vApp, VAppConfiguration configuration)
protected String generateXml(VApp vApp, VAppConfiguration configuration)
throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
String name = configuration.getName() != null ? configuration.getName() : vApp.getName();
@ -114,7 +114,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
return rootBuilder.asString(outputProperties);
}
private void addProcessorItem(XMLBuilder sectionBuilder, TerremarkVApp vApp,
private void addProcessorItem(XMLBuilder sectionBuilder, VApp vApp,
VAppConfiguration configuration) {
ResourceAllocation cpu = Iterables.getOnlyElement(vApp.getResourceAllocationByType().get(
ResourceType.PROCESSOR));
@ -123,7 +123,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
addResourceWithQuantity(sectionBuilder, cpu, quantity);
}
private void addMemoryItem(XMLBuilder sectionBuilder, TerremarkVApp vApp,
private void addMemoryItem(XMLBuilder sectionBuilder, VApp vApp,
VAppConfiguration configuration) {
ResourceAllocation memory = Iterables.getOnlyElement(vApp.getResourceAllocationByType().get(
ResourceType.MEMORY));
@ -132,7 +132,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
addResourceWithQuantity(sectionBuilder, memory, quantity);
}
private void addDiskItems(XMLBuilder sectionBuilder, TerremarkVApp vApp,
private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp,
VAppConfiguration configuration) {
for (ResourceAllocation disk : vApp.getResourceAllocationByType()
.get(ResourceType.DISK_DRIVE)) {
@ -169,21 +169,21 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
return itemBuilder;
}
protected XMLBuilder buildRoot(TerremarkVApp vApp, String name)
protected XMLBuilder buildRoot(VApp vApp, String name)
throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("VApp").a("type", vApp.getType()).a("name", name)
.a("status", vApp.getStatus().value()).a("size", vApp.getSize().toString()).a(
.a("status", vApp.getStatus().value()).a("size", vApp.getSize()+"").a(
"xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a(
"xsi:schemaLocation", ns + " " + schema);
return rootBuilder;
}
protected TerremarkVApp findVAppInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
protected VApp findVAppInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof TerremarkVApp) {
return (TerremarkVApp) arg;
} else if (arg instanceof TerremarkVApp[]) {
TerremarkVApp[] vapps = (TerremarkVApp[]) arg;
if (arg instanceof VApp) {
return (VApp) arg;
} else if (arg instanceof VApp[]) {
VApp[] vapps = (VApp[]) arg;
return (vapps.length > 0) ? vapps[0] : null;
}
}

View File

@ -35,13 +35,13 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
@ -81,7 +81,7 @@ public class TerremarkVCloudComputeClient {
.debug(
">> instantiating vApp vDC(%s) template(%s) name(%s) minCores(%d) minMegs(%d) properties(%s)",
vDCId, templateId, name, minCores, minMegs, properties);
TerremarkVApp vApp = tmClient.instantiateVAppTemplateInVDC(vDCId, name, templateId,
VApp vApp = tmClient.instantiateVAppTemplateInVDC(vDCId, name, templateId,
TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(minCores).memory(
minMegs).productProperties(properties));
logger.debug("<< instantiated VApp(%s)", vApp.getId());
@ -105,12 +105,12 @@ public class TerremarkVCloudComputeClient {
* if no address is configured
*/
public InetAddress getAnyPrivateAddress(String id) {
TerremarkVApp vApp = tmClient.getVApp(id);
VApp vApp = tmClient.getVApp(id);
return Iterables.getLast(vApp.getNetworkToAddresses().values());
}
public Set<InetAddress> getPublicAddresses(String id) {
TerremarkVApp vApp = tmClient.getVApp(id);
VApp vApp = tmClient.getVApp(id);
Set<InetAddress> ipAddresses = Sets.newHashSet();
for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC().getId())) {
for (Node node : tmClient.getNodes(service.getId())) {
@ -123,14 +123,14 @@ public class TerremarkVCloudComputeClient {
}
public void reboot(String id) {
TerremarkVApp vApp = tmClient.getVApp(id);
VApp vApp = tmClient.getVApp(id);
logger.debug(">> rebooting vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset",
VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
}
public InetAddress createPublicAddressMappedToPorts(TerremarkVApp vApp, int... ports) {
public InetAddress createPublicAddressMappedToPorts(VApp vApp, int... ports) {
PublicIpAddress ip = null;
InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
for (int port : ports) {
@ -180,7 +180,7 @@ public class TerremarkVCloudComputeClient {
}
public void stop(String id) {
TerremarkVApp vApp = tmClient.getVApp(id);
VApp vApp = tmClient.getVApp(id);
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
@ -198,7 +198,7 @@ public class TerremarkVCloudComputeClient {
logger.debug("<< deleted vApp(%s)", vApp.getId());
}
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(TerremarkVApp vApp) {
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) {
Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
SERVICE: for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC()
.getId())) {
@ -238,7 +238,7 @@ public class TerremarkVCloudComputeClient {
}
}
private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask,
private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask,
String taskType, VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getId())) {
throw new TaskException(taskType, vApp, deployTask);
@ -258,7 +258,7 @@ public class TerremarkVCloudComputeClient {
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, TerremarkVApp vApp, Task task) {
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type,
vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
@ -289,16 +289,16 @@ public class TerremarkVCloudComputeClient {
public static class VAppException extends RuntimeException {
private final TerremarkVApp vApp;
private final VApp vApp;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, TerremarkVApp vApp) {
public VAppException(String message, VApp vApp) {
super(message);
this.vApp = vApp;
}
public TerremarkVApp getvApp() {
public VApp getvApp() {
return vApp;
}

View File

@ -45,7 +45,6 @@ import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
@ -80,7 +79,7 @@ public class TerremarkVCloudComputeService implements ComputeService {
@Override
public CreateNodeResponse createNode(String name, Profile profile, Image image) {
String id = computeClient.start(name, image, 1, 512, ImmutableMap.<String, String> of());
TerremarkVApp vApp = tmClient.getVApp(id);
VApp vApp = tmClient.getVApp(id);
InetAddress publicIp = computeClient
.createPublicAddressMappedToPorts(vApp, 22, 80, 8080, 443);
return new CreateNodeResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToNodeState

View File

@ -1,35 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.domain;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVAppImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@ImplementedBy(TerremarkVAppImpl.class)
public interface TerremarkVApp extends VApp {
NamedResource getVDC();
}

View File

@ -1,302 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.domain;
import java.util.Date;
import org.jclouds.vcloud.domain.VirtualSystem;
/**
* @author Adrian Cole
*/
public class TerremarkVirtualSystem extends VirtualSystem {
private final String automaticRecoveryAction;
private final String automaticShutdownAction;
private final String automaticStartupAction;
private final String automaticStartupActionDelay;
private final String automaticStartupActionSequenceNumber;
private final String caption;
private final String configurationDataRoot;
private final String configurationFile;
private final String configurationID;
private final Date creationTime;
private final String description;
private final String logDataRoot;
private final String recoveryFile;
private final String snapshotDataRoot;
private final String suspendDataRoot;
private final String swapFileDataRoot;
public TerremarkVirtualSystem(String automaticRecoveryAction, String automaticShutdownAction,
String automaticStartupAction, String automaticStartupActionDelay,
String automaticStartupActionSequenceNumber, String caption,
String configurationDataRoot, String configurationFile, String configurationID,
Date creationTime, String description, String elementName, int instanceID,
String logDataRoot, String recoveryFile, String snapshotDataRoot,
String suspendDataRoot, String swapFileDataRoot, String virtualSystemIdentifier,
String virtualSystemType) {
super(instanceID, elementName, virtualSystemIdentifier, virtualSystemType);
this.automaticRecoveryAction = automaticRecoveryAction;
this.automaticShutdownAction = automaticShutdownAction;
this.automaticStartupAction = automaticStartupAction;
this.automaticStartupActionDelay = automaticStartupActionDelay;
this.automaticStartupActionSequenceNumber = automaticStartupActionSequenceNumber;
this.caption = caption;
this.configurationDataRoot = configurationDataRoot;
this.configurationFile = configurationFile;
this.configurationID = configurationID;
this.creationTime = creationTime;
this.description = description;
this.logDataRoot = logDataRoot;
this.recoveryFile = recoveryFile;
this.snapshotDataRoot = snapshotDataRoot;
this.suspendDataRoot = suspendDataRoot;
this.swapFileDataRoot = swapFileDataRoot;
}
public String getAutomaticRecoveryAction() {
return automaticRecoveryAction;
}
public String getAutomaticShutdownAction() {
return automaticShutdownAction;
}
public String getAutomaticStartupAction() {
return automaticStartupAction;
}
public String getAutomaticStartupActionDelay() {
return automaticStartupActionDelay;
}
public String getAutomaticStartupActionSequenceNumber() {
return automaticStartupActionSequenceNumber;
}
public String getCaption() {
return caption;
}
public String getConfigurationDataRoot() {
return configurationDataRoot;
}
public String getConfigurationFile() {
return configurationFile;
}
public String getConfigurationID() {
return configurationID;
}
public Date getCreationTime() {
return creationTime;
}
public String getDescription() {
return description;
}
public String getLogDataRoot() {
return logDataRoot;
}
public String getRecoveryFile() {
return recoveryFile;
}
public String getSnapshotDataRoot() {
return snapshotDataRoot;
}
public String getSuspendDataRoot() {
return suspendDataRoot;
}
public String getSwapFileDataRoot() {
return swapFileDataRoot;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((automaticRecoveryAction == null) ? 0 : automaticRecoveryAction.hashCode());
result = prime * result
+ ((automaticShutdownAction == null) ? 0 : automaticShutdownAction.hashCode());
result = prime * result
+ ((automaticStartupAction == null) ? 0 : automaticStartupAction.hashCode());
result = prime
* result
+ ((automaticStartupActionDelay == null) ? 0 : automaticStartupActionDelay
.hashCode());
result = prime
* result
+ ((automaticStartupActionSequenceNumber == null) ? 0
: automaticStartupActionSequenceNumber.hashCode());
result = prime * result + ((caption == null) ? 0 : caption.hashCode());
result = prime * result
+ ((configurationDataRoot == null) ? 0 : configurationDataRoot.hashCode());
result = prime * result + ((configurationFile == null) ? 0 : configurationFile.hashCode());
result = prime * result + ((configurationID == null) ? 0 : configurationID.hashCode());
result = prime * result + ((creationTime == null) ? 0 : creationTime.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + id;
result = prime * result + ((logDataRoot == null) ? 0 : logDataRoot.hashCode());
result = prime * result + ((recoveryFile == null) ? 0 : recoveryFile.hashCode());
result = prime * result + ((snapshotDataRoot == null) ? 0 : snapshotDataRoot.hashCode());
result = prime * result + ((suspendDataRoot == null) ? 0 : suspendDataRoot.hashCode());
result = prime * result + ((swapFileDataRoot == null) ? 0 : swapFileDataRoot.hashCode());
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TerremarkVirtualSystem other = (TerremarkVirtualSystem) obj;
if (automaticRecoveryAction == null) {
if (other.automaticRecoveryAction != null)
return false;
} else if (!automaticRecoveryAction.equals(other.automaticRecoveryAction))
return false;
if (automaticShutdownAction == null) {
if (other.automaticShutdownAction != null)
return false;
} else if (!automaticShutdownAction.equals(other.automaticShutdownAction))
return false;
if (automaticStartupAction == null) {
if (other.automaticStartupAction != null)
return false;
} else if (!automaticStartupAction.equals(other.automaticStartupAction))
return false;
if (automaticStartupActionDelay == null) {
if (other.automaticStartupActionDelay != null)
return false;
} else if (!automaticStartupActionDelay.equals(other.automaticStartupActionDelay))
return false;
if (automaticStartupActionSequenceNumber == null) {
if (other.automaticStartupActionSequenceNumber != null)
return false;
} else if (!automaticStartupActionSequenceNumber
.equals(other.automaticStartupActionSequenceNumber))
return false;
if (caption == null) {
if (other.caption != null)
return false;
} else if (!caption.equals(other.caption))
return false;
if (configurationDataRoot == null) {
if (other.configurationDataRoot != null)
return false;
} else if (!configurationDataRoot.equals(other.configurationDataRoot))
return false;
if (configurationFile == null) {
if (other.configurationFile != null)
return false;
} else if (!configurationFile.equals(other.configurationFile))
return false;
if (configurationID == null) {
if (other.configurationID != null)
return false;
} else if (!configurationID.equals(other.configurationID))
return false;
if (creationTime == null) {
if (other.creationTime != null)
return false;
} else if (!creationTime.equals(other.creationTime))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (id != other.id)
return false;
if (logDataRoot == null) {
if (other.logDataRoot != null)
return false;
} else if (!logDataRoot.equals(other.logDataRoot))
return false;
if (recoveryFile == null) {
if (other.recoveryFile != null)
return false;
} else if (!recoveryFile.equals(other.recoveryFile))
return false;
if (snapshotDataRoot == null) {
if (other.snapshotDataRoot != null)
return false;
} else if (!snapshotDataRoot.equals(other.snapshotDataRoot))
return false;
if (suspendDataRoot == null) {
if (other.suspendDataRoot != null)
return false;
} else if (!suspendDataRoot.equals(other.suspendDataRoot))
return false;
if (swapFileDataRoot == null) {
if (other.swapFileDataRoot != null)
return false;
} else if (!swapFileDataRoot.equals(other.swapFileDataRoot))
return false;
if (identifier == null) {
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return "VirtualSystem [automaticRecoveryAction=" + automaticRecoveryAction
+ ", automaticShutdownAction=" + automaticShutdownAction
+ ", automaticStartupAction=" + automaticStartupAction
+ ", automaticStartupActionDelay=" + automaticStartupActionDelay
+ ", automaticStartupActionSequenceNumber=" + automaticStartupActionSequenceNumber
+ ", caption=" + caption + ", configurationDataRoot=" + configurationDataRoot
+ ", configurationFile=" + configurationFile + ", configurationID="
+ configurationID + ", creationTime=" + creationTime + ", description="
+ description + ", elementName=" + name + ", instanceID=" + id + ", logDataRoot="
+ logDataRoot + ", recoveryFile=" + recoveryFile + ", snapshotDataRoot="
+ snapshotDataRoot + ", suspendDataRoot=" + suspendDataRoot + ", swapFileDataRoot="
+ swapFileDataRoot + ", virtualSystemIdentifier=" + identifier
+ ", virtualSystemType=" + type + "]";
}
}

View File

@ -1,86 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.domain.internal;
import java.net.InetAddress;
import java.net.URI;
import java.util.SortedSet;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem;
import com.google.common.collect.ListMultimap;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class TerremarkVAppImpl extends VAppImpl implements TerremarkVApp {
private final NamedResource vDC;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public TerremarkVAppImpl(String id, String name, String type, URI location, VAppStatus status,
long size, NamedResource vDC, ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, TerremarkVirtualSystem system,
SortedSet<ResourceAllocation> resourceAllocations) {
super(id, name, location, status, size, networkToAddresses, operatingSystemDescription,
system, resourceAllocations);
this.vDC = vDC;
}
public NamedResource getVDC() {
return vDC;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((vDC == null) ? 0 : vDC.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;
TerremarkVAppImpl other = (TerremarkVAppImpl) obj;
if (vDC == null) {
if (other.vDC != null)
return false;
} else if (!vDC.equals(other.vDC))
return false;
return true;
}
}

View File

@ -1,131 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.xml;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<ResourceAllocation> {
private StringBuilder currentText = new StringBuilder();
private Integer address;
private Integer addressOnParent;
private String hostResource;
private String allocationUnits;
private String description;
private String elementName;
private int instanceID;
private Integer parent;
private String resourceSubType;
private ResourceType resourceType;
private long virtualQuantity = 1;
private String virtualQuantityUnits;
private ResourceAllocation item;
private boolean skip;
public ResourceAllocation getResult() {
return item;
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (attributes.getIndex("xsi:nil") != -1 || attributes.getIndex("xmlns") == -1) {
String ns = attributes.getValue(attributes.getIndex("xmlns"));
if ("http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
.equals(ns)) {
skip = false;
} else {
skip = true;
return;
}
} else {
skip = false;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (!skip) {
if (qName.equals("Address")) {
String address = currentText.toString().trim();
if (address != null && !address.equals(""))
this.address = Integer.parseInt(address);
} else if (qName.equals("AddressOnParent")) {
String addressOnParent = currentText.toString().trim();
if (addressOnParent != null && !addressOnParent.equals(""))
this.addressOnParent = Integer.parseInt(addressOnParent);
} else if (qName.equals("AllocationUnits")) {
allocationUnits = currentText.toString().trim();
} else if (qName.equals("Description")) {
description = currentText.toString().trim();
} else if (qName.equals("ElementName")) {
elementName = currentText.toString().trim();
} else if (qName.equals("HostResource")) {
hostResource = currentText.toString().trim();
} else if (qName.equals("InstanceID")) {
instanceID = Integer.parseInt(currentText.toString().trim());
} else if (qName.equals("Parent")) {
String parent = currentText.toString().trim();
if (parent != null && !parent.equals(""))
this.parent = Integer.parseInt(parent);
} else if (qName.equals("ResourceSubType")) {
resourceSubType = currentText.toString().trim();
} else if (qName.equals("ResourceType")) {
resourceType = ResourceType.fromValue(currentText.toString().trim());
} else if (qName.equals("VirtualQuantity")) {
String quantity = currentText.toString().trim();
if (quantity != null && !quantity.equals(""))
virtualQuantity = Long.parseLong(quantity);
} else if (qName.equals("VirtualQuantityUnits")) {
virtualQuantityUnits = currentText.toString().trim();
} else if (qName.equals("Item")) {
item = new ResourceAllocation(instanceID, elementName, description, resourceType,
resourceSubType, hostResource, address, addressOnParent, parent, null, virtualQuantity,
allocationUnits != null ? allocationUnits : virtualQuantityUnits);
address = null;
addressOnParent = null;
allocationUnits = null;
description = null;
elementName = null;
instanceID = -1;
parent = null;
resourceSubType = null;
resourceType = null;
virtualQuantity = 1;
virtualQuantityUnits = null;
hostResource = null;
}
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -1,150 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.xml;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVAppImpl;
import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<TerremarkVApp> {
private final VirtualSystemHandler systemHandler;
private final ResourceAllocationHandler allocationHandler;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public TerremarkVAppHandler(VirtualSystemHandler systemHandler,
ResourceAllocationHandler allocationHandler) {
this.systemHandler = systemHandler;
this.allocationHandler = allocationHandler;
}
private TerremarkVirtualSystem system;
private SortedSet<ResourceAllocation> allocations = Sets.newTreeSet();
private NamedResource vApp;
private NamedResource vDC;
private VAppStatus status;
private int size;
private boolean skip;
private final ListMultimap<String, InetAddress> networkToAddresses = ArrayListMultimap.create();
private StringBuilder currentText = new StringBuilder();
private String operatingSystemDescription;
private boolean inOs;
private String networkName;
public TerremarkVApp getResult() {
return new TerremarkVAppImpl(vApp.getId(), vApp.getName(), vApp.getType(),
vApp.getLocation(), status, size, vDC, networkToAddresses,
operatingSystemDescription, system, allocations);
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (attributes.getIndex("xsi:nil") != -1) {
skip = true;
return;
} else {
skip = false;
}
if (qName.equals("Link")) {
if (attributes.getValue(attributes.getIndex("type")).equals(VCloudMediaType.VDC_XML)) {
vDC = Utils.newNamedResource(attributes);
}
} else if (qName.equals("VApp")) {
vApp = Utils.newNamedResource(attributes);
status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
size = Integer.parseInt(attributes.getValue(attributes.getIndex("size")));
} else if (qName.equals("OperatingSystemSection")) {
inOs = true;
} else if (qName.equals("NetworkConnection")) {
networkName = attributes.getValue(attributes.getIndex("Network"));
} else {
systemHandler.startElement(uri, localName, qName, attributes);
allocationHandler.startElement(uri, localName, qName, attributes);
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("OperatingSystemSection")) {
inOs = false;
} else if (inOs && qName.equals("Description")) {
operatingSystemDescription = currentText.toString().trim();
} else if (qName.equals("IpAddress")) {
networkToAddresses.put(networkName, parseInetAddress(currentText.toString().trim()));
} else if (qName.equals("System")) {
systemHandler.endElement(uri, localName, qName);
system = systemHandler.getResult();
} else if (qName.equals("Item")) {
allocationHandler.endElement(uri, localName, qName);
allocations.add(allocationHandler.getResult());
} else if (!skip) {
systemHandler.endElement(uri, localName, qName);
allocationHandler.endElement(uri, localName, qName);
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
systemHandler.characters(ch, start, length);
allocationHandler.characters(ch, start, length);
}
private InetAddress parseInetAddress(String string) {
String[] byteStrings = string.split("\\.");
byte[] bytes = new byte[4];
for (int i = 0; i < 4; i++) {
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
}
try {
return InetAddress.getByAddress(bytes);
} catch (UnknownHostException e) {
logger.warn(e, "error parsing ipAddress", currentText);
}
return null;
}
}

View File

@ -1,167 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.xml;
import java.util.Date;
import javax.inject.Inject;
import org.jclouds.date.DateService;
import org.jclouds.http.functions.ParseSax;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class VirtualSystemHandler extends
ParseSax.HandlerWithResult<org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem> {
private StringBuilder currentText = new StringBuilder();
protected DateService dateService;
private String automaticRecoveryAction;
private String automaticShutdownAction;
private String automaticStartupAction;
private String automaticStartupActionDelay;
private String automaticStartupActionSequenceNumber;
private String caption;
private String configurationDataRoot;
private String configurationFile;
private String configurationID;
private Date creationTime;
private String description;
private String elementName;
private int instanceID;
private String logDataRoot;
private String recoveryFile;
private String snapshotDataRoot;
private String suspendDataRoot;
private String swapFileDataRoot;
private String virtualSystemIdentifier;
private String virtualSystemType;
private org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem system;
private boolean skip;
@Inject
public VirtualSystemHandler(DateService dateService) {
this.dateService = dateService;
}
public org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem getResult() {
return system;
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (attributes.getIndex("xsi:nil") != -1
|| attributes.getIndex("xmlns") == -1
|| !"http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
.equals(attributes.getValue("xmlns"))) {
skip = true;
return;
} else {
skip = false;
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (!skip) {
if (qName.equals("AutomaticRecoveryAction")) {
this.automaticRecoveryAction = currentText.toString().trim();
} else if (qName.equals("AutomaticShutdownAction")) {
this.automaticShutdownAction = currentText.toString().trim();
} else if (qName.equals("AutomaticStartupAction")) {
this.automaticStartupAction = currentText.toString().trim();
} else if (qName.equals("AutomaticStartupActionDelay")) {
this.automaticStartupActionDelay = currentText.toString().trim();
} else if (qName.equals("AutomaticStartupActionSequenceNumber")) {
this.automaticStartupActionSequenceNumber = currentText.toString().trim();
} else if (qName.equals("Caption")) {
this.caption = currentText.toString().trim();
} else if (qName.equals("ConfigurationDataRoot")) {
this.configurationDataRoot = currentText.toString().trim();
} else if (qName.equals("ConfigurationDataRoot")) {
this.configurationDataRoot = currentText.toString().trim();
} else if (qName.equals("ConfigurationFile")) {
this.configurationFile = currentText.toString().trim();
} else if (qName.equals("ConfigurationID")) {
this.configurationID = currentText.toString().trim();
} else if (qName.equals("CreationTime")) {
this.creationTime = dateService.iso8601DateParse(currentText.toString().trim());
} else if (qName.equals("Description")) {
this.description = currentText.toString().trim();
} else if (qName.equals("ElementName")) {
this.elementName = currentText.toString().trim();
} else if (qName.equals("InstanceID")) {
this.instanceID = Integer.parseInt(currentText.toString().trim());
} else if (qName.equals("LogDataRoot")) {
this.logDataRoot = currentText.toString().trim();
} else if (qName.equals("RecoveryFile")) {
this.recoveryFile = currentText.toString().trim();
} else if (qName.equals("SnapshotDataRoot")) {
this.snapshotDataRoot = currentText.toString().trim();
} else if (qName.equals("SuspendDataRoot")) {
this.suspendDataRoot = currentText.toString().trim();
} else if (qName.equals("SwapFileDataRoot")) {
this.swapFileDataRoot = currentText.toString().trim();
} else if (qName.equals("VirtualSystemIdentifier")) {
this.virtualSystemIdentifier = currentText.toString().trim();
} else if (qName.equals("VirtualSystemType")) {
this.virtualSystemType = currentText.toString().trim();
} else if (qName.equals("System")) {
this.system = new org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem(
automaticRecoveryAction, automaticShutdownAction, automaticStartupAction,
automaticStartupActionDelay, automaticStartupActionSequenceNumber, caption,
configurationDataRoot, configurationFile, configurationID, creationTime,
description, elementName, instanceID, logDataRoot, recoveryFile,
snapshotDataRoot, suspendDataRoot, swapFileDataRoot, virtualSystemIdentifier,
virtualSystemType);
this.automaticRecoveryAction = null;
this.automaticShutdownAction = null;
this.automaticStartupAction = null;
this.automaticStartupActionDelay = null;
this.automaticStartupActionSequenceNumber = null;
this.caption = null;
this.configurationDataRoot = null;
this.configurationFile = null;
this.configurationID = null;
this.creationTime = null;
this.description = null;
this.elementName = null;
this.instanceID = -1;
this.logDataRoot = null;
this.recoveryFile = null;
this.snapshotDataRoot = null;
this.suspendDataRoot = null;
this.swapFileDataRoot = null;
this.virtualSystemIdentifier = null;
this.virtualSystemType = null;
}
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -63,9 +63,9 @@ import org.jclouds.vcloud.terremark.xml.InternetServicesHandler;
import org.jclouds.vcloud.terremark.xml.IpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
@ -165,7 +165,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
"/terremark/InstantiateVAppTemplateParams-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
@ -190,7 +190,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
"/terremark/InstantiateVAppTemplateParams-options-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);

View File

@ -52,6 +52,7 @@ import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.CloneVAppOptions;
@ -65,7 +66,6 @@ import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.testng.annotations.AfterTest;
@ -90,13 +90,13 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
private InetAddress publicIp;
private InternetService is;
private Node node;
private TerremarkVApp vApp;
private VApp vApp;
private RetryablePredicate<InetSocketAddress> socketTester;
private RetryablePredicate<String> successTester;
private TerremarkVApp clone;
private VApp clone;
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
@ -371,7 +371,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
}
private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs,
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
int processorCount, long memory, long hardDisk) {
assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);

View File

@ -37,8 +37,8 @@ import org.jclouds.vcloud.VCloudPropertiesBuilder;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVAppImpl;
import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
@ -69,10 +69,10 @@ public class BindVAppConfigurationToXmlPayloadTest {
});
public void testChangeName() throws IOException {
TerremarkVAppImpl vApp = new TerremarkVAppImpl("4213", "MyAppServer6",
"application/vnd.vmware.vcloud.vApp+xml", URI
VAppImpl vApp = new VAppImpl("4213", "MyAppServer6",
URI
.create("https://services.vcloudexpress/terremark.com/api/v0.8/vapp/4213"),
VAppStatus.OFF, 4194304, null, ImmutableListMultimap.<String, InetAddress> of(),
VAppStatus.OFF, 4194304l, null, ImmutableListMultimap.<String, InetAddress> of(),
null, null, ImmutableSortedSet.of(new ResourceAllocation(1, "n/a", null,
ResourceType.PROCESSOR, null, null, null, null, null, null, 2, null),
new ResourceAllocation(2, "n/a", null, ResourceType.MEMORY, null, null,
@ -103,10 +103,10 @@ public class BindVAppConfigurationToXmlPayloadTest {
}
public void testRemoveDisk() throws IOException {
TerremarkVAppImpl vApp = new TerremarkVAppImpl("4213", "MyAppServer6",
"application/vnd.vmware.vcloud.vApp+xml", URI
VAppImpl vApp = new VAppImpl("4213", "MyAppServer6",
URI
.create("https://services.vcloudexpress/terremark.com/api/v0.8/vapp/4213"),
VAppStatus.OFF, 4194304, null, ImmutableListMultimap.<String, InetAddress> of(),
VAppStatus.OFF, 4194304l, null, ImmutableListMultimap.<String, InetAddress> of(),
null, null, ImmutableSortedSet.of(new ResourceAllocation(1, "n/a", null,
ResourceType.PROCESSOR, null, null, null, null, null, null, 2, null),
new ResourceAllocation(2, "n/a", null, ResourceType.MEMORY, null, null,

View File

@ -31,11 +31,11 @@ import org.jclouds.compute.domain.Image;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -94,7 +94,7 @@ public class TerremarkVCloudComputeClientLiveTest {
id = client.start(serverName, toTest, processorCount, memory, properties);
Expectation expectation = expectationMap.get(toTest);
TerremarkVApp vApp = tmClient.getVApp(id);
VApp vApp = tmClient.getVApp(id);
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
expectation.hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.ON);
@ -122,7 +122,7 @@ public class TerremarkVCloudComputeClientLiveTest {
// client.exec(publicIp, "uname -a");
}
private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs,
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.xml.ResourceAllocationHandler;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

View File

@ -1,211 +0,0 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Provides;
import com.google.inject.internal.Iterables;
/**
* Tests behavior of {@code TerremarkVAppHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.TerremarkVAppHandlerTest")
public class TerremarkVAppHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
@VAppRoot
String provide() {
return "https://services.vcloudexpress.terremark.com/api/v0.8/vapp";
}
});
factory = injector.getInstance(ParseSax.Factory.class);
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/launched_vapp.xml");
TerremarkVApp result = (TerremarkVApp) factory.create(
injector.getInstance(TerremarkVAppHandler.class)).parse(is);
assertEquals(result.getId(), 13775 + "");
assertEquals(result.getName(), "adriantest");
assertEquals(result.getStatus(), VAppStatus.UNRESOLVED);
assertEquals(result.getSize(), new Long(4));
assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13775"));
assertEquals(result.getVDC(), new NamedResourceImpl("32", null,
"application/vnd.vmware.vcloud.vdc+xml", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
}
public void testGetVApp() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml");
TerremarkVApp result = (TerremarkVApp) factory.create(
injector.getInstance(TerremarkVAppHandler.class)).parse(is);
assertEquals(result.getId(), 16238 + "");
assertEquals(result.getName(), "centos-53");
assertEquals(result.getStatus(), VAppStatus.OFF);
assertEquals(result.getSize().longValue(), 10485760);
assertEquals(result.getOperatingSystemDescription(), "Red Hat Enterprise Linux 5 (64-bit)");
assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/16238"));
assertEquals(result.getVDC(), new NamedResourceImpl("32", null, VCloudMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals(result.getSystem(), new TerremarkVirtualSystem(null, null, null, null, null,
null, null, null, null, null, null, "Virtual Hardware Family", 0, null, null, null,
null, null, "centos-53", "vmx-07"));
assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.<InetAddress>of(InetAddress.getByName("10.114.34.132")));
ResourceAllocation cpu = new ResourceAllocation(1, "1 virtual CPU(s)",
"Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null,
null, 1, "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0",
"SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null,
null, 1, null);
ResourceAllocation memory = new ResourceAllocation(2, "512MB of memory", "Memory Size",
ResourceType.MEMORY, null, null, null, null, null, null, 512, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null,
ResourceType.DISK_DRIVE, null, "10485760", null, 0, 3, null, 10485760, null);
assertEquals(result.getResourceAllocations(), ImmutableSortedSet.of(cpu, controller, memory,
disk));
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.PROCESSOR))
.getVirtualQuantity(), 1);
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER))
.getVirtualQuantity(), 1);
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.MEMORY)).getVirtualQuantity(),
512);
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.DISK_DRIVE))
.getVirtualQuantity(), 10485760);
assertEquals(result.getSize().longValue(), Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.DISK_DRIVE))
.getVirtualQuantity());
}
public void testGetVApp2disks() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/get_vapp2disks.xml");
TerremarkVApp vApp = (TerremarkVApp) factory.create(
injector.getInstance(TerremarkVAppHandler.class)).parse(is);
assertEquals(vApp.getId(), 15639 + "");
assertEquals(vApp.getName(), "eduardo");
assertEquals(vApp.getStatus(), VAppStatus.OFF);
assertEquals(vApp.getSize().longValue(), 30408704);
assertEquals(vApp.getOperatingSystemDescription(), "Ubuntu Linux (32-bit)");
assertEquals(vApp.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15639"));
assertEquals(vApp.getVDC(), new NamedResourceImpl("32", null, VCloudMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals(vApp.getSystem(), new TerremarkVirtualSystem(null, null, null, null, null,
null, null, null, null, null, null, "Virtual Hardware Family", 0, null, null, null,
null, null, "eduardo", "vmx-07"));
assertEquals(vApp.getNetworkToAddresses().get("Internal"), ImmutableList.of(InetAddress
.getByName("10.114.34.131")));
ResourceAllocation cpu = new ResourceAllocation(1, "2 virtual CPU(s)",
"Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null,
null, 2, "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0",
"SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null,
null, 1, null);
ResourceAllocation memory = new ResourceAllocation(2, "1024MB of memory", "Memory Size",
ResourceType.MEMORY, null, null, null, null, null, null, 1024, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null,
ResourceType.DISK_DRIVE, null, "4194304", null, 0, 3, null, 4194304, null);
ResourceAllocation disk2 = new ResourceAllocation(9, "Hard Disk 2", null,
ResourceType.DISK_DRIVE, null, "26214400", null, 1, 3, null, 26214400, null);
assertEquals(vApp.getResourceAllocations(), ImmutableSortedSet.of(cpu, controller, memory,
disk, disk2));
assertEquals(Iterables.getOnlyElement(
vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR))
.getVirtualQuantity(), 2);
assertEquals(Iterables.getOnlyElement(
vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER))
.getVirtualQuantity(), 1);
assertEquals(Iterables.getOnlyElement(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY)).getVirtualQuantity(),
1024);
// extract the disks on the vApp sorted by addressOnParent
List<ResourceAllocation> disks = Lists.newArrayList(vApp.getResourceAllocationByType()
.get(ResourceType.DISK_DRIVE));
assertEquals(disks.get(0).getVirtualQuantity(), 4194304);
assertEquals(disks.get(1).getVirtualQuantity(), 26214400);
}
}

View File

@ -0,0 +1,247 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed 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.vcloud.terremark.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.List;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.xml.VAppHandler;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Provides;
import com.google.inject.internal.Iterables;
/**
* Tests behavior of {@code VAppHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VAppHandlerTest")
public class VAppHandlerTest extends BaseHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
@VAppRoot
String provide() {
return "https://services.vcloudexpress.terremark.com/api/v0.8/vapp";
}
});
factory = injector.getInstance(ParseSax.Factory.class);
}
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream(
"/terremark/launched_vapp.xml");
VApp result = (VApp) factory.create(
injector.getInstance(VAppHandler.class)).parse(is);
assertEquals(result.getId(), 13775 + "");
assertEquals(result.getName(), "adriantest");
assertEquals(result.getStatus(), VAppStatus.UNRESOLVED);
assertEquals(result.getSize().longValue(),4l);
assertEquals(
result.getLocation(),
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13775"));
assertEquals(
result.getVDC(),
new NamedResourceImpl(
"32",
null,
"application/vnd.vmware.vcloud.vdc+xml",
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
}
public void testGetVApp() throws UnknownHostException {
InputStream is = getClass()
.getResourceAsStream("/terremark/get_vapp.xml");
VApp result = (VApp) factory.create(
injector.getInstance(VAppHandler.class)).parse(is);
assertEquals(result.getId(), 16238 + "");
assertEquals(result.getName(), "centos-53");
assertEquals(result.getStatus(), VAppStatus.OFF);
assertEquals(result.getSize().longValue(), 10485760);
assertEquals(result.getOperatingSystemDescription(),
"Red Hat Enterprise Linux 5 (64-bit)");
assertEquals(
result.getLocation(),
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/16238"));
assertEquals(
result.getVDC(),
new NamedResourceImpl(
"32",
null,
VCloudMediaType.VDC_XML,
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals(result.getSystem(), new VirtualSystem(0,
"Virtual Hardware Family", "centos-53", "vmx-07"));
assertEquals(result.getNetworkToAddresses().get("Internal"),
ImmutableList.<InetAddress> of(InetAddress
.getByName("10.114.34.132")));
ResourceAllocation cpu = new ResourceAllocation(1, "1 virtual CPU(s)",
"Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null,
null, null, null, 1, "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(3,
"SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null,
null, 1, null);
ResourceAllocation memory = new ResourceAllocation(2, "512MB of memory",
"Memory Size", ResourceType.MEMORY, null, null, null, null, null,
null, 512, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null,
ResourceType.DISK_DRIVE, null, "10485760", null, 0, 3, null,
10485760, "byte * 2^20");
assertEquals(result.getResourceAllocations(), ImmutableSortedSet.of(cpu,
controller, memory, disk));
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.PROCESSOR))
.getVirtualQuantity(), 1);
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(
ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1);
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.MEMORY))
.getVirtualQuantity(), 512);
assertEquals(Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.DISK_DRIVE))
.getVirtualQuantity(), 10485760);
assertEquals(result.getSize().longValue(), Iterables.getOnlyElement(
result.getResourceAllocationByType().get(ResourceType.DISK_DRIVE))
.getVirtualQuantity());
}
public void testGetVApp2disks() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream(
"/terremark/get_vapp2disks.xml");
VApp vApp = factory.create(injector.getInstance(VAppHandler.class))
.parse(is);
assertEquals(vApp.getId(), 15639 + "");
assertEquals(vApp.getName(), "eduardo");
assertEquals(vApp.getStatus(), VAppStatus.OFF);
assertEquals(vApp.getSize().longValue(), 30408704);
assertEquals(vApp.getOperatingSystemDescription(),
"Ubuntu Linux (32-bit)");
assertEquals(
vApp.getLocation(),
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/15639"));
assertEquals(
vApp.getVDC(),
new NamedResourceImpl(
"32",
null,
VCloudMediaType.VDC_XML,
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals(vApp.getSystem(), new VirtualSystem(0,
"Virtual Hardware Family", "eduardo", "vmx-07"));
assertEquals(vApp.getNetworkToAddresses().get("Internal"), ImmutableList
.of(InetAddress.getByName("10.114.34.131")));
ResourceAllocation cpu = new ResourceAllocation(1, "2 virtual CPU(s)",
"Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null,
null, null, null, 2, "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(3,
"SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null,
null, 1, null);
ResourceAllocation memory = new ResourceAllocation(2, "1024MB of memory",
"Memory Size", ResourceType.MEMORY, null, null, null, null, null,
null, 1024, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null,
ResourceType.DISK_DRIVE, null, "4194304", null, 0, 3, null,
4194304, "byte * 2^20");
ResourceAllocation disk2 = new ResourceAllocation(9, "Hard Disk 2", null,
ResourceType.DISK_DRIVE, null, "26214400", null, 1, 3, null,
26214400, "byte * 2^20");
assertEquals(vApp.getResourceAllocations(), ImmutableSortedSet.of(cpu,
controller, memory, disk, disk2));
assertEquals(Iterables.getOnlyElement(
vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR))
.getVirtualQuantity(), 2);
assertEquals(Iterables.getOnlyElement(
vApp.getResourceAllocationByType()
.get(ResourceType.SCSI_CONTROLLER)).getVirtualQuantity(), 1);
assertEquals(Iterables.getOnlyElement(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY))
.getVirtualQuantity(), 1024);
// extract the disks on the vApp sorted by addressOnParent
List<ResourceAllocation> disks = Lists.newArrayList(vApp
.getResourceAllocationByType().get(ResourceType.DISK_DRIVE));
assertEquals(disks.get(0).getVirtualQuantity(), 4194304);
assertEquals(disks.get(1).getVirtualQuantity(), 26214400);
}
}

View File

@ -23,7 +23,8 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.terremark.domain.TerremarkVirtualSystem;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.xml.VirtualSystemHandler;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@ -44,7 +45,7 @@ public class VirtualSystemHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/system.xml");
TerremarkVirtualSystem result = (TerremarkVirtualSystem) factory.create(
VirtualSystem result = factory.create(
injector.getInstance(VirtualSystemHandler.class)).parse(is);
assertEquals(result.getName(), "Virtual Hardware Family");
assertEquals(result.getId(), 0);