diff --git a/core/src/main/java/org/jclouds/compute/ComputeService.java b/core/src/main/java/org/jclouds/compute/ComputeService.java index 06693c2d09..5fc9055664 100644 --- a/core/src/main/java/org/jclouds/compute/ComputeService.java +++ b/core/src/main/java/org/jclouds/compute/ComputeService.java @@ -35,7 +35,11 @@ import org.jclouds.compute.domain.CreateServerResponse; public interface ComputeService { SortedSet listServers(); - CreateServerResponse createServer(String name, String profile, String image); + /** + * + * @see Image + */ + CreateServerResponse createServer(String name, Profile profile, Image image); Server getServerById(String id); diff --git a/core/src/main/java/org/jclouds/compute/Image.java b/core/src/main/java/org/jclouds/compute/Image.java new file mode 100644 index 0000000000..333b4e8478 --- /dev/null +++ b/core/src/main/java/org/jclouds/compute/Image.java @@ -0,0 +1,31 @@ +/** + * + * 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.compute; + +/** + * @author Adrian Cole + */ +public enum Image { + CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/compute/Profile.java b/core/src/main/java/org/jclouds/compute/Profile.java new file mode 100644 index 0000000000..10cad28427 --- /dev/null +++ b/core/src/main/java/org/jclouds/compute/Profile.java @@ -0,0 +1,31 @@ +/** + * + * 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.compute; + +/** + * @author Adrian Cole + */ +public enum Profile { + SMALLEST +} \ No newline at end of file diff --git a/core/src/main/java/org/jclouds/http/HttpUtils.java b/core/src/main/java/org/jclouds/http/HttpUtils.java index 4fb64f4e09..0e830e08a7 100644 --- a/core/src/main/java/org/jclouds/http/HttpUtils.java +++ b/core/src/main/java/org/jclouds/http/HttpUtils.java @@ -165,6 +165,9 @@ public class HttpUtils { if (uriPath.indexOf('@') != 1) { List parts = Lists.newArrayList(Splitter.on('@').split(uriPath)); String path = parts.remove(parts.size() - 1); + if (parts.size() == 2) { + parts = Lists.newArrayList(urlEncode(parts.get(0) + "@" + parts.get(1), '/', ':')); + } parts.add(urlEncode(path, '/', ':')); uriPath = Joiner.on('@').join(parts); } else { diff --git a/core/src/main/resources/compute.properties b/core/src/main/resources/compute.properties index 476806f214..ed9b2edb3a 100644 --- a/core/src/main/resources/compute.properties +++ b/core/src/main/resources/compute.properties @@ -1,2 +1,4 @@ rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder -rimuhosting.propertiesbuilder=org.jclouds.rimuhosting.miro.RimuHostingPropertiesBuilder \ No newline at end of file +rimuhosting.propertiesbuilder=org.jclouds.rimuhosting.miro.RimuHostingPropertiesBuilder +terremark.contextbuilder=org.jclouds.vcloud.terremark.TerremarkVCloudContextBuilder +terremark.propertiesbuilder=org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/util/HttpUtilsTest.java b/core/src/test/java/org/jclouds/util/HttpUtilsTest.java index 3182cdc2bc..be449d7dc9 100644 --- a/core/src/test/java/org/jclouds/util/HttpUtilsTest.java +++ b/core/src/test/java/org/jclouds/util/HttpUtilsTest.java @@ -67,6 +67,12 @@ public class HttpUtilsTest extends PerformanceTest { .create("blobstore://account:Base64==@azureblob/container-hyphen/prefix")); } + public void testTerremark() { + URI creds = HttpUtils.createUri("compute://user@domain:password@terremark"); + assertEquals(creds.getUserInfo(), "user@domain:password"); + assertEquals(creds, URI.create("compute://user%40domain:password@terremark")); + } + public void testCloudFiles() { URI creds = HttpUtils.createUri("blobstore://account:h3c@cloudfiles/container-hyphen/prefix"); assertEquals(creds, URI.create("blobstore://account:h3c@cloudfiles/container-hyphen/prefix")); diff --git a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java index 6bf7dacd20..3eb82ddbf6 100644 --- a/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java +++ b/rimuhosting/src/main/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeService.java @@ -23,6 +23,9 @@ */ package org.jclouds.rimuhosting.miro.servers; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Map; import java.util.SortedSet; import java.util.TreeSet; @@ -30,11 +33,15 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.compute.ComputeService; +import org.jclouds.compute.Image; +import org.jclouds.compute.Profile; import org.jclouds.compute.domain.CreateServerResponse; import org.jclouds.rimuhosting.miro.RimuHostingClient; import org.jclouds.rimuhosting.miro.domain.NewServerResponse; import org.jclouds.rimuhosting.miro.domain.Server; +import com.google.common.collect.ImmutableMap; + /** * @author Ivan Meredith */ @@ -47,9 +54,16 @@ public class RimuHostingComputeService implements ComputeService { this.rhClient = rhClient; } + private Map imageNameMap = ImmutableMap. builder().put( + Image.CENTOS_53, "centos53").put(Image.UMBUNTU_90, "ubuntu904").build(); + private Map profileNameMap = ImmutableMap. builder().put( + Profile.SMALLEST, "MIRO1B").build(); + @Override - public CreateServerResponse createServer(String name, String profile, String image) { - NewServerResponse serverResponse = rhClient.createInstance(name, image, profile); + public CreateServerResponse createServer(String name, Profile profile, Image image) { + NewServerResponse serverResponse = rhClient.createInstance(name, checkNotNull(imageNameMap + .get(image), "image not supported: " + image), checkNotNull(profileNameMap + .get(profile), "profile not supported: " + profile)); return new RimuHostingCreateServerResponse(serverResponse); } @@ -69,8 +83,8 @@ public class RimuHostingComputeService implements ComputeService { @Override public SortedSet getServerByName(String id) { SortedSet serverSet = new TreeSet(); - for(Server rhServer : rhClient.getInstanceList()){ - serverSet.add(new RimuHostingServer(rhServer, rhClient)); + for (Server rhServer : rhClient.getInstanceList()) { + serverSet.add(new RimuHostingServer(rhServer, rhClient)); } return serverSet; } diff --git a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java index 46d82c7e87..9165fe94b7 100755 --- a/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java +++ b/rimuhosting/src/test/java/org/jclouds/rimuhosting/miro/servers/RimuHostingComputeServiceLiveTest.java @@ -26,6 +26,8 @@ package org.jclouds.rimuhosting.miro.servers; import static com.google.common.base.Preconditions.checkNotNull; import static org.testng.Assert.assertNotNull; +import org.jclouds.compute.Image; +import org.jclouds.compute.Profile; import org.jclouds.compute.domain.CreateServerResponse; import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.rimuhosting.miro.RimuHostingClient; @@ -58,7 +60,8 @@ public class RimuHostingComputeServiceLiveTest { @Test public void testServerCreate() { - CreateServerResponse server = rhServerService.createServer("test.com", "MIRO1B", "lenny"); + CreateServerResponse server = rhServerService.createServer("test.com", Profile.SMALLEST, + Image.CENTOS_53); assertNotNull(rhClient.getInstance(Long.valueOf(server.getId()))); rhServerService.getServerById(server.getId()).destroy(); } diff --git a/tools/ant-plugin/build.xml b/tools/ant-plugin/build.xml index 05005a42cf..f449e790e6 100644 --- a/tools/ant-plugin/build.xml +++ b/tools/ant-plugin/build.xml @@ -23,17 +23,37 @@ ==================================================================== --> - - + + + + - + + + + - - - + + + + + + + + + + + + + + + + + + diff --git a/tools/ant-plugin/pom.xml b/tools/ant-plugin/pom.xml index 87183750e4..5aaaa1fe63 100644 --- a/tools/ant-plugin/pom.xml +++ b/tools/ant-plugin/pom.xml @@ -1,32 +1,27 @@ - + http://www.apache.org/licenses/LICENSE-2.0.html 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. + ==================================================================== + --> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 org.jclouds @@ -45,7 +40,12 @@ ${project.groupId} - jclouds-rimuhosting + jclouds-core + ${project.version} + + + ${project.groupId} + jclouds-jsch ${project.version} diff --git a/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java index 9f00ba4f8b..b0d0a08a55 100644 --- a/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java +++ b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/ComputeTask.java @@ -27,22 +27,44 @@ import java.io.IOException; import java.net.URI; import java.util.Map; import java.util.Properties; +import java.util.SortedSet; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeServiceFactory; +import org.jclouds.compute.Image; +import org.jclouds.compute.Profile; +import org.jclouds.compute.Server; +import org.jclouds.compute.domain.CreateServerResponse; import org.jclouds.http.HttpUtils; +import org.jclouds.tools.ant.logging.config.AntLoggingModule; import com.google.common.base.Function; import com.google.common.collect.MapMaker; import com.google.common.io.Resources; +import com.google.inject.Module; +import com.google.inject.Provider; /** * @author Ivan Meredith */ public class ComputeTask extends Task { private final Map computeMap; + private static Project project; + /** + * we don't have a reference to the project during the constructor, so we need to defer expansion + * with a Provider. + */ + private static Provider defaultModulesProvider = new Provider() { + + @Override + public Module[] get() { + return new Module[] { new AntLoggingModule(project) }; + } + + }; public ComputeTask() throws IOException { this(buildComputeMap(loadDefaultProperties())); @@ -60,7 +82,7 @@ public class ComputeTask extends Task { @Override public ComputeService apply(URI from) { - return new ComputeServiceFactory(props).create(from); + return new ComputeServiceFactory(props).create(from, defaultModulesProvider.get()); } }); @@ -71,17 +93,84 @@ public class ComputeTask extends Task { this.computeMap = computeMap; } - private final String ACTION_CREATE = "create"; + public static enum Action { + CREATE, LIST, DESTROY + } private String provider; private String action; private ServerElement serverElement; + /** + * @return the configured {@link ServerElement} element + */ + public final ServerElement createServer() { + if (getServer() == null) { + this.serverElement = new ServerElement(); + } + + return this.serverElement; + } + + public ServerElement getServer() { + return this.serverElement; + } + public void execute() throws BuildException { - if (ACTION_CREATE.equalsIgnoreCase(action)) { - ComputeService computeService = computeMap.get(HttpUtils.createUri(provider)); - log("hello"); - computeService.createServer("test.com", "MIRO1B", "lenny"); + ComputeTask.project = getProject(); + Action action = Action.valueOf(this.action.toUpperCase()); + ComputeService computeService = computeMap.get(HttpUtils.createUri(provider)); + switch (action) { + case CREATE: + case DESTROY: + if (serverElement != null) { + switch (action) { + case CREATE: + create(computeService); + break; + case DESTROY: + destroy(computeService); + break; + } + } else { + this.log("missing server element for action: " + action, Project.MSG_ERR); + } + break; + case LIST: + log("list"); + for (Server server : computeService.listServers()) { + log(String.format(" id=%s, name=%s", server.getId(), server.getName())); + } + break; + default: + this.log("bad action: " + action, Project.MSG_ERR); + } + } + + private void create(ComputeService computeService) { + log(String.format("create name: %s, profile: %s, image: %s", serverElement.getName(), + serverElement.getProfile(), serverElement.getImage())); + CreateServerResponse createdServer = computeService.createServer(serverElement.getName(), + Profile.valueOf(serverElement.getProfile().toUpperCase()), Image + .valueOf(serverElement.getImage().toUpperCase())); + log(String.format(" id=%s, name=%s, connection=%s://%s:%s@%s:%d", createdServer.getId(), + createdServer.getName(), createdServer.getLoginType().toString().toLowerCase(), + createdServer.getCredentials().account, createdServer.getCredentials().key, + createdServer.getPublicAddresses().first().getHostAddress(), createdServer + .getLoginPort())); + } + + private void destroy(ComputeService computeService) { + log(String.format("destroy name: %s", serverElement.getName())); + SortedSet serversThatMatch = computeService.getServerByName(serverElement.getName()); + if (serversThatMatch.size() > 0) { + for (Server server : serversThatMatch) { + log(String.format(" destroying id=%s, name=%s", server.getId(), server.getName())); + if (!server.destroy()) { + log(String.format(" could not destroy id=%s, name=%s", server.getId(), server + .getName()), Project.MSG_ERR); + } + } } } diff --git a/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/logging/AntLogger.java b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/logging/AntLogger.java new file mode 100644 index 0000000000..88ef145964 --- /dev/null +++ b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/logging/AntLogger.java @@ -0,0 +1,93 @@ +package org.jclouds.tools.ant.logging; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.tools.ant.Project; +import org.jclouds.logging.BaseLogger; +import org.jclouds.logging.Logger; + +/** + * {@link org.apache.tools.ant.Project} implementation of {@link Logger}. + * + * @author Adrian Cole + * + */ +public class AntLogger extends BaseLogger { + private final Project project; + private final String category; + + public static class AntLoggerFactory implements LoggerFactory { + private final Project project; + + public AntLoggerFactory(Project project) { + this.project = checkNotNull(project, "project"); + } + + public Logger getLogger(String category) { + return new AntLogger(project, category); + } + } + + public AntLogger(Project project, String category) { + this.project = checkNotNull(project, "project"); + this.category = category; + } + + @Override + protected void logTrace(String message) { + } + + public boolean isTraceEnabled() { + return false; + } + + @Override + protected void logDebug(String message) { + project.log(message, Project.MSG_DEBUG); + } + + public boolean isDebugEnabled() { + return true; + } + + @Override + protected void logInfo(String message) { + project.log(message); + } + + public boolean isInfoEnabled() { + return true; + } + + @Override + protected void logWarn(String message) { + project.log(message, Project.MSG_WARN); + } + + @Override + protected void logWarn(String message, Throwable e) { + project.log(message, e, Project.MSG_WARN); + } + + public boolean isWarnEnabled() { + return true; + } + + @Override + protected void logError(String message) { + project.log(message, Project.MSG_ERR); + } + + @Override + protected void logError(String message, Throwable e) { + project.log(message, e, Project.MSG_ERR); + } + + public boolean isErrorEnabled() { + return true; + } + + public String getCategory() { + return category; + } +} \ No newline at end of file diff --git a/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/logging/config/AntLoggingModule.java b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/logging/config/AntLoggingModule.java new file mode 100644 index 0000000000..679294b62b --- /dev/null +++ b/tools/ant-plugin/src/main/java/org/jclouds/tools/ant/logging/config/AntLoggingModule.java @@ -0,0 +1,28 @@ +package org.jclouds.tools.ant.logging.config; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.apache.tools.ant.Project; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.logging.config.LoggingModule; +import org.jclouds.tools.ant.logging.AntLogger; + +/** + * Configures logging of type {@link AntLogger} + * + * @author Adrian Cole + * + */ +public class AntLoggingModule extends LoggingModule { + + private final Project project; + + public AntLoggingModule(Project project) { + this.project = project; + } + + @Override + public LoggerFactory createLoggerFactory() { + return new AntLogger.AntLoggerFactory(checkNotNull(project, "project")); + } +} diff --git a/vcloud/core/src/test/java/org/jclouds/vcloud/predicates/TaskSuccess.java b/vcloud/core/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java similarity index 100% rename from vcloud/core/src/test/java/org/jclouds/vcloud/predicates/TaskSuccess.java rename to vcloud/core/src/main/java/org/jclouds/vcloud/predicates/TaskSuccess.java diff --git a/vcloud/core/src/test/resources/log4j.xml b/vcloud/core/src/test/resources/log4j.xml index bdfc2a8733..dad90a3d84 100755 --- a/vcloud/core/src/test/resources/log4j.xml +++ b/vcloud/core/src/test/resources/log4j.xml @@ -1,37 +1,35 @@ - + 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. + ==================================================================== + --> - + + debug="false"> @@ -48,37 +46,37 @@ - - - - + + + + - - + + + + + + + + + + + + - - - - - - - - - - @@ -94,70 +92,70 @@ - - - - - + + + + + - + - - - - - + - - + + + + + + - - + + - - - - + + + + - - + + - + - - + + - - - - - - - + + + + + + + \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java index a5024b5856..f08c6b5143 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClient.java @@ -27,6 +27,7 @@ import static org.jclouds.vcloud.VCloudMediaType.VAPP_XML; import static org.jclouds.vcloud.VCloudMediaType.VDC_XML; import java.net.InetAddress; +import java.util.SortedSet; import java.util.concurrent.Future; import javax.ws.rs.Consumes; @@ -57,7 +58,9 @@ import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; +import org.jclouds.vcloud.terremark.xml.InternetServicesHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; +import org.jclouds.vcloud.terremark.xml.NodesHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; @@ -98,6 +101,12 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @MapEntityParam("protocol") String protocol, @MapEntityParam("port") int port, AddInternetServiceOptions... options); + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VDC.class) + @Path("/internetServices") + @XMLResponseParser(InternetServicesHandler.class) + Future> getAllInternetServices(); + @POST @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/publicIps/{ipId}/InternetServices") @@ -133,6 +142,13 @@ public interface TerremarkVCloudAsyncClient extends VCloudAsyncClient { @MapEntityParam("name") String name, @MapEntityParam("port") int port, AddNodeOptions... options); + @GET + @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) + @Path("/internetServices/{internetServiceId}/nodes") + @XMLResponseParser(NodesHandler.class) + Future> getNodes( + @PathParam("internetServiceId") String internetServiceId); + @GET @Endpoint(org.jclouds.vcloud.endpoints.VCloudApi.class) @Path("/nodeServices/{nodeId}") diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java index e95c80f0b0..128077cd98 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudClient.java @@ -24,6 +24,7 @@ package org.jclouds.vcloud.terremark; import java.net.InetAddress; +import java.util.SortedSet; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; @@ -69,4 +70,8 @@ public interface TerremarkVCloudClient extends VCloudClient { @Override TerremarkVApp getVApp(String vAppId); + SortedSet getAllInternetServices(); + + SortedSet getNodes(String internetServiceId); + } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java similarity index 78% rename from vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java rename to vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java index abe566fcda..aa5c0f713d 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/VCloudComputeClient.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeClient.java @@ -21,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloud.terremark; +package org.jclouds.vcloud.terremark.compute; import static com.google.common.base.Preconditions.checkArgument; @@ -29,16 +29,18 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; import java.util.Map; +import java.util.SortedSet; import javax.annotation.Resource; import javax.inject.Inject; +import org.jclouds.compute.Image; import org.jclouds.logging.Logger; -import org.jclouds.ssh.ExecResponse; -import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.SshClient.Factory; import org.jclouds.vcloud.domain.Task; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.terremark.TerremarkVCloudClient; +import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.Node; import org.jclouds.vcloud.terremark.domain.TerremarkVApp; import org.jclouds.vcloud.terremark.options.TerremarkInstantiateVAppTemplateOptions; @@ -50,31 +52,22 @@ import com.google.common.collect.Iterables; * * @author Adrian Cole */ -public class VCloudComputeClient { +public class TerremarkVCloudComputeClient { @Resource protected Logger logger = Logger.NULL; - private final Predicate socketTester; private final Predicate taskTester; private final TerremarkVCloudClient tmClient; @Inject - public VCloudComputeClient(TerremarkVCloudClient tmClient, Factory sshFactory, - Predicate socketTester, Predicate successTester) { + public TerremarkVCloudComputeClient(TerremarkVCloudClient tmClient, Predicate successTester) { this.tmClient = tmClient; - this.sshFactory = sshFactory; - this.socketTester = socketTester; this.taskTester = successTester; } - private final Factory sshFactory; - - public enum Image { - CENTOS_53, RHEL_53, UMBUNTU_90, UMBUNTU_JEOS - } - private Map imageCatalogIdMap = ImmutableMap. builder().put( - Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put(Image.UMBUNTU_JEOS, "11").build(); + Image.CENTOS_53, "6").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put( + Image.UMBUNTU_JEOS, "11").build(); public String start(String name, int minCores, int minMegs, Image image) { checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); @@ -83,7 +76,8 @@ public class VCloudComputeClient { logger.debug(">> instantiating vApp name(%s) minCores(%d) minMegs(%d) template(%s)", name, minCores, minMegs, templateId); TerremarkVApp vApp = tmClient.instantiateVAppTemplate(name, templateId, - TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes(minMegs)); + TerremarkInstantiateVAppTemplateOptions.Builder.cpuCount(minCores) + .megabytes(minMegs)); logger.debug("<< instantiated VApp(%s)", vApp.getId()); logger.debug(">> deploying vApp(%s)", vApp.getId()); @@ -109,16 +103,6 @@ public class VCloudComputeClient { return Iterables.getLast(vApp.getNetworkToAddresses().values()); } - public ExecResponse exec(InetAddress address, String command) { - InetSocketAddress sshSocket = new InetSocketAddress(address, 22); - String username = "vcloud"; - String password = "p4ssw0rd"; - logger.debug(">> exec ssh://%s@%s/%s", username, sshSocket, command); - ExecResponse exec = exec(sshSocket, username, password, command); - logger.debug("<< output(%s) error(%s)", exec.getOutput(), exec.getError()); - return exec; - } - public void reboot(String id) { TerremarkVApp vApp = tmClient.getVApp(id); logger.debug(">> rebooting vApp(%s)", vApp.getId()); @@ -129,6 +113,24 @@ public class VCloudComputeClient { public void stop(String id) { TerremarkVApp vApp = tmClient.getVApp(id); + + SERVICE: for (InternetService service : tmClient.getAllInternetServices()) { + for (Node node : tmClient.getNodes(service.getId())) { + if (vApp.getNetworkToAddresses().containsValue(node.getIpAddress())) { + logger.debug(">> deleting Node(%s)", node.getId()); + tmClient.deleteNode(node.getId()); + logger.debug("<< deleted Node(%s)", node.getId()); + SortedSet nodes = tmClient.getNodes(service.getId()); + if (nodes.size() == 0) { + logger.debug(">> deleting InternetService(%s)", service.getId()); + tmClient.deleteInternetService(service.getId()); + logger.debug("<< deleted InternetService(%s)", service.getId()); + continue SERVICE; + } + } + } + } + if (vApp.getStatus() != VAppStatus.OFF) { logger.debug(">> powering off vApp(%s)", vApp.getId()); blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOffVApp(vApp.getId()), @@ -140,23 +142,8 @@ public class VCloudComputeClient { logger.debug("<< deleted vApp(%s)", vApp.getId()); } - private ExecResponse exec(InetSocketAddress socket, String username, String password, - String command) { - if (!socketTester.apply(socket)) { - throw new SocketNotOpenException(socket); - } - SshClient connection = sshFactory.create(socket, username, password); - try { - connection.connect(); - return connection.exec(command); - } finally { - if (connection != null) - connection.disconnect(); - } - } - - private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask, String taskType, - VAppStatus expectedStatus) { + private TerremarkVApp blockUntilVAppStatusOrThrowException(TerremarkVApp vApp, Task deployTask, + String taskType, VAppStatus expectedStatus) { if (!taskTester.apply(deployTask.getLocation())) { throw new TaskException(taskType, vApp, deployTask); } diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java new file mode 100644 index 0000000000..f65537cc6d --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudComputeService.java @@ -0,0 +1,125 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.compute; + +import java.net.InetAddress; +import java.util.SortedSet; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.compute.ComputeService; +import org.jclouds.compute.Image; +import org.jclouds.compute.Profile; +import org.jclouds.compute.Server; +import org.jclouds.compute.domain.CreateServerResponse; +import org.jclouds.compute.domain.LoginType; +import org.jclouds.compute.domain.internal.CreateServerResponseImpl; +import org.jclouds.domain.Credentials; +import org.jclouds.logging.Logger; +import org.jclouds.rest.domain.NamedResource; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.terremark.TerremarkVCloudClient; +import org.jclouds.vcloud.terremark.domain.InternetService; + +import com.google.common.base.Predicate; +import com.google.common.collect.Iterables; +import com.google.common.collect.Sets; +import com.google.inject.internal.ImmutableSet; + +/** + * @author Adrian Cole + */ +@Singleton +public class TerremarkVCloudComputeService implements ComputeService { + @Resource + protected Logger logger = Logger.NULL; + private final TerremarkVCloudComputeClient computeClient; + private final TerremarkVCloudClient tmClient; + + @Inject + public TerremarkVCloudComputeService(TerremarkVCloudClient tmClient, + TerremarkVCloudComputeClient computeClient) { + this.tmClient = tmClient; + this.computeClient = computeClient; + + } + + @Override + public CreateServerResponse createServer(String name, Profile profile, Image image) { + String id = computeClient.start(name, 1, 512, image); + VApp vApp = tmClient.getVApp(id); + Iterable privateAddresses = vApp.getNetworkToAddresses().values(); + + InetAddress sshIp = null; + InternetService is; + for (int port : new int[] { 22, 80, 8080 }) { + is = tmClient.addInternetService(id + "-" + port, "TCP", port); + tmClient.addNode(is.getId(), Iterables.getLast(privateAddresses), id + "-" + port, port); + if (port == 22) { + is.getPublicIpAddress().getAddress(); + } + } + return new CreateServerResponseImpl(id, vApp.getName(), ImmutableSet. of(sshIp), + privateAddresses, 22, LoginType.SSH, new Credentials("vcloud", "p4ssw0rd")); + } + + @Override + public Server getServerById(String id) { + return new TerremarkVCloudServer(computeClient, tmClient.getVApp(id)); + } + + public SortedSet getInternetServicesByName(final String name) { + return Sets.newTreeSet(Iterables.filter(tmClient.getAllInternetServices(), + new Predicate() { + @Override + public boolean apply(InternetService input) { + return input.getName().equalsIgnoreCase(name); + } + })); + } + + @Override + public SortedSet getServerByName(final String name) { + return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate() { + @Override + public boolean apply(Server input) { + return input.getName().equalsIgnoreCase(name); + } + })); + } + + @Override + public SortedSet listServers() { + SortedSet servers = Sets.newTreeSet(); + for (NamedResource resource : tmClient.getDefaultVDC().getResourceEntities().values()) { + if (resource.getType().equals(VCloudMediaType.VAPP_XML)) { + servers.add(getServerById(resource.getId())); + } + } + return servers; + } +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudServer.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudServer.java new file mode 100644 index 0000000000..700a6c2748 --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/compute/TerremarkVCloudServer.java @@ -0,0 +1,62 @@ +/** + * + * 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.compute; + +import org.jclouds.compute.Server; +import org.jclouds.vcloud.terremark.domain.TerremarkVApp; + +/** + * + * @author Adrian Cole + */ +public class TerremarkVCloudServer implements Server { + + private final TerremarkVCloudComputeClient computeClient; + + private final TerremarkVApp vApp; + + public TerremarkVCloudServer(TerremarkVCloudComputeClient computeClient, TerremarkVApp vApp) { + this.vApp = vApp; + this.computeClient = computeClient; + } + + public String getId() { + return vApp.getId(); + } + + public Boolean destroy() { + computeClient.stop(getId()); + return Boolean.TRUE; + } + + @Override + public String getName() { + return vApp.getName(); + } + + @Override + public int compareTo(Server o) { + return (this == o) ? 0 : getId().compareTo(o.getId()); + } +} diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudContextModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudContextModule.java index 0283e3b8e5..ea23703b94 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudContextModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudContextModule.java @@ -28,6 +28,7 @@ import java.net.URI; import javax.inject.Named; import javax.inject.Singleton; +import org.jclouds.compute.ComputeService; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; @@ -35,6 +36,7 @@ import org.jclouds.vcloud.endpoints.Org; import org.jclouds.vcloud.reference.VCloudConstants; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; +import org.jclouds.vcloud.terremark.compute.TerremarkVCloudComputeService; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -45,6 +47,7 @@ import com.google.inject.Provides; public class TerremarkVCloudContextModule extends AbstractModule { @Override protected void configure() { + bind(ComputeService.class).to(TerremarkVCloudComputeService.class); } @Provides diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java index 96056a0266..f8a39c5887 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/config/TerremarkVCloudRestClientModule.java @@ -25,21 +25,30 @@ package org.jclouds.vcloud.terremark.config; import java.io.IOException; import java.io.InputStream; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.net.URI; +import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.concurrent.internal.SyncProxy; import org.jclouds.http.RequiresHttp; +import org.jclouds.predicates.AddressReachable; +import org.jclouds.predicates.RetryablePredicate; +import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; import org.jclouds.util.Utils; import org.jclouds.vcloud.VCloudAsyncClient; import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.config.VCloudRestClientModule; +import org.jclouds.vcloud.predicates.TaskSuccess; import org.jclouds.vcloud.terremark.TerremarkVCloudAsyncClient; import org.jclouds.vcloud.terremark.TerremarkVCloudClient; +import com.google.common.base.Predicate; import com.google.inject.Provides; /** @@ -50,6 +59,26 @@ import com.google.inject.Provides; @RequiresHttp @ConfiguresRestClient public class TerremarkVCloudRestClientModule extends VCloudRestClientModule { + @Provides + @Singleton + protected Predicate socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 10, TimeUnit.SECONDS);// make it + // longer + // then + // default internet + } + + @Provides + @Singleton + protected Predicate addressTester(AddressReachable reachable) { + return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); + } + + @Provides + @Singleton + protected Predicate successTester(TaskSuccess success) { + return new RetryablePredicate(success, 300, 10, TimeUnit.SECONDS); + } @Provides @Singleton diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandler.java new file mode 100644 index 0000000000..297345283b --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandler.java @@ -0,0 +1,76 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import java.util.SortedSet; + +import javax.annotation.Resource; +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.terremark.domain.InternetService; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class InternetServicesHandler extends HandlerWithResult> { + + @Resource + protected Logger logger = Logger.NULL; + private final InternetServiceHandler handler; + SortedSet result = Sets.newTreeSet(); + + @Inject + public InternetServicesHandler(InternetServiceHandler handler) { + this.handler = handler; + } + + @Override + public SortedSet getResult() { + return result; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + handler.startElement(uri, localName, qName, attributes); + } + + public void endElement(String uri, String name, String qName) { + handler.endElement(uri, name, qName); + if (qName.equals("InternetService")) { + result.add(handler.getResult()); + } + } + + public void characters(char ch[], int start, int length) { + handler.characters(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodesHandler.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodesHandler.java new file mode 100644 index 0000000000..3c1e343e3a --- /dev/null +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/xml/NodesHandler.java @@ -0,0 +1,76 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import java.util.SortedSet; + +import javax.annotation.Resource; +import javax.inject.Inject; + +import org.jclouds.http.functions.ParseSax.HandlerWithResult; +import org.jclouds.logging.Logger; +import org.jclouds.vcloud.terremark.domain.Node; +import org.xml.sax.Attributes; +import org.xml.sax.SAXException; + +import com.google.common.collect.Sets; + +/** + * @author Adrian Cole + */ +public class NodesHandler extends HandlerWithResult> { + + @Resource + protected Logger logger = Logger.NULL; + private final NodeHandler handler; + SortedSet result = Sets.newTreeSet(); + + @Inject + public NodesHandler(NodeHandler handler) { + this.handler = handler; + } + + @Override + public SortedSet getResult() { + return result; + } + + @Override + public void startElement(String uri, String localName, String qName, Attributes attributes) + throws SAXException { + handler.startElement(uri, localName, qName, attributes); + } + + public void endElement(String uri, String name, String qName) { + handler.endElement(uri, name, qName); + if (qName.equals("NodeService")) { + result.add(handler.getResult()); + } + } + + public void characters(char ch[], int start, int length) { + handler.characters(ch, start, length); + } + +} \ No newline at end of file diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java index 822a0b4841..91ab40143b 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudAsyncClientTest.java @@ -64,7 +64,9 @@ import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; import org.jclouds.vcloud.terremark.options.AddInternetServiceOptions; import org.jclouds.vcloud.terremark.options.AddNodeOptions; import org.jclouds.vcloud.terremark.xml.InternetServiceHandler; +import org.jclouds.vcloud.terremark.xml.InternetServicesHandler; import org.jclouds.vcloud.terremark.xml.NodeHandler; +import org.jclouds.vcloud.terremark.xml.NodesHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVAppHandler; import org.jclouds.vcloud.terremark.xml.TerremarkVDCHandler; import org.testng.annotations.Test; @@ -81,400 +83,367 @@ import com.google.inject.util.Providers; * @author Adrian Cole */ @Test(groups = "unit", sequential = true, testName = "vcloud.TerremarkVCloudAsyncClientTest") -public class TerremarkVCloudAsyncClientTest extends - RestClientTest { +public class TerremarkVCloudAsyncClientTest extends RestClientTest { - public void testGetDefaultVDC() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class - .getMethod("getDefaultVDC"); - GeneratedHttpRequest httpMethod = processor - .createRequest(method); + public void testGetDefaultVDC() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("getDefaultVDC"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); - assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1"); - assertHeadersEqual(httpMethod, - "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); - assertEntityEquals(httpMethod, null); + assertRequestLineEquals(httpMethod, "GET http://vdc HTTP/1.1"); + assertHeadersEqual(httpMethod, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertEntityEquals(httpMethod, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkVDCHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testInstantiateVAppTemplate() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "instantiateVAppTemplate", String.class, String.class, Array - .newInstance(InstantiateVAppTemplateOptions.class, 0) - .getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, "name", 3 + ""); + public void testInstantiateVAppTemplate() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", + String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, + 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + "name", 3 + ""); - assertRequestLineEquals(httpMethod, - "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); - assertHeadersEqual( - httpMethod, - "Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); - assertEntityEquals(httpMethod, IOUtils.toString(getClass() - .getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams-test.xml"))); + assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); + assertHeadersEqual( + httpMethod, + "Content-Length: 2270\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream( + "/terremark/InstantiateVAppTemplateParams-test.xml"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testInstantiateVAppTemplateOptions() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "instantiateVAppTemplate", String.class, String.class, Array - .newInstance( - InstantiateVAppTemplateOptions.class, - 0).getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, "name", 3 + "", cpuCount(4).megabytes( - 1024).inNetwork(URI.create("http://newnet"))); + public void testInstantiateVAppTemplateOptions() throws SecurityException, + NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("instantiateVAppTemplate", + String.class, String.class, Array.newInstance(InstantiateVAppTemplateOptions.class, + 0).getClass()); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + "name", 3 + "", cpuCount(4).megabytes(1024).inNetwork(URI.create("http://newnet"))); - assertRequestLineEquals(httpMethod, - "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); - assertHeadersEqual( - httpMethod, - "Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); - assertEntityEquals( - httpMethod, - IOUtils - .toString(getClass() - .getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams-options-test.xml"))); + assertRequestLineEquals(httpMethod, "POST http://vdc/action/instantiatevAppTemplate HTTP/1.1"); + assertHeadersEqual( + httpMethod, + "Content-Length: 2239\nContent-Type: application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml\n"); + assertEntityEquals(httpMethod, IOUtils.toString(getClass().getResourceAsStream( + "/terremark/InstantiateVAppTemplateParams-options-test.xml"))); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, TerremarkVAppHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testAddInternetService() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "addInternetService", String.class, String.class, int.class, - Array.newInstance(AddInternetServiceOptions.class, 0) - .getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, "name", "tcp", 22); + public void testAddInternetService() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetService", + String.class, String.class, int.class, Array.newInstance( + AddInternetServiceOptions.class, 0).getClass()); + GeneratedHttpRequest 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"))); + 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); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testAddInternetServiceOptions() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.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")); + public void testAddInternetServiceOptions() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.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); + 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); - } + checkFilters(httpMethod); + } - public void testGetInternetService() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "getInternetService", String.class); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, 12); + public void testGetAllInternetServices() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("getAllInternetServices"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); - assertRequestLineEquals(httpMethod, - "GET http://vcloud/internetServices/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertEntityEquals(httpMethod, null); + assertRequestLineEquals(httpMethod, "GET http://vdc/internetServices HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, InternetServicesHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testDeleteInternetService() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "deleteInternetService", String.class); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, 12); + public void testGetInternetService() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.class + .getMethod("getInternetService", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); - assertRequestLineEquals(httpMethod, - "DELETE http://vcloud/internetServices/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertEntityEquals(httpMethod, null); + assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12 HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); - assertResponseParserClassEquals(method, httpMethod, - ReturnVoidIf2xx.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testAddInternetServiceToExistingIp() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "addInternetServiceToExistingIp", String.class, String.class, - String.class, int.class, Array.newInstance( - AddInternetServiceOptions.class, 0).getClass()); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, 12, "name", "tcp", 22); + public void testDeleteInternetService() throws SecurityException, NoSuchMethodException, + IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteInternetService", + String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); - 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"))); + assertRequestLineEquals(httpMethod, "DELETE http://vcloud/internetServices/12 HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - public void testAddInternetServiceToExistingIpOptions() - throws SecurityException, NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "addInternetServiceToExistingIp", String.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")); + public void testAddInternetServiceToExistingIp() throws SecurityException, + NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", + String.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: 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); + 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"))); - checkFilters(httpMethod); - } + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, InternetServiceHandler.class); + assertExceptionParserClassEquals(method, null); - public void testAddNode() throws SecurityException, NoSuchMethodException, - IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", - String.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); + checkFilters(httpMethod); + } - 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"))); + public void testAddInternetServiceToExistingIpOptions() throws SecurityException, + NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("addInternetServiceToExistingIp", + String.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")); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, NodeHandler.class); - assertExceptionParserClassEquals(method, null); + 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); - } + checkFilters(httpMethod); + } - public void testAddNodeOptions() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", - String.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")); + public void testAddNode() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.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: 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); + 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"))); - checkFilters(httpMethod); - } + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, NodeHandler.class); + assertExceptionParserClassEquals(method, null); - public void testGetNode() throws SecurityException, NoSuchMethodException, - IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", - String.class); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, 12); + checkFilters(httpMethod); + } - assertRequestLineEquals(httpMethod, - "GET http://vcloud/nodeServices/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertEntityEquals(httpMethod, null); + public void testAddNodeOptions() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("addNode", String.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")); - assertResponseParserClassEquals(method, httpMethod, ParseSax.class); - assertSaxResponseParserClassEquals(method, NodeHandler.class); - assertExceptionParserClassEquals(method, null); + 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); - } + checkFilters(httpMethod); + } - public void testDeleteNode() throws SecurityException, - NoSuchMethodException, IOException { - Method method = TerremarkVCloudAsyncClient.class.getMethod( - "deleteNode", String.class); - GeneratedHttpRequest httpMethod = processor - .createRequest(method, 12); + public void testGetNode() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("getNode", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); - assertRequestLineEquals(httpMethod, - "DELETE http://vcloud/nodeServices/12 HTTP/1.1"); - assertHeadersEqual(httpMethod, ""); - assertEntityEquals(httpMethod, null); + assertRequestLineEquals(httpMethod, "GET http://vcloud/nodeServices/12 HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); - assertResponseParserClassEquals(method, httpMethod, - ReturnVoidIf2xx.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, NodeHandler.class); + assertExceptionParserClassEquals(method, null); - checkFilters(httpMethod); - } + checkFilters(httpMethod); + } - @Override - protected void checkFilters( - GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), - SetVCloudTokenCookie.class); - } + public void testGetNodes() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("getNodes", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } + assertRequestLineEquals(httpMethod, "GET http://vcloud/internetServices/12/nodes HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP)) - .toProvider(Providers. of("group")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW)) - .toProvider(Providers. of("row")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD)) - .toProvider(Providers. of("password")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)) - .toProvider(Providers. of("1")); - bind(String.class).annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)) - .toProvider(Providers. of("512")); - bind(String.class) - .annotatedWith( - Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)) - .toProvider( - Providers - . of("https://vcloud.safesecureweb.com/network/1990")); - bind(URI.class).annotatedWith(Catalog.class).toInstance( - URI.create("http://catalog")); - bind(String.class).annotatedWith(CatalogItemRoot.class) - .toInstance("http://catalogItem"); - bind(URI.class).annotatedWith(VCloudApi.class).toInstance( - URI.create("http://vcloud")); - bind(String.class).annotatedWith(VAppRoot.class).toInstance( - "http://vapp"); - bind(URI.class).annotatedWith(VDC.class).toInstance( - URI.create("http://vdc")); - bind(URI.class).annotatedWith(Network.class).toInstance( - URI.create("http://network")); - bind(SetVCloudTokenCookie.class).toInstance( - new SetVCloudTokenCookie(new Provider() { + assertResponseParserClassEquals(method, httpMethod, ParseSax.class); + assertSaxResponseParserClassEquals(method, NodesHandler.class); + assertExceptionParserClassEquals(method, null); - public String get() { - return "token"; - } + checkFilters(httpMethod); + } - })); + public void testDeleteNode() throws SecurityException, NoSuchMethodException, IOException { + Method method = TerremarkVCloudAsyncClient.class.getMethod("deleteNode", String.class); + GeneratedHttpRequest httpMethod = processor.createRequest(method, + 12); - bind(Logger.LoggerFactory.class).toInstance( - new LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - } + assertRequestLineEquals(httpMethod, "DELETE http://vcloud/nodeServices/12 HTTP/1.1"); + assertHeadersEqual(httpMethod, ""); + assertEntityEquals(httpMethod, null); - @SuppressWarnings("unused") - @Singleton - @Provides - @Named("InstantiateVAppTemplateParams") - String provideInstantiateVAppTemplateParams() throws IOException { - return Utils.toStringAndClose(getClass().getResourceAsStream( - "/terremark/InstantiateVAppTemplateParams.xml")); - } + assertResponseParserClassEquals(method, httpMethod, ReturnVoidIf2xx.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); - @SuppressWarnings("unused") - @Singleton - @Provides - @Named("CreateInternetService") - String provideCreateInternetService() throws IOException { - return Utils.toStringAndClose(getClass().getResourceAsStream( - "/terremark/CreateInternetService.xml")); - } + checkFilters(httpMethod); + } - @SuppressWarnings("unused") - @Singleton - @Provides - @Named("CreateNodeService") - String provideCreateNodeService() throws IOException { - return Utils.toStringAndClose(getClass().getResourceAsStream( - "/terremark/CreateNodeService.xml")); - } - }; - } + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SetVCloudTokenCookie.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTGROUP)) + .toProvider(Providers. of("group")); + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTROW)) + .toProvider(Providers. of("row")); + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_TERREMARK_DEFAULTPASSWORD)) + .toProvider(Providers. of("password")); + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTCPUCOUNT)) + .toProvider(Providers. of("1")); + bind(String.class).annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTMEMORY)) + .toProvider(Providers. of("512")); + bind(String.class) + .annotatedWith(Jsr330.named(PROPERTY_VCLOUD_DEFAULTNETWORK)) + .toProvider( + Providers + . of("https://vcloud.safesecureweb.com/network/1990")); + bind(URI.class).annotatedWith(Catalog.class).toInstance(URI.create("http://catalog")); + bind(String.class).annotatedWith(CatalogItemRoot.class) + .toInstance("http://catalogItem"); + bind(URI.class).annotatedWith(VCloudApi.class).toInstance(URI.create("http://vcloud")); + bind(String.class).annotatedWith(VAppRoot.class).toInstance("http://vapp"); + bind(URI.class).annotatedWith(VDC.class).toInstance(URI.create("http://vdc")); + bind(URI.class).annotatedWith(Network.class).toInstance(URI.create("http://network")); + bind(SetVCloudTokenCookie.class).toInstance( + new SetVCloudTokenCookie(new Provider() { + + public String get() { + return "token"; + } + + })); + + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } + + @SuppressWarnings("unused") + @Singleton + @Provides + @Named("InstantiateVAppTemplateParams") + String provideInstantiateVAppTemplateParams() throws IOException { + return Utils.toStringAndClose(getClass().getResourceAsStream( + "/terremark/InstantiateVAppTemplateParams.xml")); + } + + @SuppressWarnings("unused") + @Singleton + @Provides + @Named("CreateInternetService") + String provideCreateInternetService() throws IOException { + return Utils.toStringAndClose(getClass().getResourceAsStream( + "/terremark/CreateInternetService.xml")); + } + + @SuppressWarnings("unused") + @Singleton + @Provides + @Named("CreateNodeService") + String provideCreateNodeService() throws IOException { + return Utils.toStringAndClose(getClass().getResourceAsStream( + "/terremark/CreateNodeService.xml")); + } + }; + } } diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java index 1c82db9b98..8341d82855 100644 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudClientLiveTest.java @@ -81,6 +81,13 @@ public class TerremarkVCloudClientLiveTest extends VCloudClientLiveTest { public static final String PREFIX = System.getProperty("user.name") + "-terremark"; + @Test + public void testGetAllInternetServices() throws Exception { + for (InternetService service : tmClient.getAllInternetServices()) { + System.out.println(tmClient.getNodes(service.getId())); + } + } + @Test public void testDefaultVDC() throws Exception { super.testDefaultVDC(); diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java deleted file mode 100644 index 09c2314f32..0000000000 --- a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/TerremarkVCloudComputeClientLiveTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - */ -package org.jclouds.vcloud.terremark; - -import static com.google.common.base.Preconditions.checkNotNull; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.InetAddress; -import java.net.InetSocketAddress; -import java.net.URI; -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; - -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.predicates.AddressReachable; -import org.jclouds.predicates.RetryablePredicate; -import org.jclouds.predicates.SocketOpen; -import org.jclouds.ssh.jsch.config.JschSshClientModule; -import org.jclouds.vcloud.domain.ResourceType; -import org.jclouds.vcloud.domain.VAppStatus; -import org.jclouds.vcloud.predicates.TaskSuccess; -import org.jclouds.vcloud.terremark.VCloudComputeClient.Image; -import org.jclouds.vcloud.terremark.domain.InternetService; -import org.jclouds.vcloud.terremark.domain.Node; -import org.jclouds.vcloud.terremark.domain.TerremarkVApp; -import org.testng.annotations.AfterTest; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.inject.AbstractModule; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; -import com.google.inject.internal.ImmutableMap; - -/** - * Tests behavior of {@code TerremarkVCloudClient} - * - * @author Adrian Cole - */ -@Test(groups = "live", sequential = true, testName = "vcloud.TerremarkVCloudClientLiveTest") -public class TerremarkVCloudComputeClientLiveTest { - VCloudComputeClient client; - TerremarkVCloudClient tmClient; - - private String id; - private InetAddress privateAddress; - - public static final String PREFIX = System.getProperty("user.name") + "-terremark"; - - private static class Expectation { - final long hardDisk; - final String os; - - public Expectation(long hardDisk, String os) { - this.hardDisk = hardDisk; - this.os = os; - } - } - - private Map expectationMap = ImmutableMap. builder() - .put(Image.CENTOS_53, - new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( - Image.RHEL_53, - new Expectation(4194304 / 4 * 10, "Red Hat Enterprise Linux 5 (64-bit)")).put( - Image.UMBUNTU_90, new Expectation(4194304, "Ubuntu Linux (64-bit)")).put( - Image.UMBUNTU_JEOS, new Expectation(4194304, "Ubuntu Linux (32-bit)")).build(); - - private InternetService is; - private Node node; - private InetAddress publicIp; - private Predicate addressTester; - - @Test - public void testPowerOn() throws InterruptedException, ExecutionException, TimeoutException, - IOException { - Image toTest = Image.CENTOS_53; - - String serverName = getCompatibleServerName(toTest); - int processorCount = 1; - int memory = 512; - - id = client.start(serverName, processorCount, memory, toTest); - Expectation expectation = expectationMap.get(toTest); - - TerremarkVApp vApp = tmClient.getVApp(id); - verifyConfigurationOfVApp(vApp, serverName, expectation.os, processorCount, memory, - expectation.hardDisk); - assertEquals(vApp.getStatus(), VAppStatus.ON); - } - - private String getCompatibleServerName(Image toTest) { - String serverName = toTest.toString().toLowerCase().replaceAll("_", "-").substring(0, - toTest.toString().length() <= 15 ? toTest.toString().length() : 14); - return serverName; - } - - @Test(dependsOnMethods = "testPowerOn") - public void testGetAnyPrivateAddress() { - privateAddress = client.getAnyPrivateAddress(id); - assert !addressTester.apply(privateAddress); - } - - @Test(dependsOnMethods = "testGetAnyPrivateAddress") - public void testSshLoadBalanceIp() { - is = tmClient.addInternetService("SSH", "TCP", 22); - node = tmClient.addNode(is.getId(), privateAddress, id + "-SSH", 22); - publicIp = is.getPublicIpAddress().getAddress(); - // assert addressTester.apply(publicIp); - client.exec(publicIp, "uname -a"); - } - - private void verifyConfigurationOfVApp(TerremarkVApp vApp, String serverName, String expectedOs, - int processorCount, int memory, long hardDisk) { - assertEquals(vApp.getName(), serverName); - assertEquals(vApp.getOperatingSystemDescription(), expectedOs); - assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR) - .getVirtualQuantity(), processorCount); - assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) - .getVirtualQuantity(), 1); - assertEquals( - vApp.getResourceAllocationByType().get(ResourceType.MEMORY).getVirtualQuantity(), - memory); - assertEquals(vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) - .getVirtualQuantity(), hardDisk); - assertEquals(vApp.getSize().longValue(), vApp.getResourceAllocationByType().get(ResourceType.DISK_DRIVE) - .getVirtualQuantity()); - } - - @AfterTest - void cleanup() throws InterruptedException, ExecutionException, TimeoutException { - if (node != null) - tmClient.deleteNode(node.getId()); - if (is != null) - tmClient.deleteInternetService(is.getId()); - if (id != null) - client.stop(id); - } - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - String account = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); - String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); - Injector injector = new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder( - account, key).relaxSSLHostname().build()).withModules(new Log4JLoggingModule(), - new JschSshClientModule(), new AbstractModule() { - - @Override - protected void configure() { - } - - @SuppressWarnings("unused") - @Provides - private Predicate socketTester(SocketOpen open) { - return new RetryablePredicate(open, 130, 10, - TimeUnit.SECONDS);// make it longer then - // default internet - } - - @SuppressWarnings("unused") - @Provides - private Predicate addressTester(AddressReachable reachable) { - return new RetryablePredicate(reachable, 60, 5, TimeUnit.SECONDS); - } - - @SuppressWarnings("unused") - @Provides - private Predicate successTester(TaskSuccess success) { - return new RetryablePredicate(success, 300, 10, TimeUnit.SECONDS); - } - - }).buildInjector(); - client = injector.getInstance(VCloudComputeClient.class); - tmClient = injector.getInstance(TerremarkVCloudClient.class); - addressTester = injector.getInstance(Key.get(new TypeLiteral>() { - })); - } - -} diff --git a/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java new file mode 100644 index 0000000000..9e8622af49 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/InternetServicesHandlerTest.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.SortedSet; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.InternetService; +import org.jclouds.vcloud.terremark.domain.PublicIpAddress; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; + +/** + * Tests behavior of {@code InternetServicesHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.InternetServicesHandlerTest") +public class InternetServicesHandlerTest extends BaseHandlerTest { + + public void test2() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/InternetServices.xml"); + + SortedSet result = factory.create( + injector.getInstance(InternetServicesHandler.class)).parse(is); + assertEquals( + result, + ImmutableSortedSet + .of(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/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java new file mode 100644 index 0000000000..171a56b6e1 --- /dev/null +++ b/vcloud/terremark/src/test/java/org/jclouds/vcloud/terremark/xml/NodesHandlerTest.java @@ -0,0 +1,56 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.vcloud.terremark.xml; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.InetAddress; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.SortedSet; + +import org.jclouds.http.functions.BaseHandlerTest; +import org.jclouds.vcloud.terremark.domain.Node; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; + +/** + * Tests behavior of {@code NodesHandler} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "vcloud.NodesHandlerTest") +public class NodesHandlerTest extends BaseHandlerTest { + + public void test1() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/terremark/NodeServices.xml"); + + SortedSet result = factory.create(injector.getInstance(NodesHandler.class)).parse(is); + assertEquals(result, ImmutableSortedSet.of(new Node(242 + "", "Node for Jim", URI + .create("https://services.vcloudexpress.terremark.com/api/v0.8/NodeServices/242"), + InetAddress.getByName("172.16.20.3"), 80, false, "Some test node"))); + } +} diff --git a/vcloud/terremark/src/test/resources/log4j.xml b/vcloud/terremark/src/test/resources/log4j.xml new file mode 100755 index 0000000000..6f8f078643 --- /dev/null +++ b/vcloud/terremark/src/test/resources/log4j.xml @@ -0,0 +1,163 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/vcloud/terremark/src/test/resources/terremark/InternetServices.xml b/vcloud/terremark/src/test/resources/terremark/InternetServices.xml new file mode 100644 index 0000000000..3c1019fa2f --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/InternetServices.xml @@ -0,0 +1,20 @@ + + + 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 + + diff --git a/vcloud/terremark/src/test/resources/terremark/NodeServices.xml b/vcloud/terremark/src/test/resources/terremark/NodeServices.xml new file mode 100644 index 0000000000..226066a1df --- /dev/null +++ b/vcloud/terremark/src/test/resources/terremark/NodeServices.xml @@ -0,0 +1,13 @@ + + + 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