@Override
  public int run(String[] args) throws Exception {
    handleOpts(args);

    Integer exitCode = 1;
    UserGroupInformation loginUser = UserGroupInformation.getLoginUser();
    // If we're running as the user, then no need to impersonate
    // (which might fail if user is not a proxyuser for themselves)
    // Also if !proxy is set
    if (!proxy || loginUser.getShortUserName().equals(user)) {
      LOG.info("Running as " + user);
      exitCode = runInternal();
    } else {
      // Otherwise impersonate user.  If we're not allowed to, then this will
      // fail with an Exception
      LOG.info("Running as " + loginUser.getShortUserName() + " but will " +
          "impersonate " + user);
      UserGroupInformation proxyUser =
          UserGroupInformation.createProxyUser(user, loginUser);
      exitCode = proxyUser.doAs(new PrivilegedExceptionAction<Integer>() {
        @Override
        public Integer run() throws Exception {
          return runInternal();
        }
      });
    }
    return exitCode;
  }
@Test
  public void testHadoopArchiveLogs() throws Exception {
    String[] args = getArgs();
    final HadoopArchiveLogsRunner halr = new HadoopArchiveLogsRunner(conf);
    assertEquals(0, ToolRunner.run(halr, args));

    fs = FileSystem.get(conf);
    FileStatus[] app1Files = fs.listStatus(app1Path);
    Assert.assertEquals(1, app1Files.length);
    FileStatus harFile = app1Files[0];
    Assert.assertEquals(app1.toString() + ".har", harFile.getPath().getName());
    Path harPath = new Path("har:///" + harFile.getPath().toUri().getRawPath());
    FileStatus[] harLogs = HarFs.get(harPath.toUri(), conf).listStatus(harPath);
    Assert.assertEquals(FILE_COUNT, harLogs.length);
    Arrays.sort(harLogs, new Comparator<FileStatus>() {
      @Override
      public int compare(FileStatus o1, FileStatus o2) {
        return o1.getPath().getName().compareTo(o2.getPath().getName());
      }
    });
    for (int i = 0; i < FILE_COUNT; i++) {
      FileStatus harLog = harLogs[i];
      Assert.assertEquals("log" + (i + 1), harLog.getPath().getName());
      Assert.assertEquals(FILE_SIZES[i] * FILE_SIZE_INCREMENT, harLog.getLen());
      Assert.assertEquals(
          new FsPermission(FsAction.READ_WRITE, FsAction.READ, FsAction.NONE),
          harLog.getPermission());
      Assert.assertEquals(System.getProperty("user.name"),
          harLog.getOwner());
    }
    Assert.assertEquals(0, fs.listStatus(workingDir).length);
  }