Issue 112: interim progress on hosting.com

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2364 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-12-02 17:02:33 +00:00
parent 4a65872d9b
commit 638c80e58d
85 changed files with 4440 additions and 731 deletions

View File

@ -46,7 +46,6 @@
<module>rackspace</module> <module>rackspace</module>
<module>mezeo</module> <module>mezeo</module>
<module>nirvanix</module> <module>nirvanix</module>
<module>vcloud</module>
<module>twitter</module> <module>twitter</module>
<module>rimuhosting</module> <module>rimuhosting</module>
<module>scriptbuilder</module> <module>scriptbuilder</module>

View File

@ -41,16 +41,24 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import org.jclouds.rest.annotations.Endpoint; import org.jclouds.rest.annotations.Endpoint;
import org.jclouds.rest.annotations.MapBinder;
import org.jclouds.rest.annotations.MapEntityParam;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.RequestFilters; import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser; import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlEntity;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VDCHandler; import org.jclouds.vcloud.xml.VDCHandler;
/** /**
@ -66,7 +74,6 @@ public interface VCloudAsyncClient {
@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();
@ -162,5 +169,17 @@ public interface VCloudAsyncClient {
@Consumes(VAPP_XML) @Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vapp/{vAppId}")
Future<String> getVAppString(@PathParam("vAppId") String appId); @XMLResponseParser(VAppHandler.class)
Future<? extends VApp> getVApp(@PathParam("vAppId") String appId);
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
@XMLResponseParser(VAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlEntity.class)
Future<? extends VApp> instantiateVAppTemplate(@MapEntityParam("name") String appName,
@MapEntityParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
} }

View File

@ -30,7 +30,9 @@ import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.TasksList; import org.jclouds.vcloud.domain.TasksList;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
/** /**
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
@ -86,5 +88,8 @@ public interface VCloudClient {
void cancelTask(URI task); void cancelTask(URI task);
String getVAppString(String appId); VApp getVApp(String appId);
VApp instantiateVAppTemplate(String appName, String templateId,
InstantiateVAppTemplateOptions... options);
} }

View File

@ -24,6 +24,8 @@
package org.jclouds.vcloud; package org.jclouds.vcloud;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
@ -46,6 +48,8 @@ public class VCloudPropertiesBuilder extends HttpPropertiesBuilder {
Properties properties = super.defaultProperties(); Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8");
properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + ""); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + "");
properties.setProperty(PROPERTY_VCLOUD_DEFAULTCPUCOUNT, "1");
properties.setProperty(PROPERTY_VCLOUD_DEFAULTMEMORY, "512");
return properties; return properties;
} }

View File

@ -0,0 +1,94 @@
package org.jclouds.vcloud.binders;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringEntity;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindInstantiateVAppTemplateParamsToXmlEntity implements MapBinder {
private final String xmlTemplate;
private final BindToStringEntity stringBinder;
protected final Map<String, String> defaultParams;
@Inject
public BindInstantiateVAppTemplateParamsToXmlEntity(
@Named("InstantiateVAppTemplateParams") String xmlTemplate,
BindToStringEntity stringBinder,
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK) String defaultNetwork,
@Named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT) String defaultCpuCount,
@Named(PROPERTY_VCLOUD_DEFAULTMEMORY) String defaultMemory) {
this.xmlTemplate = xmlTemplate;
this.stringBinder = stringBinder;
this.defaultParams = Maps.newHashMap();
this.defaultParams.put("network", defaultNetwork);
this.defaultParams.put("count", defaultCpuCount);
this.defaultParams.put("megabytes", defaultMemory);
}
@SuppressWarnings("unchecked")
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
"this binder is only valid for GeneratedHttpRequests!");
GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
checkState(gRequest.getArgs() != null, "args should be initialized at this point");
postParams = new HashMap<String, String>(postParams);
postParams.putAll(defaultParams);
addOptionsToMap(postParams, gRequest);
String entity = xmlTemplate;
for (Entry<String, String> entry : postParams.entrySet()) {
entity = entity.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue());
}
stringBinder.bindToRequest(request, entity);
}
protected void addOptionsToMap(Map<String, String> postParams, GeneratedHttpRequest<?> gRequest) {
for (Object arg : gRequest.getArgs()) {
if (arg instanceof InstantiateVAppTemplateOptions) {
InstantiateVAppTemplateOptions options = (InstantiateVAppTemplateOptions) arg;
if (options.getCpuCount() != null) {
postParams.put("count", options.getCpuCount());
}
if (options.getMegabytes() != null) {
postParams.put("megabytes", options.getMegabytes());
}
if (options.getNetwork() != null) {
postParams.put("network", options.getNetwork());
}
}
}
}
public void bindToRequest(HttpRequest request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
}
String ifNullDefaultTo(String value, String defaultValue) {
return value != null ? value : checkNotNull(defaultValue, "defaultValue");
}
}

View File

@ -23,17 +23,21 @@
*/ */
package org.jclouds.vcloud.config; package org.jclouds.vcloud.config;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp; import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory; import org.jclouds.rest.RestClientFactory;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.VCloudDiscovery; import org.jclouds.vcloud.VCloudDiscovery;
@ -45,6 +49,7 @@ import org.jclouds.vcloud.endpoints.VCloudLogin;
import org.jclouds.vcloud.endpoints.VDC; import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -89,11 +94,18 @@ public class VCloudRestClientModule extends AbstractModule {
return vcloudUri.toASCIIString().replace("/login", "/vapp"); return vcloudUri.toASCIIString().replace("/login", "/vapp");
} }
@Provides
@VAppTemplateRoot
@Singleton
String provideVAppTemplateRoot(@VCloudLogin URI vcloudUri) {
return vcloudUri.toASCIIString().replace("/login", "/vAppTemplate");
}
@Provides @Provides
@Singleton @Singleton
protected Organization provideOrganization(VCloudDiscovery discovery) throws ExecutionException, protected Organization provideOrganization(VCloudDiscovery discovery) throws ExecutionException,
TimeoutException, InterruptedException { TimeoutException, InterruptedException {
return discovery.getOrganization().get(60, TimeUnit.SECONDS); return discovery.getOrganization().get(90, TimeUnit.SECONDS);
} }
@Provides @Provides
@ -110,6 +122,14 @@ public class VCloudRestClientModule extends AbstractModule {
return org.getCatalog().getLocation(); return org.getCatalog().getLocation();
} }
@Singleton
@Provides
@Named("InstantiateVAppTemplateParams")
protected String provideInstantiateVAppTemplateParams() throws IOException {
InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
return Utils.toStringAndClose(is);
}
@Provides @Provides
@Network @Network
@Singleton @Singleton

View File

@ -26,6 +26,7 @@ package org.jclouds.vcloud.domain;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogImpl;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;

View File

@ -1,17 +0,0 @@
package org.jclouds.vcloud.domain;
import org.jclouds.rest.domain.NamedLink;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import com.google.inject.ImplementedBy;
/**
* Location of a Rest resource
*
* @author Adrian Cole
*
*/
@ImplementedBy(NamedResourceImpl.class)
public interface NamedResource extends NamedLink, Comparable<NamedResource> {
String getId();
}

View File

