Issue 112: added initial support for hosting.com

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2288 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-11-14 06:34:36 +00:00
parent 3aa7e73351
commit 1d3fa374c8
30 changed files with 913 additions and 137 deletions

View File

@ -38,6 +38,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
@ -67,6 +68,7 @@ public interface VCloudClient {
@GET @GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML) @Consumes(CATALOG_XML)
@Produces(CATALOG_XML)// required for hosting.com to operate
@XMLResponseParser(CatalogHandler.class) @XMLResponseParser(CatalogHandler.class)
Future<? extends Catalog> getCatalog(); Future<? extends Catalog> getCatalog();

View File

@ -47,6 +47,7 @@ import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VCloud; import org.jclouds.vcloud.endpoints.VCloud;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -72,7 +73,7 @@ public class VCloudDiscoveryRestClientModule extends AbstractModule {
@Org @Org
@Singleton @Singleton
protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) { protected URI provideOrg(Supplier<VCloudSession> cache, @Named(PROPERTY_VCLOUD_USER) String user) {
return cache.get().getOrgs().get(user).getLocation(); return Iterables.getLast(cache.get().getOrgs().values()).getLocation();
} }
/** /**

View File

@ -0,0 +1,84 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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;
}
}

View File

@ -23,9 +23,9 @@
*/ */
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain;
import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink;
import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogImpl;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
@ -35,6 +35,10 @@ import com.google.inject.ImplementedBy;
*/ */
@org.jclouds.vcloud.endpoints.Catalog @org.jclouds.vcloud.endpoints.Catalog
@ImplementedBy(CatalogImpl.class) @ImplementedBy(CatalogImpl.class)
public interface Catalog extends NamedLink, Map<String, NamedResource> { public interface Catalog extends Map<String, NamedResource> {
String getName();
String getDescription();
URI getLocation();
} }

View File

@ -23,6 +23,7 @@
*/ */
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain;
import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.Link; import org.jclouds.rest.domain.Link;
@ -40,7 +41,12 @@ import com.google.inject.ImplementedBy;
*/ */
@Org @Org
@ImplementedBy(OrganizationImpl.class) @ImplementedBy(OrganizationImpl.class)
public interface Organization extends NamedLink { public interface Organization {
String getName();
int getId();
URI getLocation();
@Catalog @Catalog
Link getCatalog(); Link getCatalog();

View File

@ -0,0 +1,71 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* 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;
}
}

View File

@ -23,6 +23,7 @@
*/ */
package org.jclouds.vcloud.domain; package org.jclouds.vcloud.domain;
import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedLink;
@ -35,7 +36,25 @@ import com.google.inject.ImplementedBy;
*/ */
@org.jclouds.vcloud.endpoints.VDC @org.jclouds.vcloud.endpoints.VDC
@ImplementedBy(VDCImpl.class) @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<String, NamedLink> getAvailableNetworks(); Map<String, NamedLink> getAvailableNetworks();

View File

