cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r980964 - in /cassandra/trunk/src/java/org/apache/cassandra/cli: CliClient.java CliMain.java CliOptions.java CliSessionState.java
Date Fri, 30 Jul 2010 21:06:01 GMT
Author: eevans
Date: Fri Jul 30 21:06:01 2010
New Revision: 980964

URL: http://svn.apache.org/viewvc?rev=980964&view=rev
Log:
CASSANDRA-1340. cassandra-cli: batch processing mode

Passing --batch on the command line causes normal output to be suppressed,
and errors to be fatal. Useful for executing bulk commands in a script ala:

   bin/cassandra-cli < commands.txt

Patch by eevans for CASSANDRA-1340

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliOptions.java
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliSessionState.java

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java?rev=980964&r1=980963&r2=980964&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Fri Jul 30 21:06:01 2010
@@ -143,6 +143,8 @@ public class CliClient 
                     break;
                 default:
                     css_.err.println("Invalid Statement (Type: " + ast.getType() + ")");
+                    if (css_.batch)
+                        System.exit(2);
                     break;
             }
         }

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java?rev=980964&r1=980963&r2=980964&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliMain.java Fri Jul 30 21:06:01 2010
@@ -233,12 +233,20 @@ public class CliMain
             css_.err.println(ire.why);
             if (css_.debug)
                 ire.printStackTrace(css_.err);
+            
+            // Abort a batch run when errors are encountered
+            if (css_.batch)
+                System.exit(4);
         }
         catch (Exception e)
         {
             css_.err.println("Exception " + e.getMessage());
             if (css_.debug)
                 e.printStackTrace(css_.err);
+            
+            // Abort a batch run when errors are encountered
+            if (css_.batch)
+                System.exit(8);
         }
     }
 
@@ -262,19 +270,27 @@ public class CliMain
         }
 
         ConsoleReader reader = new ConsoleReader();
-        reader.addCompletor(completer_);
-        reader.setBellEnabled(false);
-
-        String historyFile = System.getProperty("user.home") + File.separator + HISTORYFILE;
-
-        try
+        
+        if (!css_.batch)
         {
-            History history = new History(new File(historyFile));
-            reader.setHistory(history);
+            reader.addCompletor(completer_);
+            reader.setBellEnabled(false);
+            
+            String historyFile = System.getProperty("user.home") + File.separator + HISTORYFILE;
+
+            try
+            {
+                History history = new History(new File(historyFile));
+                reader.setHistory(history);
+            }
+            catch (IOException exp)
+            {
+                css_.err.printf("Unable to open %s for writing%n", historyFile);
+            }
         }
-        catch (IOException exp)
+        else
         {
-            css_.err.printf("Unable to open %s for writing%n", historyFile);
+            css_.out.close();
         }
 
         printBanner();

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliOptions.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliOptions.java?rev=980964&r1=980963&r2=980964&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliOptions.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliOptions.java Fri Jul 30 21:06:01
2010
@@ -37,6 +37,7 @@ public class CliOptions {
     private static final String USERNAME_OPTION = "username";
     private static final String PASSWORD_OPTION = "password";
     private static final String KEYSPACE_OPTION = "keyspace";
+    private static final String BATCH_OPTION = "batch";
 
     // Default values for optional command line arguments
     private static final int    DEFAULT_THRIFT_PORT = 9160;
@@ -53,12 +54,14 @@ public class CliOptions {
         options.addOption(USERNAME_OPTION, true, "username for cassandra authentication");
         options.addOption(PASSWORD_OPTION, true, "password for cassandra authentication");
         options.addOption(KEYSPACE_OPTION, true, "cassandra keyspace user is authenticated
against");
+        options.addOption(BATCH_OPTION, false, "enabled batch mode (supress output; errors
are fatal)");
     }
 
     private static void printUsage()
     {
         System.err.println("");
-        System.err.println("Usage: cassandra-cli --host hostname [--port <portname>]
[--unframed] [--debug] [--username username] [--password password] [--keyspace keyspace]");
+        System.err.println("Usage: cassandra-cli --host hostname [--port <portname>]
[--unframed] [--debug]");
+        System.err.println("    [--username username] [--password password] [--keyspace keyspace]
[--batch]");
         System.err.println("");
     }
 
@@ -130,5 +133,10 @@ public class CliOptions {
         {
         	css.keyspace = cmd.getOptionValue(KEYSPACE_OPTION);
         }
+        
+        if (cmd.hasOption(BATCH_OPTION))
+        {
+            css.batch = true;
+        }
     }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/cli/CliSessionState.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/cli/CliSessionState.java?rev=980964&r1=980963&r2=980964&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliSessionState.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliSessionState.java Fri Jul 30 21:06:01
2010
@@ -33,7 +33,8 @@ public class CliSessionState
     public boolean debug = false; // print stack traces when errors occur in the CLI
     public String  username;      // cassandra login name (if SimpleAuthenticator is used)
     public String  password;      // cassandra login password (if SimpleAuthenticator is
used)
-    public String  keyspace;      // cassandra keyspace user is authenticating 			
+    public String  keyspace;      // cassandra keyspace user is authenticating
+    public boolean batch = false; // enable/disable batch processing mode
     /*
      * Streams to read/write from
      */



Mime
View raw message