Issue 112: fixed catalog and orgs to be plural; added error to task

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2605 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-06 01:28:14 +00:00
parent 15c147cd25
commit e2235e48f8
32 changed files with 842 additions and 561 deletions

View File

@ -18,6 +18,7 @@
*/ */
package org.jclouds.vcloud; package org.jclouds.vcloud;
import static org.jclouds.vcloud.VCloudMediaType.ORG_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML; import static org.jclouds.vcloud.VCloudMediaType.CATALOGITEM_XML;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML;
@ -82,15 +83,29 @@ public interface VCloudAsyncClient {
@GET @GET
@Endpoint(Org.class) @Endpoint(Org.class)
@Consumes(VCloudMediaType.ORG_XML) @Consumes(ORG_XML)
@XMLResponseParser(OrgHandler.class) @XMLResponseParser(OrgHandler.class)
Future<? extends Organization> getOrganization(); Future<? extends Organization> getDefaultOrganization();
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/org/{orgId}")
@XMLResponseParser(OrgHandler.class)
@Consumes(ORG_XML)
Future<? extends Organization> getOrganization(@PathParam("orgId") String orgId);
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML) @Consumes(CATALOG_XML)
@XMLResponseParser(CatalogHandler.class) @XMLResponseParser(CatalogHandler.class)
Future<? extends Catalog> getCatalog(); Future<? extends Catalog> getDefaultCatalog();
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/catalog/{catalogId}")
@XMLResponseParser(CatalogHandler.class)
@Consumes(CATALOG_XML)
Future<? extends Catalog> getCatalog(@PathParam("catalogId") String catalogId);
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)

View File