@ -29,11 +29,11 @@ import java.net.URI;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; 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.Catalog;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.NamedResource;
import com.google.inject.internal.Nullable;
/** /**
* Locations of resources in vCloud * Locations of resources in vCloud
* *
@ -44,33 +44,34 @@ public class CatalogImpl extends TreeMap<String, NamedResource> implements Catal
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; 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<String, NamedResource> contents) { SortedMap<String, NamedResource> contents) {
super(); super();
this.catalog = new NamedLinkImpl(checkNotNull(name, "name"), checkNotNull(type, "type"), this.name = checkNotNull(name, "name");
checkNotNull(location, "location")); this.description = description;
this.location = checkNotNull(location, "location");
putAll(checkNotNull(contents, "contents")); putAll(checkNotNull(contents, "contents"));
} }
public URI getLocation() { public URI getLocation() {
return catalog.getLocation(); return location;
} }
public String getName() { public String getName() {
return catalog.getName(); return name;
}
public String getType() {
return catalog.getType();
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); 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; return result;
} }
@ -83,12 +84,26 @@ public class CatalogImpl extends TreeMap<String, NamedResource> implements Catal
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
CatalogImpl other = (CatalogImpl) obj; CatalogImpl other = (CatalogImpl) obj;
if (catalog == null) { if (description == null) {
if (other.catalog != null) if (other.description != null)
return false; 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 false;
return true; return true;
} }
public String getDescription() {
return description;
}
} }

View File

@ -27,7 +27,6 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedLink;
import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Organization;
import org.jclouds.vcloud.endpoints.Catalog; import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.TasksList; import org.jclouds.vcloud.endpoints.TasksList;
@ -39,20 +38,36 @@ import org.jclouds.vcloud.endpoints.VDC;
* @author Adrian Cole * @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 NamedLink catalog;
private final Map<String, NamedLink> vdcs; private final Map<String, NamedLink> vdcs;
private final Map<String, NamedLink> tasksLists; private final Map<String, NamedLink> tasksLists;
public OrganizationImpl(String name, String type, URI location, NamedLink catalog, public OrganizationImpl(int id, String name, URI location, NamedLink catalog,
Map<String, NamedLink> vdcs, Map<String, NamedLink> tasksLists) { Map<String, NamedLink> vdcs, Map<String, NamedLink> tasksLists) {
super(name, type, location); this.id = id;
this.name = name;
this.location = location;
this.catalog = catalog; this.catalog = catalog;
this.vdcs = vdcs; this.vdcs = vdcs;
this.tasksLists = tasksLists; this.tasksLists = tasksLists;
} }
public int getId() {
return id;
}
public String getName() {
return name;
}
public URI getLocation() {
return location;
}
@Catalog @Catalog
public NamedLink getCatalog() { public NamedLink getCatalog() {
return catalog; return catalog;
@ -71,8 +86,11 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = 1;
result = prime * result + ((catalog == null) ? 0 : catalog.hashCode()); 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 + ((tasksLists == null) ? 0 : tasksLists.hashCode());
result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode()); result = prime * result + ((vdcs == null) ? 0 : vdcs.hashCode());
return result; return result;
@ -82,7 +100,7 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (!super.equals(obj)) if (obj == null)
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
@ -92,6 +110,18 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization {
return false; return false;
} else if (!catalog.equals(other.catalog)) } else if (!catalog.equals(other.catalog))
return false; 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 (tasksLists == null) {
if (other.tasksLists != null) if (other.tasksLists != null)
return false; return false;
@ -105,4 +135,5 @@ public class OrganizationImpl extends NamedLinkImpl implements Organization {
return true; return true;
} }
} }

View File

@ -29,7 +29,8 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink; 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.jclouds.vcloud.domain.VDC;
/** /**
@ -38,17 +39,54 @@ import org.jclouds.vcloud.domain.VDC;
* @author Adrian Cole * @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<String, NamedLink> availableNetworks; private final Map<String, NamedLink> availableNetworks;
private final Map<String, NamedLink> resourceEntities; private final Map<String, NamedLink> resourceEntities;
public VDCImpl(int id, String name, URI location, String description, Capacity storageCapacity,
Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota,
Quota deployedVmsQuota, Map<String, NamedLink> resourceEntities,
Map<String, NamedLink> 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 */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public VDCImpl(String name, String type, URI location, Map<String, NamedLink> resourceEntities, public int getId() {
Map<String, NamedLink> availableNetworks) { return id;
super(name, type, location); }
this.availableNetworks = checkNotNull(availableNetworks, "availableNetworks");
this.resourceEntities = checkNotNull(resourceEntities, "resourceEntities"); public String getName() {
return name;
}
public URI getLocation() {
return location;
} }
public Map<String, NamedLink> getAvailableNetworks() { public Map<String, NamedLink> getAvailableNetworks() {
@ -62,9 +100,19 @@ public class VDCImpl extends NamedLinkImpl implements VDC {
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = 1;
result = prime * result + ((availableNetworks == null) ? 0 : availableNetworks.hashCode()); 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 + ((resourceEntities == null) ? 0 : resourceEntities.hashCode());
result = prime * result + ((storageCapacity == null) ? 0 : storageCapacity.hashCode());
return result; return result;
} }
@ -72,7 +120,7 @@ public class VDCImpl extends NamedLinkImpl implements VDC {
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)
return true; return true;
if (!super.equals(obj)) if (obj == null)
return false; return false;
if (getClass() != obj.getClass()) if (getClass() != obj.getClass())
return false; return false;
@ -82,12 +130,77 @@ public class VDCImpl extends NamedLinkImpl implements VDC {
return false; return false;
} else if (!availableNetworks.equals(other.availableNetworks)) } else if (!availableNetworks.equals(other.availableNetworks))
return false; 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 (resourceEntities == null) {
if (other.resourceEntities != null) if (other.resourceEntities != null)
return false; return false;
} else if (!resourceEntities.equals(other.resourceEntities)) } else if (!resourceEntities.equals(other.resourceEntities))
return false; return false;
if (storageCapacity == null) {
if (other.storageCapacity != null)
return false;
} else if (!storageCapacity.equals(other.storageCapacity))
return false;
return true; 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;
}
} }

