diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java index 382d937f63..e49147e0c2 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/EC2Client.java @@ -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. diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/AllocateAddressResponseHandler.java b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/AllocateAddressResponseHandler.java index e137f9c4a3..eacf7122eb 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/xml/AllocateAddressResponseHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/ec2/xml/AllocateAddressResponseHandler.java @@ -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 { @Resource diff --git a/aws/core/src/main/java/org/jclouds/aws/ec2/functions/InetAddressToHostAddress.java b/core/src/main/java/org/jclouds/rest/functions/InetAddressToHostAddress.java similarity index 97% rename from aws/core/src/main/java/org/jclouds/aws/ec2/functions/InetAddressToHostAddress.java rename to core/src/main/java/org/jclouds/rest/functions/InetAddressToHostAddress.java index 5311f229c0..38e6d4cbc9 100644 --- a/aws/core/src/main/java/org/jclouds/aws/ec2/functions/InetAddressToHostAddress.java +++ b/core/src/main/java/org/jclouds/rest/functions/InetAddressToHostAddress.java @@ -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; diff --git a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java index eec4ee11ff..332dfc7a84 100644 --- a/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java +++ b/extensions/ssh/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java @@ -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); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java index 6f6a658d43..69b99b8494 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/VCloudClient.java @@ -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 deploy(@Endpoint URI vApp); + Future deployVApp(@PathParam("vAppId") int vAppId); @DELETE - Future delete(@Endpoint URI vApp); + @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Path("/vapp/{vAppId}") + Future 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 undeploy(@Endpoint URI vApp); + Future 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 powerOn(@Endpoint URI vApp); + Future 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 powerOff(@Endpoint URI vApp); + Future powerOffVApp(@PathParam("vAppId") int vAppId); /** * This call shuts down the vApp. */ @POST - @Path("/power/action/shutdown") - Future shutdown(@Endpoint URI vApp); + @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Path("/vapp/{vAppId}/power/action/shutdown") + Future 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 reset(@Endpoint URI vApp); + Future 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 suspend(@Endpoint URI vApp); + Future 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 getVApp(@Endpoint URI vApp); + Future getVApp(@PathParam("vAppId") int vAppId); } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java index fab0d5ae58..ec44c97a01 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/config/VCloudRestClientModule.java @@ -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 diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/internal/VAppRoot.java b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/internal/VAppRoot.java new file mode 100644 index 0000000000..ca0cdcfe5b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/endpoints/internal/VAppRoot.java @@ -0,0 +1,44 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.endpoints.internal; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Root path where all vApps exist. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.TYPE, ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface VAppRoot { + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java new file mode 100644 index 0000000000..a272de0595 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/functions/VAppIdToUri.java @@ -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 { + @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); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index 5f8987d606..00d60604cd 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -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 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 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 deleteInternetService(@PathParam("internetServiceId") int internetServiceId); + + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Path("/internetServices/{internetServiceId}") + @XMLResponseParser(InternetServiceHandler.class) + Future 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 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 getNode(@PathParam("nodeId") int nodeId); + + @DELETE + @Endpoint(org.jclouds.vcloud.endpoints.VCloud.class) + @Path("/nodeServices/{nodeId}") + Future deleteNode(@PathParam("nodeId") int nodeId); + } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlEntity.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlEntity.java new file mode 100644 index 0000000000..d7b4b0bb90 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddInternetServiceToXmlEntity.java @@ -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 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 %s", description)); + + stringBinder.bindToRequest(request, entity); + } + + public void bindToRequest(HttpRequest request, Object input) { + throw new IllegalStateException("CreateInternetService needs parameters"); + + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddNodeServiceToXmlEntity.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddNodeServiceToXmlEntity.java new file mode 100644 index 0000000000..1b4ff1c6ee --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/binders/BindAddNodeServiceToXmlEntity.java @@ -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 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 %s", description)); + + stringBinder.bindToRequest(request, entity); + } + + public void bindToRequest(HttpRequest request, Object input) { + throw new IllegalStateException("CreateNodeService needs parameters"); + + } + +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java index 6c7e856ccc..118f54003b 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java @@ -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")); + } } diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java new file mode 100644 index 0000000000..0086a8796e --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/InternetService.java @@ -0,0 +1,174 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.domain; + +import java.net.URI; + +/** + * @author Adrian Cole + */ +public class InternetService implements Comparable { + 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 + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java new file mode 100644 index 0000000000..1696bd92ca --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/Node.java @@ -0,0 +1,146 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.domain; + +import java.net.InetAddress; +import java.net.URI; + +/** + * @author Adrian Cole + */ +public class Node implements Comparable { + 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; + } +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/PublicIpAddress.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/PublicIpAddress.java new file mode 100644 index 0000000000..56e021785f --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/PublicIpAddress.java @@ -0,0 +1,109 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.domain; + +import java.net.InetAddress; +import java.net.URI; + +/** + * @author Adrian Cole + */ +public class PublicIpAddress implements Comparable { + 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 + "]"; + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java index d8acea370a..fc138b5bad 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/VApp.java @@ -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(); diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java index 2e7ccb88c2..44c90ce8d2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/domain/internal/VAppImpl.java @@ -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 networkToAddresses, String operatingSystemDescription, VirtualSystem system, SortedSet resourceAllocations) { - super(name, type, location); + super(id, name, type, location); this.status = status; this.size = size; this.vDC = vDC; diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java new file mode 100644 index 0000000000..9e4e7ce61b --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptions.java @@ -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 postParams) { + Map 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(); + } + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/options/AddNodeOptions.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/options/AddNodeOptions.java new file mode 100644 index 0000000000..ef288f14ad --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/options/AddNodeOptions.java @@ -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 postParams) { + Map 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(); + } + } +} diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java new file mode 100644 index 0000000000..5b2b6d64e6 --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandler.java @@ -0,0 +1,135 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 { + + @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); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java new file mode 100644 index 0000000000..500bcfddba --- /dev/null +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/NodeHandler.java @@ -0,0 +1,100 @@ +/** + * + * Copyright (C) 2009 Global Cloud Specialists, Inc. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.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 { + + @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); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java index 8698cabcc5..c96c22cce2 100644 --- a/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java +++ b/vcloud/core/src/main/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandler.java @@ -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 { private VirtualSystem system; private SortedSet 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 { 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 { 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 { } 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 map, Attributes attributes) { + map.put(attributes.getValue(attributes.getIndex("name")), newNamedResource(attributes)); + } } diff --git a/vcloud/core/src/main/resources/terremark/CreateInternetService.xml b/vcloud/core/src/main/resources/terremark/CreateInternetService.xml new file mode 100644 index 0000000000..96a367108c --- /dev/null +++ b/vcloud/core/src/main/resources/terremark/CreateInternetService.xml @@ -0,0 +1,7 @@ + + {name} + {protocol} + {port} + {enabled}{description} + \ No newline at end of file diff --git a/vcloud/core/src/main/resources/terremark/CreateNodeService.xml b/vcloud/core/src/main/resources/terremark/CreateNodeService.xml new file mode 100644 index 0000000000..a241d7dd31 --- /dev/null +++ b/vcloud/core/src/main/resources/terremark/CreateNodeService.xml @@ -0,0 +1,7 @@ + + {ipAddress} + {name} + {port} + {enabled}{description} + \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java index 66a7534dbf..4637844cd7 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientLiveTest.java @@ -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()); } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java index 56e9633c53..351a748f53 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/VCloudClientTest.java @@ -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 { } public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("deploy", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("deployVApp", int.class); + GeneratedHttpRequest 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 { } public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("undeploy", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("undeployVApp", int.class); + GeneratedHttpRequest 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 { } public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("delete", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("deleteVApp", int.class); + GeneratedHttpRequest 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 { } public void testPowerOn() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("powerOn", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("powerOnVApp", int.class); + GeneratedHttpRequest 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 { } public void testPowerOff() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("powerOff", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("powerOffVApp", int.class); + GeneratedHttpRequest 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 { } public void testReset() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("reset", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("resetVApp", int.class); + GeneratedHttpRequest 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 { } public void testSuspend() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("suspend", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("suspendVApp", int.class); + GeneratedHttpRequest 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 { } public void testShutdown() throws SecurityException, NoSuchMethodException, IOException { - Method method = VCloudClient.class.getMethod("shutdown", URI.class); - GeneratedHttpRequest httpMethod = processor.createRequest(method, URI - .create("https://services.vcloudexpress.terremark.com/vapp/1")); + Method method = VCloudClient.class.getMethod("shutdownVApp", int.class); + GeneratedHttpRequest 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 { public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudClient.class.getMethod("getTask", URI.class); GeneratedHttpRequest 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 { public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { Method method = VCloudClient.class.getMethod("cancelTask", URI.class); GeneratedHttpRequest 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 { 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() { diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java index 37ee845052..a42bb63b26 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/config/VCloudRestClientModuleTest.java @@ -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"); } } \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index bc80503271..ac7c19a931 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -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); + } } diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java index a6c0f3f6ef..cd6d36678a 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientTest.java @@ -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 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 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 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 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 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 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 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 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 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 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 httpMethod) { assertEquals(httpMethod.getFilters().size(), 1); @@ -146,6 +334,8 @@ public class TerremarkVCloudClientTest extends RestClientTest + * + * ==================================================================== + * 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 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); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddNodeServiceToXmlEntityTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddNodeServiceToXmlEntityTest.java new file mode 100644 index 0000000000..19655967a1 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/binders/BindAddNodeServiceToXmlEntityTest.java @@ -0,0 +1,90 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious,"LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License,"Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS,"WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND,"either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.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 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); + + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java new file mode 100644 index 0000000000..bd58d48a32 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModuleTest.java @@ -0,0 +1,84 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.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"))); + } + +} \ No newline at end of file diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptionsTest.java new file mode 100644 index 0000000000..ee48726c9b --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/options/AddInternetServiceOptionsTest.java @@ -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"); + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/options/AddNodeOptionsTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/options/AddNodeOptionsTest.java new file mode 100644 index 0000000000..0d0ffb0d4b --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/options/AddNodeOptionsTest.java @@ -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"); + } + +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java new file mode 100644 index 0000000000..5eec2d5102 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServiceHandlerTest.java @@ -0,0 +1,82 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.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")); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java new file mode 100644 index 0000000000..072ffca053 --- /dev/null +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/NodeHandlerTest.java @@ -0,0 +1,54 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.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")); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java index f99924eb6e..2d56f5e5f6 100644 --- a/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java +++ b/vcloud/core/src/test/java/org/jclouds/vcloud/terremark/xml/TerremarkVAppHandlerTest.java @@ -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); diff --git a/vcloud/core/src/test/resources/terremark/CreateInternetService-options-test.xml b/vcloud/core/src/test/resources/terremark/CreateInternetService-options-test.xml new file mode 100644 index 0000000000..3b2c9b4b07 --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/CreateInternetService-options-test.xml @@ -0,0 +1,8 @@ + + name + tcp + 22 + false + yahoo + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/CreateInternetService-test.xml b/vcloud/core/src/test/resources/terremark/CreateInternetService-test.xml new file mode 100644 index 0000000000..74e1419733 --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/CreateInternetService-test.xml @@ -0,0 +1,8 @@ + + name + TCP + 22 + true + name TCP 22 + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/CreateInternetService-test2.xml b/vcloud/core/src/test/resources/terremark/CreateInternetService-test2.xml new file mode 100644 index 0000000000..f88f8f6815 --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/CreateInternetService-test2.xml @@ -0,0 +1,7 @@ + + name + tcp + 22 + true + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/CreateNodeService-options-test.xml b/vcloud/core/src/test/resources/terremark/CreateNodeService-options-test.xml new file mode 100644 index 0000000000..038a07d59b --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/CreateNodeService-options-test.xml @@ -0,0 +1,8 @@ + + 10.2.2.2 + name + 22 + false + yahoo + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/CreateNodeService-test.xml b/vcloud/core/src/test/resources/terremark/CreateNodeService-test.xml new file mode 100644 index 0000000000..71eb80ce56 --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/CreateNodeService-test.xml @@ -0,0 +1,8 @@ + + 172.16.20.3 + Node for Jim + 80 + false + Some test node + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/CreateNodeService-test2.xml b/vcloud/core/src/test/resources/terremark/CreateNodeService-test2.xml new file mode 100644 index 0000000000..4c4eead99c --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/CreateNodeService-test2.xml @@ -0,0 +1,7 @@ + + 10.2.2.2 + name + 22 + true + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/InternetService.xml b/vcloud/core/src/test/resources/terremark/InternetService.xml new file mode 100644 index 0000000000..5290b6aa1a --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/InternetService.xml @@ -0,0 +1,16 @@ + + 523 + + IS_for_Jim + + 4208 + + 10.1.22.159 + + 80 + HTTP + false + 1 + Some test service + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/InternetService2.xml b/vcloud/core/src/test/resources/terremark/InternetService2.xml new file mode 100644 index 0000000000..c92bd343cc --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/InternetService2.xml @@ -0,0 +1,17 @@ + + 524 + https://services.vcloudexpress.terremark.com/api/v0.8/InternetServices/524 + IS_for_Jim2 + + 4208 + https://services.vcloudexpress.terremark.com/api/v0.8/PublicIps/4208 + + 10.1.22.159 + + 45 + HTTP + false + 1 + Some test service + \ No newline at end of file diff --git a/vcloud/core/src/test/resources/terremark/NodeService.xml b/vcloud/core/src/test/resources/terremark/NodeService.xml new file mode 100644 index 0000000000..49ac89a6cf --- /dev/null +++ b/vcloud/core/src/test/resources/terremark/NodeService.xml @@ -0,0 +1,11 @@ + + 242 + https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242 + + Node for Jim + 172.16.20.3 + 80 + false + Some test node + \ No newline at end of file diff --git a/vcloud/pom.xml b/vcloud/pom.xml index c8ef0bbd58..e71dc585ec 100755 --- a/vcloud/pom.xml +++ b/vcloud/pom.xml @@ -40,6 +40,12 @@ core + + ${project.groupId} + jclouds-jsch + ${project.version} + test + ${project.groupId} jclouds-core