Merge pull request #584 from mattstep/ipsocket-remove

Remove IPSocket class, replace with Guava's HostAndPort class.
This commit is contained in:
Adrian Cole 2012-04-26 07:48:35 -07:00
commit dfd84a0666
56 changed files with 205 additions and 285 deletions

View File

@ -28,12 +28,12 @@ import org.jclouds.cloudloadbalancers.predicates.LoadBalancerActive;
import org.jclouds.cloudloadbalancers.predicates.LoadBalancerDeleted; import org.jclouds.cloudloadbalancers.predicates.LoadBalancerDeleted;
import org.jclouds.loadbalancer.LoadBalancerServiceContext; import org.jclouds.loadbalancer.LoadBalancerServiceContext;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.net.HostAndPort;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -51,7 +51,7 @@ public class BaseCloudLoadBalancersClientLiveTest extends BaseViewLiveTest<LoadB
protected CloudLoadBalancersClient client; protected CloudLoadBalancersClient client;
protected RestContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> lbContext; protected RestContext<CloudLoadBalancersClient, CloudLoadBalancersAsyncClient> lbContext;
protected String[] regions = {}; protected String[] regions = {};
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
protected RetryablePredicate<LoadBalancer> loadBalancerActive; protected RetryablePredicate<LoadBalancer> loadBalancerActive;
protected RetryablePredicate<LoadBalancer> loadBalancerDeleted; protected RetryablePredicate<LoadBalancer> loadBalancerDeleted;

View File

