usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject usergrid git commit: Pass cassandra username and password to the Astyanax driver.
Date Tue, 08 Mar 2016 01:59:49 GMT
Repository: usergrid
Updated Branches:
  refs/heads/release-2.1.1 56c995f6b -> 61d0d7add


Pass cassandra username and password to the Astyanax driver.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/61d0d7ad
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/61d0d7ad
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/61d0d7ad

Branch: refs/heads/release-2.1.1
Commit: 61d0d7addd858c036d390a8f0e6a2a6c7f6b0dd0
Parents: 56c995f
Author: Michael Russo <mrusso@apigee.com>
Authored: Mon Mar 7 17:59:13 2016 -0800
Committer: Michael Russo <mrusso@apigee.com>
Committed: Mon Mar 7 17:59:13 2016 -0800

----------------------------------------------------------------------
 .../core/astyanax/CassandraClusterImpl.java     | 34 ++++++++++++++++----
 .../persistence/core/astyanax/CassandraFig.java |  8 +++++
 2 files changed, 36 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/61d0d7ad/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
index cc52f1b..5b59a98 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraClusterImpl.java
@@ -32,6 +32,7 @@ import com.netflix.astyanax.connectionpool.ConnectionPoolConfiguration;
 import com.netflix.astyanax.connectionpool.NodeDiscoveryType;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.connectionpool.impl.ConnectionPoolConfigurationImpl;
+import com.netflix.astyanax.connectionpool.impl.SimpleAuthenticationCredentials;
 import com.netflix.astyanax.connectionpool.impl.Slf4jConnectionPoolMonitorImpl;
 import com.netflix.astyanax.impl.AstyanaxConfigurationImpl;
 import com.netflix.astyanax.thrift.ThriftFamilyFactory;
@@ -158,12 +159,33 @@ public class CassandraClusterImpl implements CassandraCluster {
 
     private ConnectionPoolConfiguration getConnectionPoolConfig ( final String poolName,
final int poolSize ){
 
-        return new ConnectionPoolConfigurationImpl( poolName )
-            .setPort( cassandraFig.getThriftPort() )
-            .setLocalDatacenter( cassandraFig.getLocalDataCenter() )
-            .setMaxConnsPerHost( poolSize )
-            .setSeeds( cassandraFig.getHosts() )
-            .setSocketTimeout( cassandraFig.getTimeout() );
+        ConnectionPoolConfiguration config;
+        final String username = cassandraFig.getUsername();
+        final String password = cassandraFig.getPassword();
+
+        if ( username != null && !username.isEmpty() && password != null
&& !password.isEmpty() ){
+
+            config = new ConnectionPoolConfigurationImpl( poolName )
+                .setPort( cassandraFig.getThriftPort() )
+                .setLocalDatacenter( cassandraFig.getLocalDataCenter() )
+                .setMaxConnsPerHost( poolSize )
+                .setSeeds( cassandraFig.getHosts() )
+                .setSocketTimeout( cassandraFig.getTimeout() )
+                .setAuthenticationCredentials(new SimpleAuthenticationCredentials( username,
password));
+
+        } else {
+
+            // create instance of the connection pool without credential if they are not
set
+            config = new ConnectionPoolConfigurationImpl( poolName )
+                .setPort( cassandraFig.getThriftPort() )
+                .setLocalDatacenter( cassandraFig.getLocalDataCenter() )
+                .setMaxConnsPerHost( poolSize )
+                .setSeeds( cassandraFig.getHosts() )
+                .setSocketTimeout( cassandraFig.getTimeout() );
+        }
+
+
+        return config;
 
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/61d0d7ad/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
index e30ba9c..b00eca8 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/CassandraFig.java
@@ -38,6 +38,8 @@ public interface CassandraFig extends GuicyFig {
     String WRITE_CL = "usergrid.write.cl";
     String SHARD_VALUES = "cassandra.shardvalues";
     String THRIFT_TRANSPORT_SIZE = "cassandra.thrift.transport.frame";
+    String USERNAME = "cassandra.username";
+    String PASSWORD = "cassandra.password";
 
     // locks cassandra properties
     String LOCKS_KEYSPACE_NAME = "cassandra.lock.keyspace";
@@ -78,6 +80,12 @@ public interface CassandraFig extends GuicyFig {
     @Key( "cassandra.datacenter.local" )
     String getLocalDataCenter();
 
+    @Key( USERNAME )
+    String getUsername();
+
+    @Key( PASSWORD )
+    String getPassword();
+
     @Key( "cassandra.connections" )
     @Default( DEFAULT_CONNECTION_POOLSIZE )
     int getConnections();


Mime
View raw message