@Override
  public int run(String[] args) throws Exception {    
    Options opts = new Options();

    opts.addOption("lnl", LIST_LABELS_CMD, false,
        "List cluster node-label collection");
    opts.addOption("lna", LIST_CLUSTER_ATTRIBUTES, false,
        "List cluster node-attribute collection");
    opts.addOption("h", HELP_CMD, false, "Displays help for all commands.");
    opts.addOption("dnl", DIRECTLY_ACCESS_NODE_LABEL_STORE, false,
        "This is DEPRECATED, will be removed in future releases. Directly access node label store, "
            + "with this option, all node label related operations"
            + " will NOT connect RM. Instead, they will"
            + " access/modify stored node labels directly."
            + " By default, it is false (access via RM)."
            + " AND PLEASE NOTE: if you configured "
            + YarnConfiguration.FS_NODE_LABELS_STORE_ROOT_DIR
            + " to a local directory"
            + " (instead of NFS or HDFS), this option will only work"
            + " when the command run on the machine where RM is running."
            + " Also, this option is UNSTABLE, could be removed in future"
            + " releases.");

    int exitCode = -1;
    CommandLine parsedCli = null;
    try {
      parsedCli = new GnuParser().parse(opts, args);
    } catch (MissingArgumentException ex) {
      sysout.println("Missing argument for options");
      printUsage(opts);
      return exitCode;
    }

    createAndStartYarnClient();

    if (parsedCli.hasOption(DIRECTLY_ACCESS_NODE_LABEL_STORE)) {
      accessLocal = true;
    }

    if (parsedCli.hasOption(LIST_LABELS_CMD)) {
      printClusterNodeLabels();
    } else if(parsedCli.hasOption(LIST_CLUSTER_ATTRIBUTES)){
      printClusterNodeAttributes();
    } else if (parsedCli.hasOption(HELP_CMD)) {
      printUsage(opts);
      return 0;
    } else {
      syserr.println("Invalid Command Usage : ");
      printUsage(opts);
    }
    return 0;
  }
@Test
  public void testGetClusterNodeLabelsWithLocalAccess() throws Exception {
    when(client.getClusterNodeLabels()).thenReturn(
        Arrays.asList(NodeLabel.newInstance("remote1"),
            NodeLabel.newInstance("remote2")));
    ClusterCLI cli = createAndGetClusterCLI();
    ClusterCLI.localNodeLabelsManager = mock(CommonNodeLabelsManager.class);
    when(ClusterCLI.localNodeLabelsManager.getClusterNodeLabels()).thenReturn(
        Arrays.asList(NodeLabel.newInstance("local1"),
            NodeLabel.newInstance("local2")));

    int rc =
        cli.run(new String[] { ClusterCLI.CMD,
            "-" + ClusterCLI.LIST_LABELS_CMD,
            "-" + ClusterCLI.DIRECTLY_ACCESS_NODE_LABEL_STORE });
    assertEquals(0, rc);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    // it should return local* instead of remote*
    pw.print("Node Labels: <local1:exclusivity=true>,<local2:exclusivity=true>");
    pw.close();
    verify(sysOut).println(baos.toString("UTF-8"));
  }