/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); }
/** * Check if the executor had a timeout and logs the event. * @param executor to check * @param user user to log * @return true if timeout has occurred */ private boolean handleExecutorTimeout( ShellCommandExecutor executor, String user) { // If its a shell executor timeout, indicate so in the message // but treat the result as empty instead of throwing it up, // similar to how partial resolution failures are handled above if (executor.isTimedOut()) { LOG.warn( "Unable to return groups for user '{}' as shell group lookup " + "command '{}' ran longer than the configured timeout limit of " + "{} seconds.", user, Joiner.on(' ').join(executor.getExecString()), timeout ); return true; } return false; }
@Override public String[] getExecString() { String at = sshUserName.isEmpty() ? "" : "@"; String remoteCmd = StringUtils.join(super.getExecString(), " "); String cmd = String.format(tunnelCmd, sshOptions, sshUserName, at, hostname, remoteCmd, user); LOG.info("Executing full command [" + cmd + "]"); return new String[] { "/usr/bin/env", "bash", "-c", cmd }; }
/** * Is the process group with still alive? * * This method assumes that isAlive is called on a pid that was alive not * too long ago, and hence assumes no chance of pid-wrapping-around. * * @param pgrpId process group id * @return true if any of process in group is alive. */ public static boolean isProcessGroupAlive(String pgrpId) { ShellCommandExecutor shexec = null; try { String[] args = { "kill", "-0", "-"+pgrpId }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (ExitCodeException ee) { return false; } catch (IOException ioe) { LOG.warn("Error executing shell command " + Arrays.toString(shexec.getExecString()) + ioe); return false; } return (shexec.getExitCode() == 0 ? true : false); }
/** * Is the process group with still alive? * * This method assumes that isAlive is called on a pid that was alive not * too long ago, and hence assumes no chance of pid-wrapping-around. * * @param pgrpId process group id * @return true if any of process in group is alive. */ public static boolean isProcessGroupAlive(String pgrpId) { ShellCommandExecutor shexec = null; try { String[] args = { "kill", "-0", "-"+pgrpId }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (ExitCodeException ee) { return false; } catch (IOException ioe) { LOG.warn("Error executing shell command " + Arrays.toString(shexec.getExecString()) + ioe); return false; } return (shexec.getExitCode() == 0 ? true : false); }
/** * Is the process with PID pid still alive? * This method assumes that isAlive is called on a pid that was alive not * too long ago, and hence assumes no chance of pid-wrapping-around. * * @param pid pid of the process to check. * @return true if process is alive. */ public static boolean isAlive(String pid) { ShellCommandExecutor shexec = null; try { String[] args = { "kill", "-0", pid }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (ExitCodeException ee) { return false; } catch (IOException ioe) { LOG.warn("Error executing shell command " + Arrays.toString(shexec.getExecString()) + ioe); return false; } return (shexec.getExitCode() == 0 ? true : false); }
/** * Is the process with PID pid still alive? * This method assumes that isAlive is called on a pid that was alive not * too long ago, and hence assumes no chance of pid-wrapping-around. * * @param pid pid of the process to check. * @return true if process is alive. */ public static boolean isAlive(String pid) { ShellCommandExecutor shexec = null; try { String[] args = { "kill", "-0", pid }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (ExitCodeException ee) { return false; } catch (IOException ioe) { LOG.warn("Error executing shell command " + Arrays.toString(shexec.getExecString()) + ioe); return false; } return (shexec.getExitCode() == 0 ? true : false); }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); } }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); } }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); } }
/** * Is the process with PID pid still alive? */ private boolean isAlive(Integer pid) { // This method assumes that isAlive is called on a pid that was alive not // too long ago, and hence assumes no chance of pid-wrapping-around. ShellCommandExecutor shexec = null; try { String[] args = { "kill", "-0", pid.toString() }; shexec = new ShellCommandExecutor(args); shexec.execute(); } catch (ExitCodeException ee) { return false; } catch (IOException ioe) { LOG.warn("Error executing shell command " + Arrays.toString(shexec.getExecString()) + ioe); return false; } return (shexec.getExitCode() == 0 ? true : false); }
/** * Returns the commands of this instance. * Arguments with spaces in are presented with quotes round; other * arguments are presented raw * * @return a string representation of the object. */ @Override public String toString() { StringBuilder builder = new StringBuilder(); String[] args = getExecString(); for (String s : args) { if (s.indexOf(' ') >= 0) { builder.append('"').append(s).append('"'); } else { builder.append(s); } builder.append(' '); } return builder.toString(); }
@Override public String[] getExecString() { String at = sshUserName.isEmpty() ? "" : "@"; String remoteCmd = StringUtils.join(super.getExecString(), " "); String cmd = String.format(tunnelCmd, sshOptions, sshUserName, at, hostname, remoteCmd, user); LOG.info("Executing full command [" + cmd + "]"); return new String[] { "/usr/bin/env", "bash", "-c", cmd }; }
@Override public String[] getExecString() { String hostWithUser = hostname; if (!options.getUserName().isEmpty()) { hostWithUser = options.getUserName() + "@" + hostWithUser; } String remoteCmd = StringUtils.join(super.getExecString(), ' '); String cmd = String.format("%1$s %2$s %3$s \"%4$s\"", options.getSshCommand(), options.getSshOptions(), hostWithUser, remoteCmd); log.debug("Executing full command [" + cmd + "]"); return new String[] {"/usr/bin/env", "bash", "-c", cmd}; }