You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by xe...@apache.org on 2011/11/09 01:01:11 UTC

svn commit: r1199556 - in /cassandra/branches/cassandra-1.0: CHANGES.txt src/java/org/apache/cassandra/cli/Cli.g src/java/org/apache/cassandra/cli/CliClient.java src/resources/org/apache/cassandra/cli/CliHelp.yaml

Author: xedin
Date: Wed Nov  9 00:01:11 2011
New Revision: 1199556

URL: http://svn.apache.org/viewvc?rev=1199556&view=rev
Log:
`describe ring` command for CLI
patch by Jackson Chung; reviewed by Pavel Yaskevich for CASSANDRA-3220

Modified:
    cassandra/branches/cassandra-1.0/CHANGES.txt
    cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/Cli.g
    cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/CliClient.java
    cassandra/branches/cassandra-1.0/src/resources/org/apache/cassandra/cli/CliHelp.yaml

Modified: cassandra/branches/cassandra-1.0/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/CHANGES.txt?rev=1199556&r1=1199555&r2=1199556&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/CHANGES.txt (original)
+++ cassandra/branches/cassandra-1.0/CHANGES.txt Wed Nov  9 00:01:11 2011
@@ -14,6 +14,7 @@ Merged from 0.8:
  * Revert CASSANDRA-2855
  * Fix bug preventing the use of efficient cross-DC writes (CASSANDRA-3472)
  * Report compression ratio in CFSMBean (CASSANDRA-3393)
+ * `describe ring` command for CLI (CASSANDRA-3220)
 
 1.0.2
  * "defragment" rows for name-based queries under STCS (CASSANDRA-2503)

Modified: cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/Cli.g
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/Cli.g?rev=1199556&r1=1199555&r2=1199556&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/Cli.g (original)
+++ cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/Cli.g Wed Nov  9 00:01:11 2011
@@ -63,6 +63,7 @@ tokens {
     NODE_ASSUME;
     NODE_CONSISTENCY_LEVEL;
     NODE_DROP_INDEX;
+    NODE_DESCRIBE_RING;
 
     // Internal Nodes.
     NODE_COLUMN_ACCESS;
@@ -163,6 +164,7 @@ statement
     | assumeStatement
     | consistencyLevelStatement
     | dropIndex
+    | describeRing
     | -> ^(NODE_NO_OP)
     ;
 
@@ -210,6 +212,8 @@ helpStatement
         -> ^(NODE_HELP NODE_DEL_COLUMN_FAMILY)
     | HELP DROP INDEX
         -> ^(NODE_HELP NODE_DROP_INDEX)
+    | HELP DESCRIBE RING
+        -> ^(NODE_HELP NODE_DESCRIBE_RING)
     | HELP GET 
         -> ^(NODE_HELP NODE_THRIFT_GET)
     | HELP SET 
@@ -350,6 +354,11 @@ dropIndex
         -> ^(NODE_DROP_INDEX columnFamily columnName)
     ;
 
+describeRing
+    : DESCRIBE RING (keyspace)?
+        -> ^(NODE_DESCRIBE_RING (keyspace)?)
+    ;
+
 showVersion
     : SHOW API_VERSION
         -> ^(NODE_SHOW_VERSION)
@@ -580,6 +589,7 @@ CONSISTENCYLEVEL:   'CONSISTENCYLEVEL';
 INDEX:       'INDEX';
 ON:          'ON';
 SCHEMA:      'SCHEMA';
+RING:    'RING';
 
 IP_ADDRESS 
     : IntegerPositiveLiteral '.' IntegerPositiveLiteral '.' IntegerPositiveLiteral '.' IntegerPositiveLiteral

Modified: cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/CliClient.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/CliClient.java?rev=1199556&r1=1199555&r2=1199556&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/branches/cassandra-1.0/src/java/org/apache/cassandra/cli/CliClient.java Wed Nov  9 00:01:11 2011
@@ -284,6 +284,9 @@ public class CliClient
                 case CliParser.NODE_DROP_INDEX:
                     executeDropIndex(tree);
                     break;
+                case CliParser.NODE_DESCRIBE_RING:
+                    executeDescribeRing(tree);
+                    break;
 
                 case CliParser.NODE_NO_OP:
                     // comment lines come here; they are treated as no ops.
@@ -1430,6 +1433,59 @@ public class CliClient
         keyspacesMap.put(keySpace, thriftClient.describe_keyspace(keySpace));
     }
 
