Package org.apache.hadoop.util.Shell

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


        String confDir) {
      String[] commandArgs = getCommand(command, confDir);
      File cwd = new File(".");
      HashMap<String, String> env = new HashMap<String, String>();
      env.put("HADOOP_CONF_DIR", confDir);
      ShellCommandExecutor executor
        = new ShellCommandExecutor(commandArgs, cwd, env);
      LOG.info(executor.toString());
      return executor;
    }
View Full Code Here


    public void start() throws IOException {
      start(hadoopConfDir);
    }

    public void start(String newConfLocation) throws IOException {
      ShellCommandExecutor cme = buildCommandExecutor(START_COMMAND,
          newConfLocation);
      cme.execute();
      String output = cme.getOutput();
      if (!output.isEmpty()) { //getOutput() never returns null value
        if (output.toLowerCase().contains("error")) {
          LOG.warn("Error is detected.");
          throw new IOException("Start error\n" + output);
        }
View Full Code Here

        }
      }
    }

    public void kill(String newConfLocation) throws IOException {
      ShellCommandExecutor cme
        = buildCommandExecutor(STOP_COMMAND, newConfLocation);
      cme.execute();
      String output = cme.getOutput();
      if (!output.isEmpty()) { //getOutput() never returns null value
        if (output.toLowerCase().contains("error")) {
          LOG.info("Error is detected.");
          throw new IOException("Kill error\n" + output);
        }
View Full Code Here

        try {
          env.vargs.add(Integer.toString(jvmId.getId()));
          List<String> wrappedCommand =
            TaskLog.captureOutAndError(env.setup, env.vargs, env.stdout, env.stderr,
                env.logSize, env.pidFile);
          shexec = new ShellCommandExecutor(wrappedCommand.toArray(new String[0]),
              env.workDir, env.env);
          shexec.execute();
        } catch (IOException ioe) {
          // do nothing
          // error and output are appropriately redirected
View Full Code Here

  public void init(String location, long timeout) {
    this.healthCheckScript = location;
    this.scriptTimeout = timeout;
    ArrayList<String> execScript = new ArrayList<String>();
    execScript.add(healthCheckScript);
    this.shexec = new ShellCommandExecutor(execScript.toArray(new String[execScript.size()]), null,
        null, scriptTimeout);
    LOG.info("HealthChecker initialized.");
  }
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

      }

      // 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

      throw new IOException(
          "invalid arguments to createHardLink: link name is null");
    }
    // construct and execute shell command
    String[] hardLinkCommand = getHardLinkCommand.linkOne(file, linkName);
    ShellCommandExecutor shexec = new ShellCommandExecutor(hardLinkCommand);
    try {
      shexec.execute();
    } catch (ExitCodeException e) {
      throw new IOException("Failed to execute command " +
          Arrays.toString(hardLinkCommand) +
          "; command output: \"" + shexec.getOutput() + "\"" +
          "; WrappedException: \"" + e.getMessage() + "\"");
    }
  }
View Full Code Here

    }
   
    // construct and execute shell command
    String[] hardLinkCommand = getHardLinkCommand.linkMult(fileBaseNames,
        linkDir);
    ShellCommandExecutor shexec = new ShellCommandExecutor(hardLinkCommand,
      parentDir, null, 0L);
    try {
      shexec.execute();
    } catch (ExitCodeException e) {
      throw new IOException(shexec.getOutput() + e.getMessage());
    }
    return callCount;
  }
View Full Code Here

    String inpMsg = null;
    String errMsg = null;
    int exitValue = -1;
    BufferedReader in = null;

    ShellCommandExecutor shexec = new ShellCommandExecutor(cmd);
    try {
      shexec.execute();
      in = new BufferedReader(new StringReader(shexec.getOutput()));
      inpMsg = in.readLine();
      exitValue = shexec.getExitCode();
      if (inpMsg == null || exitValue != 0) {
        throw createIOException(fileName, inpMsg, errMsg, exitValue, null);
      }
      if (Shell.SOLARIS) {
        String[] result = inpMsg.split("\\s+");
        return Integer.parseInt(result[1]);
      } else {
        return Integer.parseInt(inpMsg);
      }
    } catch (ExitCodeException e) {
      inpMsg = shexec.getOutput();
      errMsg = e.getMessage();
      exitValue = e.getExitCode();
      throw createIOException(fileName, inpMsg, errMsg, exitValue, e);
    } catch (NumberFormatException e) {
      throw createIOException(fileName, inpMsg, errMsg, exitValue, e);
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.