@ -49,7 +49,6 @@ import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.SshClient; 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.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -79,7 +79,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
protected CloudServersClient client; protected CloudServersClient client;
protected SshClient.Factory sshFactory; protected SshClient.Factory sshFactory;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
@Override @Override
@ -89,7 +89,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
client = injector.getInstance(CloudServersClient.class); client = injector.getInstance(CloudServersClient.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 120, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger injector.injectMembers(socketOpen); // add logger
} }
@ -374,7 +374,7 @@ public class CloudServersClientLiveTest extends BaseComputeServiceContextLiveTes
} }
private void doCheckPass(Server newDetails, String pass) throws IOException { 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); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); 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 { 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); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build());
try { try {

View File

@ -46,7 +46,6 @@ import org.jclouds.cloudsigma.util.Servers;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; 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.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -81,7 +81,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
protected String vncPassword = "Il0veVNC"; protected String vncPassword = "Il0veVNC";
protected CloudSigmaClient client; protected CloudSigmaClient client;
protected RestContext<CloudSigmaClient, CloudSigmaAsyncClient> cloudSigmaContext; protected RestContext<CloudSigmaClient, CloudSigmaAsyncClient> cloudSigmaContext;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
protected Predicate<DriveInfo> driveNotClaimed; protected Predicate<DriveInfo> driveNotClaimed;
@ -94,7 +94,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
client = cloudSigmaContext.getApi(); client = cloudSigmaContext.getApi();
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
1, TimeUnit.SECONDS); 1, TimeUnit.SECONDS);
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), maxDriveImageTime, 1, socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
if (Strings.emptyToNull(imageId) == null) { if (Strings.emptyToNull(imageId) == null) {
@ -329,9 +329,9 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
@Test(dependsOnMethods = "testCreateAndStartServer") @Test(dependsOnMethods = "testCreateAndStartServer")
public void testConnectivity() throws Exception { public void testConnectivity() throws Exception {
Logger.getAnonymousLogger().info("awaiting vnc"); 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"); 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)); doConnectViaSsh(server, getSshCredentials(server));
} }
@ -389,7 +389,7 @@ public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest
protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException {
SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class) 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 { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");

View File

@ -32,7 +32,7 @@
//import org.jclouds.cloudstack.options.CreateInstanceOptions; //import org.jclouds.cloudstack.options.CreateInstanceOptions;
//import org.jclouds.domain.Credentials; //import org.jclouds.domain.Credentials;
//import org.jclouds.http.HttpRequest; //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.SshClient;
//import org.jclouds.ssh.jsch.config.JschSshClientModule; //import org.jclouds.ssh.jsch.config.JschSshClientModule;
//import org.testng.annotations.AfterGroups; //import org.testng.annotations.AfterGroups;
@ -79,7 +79,7 @@
// public void testConnectivity() throws Exception { // public void testConnectivity() throws Exception {
// Logger.getAnonymousLogger().info("awaiting ssh"); // Logger.getAnonymousLogger().info("awaiting ssh");
// // TODO // // TODO
// // assert socketTester.apply(new IPSocket(Iterables.get(instance.getPublicAddresses(), 0), // // assert socketTester.apply(HostAndPort.fromParts(Iterables.get(instance.getPublicAddresses(), 0),
// // 22)) : instance; // // 22)) : instance;
// // doConnectViaSsh(instance, getSshCredentials(instance)); // // doConnectViaSsh(instance, getSshCredentials(instance));
// } // }
@ -119,7 +119,7 @@
// //
// protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException { // protected void doConnectViaSsh(Instance instance, Credentials creds) throws IOException {
// SshClient ssh = Guice.createInjector(new JschSshClientModule()).getInstance(SshClient.Factory.class) // 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 { // try {
// ssh.connect(); // ssh.connect();
// ExecResponse hello = ssh.exec("echo hello"); // ExecResponse hello = ssh.exec("echo hello");

View File

@ -53,14 +53,13 @@ import org.jclouds.cloudstack.suppliers.GetCurrentUser;
import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser; import org.jclouds.cloudstack.suppliers.NetworksForCurrentUser;
import org.jclouds.cloudstack.suppliers.ZoneIdToZoneSupplier; import org.jclouds.cloudstack.suppliers.ZoneIdToZoneSupplier;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.ComputeTestUtils;
import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials; import org.jclouds.compute.ComputeServiceAdapter.NodeAndInitialCredentials;
import org.jclouds.compute.ComputeTestUtils;
import org.jclouds.compute.domain.Template; import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.logging.log4j.config.Log4JLoggingModule; import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.annotations.Identity;
import org.testng.annotations.AfterGroups; 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.cache.LoadingCache;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.net.HostAndPort;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -180,7 +180,7 @@ public class CloudStackComputeServiceAdapterLiveTest extends BaseCloudStackClien
loginCredentials = prioritizeCredentialsFromTemplate.apply(template, vm.getCredentials()); loginCredentials = prioritizeCredentialsFromTemplate.apply(template, vm.getCredentials());
assert InetAddresses.isInetAddress(address) : vm; assert InetAddresses.isInetAddress(address) : vm;
IPSocket socket = new IPSocket(address, 22); HostAndPort socket = HostAndPort.fromParts(address, 22);
checkSSH(socket); checkSSH(socket);
} }

View File

@ -52,7 +52,6 @@ import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeService;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.internal.BaseGenericComputeServiceContextLiveTest; import org.jclouds.compute.internal.BaseGenericComputeServiceContextLiveTest;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; 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.base.Predicates;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -156,7 +156,7 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte
protected CloudStackClient adminClient; protected CloudStackClient adminClient;
protected User user; protected User user;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
protected RetryablePredicate<Long> jobComplete; protected RetryablePredicate<Long> jobComplete;
protected RetryablePredicate<Long> adminJobComplete; protected RetryablePredicate<Long> adminJobComplete;
protected RetryablePredicate<VirtualMachine> virtualMachineRunning; protected RetryablePredicate<VirtualMachine> virtualMachineRunning;
@ -181,7 +181,7 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte
protected CloudStackGlobalClient globalAdminClient; protected CloudStackGlobalClient globalAdminClient;
protected User globalAdminUser; protected User globalAdminUser;
protected void checkSSH(IPSocket socket) { protected void checkSSH(HostAndPort socket) {
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, loginCredentials); SshClient client = sshFactory.create(socket, loginCredentials);
try { try {
@ -224,7 +224,7 @@ public class BaseCloudStackClientLiveTest extends BaseGenericComputeServiceConte
injector = Guice.createInjector(setupModules()); injector = Guice.createInjector(setupModules());
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 180, 1, 1, TimeUnit.SECONDS);
injector.injectMembers(socketTester); injector.injectMembers(socketTester);
jobComplete = new RetryablePredicate<Long>(new JobComplete(client), 1200, 1, 5, TimeUnit.SECONDS); jobComplete = new RetryablePredicate<Long>(new JobComplete(client), 1200, 1, 5, TimeUnit.SECONDS);
injector.injectMembers(jobComplete); injector.injectMembers(jobComplete);

View File

@ -36,13 +36,13 @@ import org.jclouds.cloudstack.domain.PublicIPAddress;
import org.jclouds.cloudstack.domain.VirtualMachine; import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.options.CreateFirewallRuleOptions; import org.jclouds.cloudstack.options.CreateFirewallRuleOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.net.HostAndPort;
/** /**
* Tests behavior of {@code FirewallClientLiveTest} * Tests behavior of {@code FirewallClientLiveTest}
@ -112,7 +112,7 @@ public class FirewallClientLiveTest extends BaseCloudStackClientLiveTest {
assertEquals(portForwardingRule.getProtocol(), PortForwardingRule.Protocol.TCP); assertEquals(portForwardingRule.getProtocol(), PortForwardingRule.Protocol.TCP);
checkPortForwardingRule(portForwardingRule); checkPortForwardingRule(portForwardingRule);
checkSSH(new IPSocket(ip.getIPAddress(), 22)); checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22));
} }
@Test(dependsOnMethods = "testCreatePortForwardingRule") @Test(dependsOnMethods = "testCreatePortForwardingRule")

View File

@ -35,13 +35,12 @@ import javax.annotation.Nullable;
import org.jclouds.cloudstack.domain.AsyncJob; import org.jclouds.cloudstack.domain.AsyncJob;
import org.jclouds.cloudstack.domain.JobResult; import org.jclouds.cloudstack.domain.JobResult;
import org.jclouds.cloudstack.domain.LoadBalancerRule; 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.Network;
import org.jclouds.cloudstack.domain.PublicIPAddress; import org.jclouds.cloudstack.domain.PublicIPAddress;
import org.jclouds.cloudstack.domain.VirtualMachine; 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.cloudstack.predicates.LoadBalancerRuleActive;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
import org.testng.annotations.AfterGroups; 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.Predicate;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.net.HostAndPort;
/** /**
* Tests behavior of {@code LoadBalancerClientLiveTest} * Tests behavior of {@code LoadBalancerClientLiveTest}
@ -155,7 +155,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
private void loopAndCheckSSH() throws IOException { private void loopAndCheckSSH() throws IOException {
for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate. for (int i = 0; i < 5; i++) {// retry loop TODO replace with predicate.
try { try {
checkSSH(new IPSocket(ip.getIPAddress(), 22)); checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22));
return; return;
} catch (SshException e) { } catch (SshException e) {
e.printStackTrace(); e.printStackTrace();
@ -176,7 +176,7 @@ public class LoadBalancerClientLiveTest extends BaseCloudStackClientLiveTest {
rule.getId(), vm.getId()))); rule.getId(), vm.getId())));
assertEquals(client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()).size(), 0); assertEquals(client.getLoadBalancerClient().listVirtualMachinesAssignedToLoadBalancerRule(rule.getId()).size(), 0);
assertEquals(rule.getState(), State.ADD); assertEquals(rule.getState(), State.ADD);
checkSSH(new IPSocket(ip.getIPAddress(), 22)); checkSSH(HostAndPort.fromParts(ip.getIPAddress(), 22));
} }
@AfterGroups(groups = "live") @AfterGroups(groups = "live")

View File

@ -33,7 +33,6 @@ import org.jclouds.cloudstack.domain.Zone;
import org.jclouds.cloudstack.options.AccountInDomainOptions; import org.jclouds.cloudstack.options.AccountInDomainOptions;
import org.jclouds.cloudstack.options.DeployVirtualMachineOptions; import org.jclouds.cloudstack.options.DeployVirtualMachineOptions;
import org.jclouds.cloudstack.options.ListSecurityGroupsOptions; import org.jclouds.cloudstack.options.ListSecurityGroupsOptions;
import org.jclouds.net.IPSocket;
import org.jclouds.util.Strings2; import org.jclouds.util.Strings2;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -41,6 +40,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
/** /**
* Tests behavior of {@code SecurityGroupClient} * Tests behavior of {@code SecurityGroupClient}
@ -178,7 +178,7 @@ public class SecurityGroupClientLiveTest extends BaseCloudStackClientLiveTest {
if (vm.getPassword() != null && !loginCredentials.hasPasswordOption()) if (vm.getPassword() != null && !loginCredentials.hasPasswordOption())
loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build(); loginCredentials = loginCredentials.toBuilder().password(vm.getPassword()).build();
// ingress port 22 // 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 // ingress icmp disabled as this is platform dependent and may actually
// just try tcp port 7 // just try tcp port 7
// assert InetAddress.getByName(vm.getIPAddress()).isReachable(1000) : vm; // assert InetAddress.getByName(vm.getIPAddress()).isReachable(1000) : vm;

View File

@ -53,7 +53,6 @@ import org.jclouds.cloudstack.options.ListNetworkOfferingsOptions;
import org.jclouds.cloudstack.options.ListNetworksOptions; import org.jclouds.cloudstack.options.ListNetworksOptions;
import org.jclouds.cloudstack.options.ListTemplatesOptions; import org.jclouds.cloudstack.options.ListTemplatesOptions;
import org.jclouds.cloudstack.options.ListVirtualMachinesOptions; import org.jclouds.cloudstack.options.ListVirtualMachinesOptions;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.util.InetAddresses2; import org.jclouds.util.InetAddresses2;
import org.testng.annotations.AfterGroups; 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.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Ordering; import com.google.common.collect.Ordering;
import com.google.common.net.HostAndPort;
import com.google.common.net.HostSpecifier; import com.google.common.net.HostSpecifier;
/** /**
@ -282,7 +282,7 @@ public class VirtualMachineClientLiveTest extends BaseCloudStackClientLiveTest {
assert HostSpecifier.isValid(vm.getIPAddress()); assert HostSpecifier.isValid(vm.getIPAddress());
if (!InetAddresses2.isPrivateIPAddress(vm.getIPAddress())) { if (!InetAddresses2.isPrivateIPAddress(vm.getIPAddress())) {
// not sure if the network is public or not, so we have to test // 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 socket %s%n", socket);
System.err.printf("testing ssh %s%n", socket); System.err.printf("testing ssh %s%n", socket);
checkSSH(socket); checkSSH(socket);

View File

@ -37,7 +37,6 @@ import org.jclouds.cloudstack.features.NATClientLiveTest;
import org.jclouds.cloudstack.features.VirtualMachineClientLiveTest; import org.jclouds.cloudstack.features.VirtualMachineClientLiveTest;
import org.jclouds.cloudstack.predicates.NetworkPredicates; import org.jclouds.cloudstack.predicates.NetworkPredicates;
import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult; import org.jclouds.cloudstack.strategy.BlockUntilJobCompletesAndReturnResult;
import org.jclouds.net.IPSocket;
import org.testng.annotations.AfterGroups; import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups; import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -45,6 +44,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheBuilder;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort;
/** /**
* Tests behavior of {@code StaticNATVirtualMachineInNetwork} * Tests behavior of {@code StaticNATVirtualMachineInNetwork}
@ -106,7 +106,7 @@ public class StaticNATVirtualMachineInNetworkLiveTest extends NATClientLiveTest
assertEquals(rule.getStartPort(), 22); assertEquals(rule.getStartPort(), 22);
assertEquals(rule.getProtocol(), "tcp"); assertEquals(rule.getProtocol(), "tcp");
checkRule(rule); checkRule(rule);
IPSocket socket = new IPSocket(ip.getIPAddress(), 22); HostAndPort socket = HostAndPort.fromParts(ip.getIPAddress(), 22);
checkSSH(socket); checkSSH(socket);
} }

View File

@ -32,7 +32,6 @@ import org.jclouds.deltacloud.domain.TransitionOnAction;
import org.jclouds.deltacloud.options.CreateInstanceOptions; import org.jclouds.deltacloud.options.CreateInstanceOptions;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
@ -40,6 +39,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -95,7 +95,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
@Test(dependsOnMethods = "testCreateInstance") @Test(dependsOnMethods = "testCreateInstance")
public void testConnectivity() throws Exception { public void testConnectivity() throws Exception {
Logger.getAnonymousLogger().info("awaiting ssh"); 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) { if (creds != null) {
Logger.getAnonymousLogger().info("will connect ssh"); Logger.getAnonymousLogger().info("will connect ssh");
doConnectViaSsh(instance, creds); doConnectViaSsh(instance, creds);
@ -136,7 +136,7 @@ public class DeltacloudClientLiveTest extends ReadOnlyDeltacloudClientLiveTest {
protected void doConnectViaSsh(Instance instance, LoginCredentials creds) throws IOException { protected void doConnectViaSsh(Instance instance, LoginCredentials creds) throws IOException {
SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create( 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 { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");

View File

@ -30,12 +30,11 @@ import org.jclouds.deltacloud.domain.DeltacloudCollection;
import org.jclouds.deltacloud.domain.HardwareProfile; import org.jclouds.deltacloud.domain.HardwareProfile;
import org.jclouds.deltacloud.domain.Image; import org.jclouds.deltacloud.domain.Image;
import org.jclouds.deltacloud.domain.Instance; import org.jclouds.deltacloud.domain.Instance;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.deltacloud.domain.Realm; import org.jclouds.deltacloud.domain.Realm;
import org.jclouds.deltacloud.domain.Transition; import org.jclouds.deltacloud.domain.Transition;
import org.jclouds.deltacloud.domain.Instance.State;
import org.jclouds.deltacloud.predicates.InstanceFinished; import org.jclouds.deltacloud.predicates.InstanceFinished;
import org.jclouds.deltacloud.predicates.InstanceRunning; import org.jclouds.deltacloud.predicates.InstanceRunning;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.sshj.config.SshjSshClientModule; 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.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.net.HostAndPort;
import com.google.inject.Module; import com.google.inject.Module;
/** /**
@ -64,7 +64,7 @@ public class ReadOnlyDeltacloudClientLiveTest extends BaseComputeServiceContextL
protected DeltacloudClient client; protected DeltacloudClient client;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
protected ImmutableMap<State, Predicate<Instance>> stateChanges; protected ImmutableMap<State, Predicate<Instance>> stateChanges;
@Override @Override
@ -72,7 +72,7 @@ public class ReadOnlyDeltacloudClientLiveTest extends BaseComputeServiceContextL
public void setupContext() { public void setupContext() {
super.setupContext(); super.setupContext();
client = view.unwrap(DeltacloudApiMetadata.CONTEXT_TOKEN).getApi(); client = view.unwrap(DeltacloudApiMetadata.CONTEXT_TOKEN).getApi();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 180, 1, TimeUnit.SECONDS);
stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(// stateChanges = ImmutableMap.<Instance.State, Predicate<Instance>> of(//
Instance.State.RUNNING, new RetryablePredicate<Instance>(new InstanceRunning(client), 600, 1, Instance.State.RUNNING, new RetryablePredicate<Instance>(new InstanceRunning(client), 600, 1,
TimeUnit.SECONDS),// TimeUnit.SECONDS),//

View File

@ -37,6 +37,7 @@ import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.BlockDevice;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.InstanceState; import org.jclouds.ec2.domain.InstanceState;
import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.IpProtocol; 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.PublicIpInstanceIdPair;
import org.jclouds.ec2.domain.Reservation; import org.jclouds.ec2.domain.Reservation;
import org.jclouds.ec2.domain.RunningInstance; import org.jclouds.ec2.domain.RunningInstance;
import org.jclouds.ec2.domain.Image.EbsBlockDevice;
import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior; import org.jclouds.ec2.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.ec2.predicates.InstanceHasIpAddress; import org.jclouds.ec2.predicates.InstanceHasIpAddress;
import org.jclouds.ec2.predicates.InstanceStateRunning; import org.jclouds.ec2.predicates.InstanceStateRunning;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.scriptbuilder.ScriptBuilder; 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.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -88,7 +88,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS
private String instanceId; private String instanceId;
private String address; private String address;
private RetryablePredicate<IPSocket> socketTester; private RetryablePredicate<HostAndPort> socketTester;
private RetryablePredicate<RunningInstance> hasIpTester; private RetryablePredicate<RunningInstance> hasIpTester;
private RetryablePredicate<RunningInstance> runningTester; private RetryablePredicate<RunningInstance> runningTester;
@ -102,7 +102,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS
TimeUnit.SECONDS); TimeUnit.SECONDS);
hasIpTester = new RetryablePredicate<RunningInstance>(new InstanceHasIpAddress(client), 180, 5, TimeUnit.SECONDS); hasIpTester = new RetryablePredicate<RunningInstance>(new InstanceHasIpAddress(client), 180, 5, TimeUnit.SECONDS);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 180, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 180, 1, TimeUnit.SECONDS);
} }
@Test(enabled = false) @Test(enabled = false)
@ -296,7 +296,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS
Thread.sleep(1000); Thread.sleep(1000);
instance = getInstance(instanceId); instance = getInstance(instanceId);
blockUntilWeCanSshIntoInstance(instance); 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()); LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build());
try { try {
ssh.connect(); ssh.connect();
@ -357,14 +357,14 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS
assert hasIpTester.apply(instance); assert hasIpTester.apply(instance);
System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); 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()); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName());
sshPing(instance); sshPing(instance);
System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); 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()); 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()); System.out.printf("%d: %s http service started%n", System.currentTimeMillis(), instance.getDnsName());
return instance; return instance;
} }
@ -401,7 +401,7 @@ public class CloudApplicationArchitecturesEC2ClientLiveTest extends BaseComputeS
} }
private void doCheckKey(String address) { 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()); LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build());
try { try {
ssh.connect(); ssh.connect();

View File

@ -39,6 +39,8 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.ec2.domain.Attachment; import org.jclouds.ec2.domain.Attachment;
import org.jclouds.ec2.domain.BlockDevice; import org.jclouds.ec2.domain.BlockDevice;
import org.jclouds.ec2.domain.Image; 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.InstanceState;
import org.jclouds.ec2.domain.InstanceType; import org.jclouds.ec2.domain.InstanceType;
import org.jclouds.ec2.domain.IpProtocol; 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.RunningInstance;
import org.jclouds.ec2.domain.Snapshot; import org.jclouds.ec2.domain.Snapshot;
import org.jclouds.ec2.domain.Volume; 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.domain.Volume.InstanceInitiatedShutdownBehavior;
import org.jclouds.ec2.predicates.InstanceStateRunning; import org.jclouds.ec2.predicates.InstanceStateRunning;
import org.jclouds.ec2.predicates.InstanceStateStopped; 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.ec2.predicates.VolumeAvailable;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.scriptbuilder.InitScript; 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.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -107,7 +107,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest
private KeyPair keyPair; private KeyPair keyPair;
private String securityGroupName; private String securityGroupName;
private RetryablePredicate<IPSocket> socketTester; private RetryablePredicate<HostAndPort> socketTester;
private RetryablePredicate<Attachment> attachTester; private RetryablePredicate<Attachment> attachTester;
private RetryablePredicate<Volume> volumeTester; private RetryablePredicate<Volume> volumeTester;
private RunningInstance instance; private RunningInstance instance;
@ -130,7 +130,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest
client = injector.getInstance(EC2Client.class); client = injector.getInstance(EC2Client.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 120, 1, TimeUnit.SECONDS);
VolumeAvailable volumeAvailable = injector.getInstance(VolumeAvailable.class); VolumeAvailable volumeAvailable = injector.getInstance(VolumeAvailable.class);
volumeTester = new RetryablePredicate<Volume>(volumeAvailable, 60, 1, TimeUnit.SECONDS); volumeTester = new RetryablePredicate<Volume>(volumeAvailable, 60, 1, TimeUnit.SECONDS);
@ -273,7 +273,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest
@Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume") @Test(enabled = false, dependsOnMethods = "testCreateAndAttachVolume")
void testBundleInstance() { 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()); LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build());
try { try {
ssh.connect(); ssh.connect();
@ -510,7 +510,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest
} }
private void doCheckKey(String address) { 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()); LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build());
try { try {
ssh.connect(); ssh.connect();
@ -538,7 +538,7 @@ public class EBSBootEC2ClientLiveTest extends BaseComputeServiceContextLiveTest
instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations)); instance = Iterables.getOnlyElement(Iterables.getOnlyElement(reservations));
System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), instance.getIpAddress()); 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()); System.out.printf("%d: %s ssh service started%n", System.currentTimeMillis(), instance.getDnsName());
sshPing(instance); sshPing(instance);
System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId()); System.out.printf("%d: %s ssh connection made%n", System.currentTimeMillis(), instance.getId());

View File

@ -54,7 +54,6 @@ import org.jclouds.ec2.services.ElasticBlockStoreClient;
import org.jclouds.ec2.services.InstanceClient; import org.jclouds.ec2.services.InstanceClient;
import org.jclouds.ec2.services.KeyPairClient; import org.jclouds.ec2.services.KeyPairClient;
import org.jclouds.ec2.services.SecurityGroupClient; import org.jclouds.ec2.services.SecurityGroupClient;
import org.jclouds.net.IPSocket;
import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.domain.Statements;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.util.InetAddresses2; 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.ImmutableSortedSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.net.HostAndPort;
import com.google.inject.Module; 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 // Check that the address is public and port 22 is accessible
String ip = Iterables.getOnlyElement(publicIps); String ip = Iterables.getOnlyElement(publicIps);
assertFalse(InetAddresses2.isPrivateIPAddress(ip)); 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)); 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 // check that there is an elastic ip correlating to it

View File

@ -43,7 +43,6 @@ import org.jclouds.elasticstack.domain.ServerStatus;
import org.jclouds.elasticstack.predicates.DriveClaimed; import org.jclouds.elasticstack.predicates.DriveClaimed;
import org.jclouds.elasticstack.util.Servers; import org.jclouds.elasticstack.util.Servers;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; 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.base.Strings;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.net.HostAndPort;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.inject.Guice; import com.google.inject.Guice;
@ -81,7 +81,7 @@ public class ElasticStackClientLiveTest
protected String vncPassword = "Il0veVNC"; protected String vncPassword = "Il0veVNC";
protected ElasticStackClient client; protected ElasticStackClient client;
protected RestContext<ElasticStackClient, ElasticStackAsyncClient> cloudStackContext; protected RestContext<ElasticStackClient, ElasticStackAsyncClient> cloudStackContext;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
protected Predicate<DriveInfo> driveNotClaimed; protected Predicate<DriveInfo> driveNotClaimed;
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
@ -93,7 +93,7 @@ public class ElasticStackClientLiveTest
client = cloudStackContext.getApi(); client = cloudStackContext.getApi();
driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, driveNotClaimed = new RetryablePredicate<DriveInfo>(Predicates.not(new DriveClaimed(client)), maxDriveImageTime,
1, TimeUnit.SECONDS); 1, TimeUnit.SECONDS);
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), maxDriveImageTime, 1, socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), maxDriveImageTime, 1,
TimeUnit.SECONDS); TimeUnit.SECONDS);
if (Strings.emptyToNull(imageId) == null) { if (Strings.emptyToNull(imageId) == null) {
@ -229,10 +229,10 @@ public class ElasticStackClientLiveTest
@Test(dependsOnMethods = "testCreateAndStartServer") @Test(dependsOnMethods = "testCreateAndStartServer")
public void testConnectivity() throws Exception { 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); Logger.getAnonymousLogger().info("awaiting vnc: " + vncsocket);
assert socketTester.apply(vncsocket) : server; 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); Logger.getAnonymousLogger().info("awaiting ssh: " + sshsocket);
assert socketTester.apply(sshsocket) : server; assert socketTester.apply(sshsocket) : server;
doConnectViaSsh(server, getSshCredentials(server)); doConnectViaSsh(server, getSshCredentials(server));
@ -290,7 +290,7 @@ public class ElasticStackClientLiveTest
protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException {
SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class).create( 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 { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");

View File

@ -36,7 +36,6 @@ import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket;
import org.jclouds.openstack.nova.domain.Flavor; import org.jclouds.openstack.nova.domain.Flavor;
import org.jclouds.openstack.nova.domain.Image; import org.jclouds.openstack.nova.domain.Image;
import org.jclouds.openstack.nova.domain.ImageStatus; 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.base.Predicate;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -72,7 +72,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
protected NovaClient client; protected NovaClient client;
protected SshClient.Factory sshFactory; protected SshClient.Factory sshFactory;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
@Override @Override
@ -82,7 +82,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
client = injector.getInstance(NovaClient.class); client = injector.getInstance(NovaClient.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 120, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger injector.injectMembers(socketOpen); // add logger
} }
@ -296,7 +296,7 @@ public class NovaClientLiveTest extends BaseComputeServiceContextLiveTest {
} }
private void doCheckPass(Server newDetails, String pass) throws IOException { 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); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build());

View File

@ -28,7 +28,6 @@ import static org.testng.Assert.assertNotNull;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.net.IPSocket;
import org.jclouds.vcloud.VCloudApiMetadata; import org.jclouds.vcloud.VCloudApiMetadata;
import org.jclouds.vcloud.VCloudMediaType; import org.jclouds.vcloud.VCloudMediaType;
import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
@ -41,6 +40,7 @@ import org.jclouds.vcloud.internal.BaseVCloudClientLiveTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables; 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 * 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", "")); assertEquals(apiOutput, script.replace("\n", ""));
} }
protected IPSocket getSocket(NodeMetadata node) { protected HostAndPort getSocket(NodeMetadata node) {
return new IPSocket(get(node.getPublicAddresses(), 0), 22); return HostAndPort.fromParts(get(node.getPublicAddresses(), 0), 22);
} }
} }

View File

@ -32,9 +32,9 @@ import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.Map.Entry;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
@ -43,14 +43,13 @@ import org.jclouds.cim.CIMPredicates;
import org.jclouds.cim.ResourceAllocationSettingData; import org.jclouds.cim.ResourceAllocationSettingData;
import org.jclouds.cim.ResourceAllocationSettingData.ResourceType; import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException;
import org.jclouds.ssh.SshClient.Factory; 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.Catalog;
import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem; import org.jclouds.trmk.vcloud_0_8.domain.CatalogItem;
import org.jclouds.trmk.vcloud_0_8.domain.CustomizationParameters; 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.ImmutableMap;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
@Test(groups = "live", singleThreaded = true) @Test(groups = "live", singleThreaded = true)
@ -93,7 +93,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
protected InternetService is; protected InternetService is;
protected Node node; protected Node node;
protected VApp vApp; protected VApp vApp;
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<HostAndPort> socketTester;
protected RetryablePredicate<URI> successTester; protected RetryablePredicate<URI> successTester;
protected Injector injector; protected Injector injector;
@ -429,7 +429,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
} }
protected void doCheckPass(String address) throws IOException { protected void doCheckPass(String address) throws IOException {
IPSocket socket = new IPSocket(address, 22); HostAndPort socket = HostAndPort.fromParts(address, 22);
System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), socket); System.out.printf("%d: %s awaiting ssh service to start%n", System.currentTimeMillis(), socket);
assert socketTester.apply(socket); assert socketTester.apply(socket);
@ -448,7 +448,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
} }
} }
protected abstract SshClient getConnectionFor(IPSocket socket); protected abstract SshClient getConnectionFor(HostAndPort socket);
@AfterGroups(groups = { "live" }) @AfterGroups(groups = { "live" })
void cleanup() throws InterruptedException, ExecutionException, TimeoutException { void cleanup() throws InterruptedException, ExecutionException, TimeoutException {
@ -485,7 +485,7 @@ public abstract class TerremarkClientLiveTest<S extends TerremarkVCloudClient, A
injector = view.utils().injector(); injector = view.utils().injector();
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
socketTester = new RetryablePredicate<IPSocket>(injector.getInstance(SocketOpen.class), 300, 10, TimeUnit.SECONDS);// make socketTester = new RetryablePredicate<HostAndPort>(injector.getInstance(SocketOpen.class), 300, 10, TimeUnit.SECONDS);// make
// it // it
// longer // longer
// then // then

View File

@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.compute.ComputeService; import org.jclouds.compute.ComputeService;
import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; 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.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
import com.google.inject.Module; import com.google.inject.Module;
@ -51,7 +51,7 @@ public abstract class BaseTerremarkClientLiveTest<S extends TerremarkVCloudClien
provider = "trmk-ecloud"; provider = "trmk-ecloud";
} }
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<HostAndPort> socketTester;
protected Factory sshFactory; protected Factory sshFactory;
protected S connection; protected S connection;
@ -61,7 +61,7 @@ public abstract class BaseTerremarkClientLiveTest<S extends TerremarkVCloudClien
public void setupContext() { public void setupContext() {
super.setupContext(); super.setupContext();
Injector injector = view.utils().injector(); Injector injector = view.utils().injector();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 300, 1, TimeUnit.SECONDS);
sshFactory = injector.getInstance(Factory.class); sshFactory = injector.getInstance(Factory.class);
connection = (S) RestContext.class.cast(view.unwrap()).getApi(); connection = (S) RestContext.class.cast(view.unwrap()).getApi();
} }

View File

@ -26,10 +26,10 @@ import javax.inject.Singleton;
import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen;
import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.net.HostAndPort;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -55,7 +55,7 @@ public class CreateSshClientOncePortIsListeningOnNode implements Function<NodeMe
checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId()); checkNotNull(node.getCredentials().identity, "no login identity found for node %s", node.getId());
checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node checkNotNull(node.getCredentials().credential, "no credential found for %s on node %s", node
.getCredentials().identity, node.getId()); .getCredentials().identity, node.getId());
IPSocket socket = ComputeServiceUtils.findReachableSocketOnNode(socketTester, node, node.getLoginPort()); HostAndPort socket = ComputeServiceUtils.findReachableSocketOnNode(socketTester, node, node.getLoginPort());
return sshFactory.create(socket, node.getCredentials()); return sshFactory.create(socket, node.getCredentials());
} }
} }

View File

@ -27,11 +27,11 @@ import javax.inject.Named;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.net.HostAndPort;
/** /**
* *
@ -41,7 +41,7 @@ import com.google.common.base.Predicate;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class RetryIfSocketNotYetOpen implements Predicate<IPSocket> { public class RetryIfSocketNotYetOpen implements Predicate<HostAndPort> {
@Resource @Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER) @Named(ComputeServiceConstants.COMPUTE_LOGGER)
private Logger logger = Logger.NULL; private Logger logger = Logger.NULL;
@ -84,11 +84,11 @@ public class RetryIfSocketNotYetOpen implements Predicate<IPSocket> {
} }
@Override @Override
public boolean apply(IPSocket socket) { public boolean apply(HostAndPort socket) {
logger.debug(">> blocking on socket %s for %d %s", socket, timeoutValue, timeoutUnits); logger.debug(">> blocking on socket %s for %d %s", socket, timeoutValue, timeoutUnits);
// Specify a retry period of 1s, expressed in the same time units. // Specify a retry period of 1s, expressed in the same time units.
long period = timeoutUnits.convert(1, TimeUnit.SECONDS); long period = timeoutUnits.convert(1, TimeUnit.SECONDS);
RetryablePredicate<IPSocket> tester = new RetryablePredicate<IPSocket>(socketTester, timeoutValue, period, timeoutUnits); RetryablePredicate<HostAndPort> tester = new RetryablePredicate<HostAndPort>(socketTester, timeoutValue, period, timeoutUnits);
boolean passed = tester.apply(socket); boolean passed = tester.apply(socket);
if (passed) if (passed)
logger.debug("<< socket %s opened", socket); logger.debug("<< socket %s opened", socket);

View File

@ -33,7 +33,6 @@ import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.Processor; import org.jclouds.compute.domain.Processor;
import org.jclouds.compute.domain.Volume; import org.jclouds.compute.domain.Volume;
import org.jclouds.compute.domain.internal.VolumeImpl; import org.jclouds.compute.domain.internal.VolumeImpl;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.annotations.Identity; 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.CacheLoader;
import com.google.common.cache.LoadingCache; import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
@ -128,10 +128,10 @@ public class StubComputeServiceDependenciesModule extends AbstractModule {
} }
@Override @Override
public boolean apply(IPSocket input) { public boolean apply(HostAndPort input) {
if (input.getAddress().indexOf(publicIpPrefix) == -1) if (input.getHostText().indexOf(publicIpPrefix) == -1)
return false; return false;
String id = input.getAddress().replace(publicIpPrefix, ""); String id = input.getHostText().replace(publicIpPrefix, "");
NodeMetadata node = nodes.get(id); NodeMetadata node = nodes.get(id);
return node != null && node.getState() == NodeState.RUNNING; return node != null && node.getState() == NodeState.RUNNING;
} }

View File

@ -30,8 +30,8 @@ import static org.jclouds.scriptbuilder.domain.Statements.pipeHttpResponseToBash
import java.net.URI; import java.net.URI;
import java.util.Formatter; import java.util.Formatter;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.jclouds.compute.ComputeServiceContext; 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.domain.Volume;
import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen;
import org.jclouds.http.HttpRequest; import org.jclouds.http.HttpRequest;
import org.jclouds.net.IPSocket;
import org.jclouds.scriptbuilder.domain.Statement; import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.domain.Statements;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
/** /**
@ -165,17 +165,17 @@ public class ComputeServiceUtils {
return org.jclouds.rest.Providers.getSupportedProvidersOfType(TypeToken.of(ComputeServiceContext.class)); 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) { final int port) {
checkNodeHasIps(node); checkNodeHasIps(node);
IPSocket socket = null; HostAndPort socket = null;
try { try {
socket = find(transform(concat(node.getPublicAddresses(), node.getPrivateAddresses()), socket = find(transform(concat(node.getPublicAddresses(), node.getPrivateAddresses()),
new Function<String, IPSocket>() { new Function<String, HostAndPort>() {
@Override @Override
public IPSocket apply(String from) { public HostAndPort apply(String from) {
return new IPSocket(from, port); return HostAndPort.fromParts(from, port);
} }
}), socketTester); }), socketTester);
} catch (NoSuchElementException e) { } catch (NoSuchElementException e) {

View File

@ -23,7 +23,8 @@ import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket;
import com.google.common.net.HostAndPort;
/** /**
* @author Adrian Cole * @author Adrian Cole
@ -35,12 +36,12 @@ public interface SshClient {
/** /**
* To be removed in jclouds 1.5.0 * To be removed in jclouds 1.5.0
* *
* @see #create(IPSocket, LoginCredentials) * @see #create(com.google.common.net.HostAndPort, LoginCredentials)
*/ */
@Deprecated @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);
} }

