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
This commit is contained in:
adrian.f.cole 2009-12-12 20:46:42 +00:00
parent 193de5814e
commit 0703d20b8c
37 changed files with 1488 additions and 133 deletions

View File

@ -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<? extends VDC> 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<? extends InternetService> 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<? extends SortedSet<InternetService>> 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<? extends InternetService> 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<Void> deletePublicIp(@PathParam("ipId") int ipId);
/**
* @see TerremarkVCloudClient#getInternetServicesOnPublicIP
*/
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/publicIps/{ipId}/InternetServices")
@XMLResponseParser(InternetServicesHandler.class)
Future<? extends SortedSet<InternetService>> getInternetServicesOnPublicIp(
@PathParam("ipId") int ipId);
/**
* @see TerremarkVCloudClient#getPublicIpsAssociatedWithVDC
*/
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
@Path("/publicIps")
@XMLResponseParser(PublicIpAddressesHandler.class)
Future<? extends SortedSet<PublicIpAddress>> getPublicIpsAssociatedWithVDC();
/**
* @see TerremarkVCloudClient#deleteInternetService
*/
@DELETE
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/internetServices/{internetServiceId}")
Future<Void> deleteInternetService(@PathParam("internetServiceId") String internetServiceId);
Future<Void> deleteInternetService(@PathParam("internetServiceId") int internetServiceId);
/**
* @see TerremarkVCloudClient#getInternetService
*/
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/internetServices/{internetServiceId}")
@XMLResponseParser(InternetServiceHandler.class)
Future<? extends InternetService> 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<? extends Node> 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<? extends SortedSet<InternetService>> getNodes(
@PathParam("internetServiceId") String internetServiceId);
Future<? extends SortedSet<Node>> getNodes(@PathParam("internetServiceId") int internetServiceId);
/**
* @see TerremarkVCloudClient#getNode
*/
@GET
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/nodeServices/{nodeId}")
@XMLResponseParser(NodeHandler.class)
Future<? extends Node> getNode(@PathParam("nodeId") String nodeId);
Future<? extends Node> getNode(@PathParam("nodeId") int nodeId);
/**
* @see TerremarkVCloudClient#deleteNode
*/
@DELETE
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/nodeServices/{nodeId}")
Future<Void> deleteNode(@PathParam("nodeId") String nodeId);
Future<Void> 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<? extends TerremarkVApp> getVApp(@PathParam("vAppId") String vAppId);
/**
* @see TerremarkVCloudClient#getComputeOptions
*/
@GET
@Consumes(VAPP_XML)
@Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class)
@Path("/vapp/{vAppId}")
Future<String> getVAppString(@PathParam("vAppId") String vAppId);
@Path("/vapp/{vAppId}/options/compute")
@XMLResponseParser(ComputeOptionsHandler.class)
Future<? extends SortedSet<ComputeOption>> 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<? extends CustomizationParameters> getCustomizationOptions(
@PathParam("vAppId") String vAppId);
}

View File

@ -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<ComputeOption> 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<PublicIpAddress> 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<InternetService> getAllInternetServices();
SortedSet<Node> getNodes(String internetServiceId);
/**
* This call returns information about the internet service on a public IP.
*/
SortedSet<InternetService> getInternetServicesOnPublicIp(int ipId);
/**
* This call adds a node to an existing internet service.
* <p/>
* 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<Node> getNodes(int internetServiceId);
}

View File

@ -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<PublicIpAddress> 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<PublicIpAddress> deleteInternetServicesAndNodesAssociatedWithVApp(TerremarkVApp vApp) {
Set<PublicIpAddress> 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<PublicIpAddress> ipAddresses) {
IPADDRESS: for (PublicIpAddress address : ipAddresses) {
SortedSet<InternetService> 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,

View File

@ -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
.<InetAddress> of(publicIp), vApp.getNetworkToAddresses().values(), 22,
LoginType.SSH, new Credentials("vcloud", "p4ssw0rd"));

View File

@ -0,0 +1,113 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.domain;
/**
* 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 <a
* href="https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/6-using-the-vcloud-express-api.aspx"
* >Terremark documentation</a>
*/
public class ComputeOption implements Comparable<ComputeOption> {
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 + "]";
}
}

