ACCUMULO-802 added -tn option to the TablesCommand to allow listing of tables within a specific namespace
Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/2f693507 Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/2f693507 Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/2f693507 Branch: refs/heads/ACCUMULO-802 Commit: 2f693507bb721b59609c7ac286300b0556d0902b Parents: f90e0fb Author: Sean Hickey <[email protected]> Authored: Tue Jul 23 09:36:20 2013 -0400 Committer: Christopher Tubbs <[email protected]> Committed: Thu Oct 31 21:24:36 2013 -0400 ---------------------------------------------------------------------- .../core/util/shell/commands/ConfigCommand.java | 2 +- .../core/util/shell/commands/DUCommand.java | 2 +- .../util/shell/commands/TableOperation.java | 2 +- .../core/util/shell/commands/TablesCommand.java | 28 ++++++++++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/accumulo/blob/2f693507/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java index dcfc48c..c2f93be 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java @@ -261,7 +261,7 @@ public class ConfigCommand extends Command { filterOpt = new Option("f", "filter", true, "show only properties that contain this string"); disablePaginationOpt = new Option("np", "no-pagination", false, "disables pagination of output"); outputFileOpt = new Option("o", "output", true, "local file to write the scan output to"); - tableNamespaceOpt = new Option("tn", "table-namespace", true, "table namespace to display/set/delete properties for"); + tableNamespaceOpt = new Option(Shell.tableNamespaceOption, "table-namespace", true, "table namespace to display/set/delete properties for"); tableOpt.setArgName("table"); deleteOpt.setArgName("property"); http://git-wip-us.apache.org/repos/asf/accumulo/blob/2f693507/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DUCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DUCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DUCommand.java index 356cfed..817809d 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DUCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DUCommand.java @@ -96,7 +96,7 @@ public class DUCommand extends Command { optHumanReadble = new Option("h", "human-readable", false, "format large sizes to human readable units"); optHumanReadble.setArgName("human readable output"); - optTableNamespace = new Option("tn", "table-namespace", true, "name of a table namespace"); + optTableNamespace = new Option(Shell.tableNamespaceOption, "table-namespace", true, "name of a table namespace"); optTableNamespace.setArgName("table-namespace"); o.addOption(OptUtil.tableOpt("table to examine")); http://git-wip-us.apache.org/repos/asf/accumulo/blob/2f693507/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java index 4b8b304..e2ec71f 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java @@ -108,7 +108,7 @@ public abstract class TableOperation extends Command { optTableName = new Option(Shell.tableOption, "table", true, "name of a table to operate on"); optTableName.setArgName("tableName"); - optTableNamespace = new Option("tn", "tableNamespace", true, "name of a table namespace to operate on"); + optTableNamespace = new Option(Shell.tableNamespaceOption, "table-namespace", true, "name of a table namespace to operate on"); optTableNamespace.setArgName("tableNamespace"); final OptionGroup opg = new OptionGroup(); http://git-wip-us.apache.org/repos/asf/accumulo/blob/2f693507/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java index 19b49e9..8a5d15c 100644 --- a/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java +++ b/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TablesCommand.java @@ -18,12 +18,13 @@ package org.apache.accumulo.core.util.shell.commands; import java.io.IOException; import java.util.Iterator; -import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import org.apache.accumulo.core.client.AccumuloException; import org.apache.accumulo.core.client.AccumuloSecurityException; +import org.apache.accumulo.core.client.TableNamespaceNotFoundException; +import org.apache.accumulo.core.client.impl.TableNamespaces; import org.apache.accumulo.core.util.shell.Shell; import org.apache.accumulo.core.util.shell.Shell.Command; import org.apache.commons.cli.CommandLine; @@ -34,16 +35,31 @@ import org.apache.commons.collections.iterators.AbstractIteratorDecorator; public class TablesCommand extends Command { private Option tableIdOption; private Option disablePaginationOpt; + private Option tableNamespaceOpt; @SuppressWarnings("unchecked") @Override - public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException { + public int execute(final String fullCommand, final CommandLine cl, final Shell shellState) throws AccumuloException, AccumuloSecurityException, IOException, + TableNamespaceNotFoundException { + + final Iterator<String> tableNames; + final Iterator<String> tableIds; + + if (cl.hasOption(tableNamespaceOpt.getOpt())) { + String namespace = shellState.getConnector().tableNamespaceOperations().namespaceIdMap().get(cl.getOptionValue(tableNamespaceOpt.getOpt())); + tableNames = TableNamespaces.getTableNames(shellState.getConnector().getInstance(), namespace).iterator(); + tableIds = TableNamespaces.getTableIds(shellState.getConnector().getInstance(), namespace).iterator(); + } else { + tableNames = shellState.getConnector().tableOperations().list().iterator(); + tableIds = new TableIdIterator(new TreeMap<String,String>(shellState.getConnector().tableOperations().tableIdMap()).entrySet().iterator()); + } + if (cl.hasOption(tableIdOption.getOpt())) { - final Map<String,String> tableIds = new TreeMap<String,String>(shellState.getConnector().tableOperations().tableIdMap()); - shellState.printLines(new TableIdIterator(tableIds.entrySet().iterator()), !cl.hasOption(disablePaginationOpt.getOpt())); + shellState.printLines(tableIds, !cl.hasOption(disablePaginationOpt.getOpt())); } else { - shellState.printLines(shellState.getConnector().tableOperations().list().iterator(), !cl.hasOption(disablePaginationOpt.getOpt())); + shellState.printLines(tableNames, !cl.hasOption(disablePaginationOpt.getOpt())); } + return 0; } @@ -75,6 +91,8 @@ public class TablesCommand extends Command { o.addOption(tableIdOption); disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output"); o.addOption(disablePaginationOpt); + tableNamespaceOpt = new Option(Shell.tableNamespaceOption, "table-namespace", true, "name of table namespace to list only its tables"); + o.addOption(tableNamespaceOpt); return o; }