View File

@ -25,7 +25,7 @@
org.jclouds.domain.Credentials org.jclouds.domain.Credentials
org.jclouds.domain.LoginCredentials org.jclouds.domain.LoginCredentials
org.jclouds.io.Payload org.jclouds.io.Payload
org.jclouds.net.IPSocket com.google.common.net.HostAndPort
org.jclouds.compute.domain.ExecResponse)) org.jclouds.compute.domain.ExecResponse))
(defn instantiate [impl-class & args] (defn instantiate [impl-class & args]
@ -67,7 +67,7 @@
(^void put [this ^String path ^String content]) (^void put [this ^String path ^String content])
(^void put [this ^String path ^org.jclouds.io.Payload content]) (^void put [this ^String path ^org.jclouds.io.Payload content])
(getUsername [this] username) (getUsername [this] username)
(getHostAddress [this] (.getAddress socket)) ) (getHostAddress [this] (.getHostText socket)) )
(defn no-op-ssh-client (defn no-op-ssh-client
[socket username password] [socket username password]
@ -79,11 +79,11 @@
org.jclouds.ssh.SshClient$Factory org.jclouds.ssh.SshClient$Factory
(^org.jclouds.ssh.SshClient (^org.jclouds.ssh.SshClient
create create
[_ ^IPSocket socket ^Credentials credentials] [_ ^HostAndPort socket ^Credentials credentials]
(factory-fn socket (.identity credentials) (.credential credentials))) (factory-fn socket (.identity credentials) (.credential credentials)))
(^org.jclouds.ssh.SshClient (^org.jclouds.ssh.SshClient
create create
[_ ^IPSocket socket ^LoginCredentials credentials] [_ ^HostAndPort socket ^LoginCredentials credentials]
(factory-fn socket (.identity credentials) (.credential credentials))) (factory-fn socket (.identity credentials) (.credential credentials)))
) )

