Java Code Examples for org.apache.hadoop.util.StringUtils#popOptionWithArgument()

The following examples show how to use org.apache.hadoop.util.StringUtils#popOptionWithArgument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DFSAdmin.java    From hadoop with Apache License 2.0 6 votes vote down vote up
/** Constructor */
SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) {
  super(fs);
  CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE);
  List<String> parameters = c.parse(args, pos);
  String str = parameters.remove(0).trim();
  try {
    quota = StringUtils.TraditionalBinaryPrefix.string2long(str);
  } catch (NumberFormatException nfe) {
    throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota.");
  }
  String storageTypeString =
      StringUtils.popOptionWithArgument("-storageType", parameters);
  if (storageTypeString != null) {
    this.type = StorageType.parseStorageType(storageTypeString);
  }
  
  this.args = parameters.toArray(new String[parameters.size()]);
}
 
Example 2
Source File: XAttrCommands.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
  name = StringUtils.popOptionWithArgument("-n", args);
  String v = StringUtils.popOptionWithArgument("-v", args);
  if (v != null) {
    value = XAttrCodec.decodeValue(v);
  }
  xname = StringUtils.popOptionWithArgument("-x", args);

  if (name != null && xname != null) {
    throw new HadoopIllegalArgumentException(
        "Can not specify both '-n name' and '-x name' option.");
  }
  if (name == null && xname == null) {
    throw new HadoopIllegalArgumentException(
        "Must specify '-n name' or '-x name' option.");
  }

  if (args.isEmpty()) {
    throw new HadoopIllegalArgumentException("<path> is missing.");
  }
  if (args.size() > 1) {
    throw new HadoopIllegalArgumentException("Too many arguments.");
  }
}
 
Example 3
Source File: XAttrCommands.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
  name = StringUtils.popOptionWithArgument("-n", args);
  String v = StringUtils.popOptionWithArgument("-v", args);
  if (v != null) {
    value = XAttrCodec.decodeValue(v);
  }
  xname = StringUtils.popOptionWithArgument("-x", args);

  if (name != null && xname != null) {
    throw new HadoopIllegalArgumentException(
        "Can not specify both '-n name' and '-x name' option.");
  }
  if (name == null && xname == null) {
    throw new HadoopIllegalArgumentException(
        "Must specify '-n name' or '-x name' option.");
  }

  if (args.isEmpty()) {
    throw new HadoopIllegalArgumentException("<path> is missing.");
  }
  if (args.size() > 1) {
    throw new HadoopIllegalArgumentException("Too many arguments.");
  }
}
 
Example 4
Source File: DFSAdmin.java    From big-c with Apache License 2.0 6 votes vote down vote up
/** Constructor */
SetSpaceQuotaCommand(String[] args, int pos, FileSystem fs) {
  super(fs);
  CommandFormat c = new CommandFormat(2, Integer.MAX_VALUE);
  List<String> parameters = c.parse(args, pos);
  String str = parameters.remove(0).trim();
  try {
    quota = StringUtils.TraditionalBinaryPrefix.string2long(str);
  } catch (NumberFormatException nfe) {
    throw new IllegalArgumentException("\"" + str + "\" is not a valid value for a quota.");
  }
  String storageTypeString =
      StringUtils.popOptionWithArgument("-storageType", parameters);
  if (storageTypeString != null) {
    this.type = StorageType.parseStorageType(storageTypeString);
  }
  
  this.args = parameters.toArray(new String[parameters.size()]);
}
 
Example 5
Source File: CryptoAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  final String path = StringUtils.popOptionWithArgument("-path", args);
  if (path == null) {
    System.err.println("You must specify a path with -path.");
    return 1;
  }

  final String keyName =
      StringUtils.popOptionWithArgument("-keyName", args);
  if (keyName == null) {
    System.err.println("You must specify a key name with -keyName.");
    return 1;
  }

  if (!args.isEmpty()) {
    System.err.println("Can't understand argument: " + args.get(0));
    return 1;
  }

  final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    dfs.createEncryptionZone(new Path(path), keyName);
    System.out.println("Added encryption zone " + path);
  } catch (IOException e) {
    System.err.println(prettifyException(e));
    return 2;
  }

  return 0;
}
 
