@Override
  public int run(String[] args) throws Exception {
    try {
      webServiceClient = WebServiceClient.getWebServiceClient().createClient();
      return runCommand(args);
    } finally {
      if (yarnClient != null) {
        yarnClient.close();
      }
      if (webServiceClient != null) {
        webServiceClient.destroy();
      }
    }
  }
@Test (timeout = 10000)
  public void testHelpMessage() throws Exception {
    YarnClient mockYarnClient = createMockYarnClient(
        YarnApplicationState.FINISHED,
        UserGroupInformation.getCurrentUser().getShortUserName());
    LogsCLI dumper = new LogsCLIForTest(mockYarnClient);
    dumper.setConf(conf);

    int exitCode = dumper.run(new String[]{});
    assertTrue(exitCode == -1);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    pw.println("Retrieve logs for YARN applications.");
    pw.println("usage: yarn logs -applicationId <application ID> [OPTIONS]");
    pw.println();
    pw.println("general options are:");
    pw.println(" -am <AM Containers>                          Prints the AM Container logs");
    pw.println("                                              for this application.");
    pw.println("                                              Specify comma-separated");
    pw.println("                                              value to get logs for");
    pw.println("                                              related AM Container. For");
    pw.println("                                              example, If we specify -am");
    pw.println("                                              1,2, we will get the logs");
    pw.println("                                              for the first AM Container");
    pw.println("                                              as well as the second AM");
    pw.println("                                              Container. To get logs for");
    pw.println("                                              all AM Containers, use -am");
    pw.println("                                              ALL. To get logs for the");
    pw.println("                                              latest AM Container, use -am");
    pw.println("                                              -1. By default, it will");
    pw.println("                                              print all available logs.");
    pw.println("                                              Work with -log_files to get");
    pw.println("                                              only specific logs.");
    pw.println(" -appOwner <Application Owner>                AppOwner (assumed to be");
    pw.println("                                              current user if not");
    pw.println("                                              specified)");
    pw.println(" -client_max_retries <Max Retries>            Set max retry number for a");
    pw.println("                                              retry client to get the");
    pw.println("                                              container logs for the");
    pw.println("                                              running applications. Use a");
    pw.println("                                              negative value to make retry");
    pw.println("                                              forever. The default value");
    pw.println("                                              is 30.");
    pw.println(" -client_retry_interval_ms <Retry Interval>   Work with");
    pw.println("                                              --client_max_retries to");
    pw.println("                                              create a retry client. The");
    pw.println("                                              default value is 1000.");
    pw.println(" -clusterId <Cluster ID>                      ClusterId. By default, it");
    pw.println("                                              will take default cluster id");
    pw.println("                                              from the RM");
    pw.println(" -containerId <Container ID>                  ContainerId. By default, it");
    pw.println("                                              will print all available");
    pw.println("                                              logs. Work with -log_files");
    pw.println("                                              to get only specific logs.");
    pw.println("                                              If specified, the");
    pw.println("                                              applicationId can be omitted");
    pw.println(" -help                                        Displays help for all");
    pw.println("                                              commands.");
    pw.println(" -list_nodes                                  Show the list of nodes that");
    pw.println("                                              successfully aggregated");
    pw.println("                                              logs. This option can only");
    pw.println("                                              be used with finished");
    pw.println("                                              applications.");
    pw.println(" -log_files <Log File Name>                   Specify comma-separated");
    pw.println("                                              value to get exact matched");
    pw.println("                                              log files. Use \"ALL\" or \"*\"");
    pw.println("                                              to fetch all the log files");
    pw.println("                                              for the container.");
    pw.println(" -log_files_pattern <Log File Pattern>        Specify comma-separated");
    pw.println("                                              value to get matched log");
    pw.println("                                              files by using java regex.");
    pw.println("                                              Use \".*\" to fetch all the");
    pw.println("                                              log files for the container.");
    pw.println(" -nodeAddress <Node Address>                  NodeAddress in the format");
    pw.println("                                              nodename:port");
    pw.println(" -out <Local Directory>                       Local directory for storing");
    pw.println("                                              individual container logs.");
    pw.println("                                              The container logs will be");
    pw.println("                                              stored based on the node the");
    pw.println("                                              container ran on.");
    pw.println(" -show_application_log_info                   Show the containerIds which");
    pw.println("                                              belong to the specific");
    pw.println("                                              Application. You can combine");
    pw.println("                                              this with --nodeAddress to");
    pw.println("                                              get containerIds for all the");
    pw.println("                                              containers on the specific");
    pw.println("                                              NodeManager.");
    pw.println(" -show_container_log_info                     Show the container log");
    pw.println("                                              metadata, including log-file");
    pw.println("                                              names, the size of the log");
    pw.println("                                              files. You can combine this");
    pw.println("                                              with --containerId to get");
    pw.println("                                              log metadata for the");
    pw.println("                                              specific container, or with");
    pw.println("                                              --nodeAddress to get log");
    pw.println("                                              metadata for all the");
    pw.println("                                              containers on the specific");
    pw.println("                                              NodeManager.");
    pw.println(" -size <size>                                 Prints the log file's first");
    pw.println("                                              'n' bytes or the last 'n'");
    pw.println("                                              bytes. Use negative values");
    pw.println("                                              as bytes to read from the");
    pw.println("                                              end and positive values as");
    pw.println("                                              bytes to read from the");
    pw.println("                                              beginning.");
    pw.println(" -size_limit_mb <Size Limit>                  Use this option to limit the");
    pw.println("                                              size of the total logs which");
    pw.println("                                              could be fetched. By");
    pw.println("                                              default, we only allow to");
    pw.println("                                              fetch at most 10240 MB logs.");
    pw.println("                                              If the total log size is");
    pw.println("                                              larger than the specified");
    pw.println("                                              number, the CLI would fail.");
    pw.println("                                              The user could specify -1 to");
    pw.println("                                              ignore the size limit and");
    pw.println("                                              fetch all logs.");
    pw.close();
    String appReportStr = baos.toString("UTF-8");
    Assert.assertTrue(sysOutStream.toString().contains(appReportStr));
  }