View File

@ -39,7 +39,6 @@ import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
import org.jclouds.crypto.Pems; import org.jclouds.crypto.Pems;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException; 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.Suppliers;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Module; import com.google.inject.Module;
@ -80,13 +80,13 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
protected void buildSocketTester() { protected void buildSocketTester() {
SocketOpen socketOpen = createMock(SocketOpen.class); 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 // 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); replay(socketOpen);
preciseSocketTester = socketTester = new RetryablePredicate<IPSocket>(socketOpen, 1, 1, TimeUnit.MILLISECONDS); preciseSocketTester = socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 1, 1, TimeUnit.MILLISECONDS);
} }
@Override @Override
@ -140,26 +140,26 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
SshClient client5 = createMock(SshClient.class); SshClient client5 = createMock(SshClient.class);
expect( 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); LoginCredentials.builder().user("root").password("password1").build())).andReturn(client1);
expect( 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) LoginCredentials.builder().user("web").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client1New)
.times(10); .times(10);
runScriptAndService(client1, client1New); runScriptAndService(client1, client1New);
expect( 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) LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2)
.times(4); .times(4);
expect( 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); LoginCredentials.builder().user("root").password("password2").build())).andReturn(client2New);
expect( 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); LoginCredentials.builder().user("foo").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())).andReturn(client2Foo);
expect( 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( LoginCredentials.builder().user("root").password("romeo").build())).andThrow(
new AuthorizationException("Auth fail", null)); new AuthorizationException("Auth fail", null));
@ -200,15 +200,15 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
client2Foo.disconnect(); client2Foo.disconnect();
expect( 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) LoginCredentials.builder().user("root").password("password3").build())).andReturn(client3)
.times(2); .times(2);
expect( 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) LoginCredentials.builder().user("root").password("password4").build())).andReturn(client4)
.times(2); .times(2);
expect( 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) LoginCredentials.builder().user("root").password("password5").build())).andReturn(client5)
.times(2); .times(2);
@ -217,23 +217,23 @@ public class StubComputeServiceIntegrationTest extends BaseComputeServiceLiveTes
runScriptAndInstallSsh(client5, "bootstrap", 5); runScriptAndInstallSsh(client5, "bootstrap", 5);
expect( 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()))) eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())))
.andReturn(client1); .andReturn(client1);
expect( 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()))) eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())))
.andReturn(client2); .andReturn(client2);
expect( 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()))) eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())))
.andReturn(client3); .andReturn(client3);
expect( 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()))) eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())))
.andReturn(client4); .andReturn(client4);
expect( 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()))) eq(LoginCredentials.builder().user("defaultAdminUsername").privateKey(Pems.PRIVATE_PKCS1_MARKER).build())))
.andReturn(client5); .andReturn(client5);

