accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bil...@apache.org
Subject svn commit: r1336778 - in /accumulo/trunk: core/src/main/java/org/apache/accumulo/core/util/shell/ core/src/main/java/org/apache/accumulo/core/util/shell/commands/ test/system/auto/simple/
Date Thu, 10 May 2012 16:33:03 GMT
Author: billie
Date: Thu May 10 16:33:02 2012
New Revision: 1336778

URL: http://svn.apache.org/viewvc?rev=1336778&view=rev
Log:
ACCUMULO-583 added command line table option

Added:
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java
  (with props)
Modified:
    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/CompactCommand.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/FlushCommand.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/OfflineCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/RevokeCommand.java
    accumulo/trunk/test/system/auto/simple/shell.py

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=1336778&r1=1336777&r2=1336778&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 Thu May
10 16:33:02 2012
@@ -32,9 +32,7 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.SortedSet;
 import java.util.TreeMap;
-import java.util.TreeSet;
 import java.util.UUID;
 
 import jline.ConsoleReader;
@@ -138,7 +136,6 @@ import org.apache.commons.cli.HelpFormat
 import org.apache.commons.cli.MissingArgumentException;
 import org.apache.commons.cli.MissingOptionException;
 import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionGroup;
 import org.apache.commons.cli.Options;
 import org.apache.commons.cli.ParseException;
 import org.apache.hadoop.fs.Path;
@@ -711,90 +708,6 @@ public class Shell extends ShellOptions 
     }
   }
   