View File

@ -0,0 +1,82 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.domain;
/**
* The response lists which customization options are supported for this particular vApp. The
* possible customization options are Network and Password.
*
* @author Adrian Cole
* @see <a
* href="https://community.vcloudexpress.terremark.com/en-us/product_docs/w/wiki/6-using-the-vcloud-express-api.aspx"
* >Terremark documentation</a>
*/
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 + "]";
}
}

View File

@ -29,18 +29,18 @@ import java.net.URI;
* @author Adrian Cole
*/
public class InternetService implements Comparable<InternetService> {
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<InternetService> {
return port;
}
public String getProtocol() {
public Protocol getProtocol() {
return protocol;
}
@ -76,13 +76,42 @@ public class InternetService implements Comparable<InternetService> {
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<InternetService> {
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<InternetService> {
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 + "]";
}
}

View File

@ -30,7 +30,7 @@ import java.net.URI;
* @author Adrian Cole
*/
public class Node implements Comparable<Node> {
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<Node> {
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<Node> {
return description;
}
public String getId() {
public int getId() {
return id;
}
@ -73,13 +73,26 @@ public class Node implements Comparable<Node> {
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<Node> {
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<Node> {
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)

View File

@ -0,0 +1,37 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.domain;
/**
*
* Protocol for an {@link InternetService}
*
* @author Adrian Cole
*
*/
public enum Protocol {
FTP, HTTP, HTTPS, TCP, UDP;
}

View File

@ -0,0 +1,66 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.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<Exception, Void> {
static final Void v;
static {
Constructor<Void> 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;
}
}

View File

@ -0,0 +1,65 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.xml;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.vcloud.terremark.domain.ComputeOption;
/**
* @author Adrian Cole
*/
public class ComputeOptionHandler extends HandlerWithResult<ComputeOption> {
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);
}
}

View File

@ -0,0 +1,76 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.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<SortedSet<ComputeOption>> {
@Resource
protected Logger logger = Logger.NULL;
private final ComputeOptionHandler handler;
SortedSet<ComputeOption> result = Sets.newTreeSet();
@Inject
public ComputeOptionsHandler(ComputeOptionHandler handler) {
this.handler = handler;
}
@Override
public SortedSet<ComputeOption> 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);
}
}

View File

@ -0,0 +1,61 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.xml;
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.vcloud.terremark.domain.CustomizationParameters;
/**
* @author Adrian Cole
*/
public class CustomizationParametersHandler extends HandlerWithResult<CustomizationParameters> {
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);
}
}

View File

@ -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<InternetService> {
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<InternetService> {
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<InternetService> {
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<InternetService> {
} 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")) {

View File

@ -42,7 +42,7 @@ public class NodeHandler extends HandlerWithResult<Node> {
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<Node> {
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")) {

View File

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

View File

@ -0,0 +1,76 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark.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<SortedSet<PublicIpAddress>> {
@Resource
protected Logger logger = Logger.NULL;
private final PublicIpAddressHandler handler;
SortedSet<PublicIpAddress> result = Sets.newTreeSet();
@Inject
public PublicIpAddressesHandler(PublicIpAddressHandler handler) {
this.handler = handler;
}
@Override
public SortedSet<PublicIpAddress> 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);
}
}

View File

@ -0,0 +1,123 @@
/**
*
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
*
* ====================================================================
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
* ====================================================================
*/
package org.jclouds.vcloud.terremark;
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<InternetService> services = Sets.newTreeSet();
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
@Test
public void testGetAllInternetServices() throws Exception {
SortedSet<InternetService> 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<InternetService> 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<InternetService> 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<InternetService> 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);
}
}

View File

@ -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<TerremarkVClo
public void testAddInternetService() throws SecurityException, NoSuchMethodException,
IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
String.class, String.class, int.class, Array.newInstance(
String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService",
String.class, String.class, int.class, Array.newInstance(
String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
public void testGetInternetService() throws SecurityException, NoSuchMethodException,
IOException {
Method method = TerremarkVCloudAsyncClient.class
.getMethod("getInternetService", String.class);
Method method = TerremarkVCloudAsyncClient.class.getMethod("getInternetService", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
@ -219,8 +221,8 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException,
IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService",
String.class);
Method method = TerremarkVCloudAsyncClient.class
.getMethod("deleteInternetService", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
@ -238,10 +240,10 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
public void testAddInternetServiceToExistingIp() throws SecurityException,
NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
String.class, String.class, String.class, int.class, Array.newInstance(
int.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
public void testAddInternetServiceToExistingIpOptions() throws SecurityException,
NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp",
String.class, String.class, String.class, int.class, Array.newInstance(
int.class, String.class, Protocol.class, int.class, Array.newInstance(
AddInternetServiceOptions.class, 0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVClo
}
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class,
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
@ -296,7 +298,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
}
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.class,
Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", int.class,
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
0).getClass());
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
@ -315,7 +317,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
}
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", String.class);
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
@ -331,7 +333,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
}
public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", String.class);
Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
@ -347,7 +349,7 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
}
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", String.class);
Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", int.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> httpMethod = processor.createRequest(method,
12);
@ -362,6 +364,41 @@ public class TerremarkVCloudAsyncClientTest extends RestClientTest<TerremarkVClo
checkFilters(httpMethod);
}
public void testGetComputeOptions() throws SecurityException, NoSuchMethodException, IOException {
Method method = TerremarkVCloudAsyncClient.class.getMethod("getComputeOptions", String.class);
GeneratedHttpRequest<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> 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<TerremarkVCloudAsyncClient> httpMethod) {
assertEquals(httpMethod.getFilters().size(), 1);

View File

@ -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" })

View File

@ -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");
}

View File

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

View File

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

View File

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

View File

@ -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"));
}
}