View File

@ -29,6 +29,8 @@ import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink; 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.domain.internal.VDCImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
@ -47,10 +49,13 @@ public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public TerremarkVDCImpl(String name, String type, URI location, public TerremarkVDCImpl(int id, String name, URI location, String description,
Map<String, NamedLink> availableNetworks, Map<String, NamedLink> resourceEntities, NamedLink catalog, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity,
NamedLink publicIps, NamedLink internetServices) { Quota instantiatedVmsQuota, Quota deployedVmsQuota,
super(name, type, location, availableNetworks, resourceEntities); Map<String, NamedLink> availableNetworks, Map<String, NamedLink> 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.catalog = checkNotNull(catalog, "catalog");
this.publicIps = checkNotNull(publicIps, "publicIps"); this.publicIps = checkNotNull(publicIps, "publicIps");
this.internetServices = checkNotNull(internetServices, "internetServices"); this.internetServices = checkNotNull(internetServices, "internetServices");

View File

@ -44,7 +44,9 @@ public class TerremarkVDCHandler extends VDCHandler {
public TerremarkVDC getResult() { public TerremarkVDC getResult() {
VDC vDC = super.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, .getResourceEntities(), vDC.getAvailableNetworks(), catalog, publicIps,
internetServices); internetServices);
} }

View File

@ -46,14 +46,18 @@ import com.google.common.collect.Maps;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> { public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
private StringBuilder currentText = new StringBuilder();
private NamedLink Catalog; private NamedLink Catalog;
private SortedMap<String, NamedResource> contents = Maps.newTreeMap(); private SortedMap<String, NamedResource> contents = Maps.newTreeMap();
@Inject @Inject
@CatalogItemRoot @CatalogItemRoot
private String catalogItemRoot; private String catalogItemRoot;
private String description;
public Catalog getResult() { public Catalog getResult() {
return new CatalogImpl(Catalog.getName(), Catalog.getType(), Catalog.getLocation(), contents); return new CatalogImpl(Catalog.getName(), Catalog.getLocation(), description, contents);
} }
@Override @Override
@ -68,15 +72,31 @@ public class CatalogHandler extends ParseSax.HandlerWithResult<Catalog> {
} }
} }
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) { public NamedResource newNamedResource(Attributes attributes) {
return new NamedResourceImpl(Integer.parseInt(attributes return new NamedResourceImpl(Integer.parseInt(attributes
.getValue(attributes.getIndex("href")).replace(catalogItemRoot+"/", "")), attributes .getValue(attributes.getIndex("href")).replace(catalogItemRoot + "/", "")),
.getValue(attributes.getIndex("name")), attributes.getValue(attributes attributes.getValue(attributes.getIndex("name")), attributes.getValue(attributes
.getIndex("type")), URI.create(attributes.getValue(attributes.getIndex("href")))); .getIndex("type")), URI.create(attributes.getValue(attributes
.getIndex("href"))));
} }
public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) { public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) {
map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes)); map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes));
} }
protected String currentOrNull() {
String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal;
}
} }

View File

