From 381851b8abcc9d1bdb74fd0816e818d43308f4e6 Mon Sep 17 00:00:00 2001 From: Matt Stephenson Date: Wed, 25 Apr 2012 16:28:04 -0700 Subject: [PATCH] Remove IPSocket class, replace with Guava's HostAndPort class. --- .../BaseCloudLoadBalancersClientLiveTest.java | 4 +- .../CloudServersClientLiveTest.java | 10 +-- .../cloudsigma/CloudSigmaClientLiveTest.java | 12 +-- .../cloudstack/CloudStackClientLiveTest.java | 6 +- ...oudStackComputeServiceAdapterLiveTest.java | 6 +- .../BaseCloudStackClientLiveTest.java | 8 +- .../features/FirewallClientLiveTest.java | 4 +- .../features/LoadBalancerClientLiveTest.java | 10 +-- .../features/SecurityGroupClientLiveTest.java | 4 +- .../VirtualMachineClientLiveTest.java | 4 +- ...ticNATVirtualMachineInNetworkLiveTest.java | 4 +- .../deltacloud/DeltacloudClientLiveTest.java | 6 +- .../ReadOnlyDeltacloudClientLiveTest.java | 8 +- ...icationArchitecturesEC2ClientLiveTest.java | 16 ++-- .../jclouds/ec2/EBSBootEC2ClientLiveTest.java | 16 ++-- .../compute/EC2ComputeServiceLiveTest.java | 4 +- .../ElasticStackClientLiveTest.java | 12 +-- .../openstack/nova/NovaClientLiveTest.java | 8 +- .../vcloud/features/VmClientLiveTest.java | 6 +- .../vcloud_0_8/TerremarkClientLiveTest.java | 14 ++-- .../internal/BaseTerremarkClientLiveTest.java | 6 +- ...ateSshClientOncePortIsListeningOnNode.java | 4 +- .../predicates/RetryIfSocketNotYetOpen.java | 8 +- .../StubComputeServiceDependenciesModule.java | 8 +- .../compute/util/ComputeServiceUtils.java | 14 ++-- .../main/java/org/jclouds/ssh/SshClient.java | 9 +- .../src/test/clojure/org/jclouds/ssh_test.clj | 8 +- .../StubComputeServiceIntegrationTest.java | 36 ++++---- .../internal/BaseComputeServiceLiveTest.java | 14 ++-- .../RetryIfSocketNotYetOpenTest.java | 7 +- .../predicates/SocketOpenPredicates.java | 7 +- .../main/java/org/jclouds/net/IPSocket.java | 82 ------------------- .../predicates/InetSocketAddressConnect.java | 6 +- .../org/jclouds/predicates/SocketOpen.java | 5 +- .../predicates/SocketOpenUnsupported.java | 4 +- .../org/jclouds/ssh/jsch/JschSshClient.java | 5 +- .../ssh/jsch/config/JschSshClientModule.java | 6 +- .../ssh/jsch/JschSshClientLiveTest.java | 6 +- .../jclouds/ssh/jsch/JschSshClientTest.java | 4 +- .../jsch/config/JschSshClientModuleTest.java | 4 +- .../java/org/jclouds/sshj/SshjSshClient.java | 5 +- .../sshj/config/SshjSshClientModule.java | 6 +- .../jclouds/sshj/SshjSshClientLiveTest.java | 6 +- .../org/jclouds/sshj/SshjSshClientTest.java | 4 +- .../sshj/config/SshjSshClientModuleTest.java | 4 +- .../glesys/features/IpClientLiveTest.java | 2 +- .../vpdc/features/VMClientLiveTest.java | 8 +- .../functions/IMachineToSshClient.java | 4 +- .../admin/StartVBoxIfNotAlreadyRunning.java | 6 +- .../StartVBoxIfNotAlreadyRunningLiveTest.java | 6 +- .../BaseLoadBalancerServiceLiveTest.java | 6 +- .../gogrid/GoGridLiveTestDisabled.java | 6 +- .../slicehost/SlicehostClientLiveTest.java | 8 +- ...oftLayerComputeServiceAdapterLiveTest.java | 4 +- .../ecloud/TerremarkECloudClientLiveTest.java | 5 +- .../TerremarkVCloudExpressClientLiveTest.java | 5 +- 56 files changed, 205 insertions(+), 285 deletions(-) delete mode 100644 core/src/main/java/org/jclouds/net/IPSocket.java diff --git a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java index 72e734af0c..70e77f8aab 100644 --- a/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java +++ b/apis/cloudloadbalancers/src/test/java/org/jclouds/cloudloadbalancers/internal/BaseCloudLoadBalancersClientLiveTest.java @@ -28,12 +28,12 @@ import org.jclouds.cloudloadbalancers.predicates.LoadBalancerActive; import org.jclouds.cloudloadbalancers.predicates.LoadBalancerDeleted; import org.jclouds.loadbalancer.LoadBalancerServiceContext; import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; import org.testng.annotations.BeforeGroups; import com.google.common.base.Predicate; +import com.google.common.net.HostAndPort; import com.google.common.reflect.TypeToken; import com.google.inject.Guice; import com.google.inject.Injector; @@ -51,7 +51,7 @@ public class BaseCloudLoadBalancersClientLiveTest extends BaseViewLiveTest lbContext; protected String[] regions = {}; - protected Predicate socketTester; + protected Predicate socketTester; protected RetryablePredicate loadBalancerActive; protected RetryablePredicate loadBalancerDeleted; diff --git a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java index eca7ef3d62..1dcefe6553 100644 --- a/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java +++ b/apis/cloudservers/src/test/java/org/jclouds/cloudservers/CloudServersClientLiveTest.java @@ -49,7 +49,6 @@ import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payload; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.ssh.SshClient; @@ -63,6 +62,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; /** @@ -79,7 +79,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes protected CloudServersClient client; protected SshClient.Factory sshFactory; - protected Predicate socketTester; + protected Predicate socketTester; @BeforeGroups(groups = { "integration", "live" }) @Override @@ -89,7 +89,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes client = injector.getInstance(CloudServersClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); - socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); injector.injectMembers(socketOpen); // add logger } @@ -374,7 +374,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes } private void doCheckPass(Server newDetails, String pass) throws IOException { - IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0), 22); + HostAndPort socket = HostAndPort.fromParts(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0), 22); socketTester.apply(socket); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); @@ -390,7 +390,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes } private ExecResponse exec(Server details, String pass, String command) throws IOException { - IPSocket socket = new IPSocket(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22); + HostAndPort socket = HostAndPort.fromParts(Iterables.get(details.getAddresses().getPublicAddresses(), 0), 22); socketTester.apply(socket); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); try { diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java index e8b0a729ff..1a639fc980 100644 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java @@ -46,7 +46,6 @@ import org.jclouds.cloudsigma.util.Servers; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; @@ -61,6 +60,7 @@ import com.google.common.base.Predicates; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.net.HostAndPort; import com.google.gson.Gson; import com.google.inject.Guice; @@ -81,7 +81,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest protected String vncPassword = "Il0veVNC"; protected CloudSigmaClient client; protected RestContext cloudSigmaContext; - protected Predicate socketTester; + protected Predicate socketTester; protected Predicate driveNotClaimed; @@ -94,7 +94,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest client = cloudSigmaContext.getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, 1, TimeUnit.SECONDS); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, TimeUnit.SECONDS); if (Strings.emptyToNull(imageId) == null) { @@ -329,9 +329,9 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest @Test(dependsOnMethods = "testCreateAndStartServer") public void testConnectivity() throws Exception { Logger.getAnonymousLogger().info("awaiting vnc"); - assert socketTester.apply(new IPSocket(server.getVnc().getIp(), 5900)) : server; + assert socketTester.apply(HostAndPort.fromParts(server.getVnc().getIp(), 5900)) : server; Logger.getAnonymousLogger().info("awaiting ssh"); - assert socketTester.apply(new IPSocket(server.getNics().get(0).getDhcp(), 22)) : server; + assert socketTester.apply(HostAndPort.fromParts(server.getNics().get(0).getDhcp(), 22)) : server; doConnectViaSsh(server, getSshCredentials(server)); } @@ -389,7 +389,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class) - .create(new IPSocket(server.getVnc().getIp(), 22), creds); + .create(HostAndPort.fromParts(server.getVnc().getIp(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackClientLiveTest.java index eb1e7ccc07..299f5a3da6 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/CloudStackClientLiveTest.java @@ -32,7 +32,7 @@ //import org.jclouds.cloudstack.options.CreateInstanceOptions; //import org.jclouds.domain.Credentials; //import org.jclouds.http.HttpRequest; -//import org.jclouds.net.IPSocket; +//import com.google.common.net.HostAndPort; //import org.jclouds.ssh.SshClient; //import org.jclouds.ssh.jsch.config.JschSshClientModule; //import org.testng.annotations.AfterGroups; @@ -79,7 +79,7 @@ // public void testConnectivity() throws Exception { // Logger.getAnonymousLogger().info("awaiting ssh"); // // TODO -// // assert socketTester.apply(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), +// // assert socketTester.apply(HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0), // // 22)) : instance; // // doConnectViaSsh(instance, getSshCredentials(instance)); // } @@ -119,7 +119,7 @@ // // protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException { // SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class) -// .create(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22), creds); +// .create(HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0), 22), creds); // try { // ssh.connect(); // ExecResponse hello = ssh.exec("echo hello"); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java index 41a32cc956..71fbbc9d30 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/compute/CloudStackComputeServiceAdapterLiveTest.java @@ -53,14 +53,13 @@ import org.jclouds.cloudstack.suppliers.GetCurrentUser; import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser; import org.jclouds.cloudstack.suppliers.ZoneIdToZoneSupplier; import org.jclouds.collect.Memoized; -import org.jclouds.compute.ComputeTestUtils; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; +import org.jclouds.compute.ComputeTestUtils; import org.jclouds.compute.domain.Template; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.domain.Credentials; import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.annotations.Identity; import org.testng.annotations.AfterGroups; @@ -74,6 +73,7 @@ import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.net.HostAndPort; import com.google.common.net.InetAddresses; import com.google.inject.AbstractModule; import com.google.inject.Guice; @@ -180,7 +180,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien loginCredentials = prioritizeCredentialsFromTemplate.apply(template, vm.getCredentials()); assert InetAddresses.isInetAddress(address) : vm; - IPSocket socket = new IPSocket(address, 22); + HostAndPort socket = HostAndPort.fromParts(address, 22); checkSSH(socket); } diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java index f750cca75c..d6f71d31e6 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/BaseCloudStackClientLiveTest.java @@ -52,7 +52,6 @@ import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult; import org.jclouds.compute.ComputeService; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.internal.BaseGenericComputeServiceContextLiveTest; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; @@ -65,6 +64,7 @@ import com.google.common.base.Predicate; import com.google.common.base.Predicates; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.common.reflect.TypeToken; import com.google.inject.Guice; import com.google.inject.Injector; @@ -156,7 +156,7 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte protected CloudStackClient adminClient; protected User user; - protected Predicate socketTester; + protected Predicate socketTester; protected RetryablePredicate jobComplete; protected RetryablePredicate adminJobComplete; protected RetryablePredicate virtualMachineRunning; @@ -181,7 +181,7 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte protected CloudStackGlobalClient globalAdminClient; protected User globalAdminUser; - protected void checkSSH(IPSocket socket) { + protected void checkSSH(HostAndPort socket) { socketTester.apply(socket); SshClient client = sshFactory.create(socket, loginCredentials); try { @@ -224,7 +224,7 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte injector = Guice.createInjector(setupModules()); sshFactory = injector.getInstance(SshClient.Factory.class); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS); injector.injectMembers(socketTester); jobComplete = new RetryablePredicate(new JobComplete(client), 1200, 1, 5, TimeUnit.SECONDS); injector.injectMembers(jobComplete); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java index 089af5bb70..11eeeb9948 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/FirewallClientLiveTest.java @@ -36,13 +36,13 @@ import org.jclouds.cloudstack.domain.PublicIPAddress; import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.options.CreateFirewallRuleOptions; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.net.HostAndPort; /** * Tests behavior of {@code FirewallClientLiveTest} @@ -112,7 +112,7 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest { assertEquals(portForwardingRule.getProtocol(), PortForwardingRule.Protocol.TCP); checkPortForwardingRule(portForwardingRule); - checkSSH(new IPSocket(ip.getIPAddress(), 22)); + checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); } @Test(dependsOnMethods = "testCreatePortForwardingRule") diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java index 441a0d8b8a..52453aba9f 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/LoadBalancerClientLiveTest.java @@ -35,13 +35,12 @@ import javax.annotation.Nullable; import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.cloudstack.domain.JobResult; import org.jclouds.cloudstack.domain.LoadBalancerRule; +import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; +import org.jclouds.cloudstack.domain.LoadBalancerRule.State; import org.jclouds.cloudstack.domain.Network; import org.jclouds.cloudstack.domain.PublicIPAddress; import org.jclouds.cloudstack.domain.VirtualMachine; -import org.jclouds.cloudstack.domain.LoadBalancerRule.Algorithm; -import org.jclouds.cloudstack.domain.LoadBalancerRule.State; import org.jclouds.cloudstack.predicates.LoadBalancerRuleActive; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.ssh.SshException; import org.testng.annotations.AfterGroups; @@ -50,6 +49,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.base.Predicates; +import com.google.common.net.HostAndPort; /** * Tests behavior of {@code LoadBalancerClientLiveTest} @@ -155,7 +155,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest { private void loopAndCheckSSH() throws IOException { for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. try { - checkSSH(new IPSocket(ip.getIPAddress(), 22)); + checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); return; } catch (SshException e) { e.printStackTrace(); @@ -176,7 +176,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest { rule.getId(), vm.getId()))); assertEquals(client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()).size(), 0); assertEquals(rule.getState(), State.ADD); - checkSSH(new IPSocket(ip.getIPAddress(), 22)); + checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22)); } @AfterGroups(groups = "live") diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java index fd44fd9723..78c584bbf4 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/SecurityGroupClientLiveTest.java @@ -33,7 +33,6 @@ import org.jclouds.cloudstack.domain.Zone; import org.jclouds.cloudstack.options.AccountInDomainOptions; import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; -import org.jclouds.net.IPSocket; import org.jclouds.util.Strings2; import org.testng.annotations.AfterGroups; import org.testng.annotations.Test; @@ -41,6 +40,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; /** * Tests behavior of {@code SecurityGroupClient} @@ -178,7 +178,7 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest { if (vm.getPassword() != null && !loginCredentials.hasPasswordOption()) loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build(); // ingress port 22 - checkSSH(new IPSocket(vm.getIPAddress(), 22)); + checkSSH(HostAndPort.fromParts(vm.getIPAddress(), 22)); // ingress icmp disabled as this is platform dependent and may actually // just try tcp port 7 // assert InetAddress.getByName(vm.getIPAddress()).isReachable(1000) : vm; diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java index 6b8e7ce3c3..ab7cec7a6d 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/VirtualMachineClientLiveTest.java @@ -53,7 +53,6 @@ import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions; import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.cloudstack.options.ListTemplatesOptions; import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.util.InetAddresses2; import org.testng.annotations.AfterGroups; @@ -67,6 +66,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; import com.google.common.collect.Ordering; +import com.google.common.net.HostAndPort; import com.google.common.net.HostSpecifier; /** @@ -282,7 +282,7 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest { assert HostSpecifier.isValid(vm.getIPAddress()); if (!InetAddresses2.isPrivateIPAddress(vm.getIPAddress())) { // not sure if the network is public or not, so we have to test - IPSocket socket = new IPSocket(vm.getIPAddress(), 22); + HostAndPort socket = HostAndPort.fromParts(vm.getIPAddress(), 22); System.err.printf("testing socket %s%n", socket); System.err.printf("testing ssh %s%n", socket); checkSSH(socket); diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java index c0308fac3d..1b167a7205 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/functions/StaticNATVirtualMachineInNetworkLiveTest.java @@ -37,7 +37,6 @@ import org.jclouds.cloudstack.features.NATClientLiveTest; import org.jclouds.cloudstack.features.VirtualMachineClientLiveTest; import org.jclouds.cloudstack.predicates.NetworkPredicates; import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult; -import org.jclouds.net.IPSocket; import org.testng.annotations.AfterGroups; import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; @@ -45,6 +44,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.cache.CacheBuilder; import com.google.common.collect.ImmutableSet; +import com.google.common.net.HostAndPort; /** * Tests behavior of {@code StaticNATVirtualMachineInNetwork} @@ -106,7 +106,7 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest assertEquals(rule.getStartPort(), 22); assertEquals(rule.getProtocol(), "tcp"); checkRule(rule); - IPSocket socket = new IPSocket(ip.getIPAddress(), 22); + HostAndPort socket = HostAndPort.fromParts(ip.getIPAddress(), 22); checkSSH(socket); } diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java index 82a4f46532..ba34d5e4d4 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/DeltacloudClientLiveTest.java @@ -32,7 +32,6 @@ import org.jclouds.deltacloud.domain.TransitionOnAction; import org.jclouds.deltacloud.options.CreateInstanceOptions; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpRequest; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.testng.annotations.AfterClass; @@ -40,6 +39,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.gson.Gson; import com.google.inject.Guice; @@ -95,7 +95,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest { @Test(dependsOnMethods = "testCreateInstance") public void testConnectivity() throws Exception { Logger.getAnonymousLogger().info("awaiting ssh"); - assert socketTester.apply(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22)) : instance; + assert socketTester.apply(HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0), 22)) : instance; if (creds != null) { Logger.getAnonymousLogger().info("will connect ssh"); doConnectViaSsh(instance, creds); @@ -136,7 +136,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest { protected void doConnectViaSsh(Instance instance, LoginCredentials creds) throws IOException { SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create( - new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), 22), creds); + HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); diff --git a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java index c87a0e852e..39a9d8288e 100644 --- a/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java +++ b/apis/deltacloud/src/test/java/org/jclouds/deltacloud/ReadOnlyDeltacloudClientLiveTest.java @@ -30,12 +30,11 @@ import org.jclouds.deltacloud.domain.DeltacloudCollection; import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Instance; +import org.jclouds.deltacloud.domain.Instance.State; import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.domain.Transition; -import org.jclouds.deltacloud.domain.Instance.State; import org.jclouds.deltacloud.predicates.InstanceFinished; import org.jclouds.deltacloud.predicates.InstanceRunning; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.sshj.config.SshjSshClientModule; @@ -48,6 +47,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; import com.google.common.collect.Multimap; +import com.google.common.net.HostAndPort; import com.google.inject.Module; /** @@ -64,7 +64,7 @@ public class ReadOnlyDeltacloudClientLiveTest extends BaseComputeServiceContextL protected DeltacloudClient client; - protected Predicate socketTester; + protected Predicate socketTester; protected ImmutableMap> stateChanges; @Override @@ -72,7 +72,7 @@ public class ReadOnlyDeltacloudClientLiveTest extends BaseComputeServiceContextL public void setupContext() { super.setupContext(); client = view.unwrap(DeltacloudApiMetadata.CONTEXT_TOKEN).getApi(); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS); stateChanges = ImmutableMap.> of(// Instance.State.RUNNING, new RetryablePredicate(new InstanceRunning(client), 600, 1, TimeUnit.SECONDS),// diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java index 69e4ef37b4..ad21a91cf6 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/CloudApplicationArchitecturesEC2ClientLiveTest.java @@ -37,6 +37,7 @@ import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.domain.BlockDevice; +import org.jclouds.ec2.domain.Image.EbsBlockDevice; import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.IpProtocol; @@ -44,12 +45,10 @@ import org.jclouds.ec2.domain.KeyPair; import org.jclouds.ec2.domain.PublicIpInstanceIdPair; import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.RunningInstance; -import org.jclouds.ec2.domain.Image.EbsBlockDevice; import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.ec2.predicates.InstanceHasIpAddress; import org.jclouds.ec2.predicates.InstanceStateRunning; import org.jclouds.http.HttpResponseException; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.scriptbuilder.ScriptBuilder; @@ -63,6 +62,7 @@ import org.testng.annotations.Test; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; /** @@ -88,7 +88,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS private String instanceId; private String address; - private RetryablePredicate socketTester; + private RetryablePredicate socketTester; private RetryablePredicate hasIpTester; private RetryablePredicate runningTester; @@ -102,7 +102,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS TimeUnit.SECONDS); hasIpTester = new RetryablePredicate(new InstanceHasIpAddress(client), 180, 5, TimeUnit.SECONDS); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); - socketTester = new RetryablePredicate(socketOpen, 180, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 180, 1, TimeUnit.SECONDS); } @Test(enabled = false) @@ -296,7 +296,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS Thread.sleep(1000); instance = getInstance(instanceId); blockUntilWeCanSshIntoInstance(instance); - SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), + SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); @@ -357,14 +357,14 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS assert hasIpTester.apply(instance); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); - assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22)); + assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22)); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); System.out.printf("%d: %s awaiting http service to start%n", System.currentTimeMillis(), instance.getIpAddress()); - assert socketTester.apply(new IPSocket(instance.getIpAddress(), 80)); + assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 80)); System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance.getDnsName()); return instance; } @@ -401,7 +401,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS } private void doCheckKey(String address) { - SshClient ssh = sshFactory.create(new IPSocket(address, 22), + SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java index 9f6f126bbd..a0e0a21373 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/EBSBootEC2ClientLiveTest.java @@ -39,6 +39,8 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.ec2.domain.Attachment; import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.Image; +import org.jclouds.ec2.domain.Image.Architecture; +import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.IpProtocol; @@ -48,8 +50,6 @@ import org.jclouds.ec2.domain.RootDeviceType; import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.Snapshot; import org.jclouds.ec2.domain.Volume; -import org.jclouds.ec2.domain.Image.Architecture; -import org.jclouds.ec2.domain.Image.ImageType; import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.ec2.predicates.InstanceStateRunning; import org.jclouds.ec2.predicates.InstanceStateStopped; @@ -59,7 +59,6 @@ import org.jclouds.ec2.predicates.VolumeAttached; import org.jclouds.ec2.predicates.VolumeAvailable; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payloads; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.scriptbuilder.InitScript; @@ -76,6 +75,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; /** @@ -107,7 +107,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest private KeyPair keyPair; private String securityGroupName; - private RetryablePredicate socketTester; + private RetryablePredicate socketTester; private RetryablePredicate attachTester; private RetryablePredicate volumeTester; private RunningInstance instance; @@ -130,7 +130,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest client = injector.getInstance(EC2Client.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); - socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); VolumeAvailable volumeAvailable = injector.getInstance(VolumeAvailable.class); volumeTester = new RetryablePredicate(volumeAvailable, 60, 1, TimeUnit.SECONDS); @@ -273,7 +273,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest @Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") void testBundleInstance() { - SshClient ssh = sshFactory.create(new IPSocket(instance.getIpAddress(), 22), + SshClient ssh = sshFactory.create(HostAndPort.fromParts(instance.getIpAddress(), 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); @@ -510,7 +510,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest } private void doCheckKey(String address) { - SshClient ssh = sshFactory.create(new IPSocket(address, 22), + SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); @@ -538,7 +538,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); - assert socketTester.apply(new IPSocket(instance.getIpAddress(), 22)); + assert socketTester.apply(HostAndPort.fromParts(instance.getIpAddress(), 22)); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName()); sshPing(instance); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); diff --git a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java index cb8fa386ff..39f04e8e4a 100644 --- a/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java +++ b/apis/ec2/src/test/java/org/jclouds/ec2/compute/EC2ComputeServiceLiveTest.java @@ -54,7 +54,6 @@ import org.jclouds.ec2.services.ElasticBlockStoreClient; import org.jclouds.ec2.services.InstanceClient; import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.ec2.services.SecurityGroupClient; -import org.jclouds.net.IPSocket; import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.util.InetAddresses2; @@ -65,6 +64,7 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSortedSet; import com.google.common.collect.Iterables; import com.google.common.collect.Sets; +import com.google.common.net.HostAndPort; import com.google.inject.Module; /** @@ -198,7 +198,7 @@ public class EC2ComputeServiceLiveTest extends BaseComputeServiceLiveTest { // Check that the address is public and port 22 is accessible String ip = Iterables.getOnlyElement(publicIps); assertFalse(InetAddresses2.isPrivateIPAddress(ip)); - IPSocket socket = new IPSocket(ip, 22); + HostAndPort socket = HostAndPort.fromParts(ip, 22); assertTrue(socketTester.apply(socket), String.format("failed to open socket %s on node %s", socket, node)); // check that there is an elastic ip correlating to it diff --git a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java index 5365d502c7..54c9fd1709 100644 --- a/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java +++ b/apis/elasticstack/src/test/java/org/jclouds/elasticstack/ElasticStackClientLiveTest.java @@ -43,7 +43,6 @@ import org.jclouds.elasticstack.domain.ServerStatus; import org.jclouds.elasticstack.predicates.DriveClaimed; import org.jclouds.elasticstack.util.Servers; import org.jclouds.io.Payloads; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; @@ -59,6 +58,7 @@ import com.google.common.base.Predicates; import com.google.common.base.Strings; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.net.HostAndPort; import com.google.gson.Gson; import com.google.inject.Guice; @@ -81,7 +81,7 @@ public class ElasticStackClientLiveTest protected String vncPassword = "Il0veVNC"; protected ElasticStackClient client; protected RestContext cloudStackContext; - protected Predicate socketTester; + protected Predicate socketTester; protected Predicate driveNotClaimed; @BeforeGroups(groups = { "integration", "live" }) @@ -93,7 +93,7 @@ public class ElasticStackClientLiveTest client = cloudStackContext.getApi(); driveNotClaimed = new RetryablePredicate(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, 1, TimeUnit.SECONDS); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), maxDriveImageTime, 1, TimeUnit.SECONDS); if (Strings.emptyToNull(imageId) == null) { @@ -229,10 +229,10 @@ public class ElasticStackClientLiveTest @Test(dependsOnMethods = "testCreateAndStartServer") public void testConnectivity() throws Exception { - IPSocket vncsocket = new IPSocket(server.getVnc().getIp(), 5900); + HostAndPort vncsocket = HostAndPort.fromParts(server.getVnc().getIp(), 5900); Logger.getAnonymousLogger().info("awaiting vnc: " + vncsocket); assert socketTester.apply(vncsocket) : server; - IPSocket sshsocket = new IPSocket(server.getNics().get(0).getDhcp(), 22); + HostAndPort sshsocket = HostAndPort.fromParts(server.getNics().get(0).getDhcp(), 22); Logger.getAnonymousLogger().info("awaiting ssh: " + sshsocket); assert socketTester.apply(sshsocket) : server; doConnectViaSsh(server, getSshCredentials(server)); @@ -290,7 +290,7 @@ public class ElasticStackClientLiveTest protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create( - new IPSocket(server.getVnc().getIp(), 22), creds); + HostAndPort.fromParts(server.getVnc().getIp(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); diff --git a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java index ccbdeb509d..769a3afc45 100644 --- a/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java +++ b/apis/nova/src/test/java/org/jclouds/openstack/nova/NovaClientLiveTest.java @@ -36,7 +36,6 @@ import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payload; -import org.jclouds.net.IPSocket; import org.jclouds.openstack.nova.domain.Flavor; import org.jclouds.openstack.nova.domain.Image; import org.jclouds.openstack.nova.domain.ImageStatus; @@ -56,6 +55,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; /** @@ -72,7 +72,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest { protected NovaClient client; protected SshClient.Factory sshFactory; - protected Predicate socketTester; + protected Predicate socketTester; @BeforeGroups(groups = { "integration", "live" }) @Override @@ -82,7 +82,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest { client = injector.getInstance(NovaClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); - socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); injector.injectMembers(socketOpen); // add logger } @@ -296,7 +296,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest { } private void doCheckPass(Server newDetails, String pass) throws IOException { - IPSocket socket = new IPSocket(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0).getAddress(), 22); + HostAndPort socket = HostAndPort.fromParts(Iterables.get(newDetails.getAddresses().getPublicAddresses(), 0).getAddress(), 22); socketTester.apply(socket); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); diff --git a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java index 2fd7661601..35f387467f 100644 --- a/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java +++ b/apis/vcloud/src/test/java/org/jclouds/vcloud/features/VmClientLiveTest.java @@ -28,7 +28,6 @@ import static org.testng.Assert.assertNotNull; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.net.IPSocket; import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; @@ -41,6 +40,7 @@ import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest; import org.testng.annotations.Test; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; /** * This tests that we can use guest customization as an alternative to bootstrapping with ssh. There @@ -157,8 +157,8 @@ public class VmClientLiveTest extends BaseVCloudClientLiveTest { assertEquals(apiOutput, script.replace("\n", "")); } - protected IPSocket getSocket(NodeMetadata node) { - return new IPSocket(get(node.getPublicAddresses(), 0), 22); + protected HostAndPort getSocket(NodeMetadata node) { + return HostAndPort.fromParts(get(node.getPublicAddresses(), 0), 22); } } \ No newline at end of file diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java index f6308b9841..cb33ebe12c 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/TerremarkClientLiveTest.java @@ -32,9 +32,9 @@ import java.io.IOException; import java.net.URI; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Properties; import java.util.Set; -import java.util.Map.Entry; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -43,14 +43,13 @@ import org.jclouds.cim.CIMPredicates; import org.jclouds.cim.ResourceAllocationSettingData; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.RestContext; import org.jclouds.ssh.SshClient; -import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshClient.Factory; +import org.jclouds.ssh.SshException; import org.jclouds.trmk.vcloud_0_8.domain.Catalog; import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem; import org.jclouds.trmk.vcloud_0_8.domain.CustomizationParameters; @@ -80,6 +79,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; @Test(groups = "live", singleThreaded = true) @@ -93,7 +93,7 @@ public abstract class TerremarkClientLiveTest socketTester; + protected RetryablePredicate socketTester; protected RetryablePredicate successTester; protected Injector injector; @@ -429,7 +429,7 @@ public abstract class TerremarkClientLiveTest(injector.getInstance(SocketOpen.class), 300, 10, TimeUnit.SECONDS);// make + socketTester = new RetryablePredicate(injector.getInstance(SocketOpen.class), 300, 10, TimeUnit.SECONDS);// make // it // longer // then diff --git a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java index 2d16b21584..a7ff954ad1 100644 --- a/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java +++ b/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/internal/BaseTerremarkClientLiveTest.java @@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit; import org.jclouds.compute.ComputeService; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; @@ -33,6 +32,7 @@ import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudClient; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; import com.google.inject.Module; @@ -51,7 +51,7 @@ public abstract class BaseTerremarkClientLiveTest socketTester; + protected RetryablePredicate socketTester; protected Factory sshFactory; protected S connection; @@ -61,7 +61,7 @@ public abstract class BaseTerremarkClientLiveTest(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS); sshFactory = injector.getInstance(Factory.class); connection = (S) RestContext.class.cast(view.unwrap()).getApi(); } diff --git a/compute/src/main/java/org/jclouds/compute/functions/CreateSshClientOncePortIsListeningOnNode.java b/compute/src/main/java/org/jclouds/compute/functions/CreateSshClientOncePortIsListeningOnNode.java index d4d779c0ad..90a5b23c8e 100644 --- a/compute/src/main/java/org/jclouds/compute/functions/CreateSshClientOncePortIsListeningOnNode.java +++ b/compute/src/main/java/org/jclouds/compute/functions/CreateSshClientOncePortIsListeningOnNode.java @@ -26,10 +26,10 @@ import javax.inject.Singleton; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.compute.util.ComputeServiceUtils; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import com.google.common.base.Function; +import com.google.common.net.HostAndPort; import com.google.inject.Inject; /** @@ -55,7 +55,7 @@ public class CreateSshClientOncePortIsListeningOnNode implements Function { +public class RetryIfSocketNotYetOpen implements Predicate { @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) private Logger logger = Logger.NULL; @@ -84,11 +84,11 @@ public class RetryIfSocketNotYetOpen implements Predicate { } @Override - public boolean apply(IPSocket socket) { + public boolean apply(HostAndPort socket) { logger.debug(">> blocking on socket %s for %d %s", socket, timeoutValue, timeoutUnits); // Specify a retry period of 1s, expressed in the same time units. long period = timeoutUnits.convert(1, TimeUnit.SECONDS); - RetryablePredicate tester = new RetryablePredicate(socketTester, timeoutValue, period, timeoutUnits); + RetryablePredicate tester = new RetryablePredicate(socketTester, timeoutValue, period, timeoutUnits); boolean passed = tester.apply(socket); if (passed) logger.debug("<< socket %s opened", socket); diff --git a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java index 98bde50baf..4ec374c9d7 100644 --- a/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java +++ b/compute/src/main/java/org/jclouds/compute/stub/config/StubComputeServiceDependenciesModule.java @@ -33,7 +33,6 @@ import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.internal.VolumeImpl; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.annotations.Identity; @@ -41,6 +40,7 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; import com.google.common.collect.ImmutableList; +import com.google.common.net.HostAndPort; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -128,10 +128,10 @@ public class StubComputeServiceDependenciesModule extends AbstractModule { } @Override - public boolean apply(IPSocket input) { - if (input.getAddress().indexOf(publicIpPrefix) == -1) + public boolean apply(HostAndPort input) { + if (input.getHostText().indexOf(publicIpPrefix) == -1) return false; - String id = input.getAddress().replace(publicIpPrefix, ""); + String id = input.getHostText().replace(publicIpPrefix, ""); NodeMetadata node = nodes.get(id); return node != null && node.getState() == NodeState.RUNNING; } diff --git a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java index 34e73036a0..ff149ab778 100644 --- a/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java +++ b/compute/src/main/java/org/jclouds/compute/util/ComputeServiceUtils.java @@ -30,8 +30,8 @@ import static org.jclouds.scriptbuilder.domain.Statements.pipeHttpResponseToBash import java.net.URI; import java.util.Formatter; import java.util.Map; -import java.util.NoSuchElementException; import java.util.Map.Entry; +import java.util.NoSuchElementException; import java.util.regex.Pattern; import org.jclouds.compute.ComputeServiceContext; @@ -43,13 +43,13 @@ import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Volume; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.http.HttpRequest; -import org.jclouds.net.IPSocket; import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statements; import com.google.common.base.Function; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.common.reflect.TypeToken; /** @@ -165,17 +165,17 @@ public class ComputeServiceUtils { return org.jclouds.rest.Providers.getSupportedProvidersOfType(TypeToken.of(ComputeServiceContext.class)); } - public static IPSocket findReachableSocketOnNode(RetryIfSocketNotYetOpen socketTester, final NodeMetadata node, + public static HostAndPort findReachableSocketOnNode(RetryIfSocketNotYetOpen socketTester, final NodeMetadata node, final int port) { checkNodeHasIps(node); - IPSocket socket = null; + HostAndPort socket = null; try { socket = find(transform(concat(node.getPublicAddresses(), node.getPrivateAddresses()), - new Function() { + new Function() { @Override - public IPSocket apply(String from) { - return new IPSocket(from, port); + public HostAndPort apply(String from) { + return HostAndPort.fromParts(from, port); } }), socketTester); } catch (NoSuchElementException e) { diff --git a/compute/src/main/java/org/jclouds/ssh/SshClient.java b/compute/src/main/java/org/jclouds/ssh/SshClient.java index 33c1c7331e..4e9160b704 100644 --- a/compute/src/main/java/org/jclouds/ssh/SshClient.java +++ b/compute/src/main/java/org/jclouds/ssh/SshClient.java @@ -23,7 +23,8 @@ import org.jclouds.compute.domain.ExecResponse; import org.jclouds.domain.Credentials; import org.jclouds.domain.LoginCredentials; import org.jclouds.io.Payload; -import org.jclouds.net.IPSocket; + +import com.google.common.net.HostAndPort; /** * @author Adrian Cole @@ -35,12 +36,12 @@ public interface SshClient { /** * To be removed in jclouds 1.5.0 * - * @see #create(IPSocket, LoginCredentials) + * @see #create(com.google.common.net.HostAndPort, LoginCredentials) */ @Deprecated - SshClient create(IPSocket socket, Credentials credentials); + SshClient create(HostAndPort socket, Credentials credentials); - SshClient create(IPSocket socket, LoginCredentials credentials); + SshClient create(HostAndPort socket, LoginCredentials credentials); } diff --git a/compute/src/test/clojure/org/jclouds/ssh_test.clj b/compute/src/test/clojure/org/jclouds/ssh_test.clj index d6ea701351..54b001cf97 100644 --- a/compute/src/test/clojure/org/jclouds/ssh_test.clj +++ b/compute/src/test/clojure/org/jclouds/ssh_test.clj @@ -25,7 +25,7 @@ org.jclouds.domain.Credentials org.jclouds.domain.LoginCredentials org.jclouds.io.Payload - org.jclouds.net.IPSocket + com.google.common.net.HostAndPort org.jclouds.compute.domain.ExecResponse)) (defn instantiate [impl-class & args] @@ -67,7 +67,7 @@ (^void put [this ^String path ^String content]) (^void put [this ^String path ^org.jclouds.io.Payload content]) (getUsername [this] username) - (getHostAddress [this] (.getAddress socket)) ) + (getHostAddress [this] (.getHostText socket)) ) (defn no-op-ssh-client [socket username password] @@ -79,11 +79,11 @@ org.jclouds.ssh.SshClient$Factory (^org.jclouds.ssh.SshClient create - [_ ^IPSocket socket ^Credentials credentials] + [_ ^HostAndPort socket ^Credentials credentials] (factory-fn socket (.identity credentials) (.credential credentials))) (^org.jclouds.ssh.SshClient create - [_ ^IPSocket socket ^LoginCredentials credentials] + [_ ^HostAndPort socket ^LoginCredentials credentials] (factory-fn socket (.identity credentials) (.credential credentials))) ) diff --git a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java index de65693865..0c94f6374e 100644 --- a/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java +++ b/compute/src/test/java/org/jclouds/compute/StubComputeServiceIntegrationTest.java @@ -39,7 +39,6 @@ import org.jclouds.compute.internal.BaseComputeServiceLiveTest; import org.jclouds.crypto.Pems; import org.jclouds.domain.LoginCredentials; import org.jclouds.io.Payload; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; @@ -54,6 +53,7 @@ import com.google.common.base.Supplier; import com.google.common.base.Suppliers; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; +import com.google.common.net.HostAndPort; import com.google.inject.AbstractModule; import com.google.inject.Module; @@ -80,13 +80,13 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes protected void buildSocketTester() { SocketOpen socketOpen = createMock(SocketOpen.class); - expect(socketOpen.apply(new IPSocket("144.175.1.1", 22))).andReturn(true).times(5); + expect(socketOpen.apply(HostAndPort.fromParts("144.175.1.1", 22))).andReturn(true).times(5); // restart of jboss - expect(socketOpen.apply(new IPSocket("144.175.1.1", 8080))).andReturn(true).times(2); + expect(socketOpen.apply(HostAndPort.fromParts("144.175.1.1", 8080))).andReturn(true).times(2); replay(socketOpen); - preciseSocketTester = socketTester = new RetryablePredicate(socketOpen, 1, 1, TimeUnit.MILLISECONDS); + preciseSocketTester = socketTester = new RetryablePredicate(socketOpen, 1, 1, TimeUnit.MILLISECONDS); } @Override @@ -140,26 +140,26 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes SshClient client5 = createMock(SshClient.class); expect( - factory.create(new IPSocket("144.175.1.1", 22), + factory.create(HostAndPort.fromParts("144.175.1.1", 22), LoginCredentials.builder().user("root").password("password1").build())).andReturn(client1); expect( - factory.create(new IPSocket("144.175.1.1", 22), + factory.create(HostAndPort.fromParts("144.175.1.1", 22), LoginCredentials.builder().user("web").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client1New) .times(10); runScriptAndService(client1, client1New); expect( - factory.create(new IPSocket("144.175.1.2", 22), + factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2) .times(4); expect( - factory.create(new IPSocket("144.175.1.2", 22), + factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2New); expect( - factory.create(new IPSocket("144.175.1.2", 22), + factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("foo").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client2Foo); expect( - factory.create(new IPSocket("144.175.1.2", 22), + factory.create(HostAndPort.fromParts("144.175.1.2", 22), LoginCredentials.builder().user("root").password("romeo").build())).andThrow( new AuthorizationException("Auth fail", null)); @@ -200,15 +200,15 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes client2Foo.disconnect(); expect( - factory.create(new IPSocket("144.175.1.3", 22), + factory.create(HostAndPort.fromParts("144.175.1.3", 22), LoginCredentials.builder().user("root").password("password3").build())).andReturn(client3) .times(2); expect( - factory.create(new IPSocket("144.175.1.4", 22), + factory.create(HostAndPort.fromParts("144.175.1.4", 22), LoginCredentials.builder().user("root").password("password4").build())).andReturn(client4) .times(2); expect( - factory.create(new IPSocket("144.175.1.5", 22), + factory.create(HostAndPort.fromParts("144.175.1.5", 22), LoginCredentials.builder().user("root").password("password5").build())).andReturn(client5) .times(2); @@ -217,23 +217,23 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes runScriptAndInstallSsh(client5, "bootstrap", 5); expect( - factory.create(eq(new IPSocket("144.175.1.1", 22)), + factory.create(eq(HostAndPort.fromParts("144.175.1.1", 22)), eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build()))) .andReturn(client1); expect( - factory.create(eq(new IPSocket("144.175.1.2", 22)), + factory.create(eq(HostAndPort.fromParts("144.175.1.2", 22)), eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build()))) .andReturn(client2); expect( - factory.create(eq(new IPSocket("144.175.1.3", 22)), + factory.create(eq(HostAndPort.fromParts("144.175.1.3", 22)), eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build()))) .andReturn(client3); expect( - factory.create(eq(new IPSocket("144.175.1.4", 22)), + factory.create(eq(HostAndPort.fromParts("144.175.1.4", 22)), eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build()))) .andReturn(client4); expect( - factory.create(eq(new IPSocket("144.175.1.5", 22)), + factory.create(eq(HostAndPort.fromParts("144.175.1.5", 22)), eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build()))) .andReturn(client5); diff --git a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java index 33fa6243d6..f5202b32f4 100644 --- a/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java +++ b/compute/src/test/java/org/jclouds/compute/internal/BaseComputeServiceLiveTest.java @@ -50,10 +50,10 @@ import static org.testng.Assert.assertNotNull; import java.io.IOException; import java.util.Collection; import java.util.Map; +import java.util.Map.Entry; import java.util.NoSuchElementException; import java.util.Set; import java.util.SortedSet; -import java.util.Map.Entry; import java.util.concurrent.Callable; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; @@ -84,7 +84,6 @@ import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.domain.LocationScope; import org.jclouds.domain.LoginCredentials; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.rest.AuthorizationException; @@ -105,6 +104,7 @@ import com.google.common.base.Stopwatch; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.common.util.concurrent.ListenableFuture; import com.google.inject.Module; @@ -117,8 +117,8 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte protected String group; - protected Predicate socketTester; - protected Predicate preciseSocketTester; + protected Predicate socketTester; + protected Predicate preciseSocketTester; protected SortedSet nodes; protected ComputeService client; @@ -151,12 +151,12 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte protected void buildSocketTester() { SocketOpen socketOpen = view.utils().injector().getInstance(SocketOpen.class); - socketTester = new RetryablePredicate(socketOpen, 60, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 60, 1, TimeUnit.SECONDS); // wait a maximum of 60 seconds for port 8080 to open. long maxWait = TimeUnit.SECONDS.toMillis(60); long interval = 50; // get more precise than default socket tester - preciseSocketTester = new RetryablePredicate(socketOpen, maxWait, interval, interval, + preciseSocketTester = new RetryablePredicate(socketOpen, maxWait, interval, interval, TimeUnit.MILLISECONDS); } @Override @@ -579,7 +579,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); watch.reset().start(); - IPSocket socket = new IPSocket(Iterables.get(node.getPublicAddresses(), 0), 8080); + HostAndPort socket = HostAndPort.fromParts(Iterables.get(node.getPublicAddresses(), 0), 8080); assert preciseSocketTester.apply(socket) : String.format("failed to open socket %s on node %s:%n%s%s", socket, node, init(node, processName, "stdout"), init(node, processName, "stderr")); stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); diff --git a/compute/src/test/java/org/jclouds/compute/predicates/RetryIfSocketNotYetOpenTest.java b/compute/src/test/java/org/jclouds/compute/predicates/RetryIfSocketNotYetOpenTest.java index 1b2f859b3c..c3a24721f0 100644 --- a/compute/src/test/java/org/jclouds/compute/predicates/RetryIfSocketNotYetOpenTest.java +++ b/compute/src/test/java/org/jclouds/compute/predicates/RetryIfSocketNotYetOpenTest.java @@ -26,9 +26,10 @@ import java.util.concurrent.TimeUnit; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; + /** * Tests timeout behavior of {@link RetryIfSocketNotYetOpen} predicate. @@ -36,7 +37,7 @@ import org.testng.annotations.Test; public class RetryIfSocketNotYetOpenTest { private static final Logger logger = Logger.NULL; - private static final IPSocket socket = new IPSocket("dummy", 0); + private static final HostAndPort socket = HostAndPort.fromParts("dummy", 0); @Test public void fromConstructor() { @@ -70,7 +71,7 @@ public class RetryIfSocketNotYetOpenTest { doAsserts(uninitialised, socket, false, 0, 500); } - private void doAsserts(RetryIfSocketNotYetOpen predicate, IPSocket socket, boolean expectedResult, long minMilliseconds, long maxMilliseconds) { + private void doAsserts(RetryIfSocketNotYetOpen predicate, HostAndPort socket, boolean expectedResult, long minMilliseconds, long maxMilliseconds) { long startTime = System.currentTimeMillis(); boolean result = predicate.apply(socket); long elapsedTime = System.currentTimeMillis() - startTime; diff --git a/compute/src/test/java/org/jclouds/compute/predicates/SocketOpenPredicates.java b/compute/src/test/java/org/jclouds/compute/predicates/SocketOpenPredicates.java index 12efc695ff..86ddbef963 100644 --- a/compute/src/test/java/org/jclouds/compute/predicates/SocketOpenPredicates.java +++ b/compute/src/test/java/org/jclouds/compute/predicates/SocketOpenPredicates.java @@ -18,9 +18,10 @@ */ package org.jclouds.compute.predicates; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.SocketOpen; +import com.google.common.net.HostAndPort; + /** * For use in unit tests, e.g. {@link RetryIfSocketNotYetOpenTest}. @@ -28,11 +29,11 @@ import org.jclouds.predicates.SocketOpen; public class SocketOpenPredicates { public static final SocketOpen alwaysSucceed = new SocketOpen() { - @Override public boolean apply(IPSocket socket) { return true; } + @Override public boolean apply(HostAndPort socket) { return true; } }; public static final SocketOpen alwaysFail = new SocketOpen() { - @Override public boolean apply(IPSocket socket) { return false; } + @Override public boolean apply(HostAndPort socket) { return false; } }; } diff --git a/core/src/main/java/org/jclouds/net/IPSocket.java b/core/src/main/java/org/jclouds/net/IPSocket.java deleted file mode 100644 index 315086641a..0000000000 --- a/core/src/main/java/org/jclouds/net/IPSocket.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Licensed to jclouds, Inc. (jclouds) under one or more - * contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. jclouds 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.net; - -import java.io.Serializable; - -/** - * As google appengine prohibits use of java.net classes, this will serve as a replacement. - * - * @author Adrian Cole - */ -public class IPSocket implements Serializable { - - /** The serialVersionUID */ - private static final long serialVersionUID = 2978329372952402188L; - - private final String address; - private final int port; - - public IPSocket(String address, int port) { - this.address = address; - this.port = port; - } - - public String getAddress() { - return address; - } - - public int getPort() { - return port; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((address == null) ? 0 : address.hashCode()); - result = prime * result + port; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - IPSocket other = (IPSocket) obj; - if (address == null) { - if (other.address != null) - return false; - } else if (!address.equals(other.address)) - return false; - if (port != other.port) - return false; - return true; - } - - @Override - public String toString() { - return "[address=" + address + ", port=" + port + "]"; - } - -} diff --git a/core/src/main/java/org/jclouds/predicates/InetSocketAddressConnect.java b/core/src/main/java/org/jclouds/predicates/InetSocketAddressConnect.java index 2ef0814fe8..de95e5c2ff 100644 --- a/core/src/main/java/org/jclouds/predicates/InetSocketAddressConnect.java +++ b/core/src/main/java/org/jclouds/predicates/InetSocketAddressConnect.java @@ -27,8 +27,8 @@ import javax.inject.Named; import javax.inject.Singleton; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; +import com.google.common.net.HostAndPort; import com.google.inject.Inject; /** @@ -48,8 +48,8 @@ public class InetSocketAddressConnect implements SocketOpen { private int timeout = 2000; @Override - public boolean apply(IPSocket socketA) { - InetSocketAddress socketAddress = new InetSocketAddress(socketA.getAddress(), socketA + public boolean apply(HostAndPort socketA) { + InetSocketAddress socketAddress = new InetSocketAddress(socketA.getHostText(), socketA .getPort()); Socket socket = null; try { diff --git a/core/src/main/java/org/jclouds/predicates/SocketOpen.java b/core/src/main/java/org/jclouds/predicates/SocketOpen.java index 23ade2d919..b3b380fdb4 100644 --- a/core/src/main/java/org/jclouds/predicates/SocketOpen.java +++ b/core/src/main/java/org/jclouds/predicates/SocketOpen.java @@ -18,9 +18,8 @@ */ package org.jclouds.predicates; -import org.jclouds.net.IPSocket; - import com.google.common.base.Predicate; +import com.google.common.net.HostAndPort; import com.google.inject.ImplementedBy; /** @@ -30,6 +29,6 @@ import com.google.inject.ImplementedBy; * @author Adrian Cole */ @ImplementedBy(SocketOpenUnsupported.class) -public interface SocketOpen extends Predicate { +public interface SocketOpen extends Predicate { } diff --git a/core/src/main/java/org/jclouds/predicates/SocketOpenUnsupported.java b/core/src/main/java/org/jclouds/predicates/SocketOpenUnsupported.java index 0223535223..074d0a1e85 100644 --- a/core/src/main/java/org/jclouds/predicates/SocketOpenUnsupported.java +++ b/core/src/main/java/org/jclouds/predicates/SocketOpenUnsupported.java @@ -20,7 +20,7 @@ package org.jclouds.predicates; import javax.inject.Singleton; -import org.jclouds.net.IPSocket; +import com.google.common.net.HostAndPort; /** * @@ -31,7 +31,7 @@ import org.jclouds.net.IPSocket; public class SocketOpenUnsupported implements SocketOpen { @Override - public boolean apply(IPSocket socketA) { + public boolean apply(HostAndPort socketA) { throw new UnsupportedOperationException("socket testing not configured"); } diff --git a/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java b/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java index e9ff64628b..85eb3e8d00 100644 --- a/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java +++ b/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/JschSshClient.java @@ -48,7 +48,6 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; import org.jclouds.rest.AuthorizationException; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; @@ -122,10 +121,10 @@ public class JschSshClient implements SshClient { final String user; final String host; - public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, + public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, HostAndPort socket, LoginCredentials loginCredentials, int timeout) { this.user = checkNotNull(loginCredentials, "loginCredentials").getUser(); - this.host = checkNotNull(socket, "socket").getAddress(); + this.host = checkNotNull(socket, "socket").getHostText(); checkArgument(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort()); checkArgument(loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null, "you must specify a password or a key"); diff --git a/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java b/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java index 93f2bde215..a8f4cd7a9f 100644 --- a/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java +++ b/drivers/jsch/src/main/java/org/jclouds/ssh/jsch/config/JschSshClientModule.java @@ -24,13 +24,13 @@ import org.jclouds.Constants; import org.jclouds.domain.Credentials; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.handlers.BackoffLimitedRetryHandler; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.SocketOpen; import org.jclouds.ssh.ConfiguresSshClient; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.JschSshClient; +import com.google.common.net.HostAndPort; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; @@ -64,14 +64,14 @@ public class JschSshClientModule extends AbstractModule { } @Override - public SshClient create(IPSocket socket, LoginCredentials credentials) { + public SshClient create(HostAndPort socket, LoginCredentials credentials) { SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, credentials, timeout); injector.injectMembers(client);// add logger return client; } @Override - public SshClient create(IPSocket socket, Credentials credentials) { + public SshClient create(HostAndPort socket, Credentials credentials) { return create(socket, LoginCredentials.fromCredentials(credentials)); } } diff --git a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java index 71175793b3..f2a098b826 100644 --- a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java +++ b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientLiveTest.java @@ -36,7 +36,6 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.util.Strings2; @@ -46,6 +45,7 @@ import org.testng.annotations.Test; import com.google.common.base.Strings; import com.google.common.base.Suppliers; import com.google.common.io.Closeables; +import com.google.common.net.HostAndPort; import com.google.inject.Guice; import com.google.inject.Injector; @@ -136,10 +136,10 @@ public class JschSshClientLiveTest { SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection; if (Strings.emptyToNull(sshKeyFile) != null) { - connection = factory.create(new IPSocket(sshHost, port), LoginCredentials.builder().user(sshUser) + connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser) .privateKey(Strings2.toStringAndClose(new FileInputStream(sshKeyFile))).build()); } else { - connection = factory.create(new IPSocket(sshHost, port), + connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser).password(sshPass).build()); } connection.connect(); diff --git a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientTest.java b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientTest.java index e15694d069..b62103a36e 100644 --- a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientTest.java +++ b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/JschSshClientTest.java @@ -27,13 +27,13 @@ import java.util.Properties; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.rest.AuthorizationException; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -68,7 +68,7 @@ public class JschSshClientTest { } }, new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); - JschSshClient ssh = JschSshClient.class.cast(factory.create(new IPSocket("localhost", 22), LoginCredentials + JschSshClient ssh = JschSshClient.class.cast(factory.create(HostAndPort.fromParts("localhost", 22), LoginCredentials .builder().user("username").password("password").build())); return ssh; } diff --git a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java index 135a511081..4793153db9 100644 --- a/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java +++ b/drivers/jsch/src/test/java/org/jclouds/ssh/jsch/config/JschSshClientModuleTest.java @@ -22,11 +22,11 @@ import java.net.UnknownHostException; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.jsch.JschSshClient; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; import com.google.inject.Guice; import com.google.inject.Injector; @@ -42,7 +42,7 @@ public class JschSshClientModuleTest { Injector i = Guice.createInjector(new JschSshClientModule(), new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); - SshClient connection = factory.create(new IPSocket("localhost", 22), LoginCredentials.builder().user("username") + SshClient connection = factory.create(HostAndPort.fromParts("localhost", 22), LoginCredentials.builder().user("username") .password("password").build()); assert connection instanceof JschSshClient; } diff --git a/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java b/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java index 6318db8270..ed78a53091 100644 --- a/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java +++ b/drivers/sshj/src/main/java/org/jclouds/sshj/SshjSshClient.java @@ -63,7 +63,6 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; import org.jclouds.rest.AuthorizationException; import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshException; @@ -142,10 +141,10 @@ public class SshjSshClient implements SshClient { private final BackoffLimitedRetryHandler backoffLimitedRetryHandler; - public SshjSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, + public SshjSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, HostAndPort socket, LoginCredentials loginCredentials, int timeout) { this.user = checkNotNull(loginCredentials, "loginCredentials").getUser(); - this.host = checkNotNull(socket, "socket").getAddress(); + this.host = checkNotNull(socket, "socket").getHostText(); checkArgument(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort()); checkArgument(loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null, "you must specify a password or a key"); diff --git a/drivers/sshj/src/main/java/org/jclouds/sshj/config/SshjSshClientModule.java b/drivers/sshj/src/main/java/org/jclouds/sshj/config/SshjSshClientModule.java index 7b2621e1ba..b49b6b43a5 100644 --- a/drivers/sshj/src/main/java/org/jclouds/sshj/config/SshjSshClientModule.java +++ b/drivers/sshj/src/main/java/org/jclouds/sshj/config/SshjSshClientModule.java @@ -24,13 +24,13 @@ import org.jclouds.Constants; import org.jclouds.domain.Credentials; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.handlers.BackoffLimitedRetryHandler; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.SocketOpen; import org.jclouds.ssh.ConfiguresSshClient; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.SshjSshClient; +import com.google.common.net.HostAndPort; import com.google.inject.AbstractModule; import com.google.inject.Inject; import com.google.inject.Injector; @@ -64,14 +64,14 @@ public class SshjSshClientModule extends AbstractModule { } @Override - public SshClient create(IPSocket socket, LoginCredentials credentials) { + public SshClient create(HostAndPort socket, LoginCredentials credentials) { SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout); injector.injectMembers(client);// add logger return client; } @Override - public SshClient create(IPSocket socket, Credentials credentials) { + public SshClient create(HostAndPort socket, Credentials credentials) { return create(socket, LoginCredentials.fromCredentials(credentials)); } } diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java index 2888fe7846..f0d78dd3c7 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientLiveTest.java @@ -36,7 +36,6 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.io.Payload; import org.jclouds.io.Payloads; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.util.Strings2; @@ -46,6 +45,7 @@ import org.testng.annotations.Test; import com.google.common.base.Strings; import com.google.common.base.Suppliers; import com.google.common.io.Closeables; +import com.google.common.net.HostAndPort; import com.google.inject.Guice; import com.google.inject.Injector; @@ -135,10 +135,10 @@ public class SshjSshClientLiveTest { SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient connection; if (Strings.emptyToNull(sshKeyFile) != null) { - connection = factory.create(new IPSocket(sshHost, port), LoginCredentials.builder().user(sshUser) + connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser) .privateKey(Strings2.toStringAndClose(new FileInputStream(sshKeyFile))).build()); } else { - connection = factory.create(new IPSocket(sshHost, port), + connection = factory.create(HostAndPort.fromParts(sshHost, port), LoginCredentials.builder().user(sshUser).password(sshPass).build()); } connection.connect(); diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java index 3316aee861..a3946527b9 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/SshjSshClientTest.java @@ -42,7 +42,6 @@ import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.BufferLogger; import org.jclouds.logging.BufferLogger.Record; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.rest.AuthorizationException; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.config.SshjSshClientModule; @@ -50,6 +49,7 @@ import org.testng.Assert; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; import com.google.inject.AbstractModule; import com.google.inject.Guice; import com.google.inject.Injector; @@ -83,7 +83,7 @@ public class SshjSshClientTest { }, new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); - SshjSshClient ssh = SshjSshClient.class.cast(factory.create(new IPSocket("localhost", 22), LoginCredentials + SshjSshClient ssh = SshjSshClient.class.cast(factory.create(HostAndPort.fromParts("localhost", 22), LoginCredentials .builder().user("username").password("password").build())); return ssh; } diff --git a/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java b/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java index af8aace9c4..e0a61ccf6a 100644 --- a/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java +++ b/drivers/sshj/src/test/java/org/jclouds/sshj/config/SshjSshClientModuleTest.java @@ -20,11 +20,11 @@ package org.jclouds.sshj.config; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.sshj.SshjSshClient; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; import com.google.inject.Guice; import com.google.inject.Injector; @@ -40,7 +40,7 @@ public class SshjSshClientModuleTest { Injector i = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule()); SshClient.Factory factory = i.getInstance(SshClient.Factory.class); - SshClient connection = factory.create(new IPSocket("localhost", 22), LoginCredentials.builder().user("username") + SshClient connection = factory.create(HostAndPort.fromParts("localhost", 22), LoginCredentials.builder().user("username") .password("password").build()); assert connection instanceof SshjSshClient; } diff --git a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java index 0ba66e1ade..092f16d1f5 100644 --- a/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java +++ b/labs/glesys/src/test/java/org/jclouds/glesys/features/IpClientLiveTest.java @@ -63,7 +63,7 @@ public class IpClientLiveTest extends BaseGleSYSClientLiveTest { assertEquals(ipDetails.getIpversion(), "4"); // TODO: Ask Glesys to include address in response for OpenVZ? - // assertEquals(ipDetails.getAddress(), openVzIp); + // assertEquals(ipDetails.getHostText(), openVzIp); } @Test diff --git a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java index 0afcd54aeb..e25953ed34 100644 --- a/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java +++ b/labs/savvis-symphonyvpdc/src/test/java/org/jclouds/savvis/vpdc/features/VMClientLiveTest.java @@ -28,7 +28,6 @@ import org.jclouds.cim.OSType; import org.jclouds.compute.domain.CIMOperatingSystem; import org.jclouds.compute.domain.ExecResponse; import org.jclouds.domain.LoginCredentials; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.savvis.vpdc.domain.Network; @@ -48,13 +47,14 @@ import com.google.common.base.Predicate; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; @Test(groups = "live") public class VMClientLiveTest extends BaseVPDCClientLiveTest { private VMClient client; private VM vm; - private RetryablePredicate socketTester; + private RetryablePredicate socketTester; private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider + ".loginUser"); @@ -66,7 +66,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { public void setupContext() { super.setupContext(); client = restContext.getApi().getVMClient(); - socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);// make + socketTester = new RetryablePredicate(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);// make } private String billingSiteId; @@ -277,7 +277,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest { assert clonedVM.getHref() != null : clonedVM; } - protected void checkSSH(IPSocket socket) { + protected void checkSSH(HostAndPort socket) { socketTester.apply(socket); SshClient client = view.utils().sshFactory() .create(socket, LoginCredentials.builder().user(username).password(password).build()); diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java index e4ffe87a42..6290a8c97a 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/IMachineToSshClient.java @@ -34,7 +34,6 @@ import org.jclouds.compute.options.RunScriptOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.LoginCredentials; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.virtualbox.domain.BridgedIf; import org.jclouds.virtualbox.statements.GetIPAddressFromMAC; @@ -48,6 +47,7 @@ import com.google.common.base.Function; import com.google.common.base.Splitter; import com.google.common.base.Supplier; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.inject.Inject; @Singleton @@ -114,7 +114,7 @@ public class IMachineToSshClient implements Function { checkNotNull(clientIpAddress, "clientIpAddress"); client = sshClientFactory.create( - new IPSocket(clientIpAddress, Integer.parseInt(sshPort)), + HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)), loginCredentials); checkNotNull(client); return client; diff --git a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java index 8c231f11f2..6c9d561c42 100644 --- a/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java +++ b/labs/virtualbox/src/main/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunning.java @@ -37,7 +37,6 @@ import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.location.Provider; import org.jclouds.logging.Logger; -import org.jclouds.net.IPSocket; import org.jclouds.rest.annotations.Credential; import org.jclouds.rest.annotations.Identity; import org.jclouds.scriptbuilder.domain.Statements; @@ -46,6 +45,7 @@ import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Supplier; +import com.google.common.net.HostAndPort; @Singleton public class StartVBoxIfNotAlreadyRunning implements Supplier { @@ -78,7 +78,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier public synchronized void start() { URI provider = providerSupplier.get(); - if (!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))) { + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))) { logger.debug("disabling password access"); runScriptOnNodeFactory.create(host.get(), Statements.exec("VBoxManage setproperty websrvauthlibrary null"), runAsRoot(false).wrapInInitScript(false)).init().call(); @@ -87,7 +87,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); - if (!socketTester.apply(new IPSocket(provider.getHost(), provider.getPort()))){ + if (!socketTester.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))){ throw new RuntimeException("could not connect to virtualbox"); } } diff --git a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java index be64f61b88..45958fe7f4 100644 --- a/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java +++ b/labs/virtualbox/src/test/java/org/jclouds/virtualbox/functions/admin/StartVBoxIfNotAlreadyRunningLiveTest.java @@ -36,7 +36,6 @@ import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; -import org.jclouds.net.IPSocket; import org.jclouds.scriptbuilder.domain.Statements; import org.testng.annotations.Test; import org.virtualbox_4_1.VirtualBoxManager; @@ -44,6 +43,7 @@ import org.virtualbox_4_1.VirtualBoxManager; import com.google.common.base.Function; import com.google.common.base.Functions; import com.google.common.base.Suppliers; +import com.google.common.net.HostAndPort; @Test(groups = "live", singleThreaded = true, testName = "StartVBoxIfNotAlreadyRunningLiveTest") public class StartVBoxIfNotAlreadyRunningLiveTest { @@ -59,7 +59,7 @@ public class StartVBoxIfNotAlreadyRunningLiveTest { String identity = "adminstrator"; String credential = "12345"; expect(client.seconds(3)).andReturn(client); - expect(client.apply(new IPSocket(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes(); + expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(true).anyTimes(); manager.connect(provider.toASCIIString(), "", ""); expectLastCall().anyTimes(); @@ -87,7 +87,7 @@ public class StartVBoxIfNotAlreadyRunningLiveTest { String credential = "12345"; expect(client.seconds(3)).andReturn(client); - expect(client.apply(new IPSocket(provider.getHost(), provider.getPort()))).andReturn(false).once().andReturn(true).once(); + expect(client.apply(HostAndPort.fromParts(provider.getHost(), provider.getPort()))).andReturn(false).once().andReturn(true).once(); expect( runScriptOnNodeFactory.create(host, Statements.exec("VBoxManage setproperty websrvauthlibrary null"), runAsRoot(false).wrapInInitScript(false))).andReturn(runScriptOnNode); diff --git a/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java b/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java index 9ae48242e5..5ef28f1751 100644 --- a/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java +++ b/loadbalancer/src/test/java/org/jclouds/loadbalancer/BaseLoadBalancerServiceLiveTest.java @@ -39,7 +39,6 @@ import org.jclouds.compute.predicates.NodePredicates; import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.loadbalancer.domain.LoadBalancerMetadata; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.ssh.SshClient; @@ -49,6 +48,7 @@ import org.testng.annotations.Test; import com.google.common.base.Splitter; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.common.reflect.TypeToken; import com.google.inject.Guice; import com.google.inject.Module; @@ -95,7 +95,7 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseViewLiveTest socketTester; + protected RetryablePredicate socketTester; protected Set nodes; protected Template template; protected Map keyPair; @@ -139,7 +139,7 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseViewLiveTest(socketOpen, 60, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 60, 1, TimeUnit.SECONDS); } abstract protected Module getSshModule(); diff --git a/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java b/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java index 940858cff0..8db55df797 100644 --- a/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java +++ b/providers/gogrid/src/test/java/org/jclouds/gogrid/GoGridLiveTestDisabled.java @@ -53,7 +53,6 @@ import org.jclouds.gogrid.options.GetImageListOptions; import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted; import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; import org.jclouds.javax.annotation.Nullable; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.rest.RestContext; @@ -66,6 +65,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; /** * End to end live test for GoGrid @@ -341,9 +341,9 @@ public class GoGridLiveTestDisabled extends BaseComputeServiceContextLiveTest { LoginCredentials instanceCredentials = LoginCredentials.fromCredentials(credsMap.get(createdServer.getName())); assertNotNull(instanceCredentials); - IPSocket socket = new IPSocket(createdServer.getIp().getIp(), 22); + HostAndPort socket = HostAndPort.fromParts(createdServer.getIp().getIp(), 22); - RetryablePredicate socketOpen = new RetryablePredicate(new InetSocketAddressConnect(), 180, + RetryablePredicate socketOpen = new RetryablePredicate(new InetSocketAddressConnect(), 180, 5, TimeUnit.SECONDS); socketOpen.apply(socket); diff --git a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java index 5af27f5e48..44d00b92f9 100644 --- a/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java +++ b/providers/slicehost/src/test/java/org/jclouds/slicehost/SlicehostClientLiveTest.java @@ -32,7 +32,6 @@ import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.domain.LoginCredentials; import org.jclouds.http.HttpResponseException; import org.jclouds.io.Payloads; -import org.jclouds.net.IPSocket; import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.SocketOpen; import org.jclouds.slicehost.domain.Flavor; @@ -46,6 +45,7 @@ import org.testng.annotations.Test; import com.google.common.base.Predicate; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.inject.Injector; /** @@ -62,7 +62,7 @@ public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest { protected SlicehostClient client; protected SshClient.Factory sshFactory; - private Predicate socketTester; + private Predicate socketTester; @BeforeGroups(groups = { "integration", "live" }) @Override @@ -73,7 +73,7 @@ public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest { client = injector.getInstance(SlicehostClient.class); sshFactory = injector.getInstance(SshClient.Factory.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class); - socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); + socketTester = new RetryablePredicate(socketOpen, 120, 1, TimeUnit.SECONDS); injector.injectMembers(socketOpen); // add logger } @@ -254,7 +254,7 @@ public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest { private void doCreateMarkerFile(Slice newDetails, String pass) throws IOException { String ip = getIp(newDetails); - IPSocket socket = new IPSocket(ip, 22); + HostAndPort socket = HostAndPort.fromParts(ip, 22); socketTester.apply(socket); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java index 2b40b84935..6f868a454c 100644 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java +++ b/providers/softlayer/src/test/java/org/jclouds/softlayer/compute/SoftLayerComputeServiceAdapterLiveTest.java @@ -29,7 +29,6 @@ import org.jclouds.compute.domain.Template; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.domain.LoginCredentials; -import org.jclouds.net.IPSocket; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; import org.jclouds.softlayer.domain.ProductItem; @@ -41,6 +40,7 @@ import org.testng.annotations.BeforeGroups; import org.testng.annotations.Test; import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; import com.google.common.net.InetAddresses; @Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest") @@ -82,7 +82,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL } protected void doConnectViaSsh(VirtualGuest guest, LoginCredentials creds) { - SshClient ssh = view.utils().sshFactory().create(new IPSocket(guest.getPrimaryIpAddress(), 22), creds); + SshClient ssh = view.utils().sshFactory().create(HostAndPort.fromParts(guest.getPrimaryIpAddress(), 22), creds); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java index 0c57ddd652..e16e914873 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java @@ -22,7 +22,6 @@ import java.util.Map.Entry; import java.util.Properties; import org.jclouds.domain.LoginCredentials; -import org.jclouds.net.IPSocket; import org.jclouds.ssh.SshClient; import org.jclouds.trmk.ecloud.suppliers.TerremarkECloudInternetServiceAndPublicIpAddressSupplier; import org.jclouds.trmk.vcloud_0_8.TerremarkClientLiveTest; @@ -33,6 +32,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.VApp; import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants; import org.testng.annotations.Test; +import com.google.common.net.HostAndPort; + /** * Tests behavior of {@code TerremarkECloudClient} * @@ -56,7 +57,7 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest { @Override - protected SshClient getConnectionFor(IPSocket socket) { + protected SshClient getConnectionFor(HostAndPort socket) { return sshFactory.create(socket, LoginCredentials.builder().user("vcloud").password("TmrkCl0ud1s#1!").privateKey( key.getPrivateKey()).authenticateSudo(true).build()); }