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

The following examples show how to use org.apache.hadoop.util.StringUtils#popFirstNonOption() . 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: CacheAdmin.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  String name = StringUtils.popFirstNonOption(args);
  if (name == null) {
    System.err.println("You must specify a name when deleting a " +
        "cache pool.");
    return 1;
  }
  if (!args.isEmpty()) {
    System.err.print("Can't understand arguments: " +
      Joiner.on(" ").join(args) + "\n");
    System.err.println("Usage is " + getShortUsage());
    return 1;
  }
  DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    dfs.removeCachePool(name);
  } catch (IOException e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  System.out.println("Successfully removed cache pool " + name + ".");
  return 0;
}
 
Example 2
Source File: CacheAdmin.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public int run(Configuration conf, List<String> args) throws IOException {
  String name = StringUtils.popFirstNonOption(args);
  if (name == null) {
    System.err.println("You must specify a name when deleting a " +
        "cache pool.");
    return 1;
  }
  if (!args.isEmpty()) {
    System.err.print("Can't understand arguments: " +
      Joiner.on(" ").join(args) + "\n");
    System.err.println("Usage is " + getShortUsage());
    return 1;
  }
  DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  try {
    dfs.removeCachePool(name);
  } catch (IOException e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  System.out.println("Successfully removed cache pool " + name + ".");
  return 0;
}
 
Example 3
Source File: DFSAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public int triggerBlockReport(String[] argv) throws IOException {
  List<String> args = new LinkedList<String>();
  for (int j = 1; j < argv.length; j++) {
    args.add(argv[j]);
  }
  boolean incremental = StringUtils.popOption("-incremental", args);
  String hostPort = StringUtils.popFirstNonOption(args);
  if (hostPort == null) {
    System.err.println("You must specify a host:port pair.");
    return 1;
  }
  if (!args.isEmpty()) {
    System.err.print("Can't understand arguments: " +
      Joiner.on(" ").join(args) + "\n");
    return 1;
  }
  ClientDatanodeProtocol dnProxy = getDataNodeProxy(hostPort);
  try {
    dnProxy.triggerBlockReport(
        new BlockReportOptions.Factory().
            setIncremental(incremental).
            build());
  } catch (IOException e) {
    System.err.println("triggerBlockReport error: " + e);
    return 1;
  }
  System.out.println("Triggering " +
      (incremental ? "an incremental " : "a full ") +
      "block report on " + hostPort + ".");
  return 0;
}
 
Example 4
Source File: TraceAdmin.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private int removeSpanReceiver(List<String> args) throws IOException {
  String indexStr = StringUtils.popFirstNonOption(args);
  long id = -1;
  try {
    id = Long.parseLong(indexStr);
  } catch (NumberFormatException e) {
    System.err.println("Failed to parse ID string " +
        indexStr + ": " + e.getMessage());
    return 1;
  }
  remote.removeSpanReceiver(id);
  System.err.println("Removed trace span receiver " + id);
  return 0;
}
 
Example 5
Source File: DFSAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
public int triggerBlockReport(String[] argv) throws IOException {
  List<String> args = new LinkedList<String>();
  for (int j = 1; j < argv.length; j++) {
    args.add(argv[j]);
  }
  boolean incremental = StringUtils.popOption("-incremental", args);
  String hostPort = StringUtils.popFirstNonOption(args);
  if (hostPort == null) {
    System.err.println("You must specify a host:port pair.");
    return 1;
  }
  if (!args.isEmpty()) {
    System.err.print("Can't understand arguments: " +
      Joiner.on(" ").join(args) + "\n");
    return 1;
  }
  ClientDatanodeProtocol dnProxy = getDataNodeProxy(hostPort);
  try {
    dnProxy.triggerBlockReport(
        new BlockReportOptions.Factory().
            setIncremental(incremental).
            build());
  } catch (IOException e) {
    System.err.println("triggerBlockReport error: " + e);
    return 1;
  }
  System.out.println("Triggering " +
      (incremental ? "an incremental " : "a full ") +
      "block report on " + hostPort + ".");
  return 0;
}
 
Example 6
Source File: TraceAdmin.java    From big-c with Apache License 2.0 5 votes vote down vote up
private int removeSpanReceiver(List<String> args) throws IOException {
  String indexStr = StringUtils.popFirstNonOption(args);
  long id = -1;
  try {
    id = Long.parseLong(indexStr);
  } catch (NumberFormatException e) {
    System.err.println("Failed to parse ID string " +
        indexStr + ": " + e.getMessage());
    return 1;
  }
  remote.removeSpanReceiver(id);
  System.err.println("Removed trace span receiver " + id);
  return 0;
}
 
Example 7
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 {
  String name = StringUtils.popFirstNonOption(args);
  final boolean printStats = StringUtils.popOption("-stats", args);
  if (!args.isEmpty()) {
    System.err.print("Can't understand arguments: " +
      Joiner.on(" ").join(args) + "\n");
    System.err.println("Usage is " + getShortUsage());
    return 1;
  }
  DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  TableListing.Builder builder = new TableListing.Builder().
      addField("NAME", Justification.LEFT).
      addField("OWNER", Justification.LEFT).
      addField("GROUP", Justification.LEFT).
      addField("MODE", Justification.LEFT).
      addField("LIMIT", Justification.RIGHT).
      addField("MAXTTL", Justification.RIGHT);
  if (printStats) {
    builder.
        addField("BYTES_NEEDED", Justification.RIGHT).
        addField("BYTES_CACHED", Justification.RIGHT).
        addField("BYTES_OVERLIMIT", Justification.RIGHT).
        addField("FILES_NEEDED", Justification.RIGHT).
        addField("FILES_CACHED", Justification.RIGHT);
  }
  TableListing listing = builder.build();
  int numResults = 0;
  try {
    RemoteIterator<CachePoolEntry> iter = dfs.listCachePools();
    while (iter.hasNext()) {
      CachePoolEntry entry = iter.next();
      CachePoolInfo info = entry.getInfo();
      LinkedList<String> row = new LinkedList<String>();
      if (name == null || info.getPoolName().equals(name)) {
        row.add(info.getPoolName());
        row.add(info.getOwnerName());
        row.add(info.getGroupName());
        row.add(info.getMode() != null ? info.getMode().toString() : null);
        Long limit = info.getLimit();
        String limitString;
        if (limit != null && limit.equals(CachePoolInfo.LIMIT_UNLIMITED)) {
          limitString = "unlimited";
        } else {
          limitString = "" + limit;
        }
        row.add(limitString);
        Long maxTtl = info.getMaxRelativeExpiryMs();
        String maxTtlString = null;

        if (maxTtl != null) {
          if (maxTtl == CachePoolInfo.RELATIVE_EXPIRY_NEVER) {
            maxTtlString  = "never";
          } else {
            maxTtlString = DFSUtil.durationToString(maxTtl);
          }
        }
        row.add(maxTtlString);
        if (printStats) {
          CachePoolStats stats = entry.getStats();
          row.add(Long.toString(stats.getBytesNeeded()));
          row.add(Long.toString(stats.getBytesCached()));
          row.add(Long.toString(stats.getBytesOverlimit()));
          row.add(Long.toString(stats.getFilesNeeded()));
          row.add(Long.toString(stats.getFilesCached()));
        }
        listing.addRow(row.toArray(new String[row.size()]));
        ++numResults;
        if (name != null) {
          break;
        }
      }
    }
  } catch (IOException e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  System.out.print(String.format("Found %d result%s.%n", numResults,
      (numResults == 1 ? "" : "s")));
  if (numResults > 0) { 
    System.out.print(listing);
  }
  // If list pools succeed, we return 0 (success exit code)
  return 0;
}
 
Example 8
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 {
  String name = StringUtils.popFirstNonOption(args);
  final boolean printStats = StringUtils.popOption("-stats", args);
  if (!args.isEmpty()) {
    System.err.print("Can't understand arguments: " +
      Joiner.on(" ").join(args) + "\n");
    System.err.println("Usage is " + getShortUsage());
    return 1;
  }
  DistributedFileSystem dfs = AdminHelper.getDFS(conf);
  TableListing.Builder builder = new TableListing.Builder().
      addField("NAME", Justification.LEFT).
      addField("OWNER", Justification.LEFT).
      addField("GROUP", Justification.LEFT).
      addField("MODE", Justification.LEFT).
      addField("LIMIT", Justification.RIGHT).
      addField("MAXTTL", Justification.RIGHT);
  if (printStats) {
    builder.
        addField("BYTES_NEEDED", Justification.RIGHT).
        addField("BYTES_CACHED", Justification.RIGHT).
        addField("BYTES_OVERLIMIT", Justification.RIGHT).
        addField("FILES_NEEDED", Justification.RIGHT).
        addField("FILES_CACHED", Justification.RIGHT);
  }
  TableListing listing = builder.build();
  int numResults = 0;
  try {
    RemoteIterator<CachePoolEntry> iter = dfs.listCachePools();
    while (iter.hasNext()) {
      CachePoolEntry entry = iter.next();
      CachePoolInfo info = entry.getInfo();
      LinkedList<String> row = new LinkedList<String>();
      if (name == null || info.getPoolName().equals(name)) {
        row.add(info.getPoolName());
        row.add(info.getOwnerName());
        row.add(info.getGroupName());
        row.add(info.getMode() != null ? info.getMode().toString() : null);
        Long limit = info.getLimit();
        String limitString;
        if (limit != null && limit.equals(CachePoolInfo.LIMIT_UNLIMITED)) {
          limitString = "unlimited";
        } else {
          limitString = "" + limit;
        }
        row.add(limitString);
        Long maxTtl = info.getMaxRelativeExpiryMs();
        String maxTtlString = null;

        if (maxTtl != null) {
          if (maxTtl == CachePoolInfo.RELATIVE_EXPIRY_NEVER) {
            maxTtlString  = "never";
          } else {
            maxTtlString = DFSUtil.durationToString(maxTtl);
          }
        }
        row.add(maxTtlString);
        if (printStats) {
          CachePoolStats stats = entry.getStats();
          row.add(Long.toString(stats.getBytesNeeded()));
          row.add(Long.toString(stats.getBytesCached()));
          row.add(Long.toString(stats.getBytesOverlimit()));
          row.add(Long.toString(stats.getFilesNeeded()));
          row.add(Long.toString(stats.getFilesCached()));
        }
        listing.addRow(row.toArray(new String[row.size()]));
        ++numResults;
        if (name != null) {
          break;
        }
      }
    }
  } catch (IOException e) {
    System.err.println(AdminHelper.prettifyException(e));
    return 2;
  }
  System.out.print(String.format("Found %d result%s.%n", numResults,
      (numResults == 1 ? "" : "s")));
  if (numResults > 0) { 
    System.out.print(listing);
  }
  // If list pools succeed, we return 0 (success exit code)
  return 0;
}