@ -26,18 +26,21 @@ package org.jclouds.vcloud.xml;
import static org.jclouds.rest.util.Utils.newNamedLink; import static org.jclouds.rest.util.Utils.newNamedLink;
import static org.jclouds.rest.util.Utils.putNamedLink; import static org.jclouds.rest.util.Utils.putNamedLink;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_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.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.domain.NamedLink; 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.Organization;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.OrganizationImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl;
import org.jclouds.vcloud.endpoints.VCloud;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -47,13 +50,16 @@ import com.google.common.collect.Maps;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class OrgHandler extends ParseSax.HandlerWithResult<Organization> { public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
private NamedLink org; private NamedResource org;
private Map<String, NamedLink> vdcs = Maps.newHashMap(); private Map<String, NamedLink> vdcs = Maps.newHashMap();
private Map<String, NamedLink> tasksLists = Maps.newHashMap(); private Map<String, NamedLink> tasksLists = Maps.newHashMap();
private NamedLink catalog; private NamedLink catalog;
@Inject
@VCloud
URI vcloudUri;
public Organization getResult() { 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); tasksLists);
} }
@ -61,8 +67,7 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
public void startElement(String uri, String localName, String qName, Attributes attributes) public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException { throws SAXException {
if (qName.equals("Org")) { if (qName.equals("Org")) {
org = new NamedLinkImpl(attributes.getValue(attributes.getIndex("name")), ORG_XML, URI org = newNamedResource(attributes);
.create(attributes.getValue(attributes.getIndex("href"))));
} else if (qName.equals("Link")) { } else if (qName.equals("Link")) {
int typeIndex = attributes.getIndex("type"); int typeIndex = attributes.getIndex("type");
if (typeIndex != -1) { if (typeIndex != -1) {
@ -77,4 +82,12 @@ public class OrgHandler extends ParseSax.HandlerWithResult<Organization> {
} }
} }
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"))));
}
} }

View File

@ -61,6 +61,9 @@ public class TasksListHandler extends ParseSax.HandlerWithResult<TasksList> {
throws SAXException { throws SAXException {
if (qName.equals("TasksList")) { if (qName.equals("TasksList")) {
location = Utils.newLink(attributes).getLocation(); 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 { } else {
taskHandler.startElement(uri, localName, qName, attributes); taskHandler.startElement(uri, localName, qName, attributes);
} }

View File

@ -28,11 +28,17 @@ import static org.jclouds.rest.util.Utils.putNamedLink;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.rest.domain.NamedLink; 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.VDC;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.internal.VDCImpl;
import org.jclouds.vcloud.endpoints.VCloud;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -42,22 +48,46 @@ import com.google.common.collect.Maps;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VDCHandler extends ParseSax.HandlerWithResult<VDC> { public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
private NamedLink vDC; private StringBuilder currentText = new StringBuilder();
private NamedResource vDC;
private Map<String, NamedLink> resourceEntities = Maps.newHashMap(); private Map<String, NamedLink> resourceEntities = Maps.newHashMap();
private Map<String, NamedLink> availableNetworks = Maps.newHashMap(); private Map<String, NamedLink> 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() { public VDC getResult() {
return new VDCImpl(vDC.getName(), vDC.getType(), vDC.getLocation(), resourceEntities, return new VDCImpl(vDC.getId(), vDC.getName(), vDC.getLocation(), description,
availableNetworks); storageCapacity, cpuCapacity, memoryCapacity, instantiatedVmsQuota,
deployedVmsQuota, resourceEntities, availableNetworks);
} }
@Override @Override
public void startElement(String uri, String localName, String qName, Attributes attributes) public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException { throws SAXException {
if (qName.equals("Vdc")) { if (qName.equals("Vdc")) {
vDC = new NamedLinkImpl(attributes.getValue(attributes.getIndex("name")), attributes vDC = newNamedResource(attributes);
.getValue(attributes.getIndex("type")), URI.create(attributes.getValue(attributes
.getIndex("href"))));
} else if (qName.equals("Network")) { } else if (qName.equals("Network")) {
putNamedLink(availableNetworks, attributes); putNamedLink(availableNetworks, attributes);
} else if (qName.equals("ResourceEntity")) { } else if (qName.equals("ResourceEntity")) {
@ -65,4 +95,45 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
} }
} }
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;
}
} }

View File

@ -54,7 +54,6 @@ public class VCloudClientLiveTest {
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());
assertNotNull(response.getLocation()); assertNotNull(response.getLocation());
assertEquals(response.getType(), "application/vnd.vmware.vcloud.catalog+xml");
assert response.size() > 0; assert response.size() > 0;
} }
@ -64,7 +63,6 @@ public class VCloudClientLiveTest {
assertNotNull(response); assertNotNull(response);
assertNotNull(response.getName()); assertNotNull(response.getName());
assertNotNull(response.getLocation()); assertNotNull(response.getLocation());
assertEquals(response.getType(), "application/vnd.vmware.vcloud.vdc+xml");
assertNotNull(response.getResourceEntities()); assertNotNull(response.getResourceEntities());
assertNotNull(response.getAvailableNetworks()); assertNotNull(response.getAvailableNetworks());
} }