View File

@ -50,10 +50,10 @@ import static org.testng.Assert.assertNotNull;
import java.io.IOException; import java.io.IOException;
import java.util.Collection; import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.Map.Entry;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -84,7 +84,6 @@ import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LocationScope; import org.jclouds.domain.LocationScope;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.rest.AuthorizationException; 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.ImmutableMap;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.inject.Module; import com.google.inject.Module;
@ -117,8 +117,8 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
protected String group; protected String group;
protected Predicate<IPSocket> socketTester; protected Predicate<HostAndPort> socketTester;
protected Predicate<IPSocket> preciseSocketTester; protected Predicate<HostAndPort> preciseSocketTester;
protected SortedSet<NodeMetadata> nodes; protected SortedSet<NodeMetadata> nodes;
protected ComputeService client; protected ComputeService client;
@ -151,12 +151,12 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
protected void buildSocketTester() { protected void buildSocketTester() {
SocketOpen socketOpen = view.utils().injector().getInstance(SocketOpen.class); SocketOpen socketOpen = view.utils().injector().getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 60, 1, TimeUnit.SECONDS);
// wait a maximum of 60 seconds for port 8080 to open. // wait a maximum of 60 seconds for port 8080 to open.
long maxWait = TimeUnit.SECONDS.toMillis(60); long maxWait = TimeUnit.SECONDS.toMillis(60);
long interval = 50; long interval = 50;
// get more precise than default socket tester // get more precise than default socket tester
preciseSocketTester = new RetryablePredicate<IPSocket>(socketOpen, maxWait, interval, interval, preciseSocketTester = new RetryablePredicate<HostAndPort>(socketOpen, maxWait, interval, interval,
TimeUnit.MILLISECONDS); TimeUnit.MILLISECONDS);
} }
@Override @Override
@ -579,7 +579,7 @@ public abstract class BaseComputeServiceLiveTest extends BaseComputeServiceConte
stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); stats.backgroundProcessMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);
watch.reset().start(); 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, 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")); node, init(node, processName, "stdout"), init(node, processName, "stderr"));
stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS); stats.socketOpenMilliseconds = watch.elapsedTime(TimeUnit.MILLISECONDS);

View File

