diff --git a/cassandra/README.md b/cassandra/README.md index a25b18e642..525b5990bc 100644 --- a/cassandra/README.md +++ b/cassandra/README.md @@ -76,8 +76,11 @@ For keyspace `ycsb`, table `usertable`: * `cassandra.coreconnections` * Defaults for max and core connections can be found here: https://datastax.github.io/java-driver/2.1.8/features/pooling/#pool-size. Cassandra 2.0.X falls under protocol V2, Cassandra 2.1+ falls under protocol V3. * `cassandra.connecttimeoutmillis` +* `cassandra.useSSL` + * Default value is false. + - To connect with SSL set this value to true. * `cassandra.readtimeoutmillis` * Defaults for connect and read timeouts can be found here: https://docs.datastax.com/en/drivers/java/2.0/com/datastax/driver/core/SocketOptions.html. * `cassandra.tracing` * Default is false - * https://docs.datastax.com/en/cql/3.3/cql/cql_reference/tracing_r.html \ No newline at end of file + * https://docs.datastax.com/en/cql/3.3/cql/cql_reference/tracing_r.html diff --git a/cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java b/cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java index f83b8b40dd..46fe8dc95c 100644 --- a/cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java +++ b/cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java @@ -113,7 +113,10 @@ public class CassandraCQLClient extends DB { public static final String TRACING_PROPERTY = "cassandra.tracing"; public static final String TRACING_PROPERTY_DEFAULT = "false"; - + + public static final String USE_SSL_CONNECTION = "cassandra.useSSL"; + private static final String DEFAULT_USE_SSL_CONNECTION = "false"; + /** * Count the number of times initialized to teardown on the last * {@link #cleanup()}. @@ -148,7 +151,7 @@ public void init() throws DBException { debug = Boolean.parseBoolean(getProperties().getProperty("debug", "false")); trace = Boolean.valueOf(getProperties().getProperty(TRACING_PROPERTY, TRACING_PROPERTY_DEFAULT)); - + String host = getProperties().getProperty(HOSTS_PROPERTY); if (host == null) { throw new DBException(String.format( @@ -171,9 +174,16 @@ public void init() throws DBException { getProperties().getProperty(WRITE_CONSISTENCY_LEVEL_PROPERTY, WRITE_CONSISTENCY_LEVEL_PROPERTY_DEFAULT)); + Boolean useSSL = Boolean.parseBoolean(getProperties().getProperty(USE_SSL_CONNECTION, + DEFAULT_USE_SSL_CONNECTION)); + if ((username != null) && !username.isEmpty()) { - cluster = Cluster.builder().withCredentials(username, password) - .withPort(Integer.valueOf(port)).addContactPoints(hosts).build(); + Cluster.Builder clusterBuilder = Cluster.builder().withCredentials(username, password) + .withPort(Integer.valueOf(port)).addContactPoints(hosts); + if (useSSL) { + clusterBuilder = clusterBuilder.withSSL(); + } + cluster = clusterBuilder.build(); } else { cluster = Cluster.builder().withPort(Integer.valueOf(port)) .addContactPoints(hosts).build();