Example 6
Source File: StoragePolicyAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  final String path = StringUtils.popOptionWithArgument("-path", args);
  if (path == null) {
    System.err.println("Please specify the path with -path.\nUsage:" +
        getLongUsage());
    return 1;
  }

  final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    HdfsFileStatus status = dfs.getClient().getFileInfo(path);
    if (status == null) {
      System.err.println("File/Directory does not exist: " + path);
      return 2;
    }
    byte storagePolicyId = status.getStoragePolicy();
    if (storagePolicyId == BlockStoragePolicySuite.ID_UNSPECIFIED) {
      System.out.println("The storage policy of " + path + " is unspecified");
      return 0;
    }
    BlockStoragePolicy[] policies = dfs.getStoragePolicies();
    for (BlockStoragePolicy p : policies) {
      if (p.getId() == storagePolicyId) {
        System.out.println("The storage policy of " + path + ":\n" + p);
        return 0;
      }
    }
  } catch (Exception e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  System.err.println("Cannot identify the storage policy for " + path);
  return 2;
}
 
Example 7
Source File: StoragePolicyAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  final String path = StringUtils.popOptionWithArgument("-path", args);
  if (path == null) {
    System.err.println("Please specify the path for setting the storage " +
        "policy.\nUsage: " + getLongUsage());
    return 1;
  }

  final String policyName = StringUtils.popOptionWithArgument("-policy",
      args);
  if (policyName == null) {
    System.err.println("Please specify the policy name.\nUsage: " +
        getLongUsage());
    return 1;
  }

  final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    dfs.setStoragePolicy(new Path(path), policyName);
    System.out.println("Set storage policy " + policyName + " on " + path);
  } catch (Exception e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  return 0;
}
 
Example 8
Source File: DFSAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/** Constructor */
ClearSpaceQuotaCommand(String[] args, int pos, FileSystem fs) {
  super(fs);
  CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE);
  List<String> parameters = c.parse(args, pos);
  String storageTypeString =
      StringUtils.popOptionWithArgument("-storageType", parameters);
  if (storageTypeString != null) {
    this.type = StorageType.parseStorageType(storageTypeString);
  }
  this.args = parameters.toArray(new String[parameters.size()]);
}
 
Example 9
Source File: XAttrCommands.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
  name = StringUtils.popOptionWithArgument("-n", args);
  String en = StringUtils.popOptionWithArgument("-e", args);
  if (en != null) {
    try {
      encoding = enValueOfFunc.apply(StringUtils.toUpperCase(en));
    } catch (IllegalArgumentException e) {
      throw new IllegalArgumentException(
          "Invalid/unsupported encoding option specified: " + en);
    }
    Preconditions.checkArgument(encoding != null,
        "Invalid/unsupported encoding option specified: " + en);
  }

  boolean r = StringUtils.popOption("-R", args);
  setRecursive(r);
  dump = StringUtils.popOption("-d", args);

  if (!dump && name == null) {
    throw new HadoopIllegalArgumentException(
        "Must specify '-n name' or '-d' option.");
  }

  if (args.isEmpty()) {
    throw new HadoopIllegalArgumentException("<path> is missing.");
  }
  if (args.size() > 1) {
    throw new HadoopIllegalArgumentException("Too many arguments.");
  }
}
 
Example 10
Source File: CryptoAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  final String path = StringUtils.popOptionWithArgument("-path", args);
  if (path == null) {
    System.err.println("You must specify a path with -path.");
    return 1;
  }

  final String keyName =
      StringUtils.popOptionWithArgument("-keyName", args);
  if (keyName == null) {
    System.err.println("You must specify a key name with -keyName.");
    return 1;
  }

  if (!args.isEmpty()) {
    System.err.println("Can't understand argument: " + args.get(0));
    return 1;
  }

  final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    dfs.createEncryptionZone(new Path(path), keyName);
    System.out.println("Added encryption zone " + path);
  } catch (IOException e) {
    System.err.println(prettifyException(e));
    return 2;
  }

  return 0;
}
 