@ -0,0 +1,210 @@
/**
*
* 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;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Adrian Cole
*
*/
public class ResourceAllocation implements Comparable<ResourceAllocation> {
private final int id;
private final String name;
private final String description;
private final ResourceType type;
private final String subType;
private final Integer address;
private final Integer addressOnParent;
private final Integer parent;
private final Boolean connected;
private final long virtualQuantity;
private final String virtualQuantityUnits;
public ResourceAllocation(int id, String name, String description, ResourceType type,
String subType, Integer address, Integer addressOnParent, Integer parent,
Boolean connected, long virtualQuantity, String virtualQuantityUnits) {
this.id = id;
this.name = checkNotNull(name, "name");
this.description = description;
this.type = checkNotNull(type, "type");
this.subType = subType;
this.address = address;
this.addressOnParent = addressOnParent;
this.parent = parent;
this.connected = connected;
this.virtualQuantity = virtualQuantity;
this.virtualQuantityUnits = virtualQuantityUnits;
}
public int compareTo(ResourceAllocation that) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if (this == that)
return EQUAL;
if (this.id < that.id)
return BEFORE;
if (this.id > that.id)
return AFTER;
return EQUAL;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getDescription() {
return description;
}
public ResourceType getType() {
return type;
}
public String getSubType() {
return subType;
}
public Integer getAddress() {
return address;
}
public Integer getAddressOnParent() {
return addressOnParent;
}
public Integer getParent() {
return parent;
}
public Boolean getConnected() {
return connected;
}
public long getVirtualQuantity() {
return virtualQuantity;
}
public String getVirtualQuantityUnits() {
return virtualQuantityUnits;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode());
result = prime * result + ((connected == null) ? 0 : connected.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + id;
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((parent == null) ? 0 : parent.hashCode());
result = prime * result + ((subType == null) ? 0 : subType.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
result = prime * result + (int) (virtualQuantity ^ (virtualQuantity >>> 32));
result = prime * result
+ ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ResourceAllocation other = (ResourceAllocation) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
if (addressOnParent == null) {
if (other.addressOnParent != null)
return false;
} else if (!addressOnParent.equals(other.addressOnParent))
return false;
if (connected == null) {
if (other.connected != null)
return false;
} else if (!connected.equals(other.connected))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (id != other.id)
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (parent == null) {
if (other.parent != null)
return false;
} else if (!parent.equals(other.parent))
return false;
if (subType == null) {
if (other.subType != null)
return false;
} else if (!subType.equals(other.subType))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
if (virtualQuantity != other.virtualQuantity)
return false;
if (virtualQuantityUnits == null) {
if (other.virtualQuantityUnits != null)
return false;
} else if (!virtualQuantityUnits.equals(other.virtualQuantityUnits))
return false;
return true;
}
@Override
public String toString() {
return "ResourceAllocation [address=" + address + ", addressOnParent=" + addressOnParent
+ ", connected=" + connected + ", description=" + description + ", id=" + id
+ ", name=" + name + ", parent=" + parent + ", subType=" + subType + ", type="
+ type + ", virtualQuantity=" + virtualQuantity + ", virtualQuantityUnits="
+ virtualQuantityUnits + "]";
}
}

View File

@ -10,29 +10,36 @@ import org.jclouds.vcloud.VCloudAsyncClient;
* *
* @author Adrian Cole * @author Adrian Cole
* @see VCloudAsyncClient#getVApp * @see VCloudAsyncClient#getVApp
* * @see <a href="http://blogs.vmware.com/vapp/2009/11/index.html"/>
* *
*/ */
public enum ResourceType { public enum ResourceType {
OTHER, PROCESSOR, MEMORY, IDE_CONTROLLER, SCSI_CONTROLLER, ETHERNET_ADAPTER, FLOPPY_DRIVE, CD_DRIVE, DVD_DRIVE, DISK_DRIVE, USB_CONTROLLER;
VIRTUAL_CPU,
MEMORY,
SCSI_CONTROLLER,
VIRTUAL_DISK;
public String value() { public String value() {
switch (this) { switch (this) {
case VIRTUAL_CPU: case OTHER:
return "1";
case PROCESSOR:
return "3"; return "3";
case MEMORY: case MEMORY:
return "4"; return "4";
case IDE_CONTROLLER:
return "5";
case SCSI_CONTROLLER: case SCSI_CONTROLLER:
return "6"; return "6";
case VIRTUAL_DISK: case ETHERNET_ADAPTER:
return "10";
case FLOPPY_DRIVE:
return "14";
case CD_DRIVE:
return "15";
case DVD_DRIVE:
return "16";
case DISK_DRIVE:
return "17"; return "17";
case USB_CONTROLLER:
return "23";
default: default:
throw new IllegalArgumentException("invalid type:" + this); throw new IllegalArgumentException("invalid type:" + this);
} }
@ -44,14 +51,28 @@ public enum ResourceType {
public static ResourceType fromValue(int v) { public static ResourceType fromValue(int v) {
switch (v) { switch (v) {
case 1:
return OTHER;
case 3: case 3:
return VIRTUAL_CPU; return PROCESSOR;
case 4: case 4:
return MEMORY; return MEMORY;
case 5:
return IDE_CONTROLLER;
case 6: case 6:
return SCSI_CONTROLLER; return SCSI_CONTROLLER;
case 10:
return ETHERNET_ADAPTER;
case 14:
return FLOPPY_DRIVE;
case 15:
return CD_DRIVE;
case 16:
return DVD_DRIVE;
case 17: case 17:
return VIRTUAL_DISK; return DISK_DRIVE;
case 23:
return USB_CONTROLLER;
default: default:
throw new IllegalArgumentException("invalid type:" + v); throw new IllegalArgumentException("invalid type:" + v);
} }

View File

@ -0,0 +1,348 @@
/**
*
* 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;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* @author Adrian Cole
*/
public class TerremarkResourceAllocation implements Comparable<TerremarkResourceAllocation> {
private final Integer address;
private final Integer addressOnParent;
private final String allocationUnits;
private final String automaticAllocation;
private final String automaticDeallocation;
private final String caption;
private final String consumerVisibility;
private final String description;
private final String elementName;
private final String hostResource;
private final int instanceID;
private final String limit;
private final String mappingBehavior;
private final String otherResourceType;
private final Integer parent;
private final String poolID;
private final String reservation;
private final String resourceSubType;
private final ResourceType resourceType;
private final long virtualQuantity;
private final String virtualQuantityUnits;
private final String weight;
public TerremarkResourceAllocation(Integer address, Integer addressOnParent, String allocationUnits,
String automaticAllocation, String automaticDeallocation, String caption,
String consumerVisibility, String description, String elementName, String hostResource,
int instanceID, String limit, String mappingBehavior, String otherResourceType,
Integer parent, String poolID, String reservation, String resourceSubType,
ResourceType resourceType, long virtualQuantity, String virtualQuantityUnits,
String weight) {
this.address = address;
this.addressOnParent = addressOnParent;
this.allocationUnits = allocationUnits;
this.automaticAllocation = automaticAllocation;
this.automaticDeallocation = automaticDeallocation;
this.caption = caption;
this.consumerVisibility = consumerVisibility;
this.description = description;
this.elementName = elementName;
this.hostResource = hostResource;
this.instanceID = checkNotNull(instanceID, "instanceID");
this.limit = limit;
this.mappingBehavior = mappingBehavior;
this.otherResourceType = otherResourceType;
this.parent = parent;
this.poolID = poolID;
this.reservation = reservation;
this.resourceSubType = resourceSubType;
this.resourceType = checkNotNull(resourceType, "resourceType");
this.virtualQuantity = virtualQuantity;
this.virtualQuantityUnits = virtualQuantityUnits;
this.weight = weight;
}
public Integer getAddress() {
return address;
}
public Integer getAddressOnParent() {
return addressOnParent;
}
public String getAllocationUnits() {
return allocationUnits;
}
public String getAutomaticAllocation() {
return automaticAllocation;
}
public String getAutomaticDeallocation() {
return automaticDeallocation;
}
public String getCaption() {
return caption;
}
public String getConsumerVisibility() {
return consumerVisibility;
}
public String getDescription() {
return description;
}
public String getElementName() {
return elementName;
}
public int getInstanceID() {
return instanceID;
}
public String getLimit() {
return limit;
}
public String getMappingBehavior() {
return mappingBehavior;
}
public String getOtherResourceType() {
return otherResourceType;
}
public Integer getParent() {
return parent;
}
public String getPoolID() {
return poolID;
}
public String getReservation() {
return reservation;
}
public String getResourceSubType() {
return resourceSubType;
}
public ResourceType getResourceType() {
return resourceType;
}
public long getVirtualQuantity() {
return virtualQuantity;
}
public String getVirtualQuantityUnits() {
return virtualQuantityUnits;
}
public String getWeight() {
return weight;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((address == null) ? 0 : address.hashCode());
result = prime * result + ((addressOnParent == null) ? 0 : addressOnParent.hashCode());
result = prime * result + ((allocationUnits == null) ? 0 : allocationUnits.hashCode());
result = prime * result
+ ((automaticAllocation == null) ? 0 : automaticAllocation.hashCode());
result = prime * result
+ ((automaticDeallocation == null) ? 0 : automaticDeallocation.hashCode());
result = prime * result + ((caption == null) ? 0 : caption.hashCode());
result = prime * result + ((consumerVisibility == null) ? 0 : consumerVisibility.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((elementName == null) ? 0 : elementName.hashCode());
result = prime * result + instanceID;
result = prime * result + ((limit == null) ? 0 : limit.hashCode());
result = prime * result + ((mappingBehavior == null) ? 0 : mappingBehavior.hashCode());
result = prime * result + ((otherResourceType == null) ? 0 : otherResourceType.hashCode());
result = prime * result + ((parent == null) ? 0 : parent.hashCode());
result = prime * result + ((poolID == null) ? 0 : poolID.hashCode());
result = prime * result + ((reservation == null) ? 0 : reservation.hashCode());
result = prime * result + ((resourceSubType == null) ? 0 : resourceSubType.hashCode());
result = prime * result + ((resourceType == null) ? 0 : resourceType.hashCode());
result = prime * result + (int) (virtualQuantity ^ (virtualQuantity >>> 32));
result = prime * result
+ ((virtualQuantityUnits == null) ? 0 : virtualQuantityUnits.hashCode());
result = prime * result + ((weight == null) ? 0 : weight.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TerremarkResourceAllocation other = (TerremarkResourceAllocation) obj;
if (address == null) {
if (other.address != null)
return false;
} else if (!address.equals(other.address))
return false;
if (addressOnParent == null) {
if (other.addressOnParent != null)
return false;
} else if (!addressOnParent.equals(other.addressOnParent))
return false;
if (allocationUnits == null) {
if (other.allocationUnits != null)
return false;
} else if (!allocationUnits.equals(other.allocationUnits))
return false;
if (automaticAllocation == null) {
if (other.automaticAllocation != null)
return false;
} else if (!automaticAllocation.equals(other.automaticAllocation))
return false;
if (automaticDeallocation == null) {
if (other.automaticDeallocation != null)
return false;
} else if (!automaticDeallocation.equals(other.automaticDeallocation))
return false;
if (caption == null) {
if (other.caption != null)
return false;
} else if (!caption.equals(other.caption))
return false;
if (consumerVisibility == null) {
if (other.consumerVisibility != null)
return false;
} else if (!consumerVisibility.equals(other.consumerVisibility))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (elementName == null) {
if (other.elementName != null)
return false;
} else if (!elementName.equals(other.elementName))
return false;
if (instanceID != other.instanceID)
return false;
if (limit == null) {
if (other.limit != null)
return false;
} else if (!limit.equals(other.limit))
return false;
if (mappingBehavior == null) {
if (other.mappingBehavior != null)
return false;
} else if (!mappingBehavior.equals(other.mappingBehavior))
return false;
if (otherResourceType == null) {
if (other.otherResourceType != null)
return false;
} else if (!otherResourceType.equals(other.otherResourceType))
return false;
if (parent == null) {
if (other.parent != null)
return false;
} else if (!parent.equals(other.parent))
return false;
if (poolID == null) {
if (other.poolID != null)
return false;
} else if (!poolID.equals(other.poolID))
return false;
if (reservation == null) {
if (other.reservation != null)
return false;
} else if (!reservation.equals(other.reservation))
return false;
if (resourceSubType == null) {
if (other.resourceSubType != null)
return false;
} else if (!resourceSubType.equals(other.resourceSubType))
return false;
if (resourceType == null) {
if (other.resourceType != null)
return false;
} else if (!resourceType.equals(other.resourceType))
return false;
if (virtualQuantity != other.virtualQuantity)
return false;
if (virtualQuantityUnits == null) {
if (other.virtualQuantityUnits != null)
return false;
} else if (!virtualQuantityUnits.equals(other.virtualQuantityUnits))
return false;
if (weight == null) {
if (other.weight != null)
return false;
} else if (!weight.equals(other.weight))
return false;
return true;
}
@Override
public String toString() {
return "ResourceAllocation [address=" + address + ", addressOnParent=" + addressOnParent
+ ", allocationUnits=" + allocationUnits + ", automaticAllocation="
+ automaticAllocation + ", automaticDeallocation=" + automaticDeallocation
+ ", caption=" + caption + ", consumerVisibility=" + consumerVisibility
+ ", description=" + description + ", elementName=" + elementName + ", instanceID="
+ instanceID + ", limit=" + limit + ", mappingBehavior=" + mappingBehavior
+ ", otherResourceType=" + otherResourceType + ", parent=" + parent + ", poolID="
+ poolID + ", reservation=" + reservation + ", resourceSubType=" + resourceSubType
+ ", resourceType=" + resourceType + ", virtualQuantity=" + virtualQuantity
+ ", virtualQuantityUnits=" + virtualQuantityUnits + ", weight=" + weight + "]";
}
public int compareTo(TerremarkResourceAllocation that) {
final int BEFORE = -1;
final int EQUAL = 0;
final int AFTER = 1;
if (this == that)
return EQUAL;
int comparison = this.resourceType.compareTo(that.resourceType);
if (comparison != EQUAL)
return comparison;
if (this.instanceID < that.instanceID)
return BEFORE;
if (this.instanceID > that.instanceID)
return AFTER;
return EQUAL;
}
public String getHostResource() {
return hostResource;
}
}

View File

@ -0,0 +1,305 @@
/**
*
* 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;
import org.joda.time.DateTime;
/**
* @author Adrian Cole
*/
public class TerremarkVirtualSystem extends VirtualSystem {
private final String automaticRecoveryAction;
private final String automaticShutdownAction;
private final String automaticStartupAction;
private final String automaticStartupActionDelay;
private final String automaticStartupActionSequenceNumber;
private final String caption;
private final String configurationDataRoot;
private final String configurationFile;
private final String configurationID;
private final DateTime creationTime;
private final String description;
private final String logDataRoot;
private final String recoveryFile;
private final String snapshotDataRoot;
private final String suspendDataRoot;
private final String swapFileDataRoot;
public TerremarkVirtualSystem(String automaticRecoveryAction, String automaticShutdownAction,
String automaticStartupAction, String automaticStartupActionDelay,
String automaticStartupActionSequenceNumber, String caption,
String configurationDataRoot, String configurationFile, String configurationID,
DateTime creationTime, String description, String elementName, int instanceID,
String logDataRoot, String recoveryFile, String snapshotDataRoot,
String suspendDataRoot, String swapFileDataRoot, String virtualSystemIdentifier,
String virtualSystemType) {
super(instanceID, elementName, virtualSystemIdentifier, virtualSystemType);
this.automaticRecoveryAction = automaticRecoveryAction;
this.automaticShutdownAction = automaticShutdownAction;
this.automaticStartupAction = automaticStartupAction;
this.automaticStartupActionDelay = automaticStartupActionDelay;
this.automaticStartupActionSequenceNumber = automaticStartupActionSequenceNumber;
this.caption = caption;
this.configurationDataRoot = configurationDataRoot;
this.configurationFile = configurationFile;
this.configurationID = configurationID;
this.creationTime = creationTime;
this.description = description;
this.logDataRoot = logDataRoot;
this.recoveryFile = recoveryFile;
this.snapshotDataRoot = snapshotDataRoot;
this.suspendDataRoot = suspendDataRoot;
this.swapFileDataRoot = swapFileDataRoot;
}
public String getAutomaticRecoveryAction() {
return automaticRecoveryAction;
}
public String getAutomaticShutdownAction() {
return automaticShutdownAction;
}
public String getAutomaticStartupAction() {
return automaticStartupAction;
}
public String getAutomaticStartupActionDelay() {
return automaticStartupActionDelay;
}
public String getAutomaticStartupActionSequenceNumber() {
return automaticStartupActionSequenceNumber;
}
public String getCaption() {
return caption;
}
public String getConfigurationDataRoot() {
return configurationDataRoot;
}
public String getConfigurationFile() {
return configurationFile;
}
public String getConfigurationID() {
return configurationID;
}
public DateTime getCreationTime() {
return creationTime;
}
public String getDescription() {
return description;
}
public String getLogDataRoot() {
return logDataRoot;
}
public String getRecoveryFile() {
return recoveryFile;
}
public String getSnapshotDataRoot() {
return snapshotDataRoot;
}
public String getSuspendDataRoot() {
return suspendDataRoot;
}
public String getSwapFileDataRoot() {
return swapFileDataRoot;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((automaticRecoveryAction == null) ? 0 : automaticRecoveryAction.hashCode());
result = prime * result
+ ((automaticShutdownAction == null) ? 0 : automaticShutdownAction.hashCode());
result = prime * result
+ ((automaticStartupAction == null) ? 0 : automaticStartupAction.hashCode());
result = prime
* result
+ ((automaticStartupActionDelay == null) ? 0 : automaticStartupActionDelay
.hashCode());
result = prime
* result
+ ((automaticStartupActionSequenceNumber == null) ? 0
: automaticStartupActionSequenceNumber.hashCode());
result = prime * result + ((caption == null) ? 0 : caption.hashCode());
result = prime * result
+ ((configurationDataRoot == null) ? 0 : configurationDataRoot.hashCode());
result = prime * result + ((configurationFile == null) ? 0 : configurationFile.hashCode());
result = prime * result + ((configurationID == null) ? 0 : configurationID.hashCode());
result = prime * result + ((creationTime == null) ? 0 : creationTime.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + id;
result = prime * result + ((logDataRoot == null) ? 0 : logDataRoot.hashCode());
result = prime * result + ((recoveryFile == null) ? 0 : recoveryFile.hashCode());
result = prime * result + ((snapshotDataRoot == null) ? 0 : snapshotDataRoot.hashCode());
result = prime * result + ((suspendDataRoot == null) ? 0 : suspendDataRoot.hashCode());
result = prime * result + ((swapFileDataRoot == null) ? 0 : swapFileDataRoot.hashCode());
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TerremarkVirtualSystem other = (TerremarkVirtualSystem) obj;
if (automaticRecoveryAction == null) {
if (other.automaticRecoveryAction != null)
return false;
} else if (!automaticRecoveryAction.equals(other.automaticRecoveryAction))
return false;
if (automaticShutdownAction == null) {
if (other.automaticShutdownAction != null)
return false;
} else if (!automaticShutdownAction.equals(other.automaticShutdownAction))
return false;
if (automaticStartupAction == null) {
if (other.automaticStartupAction != null)
return false;
} else if (!automaticStartupAction.equals(other.automaticStartupAction))
return false;
if (automaticStartupActionDelay == null) {
if (other.automaticStartupActionDelay != null)
return false;
} else if (!automaticStartupActionDelay.equals(other.automaticStartupActionDelay))
return false;
if (automaticStartupActionSequenceNumber == null) {
if (other.automaticStartupActionSequenceNumber != null)
return false;
} else if (!automaticStartupActionSequenceNumber
.equals(other.automaticStartupActionSequenceNumber))
return false;
if (caption == null) {
if (other.caption != null)
return false;
} else if (!caption.equals(other.caption))
return false;
if (configurationDataRoot == null) {
if (other.configurationDataRoot != null)
return false;
} else if (!configurationDataRoot.equals(other.configurationDataRoot))
return false;
if (configurationFile == null) {
if (other.configurationFile != null)
return false;
} else if (!configurationFile.equals(other.configurationFile))
return false;
if (configurationID == null) {
if (other.configurationID != null)
return false;
} else if (!configurationID.equals(other.configurationID))
return false;
if (creationTime == null) {
if (other.creationTime != null)
return false;
} else if (!creationTime.equals(other.creationTime))
return false;
if (description == null) {
if (other.description != null)
return false;
} else if (!description.equals(other.description))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (id != other.id)
return false;
if (logDataRoot == null) {
if (other.logDataRoot != null)
return false;
} else if (!logDataRoot.equals(other.logDataRoot))
return false;
if (recoveryFile == null) {
if (other.recoveryFile != null)
return false;
} else if (!recoveryFile.equals(other.recoveryFile))
return false;
if (snapshotDataRoot == null) {
if (other.snapshotDataRoot != null)
return false;
} else if (!snapshotDataRoot.equals(other.snapshotDataRoot))
return false;
if (suspendDataRoot == null) {
if (other.suspendDataRoot != null)
return false;
} else if (!suspendDataRoot.equals(other.suspendDataRoot))
return false;
if (swapFileDataRoot == null) {
if (other.swapFileDataRoot != null)
return false;
} else if (!swapFileDataRoot.equals(other.swapFileDataRoot))
return false;
if (identifier == null) {
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return "VirtualSystem [automaticRecoveryAction=" + automaticRecoveryAction
+ ", automaticShutdownAction=" + automaticShutdownAction
+ ", automaticStartupAction=" + automaticStartupAction
+ ", automaticStartupActionDelay=" + automaticStartupActionDelay
+ ", automaticStartupActionSequenceNumber=" + automaticStartupActionSequenceNumber
+ ", caption=" + caption + ", configurationDataRoot=" + configurationDataRoot
+ ", configurationFile=" + configurationFile + ", configurationID="
+ configurationID + ", creationTime=" + creationTime + ", description="
+ description + ", elementName=" + name + ", instanceID=" + id + ", logDataRoot="
+ logDataRoot + ", recoveryFile=" + recoveryFile + ", snapshotDataRoot="
+ snapshotDataRoot + ", suspendDataRoot=" + suspendDataRoot + ", swapFileDataRoot="
+ swapFileDataRoot + ", virtualSystemIdentifier=" + identifier
+ ", virtualSystemType=" + type + "]";
}
}

View File

@ -1,6 +1,6 @@
/** /**
* *
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com> * Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
* *
* ==================================================================== * ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one * Licensed to the Apache Software Foundation (ASF) under one
@ -21,36 +21,24 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.terremark.domain; package org.jclouds.vcloud.domain;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.SortedSet; import java.util.SortedSet;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.internal.VAppImpl;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
import com.google.inject.ImplementedBy;
/** public interface VApp {
* @author Adrian Cole String getId();
*/
@ImplementedBy(VAppImpl.class) URI getLocation();
public interface VApp extends NamedResource {
String getName();
VAppStatus getStatus(); VAppStatus getStatus();
long getSize();
Link getVDC();
Link getComputeOptions();
Link getCustomizationOptions();
ListMultimap<String, InetAddress> getNetworkToAddresses(); ListMultimap<String, InetAddress> getNetworkToAddresses();
String getOperatingSystemDescription(); String getOperatingSystemDescription();

View File

@ -29,12 +29,14 @@ import static com.google.common.base.Preconditions.checkNotNull;
* @author Adrian Cole * @author Adrian Cole
*/ */
public enum VAppStatus { public enum VAppStatus {
CREATING, OFF, ON; CREATING, TODO_I_DONT_KNOW, OFF, ON;
public String value() { public String value() {
switch (this) { switch (this) {
case CREATING: case CREATING:
return "0"; return "0";
case TODO_I_DONT_KNOW:
return "1";
case OFF: case OFF:
return "2"; return "2";
case ON: case ON:
@ -52,6 +54,8 @@ public enum VAppStatus {
switch (v) { switch (v) {
case 0: case 0:
return CREATING; return CREATING;
case 1:
return TODO_I_DONT_KNOW;
case 2: case 2:
return OFF; return OFF;
case 4: case 4:

View File

@ -26,7 +26,7 @@ package org.jclouds.vcloud.domain;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.internal.VDCImpl;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
@ -56,8 +56,8 @@ public interface VDC {
Quota getDeployedVmsQuota(); Quota getDeployedVmsQuota();
Map<String, NamedLink> getAvailableNetworks(); Map<String, NamedResource> getAvailableNetworks();
Map<String, NamedLink> getResourceEntities(); Map<String, NamedResource> getResourceEntities();
} }

View File

@ -0,0 +1,103 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.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;
import static com.google.common.base.Preconditions.checkNotNull;
public class VirtualSystem {
protected final int id;
protected final String name;
protected final String identifier;
protected final String type;
public VirtualSystem(int id, String name, String identifier, String type) {
this.id = id;
this.name = checkNotNull(name, "name");
this.identifier = checkNotNull(identifier, "identifier");
this.type = checkNotNull(type, "type");
}
public String getName() {
return name;
}
public int getId() {
return id;
}
public String getIdentifier() {
return identifier;
}
public String getType() {
return type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + id;
result = prime * result + ((identifier == null) ? 0 : identifier.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
VirtualSystem other = (VirtualSystem) obj;
if (id != other.id)
return false;
if (identifier == null) {
if (other.identifier != null)
return false;
} else if (!identifier.equals(other.identifier))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (type == null) {
if (other.type != null)
return false;
} else if (!type.equals(other.type))
return false;
return true;
}
@Override
public String toString() {
return "VirtualSystem [id=" + id + ", identifier=" + identifier + ", name=" + name
+ ", type=" + type + "]";
}
}

View File

@ -29,8 +29,8 @@ 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.NamedResource;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import com.google.inject.internal.Nullable; import com.google.inject.internal.Nullable;

View File

@ -1,60 +0,0 @@
package org.jclouds.vcloud.domain.internal;
import java.net.URI;
import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.vcloud.domain.NamedResource;
/**
* Location of a Rest resource
*
* @author Adrian Cole
*
*/
public class NamedResourceImpl extends NamedLinkImpl implements NamedResource {
private final String id;
public NamedResourceImpl(String id, String name, String type, URI location) {
super(name, type, location);
this.id = id;
}
public String getId() {
return id;
}
public int compareTo(NamedResource that) {
return (this == that) ? 0 : this.id.compareTo(that.getId());
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
NamedResourceImpl other = (NamedResourceImpl) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
return true;
}
@Override
public String toString() {
return "NamedResourceImpl [id=" + id + ", name=" + getName() + ", location="
+ getLocation() + ", type=" + getType() + "]";
}
}

View File

@ -21,20 +21,18 @@
* under the License. * under the License.
* ==================================================================== * ====================================================================
*/ */
package org.jclouds.vcloud.terremark.domain.internal; package org.jclouds.vcloud.domain.internal;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import java.util.SortedSet; import java.util.SortedSet;
import org.jclouds.rest.domain.Link; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.terremark.domain.ResourceAllocation;
import org.jclouds.vcloud.terremark.domain.ResourceType;
import org.jclouds.vcloud.terremark.domain.VApp;
import org.jclouds.vcloud.terremark.domain.VirtualSystem;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.ListMultimap; import com.google.common.collect.ListMultimap;
@ -46,13 +44,11 @@ import com.google.common.collect.Maps;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class VAppImpl extends NamedResourceImpl implements VApp { public class VAppImpl implements VApp {
private final String id;
private final String name;
private final URI location;
private final VAppStatus status; private final VAppStatus status;
private final long size;
private final Link vDC;
private final Link computeOptions;
private final Link customizationOptions;
private final ListMultimap<String, InetAddress> networkToAddresses; private final ListMultimap<String, InetAddress> networkToAddresses;
private final String operatingSystemDescription; private final String operatingSystemDescription;
private final VirtualSystem system; private final VirtualSystem system;
@ -62,17 +58,14 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L; private static final long serialVersionUID = 8464716396538298809L;
public VAppImpl(String id, String name, String type, URI location, VAppStatus status, long size, public VAppImpl(String id, String name, URI location, VAppStatus status,
Link vDC, Link computeOptions, Link customizationOptions,
ListMultimap<String, InetAddress> networkToAddresses, ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, VirtualSystem system, String operatingSystemDescription, VirtualSystem system,
SortedSet<ResourceAllocation> resourceAllocations) { SortedSet<ResourceAllocation> resourceAllocations) {
super(id, name, type, location); this.id = id;
this.name = name;
this.location = location;
this.status = status; this.status = status;
this.size = size;
this.vDC = vDC;
this.computeOptions = computeOptions;
this.customizationOptions = customizationOptions;
this.networkToAddresses = networkToAddresses; this.networkToAddresses = networkToAddresses;
this.operatingSystemDescription = operatingSystemDescription; this.operatingSystemDescription = operatingSystemDescription;
this.system = system; this.system = system;
@ -81,7 +74,7 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
new Function<ResourceAllocation, ResourceType>() { new Function<ResourceAllocation, ResourceType>() {
@Override @Override
public ResourceType apply(ResourceAllocation from) { public ResourceType apply(ResourceAllocation from) {
return from.getResourceType(); return from.getType();
} }
}); });
} }
@ -90,22 +83,6 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
return status; return status;
} }
public long getSize() {
return size;
}
public Link getVDC() {
return vDC;
}
public Link getComputeOptions() {
return computeOptions;
}
public Link getCustomizationOptions() {
return customizationOptions;
}
public ListMultimap<String, InetAddress> getNetworkToAddresses() { public ListMultimap<String, InetAddress> getNetworkToAddresses() {
return networkToAddresses; return networkToAddresses;
} }
@ -122,13 +99,17 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
return resourceAllocations; return resourceAllocations;
} }
public Map<ResourceType, ResourceAllocation> getResourceAllocationByType() {
return resourceAllocationByType;
}
@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 + ((computeOptions == null) ? 0 : computeOptions.hashCode()); result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result result = prime * result + ((location == null) ? 0 : location.hashCode());
+ ((customizationOptions == null) ? 0 : customizationOptions.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode());
result = prime * result result = prime * result
+ ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); + ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode());
@ -136,10 +117,8 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
+ ((resourceAllocationByType == null) ? 0 : resourceAllocationByType.hashCode()); + ((resourceAllocationByType == null) ? 0 : resourceAllocationByType.hashCode());
result = prime * result result = prime * result
+ ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode());
result = prime * result + (int) (size ^ (size >>> 32));
result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode());
result = prime * result + ((system == null) ? 0 : system.hashCode()); result = prime * result + ((system == null) ? 0 : system.hashCode());
result = prime * result + ((vDC == null) ? 0 : vDC.hashCode());
return result; return result;
} }
@ -147,20 +126,25 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
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;
VAppImpl other = (VAppImpl) obj; VAppImpl other = (VAppImpl) obj;
if (computeOptions == null) { if (id == null) {
if (other.computeOptions != null) if (other.id != null)
return false; return false;
} else if (!computeOptions.equals(other.computeOptions)) } else if (!id.equals(other.id))
return false; return false;
if (customizationOptions == null) { if (location == null) {
if (other.customizationOptions != null) if (other.location != null)
return false; return false;
} else if (!customizationOptions.equals(other.customizationOptions)) } 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;
if (networkToAddresses == null) { if (networkToAddresses == null) {
if (other.networkToAddresses != null) if (other.networkToAddresses != null)
@ -182,8 +166,6 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
return false; return false;
} else if (!resourceAllocations.equals(other.resourceAllocations)) } else if (!resourceAllocations.equals(other.resourceAllocations))
return false; return false;
if (size != other.size)
return false;
if (status == null) { if (status == null) {
if (other.status != null) if (other.status != null)
return false; return false;
@ -194,16 +176,28 @@ public class VAppImpl extends NamedResourceImpl implements VApp {
return false; return false;
} else if (!system.equals(other.system)) } else if (!system.equals(other.system))
return false; return false;
if (vDC == null) {
if (other.vDC != null)
return false;
} else if (!vDC.equals(other.vDC))
return false;
return true; return true;
} }
public Map<ResourceType, ResourceAllocation> getResourceAllocationByType() { public String getId() {
return resourceAllocationByType; return id;
}
public String getName() {
return name;
}
public URI getLocation() {
return location;
}
@Override
public String toString() {
return "VAppImpl [id=" + id + ", location=" + location + ", name=" + name
+ ", networkToAddresses=" + networkToAddresses + ", operatingSystemDescription="
+ operatingSystemDescription + ", resourceAllocationByType="
+ resourceAllocationByType + ", resourceAllocations=" + resourceAllocations
+ ", status=" + status + ", system=" + system + "]";
} }
} }

View File

@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI; import java.net.URI;
import java.util.Map; import java.util.Map;
import org.jclouds.rest.domain.NamedLink; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
@ -50,13 +50,14 @@ public class VDCImpl implements VDC {
private final Capacity memoryCapacity; private final Capacity memoryCapacity;
private final Quota instantiatedVmsQuota; private final Quota instantiatedVmsQuota;
private final Quota deployedVmsQuota; private final Quota deployedVmsQuota;
private final Map<String, NamedLink> availableNetworks; private final Map<String, NamedResource> availableNetworks;
private final Map<String, NamedLink> resourceEntities; private final Map<String, NamedResource> resourceEntities;
public VDCImpl(String id, String name, URI location, String description, Capacity storageCapacity, public VDCImpl(String id, String name, URI location, String description,
Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity,
Quota deployedVmsQuota, Map<String, NamedLink> resourceEntities, Quota instantiatedVmsQuota, Quota deployedVmsQuota,
Map<String, NamedLink> availableNetworks) { Map<String, NamedResource> resourceEntities,
Map<String, NamedResource> availableNetworks) {
this.id = id; this.id = id;
this.name = checkNotNull(name, "name"); this.name = checkNotNull(name, "name");
this.location = checkNotNull(location, "location"); this.location = checkNotNull(location, "location");
@ -85,11 +86,11 @@ public class VDCImpl implements VDC {
return location; return location;
} }
public Map<String, NamedLink> getAvailableNetworks() { public Map<String, NamedResource> getAvailableNetworks() {
return availableNetworks; return availableNetworks;
} }
public Map<String, NamedLink> getResourceEntities() { public Map<String, NamedResource> getResourceEntities() {
return resourceEntities; return resourceEntities;
} }

View File

@ -0,0 +1,44 @@
/**
*
* 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.endpoints.internal;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
/**
* Root path where all vApps exist.
*
* @author Adrian Cole
*
*/
@Retention(value = RetentionPolicy.RUNTIME)
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
@Qualifier
public @interface VAppTemplateRoot {
}

View File

@ -0,0 +1,28 @@
package org.jclouds.vcloud.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot;
import com.google.common.base.Function;
/**
* @author Adrian Cole
*/
@Singleton
public class VAppTemplateIdToUri implements Function<Object, String> {
@Inject
@VAppTemplateRoot
private String vAppTemplateRoot;
public String apply(Object from) {
checkArgument(checkNotNull(from, "from") instanceof String,
"this binder is only valid for String!");
return String.format("%s/%s", vAppTemplateRoot, from);
}
}

View File

@ -0,0 +1,74 @@
package org.jclouds.vcloud.options;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import java.net.URI;
/**
*
* @author Adrian Cole
*
*/
public class InstantiateVAppTemplateOptions {
private String cpuCount;
private String megabytes;
private String network;
public InstantiateVAppTemplateOptions cpuCount(int cpuCount) {
checkArgument(cpuCount >= 1, "cpuCount must be positive");
this.cpuCount = cpuCount + "";
return this;
}
public InstantiateVAppTemplateOptions megabytes(int megabytes) {
checkArgument(megabytes % 512 == 0, "megabytes must be in an increment of 512");
this.megabytes = megabytes + "";
return this;
}
public InstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
this.network = checkNotNull(networkLocation, "networkLocation").toASCIIString();
return this;
}
public String getCpuCount() {
return cpuCount;
}
public String getMegabytes() {
return megabytes;
}
public String getNetwork() {
return network;
}
public static class Builder {
/**
* @see InstantiateVAppTemplateOptions#cpuCount(int)
*/
public static InstantiateVAppTemplateOptions cpuCount(int cpuCount) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.cpuCount(cpuCount);
}
/**
* @see InstantiateVAppTemplateOptions#megabytes(int)
*/
public static InstantiateVAppTemplateOptions megabytes(int megabytes) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.megabytes(megabytes);
}
/**
* @see InstantiateVAppTemplateOptions#inNetwork(URI)
*/
public static InstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.inNetwork(networkLocation);
}
}
}

View File

@ -37,4 +37,8 @@ public interface VCloudConstants {
* automatically renew vcloud token before this interval expires. * automatically renew vcloud token before this interval expires.
*/ */
public static final String PROPERTY_VCLOUD_SESSIONINTERVAL = "jclouds.vcloud.sessioninterval"; public static final String PROPERTY_VCLOUD_SESSIONINTERVAL = "jclouds.vcloud.sessioninterval";
public static final String PROPERTY_VCLOUD_DEFAULTCPUCOUNT = "jclouds.vcloud.defaults.cpucount";
public static final String PROPERTY_VCLOUD_DEFAULTMEMORY = "jclouds.vcloud.defaults.memory";
public static final String PROPERTY_VCLOUD_DEFAULTNETWORK = "jclouds.vcloud.defaults.network";
} }

View File

@ -31,11 +31,11 @@ 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.NamedResource;
import org.jclouds.rest.domain.internal.NamedLinkImpl; import org.jclouds.rest.domain.internal.NamedLinkImpl;
import org.jclouds.rest.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.internal.CatalogImpl; import org.jclouds.vcloud.domain.internal.CatalogImpl;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;

View File

@ -36,9 +36,9 @@ 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.vcloud.domain.NamedResource; import org.jclouds.rest.domain.NamedResource;
import org.jclouds.rest.internal.NamedResourceImpl;
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.VCloudApi; import org.jclouds.vcloud.endpoints.VCloudApi;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;

View File

@ -0,0 +1,103 @@
package org.jclouds.vcloud.xml;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<ResourceAllocation> {
private StringBuilder currentText = new StringBuilder();
Integer address;
Integer addressOnParent;
String allocationUnits;
String automaticAllocation;
Boolean connected;
String description;
String elementName;
int instanceID;
Integer parent;
String resourceSubType;
ResourceType resourceType;
long virtualQuantity = 1;
String virtualQuantityUnits;
private org.jclouds.vcloud.domain.ResourceAllocation allocation;
public org.jclouds.vcloud.domain.ResourceAllocation getResult() {
return allocation;
}
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("rasd:Connection")) {
connected = new Boolean(attributes.getValue(attributes.getIndex("connected")));
} else if (qName.equals("rasd:HostResource")) {
virtualQuantity = Long.parseLong(attributes.getValue(attributes.getIndex("capacity")));
virtualQuantityUnits = "byte * 2^20";
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("rasd:Address")) {
address = Integer.parseInt(currentOrNull());
} else if (qName.equals("rasd:AddressOnParent")) {
addressOnParent = Integer.parseInt(currentOrNull());
} else if (qName.equals("rasd:AllocationUnits")) {
allocationUnits = currentOrNull();
} else if (qName.equals("rasd:Description")) {
description = currentOrNull();
} else if (qName.equals("rasd:ElementName")) {
elementName = currentOrNull();
} else if (qName.equals("rasd:InstanceID")) {
instanceID = Integer.parseInt(currentOrNull());
} else if (qName.equals("rasd:Parent")) {
parent = Integer.parseInt(currentOrNull());
} else if (qName.equals("rasd:ResourceSubType")) {
resourceSubType = currentOrNull();
} else if (qName.equals("rasd:ResourceType")) {
resourceType = ResourceType.fromValue(currentOrNull());
} else if (qName.equals("rasd:VirtualQuantity")) {
virtualQuantity = Long.parseLong(currentOrNull());
} else if (qName.equals("rasd:VirtualQuantityUnits")) {
virtualQuantityUnits = currentOrNull();
} else if (qName.equals("Item")) {
if (allocationUnits != null)
virtualQuantityUnits = allocationUnits;
this.allocation = new ResourceAllocation(instanceID, elementName, description,
resourceType, resourceSubType, address, addressOnParent, parent, connected,
virtualQuantity, virtualQuantityUnits);
address = null;
addressOnParent = null;
allocationUnits = null;
automaticAllocation = null;
connected = null;
description = null;
elementName = null;
instanceID = -1;
parent = null;
resourceSubType = null;
resourceType = null;
virtualQuantity = 1;
virtualQuantityUnits = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
protected String currentOrNull() {
String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal;
}
}

View File

@ -0,0 +1,118 @@
package org.jclouds.vcloud.xml;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.SortedSet;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Sets;
/**
* @author Adrian Cole
*/
public class VAppHandler extends ParseSax.HandlerWithResult<VApp> {
private final VirtualSystemHandler systemHandler;
private final ResourceAllocationHandler allocationHandler;
@Resource
protected Logger logger = Logger.NULL;
@Inject
public VAppHandler(VirtualSystemHandler systemHandler,
ResourceAllocationHandler allocationHandler) {
this.systemHandler = systemHandler;
this.allocationHandler = allocationHandler;
}
protected VirtualSystem system;
protected SortedSet<ResourceAllocation> allocations = Sets.newTreeSet();
protected VAppStatus status;
protected final ListMultimap<String, InetAddress> networkToAddresses = ArrayListMultimap.create();
protected StringBuilder currentText = new StringBuilder();
protected String operatingSystemDescription;
protected boolean inOs;
protected String networkName;
protected String name;
protected String id;
protected URI location;
public VApp getResult() {
return new VAppImpl(id, name, location, status, networkToAddresses,
operatingSystemDescription, system, allocations);
}
public void startElement(String uri, String localName, String qName, Attributes attributes)
throws SAXException {
if (qName.equals("VApp")) {
name = id = attributes.getValue(attributes.getIndex("name"));
location = URI.create(attributes.getValue(attributes.getIndex("href")));
status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
} else if (qName.equals("ovf:OperatingSystemSection")) {
inOs = true;
} else if (qName.equals("NetworkConfig")) {
networkName = attributes.getValue(attributes.getIndex("name"));
} else {
systemHandler.startElement(uri, localName, qName, attributes);
allocationHandler.startElement(uri, localName, qName, attributes);
}
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("ovf:OperatingSystemSection")) {
inOs = false;
} else if (inOs && qName.equals("Description")) {
operatingSystemDescription = currentText.toString().trim();
} else if (qName.equals("IPAddress")) {
networkToAddresses.put(networkName, parseInetAddress(currentText.toString().trim()));
} else if (qName.equals("System")) {
systemHandler.endElement(uri, localName, qName);
system = systemHandler.getResult();
} else if (qName.equals("Item")) {
allocationHandler.endElement(uri, localName, qName);
allocations.add(allocationHandler.getResult());
} else {
systemHandler.endElement(uri, localName, qName);
allocationHandler.endElement(uri, localName, qName);
}
currentText = new StringBuilder();
}
@Override
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
systemHandler.characters(ch, start, length);
allocationHandler.characters(ch, start, length);
}
private InetAddress parseInetAddress(String string) {
String[] byteStrings = string.split("\\.");
byte[] bytes = new byte[4];
for (int i = 0; i < 4; i++) {
bytes[i] = (byte) Integer.parseInt(byteStrings[i]);
}
try {
return InetAddress.getByAddress(bytes);
} catch (UnknownHostException e) {
logger.warn(e, "error parsing ipAddress", currentText);
}
return null;
}
}

View File

@ -23,22 +23,17 @@
*/ */
package org.jclouds.vcloud.xml; package org.jclouds.vcloud.xml;
import static org.jclouds.rest.util.Utils.putNamedLink; import static org.jclouds.rest.util.Utils.newNamedResource;
import static org.jclouds.rest.util.Utils.putNamedResource;
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.NamedResource;
import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.NamedResource;
import org.jclouds.vcloud.domain.Quota; 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.VCloudApi;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -51,11 +46,8 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
private NamedResource vDC; private NamedResource vDC;
private Map<String, NamedLink> resourceEntities = Maps.newHashMap(); private Map<String, NamedResource> resourceEntities = Maps.newHashMap();
private Map<String, NamedLink> availableNetworks = Maps.newHashMap(); private Map<String, NamedResource> availableNetworks = Maps.newHashMap();
@Inject
@VCloudApi
URI vcloudUri;
private String description; private String description;
@ -89,9 +81,9 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
if (qName.equals("Vdc")) { if (qName.equals("Vdc")) {
vDC = newNamedResource(attributes); vDC = newNamedResource(attributes);
} else if (qName.equals("Network")) { } else if (qName.equals("Network")) {
putNamedLink(availableNetworks, attributes); putNamedResource(availableNetworks, attributes);
} else if (qName.equals("ResourceEntity")) { } else if (qName.equals("ResourceEntity")) {
putNamedLink(resourceEntities, attributes); putNamedResource(resourceEntities, attributes);
} }
} }
@ -124,13 +116,6 @@ public class VDCHandler extends ParseSax.HandlerWithResult<VDC> {
currentText.append(ch, start, length); currentText.append(ch, start, length);
} }
public NamedResource newNamedResource(Attributes attributes) {
return new NamedResourceImpl(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() { protected String currentOrNull() {
String returnVal = currentText.toString().trim(); String returnVal = currentText.toString().trim();
return returnVal.equals("") ? null : returnVal; return returnVal.equals("") ? null : returnVal;

View File

@ -0,0 +1,50 @@
package org.jclouds.vcloud.xml;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class VirtualSystemHandler extends ParseSax.HandlerWithResult<VirtualSystem> {
private StringBuilder currentText = new StringBuilder();
private String elementName;
private int instanceID;
private String virtualSystemIdentifier;
private String virtualSystemType;
private org.jclouds.vcloud.domain.VirtualSystem system;
public org.jclouds.vcloud.domain.VirtualSystem getResult() {
return system;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("rasd:ElementName")) {
this.elementName = currentText.toString().trim();
} else if (qName.equals("rasd:InstanceID")) {
this.instanceID = Integer.parseInt(currentText.toString().trim());
} else if (qName.equals("rasd:VirtualSystemIdentifier")) {
this.virtualSystemIdentifier = currentText.toString().trim();
} else if (qName.equals("rasd:VirtualSystemType")) {
this.virtualSystemType = currentText.toString().trim();
} else if (qName.equals("System")) {
this.system = new org.jclouds.vcloud.domain.VirtualSystem(instanceID, elementName,
virtualSystemIdentifier, virtualSystemType);
this.elementName = null;
this.instanceID = -1;
this.virtualSystemIdentifier = null;
this.virtualSystemType = null;
}
currentText = new StringBuilder();
}
public void characters(char ch[], int start, int length) {
currentText.append(ch, start, length);
}
}

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<InstantiateVAppTemplateParams name="{name}"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd">
<VAppTemplate href="{template}" />
<InstantiationParams xmlns:vmw="http://www.vmware.com/schema/ovf">
<NetworkConfigSection>
<NetworkConfig name="{name}">
<Features>
<vmw:FenceMode>allowInOut</vmw:FenceMode>
<vmw:Dhcp>false</vmw:Dhcp>
</Features>
<NetworkAssociation href="{network}" />
</NetworkConfig>
</NetworkConfigSection>
</InstantiationParams>
</InstantiateVAppTemplateParams>

View File

@ -48,6 +48,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.CatalogHandler;
import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TaskHandler;
import org.jclouds.vcloud.xml.TasksListHandler; import org.jclouds.vcloud.xml.TasksListHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VDCHandler; import org.jclouds.vcloud.xml.VDCHandler;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -56,12 +57,12 @@ import com.google.inject.Module;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code VCloudClient} * Tests behavior of {@code VCloudAsyncClient}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.VCloudClientTest") @Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest")
public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> { public class VCloudAsyncClientTest extends RestClientTest<VCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getCatalog"); Method method = VCloudAsyncClient.class.getMethod("getCatalog");
@ -70,7 +71,7 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1"); assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1");
assertHeadersEqual( assertHeadersEqual(
httpMethod, httpMethod,
"Accept: application/vnd.vmware.vcloud.catalog+xml\nContent-Type: application/vnd.vmware.vcloud.catalog+xml\n"); "Accept: application/vnd.vmware.vcloud.catalog+xml\n");
assertEntityEquals(httpMethod, null); assertEntityEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class); assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
@ -126,6 +127,21 @@ public class VCloudClientTest extends RestClientTest<VCloudAsyncClient> {
checkFilters(httpMethod); checkFilters(httpMethod);
} }
public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);
assertRequestLineEquals(httpMethod, "GET http://vcloud/vapp/1 HTTP/1.1");
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vApp+xml\n");
assertEntityEquals(httpMethod, null);
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
assertSaxResponseParserClassEquals(method, VAppHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException {
Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class); Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class);
GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1); GeneratedHttpRequest<VCloudAsyncClient> httpMethod = processor.createRequest(method, 1);