@ -46,9 +46,13 @@ public interface VCloudClient {
* This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within
* the organization. * the organization.
*/ */
Organization getOrganization(); Organization getDefaultOrganization();
Catalog getCatalog(); Organization getOrganization(String orgId);
Catalog getDefaultCatalog();
Catalog getCatalog(String catalogId);
CatalogItem getCatalogItem(String catalogItemId); CatalogItem getCatalogItem(String catalogItemId);

View File

@ -33,6 +33,7 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.annotation.Resource;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -41,6 +42,7 @@ import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.encryption.EncryptionService; import org.jclouds.encryption.EncryptionService;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.logging.Logger;
import org.jclouds.predicates.AddressReachable; import org.jclouds.predicates.AddressReachable;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
@ -81,6 +83,8 @@ import com.google.inject.Provides;
@RequiresHttp @RequiresHttp
@ConfiguresRestClient @ConfiguresRestClient
public class VCloudRestClientModule extends AbstractModule { public class VCloudRestClientModule extends AbstractModule {
@Resource
protected Logger logger = Logger.NULL;
@Provides @Provides
@Singleton @Singleton
@ -102,6 +106,7 @@ public class VCloudRestClientModule extends AbstractModule {
@Override @Override
protected void configure() { protected void configure() {
requestInjection(this);
} }
@VCloudToken @VCloudToken
@ -217,21 +222,21 @@ public class VCloudRestClientModule extends AbstractModule {
@Singleton @Singleton
protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException, protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException,
TimeoutException, InterruptedException { TimeoutException, InterruptedException {
return discovery.getOrganization(); return discovery.getDefaultOrganization();
} }
@Provides @Provides
@VDC @VDC
@Singleton @Singleton
protected URI provideDefaultVDC(Organization org) { protected URI provideDefaultVDC(Organization org) {
return org.getVDCs().values().iterator().next().getLocation(); return Iterables.get(org.getVDCs().values(), 0).getLocation();
} }
@Provides @Provides
@Catalog @Catalog
@Singleton @Singleton
protected URI provideCatalog(Organization org) { protected URI provideCatalog(Organization org) {
return org.getCatalog().getLocation(); return Iterables.get(org.getCatalogs().values(), 0).getLocation();
} }
@Provides @Provides
@ -239,8 +244,7 @@ public class VCloudRestClientModule extends AbstractModule {
@Singleton @Singleton
protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException, protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException,
ExecutionException, TimeoutException { ExecutionException, TimeoutException {
return client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks().values() return Iterables.get(client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks().values(), 0).getLocation();
.iterator().next().getLocation();
} }
@Provides @Provides

View File

@ -36,7 +36,7 @@ import com.google.inject.ImplementedBy;
public interface Organization extends NamedResource { public interface Organization extends NamedResource {
@Catalog @Catalog
NamedResource getCatalog(); Map<String, NamedResource> getCatalogs();
@VDC @VDC
Map<String, NamedResource> getVDCs(); Map<String, NamedResource> getVDCs();

View File

@ -130,18 +130,24 @@ public class ResourceAllocation implements Comparable<ResourceAllocation> {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((address == null) ? 0 : address.hashCode()); result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode()); result = prime * result
+ ((addressOnParent == null) ? 0 : addressOnParent.hashCode());
result = prime * result + ((connected == null) ? 0 : connected.hashCode()); result = prime * result + ((connected == null) ? 0 : connected.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result
result = prime * result + ((hostResource == null) ? 0 : hostResource.hashCode()); + ((description == null) ? 0 : description.hashCode());
result = prime * result
+ ((hostResource == null) ? 0 : hostResource.hashCode());
result = prime * result + id; result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((parent == null) ? 0 : parent.hashCode()); result = prime * result + ((parent == null) ? 0 : parent.hashCode());
result = prime * result + ((subType == null) ? 0 : subType.hashCode()); result = prime * result + ((subType == null) ? 0 : subType.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + (int) (virtualQuantity ^ (virtualQuantity >>> 32));
result = prime * result result = prime * result
+ ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits.hashCode()); + (int) (virtualQuantity ^ (virtualQuantity >>> 32));
result = prime
* result
+ ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits
.hashCode());
return result; return result;
} }

View File

@ -49,4 +49,13 @@ public interface Task extends Comparable<Task> {
* A link to the result of the task * A link to the result of the task
*/ */
NamedResource getResult(); NamedResource getResult();
Error getError();
@ImplementedBy(TaskImpl.ErrorImpl.class)
static interface Error {
String getMessage();
String getMajorErrorCode();
String getMinorErrorCode();
}
} }

View File

@ -19,7 +19,7 @@
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain;
import java.net.InetAddress; import java.net.InetAddress;
import java.util.SortedSet; import java.util.Set;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
@ -43,7 +43,7 @@ public interface VApp extends NamedResource {
VirtualSystem getSystem(); VirtualSystem getSystem();
SortedSet<ResourceAllocation> getResourceAllocations(); Set<ResourceAllocation> getResourceAllocations();
Multimap<ResourceType, ResourceAllocation> getResourceAllocationByType(); Multimap<ResourceType, ResourceAllocation> getResourceAllocationByType();

View File

@ -54,7 +54,8 @@ public class VirtualSystem {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + id; result = prime * result + id;
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode()); result = prime * result
+ ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode()); result = prime * result + ((type == null) ? 0 : type.hashCode());
return result; return result;

View File

@ -38,16 +38,16 @@ public class OrganizationImpl implements Organization {
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 catalog; private final Map<String, NamedResource> catalogs;
private final Map<String, NamedResource> vdcs; private final Map<String, NamedResource> vdcs;
private final Map<String, NamedResource> tasksLists; private final Map<String, NamedResource> tasksLists;
public OrganizationImpl(String id, String name, URI location, NamedResource catalog, public OrganizationImpl(String id, String name, URI location, Map<String, NamedResource> catalogs,
Map<String, NamedResource> vdcs, Map<String, NamedResource> tasksLists) { Map<String, NamedResource> vdcs, Map<String, NamedResource> tasksLists) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.location = location; this.location = location;
this.catalog = catalog; this.catalogs = catalogs;
this.vdcs = vdcs; this.vdcs = vdcs;
this.tasksLists = tasksLists; this.tasksLists = tasksLists;
} }
@ -65,8 +65,8 @@ public class OrganizationImpl implements Organization {
} }
@Catalog @Catalog
public NamedResource getCatalog() { public Map<String, NamedResource> getCatalogs() {
return catalog; return catalogs;
} }
@VDC @VDC
@ -83,7 +83,7 @@ public class OrganizationImpl implements Organization {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); result = prime * result + ((catalogs == null) ? 0 : catalogs.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
@ -101,10 +101,10 @@ public class OrganizationImpl implements Organization {
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
OrganizationImpl other = (OrganizationImpl) obj; OrganizationImpl other = (OrganizationImpl) obj;
if (catalog == null) { if (catalogs == null) {
if (other.catalog != null) if (other.catalogs != null)
return false; return false;
} else if (!catalog.equals(other.catalog)) } else if (!catalogs.equals(other.catalogs))
return false; return false;
if (id == null) { if (id == null) {
if (other.id != null) if (other.id != null)

View File

@ -30,12 +30,82 @@ import org.jclouds.vcloud.domain.TaskStatus;
import com.google.inject.internal.Nullable; import com.google.inject.internal.Nullable;
/** /**
* Locations of resources in vCloud
* *
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class TaskImpl implements Task { public class TaskImpl implements Task {
public static class ErrorImpl implements Error {
private final String message;
private final String majorErrorCode;
private final String minorErrorCode;
public ErrorImpl(String message, String majorErrorCode,
String minorErrorCode) {
this.message = message;
this.majorErrorCode = majorErrorCode;
this.minorErrorCode = minorErrorCode;
}
public String getMessage() {
return message;
}
public String getMajorErrorCode() {
return majorErrorCode;
}
public String getMinorErrorCode() {
return minorErrorCode;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((majorErrorCode == null) ? 0 : majorErrorCode.hashCode());
result = prime * result + ((message == null) ? 0 : message.hashCode());
result = prime * result
+ ((minorErrorCode == null) ? 0 : minorErrorCode.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;
ErrorImpl other = (ErrorImpl) obj;
if (majorErrorCode == null) {
if (other.majorErrorCode != null)
return false;
} else if (!majorErrorCode.equals(other.majorErrorCode))
return false;
if (message == null) {
if (other.message != null)
return false;
} else if (!message.equals(other.message))
return false;
if (minorErrorCode == null) {
if (other.minorErrorCode != null)
return false;
} else if (!minorErrorCode.equals(other.minorErrorCode))
return false;
return true;
}
@Override
public String toString() {
return "ErrorImpl [majorErrorCode=" + majorErrorCode + ", message="
+ message + ", minorErrorCode=" + minorErrorCode + "]";
}
}
private final String id; private final String id;
private final URI location; private final URI location;
private final TaskStatus status; private final TaskStatus status;
@ -45,10 +115,12 @@ public class TaskImpl implements Task {
private final NamedResource owner; private final NamedResource owner;
@Nullable @Nullable
private final NamedResource result; private final NamedResource result;
@Nullable
private final Error error;
public TaskImpl(String id, URI location, TaskStatus status, Date startTime, public TaskImpl(String id, URI location, TaskStatus status, Date startTime,
@Nullable Date endTime, NamedResource owner, @Nullable Date endTime, NamedResource owner,
@Nullable NamedResource result) { @Nullable NamedResource result, Error error) {
this.id = checkNotNull(id, "id"); this.id = checkNotNull(id, "id");
this.location = checkNotNull(location, "location"); this.location = checkNotNull(location, "location");
this.status = checkNotNull(status, "status"); this.status = checkNotNull(status, "status");
@ -56,6 +128,7 @@ public class TaskImpl implements Task {
this.endTime = endTime; this.endTime = endTime;
this.owner = owner; this.owner = owner;
this.result = result; this.result = result;
this.error = error;
} }
public TaskStatus getStatus() { public TaskStatus getStatus() {
@ -90,14 +163,18 @@ public class TaskImpl implements Task {
return location; return location;
} }
public Error getError() {
return error;
}
@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 + ((endTime == null) ? 0 : endTime.hashCode()); result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
result = prime * result + ((error == null) ? 0 : error.hashCode());
result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result result = prime * result + ((location == null) ? 0 : location.hashCode());
+ ((location == null) ? 0 : location.hashCode());
result = prime * result + ((owner == null) ? 0 : owner.hashCode()); result = prime * result + ((owner == null) ? 0 : owner.hashCode());
result = prime * result result = prime * result
+ ((this.result == null) ? 0 : this.result.hashCode()); + ((this.result == null) ? 0 : this.result.hashCode());
@ -121,6 +198,11 @@ public class TaskImpl implements Task {
return false; return false;
} else if (!endTime.equals(other.endTime)) } else if (!endTime.equals(other.endTime))
return false; return false;
if (error == null) {
if (other.error != null)
return false;
} else if (!error.equals(other.error))
return false;
if (id == null) { if (id == null) {
if (other.id != null) if (other.id != null)
return false; return false;
@ -156,9 +238,9 @@ public class TaskImpl implements Task {
@Override @Override
public String toString() { public String toString() {
return "TaskImpl [endTime=" + endTime + ", id=" + id + ", location=" return "TaskImpl [endTime=" + endTime + ", error=" + error + ", id=" + id
+ location + ", owner=" + owner + ", result=" + result + ", location=" + location + ", owner=" + owner + ", result="
+ ", startTime=" + startTime + ", status=" + status + "]"; + result + ", startTime=" + startTime + ", status=" + status + "]";
} }
} }

View File

@ -20,7 +20,7 @@ package org.jclouds.vcloud.domain.internal;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.util.SortedSet; import java.util.Set;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NamedResource;
@ -49,7 +49,7 @@ public class VAppImpl implements VApp {
private final ListMultimap<String, InetAddress> networkToAddresses; private final ListMultimap<String, InetAddress> networkToAddresses;
private final String operatingSystemDescription; private final String operatingSystemDescription;
private final VirtualSystem system; private final VirtualSystem system;
private final SortedSet<ResourceAllocation> resourceAllocations; private final Set<ResourceAllocation> resourceAllocations;
private final ListMultimap<ResourceType, ResourceAllocation> resourceAllocationByType; private final ListMultimap<ResourceType, ResourceAllocation> resourceAllocationByType;
/** The serialVersionUID */ /** The serialVersionUID */
@ -58,7 +58,7 @@ public class VAppImpl implements VApp {
public VAppImpl(String id, String name, URI location, VAppStatus status, Long size, public VAppImpl(String id, String name, URI location, VAppStatus status, Long size,
ListMultimap<String, InetAddress> networkToAddresses, ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, VirtualSystem system, String operatingSystemDescription, VirtualSystem system,
SortedSet<ResourceAllocation> resourceAllocations) { Set<ResourceAllocation> resourceAllocations) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.location = location; this.location = location;
@ -93,7 +93,7 @@ public class VAppImpl implements VApp {
return system; return system;
} }
public SortedSet<ResourceAllocation> getResourceAllocations() { public Set<ResourceAllocation> getResourceAllocations() {
return resourceAllocations; return resourceAllocations;
} }
@ -108,11 +108,21 @@ public class VAppImpl implements VApp {
result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); result = prime
result = prime * result * result
+ ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
result = prime * result result = prime
+ ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); * result
+ ((operatingSystemDescription == null) ? 0
: operatingSystemDescription.hashCode());
result = prime
* result
+ ((resourceAllocationByType == null) ? 0
: resourceAllocationByType.hashCode());
result = prime
* result
+ ((resourceAllocations == null) ? 0 : resourceAllocations
.hashCode());
result = prime * result + ((size == null) ? 0 : size.hashCode()); result = prime * result + ((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());
@ -151,7 +161,13 @@ public class VAppImpl implements VApp {
if (operatingSystemDescription == null) { if (operatingSystemDescription == null) {
if (other.operatingSystemDescription != null) if (other.operatingSystemDescription != null)
return false; return false;
} else if (!operatingSystemDescription.equals(other.operatingSystemDescription)) } else if (!operatingSystemDescription
.equals(other.operatingSystemDescription))
return false;
if (resourceAllocationByType == null) {
if (other.resourceAllocationByType != null)
return false;
} else if (!resourceAllocationByType.equals(other.resourceAllocationByType))
return false; return false;
if (resourceAllocations == null) { if (resourceAllocations == null) {
if (other.resourceAllocations != null) if (other.resourceAllocations != null)

View File

@ -22,7 +22,9 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.TaskImpl.ErrorImpl;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
/** /**
@ -31,15 +33,28 @@ import org.xml.sax.Attributes;
*/ */
public class Utils { public class Utils {
public static NamedResource newNamedResource(Attributes attributes) { public static NamedResource newNamedResource(Attributes attributes) {
String uri = attributes.getValue(attributes.getIndex("href")); String uri = attributes.getValue(attributes.getIndex("href"));
String id = uri.substring(uri.lastIndexOf('/') + 1); String id = uri.substring(uri.lastIndexOf('/') + 1);
return new NamedResourceImpl(id, attributes.getValue(attributes.getIndex("name")), attributes return new NamedResourceImpl(id, attributes.getValue(attributes
.getIndex("name")), attributes
.getValue(attributes.getIndex("type")), URI.create(uri)); .getValue(attributes.getIndex("type")), URI.create(uri));
} }
public static void putNamedResource(Map<String, NamedResource> map, Attributes attributes) { public static Task.Error newError(Attributes attributes) {
map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes)); return new ErrorImpl(attrOrNull(attributes, "message"), attrOrNull(
attributes, "majorErrorCode"), attrOrNull(attributes,
"minorErrorCode"));
}
private static String attrOrNull(Attributes attributes, String attr) {
return attributes.getIndex(attr) >= 0 ? attributes.getValue(attributes
.getIndex(attr)) : null;
}
public static void putNamedResource(Map<String, NamedResource> map,
Attributes attributes) {
map.put(attributes.getValue(attributes.getIndex("name")),
newNamedResource(attributes));
} }
} }

View File

@ -40,12 +40,12 @@ import com.google.common.collect.Maps;
*/ */
public class OrgHandler extends ParseSax.HandlerWithResult<Organization> { public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
private NamedResource org; private NamedResource org;
private Map<String, NamedResource> vdcs = Maps.newHashMap(); private Map<String, NamedResource> vdcs = Maps.newLinkedHashMap();
private Map<String, NamedResource> tasksLists = Maps.newHashMap(); private Map<String, NamedResource> tasksLists = Maps.newLinkedHashMap();
private NamedResource catalog; private Map<String, NamedResource> catalogs = Maps.newLinkedHashMap();
public Organization getResult() { public Organization getResult() {
return new OrganizationImpl(org.getId(), org.getName(), org.getLocation(), catalog, vdcs, return new OrganizationImpl(org.getId(), org.getName(), org.getLocation(), catalogs, vdcs,
tasksLists); tasksLists);
} }
@ -60,7 +60,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
if (attributes.getValue(typeIndex).equals(VDC_XML)) { if (attributes.getValue(typeIndex).equals(VDC_XML)) {
putNamedResource(vdcs, attributes); putNamedResource(vdcs, attributes);
} else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) { } else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) {
catalog = newNamedResource(attributes); putNamedResource(catalogs, attributes);
} else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) { } else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) {
putNamedResource(tasksLists, attributes); putNamedResource(tasksLists, attributes);
} }

View File

@ -54,7 +54,7 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException { throws SAXException {
if (qName.equals("Connection")) { if (qName.endsWith("Connection")) {
connected = new Boolean(attributes.getValue(attributes.getIndex("connected"))); connected = new Boolean(attributes.getValue(attributes.getIndex("connected")));
} }
} }
@ -63,34 +63,34 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
String current = currentOrNull(); String current = currentOrNull();
if (current != null) { if (current != null) {
if (qName.equals("Address")) { if (qName.endsWith("Address")) {
address = Integer.parseInt(current); address = Integer.parseInt(current);
} else if (qName.equals("AddressOnParent")) { } else if (qName.endsWith("AddressOnParent")) {
addressOnParent = Integer.parseInt(current); addressOnParent = Integer.parseInt(current);
} else if (qName.equals("AllocationUnits")) { } else if (qName.endsWith("AllocationUnits")) {
allocationUnits = current; allocationUnits = current;
} else if (qName.equals("Description")) { } else if (qName.endsWith("Description")) {
description = current; description = current;
} else if (qName.equals("ElementName")) { } else if (qName.endsWith("ElementName")) {
elementName = current; elementName = current;
} else if (qName.equals("InstanceID")) { } else if (qName.endsWith("InstanceID")) {
instanceID = Integer.parseInt(current); instanceID = Integer.parseInt(current);
} else if (qName.equals("Parent")) { } else if (qName.endsWith("Parent")) {
parent = Integer.parseInt(current); parent = Integer.parseInt(current);
} else if (qName.equals("ResourceSubType")) { } else if (qName.endsWith("ResourceSubType")) {
resourceSubType = current; resourceSubType = current;
} else if (qName.equals("ResourceType")) { } else if (qName.endsWith("ResourceType")) {
resourceType = ResourceType.fromValue(current); resourceType = ResourceType.fromValue(current);
} else if (qName.equals("VirtualQuantity")) { } else if (qName.endsWith("VirtualQuantity")) {
virtualQuantity = Long.parseLong(current); virtualQuantity = Long.parseLong(current);
} else if (qName.equals("VirtualQuantityUnits")) { } else if (qName.endsWith("VirtualQuantityUnits")) {
virtualQuantityUnits = current; virtualQuantityUnits = current;
} else if (qName.equals("HostResource")) { } else if (qName.endsWith("HostResource")) {
hostResource = currentText.toString().trim(); hostResource = currentText.toString().trim();
virtualQuantity = Long.parseLong(current); virtualQuantity = Long.parseLong(current);
virtualQuantityUnits = "byte * 2^20"; virtualQuantityUnits = "byte * 2^20";
} }
} else if (qName.equals("Item")) { } else if (qName.endsWith("Item")) {
if (allocationUnits != null) if (allocationUnits != null)
virtualQuantityUnits = allocationUnits; virtualQuantityUnits = allocationUnits;
this.allocation = new ResourceAllocation(instanceID, elementName, description, this.allocation = new ResourceAllocation(instanceID, elementName, description,

View File

@ -30,6 +30,7 @@ import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TaskStatus; import org.jclouds.vcloud.domain.TaskStatus;
import org.jclouds.vcloud.domain.Task.Error;
import org.jclouds.vcloud.domain.internal.TaskImpl; import org.jclouds.vcloud.domain.internal.TaskImpl;
import org.jclouds.vcloud.util.Utils; import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
@ -48,10 +49,12 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
private Date startTime; private Date startTime;
private Date endTime; private Date endTime;
private Task task; private Task task;
private Error error;
@Resource @Resource
protected Logger logger = Logger.NULL; protected Logger logger = Logger.NULL;
@Inject @Inject
public TaskHandler(DateService dateService) { public TaskHandler(DateService dateService) {
this.dateService = dateService; this.dateService = dateService;
@ -80,18 +83,21 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
taskLink = Utils.newNamedResource(attributes); taskLink = Utils.newNamedResource(attributes);
} else if (qName.equals("Result")) { } else if (qName.equals("Result")) {
result = Utils.newNamedResource(attributes); result = Utils.newNamedResource(attributes);
} else if (qName.equals("Error")) {
error = Utils.newError(attributes);
} }
} }
private Date parseDate(Attributes attributes, String attribute) { private Date parseDate(Attributes attributes, String attribute) {
String toParse =attributes.getValue(attributes.getIndex(attribute));
try { try {
return dateService.iso8601DateParse(attributes.getValue(attributes.getIndex(attribute))); return dateService.iso8601DateParse(toParse);
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (e.getCause() instanceof ParseException) { if (e.getCause() instanceof ParseException) {
try { try {
return dateService.iso8601SecondsDateParse(attributes.getValue(attributes if (!toParse.endsWith("Z"))
.getIndex(attribute))); toParse+="Z";
return dateService.iso8601SecondsDateParse(toParse);
} catch (RuntimeException ex) { } catch (RuntimeException ex) {
logger.error(e, "error parsing date"); logger.error(e, "error parsing date");
} }
@ -105,13 +111,14 @@ public class TaskHandler extends ParseSax.HandlerWithResult<Task> {
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("Task")) { if (qName.equalsIgnoreCase("Task")) {
this.task = new TaskImpl(taskLink.getId(), taskLink.getLocation(), status, startTime, endTime, owner, result); this.task = new TaskImpl(taskLink.getId(), taskLink.getLocation(), status, startTime, endTime, owner, result, error);
taskLink = null; taskLink = null;
status = null; status = null;
startTime = null; startTime = null;
endTime = null; endTime = null;
owner = null; owner = null;
result = null; result = null;
error = null;
} }
} }

View File

@ -21,18 +21,20 @@ package org.jclouds.vcloud.xml;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.SortedSet; import java.util.Set;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.inject.Inject; 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.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;
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.VAppImpl; import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.jclouds.vcloud.util.Utils;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -58,7 +60,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
} }
protected VirtualSystem system; protected VirtualSystem system;
protected SortedSet<ResourceAllocation> allocations = Sets.newTreeSet(); protected Set<ResourceAllocation> allocations = Sets.newLinkedHashSet();
protected VAppStatus status; protected VAppStatus status;
protected final ListMultimap<String, InetAddress> networkToAddresses = ArrayListMultimap protected final ListMultimap<String, InetAddress> networkToAddresses = ArrayListMultimap
.create(); .create();
@ -79,8 +81,10 @@ public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
public void startElement(String uri, String localName, String qName, Attributes attributes) public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException { throws SAXException {
if (qName.equals("VApp")) { if (qName.equals("VApp")) {
name = id = attributes.getValue(attributes.getIndex("name")); NamedResource resource = Utils.newNamedResource(attributes);
location = URI.create(attributes.getValue(attributes.getIndex("href"))); name = resource.getName();
id = resource.getId();
location = resource.getLocation();
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")));

View File

@ -42,15 +42,15 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSyst
@Override @Override
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("ElementName")) { if (qName.endsWith("ElementName")) {
this.elementName = currentText.toString().trim(); this.elementName = currentText.toString().trim();
} else if (qName.equals("InstanceID")) { } else if (qName.endsWith("InstanceID")) {
this.instanceID = Integer.parseInt(currentText.toString().trim()); this.instanceID = Integer.parseInt(currentText.toString().trim());
} else if (qName.equals("VirtualSystemIdentifier")) { } else if (qName.endsWith("VirtualSystemIdentifier")) {
this.virtualSystemIdentifier = currentText.toString().trim(); this.virtualSystemIdentifier = currentText.toString().trim();
} else if (qName.equals("VirtualSystemType")) { } else if (qName.endsWith("VirtualSystemType")) {
this.virtualSystemType = currentText.toString().trim(); this.virtualSystemType = currentText.toString().trim();
} else if (qName.equals("System")) { } else if (qName.endsWith("System")) {
this.system = new org.jclouds.vcloud.domain.VirtualSystem(instanceID, elementName, this.system = new org.jclouds.vcloud.domain.VirtualSystem(instanceID, elementName,
virtualSystemIdentifier, virtualSystemType); virtualSystemIdentifier, virtualSystemType);
this.elementName = null; this.elementName = null;

View File

@ -161,8 +161,8 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod); checkFilters(httpMethod);
} }
public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getOrganization"); Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1");
@ -176,8 +176,23 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod); checkFilters(httpMethod);
} }
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testOrganization() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog"); Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/org/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.org+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, OrgHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testDefaultCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getDefaultCatalog");
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1");
@ -191,6 +206,21 @@ public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod); checkFilters(httpMethod);
} }
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "1");
assertRequestLineEquals(httpMethod, "GET http://vcloud/catalog/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertPayloadEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { public void testNetwork() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class); Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2"); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, "2");

View File

@ -49,23 +49,25 @@ public class VCloudClientLiveTest {
@Test @Test
public void testOrganization() throws Exception { public void testOrganization() throws Exception {
Organization response = connection.getOrganization(); Organization response = connection.getDefaultOrganization();
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getId()); assertNotNull(response.getId());
assertNotNull(account); assertNotNull(account);
assertNotNull(response.getCatalog()); assert response.getCatalogs().size() >=1;
assertEquals(response.getTasksLists().size(), 1); assert response.getTasksLists().size() >=1;
assertEquals(response.getVDCs().size(), 1); assert response.getVDCs().size() >=1;
assertEquals(connection.getOrganization(response.getId()), response);
} }
@Test @Test
public void testCatalog() throws Exception { public void testCatalog() throws Exception {
Catalog response = connection.getCatalog(); Catalog response = connection.getDefaultCatalog();
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getId()); assertNotNull(response.getId());
assertNotNull(response.getName()); assertNotNull(response.getName());
assertNotNull(response.getLocation()); assertNotNull(response.getLocation());
assert response.size() > 0; assert response.size() > 0;
assertEquals(connection.getCatalog(response.getId()), response);
} }
@Test @Test
@ -81,7 +83,7 @@ public class VCloudClientLiveTest {
@Test @Test
public void testGetCatalogItem() throws Exception { public void testGetCatalogItem() throws Exception {
Catalog response = connection.getCatalog(); Catalog response = connection.getDefaultCatalog();
for (NamedResource resource : response.values()) { for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId()); CatalogItem item = connection.getCatalogItem(resource.getId());
@ -97,7 +99,7 @@ public class VCloudClientLiveTest {
@Test @Test
public void testGetVAppTemplate() throws Exception { public void testGetVAppTemplate() throws Exception {
Catalog response = connection.getCatalog(); Catalog response = connection.getDefaultCatalog();
for (NamedResource resource : response.values()) { for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId()); CatalogItem item = connection.getCatalogItem(resource.getId());

View File

@ -47,7 +47,7 @@ import com.google.inject.TypeLiteral;
import com.google.inject.internal.ImmutableMap; import com.google.inject.internal.ImmutableMap;
/** /**
* Tests behavior of {@code HostingDotComVCloudClient} * Tests behavior of {@code VCloudComputeClientLiveTest}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */

View File

@ -130,7 +130,7 @@ public class VCloudLoginLiveTest {
@BeforeClass @BeforeClass
void setupFactory() { void setupFactory() {
final String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"), final String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint"); "jclouds.test.endpoint")+"/v0.8/login";
final String account = checkNotNull(System.getProperty("jclouds.test.user"), final String account = checkNotNull(System.getProperty("jclouds.test.user"),
"jclouds.test.user"); "jclouds.test.user");
final String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); final String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");

View File

@ -77,9 +77,9 @@ public class OrgHandlerTest {
assertEquals(result.getId(), 48 + ""); assertEquals(result.getId(), 48 + "");
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getCatalog(), new NamedResourceImpl("catalog", assertEquals(result.getCatalogs(), ImmutableMap.of("Miami Environment 1 Catalog",new NamedResourceImpl("catalog",
"Miami Environment 1 Catalog", CATALOG_XML, "Miami Environment 1 Catalog", CATALOG_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))); URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))));
assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedResourceImpl( assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedResourceImpl(
"32", "Miami Environment 1", VCloudMediaType.VDC_XML, URI "32", "Miami Environment 1", VCloudMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))));
@ -121,8 +121,8 @@ public class OrgHandlerTest {
assertEquals(result.getId(), 188849 + ""); assertEquals(result.getId(), 188849 + "");
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://vcloud.safesecureweb.com/api/v0.8/org/188849")); .create("https://vcloud.safesecureweb.com/api/v0.8/org/188849"));
assertEquals(result.getCatalog(), new NamedResourceImpl("1", "HMS Shared Catalog", assertEquals(result.getCatalogs(), ImmutableMap.of( "HMS Shared Catalog", new NamedResourceImpl("1", "HMS Shared Catalog",
CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))); CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))));
assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter",
new NamedResourceImpl("188849", "188849 Virtual DataCenter", new NamedResourceImpl("188849", "188849 Virtual DataCenter",
VCloudMediaType.VDC_XML, URI VCloudMediaType.VDC_XML, URI

View File

@ -53,18 +53,30 @@ public class TaskHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/task.xml"); InputStream is = getClass().getResourceAsStream("/task.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class))
.parse(is);
Task expects = new TaskImpl("3299", URI Task expects = new TaskImpl(
"3299",
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), TaskStatus.SUCCESS,
dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), new NamedResourceImpl("1", dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"),
"VDC Name", VCloudMediaType.VDC_XML, dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"),
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), new NamedResourceImpl(
new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI "1",
"VDC Name",
VCloudMediaType.VDC_XML,
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
new NamedResourceImpl(
"4012",
"Server1",
VCloudMediaType.VAPP_XML,
URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012") .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")
) ), null
); );
assertEquals(result, expects); assertEquals(result, expects);
@ -74,12 +86,14 @@ public class TaskHandlerTest extends BaseHandlerTest {
public void testSelf() { public void testSelf() {
InputStream is = getClass().getResourceAsStream("/task-self.xml"); InputStream is = getClass().getResourceAsStream("/task-self.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class))
.parse(is);
Task expects = new TaskImpl("d188849-78", URI Task expects = new TaskImpl(
"d188849-78",
URI
.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"), .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"),
TaskStatus.QUEUED, null, null, null, null TaskStatus.QUEUED, null, null, null, null, null);
);
assertEquals(result, expects); assertEquals(result, expects);
} }
@ -87,13 +101,45 @@ public class TaskHandlerTest extends BaseHandlerTest {
public void testApplyInputStream2() { public void testApplyInputStream2() {
InputStream is = getClass().getResourceAsStream("/task-hosting.xml"); InputStream is = getClass().getResourceAsStream("/task-hosting.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class)).parse(is); Task result = factory.create(injector.getInstance(TaskHandler.class))
.parse(is);
Task expects = new TaskImpl("d188849-72", URI Task expects = new TaskImpl(
"d188849-72",
URI
.create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-72"), .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-72"),
TaskStatus.RUNNING, dateService.iso8601SecondsDateParse("2001-01-01T05:00:00Z"), TaskStatus.RUNNING,
null, new NamedResourceImpl("188849", "188849", VCloudMediaType.VDC_XML, URI dateService.iso8601SecondsDateParse("2001-01-01T05:00:00Z"),
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")), null); null,
new NamedResourceImpl(
"188849",
"188849",
VCloudMediaType.VDC_XML,
URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")),
null, null);
assertEquals(result, expects);
}
public void testError() {
InputStream is = getClass().getResourceAsStream("/task-error.xml");
Task result = factory.create(injector.getInstance(TaskHandler.class))
.parse(is);
Task expects = new TaskImpl(
"23",
URI.create("http://10.150.4.49/api/v0.8/task/23"),
TaskStatus.ERROR,
dateService.iso8601SecondsDateParse("2009-12-07T19:05:02Z"),
dateService.iso8601SecondsDateParse("2009-12-10T14:40:32Z"),
new NamedResourceImpl("1", "APIOrg", VCloudMediaType.ORG_XML, URI
.create("http://10.150.4.49/api/v0.8/org/1")),
new NamedResourceImpl("1", "testapp1", VCloudMediaType.VAPP_XML,
URI.create("http://10.150.4.49/api/v0.8/vapp/1")),
new TaskImpl.ErrorImpl("Error processing job", "500",
" Error in runDailySummaries date used:2009-12-09 19:40:30.577326+00:00"));
assertEquals(result, expects); assertEquals(result, expects);
} }

View File

@ -67,7 +67,7 @@ public class TasksListHandlerTest extends BaseHandlerTest {
"VDC Name", VCloudMediaType.VDC_XML, "VDC Name", VCloudMediaType.VDC_XML,
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")),null);
Task task2 = new TaskImpl("3299", URI Task task2 = new TaskImpl("3299", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"),
TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"),
@ -76,9 +76,7 @@ public class TasksListHandlerTest extends BaseHandlerTest {
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")), URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1")),
new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012") .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012")
), null
)
); );
assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2)); assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2));
assertEquals( assertEquals(

View File

@ -48,7 +48,7 @@ import com.google.common.collect.ListMultimap;
public class VAppHandlerTest extends BaseHandlerTest { public class VAppHandlerTest extends BaseHandlerTest {
// TODO why does this fail? // TODO why does this fail?
@Test(enabled = false) @Test(enabled = false)
public void testApplyInputStream() throws UnknownHostException { public void testHosting() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml"); InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml");
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is); VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
@ -80,6 +80,43 @@ public class VAppHandlerTest extends BaseHandlerTest {
new Long(20971520), networkToAddresses, null, system, resourceAllocations); new Long(20971520), networkToAddresses, null, system, resourceAllocations);
assertEquals(result, expects); assertEquals(result, expects);
}
// TODO why does this fail?
@Test(enabled = false)
public void testDefault() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/vapp.xml");
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
ListMultimap<String, InetAddress> networkToAddresses = ImmutableListMultimap
.<String, InetAddress> of();
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "Oracle", "vmx-07");
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet
.<ResourceAllocation> naturalOrder().add(
new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs",
ResourceType.PROCESSOR, null, null, null, null, null, null, 1,
"hertz * 10^6"),
new ResourceAllocation(2, "16MB of memory", "Memory Size",
ResourceType.MEMORY, null, null, null, null, null, null, 16,
"byte * 2^20")).add(
new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", null, 0, null, null,
null, 1, null)).add(
new ResourceAllocation(8, "Network Adapter 1", "PCNet32 ethernet adapter on \"Internal\" network",
ResourceType.ETHERNET_ADAPTER, "PCNet32", null, null, 7, null,
true, 1, null)).add(
new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.DISK_DRIVE,
null, "104857", null, 0, 3, null, 104857, "byte * 2^20"))
.build();
VApp expects = new VAppImpl("4", "Oracle", URI
.create("http://10.150.4.49/api/v0.8/vApp/4"), VAppStatus.ON,
new Long(104857), networkToAddresses, "Other Linux (32-bit)", system, resourceAllocations);
assertEquals(result, expects);
} }
} }