Example 11
Source File: XAttrCommands.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
  name = StringUtils.popOptionWithArgument("-n", args);
  String en = StringUtils.popOptionWithArgument("-e", args);
  if (en != null) {
    try {
      encoding = enValueOfFunc.apply(StringUtils.toUpperCase(en));
    } catch (IllegalArgumentException e) {
      throw new IllegalArgumentException(
          "Invalid/unsupported encoding option specified: " + en);
    }
    Preconditions.checkArgument(encoding != null,
        "Invalid/unsupported encoding option specified: " + en);
  }

  boolean r = StringUtils.popOption("-R", args);
  setRecursive(r);
  dump = StringUtils.popOption("-d", args);

  if (!dump && name == null) {
    throw new HadoopIllegalArgumentException(
        "Must specify '-n name' or '-d' option.");
  }

  if (args.isEmpty()) {
    throw new HadoopIllegalArgumentException("<path> is missing.");
  }
  if (args.size() > 1) {
    throw new HadoopIllegalArgumentException("Too many arguments.");
  }
}
 
Example 12
Source File: StoragePolicyAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  final String path = StringUtils.popOptionWithArgument("-path", args);
  if (path == null) {
    System.err.println("Please specify the path with -path.\nUsage:" +
        getLongUsage());
    return 1;
  }

  final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    HdfsFileStatus status = dfs.getClient().getFileInfo(path);
    if (status == null) {
      System.err.println("File/Directory does not exist: " + path);
      return 2;
    }
    byte storagePolicyId = status.getStoragePolicy();
    if (storagePolicyId == BlockStoragePolicySuite.ID_UNSPECIFIED) {
      System.out.println("The storage policy of " + path + " is unspecified");
      return 0;
    }
    BlockStoragePolicy[] policies = dfs.getStoragePolicies();
    for (BlockStoragePolicy p : policies) {
      if (p.getId() == storagePolicyId) {
        System.out.println("The storage policy of " + path + ":\n" + p);
        return 0;
      }
    }
  } catch (Exception e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  System.err.println("Cannot identify the storage policy for " + path);
  return 2;
}
 
Example 13
Source File: StoragePolicyAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  final String path = StringUtils.popOptionWithArgument("-path", args);
  if (path == null) {
    System.err.println("Please specify the path for setting the storage " +
        "policy.\nUsage: " + getLongUsage());
    return 1;
  }

  final String policyName = StringUtils.popOptionWithArgument("-policy",
      args);
  if (policyName == null) {
    System.err.println("Please specify the policy name.\nUsage: " +
        getLongUsage());
    return 1;
  }

  final DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    dfs.setStoragePolicy(new Path(path), policyName);
    System.out.println("Set storage policy " + policyName + " on " + path);
  } catch (Exception e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  return 0;
}
 
Example 14
Source File: DFSAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
/** Constructor */
ClearSpaceQuotaCommand(String[] args, int pos, FileSystem fs) {
  super(fs);
  CommandFormat c = new CommandFormat(1, Integer.MAX_VALUE);
  List<String> parameters = c.parse(args, pos);
  String storageTypeString =
      StringUtils.popOptionWithArgument("-storageType", parameters);
  if (storageTypeString != null) {
    this.type = StorageType.parseStorageType(storageTypeString);
  }
  this.args = parameters.toArray(new String[parameters.size()]);
}
 