View File

@ -30,8 +30,10 @@ import static org.testng.Assert.assertNotNull;
import java.net.URI; import java.net.URI;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rest.domain.NamedResource;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -81,16 +83,19 @@ public class VCloudClientLiveTest {
assertNotNull(response.getLocation()); assertNotNull(response.getLocation());
assertNotNull(response.getTasks()); assertNotNull(response.getTasks());
for (Task t : response.getTasks()) { for (Task t : response.getTasks()) {
assertEquals(connection.getTask(t.getLocation()).getLocation(), assertEquals(connection.getTask(t.getLocation()).getLocation(), t.getLocation());
t.getLocation());
} }
} }
@Test(enabled = false) @Test(enabled = true)
public void testGetVApp() throws Exception { public void testGetVApp() throws Exception {
String response = connection.getVAppString("188849-2"); VDC response = connection.getDefaultVDC();
assertNotNull(response); for (NamedResource item : response.getResourceEntities().values()) {
System.out.println(response); if (item.getType().equals(VCloudMediaType.VAPP_XML)) {
VApp app = connection.getVApp(item.getId());
assertNotNull(app);
}
}
} }
@BeforeGroups(groups = { "live" }) @BeforeGroups(groups = { "live" })

View File

@ -0,0 +1,228 @@
/**
*
* 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;
import static com.google.common.base.Preconditions.checkArgument;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.logging.Logger;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public class VCloudComputeClient {
@Resource
protected Logger logger = Logger.NULL;
private final Predicate<InetSocketAddress> socketTester;
private final Predicate<URI> taskTester;
private final VCloudClient tmClient;
@Inject
public VCloudComputeClient(VCloudClient tmClient, Factory sshFactory,
Predicate<InetSocketAddress> socketTester, Predicate<URI> successTester) {
this.tmClient = tmClient;
this.sshFactory = sshFactory;
this.socketTester = socketTester;
this.taskTester = successTester;
}
private final Factory sshFactory;
public enum Image {
CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS
}
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(
Image.UMBUNTU_JEOS, "11").build();
private String username;
private String password;
public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
String templateId = imageCatalogIdMap.get(image);
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
minCores, minMegs, templateId);
VApp vAppResponse = tmClient.instantiateVAppTemplate(name, templateId,
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
tmClient.getVApp(vAppResponse.getId());
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
logger.debug(">> deploying vApp(%s)", vAppResponse.getId());
VApp vApp = blockUntilVAppStatusOrThrowException(vAppResponse, tmClient
.deployVApp(vAppResponse.getId()), "deploy", VAppStatus.OFF);
logger.debug("<< deployed vApp(%s)", vApp.getId());
logger.debug(">> powering vApp(%s)", vApp.getId());
vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()),
"powerOn", VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
return vApp.getId();
}
/**
*
* @throws ElementNotFoundException
* if no address is configured
*/
public InetAddress getAnyPrivateAddress(String id) {
VApp vApp = tmClient.getVApp(id);
return Iterables.getLast(vApp.getNetworkToAddresses().values());
}
public ExecResponse exec(InetAddress address, String command) {
InetSocketAddress sshSocket = new InetSocketAddress(address, 22);
logger.debug(">> exec ssh://%s@%s/%s", username, sshSocket, command);
ExecResponse exec = exec(sshSocket, username, password, command);
logger.debug("<< output(%s) error(%s)", exec.getOutput(), exec.getError());
return exec;
}
public void reboot(String id) {
VApp vApp = tmClient.getVApp(id);
logger.debug(">> rebooting vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset",
VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
}
public void stop(String id) {
VApp vApp = tmClient.getVApp(id);
if (vApp.getStatus() != VAppStatus.OFF) {
logger.debug(">> powering off vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
"powerOff", VAppStatus.OFF);
logger.debug("<< off vApp(%s)", vApp.getId());
}
logger.debug(">> deleting vApp(%s)", vApp.getId());
tmClient.deleteVApp(id);
logger.debug("<< deleted vApp(%s)", vApp.getId());
}
private ExecResponse exec(InetSocketAddress socket, String username, String password,
String command) {
if (!socketTester.apply(socket)) {
throw new SocketNotOpenException(socket);
}
SshClient connection = sshFactory.create(socket, username, password);
try {
connection.connect();
return connection.exec(command);
} finally {
if (connection != null)
connection.disconnect();
}
}
private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType,
VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getLocation())) {
throw new TaskException(taskType, vApp, deployTask);
}
vApp = tmClient.getVApp(vApp.getId());
if (vApp.getStatus() != expectedStatus) {
throw new VAppException(String.format("vApp %s status %s should be %s after %s", vApp
.getId(), vApp.getStatus(), expectedStatus, taskType), vApp);
}
return vApp;
}
public static class TaskException extends VAppException {
private final Task task;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type,
vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
}
public Task getTask() {
return task;
}
}
public static class SocketNotOpenException extends RuntimeException {
private final InetSocketAddress socket;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public SocketNotOpenException(InetSocketAddress socket) {
super("socket not open: " + socket);
this.socket = socket;
}
public InetSocketAddress getSocket() {
return socket;
}
}
public static class VAppException extends RuntimeException {
private final VApp vApp;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, VApp vApp) {
super(message);
this.vApp = vApp;
}
public VApp getvApp() {
return vApp;
}
}
}

