@Override public boolean apply(String input) { return commandRunner.runAction(input).getExitStatus() > 0; }
@Override public boolean apply(String input) { return commandRunner.runAction(input).getExitStatus() > 0; }
public ExecResponse runAction(String action) { ExecResponse returnVal; String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action) : execScriptAsDefaultUser(action); returnVal = runCommand(command); if (ImmutableSet.of("status", "stdout", "stderr").contains(action)) logger.trace("<< %s(%d)", action, returnVal.getExitStatus()); else if (computeLogger.isTraceEnabled()) computeLogger.trace("<< %s[%s]", action, returnVal); else computeLogger.debug("<< %s(%d)", action, returnVal.getExitStatus()); return returnVal; }
public ExecResponse runAction(String action) { ExecResponse returnVal; String command = (runAsRoot && Predicates.in(ImmutableSet.of("start", "stop", "run")).apply(action)) ? execScriptAsRoot(action) : execScriptAsDefaultUser(action); returnVal = runCommand(command); if (ImmutableSet.of("status", "stdout", "stderr").contains(action)) logger.trace("<< %s(%d)", action, returnVal.getExitStatus()); else if (computeLogger.isTraceEnabled()) computeLogger.trace("<< %s[%s]", action, returnVal); else computeLogger.debug("<< %s(%d)", action, returnVal.getExitStatus()); return returnVal; }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
ExecResponse runCommand(String command) { String statement = String.format("[%s] as %s@%s", command.replace( node.getCredentials().getOptionalPassword().isPresent() ? node.getCredentials().getOptionalPassword().get() : "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; }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
@Override public boolean apply(CommandUsingClient commandUsingClient) { logger.trace("looking for [%s] state on %s@%s", commandUsingClient.command, commandUsingClient.client .getUsername(), commandUsingClient.client.getHostAddress()); ExecResponse response = refresh(commandUsingClient); while (response.getExitStatus() == -1) response = refresh(commandUsingClient); logger.trace("%s@%s: looking for exit code 0: currently: %s", commandUsingClient.client.getUsername(), commandUsingClient.client.getHostAddress(), response.getExitStatus()); return 0 == response.getExitStatus(); }
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; }
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
public BlockUntilInitScriptStatusIsZeroThenReturnOutput future() { ExecResponse returnVal = super.doCall(); if (returnVal.getExitStatus() != 0) { IllegalStateException e = new IllegalStateException(String.format( "instance: %s on node: %s had non-zero exit status: %s", init.getInstanceName(), getNode().getId(), returnVal)); eventBus.post(new StatementOnNodeFailure(init, node, e)); throw e; } return statusFactory.create(this).init(); }
@Subscribe @AllowConcurrentEvents public void onSuccess(StatementOnNodeCompletion event) { ExecResponse arg0 = event.getResponse(); if (arg0.getExitStatus() != 0) { LOG.error("<< error running {} on node({}): {}", new Object[] { event.getStatement(), event.getNode().getId(), arg0 }); } else { LOG.info("<< success executing {} on node({}): {}", new Object[] { event.getStatement(), event.getNode().getId(), arg0 }); } }
@Subscribe @AllowConcurrentEvents public void onSuccess(StatementOnNodeCompletion event) { ExecResponse arg0 = event.getResponse(); if (arg0.getExitStatus() != 0) { LOG.error("<< error running {} on node({}): {}", new Object[] { event.getStatement(), event.getNode().getId(), arg0 }); } else { LOG.info("<< success executing {} on node({}): {}", new Object[] { event.getStatement(), event.getNode().getId(), arg0 }); } }
@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(); } }
@Override public ExecResponse apply(@Nullable org.jclouds.compute.domain.ExecResponse input) { if (input == null) { return null; } return ExecResponse.builder().output(input.getOutput()).error(input.getError()).exitStatus(input.getExitStatus()) .build(); } }
public Boolean call() { Statement statement = Statements.newStatementList(exec("hostname")); // NB this assumes passwordless sudo ! ExecResponse response = computeService.runScriptOnNode(nodeRef.getId(), statement, overrideLoginCredentials(expectedCredentialsRef).runAsRoot(false)); return response.getExitStatus() == 0; }}) .limitTimeTo(delayMs, MILLISECONDS)
@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(); } }