Example 15
Source File: TraceAdmin.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public int run(String argv[]) throws Exception {
  LinkedList<String> args = new LinkedList<String>();
  for (String arg : argv) {
    args.add(arg);
  }
  if (StringUtils.popOption("-h", args) ||
      StringUtils.popOption("-help", args)) {
    usage();
    return 0;
  } else if (args.size() == 0) {
    usage();
    return 0;
  }
  String hostPort = StringUtils.popOptionWithArgument("-host", args);
  if (hostPort == null) {
    System.err.println("You must specify a host with -host.");
    return 1;
  }
  if (args.size() < 0) {
    System.err.println("You must specify an operation.");
    return 1;
  }
  RPC.setProtocolEngine(getConf(), TraceAdminProtocolPB.class,
      ProtobufRpcEngine.class);
  InetSocketAddress address = NetUtils.createSocketAddr(hostPort);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  Class<?> xface = TraceAdminProtocolPB.class;
  proxy = (TraceAdminProtocolPB)RPC.getProxy(xface,
      RPC.getProtocolVersion(xface), address,
      ugi, getConf(), NetUtils.getDefaultSocketFactory(getConf()), 0);
  remote = new TraceAdminProtocolTranslatorPB(proxy);
  try {
    if (args.get(0).equals("-list")) {
      return listSpanReceivers(args.subList(1, args.size()));
    } else if (args.get(0).equals("-add")) {
      return addSpanReceiver(args.subList(1, args.size()));
    } else if (args.get(0).equals("-remove")) {
      return removeSpanReceiver(args.subList(1, args.size()));
    } else {
      System.err.println("Unrecognized tracing command: " + args.get(0));
      System.err.println("Use -help for help.");
      return 1;
    }
  } finally {
    remote.close();
  }
}
 
Example 16
Source File: TraceAdmin.java    From big-c with Apache License 2.0 4 votes vote down vote up
private int addSpanReceiver(List<String> args) throws IOException {
  String className = StringUtils.popOptionWithArgument("-class", args);
  if (className == null) {
    System.err.println("You must specify the classname with -class.");
    return 1;
  }
  ByteArrayOutputStream configStream = new ByteArrayOutputStream();
  PrintStream configsOut = new PrintStream(configStream, false, "UTF-8");
  SpanReceiverInfoBuilder factory = new SpanReceiverInfoBuilder(className);
  String prefix = "";
  for (int i = 0; i < args.size(); ++i) {
    String str = args.get(i);
    if (!str.startsWith(CONFIG_PREFIX)) {
      System.err.println("Can't understand argument: " + str);
      return 1;
    }
    str = str.substring(CONFIG_PREFIX.length());
    int equalsIndex = str.indexOf("=");
    if (equalsIndex < 0) {
      System.err.println("Can't parse configuration argument " + str);
      System.err.println("Arguments must be in the form key=value");
      return 1;
    }
    String key = str.substring(0, equalsIndex);
    String value = str.substring(equalsIndex + 1);
    factory.addConfigurationPair(key, value);
    configsOut.print(prefix + key + " = " + value);
    prefix = ", ";
  }

  String configStreamStr = configStream.toString("UTF-8");
  try {
    long id = remote.addSpanReceiver(factory.build());
    System.out.println("Added trace span receiver " + id +
        " with configuration " + configStreamStr);
  } catch (IOException e) {
    System.out.println("addSpanReceiver error with configuration " +
                           configStreamStr);
    throw e;
  }
  return 0;
}
 
