@Override public ExecResponse call() { ExecResponse response = client.exec("hostname"); //System.out.println("completed (concurrently) "+count.incrementAndGet()); return response; } }));
@Override public ExecResponse call() { ExecResponse response = client.exec("hostname"); //System.out.println("completed (concurrently) " + count.incrementAndGet()); return response; } }));
ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getPassword() != null ? node.getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh .getUsername(), ssh.getHostAddress()); if (command.endsWith("status") || command.endsWith("stdout") || command.endsWith("stderr")) logger.trace(">> running %s", statement); else computeLogger.debug(">> running " + statement); ExecResponse returnVal = ssh.exec(command); if (!command.endsWith("status")) checkState(returnVal.getExitStatus() == 0, "error running %s; returnVal !=0: %s", statement, returnVal); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getOptionalPassword().isPresent() ? node .getCredentials().getOptionalPassword().get() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getOptionalPassword().isPresent() ? node .getCredentials().getOptionalPassword().get() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
public void testExecHostname() throws IOException, InterruptedException { SshClient client = setupClient(); ExecResponse response = client.exec("hostname"); assertEquals(response.getError(), ""); assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName() : sshHost); }
@Override public boolean apply(SshClient input) { input.connect(); if (input.exec("id").getExitStatus() == 0) { return true; } return false; } }, getSpawnNodeMaxWait(), 1l, SECONDS).apply(client));
@Test public void testExecHostname() throws IOException { SshClient client = setupClient(); try { ExecResponse response = client.exec("hostname"); assertEquals(response.getExitStatus(), 0); assertEquals(response.getError(), ""); assertEquals(response.getOutput().trim(), "localhost".equals(sshHost) ? InetAddress.getLocalHost().getHostName() : sshHost); } finally { client.disconnect(); } }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getPassword() != null ? node .getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
protected ExecResponse runCommand(String command) { ExecResponse returnVal; logger.debug(">> running [%s] as %s@%s", command.replace(node.getCredentials().getPassword() != null ? node .getCredentials().getPassword() : "XXXXX", "XXXXX"), ssh.getUsername(), ssh.getHostAddress()); returnVal = ssh.exec(command); return returnVal; }
protected void checkSSH(HostAndPort socket) { socketTester.apply(socket); SshClient client = sshFactory.create(socket, loginCredentials); try { client.connect(); ExecResponse exec = client.exec("echo hello"); System.out.println(exec); assertEquals(exec.getOutput().trim(), "hello"); } finally { if (client != null) client.disconnect(); } }
@Test public void testExecInvalidCommand() throws IOException { SshClient client = setupClient(); try { ExecResponse response = client.exec("thisCommandDoesNotExist"); assertNotEquals(response.getExitStatus(), 0); assertTrue(response.getOutput().contains("not found") || response.getError().contains("not found"), "stdout="+response.getOutput()+"; stderr="+response.getError()); } finally { client.disconnect(); } }
@Test public void testExecInvalidCommand() throws IOException { SshClient client = setupClient(); try { ExecResponse response = client.exec("thisCommandDoesNotExist"); assertNotEquals(response.getExitStatus(), 0); assertTrue(response.getOutput().contains("not found") || response.getError().contains("not found"), "stdout=" + response.getOutput() + "; stderr=" + response.getError()); } finally { client.disconnect(); } }
public void simpleTest() { RunScriptOnNodeUsingSsh testMe = new RunScriptOnNodeUsingSsh(sshFactory, eventBus, node, exec("echo $USER\necho $USER"), wrapInInitScript(false).runAsRoot(false)); testMe.init(); sshClient.connect(); expect(sshClient.getUsername()).andReturn("tester"); expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect(sshClient.exec("echo $USER\n" + "echo $USER\n")).andReturn(new ExecResponse("tester\ntester\n", null, 0)); sshClient.disconnect(); replay(sshClient); testMe.call(); }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("root").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }
private void doCheckKey(String address) { SshClient ssh = sshFactory.create(HostAndPort.fromParts(address, 22), LoginCredentials.builder().user("ubuntu").privateKey(keyPair.getKeyMaterial()).build()); try { ssh.connect(); ExecResponse hello = ssh.exec("echo hello"); assertEquals(hello.getOutput().trim(), "hello"); } finally { if (ssh != null) ssh.disconnect(); } }