@ -26,9 +26,10 @@ import java.util.concurrent.TimeUnit;
import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
/** /**
* Tests timeout behavior of {@link RetryIfSocketNotYetOpen} predicate. * Tests timeout behavior of {@link RetryIfSocketNotYetOpen} predicate.
@ -36,7 +37,7 @@ import org.testng.annotations.Test;
public class RetryIfSocketNotYetOpenTest { public class RetryIfSocketNotYetOpenTest {
private static final Logger logger = Logger.NULL; 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 @Test
public void fromConstructor() { public void fromConstructor() {
@ -70,7 +71,7 @@ public class RetryIfSocketNotYetOpenTest {
doAsserts(uninitialised, socket, false, 0, 500); 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(); long startTime = System.currentTimeMillis();
boolean result = predicate.apply(socket); boolean result = predicate.apply(socket);
long elapsedTime = System.currentTimeMillis() - startTime; long elapsedTime = System.currentTimeMillis() - startTime;

View File

@ -18,9 +18,10 @@
*/ */
package org.jclouds.compute.predicates; package org.jclouds.compute.predicates;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import com.google.common.net.HostAndPort;
/** /**
* For use in unit tests, e.g. {@link RetryIfSocketNotYetOpenTest}. * For use in unit tests, e.g. {@link RetryIfSocketNotYetOpenTest}.
@ -28,11 +29,11 @@ import org.jclouds.predicates.SocketOpen;
public class SocketOpenPredicates { public class SocketOpenPredicates {
public static final SocketOpen alwaysSucceed = new SocketOpen() { 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() { public static final SocketOpen alwaysFail = new SocketOpen() {
@Override public boolean apply(IPSocket socket) { return false; } @Override public boolean apply(HostAndPort socket) { return false; }
}; };
} }

View File

@ -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 + "]";
}
}

View File

@ -27,8 +27,8 @@ import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import com.google.common.net.HostAndPort;
import com.google.inject.Inject; import com.google.inject.Inject;
/** /**
@ -48,8 +48,8 @@ public class InetSocketAddressConnect implements SocketOpen {
private int timeout = 2000; private int timeout = 2000;
@Override @Override
public boolean apply(IPSocket socketA) { public boolean apply(HostAndPort socketA) {
InetSocketAddress socketAddress = new InetSocketAddress(socketA.getAddress(), socketA InetSocketAddress socketAddress = new InetSocketAddress(socketA.getHostText(), socketA
.getPort()); .getPort());
Socket socket = null; Socket socket = null;
try { try {

View File

@ -18,9 +18,8 @@
*/ */
package org.jclouds.predicates; package org.jclouds.predicates;
import org.jclouds.net.IPSocket;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.net.HostAndPort;
import com.google.inject.ImplementedBy; import com.google.inject.ImplementedBy;
/** /**
@ -30,6 +29,6 @@ import com.google.inject.ImplementedBy;
* @author Adrian Cole * @author Adrian Cole
*/ */
@ImplementedBy(SocketOpenUnsupported.class) @ImplementedBy(SocketOpenUnsupported.class)
public interface SocketOpen extends Predicate<IPSocket> { public interface SocketOpen extends Predicate<HostAndPort> {
} }

View File

@ -20,7 +20,7 @@ package org.jclouds.predicates;
import javax.inject.Singleton; 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 { public class SocketOpenUnsupported implements SocketOpen {
@Override @Override
public boolean apply(IPSocket socketA) { public boolean apply(HostAndPort socketA) {
throw new UnsupportedOperationException("socket testing not configured"); throw new UnsupportedOperationException("socket testing not configured");
} }

View File

@ -48,7 +48,6 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
@ -122,10 +121,10 @@ public class JschSshClient implements SshClient {
final String user; final String user;
final String host; final String host;
public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, public JschSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, HostAndPort socket,
LoginCredentials loginCredentials, int timeout) { LoginCredentials loginCredentials, int timeout) {
this.user = checkNotNull(loginCredentials, "loginCredentials").getUser(); 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(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort());
checkArgument(loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null, checkArgument(loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null,
"you must specify a password or a key"); "you must specify a password or a key");

View File

@ -24,13 +24,13 @@ import org.jclouds.Constants;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.ConfiguresSshClient; import org.jclouds.ssh.ConfiguresSshClient;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.JschSshClient; import org.jclouds.ssh.jsch.JschSshClient;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -64,14 +64,14 @@ public class JschSshClientModule extends AbstractModule {
} }
@Override @Override
public SshClient create(IPSocket socket, LoginCredentials credentials) { public SshClient create(HostAndPort socket, LoginCredentials credentials) {
SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, credentials, timeout); SshClient client = new JschSshClient(backoffLimitedRetryHandler, socket, credentials, timeout);
injector.injectMembers(client);// add logger injector.injectMembers(client);// add logger
return client; return client;
} }
@Override @Override
public SshClient create(IPSocket socket, Credentials credentials) { public SshClient create(HostAndPort socket, Credentials credentials) {
return create(socket, LoginCredentials.fromCredentials(credentials)); return create(socket, LoginCredentials.fromCredentials(credentials));
} }
} }

View File

@ -36,7 +36,6 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.jclouds.util.Strings2; 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.Strings;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.common.net.HostAndPort;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -136,10 +136,10 @@ public class JschSshClientLiveTest {
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection; SshClient connection;
if (Strings.emptyToNull(sshKeyFile) != null) { 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()); .privateKey(Strings2.toStringAndClose(new FileInputStream(sshKeyFile))).build());
} else { } else {
connection = factory.create(new IPSocket(sshHost, port), connection = factory.create(HostAndPort.fromParts(sshHost, port),
LoginCredentials.builder().user(sshUser).password(sshPass).build()); LoginCredentials.builder().user(sshUser).password(sshPass).build());
} }
connection.connect(); connection.connect();

View File

@ -27,13 +27,13 @@ import java.util.Properties;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.config.JschSshClientModule; import org.jclouds.ssh.jsch.config.JschSshClientModule;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -68,7 +68,7 @@ public class JschSshClientTest {
} }
}, new SLF4JLoggingModule()); }, new SLF4JLoggingModule());
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); 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())); .builder().user("username").password("password").build()));
return ssh; return ssh;
} }

View File

@ -22,11 +22,11 @@ import java.net.UnknownHostException;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.jsch.JschSshClient; import org.jclouds.ssh.jsch.JschSshClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -42,7 +42,7 @@ public class JschSshClientModuleTest {
Injector i = Guice.createInjector(new JschSshClientModule(), new SLF4JLoggingModule()); Injector i = Guice.createInjector(new JschSshClientModule(), new SLF4JLoggingModule());
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); 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()); .password("password").build());
assert connection instanceof JschSshClient; assert connection instanceof JschSshClient;
} }

View File

@ -63,7 +63,6 @@ import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.ssh.SshException; import org.jclouds.ssh.SshException;
@ -142,10 +141,10 @@ public class SshjSshClient implements SshClient {
private final BackoffLimitedRetryHandler backoffLimitedRetryHandler; private final BackoffLimitedRetryHandler backoffLimitedRetryHandler;
public SshjSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, IPSocket socket, public SshjSshClient(BackoffLimitedRetryHandler backoffLimitedRetryHandler, HostAndPort socket,
LoginCredentials loginCredentials, int timeout) { LoginCredentials loginCredentials, int timeout) {
this.user = checkNotNull(loginCredentials, "loginCredentials").getUser(); 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(socket.getPort() > 0, "ssh port must be greater then zero" + socket.getPort());
checkArgument(loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null, checkArgument(loginCredentials.getPassword() != null || loginCredentials.getPrivateKey() != null,
"you must specify a password or a key"); "you must specify a password or a key");

View File

@ -24,13 +24,13 @@ import org.jclouds.Constants;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.handlers.BackoffLimitedRetryHandler; import org.jclouds.http.handlers.BackoffLimitedRetryHandler;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.ConfiguresSshClient; import org.jclouds.ssh.ConfiguresSshClient;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.SshjSshClient; import org.jclouds.sshj.SshjSshClient;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -64,14 +64,14 @@ public class SshjSshClientModule extends AbstractModule {
} }
@Override @Override
public SshClient create(IPSocket socket, LoginCredentials credentials) { public SshClient create(HostAndPort socket, LoginCredentials credentials) {
SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout); SshClient client = new SshjSshClient(backoffLimitedRetryHandler, socket, credentials, timeout);
injector.injectMembers(client);// add logger injector.injectMembers(client);// add logger
return client; return client;
} }
@Override @Override
public SshClient create(IPSocket socket, Credentials credentials) { public SshClient create(HostAndPort socket, Credentials credentials) {
return create(socket, LoginCredentials.fromCredentials(credentials)); return create(socket, LoginCredentials.fromCredentials(credentials));
} }
} }

View File

@ -36,7 +36,6 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.io.Payload; import org.jclouds.io.Payload;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
import org.jclouds.util.Strings2; 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.Strings;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.common.net.HostAndPort;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -135,10 +135,10 @@ public class SshjSshClientLiveTest {
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); SshClient.Factory factory = i.getInstance(SshClient.Factory.class);
SshClient connection; SshClient connection;
if (Strings.emptyToNull(sshKeyFile) != null) { 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()); .privateKey(Strings2.toStringAndClose(new FileInputStream(sshKeyFile))).build());
} else { } else {
connection = factory.create(new IPSocket(sshHost, port), connection = factory.create(HostAndPort.fromParts(sshHost, port),
LoginCredentials.builder().user(sshUser).password(sshPass).build()); LoginCredentials.builder().user(sshUser).password(sshPass).build());
} }
connection.connect(); connection.connect();