View File

@ -0,0 +1,193 @@
/**
*
* 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;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.AddressReachable;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.VCloudComputeClient.Image;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.ImmutableMap;
/**
* Tests behavior of {@code VCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.VCloudClientLiveTest")
public class VCloudComputeClientLiveTest {
VCloudComputeClient client;
VCloudClient tmClient;
private String id;
private InetAddress privateAddress;
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
private static class Expectation {
final long hardDisk;
final String os;
public Expectation(long hardDisk, String os) {
this.hardDisk = hardDisk;
this.os = os;
}
}
private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder()
.put(Image.CENTOS_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.RHEL_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
private Predicate<InetAddress> addressTester;
@Test
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
Image toTest = Image.CENTOS_53;
String serverName = getCompatibleServerName(toTest);
int processorCount = 1;
int memory = 512;
id = client.start(serverName, processorCount, memory, toTest);
Expectation expectation = expectationMap.get(toTest);
VApp vApp = tmClient.getVApp(id);
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
expectation.hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.ON);
}
private String getCompatibleServerName(Image toTest) {
String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0,
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
return serverName;
}
@Test(dependsOnMethods = "testPowerOn")
public void testGetAnyPrivateAddress() {
privateAddress = client.getAnyPrivateAddress(id);
assert !addressTester.apply(privateAddress);
}
@Test(dependsOnMethods = "testGetAnyPrivateAddress")
public void testSshLoadBalanceIp() {
// assert addressTester.apply(publicIp);
client.exec(privateAddress, "uname -a");
}
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)
.getVirtualQuantity(), processorCount);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
.getVirtualQuantity(), 1);
assertEquals(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
memory);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.getVirtualQuantity(), hardDisk);
}
@AfterTest
void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
if (id != null)
client.stop(id);
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
String endpoint = checkNotNull(System.getProperty("jclouds.test.endpoint"),
"jclouds.test.endpoint");
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new VCloudContextBuilder(new VCloudPropertiesBuilder(
URI.create(endpoint), account, key).relaxSSLHostname().build()).withModules(
new Log4JLoggingModule(), new JschSshClientModule(), new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetSocketAddress> socketTester(SocketOpen open) {
return new RetryablePredicate<InetSocketAddress>(open, 130, 10,
TimeUnit.SECONDS);// make it longer then
// default internet
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetAddress> addressTester(AddressReachable reachable) {
return new RetryablePredicate<InetAddress>(reachable, 60, 5, TimeUnit.SECONDS);
}
@SuppressWarnings("unused")
@Provides
private Predicate<URI> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS);
}
}).buildInjector();
client = injector.getInstance(VCloudComputeClient.class);
tmClient = injector.getInstance(VCloudClient.class);
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
}));
}
}

View File

@ -0,0 +1,93 @@
package org.jclouds.vcloud.binders;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.Collections;
import java.util.Map;
import javax.inject.Named;
import javax.inject.Singleton;
import javax.ws.rs.core.HttpHeaders;
import org.apache.commons.io.IOUtils;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import com.google.inject.util.Providers;
/**
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlEntity}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlEntityTest")
public class BindInstantiateVAppTemplateParamsToXmlEntityTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT))
.toProvider(Providers.<String> of(null));
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider(
Providers.<String> of(null));
bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)).toProvider(
Providers.<String> of(null));
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Named("InstantiateVAppTemplateParams")
String provideInstantiateVAppTemplateParams() throws IOException {
InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml");
return Utils.toStringAndClose(is);
}
});
public void testApplyInputStream() throws IOException {
String expected = IOUtils.toString(getClass().getResourceAsStream("/newvapp-hosting.xml"));
Multimap<String, String> headers = Multimaps.synchronizedMultimap(HashMultimap
.<String, String> create());
GeneratedHttpRequest<?> request = createMock(GeneratedHttpRequest.class);
expect(request.getEndpoint()).andReturn(URI.create("http://localhost/key")).anyTimes();
expect(request.getArgs()).andReturn(new Object[] {}).atLeastOnce();
expect(request.getFirstHeaderOrNull("Content-Type")).andReturn(null).atLeastOnce();
expect(request.getHeaders()).andReturn(headers).atLeastOnce();
request.setEntity(expected);
replay(request);
BindInstantiateVAppTemplateParamsToXmlEntity binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class);
Map<String, String> map = Maps.newHashMap();
map.put("name", "CentOS 01");
map.put("template", "https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3");
map.put("count", "1");
map.put("megabytes", "512");
map.put("network", "https://vcloud.safesecureweb.com/network/1990");
binder.bindToRequest(request, map);
assertEquals(headers.get(HttpHeaders.CONTENT_TYPE), Collections
.singletonList("application/unknown"));
assertEquals(headers.get(HttpHeaders.CONTENT_LENGTH), Collections.singletonList("901"));
}
}

View File

@ -0,0 +1,53 @@
package org.jclouds.vcloud.config;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.util.Jsr330;
import org.jclouds.util.Utils;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Key;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VCloudRestClientModuleTest")
public class VCloudRestClientModuleTest {
protected Injector createInjector() {
return Guice.createInjector(new VCloudRestClientModule(),
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_VERSION)).to("0.8");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to(
"http://localhost");
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL))
.to("2");
}
});
}
@Test
void postStrings() throws IOException {
assertEquals(createInjector().getInstance(
Key.get(String.class, Jsr330.named("InstantiateVAppTemplateParams"))), Utils
.toStringAndClose(getClass().getResourceAsStream(
"/InstantiateVAppTemplateParams.xml")));
}
}

View File

@ -0,0 +1,69 @@
package org.jclouds.vcloud.options;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.cpuCount;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.inNetwork;
import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.megabytes;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code InstantiateVAppTemplateOptions}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.InstantiateVAppTemplateOptionsTest")
public class InstantiateVAppTemplateOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
@Test
public void testInNetwork() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.inNetwork(URI.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}
@Test
public void testInNetworkStatic() {
InstantiateVAppTemplateOptions options = inNetwork(URI.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}
@Test
public void testCpuCount() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.cpuCount(3);
assertEquals(options.getCpuCount(), "3");
}
@Test
public void testCpuCountStatic() {
InstantiateVAppTemplateOptions options = cpuCount(3);
assertEquals(options.getCpuCount(), "3");
}
@Test
public void testMegabytes() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.megabytes(512);
assertEquals(options.getMegabytes(), "512");
}
@Test
public void testMegabytesStatic() {
InstantiateVAppTemplateOptions options = megabytes(512);
assertEquals(options.getMegabytes(), "512");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMegabytesStaticWrong() {
megabytes(511);
}
}

View File

@ -32,8 +32,8 @@ import java.net.URI;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Catalog;
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.Test; import org.testng.annotations.Test;

View File

@ -0,0 +1,55 @@
/**
*
* 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.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code ResourceAllocationHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.ResourceAllocationHandlerTest")
public class ResourceAllocationHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/resourceallocation-hosting.xml");
ResourceAllocation result = factory.create(
injector.getInstance(ResourceAllocationHandler.class)).parse(is);
ResourceAllocation expects = new ResourceAllocation(1, "1 virtual CPU(s)",
"Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, 1,
"hertz * 10^6");
assertEquals(result, expects);
}
}

View File

@ -0,0 +1,93 @@
/**
*
* 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.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.SortedSet;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.ListMultimap;
/**
* Tests behavior of {@code VAppHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VAppHandlerTest")
public class VAppHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/vapp-hosting.xml");
VApp result = factory.create(injector.getInstance(VAppHandler.class)).parse(is);
ListMultimap<String, InetAddress> networkToAddresses = ImmutableListMultimap
.<String, InetAddress> of("eth0", InetAddress.getByName("204.12.42.207"));
VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-04");
SortedSet<ResourceAllocation> resourceAllocations = ImmutableSortedSet
.<ResourceAllocation> naturalOrder().add(
new ResourceAllocation(1, "1 virtual CPU(s)", "Number of Virtual CPUs",
ResourceType.PROCESSOR, null, null, null, null, null, 1,
"hertz * 10^6"),
new ResourceAllocation(2, "512MB of memory", "Memory Size",
ResourceType.MEMORY, null, null, null, null, null, 1536,
"byte * 2^20")).add(
new ResourceAllocation(3, "SCSI Controller 0", "SCSI Controller",
ResourceType.SCSI_CONTROLLER, "lsilogic", 0, null, null, null, 1,
null)).add(
new ResourceAllocation(8, "Network Adapter 1",
"PCNet32 ethernet adapter on \"VLAN 536\" network",
ResourceType.ETHERNET_ADAPTER, "PCNet32", null, 7, null, true, 1,
null)).add(
new ResourceAllocation(9, "Hard Disk 1", null, ResourceType.OTHER, null,
null, 0, 3, null, 20971520, "byte * 2^20")).build();
VApp expects = new VAppImpl("188849-2", "188849-2", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-2"), VAppStatus.OFF,
networkToAddresses, "", system, resourceAllocations);
assertEquals(result, expects);
}
}

View File

@ -32,7 +32,7 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.ParseSax.Factory;
import org.jclouds.http.functions.config.ParserModule; 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.internal.NamedResourceImpl;
import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
@ -86,7 +86,8 @@ public class VDCHandlerTest {
ImmutableMap ImmutableMap
.of( .of(
"10.114.34.128/26", "10.114.34.128/26",
new NamedLinkImpl( new NamedResourceImpl(
"1708",
"10.114.34.128/26", "10.114.34.128/26",
"application/vnd.vmware.vcloud.network+xml", "application/vnd.vmware.vcloud.network+xml",
URI URI
@ -125,7 +126,8 @@ public class VDCHandlerTest {
new ImmutableMap.Builder<String, NamedLink>() new ImmutableMap.Builder<String, NamedLink>()
.put( .put(
"Plesk (Linux) 64-bit Template", "Plesk (Linux) 64-bit Template",
new NamedLinkImpl( new NamedResourceImpl(
"1",
"Plesk (Linux) 64-bit Template", "Plesk (Linux) 64-bit Template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI URI
@ -133,35 +135,40 @@ public class VDCHandlerTest {
.put( .put(
"Windows 2008 Datacenter 64 Bit Template", "Windows 2008 Datacenter 64 Bit Template",
new NamedLinkImpl( new NamedResourceImpl(
"2",
"Windows 2008 Datacenter 64 Bit Template", "Windows 2008 Datacenter 64 Bit Template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2"))) .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2")))
.put( .put(
"Cent OS 64 Bit Template", "Cent OS 64 Bit Template",
new NamedLinkImpl( new NamedResourceImpl(
"3",
"Cent OS 64 Bit Template", "Cent OS 64 Bit Template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"))) .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3")))
.put( .put(
"cPanel (Linux) 64 Bit Template", "cPanel (Linux) 64 Bit Template",
new NamedLinkImpl( new NamedResourceImpl(
"4",
"cPanel (Linux) 64 Bit Template", "cPanel (Linux) 64 Bit Template",
"application/vnd.vmware.vcloud.vAppTemplate+xml", "application/vnd.vmware.vcloud.vAppTemplate+xml",
URI URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4"))) .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4")))
.put( .put(
"188849-1", "188849-1",
new NamedLinkImpl( new NamedResourceImpl(
"188849-1",
"188849-1", "188849-1",
"application/vnd.vmware.vcloud.vApp+xml", "application/vnd.vmware.vcloud.vApp+xml",
URI URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1"))) .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1")))
.put( .put(
"188849-2", "188849-2",
new NamedLinkImpl( new NamedResourceImpl(
"188849-2",
"188849-2", "188849-2",
"application/vnd.vmware.vcloud.vApp+xml", "application/vnd.vmware.vcloud.vApp+xml",
URI URI

View File

@ -0,0 +1,52 @@
/**
*
* 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.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.testng.annotations.Test;
/**
* Tests behavior of {@code VirtualSystemHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.VirtualSystemHandlerTest")
public class VirtualSystemHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/virtualsystem-hosting.xml");
VirtualSystem result = factory.create(injector.getInstance(VirtualSystemHandler.class))
.parse(is);
VirtualSystem expects = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-04");
assertEquals(result, expects);
}
}

View File

@ -146,13 +146,13 @@
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category> </category>
<!--
<category name="jclouds.http.wire"> <category name="jclouds.http.wire">
<priority value="DEBUG" /> <priority value="DEBUG" />
<appender-ref ref="ASYNCWIRE" /> <appender-ref ref="ASYNCWIRE" />
</category> </category>
--><!-- ======================= --> <!-- ======================= -->
<!-- Setup the Root category --> <!-- Setup the Root category -->
<!-- ======================= --> <!-- ======================= -->

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<InstantiateVAppTemplateParams name="CentOS 01"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8 http://vcloud.safesecureweb.com/ns/vcloud.xsd">
<VAppTemplate href="https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3" />
<InstantiationParams xmlns:vmw="http://www.vmware.com/schema/ovf">
<NetworkConfigSection>
<NetworkConfig name="CentOS 01">
<Features>
<vmw:FenceMode>allowInOut</vmw:FenceMode>
<vmw:Dhcp>false</vmw:Dhcp>
</Features>
<NetworkAssociation href="https://vcloud.safesecureweb.com/network/1990" />
</NetworkConfig>
</NetworkConfigSection>
</InstantiationParams>
</InstantiateVAppTemplateParams>

View File

@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-2"
name="188849-2" status="2" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/vapp.xsd"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Item>
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>count</rasd:VirtualQuantityUnits>
</Item>
</VApp>

View File

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-2"
name="188849-2" status="2" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/vapp.xsd"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns="http://www.vmware.com/vcloud/v0.8"
xmlns:vmw="http://www.vmware.com/schema/ovf"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:rasd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NetworkSection>
<ovf:Info>The list of logical networks</ovf:Info>
<Network ovf:name="eth0" network="VLAN 536" />
</NetworkSection>
<NetworkConfigSection
href="https://vcloud.safesecureweb.com/api/v0.8/networkConfigSection/1">
<NetworkConfig name="eth0">
<Features>
<vmw:FenceMode>bridged</vmw:FenceMode>
<vmw:Dhcp>false</vmw:Dhcp>
</Features>
<vmw:NetworkAssociation
href="https://vcloud.safesecureweb.com/api/v0.8/network"
type="application/vnd.vmware.vcloud.network+xml" name="eth0" />
</NetworkConfig>
</NetworkConfigSection>
<NetworkConnectionSection>
<NetworkConnection name="eth0">
<IPAddress>204.12.42.207</IPAddress>
<VMWareNetwork>VLAN 536</VMWareNetwork>
</NetworkConnection>
</NetworkConnectionSection>
<ovf:OperatingSystemSection ovf:id="" vmw:osType="">
<!-- Configuration links. -->
<ovf:Info>The kind of installed guest operating system</ovf:Info>
<Description></Description>
</ovf:OperatingSystemSection>
<ovf:VirtualHardwareSection ovf:transport="iso">
<!-- Configuration links -->
<ovf:Info>Virtual hardware</ovf:Info>
<System>
<rasd:ElementName>Virtual Hardware Family</rasd:ElementName>
<rasd:InstanceID>0</rasd:InstanceID>
<rasd:VirtualSystemIdentifier>SimpleVM</rasd:VirtualSystemIdentifier>
<rasd:VirtualSystemType>vmx-04</rasd:VirtualSystemType>
</System>
<Item>
<rasd:AllocationUnits>hertz * 10^6</rasd:AllocationUnits>
<rasd:Description>Number of Virtual CPUs</rasd:Description>
<rasd:ElementName>1 virtual CPU(s)</rasd:ElementName>
<rasd:InstanceID>1</rasd:InstanceID>
<rasd:ResourceType>3</rasd:ResourceType>
<rasd:VirtualQuantity>1</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>count</rasd:VirtualQuantityUnits>
</Item>
<Item>
<rasd:AllocationUnits>byte * 2^20</rasd:AllocationUnits>
<rasd:Description>Memory Size</rasd:Description>
<rasd:ElementName>512MB of memory</rasd:ElementName>
<rasd:InstanceID>2</rasd:InstanceID>
<rasd:ResourceType>4</rasd:ResourceType>
<rasd:VirtualQuantity>1536</rasd:VirtualQuantity>
<rasd:VirtualQuantityUnits>byte * 2^20</rasd:VirtualQuantityUnits>
</Item>
<Item>
<rasd:Address>0</rasd:Address>
<rasd:Description>SCSI Controller</rasd:Description>
<rasd:ElementName>SCSI Controller 0</rasd:ElementName>
<rasd:InstanceID>3</rasd:InstanceID>
<rasd:ResourceSubType>lsilogic</rasd:ResourceSubType>
<rasd:ResourceType>6</rasd:ResourceType>
</Item>
<Item>
<rasd:AddressOnParent>7</rasd:AddressOnParent>
<rasd:AutomaticAllocation>true</rasd:AutomaticAllocation>
<rasd:Connection connected="true">eth0</rasd:Connection>
<rasd:Description>PCNet32 ethernet adapter on "VLAN 536" network</rasd:Description>
<rasd:ElementName>Network Adapter 1</rasd:ElementName>
<rasd:InstanceID>8</rasd:InstanceID>
<rasd:ResourceSubType>PCNet32</rasd:ResourceSubType>
<rasd:ResourceType>10</rasd:ResourceType>
</Item>
<Item>
<rasd:AddressOnParent>0</rasd:AddressOnParent>
<rasd:ElementName>Hard Disk 1</rasd:ElementName>
<rasd:HostResource capacity="20971520" />
<rasd:InstanceID>9</rasd:InstanceID>
<rasd:Parent>3</rasd:Parent>
<rasd:ResourceType>1</rasd:ResourceType>
</Item>
</ovf:VirtualHardwareSection>
</VApp>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp href="https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-2"
name="188849-2" status="2" xsi:schemaLocation="http://www.vmware.com/vcloud/v0.8/vapp.xsd"
xmlns:vssd="http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_VirtualSystemSettingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<System>
<rasd:ElementName>Virtual Hardware Family</rasd:ElementName>
<rasd:InstanceID>0</rasd:InstanceID>
<rasd:VirtualSystemIdentifier>SimpleVM</rasd:VirtualSystemIdentifier>
<rasd:VirtualSystemType>vmx-04</rasd:VirtualSystemType>
</System>
</VApp>

View File

@ -0,0 +1,94 @@
/**
*
* 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.hostingdotcom;
import static org.jclouds.vcloud.VCloudMediaType.CATALOG_XML;
import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML;
import java.util.concurrent.Future;
import javax.ws.rs.Consumes;
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.MapBinder;
import org.jclouds.rest.annotations.MapEntityParam;
import org.jclouds.rest.annotations.ParamParser;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.XMLResponseParser;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlEntity;
import org.jclouds.vcloud.domain.Catalog;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.VAppTemplateIdToUri;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.hostingdotcom.xml.HostingDotComVAppHandler;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.xml.CatalogHandler;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@RequestFilters(SetVCloudTokenCookie.class)
public interface HostingDotComVCloudAsyncClient extends VCloudAsyncClient {
@GET
@Endpoint(org.jclouds.vcloud.endpoints.Catalog.class)
@Consumes(CATALOG_XML)
@Produces(CATALOG_XML)
// produces is incorrect, but required for hosting.com to operate
@XMLResponseParser(CatalogHandler.class)
@Override
Future<? extends Catalog> getCatalog();
@GET
@Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}")
@XMLResponseParser(HostingDotComVAppHandler.class)
@Override
Future<? extends HostingDotComVApp> getVApp(@PathParam("vAppId") String appId);
@POST
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@Path("/action/instantiateVAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@Consumes(VAPP_XML)
// required for hosting.com to operate
@XMLResponseParser(HostingDotComVAppHandler.class)
@MapBinder(BindInstantiateVAppTemplateParamsToXmlEntity.class)
@Override
Future<? extends HostingDotComVApp> instantiateVAppTemplate(
@MapEntityParam("name") String appName,
@MapEntityParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options);
}

View File

@ -0,0 +1,50 @@
/**
*
* 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.hostingdotcom;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
/**
* Provides access to VCloud resources via their REST API.
* <p/>
*
* @see <a href="https://community.vcloudexpress.terremark.com/en-us/discussion_forums/f/60.aspx" />
* @author Adrian Cole
*/
@Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
public interface HostingDotComVCloudClient extends VCloudClient {
@Override
HostingDotComVApp instantiateVAppTemplate(String appName, String templateId,
InstantiateVAppTemplateOptions... options);
@Override
HostingDotComVApp getVApp(String vAppId);
}