View File

@ -1,41 +1,45 @@
<?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/5" type="application/vnd.vmware.vcloud.vApp+xml" <VApp href="http://10.150.4.49/api/v0.8/vApp/4" type="application/vnd.vmware.vcloud.vApp+xml"
name="SQL" status="4" name="Oracle" status="4"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://10.150.4.49/api/v0.8/vcloud/vApp.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"> xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns="http://www.vmware.com/vcloud/v0.8"
<Link rel="up" xmlns:vmw="http://www.vmware.com/schema/ovf"
href="http://10.150.4.49/api/v0.8/vdc/3" xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
type="application/vnd.vmware.vcloud.vdc+xml"/> xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
<OperatingSystemSection ovf:id="36" xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" size="104857">
<Link rel="up" href="http://10.150.4.49/api/v0.8/vdc/4" type="application/vnd.vmware.vcloud.vdc+xml" />
<OperatingSystemSection d2p1:id="36"
xmlns="http://schemas.dmtf.org/ovf/envelope/1" xmlns:d2p1="http://schemas.dmtf.org/ovf/envelope/1">
<Info>The kind of installed guest operating system</Info> <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">
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">
<Info>Virtual hardware</Info> <Info>Virtual hardware</Info>
<Link rel="edit" href="http://10.150.4.49/api/v0.8/vApp/5" type="application/vnd.vmware.ovf.virtualHardwareSection+xml"/> <Link rel="edit" href="http://10.150.4.49/api/v0.8/vApp/4"
type="application/vnd.vmware.ovf.virtualHardwareSection+xml" />
<System> <System>
<rasd:AutomaticRecoveryAction xsi:nil="true" /> <vssd:AutomaticRecoveryAction xsi:nil="true" />
<rasd:AutomaticShutdownAction xsi:nil="true" /> <vssd:AutomaticShutdownAction xsi:nil="true" />
<rasd:AutomaticStartupAction xsi:nil="true" /> <vssd:AutomaticStartupAction xsi:nil="true" />
<rasd:AutomaticStartupActionDelay xsi:nil="true" /> <vssd:AutomaticStartupActionDelay
<rasd:AutomaticStartupActionSequenceNumber xsi:nil="true" /> xsi:nil="true" />
<rasd:Caption xsi:nil="true" /> <vssd:AutomaticStartupActionSequenceNumber
<rasd:ConfigurationDataRoot xsi:nil="true" /> xsi:nil="true" />
<rasd:ConfigurationFile xsi:nil="true" /> <vssd:Caption xsi:nil="true" />
<rasd:ConfigurationID xsi:nil="true" /> <vssd:ConfigurationDataRoot xsi:nil="true" />
<rasd:CreationTime xsi:nil="true" /> <vssd:ConfigurationFile xsi:nil="true" />
<rasd:Description xsi:nil="true" /> <vssd:ConfigurationID xsi:nil="true" />
<rasd:ElementName>Virtual Hardware Family</rasd:ElementName> <vssd:CreationTime xsi:nil="true" />
<rasd:InstanceID>0</rasd:InstanceID> <vssd:Description xsi:nil="true" />
<rasd:LogDataRoot xsi:nil="true" /> <vssd:ElementName>Virtual Hardware Family</vssd:ElementName>
<rasd:RecoveryFile xsi:nil="true" /> <vssd:InstanceID>0</vssd:InstanceID>
<rasd:SnapshotDataRoot xsi:nil="true" /> <vssd:LogDataRoot xsi:nil="true" />
<rasd:SuspendDataRoot xsi:nil="true" /> <vssd:RecoveryFile xsi:nil="true" />
<rasd:SwapFileDataRoot xsi:nil="true" /> <vssd:SnapshotDataRoot xsi:nil="true" />
<rasd:VirtualSystemIdentifier>SQL</rasd:VirtualSystemIdentifier> <vssd:SuspendDataRoot xsi:nil="true" />
<rasd:VirtualSystemType>vmx-07</rasd:VirtualSystemType> <vssd:SwapFileDataRoot xsi:nil="true" />
<vssd:VirtualSystemIdentifier>Oracle</vssd:VirtualSystemIdentifier>
<vssd:VirtualSystemType>vmx-07</vssd:VirtualSystemType>
</System> </System>
<Item> <Item>
<rasd:Address xsi:nil="true" /> <rasd:Address xsi:nil="true" />
@ -110,7 +114,8 @@
<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> <rasd:Description>PCNet32 ethernet adapter on "Internal" network
</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