Example 17
Source File: CacheAdmin.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  CacheDirectiveInfo.Builder builder =
      new CacheDirectiveInfo.Builder();
  String pathFilter = StringUtils.popOptionWithArgument("-path", args);
  if (pathFilter != null) {
    builder.setPath(new Path(pathFilter));
  }
  String poolFilter = StringUtils.popOptionWithArgument("-pool", args);
  if (poolFilter != null) {
    builder.setPool(poolFilter);
  }
  boolean printStats = StringUtils.popOption("-stats", args);
  String idFilter = StringUtils.popOptionWithArgument("-id", args);
  if (idFilter != null) {
    builder.setId(Long.parseLong(idFilter));
  }
  if (!args.isEmpty()) {
    System.err.println("Can't understand argument: " + args.get(0));
    return 1;
  }
  TableListing.Builder tableBuilder = new TableListing.Builder().
      addField("ID", Justification.RIGHT).
      addField("POOL", Justification.LEFT).
      addField("REPL", Justification.RIGHT).
      addField("EXPIRY", Justification.LEFT).
      addField("PATH", Justification.LEFT);
  if (printStats) {
    tableBuilder.addField("BYTES_NEEDED", Justification.RIGHT).
                addField("BYTES_CACHED", Justification.RIGHT).
                addField("FILES_NEEDED", Justification.RIGHT).
                addField("FILES_CACHED", Justification.RIGHT);
  }
  TableListing tableListing = tableBuilder.build();
  try {
    DistributedFileSystem dfs = AdminHelper.getDFS(conf);
    RemoteIterator<CacheDirectiveEntry> iter =
        dfs.listCacheDirectives(builder.build());
    int numEntries = 0;
    while (iter.hasNext()) {
      CacheDirectiveEntry entry = iter.next();
      CacheDirectiveInfo directive = entry.getInfo();
      CacheDirectiveStats stats = entry.getStats();
      List<String> row = new LinkedList<String>();
      row.add("" + directive.getId());
      row.add(directive.getPool());
      row.add("" + directive.getReplication());
      String expiry;
      // This is effectively never, round for nice printing
      if (directive.getExpiration().getMillis() >
          Expiration.MAX_RELATIVE_EXPIRY_MS / 2) {
        expiry = "never";
      } else {
        expiry = directive.getExpiration().toString();
      }
      row.add(expiry);
      row.add(directive.getPath().toUri().getPath());
      if (printStats) {
        row.add("" + stats.getBytesNeeded());
        row.add("" + stats.getBytesCached());
        row.add("" + stats.getFilesNeeded());
        row.add("" + stats.getFilesCached());
      }
      tableListing.addRow(row.toArray(new String[row.size()]));
      numEntries++;
    }
    System.out.print(String.format("Found %d entr%s%n",
        numEntries, numEntries == 1 ? "y" : "ies"));
    if (numEntries > 0) {
      System.out.print(tableListing);
    }
  } catch (IOException e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  return 0;
}
 
Example 18
Source File: TraceAdmin.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public int run(String argv[]) throws Exception {
  LinkedList<String> args = new LinkedList<String>();
  for (String arg : argv) {
    args.add(arg);
  }
  if (StringUtils.popOption("-h", args) ||
      StringUtils.popOption("-help", args)) {
    usage();
    return 0;
  } else if (args.size() == 0) {
    usage();
    return 0;
  }
  String hostPort = StringUtils.popOptionWithArgument("-host", args);
  if (hostPort == null) {
    System.err.println("You must specify a host with -host.");
    return 1;
  }
  if (args.size() < 0) {
    System.err.println("You must specify an operation.");
    return 1;
  }
  RPC.setProtocolEngine(getConf(), TraceAdminProtocolPB.class,
      ProtobufRpcEngine.class);
  InetSocketAddress address = NetUtils.createSocketAddr(hostPort);
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  Class<?> xface = TraceAdminProtocolPB.class;
  proxy = (TraceAdminProtocolPB)RPC.getProxy(xface,
      RPC.getProtocolVersion(xface), address,
      ugi, getConf(), NetUtils.getDefaultSocketFactory(getConf()), 0);
  remote = new TraceAdminProtocolTranslatorPB(proxy);
  try {
    if (args.get(0).equals("-list")) {
      return listSpanReceivers(args.subList(1, args.size()));
    } else if (args.get(0).equals("-add")) {
      return addSpanReceiver(args.subList(1, args.size()));
    } else if (args.get(0).equals("-remove")) {
      return removeSpanReceiver(args.subList(1, args.size()));
    } else {
      System.err.println("Unrecognized tracing command: " + args.get(0));
      System.err.println("Use -help for help.");
      return 1;
    }
  } finally {
    remote.close();
  }
}
 