View File

@ -0,0 +1,86 @@
/**
*
* 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.hostingdotcom;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ExecutorService;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.logging.jdk.config.JDKLoggingModule;
import org.jclouds.rest.RestContext;
import org.jclouds.rest.RestContextBuilder;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.config.VCloudContextModule;
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule;
import com.google.inject.Module;
import com.google.inject.TypeLiteral;
/**
* Creates {@link RestContext} for {@link VCloudAsyncClient} instances based on the most commonly
* requested arguments.
* <p/>
* Note that Threadsafe objects will be bound as singletons to the Injector or Context provided.
* <p/>
* <p/>
* If no <code>Module</code>s are specified, the default {@link JDKLoggingModule logging} and
* {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed.
*
* @author Adrian Cole
* @see RestContext
* @see VCloudAsyncClient
*/
public class HostingDotComVCloudContextBuilder extends
RestContextBuilder<HostingDotComVCloudAsyncClient, HostingDotComVCloudClient> {
public HostingDotComVCloudContextBuilder(Properties props) {
super(new TypeLiteral<HostingDotComVCloudAsyncClient>() {
}, new TypeLiteral<HostingDotComVCloudClient>() {
}, props);
}
@Override
protected void addClientModule(List<Module> modules) {
modules.add(new VCloudDiscoveryRestClientModule());
modules.add(new HostingDotComVCloudRestClientModule());
}
@Override
protected void addContextModule(List<Module> modules) {
modules.add(new VCloudContextModule());
}
@Override
public HostingDotComVCloudContextBuilder withExecutorService(ExecutorService service) {
return (HostingDotComVCloudContextBuilder) super.withExecutorService(service);
}
@Override
public HostingDotComVCloudContextBuilder withModules(Module... modules) {
return (HostingDotComVCloudContextBuilder) super.withModules(modules);
}
}

View File

@ -0,0 +1,56 @@
/**
*
* 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.hostingdotcom;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
import java.net.URI;
import java.util.Properties;
import org.jclouds.vcloud.VCloudPropertiesBuilder;
/**
* Builds properties used in hosting.com VCloud Clients
*
* @author Adrian Cole
*/
public class HostingDotComVCloudPropertiesBuilder extends VCloudPropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_VCLOUD_ENDPOINT, "https://vcloud.safesecureweb.com/api");
properties.setProperty(PROPERTY_VCLOUD_DEFAULTNETWORK,
"https://vcloud.safesecureweb.com/network/1990");
return properties;
}
public HostingDotComVCloudPropertiesBuilder(Properties properties) {
super(properties);
}
public HostingDotComVCloudPropertiesBuilder(String id, String secret) {
super(URI.create("https://vcloud.safesecureweb.com/api"), id, secret);
}
}

View File

@ -0,0 +1,54 @@
package org.jclouds.vcloud.hostingdotcom.config;
import java.net.URI;
import javax.inject.Singleton;
import org.jclouds.concurrent.internal.SyncProxy;
import org.jclouds.http.RequiresHttp;
import org.jclouds.rest.ConfiguresRestClient;
import org.jclouds.rest.RestClientFactory;
import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.config.VCloudRestClientModule;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient;
import com.google.inject.Provides;
/**
* Configures the VCloud authentication service connection, including logging and http transport.
*
* @author Adrian Cole
*/
@RequiresHttp
@ConfiguresRestClient
public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule {
@Provides
@Singleton
protected HostingDotComVCloudAsyncClient provideHostingDotComVCloudAsyncClient(VCloudAsyncClient in) {
return (HostingDotComVCloudAsyncClient) in;
}
@Override
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(HostingDotComVCloudAsyncClient.class);
}
@Provides
@Singleton
protected HostingDotComVCloudClient provideHostingDotComVCloudClient(VCloudClient in) {
return (HostingDotComVCloudClient) in;
}
@Override
public VCloudClient provideClient(VCloudAsyncClient client) throws IllegalArgumentException,
SecurityException, NoSuchMethodException {
return SyncProxy.create(HostingDotComVCloudClient.class, client);
}
@Override
protected URI provideDefaultNetwork(VCloudAsyncClient client) {
return URI.create("https://vcloud.safesecureweb.com/network/1990");
}
}

View File

@ -0,0 +1,17 @@
package org.jclouds.vcloud.hostingdotcom.domain;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@ImplementedBy(HostingDotComVAppImpl.class)
public interface HostingDotComVApp extends VApp {
String getUsername();
String getPassword();
}

View File

@ -0,0 +1,79 @@
package org.jclouds.vcloud.hostingdotcom.domain.internal;
import java.net.InetAddress;
import java.net.URI;
import java.util.SortedSet;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.VirtualSystem;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import com.google.common.collect.ListMultimap;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class HostingDotComVAppImpl extends VAppImpl implements HostingDotComVApp {
private final String username;
private final String password;;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public HostingDotComVAppImpl(String id, String name, URI location, VAppStatus status,
ListMultimap<String, InetAddress> networkToAddresses, String operatingSystemDescription,
VirtualSystem system, SortedSet<ResourceAllocation> resourceAllocations,
String username, String password) {
super(id, name, location, status, networkToAddresses, operatingSystemDescription, system,
resourceAllocations);
this.username = username;
this.password = password;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((password == null) ? 0 : password.hashCode());
result = prime * result + ((username == null) ? 0 : username.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
HostingDotComVAppImpl other = (HostingDotComVAppImpl) obj;
if (password == null) {
if (other.password != null)
return false;
} else if (!password.equals(other.password))
return false;
if (username == null) {
if (other.username != null)
return false;
} else if (!username.equals(other.username))
return false;
return true;
}
}

View File

@ -0,0 +1,43 @@
package org.jclouds.vcloud.hostingdotcom.xml;
import javax.inject.Inject;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import org.jclouds.vcloud.xml.ResourceAllocationHandler;
import org.jclouds.vcloud.xml.VAppHandler;
import org.jclouds.vcloud.xml.VirtualSystemHandler;
import org.xml.sax.SAXException;
/**
* @author Adrian Cole
*/
public class HostingDotComVAppHandler extends VAppHandler {
private String username;
private String password;
@Inject
public HostingDotComVAppHandler(VirtualSystemHandler systemHandler,
ResourceAllocationHandler allocationHandler) {
super(systemHandler, allocationHandler);
}
public HostingDotComVApp getResult() {
return new HostingDotComVAppImpl(id, name, location, status, networkToAddresses,
operatingSystemDescription, system, allocations, username, password);
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equals("hmsns:username")) {
username = currentText.toString().trim();
} else if (qName.equals("hmsns:password")) {
password = currentText.toString().trim();
} else {
super.endElement(uri, localName, qName);
}
currentText = new StringBuilder();
}
}

View File

@ -0,0 +1,153 @@
/**
*
* 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.hostingdotcom;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;
import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger;
import org.jclouds.logging.Logger.LoggerFactory;
import org.jclouds.rest.RestClientTest;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.rest.internal.RestAnnotationProcessor;
import org.jclouds.util.Utils;
import org.jclouds.vcloud.endpoints.Catalog;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.endpoints.VCloudApi;
import org.jclouds.vcloud.endpoints.VDC;
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.xml.CatalogHandler;
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;
/**
* Tests behavior of {@code HostingDotComVCloudAsyncClient}
*
* @author Adrian Cole
*/
@Test(groups = "unit", sequential = true, testName = "vcloud.HostingDotComVCloudAsyncClientTest")
public class HostingDotComVCloudAsyncClientTest extends
RestClientTest<HostingDotComVCloudAsyncClient> {
public void testCatalog() throws SecurityException, NoSuchMethodException, IOException {
Method method = HostingDotComVCloudAsyncClient.class.getMethod("getCatalog");
GeneratedHttpRequest<HostingDotComVCloudAsyncClient> httpMethod = processor
.createRequest(method);
assertRequestLineEquals(httpMethod, "GET http://catalog HTTP/1.1");
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);
assertSaxResponseParserClassEquals(method, CatalogHandler.class);
assertExceptionParserClassEquals(method, null);
checkFilters(httpMethod);
}
@Override
protected void checkFilters(GeneratedHttpRequest<HostingDotComVCloudAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);
assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class);
}
@Override
protected TypeLiteral<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>> createTypeLiteral() {
return new TypeLiteral<RestAnnotationProcessor<HostingDotComVCloudAsyncClient>>() {
};
}
@Override
protected Module createModule() {
return new AbstractModule() {
@Override
protected void configure() {
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
bind(String.class).annotatedWith(CatalogItemRoot.class)
.toInstance("http://catalogItem");
bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud"));
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp");
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network"));
bind(SetVCloudTokenCookie.class).toInstance(
new SetVCloudTokenCookie(new Provider<String>() {
public String get() {
return "token";
}
}));
bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() {
public Logger getLogger(String category) {
return Logger.NULL;
}
});
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Named("InstantiateVAppTemplateParams")
String provideInstantiateVAppTemplateParams() throws IOException {
return Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams.xml"));
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Named("CreateInternetService")
String provideCreateInternetService() throws IOException {
return Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateInternetService.xml"));
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Named("CreateNodeService")
String provideCreateNodeService() throws IOException {
return Utils.toStringAndClose(getClass().getResourceAsStream(
"/terremark/CreateNodeService.xml"));
}
};
}
}

View File

@ -0,0 +1,237 @@
/**
*
* 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.hostingdotcom;
import static com.google.common.base.Preconditions.checkArgument;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import javax.annotation.Resource;
import javax.inject.Inject;
import org.jclouds.logging.Logger;
import org.jclouds.ssh.ExecResponse;
import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
/**
*
* @author Adrian Cole
*/
public class HostingDotComVCloudComputeClient {
@Resource
protected Logger logger = Logger.NULL;
private final Predicate<InetSocketAddress> socketTester;
private final Predicate<URI> taskTester;
private final HostingDotComVCloudClient tmClient;
@Inject
public HostingDotComVCloudComputeClient(HostingDotComVCloudClient tmClient, Factory sshFactory,
Predicate<InetSocketAddress> socketTester, Predicate<URI> successTester) {
this.tmClient = tmClient;
this.sshFactory = sshFactory;
this.socketTester = socketTester;
this.taskTester = successTester;
}
private final Factory sshFactory;
public enum Image {
CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS
}
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "3").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(
Image.UMBUNTU_JEOS, "11").build();
private String username;
private String password;
public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
String templateId = imageCatalogIdMap.get(image);
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
minCores, minMegs, templateId);
HostingDotComVApp vAppResponse = (HostingDotComVApp) tmClient.instantiateVAppTemplate(name,
templateId, InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(
minMegs));
this.username = vAppResponse.getUsername();
this.password = vAppResponse.getPassword();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}
tmClient.getVApp(vAppResponse.getId());
logger.debug("<< instantiated VApp(%s)", vAppResponse.getId());
logger.debug(">> deploying vApp(%s)", vAppResponse.getId());
VApp vApp = blockUntilVAppStatusOrThrowException(vAppResponse, tmClient
.deployVApp(vAppResponse.getId()), "deploy", VAppStatus.OFF);
logger.debug("<< deployed vApp(%s)", vApp.getId());
logger.debug(">> powering vApp(%s)", vApp.getId());
vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()),
"powerOn", VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
return vApp.getId();
}
/**
*
* @throws ElementNotFoundException
* if no address is configured
*/
public InetAddress getAnyPrivateAddress(String id) {
VApp vApp = tmClient.getVApp(id);
return Iterables.getLast(vApp.getNetworkToAddresses().values());
}
public ExecResponse exec(InetAddress address, String command) {
InetSocketAddress sshSocket = new InetSocketAddress(address, 22);
logger.debug(">> exec ssh://%s@%s/%s", username, sshSocket, command);
ExecResponse exec = exec(sshSocket, username, password, command);
logger.debug("<< output(%s) error(%s)", exec.getOutput(), exec.getError());
return exec;
}
public void reboot(String id) {
VApp vApp = tmClient.getVApp(id);
logger.debug(">> rebooting vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset",
VAppStatus.ON);
logger.debug("<< on vApp(%s)", vApp.getId());
}
public void stop(String id) {
VApp vApp = tmClient.getVApp(id);
if (vApp.getStatus() != VAppStatus.OFF) {
logger.debug(">> powering off vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
"powerOff", VAppStatus.OFF);
logger.debug("<< off vApp(%s)", vApp.getId());
}
logger.debug(">> deleting vApp(%s)", vApp.getId());
tmClient.deleteVApp(id);
logger.debug("<< deleted vApp(%s)", vApp.getId());
}
private ExecResponse exec(InetSocketAddress socket, String username, String password,
String command) {
if (!socketTester.apply(socket)) {
throw new SocketNotOpenException(socket);
}
SshClient connection = sshFactory.create(socket, username, password);
try {
connection.connect();
return connection.exec(command);
} finally {
if (connection != null)
connection.disconnect();
}
}
private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType,
VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getLocation())) {
throw new TaskException(taskType, vApp, deployTask);
}
vApp = tmClient.getVApp(vApp.getId());
if (vApp.getStatus() != expectedStatus) {
throw new VAppException(String.format("vApp %s status %s should be %s after %s", vApp
.getId(), vApp.getStatus(), expectedStatus, taskType), vApp);
}
return vApp;
}
public static class TaskException extends VAppException {
private final Task task;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, VApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type,
vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task;
}
public Task getTask() {
return task;
}
}
public static class SocketNotOpenException extends RuntimeException {
private final InetSocketAddress socket;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public SocketNotOpenException(InetSocketAddress socket) {
super("socket not open: " + socket);
this.socket = socket;
}
public InetSocketAddress getSocket() {
return socket;
}
}
public static class VAppException extends RuntimeException {
private final VApp vApp;
/** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, VApp vApp) {
super(message);
this.vApp = vApp;
}
public VApp getvApp() {
return vApp;
}
}
}

View File

@ -0,0 +1,171 @@
package org.jclouds.vcloud.hostingdotcom;
import static com.google.common.base.Preconditions.checkNotNull;
import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.predicates.AddressReachable;
import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudComputeClient.Image;
import org.jclouds.vcloud.predicates.TaskSuccess;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.base.Predicate;
import com.google.inject.AbstractModule;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
import com.google.inject.internal.ImmutableMap;
/**
* Tests behavior of {@code HostingDotComVCloudClient}
*
* @author Adrian Cole
*/
@Test(groups = "live", sequential = true, testName = "vcloud.HostingDotComVCloudClientLiveTest")
public class HostingDotComVCloudComputeClientLiveTest {
HostingDotComVCloudComputeClient client;
HostingDotComVCloudClient tmClient;
private String id;
private InetAddress privateAddress;
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
private static class Expectation {
final long hardDisk;
final String os;
public Expectation(long hardDisk, String os) {
this.hardDisk = hardDisk;
this.os = os;
}
}
private Map<Image, Expectation> expectationMap = ImmutableMap.<Image, Expectation> builder()
.put(Image.CENTOS_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.RHEL_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
private Predicate<InetAddress> addressTester;
@Test
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException {
Image toTest = Image.CENTOS_53;
String serverName = getCompatibleServerName(toTest);
int processorCount = 1;
int memory = 512;
id = client.start(serverName, processorCount, memory, toTest);
Expectation expectation = expectationMap.get(toTest);
VApp vApp = tmClient.getVApp(id);
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
expectation.hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.ON);
}
private String getCompatibleServerName(Image toTest) {
String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0,
toTest.toString().length() <= 15 ? toTest.toString().length() : 14);
return serverName;
}
@Test(dependsOnMethods = "testPowerOn")
public void testGetAnyPrivateAddress() {
privateAddress = client.getAnyPrivateAddress(id);
assert !addressTester.apply(privateAddress);
}
@Test(dependsOnMethods = "testGetAnyPrivateAddress")
public void testSshLoadBalanceIp() {
// assert addressTester.apply(publicIp);
client.exec(privateAddress, "uname -a");
}
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)
.getVirtualQuantity(), processorCount);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
.getVirtualQuantity(), 1);
assertEquals(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
memory);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.getVirtualQuantity(), hardDisk);
}
@AfterTest
void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
if (id != null)
client.stop(id);
}
@BeforeGroups(groups = { "live" })
public void setupClient() {
String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user");
String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key");
Injector injector = new HostingDotComVCloudContextBuilder(
new HostingDotComVCloudPropertiesBuilder(account, key).relaxSSLHostname().build())
.withModules(new Log4JLoggingModule(), new JschSshClientModule(),
new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetSocketAddress> socketTester(SocketOpen open) {
return new RetryablePredicate<InetSocketAddress>(open, 130, 10,
TimeUnit.SECONDS);// make it longer then
// default internet
}
@SuppressWarnings("unused")
@Provides
private Predicate<InetAddress> addressTester(AddressReachable reachable) {
return new RetryablePredicate<InetAddress>(reachable, 60, 5,
TimeUnit.SECONDS);
}
@SuppressWarnings("unused")
@Provides
private Predicate<URI> successTester(TaskSuccess success) {
return new RetryablePredicate<URI>(success, 300, 10, TimeUnit.SECONDS);
}
}).buildInjector();
client = injector.getInstance(HostingDotComVCloudComputeClient.class);
tmClient = injector.getInstance(HostingDotComVCloudClient.class);
addressTester = injector.getInstance(Key.get(new TypeLiteral<Predicate<InetAddress>>() {
}));
}
}

