ACCUMULO-802 added -l option to namespaces command
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/d10feb7c Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/d10feb7c Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/d10feb7c Branch: refs/heads/1.6.0-SNAPSHOT Commit: d10feb7c7f7ae9eb5affe69ab18959e8bd7c16d7 Parents: 51f07eb Author: Sean Hickey <tallirishll...@gmail.com> Authored: Mon Aug 12 08:11:31 2013 -0400 Committer: Christopher Tubbs <ctubb...@apache.org> Committed: Wed Dec 4 18:46:10 2013 -0500 ---------------------------------------------------------------------- .../util/shell/commands/NamespacesCommand.java | 34 ++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/d10feb7c/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NamespacesCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NamespacesCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NamespacesCommand.java index dcb4bd7..ad30699 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NamespacesCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NamespacesCommand.java @@ -17,6 +17,9 @@ package org.apache.accumulo.core.util.shell.commands; import java.io.IOException; +import java.util.Iterator; +import java.util.TreeMap; +import java.util.Map.Entry; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; @@ -25,16 +28,41 @@ import org.apache.accumulo.core.util.shell.Shell.Command; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Option; import org.apache.commons.cli.Options; +import org.apache.commons.collections.iterators.AbstractIteratorDecorator; public class NamespacesCommand extends Command { - private Option disablePaginationOpt; + private Option disablePaginationOpt, namespaceIdOption; + @SuppressWarnings("unchecked") @Override public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { - shellState.printLines(shellState.getConnector().tableNamespaceOperations().list().iterator(), !cl.hasOption(disablePaginationOpt.getOpt())); + Iterator<String> names = shellState.getConnector().tableNamespaceOperations().list().iterator(); + Iterator<String> ids = new NamespaceIdIterator(new TreeMap<String,String>(shellState.getConnector().tableNamespaceOperations().namespaceIdMap()).entrySet().iterator()); + + if (cl.hasOption(namespaceIdOption.getOpt())) { + shellState.printLines(ids, !cl.hasOption(disablePaginationOpt.getOpt())); + } else { + shellState.printLines(names, !cl.hasOption(disablePaginationOpt.getOpt())); + } return 0; } + /** + * Decorator that formats the id and name for display. + */ + private static final class NamespaceIdIterator extends AbstractIteratorDecorator { + public NamespaceIdIterator(Iterator<Entry<String,String>> iterator) { + super(iterator); + } + + @SuppressWarnings("rawtypes") + @Override + public Object next() { + Entry entry = (Entry) super.next(); + return String.format("%-15s => %10s%n", entry.getKey(), entry.getValue()); + } + } + @Override public String description() { return "displays a list of all existing table namespaces"; @@ -43,6 +71,8 @@ public class NamespacesCommand extends Command { @Override public Options getOptions() { final Options o = new Options(); + namespaceIdOption = new Option("l", "list-ids", false, "display internal table namespace ids along with the name"); + o.addOption(namespaceIdOption); disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output"); o.addOption(disablePaginationOpt); return o;