mirror of https://github.com/apache/jclouds.git
Issue 112: added support for most Terremark Internet Services Functions
git-svn-id: http://jclouds.googlecode.com/svn/trunk@2287 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
parent
c7306a255f
commit
3aa7e73351
|
@ -49,7 +49,6 @@ import org.jclouds.aws.ec2.domain.SecurityGroup;
|
|||
import org.jclouds.aws.ec2.domain.TerminatedInstance;
|
||||
import org.jclouds.aws.ec2.domain.UserIdGroupPair;
|
||||
import org.jclouds.aws.ec2.filters.FormSigner;
|
||||
import org.jclouds.aws.ec2.functions.InetAddressToHostAddress;
|
||||
import org.jclouds.aws.ec2.functions.ReturnVoidOnGroupNotFound;
|
||||
import org.jclouds.aws.ec2.options.DescribeImagesOptions;
|
||||
import org.jclouds.aws.ec2.options.RunInstancesOptions;
|
||||
|
@ -70,6 +69,7 @@ import org.jclouds.rest.annotations.ParamParser;
|
|||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.VirtualHost;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.InetAddressToHostAddress;
|
||||
|
||||
/**
|
||||
* Provides access to EC2 via their REST API.
|
||||
|
|
|
@ -31,6 +31,9 @@ import javax.annotation.Resource;
|
|||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class AllocateAddressResponseHandler extends HandlerWithResult<InetAddress> {
|
||||
|
||||
@Resource
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* ====================================================================
|
||||
*/
|
||||
|
||||
package org.jclouds.aws.ec2.functions;
|
||||
package org.jclouds.rest.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
@ -139,6 +139,7 @@ public class JschSshClient implements SshClient {
|
|||
session = null;
|
||||
try {
|
||||
session = jsch.getSession(username, host.getHostAddress(), port);
|
||||
session.setTimeout(120 * 1000);
|
||||
logger.debug("%s@%s:%d: Session created.", username, host.getHostAddress(), port);
|
||||
if (password != null) {
|
||||
session.setPassword(password);
|
||||
|
|
|
@ -37,6 +37,7 @@ import javax.ws.rs.DELETE;
|
|||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
|
@ -83,61 +84,70 @@ public interface VCloudClient {
|
|||
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/action/deploy")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/action/deploy")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> deploy(@Endpoint URI vApp);
|
||||
Future<? extends Task> deployVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
@DELETE
|
||||
Future<Void> delete(@Endpoint URI vApp);
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}")
|
||||
Future<Void> deleteVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/action/undeploy")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/action/undeploy")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> undeploy(@Endpoint URI vApp);
|
||||
Future<? extends Task> undeployVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
/**
|
||||
* This call powers on the vApp, as specified in the vApp's ovf:Startup element.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/powerOn")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/power/action/powerOn")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> powerOn(@Endpoint URI vApp);
|
||||
Future<? extends Task> powerOnVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
/**
|
||||
* This call powers off the vApp, as specified in the vApp's ovf:Startup element.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/powerOff")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/power/action/powerOff")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> powerOff(@Endpoint URI vApp);
|
||||
Future<? extends Task> powerOffVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
/**
|
||||
* This call shuts down the vApp.
|
||||
*/
|
||||
@POST
|
||||
@Path("/power/action/shutdown")
|
||||
Future<Void> shutdown(@Endpoint URI vApp);
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/power/action/shutdown")
|
||||
Future<Void> shutdownVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
/**
|
||||
* This call resets the vApp.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/reset")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/power/action/reset")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> reset(@Endpoint URI vApp);
|
||||
Future<? extends Task> resetVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
/**
|
||||
* This call suspends the vApp.
|
||||
*/
|
||||
@POST
|
||||
@Consumes(TASK_XML)
|
||||
@Path("/power/action/suspend")
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}/power/action/suspend")
|
||||
@XMLResponseParser(TaskHandler.class)
|
||||
Future<? extends Task> suspend(@Endpoint URI vApp);
|
||||
Future<? extends Task> suspendVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
@GET
|
||||
@Consumes(TASK_XML)
|
||||
|
@ -150,7 +160,9 @@ public interface VCloudClient {
|
|||
|
||||
@GET
|
||||
@Consumes(VAPP_XML)
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/vapp/{vAppId}")
|
||||
@XMLResponseParser(TerremarkVAppHandler.class)
|
||||
Future<? extends VApp> getVApp(@Endpoint URI vApp);
|
||||
Future<? extends VApp> getVApp(@PathParam("vAppId") int vAppId);
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.jclouds.vcloud.endpoints.TasksList;
|
|||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Provides;
|
||||
|
@ -78,7 +79,12 @@ public class VCloudRestClientModule extends AbstractModule {
|
|||
return vcloudUri.toASCIIString()+"/catalogItem";
|
||||
}
|
||||
|
||||
|
||||
@Provides
|
||||
@VAppRoot
|
||||
@Singleton
|
||||
String provideVAppRoot(@VCloud URI vcloudUri) {
|
||||
return vcloudUri.toASCIIString()+"/vapp";
|
||||
}
|
||||
|
||||
@Provides
|
||||
@VDC
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.endpoints.internal;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Root path where all vApps exist.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Retention(value = RetentionPolicy.RUNTIME)
|
||||
@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Qualifier
|
||||
public @interface VAppRoot {
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.jclouds.vcloud.functions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class VAppIdToUri implements Function<Object, String> {
|
||||
@Inject
|
||||
@VAppRoot
|
||||
private String vAppRoot;
|
||||
|
||||
@Override
|
||||
public String apply(Object from) {
|
||||
checkArgument(checkNotNull(from, "from") instanceof Integer,
|
||||
"this binder is only valid for Integers!");
|
||||
return String.format("%s/%d",vAppRoot,from);
|
||||
}
|
||||
|
||||
}
|
|
@ -25,13 +25,17 @@ package org.jclouds.vcloud.terremark;
|
|||
|
||||
import static org.jclouds.vcloud.VCloudMediaType.VDC_XML;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.rest.annotations.Endpoint;
|
||||
import org.jclouds.rest.annotations.MapBinder;
|
||||
|
@ -39,12 +43,19 @@ import org.jclouds.rest.annotations.MapEntityParam;
|
|||
import org.jclouds.rest.annotations.ParamParser;
|
||||
import org.jclouds.rest.annotations.RequestFilters;
|
||||
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||
import org.jclouds.rest.functions.InetAddressToHostAddress;
|
||||
import org.jclouds.vcloud.VCloudClient;
|
||||
import org.jclouds.vcloud.domain.VDC;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.functions.CatalogIdToUri;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.VApp;
|
||||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||
|
||||
|
@ -74,4 +85,60 @@ public interface TerremarkVCloudClient extends VCloudClient {
|
|||
@MapEntityParam("template") @ParamParser(CatalogIdToUri.class) int templateId,
|
||||
InstantiateVAppTemplateOptions... options);
|
||||
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VDC.class)
|
||||
@Path("/internetServices")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
Future<? extends InternetService> addInternetService(@MapEntityParam("name") String serviceName,
|
||||
@MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port,
|
||||
AddInternetServiceOptions... options);
|
||||
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/publicIps/{ipId}/InternetServices")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
@MapBinder(AddInternetServiceOptions.class)
|
||||
Future<? extends InternetService> addInternetServiceToExistingIp(
|
||||
@PathParam("ipId") int existingIpId, @MapEntityParam("name") String serviceName,
|
||||
@MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port,
|
||||
AddInternetServiceOptions... options);
|
||||
|
||||
@DELETE
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/internetServices/{internetServiceId}")
|
||||
Future<Void> deleteInternetService(@PathParam("internetServiceId") int internetServiceId);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/internetServices/{internetServiceId}")
|
||||
@XMLResponseParser(InternetServiceHandler.class)
|
||||
Future<? extends InternetService> getInternetService(
|
||||
@PathParam("internetServiceId") int internetServiceId);
|
||||
|
||||
@POST
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/internetServices/{internetServiceId}/nodes")
|
||||
@Produces(MediaType.APPLICATION_XML)
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
@MapBinder(AddNodeOptions.class)
|
||||
Future<? extends Node> addNode(
|
||||
@PathParam("internetServiceId") int internetServiceId,
|
||||
@MapEntityParam("ipAddress") @ParamParser(InetAddressToHostAddress.class) InetAddress ipAddress,
|
||||
@MapEntityParam("name") String name, @MapEntityParam("port") int port,
|
||||
AddNodeOptions... options);
|
||||
|
||||
@GET
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/nodeServices/{nodeId}")
|
||||
@XMLResponseParser(NodeHandler.class)
|
||||
Future<? extends Node> getNode(@PathParam("nodeId") int nodeId);
|
||||
|
||||
@DELETE
|
||||
@Endpoint(org.jclouds.vcloud.endpoints.VCloud.class)
|
||||
@Path("/nodeServices/{nodeId}")
|
||||
Future<Void> deleteNode(@PathParam("nodeId") int nodeId);
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
package org.jclouds.vcloud.terremark.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindAddInternetServiceToXmlEntity implements MapBinder {
|
||||
|
||||
@Inject
|
||||
@Named("CreateInternetService")
|
||||
private String xmlTemplate;
|
||||
@Inject
|
||||
private BindToStringEntity stringBinder;
|
||||
|
||||
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
|
||||
|
||||
String name = checkNotNull(postParams.get("name"), "name parameter not present");
|
||||
String protocol = checkNotNull(postParams.get("protocol"), "protocol parameter not present");
|
||||
String port = checkNotNull(postParams.get("port"), "port parameter not present");
|
||||
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present");
|
||||
String description = postParams.get("description");
|
||||
|
||||
String entity = xmlTemplate.replaceAll("\\{name\\}", name);
|
||||
entity = entity.replaceAll("\\{protocol\\}", protocol);
|
||||
entity = entity.replaceAll("\\{port\\}", port);
|
||||
entity = entity.replaceAll("\\{enabled\\}", enabled);
|
||||
entity = entity.replaceAll("\\{description\\}", description == null ? "" : String.format(
|
||||
"%n <Description>%s</Description>", description));
|
||||
|
||||
stringBinder.bindToRequest(request, entity);
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
throw new IllegalStateException("CreateInternetService needs parameters");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package org.jclouds.vcloud.terremark.binders;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.rest.MapBinder;
|
||||
import org.jclouds.rest.binders.BindToStringEntity;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
@Singleton
|
||||
public class BindAddNodeServiceToXmlEntity implements MapBinder {
|
||||
|
||||
@Inject
|
||||
@Named("CreateNodeService")
|
||||
private String xmlTemplate;
|
||||
@Inject
|
||||
private BindToStringEntity stringBinder;
|
||||
|
||||
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
|
||||
String ipAddress = checkNotNull(postParams.get("ipAddress"),
|
||||
"ipAddress parameter not present");
|
||||
String name = checkNotNull(postParams.get("name"), "name parameter not present");
|
||||
String port = checkNotNull(postParams.get("port"), "port parameter not present");
|
||||
String enabled = checkNotNull(postParams.get("enabled"), "enabled parameter not present");
|
||||
String description = postParams.get("description");
|
||||
|
||||
String entity = xmlTemplate.replaceAll("\\{ipAddress\\}", ipAddress);
|
||||
entity = entity.replaceAll("\\{name\\}", name);
|
||||
entity = entity.replaceAll("\\{port\\}", port);
|
||||
entity = entity.replaceAll("\\{enabled\\}", enabled);
|
||||
entity = entity.replaceAll("\\{description\\}", description == null ? "" : String.format(
|
||||
"%n <Description>%s</Description>", description));
|
||||
|
||||
stringBinder.bindToRequest(request, entity);
|
||||
}
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
throw new IllegalStateException("CreateNodeService needs parameters");
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -68,4 +68,19 @@ public class TerremarkVCloudRestClientModule extends VCloudRestClientModule {
|
|||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateInternetService")
|
||||
String provideCreateInternetService() throws IOException {
|
||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService.xml"));
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateNodeService")
|
||||
String provideCreateNodeService() throws IOException {
|
||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService.xml"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,174 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InternetService implements Comparable<InternetService> {
|
||||
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 boolean enabled;
|
||||
private final int timeout;
|
||||
private final String description;
|
||||
|
||||
public InternetService(int id, String name, URI location, PublicIpAddress publicIpAddress,
|
||||
int port, String protocol, boolean enabled, int timeout, String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.publicIpAddress = publicIpAddress;
|
||||
this.port = port;
|
||||
this.protocol = protocol;
|
||||
this.enabled = enabled;
|
||||
this.timeout = timeout;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public PublicIpAddress getPublicIpAddress() {
|
||||
return publicIpAddress;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public int getTimeout() {
|
||||
return timeout;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@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;
|
||||
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + port;
|
||||
result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
|
||||
result = prime * result + ((publicIpAddress == null) ? 0 : publicIpAddress.hashCode());
|
||||
result = prime * result + timeout;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
InternetService other = (InternetService) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (location == null) {
|
||||
if (other.location != null)
|
||||
return false;
|
||||
} else if (!location.equals(other.location))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (port != other.port)
|
||||
return false;
|
||||
if (protocol == null) {
|
||||
if (other.protocol != null)
|
||||
return false;
|
||||
} else if (!protocol.equals(other.protocol))
|
||||
return false;
|
||||
if (publicIpAddress == null) {
|
||||
if (other.publicIpAddress != null)
|
||||
return false;
|
||||
} else if (!publicIpAddress.equals(other.publicIpAddress))
|
||||
return false;
|
||||
if (timeout != other.timeout)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public int compareTo(InternetService that) {
|
||||
final int BEFORE = -1;
|
||||
final int EQUAL = 0;
|
||||
final int AFTER = 1;
|
||||
|
||||
if (this == that)
|
||||
return EQUAL;
|
||||
|
||||
if (this.getId() < that.getId())
|
||||
return BEFORE;
|
||||
if (this.getId() > that.getId())
|
||||
return AFTER;
|
||||
return EQUAL;
|
||||
}
|
||||
|
||||
public int 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 + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,146 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class Node implements Comparable<Node> {
|
||||
private final int id;
|
||||
private final String name;
|
||||
private final URI location;
|
||||
private final InetAddress ipAddress;
|
||||
private final int port;
|
||||
private final boolean enabled;
|
||||
private final String description;
|
||||
|
||||
public Node(int id, String name, URI location, InetAddress ipAddress, int port,
|
||||
boolean enabled, String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.location = location;
|
||||
this.ipAddress = ipAddress;
|
||||
this.port = port;
|
||||
this.enabled = enabled;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public int getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public URI getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public int compareTo(Node that) {
|
||||
final int BEFORE = -1;
|
||||
final int EQUAL = 0;
|
||||
final int AFTER = 1;
|
||||
|
||||
if (this == that)
|
||||
return EQUAL;
|
||||
|
||||
if (this.getId() < that.getId())
|
||||
return BEFORE;
|
||||
if (this.getId() > that.getId())
|
||||
return AFTER;
|
||||
return EQUAL;
|
||||
}
|
||||
|
||||
public InetAddress getIpAddress() {
|
||||
return ipAddress;
|
||||
}
|
||||
|
||||
@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;
|
||||
result = prime * result + ((ipAddress == null) ? 0 : ipAddress.hashCode());
|
||||
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + port;
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Node other = (Node) obj;
|
||||
if (description == null) {
|
||||
if (other.description != null)
|
||||
return false;
|
||||
} else if (!description.equals(other.description))
|
||||
return false;
|
||||
if (enabled != other.enabled)
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (ipAddress == null) {
|
||||
if (other.ipAddress != null)
|
||||
return false;
|
||||
} else if (!ipAddress.equals(other.ipAddress))
|
||||
return false;
|
||||
if (location == null) {
|
||||
if (other.location != null)
|
||||
return false;
|
||||
} else if (!location.equals(other.location))
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
} else if (!name.equals(other.name))
|
||||
return false;
|
||||
if (port != other.port)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.domain;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class PublicIpAddress implements Comparable<PublicIpAddress> {
|
||||
private final int id;
|
||||
private final InetAddress address;
|
||||
private final URI location;
|
||||
|
||||
public PublicIpAddress(int id, InetAddress address, URI location) {
|
||||
this.id = id;
|
||||
this.address = address;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public URI getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public InetAddress getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public int compareTo(PublicIpAddress that) {
|
||||
final int BEFORE = -1;
|
||||
final int EQUAL = 0;
|
||||
final int AFTER = 1;
|
||||
|
||||
if (this == that)
|
||||
return EQUAL;
|
||||
|
||||
if (this.id < that.getId())
|
||||
return BEFORE;
|
||||
if (this.id > that.getId())
|
||||
return AFTER;
|
||||
return EQUAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + ((address == null) ? 0 : address.hashCode());
|
||||
result = prime * result + id;
|
||||
result = prime * result + ((location == null) ? 0 : location.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
PublicIpAddress other = (PublicIpAddress) obj;
|
||||
if (address == null) {
|
||||
if (other.address != null)
|
||||
return false;
|
||||
} else if (!address.equals(other.address))
|
||||
return false;
|
||||
if (id != other.id)
|
||||
return false;
|
||||
if (location == null) {
|
||||
if (other.location != null)
|
||||
return false;
|
||||
} else if (!location.equals(other.location))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PublicIpAddress [address=" + address + ", id=" + id + ", location=" + location + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ import java.util.Map;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.rest.domain.Link;
|
||||
import org.jclouds.rest.domain.NamedLink;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.domain.internal.VAppImpl;
|
||||
|
||||
|
@ -39,7 +39,7 @@ import com.google.inject.ImplementedBy;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
@ImplementedBy(VAppImpl.class)
|
||||
public interface VApp extends NamedLink {
|
||||
public interface VApp extends NamedResource {
|
||||
|
||||
VAppStatus getStatus();
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ import java.util.Map;
|
|||
import java.util.SortedSet;
|
||||
|
||||
import org.jclouds.rest.domain.Link;
|
||||
import org.jclouds.rest.domain.internal.NamedLinkImpl;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.terremark.domain.ResourceAllocation;
|
||||
import org.jclouds.vcloud.terremark.domain.ResourceType;
|
||||
import org.jclouds.vcloud.terremark.domain.VApp;
|
||||
|
@ -46,7 +46,7 @@ import com.google.common.collect.Maps;
|
|||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class VAppImpl extends NamedLinkImpl implements VApp {
|
||||
public class VAppImpl extends NamedResourceImpl implements VApp {
|
||||
|
||||
private final VAppStatus status;
|
||||
private final long size;
|
||||
|
@ -62,12 +62,12 @@ public class VAppImpl extends NamedLinkImpl implements VApp {
|
|||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = 8464716396538298809L;
|
||||
|
||||
public VAppImpl(String name, String type, URI location, VAppStatus status, long size, Link vDC,
|
||||
Link computeOptions, Link customizationOptions,
|
||||
public VAppImpl(int id, String name, String type, URI location, VAppStatus status, long size,
|
||||
Link vDC, Link computeOptions, Link customizationOptions,
|
||||
ListMultimap<String, InetAddress> networkToAddresses,
|
||||
String operatingSystemDescription, VirtualSystem system,
|
||||
SortedSet<ResourceAllocation> resourceAllocations) {
|
||||
super(name, type, location);
|
||||
super(id, name, type, location);
|
||||
this.status = status;
|
||||
this.size = size;
|
||||
this.vDC = vDC;
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package org.jclouds.vcloud.terremark.options;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.vcloud.terremark.binders.BindAddInternetServiceToXmlEntity;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class AddInternetServiceOptions extends BindAddInternetServiceToXmlEntity {
|
||||
|
||||
@VisibleForTesting
|
||||
String description = null;
|
||||
@VisibleForTesting
|
||||
String enabled = "true";
|
||||
|
||||
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
|
||||
Map<String, String> copy = Maps.newHashMap();
|
||||
copy.putAll(postParams);
|
||||
copy.put("description", description);
|
||||
copy.put("enabled", enabled);
|
||||
super.bindToRequest(request, copy);
|
||||
}
|
||||
|
||||
public AddInternetServiceOptions disabled() {
|
||||
this.enabled = "false";
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddInternetServiceOptions withDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see AddInternetServiceOptions#withDescription(String)
|
||||
*/
|
||||
public static AddInternetServiceOptions withDescription(String description) {
|
||||
AddInternetServiceOptions options = new AddInternetServiceOptions();
|
||||
return options.withDescription(description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AddInternetServiceOptions#disabled()
|
||||
*/
|
||||
public static AddInternetServiceOptions disabled() {
|
||||
AddInternetServiceOptions options = new AddInternetServiceOptions();
|
||||
return options.disabled();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package org.jclouds.vcloud.terremark.options;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.vcloud.terremark.binders.BindAddNodeServiceToXmlEntity;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*
|
||||
*/
|
||||
public class AddNodeOptions extends BindAddNodeServiceToXmlEntity {
|
||||
|
||||
@VisibleForTesting
|
||||
String description = null;
|
||||
@VisibleForTesting
|
||||
String enabled = "true";
|
||||
|
||||
public void bindToRequest(HttpRequest request, Map<String, String> postParams) {
|
||||
Map<String, String> copy = Maps.newHashMap();
|
||||
copy.putAll(postParams);
|
||||
copy.put("description", description);
|
||||
copy.put("enabled", enabled);
|
||||
super.bindToRequest(request, copy);
|
||||
}
|
||||
|
||||
public AddNodeOptions disabled() {
|
||||
this.enabled = "false";
|
||||
return this;
|
||||
}
|
||||
|
||||
public AddNodeOptions withDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* @see AddNodeOptions#withDescription(String)
|
||||
*/
|
||||
public static AddNodeOptions withDescription(String description) {
|
||||
AddNodeOptions options = new AddNodeOptions();
|
||||
return options.withDescription(description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see AddNodeOptions#disabled()
|
||||
*/
|
||||
public static AddNodeOptions disabled() {
|
||||
AddNodeOptions options = new AddNodeOptions();
|
||||
return options.disabled();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class InternetServiceHandler extends HandlerWithResult<InternetService> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private boolean inPublicIpAddress;
|
||||
private int addressId;
|
||||
private int id;
|
||||
private URI location;
|
||||
private URI addressLocation;
|
||||
private String serviceName;
|
||||
private InetAddress address;
|
||||
private PublicIpAddress publicIpAddress;
|
||||
private int port;
|
||||
private String description;
|
||||
private int timeout;
|
||||
private boolean enabled;
|
||||
private String protocol;
|
||||
|
||||
protected String currentOrNull() {
|
||||
String returnVal = currentText.toString().trim();
|
||||
return returnVal.equals("") ? null : returnVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InternetService getResult() {
|
||||
return new InternetService(id, serviceName, location, publicIpAddress, port, protocol,
|
||||
enabled, timeout, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes)
|
||||
throws SAXException {
|
||||
if (qName.equals("PublicIpAddress")) {
|
||||
inPublicIpAddress = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String name, String qName) {
|
||||
if (qName.equals("Id")) {
|
||||
if (inPublicIpAddress)
|
||||
addressId = Integer.parseInt(currentOrNull());
|
||||
else
|
||||
id = Integer.parseInt(currentOrNull());
|
||||
} else if (qName.equals("Href") && currentOrNull() != null) {
|
||||
if (inPublicIpAddress)
|
||||
addressLocation = URI.create(currentOrNull());
|
||||
else
|
||||
location = URI.create(currentOrNull());
|
||||
} else if (qName.equals("Name")) {
|
||||
if (inPublicIpAddress)
|
||||
address = parseInetAddress(currentOrNull());
|
||||
else
|
||||
serviceName = currentOrNull();
|
||||
} else if (qName.equals("PublicIpAddress")) {
|
||||
publicIpAddress = new PublicIpAddress(addressId, address, addressLocation);
|
||||
addressId = -1;
|
||||
address = null;
|
||||
addressLocation = null;
|
||||
inPublicIpAddress = false;
|
||||
} else if (qName.equals("Port")) {
|
||||
port = Integer.parseInt(currentOrNull());
|
||||
} else if (qName.equals("Protocol")) {
|
||||
protocol = currentOrNull();
|
||||
} else if (qName.equals("Enabled")) {
|
||||
enabled = Boolean.parseBoolean(currentOrNull());
|
||||
} else if (qName.equals("Timeout")) {
|
||||
timeout = Integer.parseInt(currentOrNull());
|
||||
} else if (qName.equals("Description")) {
|
||||
description = 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.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.Node;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class NodeHandler extends HandlerWithResult<Node> {
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
private StringBuilder currentText = new StringBuilder();
|
||||
|
||||
private int id;
|
||||
private URI location;
|
||||
private String serviceName;
|
||||
private InetAddress address;
|
||||
private int port;
|
||||
private String description;
|
||||
private boolean enabled;
|
||||
|
||||
protected String currentOrNull() {
|
||||
String returnVal = currentText.toString().trim();
|
||||
return returnVal.equals("") ? null : returnVal;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Node getResult() {
|
||||
return new Node(id, serviceName, location, address, port, enabled, description);
|
||||
}
|
||||
|
||||
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")) {
|
||||
serviceName = currentOrNull();
|
||||
} else if (qName.equals("Port")) {
|
||||
port = Integer.parseInt(currentOrNull());
|
||||
} else if (qName.equals("Enabled")) {
|
||||
enabled = Boolean.parseBoolean(currentOrNull());
|
||||
} else if (qName.equals("IpAddress")) {
|
||||
address = parseInetAddress(currentOrNull());
|
||||
} else if (qName.equals("Description")) {
|
||||
description = 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);
|
||||
}
|
||||
|
||||
}
|
|
@ -24,7 +24,9 @@
|
|||
package org.jclouds.vcloud.terremark.xml;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Map;
|
||||
import java.util.SortedSet;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
@ -33,10 +35,12 @@ import javax.inject.Inject;
|
|||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rest.domain.Link;
|
||||
import org.jclouds.rest.domain.NamedLink;
|
||||
import org.jclouds.rest.util.Utils;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.NamedResource;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.domain.internal.NamedResourceImpl;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.jclouds.vcloud.terremark.domain.ResourceAllocation;
|
||||
import org.jclouds.vcloud.terremark.domain.VApp;
|
||||
import org.jclouds.vcloud.terremark.domain.VirtualSystem;
|
||||
|
@ -67,7 +71,7 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
|
||||
private VirtualSystem system;
|
||||
private SortedSet<ResourceAllocation> allocations = Sets.newTreeSet();
|
||||
private NamedLink vApp;
|
||||
private NamedResource vApp;
|
||||
private Link vDC;
|
||||
private VAppStatus status;
|
||||
private int size;
|
||||
|
@ -79,10 +83,13 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
private String operatingSystemDescription;
|
||||
private boolean inOs;
|
||||
private String networkName;
|
||||
@Inject
|
||||
@VAppRoot
|
||||
private String vAppRoot;
|
||||
|
||||
public VApp getResult() {
|
||||
return new VAppImpl(vApp.getName(), vApp.getType(), vApp.getLocation(), status, size, vDC,
|
||||
computeOptions, customizationOptions, networkToAddresses,
|
||||
return new VAppImpl(vApp.getId(), vApp.getName(), vApp.getType(), vApp.getLocation(), status,
|
||||
size, vDC, computeOptions, customizationOptions, networkToAddresses,
|
||||
operatingSystemDescription, system, allocations);
|
||||
}
|
||||
|
||||
|
@ -104,7 +111,7 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
this.customizationOptions = Utils.newLink(attributes);
|
||||
}
|
||||
} else if (qName.equals("VApp")) {
|
||||
vApp = Utils.newNamedLink(attributes);
|
||||
vApp = newNamedResource(attributes);
|
||||
status = VAppStatus.fromValue(attributes.getValue(attributes.getIndex("status")));
|
||||
size = Integer.parseInt(attributes.getValue(attributes.getIndex("size")));
|
||||
} else if (qName.equals("OperatingSystemSection")) {
|
||||
|
@ -159,4 +166,15 @@ public class TerremarkVAppHandler extends ParseSax.HandlerWithResult<VApp> {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public NamedResource newNamedResource(Attributes attributes) {
|
||||
return new NamedResourceImpl(Integer.parseInt(attributes
|
||||
.getValue(attributes.getIndex("href")).replace(vAppRoot + "/", "")), attributes
|
||||
.getValue(attributes.getIndex("name")), attributes.getValue(attributes
|
||||
.getIndex("type")), URI.create(attributes.getValue(attributes.getIndex("href"))));
|
||||
}
|
||||
|
||||
public void putNamedResource(Map<String, NamedResource> map, Attributes attributes) {
|
||||
map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +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>{protocol}</Protocol>
|
||||
<Port>{port}</Port>
|
||||
<Enabled>{enabled}</Enabled>{description}
|
||||
</InternetService>
|
|
@ -0,0 +1,7 @@
|
|||
<NodeService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createNodeService">
|
||||
<IpAddress>{ipAddress}</IpAddress>
|
||||
<Name>{name}</Name>
|
||||
<Port>{port}</Port>
|
||||
<Enabled>{enabled}</Enabled>{description}
|
||||
</NodeService>
|
|
@ -86,7 +86,7 @@ public class VCloudClientLiveTest {
|
|||
assertNotNull(response.getLocation());
|
||||
assertNotNull(response.getTasks());
|
||||
for (Task t : response.getTasks()) {
|
||||
assertEquals(connection.getTask(t.getLocation()).get(10, TimeUnit.SECONDS).getLocation(),
|
||||
assertEquals(connection.getTask(t.getLocation()).get(30, TimeUnit.SECONDS).getLocation(),
|
||||
t.getLocation());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,8 +40,10 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.TasksList;
|
||||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.xml.CatalogHandler;
|
||||
import org.jclouds.vcloud.xml.TaskHandler;
|
||||
|
@ -108,12 +110,10 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("deploy", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("deployVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/action/deploy HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/deploy HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -125,12 +125,10 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("undeploy", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("undeployVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/action/undeploy HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/action/undeploy HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -142,12 +140,10 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("delete", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("deleteVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"DELETE https://services.vcloudexpress.terremark.com/vapp/1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/vapp/1 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -159,12 +155,10 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("powerOn", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("powerOnVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/power/action/powerOn HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/powerOn HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -176,12 +170,11 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("powerOff", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("powerOffVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/power/action/powerOff HTTP/1.1");
|
||||
"POST http://vcloud/vapp/1/power/action/powerOff HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -193,12 +186,10 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testReset() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("reset", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("resetVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/power/action/reset HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/reset HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -210,12 +201,10 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testSuspend() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("suspend", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("suspendVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/power/action/suspend HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/vapp/1/power/action/suspend HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -227,12 +216,11 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
}
|
||||
|
||||
public void testShutdown() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("shutdown", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/vapp/1"));
|
||||
Method method = VCloudClient.class.getMethod("shutdownVApp", int.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, 1);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/vapp/1/power/action/shutdown HTTP/1.1");
|
||||
"POST http://vcloud/vapp/1/power/action/shutdown HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -246,10 +234,9 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
public void testGetTask() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("getTask", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/task/1"));
|
||||
.create("http://vcloud/task/1"));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"GET https://services.vcloudexpress.terremark.com/task/1 HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/task/1 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.task+xml\n");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -263,10 +250,9 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = VCloudClient.class.getMethod("cancelTask", URI.class);
|
||||
GeneratedHttpRequest<VCloudClient> httpMethod = processor.createRequest(method, URI
|
||||
.create("https://services.vcloudexpress.terremark.com/task/1"));
|
||||
.create("http://vcloud/task/1"));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST https://services.vcloudexpress.terremark.com/task/1/action/cancel HTTP/1.1");
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/task/1/action/cancel HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
|
@ -297,9 +283,11 @@ public class VCloudClientTest extends RestClientTest<VCloudClient> {
|
|||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
||||
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
||||
.toInstance("http://catalogItem");
|
||||
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapps");
|
||||
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
||||
bind(URI.class).annotatedWith(TasksList.class).toInstance(
|
||||
URI.create("http://tasksList"));
|
||||
bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create("http://vcloud"));
|
||||
bind(SetVCloudTokenCookie.class).toInstance(
|
||||
new SetVCloudTokenCookie(new Provider<String>() {
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@ import static org.testng.Assert.assertEquals;
|
|||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
@ -45,7 +46,7 @@ import com.google.inject.Key;
|
|||
@Test(groups = "unit", testName = "vcloud.VCloudRestClientModuleTest")
|
||||
public class VCloudRestClientModuleTest extends VCloudDiscoveryRestClientModuleTest {
|
||||
|
||||
Injector createInjector() {
|
||||
protected Injector createInjector() {
|
||||
return Guice.createInjector(new VCloudRestClientModule(),
|
||||
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
|
||||
@Override
|
||||
|
@ -64,6 +65,8 @@ public class VCloudRestClientModuleTest extends VCloudDiscoveryRestClientModuleT
|
|||
void testCatalogItemRoot() {
|
||||
assertEquals(createInjector().getInstance(Key.get(String.class, CatalogItemRoot.class)),
|
||||
"http://localhost/catalogItem");
|
||||
assertEquals(createInjector().getInstance(Key.get(String.class, VAppRoot.class)),
|
||||
"http://localhost/vapp");
|
||||
}
|
||||
|
||||
}
|
|
@ -27,24 +27,39 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.jclouds.concurrent.WithinThreadExecutorService;
|
||||
import org.jclouds.concurrent.config.ExecutorServiceModule;
|
||||
import org.jclouds.http.HttpResponseException;
|
||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||
import org.jclouds.ssh.SshClient;
|
||||
import org.jclouds.ssh.SshClient.Factory;
|
||||
import org.jclouds.ssh.jsch.config.JschSshClientModule;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.VCloudClientLiveTest;
|
||||
import org.jclouds.vcloud.domain.Task;
|
||||
import org.jclouds.vcloud.domain.TaskStatus;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.terremark.domain.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.jclouds.vcloud.terremark.domain.ResourceType;
|
||||
import org.jclouds.vcloud.terremark.domain.TerremarkVDC;
|
||||
import org.jclouds.vcloud.terremark.domain.VApp;
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkVCloudClient}
|
||||
|
@ -55,6 +70,13 @@ import com.google.common.collect.Iterables;
|
|||
public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
||||
TerremarkVCloudClient tmClient;
|
||||
|
||||
private Factory sshFactory;
|
||||
|
||||
private InetAddress publicIp;
|
||||
private InternetService is;
|
||||
private Node node;
|
||||
private VApp vApp;
|
||||
|
||||
public static final String PREFIX = System.getProperty("user.name") + "-terremark";
|
||||
|
||||
@Test
|
||||
|
@ -68,17 +90,18 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testInstantiate() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
public void testInstantiateAndPowerOn() throws InterruptedException, ExecutionException,
|
||||
TimeoutException, IOException {
|
||||
String serverName = "adriantest";
|
||||
int processorCount = 1;
|
||||
int memory = 512;
|
||||
String catalogOs = "Ubuntu Server 9.04 (32-bit)";
|
||||
long hardDisk = 4194304;
|
||||
String catalogOs = "Ubuntu JeOS 9.04 (32-bit)";
|
||||
String expectedOs = "Ubuntu Linux (32-bit)";
|
||||
|
||||
int templateId = tmClient.getCatalog().get(45, TimeUnit.SECONDS).get(catalogOs).getId();
|
||||
|
||||
VApp vApp = tmClient.instantiateVAppTemplate(serverName, templateId)
|
||||
.get(45, TimeUnit.SECONDS);
|
||||
vApp = tmClient.instantiateVAppTemplate(serverName, templateId).get(45, TimeUnit.SECONDS);
|
||||
|
||||
assertEquals(vApp.getStatus(), VAppStatus.CREATING);
|
||||
|
||||
|
@ -87,14 +110,14 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
|
||||
// in terremark, this should be a no-op, as it should simply return the above task, which is
|
||||
// already deploying
|
||||
Task deployTask = tmClient.deploy(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
Task deployTask = tmClient.deployVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(deployTask.getLocation(), instantiateTask.getLocation());
|
||||
|
||||
// check to see the result of calling deploy twice
|
||||
deployTask = tmClient.deploy(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
deployTask = tmClient.deployVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(deployTask.getLocation(), instantiateTask.getLocation());
|
||||
|
||||
vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
vApp = tmClient.getVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.CREATING);
|
||||
|
||||
try {// per docs, this is not supported
|
||||
|
@ -106,49 +129,70 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
|
||||
deployTask = blockUntilSuccess(deployTask);
|
||||
|
||||
vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory);
|
||||
vApp = tmClient.getVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
verifyConfigurationOfVApp(vApp, serverName, expectedOs, processorCount, memory, hardDisk);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.OFF);
|
||||
|
||||
deployTask = blockUntilSuccess(tmClient.powerOnVApp(vApp.getId()).get(45, TimeUnit.SECONDS));
|
||||
vApp = tmClient.getVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddInternetService() throws InterruptedException, ExecutionException,
|
||||
TimeoutException, IOException {
|
||||
is = tmClient.addInternetService("SSH", "TCP", 22).get(45, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testInstantiateAndPowerOn", "testAddInternetService" })
|
||||
public void testPublicIp() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
IOException {
|
||||
node = tmClient.addNode(is.getId(), vApp.getNetworkToAddresses().values().iterator().next(),
|
||||
vApp.getName() + "-SSH", 22).get(45, TimeUnit.SECONDS);
|
||||
publicIp = is.getPublicIpAddress().getAddress();
|
||||
try {
|
||||
doCheckPass(publicIp);
|
||||
} catch (Exception e) {
|
||||
// TODO - harden this up, when we stop hanging
|
||||
System.err.printf("%s:22 -> %s:22%n%s%n", vApp.getNetworkToAddresses().values().iterator()
|
||||
.next(), publicIp, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = "testPublicIp")
|
||||
public void testLifeCycle() throws InterruptedException, ExecutionException, TimeoutException,
|
||||
IOException {
|
||||
|
||||
try {// per docs, this is not supported
|
||||
tmClient.undeploy(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS);
|
||||
tmClient.undeployVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException e) {
|
||||
assertEquals(e.getCause().getClass(), HttpResponseException.class);
|
||||
assertEquals(((HttpResponseException) e.getCause()).getResponse().getStatusCode(), 501);
|
||||
}
|
||||
|
||||
deployTask = blockUntilSuccess(tmClient.powerOn(deployTask.getResult().getLocation()).get(45,
|
||||
TimeUnit.SECONDS));
|
||||
vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||
|
||||
try {// per docs, this is not supported
|
||||
tmClient.suspend(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS);
|
||||
tmClient.suspendVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
} catch (ExecutionException e) {
|
||||
assertEquals(e.getCause().getClass(), HttpResponseException.class);
|
||||
assertEquals(((HttpResponseException) e.getCause()).getResponse().getStatusCode(), 501);
|
||||
}
|
||||
|
||||
deployTask = blockUntilSuccess(tmClient.reset(deployTask.getResult().getLocation()).get(45,
|
||||
TimeUnit.SECONDS));
|
||||
vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
blockUntilSuccess(tmClient.resetVApp(vApp.getId()).get(45, TimeUnit.SECONDS));
|
||||
vApp = tmClient.getVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||
|
||||
tmClient.shutdown(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS);
|
||||
vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
tmClient.shutdownVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
vApp = tmClient.getVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.ON);
|
||||
|
||||
deployTask = blockUntilSuccess(tmClient.powerOff(deployTask.getResult().getLocation()).get(
|
||||
45, TimeUnit.SECONDS));
|
||||
vApp = tmClient.getVApp(vApp.getLocation()).get(45, TimeUnit.SECONDS);
|
||||
blockUntilSuccess(tmClient.powerOffVApp(vApp.getId()).get(45, TimeUnit.SECONDS));
|
||||
vApp = tmClient.getVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
assertEquals(vApp.getStatus(), VAppStatus.OFF);
|
||||
|
||||
tmClient.delete(deployTask.getResult().getLocation()).get(45, TimeUnit.SECONDS);
|
||||
// TODO verify not present anymore
|
||||
}
|
||||
|
||||
private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs,
|
||||
int processorCount, int memory) {
|
||||
int processorCount, int memory, long hardDisk) {
|
||||
assertEquals(vApp.getName(), serverName);
|
||||
assertEquals(vApp.getOperatingSystemDescription(), expectedOs);
|
||||
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_CPU)
|
||||
|
@ -159,7 +203,7 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(),
|
||||
memory);
|
||||
assertEquals(vApp.getResourceAllocationByType().get(ResourceType.VIRTUAL_DISK)
|
||||
.getVirtualQuantity(), memory * 8192);
|
||||
.getVirtualQuantity(), hardDisk);
|
||||
assertEquals(vApp.getSize(), vApp.getResourceAllocationByType()
|
||||
.get(ResourceType.VIRTUAL_DISK).getVirtualQuantity());
|
||||
}
|
||||
|
@ -182,6 +226,35 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
.getTasksByOwner().get(owner));
|
||||
}
|
||||
|
||||
private void doCheckPass(InetAddress address) throws IOException {
|
||||
System.out.printf("%s:%s%n", address, 22);
|
||||
SshClient connection = sshFactory.create(new InetSocketAddress(address, 22), "vcloud",
|
||||
"p4ssw0rd");
|
||||
try {
|
||||
connection.connect();
|
||||
InputStream etcPasswd = connection.get("/etc/passwd");
|
||||
Utils.toStringAndClose(etcPasswd);
|
||||
} finally {
|
||||
if (connection != null)
|
||||
connection.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
@AfterTest
|
||||
void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
|
||||
if (node != null)
|
||||
tmClient.deleteNode(node.getId()).get(30, TimeUnit.SECONDS);
|
||||
if (is != null)
|
||||
tmClient.deleteInternetService(is.getId()).get(30, TimeUnit.SECONDS);
|
||||
if (vApp != null) {
|
||||
try {
|
||||
blockUntilSuccess(tmClient.powerOffVApp(vApp.getId()).get(45, TimeUnit.SECONDS));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
tmClient.deleteVApp(vApp.getId()).get(45, TimeUnit.SECONDS);
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeGroups(groups = { "live" })
|
||||
@Override
|
||||
public void setupClient() {
|
||||
|
@ -190,6 +263,10 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest {
|
|||
connection = tmClient = new TerremarkVCloudContextBuilder(
|
||||
new TerremarkVCloudPropertiesBuilder(account, key).build()).withModules(
|
||||
new Log4JLoggingModule()).buildContext().getApi();
|
||||
Injector injector = Guice.createInjector(new Log4JLoggingModule(), new JschSshClientModule(),
|
||||
new ExecutorServiceModule(new WithinThreadExecutorService()));
|
||||
sshFactory = injector.getInstance(SshClient.Factory.class);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,14 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.terremark;
|
||||
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
||||
import static org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions.Builder.cpuCount;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
@ -38,6 +39,7 @@ import javax.inject.Singleton;
|
|||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ReturnVoidIf2xx;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.logging.Logger.LoggerFactory;
|
||||
import org.jclouds.rest.RestClientTest;
|
||||
|
@ -46,10 +48,16 @@ import org.jclouds.rest.internal.RestAnnotationProcessor;
|
|||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.endpoints.Catalog;
|
||||
import org.jclouds.vcloud.endpoints.Network;
|
||||
import org.jclouds.vcloud.endpoints.VCloud;
|
||||
import org.jclouds.vcloud.endpoints.VDC;
|
||||
import org.jclouds.vcloud.endpoints.internal.CatalogItemRoot;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.jclouds.vcloud.filters.SetVCloudTokenCookie;
|
||||
import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions;
|
||||
import org.jclouds.vcloud.terremark.options.AddNodeOptions;
|
||||
import org.jclouds.vcloud.terremark.options.InstantiateVAppTemplateOptions;
|
||||
import org.jclouds.vcloud.terremark.xml.InternetServiceHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.NodeHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler;
|
||||
import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -126,6 +134,186 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudCli
|
|||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("addInternetService", String.class,
|
||||
String.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0)
|
||||
.getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method,
|
||||
"name", "tcp", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("addInternetService", String.class,
|
||||
String.class, int.class, Array.newInstance(AddInternetServiceOptions.class, 0)
|
||||
.getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method,
|
||||
"name", "tcp", 22, disabled().withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vdc/internetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("getInternetService", int.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testDeleteInternetService() throws SecurityException, NoSuchMethodException,
|
||||
IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("deleteInternetService", int.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetServiceToExistingIp() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("addInternetServiceToExistingIp",
|
||||
int.class, String.class, String.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12,
|
||||
"name", "tcp", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 303\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test2.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddInternetServiceToExistingIpOptions() throws SecurityException,
|
||||
NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("addInternetServiceToExistingIp",
|
||||
int.class, String.class, String.class, int.class, Array.newInstance(
|
||||
AddInternetServiceOptions.class, 0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12,
|
||||
"name", "tcp", 22, disabled().withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod,
|
||||
"POST http://vcloud/publicIps/12/InternetServices HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 341\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, InternetServiceHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("addNode", int.class,
|
||||
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
|
||||
0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12,
|
||||
InetAddress.getByName("10.2.2.2"), "name", 22);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 298\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-test2.xml")));
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("addNode", int.class,
|
||||
InetAddress.class, String.class, int.class, Array.newInstance(AddNodeOptions.class,
|
||||
0).getClass());
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12,
|
||||
InetAddress.getByName("10.2.2.2"), "name", 22, AddNodeOptions.Builder.disabled()
|
||||
.withDescription("yahoo"));
|
||||
|
||||
assertRequestLineEquals(httpMethod, "POST http://vcloud/internetServices/12/nodes HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "Content-Length: 336\nContent-Type: application/xml\n");
|
||||
assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-options-test.xml")));
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testGetNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("getNode", int.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ParseSax.class);
|
||||
assertSaxResponseParserClassEquals(method, NodeHandler.class);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = TerremarkVCloudClient.class.getMethod("deleteNode", int.class);
|
||||
GeneratedHttpRequest<TerremarkVCloudClient> httpMethod = processor.createRequest(method, 12);
|
||||
|
||||
assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1");
|
||||
assertHeadersEqual(httpMethod, "");
|
||||
assertEntityEquals(httpMethod, null);
|
||||
|
||||
assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(httpMethod);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(GeneratedHttpRequest<TerremarkVCloudClient> httpMethod) {
|
||||
assertEquals(httpMethod.getFilters().size(), 1);
|
||||
|
@ -146,6 +334,8 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudCli
|
|||
bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog"));
|
||||
bind(String.class).annotatedWith(CatalogItemRoot.class)
|
||||
.toInstance("http://catalogItem");
|
||||
bind(URI.class).annotatedWith(VCloud.class).toInstance(URI.create("http://vcloud"));
|
||||
bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp");
|
||||
bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc"));
|
||||
bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network"));
|
||||
bind(SetVCloudTokenCookie.class).toInstance(
|
||||
|
@ -169,9 +359,26 @@ public class TerremarkVCloudClientTest extends RestClientTest<TerremarkVCloudCli
|
|||
@Provides
|
||||
@Named("InstantiateVAppTemplateParams")
|
||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateInternetService")
|
||||
String provideCreateInternetService() throws IOException {
|
||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService.xml"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateNodeService")
|
||||
String provideCreateNodeService() throws IOException {
|
||||
return Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService.xml"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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.binders;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindAddInternetServiceToXmlEntity}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.BindAddInternetServiceToXmlEntityTest")
|
||||
public class BindAddInternetServiceToXmlEntityTest {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateInternetService")
|
||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/CreateInternetService.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
});
|
||||
|
||||
public void testApplyInputStream() throws IOException {
|
||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService-test.xml"));
|
||||
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||
BindAddInternetServiceToXmlEntity binder = injector
|
||||
.getInstance(BindAddInternetServiceToXmlEntity.class);
|
||||
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("name", "name");
|
||||
map.put("protocol", "TCP");
|
||||
map.put("port", "22");
|
||||
map.put("enabled", "true");
|
||||
map.put("description", "name TCP 22");
|
||||
binder.bindToRequest(request, map);
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "application/unknown");
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "346");
|
||||
assertEquals(request.getEntity(), expected);
|
||||
|
||||
}
|
||||
}
|
|
@ -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.binders;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
import javax.ws.rs.core.HttpHeaders;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code BindAddNodeServiceToXmlEntity}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.BindAddNodeServiceToXmlEntityTest")
|
||||
public class BindAddNodeServiceToXmlEntityTest {
|
||||
Injector injector = Guice.createInjector(new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Singleton
|
||||
@Provides
|
||||
@Named("CreateNodeService")
|
||||
String provideInstantiateVAppTemplateParams() throws IOException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/CreateNodeService.xml");
|
||||
return Utils.toStringAndClose(is);
|
||||
}
|
||||
});
|
||||
|
||||
public void testApplyInputStream() throws IOException {
|
||||
String expected = IOUtils.toString(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService-test.xml"));
|
||||
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
|
||||
BindAddNodeServiceToXmlEntity binder = injector
|
||||
.getInstance(BindAddNodeServiceToXmlEntity.class);
|
||||
|
||||
Map<String, String> map = Maps.newHashMap();
|
||||
map.put("name", "Node for Jim");
|
||||
map.put("ipAddress", "172.16.20.3");
|
||||
map.put("port", "80");
|
||||
map.put("enabled", "false");
|
||||
map.put("description", "Some test node");
|
||||
binder.bindToRequest(request, map);
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_TYPE), "application/unknown");
|
||||
assertEquals(request.getFirstHeaderOrNull(HttpHeaders.CONTENT_LENGTH), "356");
|
||||
assertEquals(request.getEntity(), expected);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
*
|
||||
* Copyright (C) 2009 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*/
|
||||
package org.jclouds.vcloud.terremark.config;
|
||||
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_ENDPOINT;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_KEY;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_SESSIONINTERVAL;
|
||||
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_USER;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.util.Jsr330;
|
||||
import org.jclouds.util.Utils;
|
||||
import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule;
|
||||
import org.jclouds.vcloud.config.VCloudRestClientModuleTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Key;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.TerremarkVCloudRestClientModuleTest")
|
||||
public class TerremarkVCloudRestClientModuleTest extends VCloudRestClientModuleTest {
|
||||
|
||||
@Override
|
||||
protected Injector createInjector() {
|
||||
return Guice.createInjector(new TerremarkVCloudRestClientModule(),
|
||||
new VCloudDiscoveryRestClientModule(), new ParserModule(), new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_USER)).to("user");
|
||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_KEY)).to("secret");
|
||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_ENDPOINT)).to(
|
||||
"http://localhost");
|
||||
bindConstant().annotatedWith(Jsr330.named(PROPERTY_VCLOUD_SESSIONINTERVAL))
|
||||
.to("2");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void postStrings() throws IOException {
|
||||
assertEquals(createInjector().getInstance(
|
||||
Key.get(String.class, Jsr330.named("InstantiateVAppTemplateParams"))), Utils
|
||||
.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/InstantiateVAppTemplateParams.xml")));
|
||||
assertEquals(createInjector().getInstance(
|
||||
Key.get(String.class, Jsr330.named("CreateInternetService"))), Utils
|
||||
.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateInternetService.xml")));
|
||||
assertEquals(createInjector().getInstance(
|
||||
Key.get(String.class, Jsr330.named("CreateNodeService"))),
|
||||
Utils.toStringAndClose(getClass().getResourceAsStream(
|
||||
"/terremark/CreateNodeService.xml")));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.jclouds.vcloud.terremark.options;
|
||||
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.disabled;
|
||||
import static org.jclouds.vcloud.terremark.options.AddInternetServiceOptions.Builder.withDescription;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CreateInternetServiceOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.CreateInternetServiceOptionsTest")
|
||||
public class AddInternetServiceOptionsTest {
|
||||
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
|
||||
@Test
|
||||
public void testWithDescription() {
|
||||
AddInternetServiceOptions options = new AddInternetServiceOptions();
|
||||
options.withDescription("yallo");
|
||||
assertEquals(options.description, "yallo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithDescriptionStatic() {
|
||||
AddInternetServiceOptions options = withDescription("yallo");
|
||||
assertEquals(options.description, "yallo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabled() {
|
||||
AddInternetServiceOptions options = new AddInternetServiceOptions();
|
||||
options.disabled();
|
||||
assertEquals(options.enabled, "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabledStatic() {
|
||||
AddInternetServiceOptions options = disabled();
|
||||
assertEquals(options.enabled, "false");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.jclouds.vcloud.terremark.options;
|
||||
|
||||
import static org.jclouds.vcloud.terremark.options.AddNodeOptions.Builder.disabled;
|
||||
import static org.jclouds.vcloud.terremark.options.AddNodeOptions.Builder.withDescription;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CreateNodeOptions}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.AddNodeOptionsTest")
|
||||
public class AddNodeOptionsTest {
|
||||
|
||||
Injector injector = Guice.createInjector(new ParserModule());
|
||||
|
||||
@Test
|
||||
public void testWithDescription() {
|
||||
AddNodeOptions options = new AddNodeOptions();
|
||||
options.withDescription("yallo");
|
||||
assertEquals(options.description, "yallo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithDescriptionStatic() {
|
||||
AddNodeOptions options = withDescription("yallo");
|
||||
assertEquals(options.description, "yallo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabled() {
|
||||
AddNodeOptions options = new AddNodeOptions();
|
||||
options.disabled();
|
||||
assertEquals(options.enabled, "false");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisabledStatic() {
|
||||
AddNodeOptions options = disabled();
|
||||
assertEquals(options.enabled, "false");
|
||||
}
|
||||
|
||||
}
|
|
@ -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.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.InternetService;
|
||||
import org.jclouds.vcloud.terremark.domain.PublicIpAddress;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code InternetServiceHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.InternetServiceHandlerTest")
|
||||
public class InternetServiceHandlerTest extends BaseHandlerTest {
|
||||
|
||||
@BeforeTest
|
||||
@Override
|
||||
protected void setUpInjector() {
|
||||
super.setUpInjector();
|
||||
}
|
||||
|
||||
public void test1() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/InternetService.xml");
|
||||
|
||||
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,
|
||||
"Some test service"));
|
||||
}
|
||||
|
||||
public void test2() throws UnknownHostException {
|
||||
InputStream is = getClass().getResourceAsStream("/terremark/InternetService2.xml");
|
||||
|
||||
InternetService result = (InternetService) factory.create(
|
||||
injector.getInstance(InternetServiceHandler.class)).parse(is);
|
||||
assertEquals(
|
||||
result,
|
||||
new InternetService(
|
||||
524,
|
||||
"IS_for_Jim2",
|
||||
URI
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524"),
|
||||
new PublicIpAddress(
|
||||
4208,
|
||||
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"));
|
||||
}
|
||||
}
|
|
@ -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.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.vcloud.terremark.domain.Node;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code NodeServiceHandler}
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "vcloud.NodeServiceHandlerTest")
|
||||
public class NodeHandlerTest extends BaseHandlerTest {
|
||||
|
||||
public void test1() throws UnknownHostException {
|
||||
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
|
||||
.create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"),
|
||||
InetAddress.getByName("172.16.20.3"), 80, false, "Some test node"));
|
||||
}
|
||||
}
|
|
@ -33,9 +33,12 @@ import java.net.UnknownHostException;
|
|||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.http.functions.BaseHandlerTest;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.config.ParserModule;
|
||||
import org.jclouds.rest.domain.internal.LinkImpl;
|
||||
import org.jclouds.vcloud.VCloudMediaType;
|
||||
import org.jclouds.vcloud.domain.VAppStatus;
|
||||
import org.jclouds.vcloud.endpoints.internal.VAppRoot;
|
||||
import org.jclouds.vcloud.terremark.domain.ResourceAllocation;
|
||||
import org.jclouds.vcloud.terremark.domain.ResourceType;
|
||||
import org.jclouds.vcloud.terremark.domain.VApp;
|
||||
|
@ -45,6 +48,9 @@ import org.testng.annotations.Test;
|
|||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableSortedSet;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Provides;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code TerremarkVAppHandler}
|
||||
|
@ -57,7 +63,21 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
|
|||
@BeforeTest
|
||||
@Override
|
||||
protected void setUpInjector() {
|
||||
super.setUpInjector();
|
||||
injector = Guice.createInjector(new ParserModule(), new AbstractModule() {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Provides
|
||||
@VAppRoot
|
||||
String provide() {
|
||||
return "https://services.vcloudexpress.terremark.com/api/v0.8/vapp";
|
||||
}
|
||||
|
||||
});
|
||||
factory = injector.getInstance(ParseSax.Factory.class);
|
||||
}
|
||||
|
||||
public void testApplyInputStream() {
|
||||
|
@ -65,6 +85,8 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
|
|||
|
||||
VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result.getId(), 13775);
|
||||
|
||||
assertEquals(result.getName(), "adriantest");
|
||||
assertEquals(result.getStatus(), VAppStatus.CREATING);
|
||||
|
||||
|
@ -83,6 +105,8 @@ public class TerremarkVAppHandlerTest extends BaseHandlerTest {
|
|||
|
||||
VApp result = (VApp) factory.create(injector.getInstance(TerremarkVAppHandler.class)).parse(
|
||||
is);
|
||||
assertEquals(result.getId(), 13850);
|
||||
|
||||
assertEquals(result.getName(), "adriantest1");
|
||||
assertEquals(result.getStatus(), VAppStatus.OFF);
|
||||
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
<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>
|
||||
<Port>22</Port>
|
||||
<Enabled>false</Enabled>
|
||||
<Description>yahoo</Description>
|
||||
</InternetService>
|
|
@ -0,0 +1,8 @@
|
|||
<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>
|
||||
<Port>22</Port>
|
||||
<Enabled>true</Enabled>
|
||||
<Description>name TCP 22</Description>
|
||||
</InternetService>
|
|
@ -0,0 +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>
|
||||
<Port>22</Port>
|
||||
<Enabled>true</Enabled>
|
||||
</InternetService>
|
|
@ -0,0 +1,8 @@
|
|||
<NodeService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createNodeService">
|
||||
<IpAddress>10.2.2.2</IpAddress>
|
||||
<Name>name</Name>
|
||||
<Port>22</Port>
|
||||
<Enabled>false</Enabled>
|
||||
<Description>yahoo</Description>
|
||||
</NodeService>
|
|
@ -0,0 +1,8 @@
|
|||
<NodeService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createNodeService">
|
||||
<IpAddress>172.16.20.3</IpAddress>
|
||||
<Name>Node for Jim</Name>
|
||||
<Port>80</Port>
|
||||
<Enabled>false</Enabled>
|
||||
<Description>Some test node</Description>
|
||||
</NodeService>
|
|
@ -0,0 +1,7 @@
|
|||
<NodeService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:tmrk:vCloudExpress-1.0:request:createNodeService">
|
||||
<IpAddress>10.2.2.2</IpAddress>
|
||||
<Name>name</Name>
|
||||
<Port>22</Port>
|
||||
<Enabled>true</Enabled>
|
||||
</NodeService>
|
|
@ -0,0 +1,16 @@
|
|||
<InternetService xmlns="urn:tmrk:vCloudExpress-1.0"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-Instance">
|
||||
<Id>523</Id>
|
||||
<Href i:nil="true" />
|
||||
<Name>IS_for_Jim</Name>
|
||||
<PublicIpAddress>
|
||||
<Id>4208</Id>
|
||||
<Href i:nil="true" />
|
||||
<Name>10.1.22.159</Name>
|
||||
</PublicIpAddress>
|
||||
<Port>80</Port>
|
||||
<Protocol>HTTP</Protocol>
|
||||
<Enabled>false</Enabled>
|
||||
<Timeout>1</Timeout>
|
||||
<Description>Some test service</Description>
|
||||
</InternetService>
|
|
@ -0,0 +1,17 @@
|
|||
<InternetService xmlns="urn:tmrk:vCloudExpress-1.0"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Id>524</Id>
|
||||
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524</Href>
|
||||
<Name>IS_for_Jim2</Name>
|
||||
<PublicIpAddress>
|
||||
<Id>4208</Id>
|
||||
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208
|
||||
</Href>
|
||||
<Name>10.1.22.159</Name>
|
||||
</PublicIpAddress>
|
||||
<Port>45</Port>
|
||||
<Protocol>HTTP</Protocol>
|
||||
<Enabled>false</Enabled>
|
||||
<Timeout>1</Timeout>
|
||||
<Description>Some test service</Description>
|
||||
</InternetService>
|
|
@ -0,0 +1,11 @@
|
|||
<NodeService xmlns="urn:tmrk:vCloudExpress-1.0"
|
||||
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<Id>242</Id>
|
||||
<Href>https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242
|
||||
</Href>
|
||||
<Name>Node for Jim</Name>
|
||||
<IpAddress>172.16.20.3</IpAddress>
|
||||
<Port>80</Port>
|
||||
<Enabled>false</Enabled>
|
||||
<Description>Some test node</Description>
|
||||
</NodeService>
|
|
@ -40,6 +40,12 @@
|
|||
<module>core</module>
|
||||
</modules>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-jsch</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>jclouds-core</artifactId>
|
||||
|
|
Loading…
Reference in New Issue