+    private void executeDescribeRing(Tree statement) throws TException, InvalidRequestException
+    {
+        if (!CliMain.isConnected())
+            return;
+
+        int argCount = statement.getChildCount();
+
+        if (argCount > 1) // in case somebody changes Cli grammar
+            throw new RuntimeException("`describe ring` command takes maximum one argument. See `help describe ring;`");
+
+        KsDef currentKeySpace = keyspacesMap.get(keySpace);
+
+        if (argCount == 0 && currentKeySpace != null)
+        {
+            describeRing(currentKeySpace.name);
+        }
+        else if (argCount == 1)
+        {
+            String entityName = statement.getChild(0).getText();
+            KsDef inputKsDef = CliUtils.getKeySpaceDef(entityName, thriftClient.describe_keyspaces());
+
+            if (inputKsDef == null)
+            {
+                sessionState.out.println("Sorry, no Keyspace was found with name: " + entityName);
+                return;
+            }
+
+            describeRing(inputKsDef.name);
+        }
+        else
+        {
+            sessionState.out.println("Authenticate to a Keyspace before using `describe ring` or `describe ring <keyspace>`");
+        }
+    }
+
+    private void describeRing(String name) throws TException
+    {
+        List<TokenRange> tokenRangeList;
+
+        try
+        {
+            for (TokenRange tokenRange : thriftClient.describe_ring(name))
+                sessionState.out.println(tokenRange);
+        }
+        catch (InvalidRequestException e)
+        {
+            sessionState.err.println(e.getWhy());
+
+            if (sessionState.debug)
+                e.printStackTrace();
+        }
+    }
+
     // TRUNCATE <columnFamily>
     private void executeTruncate(String columnFamily) throws TException, InvalidRequestException, UnavailableException
     {

Modified: cassandra/branches/cassandra-1.0/src/resources/org/apache/cassandra/cli/CliHelp.yaml
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-1.0/src/resources/org/apache/cassandra/cli/CliHelp.yaml?rev=1199556&r1=1199555&r2=1199556&view=diff
==============================================================================
--- cassandra/branches/cassandra-1.0/src/resources/org/apache/cassandra/cli/CliHelp.yaml (original)
+++ cassandra/branches/cassandra-1.0/src/resources/org/apache/cassandra/cli/CliHelp.yaml Wed Nov  9 00:01:11 2011
@@ -40,6 +40,7 @@ help: |
     create keyspace         Add a keyspace to the cluster.
     del                     Delete a column, super column or row.
     decr                    Decrements a counter column.
+    describe ring           Describe the token range information.
     describe cluster        Describe the cluster configuration.
     describe                Describe a keyspace and it's column families or column family in current keyspace.
     drop column family      Remove a column family and it's data.
@@ -132,6 +133,18 @@ commands:
         describe; - Describes current authenticated keyspace
         describe <keyspace>; - Describe this keyspace
         describe <column_family>; - Describe the colum family in the current authenticated keyspace
+    - name: NODE_DESCRIBE_RING
+      help: |
+        describe ring <keyspace>;
+
+        Describes the token range settings for the named keyspace.
+
+        Optional Parameters:
+        - keyspace: Name of the keyspace to describe.
+
+        Examples:
+        describe ring; - Describes the token range settings for the current authenticated keyspace
+        describe <keyspace>; - Describe the token range settings for this keyspace
     - name:
       help: |
         describe cluster;