cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1022101 - in /cassandra/trunk: CHANGES.txt src/java/org/apache/cassandra/cli/CliClient.java
Date Wed, 13 Oct 2010 13:52:18 GMT
Author: jbellis
Date: Wed Oct 13 13:52:17 2010
New Revision: 1022101

URL: http://svn.apache.org/viewvc?rev=1022101&view=rev
Log:
cli support for strategy_options.
patch by Pavel Yaskevich; reviewed by jbellis for CASSANDRA-1612

Modified:
    cassandra/trunk/CHANGES.txt
    cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java

Modified: cassandra/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/trunk/CHANGES.txt?rev=1022101&r1=1022100&r2=1022101&view=diff
==============================================================================
--- cassandra/trunk/CHANGES.txt (original)
+++ cassandra/trunk/CHANGES.txt Wed Oct 13 13:52:17 2010
@@ -24,7 +24,7 @@ dev
  * log auto-guessed memtable thresholds (CASSANDRA-1595)
  * add ColumnDef support to cli (CASSANDRA-1583)
  * reduce index sample time by 75% (CASSANDRA-1572)
- * add cli support for column metadata (CASSANDRA-1578)
+ * add cli support for column, strategy metadata (CASSANDRA-1578, 1612)
  * add cli support for schema modification (CASSANDRA-1584)
  * delete temp files on failed compactions (CASSANDRA-1596)
  * avoid blocking for dead nodes during removetoken (CASSANDRA-1605)

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=1022101&r1=1022100&r2=1022101&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/cli/CliClient.java Wed Oct 13 13:52:17 2010
@@ -58,7 +58,8 @@ public class CliClient 
      */
     private enum AddKeyspaceArgument {
         REPLICATION_FACTOR,
-        PLACEMENT_STRATEGY
+        PLACEMENT_STRATEGY,
+        STRATEGY_OPTIONS
     }
 
     private Cassandra.Client thriftClient_ = null;
@@ -226,10 +227,12 @@ public class CliClient 
                 css_.out.println("                        this keyspace. Valid values are");
                 css_.out.println("                        org.apache.cassandra.locator.SimpleStrategy,");
                 css_.out.println("                        org.apache.cassandra.locator.NetworkTopologyStrategy,");
-                css_.out.println("                        and org.apache.cassandra.locator.OldNetworkTopologyStrategy\n");
+                css_.out.println("                        and org.apache.cassandra.locator.OldNetworkTopologyStrategy");
+                css_.out.println("      strategy_options: additional options for placement_strategy.\n");
                 css_.out.println("example:");
                 css_.out.println("create keyspace foo with replication_factor = 3 and ");
                 css_.out.println("        placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'");
+                css_.out.println("        and strategy_options=[{DC1:2, DC2:2}]");
                 break;
 
             case CliParser.NODE_UPDATE_KEYSPACE:
@@ -244,10 +247,12 @@ public class CliClient 
                 css_.out.println("                        this keyspace. Valid values are");
                 css_.out.println("                        org.apache.cassandra.locator.SimpleStrategy,");
                 css_.out.println("                        org.apache.cassandra.locator.NetworkTopologyStrategy,");
-                css_.out.println("                        and org.apache.cassandra.locator.OldNetworkTopologyStrategy\n");
+                css_.out.println("                        and org.apache.cassandra.locator.OldNetworkTopologyStrategy");
+                css_.out.println("      strategy_options: additional options for placement_strategy.\n");
                 css_.out.println("example:");
                 css_.out.println("update keyspace foo with replication_factor = 2 and ");
                 css_.out.println("        placement_strategy = 'org.apache.cassandra.locator.LocalStrategy'");
+                css_.out.println("        and strategy_options=[{DC1:1, DC2:4, DC3:2}]");
                 break;
 
             case CliParser.NODE_ADD_COLUMN_FAMILY:
@@ -875,6 +880,9 @@ public class CliClient 
             case REPLICATION_FACTOR:
                 ksDef.setReplication_factor(Integer.parseInt(mValue));
                 break;
+            case STRATEGY_OPTIONS:
+                ksDef.setStrategy_options(getStrategyOptionsFromTree(statement.getChild(i
+ 1)));
+                break;
             default:
                 //must match one of the above or we'd throw an exception at the valueOf statement
above.
                 assert(false);
@@ -1505,4 +1513,36 @@ public class CliClient 
         return null;
     }
 
+    /**
+     * Used to get Map of the provided options by create/update keyspace commands
+     * @param options - tree representing options
+     * @return Map - strategy_options map
+     */
+    private Map<String, String> getStrategyOptionsFromTree(final Tree options)
+    {
+        // this map will be returned
+        final Map<String, String> strategyOptions = new HashMap<String, String>();
+
+        // each child node is a ^(HASH ...)
+        for (int i = 0; i < options.getChildCount(); i++)
+        {
+            Tree optionsHash = options.getChild(i);
+            
+            // each child node is ^(PAIR $key $value)
+            for (int j = 0; j < optionsHash.getChildCount(); j++)
+            {
+                Tree optionPair = optionsHash.getChild(j);
+
+                // current $key
+                final String key = CliUtils.unescapeSQLString(optionPair.getChild(0).getText());
+                // current $value
+                final String val = CliUtils.unescapeSQLString(optionPair.getChild(1).getText());
+
+                strategyOptions.put(key, val);
+            }
+        }
+
+        return strategyOptions;
+    }
+
 }



Mime
View raw message