From 1d3fa374c8976ebca9a93ef8bf9495a54f1bdb60 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sat, 14 Nov 2009 06:34:36 +0000 Subject: [PATCH] Issue 112: added initial support for hosting.com git-svn-id: http://jclouds.googlecode.com/svn/trunk@2288 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../java/org/jclouds/vcloud/VCloudClient.java | 2 + .../VCloudDiscoveryRestClientModule.java | 3 +- .../org/jclouds/vcloud/domain/Capacity.java | 84 +++++++++++ .../org/jclouds/vcloud/domain/Catalog.java | 8 +- .../jclouds/vcloud/domain/Organization.java | 8 +- .../java/org/jclouds/vcloud/domain/Quota.java | 71 ++++++++++ .../java/org/jclouds/vcloud/domain/VDC.java | 21 ++- .../vcloud/domain/internal/CatalogImpl.java | 47 ++++--- .../domain/internal/OrganizationImpl.java | 45 +++++- .../vcloud/domain/internal/VDCImpl.java | 131 ++++++++++++++++-- .../domain/internal/TerremarkVDCImpl.java | 13 +- .../terremark/xml/TerremarkVDCHandler.java | 4 +- .../jclouds/vcloud/xml/CatalogHandler.java | 28 +++- .../org/jclouds/vcloud/xml/OrgHandler.java | 25 +++- .../jclouds/vcloud/xml/TasksListHandler.java | 3 + .../org/jclouds/vcloud/xml/VDCHandler.java | 85 +++++++++++- .../jclouds/vcloud/VCloudClientLiveTest.java | 2 - .../org/jclouds/vcloud/VCloudClientTest.java | 4 +- .../vcloud/VCloudDiscoveryLiveTest.java | 1 - .../jclouds/vcloud/VCloudDiscoveryTest.java | 9 +- .../xml/TerremarkVDCHandlerTest.java | 51 +++++-- .../vcloud/xml/CatalogHandlerTest.java | 64 +++++++-- .../jclouds/vcloud/xml/OrgHandlerTest.java | 76 ++++++++-- .../vcloud/xml/TasksListHandlerTest.java | 10 ++ .../jclouds/vcloud/xml/VDCHandlerTest.java | 119 ++++++++++++++-- .../src/test/resources/catalog-hosting.xml | 25 ++++ .../core/src/test/resources/org-hosting.xml | 12 ++ vcloud/core/src/test/resources/org.xml | 25 ---- .../src/test/resources/taskslist-hosting.xml | 14 ++ .../core/src/test/resources/vdc-hosting.xml | 60 ++++++++ 30 files changed, 913 insertions(+), 137 deletions(-) create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/domain/Capacity.java create mode 100644 vcloud/core/src/main/java/org/jclouds/vcloud/domain/Quota.java create mode 100644 vcloud/core/src/test/resources/catalog-hosting.xml create mode 100644 vcloud/core/src/test/resources/org-hosting.xml create mode 100644 vcloud/core/src/test/resources/taskslist-hosting.xml create mode 100644 vcloud/core/src/test/resources/vdc-hosting.xml 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 69b99b8494..c9fb322409 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -38,6 +38,7 @@ import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.RequestFilters; @@ -67,6 +68,7 @@ public interface VCloudClient { @GET @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @Consumes(CATALOG_XML) + @Produces(CATALOG_XML)// required for hosting.com to operate @XMLResponseParser(CatalogHandler.class) Future getCatalog(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java index 4dea1b7381..48004e56fa 100755 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudDiscoveryRestClientModule.java @@ -47,6 +47,7 @@ import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.VCloud; import com.google.common.base.Supplier; +import com.google.common.collect.Iterables; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -72,7 +73,7 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule { @Org @Singleton protected URI provideOrg(Supplier cache, @Named(PROPERTY_VCLOUD_USER) String user) { - return cache.get().getOrgs().get(user).getLocation(); + return Iterables.getLast(cache.get().getOrgs().values()).getLocation(); } /** diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Capacity.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Capacity.java new file mode 100644 index 0000000000..30e44ac2e2 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Capacity.java @@ -0,0 +1,84 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + + +/** + * @author Adrian Cole + */ +public class Capacity { + + private final String units; + private final int allocated; + private final int used; + + public Capacity(String units, int allocated, int used) { + this.units = units; + this.allocated = allocated; + this.used = used; + } + + public String getUnits() { + return units; + } + + public int getAllocated() { + return allocated; + } + + public int getUsed() { + return used; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + allocated; + result = prime * result + ((units == null) ? 0 : units.hashCode()); + result = prime * result + used; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Capacity other = (Capacity) obj; + if (allocated != other.allocated) + return false; + if (units == null) { + if (other.units != null) + return false; + } else if (!units.equals(other.units)) + return false; + if (used != other.used) + return false; + return true; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java index a0d863e8f5..8758a953ef 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java @@ -23,9 +23,9 @@ */ package org.jclouds.vcloud.domain; +import java.net.URI; import java.util.Map; -import org.jclouds.rest.domain.NamedLink; import org.jclouds.vcloud.domain.internal.CatalogImpl; import com.google.inject.ImplementedBy; @@ -35,6 +35,10 @@ import com.google.inject.ImplementedBy; */ @org.jclouds.vcloud.endpoints.Catalog @ImplementedBy(CatalogImpl.class) -public interface Catalog extends NamedLink, Map { +public interface Catalog extends Map { + String getName(); + String getDescription(); + + URI getLocation(); } \ No newline at end of file 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 0df74373aa..a2d4ba38ee 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 @@ -23,6 +23,7 @@ */ package org.jclouds.vcloud.domain; +import java.net.URI; import java.util.Map; import org.jclouds.rest.domain.Link; @@ -40,7 +41,12 @@ import com.google.inject.ImplementedBy; */ @Org @ImplementedBy(OrganizationImpl.class) -public interface Organization extends NamedLink { +public interface Organization { + String getName(); + + int getId(); + + URI getLocation(); @Catalog Link getCatalog(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Quota.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Quota.java new file mode 100644 index 0000000000..bf50bca615 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Quota.java @@ -0,0 +1,71 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + +/** + * @author Adrian Cole + */ +public class Quota { + + private final int limit; + private final int used; + + public Quota(int limit, int used) { + this.limit = limit; + this.used = used; + } + + public int getLimit() { + return limit; + } + + public int getUsed() { + return used; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + limit; + result = prime * result + used; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Quota other = (Quota) obj; + if (limit != other.limit) + return false; + if (used != other.used) + return false; + return true; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java index 058536f942..01879b3eb6 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java @@ -23,6 +23,7 @@ */ package org.jclouds.vcloud.domain; +import java.net.URI; import java.util.Map; import org.jclouds.rest.domain.NamedLink; @@ -35,7 +36,25 @@ import com.google.inject.ImplementedBy; */ @org.jclouds.vcloud.endpoints.VDC @ImplementedBy(VDCImpl.class) -public interface VDC extends NamedLink { +public interface VDC { + + String getName(); + + int getId(); + + URI getLocation(); + + String getDescription(); + + Capacity getStorageCapacity(); + + Capacity getCpuCapacity(); + + Capacity getMemoryCapacity(); + + Quota getInstantiatedVmsQuota(); + + Quota getDeployedVmsQuota(); Map getAvailableNetworks(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java index 56ac3a8b56..0253868b57 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java @@ -29,11 +29,11 @@ import java.net.URI; import java.util.SortedMap; import java.util.TreeMap; -import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.NamedResource; +import com.google.inject.internal.Nullable; + /** * Locations of resources in vCloud * @@ -44,33 +44,34 @@ public class CatalogImpl extends TreeMap implements Catal /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - private final NamedLink catalog; + private final String name; + private final String description; + private final URI location; - public CatalogImpl(String name, String type, URI location, + public CatalogImpl(String name, URI location, @Nullable String description, SortedMap contents) { super(); - this.catalog = new NamedLinkImpl(checkNotNull(name, "name"), checkNotNull(type, "type"), - checkNotNull(location, "location")); + this.name = checkNotNull(name, "name"); + this.description = description; + this.location = checkNotNull(location, "location"); putAll(checkNotNull(contents, "contents")); } public URI getLocation() { - return catalog.getLocation(); + return location; } public String getName() { - return catalog.getName(); - } - - public String getType() { - return catalog.getType(); + return name; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } @@ -83,12 +84,26 @@ public class CatalogImpl extends TreeMap implements Catal if (getClass() != obj.getClass()) return false; CatalogImpl other = (CatalogImpl) obj; - if (catalog == null) { - if (other.catalog != null) + if (description == null) { + if (other.description != null) return false; - } else if (!catalog.equals(other.catalog)) + } else if (!description.equals(other.description)) + 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; return true; } + public String getDescription() { + return description; + } + } \ No newline at end of file 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 a46a8d5a7e..9a819a7455 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 @@ -27,7 +27,6 @@ import java.net.URI; import java.util.Map; import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.TasksList; @@ -39,20 +38,36 @@ import org.jclouds.vcloud.endpoints.VDC; * @author Adrian Cole * */ -public class OrganizationImpl extends NamedLinkImpl implements Organization { - +public class OrganizationImpl implements Organization { + private final int id; + private final String name; + private final URI location; private final NamedLink catalog; private final Map vdcs; private final Map tasksLists; - public OrganizationImpl(String name, String type, URI location, NamedLink catalog, + public OrganizationImpl(int id, String name, URI location, NamedLink catalog, Map vdcs, Map tasksLists) { - super(name, type, location); + this.id = id; + this.name = name; + this.location = location; this.catalog = catalog; this.vdcs = vdcs; this.tasksLists = tasksLists; } + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public URI getLocation() { + return location; + } + @Catalog public NamedLink getCatalog() { return catalog; @@ -71,8 +86,11 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization { @Override public int hashCode() { final int prime = 31; - int result = super.hashCode(); + int result = 1; result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); + result = prime * result + id; + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((tasksLists == null) ? 0 : tasksLists.hashCode()); result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode()); return result; @@ -82,7 +100,7 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization { public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) + if (obj == null) return false; if (getClass() != obj.getClass()) return false; @@ -92,6 +110,18 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization { return false; } else if (!catalog.equals(other.catalog)) return false; + if (id != 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 (tasksLists == null) { if (other.tasksLists != null) return false; @@ -105,4 +135,5 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization { return true; } + } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java index d42f6176cb..e910324517 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java @@ -29,7 +29,8 @@ import java.net.URI; import java.util.Map; import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.vcloud.domain.Capacity; +import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; /** @@ -38,17 +39,54 @@ import org.jclouds.vcloud.domain.VDC; * @author Adrian Cole * */ -public class VDCImpl extends NamedLinkImpl implements VDC { +public class VDCImpl implements VDC { + + private final int id; + private final String name; + private final URI location; + private final String description; + private final Capacity storageCapacity; + private final Capacity cpuCapacity; + private final Capacity memoryCapacity; + private final Quota instantiatedVmsQuota; + private final Quota deployedVmsQuota; private final Map availableNetworks; private final Map resourceEntities; + + public VDCImpl(int id, String name, URI location, String description, Capacity storageCapacity, + Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, + Quota deployedVmsQuota, Map resourceEntities, + Map availableNetworks) { + this.id = id; + this.name = checkNotNull(name, "name"); + ; + this.location = checkNotNull(location, "location"); + ; + this.description = description; + this.storageCapacity = storageCapacity; + this.cpuCapacity = cpuCapacity; + this.memoryCapacity = memoryCapacity; + this.instantiatedVmsQuota = instantiatedVmsQuota; + this.deployedVmsQuota = deployedVmsQuota; + this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks"); + ; + this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities"); + ; + } + /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public VDCImpl(String name, String type, URI location, Map resourceEntities, - Map availableNetworks) { - super(name, type, location); - this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks"); - this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities"); + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public URI getLocation() { + return location; } public Map getAvailableNetworks() { @@ -62,9 +100,19 @@ public class VDCImpl extends NamedLinkImpl implements VDC { @Override public int hashCode() { final int prime = 31; - int result = super.hashCode(); + int result = 1; result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode()); + result = prime * result + ((cpuCapacity == null) ? 0 : cpuCapacity.hashCode()); + result = prime * result + ((deployedVmsQuota == null) ? 0 : deployedVmsQuota.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + result = prime * result + id; + result = prime * result + + ((instantiatedVmsQuota == null) ? 0 : instantiatedVmsQuota.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((memoryCapacity == null) ? 0 : memoryCapacity.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((resourceEntities == null) ? 0 : resourceEntities.hashCode()); + result = prime * result + ((storageCapacity == null) ? 0 : storageCapacity.hashCode()); return result; } @@ -72,7 +120,7 @@ public class VDCImpl extends NamedLinkImpl implements VDC { public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) + if (obj == null) return false; if (getClass() != obj.getClass()) return false; @@ -82,12 +130,77 @@ public class VDCImpl extends NamedLinkImpl implements VDC { return false; } else if (!availableNetworks.equals(other.availableNetworks)) return false; + if (cpuCapacity == null) { + if (other.cpuCapacity != null) + return false; + } else if (!cpuCapacity.equals(other.cpuCapacity)) + return false; + if (deployedVmsQuota == null) { + if (other.deployedVmsQuota != null) + return false; + } else if (!deployedVmsQuota.equals(other.deployedVmsQuota)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + if (id != other.id) + return false; + if (instantiatedVmsQuota == null) { + if (other.instantiatedVmsQuota != null) + return false; + } else if (!instantiatedVmsQuota.equals(other.instantiatedVmsQuota)) + return false; + if (location == null) { + if (other.location != null) + return false; + } else if (!location.equals(other.location)) + return false; + if (memoryCapacity == null) { + if (other.memoryCapacity != null) + return false; + } else if (!memoryCapacity.equals(other.memoryCapacity)) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; if (resourceEntities == null) { if (other.resourceEntities != null) return false; } else if (!resourceEntities.equals(other.resourceEntities)) return false; + if (storageCapacity == null) { + if (other.storageCapacity != null) + return false; + } else if (!storageCapacity.equals(other.storageCapacity)) + return false; return true; } + public String getDescription() { + return description; + } + + public Capacity getStorageCapacity() { + return storageCapacity; + } + + public Capacity getCpuCapacity() { + return cpuCapacity; + } + + public Capacity getMemoryCapacity() { + return memoryCapacity; + } + + public Quota getInstantiatedVmsQuota() { + return instantiatedVmsQuota; + } + + public Quota getDeployedVmsQuota() { + return deployedVmsQuota; + } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java index 4d341b751b..ebad799171 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java @@ -29,6 +29,8 @@ import java.net.URI; import java.util.Map; import org.jclouds.rest.domain.NamedLink; +import org.jclouds.vcloud.domain.Capacity; +import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; @@ -47,10 +49,13 @@ public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC { /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public TerremarkVDCImpl(String name, String type, URI location, - Map availableNetworks, Map resourceEntities, NamedLink catalog, - NamedLink publicIps, NamedLink internetServices) { - super(name, type, location, availableNetworks, resourceEntities); + public TerremarkVDCImpl(int id, String name, URI location, String description, + Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, + Quota instantiatedVmsQuota, Quota deployedVmsQuota, + Map availableNetworks, Map resourceEntities, + NamedLink catalog, NamedLink publicIps, NamedLink internetServices) { + super(id, name, location, description, storageCapacity, cpuCapacity, memoryCapacity, + instantiatedVmsQuota, deployedVmsQuota, availableNetworks, resourceEntities); this.catalog = checkNotNull(catalog, "catalog"); this.publicIps = checkNotNull(publicIps, "publicIps"); this.internetServices = checkNotNull(internetServices, "internetServices"); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java index 1f9e9ee199..f00cbb35bd 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandler.java @@ -44,7 +44,9 @@ public class TerremarkVDCHandler extends VDCHandler { public TerremarkVDC getResult() { VDC vDC = super.getResult(); - return new TerremarkVDCImpl(vDC.getName(), vDC.getType(), vDC.getLocation(), vDC + return new TerremarkVDCImpl(vDC.getId(), vDC.getName(), vDC.getLocation(), vDC + .getDescription(), vDC.getStorageCapacity(), vDC.getCpuCapacity(), vDC + .getMemoryCapacity(), vDC.getInstantiatedVmsQuota(), vDC.getDeployedVmsQuota(), vDC .getResourceEntities(), vDC.getAvailableNetworks(), catalog, publicIps, internetServices); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java index fcf54b6c91..37459484a1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java @@ -46,14 +46,18 @@ import com.google.common.collect.Maps; * @author Adrian Cole */ public class CatalogHandler extends ParseSax.HandlerWithResult { + private StringBuilder currentText = new StringBuilder(); + private NamedLink Catalog; private SortedMap contents = Maps.newTreeMap(); @Inject @CatalogItemRoot private String catalogItemRoot; + private String description; + public Catalog getResult() { - return new CatalogImpl(Catalog.getName(), Catalog.getType(), Catalog.getLocation(), contents); + return new CatalogImpl(Catalog.getName(), Catalog.getLocation(), description, contents); } @Override @@ -68,15 +72,31 @@ public class CatalogHandler extends ParseSax.HandlerWithResult { } } + public void endElement(String uri, String name, String qName) { + if (qName.equals("Description")) { + description = currentOrNull(); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + public NamedResource newNamedResource(Attributes attributes) { return new NamedResourceImpl(Integer.parseInt(attributes - .getValue(attributes.getIndex("href")).replace(catalogItemRoot+"/", "")), attributes - .getValue(attributes.getIndex("name")), attributes.getValue(attributes - .getIndex("type")), URI.create(attributes.getValue(attributes.getIndex("href")))); + .getValue(attributes.getIndex("href")).replace(catalogItemRoot + "/", "")), + attributes.getValue(attributes.getIndex("name")), attributes.getValue(attributes + .getIndex("type")), URI.create(attributes.getValue(attributes + .getIndex("href")))); } public void putNamedResource(Map map, Attributes attributes) { map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes)); } + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } } 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 e406c72c82..c77294373e 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 @@ -26,18 +26,21 @@ package org.jclouds.vcloud.xml; import static org.jclouds.rest.util.Utils.newNamedLink; import static org.jclouds.rest.util.Utils.putNamedLink; import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; import java.net.URI; import java.util.Map; +import javax.inject.Inject; + import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.Organization; +import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl; +import org.jclouds.vcloud.endpoints.VCloud; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -47,13 +50,16 @@ import com.google.common.collect.Maps; * @author Adrian Cole */ public class OrgHandler extends ParseSax.HandlerWithResult { - private NamedLink org; + private NamedResource org; private Map vdcs = Maps.newHashMap(); private Map tasksLists = Maps.newHashMap(); private NamedLink catalog; + @Inject + @VCloud + URI vcloudUri; public Organization getResult() { - return new OrganizationImpl(org.getName(), org.getType(), org.getLocation(), catalog, vdcs, + return new OrganizationImpl(org.getId(), org.getName(), org.getLocation(), catalog, vdcs, tasksLists); } @@ -61,8 +67,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult { public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("Org")) { - org = new NamedLinkImpl(attributes.getValue(attributes.getIndex("name")), ORG_XML, URI - .create(attributes.getValue(attributes.getIndex("href")))); + org = newNamedResource(attributes); } else if (qName.equals("Link")) { int typeIndex = attributes.getIndex("type"); if (typeIndex != -1) { @@ -77,4 +82,12 @@ public class OrgHandler extends ParseSax.HandlerWithResult { } } + public NamedResource newNamedResource(Attributes attributes) { + return new NamedResourceImpl( + Integer.parseInt(attributes.getValue(attributes.getIndex("href")).replace( + vcloudUri.toASCIIString() + "/org/", "")), attributes.getValue(attributes + .getIndex("name")), attributes.getValue(attributes.getIndex("type")), URI + .create(attributes.getValue(attributes.getIndex("href")))); + } + } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java index 3a3cad7cc6..f8f6333c43 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/TasksListHandler.java @@ -61,6 +61,9 @@ public class TasksListHandler extends ParseSax.HandlerWithResult { throws SAXException { if (qName.equals("TasksList")) { location = Utils.newLink(attributes).getLocation(); + } else if (qName.equals("Link") && attributes.getIndex("rel") != -1 + && attributes.getValue(attributes.getIndex("rel")).equals("self")) { + location = Utils.newLink(attributes).getLocation(); } else { taskHandler.startElement(uri, localName, qName, attributes); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java index c6ae2fd65e..3b53f75e2b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java @@ -28,11 +28,17 @@ import static org.jclouds.rest.util.Utils.putNamedLink; import java.net.URI; import java.util.Map; +import javax.inject.Inject; + import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.vcloud.domain.Capacity; +import org.jclouds.vcloud.domain.NamedResource; +import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.VDCImpl; +import org.jclouds.vcloud.endpoints.VCloud; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -42,22 +48,46 @@ import com.google.common.collect.Maps; * @author Adrian Cole */ public class VDCHandler extends ParseSax.HandlerWithResult { - private NamedLink vDC; + private StringBuilder currentText = new StringBuilder(); + + private NamedResource vDC; private Map resourceEntities = Maps.newHashMap(); private Map availableNetworks = Maps.newHashMap(); + @Inject + @VCloud + URI vcloudUri; + + private String description; + + private Quota instantiatedVmsQuota; + + private Capacity memoryCapacity; + + private Capacity cpuCapacity; + + private Capacity storageCapacity; + + private Quota deployedVmsQuota; + + private String units; + + private int allocated; + + private int used; + + private int limit; public VDC getResult() { - return new VDCImpl(vDC.getName(), vDC.getType(), vDC.getLocation(), resourceEntities, - availableNetworks); + return new VDCImpl(vDC.getId(), vDC.getName(), vDC.getLocation(), description, + storageCapacity, cpuCapacity, memoryCapacity, instantiatedVmsQuota, + deployedVmsQuota, resourceEntities, availableNetworks); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if (qName.equals("Vdc")) { - vDC = new NamedLinkImpl(attributes.getValue(attributes.getIndex("name")), attributes - .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes - .getIndex("href")))); + vDC = newNamedResource(attributes); } else if (qName.equals("Network")) { putNamedLink(availableNetworks, attributes); } else if (qName.equals("ResourceEntity")) { @@ -65,4 +95,45 @@ public class VDCHandler extends ParseSax.HandlerWithResult { } } + public void endElement(String uri, String name, String qName) { + if (qName.equals("Description")) { + description = currentOrNull(); + } else if (qName.equals("Units")) { + units = currentOrNull(); + } else if (qName.equals("Allocated")) { + allocated = Integer.parseInt(currentOrNull()); + } else if (qName.equals("Used")) { + used = Integer.parseInt(currentOrNull()); + } else if (qName.equals("Limit")) { + limit = Integer.parseInt(currentOrNull()); + } else if (qName.equals("StorageCapacity")) { + storageCapacity = new Capacity(units, allocated, used); + } else if (qName.equals("Cpu")) { + cpuCapacity = new Capacity(units, allocated, used); + } else if (qName.equals("Memory")) { + memoryCapacity = new Capacity(units, allocated, used); + } else if (qName.equals("InstantiatedVmsQuota")) { + instantiatedVmsQuota = new Quota(limit, used); + } else if (qName.equals("DeployedVmsQuota")) { + deployedVmsQuota = new Quota(limit, used); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + + public NamedResource newNamedResource(Attributes attributes) { + return new NamedResourceImpl(Integer.parseInt(attributes + .getValue(attributes.getIndex("href")).replace(vcloudUri.toASCIIString() + "/vdc/", + "")), attributes.getValue(attributes.getIndex("name")), attributes + .getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes + .getIndex("href")))); + } + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } } 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 4637844cd7..751bb107cf 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -54,7 +54,6 @@ public class VCloudClientLiveTest { assertNotNull(response); assertNotNull(response.getName()); assertNotNull(response.getLocation()); - assertEquals(response.getType(), "application/vnd.vmware.vcloud.catalog+xml"); assert response.size() > 0; } @@ -64,7 +63,6 @@ public class VCloudClientLiveTest { assertNotNull(response); assertNotNull(response.getName()); assertNotNull(response.getLocation()); - assertEquals(response.getType(), "application/vnd.vmware.vcloud.vdc+xml"); assertNotNull(response.getResourceEntities()); assertNotNull(response.getAvailableNetworks()); } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java index 351a748f53..aebfa76e12 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java @@ -68,7 +68,9 @@ public class VCloudClientTest extends RestClientTest { GeneratedHttpRequest httpMethod = processor.createRequest(method); assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); - assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertHeadersEqual( + httpMethod, + "Accept: application/vnd.vmware.vcloud.catalog+xml\nContent-Type: application/vnd.vmware.vcloud.catalog+xml\n"); assertEntityEquals(httpMethod, null); assertResponseParserClassEquals(method, httpMethod, ParseSax.class); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java index bb9cc07a97..7978c41570 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryLiveTest.java @@ -92,7 +92,6 @@ public class VCloudDiscoveryLiveTest { Organization response = context.getApi().getOrganization(); assertNotNull(response); assertEquals(response.getName(), account); - assertEquals(response.getType(), VCloudMediaType.ORG_XML); assertNotNull(response.getCatalog()); assertEquals(response.getTasksLists().size(), 1); assertEquals(response.getVDCs().size(), 1); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java index 556ab6d0d3..d47f707129 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudDiscoveryTest.java @@ -38,12 +38,14 @@ import org.jclouds.rest.RestClientTest; import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.xml.OrgHandler; import org.testng.annotations.Test; import com.google.inject.AbstractModule; import com.google.inject.Module; +import com.google.inject.Provides; import com.google.inject.TypeLiteral; /** @@ -102,7 +104,12 @@ public class VCloudDiscoveryTest extends RestClientTest { } }); } - + @SuppressWarnings("unused") + @Provides + @VCloud + URI provide() { + return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); + } }; } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java index 072c1c5209..a9477c0836 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVDCHandlerTest.java @@ -29,14 +29,20 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Provides; /** * Tests behavior of {@code TerremarkVDCHandler} @@ -44,29 +50,44 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.TerremarkVDCHandlerTest") -public class TerremarkVDCHandlerTest extends BaseHandlerTest { - - @BeforeTest - @Override - protected void setUpInjector() { - super.setUpInjector(); - } +public class TerremarkVDCHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/terremark/vdc.xml"); + Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @VCloud + URI provide() { + return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); + } + + }); + Factory factory = injector.getInstance(ParseSax.Factory.class); TerremarkVDC result = (TerremarkVDC) factory.create( injector.getInstance(TerremarkVDCHandler.class)).parse(is); assertEquals(result.getName(), "Miami Environment 1"); assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")); - assertEquals(result.getType(), "application/vnd.vmware.vcloud.vdc+xml"); assertEquals(result.getResourceEntities(), ImmutableMap. of()); - assertEquals(result.getAvailableNetworks(), ImmutableMap.of("10.114.34.128/26", new NamedLinkImpl( - "10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml", - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708")))); - assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1", CATALOG_XML, - URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))); + assertEquals( + result.getAvailableNetworks(), + ImmutableMap + .of( + "10.114.34.128/26", + new NamedLinkImpl( + "10.114.34.128/26", + "application/vnd.vmware.vcloud.network+xml", + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708")))); + assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1", CATALOG_XML, URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))); assertEquals(result.getPublicIps(), new NamedLinkImpl("Public IPs", "application/xml", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps"))); assertEquals( diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java index 380b845b4c..171b6aefda 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java @@ -29,17 +29,17 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; -import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import com.google.inject.AbstractModule; import com.google.inject.Guice; +import com.google.inject.Injector; import com.google.inject.Provides; /** @@ -48,11 +48,14 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.CatalogHandlerTest") -public class CatalogHandlerTest extends BaseHandlerTest { +public class CatalogHandlerTest { - @BeforeTest - @Override - protected void setUpInjector() { + private Injector injector; + + private Factory factory; + + public void testApplyInputStream() { + InputStream is = getClass().getResourceAsStream("/catalog.xml"); injector = Guice.createInjector(new ParserModule(), new AbstractModule() { @Override @@ -68,17 +71,13 @@ public class CatalogHandlerTest extends BaseHandlerTest { }); factory = injector.getInstance(ParseSax.Factory.class); - } - - public void testApplyInputStream() { - InputStream is = getClass().getResourceAsStream("/catalog.xml"); - Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( is); assertEquals(result.getName(), "Miami Environment 1"); + assert result.getDescription() == null; + assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); - assertEquals(result.getType(), "application/vnd.vmware.vcloud.catalog+xml"); assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5, "CentOS 5.3 (32-bit)", CATALOGITEM_XML, @@ -161,4 +160,45 @@ public class CatalogHandlerTest extends BaseHandlerTest { URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/catalogItem/22"))); } + + public void testHosting() { + InputStream is = getClass().getResourceAsStream("/catalog-hosting.xml"); + injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @CatalogItemRoot + String provide() { + return "https://vcloud.safesecureweb.com/api/v0.8/catalogItem"; + } + + }); + factory = injector.getInstance(ParseSax.Factory.class); + Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse( + is); + assertEquals(result.getName(), "HMSCatalog"); + assertEquals(result.getDescription(), "HMS Shared Catalog"); + assertEquals(result.getLocation(), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalog/1")); + + assertEquals(result.get("Plesk (Linux) 64-bit Template"), new NamedResourceImpl(1, + "Plesk (Linux) 64-bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1"))); + + assertEquals(result.get("Windows 2008 Datacenter 64 Bit Template"), new NamedResourceImpl(2, + "Windows 2008 Datacenter 64 Bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"))); + + assertEquals(result.get("Cent OS 64 Bit Template"), new NamedResourceImpl(3, + "Cent OS 64 Bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3"))); + + assertEquals(result.get("cPanel (Linux) 64 Bit Template"), new NamedResourceImpl(4, + "cPanel (Linux) 64 Bit Template", CATALOGITEM_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"))); + } } 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 1794028c81..a044a437b5 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 @@ -24,21 +24,28 @@ package org.jclouds.vcloud.xml; import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML; -import static org.jclouds.vcloud.VCloudMediaType.ORG_XML; import static org.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML; import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import org.jclouds.http.functions.BaseHandlerTest; +import javax.inject.Singleton; + +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.domain.Organization; -import org.testng.annotations.BeforeTest; +import org.jclouds.vcloud.endpoints.VCloud; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Provides; /** * Tests behavior of {@code OrgHandler} @@ -46,24 +53,37 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.OrgHandlerTest") -public class OrgHandlerTest extends BaseHandlerTest { +public class OrgHandlerTest { - @BeforeTest - @Override - protected void setUpInjector() { - super.setUpInjector(); - } public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/org.xml"); + + Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule(){ + @Override + protected void configure() { + + } + @SuppressWarnings("unused") + @Provides + @Singleton + @VCloud + URI provide(){ + return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); + } + + }); + Factory factory = injector.getInstance(ParseSax.Factory.class); + Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) .parse(is); assertEquals(result.getName(), "adrian@jclouds.org"); + assertEquals(result.getId(), 48); assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); - assertEquals(result.getType(), ORG_XML); - assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog", CATALOG_XML, + assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog", + CATALOG_XML, URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))); assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedLinkImpl( "Miami Environment 1", VCloudMediaType.VDC_XML, URI @@ -79,4 +99,38 @@ public class OrgHandlerTest extends BaseHandlerTest { URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")))); } + + public void testHosting() { + InputStream is = getClass().getResourceAsStream("/org-hosting.xml"); + Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule(){ + + @Override + protected void configure() { + + } + @SuppressWarnings("unused") + @Provides + @Singleton + @VCloud + URI provide(){ + return URI.create("https://vcloud.safesecureweb.com/api/v0.8"); + } + + }); + Factory factory = injector.getInstance(ParseSax.Factory.class); + Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class)) + .parse(is); + assertEquals(result.getName(), "Customer 188849"); + assertEquals(result.getId(), 188849); + assertEquals(result.getLocation(), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/org/188849")); + assertEquals(result.getCatalog(), new NamedLinkImpl("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 NamedLinkImpl("188849 Virtual DataCenter", VCloudMediaType.VDC_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")))); + assertEquals(result.getTasksLists(), ImmutableMap.of("188849 Task List", new NamedLinkImpl( + "188849 Task List", TASKSLIST_XML, URI + .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849")))); + } } 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 17f8967452..c347a33d0b 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 @@ -100,4 +100,14 @@ public class TasksListHandlerTest extends BaseHandlerTest { .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1"), task2, URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1"), task1)); } + + public void testApplyInputStreamHosting() { + InputStream is = getClass().getResourceAsStream("/taskslist-hosting.xml"); + + TasksList result = factory.create(injector.getInstance(TasksListHandler.class)).parse(is); + assertEquals(result.getLocation(), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849")); + + } + } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java index e92e2c87cf..c84fa999ce 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java @@ -28,14 +28,22 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import java.net.URI; -import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ParseSax.Factory; +import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.vcloud.domain.Capacity; +import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; -import org.testng.annotations.BeforeTest; +import org.jclouds.vcloud.endpoints.VCloud; import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Provides; /** * Tests behavior of {@code VDCHandler} @@ -43,22 +51,35 @@ import com.google.common.collect.ImmutableMap; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.VDCHandlerTest") -public class VDCHandlerTest extends BaseHandlerTest { - - @BeforeTest - @Override - protected void setUpInjector() { - super.setUpInjector(); - } +public class VDCHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/vdc.xml"); + Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @VCloud + URI provide() { + return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8"); + } + + }); + Factory factory = injector.getInstance(ParseSax.Factory.class); VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); assertEquals(result.getName(), "Miami Environment 1"); assertEquals(result.getLocation(), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")); - assertEquals(result.getType(), "application/vnd.vmware.vcloud.vdc+xml"); + assertEquals(result.getDescription(), null); + assertEquals(result.getStorageCapacity(), null); + assertEquals(result.getCpuCapacity(), null); + assertEquals(result.getMemoryCapacity(), null); + assertEquals(result.getInstantiatedVmsQuota(), null); + assertEquals(result.getDeployedVmsQuota(), null); assertEquals(result.getResourceEntities(), ImmutableMap. of()); assertEquals( result.getAvailableNetworks(), @@ -71,4 +92,82 @@ public class VDCHandlerTest extends BaseHandlerTest { URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708")))); } + + public void testApplyHosting() { + InputStream is = getClass().getResourceAsStream("/vdc-hosting.xml"); + Injector injector = Guice.createInjector(new ParserModule(), new AbstractModule() { + + @Override + protected void configure() { + } + + @SuppressWarnings("unused") + @Provides + @VCloud + URI provide() { + return URI.create("https://vcloud.safesecureweb.com/api/v0.8"); + } + + }); + Factory factory = injector.getInstance(ParseSax.Factory.class); + VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is); + assertEquals(result.getName(), "vDC Name"); + assertEquals(result.getLocation(), URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vdc/188849")); + assertEquals(result.getDescription(), "vDC Name"); + assertEquals(result.getStorageCapacity(), new Capacity("bytes * 10^9", 0, 40960)); + assertEquals(result.getCpuCapacity(), new Capacity("hz * 10^6", 0, 2400)); + assertEquals(result.getMemoryCapacity(), new Capacity("bytes * 10^9", 0, 2)); + assertEquals(result.getInstantiatedVmsQuota(), new Quota(0, 2)); + assertEquals(result.getDeployedVmsQuota(), new Quota(0, 2)); + assertEquals( + result.getResourceEntities(), + new ImmutableMap.Builder() + .put( + "Plesk (Linux) 64-bit Template", + new NamedLinkImpl( + "Plesk (Linux) 64-bit Template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/1"))) + .put( + + "Windows 2008 Datacenter 64 Bit Template", + new NamedLinkImpl( + "Windows 2008 Datacenter 64 Bit Template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2"))) + .put( + "Cent OS 64 Bit Template", + new NamedLinkImpl( + "Cent OS 64 Bit Template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"))) + .put( + "cPanel (Linux) 64 Bit Template", + new NamedLinkImpl( + "cPanel (Linux) 64 Bit Template", + "application/vnd.vmware.vcloud.vAppTemplate+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4"))) + .put( + "188849-1", + new NamedLinkImpl( + "188849-1", + "application/vnd.vmware.vcloud.vApp+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1"))) + .put( + "188849-2", + new NamedLinkImpl( + "188849-2", + "application/vnd.vmware.vcloud.vApp+xml", + URI + .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-2"))) + .build()); + + assertEquals(result.getAvailableNetworks(), ImmutableMap. of()); + } } diff --git a/vcloud/core/src/test/resources/catalog-hosting.xml b/vcloud/core/src/test/resources/catalog-hosting.xml new file mode 100644 index 0000000000..be510a9aa2 --- /dev/null +++ b/vcloud/core/src/test/resources/catalog-hosting.xml @@ -0,0 +1,25 @@ + + + HMS Shared Catalog + + + + + + + + + + diff --git a/vcloud/core/src/test/resources/org-hosting.xml b/vcloud/core/src/test/resources/org-hosting.xml new file mode 100644 index 0000000000..3bd9842058 --- /dev/null +++ b/vcloud/core/src/test/resources/org-hosting.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/org.xml b/vcloud/core/src/test/resources/org.xml index 42a71edc62..1728721aa0 100644 --- a/vcloud/core/src/test/resources/org.xml +++ b/vcloud/core/src/test/resources/org.xml @@ -1,28 +1,3 @@ - diff --git a/vcloud/core/src/test/resources/taskslist-hosting.xml b/vcloud/core/src/test/resources/taskslist-hosting.xml new file mode 100644 index 0000000000..1511d134f4 --- /dev/null +++ b/vcloud/core/src/test/resources/taskslist-hosting.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/vdc-hosting.xml b/vcloud/core/src/test/resources/vdc-hosting.xml new file mode 100644 index 0000000000..6254112cf8 --- /dev/null +++ b/vcloud/core/src/test/resources/vdc-hosting.xml @@ -0,0 +1,60 @@ + + + + + + vDC Name + + bytes * 10^9 + 0 + 40960 + + + + hz * 10^6 + 0 + 2400 + + + bytes * 10^9 + 0 + 2 + + + 0 + 2 + + + 0 + 2 + + + + + + + + + + +