View File

@ -68,7 +68,9 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method); GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); 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); assertEntityEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);

View File

@ -92,7 +92,6 @@ public class VCloudDiscoveryLiveTest {
Organization response = context.getApi().getOrganization(); Organization response = context.getApi().getOrganization();
assertNotNull(response); assertNotNull(response);
assertEquals(response.getName(), account); assertEquals(response.getName(), account);
assertEquals(response.getType(), VCloudMediaType.ORG_XML);
assertNotNull(response.getCatalog()); assertNotNull(response.getCatalog());
assertEquals(response.getTasksLists().size(), 1); assertEquals(response.getTasksLists().size(), 1);
assertEquals(response.getVDCs().size(), 1); assertEquals(response.getVDCs().size(), 1);

View File

@ -38,12 +38,14 @@ import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest; import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.endpoints.Org;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.OrgHandler; import org.jclouds.vcloud.xml.OrgHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
@ -102,7 +104,12 @@ public class VCloudDiscoveryTest extends RestClientTest<VCloudDiscovery> {
} }
}); });
} }
@SuppressWarnings("unused")
@Provides
@VCloud
URI provide() {
return URI.create("https://services.vcloudexpress.terremark.com/api/v0.8");
}
}; };
} }

View File

@ -29,14 +29,20 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; 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.NamedLink;
import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.endpoints.VCloud;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; 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} * Tests behavior of {@code TerremarkVDCHandler}
@ -44,29 +50,44 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.TerremarkVDCHandlerTest") @Test(groups = "unit", testName = "vcloud.TerremarkVDCHandlerTest")
public class TerremarkVDCHandlerTest extends BaseHandlerTest { public class TerremarkVDCHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/vdc.xml"); 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( TerremarkVDC result = (TerremarkVDC) factory.create(
injector.getInstance(TerremarkVDCHandler.class)).parse(is); injector.getInstance(TerremarkVDCHandler.class)).parse(is);
assertEquals(result.getName(), "Miami Environment 1"); assertEquals(result.getName(), "Miami Environment 1");
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vdc+xml");
assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedLink> of()); assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedLink> of());
assertEquals(result.getAvailableNetworks(), ImmutableMap.of("10.114.34.128/26", new NamedLinkImpl( assertEquals(
"10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml", result.getAvailableNetworks(),
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708")))); ImmutableMap
assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1", CATALOG_XML, .of(
URI.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog"))); "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 assertEquals(result.getPublicIps(), new NamedLinkImpl("Public IPs", "application/xml", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/publicIps")));
assertEquals( assertEquals(

View File

@ -29,17 +29,17 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
@ -48,11 +48,14 @@ import com.google.inject.Provides;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.CatalogHandlerTest") @Test(groups = "unit", testName = "vcloud.CatalogHandlerTest")
public class CatalogHandlerTest extends BaseHandlerTest { public class CatalogHandlerTest {
@BeforeTest private Injector injector;
@Override
protected void setUpInjector() { private Factory factory;
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/catalog.xml");
injector = Guice.createInjector(new ParserModule(), new AbstractModule() { injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
@Override @Override
@ -68,17 +71,13 @@ public class CatalogHandlerTest extends BaseHandlerTest {
}); });
factory = injector.getInstance(ParseSax.Factory.class); 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( Catalog result = (Catalog) factory.create(injector.getInstance(CatalogHandler.class)).parse(
is); is);
assertEquals(result.getName(), "Miami Environment 1"); assertEquals(result.getName(), "Miami Environment 1");
assert result.getDescription() == null;
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog")); .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, assertEquals(result.get("CentOS 5.3 (32-bit)"), new NamedResourceImpl(5,
"CentOS 5.3 (32-bit)", CATALOGITEM_XML, "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"))); 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")));
}
} }

View File

@ -24,21 +24,28 @@
package org.jclouds.vcloud.xml; package org.jclouds.vcloud.xml;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_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.jclouds.vcloud.VCloudMediaType.TASKSLIST_XML;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; 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.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.Organization; import org.jclouds.vcloud.domain.Organization;
import org.testng.annotations.BeforeTest; import org.jclouds.vcloud.endpoints.VCloud;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; 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} * Tests behavior of {@code OrgHandler}
@ -46,24 +53,37 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.OrgHandlerTest") @Test(groups = "unit", testName = "vcloud.OrgHandlerTest")
public class OrgHandlerTest extends BaseHandlerTest { public class OrgHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/org.xml"); 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)) Organization result = (Organization) factory.create(injector.getInstance(OrgHandler.class))
.parse(is); .parse(is);
assertEquals(result.getName(), "adrian@jclouds.org"); assertEquals(result.getName(), "adrian@jclouds.org");
assertEquals(result.getId(), 48);
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/org/48"));
assertEquals(result.getType(), ORG_XML); assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog",
assertEquals(result.getCatalog(), new NamedLinkImpl("Miami Environment 1 Catalog", CATALOG_XML, 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 NamedLinkImpl( assertEquals(result.getVDCs(), ImmutableMap.of("Miami Environment 1", new NamedLinkImpl(
"Miami Environment 1", VCloudMediaType.VDC_XML, URI "Miami Environment 1", VCloudMediaType.VDC_XML, URI
@ -79,4 +99,38 @@ public class OrgHandlerTest extends BaseHandlerTest {
URI URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/tasksList/32")))); .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"))));
}
} }

View File

@ -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"), task2, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/1"), task1)); .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"));
}
} }

