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.net.InetAddress;
import java.util.Set; import java.util.Set;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap; 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 * 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 * @author Adrian Cole
*/ */
@ImplementedBy(VAppImpl.class)
public interface VApp extends NamedResource { public interface VApp extends NamedResource {
NamedResource getVDC();
VAppStatus getStatus(); VAppStatus getStatus();

View File

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

View File

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

View File

@ -56,7 +56,7 @@ public class VCloudComputeClient {
} }
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put( 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(); Image.UBUNTU_JEOS_90, "11").build();
public Map<String, String> start(String name, Image image, int minCores, int minMegs, 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 * @author Adrian Cole
*/ */
@Test(groups = "live", sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest") @Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest")
public class VCloudComputeClientLiveTest { public class VCloudComputeClientLiveTest {
VCloudComputeClient client; VCloudComputeClient client;
VCloudClient tmClient; VCloudClient tmClient;
@ -59,7 +59,7 @@ public class VCloudComputeClientLiveTest {
private String id; private String id;
private InetAddress privateAddress; 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 { private static class Expectation {
final long hardDisk; final long hardDisk;
@ -103,8 +103,8 @@ public class VCloudComputeClientLiveTest {
private String getCompatibleServerName(Image toTest) { private String getCompatibleServerName(Image toTest) {
String serverName = CaseFormat.UPPER_UNDERSCORE String serverName = CaseFormat.UPPER_UNDERSCORE
.to(CaseFormat.LOWER_HYPHEN, toTest.toString()).substring(0, .to(CaseFormat.LOWER_CAMEL, toTest.toString()).substring(0,
toTest.toString().length() <= 15 ? toTest.toString().length() : 14); toTest.toString().length()-1 <= 15 ? toTest.toString().length()-1 : 14);
return serverName; 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.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem; import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.VAppImpl; import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
@ -46,8 +48,7 @@ import com.google.common.collect.ListMultimap;
*/ */
@Test(groups = "unit", testName = "vcloud.VAppHandlerTest") @Test(groups = "unit", testName = "vcloud.VAppHandlerTest")
public class VAppHandlerTest extends BaseHandlerTest { public class VAppHandlerTest extends BaseHandlerTest {
// TODO why does this fail? @Test(enabled=false)
@Test(enabled = false)
public void testHosting() throws UnknownHostException { public void testHosting() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml"); 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 VApp expects = new VAppImpl("188849-74", "188849-74", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-74"), VAppStatus.ON, .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); 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? // TODO why does this fail?
@Test(enabled = false) @Test(enabled = false)
public void testDefault() throws UnknownHostException { public void testDefault() throws UnknownHostException {
@ -114,7 +130,10 @@ public class VAppHandlerTest extends BaseHandlerTest {
VApp expects = new VAppImpl("4", "Oracle", URI VApp expects = new VAppImpl("4", "Oracle", URI
.create("http://10.150.4.49/api/v0.8/vApp/4"), VAppStatus.ON, .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); 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,30 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?> <?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" <VApp href="http://10.150.4.49/api/v0.8/vApp/10" type="application/vnd.vmware.vcloud.vApp+xml"
name="Oracle" status="4" name="centos53" status="4"
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://10.150.4.49/api/v0.8/vcloud/vApp.xsd" 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: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:vmw="http://www.vmware.com/schema/ovf"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData" 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:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" size="104857"> 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" /> <Link rel="up"
<OperatingSystemSection d2p1:id="36" href="http://10.150.4.49/api/v0.8/vdc/4"
xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:d2p1="http://schemas.dmtf.org/ovf/envelope/1"> 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> <Info>The kind of installed guest operating system</Info>
<Description>Other Linux (32-bit)</Description> <Description>Other Linux (32-bit)</Description>
</OperatingSystemSection> </OperatingSystemSection>
<VirtualHardwareSection xmlns="http://schemas.dmtf.org/ovf/envelope/1"> <VirtualHardwareSection xmlns="http://schemas.dmtf.org/ovf/envelope/1">
<Info>Virtual hardware</Info> <Info>Virtual hardware</Info>
<Link rel="edit" href="http://10.150.4.49/api/v0.8/vApp/4" <Link rel="edit" href="http://10.150.4.49/api/v0.8/vApp/10" type="application/vnd.vmware.ovf.virtualHardwareSection+xml"/>
type="application/vnd.vmware.ovf.virtualHardwareSection+xml" />
<System> <System>
<vssd:AutomaticRecoveryAction xsi:nil="true" /> <vssd:AutomaticRecoveryAction xsi:nil="true" />
<vssd:AutomaticShutdownAction xsi:nil="true" /> <vssd:AutomaticShutdownAction xsi:nil="true" />
<vssd:AutomaticStartupAction xsi:nil="true" /> <vssd:AutomaticStartupAction xsi:nil="true" />
<vssd:AutomaticStartupActionDelay <vssd:AutomaticStartupActionDelay xsi:nil="true" />
xsi:nil="true" /> <vssd:AutomaticStartupActionSequenceNumber xsi:nil="true" />
<vssd:AutomaticStartupActionSequenceNumber
xsi:nil="true" />
<vssd:Caption xsi:nil="true" /> <vssd:Caption xsi:nil="true" />
<vssd:ConfigurationDataRoot xsi:nil="true" /> <vssd:ConfigurationDataRoot xsi:nil="true" />
<vssd:ConfigurationFile xsi:nil="true" /> <vssd:ConfigurationFile xsi:nil="true" />
@ -38,7 +43,7 @@
<vssd:SnapshotDataRoot xsi:nil="true" /> <vssd:SnapshotDataRoot xsi:nil="true" />
<vssd:SuspendDataRoot xsi:nil="true" /> <vssd:SuspendDataRoot xsi:nil="true" />
<vssd:SwapFileDataRoot xsi:nil="true" /> <vssd:SwapFileDataRoot xsi:nil="true" />
<vssd:VirtualSystemIdentifier>Oracle</vssd:VirtualSystemIdentifier> <vssd:VirtualSystemIdentifier>centos53</vssd:VirtualSystemIdentifier>
<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType> <vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>
</System> </System>
<Item> <Item>
@ -114,8 +119,7 @@
<rasd:AddressOnParent>7</rasd:AddressOnParent> <rasd:AddressOnParent>7</rasd:AddressOnParent>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation> <rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Connection connected="true">Internal</rasd:Connection> <rasd:Connection connected="true">Internal</rasd:Connection>
<rasd:Description>PCNet32 ethernet adapter on "Internal" network <rasd:Description>PCNet32 ethernet adapter on "Internal" network</rasd:Description>
</rasd:Description>
<rasd:ElementName>Network Adapter 1</rasd:ElementName> <rasd:ElementName>Network Adapter 1</rasd:ElementName>
<rasd:InstanceID>8</rasd:InstanceID> <rasd:InstanceID>8</rasd:InstanceID>
<rasd:ResourceSubType>PCNet32</rasd:ResourceSubType> <rasd:ResourceSubType>PCNet32</rasd:ResourceSubType>

View File

@ -19,11 +19,13 @@
package org.jclouds.vcloud.hostingdotcom.config; package org.jclouds.vcloud.hostingdotcom.config;
import java.net.URI; import java.net.URI;
import java.util.concurrent.TimeUnit;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.RestClientFactory;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
@ -31,7 +33,9 @@ import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient;
import org.jclouds.vcloud.predicates.TaskSuccess;
import com.google.common.base.Predicate;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -72,4 +76,8 @@ public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule
return URI.create("https://vcloud.safesecureweb.com/network/1990"); 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.net.URI;
import java.util.Set; import java.util.Set;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem; import org.jclouds.vcloud.domain.VirtualSystem;
@ -45,10 +46,10 @@ public class HostingDotComVAppImpl extends VAppImpl implements HostingDotComVApp
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public HostingDotComVAppImpl(String id, String name, URI location, VAppStatus status, Long size, 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, String operatingSystemDescription, VirtualSystem system,
Set<ResourceAllocation> resourceAllocations, String username, String password) { 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); system, resourceAllocations);
this.username = username; this.username = username;
this.password = password; this.password = password;

View File

@ -43,7 +43,7 @@ public class HostingDotComVAppHandler extends VAppHandler {
} }
public HostingDotComVApp getResult() { 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); operatingSystemDescription, system, allocations, username, password);
} }

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.domain.Task; 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.ComputeOptions;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
import org.jclouds.vcloud.terremark.domain.InternetService; 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.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress; 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.domain.VAppConfiguration;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@ -50,13 +49,6 @@ import org.jclouds.vcloud.terremark.options.AddNodeOptions;
@Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudClient { 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 * 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 * 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 * @param configuration(s) to change
* @return task of configuration 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.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.VAppConfiguration; import org.jclouds.vcloud.terremark.domain.VAppConfiguration;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
@ -77,7 +77,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request; GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point"); 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!"); checkArgument(vApp.getStatus() == VAppStatus.OFF, "vApp must be off!");
VAppConfiguration configuration = checkNotNull(findConfigInArgsOrNull(gRequest), "config"); 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 { throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
String name = configuration.getName() != null ? configuration.getName() : vApp.getName(); String name = configuration.getName() != null ? configuration.getName() : vApp.getName();
@ -114,7 +114,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
return rootBuilder.asString(outputProperties); return rootBuilder.asString(outputProperties);
} }
private void addProcessorItem(XMLBuilder sectionBuilder, TerremarkVApp vApp, private void addProcessorItem(XMLBuilder sectionBuilder, VApp vApp,
VAppConfiguration configuration) { VAppConfiguration configuration) {
ResourceAllocation cpu = Iterables.getOnlyElement(vApp.getResourceAllocationByType().get( ResourceAllocation cpu = Iterables.getOnlyElement(vApp.getResourceAllocationByType().get(
ResourceType.PROCESSOR)); ResourceType.PROCESSOR));
@ -123,7 +123,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
addResourceWithQuantity(sectionBuilder, cpu, quantity); addResourceWithQuantity(sectionBuilder, cpu, quantity);
} }
private void addMemoryItem(XMLBuilder sectionBuilder, TerremarkVApp vApp, private void addMemoryItem(XMLBuilder sectionBuilder, VApp vApp,
VAppConfiguration configuration) { VAppConfiguration configuration) {
ResourceAllocation memory = Iterables.getOnlyElement(vApp.getResourceAllocationByType().get( ResourceAllocation memory = Iterables.getOnlyElement(vApp.getResourceAllocationByType().get(
ResourceType.MEMORY)); ResourceType.MEMORY));
@ -132,7 +132,7 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
addResourceWithQuantity(sectionBuilder, memory, quantity); addResourceWithQuantity(sectionBuilder, memory, quantity);
} }
private void addDiskItems(XMLBuilder sectionBuilder, TerremarkVApp vApp, private void addDiskItems(XMLBuilder sectionBuilder, VApp vApp,
VAppConfiguration configuration) { VAppConfiguration configuration) {
for (ResourceAllocation disk : vApp.getResourceAllocationByType() for (ResourceAllocation disk : vApp.getResourceAllocationByType()
.get(ResourceType.DISK_DRIVE)) { .get(ResourceType.DISK_DRIVE)) {
@ -169,21 +169,21 @@ public class BindVAppConfigurationToXmlPayload implements MapBinder {
return itemBuilder; return itemBuilder;
} }
protected XMLBuilder buildRoot(TerremarkVApp vApp, String name) protected XMLBuilder buildRoot(VApp vApp, String name)
throws ParserConfigurationException, FactoryConfigurationError { throws ParserConfigurationException, FactoryConfigurationError {
XMLBuilder rootBuilder = XMLBuilder.create("VApp").a("type", vApp.getType()).a("name", name) 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( "xmlns", ns).a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a(
"xsi:schemaLocation", ns + " " + schema); "xsi:schemaLocation", ns + " " + schema);
return rootBuilder; return rootBuilder;
} }
protected TerremarkVApp findVAppInArgsOrNull(GeneratedHttpRequest<?> gRequest) { protected VApp findVAppInArgsOrNull(GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) { for (Object arg : gRequest.getArgs()) {
if (arg instanceof TerremarkVApp) { if (arg instanceof VApp) {
return (TerremarkVApp) arg; return (VApp) arg;
} else if (arg instanceof TerremarkVApp[]) { } else if (arg instanceof VApp[]) {
TerremarkVApp[] vapps = (TerremarkVApp[]) arg; VApp[] vapps = (VApp[]) arg;
return (vapps.length > 0) ? vapps[0] : null; 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.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
@ -81,7 +81,7 @@ public class TerremarkVCloudComputeClient {
.debug( .debug(
">> instantiating vApp vDC(%s) template(%s) name(%s) minCores(%d) minMegs(%d) properties(%s)", ">> instantiating vApp vDC(%s) template(%s) name(%s) minCores(%d) minMegs(%d) properties(%s)",
vDCId, templateId, name, minCores, minMegs, properties); 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( TerremarkInstantiateVAppTemplateOptions.Builder.processorCount(minCores).memory(
minMegs).productProperties(properties)); minMegs).productProperties(properties));
logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug("<< instantiated VApp(%s)", vApp.getId());
@ -105,12 +105,12 @@ public class TerremarkVCloudComputeClient {
* if no address is configured * if no address is configured
*/ */
public InetAddress getAnyPrivateAddress(String id) { public InetAddress getAnyPrivateAddress(String id) {
TerremarkVApp vApp = tmClient.getVApp(id); VApp vApp = tmClient.getVApp(id);
return Iterables.getLast(vApp.getNetworkToAddresses().values()); return Iterables.getLast(vApp.getNetworkToAddresses().values());
} }
public Set<InetAddress> getPublicAddresses(String id) { public Set<InetAddress> getPublicAddresses(String id) {
TerremarkVApp vApp = tmClient.getVApp(id); VApp vApp = tmClient.getVApp(id);
Set<InetAddress> ipAddresses = Sets.newHashSet(); Set<InetAddress> ipAddresses = Sets.newHashSet();
for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC().getId())) { for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC().getId())) {
for (Node node : tmClient.getNodes(service.getId())) { for (Node node : tmClient.getNodes(service.getId())) {
@ -123,14 +123,14 @@ public class TerremarkVCloudComputeClient {
} }
public void reboot(String id) { public void reboot(String id) {
TerremarkVApp vApp = tmClient.getVApp(id); VApp vApp = tmClient.getVApp(id);
logger.debug(">> rebooting vApp(%s)", vApp.getId()); logger.debug(">> rebooting vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset", blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset",
VAppStatus.ON); VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId()); logger.debug("<< on vApp(%s)", vApp.getId());
} }
public InetAddress createPublicAddressMappedToPorts(TerremarkVApp vApp, int... ports) { public InetAddress createPublicAddressMappedToPorts(VApp vApp, int... ports) {
PublicIpAddress ip = null; PublicIpAddress ip = null;
InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values()); InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values());
for (int port : ports) { for (int port : ports) {
@ -180,7 +180,7 @@ public class TerremarkVCloudComputeClient {
} }
public void stop(String id) { public void stop(String id) {
TerremarkVApp vApp = tmClient.getVApp(id); VApp vApp = tmClient.getVApp(id);
Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp); Set<PublicIpAddress> ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp);
@ -198,7 +198,7 @@ public class TerremarkVCloudComputeClient {
logger.debug("<< deleted vApp(%s)", vApp.getId()); logger.debug("<< deleted vApp(%s)", vApp.getId());
} }
private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(TerremarkVApp vApp) { private Set<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(VApp vApp) {
Set<PublicIpAddress> ipAddresses = Sets.newHashSet(); Set<PublicIpAddress> ipAddresses = Sets.newHashSet();
SERVICE: for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC() SERVICE: for (InternetService service : tmClient.getAllInternetServicesInVDC(vApp.getVDC()
.getId())) { .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) { String taskType, VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getId())) { if (!taskTester.apply(deployTask.getId())) {
throw new TaskException(taskType, vApp, deployTask); throw new TaskException(taskType, vApp, deployTask);
@ -258,7 +258,7 @@ public class TerremarkVCloudComputeClient {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L; 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, super(String.format("failed to %s vApp %s status %s;task %s status %s", type,
vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task; this.task = task;
@ -289,16 +289,16 @@ public class TerremarkVCloudComputeClient {
public static class VAppException extends RuntimeException { public static class VAppException extends RuntimeException {
private final TerremarkVApp vApp; private final VApp vApp;
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L; private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, TerremarkVApp vApp) { public VAppException(String message, VApp vApp) {
super(message); super(message);
this.vApp = vApp; this.vApp = vApp;
} }
public TerremarkVApp getvApp() { public VApp getvApp() {
return vApp; 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.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -80,7 +79,7 @@ public class TerremarkVCloudComputeService implements ComputeService {
@Override @Override
public CreateNodeResponse createNode(String name, Profile profile, Image image) { public CreateNodeResponse createNode(String name, Profile profile, Image image) {
String id = computeClient.start(name, image, 1, 512, ImmutableMap.<String, String> of()); 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 InetAddress publicIp = computeClient
.createPublicAddressMappedToPorts(vApp, 22, 80, 8080, 443); .createPublicAddressMappedToPorts(vApp, 22, 80, 8080, 443);
return new CreateNodeResponseImpl(vApp.getId(), vApp.getName(), vAppStatusToNodeState 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.IpAddressesHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.NodesHandler; 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.terremark.xml.TerremarkVDCHandler;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
@ -165,7 +165,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
"/terremark/InstantiateVAppTemplateParams-test.xml"))); "/terremark/InstantiateVAppTemplateParams-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); checkFilters(httpMethod);
@ -190,7 +190,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
"/terremark/InstantiateVAppTemplateParams-options-test.xml"))); "/terremark/InstantiateVAppTemplateParams-options-test.xml")));
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class); assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null); assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod); 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.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.CloneVAppOptions; 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.NodeConfiguration;
import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.Protocol;
import org.jclouds.vcloud.terremark.domain.PublicIpAddress; 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.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
@ -90,13 +90,13 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
private InetAddress publicIp; private InetAddress publicIp;
private InternetService is; private InternetService is;
private Node node; private Node node;
private TerremarkVApp vApp; private VApp vApp;
private RetryablePredicate<InetSocketAddress> socketTester; private RetryablePredicate<InetSocketAddress> socketTester;
private RetryablePredicate<String> successTester; private RetryablePredicate<String> successTester;
private TerremarkVApp clone; private VApp clone;
public static final String PREFIX = System.getProperty("user.name") + "-terremark"; 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) { int processorCount, long memory, long hardDisk) {
assertEquals(vApp.getName(), serverName); assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs); 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.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VAppStatus; 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.VAppConfiguration;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVAppImpl;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
@ -69,10 +69,10 @@ public class BindVAppConfigurationToXmlPayloadTest {
}); });
public void testChangeName() throws IOException { public void testChangeName() throws IOException {
TerremarkVAppImpl vApp = new TerremarkVAppImpl("4213", "MyAppServer6", VAppImpl vApp = new VAppImpl("4213", "MyAppServer6",
"application/vnd.vmware.vcloud.vApp+xml", URI URI
.create("https://services.vcloudexpress/terremark.com/api/v0.8/vapp/4213"), .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, null, null, ImmutableSortedSet.of(new ResourceAllocation(1, "n/a", null,
ResourceType.PROCESSOR, null, null, null, null, null, null, 2, null), ResourceType.PROCESSOR, null, null, null, null, null, null, 2, null),
new ResourceAllocation(2, "n/a", null, ResourceType.MEMORY, null, null, new ResourceAllocation(2, "n/a", null, ResourceType.MEMORY, null, null,
@ -103,10 +103,10 @@ public class BindVAppConfigurationToXmlPayloadTest {
} }
public void testRemoveDisk() throws IOException { public void testRemoveDisk() throws IOException {
TerremarkVAppImpl vApp = new TerremarkVAppImpl("4213", "MyAppServer6", VAppImpl vApp = new VAppImpl("4213", "MyAppServer6",
"application/vnd.vmware.vcloud.vApp+xml", URI URI
.create("https://services.vcloudexpress/terremark.com/api/v0.8/vapp/4213"), .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, null, null, ImmutableSortedSet.of(new ResourceAllocation(1, "n/a", null,
ResourceType.PROCESSOR, null, null, null, null, null, null, 2, null), ResourceType.PROCESSOR, null, null, null, null, null, null, 2, null),
new ResourceAllocation(2, "n/a", null, ResourceType.MEMORY, null, 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.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient;
import org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder; import org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder;
import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder; import org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -94,7 +94,7 @@ public class TerremarkVCloudComputeClientLiveTest {
id = client.start(serverName, toTest, processorCount, memory, properties); id = client.start(serverName, toTest, processorCount, memory, properties);
Expectation expectation = expectationMap.get(toTest); Expectation expectation = expectationMap.get(toTest);
TerremarkVApp vApp = tmClient.getVApp(id); VApp vApp = tmClient.getVApp(id);
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory, verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
expectation.hardDisk); expectation.hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.ON); assertEquals(vApp.getStatus(), VAppStatus.ON);
@ -122,7 +122,7 @@ public class TerremarkVCloudComputeClientLiveTest {
// client.exec(publicIp, "uname -a"); // 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) { int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName); assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getOperatingSystemDescription(), expectedOs);

View File

@ -25,6 +25,7 @@ import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.xml.ResourceAllocationHandler;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; 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 java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; 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.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -44,7 +45,7 @@ public class VirtualSystemHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/system.xml"); InputStream is = getClass().getResourceAsStream("/terremark/system.xml");
TerremarkVirtualSystem result = (TerremarkVirtualSystem) factory.create( VirtualSystem result = factory.create(
injector.getInstance(VirtualSystemHandler.class)).parse(is); injector.getInstance(VirtualSystemHandler.class)).parse(is);
assertEquals(result.getName(), "Virtual Hardware Family"); assertEquals(result.getName(), "Virtual Hardware Family");
assertEquals(result.getId(), 0); assertEquals(result.getId(), 0);