cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alek...@apache.org
Subject git commit: Switch stress to use ITransportFactory (trunk followup)
Date Fri, 31 Jan 2014 17:02:12 GMT
Updated Branches:
  refs/heads/trunk 9d41638ab -> 016a2b052


Switch stress to use ITransportFactory (trunk followup)

patch by Sam Tunnicliffe; reviewed by Benedict Elliott Smith for
CASSANDRA-6641


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/016a2b05
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/016a2b05
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/016a2b05

Branch: refs/heads/trunk
Commit: 016a2b052b9aa71be9d2d4e9afa60525d19f322d
Parents: 9d41638
Author: Aleksey Yeschenko <aleksey@apache.org>
Authored: Fri Jan 31 11:57:55 2014 -0500
Committer: Aleksey Yeschenko <aleksey@apache.org>
Committed: Fri Jan 31 11:57:55 2014 -0500

----------------------------------------------------------------------
 .../cassandra/stress/settings/Legacy.java       | 35 ++++----
 .../stress/settings/SettingsTransport.java      | 92 ++++++++++++--------
 .../stress/settings/StressSettings.java         |  9 +-
 3 files changed, 79 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/016a2b05/tools/stress/src/org/apache/cassandra/stress/settings/Legacy.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/Legacy.java b/tools/stress/src/org/apache/cassandra/stress/settings/Legacy.java
index 6242425..5c793e6 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/Legacy.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/Legacy.java
@@ -265,24 +265,23 @@ public class Legacy implements Serializable
             if (cmd.hasOption("tf"))
                 r.add("-transport", "factory=" + cmd.getOptionValue("tf"));
 
-            // THESE DON'T SEEM TO AFFECT PROGRAM BEHAVIOUR
-//            if(cmd.hasOption(SSL_TRUSTSTORE))
-//                encOptions.truststore = cmd.getOptionValue(SSL_TRUSTSTORE);
-//
-//            if(cmd.hasOption(SSL_TRUSTSTORE_PW))
-//                encOptions.truststore_password = cmd.getOptionValue(SSL_TRUSTSTORE_PW);
-//
-//            if(cmd.hasOption(SSL_PROTOCOL))
-//                encOptions.protocol = cmd.getOptionValue(SSL_PROTOCOL);
-//
-//            if(cmd.hasOption(SSL_ALGORITHM))
-//                encOptions.algorithm = cmd.getOptionValue(SSL_ALGORITHM);
-//
-//            if(cmd.hasOption(SSL_STORE_TYPE))
-//                encOptions.store_type = cmd.getOptionValue(SSL_STORE_TYPE);
-//
-//            if(cmd.hasOption(SSL_CIPHER_SUITES))
-//                encOptions.cipher_suites = cmd.getOptionValue(SSL_CIPHER_SUITES).split(",");
+            if(cmd.hasOption(SSL_TRUSTSTORE))
+                r.add("-transport", "truststore=" + cmd.getOptionValue(SSL_TRUSTSTORE));
+
+            if(cmd.hasOption(SSL_TRUSTSTORE_PW))
+                r.add("-transport", "truststore-password=" + cmd.getOptionValue(SSL_TRUSTSTORE_PW));
+
+            if(cmd.hasOption(SSL_PROTOCOL))
+                r.add("-transport", "ssl-protocol=" + cmd.getOptionValue(SSL_PROTOCOL));
+
+            if(cmd.hasOption(SSL_ALGORITHM))
+                r.add("-transport", "ssl-alg=" +  cmd.getOptionValue(SSL_ALGORITHM));
+
+            if(cmd.hasOption(SSL_STORE_TYPE))
+                r.add("-transport", "store-type=" +  cmd.getOptionValue(SSL_STORE_TYPE));
+
+            if(cmd.hasOption(SSL_CIPHER_SUITES))
+                r.add("-transport", "ssl-ciphers=" +  cmd.getOptionValue(SSL_CIPHER_SUITES));
 
         }
         catch (ParseException e)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/016a2b05/tools/stress/src/org/apache/cassandra/stress/settings/SettingsTransport.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsTransport.java
b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsTransport.java
index 3cb0402..f4c8d84 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/SettingsTransport.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/SettingsTransport.java
@@ -2,49 +2,68 @@ package org.apache.cassandra.stress.settings;
 
 import java.io.Serializable;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import org.apache.thrift.transport.TTransportFactory;
