Skip to content

Commit

Permalink
support for 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmhess committed Mar 8, 2016
1 parent 6d644f5 commit f76b712
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 16 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 0.0.18
- Support for Cassandra 3.0

## 0.0.17
- Fixed null collection issue / NPE (Issue 8)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ loading of various types of delimited files, including

### Downloading
This utility has already been built, and is available at
https://github.com/brianmhess/cassandra-loader/releases/download/v0.0.17/cassandra-loader
https://github.com/brianmhess/cassandra-loader/releases/download/v0.0.18/cassandra-loader

Get it with wget:
```
wget https://github.com/brianmhess/cassandra-loader/releases/download/v0.0.17/cassandra-loader
wget https://github.com/brianmhess/cassandra-loader/releases/download/v0.0.18/cassandra-loader
```

### Building
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'java'
apply plugin: 'application'

def versionNum = '0.0.17'
def versionNum = '0.0.18'

allprojects {
tasks.withType(JavaCompile) {
Expand Down Expand Up @@ -29,7 +29,7 @@ repositories {
}

dependencies {
compile 'com.datastax.cassandra:cassandra-driver-core:2.1.6'
compile 'com.datastax.cassandra:cassandra-driver-core:3.0.0'
compile 'org.xerial.snappy:snappy-java:1.0.5'
compile 'net.jpountz.lz4:lz4:1.2.0'
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/com/datastax/loader/CqlDelimLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@
import com.datastax.driver.core.BoundStatement;
import com.datastax.driver.core.ResultSetFuture;
import com.datastax.driver.core.SSLOptions;
import com.datastax.driver.core.JdkSSLOptions;
import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;

import com.codahale.metrics.Timer;

public class CqlDelimLoad {
private String version = "0.0.17";
private String version = "0.0.18";
private String host = null;
private int port = 9042;
private String username = null;
Expand Down Expand Up @@ -416,7 +417,7 @@ private boolean parseArgs(String[] args) throws IOException, FileNotFoundExcepti
return validateArgs();
}

private SSLOptions createSSLContext()
private SSLOptions createSSLOptions()
throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException,
KeyManagementException, CertificateException, UnrecoverableKeyException {
TrustManagerFactory tmf = null;
Expand All @@ -440,7 +441,7 @@ private SSLOptions createSSLContext()
tmf != null ? tmf.getTrustManagers() : null,
new SecureRandom());

return new SSLOptions(sslContext, SSLOptions.DEFAULT_SSL_CIPHER_SUITES);
return JdkSSLOptions.builder().withSSLContext(sslContext).build();
}

private void setup()
Expand All @@ -453,16 +454,15 @@ private void setup()
Cluster.Builder clusterBuilder = Cluster.builder()
.addContactPoint(host)
.withPort(port)
//.withProtocolVersion(ProtocolVersion.V3)
.withProtocolVersion(ProtocolVersion.V2) // Should be V3, but issues for now....
//.withCompression(ProtocolOptions.Compression.LZ4)
.withPoolingOptions(pOpts)
.withLoadBalancingPolicy(new TokenAwarePolicy( new DCAwareRoundRobinPolicy(), true));
.withLoadBalancingPolicy(new TokenAwarePolicy( DCAwareRoundRobinPolicy.builder().build()))
;

if (null != username)
clusterBuilder = clusterBuilder.withCredentials(username, password);
if (null != truststorePath)
clusterBuilder = clusterBuilder.withSSL(createSSLContext());
clusterBuilder = clusterBuilder.withSSL(createSSLOptions());

cluster = clusterBuilder.build();
if (null == cluster) {
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/datastax/loader/CqlDelimUnload.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.SSLOptions;
import com.datastax.driver.core.JdkSSLOptions;
import com.datastax.driver.core.policies.TokenAwarePolicy;
import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;


public class CqlDelimUnload {
private String version = "0.0.17";
private String version = "0.0.18";
private String host = null;
private int port = 9042;
private String username = null;
Expand Down Expand Up @@ -278,7 +279,7 @@ private boolean parseArgs(String[] args)
return validateArgs();
}

private SSLOptions createSSLContext()
private SSLOptions createSSLOptions()
throws KeyStoreException, FileNotFoundException, IOException, NoSuchAlgorithmException,
KeyManagementException, CertificateException, UnrecoverableKeyException {
TrustManagerFactory tmf = null;
Expand All @@ -302,7 +303,7 @@ private SSLOptions createSSLContext()
tmf != null ? tmf.getTrustManagers() : null,
new SecureRandom());

return new SSLOptions(sslContext, SSLOptions.DEFAULT_SSL_CIPHER_SUITES);
return JdkSSLOptions.builder().withSSLContext(sslContext).build();
}

private void setup()
Expand All @@ -316,11 +317,11 @@ private void setup()
.addContactPoint(host)
.withPort(port)
.withPoolingOptions(pOpts)
.withLoadBalancingPolicy(new TokenAwarePolicy( new DCAwareRoundRobinPolicy()));
.withLoadBalancingPolicy(new TokenAwarePolicy( DCAwareRoundRobinPolicy.builder().build()));
if (null != username)
clusterBuilder = clusterBuilder.withCredentials(username, password);
if (null != truststorePath)
clusterBuilder = clusterBuilder.withSSL(createSSLContext());
clusterBuilder = clusterBuilder.withSSL(createSSLOptions());

cluster = clusterBuilder.build();
if (null == cluster) {
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/datastax/loader/EnhancedSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.datastax.loader;

import java.util.Map;

import com.datastax.driver.core.Session;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.CloseFuture;
Expand Down Expand Up @@ -52,6 +54,10 @@ public ResultSet execute(String query, Object... values) {
return session.execute(query, values);
}

public ResultSet execute(String query, Map<String,Object> values) {
return session.execute(query, values);
}

public ResultSetFuture executeAsync(Statement statement) {
return session.executeAsync(statement);
}
Expand All @@ -64,6 +70,10 @@ public ResultSetFuture executeAsync(String query, Object... values) {
return session.executeAsync(query, values);
}

public ResultSetFuture executeAsync(String query, Map<String,Object> values) {
return session.executeAsync(query, values);
}

public Cluster getCluster() {
return session.getCluster();
}
Expand All @@ -81,6 +91,10 @@ public EnhancedSession init() {
return this;
}

public com.google.common.util.concurrent.ListenableFuture<Session> initAsync() {
return session.initAsync();
}

public boolean isClosed() {
return session.isClosed();
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/datastax/loader/LoaderRetryPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import com.datastax.driver.core.policies.RetryPolicy;
import com.datastax.driver.core.ConsistencyLevel;
import com.datastax.driver.core.Statement;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.WriteType;
import com.datastax.driver.core.exceptions.DriverException;

class LoaderRetryPolicy implements RetryPolicy {
private int numRetries;
Expand Down Expand Up @@ -46,4 +48,17 @@ public RetryDecision onWriteTimeout(Statement statement,

return RetryDecision.retry(cl);
}

public RetryPolicy.RetryDecision onRequestError(Statement statement,
ConsistencyLevel cl,
DriverException e,
int nbRetry) {
return RetryDecision.tryNextHost(cl);
}

public void close() {
}

public void init(Cluster cluster) {
}
}

0 comments on commit f76b712

Please sign in to comment.