From 0703d20b8c9627a3afdf09026f9bb729984bfe83 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Sat, 12 Dec 2009 20:46:42 +0000 Subject: [PATCH] Issue 112: updated support for terremark, adding ability to remove public ip addresses no longer in use git-svn-id: http://jclouds.googlecode.com/svn/trunk@2403 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../terremark/TerremarkVCloudAsyncClient.java | 112 ++++++++++++++-- .../terremark/TerremarkVCloudClient.java | 101 +++++++++++--- .../compute/TerremarkVCloudComputeClient.java | 76 ++++++++--- .../TerremarkVCloudComputeService.java | 2 +- .../terremark/domain/ComputeOption.java | 113 ++++++++++++++++ .../domain/CustomizationParameters.java | 82 ++++++++++++ .../terremark/domain/InternetService.java | 69 +++++----- .../jclouds/vcloud/terremark/domain/Node.java | 34 +++-- .../vcloud/terremark/domain/Protocol.java | 37 ++++++ .../options/ReturnVoidOnDeleteDefaultIp.java | 66 ++++++++++ .../terremark/xml/ComputeOptionHandler.java | 65 +++++++++ .../terremark/xml/ComputeOptionsHandler.java | 76 +++++++++++ .../xml/CustomizationParametersHandler.java | 61 +++++++++ .../terremark/xml/InternetServiceHandler.java | 9 +- .../vcloud/terremark/xml/NodeHandler.java | 4 +- .../terremark/xml/PublicIpAddressHandler.java | 90 +++++++++++++ .../xml/PublicIpAddressesHandler.java | 76 +++++++++++ .../terremark/InternetServiceLiveTest.java | 123 ++++++++++++++++++ .../TerremarkVCloudAsyncClientTest.java | 71 +++++++--- .../TerremarkVCloudClientLiveTest.java | 7 +- .../TerremarkVCloudComputeClientLiveTest.java | 3 +- .../xml/ComputeOptionHandlerTest.java | 50 +++++++ .../xml/ComputeOptionsHandlerTest.java | 54 ++++++++ .../CustomizationParametersHandlerTest.java | 50 +++++++ .../xml/InternetServiceHandlerTest.java | 9 +- .../xml/InternetServicesHandlerTest.java | 5 +- .../vcloud/terremark/xml/NodeHandlerTest.java | 2 +- .../terremark/xml/NodesHandlerTest.java | 2 +- .../xml/PublicIpAddressHandlerTest.java | 53 ++++++++ .../xml/PublicIpAddressesHandlerTest.java | 69 ++++++++++ .../resources/terremark/ComputeOption.xml | 6 + .../resources/terremark/ComputeOptions.xml | 13 ++ .../CreateInternetService-options-test.xml | 2 +- .../terremark/CreateInternetService-test2.xml | 2 +- .../terremark/CustomizationParameters.xml | 5 + .../resources/terremark/PublicIpAddress.xml | 7 + .../resources/terremark/PublicIpAddresses.xml | 15 +++ 37 files changed, 1488 insertions(+), 133 deletions(-) create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Protocol.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/ReturnVoidOnDeleteDefaultIp.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandler.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandler.java create mode 100644 vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandler.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandlerTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandlerTest.java create mode 100644 vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandlerTest.java create mode 100644 vcloud/terremark/src/test/resources/terremark/ComputeOption.xml create mode 100644 vcloud/terremark/src/test/resources/terremark/ComputeOptions.xml create mode 100644 vcloud/terremark/src/test/resources/terremark/CustomizationParameters.xml create mode 100644 vcloud/terremark/src/test/resources/terremark/PublicIpAddress.xml create mode 100644 vcloud/terremark/src/test/resources/terremark/PublicIpAddresses.xml 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 f08c6b5143..9a050cb935 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 @@ -40,6 +40,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.ExceptionParser; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.MapEntityParam; import org.jclouds.rest.annotations.ParamParser; @@ -52,15 +53,23 @@ 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.ComputeOption; +import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; +import org.jclouds.vcloud.terremark.domain.Protocol; +import org.jclouds.vcloud.terremark.domain.PublicIpAddress; 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.ReturnVoidOnDeleteDefaultIp; +import org.jclouds.vcloud.terremark.xml.ComputeOptionsHandler; +import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; import org.jclouds.vcloud.terremark.xml.InternetServicesHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; import org.jclouds.vcloud.terremark.xml.NodesHandler; +import org.jclouds.vcloud.terremark.xml.PublicIpAddressesHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; @@ -73,13 +82,18 @@ import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; */ @RequestFilters(SetVCloudTokenCookie.class) public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { - + /** + * @see TerremarkVCloudClient#getDefaultVDC + */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @XMLResponseParser(TerremarkVDCHandler.class) @Consumes(VDC_XML) Future getDefaultVDC(); + /** + * @see TerremarkVCloudClient#instantiateVAppTemplate + */ @POST @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Path("/action/instantiatevAppTemplate") @@ -91,6 +105,9 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @MapEntityParam("template") @ParamParser(CatalogIdToUri.class) String templateId, InstantiateVAppTemplateOptions... options); + /** + * @see TerremarkVCloudClient#addInternetService + */ @POST @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Path("/internetServices") @@ -98,15 +115,21 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(InternetServiceHandler.class) @MapBinder(AddInternetServiceOptions.class) Future addInternetService(@MapEntityParam("name") String serviceName, - @MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port, + @MapEntityParam("protocol") Protocol protocol, @MapEntityParam("port") int port, AddInternetServiceOptions... options); + /** + * @see TerremarkVCloudClient#getAllInternetServices + */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) @Path("/internetServices") @XMLResponseParser(InternetServicesHandler.class) Future> getAllInternetServices(); + /** + * @see TerremarkVCloudClient#addInternetServiceToExistingIp + */ @POST @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/publicIps/{ipId}/InternetServices") @@ -114,22 +137,59 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(InternetServiceHandler.class) @MapBinder(AddInternetServiceOptions.class) Future addInternetServiceToExistingIp( - @PathParam("ipId") String existingIpId, @MapEntityParam("name") String serviceName, - @MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port, + @PathParam("ipId") int existingIpId, @MapEntityParam("name") String serviceName, + @MapEntityParam("protocol") Protocol protocol, @MapEntityParam("port") int port, AddInternetServiceOptions... options); + /** + * @see TerremarkVCloudClient#deletePublicIp + */ + @DELETE + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/PublicIps/{ipId}") + @ExceptionParser(ReturnVoidOnDeleteDefaultIp.class) + Future deletePublicIp(@PathParam("ipId") int ipId); + + /** + * @see TerremarkVCloudClient#getInternetServicesOnPublicIP + */ + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/publicIps/{ipId}/InternetServices") + @XMLResponseParser(InternetServicesHandler.class) + Future> getInternetServicesOnPublicIp( + @PathParam("ipId") int ipId); + + /** + * @see TerremarkVCloudClient#getPublicIpsAssociatedWithVDC + */ + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) + @Path("/publicIps") + @XMLResponseParser(PublicIpAddressesHandler.class) + Future> getPublicIpsAssociatedWithVDC(); + + /** + * @see TerremarkVCloudClient#deleteInternetService + */ @DELETE @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}") - Future deleteInternetService(@PathParam("internetServiceId") String internetServiceId); + Future deleteInternetService(@PathParam("internetServiceId") int internetServiceId); + /** + * @see TerremarkVCloudClient#getInternetService + */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}") @XMLResponseParser(InternetServiceHandler.class) Future getInternetService( - @PathParam("internetServiceId") String internetServiceId); + @PathParam("internetServiceId") int internetServiceId); + /** + * @see TerremarkVCloudClient#addNode + */ @POST @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}/nodes") @@ -137,29 +197,40 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @XMLResponseParser(NodeHandler.class) @MapBinder(AddNodeOptions.class) Future addNode( - @PathParam("internetServiceId") String internetServiceId, + @PathParam("internetServiceId") int internetServiceId, @MapEntityParam("ipAddress") @ParamParser(InetAddressToHostAddress.class) InetAddress ipAddress, @MapEntityParam("name") String name, @MapEntityParam("port") int port, AddNodeOptions... options); + /** + * @see TerremarkVCloudClient#getNodes + */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/internetServices/{internetServiceId}/nodes") @XMLResponseParser(NodesHandler.class) - Future> getNodes( - @PathParam("internetServiceId") String internetServiceId); + Future> getNodes(@PathParam("internetServiceId") int internetServiceId); + /** + * @see TerremarkVCloudClient#getNode + */ @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/nodeServices/{nodeId}") @XMLResponseParser(NodeHandler.class) - Future getNode(@PathParam("nodeId") String nodeId); + Future getNode(@PathParam("nodeId") int nodeId); + /** + * @see TerremarkVCloudClient#deleteNode + */ @DELETE @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/nodeServices/{nodeId}") - Future deleteNode(@PathParam("nodeId") String nodeId); + Future deleteNode(@PathParam("nodeId") int nodeId); + /** + * @see TerremarkVCloudClient#getVApp + */ @GET @Consumes(VAPP_XML) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @@ -168,9 +239,22 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @Override Future getVApp(@PathParam("vAppId") String vAppId); + /** + * @see TerremarkVCloudClient#getComputeOptions + */ @GET - @Consumes(VAPP_XML) @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) - @Path("/vapp/{vAppId}") - Future getVAppString(@PathParam("vAppId") String vAppId); + @Path("/vapp/{vAppId}/options/compute") + @XMLResponseParser(ComputeOptionsHandler.class) + Future> getComputeOptions(@PathParam("vAppId") String vAppId); + + /** + * @see TerremarkVCloudClient#getCustomizationOptions + */ + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/vapp/{vAppId}/options/customization") + @XMLResponseParser(CustomizationParametersHandler.class) + Future getCustomizationOptions( + @PathParam("vAppId") String vAppId); } 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 128077cd98..bccd55185f 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 @@ -30,8 +30,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.ComputeOption; +import org.jclouds.vcloud.terremark.domain.CustomizationParameters; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; +import org.jclouds.vcloud.terremark.domain.Protocol; +import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; @@ -50,28 +54,89 @@ public interface TerremarkVCloudClient extends VCloudClient { TerremarkVApp instantiateVAppTemplate(String appName, String templateId, InstantiateVAppTemplateOptions... options); - InternetService addInternetService(String serviceName, String protocol, int port, - AddInternetServiceOptions... options); - - InternetService addInternetServiceToExistingIp(String existingIpId, String serviceName, - String protocol, int port, AddInternetServiceOptions... options); - - void deleteInternetService(String internetServiceId); - - InternetService getInternetService(String internetServiceId); - - Node addNode(String internetServiceId, InetAddress ipAddress, String name, int port, - AddNodeOptions... options); - - Node getNode(String nodeId); - - void deleteNode(String nodeId); - @Override TerremarkVApp getVApp(String vAppId); + /** + * This call returns the compute options for the vApp. The compute options are the CPU and memory + * configurations supported by Terremark and by the guest operating system of the vApp. This call + * also returns the cost per hour for each configuration. + */ + SortedSet getComputeOptions(String vAppId); + + /** + * This call returns the customization options for the vApp. The response lists which + * customization options are supported for this particular vApp. The possible customization + * options are Network and Password. + */ + CustomizationParameters getCustomizationOptions(String vAppId); + + /** + * This call returns a list of public IP addresses. + */ + SortedSet getPublicIpsAssociatedWithVDC(); + + void deletePublicIp(int ipId); + + /** + * The call creates a new internet server, including protocol and port information. The public IP + * is dynamically allocated. + * + * @param serviceName + * @param protocol + * @param port + * @param options + * @return + */ + InternetService addInternetService(String serviceName, Protocol protocol, int port, + AddInternetServiceOptions... options); + + /** + * This call adds an internet service to a known, existing public IP. This call is identical to + * Add Internet Service except you specify the public IP in the request. + * + * @param existingIpId + * @param serviceName + * @param protocol + * @param port + * @param options + * @return + */ + InternetService addInternetServiceToExistingIp(int existingIpId, String serviceName, + Protocol protocol, int port, AddInternetServiceOptions... options); + + void deleteInternetService(int internetServiceId); + + InternetService getInternetService(int internetServiceId); + SortedSet getAllInternetServices(); - SortedSet getNodes(String internetServiceId); + /** + * This call returns information about the internet service on a public IP. + */ + SortedSet getInternetServicesOnPublicIp(int ipId); + + /** + * This call adds a node to an existing internet service. + *