@ -63,7 +63,7 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
// produces is incorrect, but required for hosting.com to operate // produces is incorrect, but required for hosting.com to operate
@XMLResponseParser(CatalogHandler.class) @XMLResponseParser(CatalogHandler.class)
@Override @Override
Future<? extends Catalog> getCatalog(); Future<? extends Catalog> getDefaultCatalog();
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)

View File

@ -20,7 +20,7 @@ package org.jclouds.vcloud.hostingdotcom.domain.internal;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.util.SortedSet; import java.util.Set;
import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
@ -47,7 +47,7 @@ public class HostingDotComVAppImpl extends VAppImpl implements HostingDotComVApp
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, ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, VirtualSystem system, String operatingSystemDescription, VirtualSystem system,
SortedSet<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, networkToAddresses, operatingSystemDescription,
system, resourceAllocations); system, resourceAllocations);
this.username = username; this.username = username;

View File

@ -59,7 +59,7 @@ import com.google.inject.TypeLiteral;
public class HostingDotComVCloudAsyncClientTest extends public class HostingDotComVCloudAsyncClientTest extends
RestClientTest<HostingDotComVCloudAsyncClient> { RestClientTest<HostingDotComVCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = HostingDotComVCloudAsyncClient.class.getMethod("getCatalog"); Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog");
GeneratedHttpRequest<HostingDotComVCloudAsyncClient> httpMethod = processor GeneratedHttpRequest<HostingDotComVCloudAsyncClient> httpMethod = processor
.createRequest(method); .createRequest(method);

View File

@ -44,7 +44,7 @@ public class ParseTaskFromLocationHeader implements Function<HttpResponse, Task>
if (location != null) { if (location != null) {
String taskId = location.substring(location.lastIndexOf('/') + 1); String taskId = location.substring(location.lastIndexOf('/') + 1);
return new TaskImpl(taskId, URI.create(location), TaskStatus.QUEUED, new Date(), null, return new TaskImpl(taskId, URI.create(location), TaskStatus.QUEUED, new Date(), null,
null, null); null, null, null);
} else { } else {
throw new HttpResponseException("no uri in headers or content", null, from); throw new HttpResponseException("no uri in headers or content", null, from);
} }

View File

@ -130,7 +130,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
@Test @Test
public void testGetConfigCustomizationOptions() throws Exception { public void testGetConfigCustomizationOptions() throws Exception {
Catalog response = connection.getCatalog(); Catalog response = connection.getDefaultCatalog();
for (NamedResource resource : response.values()) { for (NamedResource resource : response.values()) {
if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) {
CatalogItem item = connection.getCatalogItem(resource.getId()); CatalogItem item = connection.getCatalogItem(resource.getId());
@ -168,7 +168,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
String vDCId = tmClient.getDefaultVDC().getId(); String vDCId = tmClient.getDefaultVDC().getId();
// lookup the id of the item in the catalog you wish to deploy by name // lookup the id of the item in the catalog you wish to deploy by name
String itemId = tmClient.getCatalog().get("Ubuntu JeOS 9.04 (32-bit)").getId(); String itemId = tmClient.getDefaultCatalog().get("Ubuntu JeOS 9.04 (32-bit)").getId();
// determine the cheapest configuration size // determine the cheapest configuration size
SortedSet<ComputeOptions> sizeOptions = tmClient.getComputeOptionsOfCatalogItem(itemId); SortedSet<ComputeOptions> sizeOptions = tmClient.getComputeOptionsOfCatalogItem(itemId);