diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index 75c4172dd0..dce5a7a519 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -18,6 +18,7 @@ */ 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.CATALOG_XML; import static org.jclouds.vcloud.VCloudMediaType.NETWORK_XML; @@ -82,16 +83,30 @@ public interface VCloudAsyncClient { @GET @Endpoint(Org.class) - @Consumes(VCloudMediaType.ORG_XML) + @Consumes(ORG_XML) @XMLResponseParser(OrgHandler.class) - Future getOrganization(); - + Future getDefaultOrganization(); + + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/org/{orgId}") + @XMLResponseParser(OrgHandler.class) + @Consumes(ORG_XML) + Future getOrganization(@PathParam("orgId") String orgId); + @GET @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @Consumes(CATALOG_XML) @XMLResponseParser(CatalogHandler.class) - Future getCatalog(); - + Future getDefaultCatalog(); + + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/catalog/{catalogId}") + @XMLResponseParser(CatalogHandler.class) + @Consumes(CATALOG_XML) + Future getCatalog(@PathParam("catalogId") String catalogId); + @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vAppTemplate/{vAppTemplateId}") diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index be661bb2bf..d49f2eed64 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -46,9 +46,13 @@ public interface VCloudClient { * This call returns a list of all vCloud Data Centers (vdcs), catalogs, and task lists within * the organization. */ - Organization getOrganization(); + Organization getDefaultOrganization(); + + Organization getOrganization(String orgId); - Catalog getCatalog(); + Catalog getDefaultCatalog(); + + Catalog getCatalog(String catalogId); CatalogItem getCatalogItem(String catalogItemId); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java index c2c15126f5..b93f4230d9 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java @@ -181,7 +181,7 @@ public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder } protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder, String name, - String network) { + String network) { XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection").e( "NetworkConfig").a("name", name); XMLBuilder featuresBuilder = networkConfigBuilder.e("Features"); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index b5aae2dcf4..d282a70c4f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -33,6 +33,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import javax.annotation.Resource; import javax.inject.Named; import javax.inject.Singleton; @@ -41,6 +42,7 @@ import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.encryption.EncryptionService; import org.jclouds.http.RequiresHttp; import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.logging.Logger; import org.jclouds.predicates.AddressReachable; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; @@ -81,7 +83,9 @@ import com.google.inject.Provides; @RequiresHttp @ConfiguresRestClient public class VCloudRestClientModule extends AbstractModule { - + @Resource + protected Logger logger = Logger.NULL; + @Provides @Singleton protected Predicate socketTester(SocketOpen open) { @@ -102,6 +106,7 @@ public class VCloudRestClientModule extends AbstractModule { @Override protected void configure() { + requestInjection(this); } @VCloudToken @@ -217,21 +222,21 @@ public class VCloudRestClientModule extends AbstractModule { @Singleton protected Organization provideOrganization(VCloudClient discovery) throws ExecutionException, TimeoutException, InterruptedException { - return discovery.getOrganization(); + return discovery.getDefaultOrganization(); } @Provides @VDC @Singleton protected URI provideDefaultVDC(Organization org) { - return org.getVDCs().values().iterator().next().getLocation(); + return Iterables.get(org.getVDCs().values(), 0).getLocation(); } @Provides @Catalog @Singleton protected URI provideCatalog(Organization org) { - return org.getCatalog().getLocation(); + return Iterables.get(org.getCatalogs().values(), 0).getLocation(); } @Provides @@ -239,8 +244,7 @@ public class VCloudRestClientModule extends AbstractModule { @Singleton protected URI provideDefaultNetwork(VCloudAsyncClient client) throws InterruptedException, ExecutionException, TimeoutException { - return client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks().values() - .iterator().next().getLocation(); + return Iterables.get(client.getDefaultVDC().get(180, TimeUnit.SECONDS).getAvailableNetworks().values(), 0).getLocation(); } @Provides diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java index 4ad0647d4b..c536ceb657 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Organization.java @@ -36,7 +36,7 @@ import com.google.inject.ImplementedBy; public interface Organization extends NamedResource { @Catalog - NamedResource getCatalog(); + Map getCatalogs(); @VDC Map getVDCs(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java index 3db97b82e1..64fc8b4999 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java @@ -126,90 +126,96 @@ public class ResourceAllocation implements Comparable { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((address == null) ? 0 : address.hashCode()); - result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode()); - result = prime * result + ((connected == null) ? 0 : connected.hashCode()); - result = prime * result + ((description == null) ? 0 : description.hashCode()); - result = prime * result + ((hostResource == null) ? 0 : hostResource.hashCode()); - result = prime * result + id; - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((parent == null) ? 0 : parent.hashCode()); - result = prime * result + ((subType == null) ? 0 : subType.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + (int) (virtualQuantity ^ (virtualQuantity >>> 32)); - result = prime * result - + ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits.hashCode()); - return result; - } +public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((address == null) ? 0 : address.hashCode()); + result = prime * result + + ((addressOnParent == null) ? 0 : addressOnParent.hashCode()); + result = prime * result + ((connected == null) ? 0 : connected.hashCode()); + result = prime * result + + ((description == null) ? 0 : description.hashCode()); + result = prime * result + + ((hostResource == null) ? 0 : hostResource.hashCode()); + result = prime * result + id; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((parent == null) ? 0 : parent.hashCode()); + result = prime * result + ((subType == null) ? 0 : subType.hashCode()); + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + + (int) (virtualQuantity ^ (virtualQuantity >>> 32)); + result = prime + * result + + ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits + .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; - ResourceAllocation other = (ResourceAllocation) obj; - if (address == null) { - if (other.address != null) - return false; - } else if (!address.equals(other.address)) - return false; - if (addressOnParent == null) { - if (other.addressOnParent != null) - return false; - } else if (!addressOnParent.equals(other.addressOnParent)) - return false; - if (connected == null) { - if (other.connected != null) - return false; - } else if (!connected.equals(other.connected)) - return false; - if (description == null) { - if (other.description != null) - return false; - } else if (!description.equals(other.description)) - return false; - if (hostResource == null) { - if (other.hostResource != null) - return false; - } else if (!hostResource.equals(other.hostResource)) - return false; - if (id != other.id) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (parent == null) { - if (other.parent != null) - return false; - } else if (!parent.equals(other.parent)) - return false; - if (subType == null) { - if (other.subType != null) - return false; - } else if (!subType.equals(other.subType)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - if (virtualQuantity != other.virtualQuantity) - return false; - if (virtualQuantityUnits == null) { - if (other.virtualQuantityUnits != null) - return false; - } else if (!virtualQuantityUnits.equals(other.virtualQuantityUnits)) - return false; - return true; - } +public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ResourceAllocation other = (ResourceAllocation) obj; + if (address == null) { + if (other.address != null) + return false; + } else if (!address.equals(other.address)) + return false; + if (addressOnParent == null) { + if (other.addressOnParent != null) + return false; + } else if (!addressOnParent.equals(other.addressOnParent)) + return false; + if (connected == null) { + if (other.connected != null) + return false; + } else if (!connected.equals(other.connected)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (hostResource == null) { + if (other.hostResource != null) + return false; + } else if (!hostResource.equals(other.hostResource)) + return false; + if (id != other.id) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (parent == null) { + if (other.parent != null) + return false; + } else if (!parent.equals(other.parent)) + return false; + if (subType == null) { + if (other.subType != null) + return false; + } else if (!subType.equals(other.subType)) + return false; + if (type == null) { + if (other.type != null) + return false; + } else if (!type.equals(other.type)) + return false; + if (virtualQuantity != other.virtualQuantity) + return false; + if (virtualQuantityUnits == null) { + if (other.virtualQuantityUnits != null) + return false; + } else if (!virtualQuantityUnits.equals(other.virtualQuantityUnits)) + return false; + return true; +} @Override public String toString() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java index 7d94aa13f0..f51402786f 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Task.java @@ -49,4 +49,13 @@ public interface Task extends Comparable { * A link to the result of the task */ NamedResource getResult(); + + Error getError(); + + @ImplementedBy(TaskImpl.ErrorImpl.class) + static interface Error { + String getMessage(); + String getMajorErrorCode(); + String getMinorErrorCode(); + } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java index a62de5899d..57fc70e17b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java @@ -19,7 +19,7 @@ package org.jclouds.vcloud.domain; import java.net.InetAddress; -import java.util.SortedSet; +import java.util.Set; import com.google.common.collect.ListMultimap; import com.google.common.collect.Multimap; @@ -43,7 +43,7 @@ public interface VApp extends NamedResource { VirtualSystem getSystem(); - SortedSet getResourceAllocations(); + Set getResourceAllocations(); Multimap getResourceAllocationByType(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java index 2bfdc4d4c3..07cd7cf495 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java @@ -50,44 +50,45 @@ public class VirtualSystem { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - result = prime * result + ((identifier == null) ? 0 : identifier.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((type == null) ? 0 : type.hashCode()); - return result; - } +public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + result = prime * result + + ((identifier == null) ? 0 : identifier.hashCode()); + result = prime * result + ((name == null) ? 0 : name.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; - VirtualSystem other = (VirtualSystem) obj; - if (id != other.id) - return false; - if (identifier == null) { - if (other.identifier != null) - return false; - } else if (!identifier.equals(other.identifier)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (type == null) { - if (other.type != null) - return false; - } else if (!type.equals(other.type)) - return false; - return true; - } +public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VirtualSystem other = (VirtualSystem) obj; + if (id != other.id) + return false; + if (identifier == null) { + if (other.identifier != null) + return false; + } else if (!identifier.equals(other.identifier)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + 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() { diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java index 20f53a6dbf..677ddc5e53 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/OrganizationImpl.java @@ -38,16 +38,16 @@ public class OrganizationImpl implements Organization { private final String id; private final String name; private final URI location; - private final NamedResource catalog; + private final Map catalogs; private final Map vdcs; private final Map tasksLists; - public OrganizationImpl(String id, String name, URI location, NamedResource catalog, + public OrganizationImpl(String id, String name, URI location, Map catalogs, Map vdcs, Map tasksLists) { this.id = id; this.name = name; this.location = location; - this.catalog = catalog; + this.catalogs = catalogs; this.vdcs = vdcs; this.tasksLists = tasksLists; } @@ -65,8 +65,8 @@ public class OrganizationImpl implements Organization { } @Catalog - public NamedResource getCatalog() { - return catalog; + public Map getCatalogs() { + return catalogs; } @VDC @@ -83,7 +83,7 @@ public class OrganizationImpl implements Organization { public int hashCode() { final int prime = 31; 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 + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); @@ -101,10 +101,10 @@ public class OrganizationImpl implements Organization { if (getClass() != obj.getClass()) return false; OrganizationImpl other = (OrganizationImpl) obj; - if (catalog == null) { - if (other.catalog != null) + if (catalogs == null) { + if (other.catalogs != null) return false; - } else if (!catalog.equals(other.catalog)) + } else if (!catalogs.equals(other.catalogs)) return false; if (id == null) { if (other.id != null) diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java index 6c56eff556..540a2dd8bc 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/TaskImpl.java @@ -30,135 +30,217 @@ import org.jclouds.vcloud.domain.TaskStatus; import com.google.inject.internal.Nullable; /** - * Locations of resources in vCloud * * @author Adrian Cole * */ public class TaskImpl implements Task { - private final String id; - private final URI location; - private final TaskStatus status; - private final Date startTime; - @Nullable - private final Date endTime; - private final NamedResource owner; - @Nullable - private final NamedResource result; - public TaskImpl(String id, URI location, TaskStatus status, Date startTime, - @Nullable Date endTime, NamedResource owner, - @Nullable NamedResource result) { - this.id = checkNotNull(id, "id"); - this.location = checkNotNull(location, "location"); - this.status = checkNotNull(status, "status"); - this.startTime = startTime; - this.endTime = endTime; - this.owner = owner; - this.result = result; - } + public static class ErrorImpl implements Error { + private final String message; + private final String majorErrorCode; + private final String minorErrorCode; - public TaskStatus getStatus() { - return status; - } + public ErrorImpl(String message, String majorErrorCode, + String minorErrorCode) { + this.message = message; + this.majorErrorCode = majorErrorCode; + this.minorErrorCode = minorErrorCode; + } - public Date getStartTime() { - return startTime; - } + public String getMessage() { + return message; + } - public NamedResource getOwner() { - return owner; - } + public String getMajorErrorCode() { + return majorErrorCode; + } - public NamedResource getResult() { - return result; - } + public String getMinorErrorCode() { + return minorErrorCode; + } - public Date getEndTime() { - return endTime; - } + @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; + } - public int compareTo(Task o) { - return (this == o) ? 0 : getId().compareTo(o.getId()); - } + @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; + } - public String getId() { - return id; - } + @Override + public String toString() { + return "ErrorImpl [majorErrorCode=" + majorErrorCode + ", message=" + + message + ", minorErrorCode=" + minorErrorCode + "]"; + } + } - public URI getLocation() { - return location; - } + private final String id; + private final URI location; + private final TaskStatus status; + private final Date startTime; + @Nullable + private final Date endTime; + private final NamedResource owner; + @Nullable + private final NamedResource result; + @Nullable + private final Error error; - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((endTime == null) ? 0 : endTime.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result - + ((location == null) ? 0 : location.hashCode()); - result = prime * result + ((owner == null) ? 0 : owner.hashCode()); - result = prime * result - + ((this.result == null) ? 0 : this.result.hashCode()); - result = prime * result - + ((startTime == null) ? 0 : startTime.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - return result; - } + public TaskImpl(String id, URI location, TaskStatus status, Date startTime, + @Nullable Date endTime, NamedResource owner, + @Nullable NamedResource result, Error error) { + this.id = checkNotNull(id, "id"); + this.location = checkNotNull(location, "location"); + this.status = checkNotNull(status, "status"); + this.startTime = startTime; + this.endTime = endTime; + this.owner = owner; + this.result = result; + this.error = error; + } - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - TaskImpl other = (TaskImpl) obj; - if (endTime == null) { - if (other.endTime != null) - return false; - } else if (!endTime.equals(other.endTime)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (location == null) { - if (other.location != null) - return false; - } else if (!location.equals(other.location)) - return false; - if (owner == null) { - if (other.owner != null) - return false; - } else if (!owner.equals(other.owner)) - return false; - if (result == null) { - if (other.result != null) - return false; - } else if (!result.equals(other.result)) - return false; - if (startTime == null) { - if (other.startTime != null) - return false; - } else if (!startTime.equals(other.startTime)) - return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - return false; - return true; - } + public TaskStatus getStatus() { + return status; + } - @Override - public String toString() { - return "TaskImpl [endTime=" + endTime + ", id=" + id + ", location=" - + location + ", owner=" + owner + ", result=" + result - + ", startTime=" + startTime + ", status=" + status + "]"; - } + public Date getStartTime() { + return startTime; + } + + public NamedResource getOwner() { + return owner; + } + + public NamedResource getResult() { + return result; + } + + public Date getEndTime() { + return endTime; + } + + public int compareTo(Task o) { + return (this == o) ? 0 : getId().compareTo(o.getId()); + } + + public String getId() { + return id; + } + + public URI getLocation() { + return location; + } + + public Error getError() { + return error; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + 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 + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((owner == null) ? 0 : owner.hashCode()); + result = prime * result + + ((this.result == null) ? 0 : this.result.hashCode()); + result = prime * result + + ((startTime == null) ? 0 : startTime.hashCode()); + result = prime * result + ((status == null) ? 0 : status.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; + TaskImpl other = (TaskImpl) obj; + if (endTime == null) { + if (other.endTime != null) + return false; + } else if (!endTime.equals(other.endTime)) + return false; + if (error == null) { + if (other.error != null) + return false; + } else if (!error.equals(other.error)) + return false; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + return false; + if (owner == null) { + if (other.owner != null) + return false; + } else if (!owner.equals(other.owner)) + return false; + if (result == null) { + if (other.result != null) + return false; + } else if (!result.equals(other.result)) + return false; + if (startTime == null) { + if (other.startTime != null) + return false; + } else if (!startTime.equals(other.startTime)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + return true; + } + + @Override + public String toString() { + return "TaskImpl [endTime=" + endTime + ", error=" + error + ", id=" + id + + ", location=" + location + ", owner=" + owner + ", result=" + + result + ", startTime=" + startTime + ", status=" + status + "]"; + } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java index 1bbe6b4501..12839da59b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.domain.internal; import java.net.InetAddress; import java.net.URI; -import java.util.SortedSet; +import java.util.Set; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.NamedResource; @@ -49,7 +49,7 @@ public class VAppImpl implements VApp { private final ListMultimap networkToAddresses; private final String operatingSystemDescription; private final VirtualSystem system; - private final SortedSet resourceAllocations; + private final Set resourceAllocations; private final ListMultimap resourceAllocationByType; /** The serialVersionUID */ @@ -58,7 +58,7 @@ public class VAppImpl implements VApp { public VAppImpl(String id, String name, URI location, VAppStatus status, Long size, ListMultimap networkToAddresses, String operatingSystemDescription, VirtualSystem system, - SortedSet resourceAllocations) { + Set resourceAllocations) { this.id = id; this.name = name; this.location = location; @@ -93,7 +93,7 @@ public class VAppImpl implements VApp { return system; } - public SortedSet getResourceAllocations() { + public Set getResourceAllocations() { return resourceAllocations; } @@ -102,79 +102,95 @@ public class VAppImpl implements VApp { } @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((location == null) ? 0 : location.hashCode()); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); - result = prime * result - + ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); - result = prime * result - + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); - result = prime * result + ((size == null) ? 0 : size.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); - result = prime * result + ((system == null) ? 0 : system.hashCode()); - return result; - } +public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime + * result + + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); + result = prime + * result + + ((operatingSystemDescription == null) ? 0 + : operatingSystemDescription.hashCode()); + result = prime + * result + + ((resourceAllocationByType == null) ? 0 + : resourceAllocationByType.hashCode()); + result = prime + * result + + ((resourceAllocations == null) ? 0 : resourceAllocations + .hashCode()); + result = prime * result + ((size == null) ? 0 : size.hashCode()); + result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + ((system == null) ? 0 : system.hashCode()); + return result; +} @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - VAppImpl other = (VAppImpl) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (location == null) { - if (other.location != null) - return false; - } else if (!location.equals(other.location)) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (networkToAddresses == null) { - if (other.networkToAddresses != null) - return false; - } else if (!networkToAddresses.equals(other.networkToAddresses)) - return false; - if (operatingSystemDescription == null) { - if (other.operatingSystemDescription != null) - return false; - } else if (!operatingSystemDescription.equals(other.operatingSystemDescription)) - return false; - if (resourceAllocations == null) { - if (other.resourceAllocations != null) - return false; - } else if (!resourceAllocations.equals(other.resourceAllocations)) - return false; - if (size == null) { - if (other.size != null) - return false; - } else if (!size.equals(other.size)) - return false; - if (status == null) { - if (other.status != null) - return false; - } else if (!status.equals(other.status)) - return false; - if (system == null) { - if (other.system != null) - return false; - } else if (!system.equals(other.system)) - return false; - return true; - } +public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + VAppImpl other = (VAppImpl) obj; + if (id == null) { + if (other.id != null) + return false; + } else if (!id.equals(other.id)) + return false; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (networkToAddresses == null) { + if (other.networkToAddresses != null) + return false; + } else if (!networkToAddresses.equals(other.networkToAddresses)) + return false; + if (operatingSystemDescription == null) { + if (other.operatingSystemDescription != null) + return false; + } else if (!operatingSystemDescription + .equals(other.operatingSystemDescription)) + return false; + if (resourceAllocationByType == null) { + if (other.resourceAllocationByType != null) + return false; + } else if (!resourceAllocationByType.equals(other.resourceAllocationByType)) + return false; + if (resourceAllocations == null) { + if (other.resourceAllocations != null) + return false; + } else if (!resourceAllocations.equals(other.resourceAllocations)) + return false; + if (size == null) { + if (other.size != null) + return false; + } else if (!size.equals(other.size)) + return false; + if (status == null) { + if (other.status != null) + return false; + } else if (!status.equals(other.status)) + return false; + if (system == null) { + if (other.system != null) + return false; + } else if (!system.equals(other.system)) + return false; + return true; +} public String getId() { return id; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java index 05b2797410..2e8ede14cb 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/util/Utils.java @@ -22,7 +22,9 @@ import java.net.URI; import java.util.Map; 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.TaskImpl.ErrorImpl; import org.xml.sax.Attributes; /** @@ -31,15 +33,28 @@ import org.xml.sax.Attributes; */ public class Utils { - public static NamedResource newNamedResource(Attributes attributes) { String uri = attributes.getValue(attributes.getIndex("href")); String id = uri.substring(uri.lastIndexOf('/') + 1); - return new NamedResourceImpl(id, attributes.getValue(attributes.getIndex("name")), attributes - .getValue(attributes.getIndex("type")), URI.create(uri)); + return new NamedResourceImpl(id, attributes.getValue(attributes + .getIndex("name")), attributes + .getValue(attributes.getIndex("type")), URI.create(uri)); } - public static void putNamedResource(Map map, Attributes attributes) { - map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes)); + public static Task.Error newError(Attributes 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 map, + Attributes attributes) { + map.put(attributes.getValue(attributes.getIndex("name")), + newNamedResource(attributes)); } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java index 30b4721850..102ac73849 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java @@ -40,12 +40,12 @@ import com.google.common.collect.Maps; */ public class OrgHandler extends ParseSax.HandlerWithResult { private NamedResource org; - private Map vdcs = Maps.newHashMap(); - private Map tasksLists = Maps.newHashMap(); - private NamedResource catalog; + private Map vdcs = Maps.newLinkedHashMap(); + private Map tasksLists = Maps.newLinkedHashMap(); + private Map catalogs = Maps.newLinkedHashMap(); 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); } @@ -60,7 +60,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult { if (attributes.getValue(typeIndex).equals(VDC_XML)) { putNamedResource(vdcs, attributes); } else if (attributes.getValue(typeIndex).equals(CATALOG_XML)) { - catalog = newNamedResource(attributes); + putNamedResource(catalogs, attributes); } else if (attributes.getValue(typeIndex).equals(TASKSLIST_XML)) { putNamedResource(tasksLists, attributes); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java index 3db44fa530..358c6b81c6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java @@ -54,7 +54,7 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult { private Date startTime; private Date endTime; private Task task; + private Error error; @Resource protected Logger logger = Logger.NULL; + @Inject public TaskHandler(DateService dateService) { this.dateService = dateService; @@ -80,18 +83,21 @@ public class TaskHandler extends ParseSax.HandlerWithResult { taskLink = Utils.newNamedResource(attributes); } else if (qName.equals("Result")) { result = Utils.newNamedResource(attributes); + } else if (qName.equals("Error")) { + error = Utils.newError(attributes); } } private Date parseDate(Attributes attributes, String attribute) { + String toParse =attributes.getValue(attributes.getIndex(attribute)); try { - return dateService.iso8601DateParse(attributes.getValue(attributes.getIndex(attribute))); - + return dateService.iso8601DateParse(toParse); } catch (RuntimeException e) { if (e.getCause() instanceof ParseException) { try { - return dateService.iso8601SecondsDateParse(attributes.getValue(attributes - .getIndex(attribute))); + if (!toParse.endsWith("Z")) + toParse+="Z"; + return dateService.iso8601SecondsDateParse(toParse); } catch (RuntimeException ex) { logger.error(e, "error parsing date"); } @@ -105,13 +111,14 @@ public class TaskHandler extends ParseSax.HandlerWithResult { @Override public void endElement(String uri, String localName, String qName) throws SAXException { 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; status = null; startTime = null; endTime = null; owner = null; result = null; + error = null; } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java index 3a9b9ffa68..4a19c24c0a 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java @@ -21,18 +21,20 @@ package org.jclouds.vcloud.xml; import java.net.InetAddress; import java.net.URI; import java.net.UnknownHostException; -import java.util.SortedSet; +import java.util.Set; import javax.annotation.Resource; import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; import org.jclouds.logging.Logger; +import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation; import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VirtualSystem; import org.jclouds.vcloud.domain.internal.VAppImpl; +import org.jclouds.vcloud.util.Utils; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -58,7 +60,7 @@ public class VAppHandler extends ParseSax.HandlerWithResult { } protected VirtualSystem system; - protected SortedSet allocations = Sets.newTreeSet(); + protected Set allocations = Sets.newLinkedHashSet(); protected VAppStatus status; protected final ListMultimap networkToAddresses = ArrayListMultimap .create(); @@ -79,8 +81,10 @@ public class VAppHandler extends ParseSax.HandlerWithResult { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("VApp")) { - name = id = attributes.getValue(attributes.getIndex("name")); - location = URI.create(attributes.getValue(attributes.getIndex("href"))); + NamedResource resource = Utils.newNamedResource(attributes); + name = resource.getName(); + id = resource.getId(); + location = resource.getLocation(); status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status"))); if (attributes.getIndex("size") != -1) size = new Long(attributes.getValue(attributes.getIndex("size"))); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java index ebdb454b04..a54261c2a0 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java @@ -42,15 +42,15 @@ public class VirtualSystemHandler extends ParseSax.HandlerWithResult { checkFilters(httpMethod); } - public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getOrganization"); + public void testDefaultOrganization() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getDefaultOrganization"); GeneratedHttpRequest httpMethod = processor.createRequest(method); assertRequestLineEquals(httpMethod, "GET http://org HTTP/1.1"); @@ -175,9 +175,24 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(httpMethod); } + + public void testOrganization() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getOrganization", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, "1"); - public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudAsyncClient.class.getMethod("getCatalog"); + 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 httpMethod = processor.createRequest(method); assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); @@ -190,6 +205,21 @@ public class VCloudAsyncClientTest extends RestClientTest { checkFilters(httpMethod); } + + public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getCatalog", String.class); + GeneratedHttpRequest 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 { Method method = VCloudAsyncClient.class.getMethod("getNetwork", String.class); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 73671a7f3b..d3b24284bd 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -49,23 +49,25 @@ public class VCloudClientLiveTest { @Test public void testOrganization() throws Exception { - Organization response = connection.getOrganization(); + Organization response = connection.getDefaultOrganization(); assertNotNull(response); assertNotNull(response.getId()); assertNotNull(account); - assertNotNull(response.getCatalog()); - assertEquals(response.getTasksLists().size(), 1); - assertEquals(response.getVDCs().size(), 1); + assert response.getCatalogs().size() >=1; + assert response.getTasksLists().size() >=1; + assert response.getVDCs().size() >=1; + assertEquals(connection.getOrganization(response.getId()), response); } @Test public void testCatalog() throws Exception { - Catalog response = connection.getCatalog(); + Catalog response = connection.getDefaultCatalog(); assertNotNull(response); assertNotNull(response.getId()); assertNotNull(response.getName()); assertNotNull(response.getLocation()); assert response.size() > 0; + assertEquals(connection.getCatalog(response.getId()), response); } @Test @@ -81,7 +83,7 @@ public class VCloudClientLiveTest { @Test public void testGetCatalogItem() throws Exception { - Catalog response = connection.getCatalog(); + Catalog response = connection.getDefaultCatalog(); for (NamedResource resource : response.values()) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { CatalogItem item = connection.getCatalogItem(resource.getId()); @@ -97,7 +99,7 @@ public class VCloudClientLiveTest { @Test public void testGetVAppTemplate() throws Exception { - Catalog response = connection.getCatalog(); + Catalog response = connection.getDefaultCatalog(); for (NamedResource resource : response.values()) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { CatalogItem item = connection.getCatalogItem(resource.getId()); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java index f811ba4753..7de7a2a9b0 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java @@ -47,7 +47,7 @@ import com.google.inject.TypeLiteral; import com.google.inject.internal.ImmutableMap; /** - * Tests behavior of {@code HostingDotComVCloudClient} + * Tests behavior of {@code VCloudComputeClientLiveTest} * * @author Adrian Cole */ diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java index df61716e9d..12794589e8 100755 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudLoginLiveTest.java @@ -130,7 +130,7 @@ public class VCloudLoginLiveTest { @BeforeClass void setupFactory() { 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"), "jclouds.test.user"); final String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java index 5e711fd963..dcb3a3e5c2 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/OrgHandlerTest.java @@ -77,9 +77,9 @@ public class OrgHandlerTest { assertEquals(result.getId(), 48 + ""); assertEquals(result.getLocation(), URI .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, - 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( "32", "Miami Environment 1", VCloudMediaType.VDC_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")))); @@ -121,8 +121,8 @@ public class OrgHandlerTest { assertEquals(result.getId(), 188849 + ""); assertEquals(result.getLocation(), URI .create("https://vcloud.safesecureweb.com/api/v0.8/org/188849")); - assertEquals(result.getCatalog(), new NamedResourceImpl("1", "HMS Shared Catalog", - CATALOG_XML, URI.create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1"))); + 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")))); assertEquals(result.getVDCs(), ImmutableMap.of("188849 Virtual DataCenter", new NamedResourceImpl("188849", "188849 Virtual DataCenter", VCloudMediaType.VDC_XML, URI diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java index 20c116d395..7e0b830c95 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TaskHandlerTest.java @@ -53,18 +53,30 @@ public class TaskHandlerTest extends BaseHandlerTest { public void testApplyInputStream() { 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 - .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), - TaskStatus.SUCCESS, dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), - dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), new NamedResourceImpl("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 + Task expects = new TaskImpl( + "3299", + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), + TaskStatus.SUCCESS, + dateService.iso8601DateParse("2009-08-24T21:29:32.983Z"), + dateService.iso8601DateParse("2009-08-24T21:29:44.65Z"), + new NamedResourceImpl( + "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") - ) + ), null ); assertEquals(result, expects); @@ -74,12 +86,14 @@ public class TaskHandlerTest extends BaseHandlerTest { public void testSelf() { 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 - .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"), - TaskStatus.QUEUED, null, null, null, null - ); + Task expects = new TaskImpl( + "d188849-78", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-78"), + TaskStatus.QUEUED, null, null, null, null, null); assertEquals(result, expects); } @@ -87,13 +101,45 @@ public class TaskHandlerTest extends BaseHandlerTest { public void testApplyInputStream2() { 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 - .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-72"), - TaskStatus.RUNNING, dateService.iso8601SecondsDateParse("2001-01-01T05:00:00Z"), - null, new NamedResourceImpl("188849", "188849", VCloudMediaType.VDC_XML, URI - .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")), null); + Task expects = new TaskImpl( + "d188849-72", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/task/d188849-72"), + TaskStatus.RUNNING, + dateService.iso8601SecondsDateParse("2001-01-01T05:00:00Z"), + 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); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java index c5d7c291d9..1a8ff15831 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/TasksListHandlerTest.java @@ -67,7 +67,7 @@ public class TasksListHandlerTest extends BaseHandlerTest { "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); Task task2 = new TaskImpl("3299", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/task/3299"), 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")), new NamedResourceImpl("4012", "Server1", VCloudMediaType.VAPP_XML, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/4012") - - ) - + ), null ); assertEquals(result.getTasks(), ImmutableSortedSet.of(task1, task2)); assertEquals( diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java index 1dfe97ee3f..bcd9ed6828 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java @@ -48,7 +48,7 @@ import com.google.common.collect.ListMultimap; public class VAppHandlerTest extends BaseHandlerTest { // TODO why does this fail? @Test(enabled = false) - public void testApplyInputStream() throws UnknownHostException { + public void testHosting() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml"); 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); 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 networkToAddresses = ImmutableListMultimap + . of(); + + VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "Oracle", "vmx-07"); + + SortedSet resourceAllocations = ImmutableSortedSet + . 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); } } diff --git a/vcloud/core/src/test/resources/vapp.xml b/vcloud/core/src/test/resources/vapp.xml index 7154585cd8..b6035ba5f3 100644 --- a/vcloud/core/src/test/resources/vapp.xml +++ b/vcloud/core/src/test/resources/vapp.xml @@ -1,144 +1,149 @@ - - - - The kind of installed guest operating system - Other Linux (32-bit) - - - Virtual hardware - - - - - - - - - - - - - - Virtual Hardware Family - 0 - - - - - - SQL - vmx-07 - - - - - hertz * 10^6 - - - - - Number of Virtual CPUs - 1 virtual CPU(s) - 1 - - - - - - - - 3 - 1 - count - - - - - - byte * 2^20 - - - - - Memory Size - 16MB of memory - 2 - - - - - - - - 4 - 16 - byte * 2^20 - - - - 0 - - - - - - - SCSI Controller - SCSI Controller 0 - 3 - - - - - - - lsilogic - 6 - - - - - - 7 - true - Internal - PCNet32 ethernet adapter on "Internal" network - Network Adapter 1 - 8 - PCNet32 - 10 - - - - 0 - - - - - - - Hard Disk 1 - 104857 - 9 - - - - 3 - - - - 17 - 104857 - - - - + + + + The kind of installed guest operating system + Other Linux (32-bit) + + + Virtual hardware + + + + + + + + + + + + + + Virtual Hardware Family + 0 + + + + + + Oracle + vmx-07 + + + + + hertz * 10^6 + + + + + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + + + + + + + + 3 + 1 + count + + + + + + byte * 2^20 + + + + + Memory Size + 16MB of memory + 2 + + + + + + + + 4 + 16 + byte * 2^20 + + + + 0 + + + + + + + SCSI Controller + SCSI Controller 0 + 3 + + + + + + + lsilogic + 6 + + + + + + 7 + true + Internal + PCNet32 ethernet adapter on "Internal" network + + Network Adapter 1 + 8 + PCNet32 + 10 + + + + 0 + + + + + + + Hard Disk 1 + 104857 + 9 + + + + 3 + + + + 17 + 104857 + + + + \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java index 0011da5fcb..e3dce87a38 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java @@ -63,7 +63,7 @@ public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient { // produces is incorrect, but required for hosting.com to operate @XMLResponseParser(CatalogHandler.class) @Override - Future getCatalog(); + Future getDefaultCatalog(); @GET @Consumes(VAPP_XML) diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java index 0aec330fb6..e649db68b4 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java @@ -20,7 +20,7 @@ package org.jclouds.vcloud.hostingdotcom.domain.internal; import java.net.InetAddress; import java.net.URI; -import java.util.SortedSet; +import java.util.Set; import org.jclouds.vcloud.domain.ResourceAllocation; 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, ListMultimap networkToAddresses, String operatingSystemDescription, VirtualSystem system, - SortedSet resourceAllocations, String username, String password) { + Set resourceAllocations, String username, String password) { super(id, name, location, status, size, networkToAddresses, operatingSystemDescription, system, resourceAllocations); this.username = username; diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java index 1120fc3c05..1a15e5b183 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java @@ -59,7 +59,7 @@ import com.google.inject.TypeLiteral; public class HostingDotComVCloudAsyncClientTest extends RestClientTest { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { - Method method = HostingDotComVCloudAsyncClient.class.getMethod("getCatalog"); + Method method = HostingDotComVCloudAsyncClient.class.getMethod("getDefaultCatalog"); GeneratedHttpRequest httpMethod = processor .createRequest(method); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java index e41fe21602..39c303e3c5 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/functions/ParseTaskFromLocationHeader.java @@ -44,7 +44,7 @@ public class ParseTaskFromLocationHeader implements Function if (location != null) { String taskId = location.substring(location.lastIndexOf('/') + 1); return new TaskImpl(taskId, URI.create(location), TaskStatus.QUEUED, new Date(), null, - null, null); + null, null, null); } else { throw new HttpResponseException("no uri in headers or content", null, from); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index 4526b5df4c..46a742249f 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -130,7 +130,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { @Test public void testGetConfigCustomizationOptions() throws Exception { - Catalog response = connection.getCatalog(); + Catalog response = connection.getDefaultCatalog(); for (NamedResource resource : response.values()) { if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { CatalogItem item = connection.getCatalogItem(resource.getId()); @@ -168,7 +168,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { String vDCId = tmClient.getDefaultVDC().getId(); // 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 SortedSet sizeOptions = tmClient.getComputeOptionsOfCatalogItem(itemId);