View File

@ -0,0 +1,65 @@
/**
*
* 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.hostingdotcom.xml;
import static org.testng.Assert.assertEquals;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp;
import org.jclouds.vcloud.hostingdotcom.domain.internal.HostingDotComVAppImpl;
import org.testng.annotations.Test;
import com.google.common.collect.ImmutableListMultimap;
import com.google.common.collect.ImmutableSortedSet;
/**
* Tests behavior of {@code HostingDotComVAppHandler}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.HostingDotComVAppHandlerTest")
public class HostingDotComVAppHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/hostingdotcom/instantiatevapp.xml");
HostingDotComVApp result = (HostingDotComVApp) factory.create(
injector.getInstance(HostingDotComVAppHandler.class)).parse(is);
HostingDotComVApp expects = new HostingDotComVAppImpl("188849-13", "188849-13", URI
.create("https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-13"),
VAppStatus.TODO_I_DONT_KNOW, ImmutableListMultimap.<String, InetAddress> of(), null,
null, ImmutableSortedSet.<ResourceAllocation> of(), "root", "peoplearelovely");
assertEquals(result, expects);
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<VApp name="188849-13" status="1"
href="https://vcloud.safesecureweb.com/api/v0.8/vapp/188849-13"
xmlns="http://www.vmware.com/vcloud/v0.8" xmlns:hmsns="https://vcloud.safesecureweb.com/ns/v1/VApp"
xmlns:ovf="http://schemas.dmtf.org/ovf/envelope/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.vmware.com/vcloud/1
https://vcloud.safesecureweb.com/ns/vcloud.xsd">
<Link rel="up"
href="https://vcloud.safesecureweb.com/api/v0.8/vdc/188849"
type="application/vnd.vmware.vcloud.vdc+xml" />
<hmsns:username>root</hmsns:username>
<hmsns:password>peoplearelovely</hmsns:password>
</VApp>

View File

@ -49,12 +49,13 @@ import org.jclouds.vcloud.VCloudAsyncClient;
import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.domain.VDC;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.functions.CatalogIdToUri; import org.jclouds.vcloud.functions.CatalogIdToUri;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.binders.TerremarkBindInstantiateVAppTemplateParamsToXmlEntity;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.VApp; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions;
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
@ -81,8 +82,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@Path("/action/instantiatevAppTemplate") @Path("/action/instantiatevAppTemplate")
@Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml")
@XMLResponseParser(TerremarkVAppHandler.class) @XMLResponseParser(TerremarkVAppHandler.class)
@MapBinder(InstantiateVAppTemplateOptions.class) @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class)
Future<? extends VApp> instantiateVAppTemplate(@MapEntityParam("name") String appName, @Override
Future<? extends TerremarkVApp> instantiateVAppTemplate(@MapEntityParam("name") String appName,
@MapEntityParam("template") @ParamParser(CatalogIdToUri.class) String templateId, @MapEntityParam("template") @ParamParser(CatalogIdToUri.class) String templateId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
@ -147,7 +149,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient {
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}") @Path("/vapp/{vAppId}")
@XMLResponseParser(TerremarkVAppHandler.class) @XMLResponseParser(TerremarkVAppHandler.class)
Future<? extends VApp> getVApp(@PathParam("vAppId") String vAppId); @Override
Future<? extends TerremarkVApp> getVApp(@PathParam("vAppId") String vAppId);
@GET @GET
@Consumes(VAPP_XML) @Consumes(VAPP_XML)

View File

@ -28,12 +28,12 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout; import org.jclouds.concurrent.Timeout;
import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.VCloudClient;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.VApp; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions;
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
/** /**
* Provides access to VCloud resources via their REST API. * Provides access to VCloud resources via their REST API.
@ -45,7 +45,8 @@ import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
@Timeout(duration = 45, timeUnit = TimeUnit.SECONDS) @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS)
public interface TerremarkVCloudClient extends VCloudClient { public interface TerremarkVCloudClient extends VCloudClient {
VApp instantiateVAppTemplate(String appName, String templateId, @Override
TerremarkVApp instantiateVAppTemplate(String appName, String templateId,
InstantiateVAppTemplateOptions... options); InstantiateVAppTemplateOptions... options);
InternetService addInternetService(String serviceName, String protocol, int port, InternetService addInternetService(String serviceName, String protocol, int port,
@ -65,6 +66,7 @@ public interface TerremarkVCloudClient extends VCloudClient {
void deleteNode(String nodeId); void deleteNode(String nodeId);
VApp getVApp(String vAppId); @Override
TerremarkVApp getVApp(String vAppId);
} }

View File

@ -1,59 +0,0 @@
package org.jclouds.vcloud.terremark.binders;
import static com.google.common.base.Preconditions.checkNotNull;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.http.HttpRequest;
import org.jclouds.rest.MapBinder;
import org.jclouds.rest.binders.BindToStringEntity;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class BindInstantiateVAppTemplateParamsToXmlEntity implements MapBinder {
@Inject
@Named("InstantiateVAppTemplateParams")
private String xmlTemplate;
@Inject
private BindToStringEntity stringBinder;
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
String name = checkNotNull(postParams.get("name"), "name parameter not present");
String password = checkNotNull(postParams.get("password"), "password parameter not present");
String row = checkNotNull(postParams.get("row"), "row parameter not present");
String group = checkNotNull(postParams.get("group"), "group parameter not present");
String template = checkNotNull(postParams.get("template"), "template parameter not present");
String count = checkNotNull(postParams.get("count"), "count parameter not present");
String megabytes = checkNotNull(postParams.get("megabytes"),
"megabytes parameter not present");
String network = checkNotNull(postParams.get("network"), "network parameter not present");
String entity = xmlTemplate.replaceAll("\\{name\\}", name);
entity = entity.replaceAll("\\{password\\}", password);
entity = entity.replaceAll("\\{row\\}", row);
entity = entity.replaceAll("\\{group\\}", group);
entity = entity.replaceAll("\\{template\\}", template);
entity = entity.replaceAll("\\{count\\}", count);
entity = entity.replaceAll("\\{megabytes\\}", megabytes);
entity = entity.replaceAll("\\{network\\}", network);
stringBinder.bindToRequest(request, entity);
}
public void bindToRequest(HttpRequest request, Object input) {
throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
}
}

View File

@ -0,0 +1,65 @@
package org.jclouds.vcloud.terremark.binders;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTCPUCOUNT;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTMEMORY;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULTNETWORK;
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTGROUP;
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTPASSWORD;
import static org.jclouds.vcloud.terremark.reference.TerremarkVCloudConstants.PROPERTY_TERREMARK_DEFAULTROW;
import java.util.Map;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.jclouds.rest.binders.BindToStringEntity;
import org.jclouds.rest.internal.GeneratedHttpRequest;
import org.jclouds.vcloud.binders.BindInstantiateVAppTemplateParamsToXmlEntity;
import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
/**
*
* @author Adrian Cole
*
*/
@Singleton
public class TerremarkBindInstantiateVAppTemplateParamsToXmlEntity extends
BindInstantiateVAppTemplateParamsToXmlEntity {
@Inject
public TerremarkBindInstantiateVAppTemplateParamsToXmlEntity(
@Named("InstantiateVAppTemplateParams") String xmlTemplate,
BindToStringEntity stringBinder,
@Named(PROPERTY_VCLOUD_DEFAULTNETWORK) String defaultNetwork,
@Named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT) String defaultCpuCount,
@Named(PROPERTY_VCLOUD_DEFAULTMEMORY) String defaultMemory,
@Named(PROPERTY_TERREMARK_DEFAULTGROUP) String defaultGroup,
@Named(PROPERTY_TERREMARK_DEFAULTROW) String defaultRow,
@Named(PROPERTY_TERREMARK_DEFAULTPASSWORD) String defaultPassword) {
super(xmlTemplate, stringBinder, defaultNetwork, defaultCpuCount, defaultMemory);
this.defaultParams.put("group", defaultGroup);
this.defaultParams.put("row", defaultRow);
this.defaultParams.put("password", defaultPassword);
}
@Override
protected void addOptionsToMap(Map<String, String> postParams, GeneratedHttpRequest<?> gRequest) {
super.addOptionsToMap(postParams, gRequest);
for (Object arg : gRequest.getArgs()) {
if (arg instanceof TerremarkInstantiateVAppTemplateOptions) {
TerremarkInstantiateVAppTemplateOptions options = (TerremarkInstantiateVAppTemplateOptions) arg;
if (options.getGroup() != null) {
postParams.put("group", options.getGroup());
}
if (options.getRow() != null) {
postParams.put("row", options.getRow());
}
if (options.getPassword() != null) {
postParams.put("password", options.getPassword());
}
}
}
}
}

View File

@ -57,7 +57,6 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
return (TerremarkVCloudAsyncClient) in; return (TerremarkVCloudAsyncClient) in;
} }
@Override @Override
protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) { protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) {
return factory.create(TerremarkVCloudAsyncClient.class); return factory.create(TerremarkVCloudAsyncClient.class);
@ -75,10 +74,8 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
return SyncProxy.create(TerremarkVCloudClient.class, client); return SyncProxy.create(TerremarkVCloudClient.class, client);
} }
@Singleton @Override
@Provides protected String provideInstantiateVAppTemplateParams() throws IOException {
@Named("InstantiateVAppTemplateParams")
String provideInstantiateVAppTemplateParams() throws IOException {
InputStream is = getClass().getResourceAsStream( InputStream is = getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams.xml"); "/terremark/InstantiateVAppTemplateParams.xml");
return Utils.toStringAndClose(is); return Utils.toStringAndClose(is);

View File

@ -0,0 +1,46 @@
/**
*
* 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.terremark.domain;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.VApp;
import org.jclouds.vcloud.terremark.domain.internal.TerremarkVAppImpl;
import com.google.inject.ImplementedBy;
/**
* @author Adrian Cole
*/
@ImplementedBy(TerremarkVAppImpl.class)
public interface TerremarkVApp extends VApp {
long getSize();
Link getVDC();
Link getComputeOptions();
Link getCustomizationOptions();
}

View File

@ -0,0 +1,125 @@
/**
*
* 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.terremark.domain.internal;
import java.net.InetAddress;
import java.net.URI;
import java.util.SortedSet;
import org.jclouds.rest.domain.Link;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.TerremarkVirtualSystem;
import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.VAppImpl;
import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import com.google.common.collect.ListMultimap;
/**
* Locations of resources in vCloud
*
* @author Adrian Cole
*
*/
public class TerremarkVAppImpl extends VAppImpl implements TerremarkVApp {
private final long size;
private final Link vDC;
private final Link computeOptions;
private final Link customizationOptions;
/** The serialVersionUID */
private static final long serialVersionUID = 8464716396538298809L;
public TerremarkVAppImpl(String id, String name, String type, URI location, VAppStatus status,
long size, Link vDC, Link computeOptions, Link customizationOptions,
ListMultimap<String, InetAddress> networkToAddresses,
String operatingSystemDescription, TerremarkVirtualSystem system,
SortedSet<ResourceAllocation> resourceAllocations) {
super(id, name, location, status, networkToAddresses, operatingSystemDescription, system,
resourceAllocations);
this.size = size;
this.vDC = vDC;
this.computeOptions = computeOptions;
this.customizationOptions = customizationOptions;
}
public long getSize() {
return size;
}
public Link getVDC() {
return vDC;
}
public Link getComputeOptions() {
return computeOptions;
}
public Link getCustomizationOptions() {
return customizationOptions;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((computeOptions == null) ? 0 : computeOptions.hashCode());
result = prime * result
+ ((customizationOptions == null) ? 0 : customizationOptions.hashCode());
result = prime * result + (int) (size ^ (size >>> 32));
result = prime * result + ((vDC == null) ? 0 : vDC.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
TerremarkVAppImpl other = (TerremarkVAppImpl) obj;
if (computeOptions == null) {
if (other.computeOptions != null)
return false;
} else if (!computeOptions.equals(other.computeOptions))
return false;
if (customizationOptions == null) {
if (other.customizationOptions != null)
return false;
} else if (!customizationOptions.equals(other.customizationOptions))
return false;
if (size != other.size)
return false;
if (vDC == null) {
if (other.vDC != null)
return false;
} else if (!vDC.equals(other.vDC))
return false;
return true;
}
}

View File

@ -29,6 +29,7 @@ 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.NamedResource;
import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Capacity;
import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.Quota;
import org.jclouds.vcloud.domain.internal.VDCImpl; import org.jclouds.vcloud.domain.internal.VDCImpl;
@ -52,8 +53,9 @@ public class TerremarkVDCImpl extends VDCImpl implements TerremarkVDC {
public TerremarkVDCImpl(String id, String name, URI location, String description, public TerremarkVDCImpl(String id, String name, URI location, String description,
Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity,
Quota instantiatedVmsQuota, Quota deployedVmsQuota, Quota instantiatedVmsQuota, Quota deployedVmsQuota,
Map<String, NamedLink> availableNetworks, Map<String, NamedLink> resourceEntities, Map<String, NamedResource> availableNetworks,
NamedLink catalog, NamedLink publicIps, NamedLink internetServices) { Map<String, NamedResource> resourceEntities, NamedLink catalog, NamedLink publicIps,
NamedLink internetServices) {
super(id, name, location, description, storageCapacity, cpuCapacity, memoryCapacity, super(id, name, location, description, storageCapacity, cpuCapacity, memoryCapacity,
instantiatedVmsQuota, deployedVmsQuota, availableNetworks, resourceEntities); instantiatedVmsQuota, deployedVmsQuota, availableNetworks, resourceEntities);
this.catalog = checkNotNull(catalog, "catalog"); this.catalog = checkNotNull(catalog, "catalog");

View File

@ -1,136 +0,0 @@
package org.jclouds.vcloud.terremark.options;
import static com.google.common.base.Preconditions.checkArgument;
import java.net.URI;
import java.util.Map;
import javax.inject.Inject;
import org.jclouds.http.HttpRequest;
import org.jclouds.vcloud.endpoints.Network;
import org.jclouds.vcloud.terremark.binders.BindInstantiateVAppTemplateParamsToXmlEntity;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
/**
*
* @author Adrian Cole
*
*/
public class InstantiateVAppTemplateOptions extends BindInstantiateVAppTemplateParamsToXmlEntity {
@Inject
@Network
private URI defaultNetwork;
@VisibleForTesting
String password = "password";
@VisibleForTesting
String group = "default";
@VisibleForTesting
String row = "default";
@VisibleForTesting
String cpuCount = "1";
@VisibleForTesting
String megabytes = "512";
@VisibleForTesting
String network;
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
Map<String, String> copy = Maps.newHashMap();
copy.putAll(postParams);
copy.put("count", cpuCount);
copy.put("password", password);
copy.put("group", group);
copy.put("row", row);
copy.put("megabytes", megabytes);
copy.put("network", network != null ? network : defaultNetwork.toASCIIString());
super.bindToRequest(request, copy);
}
public InstantiateVAppTemplateOptions cpuCount(int cpuCount) {
checkArgument(cpuCount >= 1, "cpuCount must be positive");
this.cpuCount = cpuCount + "";
return this;
}
public InstantiateVAppTemplateOptions megabytes(int megabytes) {
checkArgument(megabytes % 512 == 0, "megabytes must be in an increment of 512");
this.megabytes = megabytes + "";
return this;
}
public InstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
this.network = networkLocation.toASCIIString();
return this;
}
public InstantiateVAppTemplateOptions withPassword(String password) {
this.password = password;
return this;
}
public InstantiateVAppTemplateOptions inGroup(String group) {
this.group = group;
return this;
}
public InstantiateVAppTemplateOptions inRow(String row) {
this.row = row;
return this;
}
public static class Builder {
/**
* @see InstantiateVAppTemplateOptions#cpuCount(int)
*/
public static InstantiateVAppTemplateOptions cpuCount(int cpuCount) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.cpuCount(cpuCount);
}
/**
* @see InstantiateVAppTemplateOptions#megabytes(int)
*/
public static InstantiateVAppTemplateOptions megabytes(int megabytes) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.megabytes(megabytes);
}
/**
* @see InstantiateVAppTemplateOptions#inNetwork(URI)
*/
public static InstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.inNetwork(networkLocation);
}
/**
* @see InstantiateVAppTemplateOptions#withPassword(String)
*/
public static InstantiateVAppTemplateOptions withPassword(String password) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.withPassword(password);
}
/**
* @see InstantiateVAppTemplateOptions#inGroup(String)
*/
public static InstantiateVAppTemplateOptions inGroup(String group) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.inGroup(group);
}
/**
* @see InstantiateVAppTemplateOptions#inRow(String)
*/
public static InstantiateVAppTemplateOptions inRow(String row) {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
return options.inRow(row);
}
}
}

