From f9e58391342cf5da0dc50961248469ba3eebcc65 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Wed, 16 Dec 2009 03:49:13 +0000 Subject: [PATCH] Issue 112, Issue 129, Issue 130: add hosting.com to compute provider and ant tool git-svn-id: http://jclouds.googlecode.com/svn/trunk@2444 3d8758e0-26b5-11de-8745-db77d3ebf521 --- core/src/main/resources/compute.properties | 4 +- .../org/jclouds/domain/CredentialsTest.java | 9 +- .../java/org/jclouds/util/HttpUtilsTest.java | 6 + tools/ant-plugin/build.xml | 1 + .../HostingDotComVCloudContextBuilder.java | 4 +- .../HostingDotComVCloudContextFactory.java | 38 ++++++ .../HostingDotComVCloudComputeClient.java | 86 +++---------- .../HostingDotComVCloudComputeService.java | 114 ++++++++++++++++++ .../HostingDotComVCloudContextModule.java | 39 ++++++ .../HostingDotComVCloudRestClientModule.java | 31 ++++- ...tingDotComVCloudComputeClientLiveTest.java | 58 ++------- .../TerremarkVCloudContextFactory.java | 18 +-- 12 files changed, 270 insertions(+), 138 deletions(-) create mode 100644 vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextFactory.java rename vcloud/hostingdotcom/src/{test/java/org/jclouds/vcloud/hostingdotcom => main/java/org/jclouds/vcloud/hostingdotcom/compute}/HostingDotComVCloudComputeClient.java (69%) create mode 100644 vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java create mode 100644 vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudContextModule.java rename vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/{ => compute}/HostingDotComVCloudComputeClientLiveTest.java (73%) diff --git a/core/src/main/resources/compute.properties b/core/src/main/resources/compute.properties index ed9b2edb3a..61c17ba48a 100644 --- a/core/src/main/resources/compute.properties +++ b/core/src/main/resources/compute.properties @@ -1,4 +1,6 @@ rimuhosting.contextbuilder=org.jclouds.rimuhosting.miro.RimuHostingContextBuilder 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 +terremark.propertiesbuilder=org.jclouds.vcloud.terremark.TerremarkVCloudPropertiesBuilder +hostingdotcom.contextbuilder=org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudContextBuilder +hostingdotcom.propertiesbuilder=org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudPropertiesBuilder \ No newline at end of file diff --git a/core/src/test/java/org/jclouds/domain/CredentialsTest.java b/core/src/test/java/org/jclouds/domain/CredentialsTest.java index aa856de7ab..e457b6b1e0 100644 --- a/core/src/test/java/org/jclouds/domain/CredentialsTest.java +++ b/core/src/test/java/org/jclouds/domain/CredentialsTest.java @@ -41,7 +41,7 @@ public class CredentialsTest { assertEquals(creds.account, "account"); assertEquals(creds.key, "Base64=="); } - + public void testAtmos() { Credentials creds = Credentials.parse(URI .create("blobstore://domain%2Fuser:Base64%3D%3D@azureblob/container-hyphen/prefix")); @@ -49,6 +49,13 @@ public class CredentialsTest { assertEquals(creds.key, "Base64=="); } + public void testHosting() { + Credentials creds = Credentials.parse(URI + .create("compute://user%40domain:pa%24sword@hostingdotcom")); + assertEquals(creds.account, "user@domain"); + assertEquals(creds.key, "pa$sword"); + } + public void testCloudFiles() { Credentials creds = Credentials.parse(URI .create("blobstore://account:h3c@cloudfiles/container-hyphen/prefix")); diff --git a/core/src/test/java/org/jclouds/util/HttpUtilsTest.java b/core/src/test/java/org/jclouds/util/HttpUtilsTest.java index abcf7414c0..40839b39e5 100644 --- a/core/src/test/java/org/jclouds/util/HttpUtilsTest.java +++ b/core/src/test/java/org/jclouds/util/HttpUtilsTest.java @@ -64,6 +64,12 @@ public class HttpUtilsTest extends PerformanceTest { .create("blobstore://account:Base64==@azureblob/container-hyphen/prefix")); } + public void testHosting() { + URI creds = HttpUtils.createUri("compute://user@domain:pa$sword@hostingdotcom"); + assertEquals(creds.getUserInfo(), "user@domain:pa$sword"); + assertEquals(creds, URI.create("compute://user%40domain:pa%24sword@hostingdotcom")); + } + public void testTerremark() { URI creds = HttpUtils.createUri("compute://user@domain:password@terremark"); assertEquals(creds.getUserInfo(), "user@domain:password"); diff --git a/tools/ant-plugin/build.xml b/tools/ant-plugin/build.xml index 41c314d068..8dd5eca41f 100644 --- a/tools/ant-plugin/build.xml +++ b/tools/ant-plugin/build.xml @@ -30,6 +30,7 @@ + diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java index b11c495abe..e7016a3013 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextBuilder.java @@ -32,8 +32,8 @@ import org.jclouds.logging.jdk.config.JDKLoggingModule; import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContextBuilder; import org.jclouds.vcloud.VCloudAsyncClient; -import org.jclouds.vcloud.config.VCloudContextModule; import org.jclouds.vcloud.config.VCloudDiscoveryRestClientModule; +import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudContextModule; import org.jclouds.vcloud.hostingdotcom.config.HostingDotComVCloudRestClientModule; import com.google.inject.Module; @@ -70,7 +70,7 @@ public class HostingDotComVCloudContextBuilder extends @Override protected void addContextModule(List modules) { - modules.add(new VCloudContextModule()); + modules.add(new HostingDotComVCloudContextModule()); } @Override diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextFactory.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextFactory.java new file mode 100644 index 0000000000..416e988fc5 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudContextFactory.java @@ -0,0 +1,38 @@ +package org.jclouds.vcloud.hostingdotcom; + +import java.util.Properties; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rest.RestContext; + +import com.google.inject.Module; + +/** + * Creates {@link HostingDotComVCloudContext} instances based on the most commonly requested + * arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see HostingDotComVCloudContext + */ +public class HostingDotComVCloudContextFactory { + + public static RestContext createContext( + String username, String password, Module... modules) { + return new HostingDotComVCloudContextBuilder(new HostingDotComVCloudPropertiesBuilder( + username, password).build()).withModules(modules).buildContext(); + } + + public static RestContext createContext( + Properties props, Module... modules) { + return new HostingDotComVCloudContextBuilder(new HostingDotComVCloudPropertiesBuilder(props) + .build()).withModules(modules).buildContext(); + } + +} \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClient.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java similarity index 69% rename from vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClient.java rename to vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java index a613903a54..830bb0608d 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClient.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClient.java @@ -21,25 +21,23 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloud.hostingdotcom; +package org.jclouds.vcloud.hostingdotcom.compute; import static com.google.common.base.Preconditions.checkArgument; import java.net.InetAddress; -import java.net.InetSocketAddress; import java.net.URI; import java.util.Map; import javax.annotation.Resource; import javax.inject.Inject; +import org.jclouds.compute.domain.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.VApp; import org.jclouds.vcloud.domain.VAppStatus; +import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; import org.jclouds.vcloud.hostingdotcom.domain.HostingDotComVApp; import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; @@ -55,34 +53,21 @@ public class HostingDotComVCloudComputeClient { @Resource protected Logger logger = Logger.NULL; - private final Predicate socketTester; private final Predicate taskTester; private final HostingDotComVCloudClient tmClient; @Inject - public HostingDotComVCloudComputeClient(HostingDotComVCloudClient tmClient, Factory sshFactory, - Predicate socketTester, Predicate successTester) { + public HostingDotComVCloudComputeClient(HostingDotComVCloudClient 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, "3").put(Image.RHEL_53, "8").put(Image.UMBUNTU_90, "10").put( Image.UMBUNTU_JEOS, "11").build(); - private String username; - - private String password; - - public String start(String name, int minCores, int minMegs, Image image) { + public Map start(String name, int minCores, int minMegs, Image image) { checkArgument(imageCatalogIdMap.containsKey(image), "image not configured: " + image); String templateId = imageCatalogIdMap.get(image); @@ -91,23 +76,22 @@ public class HostingDotComVCloudComputeClient { HostingDotComVApp vAppResponse = (HostingDotComVApp) tmClient.instantiateVAppTemplate(name, templateId, InstantiateVAppTemplateOptions.Builder.cpuCount(minCores).megabytes( minMegs)); - this.username = vAppResponse.getUsername(); - this.password = vAppResponse.getPassword(); logger.debug("<< instantiated VApp(%s)", vAppResponse.getId()); logger.debug(">> deploying vApp(%s)", vAppResponse.getId()); VApp vApp = blockUntilVAppStatusOrThrowException(vAppResponse, tmClient .deployVApp(vAppResponse.getId()), "deploy", VAppStatus.ON);// TODO, I'm not sure - // this should be on - // already -// logger.debug("<< deployed vApp(%s)", vApp.getId()); -// -// logger.debug(">> powering vApp(%s)", vApp.getId()); -// vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()), -// "powerOn", VAppStatus.ON); + // this should be on + // already + // logger.debug("<< deployed vApp(%s)", vApp.getId()); + // + // logger.debug(">> powering vApp(%s)", vApp.getId()); + // vApp = blockUntilVAppStatusOrThrowException(vApp, tmClient.powerOnVApp(vApp.getId()), + // "powerOn", VAppStatus.ON); logger.debug("<< on vApp(%s)", vApp.getId()); - return vApp.getId(); + return ImmutableMap. of("id", vApp.getId(), "username", vAppResponse + .getUsername(), "password", vAppResponse.getPassword()); } /** @@ -120,14 +104,6 @@ public class HostingDotComVCloudComputeClient { return Iterables.getLast(vApp.getNetworkToAddresses().values()); } - public ExecResponse exec(InetAddress address, String command) { - InetSocketAddress sshSocket = new InetSocketAddress(address, 22); - 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) { VApp vApp = tmClient.getVApp(id); logger.debug(">> rebooting vApp(%s)", vApp.getId()); @@ -149,21 +125,6 @@ public class HostingDotComVCloudComputeClient { 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 VApp blockUntilVAppStatusOrThrowException(VApp vApp, Task deployTask, String taskType, VAppStatus expectedStatus) { if (!taskTester.apply(deployTask.getLocation())) { @@ -196,23 +157,6 @@ public class HostingDotComVCloudComputeClient { } - public static class SocketNotOpenException extends RuntimeException { - - private final InetSocketAddress socket; - /** The serialVersionUID */ - private static final long serialVersionUID = 251801929573211256L; - - public SocketNotOpenException(InetSocketAddress socket) { - super("socket not open: " + socket); - this.socket = socket; - } - - public InetSocketAddress getSocket() { - return socket; - } - - } - public static class VAppException extends RuntimeException { private final VApp vApp; diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java new file mode 100644 index 0000000000..236f0e04d4 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeService.java @@ -0,0 +1,114 @@ +/** + * + * 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.hostingdotcom.compute; + +import java.net.InetAddress; +import java.util.Map; +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.domain.CreateServerResponse; +import org.jclouds.compute.domain.Image; +import org.jclouds.compute.domain.LoginType; +import org.jclouds.compute.domain.Profile; +import org.jclouds.compute.domain.ServerIdentity; +import org.jclouds.compute.domain.ServerMetadata; +import org.jclouds.compute.domain.internal.CreateServerResponseImpl; +import org.jclouds.compute.domain.internal.ServerMetadataImpl; +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.hostingdotcom.HostingDotComVCloudClient; + +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 HostingDotComVCloudComputeService implements ComputeService { + @Resource + protected Logger logger = Logger.NULL; + private final HostingDotComVCloudComputeClient computeClient; + private final HostingDotComVCloudClient tmClient; + + @Inject + public HostingDotComVCloudComputeService(HostingDotComVCloudClient tmClient, + HostingDotComVCloudComputeClient computeClient) { + this.tmClient = tmClient; + this.computeClient = computeClient; + + } + + @Override + public CreateServerResponse createServer(String name, Profile profile, Image image) { + Map metaMap = computeClient.start(name, 1, 512, image); + VApp vApp = tmClient.getVApp(metaMap.get("id")); + return new CreateServerResponseImpl(vApp.getId(), vApp.getName(), vApp + .getNetworkToAddresses().values(), ImmutableSet. of(), 22, + LoginType.SSH, new Credentials(metaMap.get("username"), metaMap.get("password"))); + } + + @Override + public ServerMetadata getServerMetadata(String id) { + VApp vApp = tmClient.getVApp(id); + return new ServerMetadataImpl(vApp.getId(), vApp.getName(), vApp.getNetworkToAddresses() + .values(), ImmutableSet. of(), 22, LoginType.SSH); + } + + @Override + public SortedSet getServerByName(final String name) { + return Sets.newTreeSet(Iterables.filter(listServers(), new Predicate() { + @Override + public boolean apply(ServerIdentity 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(getServerMetadata(resource.getId())); + } + } + return servers; + } + + @Override + public void destroyServer(String id) { + computeClient.stop(id); + } +} \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudContextModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudContextModule.java new file mode 100644 index 0000000000..ce0de0bce8 --- /dev/null +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudContextModule.java @@ -0,0 +1,39 @@ +package org.jclouds.vcloud.hostingdotcom.config; + +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; +import org.jclouds.vcloud.endpoints.Org; +import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient; +import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; +import org.jclouds.vcloud.hostingdotcom.compute.HostingDotComVCloudComputeService; +import org.jclouds.vcloud.reference.VCloudConstants; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * @author Adrian Cole + */ +public class HostingDotComVCloudContextModule extends AbstractModule { + @Override + protected void configure() { + bind(ComputeService.class).to(HostingDotComVCloudComputeService.class); + } + + @Provides + @Singleton + RestContext provideContext(Closer closer, + HostingDotComVCloudAsyncClient asynchApi, HostingDotComVCloudClient defaultApi, + @Org URI endPoint, @Named(VCloudConstants.PROPERTY_VCLOUD_USER) String account) { + return new RestContextImpl(closer, + asynchApi, defaultApi, endPoint, account); + } + +} \ No newline at end of file diff --git a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java index 697eeef7dc..eff972e5a0 100644 --- a/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java +++ b/vcloud/hostingdotcom/src/main/java/org/jclouds/vcloud/hostingdotcom/config/HostingDotComVCloudRestClientModule.java @@ -23,12 +23,18 @@ */ package org.jclouds.vcloud.hostingdotcom.config; +import java.net.InetAddress; +import java.net.InetSocketAddress; import java.net.URI; +import java.util.concurrent.TimeUnit; 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.vcloud.VCloudAsyncClient; @@ -36,7 +42,9 @@ import org.jclouds.vcloud.VCloudClient; import org.jclouds.vcloud.config.VCloudRestClientModule; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudAsyncClient; import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; +import org.jclouds.vcloud.predicates.TaskSuccess; +import com.google.common.base.Predicate; import com.google.inject.Provides; /** @@ -49,7 +57,26 @@ import com.google.inject.Provides; public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule { @Provides @Singleton - protected HostingDotComVCloudAsyncClient provideHostingDotComVCloudAsyncClient(VCloudAsyncClient in) { + protected Predicate socketTester(SocketOpen open) { + return new RetryablePredicate(open, 130, 10, TimeUnit.SECONDS); + } + + @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, 600, 10, TimeUnit.SECONDS); + } + + @Provides + @Singleton + protected HostingDotComVCloudAsyncClient provideHostingDotComVCloudAsyncClient( + VCloudAsyncClient in) { return (HostingDotComVCloudAsyncClient) in; } @@ -69,7 +96,7 @@ public class HostingDotComVCloudRestClientModule extends VCloudRestClientModule SecurityException, NoSuchMethodException { return SyncProxy.create(HostingDotComVCloudClient.class, client); } - + @Override protected URI provideDefaultNetwork(VCloudAsyncClient client) { return URI.create("https://vcloud.safesecureweb.com/network/1990"); diff --git a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClientLiveTest.java b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java similarity index 73% rename from vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClientLiveTest.java rename to vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java index 3f1cbd3b6a..73297c22a2 100644 --- a/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/HostingDotComVCloudComputeClientLiveTest.java +++ b/vcloud/hostingdotcom/src/test/java/org/jclouds/vcloud/hostingdotcom/compute/HostingDotComVCloudComputeClientLiveTest.java @@ -21,39 +21,33 @@ * under the License. * ==================================================================== */ -package org.jclouds.vcloud.hostingdotcom; +package org.jclouds.vcloud.hostingdotcom.compute; 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.compute.domain.Image; 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.VApp; import org.jclouds.vcloud.domain.VAppStatus; -import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudComputeClient.Image; -import org.jclouds.vcloud.predicates.TaskSuccess; +import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudClient; +import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudContextBuilder; +import org.jclouds.vcloud.hostingdotcom.HostingDotComVCloudPropertiesBuilder; 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; @@ -101,7 +95,7 @@ public class HostingDotComVCloudComputeClientLiveTest { int processorCount = 1; int memory = 512; - id = client.start(serverName, processorCount, memory, toTest); + id = client.start(serverName, processorCount, memory, toTest).get("id"); Expectation expectation = expectationMap.get(toTest); VApp vApp = tmClient.getVApp(id); @@ -122,16 +116,10 @@ public class HostingDotComVCloudComputeClientLiveTest { assert !addressTester.apply(privateAddress); } - @Test(dependsOnMethods = "testGetAnyPrivateAddress") - public void testSshLoadBalanceIp() { - // assert addressTester.apply(publicIp); - client.exec(privateAddress, "uname -a"); - } - private void verifyConfigurationOfVApp(VApp vApp, String serverName, String expectedOs, int processorCount, int memory, long hardDisk) { -// assertEquals(vApp.getName(), serverName); -// assertEquals(vApp.getOperatingSystemDescription(), expectedOs); + // assertEquals(vApp.getName(), serverName); + // assertEquals(vApp.getOperatingSystemDescription(), expectedOs); assertEquals(vApp.getResourceAllocationByType().get(ResourceType.PROCESSOR) .getVirtualQuantity(), processorCount); assertEquals(vApp.getResourceAllocationByType().get(ResourceType.SCSI_CONTROLLER) @@ -156,35 +144,7 @@ public class HostingDotComVCloudComputeClientLiveTest { String key = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); Injector injector = new HostingDotComVCloudContextBuilder( new HostingDotComVCloudPropertiesBuilder(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, 5400, 10, TimeUnit.SECONDS); - } - - }).buildInjector(); + .withModules(new Log4JLoggingModule(), new JschSshClientModule()).buildInjector(); client = injector.getInstance(HostingDotComVCloudComputeClient.class); tmClient = injector.getInstance(HostingDotComVCloudClient.class); addressTester = injector.getInstance(Key.get(new TypeLiteral>() { diff --git a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudContextFactory.java b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudContextFactory.java index 95d6b70291..21f2d84b40 100644 --- a/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudContextFactory.java +++ b/vcloud/terremark/src/main/java/org/jclouds/vcloud/terremark/TerremarkVCloudContextFactory.java @@ -1,6 +1,5 @@ package org.jclouds.vcloud.terremark; -import java.net.URI; import java.util.Properties; import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; @@ -23,19 +22,14 @@ import com.google.inject.Module; */ public class TerremarkVCloudContextFactory { - public static RestContext createContext(String username, String password, - Module... modules) { - return new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(username, password).build()) - .withModules(modules).buildContext(); + public static RestContext createContext( + String username, String password, Module... modules) { + return new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(username, + password).build()).withModules(modules).buildContext(); } - public static RestContext createContext(URI endpoint, String username, - String password, Module... modules) { - return new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(username, password).withEndpoint( - endpoint).build()).withModules(modules).buildContext(); - } - - public static RestContext createContext(Properties props, Module... modules) { + public static RestContext createContext( + Properties props, Module... modules) { return new TerremarkVCloudContextBuilder(new TerremarkVCloudPropertiesBuilder(props).build()) .withModules(modules).buildContext(); }