-  public static abstract class TableOperation extends Command {
-    
-    protected Option optTablePattern, optTableName;
-    private boolean force = true;
-    
-    public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception
{
-      // 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 (operate)
-          doTableOp(shellState, tableName);
-      }
-      
-      return 0;
-    }
-    
-    protected abstract void doTableOp(Shell shellState, String tableName) throws Exception;
-    
-    @Override
-    public String description() {
-      return "makes a best effort to flush tables from memory to disk";
-    }
-    
-    @Override
-    public Options getOptions() {
-      Options o = new Options();
-      
-      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 operate on");
-      optTableName.setArgName("tableName");
-      
-      OptionGroup opg = new OptionGroup();
-      
-      opg.addOption(optTablePattern);
-      opg.addOption(optTableName);
-      
-      o.addOptionGroup(opg);
-      
-      return o;
-    }
-    
-    @Override
-    public int numArgs() {
-      return 0;
-    }
-    
-    protected void force() {
-      force = true;
-    }
-    
-    protected void noForce() {
-      force = false;
-    }
-  }
-  
   public interface PrintLine {
     public void print(String s);
     

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java?rev=1336778&r1=1336777&r2=1336778&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/CompactCommand.java
Thu May 10 16:33:02 2012
@@ -19,7 +19,6 @@ package org.apache.accumulo.core.util.sh
 import org.apache.accumulo.core.client.AccumuloException;
 import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.util.shell.Shell;
-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;

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=1336778&r1=1336777&r2=1336778&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
Thu May 10 16:33:02 2012
@@ -17,7 +17,6 @@
 package org.apache.accumulo.core.util.shell.commands;
 
 import org.apache.accumulo.core.util.shell.Shell;
-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;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FlushCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FlushCommand.java?rev=1336778&r1=1336777&r2=1336778&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FlushCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/FlushCommand.java
Thu May 10 16:33:02 2012
@@ -21,14 +21,12 @@ import org.apache.accumulo.core.client.A
 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.TableOperation;
 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 FlushCommand extends TableOperation {
-  
   private Text startRow;
   private Text endRow;
   

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=1336778&r1=1336777&r2=1336778&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
Thu May 10 16:33:02 2012
@@ -24,7 +24,6 @@ import org.apache.accumulo.core.security
 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;
@@ -32,6 +31,10 @@ import org.apache.commons.cli.OptionGrou
 import org.apache.commons.cli.Options;
 
 public class GrantCommand extends TableOperation {
+  {
+    disableUnflaggedTableOptions();
+  }
+  
   private Option systemOpt, userOpt;
   private String user;
   private String[] permission;

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java?rev=1336778&r1=1336777&r2=1336778&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OfflineCommand.java
Thu May 10 16:33:02 2012
@@ -21,10 +21,8 @@ import org.apache.accumulo.core.client.A
 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.TableOperation;
 
 public class OfflineCommand extends TableOperation {
-  
   @Override
   public String description() {
     return "starts the process of taking table offline";

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java?rev=1336778&r1=1336777&r2=1336778&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/OnlineCommand.java
Thu May 10 16:33:02 2012
@@ -21,10 +21,8 @@ import org.apache.accumulo.core.client.A
 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.TableOperation;
 
 public class OnlineCommand extends TableOperation {
-  
   @Override
   public String description() {
     return "starts the process of putting a table online";

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=1336778&r1=1336777&r2=1336778&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
Thu May 10 16:33:02 2012
@@ -24,7 +24,6 @@ import org.apache.accumulo.core.security
 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;
@@ -32,6 +31,10 @@ import org.apache.commons.cli.OptionGrou
 import org.apache.commons.cli.Options;
 
 public class RevokeCommand extends TableOperation {
+  {
+    disableUnflaggedTableOptions();
+  }
+  
   private Option systemOpt, userOpt;
   private String user;
   private String[] permission;

Added: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java?rev=1336778&view=auto
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java
(added)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/TableOperation.java
Thu May 10 16:33:02 2012
@@ -0,0 +1,137 @@
+/**
+ * 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;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+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.commons.cli.CommandLine;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+
+public abstract class TableOperation extends Command {
+  
+  protected Option optTablePattern, optTableName;
+  private boolean force = true;
+  private boolean useCommandLine = true;
+  
+  public int execute(String fullCommand, CommandLine cl, Shell shellState) throws Exception
{
+    // 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 if (useCommandLine && cl.getArgs().length > 0) {
+      for (String tableName : cl.getArgs())
+        tableSet.add(tableName);
+    } else {
+      shellState.checkTableState();
+      tableSet.add(shellState.getTableName());
+    }
+    
+    if (tableSet.isEmpty())
+      Shell.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 (operate)
+        doTableOp(shellState, tableName);
+    }
+    
+    return 0;
+  }
+  
+  protected abstract void doTableOp(Shell shellState, String tableName) throws Exception;
+  
+  @Override
+  public String description() {
+    return "makes a best effort to flush tables from memory to disk";
+  }
+  
+  @Override
+  public Options getOptions() {
+    Options o = new Options();
+    
+    optTablePattern = new Option("p", "pattern", true, "regex pattern of table names to operate
on");
+    optTablePattern.setArgName("pattern");
+    
+    optTableName = new Option(Shell.tableOption, "table", true, "name of a table to operate
on");
+    optTableName.setArgName("tableName");
+    
+    OptionGroup opg = new OptionGroup();
+    
+    opg.addOption(optTablePattern);
+    opg.addOption(optTableName);
+    
+    o.addOptionGroup(opg);
+    
+    return o;
+  }
+  
+  @Override
+  public int numArgs() {
+    if (useCommandLine)
+      return Shell.NO_FIXED_ARG_LENGTH_CHECK;
+    else
+      return 0;
+  }
+  
+  protected void force() {
+    force = true;
+  }
+  
+  protected void noForce() {
+    force = false;
+  }
+  
+  protected void disableUnflaggedTableOptions() {
+    useCommandLine = false;
+  }
+  
+  @Override
+  public String usage() {
+    return getName() + " [<table>{ <table>}]";
+  }
+  
+  @Override
+  public void registerCompletion(Token root, Map<Command.CompletionSet,Set<String>>
special) {
+    if (useCommandLine)
+      registerCompletionForTables(root, special);
+  }
+}

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

Modified: accumulo/trunk/test/system/auto/simple/shell.py
URL: http://svn.apache.org/viewvc/accumulo/trunk/test/system/auto/simple/shell.py?rev=1336778&r1=1336777&r2=1336778&view=diff
==============================================================================
--- accumulo/trunk/test/system/auto/simple/shell.py (original)
+++ accumulo/trunk/test/system/auto/simple/shell.py Thu May 10 16:33:02 2012
@@ -372,7 +372,14 @@ class ShellTest(TestUtilsMixin,unittest.
         self.processResult(out, err, code)
         self.failIf(out.find("test_delete_table") >= 0,
                         "deletetable command did not delete the current table" )
-
+        delete = "createtable test_delete_table\ndeletetable test_delete_table -f\n"
+        out, err, code = self.rootShell(self.masterHost(), delete)
+        self.processResult(out, err, code)
+        input = "tables\n"
+        out, err, code = self.rootShell(self.masterHost(), input)
+        self.processResult(out, err, code)
+        self.failIf(out.find("test_delete_table") >= 0,
+                        "deletetable command did not delete the current table" )
         
     def scanTest(self):
         input = "createtable test_scan_table\n"
@@ -420,10 +427,20 @@ class ShellTest(TestUtilsMixin,unittest.
         self.processResult(out, err, code)
         
     def flushTest(self):
-        input = "flush -t !METADATA\n"
+        input = "flush -t !METADATA -w\n"
+        out, err, code = self.rootShell(self.masterHost(), input)
+        self.processResult(out, err, code)
+        self.failUnless(out.find("Flush of table !METADATA completed") >= 0, 
+                        "flush command did not flush the tables")
+        input = "flush !METADATA -w\n"
+        out, err, code = self.rootShell(self.masterHost(), input)
+        self.processResult(out, err, code)
+        self.failUnless(out.find("Flush of table !METADATA completed") >= 0,
+                        "flush command did not flush the tables")
+        input = "table !METADATA\nflush -w\n"
         out, err, code = self.rootShell(self.masterHost(), input)
         self.processResult(out, err, code)
-        self.failUnless(out.find("Flush of table !METADATA initiated") >= 0, 
+        self.failUnless(out.find("Flush of table !METADATA completed") >= 0,
                         "flush command did not flush the tables")
         
     def whoamiTest(self):



Mime
View raw message