View File

@ -0,0 +1,111 @@
package org.jclouds.vcloud.terremark.options;
import java.net.URI;
import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
/**
*
* @author Adrian Cole
*
*/
public class TerremarkInstantiateVAppTemplateOptions extends InstantiateVAppTemplateOptions {
private String password;
private String group;
private String row;
public TerremarkInstantiateVAppTemplateOptions withPassword(String password) {
this.password = password;
return this;
}
public TerremarkInstantiateVAppTemplateOptions inGroup(String group) {
this.group = group;
return this;
}
public TerremarkInstantiateVAppTemplateOptions inRow(String row) {
this.row = row;
return this;
}
public static class Builder {
/**
* @see TerremarkInstantiateVAppTemplateOptions#cpuCount(int)
*/
public static TerremarkInstantiateVAppTemplateOptions cpuCount(int cpuCount) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.cpuCount(cpuCount);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#megabytes(int)
*/
public static TerremarkInstantiateVAppTemplateOptions megabytes(int megabytes) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.megabytes(megabytes);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#inNetwork(URI)
*/
public static TerremarkInstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.inNetwork(networkLocation);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#withPassword(String)
*/
public static TerremarkInstantiateVAppTemplateOptions withPassword(String password) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.withPassword(password);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#inGroup(String)
*/
public static TerremarkInstantiateVAppTemplateOptions inGroup(String group) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.inGroup(group);
}
/**
* @see TerremarkInstantiateVAppTemplateOptions#inRow(String)
*/
public static TerremarkInstantiateVAppTemplateOptions inRow(String row) {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
return options.inRow(row);
}
}
@Override
public TerremarkInstantiateVAppTemplateOptions cpuCount(int cpuCount) {
return (TerremarkInstantiateVAppTemplateOptions) super.cpuCount(cpuCount);
}
@Override
public TerremarkInstantiateVAppTemplateOptions inNetwork(URI networkLocation) {
return (TerremarkInstantiateVAppTemplateOptions) super.inNetwork(networkLocation);
}
@Override
public TerremarkInstantiateVAppTemplateOptions megabytes(int megabytes) {
return (TerremarkInstantiateVAppTemplateOptions) super.megabytes(megabytes);
}
public String getPassword() {
return password;
}
public String getGroup() {
return group;
}
public String getRow() {
return row;
}
}

View File

@ -0,0 +1,16 @@
package org.jclouds.vcloud.terremark.reference;
import org.jclouds.vcloud.reference.VCloudConstants;
/**
* Configuration properties and constants used in Terremark VCloud connections.
*
* @author Adrian Cole
*/
public interface TerremarkVCloudConstants extends VCloudConstants {
public static final String PROPERTY_TERREMARK_DEFAULTGROUP = "jclouds.terremark.defaults.group";
public static final String PROPERTY_TERREMARK_DEFAULTROW = "jclouds.terremark.defaults.row";
public static final String PROPERTY_TERREMARK_DEFAULTPASSWORD = "jclouds.terremark.defaults.password";
}

View File

@ -24,8 +24,8 @@
package org.jclouds.vcloud.terremark.xml; package org.jclouds.vcloud.terremark.xml;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.vcloud.terremark.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -38,25 +38,14 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
private Integer address; private Integer address;
private Integer addressOnParent; private Integer addressOnParent;
private String allocationUnits; private String allocationUnits;
private String automaticAllocation;
private String automaticDeallocation;
private String caption;
private String consumerVisibility;
private String description; private String description;
private String elementName; private String elementName;
private String hostResource;
private int instanceID; private int instanceID;
private String limit;
private String mappingBehavior;
private String otherResourceType;
private Integer parent; private Integer parent;
private String poolID;
private String reservation;
private String resourceSubType; private String resourceSubType;
private ResourceType resourceType; private ResourceType resourceType;
private long virtualQuantity = 1; private long virtualQuantity = 1;
private String virtualQuantityUnits; private String virtualQuantityUnits;
private String weight;
private ResourceAllocation item; private ResourceAllocation item;
@ -95,36 +84,16 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
this.addressOnParent = Integer.parseInt(addressOnParent); this.addressOnParent = Integer.parseInt(addressOnParent);
} else if (qName.equals("AllocationUnits")) { } else if (qName.equals("AllocationUnits")) {
this.allocationUnits = currentText.toString().trim(); this.allocationUnits = currentText.toString().trim();
} else if (qName.equals("AutomaticAllocation")) {
this.automaticAllocation = currentText.toString().trim();
} else if (qName.equals("AutomaticDeallocation")) {
this.automaticDeallocation = currentText.toString().trim();
} else if (qName.equals("Caption")) {
this.caption = currentText.toString().trim();
} else if (qName.equals("ConsumerVisibility")) {
this.consumerVisibility = currentText.toString().trim();
} else if (qName.equals("Description")) { } else if (qName.equals("Description")) {
this.description = currentText.toString().trim(); this.description = currentText.toString().trim();
} else if (qName.equals("ElementName")) { } else if (qName.equals("ElementName")) {
this.elementName = currentText.toString().trim(); this.elementName = currentText.toString().trim();
} else if (qName.equals("HostResource")) {
this.hostResource = currentText.toString().trim();
} else if (qName.equals("InstanceID")) { } else if (qName.equals("InstanceID")) {
this.instanceID = Integer.parseInt(currentText.toString().trim()); this.instanceID = Integer.parseInt(currentText.toString().trim());
} else if (qName.equals("Limit")) {
this.limit = currentText.toString().trim();
} else if (qName.equals("MappingBehavior")) {
this.mappingBehavior = currentText.toString().trim();
} else if (qName.equals("OtherResourceType")) {
this.otherResourceType = currentText.toString().trim();
} else if (qName.equals("Parent")) { } else if (qName.equals("Parent")) {
String parent = currentText.toString().trim(); String parent = currentText.toString().trim();
if (parent != null && !parent.equals("")) if (parent != null && !parent.equals(""))
this.parent = Integer.parseInt(parent); this.parent = Integer.parseInt(parent);
} else if (qName.equals("PoolID")) {
this.poolID = currentText.toString().trim();
} else if (qName.equals("Reservation")) {
this.reservation = currentText.toString().trim();
} else if (qName.equals("ResourceSubType")) { } else if (qName.equals("ResourceSubType")) {
this.resourceSubType = currentText.toString().trim(); this.resourceSubType = currentText.toString().trim();
} else if (qName.equals("ResourceType")) { } else if (qName.equals("ResourceType")) {
@ -135,36 +104,21 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult<Resour
this.virtualQuantity = Long.parseLong(quantity); this.virtualQuantity = Long.parseLong(quantity);
} else if (qName.equals("VirtualQuantityUnits")) { } else if (qName.equals("VirtualQuantityUnits")) {
this.virtualQuantityUnits = currentText.toString().trim(); this.virtualQuantityUnits = currentText.toString().trim();
} else if (qName.equals("Weight")) {
this.weight = currentText.toString().trim();
} else if (qName.equals("q2:Item")) { } else if (qName.equals("q2:Item")) {
this.item = new ResourceAllocation(address, addressOnParent, allocationUnits, this.item = new ResourceAllocation(instanceID, elementName, description, resourceType,
automaticAllocation, automaticDeallocation, caption, consumerVisibility, resourceSubType, address, addressOnParent, parent, null, virtualQuantity,
description, elementName, hostResource, instanceID, limit, mappingBehavior, allocationUnits != null ? allocationUnits : virtualQuantityUnits);
otherResourceType, parent, poolID, reservation, resourceSubType, resourceType,
virtualQuantity, virtualQuantityUnits, weight);
this.address = null; this.address = null;
this.addressOnParent = null; this.addressOnParent = null;
this.allocationUnits = null; this.allocationUnits = null;
this.automaticAllocation = null;
this.automaticDeallocation = null;
this.caption = null;
this.consumerVisibility = null;
this.description = null; this.description = null;
this.elementName = null; this.elementName = null;
this.hostResource = null;
this.instanceID = -1; this.instanceID = -1;
this.limit = null;
this.mappingBehavior = null;
this.otherResourceType = null;
this.parent = null; this.parent = null;
this.poolID = null;
this.reservation = null;
this.resourceSubType = null; this.resourceSubType = null;
this.resourceType = null; this.resourceType = null;
this.virtualQuantity = 1; this.virtualQuantity = 1;
this.virtualQuantityUnits = null; this.virtualQuantityUnits = null;
this.weight = null;
} }
} }
currentText = new StringBuilder(); currentText = new StringBuilder();

View File

@ -35,16 +35,16 @@ import javax.inject.Inject;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.rest.domain.Link; import org.jclouds.rest.domain.Link;
import org.jclouds.rest.domain.NamedResource;
import org.jclouds.rest.internal.NamedResourceImpl;
import org.jclouds.rest.util.Utils; import org.jclouds.rest.util.Utils;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.NamedResource; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.TerremarkVirtualSystem;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.terremark.domain.ResourceAllocation; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.VApp; import org.jclouds.vcloud.terremark.domain.internal.TerremarkVAppImpl;
import org.jclouds.vcloud.terremark.domain.VirtualSystem;
import org.jclouds.vcloud.terremark.domain.internal.VAppImpl;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
@ -55,7 +55,7 @@ import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> { public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<TerremarkVApp> {
private final VirtualSystemHandler systemHandler; private final VirtualSystemHandler systemHandler;
private final ResourceAllocationHandler allocationHandler; private final ResourceAllocationHandler allocationHandler;
@ -69,7 +69,7 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
this.allocationHandler = allocationHandler; this.allocationHandler = allocationHandler;
} }
private VirtualSystem system; private TerremarkVirtualSystem system;
private SortedSet<ResourceAllocation> allocations = Sets.newTreeSet(); private SortedSet<ResourceAllocation> allocations = Sets.newTreeSet();
private NamedResource vApp; private NamedResource vApp;
private Link vDC; private Link vDC;
@ -87,8 +87,8 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
@VAppRoot @VAppRoot
private String vAppRoot; private String vAppRoot;
public VApp getResult() { public TerremarkVApp getResult() {
return new VAppImpl(vApp.getId(), vApp.getName(), vApp.getType(), vApp.getLocation(), status, return new TerremarkVAppImpl(vApp.getId(), vApp.getName(), vApp.getType(), vApp.getLocation(), status,
size, vDC, computeOptions, customizationOptions, networkToAddresses, size, vDC, computeOptions, customizationOptions, networkToAddresses,
operatingSystemDescription, system, allocations); operatingSystemDescription, system, allocations);
} }

View File