View File

@ -42,7 +42,6 @@ import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.BufferLogger; import org.jclouds.logging.BufferLogger;
import org.jclouds.logging.BufferLogger.Record; import org.jclouds.logging.BufferLogger.Record;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.rest.AuthorizationException; import org.jclouds.rest.AuthorizationException;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.config.SshjSshClientModule; import org.jclouds.sshj.config.SshjSshClientModule;
@ -50,6 +49,7 @@ import org.testng.Assert;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -83,7 +83,7 @@ public class SshjSshClientTest {
}, new SLF4JLoggingModule()); }, new SLF4JLoggingModule());
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); 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())); .builder().user("username").password("password").build()));
return ssh; return ssh;
} }

View File

@ -20,11 +20,11 @@ package org.jclouds.sshj.config;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.sshj.SshjSshClient; import org.jclouds.sshj.SshjSshClient;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Injector; import com.google.inject.Injector;
@ -40,7 +40,7 @@ public class SshjSshClientModuleTest {
Injector i = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule()); Injector i = Guice.createInjector(new SshjSshClientModule(), new SLF4JLoggingModule());
SshClient.Factory factory = i.getInstance(SshClient.Factory.class); 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()); .password("password").build());
assert connection instanceof SshjSshClient; assert connection instanceof SshjSshClient;
} }

View File

@ -63,7 +63,7 @@ public class IpClientLiveTest extends BaseGleSYSClientLiveTest {
assertEquals(ipDetails.getIpversion(), "4"); assertEquals(ipDetails.getIpversion(), "4");
// TODO: Ask Glesys to include address in response for OpenVZ? // TODO: Ask Glesys to include address in response for OpenVZ?
// assertEquals(ipDetails.getAddress(), openVzIp); // assertEquals(ipDetails.getHostText(), openVzIp);
} }
@Test @Test

View File