View File

@ -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")));
}
}

View File

@ -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"));
}

View File

@ -49,7 +49,7 @@ public class NodesHandlerTest extends BaseHandlerTest {
InputStream is = getClass().getResourceAsStream("/terremark/NodeServices.xml");
SortedSet<Node> 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")));
}

View File

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

View File

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

View File

@ -0,0 +1,6 @@
<ComputeOption xmlns="urn:tmrk:vCloudExpress-1.0"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ProcessorCount>1</ProcessorCount>
<Memory>512</Memory>
<CostPerHour>0.0390</CostPerHour>
</ComputeOption>

View File

@ -0,0 +1,13 @@
<ComputeOptions xmlns="urn:tmrk:vCloudExpress-1.0"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ComputeOption>
<ProcessorCount>1</ProcessorCount>
<Memory>512</Memory>
<CostPerHour>0.0390</CostPerHour>
</ComputeOption>
<ComputeOption>
<ProcessorCount>8</ProcessorCount>
<Memory>16384</Memory>
<CostPerHour>1.6100</CostPerHour>
</ComputeOption>
</ComputeOptions>

View File

@ -1,7 +1,7 @@
<InternetService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createInternetService">
<Name>name</Name>
<Protocol>tcp</Protocol>
<Protocol>TCP</Protocol>
<Port>22</Port>
<Enabled>false</Enabled>
<Description>yahoo</Description>

View File

@ -1,7 +1,7 @@
<InternetService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createInternetService">
<Name>name</Name>
<Protocol>tcp</Protocol>
<Protocol>TCP</Protocol>
<Port>22</Port>
<Enabled>true</Enabled>
</InternetService>

View File

@ -0,0 +1,5 @@
<CustomizationParameters xmlns="urn:tmrk:vCloudExpress-1.0"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<CustomizeNetwork>true</CustomizeNetwork>
<CustomizePassword>false</CustomizePassword>
</CustomizationParameters>

View File

@ -0,0 +1,7 @@
<PublicIPAddress xmlns="urn:tmrk:vCloudExpress-1.0"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<Id>8720</Id>
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/8720
</Href>
<Name>204.51.112.91</Name>
</PublicIPAddress>

View File

@ -0,0 +1,15 @@
<PublicIpAddresses xmlns="urn:tmrk:vCloudExpress-1.0"
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<PublicIPAddress>
<Id>8720</Id>
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/8720
</Href>
<Name>204.51.112.91</Name>
</PublicIPAddress>
<PublicIPAddress>
<Id>14965</Id>
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/14965
</Href>
<Name>204.51.114.79</Name>
</PublicIPAddress>
</PublicIpAddresses>