accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ctubb...@apache.org
Subject svn commit: r1398586 - in /accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell: Shell.java commands/ConfigCommand.java commands/ScanCommand.java
Date Tue, 16 Oct 2012 00:27:23 GMT
Author: ctubbsii
Date: Tue Oct 16 00:27:23 2012
New Revision: 1398586

URL: http://svn.apache.org/viewvc?rev=1398586&view=rev
Log:
ACCUMULO-808 Applied patch provided by Jira user jskora after formatting to Accumulo template

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/ConfigCommand.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/util/shell/commands/ScanCommand.java

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=1398586&r1=1398585&r2=1398586&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 Oct
16 00:27:23 2012
@@ -766,6 +766,10 @@ public class Shell extends ShellOptions 
   };
   
   public final void printLines(Iterator<String> lines, boolean paginate) throws IOException
{
+    printLines(lines, paginate, null);
+  }
+
+  public final void printLines(Iterator<String> lines, boolean paginate, PrintLine
out) throws IOException {
     int linesPrinted = 0;
     String prompt = "-- hit any key to continue or 'q' to quit --";
     int lastPromptLength = prompt.length();
@@ -778,46 +782,59 @@ public class Shell extends ShellOptions 
       if (nextLine == null)
         continue;
       for (String line : nextLine.split("\\n")) {
-        if (peek != null) {
-          reader.printString(peek);
-          reader.printNewline();
-          if (paginate) {
-            linesPrinted += peek.length() == 0 ? 0 : Math.ceil(peek.length() * 1.0 / termWidth);
-            
-            // check if displaying the next line would result in
-            // scrolling off the screen
-            if (linesPrinted + Math.ceil(lastPromptLength * 1.0 / termWidth) + Math.ceil(prompt.length()
* 1.0 / termWidth)
-                + Math.ceil(line.length() * 1.0 / termWidth) > maxLines) {
-              linesPrinted = 0;
-              int numdashes = (termWidth - prompt.length()) / 2;
-              String nextPrompt = repeat("-", numdashes) + prompt + repeat("-", numdashes);
-              lastPromptLength = nextPrompt.length();
-              reader.printString(nextPrompt);
-              reader.flushConsole();
-              if (Character.toUpperCase((char) reader.readVirtualKey()) == 'Q') {
+        if (out == null) {
+          if (peek != null) {
+            reader.printString(peek);
+            reader.printNewline();
+            if (paginate) {
+              linesPrinted += peek.length() == 0 ? 0 : Math.ceil(peek.length() * 1.0 / termWidth);
+              
+              // check if displaying the next line would result in
+              // scrolling off the screen
+              if (linesPrinted + Math.ceil(lastPromptLength * 1.0 / termWidth) + Math.ceil(prompt.length()
* 1.0 / termWidth)
+                  + Math.ceil(line.length() * 1.0 / termWidth) > maxLines) {
+                linesPrinted = 0;
+                int numdashes = (termWidth - prompt.length()) / 2;
+                String nextPrompt = repeat("-", numdashes) + prompt + repeat("-", numdashes);
+                lastPromptLength = nextPrompt.length();
+                reader.printString(nextPrompt);
+                reader.flushConsole();
+                if (Character.toUpperCase((char) reader.readVirtualKey()) == 'Q') {
+                  reader.printNewline();
+                  return;
+                }
                 reader.printNewline();
-                return;
+                termWidth = reader.getTermwidth();
+                maxLines = reader.getTermheight();
               }
-              reader.printNewline();
-              termWidth = reader.getTermwidth();
-              maxLines = reader.getTermheight();
             }
           }
+          peek = line;
+        } else {
+          out.print(line);
         }
-        peek = line;
       }
     }
-    if (peek != null) {
+    if (out == null && peek != null) {
       reader.printString(peek);
       reader.printNewline();
     }
   }
   
+  public final void printRecords(Iterable<Entry<Key,Value>> scanner, boolean
printTimestamps, boolean paginate, Class<? extends Formatter> formatterClass,
+      PrintLine outFile) throws IOException {
+    printLines(FormatterFactory.getFormatter(formatterClass, scanner, printTimestamps), paginate,
outFile);
+  }
+  
   public final void printRecords(Iterable<Entry<Key,Value>> scanner, boolean
printTimestamps, boolean paginate, Class<? extends Formatter> formatterClass)
       throws IOException {
     printLines(FormatterFactory.getFormatter(formatterClass, scanner, printTimestamps), paginate);
   }
   
+  public final void printBinaryRecords(Iterable<Entry<Key,Value>> scanner, boolean
printTimestamps, boolean paginate, PrintLine outFile) throws IOException {
+    printLines(FormatterFactory.getFormatter(binaryFormatterClass, scanner, printTimestamps),
paginate, outFile);
+  }
+  
   public final void printBinaryRecords(Iterable<Entry<Key,Value>> scanner, boolean
printTimestamps, boolean paginate) throws IOException {
     printLines(FormatterFactory.getFormatter(binaryFormatterClass, scanner, printTimestamps),
paginate);
   }

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=1398586&r1=1398585&r2=1398586&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 Oct 16 00:27:23 2012
@@ -35,6 +35,7 @@ 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.PrintFile;
 import org.apache.accumulo.core.util.shell.Token;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
@@ -42,7 +43,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 tableOpt, deleteOpt, setOpt, filterOpt, disablePaginationOpt, outputFileOpt;
   
   private int COL1 = 8, COL2 = 7;
   private ConsoleReader reader;
@@ -60,8 +61,8 @@ public class ConfigCommand extends Comma
     root.addSubcommand(cmd);
   }
   
-  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
-      IOException, ClassNotFoundException {
+  public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws AccumuloException, AccumuloSecurityException,
+      TableNotFoundException, IOException, ClassNotFoundException {
     reader = shellState.getReader();
     
     final String tableName = cl.getOptionValue(tableOpt.getOpt());
@@ -77,7 +78,7 @@ 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 {
@@ -92,7 +93,7 @@ public class ConfigCommand extends Comma
       String property = cl.getOptionValue(setOpt.getOpt()), value = null;
       if (!property.contains("=")) {
         throw new BadArgumentException("Missing '=' operator in set operation.", fullCommand,
fullCommand.indexOf(property));
-      }     
+      }
       final String pair[] = property.split("=", 2);
       property = pair[0];
       value = pair[1];
@@ -100,7 +101,7 @@ public class ConfigCommand extends Comma
       if (tableName != null) {
         if (!Property.isValidTablePropertyKey(property)) {
           throw new BadArgumentException("Invalid per-table property.", fullCommand, fullCommand.indexOf(property));
-        }   
+        }
         if (property.equals(Property.TABLE_DEFAULT_SCANTIME_VISIBILITY.getKey())) {
           new ColumnVisibility(value); // validate that it is a valid expression
         }
@@ -118,6 +119,9 @@ public class ConfigCommand extends Comma
       final TreeMap<String,String> systemConfig = new TreeMap<String,String>();
       systemConfig.putAll(shellState.getConnector().instanceOperations().getSystemConfiguration());
       
+      final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
+      final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);
+      
       final TreeMap<String,String> siteConfig = new TreeMap<String,String>();
       siteConfig.putAll(shellState.getConnector().instanceOperations().getSiteConfiguration());
       
@@ -191,7 +195,10 @@ public class ConfigCommand extends Comma
         }
       }
       printConfFooter(output);
-      shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()));
+      shellState.printLines(output.iterator(), !cl.hasOption(disablePaginationOpt.getOpt()),
printFile);
+      if (printFile != null) {
+        printFile.close();
+      }
     }
     return 0;
   }