@ -28,7 +28,6 @@ import org.jclouds.cim.OSType;
import org.jclouds.compute.domain.CIMOperatingSystem; import org.jclouds.compute.domain.CIMOperatingSystem;
import org.jclouds.compute.domain.ExecResponse; import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.savvis.vpdc.domain.Network; 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;
import com.google.common.collect.ImmutableSet.Builder; import com.google.common.collect.ImmutableSet.Builder;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
@Test(groups = "live") @Test(groups = "live")
public class VMClientLiveTest extends BaseVPDCClientLiveTest { public class VMClientLiveTest extends BaseVPDCClientLiveTest {
private VMClient client; private VMClient client;
private VM vm; private VM vm;
private RetryablePredicate<IPSocket> socketTester; private RetryablePredicate<HostAndPort> socketTester;
private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider private String username = checkNotNull(System.getProperty("test." + provider + ".loginUser"), "test." + provider
+ ".loginUser"); + ".loginUser");
@ -66,7 +66,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
public void setupContext() { public void setupContext() {
super.setupContext(); super.setupContext();
client = restContext.getApi().getVMClient(); client = restContext.getApi().getVMClient();
socketTester = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);// make socketTester = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 130, 10, TimeUnit.SECONDS);// make
} }
private String billingSiteId; private String billingSiteId;
@ -277,7 +277,7 @@ public class VMClientLiveTest extends BaseVPDCClientLiveTest {
assert clonedVM.getHref() != null : clonedVM; assert clonedVM.getHref() != null : clonedVM;
} }
protected void checkSSH(IPSocket socket) { protected void checkSSH(HostAndPort socket) {
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = view.utils().sshFactory() SshClient client = view.utils().sshFactory()
.create(socket, LoginCredentials.builder().user(username).password(password).build()); .create(socket, LoginCredentials.builder().user(username).password(password).build());

View File

@ -34,7 +34,6 @@ import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.virtualbox.domain.BridgedIf; import org.jclouds.virtualbox.domain.BridgedIf;
import org.jclouds.virtualbox.statements.GetIPAddressFromMAC; 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.Splitter;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.inject.Inject; import com.google.inject.Inject;
@Singleton @Singleton
@ -114,7 +114,7 @@ public class IMachineToSshClient implements Function<IMachine, SshClient> {
checkNotNull(clientIpAddress, "clientIpAddress"); checkNotNull(clientIpAddress, "clientIpAddress");
client = sshClientFactory.create( client = sshClientFactory.create(
new IPSocket(clientIpAddress, Integer.parseInt(sshPort)), HostAndPort.fromParts(clientIpAddress, Integer.parseInt(sshPort)),
loginCredentials); loginCredentials);
checkNotNull(client); checkNotNull(client);
return client; return client;

View File

@ -37,7 +37,6 @@ import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.location.Provider; import org.jclouds.location.Provider;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
import org.jclouds.net.IPSocket;
import org.jclouds.rest.annotations.Credential; import org.jclouds.rest.annotations.Credential;
import org.jclouds.rest.annotations.Identity; import org.jclouds.rest.annotations.Identity;
import org.jclouds.scriptbuilder.domain.Statements; 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.Function;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.net.HostAndPort;
@Singleton @Singleton
public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager> { public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager> {
@ -78,7 +78,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
public synchronized void start() { public synchronized void start() {
URI provider = providerSupplier.get(); 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"); logger.debug("disabling password access");
runScriptOnNodeFactory.create(host.get(), Statements.exec("VBoxManage setproperty websrvauthlibrary null"), runScriptOnNodeFactory.create(host.get(), Statements.exec("VBoxManage setproperty websrvauthlibrary null"),
runAsRoot(false).wrapInInitScript(false)).init().call(); runAsRoot(false).wrapInInitScript(false)).init().call();
@ -87,7 +87,7 @@ public class StartVBoxIfNotAlreadyRunning implements Supplier<VirtualBoxManager>
runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv), runScriptOnNodeFactory.create(host.get(), Statements.exec(vboxwebsrv),
runAsRoot(false).wrapInInitScript(false).blockOnComplete(false).nameTask("vboxwebsrv")).init().call(); 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"); throw new RuntimeException("could not connect to virtualbox");
} }
} }

View File

@ -36,7 +36,6 @@ import org.jclouds.compute.domain.NodeMetadataBuilder;
import org.jclouds.compute.domain.NodeState; import org.jclouds.compute.domain.NodeState;
import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen; import org.jclouds.compute.predicates.RetryIfSocketNotYetOpen;
import org.jclouds.net.IPSocket;
import org.jclouds.scriptbuilder.domain.Statements; import org.jclouds.scriptbuilder.domain.Statements;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.virtualbox_4_1.VirtualBoxManager; 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.Function;
import com.google.common.base.Functions; import com.google.common.base.Functions;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import com.google.common.net.HostAndPort;
@Test(groups = "live", singleThreaded = true, testName = "StartVBoxIfNotAlreadyRunningLiveTest") @Test(groups = "live", singleThreaded = true, testName = "StartVBoxIfNotAlreadyRunningLiveTest")
public class StartVBoxIfNotAlreadyRunningLiveTest { public class StartVBoxIfNotAlreadyRunningLiveTest {
@ -59,7 +59,7 @@ public class StartVBoxIfNotAlreadyRunningLiveTest {
String identity = "adminstrator"; String identity = "adminstrator";
String credential = "12345"; String credential = "12345";
expect(client.seconds(3)).andReturn(client); 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(), "", ""); manager.connect(provider.toASCIIString(), "", "");
expectLastCall().anyTimes(); expectLastCall().anyTimes();
@ -87,7 +87,7 @@ public class StartVBoxIfNotAlreadyRunningLiveTest {
String credential = "12345"; String credential = "12345";
expect(client.seconds(3)).andReturn(client); 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( expect(
runScriptOnNodeFactory.create(host, Statements.exec("VBoxManage setproperty websrvauthlibrary null"), runScriptOnNodeFactory.create(host, Statements.exec("VBoxManage setproperty websrvauthlibrary null"),
runAsRoot(false).wrapInInitScript(false))).andReturn(runScriptOnNode); runAsRoot(false).wrapInInitScript(false))).andReturn(runScriptOnNode);

View File

@ -39,7 +39,6 @@ import org.jclouds.compute.predicates.NodePredicates;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.domain.LoginCredentials.Builder; import org.jclouds.domain.LoginCredentials.Builder;
import org.jclouds.loadbalancer.domain.LoadBalancerMetadata; import org.jclouds.loadbalancer.domain.LoadBalancerMetadata;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
@ -49,6 +48,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.google.inject.Guice; import com.google.inject.Guice;
import com.google.inject.Module; import com.google.inject.Module;
@ -95,7 +95,7 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseViewLiveTest<L
protected SshClient.Factory sshFactory; protected SshClient.Factory sshFactory;
protected String group; protected String group;
protected RetryablePredicate<IPSocket> socketTester; protected RetryablePredicate<HostAndPort> socketTester;
protected Set<? extends NodeMetadata> nodes; protected Set<? extends NodeMetadata> nodes;
protected Template template; protected Template template;
protected Map<String, String> keyPair; protected Map<String, String> keyPair;
@ -139,7 +139,7 @@ public abstract class BaseLoadBalancerServiceLiveTest extends BaseViewLiveTest<L
protected void buildSocketTester() { protected void buildSocketTester() {
SocketOpen socketOpen = Guice.createInjector(getSshModule()).getInstance(SocketOpen.class); SocketOpen socketOpen = Guice.createInjector(getSshModule()).getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 60, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 60, 1, TimeUnit.SECONDS);
} }
abstract protected Module getSshModule(); abstract protected Module getSshModule();

View File

@ -53,7 +53,6 @@ import org.jclouds.gogrid.options.GetImageListOptions;
import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted; import org.jclouds.gogrid.predicates.LoadBalancerLatestJobCompleted;
import org.jclouds.gogrid.predicates.ServerLatestJobCompleted; import org.jclouds.gogrid.predicates.ServerLatestJobCompleted;
import org.jclouds.javax.annotation.Nullable; import org.jclouds.javax.annotation.Nullable;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.InetSocketAddressConnect; import org.jclouds.predicates.InetSocketAddressConnect;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.rest.RestContext; import org.jclouds.rest.RestContext;
@ -66,6 +65,7 @@ import org.testng.annotations.Test;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
/** /**
* End to end live test for GoGrid * End to end live test for GoGrid
@ -341,9 +341,9 @@ public class GoGridLiveTestDisabled extends BaseComputeServiceContextLiveTest {
LoginCredentials instanceCredentials = LoginCredentials.fromCredentials(credsMap.get(createdServer.getName())); LoginCredentials instanceCredentials = LoginCredentials.fromCredentials(credsMap.get(createdServer.getName()));
assertNotNull(instanceCredentials); assertNotNull(instanceCredentials);
IPSocket socket = new IPSocket(createdServer.getIp().getIp(), 22); HostAndPort socket = HostAndPort.fromParts(createdServer.getIp().getIp(), 22);
RetryablePredicate<IPSocket> socketOpen = new RetryablePredicate<IPSocket>(new InetSocketAddressConnect(), 180, RetryablePredicate<HostAndPort> socketOpen = new RetryablePredicate<HostAndPort>(new InetSocketAddressConnect(), 180,
5, TimeUnit.SECONDS); 5, TimeUnit.SECONDS);
socketOpen.apply(socket); socketOpen.apply(socket);

View File

@ -32,7 +32,6 @@ import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.http.HttpResponseException; import org.jclouds.http.HttpResponseException;
import org.jclouds.io.Payloads; import org.jclouds.io.Payloads;
import org.jclouds.net.IPSocket;
import org.jclouds.predicates.RetryablePredicate; import org.jclouds.predicates.RetryablePredicate;
import org.jclouds.predicates.SocketOpen; import org.jclouds.predicates.SocketOpen;
import org.jclouds.slicehost.domain.Flavor; 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.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.inject.Injector; import com.google.inject.Injector;
/** /**
@ -62,7 +62,7 @@ public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest {
protected SlicehostClient client; protected SlicehostClient client;
protected SshClient.Factory sshFactory; protected SshClient.Factory sshFactory;
private Predicate<IPSocket> socketTester; private Predicate<HostAndPort> socketTester;
@BeforeGroups(groups = { "integration", "live" }) @BeforeGroups(groups = { "integration", "live" })
@Override @Override
@ -73,7 +73,7 @@ public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest {
client = injector.getInstance(SlicehostClient.class); client = injector.getInstance(SlicehostClient.class);
sshFactory = injector.getInstance(SshClient.Factory.class); sshFactory = injector.getInstance(SshClient.Factory.class);
SocketOpen socketOpen = injector.getInstance(SocketOpen.class); SocketOpen socketOpen = injector.getInstance(SocketOpen.class);
socketTester = new RetryablePredicate<IPSocket>(socketOpen, 120, 1, TimeUnit.SECONDS); socketTester = new RetryablePredicate<HostAndPort>(socketOpen, 120, 1, TimeUnit.SECONDS);
injector.injectMembers(socketOpen); // add logger injector.injectMembers(socketOpen); // add logger
} }
@ -254,7 +254,7 @@ public class SlicehostClientLiveTest extends BaseComputeServiceContextLiveTest {
private void doCreateMarkerFile(Slice newDetails, String pass) throws IOException { private void doCreateMarkerFile(Slice newDetails, String pass) throws IOException {
String ip = getIp(newDetails); String ip = getIp(newDetails);
IPSocket socket = new IPSocket(ip, 22); HostAndPort socket = HostAndPort.fromParts(ip, 22);
socketTester.apply(socket); socketTester.apply(socket);
SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build()); SshClient client = sshFactory.create(socket, LoginCredentials.builder().user("root").password(pass).build());

View File

@ -29,7 +29,6 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials; import org.jclouds.compute.functions.DefaultCredentialsFromImageOrOverridingCredentials;
import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate; import org.jclouds.compute.strategy.PrioritizeCredentialsFromTemplate;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions; import org.jclouds.softlayer.compute.options.SoftLayerTemplateOptions;
import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter; import org.jclouds.softlayer.compute.strategy.SoftLayerComputeServiceAdapter;
import org.jclouds.softlayer.domain.ProductItem; import org.jclouds.softlayer.domain.ProductItem;
@ -41,6 +40,7 @@ import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.net.HostAndPort;
import com.google.common.net.InetAddresses; import com.google.common.net.InetAddresses;
@Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest") @Test(groups = "live", singleThreaded = true, testName = "SoftLayerComputeServiceAdapterLiveTest")
@ -82,7 +82,7 @@ public class SoftLayerComputeServiceAdapterLiveTest extends BaseSoftLayerClientL
} }
protected void doConnectViaSsh(VirtualGuest guest, LoginCredentials creds) { 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 { try {
ssh.connect(); ssh.connect();
ExecResponse hello = ssh.exec("echo hello"); ExecResponse hello = ssh.exec("echo hello");

View File

@ -22,7 +22,6 @@ import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.trmk.ecloud.suppliers.TerremarkECloudInternetServiceAndPublicIpAddressSupplier; import org.jclouds.trmk.ecloud.suppliers.TerremarkECloudInternetServiceAndPublicIpAddressSupplier;
import org.jclouds.trmk.vcloud_0_8.TerremarkClientLiveTest; 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.jclouds.trmk.vcloud_0_8.reference.VCloudConstants;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
/** /**
* Tests behavior of {@code TerremarkECloudClient} * Tests behavior of {@code TerremarkECloudClient}
* *
@ -56,7 +57,7 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest<Terre
} }
@Override @Override
protected SshClient getConnectionFor(IPSocket socket) { protected SshClient getConnectionFor(HostAndPort socket) {
return sshFactory.create(socket, LoginCredentials.builder().user("ecloud").password("TmrkCl0ud1s#1!").privateKey( return sshFactory.create(socket, LoginCredentials.builder().user("ecloud").password("TmrkCl0ud1s#1!").privateKey(
key.getPrivateKey()).authenticateSudo(true).build()); key.getPrivateKey()).authenticateSudo(true).build());
} }

View File

@ -21,7 +21,6 @@ package org.jclouds.trmk.vcloudexpress;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.jclouds.domain.LoginCredentials; import org.jclouds.domain.LoginCredentials;
import org.jclouds.net.IPSocket;
import org.jclouds.ssh.SshClient; import org.jclouds.ssh.SshClient;
import org.jclouds.trmk.vcloud_0_8.TerremarkClientLiveTest; import org.jclouds.trmk.vcloud_0_8.TerremarkClientLiveTest;
import org.jclouds.trmk.vcloud_0_8.domain.InternetService; import org.jclouds.trmk.vcloud_0_8.domain.InternetService;
@ -31,6 +30,8 @@ import org.jclouds.trmk.vcloud_0_8.domain.VApp;
import org.jclouds.trmk.vcloudexpress.suppliers.TerremarkVCloudExpressInternetServiceAndPublicIpAddressSupplier; import org.jclouds.trmk.vcloudexpress.suppliers.TerremarkVCloudExpressInternetServiceAndPublicIpAddressSupplier;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.net.HostAndPort;
/** /**
* Tests behavior of {@code TerremarkVCloudExpressClient} * Tests behavior of {@code TerremarkVCloudExpressClient}
* *
@ -40,7 +41,7 @@ import org.testng.annotations.Test;
public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTest<TerremarkVCloudExpressClient, TerremarkVCloudExpressAsyncClient> { public class TerremarkVCloudExpressClientLiveTest extends TerremarkClientLiveTest<TerremarkVCloudExpressClient, TerremarkVCloudExpressAsyncClient> {
@Override @Override
protected SshClient getConnectionFor(IPSocket socket) { protected SshClient getConnectionFor(HostAndPort socket) {
return sshFactory.create(socket, LoginCredentials.builder().user("vcloud").password("TmrkCl0ud1s#1!").privateKey( return sshFactory.create(socket, LoginCredentials.builder().user("vcloud").password("TmrkCl0ud1s#1!").privateKey(
key.getPrivateKey()).authenticateSudo(true).build()); key.getPrivateKey()).authenticateSudo(true).build());
} }