Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding the ability to connect to Cassandra using SSL connections. #1294

Merged
merged 4 commits into from
Apr 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cassandra/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* https://docs.datastax.com/en/cql/3.3/cql/cql_reference/tracing_r.html
18 changes: 14 additions & 4 deletions cassandra/src/main/java/com/yahoo/ycsb/db/CassandraCQLClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()}.
Expand Down Expand Up @@ -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(
Expand All @@ -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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these lines of code be merged into just a couple of lines like below?

clusterBuilder = Cluster.builder().with.....addContactPoints(hosts)
if (useSSL) ClusterBuilder = clusterBulider.withSSL()
Cluster = clusterBuilder.build()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure let me try and optimize it.

clusterBuilder = clusterBuilder.withSSL();
}
cluster = clusterBuilder.build();
} else {
cluster = Cluster.builder().withPort(Integer.valueOf(port))
.addContactPoints(hosts).build();
Expand Down