+ * Every vDC is assigned a network of 60 IP addresses that can be used as nodes. Each node can + * associated with multiple internet service. You can get a list of the available IP addresses by + * calling Get IP Addresses for a Network. + * + * @param internetServiceId + * @param ipAddress + * @param name + * @param port + * @param options + * @return + */ + Node addNode(int internetServiceId, InetAddress ipAddress, String name, int port, + AddNodeOptions... options); + + Node getNode(int nodeId); + + void deleteNode(int nodeId); + + SortedSet getNodes(int internetServiceId); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index d06fb17e06..b88f80404b 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -30,6 +30,7 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.util.Map; +import java.util.Set; import java.util.SortedSet; import javax.annotation.Resource; @@ -43,6 +44,7 @@ import org.jclouds.vcloud.domain.VAppStatus; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; import org.jclouds.vcloud.terremark.domain.InternetService; import org.jclouds.vcloud.terremark.domain.Node; +import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; @@ -50,6 +52,7 @@ import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOpti import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; /** * @@ -115,23 +118,35 @@ public class TerremarkVCloudComputeClient { } public InetAddress createPublicAddressMappedToPorts(VApp vApp, int... ports) { - PublicIpAddress sshIp = null; + PublicIpAddress ip = null; InetAddress privateAddress = Iterables.getLast(vApp.getNetworkToAddresses().values()); for (int port : ports) { InternetService is = null; - if (sshIp == null) { + Protocol protocol; + switch (port) { + case 22: + protocol = Protocol.TCP; + case 80: + case 8080: + protocol = Protocol.HTTP; + case 443: + protocol = Protocol.HTTPS; + default: + protocol = Protocol.HTTP; + + } + if (ip == null) { logger.debug(">> creating InternetService %d", port); - is = tmClient.addInternetService(vApp.getName() + "-" + port, "TCP", port, + is = tmClient.addInternetService(vApp.getName() + "-" + port, protocol, port, withDescription(String.format("port %d access to serverId: %s name: %s", port, vApp.getId(), vApp.getName()))); - sshIp = is.getPublicIpAddress(); + ip = is.getPublicIpAddress(); } else { - logger.debug(">> adding InternetService %s:%d", sshIp.getAddress().getHostAddress(), - port); - is = tmClient.addInternetServiceToExistingIp(sshIp.getId() + "", vApp.getName() + "-" - + port, "TCP", port, - withDescription(String.format("port %d access to serverId: %s name: %s", port, - vApp.getId(), vApp.getName()))); + logger.debug(">> adding InternetService %s:%d", ip.getAddress().getHostAddress(), port); + is = tmClient.addInternetServiceToExistingIp(ip.getId(), vApp.getName() + "-" + port, + protocol, port, withDescription(String.format( + "port %d access to serverId: %s name: %s", port, vApp.getId(), vApp + .getName()))); } logger.debug("<< created InternetService(%s) %s:%d", is.getId(), is.getPublicIpAddress() .getAddress().getHostAddress(), is.getPort()); @@ -141,15 +156,33 @@ public class TerremarkVCloudComputeClient { .addNode(is.getId(), privateAddress, vApp.getName() + "-" + port, port); logger.debug("<< added Node(%s)", node.getId()); } - return sshIp.getAddress(); + return ip.getAddress(); } public void stop(String id) { TerremarkVApp vApp = tmClient.getVApp(id); + Set ipAddresses = deleteInternetServicesAndNodesAssociatedWithVApp(vApp); + + deletePublicIpAddressesWithNoServicesAttached(ipAddresses); + + 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 Set deleteInternetServicesAndNodesAssociatedWithVApp(TerremarkVApp vApp) { + Set ipAddresses = Sets.newHashSet(); SERVICE: for (InternetService service : tmClient.getAllInternetServices()) { for (Node node : tmClient.getNodes(service.getId())) { if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) { + ipAddresses.add(service.getPublicIpAddress()); logger.debug(">> deleting Node(%s) %s:%d -> %s:%d", node.getId(), service .getPublicIpAddress().getAddress().getHostAddress(), service.getPort(), node.getIpAddress().getHostAddress(), node.getPort()); @@ -166,16 +199,21 @@ public class TerremarkVCloudComputeClient { } } } + return ipAddresses; + } - 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()); + private void deletePublicIpAddressesWithNoServicesAttached(Set ipAddresses) { + IPADDRESS: for (PublicIpAddress address : ipAddresses) { + SortedSet services = tmClient.getInternetServicesOnPublicIp(address + .getId()); + if (services.size() == 0) { + logger.debug(">> deleting PublicIpAddress(%s) %s", address.getId(), address + .getAddress().getHostAddress()); + tmClient.deleteInternetService(address.getId()); + logger.debug("<< deleted PublicIpAddress(%s)", address.getId()); + continue IPADDRESS; + } } - logger.debug(">> deleting vApp(%s)", vApp.getId()); - tmClient.deleteVApp(id); - logger.debug("<< deleted vApp(%s)", vApp.getId()); } private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask, diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java index 20e371b98b..0b88a0e4c6 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java @@ -72,7 +72,7 @@ public class TerremarkVCloudComputeService implements ComputeService { public CreateServerResponse createServer(String name, Profile profile, Image image) { String id = computeClient.start(name, 1, 512, image); VApp vApp = tmClient.getVApp(id); - InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22); + InetAddress publicIp = computeClient.createPublicAddressMappedToPorts(vApp, 22, 80, 8080); return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), ImmutableSet . of(publicIp), vApp.getNetworkToAddresses().values(), 22, LoginType.SSH, new Credentials("vcloud", "p4ssw0rd")); diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java new file mode 100644 index 0000000000..a9dd3362a1 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/ComputeOption.java @@ -0,0 +1,113 @@ +/** + * + * 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; + +/** + * The compute options are the CPU and memory configurations supported by Terremark and by the guest + * operating system of the vApp. + * + * @author Adrian Cole + * @see Terremark documentation + */ +public class ComputeOption implements Comparable { + private final int processorCount; + private final long memory; + private final float costPerHour; + + public ComputeOption(int processorCount, long memory, float costPerHour) { + this.processorCount = processorCount; + this.memory = memory; + this.costPerHour = costPerHour; + } + + public int getProcessorCount() { + return processorCount; + } + + public long getMemory() { + return memory; + } + + public float getCostPerHour() { + return costPerHour; + } + + /** + * orders processor, memory, then cost. + */ + public int compareTo(ComputeOption that) { + if (this == that) + return 0; + double compareThis = compare(this); + double compareThat = compare(that); + if (compareThis < compareThat) + return -1; + if (compareThis > compareThat) + return 1; + return 0; + } + + private double compare(ComputeOption option) { + double comparison = processorCount * 20000; + comparison += memory; + comparison += costPerHour; + return comparison; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + Float.floatToIntBits(costPerHour); + result = prime * result + (int) (memory ^ (memory >>> 32)); + result = prime * result + processorCount; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ComputeOption other = (ComputeOption) obj; + if (Float.floatToIntBits(costPerHour) != Float.floatToIntBits(other.costPerHour)) + return false; + if (memory != other.memory) + return false; + if (processorCount != other.processorCount) + return false; + return true; + } + + @Override + public String toString() { + return "ComputeOption [costPerHour=" + costPerHour + ", memory=" + memory + + ", processorCount=" + processorCount + "]"; + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java new file mode 100644 index 0000000000..e56455e502 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/CustomizationParameters.java @@ -0,0 +1,82 @@ +/** + * + * 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; + +/** + * The response lists which customization options are supported for this particular vApp. The + * possible customization options are Network and Password. + * + * @author Adrian Cole + * @see Terremark documentation + */ +public class CustomizationParameters { + private final boolean customizeNetwork; + private final boolean customizePassword; + + public CustomizationParameters(boolean customizeNetwork, boolean customizePassword) { + this.customizeNetwork = customizeNetwork; + this.customizePassword = customizePassword; + } + + public boolean isCustomizeNetwork() { + return customizeNetwork; + } + + public boolean isCustomizePassword() { + return customizePassword; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (customizeNetwork ? 1231 : 1237); + result = prime * result + (customizePassword ? 1231 : 1237); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + CustomizationParameters other = (CustomizationParameters) obj; + if (customizeNetwork != other.customizeNetwork) + return false; + if (customizePassword != other.customizePassword) + return false; + return true; + } + + @Override + public String toString() { + return "CustomizationParameters [customizeNetwork=" + customizeNetwork + + ", customizePassword=" + customizePassword + "]"; + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java index 33075ebdb3..0d2d7f45eb 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java @@ -29,18 +29,18 @@ import java.net.URI; * @author Adrian Cole */ public class InternetService implements Comparable { - private final String id; + private final int id; private final String name; private final URI location; private final PublicIpAddress publicIpAddress; private final int port; - private final String protocol; + private final Protocol protocol; private final boolean enabled; private final int timeout; private final String description; - public InternetService(String id, String name, URI location, PublicIpAddress publicIpAddress, - int port, String protocol, boolean enabled, int timeout, String description) { + public InternetService(int id, String name, URI location, PublicIpAddress publicIpAddress, + int port, Protocol protocol, boolean enabled, int timeout, String description) { this.id = id; this.name = name; this.location = location; @@ -60,7 +60,7 @@ public class InternetService implements Comparable { return port; } - public String getProtocol() { + public Protocol getProtocol() { return protocol; } @@ -76,13 +76,42 @@ public class InternetService implements Comparable { return description; } + public int getId() { + return id; + } + + public String getName() { + return name; + } + + public URI getLocation() { + return location; + } + + public int compareTo(InternetService that) { + if (this == that) + return 0; + if (this.id < that.id) + return -1; + if (this.id > that.id) + return 1; + return 0; + } + + @Override + public String toString() { + return "InternetService [description=" + description + ", enabled=" + enabled + ", id=" + id + + ", location=" + location + ", name=" + name + ", port=" + port + ", protocol=" + + protocol + ", publicIpAddress=" + publicIpAddress + ", timeout=" + timeout + "]"; + } + @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + id; result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + port; @@ -108,10 +137,7 @@ public class InternetService implements Comparable { return false; if (enabled != other.enabled) return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) + if (id != other.id) return false; if (location == null) { if (other.location != null) @@ -140,27 +166,4 @@ public class InternetService implements Comparable { return true; } - public int compareTo(InternetService that) { - return (this == that) ? 0 : this.getId().compareTo(that.getId()); - } - - public String getId() { - return id; - } - - public String getName() { - return name; - } - - public URI getLocation() { - return location; - } - - @Override - public String toString() { - return "InternetService [description=" + description + ", enabled=" + enabled + ", id=" + id - + ", location=" + location + ", name=" + name + ", port=" + port + ", protocol=" - + protocol + ", publicIpAddress=" + publicIpAddress + ", timeout=" + timeout + "]"; - } - } \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java index 3dd569ba0c..9e995d1b9a 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java @@ -30,7 +30,7 @@ import java.net.URI; * @author Adrian Cole */ public class Node implements Comparable { - private final String id; + private final int id; private final String name; private final URI location; private final InetAddress ipAddress; @@ -38,7 +38,7 @@ public class Node implements Comparable { private final boolean enabled; private final String description; - public Node(String id, String name, URI location, InetAddress ipAddress, int port, + public Node(int id, String name, URI location, InetAddress ipAddress, int port, boolean enabled, String description) { this.id = id; this.name = name; @@ -61,7 +61,7 @@ public class Node implements Comparable { return description; } - public String getId() { + public int getId() { return id; } @@ -73,13 +73,26 @@ public class Node implements Comparable { return location; } - public int compareTo(Node that) { - return (this == that) ? 0 : this.getId().compareTo(that.getId()); - } - public InetAddress getIpAddress() { return ipAddress; } + + public int compareTo(Node that) { + if (this == that) + return 0; + if (this.id < that.id) + return -1; + if (this.id > that.id) + return 1; + return 0; + } + + @Override + public String toString() { + return "Node [id=" + id + ", name=" + name + ", description=" + description + ", ipAddress=" + + ipAddress + ", port=" + port + ", location=" + location + ", enabled=" + enabled + + "]"; + } @Override public int hashCode() { @@ -87,7 +100,7 @@ public class Node implements Comparable { int result = 1; result = prime * result + ((description == null) ? 0 : description.hashCode()); result = prime * result + (enabled ? 1231 : 1237); - result = prime * result + ((id == null) ? 0 : id.hashCode()); + result = prime * result + id; result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode()); result = prime * result + ((location == null) ? 0 : location.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); @@ -111,10 +124,7 @@ public class Node implements Comparable { return false; if (enabled != other.enabled) return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) + if (id != other.id) return false; if (ipAddress == null) { if (other.ipAddress != null) diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Protocol.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Protocol.java new file mode 100644 index 0000000000..58c87ffc60 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/domain/Protocol.java @@ -0,0 +1,37 @@ +/** + * + * 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; + +/** + * + * Protocol for an {@link InternetService} + * + * @author Adrian Cole + * + */ +public enum Protocol { + + FTP, HTTP, HTTPS, TCP, UDP; + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/ReturnVoidOnDeleteDefaultIp.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/ReturnVoidOnDeleteDefaultIp.java new file mode 100644 index 0000000000..6d525e9dab --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/options/ReturnVoidOnDeleteDefaultIp.java @@ -0,0 +1,66 @@ +/** + * + * 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.options; + +import java.lang.reflect.Constructor; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpResponseException; + +import com.google.common.base.Function; + +/** + * There's no current way to determine if an IP is the default outbound one. In this case, we may + * get errors on deleting an IP, which are ok. + * + * @author Adrian Cole + */ +@Singleton +public class ReturnVoidOnDeleteDefaultIp implements Function { + + static final Void v; + static { + Constructor cv; + try { + cv = Void.class.getDeclaredConstructor(); + cv.setAccessible(true); + v = cv.newInstance(); + } catch (Exception e) { + throw new Error("Error setting up class", e); + } + } + + public Void apply(Exception from) { + if (from instanceof HttpResponseException) { + HttpResponseException hre = (HttpResponseException) from; + if (hre.getResponse().getStatusCode() == 503 + || hre.getMessage().matches( + ".*Cannot release this Public IP as it is default oubound IP.*")) + return v; + } + return null; + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.java new file mode 100644 index 0000000000..d3faaa7eeb --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandler.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.terremark.xml; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.vcloud.terremark.domain.ComputeOption; + +/** + * @author Adrian Cole + */ +public class ComputeOptionHandler extends HandlerWithResult { + + private StringBuilder currentText = new StringBuilder(); + + int processorCount; + int memory; + float costPerHour; + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } + + @Override + public ComputeOption getResult() { + return new ComputeOption(processorCount, memory, costPerHour); + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("ProcessorCount")) { + processorCount = Integer.parseInt(currentOrNull()); + } else if (qName.equals("Memory")) { + memory = Integer.parseInt(currentOrNull()); + } else if (qName.equals("CostPerHour")) { + costPerHour = Float.parseFloat(currentOrNull()); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java new file mode 100644 index 0000000000..91a15639d9 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandler.java @@ -0,0 +1,76 @@ +/** + * + * 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.xml; + +import java.util.SortedSet; + +import javax.annotation.Resource; +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class ComputeOptionsHandler extends HandlerWithResult> { + + @Resource + protected Logger logger = Logger.NULL; + private final ComputeOptionHandler handler; + SortedSet result = Sets.newTreeSet(); + + @Inject + public ComputeOptionsHandler(ComputeOptionHandler handler) { + this.handler = handler; + } + + @Override + public SortedSet getResult() { + return result; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + handler.startElement(uri, localName, qName, attributes); + } + + public void endElement(String uri, String name, String qName) { + handler.endElement(uri, name, qName); + if (qName.equals("ComputeOption")) { + result.add(handler.getResult()); + } + } + + public void characters(char ch[], int start, int length) { + handler.characters(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandler.java new file mode 100644 index 0000000000..fb5e431477 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandler.java @@ -0,0 +1,61 @@ +/** + * + * 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.xml; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.vcloud.terremark.domain.CustomizationParameters; + +/** + * @author Adrian Cole + */ +public class CustomizationParametersHandler extends HandlerWithResult { + + private StringBuilder currentText = new StringBuilder(); + boolean customizeNetwork; + boolean customizePassword; + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } + + @Override + public CustomizationParameters getResult() { + return new CustomizationParameters(customizeNetwork, customizePassword); + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("CustomizeNetwork")) { + customizeNetwork = Boolean.parseBoolean(currentOrNull()); + } else if (qName.equals("CustomizePassword")) { + customizePassword = Boolean.parseBoolean(currentOrNull()); + } + currentText = new StringBuilder(); + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java index 4e9b1219b1..08d876c9ba 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java @@ -32,6 +32,7 @@ import javax.annotation.Resource; import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.logging.Logger; import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.xml.sax.Attributes; import org.xml.sax.SAXException; @@ -47,7 +48,7 @@ public class InternetServiceHandler extends HandlerWithResult { private boolean inPublicIpAddress; private int addressId; - private String id; + private int id; private URI location; private URI addressLocation; private String serviceName; @@ -57,7 +58,7 @@ public class InternetServiceHandler extends HandlerWithResult { private String description; private int timeout; private boolean enabled; - private String protocol; + private Protocol protocol; protected String currentOrNull() { String returnVal = currentText.toString().trim(); @@ -83,7 +84,7 @@ public class InternetServiceHandler extends HandlerWithResult { if (inPublicIpAddress) addressId = Integer.parseInt(currentOrNull()); else - id = currentOrNull(); + id = Integer.parseInt(currentOrNull()); } else if (qName.equals("Href") && currentOrNull() != null) { if (inPublicIpAddress) addressLocation = URI.create(currentOrNull()); @@ -103,7 +104,7 @@ public class InternetServiceHandler extends HandlerWithResult { } else if (qName.equals("Port")) { port = Integer.parseInt(currentOrNull()); } else if (qName.equals("Protocol")) { - protocol = currentOrNull(); + protocol = Protocol.valueOf(currentOrNull()); } else if (qName.equals("Enabled")) { enabled = Boolean.parseBoolean(currentOrNull()); } else if (qName.equals("Timeout")) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java index 29eb2d86bb..480ab6191b 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java @@ -42,7 +42,7 @@ public class NodeHandler extends HandlerWithResult { protected Logger logger = Logger.NULL; private StringBuilder currentText = new StringBuilder(); - private String id; + private int id; private URI location; private String serviceName; private InetAddress address; @@ -62,7 +62,7 @@ public class NodeHandler extends HandlerWithResult { public void endElement(String uri, String name, String qName) { if (qName.equals("Id")) { - id = currentOrNull(); + id = Integer.parseInt(currentOrNull()); } else if (qName.equals("Href") && currentOrNull() != null) { location = URI.create(currentOrNull()); } else if (qName.equals("Name")) { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandler.java new file mode 100644 index 0000000000..41df9fe449 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandler.java @@ -0,0 +1,90 @@ +/** + * + * 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.xml; + +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; + +import javax.annotation.Resource; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.terremark.domain.PublicIpAddress; + +/** + * @author Adrian Cole + */ +public class PublicIpAddressHandler extends HandlerWithResult { + + @Resource + protected Logger logger = Logger.NULL; + + private StringBuilder currentText = new StringBuilder(); + + private int id; + private InetAddress address; + + private URI location; + + protected String currentOrNull() { + String returnVal = currentText.toString().trim(); + return returnVal.equals("") ? null : returnVal; + } + + @Override + public PublicIpAddress getResult() { + return new PublicIpAddress(id, address, location); + } + + public void endElement(String uri, String name, String qName) { + if (qName.equals("Id")) { + id = Integer.parseInt(currentOrNull()); + } else if (qName.equals("Href") && currentOrNull() != null) { + location = URI.create(currentOrNull()); + } else if (qName.equals("Name")) { + address = parseInetAddress(currentOrNull()); + } + currentText = new StringBuilder(); + } + + 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); + throw new RuntimeException(e); + } + } + + public void characters(char ch[], int start, int length) { + currentText.append(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandler.java new file mode 100644 index 0000000000..29a0265e21 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandler.java @@ -0,0 +1,76 @@ +/** + * + * 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.xml; + +import java.util.SortedSet; + +import javax.annotation.Resource; +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class PublicIpAddressesHandler extends HandlerWithResult> { + + @Resource + protected Logger logger = Logger.NULL; + private final PublicIpAddressHandler handler; + SortedSet result = Sets.newTreeSet(); + + @Inject + public PublicIpAddressesHandler(PublicIpAddressHandler handler) { + this.handler = handler; + } + + @Override + public SortedSet getResult() { + return result; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + handler.startElement(uri, localName, qName, attributes); + } + + public void endElement(String uri, String name, String qName) { + handler.endElement(uri, name, qName); + if (qName.equals("PublicIPAddress")) { + result.add(handler.getResult()); + } + } + + public void characters(char ch[], int start, int length) { + handler.characters(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java new file mode 100644 index 0000000000..87f3d97de0 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/InternetServiceLiveTest.java @@ -0,0 +1,123 @@ +/** + * + * 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; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.SortedSet; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeoutException; + +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.ssh.jsch.config.JschSshClientModule; +import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.Node; +import org.jclouds.vcloud.terremark.domain.Protocol; +import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.testng.annotations.AfterTest; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.collect.Sets; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code TerremarkVCloudClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest") +public class InternetServiceLiveTest { + TerremarkVCloudClient tmClient; + + private SortedSet services = Sets.newTreeSet(); + + public static final String PREFIX = System.getProperty("user.name") + "-terremark"; + + @Test + public void testGetAllInternetServices() throws Exception { + SortedSet set = tmClient.getAllInternetServices(); + print(set); + } + + @Test + public void testAddInternetService() { + + InternetService is = tmClient.addInternetService("test-" + 22, Protocol.TCP, 22); + services.add(is); + PublicIpAddress ip = is.getPublicIpAddress(); + for (int port : new int[] { 80, 8080 }) { + services.add(tmClient.addInternetServiceToExistingIp(ip.getId(), "test-" + port, + Protocol.HTTP, port)); + } + print(tmClient.getInternetServicesOnPublicIp(ip.getId())); + } + + private void print(SortedSet set) { + for (InternetService service : set) { + System.out.printf("%d (%s:%d%n)", service.getId(), service.getPublicIpAddress() + .getAddress().getHostAddress(), service.getPort()); + for (Node node : tmClient.getNodes(service.getId())) { + System.out.printf(" %d (%s:%d%n)", node.getId(), + node.getIpAddress().getHostAddress(), node.getPort()); + } + } + } + + private void delete(SortedSet set) { + for (InternetService service : set) { + for (Node node : tmClient.getNodes(service.getId())) { + tmClient.deleteNode(node.getId()); + } + tmClient.deleteInternetService(service.getId()); + tmClient.deletePublicIp(service.getPublicIpAddress().getId()); + } + } + + @Test + public void testGetAllPublicIps() throws Exception { + for (PublicIpAddress ip : tmClient.getPublicIpsAssociatedWithVDC()) { + SortedSet set = tmClient.getInternetServicesOnPublicIp(ip.getId()); + print(set); + } + } + + @AfterTest + void cleanup() throws InterruptedException, ExecutionException, TimeoutException { + delete(services); + } + + @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 TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder( + account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(), + new JschSshClientModule()).buildInjector(); + + tmClient = injector.getInstance(TerremarkVCloudClient.class); + + } + +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 91ab40143b..f2d7cf4343 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -61,8 +61,11 @@ import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot; import org.jclouds.vcloud.endpoints.internal.VAppRoot; import org.jclouds.vcloud.filters.SetVCloudTokenCookie; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; +import org.jclouds.vcloud.terremark.xml.ComputeOptionsHandler; +import org.jclouds.vcloud.terremark.xml.CustomizationParametersHandler; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; import org.jclouds.vcloud.terremark.xml.InternetServicesHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; @@ -147,10 +150,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", "tcp", 22); + "name", Protocol.TCP, 22); assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1"); assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n"); @@ -167,10 +170,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - "name", "tcp", 22, disabled().withDescription("yahoo")); + "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1"); assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n"); @@ -201,8 +204,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -219,8 +221,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -238,10 +240,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - 12, "name", "tcp", 22); + 12, "name", Protocol.TCP, 22); assertRequestLineEquals(httpMethod, "POST http://vcloud/publicIps/12/InternetServices HTTP/1.1"); @@ -259,10 +261,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, - 12, "name", "tcp", 22, disabled().withDescription("yahoo")); + 12, "name", Protocol.TCP, 22, disabled().withDescription("yahoo")); assertRequestLineEquals(httpMethod, "POST http://vcloud/publicIps/12/InternetServices HTTP/1.1"); @@ -277,7 +279,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, @@ -296,7 +298,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, @@ -315,7 +317,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -331,7 +333,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -347,7 +349,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, 12); @@ -362,6 +364,41 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest httpMethod = processor.createRequest(method, + 12); + + assertRequestLineEquals(httpMethod, "GET http://vcloud/vapp/12/options/compute HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, ComputeOptionsHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + public void testGetCustomizationOptions() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("getCustomizationOptions", + String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); + + assertRequestLineEquals(httpMethod, + "GET http://vcloud/vapp/12/options/customization HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, CustomizationParametersHandler.class); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + @Override protected void checkFilters(GeneratedHttpRequest httpMethod) { assertEquals(httpMethod.getFilters().size(), 1); 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 8341d82855..bd1fd9e9c1 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 @@ -51,6 +51,7 @@ 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.Protocol; import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.jclouds.vcloud.terremark.domain.TerremarkVDC; import org.testng.annotations.AfterTest; @@ -127,6 +128,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { assertEquals(deployTask.getLocation(), deployTask.getLocation()); vApp = tmClient.getVApp(vApp.getId()); + assertEquals(vApp.getStatus(), VAppStatus.CREATING); try {// per docs, this is not supported @@ -147,13 +149,14 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { vApp = tmClient.getVApp(vApp.getId()); assertEquals(vApp.getStatus(), VAppStatus.ON); - + System.out.println(tmClient.getComputeOptions(vApp.getId())); + System.out.println(tmClient.getCustomizationOptions(vApp.getId())); } @Test public void testAddInternetService() throws InterruptedException, ExecutionException, TimeoutException, IOException { - is = tmClient.addInternetService("SSH", "TCP", 22); + is = tmClient.addInternetService("SSH", Protocol.TCP, 22); } @Test(dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" }) diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java index 07669e7448..6cbc5b1e15 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClientLiveTest.java @@ -119,7 +119,8 @@ public class TerremarkVCloudComputeClientLiveTest { @Test(dependsOnMethods = "testGetAnyPrivateAddress") public void testSshLoadBalanceIp() { - InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22); + InetAddress publicIp = client.createPublicAddressMappedToPorts(tmClient.getVApp(id), 22, 80, + 8080); assert addressTester.apply(publicIp); // client.exec(publicIp, "uname -a"); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.java new file mode 100644 index 0000000000..c26aa7c981 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionHandlerTest.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.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.UnknownHostException; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code ComputeOptionServiceHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.ComputeOptionHandlerTest") +public class ComputeOptionHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/ComputeOption.xml"); + + ComputeOption result = (ComputeOption) factory.create( + injector.getInstance(ComputeOptionHandler.class)).parse(is); + assertEquals(result, new ComputeOption(1, 512, 0.039f)); + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java new file mode 100644 index 0000000000..9f508a2c0d --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/ComputeOptionsHandlerTest.java @@ -0,0 +1,54 @@ +/** + * + * 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.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.UnknownHostException; +import java.util.SortedSet; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.ComputeOption; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; + +/** + * Tests behavior of {@code ComputeOptionsHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.ComputeOptionsHandlerTest") +public class ComputeOptionsHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/ComputeOptions.xml"); + + SortedSet result = factory.create( + injector.getInstance(ComputeOptionsHandler.class)).parse(is); + assertEquals(result, ImmutableSortedSet.of(new ComputeOption(1, 512, 0.039f), + new ComputeOption(8, 16384, 1.61f))); + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandlerTest.java new file mode 100644 index 0000000000..ea04efa75f --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/CustomizationParametersHandlerTest.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.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.UnknownHostException; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.CustomizationParameters; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code CustomizationParametersHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.CustomizationParametersHandlerTest") +public class CustomizationParametersHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/CustomizationParameters.xml"); + + CustomizationParameters result = (CustomizationParameters) factory.create( + injector.getInstance(CustomizationParametersHandler.class)).parse(is); + assertEquals(result, new CustomizationParameters(true, false)); + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java index 114ad2f811..a95a079a36 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java @@ -32,6 +32,7 @@ import java.net.UnknownHostException; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -55,8 +56,8 @@ public class InternetServiceHandlerTest extends BaseHandlerTest { InternetService result = (InternetService) factory.create( injector.getInstance(InternetServiceHandler.class)).parse(is); - assertEquals(result, new InternetService(523 + "", "IS_for_Jim", null, new PublicIpAddress( - 4208, InetAddress.getByName("10.1.22.159"), null), 80, "HTTP", false, 1, + assertEquals(result, new InternetService(523, "IS_for_Jim", null, new PublicIpAddress(4208, + InetAddress.getByName("10.1.22.159"), null), 80, Protocol.HTTP, false, 1, "Some test service")); } @@ -68,7 +69,7 @@ public class InternetServiceHandlerTest extends BaseHandlerTest { assertEquals( result, new InternetService( - 524 + "", + 524, "IS_for_Jim2", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"), @@ -77,6 +78,6 @@ public class InternetServiceHandlerTest extends BaseHandlerTest { InetAddress.getByName("10.1.22.159"), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208")), - 45, "HTTP", false, 1, "Some test service")); + 45, Protocol.HTTP, false, 1, "Some test service")); } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java index 9e8622af49..b0bf265a17 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java @@ -33,6 +33,7 @@ import java.util.SortedSet; import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.Protocol; import org.jclouds.vcloud.terremark.domain.PublicIpAddress; import org.testng.annotations.Test; @@ -55,7 +56,7 @@ public class InternetServicesHandlerTest extends BaseHandlerTest { result, ImmutableSortedSet .of(new InternetService( - 524 + "", + 524, "IS_for_Jim2", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"), @@ -64,6 +65,6 @@ public class InternetServicesHandlerTest extends BaseHandlerTest { InetAddress.getByName("10.1.22.159"), URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208")), - 45, "HTTP", false, 1, "Some test service"))); + 45, Protocol.HTTP, false, 1, "Some test service"))); } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java index 9cfc74b488..7306849b1f 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java @@ -46,7 +46,7 @@ public class NodeHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/terremark/NodeService.xml"); Node result = (Node) factory.create(injector.getInstance(NodeHandler.class)).parse(is); - assertEquals(result, new Node(242 + "", "Node for Jim", URI + assertEquals(result, new Node(242, "Node for Jim", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"), InetAddress.getByName("172.16.20.3"), 80, false, "Some test node")); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java index 171a56b6e1..18d4ae517e 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java @@ -49,7 +49,7 @@ public class NodesHandlerTest extends BaseHandlerTest { InputStream is = getClass().getResourceAsStream("/terremark/NodeServices.xml"); SortedSet result = factory.create(injector.getInstance(NodesHandler.class)).parse(is); - assertEquals(result, ImmutableSortedSet.of(new Node(242 + "", "Node for Jim", URI + assertEquals(result, ImmutableSortedSet.of(new Node(242, "Node for Jim", URI .create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"), InetAddress.getByName("172.16.20.3"), 80, false, "Some test node"))); } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandlerTest.java new file mode 100644 index 0000000000..46f0afa295 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressHandlerTest.java @@ -0,0 +1,53 @@ +/** + * + * 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.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.terremark.domain.PublicIpAddress; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code PublicIpAddressHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.PublicIpAddressHandlerTest") +public class PublicIpAddressHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/PublicIpAddress.xml"); + + PublicIpAddress result = factory.create(injector.getInstance(PublicIpAddressHandler.class)) + .parse(is); + assertEquals(result, new PublicIpAddress(8720, InetAddress.getByName("204.51.112.91"), URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/8720"))); + } +} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandlerTest.java new file mode 100644 index 0000000000..0c53c063b5 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/PublicIpAddressesHandlerTest.java @@ -0,0 +1,69 @@ +/** + * + * 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.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.terremark.domain.PublicIpAddress; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; + +/** + * Tests behavior of {@code PublicIpAddressesHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "terremark.PublicIpAddressesHandlerTest") +public class PublicIpAddressesHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/PublicIpAddresses.xml"); + + SortedSet result = factory.create( + injector.getInstance(PublicIpAddressesHandler.class)).parse(is); + assertEquals( + result, + ImmutableSortedSet + .of( + new PublicIpAddress( + 8720, + InetAddress.getByName("204.51.112.91"), + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/8720")), + new PublicIpAddress( + 14965, + InetAddress.getByName("204.51.114.79"), + URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/14965")))); + + } +} diff --git a/vcloud/terremark/src/test/resources/terremark/ComputeOption.xml b/vcloud/terremark/src/test/resources/terremark/ComputeOption.xml new file mode 100644 index 0000000000..6ba5e98bd8 --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/ComputeOption.xml @@ -0,0 +1,6 @@ + + 1 + 512 + 0.0390 + \ No newline at end of file diff --git a/vcloud/terremark/src/test/resources/terremark/ComputeOptions.xml b/vcloud/terremark/src/test/resources/terremark/ComputeOptions.xml new file mode 100644 index 0000000000..2dded5764d --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/ComputeOptions.xml @@ -0,0 +1,13 @@ + + + 1 + 512 + 0.0390 + + + 8 + 16384 + 1.6100 + + diff --git a/vcloud/terremark/src/test/resources/terremark/CreateInternetService-options-test.xml b/vcloud/terremark/src/test/resources/terremark/CreateInternetService-options-test.xml index 3b2c9b4b07..0bd090aafa 100644 --- a/vcloud/terremark/src/test/resources/terremark/CreateInternetService-options-test.xml +++ b/vcloud/terremark/src/test/resources/terremark/CreateInternetService-options-test.xml @@ -1,7 +1,7 @@ name - tcp + TCP 22 false yahoo diff --git a/vcloud/terremark/src/test/resources/terremark/CreateInternetService-test2.xml b/vcloud/terremark/src/test/resources/terremark/CreateInternetService-test2.xml index f88f8f6815..e97a9d2e7f 100644 --- a/vcloud/terremark/src/test/resources/terremark/CreateInternetService-test2.xml +++ b/vcloud/terremark/src/test/resources/terremark/CreateInternetService-test2.xml @@ -1,7 +1,7 @@ name - tcp + TCP 22 true \ No newline at end of file diff --git a/vcloud/terremark/src/test/resources/terremark/CustomizationParameters.xml b/vcloud/terremark/src/test/resources/terremark/CustomizationParameters.xml new file mode 100644 index 0000000000..2cabbe7570 --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/CustomizationParameters.xml @@ -0,0 +1,5 @@ + + true + false + \ No newline at end of file diff --git a/vcloud/terremark/src/test/resources/terremark/PublicIpAddress.xml b/vcloud/terremark/src/test/resources/terremark/PublicIpAddress.xml new file mode 100644 index 0000000000..a519a81e62 --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/PublicIpAddress.xml @@ -0,0 +1,7 @@ + + 8720 + https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/8720 + + 204.51.112.91 + \ No newline at end of file diff --git a/vcloud/terremark/src/test/resources/terremark/PublicIpAddresses.xml b/vcloud/terremark/src/test/resources/terremark/PublicIpAddresses.xml new file mode 100644 index 0000000000..264863e334 --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/PublicIpAddresses.xml @@ -0,0 +1,15 @@ + + + 8720 + https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/8720 + + 204.51.112.91 + + + 14965 + https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/14965 + + 204.51.114.79 + + \ No newline at end of file