Examples of ShellCommandExecutor


Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

      }

      // Guarantee target exists before creating symlink.
      targetWorkDir.mkdirs();

      ShellCommandExecutor shexec = new ShellCommandExecutor(
        Shell.getSymlinkCommand(targetPath, linkPath));
      try {
        shexec.execute();
      } catch (IOException e) {
        throw new YarnRuntimeException(String.format(
          "failed to create symlink from %s to %s, shell output: %s", linkPath,
          targetPath, shexec.getOutput()), e);
      }

      this.testWorkDir = link;
    } else {
      this.testWorkDir = targetWorkDir;
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

     * @param args script name followed by its argumnets
     * @param dir current working directory.
     * @throws IOException
     */
    public void runScript(List<String> args, File dir) throws IOException {
      ShellCommandExecutor shexec =
              new ShellCommandExecutor(args.toArray(new String[0]), dir);
      shexec.execute();
      int exitCode = shexec.getExitCode();
      if (exitCode != 0) {
        throw new IOException("Task debug script exit with nonzero status of "
                              + exitCode + ".");
      }
    }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

  public void destroy() {
    LOG.debug("Killing ProcfsBasedProcessTree of " + pid);
    if (pid == -1) {
      return;
    }
    ShellCommandExecutor shexec = null;

    if (isAlive(this.pid)) {
      try {
        String[] args = { "kill", this.pid.toString() };
        shexec = new ShellCommandExecutor(args);
        shexec.execute();
      } catch (IOException ioe) {
        LOG.warn("Error executing shell command " + ioe);
      } finally {
        LOG.info("Killing " + pid + " with SIGTERM. Exit code "
            + shexec.getExitCode());
      }
    }

    SigKillThread sigKillThread = new SigKillThread();
    sigKillThread.setDaemon(true);
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   * 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);
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   */
  private class SigKillThread extends Thread {

    public void run() {
      this.setName(this.getClass().getName() + "-" + String.valueOf(pid));
      ShellCommandExecutor shexec = null;

      try {
        // Sleep for some time before sending SIGKILL
        Thread.sleep(sleepTimeBeforeSigKill);
      } catch (InterruptedException i) {
        LOG.warn("Thread sleep is interrupted.");
      }

      // Kill the root process with SIGKILL if it is still alive
      if (ProcfsBasedProcessTree.this.isAlive(pid)) {
        try {
          String[] args = { "kill", "-9", pid.toString() };
          shexec = new ShellCommandExecutor(args);
          shexec.execute();
        } catch (IOException ioe) {
          LOG.warn("Error executing shell command " + ioe);
        } finally {
          LOG.info("Killing " + pid + " with SIGKILL. Exit code "
              + shexec.getExitCode());
        }
      }
    }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

  private class RogueTaskThread extends Thread {
    public void run() {
      try {
        String args[] = { "bash", "-c",
            "echo $$ > " + pidFile + "; sh " + shellScript + " " + N + ";" };
        shexec = new ShellCommandExecutor(args);
        shexec.execute();
      } catch (ExitCodeException ee) {
        LOG.info("Shell Command exit with a non-zero exit code. " + ee);
      } catch (IOException ioe) {
        LOG.info("Error executing shell command " + ioe);
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   */
  private void runChild(List<String> args, File dir,
                        String taskid) throws IOException {

    try {
      shexec = new ShellCommandExecutor(args.toArray(new String[0]), dir);
      shexec.execute();
    } catch (IOException ioe) {
      // do nothing
      // error and output are appropriately redirected
    } finally { // handle the exit code
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

     * @param args script name followed by its argumnets
     * @param dir current working directory.
     * @throws IOException
     */
    public void runScript(List<String> args, File dir) throws IOException {
      ShellCommandExecutor shexec =
              new ShellCommandExecutor(args.toArray(new String[0]), dir);
      shexec.execute();
      int exitCode = shexec.getExitCode();
      if (exitCode != 0) {
        throw new IOException("Task debug script exit with nonzero status of "
                              + exitCode + ".");
      }
    }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

  public static final long DEFAULT_SLEEPTIME_BEFORE_SIGKILL = 5000L;

  public static final boolean isSetsidAvailable = isSetsidSupported();
  private static boolean isSetsidSupported() {
    ShellCommandExecutor shexec = null;
    boolean setsidSupported = true;
    try {
      String[] args = {"setsid", "bash", "-c", "echo $$"};
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (IOException ioe) {
      LOG.warn("setsid is not available on this machine. So not using it.");
      setsidSupported = false;
    } finally { // handle the exit code
      LOG.info("setsid exited with exit code " + shexec.getExitCode());
      return setsidSupported;
    }
  }
View Full Code Here

Examples of org.apache.hadoop.util.Shell.ShellCommandExecutor

   * Sends terminate signal to the process, allowing it to gracefully exit.
   *
   * @param pid pid of the process to be sent SIGTERM
   */
  public static void terminateProcess(String pid) {
    ShellCommandExecutor shexec = null;
    String errMsg = null;
    try {
      String[] args = { "kill", pid };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (IOException ioe) {
      // Do nothing, we log the exit code in the finally block.
      errMsg = ioe.getMessage();
    } finally {
      LOG.info("Killing process " + pid +
               " with SIGTERM. Exit code " + shexec.getExitCode() +
               (errMsg == null ? "" : " (" + errMsg + ")"));
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.