Package org.apache.hadoop.util.Shell

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


   * group, allowing the group to gracefully exit.
   *
   * @param pgrpId process group id
   */
  public static void terminateProcessGroup(String pgrpId) {
    ShellCommandExecutor shexec = null;
    try {
      String[] args = { "kill", "--", "-" + pgrpId };
      shexec = new ShellCommandExecutor(args);
      shexec.execute();
    } catch (IOException ioe) {
      LOG.warn("Error executing shell command " + ioe);
    } finally {
      LOG.info("Killing all processes in the process group " + pgrpId +
               " with SIGTERM. Exit code " + shexec.getExitCode());
    }
  }
View Full Code Here


    //If process tree is not alive then return immediately.
    if(!ProcessTree.isAlive(pid)) {
      return;
    }
    String[] args = { "kill", "-9", pid };
    ShellCommandExecutor shexec = new ShellCommandExecutor(args);
    try {
      shexec.execute();
    } catch (IOException e) {
      LOG.warn("Error sending SIGKILL to process "+ pid + " ."+
          StringUtils.stringifyException(e));
    } finally {
      LOG.info("Killing process " + pid + " with SIGKILL. Exit code "
          + shexec.getExitCode());
    }
  }
View Full Code Here

    if(!ProcessTree.isProcessGroupAlive(pgrpId)) {
      return;
    }

    String[] args = { "kill", "-9", "-"+pgrpId };
    ShellCommandExecutor shexec = new ShellCommandExecutor(args);
    try {
      shexec.execute();
    } catch (IOException e) {
      LOG.warn("Error sending SIGKILL to process group "+ pgrpId + " ."+
          StringUtils.stringifyException(e));
    } finally {
      LOG.info("Killing process group" + pgrpId + " with SIGKILL. Exit code "
          + shexec.getExitCode());
    }
  }
View Full Code Here

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

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

      untarCommand.append(" -)");
    } else {
      untarCommand.append(FileUtil.makeShellPath(inFile));
    }
    String[] shellCmd = { "bash", "-c", untarCommand.toString() };
    ShellCommandExecutor shexec = new ShellCommandExecutor(shellCmd);
    shexec.execute();
    int exitcode = shexec.getExitCode();
    if (exitcode != 0) {
      throw new IOException("Error untarring file " + inFile +
                  ". Tar process exited with exit code " + exitcode);
    }
  }
View Full Code Here

      cmdBuf.append("-R ");
    }
    cmdBuf.append(perm).append(" ");
    cmdBuf.append(filename);
    String[] shellCmd = {"bash", "-c" ,cmdBuf.toString()};
    ShellCommandExecutor shExec = new ShellCommandExecutor(shellCmd);
    try {
      shExec.execute();
    }catch(IOException e) {
      if(Log.isDebugEnabled()) {
        Log.debug("Error while changing permission : " + filename
            +" Exception: " + StringUtils.stringifyException(e));
      }
    }
    return shExec.getExitCode();
  }
View Full Code Here

     * @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

    private ShellCommandExecutor buildPushConfig(String local, String remote )
        throws IOException {
      File scriptDir = new File(scriptsDir);
      String[] commandArgs = getPushConfigCommand(local, remote, scriptDir);
      HashMap<String, String> env = new HashMap<String, String>();
      ShellCommandExecutor executor = new ShellCommandExecutor(commandArgs,
          scriptDir, env);
      LOG.info(executor.toString());
      return executor;
    }
View Full Code Here

          " ];\n then echo Will remove existing directory;  rm -rf "+
          hadoopNewConfDir+";\nmkdir "+ hadoopNewConfDir+"; else \n"+
          "echo " + hadoopNewConfDir + " doesnt exist hence creating" +
          ";  mkdir " + hadoopNewConfDir + ";\n  fi");
      String[] cmd = (String[]) cmdArgs.toArray(new String[cmdArgs.size()]);
      ShellCommandExecutor executor = new ShellCommandExecutor(cmd);
      LOG.info(executor.toString());
      return executor;
    }
View Full Code Here

TOP

Related Classes of org.apache.hadoop.util.Shell.ShellCommandExecutor

Copyright © 2018 www.massapicom. 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.