+import org.apache.cassandra.config.EncryptionOptions;
+import org.apache.cassandra.thrift.ITransportFactory;
+import org.apache.cassandra.thrift.SSLTransportFactory;
+import org.apache.cassandra.thrift.TFramedTransportFactory;
 
 public class SettingsTransport implements Serializable
 {
 
     private final String fqFactoryClass;
-    private TTransportFactory factory;
+    private final TOptions options;
+    private ITransportFactory factory;
 
     public SettingsTransport(TOptions options)
     {
-        if (options instanceof SSLOptions)
+        this.options = options;
+        this.fqFactoryClass = options.factory.value();
+        try
         {
-            throw new UnsupportedOperationException();
+            Class<?> clazz = Class.forName(fqFactoryClass);
+            if (!ITransportFactory.class.isAssignableFrom(clazz))
+                throw new ClassCastException();
+            // check we can instantiate it
+            clazz.newInstance();
         }
-        else
+        catch (Exception e)
         {
-            this.fqFactoryClass = options.factory.value();
-            try
-            {
-                Class<?> clazz = Class.forName(fqFactoryClass);
-                if (!TTransportFactory.class.isAssignableFrom(clazz))
-                    throw new ClassCastException();
-                // check we can instantiate it
-                clazz.newInstance();
-            }
-            catch (Exception e)
-            {
-                throw new IllegalArgumentException("Invalid transport factory class: " +
options.factory.value(), e);
-            }
-
+            throw new IllegalArgumentException("Invalid transport factory class: " + options.factory.value(),
e);
         }
     }
 
-    public synchronized TTransportFactory getFactory()
+    private void configureTransportFactory(ITransportFactory transportFactory, TOptions options)
+    {
+        Map<String, String> factoryOptions = new HashMap<>();
+        // If the supplied factory supports the same set of options as our SSL impl, set
those
+        if (transportFactory.supportedOptions().contains(SSLTransportFactory.TRUSTSTORE))
+            factoryOptions.put(SSLTransportFactory.TRUSTSTORE, options.trustStore.value());
+        if (transportFactory.supportedOptions().contains(SSLTransportFactory.TRUSTSTORE_PASSWORD))
+            factoryOptions.put(SSLTransportFactory.TRUSTSTORE_PASSWORD, options.trustStorePw.value());
+        if (transportFactory.supportedOptions().contains(SSLTransportFactory.PROTOCOL))
+            factoryOptions.put(SSLTransportFactory.PROTOCOL, options.protocol.value());
+        if (transportFactory.supportedOptions().contains(SSLTransportFactory.CIPHER_SUITES))
+            factoryOptions.put(SSLTransportFactory.CIPHER_SUITES, options.ciphers.value());
+        // Now check if any of the factory's supported options are set as system properties
+        for (String optionKey : transportFactory.supportedOptions())
+            if (System.getProperty(optionKey) != null)
+                factoryOptions.put(optionKey, System.getProperty(optionKey));
+
+        transportFactory.setOptions(factoryOptions);
+    }
+
+    public synchronized ITransportFactory getFactory()
     {
         if (factory == null)
         {
             try
             {
-                this.factory = (TTransportFactory) Class.forName(fqFactoryClass).newInstance();
+                this.factory = (ITransportFactory) Class.forName(fqFactoryClass).newInstance();
+                configureTransportFactory(this.factory, this.options);
             }
             catch (Exception e)
             {
@@ -54,27 +73,32 @@ public class SettingsTransport implements Serializable
         return factory;
     }
 
-    // Option Declarations
-
-    static class TOptions extends GroupedOptions
+    public EncryptionOptions.ClientEncryptionOptions getEncryptionOptions()
     {
-        final OptionSimple factory = new OptionSimple("factory=", ".*", "org.apache.cassandra.cli.transport.FramedTransportFactory",
"Fully-qualified TTransportFactory class name for creating a connection. Note: For Thrift
over SSL, use org.apache.cassandra.stress.SSLTransportFactory.", false);
-
-        @Override
-        public List<? extends Option> options()
+        EncryptionOptions.ClientEncryptionOptions encOptions = new EncryptionOptions.ClientEncryptionOptions();
+        if (options.trustStore.present())
         {
-            return Arrays.asList(factory);
+            encOptions.enabled = true;
+            encOptions.truststore = options.trustStore.value();
+            encOptions.truststore_password = options.trustStorePw.value();
+            encOptions.algorithm = options.alg.value();
+            encOptions.protocol = options.protocol.value();
+            encOptions.cipher_suites = options.ciphers.value().split(",");
         }
+        return encOptions;
     }
 
-    static final class SSLOptions extends TOptions
+    // Option Declarations
+
+    static class TOptions extends GroupedOptions
     {
+        final OptionSimple factory = new OptionSimple("factory=", ".*", TFramedTransportFactory.class.getName(),
"Fully-qualified ITransportFactory class name for creating a connection. Note: For Thrift
over SSL, use org.apache.cassandra.thrift.SSLTransportFactory.", false);
         final OptionSimple trustStore = new OptionSimple("truststore=", ".*", null, "SSL:
full path to truststore", false);
-        final OptionSimple trustStorePw = new OptionSimple("truststore-password=", ".*",
null, "", false);
-        final OptionSimple protocol = new OptionSimple("ssl-protocol=", ".*", "TLS", "SSL:
connections protocol to use", false);
+        final OptionSimple trustStorePw = new OptionSimple("truststore-password=", ".*",
null, "SSL: truststore password", false);
+        final OptionSimple protocol = new OptionSimple("ssl-protocol=", ".*", "TLS", "SSL:
connection protocol to use", false);
         final OptionSimple alg = new OptionSimple("ssl-alg=", ".*", "SunX509", "SSL: algorithm",
false);
-        final OptionSimple storeType = new OptionSimple("store-type=", ".*", "TLS", "SSL:
comma delimited list of encryption suites to use", false);
-        final OptionSimple ciphers = new OptionSimple("ssl-ciphers=", ".*", "TLS", "SSL:
comma delimited list of encryption suites to use", false);
+        final OptionSimple storeType = new OptionSimple("store-type=", ".*", "JKS", "SSL:
keystore format", false);
+        final OptionSimple ciphers = new OptionSimple("ssl-ciphers=", ".*", "TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_AES_256_CBC_SHA",
"SSL: comma delimited list of encryption suites to use", false);
 
         @Override
         public List<? extends Option> options()

http://git-wip-us.apache.org/repos/asf/cassandra/blob/016a2b05/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java b/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
index b3fe406..0c8e8c6 100644
--- a/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
+++ b/tools/stress/src/org/apache/cassandra/stress/settings/StressSettings.java
@@ -4,6 +4,7 @@ import java.io.Serializable;
 import java.util.*;
 
 import com.datastax.driver.core.Metadata;
+import org.apache.cassandra.config.EncryptionOptions;
 import org.apache.cassandra.stress.util.JavaDriverClient;
 import org.apache.cassandra.stress.util.SimpleThriftClient;
 import org.apache.cassandra.stress.util.SmartThriftClient;
@@ -11,7 +12,6 @@ import org.apache.cassandra.thrift.Cassandra;
 import org.apache.cassandra.thrift.InvalidRequestException;
 import org.apache.cassandra.transport.SimpleClient;
 import org.apache.thrift.protocol.TBinaryProtocol;
-import org.apache.thrift.transport.TSocket;
 import org.apache.thrift.transport.TTransport;
 
 public class StressSettings implements Serializable
@@ -71,13 +71,11 @@ public class StressSettings implements Serializable
 
     public Cassandra.Client getRawThriftClient(String host, boolean setKeyspace)
     {
-        TSocket socket = new TSocket(host, port.thriftPort);
         Cassandra.Client client;
 
         try
         {
-            TTransport transport = this.transport.getFactory().getTransport(socket);
-            transport.open();
+            TTransport transport = this.transport.getFactory().openTransport(host, port.thriftPort);
 
             client = new Cassandra.Client(new TBinaryProtocol(transport));
 
@@ -131,7 +129,8 @@ public class StressSettings implements Serializable
                 if (client != null)
                     return client;
 
-                JavaDriverClient c = new JavaDriverClient(currentNode, port.nativePort);
+                EncryptionOptions.ClientEncryptionOptions encOptions = transport.getEncryptionOptions();
+                JavaDriverClient c = new JavaDriverClient(currentNode, port.nativePort, encOptions);
                 c.connect(mode.compression());
                 c.execute("USE \"Keyspace1\";", org.apache.cassandra.db.ConsistencyLevel.ONE);
                 return client = c;


Mime
View raw message