Example #1
0
  /**
   * Implementation of Tool::run(). Orchestrates the copy of source file(s) to target location, by:
   * 1. Creating a list of files to be copied to target. 2. Launching a Map-only job to copy the
   * files. (Delegates to execute().)
   *
   * @param argv: List of arguments passed to DistCp, from the ToolRunner.
   * @return On success, it returns 0. Else, -1.
   */
  public int run(String[] argv) {
    try {
      inputOptions = (OptionsParser.parse(argv));

      LOG.info("Input Options: " + inputOptions);
    } catch (Throwable e) {
      LOG.error("Invalid arguments: ", e);
      System.err.println("Invalid arguments: " + e.getMessage());
      OptionsParser.usage();
      return DistCpConstants.INVALID_ARGUMENT;
    }

    try {
      execute();
    } catch (InvalidInputException e) {
      LOG.error("Invalid input: ", e);
      return DistCpConstants.INVALID_ARGUMENT;
    } catch (DuplicateFileException e) {
      LOG.error("Duplicate files in input path: ", e);
      return DistCpConstants.DUPLICATE_INPUT;
    } catch (Exception e) {
      LOG.error("Exception encountered ", e);
      return DistCpConstants.UNKNOWN_ERROR;
    }
    return DistCpConstants.SUCCESS;
  }