accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject [47/54] git commit: ACCUMULO-802 added -l option to namespaces command
Date Fri, 01 Nov 2013 02:00:48 GMT
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/1945411e
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/1945411e
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/1945411e

Branch: refs/heads/ACCUMULO-802
Commit: 1945411e24ab2f6ac5dd01f6543697e835dd4f22
Parents: 3340ccc
Author: Sean Hickey <tallirishllama@gmail.com>
Authored: Mon Aug 12 08:11:31 2013 -0400
Committer: Christopher Tubbs <ctubbsii@apache.org>
Committed: Thu Oct 31 21:37:55 2013 -0400

----------------------------------------------------------------------
 .../util/shell/commands/NamespacesCommand.java  | 34 ++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/1945411e/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;


Mime
View raw message