accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1335772 [1/2] - in /accumulo/trunk: ./ core/ core/src/main/java/org/apache/accumulo/core/util/shell/ core/src/main/java/org/apache/accumulo/core/util/shell/commands/ server/ server/src/main/java/org/apache/accumulo/server/logger/ src/ test...
Date Tue, 08 May 2012 21:14:40 GMT
Author: billie
Date: Tue May  8 21:14:39 2012
New Revision: 1335772

URL: http://svn.apache.org/viewvc?rev=1335772&view=rev
Log:
ACCUMULO-579 ACCUMULO-572 made use of table options consistent, added some tests, created constraint command

Added:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java   (with props)
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java   (with props)
Modified:
    accumulo/trunk/   (props changed)
    accumulo/trunk/core/   (props changed)
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteScanIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteTableCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FormatterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RevokeCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetGroupsCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SleepCommand.java
    accumulo/trunk/server/   (props changed)
    accumulo/trunk/server/src/main/java/org/apache/accumulo/server/logger/LogReader.java
    accumulo/trunk/src/   (props changed)
    accumulo/trunk/test/system/auto/simple/shell.py

Propchange: accumulo/trunk/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/src:r1335106-1335108
  Merged /accumulo/branches/1.4:r1335106-1335108

Propchange: accumulo/trunk/core/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/core:r1335106-1335108
  Merged /accumulo/branches/1.4/src/core:r1335106-1335108

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/Shell.java Tue May  8 21:14:39 2012
@@ -73,6 +73,7 @@ import org.apache.accumulo.core.util.she
 import org.apache.accumulo.core.util.shell.commands.ClsCommand;
 import org.apache.accumulo.core.util.shell.commands.CompactCommand;
 import org.apache.accumulo.core.util.shell.commands.ConfigCommand;
+import org.apache.accumulo.core.util.shell.commands.ConstraintCommand;
 import org.apache.accumulo.core.util.shell.commands.CreateTableCommand;
 import org.apache.accumulo.core.util.shell.commands.CreateUserCommand;
 import org.apache.accumulo.core.util.shell.commands.DUCommand;
@@ -295,8 +296,8 @@ public class Shell extends ShellOptions 
         new UserCommand(), new WhoAmICommand()};
     Command[] tableCommands = {new CloneTableCommand(), new ConfigCommand(), new CreateTableCommand(), new DeleteTableCommand(), new DropTableCommand(),
         new DUCommand(), new OfflineCommand(), new OnlineCommand(), new RenameTableCommand(), new TablesCommand()};
-    Command[] tableControlCommands = {new AddSplitsCommand(), new CompactCommand(), new FlushCommand(), new GetGroupsCommand(), new GetSplitsCommand(),
-        new MergeCommand(), new SetGroupsCommand()};
+    Command[] tableControlCommands = {new AddSplitsCommand(), new CompactCommand(), new ConstraintCommand(), new FlushCommand(), new GetGroupsCommand(),
+        new GetSplitsCommand(), new MergeCommand(), new SetGroupsCommand()};
     Command[] userCommands = {new CreateUserCommand(), new DeleteUserCommand(), new DropUserCommand(), new GetAuthsCommand(), new PasswdCommand(),
         new SetAuthsCommand(), new UsersCommand()};
     commandGrouping.put("-- Writing, Reading, and Removing Data --", dataCommands);
@@ -659,6 +660,10 @@ public class Shell extends ShellOptions 
     
     public abstract String description();
     
+    /**
+     * If the number of arguments is not always zero (not including those arguments handled through Options), make sure to override the {@link #usage()} method.
+     * Otherwise, {@link #usage()} does need to be overridden.
+     */
     public abstract int numArgs();
     
     // OPTIONAL methods to override:
@@ -708,56 +713,48 @@ public class Shell extends ShellOptions 
   
   public static abstract class TableOperation extends Command {
     
-    private Option optTablePattern, optTableName;
+    protected Option optTablePattern, optTableName;
+    private boolean force = true;
     
     public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
-      
-      String originalTable = "";
-      
-      if (shellState.getTableName() != "") {
-        originalTable = shellState.getTableName();
-      }
-      
-      if (cl.hasOption(optTableName.getOpt())) {
-        String tableName = cl.getOptionValue(optTableName.getOpt());
-        shellState.setTableName(tableName);
-      }
-      
-      try {
-        // populate the tablesToFlush set with the tables you want to flush
-        SortedSet<String> tablesToFlush = new TreeSet<String>();
-        if (cl.hasOption(optTablePattern.getOpt())) {
-          for (String table : shellState.getConnector().tableOperations().list())
-            if (table.matches(cl.getOptionValue(optTablePattern.getOpt())))
-              tablesToFlush.add(table);
-        } else if (cl.hasOption(optTableName.getOpt())) {
-          tablesToFlush.add(cl.getOptionValue(optTableName.getOpt()));
-        }
-        
-        else {
-          shellState.checkTableState();
-          tablesToFlush.add(shellState.getTableName());
+      // populate the tableSet set with the tables you want to operate on
+      SortedSet<String> tableSet = new TreeSet<String>();
+      if (cl.hasOption(optTablePattern.getOpt())) {
+        for (String table : shellState.getConnector().tableOperations().list())
+          if (table.matches(cl.getOptionValue(optTablePattern.getOpt())))
+            tableSet.add(table);
+      } else if (cl.hasOption(optTableName.getOpt())) {
+        tableSet.add(cl.getOptionValue(optTableName.getOpt()));
+      } else {
+        shellState.checkTableState();
+        tableSet.add(shellState.getTableName());
+      }
+      
+      if (tableSet.isEmpty())
+        log.warn("No tables found that match your criteria");
+      
+      boolean more = true;
+      // flush the tables
+      for (String tableName : tableSet) {
+        if (!more)
+          break;
+        if (!shellState.getConnector().tableOperations().exists(tableName))
+          throw new TableNotFoundException(null, tableName, null);
+        boolean operate = true;
+        if (!force) {
+          shellState.getReader().flushConsole();
+          String line = shellState.getReader().readLine(getName() + " { " + tableName + " } (yes|no)? ");
+          more = line != null;
+          operate = line != null && (line.equalsIgnoreCase("y") || line.equalsIgnoreCase("yes"));
         }
-        
-        if (tablesToFlush.isEmpty())
-          log.warn("No tables found that match your criteria");
-        
-        // flush the tables
-        for (String tableName : tablesToFlush) {
-          if (!shellState.getConnector().tableOperations().exists(tableName))
-            throw new TableNotFoundException(null, tableName, null);
+        if (operate)
           doTableOp(shellState, tableName);
-        }
-      }
-      
-      finally {
-        shellState.setTableName(originalTable);
       }
       
       return 0;
     }
     
-    protected abstract void doTableOp(Shell shellState, String tableName) throws AccumuloException, AccumuloSecurityException, TableNotFoundException;
+    protected abstract void doTableOp(Shell shellState, String tableName) throws Exception;
     
     @Override
     public String description() {
@@ -768,10 +765,10 @@ public class Shell extends ShellOptions 
     public Options getOptions() {
       Options o = new Options();
       
-      optTablePattern = new Option("p", "pattern", true, "regex pattern of table names to flush");
+      optTablePattern = new Option("p", "pattern", true, "regex pattern of table names to operate on");
       optTablePattern.setArgName("pattern");
       
-      optTableName = new Option(tableOption, "table", true, "name of a table to flush");
+      optTableName = new Option(tableOption, "table", true, "name of a table to operate on");
       optTableName.setArgName("tableName");
       
       OptionGroup opg = new OptionGroup();
@@ -788,6 +785,14 @@ public class Shell extends ShellOptions 
     public int numArgs() {
       return 0;
     }
+    
+    protected void force() {
+      force = true;
+    }
+    
+    protected void noForce() {
+      force = false;
+    }
   }
   
   public interface PrintLine {

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/AddSplitsCommand.java Tue May  8 21:14:39 2012
@@ -17,11 +17,8 @@
 package org.apache.accumulo.core.util.shell.commands;
 
 import java.io.File;
-import java.io.FileNotFoundException;
 import java.util.TreeSet;
 
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
@@ -33,23 +30,10 @@ import org.apache.commons.codec.binary.B
 import org.apache.hadoop.io.Text;
 
 public class AddSplitsCommand extends Command {
-  private Option tableOpt, optSplitsFile, base64Opt;
+  private Option optSplitsFile, base64Opt;
   
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
-      MissingArgumentException, FileNotFoundException {
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
-    
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     boolean decode = cl.hasOption(base64Opt.getOpt());
     
     TreeSet<Text> splits = new TreeSet<Text>();
@@ -89,16 +73,12 @@ public class AddSplitsCommand extends Co
   public Options getOptions() {
     Options o = new Options();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "name of the table to add split points to");
-    tableOpt.setArgName("tableName");
-    tableOpt.setRequired(false);
-    
     optSplitsFile = new Option("sf", "splits-file", true, "file with a newline-separated list of rows to split the table with");
     optSplitsFile.setArgName("filename");
     
     base64Opt = new Option("b64", "base64encoded", false, "decode encoded split points");
     
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("name of the table to add split points to"));
     o.addOption(optSplitsFile);
     o.addOption(base64Opt);
     return o;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConfigCommand.java Tue May  8 21:14:39 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.accumulo.core.util.shell.commands;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Map;
 import java.util.Map.Entry;
@@ -25,9 +24,6 @@ import java.util.TreeMap;
 
 import jline.ConsoleReader;
 
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.conf.Property;
 import org.apache.accumulo.core.security.ColumnVisibility;
@@ -41,7 +37,7 @@ import org.apache.commons.cli.OptionGrou
 import org.apache.commons.cli.Options;
 
 public class ConfigCommand extends Command {
-  private Option tableOpt, deleteOpt, setOpt, filterOpt, disablePaginationOpt;
+  private Option deleteOpt, setOpt, filterOpt, disablePaginationOpt;
   
   private int COL1 = 8, COL2 = 7;
   private ConsoleReader reader;
@@ -58,14 +54,10 @@ public class ConfigCommand extends Comma
     root.addSubcommand(cmd);
   }
   
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
-      IOException, ClassNotFoundException {
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     reader = shellState.getReader();
     
-    String tableName = cl.getOptionValue(tableOpt.getOpt());
-    if (tableName != null && !shellState.getConnector().tableOperations().exists(tableName))
-      throw new TableNotFoundException(null, tableName, null);
-    
     if (cl.hasOption(deleteOpt.getOpt())) {
       // delete property from table
       String property = cl.getOptionValue(deleteOpt.getOpt());
@@ -74,7 +66,6 @@ public class ConfigCommand extends Comma
       if (tableName != null) {
         if (!Property.isValidTablePropertyKey(property))
           Shell.log.warn("Invalid per-table property : " + property + ", still removing from zookeeper if it's there.");
-        
         shellState.getConnector().tableOperations().removeProperty(tableName, property);
         Shell.log.debug("Successfully deleted table configuration option.");
       } else {
@@ -217,13 +208,11 @@ public class ConfigCommand extends Comma
     Options o = new Options();
     OptionGroup og = new OptionGroup();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to display/set/delete properties for");
     deleteOpt = new Option("d", "delete", true, "delete a per-table property");
     setOpt = new Option("s", "set", true, "set a per-table property");
     filterOpt = new Option("f", "filter", true, "show only properties that contain this string");
     disablePaginationOpt = new Option("np", "no-pagination", false, "disables pagination of output");
     
-    tableOpt.setArgName("table");
     deleteOpt.setArgName("property");
     setOpt.setArgName("property=value");
     filterOpt.setArgName("string");
@@ -232,7 +221,7 @@ public class ConfigCommand extends Comma
     og.addOption(setOpt);
     og.addOption(filterOpt);
     
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to display/set/delete properties for"));
     o.addOptionGroup(og);
     o.addOption(disablePaginationOpt);
     

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java?rev=1335772&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java (added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java Tue May  8 21:14:39 2012
@@ -0,0 +1,110 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import java.util.Map.Entry;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.constraints.Constraint;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.ShellCommandException;
+import org.apache.accumulo.core.util.shell.ShellCommandException.ErrorCode;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Options;
+
+public class ConstraintCommand extends Command {
+  @Override
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
+    int i;
+    
+    switch (OptUtil.configureAldOpt(cl)) {
+      case ADD:
+        TreeSet<Integer> constraintNumbers = new TreeSet<Integer>();
+        TreeMap<String,Integer> constraintClasses = new TreeMap<String,Integer>();
+        for (Entry<String,String> property : shellState.getConnector().tableOperations().getProperties(tableName)) {
+          if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString())) {
+            i = Integer.parseInt(property.getKey().substring(Property.TABLE_CONSTRAINT_PREFIX.toString().length()));
+            constraintNumbers.add(i);
+            constraintClasses.put(property.getValue(), i);
+          }
+        }
+        i = 1;
+        while (constraintNumbers.contains(i))
+          i++;
+        for (String constraint : cl.getArgs()) {
+          if (constraintClasses.containsKey(constraint)) {
+            shellState.getReader().printString(
+                "Constraint " + constraint + " already exists for table " + tableName + " with number " + constraintClasses.get(constraint) + "\n");
+            continue;
+          }
+          if (!shellState.getConnector().instanceOperations().testClassLoad(constraint, Constraint.class.getName()))
+            throw new ShellCommandException(ErrorCode.INITIALIZATION_FAILURE, "Servers are unable to load " + constraint + " as type "
+                + Constraint.class.getName());
+          shellState.getConnector().tableOperations().setProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + i, constraint);
+          shellState.getReader().printString("Added constraint " + constraint + " to table " + tableName + " with number " + i + "\n");
+          i++;
+          while (constraintNumbers.contains(i))
+            i++;
+        }
+        break;
+      case DELETE:
+        for (String constraint : cl.getArgs()) {
+          i = Integer.parseInt(constraint);
+          shellState.getConnector().tableOperations().removeProperty(tableName, Property.TABLE_CONSTRAINT_PREFIX.toString() + i);
+          shellState.getReader().printString("Removed constraint " + i + " from table " + tableName + "\n");
+        }
+        break;
+      case LIST:
+        TreeMap<String,String> properties = new TreeMap<String,String>();
+        for (Entry<String,String> property : shellState.getConnector().tableOperations().getProperties(tableName)) {
+          if (property.getKey().startsWith(Property.TABLE_CONSTRAINT_PREFIX.toString()))
+            properties.put(property.getKey(), property.getValue());
+        }
+        for (Entry<String,String> property : properties.entrySet())
+          shellState.getReader().printString(property.toString());
+    }
+    
+    return 0;
+  }
+  
+  @Override
+  public String description() {
+    return "adds, deletes, or lists constraints for a table";
+  }
+  
+  @Override
+  public int numArgs() {
+    return Shell.NO_FIXED_ARG_LENGTH_CHECK;
+  }
+  
+  @Override
+  public String usage() {
+    return getName() + " <constraint>{ <constraint>}";
+  }
+  
+  @Override
+  public Options getOptions() {
+    Options o = new Options();
+    o.addOptionGroup(OptUtil.addListDeleteGroup("constraint"));
+    o.addOption(OptUtil.tableOpt("table to add, delete, or list constraints for"));
+    return o;
+  }
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ConstraintCommand.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteCommand.java Tue May  8 21:14:39 2012
@@ -76,7 +76,7 @@ public class DeleteCommand extends Comma
     deleteOptAuths.setArgName("expression");
     o.addOption(deleteOptAuths);
     
-    timestampOpt = new Option("t", "timestamp", true, "timestamp to use for deletion");
+    timestampOpt = new Option("ts", "timestamp", true, "timestamp to use for deletion");
     timestampOpt.setArgName("timestamp");
     o.addOption(timestampOpt);
     

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteIterCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteIterCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteIterCommand.java Tue May  8 21:14:39 2012
@@ -18,9 +18,6 @@ package org.apache.accumulo.core.util.sh
 
 import java.util.EnumSet;
 
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
@@ -29,21 +26,10 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 
 public class DeleteIterCommand extends Command {
-  private Option tableOpt, mincScopeOpt, majcScopeOpt, scanScopeOpt, nameOpt;
+  private Option mincScopeOpt, majcScopeOpt, scanScopeOpt, nameOpt;
   
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     String name = cl.getOptionValue(nameOpt.getOpt());
     if (!shellState.getConnector().tableOperations().listIterators(tableName).containsKey(name)) {
@@ -72,9 +58,6 @@ public class DeleteIterCommand extends C
   public Options getOptions() {
     Options o = new Options();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to delete the iterator from");
-    tableOpt.setArgName("table");
-    
     nameOpt = new Option("n", "name", true, "iterator to delete");
     nameOpt.setArgName("itername");
     nameOpt.setRequired(true);
@@ -83,7 +66,7 @@ public class DeleteIterCommand extends C
     majcScopeOpt = new Option(IteratorScope.majc.name(), "major-compaction", false, "remove from major compaction scope");
     scanScopeOpt = new Option(IteratorScope.scan.name(), "scan-time", false, "remove from scan scope");
     
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to delete the iterator from"));
     o.addOption(nameOpt);
     
     o.addOption(mincScopeOpt);

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteManyCommand.java Tue May  8 21:14:39 2012
@@ -34,23 +34,12 @@ import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 
 public class DeleteManyCommand extends ScanCommand {
-  private Option forceOpt, tableOpt;
+  private Option forceOpt;
   
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
       IOException, ParseException {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
     // handle first argument, if present, the authorizations list to
     // scan with
     Authorizations auths = getAuths(cl, shellState);
@@ -80,12 +69,8 @@ public class DeleteManyCommand extends S
   public Options getOptions() {
     forceOpt = new Option("f", "force", false, "force deletion without prompting");
     Options opts = super.getOptions();
-    
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to delete entries from");
-    tableOpt.setArgName("table");
-    
     opts.addOption(forceOpt);
-    opts.addOption(tableOpt);
+    opts.addOption(OptUtil.tableOpt("table to delete entries from"));
     return opts;
   }
   

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteRowsCommand.java Tue May  8 21:14:39 2012
@@ -16,7 +16,6 @@
  */
 package org.apache.accumulo.core.util.shell.commands;
 
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
 import org.apache.commons.cli.CommandLine;
@@ -25,19 +24,11 @@ import org.apache.commons.cli.Options;
 import org.apache.hadoop.io.Text;
 
 public class DeleteRowsCommand extends Command {
-  private Option optStartRow, optEndRow, tableOpt, forceOpt;
+  private Option optStartRow, optEndRow, forceOpt;
   
   @Override
   public int execute(String fullCommand, CommandLine cl, final Shell shellState) throws Exception {
-    String tableName;
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    } else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     Text startRow = null;
     if (cl.hasOption(optStartRow.getOpt()))
       startRow = new Text(cl.getOptionValue(optStartRow.getOpt()));
@@ -65,15 +56,12 @@ public class DeleteRowsCommand extends C
   @Override
   public Options getOptions() {
     Options o = new Options();
-    tableOpt = new Option(Shell.tableOption, "tableName", true, "table to delete a row range from");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
     optStartRow = new Option("b", "begin-row", true, "begin row");
     optEndRow = new Option("e", "end-row", true, "end row");
     forceOpt = new Option("f", "force", false, "delete data even if start or end are not specified");
     o.addOption(optStartRow);
     o.addOption(optEndRow);
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to delete a row range from"));
     o.addOption(forceOpt);
     return o;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteScanIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteScanIterCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteScanIterCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteScanIterCommand.java Tue May  8 21:14:39 2012
@@ -20,7 +20,6 @@ import java.util.Iterator;
 import java.util.List;
 
 import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
 import org.apache.commons.cli.CommandLine;
@@ -29,22 +28,11 @@ import org.apache.commons.cli.OptionGrou
 import org.apache.commons.cli.Options;
 
 public class DeleteScanIterCommand extends Command {
-  private Option tableOpt, nameOpt, allOpt;
+  private Option nameOpt, allOpt;
   
   @Override
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     if (cl.hasOption(allOpt.getOpt())) {
       List<IteratorSetting> tableScanIterators = shellState.scanIteratorOptions.remove(tableName);
@@ -88,9 +76,6 @@ public class DeleteScanIterCommand exten
   public Options getOptions() {
     Options o = new Options();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "tableName");
-    tableOpt.setArgName("table");
-    
     OptionGroup nameGroup = new OptionGroup();
     
     nameOpt = new Option("n", "name", true, "iterator to delete");
@@ -102,8 +87,8 @@ public class DeleteScanIterCommand exten
     nameGroup.addOption(nameOpt);
     nameGroup.addOption(allOpt);
     nameGroup.setRequired(true);
-    o.addOption(tableOpt);
     o.addOptionGroup(nameGroup);
+    o.addOption(OptUtil.tableOpt("table to delete scan iterators from"));
     
     return o;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteTableCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteTableCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteTableCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/DeleteTableCommand.java Tue May  8 21:14:39 2012
@@ -16,36 +16,21 @@
  */
 package org.apache.accumulo.core.util.shell.commands;
 
-import java.io.IOException;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.util.shell.Shell;
-import org.apache.accumulo.core.util.shell.Shell.Command;
-import org.apache.accumulo.core.util.shell.Token;
+import org.apache.accumulo.core.util.shell.Shell.TableOperation;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 
-public class DeleteTableCommand extends Command {
-  
-  private Option tableOpt;
+public class DeleteTableCommand extends TableOperation {
+  private Option forceOpt;
   
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
-      IOException {
-    
-    String tableName = cl.getArgs()[0];
-    if (!shellState.getConnector().tableOperations().exists(tableName))
-      throw new TableNotFoundException(null, tableName, null);
-    
-    shellState.getConnector().tableOperations().delete(tableName);
-    shellState.getReader().printString("Table: [" + tableName + "] has been deleted. \n");
-    if (shellState.getTableName().equals(tableName))
-      shellState.setTableName("");
-    return 0;
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    if (cl.hasOption(forceOpt.getOpt()))
+      super.force();
+    else
+      super.noForce();
+    return super.execute(fullCommand, cl, shellState);
   }
   
   @Override
@@ -54,27 +39,19 @@ public class DeleteTableCommand extends 
   }
   
   @Override
-  public void registerCompletion(Token root, Map<Command.CompletionSet,Set<String>> special) {
-    registerCompletionForTables(root, special);
-  }
-  
-  @Override
-  public String usage() {
-    return getName() + " <tableName>";
+  protected void doTableOp(Shell shellState, String tableName) throws Exception {
+    shellState.getConnector().tableOperations().delete(tableName);
+    shellState.getReader().printString("Table: [" + tableName + "] has been deleted. \n");
+    if (shellState.getTableName().equals(tableName))
+      shellState.setTableName("");
   }
   
   @Override
   public Options getOptions() {
+    forceOpt = new Option("f", "force", false, "force deletion without prompting");
+    Options opts = super.getOptions();
     
-    Options o = new Options();
-    tableOpt = new Option(Shell.tableOption, "tableName", true, "table to delete");
-    o.addOption(tableOpt);
-    return o;
-    
-  }
-  
-  @Override
-  public int numArgs() {
-    return 1;
+    opts.addOption(forceOpt);
+    return opts;
   }
 }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ExecfileCommand.java Tue May  8 21:14:39 2012
@@ -41,6 +41,11 @@ public class ExecfileCommand extends Com
   }
   
   @Override
+  public String usage() {
+    return getName() + " <fileName>";
+  }
+  
+  @Override
   public int numArgs() {
     return 1;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FormatterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FormatterCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FormatterCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FormatterCommand.java Tue May  8 21:14:39 2012
@@ -32,7 +32,7 @@ import org.apache.commons.cli.OptionGrou
 import org.apache.commons.cli.Options;
 
 public class FormatterCommand extends Command {
-  private Option removeFormatterOption, formatterClassOption, listClassOption, tableOption;
+  private Option removeFormatterOption, formatterClassOption, listClassOption;
   
   @Override
   public String description() {
@@ -41,11 +41,7 @@ public class FormatterCommand extends Co
   
   @Override
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
-    String tableName = shellState.getTableName();
-    
-    if (cl.hasOption(tableOption.getOpt())) {
-      tableName = cl.getOptionValue(tableOption.getOpt());
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     if (cl.hasOption(removeFormatterOption.getOpt())) {
       // Remove the property
@@ -57,7 +53,7 @@ public class FormatterCommand extends Co
       Iterator<Entry<String,String>> iter = shellState.getConnector().tableOperations().getProperties(tableName).iterator();
       
       while (iter.hasNext()) {
-        Entry<String, String> ent = iter.next();
+        Entry<String,String> ent = iter.next();
         
         // List all parameters with the property name
         if (ent.getKey().startsWith(Property.TABLE_FORMATTER_CLASS.toString())) {
@@ -76,7 +72,7 @@ public class FormatterCommand extends Co
   }
   
   public static Class<? extends Formatter> getCurrentFormatter(String tableName, Shell shellState) {
-    Iterator<Entry<String, String>> props;
+    Iterator<Entry<String,String>> props;
     try {
       props = shellState.getConnector().tableOperations().getProperties(tableName).iterator();
     } catch (AccumuloException e) {
@@ -86,7 +82,7 @@ public class FormatterCommand extends Co
     }
     
     while (props.hasNext()) {
-      Entry<String, String> ent = props.next();
+      Entry<String,String> ent = props.next();
       if (ent.getKey().equals(Property.TABLE_FORMATTER_CLASS.toString())) {
         Class<? extends Formatter> formatter;
         try {
@@ -107,11 +103,6 @@ public class FormatterCommand extends Co
     Options o = new Options();
     OptionGroup actionGroup = new OptionGroup();
     
-    // Table and formatter class name
-    tableOption = new Option("t", "table", true, "table to set the formatter on");
-    tableOption.setArgName("table");
-    tableOption.setRequired(false);
-    
     formatterClassOption = new Option("f", "formatter", true, "fully qualified name of the formatter class to use");
     formatterClassOption.setArgName("className");
     
@@ -125,7 +116,7 @@ public class FormatterCommand extends Co
     actionGroup.setRequired(true);
     
     o.addOptionGroup(actionGroup);
-    o.addOption(tableOption);
+    o.addOption(OptUtil.tableOpt("table to set the formatter on"));
     
     return o;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetGroupsCommand.java Tue May  8 21:14:39 2012
@@ -20,34 +20,18 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.util.LocalityGroupUtil;
 import org.apache.accumulo.core.util.shell.Shell;
 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.hadoop.io.Text;
 
 public class GetGroupsCommand extends Command {
   
-  private Option tableOpt;
-  
   @Override
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
-    
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     Map<String,Set<Text>> groups = shellState.getConnector().tableOperations().getLocalityGroups(tableName);
     
@@ -70,12 +54,7 @@ public class GetGroupsCommand extends Co
   @Override
   public Options getOptions() {
     Options opts = new Options();
-    
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to fetch locality groups from");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
-    opts.addOption(tableOpt);
+    opts.addOption(OptUtil.tableOpt("table to fetch locality groups from"));
     return opts;
   }
-  
 }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GetSplitsCommand.java Tue May  8 21:14:39 2012
@@ -46,24 +46,12 @@ import org.apache.hadoop.io.Text;
 
 public class GetSplitsCommand extends Command {
   
-  private Option outputFileOpt, maxSplitsOpt, base64Opt, verboseOpt, tableOpt;
+  private Option outputFileOpt, maxSplitsOpt, base64Opt, verboseOpt;
   
   @Override
   public int execute(String fullCommand, CommandLine cl, final Shell shellState) throws IOException, AccumuloException, AccumuloSecurityException,
       TableNotFoundException {
-    
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
     final String m = cl.getOptionValue(maxSplitsOpt.getOpt());
@@ -149,15 +137,11 @@ public class GetSplitsCommand extends Co
     
     verboseOpt = new Option("v", "verbose", false, "print out the tablet information with start/end rows");
     
-    tableOpt = new Option(Shell.tableOption, "tableName", true, "table to get splits for");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
-    
     opts.addOption(outputFileOpt);
     opts.addOption(maxSplitsOpt);
     opts.addOption(base64Opt);
     opts.addOption(verboseOpt);
-    opts.addOption(tableOpt);
+    opts.addOption(OptUtil.tableOpt("table to get splits for"));
     
     return opts;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrantCommand.java Tue May  8 21:14:39 2012
@@ -19,28 +19,28 @@ package org.apache.accumulo.core.util.sh
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.security.SystemPermission;
 import org.apache.accumulo.core.security.TablePermission;
 import org.apache.accumulo.core.util.BadArgumentException;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.Shell.TableOperation;
 import org.apache.accumulo.core.util.shell.Token;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
 
-public class GrantCommand extends Command {
-  private Option systemOpt, tableOpt, userOpt;
-  private Option tablePatternOpt;
+public class GrantCommand extends TableOperation {
+  private Option systemOpt, userOpt;
+  private String user;
+  private String[] permission;
   
   @Override
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException {
-    String user = cl.hasOption(userOpt.getOpt()) ? cl.getOptionValue(userOpt.getOpt()) : shellState.getConnector().whoami();
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    user = cl.hasOption(userOpt.getOpt()) ? cl.getOptionValue(userOpt.getOpt()) : shellState.getConnector().whoami();
     
-    String permission[] = cl.getArgs()[0].split("\\.", 2);
+    permission = cl.getArgs()[0].split("\\.", 2);
     if (cl.hasOption(systemOpt.getOpt()) && permission[0].equalsIgnoreCase("System")) {
       try {
         shellState.getConnector().securityOperations().grantSystemPermission(user, SystemPermission.valueOf(permission[1]));
@@ -49,28 +49,7 @@ public class GrantCommand extends Comman
         throw new BadArgumentException("No such system permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
       }
     } else if (permission[0].equalsIgnoreCase("Table")) {
-      if (cl.hasOption(tableOpt.getOpt())) {
-        String tableName = cl.getOptionValue(tableOpt.getOpt());
-        try {
-          shellState.getConnector().securityOperations().grantTablePermission(user, tableName, TablePermission.valueOf(permission[1]));
-          Shell.log.debug("Granted " + user + " the " + permission[1] + " permission on table " + tableName);
-        } catch (IllegalArgumentException e) {
-          throw new BadArgumentException("No such table permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
-        }
-      } else if (cl.hasOption(tablePatternOpt.getOpt())) {
-        for (String tableName : shellState.getConnector().tableOperations().list()) {
-          if (tableName.matches(cl.getOptionValue(tablePatternOpt.getOpt()))) {
-            try {
-              shellState.getConnector().securityOperations().grantTablePermission(user, tableName, TablePermission.valueOf(permission[1]));
-              Shell.log.debug("Granted " + user + " the " + permission[1] + " permission on table " + tableName);
-            } catch (IllegalArgumentException e) {
-              throw new BadArgumentException("No such table permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
-            }
-          }
-        }
-      } else {
-        throw new BadArgumentException("You must provide a table name", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
-      }
+      super.execute(fullCommand, cl, shellState);
     } else {
       throw new BadArgumentException("Unrecognized permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
     }
@@ -78,6 +57,16 @@ public class GrantCommand extends Comman
   }
   
   @Override
+  protected void doTableOp(Shell shellState, String tableName) throws Exception {
+    try {
+      shellState.getConnector().securityOperations().grantTablePermission(user, tableName, TablePermission.valueOf(permission[1]));
+      Shell.log.debug("Granted " + user + " the " + permission[1] + " permission on table " + tableName);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException("No such table permission", e);
+    }
+  }
+  
+  @Override
   public String description() {
     return "grants system or table permissions for a user";
   }
@@ -97,20 +86,16 @@ public class GrantCommand extends Comman
   
   @Override
   public Options getOptions() {
+    super.getOptions();
     Options o = new Options();
+    
     OptionGroup group = new OptionGroup();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to grant a table permission for");
     systemOpt = new Option("s", "system", false, "grant a system permission");
-    tablePatternOpt = new Option("p", "pattern", true, "regex pattern of tables to grant permissions for");
-    tablePatternOpt.setArgName("pattern");
-    
-    tableOpt.setArgName("table");
     
     group.addOption(systemOpt);
-    group.addOption(tableOpt);
-    group.addOption(tablePatternOpt);
-    group.setRequired(true);
+    group.addOption(optTableName);
+    group.addOption(optTablePattern);
     
     o.addOptionGroup(group);
     userOpt = new Option(Shell.userOption, "user", true, "user to operate on");

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/GrepCommand.java Tue May  8 21:14:39 2012
@@ -34,23 +34,12 @@ import org.apache.commons.cli.Options;
 
 public class GrepCommand extends ScanCommand {
   
-  private Option numThreadsOpt, tableOpt;
+  private Option numThreadsOpt;
   
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
       IOException, MissingArgumentException {
     
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     if (cl.getArgList().isEmpty())
       throw new MissingArgumentException("No terms specified");
@@ -99,11 +88,6 @@ public class GrepCommand extends ScanCom
   public Options getOptions() {
     Options opts = super.getOptions();
     numThreadsOpt = new Option("nt", "num-threads", true, "number of threads to use");
-    tableOpt = new Option(Shell.tableOption, "tableName", true, "table to grep through");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
-    
-    opts.addOption(tableOpt);
     opts.addOption(numThreadsOpt);
     return opts;
   }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/InsertCommand.java Tue May  8 21:14:39 2012
@@ -99,7 +99,7 @@ public class InsertCommand extends Comma
     insertOptAuths.setArgName("expression");
     o.addOption(insertOptAuths);
     
-    timestampOpt = new Option("t", "timestamp", true, "timestamp to use for insert");
+    timestampOpt = new Option("ts", "timestamp", true, "timestamp to use for insert");
     timestampOpt.setArgName("timestamp");
     o.addOption(timestampOpt);
     

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ListIterCommand.java Tue May  8 21:14:39 2012
@@ -22,7 +22,6 @@ import java.util.Map;
 import java.util.Map.Entry;
 
 import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
@@ -31,21 +30,12 @@ import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
 
 public class ListIterCommand extends Command {
-  private Option tableOpt, nameOpt;
+  private Option nameOpt;
   private Map<IteratorScope,Option> scopeOpts;
   
   @Override
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    } else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     Map<String,EnumSet<IteratorScope>> iterators = shellState.getConnector().tableOperations().listIterators(tableName);
     
@@ -101,9 +91,6 @@ public class ListIterCommand extends Com
   public Options getOptions() {
     Options o = new Options();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to list the configured iterators on");
-    tableOpt.setArgName("table");
-    
     nameOpt = new Option("n", "name", true, "iterator to list");
     nameOpt.setArgName("itername");
     
@@ -112,7 +99,7 @@ public class ListIterCommand extends Com
     scopeOpts.put(IteratorScope.majc, new Option(IteratorScope.majc.name(), "major-compaction", false, "list iterator for major compaction scope"));
     scopeOpts.put(IteratorScope.scan, new Option(IteratorScope.scan.name(), "scan-time", false, "list iterator for scan scope"));
     
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to list the configured iterators on"));
     o.addOption(nameOpt);
     
     for (Option opt : scopeOpts.values()) {

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MaxRowCommand.java Tue May  8 21:14:39 2012
@@ -21,40 +21,26 @@ import java.io.IOException;
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.security.Authorizations;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.hadoop.io.Text;
 
 public class MaxRowCommand extends ScanCommand {
-  private Option tableOpt, optAuths, optStartRow, optEndRow, optStartRowExclusive, optEndRowExclusive;
   
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
       IOException, ParseException {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
+    Range range = getRange(cl);
+    Authorizations auths = getAuths(cl, shellState);
+    Text startRow = range.getStartKey() == null ? null : range.getStartKey().getRow();
+    Text endRow = range.getEndKey() == null ? null : range.getEndKey().getRow();
     
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
-    
-    Text startRow = cl.hasOption(optStartRow.getOpt()) ? new Text(cl.getOptionValue(optStartRow.getOpt())) : null;
-    Text endRow = cl.hasOption(optEndRow.getOpt()) ? new Text(cl.getOptionValue(optEndRow.getOpt())) : null;
-    
-    boolean startInclusive = !cl.hasOption(optStartRowExclusive.getOpt());
-    boolean endInclusive = !cl.hasOption(optEndRowExclusive.getOpt());
     try {
-      Text max = shellState.getConnector().tableOperations().getMaxRow(tableName, getAuths(cl, shellState), startRow, startInclusive, endRow, endInclusive);
+      Text max = shellState.getConnector().tableOperations()
+          .getMaxRow(tableName, auths, startRow, range.isStartKeyInclusive(), endRow, range.isEndKeyInclusive());
       if (max != null)
         shellState.getReader().printString(max.toString() + "\n");
     } catch (Exception e) {
@@ -64,50 +50,8 @@ public class MaxRowCommand extends ScanC
     return 0;
   }
   
-  protected Authorizations getAuths(CommandLine cl, Shell shellState) throws AccumuloSecurityException, AccumuloException {
-    String user = shellState.getConnector().whoami();
-    Authorizations auths = shellState.getConnector().securityOperations().getUserAuthorizations(user);
-    if (cl.hasOption(optAuths.getOpt())) {
-      auths = CreateUserCommand.parseAuthorizations(cl.getOptionValue(optAuths.getOpt()));
-    }
-    return auths;
-  }
-  
   @Override
   public String description() {
     return "finds the max row in a table within a given range";
   }
-  
-  @Override
-  public Options getOptions() {
-    
-    Options opts = new Options();
-    
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to be created");
-    tableOpt.setArgName("table");
-    
-    optAuths = new Option("s", "scan-authorizations", true, "scan authorizations (all user auths are used if this argument is not specified)");
-    optAuths.setArgName("comma-separated-authorizations");
-    
-    optStartRow = new Option("b", "begin-row", true, "begin row");
-    optStartRow.setArgName("begin-row");
-    
-    optEndRow = new Option("e", "end-row", true, "end row");
-    optEndRow.setArgName("end-row");
-    
-    optStartRowExclusive = new Option("be", "begin-exclusive", false, "make start row exclusive (by default it's inclusive)");
-    optStartRowExclusive.setArgName("begin-exclusive");
-    
-    optEndRowExclusive = new Option("ee", "end-exclusive", false, "make end row exclusive (by default it's inclusive)");
-    optEndRowExclusive.setArgName("end-exclusive");
-    
-    opts.addOption(tableOpt);
-    opts.addOption(optAuths);
-    opts.addOption(optStartRow);
-    opts.addOption(optEndRow);
-    opts.addOption(optStartRowExclusive);
-    opts.addOption(optEndRowExclusive);
-    
-    return opts;
-  }
 }

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/MergeCommand.java Tue May  8 21:14:39 2012
@@ -18,7 +18,6 @@ package org.apache.accumulo.core.util.sh
 
 import java.io.IOException;
 
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.conf.AccumuloConfiguration;
 import org.apache.accumulo.core.util.Merge;
 import org.apache.accumulo.core.util.shell.Shell;
@@ -29,22 +28,14 @@ import org.apache.commons.cli.Options;
 import org.apache.hadoop.io.Text;
 
 public class MergeCommand extends Command {
-  private Option mergeOptStartRow, mergeOptEndRow, tableOpt, verboseOpt, forceOpt, sizeOpt;
+  private Option mergeOptStartRow, mergeOptEndRow, verboseOpt, forceOpt, sizeOpt;
   
   @Override
   public int execute(String fullCommand, CommandLine cl, final Shell shellState) throws Exception {
     boolean verbose = shellState.isVerbose();
     boolean force = false;
     long size = -1;
-    String tableName;
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    } else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     Text startRow = null;
     if (cl.hasOption(mergeOptStartRow.getOpt()))
       startRow = new Text(cl.getOptionValue(mergeOptStartRow.getOpt()));
@@ -92,9 +83,6 @@ public class MergeCommand extends Comman
   @Override
   public Options getOptions() {
     Options o = new Options();
-    tableOpt = new Option(Shell.tableOption, "tableName", true, "table to be merged");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
     mergeOptStartRow = new Option("b", "begin-row", true, "begin row");
     mergeOptEndRow = new Option("e", "end-row", true, "end row");
     verboseOpt = new Option("v", "verbose", false, "verbose output during merge");
@@ -102,7 +90,7 @@ public class MergeCommand extends Comman
     forceOpt = new Option("f", "force", false, "merge small tablets to large tablets, even if it goes over the given size");
     o.addOption(mergeOptStartRow);
     o.addOption(mergeOptEndRow);
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to be merged"));
     o.addOption(verboseOpt);
     o.addOption(sizeOpt);
     o.addOption(forceOpt);

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/NoTableCommand.java Tue May  8 21:14:39 2012
@@ -33,10 +33,6 @@ public class NoTableCommand extends Comm
     return "returns to a tableless shell state";
   }
   
-  public String usage() {
-    return getName();
-  }
-  
   @Override
   public int numArgs() {
     return 0;

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java?rev=1335772&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java (added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java Tue May  8 21:14:39 2012
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.core.util.shell.commands;
+
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.util.shell.Shell;
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+
+public abstract class OptUtil {
+  public static String configureTableOpt(CommandLine cl, Shell shellState) throws TableNotFoundException {
+    String tableName;
+    
+    if (cl.hasOption(Shell.tableOption)) {
+      tableName = cl.getOptionValue(Shell.tableOption);
+      if (!shellState.getConnector().tableOperations().exists(tableName))
+        throw new TableNotFoundException(null, tableName, null);
+    } else {
+      shellState.checkTableState();
+      tableName = shellState.getTableName();
+    }
+    
+    return tableName;
+  }
+  
+  public static Option tableOpt() {
+    return tableOpt("tableName");
+  }
+  
+  public static Option tableOpt(String description) {
+    Option tableOpt = new Option(Shell.tableOption, "table", true, description);
+    tableOpt.setArgName("table");
+    tableOpt.setRequired(false);
+    return tableOpt;
+  }
+  
+  public static enum AdlOpt {
+    ADD("a"), DELETE("d"), LIST("l");
+    
+    public final String opt;
+    
+    private AdlOpt(String opt) {
+      this.opt = opt;
+    }
+  }
+  
+  public static AdlOpt configureAldOpt(CommandLine cl) {
+    if (cl.hasOption(AdlOpt.ADD.opt)) {
+      return AdlOpt.ADD;
+    } else if (cl.hasOption(AdlOpt.DELETE.opt)) {
+      return AdlOpt.DELETE;
+    } else {
+      return AdlOpt.LIST;
+    }
+  }
+  
+  public static OptionGroup addListDeleteGroup(String name) {
+    Option addOpt = new Option(AdlOpt.ADD.opt, "add", false, "add " + name);
+    Option deleteOpt = new Option(AdlOpt.DELETE.opt, "delete", false, "delete " + name);
+    Option listOpt = new Option(AdlOpt.LIST.opt, "list", false, "list " + name + "(s)");
+    OptionGroup og = new OptionGroup();
+    og.addOption(addOpt);
+    og.addOption(deleteOpt);
+    og.addOption(listOpt);
+    og.setRequired(true);
+    return og;
+  }
+}

Propchange: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OptUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RevokeCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RevokeCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RevokeCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RevokeCommand.java Tue May  8 21:14:39 2012
@@ -19,27 +19,28 @@ package org.apache.accumulo.core.util.sh
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.security.SystemPermission;
 import org.apache.accumulo.core.security.TablePermission;
 import org.apache.accumulo.core.util.BadArgumentException;
 import org.apache.accumulo.core.util.shell.Shell;
 import org.apache.accumulo.core.util.shell.Shell.Command;
+import org.apache.accumulo.core.util.shell.Shell.TableOperation;
 import org.apache.accumulo.core.util.shell.Token;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
 
-public class RevokeCommand extends Command {
-  private Option systemOpt, tableOpt, userOpt;
+public class RevokeCommand extends TableOperation {
+  private Option systemOpt, userOpt;
+  private String user;
+  private String[] permission;
   
   @Override
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException {
-    String user = cl.hasOption(userOpt.getOpt()) ? cl.getOptionValue(userOpt.getOpt()) : shellState.getConnector().whoami();
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    user = cl.hasOption(userOpt.getOpt()) ? cl.getOptionValue(userOpt.getOpt()) : shellState.getConnector().whoami();
     
-    String permission[] = cl.getArgs()[0].split("\\.", 2);
+    permission = cl.getArgs()[0].split("\\.", 2);
     if (cl.hasOption(systemOpt.getOpt()) && permission[0].equalsIgnoreCase("System")) {
       try {
         shellState.getConnector().securityOperations().revokeSystemPermission(user, SystemPermission.valueOf(permission[1]));
@@ -47,14 +48,8 @@ public class RevokeCommand extends Comma
       } catch (IllegalArgumentException e) {
         throw new BadArgumentException("No such system permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
       }
-    } else if (cl.hasOption(tableOpt.getOpt()) && permission[0].equalsIgnoreCase("Table")) {
-      String tableName = cl.getOptionValue(tableOpt.getOpt());
-      try {
-        shellState.getConnector().securityOperations().revokeTablePermission(user, tableName, TablePermission.valueOf(permission[1]));
-        Shell.log.debug("Revoked from " + user + " the " + permission[1] + " permission on table " + tableName);
-      } catch (IllegalArgumentException e) {
-        throw new BadArgumentException("No such table permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
-      }
+    } else if (permission[0].equalsIgnoreCase("Table")) {
+      super.execute(fullCommand, cl, shellState);
     } else {
       throw new BadArgumentException("Unrecognized permission", fullCommand, fullCommand.indexOf(cl.getArgs()[0]));
     }
@@ -62,6 +57,16 @@ public class RevokeCommand extends Comma
   }
   
   @Override
+  protected void doTableOp(Shell shellState, String tableName) throws Exception {
+    try {
+      shellState.getConnector().securityOperations().revokeTablePermission(user, tableName, TablePermission.valueOf(permission[1]));
+      Shell.log.debug("Revoked from " + user + " the " + permission[1] + " permission on table " + tableName);
+    } catch (IllegalArgumentException e) {
+      throw new IllegalArgumentException("No such table permission", e);
+    }
+  }
+  
+  @Override
   public String description() {
     return "revokes system or table permissions from a user";
   }
@@ -81,20 +86,18 @@ public class RevokeCommand extends Comma
   
   @Override
   public Options getOptions() {
+    super.getOptions();
     Options o = new Options();
+    
     OptionGroup group = new OptionGroup();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to revoke a table permission for");
     systemOpt = new Option("s", "system", false, "revoke a system permission");
     
-    tableOpt.setArgName("table");
-    
     group.addOption(systemOpt);
-    group.addOption(tableOpt);
-    group.setRequired(true);
+    group.addOption(optTableName);
+    group.addOption(optTablePattern);
     
     o.addOptionGroup(group);
-    
     userOpt = new Option(Shell.userOption, "user", true, "user to operate on");
     userOpt.setArgName("username");
     userOpt.setRequired(true);

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java Tue May  8 21:14:39 2012
@@ -25,7 +25,6 @@ import org.apache.accumulo.core.client.A
 import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.client.ScannerBase;
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
 import org.apache.accumulo.core.data.Value;
@@ -38,32 +37,23 @@ import org.apache.accumulo.start.classlo
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
 import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
 import org.apache.hadoop.io.Text;
 
 public class ScanCommand extends Command {
   
-  private Option scanOptAuths, scanOptStartRow, scanOptEndRow, scanOptRow, scanOptColumns, disablePaginationOpt, tableOpt, showFewOpt, formatterOpt;
+  private Option scanOptAuths, scanOptStartRow, scanOptEndRow, scanOptRow, scanOptColumns, disablePaginationOpt, showFewOpt, formatterOpt;
   protected Option timestampOpt;
+  private Option optStartRowExclusive;
+  private Option optEndRowExclusive;
   
-  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
-      IOException, ParseException {
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
-    String tableName;
     Class<? extends Formatter> formatter = null;
     
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-      
-      // Use the configured formatter unless one was provided
-      if (!cl.hasOption(formatterOpt.getOpt())) {
-        formatter = FormatterCommand.getCurrentFormatter(tableName, shellState);
-      }
-    } else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
+    // Use the configured formatter unless one was provided
+    if (!cl.hasOption(formatterOpt.getOpt())) {
+      formatter = FormatterCommand.getCurrentFormatter(tableName, shellState);
     }
     
     // handle first argument, if present, the authorizations list to
@@ -172,7 +162,9 @@ public class ScanCommand extends Command
     } else {
       Text startRow = cl.hasOption(scanOptStartRow.getOpt()) ? new Text(cl.getOptionValue(scanOptStartRow.getOpt())) : null;
       Text endRow = cl.hasOption(scanOptEndRow.getOpt()) ? new Text(cl.getOptionValue(scanOptEndRow.getOpt())) : null;
-      return new Range(startRow, endRow);
+      boolean startInclusive = !cl.hasOption(optStartRowExclusive.getOpt());
+      boolean endInclusive = !cl.hasOption(optEndRowExclusive.getOpt());
+      return new Range(startRow, startInclusive, endRow, endInclusive);
     }
   }
   
@@ -197,11 +189,14 @@ public class ScanCommand extends Command
     scanOptAuths = new Option("s", "scan-authorizations", true, "scan authorizations (all user auths are used if this argument is not specified)");
     scanOptStartRow = new Option("b", "begin-row", true, "begin row (inclusive)");
     scanOptEndRow = new Option("e", "end-row", true, "end row (inclusive)");
+    optStartRowExclusive = new Option("be", "begin-exclusive", false, "make start row exclusive (by default it's inclusive)");
+    optStartRowExclusive.setArgName("begin-exclusive");
+    optEndRowExclusive = new Option("ee", "end-exclusive", false, "make end row exclusive (by default it's inclusive)");
+    optEndRowExclusive.setArgName("end-exclusive");
     scanOptRow = new Option("r", "row", true, "row to scan");
     scanOptColumns = new Option("c", "columns", true, "comma-separated columns");
     timestampOpt = new Option("st", "show-timestamps", false, "display timestamps");
     disablePaginationOpt = new Option("np", "no-pagination", false, "disable pagination of output");
-    tableOpt = new Option(Shell.tableOption, "tableName", true, "table to be scanned");
     showFewOpt = new Option("f", "show few", true, "show only a specified number of characters");
     formatterOpt = new Option("fm", "formatter", true, "fully qualified name of the formatter class to use");
     
@@ -210,8 +205,6 @@ public class ScanCommand extends Command
     scanOptStartRow.setArgName("start-row");
     scanOptEndRow.setArgName("end-row");
     scanOptColumns.setArgName("<columnfamily>[:<columnqualifier>]{,<columnfamily>[:<columnqualifier>]}");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
     showFewOpt.setRequired(false);
     showFewOpt.setArgName("int");
     formatterOpt.setArgName("className");
@@ -220,10 +213,12 @@ public class ScanCommand extends Command
     o.addOption(scanOptRow);
     o.addOption(scanOptStartRow);
     o.addOption(scanOptEndRow);
+    o.addOption(optStartRowExclusive);
+    o.addOption(optEndRowExclusive);
     o.addOption(scanOptColumns);
     o.addOption(timestampOpt);
     o.addOption(disablePaginationOpt);
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to be scanned"));
     o.addOption(showFewOpt);
     o.addOption(formatterOpt);
     

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetGroupsCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetGroupsCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetGroupsCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetGroupsCommand.java Tue May  8 21:14:39 2012
@@ -20,18 +20,13 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
 
-import org.apache.accumulo.core.client.TableNotFoundException;
 import org.apache.accumulo.core.util.shell.Shell;
 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.hadoop.io.Text;
 
 public class SetGroupsCommand extends Command {
-  
-  private Option tableOpt;
-  
   @Override
   public String description() {
     return "sets the locality groups for a given table (for binary or commas, use Java API)";
@@ -39,19 +34,7 @@ public class SetGroupsCommand extends Co
   
   @Override
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception {
-    
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     HashMap<String,Set<Text>> groups = new HashMap<String,Set<Text>>();
     
@@ -87,11 +70,7 @@ public class SetGroupsCommand extends Co
   @Override
   public Options getOptions() {
     Options opts = new Options();
-    
-    tableOpt = new Option(Shell.tableOption, "table", true, "table to fetch locality groups for");
-    tableOpt.setArgName("table");
-    tableOpt.setRequired(false);
-    opts.addOption(tableOpt);
+    opts.addOption(OptUtil.tableOpt("table to fetch locality groups for"));
     return opts;
   }
   

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SetIterCommand.java Tue May  8 21:14:39 2012
@@ -49,24 +49,12 @@ import org.apache.commons.cli.Options;
 
 public class SetIterCommand extends Command {
   
-  private Option tableOpt, mincScopeOpt, majcScopeOpt, scanScopeOpt, nameOpt, priorityOpt;
+  private Option mincScopeOpt, majcScopeOpt, scanScopeOpt, nameOpt, priorityOpt;
   private Option ageoffTypeOpt, regexTypeOpt, versionTypeOpt, reqvisTypeOpt, classnameTypeOpt;
   
   public int execute(String fullCommand, CommandLine cl, Shell shellState) throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
       IOException, ShellCommandException {
-    
-    String tableName;
-    
-    if (cl.hasOption(tableOpt.getOpt())) {
-      tableName = cl.getOptionValue(tableOpt.getOpt());
-      if (!shellState.getConnector().tableOperations().exists(tableName))
-        throw new TableNotFoundException(null, tableName, null);
-    }
-    
-    else {
-      shellState.checkTableState();
-      tableName = shellState.getTableName();
-    }
+    String tableName = OptUtil.configureTableOpt(cl, shellState);
     
     int priority = Integer.parseInt(cl.getOptionValue(priorityOpt.getOpt()));
     
@@ -205,9 +193,6 @@ public class SetIterCommand extends Comm
   public Options getOptions() {
     Options o = new Options();
     
-    tableOpt = new Option(Shell.tableOption, "table", true, "tableName");
-    tableOpt.setArgName("table");
-    
     priorityOpt = new Option("p", "priority", true, "the order in which the iterator is applied");
     priorityOpt.setArgName("pri");
     priorityOpt.setRequired(true);
@@ -234,7 +219,7 @@ public class SetIterCommand extends Comm
     typeGroup.addOption(ageoffTypeOpt);
     typeGroup.setRequired(true);
     
-    o.addOption(tableOpt);
+    o.addOption(OptUtil.tableOpt("table to configure iterators on"));
     o.addOption(priorityOpt);
     o.addOption(nameOpt);
     o.addOption(mincScopeOpt);

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SleepCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SleepCommand.java?rev=1335772&r1=1335771&r2=1335772&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SleepCommand.java (original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/SleepCommand.java Tue May  8 21:14:39 2012
@@ -39,4 +39,8 @@ public class SleepCommand extends Comman
     return 1;
   }
   
+  @Override
+  public String usage() {
+    return getName() + " <seconds>";
+  }
 }

Propchange: accumulo/trunk/server/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/server:r1335106-1335108
  Merged /accumulo/branches/1.4/src/server:r1335106-1335108



Mime
View raw message