Skip to content

Commit

Permalink
Beta protocol support for cass plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
Sumanth Pasupuleti authored and sumanth-pasupuleti committed Nov 11, 2020
1 parent 91ba19a commit 4d82dc3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public abstract class CJavaDriverBasePlugin<C extends CassandraConfigurationBase
protected volatile Session session;
protected volatile PreparedStatement readPstmt;
protected volatile PreparedStatement writePstmt;
protected volatile boolean allowBetaProtocol;

/**
* Creates an instance of the abstract CJavaDriverBasePlugin class. Subclasses calling this method should use
Expand All @@ -70,6 +71,7 @@ public void init(DataGenerator dataGenerator) throws Exception {
this.connections = config.getConnections();
this.username = config.getUsername();
this.password = config.getPassword();
this.allowBetaProtocol = config.getAllowBetaProtocol();

// we do not set ReadConsistencyLevel and WriteConsistencyLevel and MaxColCount here because the
// enum classes corresponding to the consistency levels differ among the concrete subclasses and because
Expand Down Expand Up @@ -99,9 +101,12 @@ public String runWorkFlow() {
private void initDriver() {
logger.info("Cassandra Cluster: " + clusterName);

this.cluster = cassJavaDriverManager.registerCluster(clusterName, clusterContactPoint, connections, port,
this.cluster = cassJavaDriverManager.registerCluster(clusterName, clusterContactPoint, connections, port, allowBetaProtocol,
username, password);
this.session = cassJavaDriverManager.getSession(cluster);

logger.info("Protocol version in use: {}", session.getCluster().getConfiguration().getProtocolOptions().getProtocolVersion());

if(config.getCreateSchema())
{
logger.info("Trying to upsert schema");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
@ImplementedBy(CassJavaDriverManagerImpl.class)
public interface CassJavaDriverManager {
Cluster registerCluster(String clName, String contactPoint, int connections, int port, String username, String password);
Cluster registerCluster(String clName, String contactPoint, int connections, int port, boolean allowBetaProtocol, String username, String password);
Cluster registerCluster(String clName, String contactPoint, int connections, int port);
Session getSession(Cluster cluster);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public class CassJavaDriverManagerImpl implements CassJavaDriverManager {

@Override
public Cluster registerCluster(String clName, String contactPoint, int connections, int port) {
return registerCluster(clName,contactPoint,connections,port,null,null);
return registerCluster(clName,contactPoint,connections,port, false, null,null);
}
@Override
public Cluster registerCluster(String clName, String contactPoint, int connections, int port, String username, String password) {

@Override
public Cluster registerCluster(String clName, String contactPoint, int connections, int port, boolean allowBetaProtocol, String username, String password) {

PoolingOptions poolingOpts = new PoolingOptions()
.setConnectionsPerHost(HostDistance.LOCAL, connections, connections)
Expand All @@ -40,6 +41,10 @@ public Cluster registerCluster(String clName, String contactPoint, int connectio
clusterBuilder = clusterBuilder.withCredentials(username, password);
}

if (allowBetaProtocol) {
clusterBuilder.allowBetaProtocolVersion();
}

cluster = clusterBuilder.build();
return cluster;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,7 @@ public interface CassandraConfigurationBase {

@DefaultValue("true")
Boolean getCreateSchema();

@DefaultValue("false")
Boolean getAllowBetaProtocol();
}

0 comments on commit 4d82dc3

Please sign in to comment.