@ -35,7 +35,7 @@ import org.xml.sax.SAXException;
* @author Adrian Cole * @author Adrian Cole
*/ */
public class VirtualSystemHandler extends public class VirtualSystemHandler extends
ParseSax.HandlerWithResult<org.jclouds.vcloud.terremark.domain.VirtualSystem> { ParseSax.HandlerWithResult<org.jclouds.vcloud.domain.TerremarkVirtualSystem> {
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
protected DateService dateService; protected DateService dateService;
@ -61,7 +61,7 @@ public class VirtualSystemHandler extends
private String virtualSystemIdentifier; private String virtualSystemIdentifier;
private String virtualSystemType; private String virtualSystemType;
private org.jclouds.vcloud.terremark.domain.VirtualSystem system; private org.jclouds.vcloud.domain.TerremarkVirtualSystem system;
private boolean skip; private boolean skip;
@ -70,7 +70,7 @@ public class VirtualSystemHandler extends
this.dateService = dateService; this.dateService = dateService;
} }
public org.jclouds.vcloud.terremark.domain.VirtualSystem getResult() { public org.jclouds.vcloud.domain.TerremarkVirtualSystem getResult() {
return system; return system;
} }
@ -132,7 +132,7 @@ public class VirtualSystemHandler extends
} else if (qName.equals("VirtualSystemType")) { } else if (qName.equals("VirtualSystemType")) {
this.virtualSystemType = currentText.toString().trim(); this.virtualSystemType = currentText.toString().trim();
} else if (qName.equals("q2:System")) { } else if (qName.equals("q2:System")) {
this.system = new org.jclouds.vcloud.terremark.domain.VirtualSystem(automaticRecoveryAction, this.system = new org.jclouds.vcloud.domain.TerremarkVirtualSystem(automaticRecoveryAction,
automaticShutdownAction, automaticStartupAction, automaticStartupActionDelay, automaticShutdownAction, automaticStartupAction, automaticStartupActionDelay,
automaticStartupActionSequenceNumber, caption, configurationDataRoot, automaticStartupActionSequenceNumber, caption, configurationDataRoot,
configurationFile, configurationID, creationTime, description, elementName, configurationFile, configurationID, creationTime, description, elementName,

View File

@ -24,7 +24,7 @@
package org.jclouds.vcloud.terremark; package org.jclouds.vcloud.terremark;
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled; import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.cpuCount; import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
@ -55,7 +55,7 @@ import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions;
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler;
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
@ -68,12 +68,12 @@ import com.google.inject.Provides;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
/** /**
* Tests behavior of {@code TerremarkVCloudClient} * Tests behavior of {@code TerremarkVCloudAsyncClient}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudClientTest") @Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest")
public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsyncClient> { public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVCloudAsyncClient> {
public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC"); Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC");
@ -93,7 +93,7 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException,
IOException { IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, String.class, String.class, Array.newInstance(TerremarkInstantiateVAppTemplateOptions.class,
0).getClass()); 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", 3 + ""); "name", 3 + "");
@ -115,7 +115,7 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudAsy
public void testInstantiateVAppTemplateOptions() throws SecurityException, public void testInstantiateVAppTemplateOptions() throws SecurityException,
NoSuchMethodException, IOException { NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate",
String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, String.class, String.class, Array.newInstance(TerremarkInstantiateVAppTemplateOptions.class,
0).getClass()); 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method, GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
"name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); "name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet")));

View File

@ -45,14 +45,14 @@ import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.util.Utils; import org.jclouds.util.Utils;
import org.jclouds.vcloud.VCloudClientLiveTest; import org.jclouds.vcloud.VCloudClientLiveTest;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
import org.jclouds.vcloud.terremark.domain.VApp;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -73,7 +73,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
private InetAddress publicIp; private InetAddress publicIp;
private InternetService is; private InternetService is;
private Node node; private Node node;
private VApp vApp; private TerremarkVApp vApp;
private RetryablePredicate<InetSocketAddress> socketTester; private RetryablePredicate<InetSocketAddress> socketTester;
@ -190,21 +190,21 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
assertEquals(vApp.getStatus(), VAppStatus.OFF); assertEquals(vApp.getStatus(), VAppStatus.OFF);
} }
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) { int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName); assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)
.getVirtualQuantity(), processorCount); .getVirtualQuantity(), processorCount);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
.getVirtualQuantity(), 1); .getVirtualQuantity(), 1);
assertEquals( assertEquals(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(), vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
memory); memory);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.getVirtualQuantity(), hardDisk); .getVirtualQuantity(), hardDisk);
assertEquals(vApp.getSize(), vApp.getResourceAllocationByType() assertEquals(vApp.getSize(), vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); .getVirtualQuantity());
} }
private void doCheckPass(InetAddress address) throws IOException { private void doCheckPass(InetAddress address) throws IOException {

View File

@ -40,13 +40,13 @@ import org.jclouds.predicates.AddressReachable;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.predicates.TaskSuccess;
import org.jclouds.vcloud.terremark.VCloudComputeClient.Image; import org.jclouds.vcloud.terremark.VCloudComputeClient.Image;
import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.InternetService;
import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.Node;
import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.VApp;
import org.testng.annotations.AfterTest; import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -89,7 +89,8 @@ public class TerremarkVCloudComputeClientLiveTest {
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.RHEL_53, Image.RHEL_53,
new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put(
Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).build(); Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put(
Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build();
private InternetService is; private InternetService is;
private Node node; private Node node;
@ -99,7 +100,7 @@ public class TerremarkVCloudComputeClientLiveTest {
@Test @Test
public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException,
IOException { IOException {
Image toTest = Image.UMBUNTU_90; Image toTest = Image.CENTOS_53;
String serverName = getCompatibleServerName(toTest); String serverName = getCompatibleServerName(toTest);
int processorCount = 1; int processorCount = 1;
@ -108,7 +109,7 @@ public class TerremarkVCloudComputeClientLiveTest {
id = client.start(serverName, processorCount, memory, toTest); id = client.start(serverName, processorCount, memory, toTest);
Expectation expectation = expectationMap.get(toTest); Expectation expectation = expectationMap.get(toTest);
VApp vApp = tmClient.getVApp(id); TerremarkVApp vApp = tmClient.getVApp(id);
verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory, verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory,
expectation.hardDisk); expectation.hardDisk);
assertEquals(vApp.getStatus(), VAppStatus.ON); assertEquals(vApp.getStatus(), VAppStatus.ON);
@ -135,21 +136,21 @@ public class TerremarkVCloudComputeClientLiveTest {
client.exec(publicIp, "uname -a"); client.exec(publicIp, "uname -a");
} }
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs,
int processorCount, int memory, long hardDisk) { int processorCount, int memory, long hardDisk) {
assertEquals(vApp.getName(), serverName); assertEquals(vApp.getName(), serverName);
assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR)
.getVirtualQuantity(), processorCount); .getVirtualQuantity(), processorCount);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
.getVirtualQuantity(), 1); .getVirtualQuantity(), 1);
assertEquals( assertEquals(
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(), vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
memory); memory);
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.getVirtualQuantity(), hardDisk); .getVirtualQuantity(), hardDisk);
assertEquals(vApp.getSize(), vApp.getResourceAllocationByType() assertEquals(vApp.getSize(), vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); .getVirtualQuantity());
} }
@AfterTest @AfterTest

View File

@ -39,8 +39,8 @@ import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshClient.Factory; import org.jclouds.ssh.SshClient.Factory;
import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.Task;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.terremark.domain.VApp; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
@ -70,11 +70,11 @@ public class VCloudComputeClient {
private final Factory sshFactory; private final Factory sshFactory;
public enum Image { public enum Image {
CENTOS_53, RHEL_53, UMBUNTU_90 CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS
} }
private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put( private Map<Image, String> imageCatalogIdMap = ImmutableMap.<Image, String> builder().put(
Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").build(); Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(Image.UMBUNTU_JEOS, "11").build();
public String start(String name, int minCores, int minMegs, Image image) { public String start(String name, int minCores, int minMegs, Image image) {
checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image);
@ -82,8 +82,8 @@ public class VCloudComputeClient {
logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name, logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name,
minCores, minMegs, templateId); minCores, minMegs, templateId);
VApp vApp = tmClient.instantiateVAppTemplate(name, templateId, TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId,
InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs));
logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug("<< instantiated VApp(%s)", vApp.getId());
logger.debug(">> deploying vApp(%s)", vApp.getId()); logger.debug(">> deploying vApp(%s)", vApp.getId());
@ -105,7 +105,7 @@ public class VCloudComputeClient {
* if no address is configured * if no address is configured
*/ */
public InetAddress getAnyPrivateAddress(String id) { public InetAddress getAnyPrivateAddress(String id) {
VApp vApp = tmClient.getVApp(id); TerremarkVApp vApp = tmClient.getVApp(id);
return Iterables.getLast(vApp.getNetworkToAddresses().values()); return Iterables.getLast(vApp.getNetworkToAddresses().values());
} }
@ -120,7 +120,7 @@ public class VCloudComputeClient {
} }
public void reboot(String id) { public void reboot(String id) {
VApp vApp = tmClient.getVApp(id); TerremarkVApp vApp = tmClient.getVApp(id);
logger.debug(">> rebooting vApp(%s)", vApp.getId()); logger.debug(">> rebooting vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset", blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset",
VAppStatus.ON); VAppStatus.ON);
@ -128,7 +128,7 @@ public class VCloudComputeClient {
} }
public void stop(String id) { public void stop(String id) {
VApp vApp = tmClient.getVApp(id); TerremarkVApp vApp = tmClient.getVApp(id);
if (vApp.getStatus() != VAppStatus.OFF) { if (vApp.getStatus() != VAppStatus.OFF) {
logger.debug(">> powering off vApp(%s)", vApp.getId()); logger.debug(">> powering off vApp(%s)", vApp.getId());
blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()), blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()),
@ -155,7 +155,7 @@ public class VCloudComputeClient {
} }
} }
private VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType, private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask, String taskType,
VAppStatus expectedStatus) { VAppStatus expectedStatus) {
if (!taskTester.apply(deployTask.getLocation())) { if (!taskTester.apply(deployTask.getLocation())) {
throw new TaskException(taskType, vApp, deployTask); throw new TaskException(taskType, vApp, deployTask);
@ -175,7 +175,7 @@ public class VCloudComputeClient {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L; private static final long serialVersionUID = 251801929573211256L;
public TaskException(String type, VApp vApp, Task task) { public TaskException(String type, TerremarkVApp vApp, Task task) {
super(String.format("failed to %s vApp %s status %s;task %s status %s", type, super(String.format("failed to %s vApp %s status %s;task %s status %s", type,
vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp);
this.task = task; this.task = task;
@ -206,16 +206,16 @@ public class VCloudComputeClient {
public static class VAppException extends RuntimeException { public static class VAppException extends RuntimeException {
private final VApp vApp; private final TerremarkVApp vApp;
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = 251801929573211256L; private static final long serialVersionUID = 251801929573211256L;
public VAppException(String message, VApp vApp) { public VAppException(String message, TerremarkVApp vApp) {
super(message); super(message);
this.vApp = vApp; this.vApp = vApp;
} }
public VApp getvApp() { public TerremarkVApp getvApp() {
return vApp; return vApp;
} }

View File

@ -46,12 +46,12 @@ import com.google.inject.Injector;
import com.google.inject.Provides; import com.google.inject.Provides;
/** /**
* Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlEntity} * Tests behavior of {@code TerremarkBindInstantiateVAppTemplateParamsToXmlEntity}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlEntityTest") @Test(groups = "unit", testName = "vcloud.TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest")
public class BindInstantiateVAppTemplateParamsToXmlEntityTest { public class TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest {
Injector injector = Guice.createInjector(new AbstractModule() { Injector injector = Guice.createInjector(new AbstractModule() {
@Override @Override
@ -73,8 +73,8 @@ public class BindInstantiateVAppTemplateParamsToXmlEntityTest {
String expected = IOUtils.toString(getClass().getResourceAsStream( String expected = IOUtils.toString(getClass().getResourceAsStream(
"/terremark/InstantiateVAppTemplateParams-test-2.xml")); "/terremark/InstantiateVAppTemplateParams-test-2.xml"));
HttpRequest request = new HttpRequest("GET", URI.create("http://test")); HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindInstantiateVAppTemplateParamsToXmlEntity binder = injector TerremarkBindInstantiateVAppTemplateParamsToXmlEntity binder = injector
.getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class); .getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class);
Map<String, String> map = Maps.newHashMap(); Map<String, String> map = Maps.newHashMap();
map.put("name", "name"); map.put("name", "name");

View File

@ -1,129 +0,0 @@
package org.jclouds.vcloud.terremark.options;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.cpuCount;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.inGroup;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.inNetwork;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.inRow;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.megabytes;
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.withPassword;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code InstantiateVAppTemplateOptions}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.InstantiateVAppTemplateOptionsTest")
public class InstantiateVAppTemplateOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
@Test
public void testInGroupDefault() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
assertEquals(options.group, "default");
}
@Test
public void testInGroup() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.inGroup("group1");
assertEquals(options.group, "group1");
}
@Test
public void testInGroupStatic() {
InstantiateVAppTemplateOptions options = inGroup("group1");
assertEquals(options.group, "group1");
}
@Test
public void testInRowDefault() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
assertEquals(options.row, "default");
}
@Test
public void testInRow() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.inRow("row1");
assertEquals(options.row, "row1");
}
@Test
public void testInRowStatic() {
InstantiateVAppTemplateOptions options = inRow("row1");
assertEquals(options.row, "row1");
}
@Test
public void testWithPasswordDefault() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
assertEquals(options.password, "password");
}
@Test
public void testWithPassword() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.withPassword("password1");
assertEquals(options.password, "password1");
}
@Test
public void testWithPasswordStatic() {
InstantiateVAppTemplateOptions options = withPassword("password1");
assertEquals(options.password, "password1");
}
@Test
public void testInNetwork() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.inNetwork(URI.create("http://localhost"));
assertEquals(options.network, "http://localhost");
}
@Test
public void testInNetworkStatic() {
InstantiateVAppTemplateOptions options = inNetwork(URI.create("http://localhost"));
assertEquals(options.network, "http://localhost");
}
@Test
public void testCpuCount() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.cpuCount(3);
assertEquals(options.cpuCount, "3");
}
@Test
public void testCpuCountStatic() {
InstantiateVAppTemplateOptions options = cpuCount(3);
assertEquals(options.cpuCount, "3");
}
@Test
public void testMegabytes() {
InstantiateVAppTemplateOptions options = new InstantiateVAppTemplateOptions();
options.megabytes(512);
assertEquals(options.megabytes, "512");
}
@Test
public void testMegabytesStatic() {
InstantiateVAppTemplateOptions options = megabytes(512);
assertEquals(options.megabytes, "512");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMegabytesStaticWrong() {
megabytes(511);
}
}

View File

@ -0,0 +1,129 @@
package org.jclouds.vcloud.terremark.options;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inGroup;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inNetwork;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.inRow;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.megabytes;
import static org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions.Builder.withPassword;
import static org.testng.Assert.assertEquals;
import java.net.URI;
import org.jclouds.http.functions.config.ParserModule;
import org.testng.annotations.Test;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* Tests behavior of {@code TerremarkInstantiateVAppTemplateOptions}
*
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "vcloud.TerremarkInstantiateVAppTemplateOptionsTest")
public class TerremarkInstantiateVAppTemplateOptionsTest {
Injector injector = Guice.createInjector(new ParserModule());
@Test
public void testInGroupDefault() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
assertEquals(options.getGroup(), "default");
}
@Test
public void testInGroup() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.inGroup("group1");
assertEquals(options.getGroup(), "group1");
}
@Test
public void testInGroupStatic() {
TerremarkInstantiateVAppTemplateOptions options = inGroup("group1");
assertEquals(options.getGroup(), "group1");
}
@Test
public void testInRowDefault() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
assertEquals(options.getRow(), "default");
}
@Test
public void testInRow() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.inRow("row1");
assertEquals(options.getRow(), "row1");
}
@Test
public void testInRowStatic() {
TerremarkInstantiateVAppTemplateOptions options = inRow("row1");
assertEquals(options.getRow(), "row1");
}
@Test
public void testWithPasswordDefault() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
assertEquals(options.getPassword(), "getPassword()");
}
@Test
public void testWithPassword() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.withPassword("password1");
assertEquals(options.getPassword(), "password1");
}
@Test
public void testWithPasswordStatic() {
TerremarkInstantiateVAppTemplateOptions options = withPassword("password1");
assertEquals(options.getPassword(), "password1");
}
@Test
public void testInNetwork() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.inNetwork(URI.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}
@Test
public void testInNetworkStatic() {
TerremarkInstantiateVAppTemplateOptions options = inNetwork(URI.create("http://localhost"));
assertEquals(options.getNetwork(), "http://localhost");
}
@Test
public void testCpuCount() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
cpuCount(3);
assertEquals(options.getCpuCount(), "3");
}
@Test
public void testCpuCountStatic() {
TerremarkInstantiateVAppTemplateOptions options = cpuCount(3);
assertEquals(options.getCpuCount(), "3");
}
@Test
public void testMegabytes() {
TerremarkInstantiateVAppTemplateOptions options = new TerremarkInstantiateVAppTemplateOptions();
options.megabytes(512);
assertEquals(options.getMegabytes(), "512");
}
@Test
public void testMegabytesStatic() {
TerremarkInstantiateVAppTemplateOptions options = megabytes(512);
assertEquals(options.getMegabytes(), "512");
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void testMegabytesStaticWrong() {
megabytes(511);
}
}

View File

@ -28,8 +28,8 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.terremark.domain.ResourceAllocation; import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.terremark.domain.ResourceType; import org.jclouds.vcloud.domain.ResourceType;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -54,10 +54,10 @@ public class ResourceAllocationHandlerTest extends BaseHandlerTest {
injector.getInstance(ResourceAllocationHandler.class)).parse(is); injector.getInstance(ResourceAllocationHandler.class)).parse(is);
assertEquals(result.getAddress(), new Integer(0)); assertEquals(result.getAddress(), new Integer(0));
assertEquals(result.getDescription(), "SCSI Controller"); assertEquals(result.getDescription(), "SCSI Controller");
assertEquals(result.getElementName(), "SCSI Controller 0"); assertEquals(result.getName(), "SCSI Controller 0");
assertEquals(result.getInstanceID(), 3); assertEquals(result.getId(), 3);
assertEquals(result.getResourceSubType(), "lsilogic"); assertEquals(result.getSubType(), "lsilogic");
assertEquals(result.getResourceType(), ResourceType.SCSI_CONTROLLER); assertEquals(result.getType(), ResourceType.SCSI_CONTROLLER);
assertEquals(result.getVirtualQuantity(), 1); assertEquals(result.getVirtualQuantity(), 1);
} }

View File

@ -37,12 +37,12 @@ import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.config.ParserModule; import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.rest.domain.internal.LinkImpl; import org.jclouds.rest.domain.internal.LinkImpl;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.domain.ResourceAllocation;
import org.jclouds.vcloud.domain.ResourceType;
import org.jclouds.vcloud.domain.TerremarkVirtualSystem;
import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.domain.VAppStatus;
import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot;
import org.jclouds.vcloud.terremark.domain.ResourceAllocation; import org.jclouds.vcloud.terremark.domain.TerremarkVApp;
import org.jclouds.vcloud.terremark.domain.ResourceType;
import org.jclouds.vcloud.terremark.domain.VApp;
import org.jclouds.vcloud.terremark.domain.VirtualSystem;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -83,8 +83,8 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/launched_vapp.xml"); InputStream is = getClass().getResourceAsStream("/terremark/launched_vapp.xml");
VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( TerremarkVApp result = (TerremarkVApp) factory.create(
is); injector.getInstance(TerremarkVAppHandler.class)).parse(is);
assertEquals(result.getId(), 13775 + ""); assertEquals(result.getId(), 13775 + "");
assertEquals(result.getName(), "adriantest"); assertEquals(result.getName(), "adriantest");
@ -94,7 +94,6 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13775")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13775"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vApp+xml");
assertEquals(result.getVDC(), new LinkImpl("application/vnd.vmware.vcloud.vdc+xml", URI assertEquals(result.getVDC(), new LinkImpl("application/vnd.vmware.vcloud.vdc+xml", URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
@ -103,8 +102,8 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
public void testGetVApp() throws UnknownHostException { public void testGetVApp() throws UnknownHostException {
InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml"); InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml");
VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( TerremarkVApp result = (TerremarkVApp) factory.create(
is); injector.getInstance(TerremarkVAppHandler.class)).parse(is);
assertEquals(result.getId(), 13850 + ""); assertEquals(result.getId(), 13850 + "");
assertEquals(result.getName(), "adriantest1"); assertEquals(result.getName(), "adriantest1");
@ -115,7 +114,6 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
assertEquals(result.getLocation(), URI assertEquals(result.getLocation(), URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850")); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850"));
assertEquals(result.getType(), "application/vnd.vmware.vcloud.vApp+xml");
assertEquals(result.getVDC(), new LinkImpl(VCloudMediaType.VDC_XML, URI assertEquals(result.getVDC(), new LinkImpl(VCloudMediaType.VDC_XML, URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32")));
assertEquals( assertEquals(
@ -130,35 +128,34 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
MediaType.APPLICATION_XML, MediaType.APPLICATION_XML,
URI URI
.create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850/options/customization"))); .create("https://services.vcloudexpress.terremark.com/api/v0.8/vapp/13850/options/customization")));
assertEquals(result.getSystem(), new VirtualSystem(null, null, null, null, null, null, null, assertEquals(result.getSystem(), new TerremarkVirtualSystem(null, null, null, null, null,
null, null, null, null, "Virtual Hardware Family", 0, null, null, null, null, null, null, null, null, null, null, null, "Virtual Hardware Family", 0, null, null, null,
"adriantest1", "vmx-07")); null, null, "adriantest1", "vmx-07"));
assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.of(InetAddress assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.of(InetAddress
.getByName("10.114.34.132"))); .getByName("10.114.34.132")));
ResourceAllocation cpu = new ResourceAllocation(null, null, "hertz * 10^6", null, null, null, ResourceAllocation cpu = new ResourceAllocation(1, "1 virtual CPU(s)",
null, "Number of Virtual CPUs", "1 virtual CPU(s)", null, 1, null, null, null, null, "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, 1,
null, null, null, ResourceType.VIRTUAL_CPU, 1, "count", null); "hertz * 10^6");
ResourceAllocation controller = new ResourceAllocation(0, null, null, null, null, null, null,
"SCSI Controller", "SCSI Controller 0", null, 3, null, null, null, null, null, null, ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0",
"lsilogic", ResourceType.SCSI_CONTROLLER, 1, null, null); "SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", 0, null, null, null, 1,
ResourceAllocation memory = new ResourceAllocation(null, null, "byte * 2^20", null, null, null);
null, null, "Memory Size", "512MB of memory", null, 2, null, null, null, null, null, ResourceAllocation memory = new ResourceAllocation(2, "512MB of memory", "Memory Size",
null, null, ResourceType.MEMORY, 512, "byte * 2^20", null); ResourceType.MEMORY, null, null, null, null, null, 512, "byte * 2^20");
ResourceAllocation disk = new ResourceAllocation(null, 0, null, null, null, null, null, null, ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null,
"Hard Disk 1", "4194304", 9, null, null, null, 3, null, null, null, ResourceType.DISK_DRIVE, null, null, 0, 3, null, 4194304, null);
ResourceType.VIRTUAL_DISK, 4194304, null, null);
assertEquals(result.getResourceAllocations(), ImmutableSortedSet.of(cpu, controller, memory, assertEquals(result.getResourceAllocations(), ImmutableSortedSet.of(cpu, controller, memory,
disk)); disk));
assertEquals(result.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) assertEquals(result.getResourceAllocationByType().get(ResourceType.PROCESSOR)
.getVirtualQuantity(), 1); .getVirtualQuantity(), 1);
assertEquals(result.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) assertEquals(result.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER)
.getVirtualQuantity(), 1); .getVirtualQuantity(), 1);
assertEquals(result.getResourceAllocationByType().get(ResourceType.MEMORY) assertEquals(result.getResourceAllocationByType().get(ResourceType.MEMORY)
.getVirtualQuantity(), 512); .getVirtualQuantity(), 512);
assertEquals(result.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) assertEquals(result.getResourceAllocationByType().get(ResourceType.DISK_DRIVE)
.getVirtualQuantity(), 4194304); .getVirtualQuantity(), 4194304);
assertEquals(result.getSize(), result.getResourceAllocationByType().get( assertEquals(result.getSize(), result.getResourceAllocationByType().get(
ResourceType.VIRTUAL_DISK).getVirtualQuantity()); ResourceType.DISK_DRIVE).getVirtualQuantity());
} }
} }

View File

@ -28,7 +28,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.vcloud.terremark.domain.VirtualSystem; import org.jclouds.vcloud.domain.TerremarkVirtualSystem;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -49,11 +49,11 @@ public class VirtualSystemHandlerTest extends BaseHandlerTest {
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/terremark/system.xml"); InputStream is = getClass().getResourceAsStream("/terremark/system.xml");
VirtualSystem result = (VirtualSystem) factory.create( TerremarkVirtualSystem result = (TerremarkVirtualSystem) factory.create(
injector.getInstance(VirtualSystemHandler.class)).parse(is); injector.getInstance(VirtualSystemHandler.class)).parse(is);
assertEquals(result.getElementName(), "Virtual Hardware Family"); assertEquals(result.getName(), "Virtual Hardware Family");
assertEquals(result.getInstanceID(), 0); assertEquals(result.getId(), 0);
assertEquals(result.getVirtualSystemIdentifier(), "adriantest1"); assertEquals(result.getIdentifier(), "adriantest1");
assertEquals(result.getVirtualSystemType(), "vmx-07"); assertEquals(result.getType(), "vmx-07");
} }
} }