View File

@ -28,14 +28,22 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; 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.NamedLink;
import org.jclouds.rest.domain.internal.NamedLinkImpl; 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.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeTest; import org.jclouds.vcloud.endpoints.VCloud;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableMap; 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} * Tests behavior of {@code VDCHandler}
@ -43,22 +51,35 @@ import com.google.common.collect.ImmutableMap;
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.VDCHandlerTest") @Test(groups = "unit", testName = "vcloud.VDCHandlerTest")
public class VDCHandlerTest extends BaseHandlerTest { public class VDCHandlerTest {
@BeforeTest
@Override
protected void setUpInjector() {
super.setUpInjector();
}
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/vdc.xml"); 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); VDC result = factory.create(injector.getInstance(VDCHandler.class)).parse(is);
assertEquals(result.getName(), "Miami Environment 1"); assertEquals(result.getName(), "Miami Environment 1");
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")); .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.<String, NamedLink> of()); assertEquals(result.getResourceEntities(), ImmutableMap.<String, NamedLink> of());
assertEquals( assertEquals(
result.getAvailableNetworks(), result.getAvailableNetworks(),
@ -71,4 +92,82 @@ public class VDCHandlerTest extends BaseHandlerTest {
URI URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/network/1708")))); .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<String, NamedLink>()
.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.<String, NamedLink> of());
}
} }

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<Catalog href="https://vcloud.safesecureweb.com/api/v0.8/catalog/1"
name="HMSCatalog" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/catalog.xsd"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Description>HMS Shared Catalog</Description>
<Link rel="add"
href="https://vcloud.safesecureweb.com/api/v0.8/catalog/1/catalogItems"
type="application/vnd.vmware.vcloud.catalogItem+xml" />
<CatalogItems>
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml"
href="https://vcloud.safesecureweb.com/api/v0.8/catalogItem/1"
name="Plesk (Linux) 64-bit Template" />
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml"
href="https://vcloud.safesecureweb.com/api/v0.8/catalogItem/2"
name="Windows 2008 Datacenter 64 Bit Template" />
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml"
href="https://vcloud.safesecureweb.com/api/v0.8/catalogItem/3"
name="Cent OS 64 Bit Template" />
<CatalogItem type="application/vnd.vmware.vcloud.catalogItem+xml"
href="https://vcloud.safesecureweb.com/api/v0.8/catalogItem/4"
name="cPanel (Linux) 64 Bit Template" />
</CatalogItems>
</Catalog>

View File

@ -0,0 +1,12 @@
<Org href="https://vcloud.safesecureweb.com/api/v0.8/org/188849"
name="Customer 188849" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/organization.xsd"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Link rel="down" href="https://vcloud.safesecureweb.com/api/v0.8/catalog/1"
type="application/vnd.vmware.vcloud.catalog+xml" name="HMS Shared Catalog" />
<Link rel="down"
href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"
type="application/vnd.vmware.vcloud.vdc+xml" name="188849 Virtual DataCenter" />
<Link rel="down"
href="https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849"
type="application/vnd.vmware.vcloud.tasksList+xml" name="188849 Task List" />
</Org>

View File

@ -1,28 +1,3 @@
<!--
Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
====================================================================
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.
====================================================================
-->
<Org href="https://services.vcloudexpress.terremark.com/api/v0.8/org/48" name="adrian@jclouds.org" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Org href="https://services.vcloudexpress.terremark.com/api/v0.8/org/48" name="adrian@jclouds.org" xmlns="http://www.vmware.com/vcloud/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1"/> <Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32" type="application/vnd.vmware.vcloud.vdc+xml" name="Miami Environment 1"/>
<Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog" type="application/vnd.vmware.vcloud.catalog+xml" name="Miami Environment 1 Catalog"/> <Link rel="down" href="https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32/catalog" type="application/vnd.vmware.vcloud.catalog+xml" name="Miami Environment 1 Catalog"/>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<tasks xmlns="http://www.vmware.com/vcloud/tasks" xmlns:common="http://www.vmware.com/vcloud/v0.8"
xmlns:task="http://www.vmware.com/vcloud/task"
xsi:schemaLocation="http://www.vmware.com/vcloud/tasks
https://vcloud.safesecureweb.com/ns/vcloud/tasks-1.0.xsd
http://www.vmware.com/vcloud/v0.8
https://vcloud.safesecureweb.com/ns/vcloud/common-1.0.xsd
http://www.vmware.com/vcloud/task
https://vcloud.safesecureweb.com/ns/vcloud/task-1.0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Link rel="self"
href="https://vcloud.safesecureweb.com/api/v0.8/tasksList/188849"
type="application/vnd.vmware.vcloud.tasksList+xml" />
</tasks>

View File

@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<Vdc href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"
name="vDC Name" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/vdc.xsd"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Link rel="add"
href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849/vApps"
type="application/vnd.vmware.vcloud.vApp+xml" />
<Link rel="add"
href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849/vAppTemplates"
type="application/vnd.vmware.vcloud.catalogItem+xml" />
<Link rel="add"
href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849/media"
type="application/vnd.vmware.vcloud.media+xml" />
<Description>vDC Name</Description>
<StorageCapacity>
<Units>bytes * 10^9</Units>
<Allocated>0</Allocated>
<Used>40960</Used>
</StorageCapacity>
<ComputeCapacity>
<Cpu>
<Units>hz * 10^6</Units>
<Allocated>0</Allocated>
<Used>2400</Used>
</Cpu>
<Memory>
<Units>bytes * 10^9</Units>
<Allocated>0</Allocated>
<Used>2</Used>
</Memory>
<InstantiatedVmsQuota>
<Limit>0</Limit>
<Used>2</Used>
</InstantiatedVmsQuota>
<DeployedVmsQuota>
<Limit>0</Limit>
<Used>2</Used>
</DeployedVmsQuota>
</ComputeCapacity>
<ResourceEntities>
<ResourceEntity
href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/1"
type="application/vnd.vmware.vcloud.vAppTemplate+xml" name="Plesk (Linux) 64-bit Template" />
<ResourceEntity
href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2"
type="application/vnd.vmware.vcloud.vAppTemplate+xml" name="Windows 2008 Datacenter 64 Bit Template" />
<ResourceEntity
href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"
type="application/vnd.vmware.vcloud.vAppTemplate+xml" name="Cent OS 64 Bit Template" />
<ResourceEntity
href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4"
type="application/vnd.vmware.vcloud.vAppTemplate+xml" name="cPanel (Linux) 64 Bit Template" />
<ResourceEntity
href="https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1"
type="application/vnd.vmware.vcloud.vApp+xml" name="188849-1" />
<ResourceEntity
href="https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-2"
type="application/vnd.vmware.vcloud.vApp+xml" name="188849-2" />
</ResourceEntities>
</Vdc>