Example 19
Source File: TraceAdmin.java    From hadoop with Apache License 2.0 4 votes vote down vote up
private int addSpanReceiver(List<String> args) throws IOException {
  String className = StringUtils.popOptionWithArgument("-class", args);
  if (className == null) {
    System.err.println("You must specify the classname with -class.");
    return 1;
  }
  ByteArrayOutputStream configStream = new ByteArrayOutputStream();
  PrintStream configsOut = new PrintStream(configStream, false, "UTF-8");
  SpanReceiverInfoBuilder factory = new SpanReceiverInfoBuilder(className);
  String prefix = "";
  for (int i = 0; i < args.size(); ++i) {
    String str = args.get(i);
    if (!str.startsWith(CONFIG_PREFIX)) {
      System.err.println("Can't understand argument: " + str);
      return 1;
    }
    str = str.substring(CONFIG_PREFIX.length());
    int equalsIndex = str.indexOf("=");
    if (equalsIndex < 0) {
      System.err.println("Can't parse configuration argument " + str);
      System.err.println("Arguments must be in the form key=value");
      return 1;
    }
    String key = str.substring(0, equalsIndex);
    String value = str.substring(equalsIndex + 1);
    factory.addConfigurationPair(key, value);
    configsOut.print(prefix + key + " = " + value);
    prefix = ", ";
  }

  String configStreamStr = configStream.toString("UTF-8");
  try {
    long id = remote.addSpanReceiver(factory.build());
    System.out.println("Added trace span receiver " + id +
        " with configuration " + configStreamStr);
  } catch (IOException e) {
    System.out.println("addSpanReceiver error with configuration " +
                           configStreamStr);
    throw e;
  }
  return 0;
}
 
Example 20
Source File: CacheAdmin.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  CacheDirectiveInfo.Builder builder =
      new CacheDirectiveInfo.Builder();
  String pathFilter = StringUtils.popOptionWithArgument("-path", args);
  if (pathFilter != null) {
    builder.setPath(new Path(pathFilter));
  }
  String poolFilter = StringUtils.popOptionWithArgument("-pool", args);
  if (poolFilter != null) {
    builder.setPool(poolFilter);
  }
  boolean printStats = StringUtils.popOption("-stats", args);
  String idFilter = StringUtils.popOptionWithArgument("-id", args);
  if (idFilter != null) {
    builder.setId(Long.parseLong(idFilter));
  }
  if (!args.isEmpty()) {
    System.err.println("Can't understand argument: " + args.get(0));
    return 1;
  }
  TableListing.Builder tableBuilder = new TableListing.Builder().
      addField("ID", Justification.RIGHT).
      addField("POOL", Justification.LEFT).
      addField("REPL", Justification.RIGHT).
      addField("EXPIRY", Justification.LEFT).
      addField("PATH", Justification.LEFT);
  if (printStats) {
    tableBuilder.addField("BYTES_NEEDED", Justification.RIGHT).
                addField("BYTES_CACHED", Justification.RIGHT).
                addField("FILES_NEEDED", Justification.RIGHT).
                addField("FILES_CACHED", Justification.RIGHT);
  }
  TableListing tableListing = tableBuilder.build();
  try {
    DistributedFileSystem dfs = AdminHelper.getDFS(conf);
    RemoteIterator<CacheDirectiveEntry> iter =
        dfs.listCacheDirectives(builder.build());
    int numEntries = 0;
    while (iter.hasNext()) {
      CacheDirectiveEntry entry = iter.next();
      CacheDirectiveInfo directive = entry.getInfo();
      CacheDirectiveStats stats = entry.getStats();
      List<String> row = new LinkedList<String>();
      row.add("" + directive.getId());
      row.add(directive.getPool());
      row.add("" + directive.getReplication());
      String expiry;
      // This is effectively never, round for nice printing
      if (directive.getExpiration().getMillis() >
          Expiration.MAX_RELATIVE_EXPIRY_MS / 2) {
        expiry = "never";
      } else {
        expiry = directive.getExpiration().toString();
      }
      row.add(expiry);
      row.add(directive.getPath().toUri().getPath());
      if (printStats) {
        row.add("" + stats.getBytesNeeded());
        row.add("" + stats.getBytesCached());
        row.add("" + stats.getFilesNeeded());
        row.add("" + stats.getFilesCached());
      }
      tableListing.addRow(row.toArray(new String[row.size()]));
      numEntries++;
    }
    System.out.print(String.format("Found %d entr%s%n",
        numEntries, numEntries == 1 ? "y" : "ies"));
    if (numEntries > 0) {
      System.out.print(tableListing);
    }
  } catch (IOException e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  return 0;
}