@Test(expected = SshNotConnected.class) public void shouldThrowExepctionToInvalidNode() throws SshNotConnected { String ip = "invalid_ip"; String user = "Invalid user"; String key = "Invalid key"; SshWaiter sshWaiter = new SshWaiter(); sshWaiter.waitSsh(ip, user, key, 10); }
public SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds) throws SshNotConnected { SshWaiterCallable callable = new SshWaiterCallable(ip, user, keyPath); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<SshUtil> future = executor.submit(callable); Concurrency.waitExecutor(executor, timeoutSeconds, TimeUnit.SECONDS, logger, "Could not ssh into node " + ip); try { SshUtil ssh = Concurrency.checkAndGetFromFuture(future); if (ssh != null) { return ssh; } else { throw new SshNotConnected("Could not SSH into " + ip); } } catch (ExecutionException e) { throw new SshNotConnected("Could not SSH into " + ip); } catch (IllegalStateException e) { throw new SshNotConnected("Could not SSH into " + ip); } }
SshWaiter { public SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds) throws SshNotConnected { SshWaiterCallable callable = new SshWaiterCallable(ip, user, keyPath); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<SshUtil> future = executor.submit(callable); Concurrency.waitExecutor(executor, timeoutSeconds, TimeUnit.SECONDS, logger, "Could not ssh into node " + ip); try { SshUtil ssh = Concurrency.checkAndGetFromFuture(future); if (ssh != null) { return ssh; } else { throw new SshNotConnected("Could not SSH into " + ip); } } catch (ExecutionException e) { throw new SshNotConnected("Could not SSH into " + ip); } catch (IllegalStateException e) { throw new SshNotConnected("Could not SSH into " + ip); } } }
SshWaiter { public SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds) throws SshNotConnected { SshWaiterCallable callable = new SshWaiterCallable(ip, user, keyPath); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<SshUtil> future = executor.submit(callable); Concurrency.waitExecutor(executor, timeoutSeconds, TimeUnit.SECONDS, logger, "Could not ssh into node " + ip); try { SshUtil ssh = Concurrency.checkAndGetFromFuture(future); if (ssh != null) { return ssh; } else { throw new SshNotConnected("Could not SSH into " + ip); } } catch (ExecutionException e) { throw new SshNotConnected("Could not SSH into " + ip); } catch (IllegalStateException e) { throw new SshNotConnected("Could not SSH into " + ip); } }  }
SshWaiter { public SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds) throws SshNotConnected { SshWaiterCallable callable = new SshWaiterCallable(ip, user, keyPath); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<SshUtil> future = executor.submit(callable); Concurrency.waitExecutor(executor, timeoutSeconds, TimeUnit.SECONDS, logger, "Could not ssh into node " + ip); try { SshUtil ssh = Concurrency.checkAndGetFromFuture(future); if (ssh != null) { return ssh; } else { throw new SshNotConnected("Could not SSH into " + ip); } } catch (ExecutionException e) { throw new SshNotConnected("Could not SSH into " + ip); } catch (IllegalStateException e) { throw new SshNotConnected("Could not SSH into " + ip); } }  SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds); }
SshWaiter { public SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds) throws SshNotConnected { SshWaiterCallable callable = new SshWaiterCallable(ip, user, keyPath); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<SshUtil> future = executor.submit(callable); Concurrency.waitExecutor(executor, timeoutSeconds, TimeUnit.SECONDS, logger, "Could not ssh into node " + ip); try { SshUtil ssh = Concurrency.checkAndGetFromFuture(future); if (ssh != null) { return ssh; } else { throw new SshNotConnected("Could not SSH into " + ip); } } catch (ExecutionException e) { throw new SshNotConnected("Could not SSH into " + ip); } catch (IllegalStateException e) { throw new SshNotConnected("Could not SSH into " + ip); } }  SshUtil waitSsh(String ip, String user, String keyPath, int timeoutSeconds);  }