@@ -230,11 +237,13 @@ public class ConfigCommand extends Comma
     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");
-    
+    outputFileOpt = new Option("o", "output", true, "local file to write the scan output
to");
+
     tableOpt.setArgName("table");
     deleteOpt.setArgName("property");
     setOpt.setArgName("property=value");
     filterOpt.setArgName("string");
+    outputFileOpt.setArgName("file");
     
     og.addOption(deleteOpt);
     og.addOption(setOpt);
@@ -243,6 +252,7 @@ public class ConfigCommand extends Comma
     o.addOption(tableOpt);
     o.addOptionGroup(og);
     o.addOption(disablePaginationOpt);
+    o.addOption(outputFileOpt);
     
     return o;
   }

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=1398586&r1=1398585&r2=1398586&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 Oct 16 00:27:23 2012
@@ -38,6 +38,7 @@ import org.apache.accumulo.core.util.int
 import org.apache.accumulo.core.util.interpret.ScanInterpreter;
 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.PrintFile;
 import org.apache.accumulo.start.classloader.AccumuloClassLoader;
 import org.apache.commons.cli.CommandLine;
 import org.apache.commons.cli.Option;
@@ -46,13 +47,19 @@ import org.apache.hadoop.io.Text;
 
 public class ScanCommand extends Command {
   
-  private Option scanOptAuths, scanOptRow, scanOptColumns, disablePaginationOpt, showFewOpt,
formatterOpt, interpreterOpt, formatterInterpeterOpt;
+  private Option scanOptAuths, scanOptRow, scanOptColumns, disablePaginationOpt, showFewOpt,
formatterOpt, interpreterOpt, formatterInterpeterOpt,
+      outputFileOpt;
+  
   protected Option timestampOpt;
   private Option optStartRowExclusive;
   private Option optEndRowExclusive;
   private Option timeoutOption;
   
   public int execute(final String fullCommand, final CommandLine cl, final Shell shellState)
throws Exception {
+
+    final String outputFile = cl.getOptionValue(outputFileOpt.getOpt());
+    final PrintFile printFile = outputFile == null ? null : new PrintFile(outputFile);
+    
     final String tableName = OptUtil.getTableOpt(cl, shellState);
     
     final Class<? extends Formatter> formatter = getFormatter(cl, tableName, shellState);
@@ -84,7 +91,7 @@ public class ScanCommand extends Command
           throw new IllegalArgumentException();
         }
         BinaryFormatter.getlength(length);
-        printBinaryRecords(cl, shellState, scanner);
+        printBinaryRecords(cl, shellState, scanner, printFile);
       } catch (NumberFormatException nfe) {
         shellState.getReader().printString("Arg must be an integer. \n");
       } catch (IllegalArgumentException iae) {
@@ -92,7 +99,10 @@ public class ScanCommand extends Command
       }
       
     } else {
-        printRecords(cl, shellState, scanner, formatter);
+      printRecords(cl, shellState, scanner, formatter, printFile);
+    }
+    if (printFile != null) {
+      printFile.close();
     }
     
     return 0;
