diff --git a/pom.xml b/pom.xml index 4f4725a813..7ead5a9214 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,6 @@ rackspace mezeo nirvanix - vcloud twitter rimuhosting scriptbuilder diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java index f50173d5ae..24f0a7a323 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudAsyncClient.java @@ -41,16 +41,24 @@ 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.binders.BindInstantiateVAppTemplateParamsToXmlEntity; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; +import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; 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.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; +import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VDCHandler; /** @@ -66,7 +74,6 @@ public interface VCloudAsyncClient { @GET @Endpoint(org.jclouds.vcloud.endpoints.Catalog.class) @Consumes(CATALOG_XML) - @Produces(CATALOG_XML)// required for hosting.com to operate @XMLResponseParser(CatalogHandler.class) Future getCatalog(); @@ -162,5 +169,17 @@ public interface VCloudAsyncClient { @Consumes(VAPP_XML) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}") - Future getVAppString(@PathParam("vAppId") String appId); + @XMLResponseParser(VAppHandler.class) + Future 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 instantiateVAppTemplate(@MapEntityParam("name") String appName, + @MapEntityParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, + InstantiateVAppTemplateOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index 4ae620bbbe..86004a3543 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -30,7 +30,9 @@ import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.TasksList; +import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; /** * Provides access to VCloud resources via their REST API. @@ -41,13 +43,13 @@ import org.jclouds.vcloud.domain.VDC; */ @Timeout(duration = 45, timeUnit = TimeUnit.SECONDS) public interface VCloudClient { - + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) Catalog getCatalog(); - + @Timeout(duration = 180, timeUnit = TimeUnit.SECONDS) VDC getDefaultVDC(); - + @Timeout(duration = 90, timeUnit = TimeUnit.SECONDS) TasksList getDefaultTasksList(); @@ -86,5 +88,8 @@ public interface VCloudClient { void cancelTask(URI task); - String getVAppString(String appId); + VApp getVApp(String appId); + + VApp instantiateVAppTemplate(String appName, String templateId, + InstantiateVAppTemplateOptions... options); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java index 7190900356..aab7acdf6c 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudPropertiesBuilder.java @@ -24,6 +24,8 @@ package org.jclouds.vcloud; 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_KEY; import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL; @@ -46,6 +48,8 @@ public class VCloudPropertiesBuilder extends HttpPropertiesBuilder { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_VCLOUD_VERSION, "0.8"); properties.setProperty(PROPERTY_VCLOUD_SESSIONINTERVAL, 9 * 60 + ""); + properties.setProperty(PROPERTY_VCLOUD_DEFAULTCPUCOUNT, "1"); + properties.setProperty(PROPERTY_VCLOUD_DEFAULTMEMORY, "512"); return properties; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlEntity.java b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlEntity.java new file mode 100644 index 0000000000..f7f21c7a8a --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlEntity.java @@ -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 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 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(postParams); + postParams.putAll(defaultParams); + addOptionsToMap(postParams, gRequest); + + String entity = xmlTemplate; + for (Entry entry : postParams.entrySet()) { + entity = entity.replaceAll("\\{" + entry.getKey() + "\\}", entry.getValue()); + } + stringBinder.bindToRequest(request, entity); + } + + protected void addOptionsToMap(Map 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"); + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index 2f4b275873..2fdfab3af5 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -23,17 +23,21 @@ */ package org.jclouds.vcloud.config; +import java.io.IOException; +import java.io.InputStream; import java.net.URI; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import javax.inject.Named; 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.util.Utils; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; 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.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot; +import org.jclouds.vcloud.endpoints.internal.VAppTemplateRoot; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -89,11 +94,18 @@ public class VCloudRestClientModule extends AbstractModule { return vcloudUri.toASCIIString().replace("/login", "/vapp"); } + @Provides + @VAppTemplateRoot + @Singleton + String provideVAppTemplateRoot(@VCloudLogin URI vcloudUri) { + return vcloudUri.toASCIIString().replace("/login", "/vAppTemplate"); + } + @Provides @Singleton protected Organization provideOrganization(VCloudDiscovery discovery) throws ExecutionException, TimeoutException, InterruptedException { - return discovery.getOrganization().get(60, TimeUnit.SECONDS); + return discovery.getOrganization().get(90, TimeUnit.SECONDS); } @Provides @@ -110,6 +122,14 @@ public class VCloudRestClientModule extends AbstractModule { return org.getCatalog().getLocation(); } + @Singleton + @Provides + @Named("InstantiateVAppTemplateParams") + protected String provideInstantiateVAppTemplateParams() throws IOException { + InputStream is = getClass().getResourceAsStream("/InstantiateVAppTemplateParams.xml"); + return Utils.toStringAndClose(is); + } + @Provides @Network @Singleton diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java index 8758a953ef..e536dddcea 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/Catalog.java @@ -26,6 +26,7 @@ package org.jclouds.vcloud.domain; import java.net.URI; import java.util.Map; +import org.jclouds.rest.domain.NamedResource; import org.jclouds.vcloud.domain.internal.CatalogImpl; import com.google.inject.ImplementedBy; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java deleted file mode 100644 index 0b1da8af26..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/NamedResource.java +++ /dev/null @@ -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 { - String getId(); -} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java new file mode 100644 index 0000000000..29178b80fd --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceAllocation.java @@ -0,0 +1,210 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Adrian Cole + * + */ +public class ResourceAllocation implements Comparable { + + 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 + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java index 0e7b4960c9..300c774143 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/ResourceType.java @@ -10,29 +10,36 @@ import org.jclouds.vcloud.VCloudAsyncClient; * * @author Adrian Cole * @see VCloudAsyncClient#getVApp - * + * @see * */ public enum ResourceType { - - VIRTUAL_CPU, - - MEMORY, - - SCSI_CONTROLLER, - - VIRTUAL_DISK; + OTHER, PROCESSOR, MEMORY, IDE_CONTROLLER, SCSI_CONTROLLER, ETHERNET_ADAPTER, FLOPPY_DRIVE, CD_DRIVE, DVD_DRIVE, DISK_DRIVE, USB_CONTROLLER; public String value() { switch (this) { - case VIRTUAL_CPU: + case OTHER: + return "1"; + case PROCESSOR: return "3"; case MEMORY: return "4"; + case IDE_CONTROLLER: + return "5"; case SCSI_CONTROLLER: 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"; + case USB_CONTROLLER: + return "23"; default: throw new IllegalArgumentException("invalid type:" + this); } @@ -44,14 +51,28 @@ public enum ResourceType { public static ResourceType fromValue(int v) { switch (v) { + case 1: + return OTHER; case 3: - return VIRTUAL_CPU; + return PROCESSOR; case 4: return MEMORY; + case 5: + return IDE_CONTROLLER; case 6: 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: - return VIRTUAL_DISK; + return DISK_DRIVE; + case 23: + return USB_CONTROLLER; default: throw new IllegalArgumentException("invalid type:" + v); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TerremarkResourceAllocation.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TerremarkResourceAllocation.java new file mode 100644 index 0000000000..084b6347ef --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TerremarkResourceAllocation.java @@ -0,0 +1,348 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * @author Adrian Cole + */ +public class TerremarkResourceAllocation implements Comparable { + 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; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TerremarkVirtualSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TerremarkVirtualSystem.java new file mode 100644 index 0000000000..9c9ced7947 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/TerremarkVirtualSystem.java @@ -0,0 +1,305 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.domain; + +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 + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java similarity index 71% rename from vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java index fc138b5bad..7e81484b98 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VApp.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2009 Global Cloud Specialists, Inc. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -21,36 +21,24 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloud.terremark.domain; +package org.jclouds.vcloud.domain; import java.net.InetAddress; +import java.net.URI; import java.util.Map; 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.inject.ImplementedBy; -/** - * @author Adrian Cole - */ -@ImplementedBy(VAppImpl.class) -public interface VApp extends NamedResource { +public interface VApp { + String getId(); + + URI getLocation(); + + String getName(); VAppStatus getStatus(); - long getSize(); - - Link getVDC(); - - Link getComputeOptions(); - - Link getCustomizationOptions(); - ListMultimap getNetworkToAddresses(); String getOperatingSystemDescription(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java index 2565e638f3..4aa001aa82 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VAppStatus.java @@ -29,12 +29,14 @@ import static com.google.common.base.Preconditions.checkNotNull; * @author Adrian Cole */ public enum VAppStatus { - CREATING, OFF, ON; + CREATING, TODO_I_DONT_KNOW, OFF, ON; public String value() { switch (this) { case CREATING: return "0"; + case TODO_I_DONT_KNOW: + return "1"; case OFF: return "2"; case ON: @@ -52,6 +54,8 @@ public enum VAppStatus { switch (v) { case 0: return CREATING; + case 1: + return TODO_I_DONT_KNOW; case 2: return OFF; case 4: diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java index 0e22fe5498..bc6fb93d8b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VDC.java @@ -26,7 +26,7 @@ package org.jclouds.vcloud.domain; import java.net.URI; import java.util.Map; -import org.jclouds.rest.domain.NamedLink; +import org.jclouds.rest.domain.NamedResource; import org.jclouds.vcloud.domain.internal.VDCImpl; import com.google.inject.ImplementedBy; @@ -56,8 +56,8 @@ public interface VDC { Quota getDeployedVmsQuota(); - Map getAvailableNetworks(); + Map getAvailableNetworks(); - Map getResourceEntities(); + Map getResourceEntities(); } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java new file mode 100644 index 0000000000..06ac7d2130 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/VirtualSystem.java @@ -0,0 +1,103 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * 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 + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java index 0253868b57..d3d6b184c1 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/CatalogImpl.java @@ -29,8 +29,8 @@ import java.net.URI; import java.util.SortedMap; import java.util.TreeMap; +import org.jclouds.rest.domain.NamedResource; import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.NamedResource; import com.google.inject.internal.Nullable; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java deleted file mode 100644 index 094ea91675..0000000000 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/NamedResourceImpl.java +++ /dev/null @@ -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() + "]"; - } -} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java similarity index 72% rename from vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java index 490b843474..a503e6a943 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VAppImpl.java @@ -21,20 +21,18 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloud.terremark.domain.internal; +package org.jclouds.vcloud.domain.internal; import java.net.InetAddress; import java.net.URI; import java.util.Map; 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.internal.NamedResourceImpl; -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 org.jclouds.vcloud.domain.VirtualSystem; import com.google.common.base.Function; import com.google.common.collect.ListMultimap; @@ -46,13 +44,11 @@ import com.google.common.collect.Maps; * @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 long size; - private final Link vDC; - private final Link computeOptions; - private final Link customizationOptions; private final ListMultimap networkToAddresses; private final String operatingSystemDescription; private final VirtualSystem system; @@ -62,17 +58,14 @@ public class VAppImpl extends NamedResourceImpl implements VApp { /** The serialVersionUID */ private static final long serialVersionUID = 8464716396538298809L; - public VAppImpl(String id, String name, String type, URI location, VAppStatus status, long size, - Link vDC, Link computeOptions, Link customizationOptions, + public VAppImpl(String id, String name, URI location, VAppStatus status, ListMultimap networkToAddresses, String operatingSystemDescription, VirtualSystem system, SortedSet resourceAllocations) { - super(id, name, type, location); + this.id = id; + this.name = name; + this.location = location; this.status = status; - this.size = size; - this.vDC = vDC; - this.computeOptions = computeOptions; - this.customizationOptions = customizationOptions; this.networkToAddresses = networkToAddresses; this.operatingSystemDescription = operatingSystemDescription; this.system = system; @@ -81,7 +74,7 @@ public class VAppImpl extends NamedResourceImpl implements VApp { new Function() { @Override public ResourceType apply(ResourceAllocation from) { - return from.getResourceType(); + return from.getType(); } }); } @@ -90,22 +83,6 @@ public class VAppImpl extends NamedResourceImpl implements VApp { return status; } - public long getSize() { - return size; - } - - public Link getVDC() { - return vDC; - } - - public Link getComputeOptions() { - return computeOptions; - } - - public Link getCustomizationOptions() { - return customizationOptions; - } - public ListMultimap getNetworkToAddresses() { return networkToAddresses; } @@ -122,13 +99,17 @@ public class VAppImpl extends NamedResourceImpl implements VApp { return resourceAllocations; } + public Map getResourceAllocationByType() { + return resourceAllocationByType; + } + @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()); + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + ((location == null) ? 0 : location.hashCode()); + result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); result = prime * result + ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); @@ -136,10 +117,8 @@ public class VAppImpl extends NamedResourceImpl implements VApp { + ((resourceAllocationByType == null) ? 0 : resourceAllocationByType.hashCode()); result = prime * result + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); - result = prime * result + (int) (size ^ (size >>> 32)); result = prime * result + ((status == null) ? 0 : status.hashCode()); result = prime * result + ((system == null) ? 0 : system.hashCode()); - result = prime * result + ((vDC == null) ? 0 : vDC.hashCode()); return result; } @@ -147,20 +126,25 @@ public class VAppImpl extends NamedResourceImpl implements VApp { public boolean equals(Object obj) { if (this == obj) return true; - if (!super.equals(obj)) + if (obj == null) return false; if (getClass() != obj.getClass()) return false; VAppImpl other = (VAppImpl) obj; - if (computeOptions == null) { - if (other.computeOptions != null) + if (id == null) { + if (other.id != null) return false; - } else if (!computeOptions.equals(other.computeOptions)) + } else if (!id.equals(other.id)) return false; - if (customizationOptions == null) { - if (other.customizationOptions != null) + if (location == null) { + if (other.location != null) 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; if (networkToAddresses == null) { if (other.networkToAddresses != null) @@ -182,8 +166,6 @@ public class VAppImpl extends NamedResourceImpl implements VApp { return false; } else if (!resourceAllocations.equals(other.resourceAllocations)) return false; - if (size != other.size) - return false; if (status == null) { if (other.status != null) return false; @@ -194,16 +176,28 @@ public class VAppImpl extends NamedResourceImpl implements VApp { return false; } else if (!system.equals(other.system)) return false; - if (vDC == null) { - if (other.vDC != null) - return false; - } else if (!vDC.equals(other.vDC)) - return false; return true; } - public Map getResourceAllocationByType() { - return resourceAllocationByType; + public String getId() { + 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 + "]"; } } \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java index 7ade0eaf8b..75c15675de 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/domain/internal/VDCImpl.java @@ -28,7 +28,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import java.net.URI; 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.Quota; import org.jclouds.vcloud.domain.VDC; @@ -50,13 +50,14 @@ public class VDCImpl implements VDC { private final Capacity memoryCapacity; private final Quota instantiatedVmsQuota; private final Quota deployedVmsQuota; - private final Map availableNetworks; - private final Map resourceEntities; + private final Map availableNetworks; + private final Map resourceEntities; - public VDCImpl(String id, String name, URI location, String description, Capacity storageCapacity, - Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, - Quota deployedVmsQuota, Map resourceEntities, - Map availableNetworks) { + public VDCImpl(String id, String name, URI location, String description, + Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, + Quota instantiatedVmsQuota, Quota deployedVmsQuota, + Map resourceEntities, + Map availableNetworks) { this.id = id; this.name = checkNotNull(name, "name"); this.location = checkNotNull(location, "location"); @@ -85,11 +86,11 @@ public class VDCImpl implements VDC { return location; } - public Map getAvailableNetworks() { + public Map getAvailableNetworks() { return availableNetworks; } - public Map getResourceEntities() { + public Map getResourceEntities() { return resourceEntities; } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/internal/VAppTemplateRoot.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/internal/VAppTemplateRoot.java new file mode 100644 index 0000000000..0d52935f56 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/internal/VAppTemplateRoot.java @@ -0,0 +1,44 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 { + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplateIdToUri.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplateIdToUri.java new file mode 100644 index 0000000000..262d227f86 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppTemplateIdToUri.java @@ -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 { + @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); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java new file mode 100644 index 0000000000..10472d386b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptions.java @@ -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); + } + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java index 0917b202d6..e711f982b2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/reference/VCloudConstants.java @@ -37,4 +37,8 @@ public interface VCloudConstants { * automatically renew vcloud token before this interval expires. */ 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"; + } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java index ea2884acd6..b35e790475 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/CatalogHandler.java @@ -31,11 +31,11 @@ import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; import org.jclouds.rest.domain.NamedLink; +import org.jclouds.rest.domain.NamedResource; import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.rest.internal.NamedResourceImpl; 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.NamedResourceImpl; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.xml.sax.Attributes; import org.xml.sax.SAXException; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java index be346c4bbb..41eda4be70 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/OrgHandler.java @@ -36,9 +36,9 @@ import javax.inject.Inject; import org.jclouds.http.functions.ParseSax; 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.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.OrganizationImpl; import org.jclouds.vcloud.endpoints.VCloudApi; import org.xml.sax.Attributes; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java new file mode 100644 index 0000000000..ed1210a413 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/ResourceAllocationHandler.java @@ -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 { + 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; + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java new file mode 100644 index 0000000000..f9a745622b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VAppHandler.java @@ -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 { + + 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 allocations = Sets.newTreeSet(); + protected VAppStatus status; + protected final ListMultimap 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; + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java index 62b91ed88d..9bf37605ef 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VDCHandler.java @@ -23,22 +23,17 @@ */ 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 javax.inject.Inject; - 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.NamedResource; import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; -import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.internal.VDCImpl; -import org.jclouds.vcloud.endpoints.VCloudApi; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -51,11 +46,8 @@ public class VDCHandler extends ParseSax.HandlerWithResult { private StringBuilder currentText = new StringBuilder(); private NamedResource vDC; - private Map resourceEntities = Maps.newHashMap(); - private Map availableNetworks = Maps.newHashMap(); - @Inject - @VCloudApi - URI vcloudUri; + private Map resourceEntities = Maps.newHashMap(); + private Map availableNetworks = Maps.newHashMap(); private String description; @@ -89,9 +81,9 @@ public class VDCHandler extends ParseSax.HandlerWithResult { if (qName.equals("Vdc")) { vDC = newNamedResource(attributes); } else if (qName.equals("Network")) { - putNamedLink(availableNetworks, attributes); + putNamedResource(availableNetworks, attributes); } else if (qName.equals("ResourceEntity")) { - putNamedLink(resourceEntities, attributes); + putNamedResource(resourceEntities, attributes); } } @@ -124,13 +116,6 @@ public class VDCHandler extends ParseSax.HandlerWithResult { 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() { String returnVal = currentText.toString().trim(); return returnVal.equals("") ? null : returnVal; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java new file mode 100644 index 0000000000..200a9a7990 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/xml/VirtualSystemHandler.java @@ -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 { + 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); + } +} diff --git a/vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml b/vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml new file mode 100644 index 0000000000..38256f7db8 --- /dev/null +++ b/vcloud/core/src/main/resources/InstantiateVAppTemplateParams.xml @@ -0,0 +1,17 @@ + + + + + + + + allowInOut + false + + + + + + \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java similarity index 93% rename from vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java rename to vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java index a129940070..8867a2573d 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudAsyncClientTest.java @@ -48,6 +48,7 @@ import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.xml.CatalogHandler; import org.jclouds.vcloud.xml.TaskHandler; import org.jclouds.vcloud.xml.TasksListHandler; +import org.jclouds.vcloud.xml.VAppHandler; import org.jclouds.vcloud.xml.VDCHandler; import org.testng.annotations.Test; @@ -56,12 +57,12 @@ import com.google.inject.Module; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code VCloudClient} + * Tests behavior of {@code VCloudAsyncClient} * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloud.VCloudClientTest") -public class VCloudClientTest extends RestClientTest { +@Test(groups = "unit", testName = "vcloud.VCloudAsyncClientTest") +public class VCloudAsyncClientTest extends RestClientTest { public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudAsyncClient.class.getMethod("getCatalog"); @@ -70,7 +71,7 @@ public class VCloudClientTest extends RestClientTest { 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"); + "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); assertEntityEquals(httpMethod, null); assertResponseParserClassEquals(method, httpMethod, ParseSax.class); @@ -126,6 +127,21 @@ public class VCloudClientTest extends RestClientTest { checkFilters(httpMethod); } + public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { + Method method = VCloudAsyncClient.class.getMethod("getVApp", String.class); + GeneratedHttpRequest 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 { Method method = VCloudAsyncClient.class.getMethod("undeployVApp", String.class); GeneratedHttpRequest httpMethod = processor.createRequest(method, 1); diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 53f2bdc299..25c3b86c2b 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -30,8 +30,10 @@ import static org.testng.Assert.assertNotNull; import java.net.URI; import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.rest.domain.NamedResource; import org.jclouds.vcloud.domain.Catalog; import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.VApp; import org.jclouds.vcloud.domain.VDC; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -81,16 +83,19 @@ public class VCloudClientLiveTest { assertNotNull(response.getLocation()); assertNotNull(response.getTasks()); for (Task t : response.getTasks()) { - assertEquals(connection.getTask(t.getLocation()).getLocation(), - t.getLocation()); + assertEquals(connection.getTask(t.getLocation()).getLocation(), t.getLocation()); } } - @Test(enabled = false) + @Test(enabled = true) public void testGetVApp() throws Exception { - String response = connection.getVAppString("188849-2"); - assertNotNull(response); - System.out.println(response); + VDC response = connection.getDefaultVDC(); + for (NamedResource item : response.getResourceEntities().values()) { + if (item.getType().equals(VCloudMediaType.VAPP_XML)) { + VApp app = connection.getVApp(item.getId()); + assertNotNull(app); + } + } } @BeforeGroups(groups = { "live" }) diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java new file mode 100644 index 0000000000..ddb3744ca6 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClient.java @@ -0,0 +1,228 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud; + +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 socketTester; + private final Predicate taskTester; + private final VCloudClient tmClient; + + @Inject + public VCloudComputeClient(VCloudClient tmClient, Factory sshFactory, + Predicate socketTester, Predicate 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 imageCatalogIdMap = ImmutableMap. 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; + } + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java new file mode 100644 index 0000000000..df8c1c8256 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudComputeClientLiveTest.java @@ -0,0 +1,193 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud; + +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 expectationMap = ImmutableMap. 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 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 socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 10, + TimeUnit.SECONDS);// make it longer then + // default internet + } + + @SuppressWarnings("unused") + @Provides + private Predicate addressTester(AddressReachable reachable) { + return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); + } + + @SuppressWarnings("unused") + @Provides + private Predicate successTester(TaskSuccess success) { + return new RetryablePredicate(success, 300, 10, TimeUnit.SECONDS); + } + + }).buildInjector(); + client = injector.getInstance(VCloudComputeClient.class); + tmClient = injector.getInstance(VCloudClient.class); + addressTester = injector.getInstance(Key.get(new TypeLiteral>() { + })); + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlEntityTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlEntityTest.java new file mode 100644 index 0000000000..d94d13f909 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlEntityTest.java @@ -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. of(null)); + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)).toProvider( + Providers. of(null)); + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)).toProvider( + Providers. 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 headers = Multimaps.synchronizedMultimap(HashMultimap + . 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 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")); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java new file mode 100644 index 0000000000..c4523e29b3 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java @@ -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"))); + + } + +} \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java new file mode 100644 index 0000000000..e086a32c53 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/options/InstantiateVAppTemplateOptionsTest.java @@ -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); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java index 2e7ce93ebb..0a55bc65aa 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/CatalogHandlerTest.java @@ -32,8 +32,8 @@ import java.net.URI; import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.rest.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.Catalog; -import org.jclouds.vcloud.domain.internal.NamedResourceImpl; import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.testng.annotations.Test; diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ResourceAllocationHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ResourceAllocationHandlerTest.java new file mode 100644 index 0000000000..77aef90217 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/ResourceAllocationHandlerTest.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java new file mode 100644 index 0000000000..7d03cb2682 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VAppHandlerTest.java @@ -0,0 +1,93 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 networkToAddresses = ImmutableListMultimap + . of("eth0", InetAddress.getByName("204.12.42.207")); + + VirtualSystem system = new VirtualSystem(0, "Virtual Hardware Family", "SimpleVM", "vmx-04"); + + SortedSet resourceAllocations = ImmutableSortedSet + . 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); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java index b8ee61068b..5501e7426d 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VDCHandlerTest.java @@ -32,7 +32,7 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax.Factory; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.NamedLink; -import org.jclouds.rest.domain.internal.NamedLinkImpl; +import org.jclouds.rest.internal.NamedResourceImpl; import org.jclouds.vcloud.domain.Capacity; import org.jclouds.vcloud.domain.Quota; import org.jclouds.vcloud.domain.VDC; @@ -51,7 +51,7 @@ import com.google.inject.Provides; * @author Adrian Cole */ @Test(groups = "unit", testName = "vcloud.VDCHandlerTest") -public class VDCHandlerTest { +public class VDCHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/vdc.xml"); @@ -86,7 +86,8 @@ public class VDCHandlerTest { ImmutableMap .of( "10.114.34.128/26", - new NamedLinkImpl( + new NamedResourceImpl( + "1708", "10.114.34.128/26", "application/vnd.vmware.vcloud.network+xml", URI @@ -125,7 +126,8 @@ public class VDCHandlerTest { new ImmutableMap.Builder() .put( "Plesk (Linux) 64-bit Template", - new NamedLinkImpl( + new NamedResourceImpl( + "1", "Plesk (Linux) 64-bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI @@ -133,35 +135,40 @@ public class VDCHandlerTest { .put( "Windows 2008 Datacenter 64 Bit Template", - new NamedLinkImpl( + new NamedResourceImpl( + "2", "Windows 2008 Datacenter 64 Bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/2"))) .put( "Cent OS 64 Bit Template", - new NamedLinkImpl( + new NamedResourceImpl( + "3", "Cent OS 64 Bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/3"))) .put( "cPanel (Linux) 64 Bit Template", - new NamedLinkImpl( + new NamedResourceImpl( + "4", "cPanel (Linux) 64 Bit Template", "application/vnd.vmware.vcloud.vAppTemplate+xml", URI .create("https://vcloud.safesecureweb.com/api/v0.8/vAppTemplate/4"))) .put( "188849-1", - new NamedLinkImpl( + new NamedResourceImpl( + "188849-1", "188849-1", "application/vnd.vmware.vcloud.vApp+xml", URI .create("https://vcloud.safesecureweb.com/api/v0.8/vApp/188849-1"))) .put( "188849-2", - new NamedLinkImpl( + new NamedResourceImpl( + "188849-2", "188849-2", "application/vnd.vmware.vcloud.vApp+xml", URI diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VirtualSystemHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VirtualSystemHandlerTest.java new file mode 100644 index 0000000000..8a6f589df9 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/xml/VirtualSystemHandlerTest.java @@ -0,0 +1,52 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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); + + } +} diff --git a/vcloud/core/src/test/resources/log4j.xml b/vcloud/core/src/test/resources/log4j.xml index f98e3505db..bdfc2a8733 100755 --- a/vcloud/core/src/test/resources/log4j.xml +++ b/vcloud/core/src/test/resources/log4j.xml @@ -146,13 +146,13 @@ - + diff --git a/vcloud/core/src/test/resources/newvapp-hosting.xml b/vcloud/core/src/test/resources/newvapp-hosting.xml new file mode 100644 index 0000000000..c18be4cabf --- /dev/null +++ b/vcloud/core/src/test/resources/newvapp-hosting.xml @@ -0,0 +1,17 @@ + + + + + + + + allowInOut + false + + + + + + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/resourceallocation-hosting.xml b/vcloud/core/src/test/resources/resourceallocation-hosting.xml new file mode 100644 index 0000000000..8d720aba02 --- /dev/null +++ b/vcloud/core/src/test/resources/resourceallocation-hosting.xml @@ -0,0 +1,15 @@ + + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + 3 + 1 + count + + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/vapp-hosting.xml b/vcloud/core/src/test/resources/vapp-hosting.xml new file mode 100644 index 0000000000..97b50b16ef --- /dev/null +++ b/vcloud/core/src/test/resources/vapp-hosting.xml @@ -0,0 +1,95 @@ + + + + + The list of logical networks + + + + + + + bridged + false + + + + + + + + 204.12.42.207 + VLAN 536 + + + + + + The kind of installed guest operating system + + + + + + Virtual hardware + + Virtual Hardware Family + 0 + SimpleVM + vmx-04 + + + hertz * 10^6 + Number of Virtual CPUs + 1 virtual CPU(s) + 1 + 3 + 1 + count + + + byte * 2^20 + Memory Size + 512MB of memory + 2 + 4 + 1536 + byte * 2^20 + + + 0 + SCSI Controller + SCSI Controller 0 + 3 + lsilogic + 6 + + + 7 + true + eth0 + PCNet32 ethernet adapter on "VLAN 536" network + Network Adapter 1 + 8 + PCNet32 + 10 + + + 0 + Hard Disk 1 + + 9 + 3 + 1 + + + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/virtualsystem-hosting.xml b/vcloud/core/src/test/resources/virtualsystem-hosting.xml new file mode 100644 index 0000000000..534d22f5b6 --- /dev/null +++ b/vcloud/core/src/test/resources/virtualsystem-hosting.xml @@ -0,0 +1,14 @@ + + + + + Virtual Hardware Family + 0 + SimpleVM + vmx-04 + + + \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java new file mode 100644 index 0000000000..896d8a6a81 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClient.java @@ -0,0 +1,94 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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. + *

+ * + * @see + * @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 getCatalog(); + + @GET + @Consumes(VAPP_XML) + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vapp/{vAppId}") + @XMLResponseParser(HostingDotComVAppHandler.class) + @Override + Future 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 instantiateVAppTemplate( + @MapEntityParam("name") String appName, + @MapEntityParam("template") @ParamParser(VAppTemplateIdToUri.class) String templateId, + InstantiateVAppTemplateOptions... options); +} diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java new file mode 100644 index 0000000000..e2b8331943 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudClient.java @@ -0,0 +1,50 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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. + *

+ * + * @see + * @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); + +} diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java new file mode 100644 index 0000000000..b11c495abe --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java @@ -0,0 +1,86 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules 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 { + + public HostingDotComVCloudContextBuilder(Properties props) { + super(new TypeLiteral() { + }, new TypeLiteral() { + }, props); + } + + @Override + protected void addClientModule(List modules) { + modules.add(new VCloudDiscoveryRestClientModule()); + modules.add(new HostingDotComVCloudRestClientModule()); + } + + @Override + protected void addContextModule(List 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); + } + +} diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java new file mode 100644 index 0000000000..645d2e3aa7 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudPropertiesBuilder.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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); + } +} diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java new file mode 100644 index 0000000000..0d93235963 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java @@ -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"); + } + +} diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/HostingDotComVApp.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/HostingDotComVApp.java new file mode 100644 index 0000000000..f44cfdbb30 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/HostingDotComVApp.java @@ -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(); +} \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java new file mode 100644 index 0000000000..1659970852 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/domain/internal/HostingDotComVAppImpl.java @@ -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 networkToAddresses, String operatingSystemDescription, + VirtualSystem system, SortedSet 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; + } +} \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/xml/HostingDotComVAppHandler.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/xml/HostingDotComVAppHandler.java new file mode 100644 index 0000000000..21019fd46b --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/xml/HostingDotComVAppHandler.java @@ -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(); + } + +} diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java new file mode 100644 index 0000000000..c5862c86b4 --- /dev/null +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudAsyncClientTest.java @@ -0,0 +1,153 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 { + public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { + Method method = HostingDotComVCloudAsyncClient.class.getMethod("getCatalog"); + GeneratedHttpRequest 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 httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @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() { + + 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")); + } + }; + } + +} diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClient.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClient.java new file mode 100644 index 0000000000..995857c3c4 --- /dev/null +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClient.java @@ -0,0 +1,237 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 socketTester; + private final Predicate taskTester; + private final HostingDotComVCloudClient tmClient; + + @Inject + public HostingDotComVCloudComputeClient(HostingDotComVCloudClient tmClient, Factory sshFactory, + Predicate socketTester, Predicate 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 imageCatalogIdMap = ImmutableMap. 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; + } + + } +} diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClientLiveTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClientLiveTest.java new file mode 100644 index 0000000000..8af9f76ccd --- /dev/null +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClientLiveTest.java @@ -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 expectationMap = ImmutableMap. 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 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 socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 10, + TimeUnit.SECONDS);// make it longer then + // default internet + } + + @SuppressWarnings("unused") + @Provides + private Predicate addressTester(AddressReachable reachable) { + return new RetryablePredicate(reachable, 60, 5, + TimeUnit.SECONDS); + } + + @SuppressWarnings("unused") + @Provides + private Predicate successTester(TaskSuccess success) { + return new RetryablePredicate(success, 300, 10, TimeUnit.SECONDS); + } + + }).buildInjector(); + client = injector.getInstance(HostingDotComVCloudComputeClient.class); + tmClient = injector.getInstance(HostingDotComVCloudClient.class); + addressTester = injector.getInstance(Key.get(new TypeLiteral>() { + })); + } + +} diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/xml/HostingDotComVAppHandlerTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/xml/HostingDotComVAppHandlerTest.java new file mode 100644 index 0000000000..59165a3bfc --- /dev/null +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/xml/HostingDotComVAppHandlerTest.java @@ -0,0 +1,65 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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. of(), null, + null, ImmutableSortedSet. of(), "root", "peoplearelovely"); + + assertEquals(result, expects); + + } +} diff --git a/vcloud/hostingdotcom/src/test/resources/hostingdotcom/instantiatevapp.xml b/vcloud/hostingdotcom/src/test/resources/hostingdotcom/instantiatevapp.xml new file mode 100644 index 0000000000..2c0030b30c --- /dev/null +++ b/vcloud/hostingdotcom/src/test/resources/hostingdotcom/instantiatevapp.xml @@ -0,0 +1,13 @@ + + + + root + peoplearelovely + diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java index 4a4041e7de..a5024b5856 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java @@ -49,12 +49,13 @@ import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.domain.VDC; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; 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.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.AddNodeOptions; -import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; @@ -81,8 +82,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @Path("/action/instantiatevAppTemplate") @Produces("application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml") @XMLResponseParser(TerremarkVAppHandler.class) - @MapBinder(InstantiateVAppTemplateOptions.class) - Future instantiateVAppTemplate(@MapEntityParam("name") String appName, + @MapBinder(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class) + @Override + Future instantiateVAppTemplate(@MapEntityParam("name") String appName, @MapEntityParam("template") @ParamParser(CatalogIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); @@ -147,7 +149,8 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/vapp/{vAppId}") @XMLResponseParser(TerremarkVAppHandler.class) - Future getVApp(@PathParam("vAppId") String vAppId); + @Override + Future getVApp(@PathParam("vAppId") String vAppId); @GET @Consumes(VAPP_XML) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index ff1fca29b7..e95c80f0b0 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -28,12 +28,12 @@ import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; import org.jclouds.vcloud.VCloudClient; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.domain.InternetService; 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.AddNodeOptions; -import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; /** * 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) public interface TerremarkVCloudClient extends VCloudClient { - VApp instantiateVAppTemplate(String appName, String templateId, + @Override + TerremarkVApp instantiateVAppTemplate(String appName, String templateId, InstantiateVAppTemplateOptions... options); InternetService addInternetService(String serviceName, String protocol, int port, @@ -65,6 +66,7 @@ public interface TerremarkVCloudClient extends VCloudClient { void deleteNode(String nodeId); - VApp getVApp(String vAppId); + @Override + TerremarkVApp getVApp(String vAppId); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindInstantiateVAppTemplateParamsToXmlEntity.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindInstantiateVAppTemplateParamsToXmlEntity.java deleted file mode 100644 index 1bd8152b21..0000000000 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/BindInstantiateVAppTemplateParamsToXmlEntity.java +++ /dev/null @@ -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 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"); - - } - -} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.java new file mode 100644 index 0000000000..11776b8b07 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.java @@ -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 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()); + } + } + } + } + +} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java index eb2a563210..96056a0266 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java @@ -57,7 +57,6 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule { return (TerremarkVCloudAsyncClient) in; } - @Override protected VCloudAsyncClient provideAsyncClient(RestClientFactory factory) { return factory.create(TerremarkVCloudAsyncClient.class); @@ -75,10 +74,8 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule { return SyncProxy.create(TerremarkVCloudClient.class, client); } - @Singleton - @Provides - @Named("InstantiateVAppTemplateParams") - String provideInstantiateVAppTemplateParams() throws IOException { + @Override + protected String provideInstantiateVAppTemplateParams() throws IOException { InputStream is = getClass().getResourceAsStream( "/terremark/InstantiateVAppTemplateParams.xml"); return Utils.toStringAndClose(is); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkVApp.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkVApp.java new file mode 100644 index 0000000000..7e07bfc3da --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/TerremarkVApp.java @@ -0,0 +1,46 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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(); + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVAppImpl.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVAppImpl.java new file mode 100644 index 0000000000..0718f3cbd8 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVAppImpl.java @@ -0,0 +1,125 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 networkToAddresses, + String operatingSystemDescription, TerremarkVirtualSystem system, + SortedSet 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; + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java index 1fa973dc47..e77dde6c9b 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/internal/TerremarkVDCImpl.java @@ -29,6 +29,7 @@ import java.net.URI; 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.Quota; 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, Capacity storageCapacity, Capacity cpuCapacity, Capacity memoryCapacity, Quota instantiatedVmsQuota, Quota deployedVmsQuota, - Map availableNetworks, Map resourceEntities, - NamedLink catalog, NamedLink publicIps, NamedLink internetServices) { + Map availableNetworks, + Map resourceEntities, NamedLink catalog, NamedLink publicIps, + NamedLink internetServices) { super(id, name, location, description, storageCapacity, cpuCapacity, memoryCapacity, instantiatedVmsQuota, deployedVmsQuota, availableNetworks, resourceEntities); this.catalog = checkNotNull(catalog, "catalog"); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/InstantiateVAppTemplateOptions.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/InstantiateVAppTemplateOptions.java deleted file mode 100644 index 2863cdd7f2..0000000000 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/InstantiateVAppTemplateOptions.java +++ /dev/null @@ -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 postParams) { - Map 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); - } - - } -} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java new file mode 100644 index 0000000000..0bb618e310 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptions.java @@ -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; + } +} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java new file mode 100644 index 0000000000..f6619a5645 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/reference/TerremarkVCloudConstants.java @@ -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"; + +} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java index 1fec95f9fb..2d0e2e71e7 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandler.java @@ -24,8 +24,8 @@ package org.jclouds.vcloud.terremark.xml; import org.jclouds.http.functions.ParseSax; -import org.jclouds.vcloud.terremark.domain.ResourceAllocation; -import org.jclouds.vcloud.terremark.domain.ResourceType; +import org.jclouds.vcloud.domain.ResourceAllocation; +import org.jclouds.vcloud.domain.ResourceType; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -38,25 +38,14 @@ public class ResourceAllocationHandler extends ParseSax.HandlerWithResult { +public class TerremarkVAppHandler extends ParseSax.HandlerWithResult { private final VirtualSystemHandler systemHandler; private final ResourceAllocationHandler allocationHandler; @@ -69,7 +69,7 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult { this.allocationHandler = allocationHandler; } - private VirtualSystem system; + private TerremarkVirtualSystem system; private SortedSet allocations = Sets.newTreeSet(); private NamedResource vApp; private Link vDC; @@ -87,8 +87,8 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult { @VAppRoot private String vAppRoot; - public VApp getResult() { - return new VAppImpl(vApp.getId(), vApp.getName(), vApp.getType(), vApp.getLocation(), status, + public TerremarkVApp getResult() { + return new TerremarkVAppImpl(vApp.getId(), vApp.getName(), vApp.getType(), vApp.getLocation(), status, size, vDC, computeOptions, customizationOptions, networkToAddresses, operatingSystemDescription, system, allocations); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java index 8888316115..56f66d5c3f 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandler.java @@ -35,7 +35,7 @@ import org.xml.sax.SAXException; * @author Adrian Cole */ public class VirtualSystemHandler extends - ParseSax.HandlerWithResult { + ParseSax.HandlerWithResult { private StringBuilder currentText = new StringBuilder(); protected DateService dateService; @@ -61,7 +61,7 @@ public class VirtualSystemHandler extends private String virtualSystemIdentifier; private String virtualSystemType; - private org.jclouds.vcloud.terremark.domain.VirtualSystem system; + private org.jclouds.vcloud.domain.TerremarkVirtualSystem system; private boolean skip; @@ -70,7 +70,7 @@ public class VirtualSystemHandler extends this.dateService = dateService; } - public org.jclouds.vcloud.terremark.domain.VirtualSystem getResult() { + public org.jclouds.vcloud.domain.TerremarkVirtualSystem getResult() { return system; } @@ -132,7 +132,7 @@ public class VirtualSystemHandler extends } else if (qName.equals("VirtualSystemType")) { this.virtualSystemType = currentText.toString().trim(); } 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, automaticStartupActionSequenceNumber, caption, configurationDataRoot, configurationFile, configurationID, creationTime, description, elementName, diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java similarity index 96% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java rename to vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 8eaf66585a..79e80edc76 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -24,7 +24,7 @@ package org.jclouds.vcloud.terremark; 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 java.io.IOException; @@ -55,7 +55,7 @@ import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; 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.NodeHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; @@ -68,12 +68,12 @@ import com.google.inject.Provides; import com.google.inject.TypeLiteral; /** - * Tests behavior of {@code TerremarkVCloudClient} + * Tests behavior of {@code TerremarkVCloudAsyncClient} * * @author Adrian Cole */ -@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudClientTest") -public class TerremarkVCloudClientTest extends RestClientTest { +@Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest") +public class TerremarkVCloudAsyncClientTest extends RestClientTest { public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC"); @@ -93,7 +93,7 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, "name", 3 + ""); @@ -115,7 +115,7 @@ public class TerremarkVCloudClientTest extends RestClientTest httpMethod = processor.createRequest(method, "name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index b874d362ab..8cc404a7eb 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -45,14 +45,14 @@ import org.jclouds.ssh.SshClient.Factory; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudClientLiveTest; +import org.jclouds.vcloud.domain.ResourceType; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.domain.InternetService; 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.VApp; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -73,7 +73,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { private InetAddress publicIp; private InternetService is; private Node node; - private VApp vApp; + private TerremarkVApp vApp; private RetryablePredicate socketTester; @@ -190,21 +190,21 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { 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) { assertEquals(vApp.getName(), serverName); assertEquals(vApp.getOperatingSystemDescription(), expectedOs); - assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) + 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.VIRTUAL_DISK) + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) .getVirtualQuantity(), hardDisk); - assertEquals(vApp.getSize(), vApp.getResourceAllocationByType() - .get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); + assertEquals(vApp.getSize(), vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) + .getVirtualQuantity()); } private void doCheckPass(InetAddress address) throws IOException { diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java index 14863c1bda..735fca6e3d 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java @@ -40,13 +40,13 @@ 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.VAppStatus; import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.VCloudComputeClient.Image; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; -import org.jclouds.vcloud.terremark.domain.ResourceType; -import org.jclouds.vcloud.terremark.domain.VApp; +import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeGroups; 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( 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)")).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 Node node; @@ -99,7 +100,7 @@ public class TerremarkVCloudComputeClientLiveTest { @Test public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, IOException { - Image toTest = Image.UMBUNTU_90; + Image toTest = Image.CENTOS_53; String serverName = getCompatibleServerName(toTest); int processorCount = 1; @@ -108,7 +109,7 @@ public class TerremarkVCloudComputeClientLiveTest { id = client.start(serverName, processorCount, memory, toTest); Expectation expectation = expectationMap.get(toTest); - VApp vApp = tmClient.getVApp(id); + TerremarkVApp vApp = tmClient.getVApp(id); verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory, expectation.hardDisk); assertEquals(vApp.getStatus(), VAppStatus.ON); @@ -135,21 +136,21 @@ public class TerremarkVCloudComputeClientLiveTest { 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) { assertEquals(vApp.getName(), serverName); assertEquals(vApp.getOperatingSystemDescription(), expectedOs); - assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) + 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.VIRTUAL_DISK) + assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) .getVirtualQuantity(), hardDisk); - assertEquals(vApp.getSize(), vApp.getResourceAllocationByType() - .get(ResourceType.VIRTUAL_DISK).getVirtualQuantity()); + assertEquals(vApp.getSize(), vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) + .getVirtualQuantity()); } @AfterTest diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java index 0e9d2f584c..abe566fcda 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java @@ -39,8 +39,8 @@ import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient.Factory; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppStatus; -import org.jclouds.vcloud.terremark.domain.VApp; -import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.terremark.domain.TerremarkVApp; +import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; @@ -70,11 +70,11 @@ public class VCloudComputeClient { private final Factory sshFactory; public enum Image { - CENTOS_53, RHEL_53, UMBUNTU_90 + CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS } private Map imageCatalogIdMap = ImmutableMap. 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) { 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, minCores, minMegs, templateId); - VApp vApp = tmClient.instantiateVAppTemplate(name, templateId, - InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); + TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, + TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug(">> deploying vApp(%s)", vApp.getId()); @@ -105,7 +105,7 @@ public class VCloudComputeClient { * if no address is configured */ public InetAddress getAnyPrivateAddress(String id) { - VApp vApp = tmClient.getVApp(id); + TerremarkVApp vApp = tmClient.getVApp(id); return Iterables.getLast(vApp.getNetworkToAddresses().values()); } @@ -120,7 +120,7 @@ public class VCloudComputeClient { } public void reboot(String id) { - VApp vApp = tmClient.getVApp(id); + TerremarkVApp vApp = tmClient.getVApp(id); logger.debug(">> rebooting vApp(%s)", vApp.getId()); blockUntilVAppStatusOrThrowException(vApp, tmClient.resetVApp(vApp.getId()), "reset", VAppStatus.ON); @@ -128,7 +128,7 @@ public class VCloudComputeClient { } public void stop(String id) { - VApp vApp = tmClient.getVApp(id); + TerremarkVApp vApp = tmClient.getVApp(id); if (vApp.getStatus() != VAppStatus.OFF) { logger.debug(">> powering off vApp(%s)", 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) { if (!taskTester.apply(deployTask.getLocation())) { throw new TaskException(taskType, vApp, deployTask); @@ -175,7 +175,7 @@ public class VCloudComputeClient { /** The serialVersionUID */ 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, vApp.getId(), vApp.getStatus(), task.getLocation(), task.getStatus()), vApp); this.task = task; @@ -206,16 +206,16 @@ public class VCloudComputeClient { public static class VAppException extends RuntimeException { - private final VApp vApp; + private final TerremarkVApp vApp; /** The serialVersionUID */ private static final long serialVersionUID = 251801929573211256L; - public VAppException(String message, VApp vApp) { + public VAppException(String message, TerremarkVApp vApp) { super(message); this.vApp = vApp; } - public VApp getvApp() { + public TerremarkVApp getvApp() { return vApp; } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindInstantiateVAppTemplateParamsToXmlEntityTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest.java similarity index 87% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindInstantiateVAppTemplateParamsToXmlEntityTest.java rename to vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest.java index 62082806ec..5eafe07ba6 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/BindInstantiateVAppTemplateParamsToXmlEntityTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/binders/TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest.java @@ -46,12 +46,12 @@ import com.google.inject.Injector; import com.google.inject.Provides; /** - * Tests behavior of {@code BindInstantiateVAppTemplateParamsToXmlEntity} + * Tests behavior of {@code TerremarkBindInstantiateVAppTemplateParamsToXmlEntity} * * @author Adrian Cole */ -@Test(groups = "unit", testName = "vcloud.BindInstantiateVAppTemplateParamsToXmlEntityTest") -public class BindInstantiateVAppTemplateParamsToXmlEntityTest { +@Test(groups = "unit", testName = "vcloud.TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest") +public class TerremarkBindInstantiateVAppTemplateParamsToXmlEntityTest { Injector injector = Guice.createInjector(new AbstractModule() { @Override @@ -73,8 +73,8 @@ public class BindInstantiateVAppTemplateParamsToXmlEntityTest { String expected = IOUtils.toString(getClass().getResourceAsStream( "/terremark/InstantiateVAppTemplateParams-test-2.xml")); HttpRequest request = new HttpRequest("GET", URI.create("http://test")); - BindInstantiateVAppTemplateParamsToXmlEntity binder = injector - .getInstance(BindInstantiateVAppTemplateParamsToXmlEntity.class); + TerremarkBindInstantiateVAppTemplateParamsToXmlEntity binder = injector + .getInstance(TerremarkBindInstantiateVAppTemplateParamsToXmlEntity.class); Map map = Maps.newHashMap(); map.put("name", "name"); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/InstantiateVAppTemplateOptionsTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/InstantiateVAppTemplateOptionsTest.java deleted file mode 100644 index d90dfd0bcd..0000000000 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/InstantiateVAppTemplateOptionsTest.java +++ /dev/null @@ -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); - } -} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java new file mode 100644 index 0000000000..f856d9bdf4 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/options/TerremarkInstantiateVAppTemplateOptionsTest.java @@ -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); + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java index 77c2dbbe1b..8ba07390de 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ResourceAllocationHandlerTest.java @@ -28,8 +28,8 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; import org.jclouds.http.functions.BaseHandlerTest; -import org.jclouds.vcloud.terremark.domain.ResourceAllocation; -import org.jclouds.vcloud.terremark.domain.ResourceType; +import org.jclouds.vcloud.domain.ResourceAllocation; +import org.jclouds.vcloud.domain.ResourceType; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -54,10 +54,10 @@ public class ResourceAllocationHandlerTest extends BaseHandlerTest { injector.getInstance(ResourceAllocationHandler.class)).parse(is); assertEquals(result.getAddress(), new Integer(0)); assertEquals(result.getDescription(), "SCSI Controller"); - assertEquals(result.getElementName(), "SCSI Controller 0"); - assertEquals(result.getInstanceID(), 3); - assertEquals(result.getResourceSubType(), "lsilogic"); - assertEquals(result.getResourceType(), ResourceType.SCSI_CONTROLLER); + assertEquals(result.getName(), "SCSI Controller 0"); + assertEquals(result.getId(), 3); + assertEquals(result.getSubType(), "lsilogic"); + assertEquals(result.getType(), ResourceType.SCSI_CONTROLLER); assertEquals(result.getVirtualQuantity(), 1); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java index 45e7819359..ce674c202a 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java @@ -37,12 +37,12 @@ import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.rest.domain.internal.LinkImpl; 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.endpoints.internal.VAppRoot; -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 org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -83,9 +83,9 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/terremark/launched_vapp.xml"); - VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( - is); - assertEquals(result.getId(), 13775+""); + TerremarkVApp result = (TerremarkVApp) factory.create( + injector.getInstance(TerremarkVAppHandler.class)).parse(is); + assertEquals(result.getId(), 13775 + ""); assertEquals(result.getName(), "adriantest"); assertEquals(result.getStatus(), VAppStatus.CREATING); @@ -94,7 +94,6 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { assertEquals(result.getLocation(), URI .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 .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); @@ -103,9 +102,9 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { public void testGetVApp() throws UnknownHostException { InputStream is = getClass().getResourceAsStream("/terremark/get_vapp.xml"); - VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse( - is); - assertEquals(result.getId(), 13850+""); + TerremarkVApp result = (TerremarkVApp) factory.create( + injector.getInstance(TerremarkVAppHandler.class)).parse(is); + assertEquals(result.getId(), 13850 + ""); assertEquals(result.getName(), "adriantest1"); assertEquals(result.getStatus(), VAppStatus.OFF); @@ -115,7 +114,6 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { assertEquals(result.getLocation(), URI .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 .create("https://services.vcloudexpress.terremark.com/api/v0.8/vdc/32"))); assertEquals( @@ -130,35 +128,34 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest { MediaType.APPLICATION_XML, URI .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, - null, null, null, null, "Virtual Hardware Family", 0, null, null, null, null, null, - "adriantest1", "vmx-07")); + assertEquals(result.getSystem(), new TerremarkVirtualSystem(null, null, null, null, null, + null, null, null, null, null, null, "Virtual Hardware Family", 0, null, null, null, + null, null, "adriantest1", "vmx-07")); assertEquals(result.getNetworkToAddresses().get("Internal"), ImmutableList.of(InetAddress .getByName("10.114.34.132"))); - ResourceAllocation cpu = new ResourceAllocation(null, null, "hertz * 10^6", null, null, null, - null, "Number of Virtual CPUs", "1 virtual CPU(s)", null, 1, null, null, null, null, - null, null, null, ResourceType.VIRTUAL_CPU, 1, "count", null); - ResourceAllocation controller = new ResourceAllocation(0, null, null, null, null, null, null, - "SCSI Controller", "SCSI Controller 0", null, 3, null, null, null, null, null, null, - "lsilogic", ResourceType.SCSI_CONTROLLER, 1, null, null); - ResourceAllocation memory = new ResourceAllocation(null, null, "byte * 2^20", null, null, - null, null, "Memory Size", "512MB of memory", null, 2, null, null, null, null, null, - null, null, ResourceType.MEMORY, 512, "byte * 2^20", null); - ResourceAllocation disk = new ResourceAllocation(null, 0, null, null, null, null, null, null, - "Hard Disk 1", "4194304", 9, null, null, null, 3, null, null, null, - ResourceType.VIRTUAL_DISK, 4194304, null, null); + ResourceAllocation cpu = new ResourceAllocation(1, "1 virtual CPU(s)", + "Number of Virtual CPUs", ResourceType.PROCESSOR, null, null, null, null, null, 1, + "hertz * 10^6"); + + ResourceAllocation controller = new ResourceAllocation(3, "SCSI Controller 0", + "SCSI Controller", ResourceType.SCSI_CONTROLLER, "lsilogic", 0, null, null, null, 1, + null); + ResourceAllocation memory = new ResourceAllocation(2, "512MB of memory", "Memory Size", + ResourceType.MEMORY, null, null, null, null, null, 512, "byte * 2^20"); + ResourceAllocation disk = new ResourceAllocation(9, "Hard Disk 1", null, + ResourceType.DISK_DRIVE, null, null, 0, 3, null, 4194304, null); assertEquals(result.getResourceAllocations(), ImmutableSortedSet.of(cpu, controller, memory, disk)); - assertEquals(result.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU) + assertEquals(result.getResourceAllocationByType().get(ResourceType.PROCESSOR) .getVirtualQuantity(), 1); assertEquals(result.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) .getVirtualQuantity(), 1); assertEquals(result.getResourceAllocationByType().get(ResourceType.MEMORY) .getVirtualQuantity(), 512); - assertEquals(result.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK) + assertEquals(result.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) .getVirtualQuantity(), 4194304); assertEquals(result.getSize(), result.getResourceAllocationByType().get( - ResourceType.VIRTUAL_DISK).getVirtualQuantity()); + ResourceType.DISK_DRIVE).getVirtualQuantity()); } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java index 2fc3115e74..57a0eed7ba 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/VirtualSystemHandlerTest.java @@ -28,7 +28,7 @@ import static org.testng.Assert.assertEquals; import java.io.InputStream; 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.Test; @@ -49,11 +49,11 @@ public class VirtualSystemHandlerTest extends BaseHandlerTest { public void testApplyInputStream() { InputStream is = getClass().getResourceAsStream("/terremark/system.xml"); - VirtualSystem result = (VirtualSystem) factory.create( + TerremarkVirtualSystem result = (TerremarkVirtualSystem) factory.create( injector.getInstance(VirtualSystemHandler.class)).parse(is); - assertEquals(result.getElementName(), "Virtual Hardware Family"); - assertEquals(result.getInstanceID(), 0); - assertEquals(result.getVirtualSystemIdentifier(), "adriantest1"); - assertEquals(result.getVirtualSystemType(), "vmx-07"); + assertEquals(result.getName(), "Virtual Hardware Family"); + assertEquals(result.getId(), 0); + assertEquals(result.getIdentifier(), "adriantest1"); + assertEquals(result.getType(), "vmx-07"); } }