@@ -124,12 +134,31 @@ public class ScanCommand extends Command
     }
   }
   
-  protected void printRecords(final CommandLine cl, final Shell shellState, final Iterable<Entry<Key,Value>>
scanner, final Class<? extends Formatter> formatter) throws IOException {
-    shellState.printRecords(scanner, cl.hasOption(timestampOpt.getOpt()), !cl.hasOption(disablePaginationOpt.getOpt()),
formatter);
+  protected void printRecords(final CommandLine cl, final Shell shellState, final Iterable<Entry<Key,Value>>
scanner, final Class<? extends Formatter> formatter)
+      throws IOException {
+    printRecords(cl, shellState, scanner, formatter);
   }
   
+  protected void printRecords(final CommandLine cl, final Shell shellState, final Iterable<Entry<Key,Value>>
scanner,
+      final Class<? extends Formatter> formatter, PrintFile outFile) throws IOException
{
+    if (outFile == null) {
+      shellState.printRecords(scanner, cl.hasOption(timestampOpt.getOpt()), !cl.hasOption(disablePaginationOpt.getOpt()),
formatter);
+    } else {
+      shellState.printRecords(scanner, cl.hasOption(timestampOpt.getOpt()), !cl.hasOption(disablePaginationOpt.getOpt()),
formatter, outFile);
+    }
+  }
+
   protected void printBinaryRecords(final CommandLine cl, final Shell shellState, final Iterable<Entry<Key,Value>>
scanner) throws IOException {
-    shellState.printBinaryRecords(scanner, cl.hasOption(timestampOpt.getOpt()), !cl.hasOption(disablePaginationOpt.getOpt()));
+    printBinaryRecords(cl, shellState, scanner, null);
+  }
+  
+  protected void printBinaryRecords(final CommandLine cl, final Shell shellState, final Iterable<Entry<Key,Value>>
scanner, PrintFile outFile)
+      throws IOException {
+    if (outFile == null) {
+      shellState.printBinaryRecords(scanner, cl.hasOption(timestampOpt.getOpt()), !cl.hasOption(disablePaginationOpt.getOpt()));
+    } else {
+      shellState.printBinaryRecords(scanner, cl.hasOption(timestampOpt.getOpt()), !cl.hasOption(disablePaginationOpt.getOpt()),
outFile);
+    }
   }
   
   protected ScanInterpreter getInterpreter(final CommandLine cl, final String tableName,
final Shell shellState) throws Exception {
@@ -239,6 +268,7 @@ public class ScanCommand extends Command
     formatterInterpeterOpt = new Option("fi", "fmt-interpreter", true, "fully qualified name
of a class that is a formatter and interpreter");
     timeoutOption = new Option(null, "timeout", true,
         "time before scan should fail if no data is returned. If no unit is given assumes
seconds.  Units d,h,m,s,and ms are supported.  e.g. 30s or 100ms");
+    outputFileOpt = new Option("o", "output", true, "local file to write the scan output
to");
     
     scanOptAuths.setArgName("comma-separated-authorizations");
     scanOptRow.setArgName("row");
@@ -247,6 +277,7 @@ public class ScanCommand extends Command
     showFewOpt.setArgName("int");
     formatterOpt.setArgName("className");
     timeoutOption.setArgName("timeout");
+    outputFileOpt.setArgName("file");
     
     o.addOption(scanOptAuths);
     o.addOption(scanOptRow);
@@ -263,6 +294,7 @@ public class ScanCommand extends Command
     o.addOption(interpreterOpt);
     o.addOption(formatterInterpeterOpt);
     o.addOption(timeoutOption);
+    o.addOption(outputFileOpt);
     
     return o;
   }



Mime
View raw message