You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by gr...@apache.org on 2015/02/24 01:25:34 UTC

[1/3] incubator-usergrid git commit: [USERGRID-409} Fixed all commit errors and merged the STATIC_APPLICATION_KEYSPACE and the SYSTEM_KEYSPACE into a single static ApplicationKeyspace. This allows us to separate a keyspace for each individual application

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-409 [created] 08c1f1d08


[USERGRID-409} Fixed all commit errors and merged the STATIC_APPLICATION_KEYSPACE and the SYSTEM_KEYSPACE into a single static ApplicationKeyspace. This allows us to separate a keyspace for each individual application on the system.


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

Branch: refs/heads/USERGRID-409
Commit: f817f52437cfe3202db12c56b9f94b616ac8431c
Parents: 13da256
Author: grey <gr...@apigee.com>
Authored: Mon Feb 23 12:02:26 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Feb 23 12:02:26 2015 -0800

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpSetup.java       | 35 ++++++------
 .../persistence/cassandra/CassandraService.java | 58 +++++++++++---------
 .../cassandra/EntityManagerFactoryImpl.java     | 20 +++----
 .../persistence/cassandra/SetupImpl.java        | 43 +++++++--------
 .../main/resources/usergrid-core-context.xml    |  1 +
 .../core/astyanax/AstyanaxKeyspaceProvider.java |  2 +-
 .../persistence/core/astyanax/CassandraFig.java | 10 ++--
 .../tokens/cassandra/TokenServiceImpl.java      | 14 ++---
 8 files changed, 93 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index a09ca49..c71c172 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -45,10 +45,9 @@ import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT
 import static org.apache.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.PRINCIPAL_TOKEN_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.PROPERTIES_CF;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.STATIC_APPLICATION_KEYSPACE;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.SYSTEM_KEYSPACE;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.TOKENS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.USE_VIRTUAL_KEYSPACES;
+import static org.apache.usergrid.persistence.cassandra.CassandraService.getApplicationKeyspace;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.keyspaceForApplication;
 
 
@@ -146,17 +145,17 @@ public class CpSetup implements Setup {
 
         migrate();
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE,
-            createColumnFamilyDefinition( SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(),
+            createColumnFamilyDefinition( getApplicationKeyspace(), APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE,
-            createColumnFamilyDefinition( SYSTEM_KEYSPACE, PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(),
+            createColumnFamilyDefinition( getApplicationKeyspace(), PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE,
-            createColumnFamilyDefinition( SYSTEM_KEYSPACE, TOKENS_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(),
+            createColumnFamilyDefinition( getApplicationKeyspace(), TOKENS_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE,
-            createColumnFamilyDefinition( SYSTEM_KEYSPACE, PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(),
+            createColumnFamilyDefinition( getApplicationKeyspace(), PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
 
         logger.info( "System keyspace initialized" );
     }
@@ -184,7 +183,7 @@ public class CpSetup implements Setup {
             logger.info( "Creating application keyspace " + app_keyspace + " for " + applicationName + " application" );
 
             cass.createColumnFamily( app_keyspace,
-                createColumnFamilyDefinition( SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
+                createColumnFamilyDefinition( getApplicationKeyspace(), APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
 
             cass.createColumnFamilies( app_keyspace, getCfDefs( ApplicationCF.class, app_keyspace ) );
 
@@ -202,17 +201,17 @@ public class CpSetup implements Setup {
 
         if ( USE_VIRTUAL_KEYSPACES ) {
 
-            logger.info( "Creating static application keyspace " + STATIC_APPLICATION_KEYSPACE );
+            logger.info( "Creating static application keyspace " + getApplicationKeyspace() );
 
-            cass.createColumnFamily( STATIC_APPLICATION_KEYSPACE,
-                createColumnFamilyDefinition( STATIC_APPLICATION_KEYSPACE, APPLICATIONS_CF,
+            cass.createColumnFamily( getApplicationKeyspace(),
+                createColumnFamilyDefinition( getApplicationKeyspace(), APPLICATIONS_CF,
                     ComparatorType.BYTESTYPE ) );
 
-            cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
-                getCfDefs( ApplicationCF.class, STATIC_APPLICATION_KEYSPACE ) );
+            cass.createColumnFamilies( getApplicationKeyspace(),
+                getCfDefs( ApplicationCF.class, getApplicationKeyspace() ) );
 
-            cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
-                getCfDefs( QueuesCF.class, STATIC_APPLICATION_KEYSPACE ) );
+            cass.createColumnFamilies( getApplicationKeyspace(),
+                getCfDefs( QueuesCF.class, getApplicationKeyspace() ) );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
index 2322b95..2c74e77 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/CassandraService.java
@@ -36,9 +36,12 @@ import org.apache.usergrid.persistence.IndexBucketLocator;
 import org.apache.usergrid.persistence.IndexBucketLocator.IndexType;
 import org.apache.usergrid.persistence.cassandra.index.IndexBucketScanner;
 import org.apache.usergrid.persistence.cassandra.index.IndexScanner;
+import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
 import org.apache.usergrid.persistence.hector.CountingMutator;
 import org.apache.usergrid.utils.MapUtils;
 
+import com.google.inject.Injector;
+
 import me.prettyprint.cassandra.connection.HConnectionManager;
 import me.prettyprint.cassandra.model.ConfigurableConsistencyLevel;
 import me.prettyprint.cassandra.serializers.ByteBufferSerializer;
@@ -90,10 +93,10 @@ import static org.apache.usergrid.utils.MapUtils.filter;
 
 public class CassandraService {
 
-    public static String SYSTEM_KEYSPACE = "Usergrid";
-
-    public static String STATIC_APPLICATION_KEYSPACE = "Usergrid_Applications";
+    //make the below two not static
+   // public static String SYSTEM_KEYSPACE = "Usergrid";
 
+    public static String applicationKeyspace;
     public static final boolean USE_VIRTUAL_KEYSPACES = true;
 
     public static final String APPLICATIONS_CF = "Applications";
@@ -137,14 +140,17 @@ public class CassandraService {
 
     public static final UUID NULL_ID = new UUID( 0, 0 );
 
-
+//Wire guice injector via spring here, just pass the injector in the spring
     public CassandraService( Properties properties, Cluster cluster,
-                             CassandraHostConfigurator cassandraHostConfigurator, LockManager lockManager ) {
+                             CassandraHostConfigurator cassandraHostConfigurator, LockManager lockManager,
+                           final Injector injector) {
         this.properties = properties;
         this.cluster = cluster;
         chc = cassandraHostConfigurator;
         this.lockManager = lockManager;
         db_logger.info( "" + cluster.getKnownPoolHosts( false ) );
+        //getInjector
+        applicationKeyspace  = injector.getInstance( CassandraFig.class ).getApplicationKeyspace();
     }
 
 
@@ -158,7 +164,7 @@ public class CassandraService {
         accessMap.put( "username", properties.getProperty( "cassandra.username" ) );
         accessMap.put( "password", properties.getProperty( "cassandra.password" ) );
         systemKeyspace =
-                HFactory.createKeyspace( SYSTEM_KEYSPACE, cluster, consistencyLevelPolicy, ON_FAIL_TRY_ALL_AVAILABLE,
+                HFactory.createKeyspace( getApplicationKeyspace() , cluster, consistencyLevelPolicy, ON_FAIL_TRY_ALL_AVAILABLE,
                         accessMap );
 
 
@@ -168,6 +174,9 @@ public class CassandraService {
 
     }
 
+    public static String getApplicationKeyspace() {
+        return applicationKeyspace;
+    }
 
     public Cluster getCluster() {
         return cluster;
@@ -230,7 +239,7 @@ public class CassandraService {
     /** @return keyspace for application UUID */
     public static String keyspaceForApplication( UUID applicationId ) {
         if ( USE_VIRTUAL_KEYSPACES ) {
-            return STATIC_APPLICATION_KEYSPACE;
+            return getApplicationKeyspace();
         }
         else {
             return "Application_" + applicationId.toString().replace( '-', '_' );
@@ -271,20 +280,15 @@ public class CassandraService {
 
     /** The Usergrid_Applications keyspace directly */
     public Keyspace getUsergridApplicationKeyspace() {
-        return getKeyspace( STATIC_APPLICATION_KEYSPACE, null );
-    }
-
-
-    public Keyspace getSystemKeyspace() {
-        return systemKeyspace;
+        return getKeyspace( getApplicationKeyspace(), null );
     }
 
 
     public boolean checkKeyspacesExist() {
         boolean exists = false;
         try {
-            exists = cluster.describeKeyspace( SYSTEM_KEYSPACE ) != null
-                    && cluster.describeKeyspace( STATIC_APPLICATION_KEYSPACE ) != null;
+            exists = cluster.describeKeyspace( getApplicationKeyspace() ) != null;
+
         }
         catch ( Exception ex ) {
             logger.error( "could not describe keyspaces", ex );
@@ -406,7 +410,7 @@ public class CassandraService {
     /**
      * Gets the columns.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      *
@@ -462,7 +466,7 @@ public class CassandraService {
     /**
      * Gets the columns.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      * @param start the start
@@ -584,7 +588,7 @@ public class CassandraService {
     /**
      * Gets the columns.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param keys the keys
      *
@@ -623,7 +627,7 @@ public class CassandraService {
     /**
      * Gets the columns.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      * @param columnNames the column names
@@ -668,7 +672,7 @@ public class CassandraService {
     /**
      * Gets the columns.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param keys the keys
      * @param columnNames the column names
@@ -711,7 +715,7 @@ public class CassandraService {
     /**
      * Gets the column.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      * @param column the column
@@ -827,7 +831,7 @@ public class CassandraService {
     /**
      * Sets the columns.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      * @param map the map
@@ -894,7 +898,7 @@ public class CassandraService {
     /**
      * Delete column.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      * @param column the column
@@ -915,7 +919,7 @@ public class CassandraService {
     /**
      * Gets the row keys.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      *
      * @return set of keys
@@ -953,7 +957,7 @@ public class CassandraService {
     /**
      * Gets the row keys as uui ds.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      *
      * @return list of row key UUIDs
@@ -985,7 +989,7 @@ public class CassandraService {
     /**
      * Delete row.
      *
-     * @param keyspace the keyspace
+     * @param ko the keyspace
      * @param columnFamily the column family
      * @param key the key
      *
@@ -1043,7 +1047,7 @@ public class CassandraService {
 
 
 
-    
+
     public void destroy() throws Exception {
     	if (cluster != null) {
     		HConnectionManager connectionManager = cluster.getConnectionManager();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
index 8b5906c..9a90e59 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
@@ -192,7 +192,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
         String appName = buildAppName( organizationName, name );
 
         HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getSystemKeyspace(), APPLICATIONS_CF, appName, PROPERTY_UUID );
+                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, appName, PROPERTY_UUID );
         if ( column != null ) {
             throw new ApplicationAlreadyExistsException( name );
             // UUID uuid = uuid(column.getValue());
@@ -236,7 +236,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
 
         getSetup().setupApplicationKeyspace( applicationId, appName );
 
-        Keyspace ko = cass.getSystemKeyspace();
+        Keyspace ko = cass.getUsergridApplicationKeyspace();
         Mutator<ByteBuffer> m = CountingMutator.createFlushingMutator( ko, be );
 
         long timestamp = cass.createTimestamp();
@@ -262,7 +262,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
         name = buildAppName( organizationName, name );
 
         HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getSystemKeyspace(), APPLICATIONS_CF, name, PROPERTY_UUID );
+                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name, PROPERTY_UUID );
         if ( column != null ) {
             throw new ApplicationAlreadyExistsException( name );
             // UUID uuid = uuid(column.getValue());
@@ -278,7 +278,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     public UUID lookupApplication( String name ) throws Exception {
         name = name.toLowerCase();
         HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getSystemKeyspace(), APPLICATIONS_CF, name, PROPERTY_UUID );
+                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name, PROPERTY_UUID );
         if ( column != null ) {
             return uuid( column.getValue() );
         }
@@ -299,7 +299,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     public Application getApplication( String name ) throws Exception {
         name = name.toLowerCase();
         HColumn<String, ByteBuffer> column =
-                cass.getColumn( cass.getSystemKeyspace(), APPLICATIONS_CF, name, PROPERTY_UUID );
+                cass.getColumn( cass.getUsergridApplicationKeyspace(), APPLICATIONS_CF, name, PROPERTY_UUID );
         if ( column == null ) {
             return null;
         }
@@ -314,7 +314,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     @Override
     public Map<String, UUID> getApplications() throws Exception {
         Map<String, UUID> applications = new TreeMap<String, UUID>( CASE_INSENSITIVE_ORDER );
-        Keyspace ko = cass.getSystemKeyspace();
+        Keyspace ko = cass.getUsergridApplicationKeyspace();
         RangeSlicesQuery<String, String, UUID> q = createRangeSlicesQuery( ko, se, se, ue );
         q.setKeys( "", "\uFFFF" );
         q.setColumnFamily( APPLICATIONS_CF );
@@ -333,7 +333,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
    @Override
     public boolean setServiceProperty( String name, String value ) {
         try {
-            cass.setColumn( cass.getSystemKeyspace(), PROPERTIES_CF, PROPERTIES_CF, name, value );
+            cass.setColumn( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF, name, value );
             return true;
         }
         catch ( Exception e ) {
@@ -346,7 +346,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     @Override
     public boolean deleteServiceProperty( String name ) {
         try {
-            cass.deleteColumn( cass.getSystemKeyspace(), PROPERTIES_CF, PROPERTIES_CF, name );
+            cass.deleteColumn( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF, name );
             return true;
         }
         catch ( Exception e ) {
@@ -359,7 +359,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     @Override
     public boolean updateServiceProperties( Map<String, String> properties ) {
         try {
-            cass.setColumns( cass.getSystemKeyspace(), PROPERTIES_CF, PROPERTIES_CF.getBytes(), properties );
+            cass.setColumns( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF.getBytes(), properties );
             return true;
         }
         catch ( Exception e ) {
@@ -372,7 +372,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory, Applicati
     @Override
     public Map<String, String> getServiceProperties() {
         try {
-            return asMap( cass.getAllColumns( cass.getSystemKeyspace(), PROPERTIES_CF, PROPERTIES_CF, se, se ) );
+            return asMap( cass.getAllColumns( cass.getUsergridApplicationKeyspace(), PROPERTIES_CF, PROPERTIES_CF, se, se ) );
         }
         catch ( Exception e ) {
             logger.error( "Unable to load properties: " + e.getMessage() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
index 97a7654..775f43b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/SetupImpl.java
@@ -29,10 +29,9 @@ import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT
 import static org.apache.usergrid.persistence.cassandra.CassandraService.MANAGEMENT_APPLICATION;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.PRINCIPAL_TOKEN_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.PROPERTIES_CF;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.STATIC_APPLICATION_KEYSPACE;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.SYSTEM_KEYSPACE;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.TOKENS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.USE_VIRTUAL_KEYSPACES;
+import static org.apache.usergrid.persistence.cassandra.CassandraService.getApplicationKeyspace;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.keyspaceForApplication;
 import org.apache.usergrid.persistence.entities.Application;
 import org.slf4j.Logger;
@@ -80,17 +79,17 @@ public class SetupImpl implements Setup {
 
         logger.info( "Initialize system keyspace" );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition(
-                SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(), createColumnFamilyDefinition(
+                getApplicationKeyspace(), APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition(
-                SYSTEM_KEYSPACE, PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(), createColumnFamilyDefinition(
+                getApplicationKeyspace(), PROPERTIES_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition(
-                SYSTEM_KEYSPACE, TOKENS_CF, ComparatorType.BYTESTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(), createColumnFamilyDefinition(
+                getApplicationKeyspace(), TOKENS_CF, ComparatorType.BYTESTYPE ) );
 
-        cass.createColumnFamily( SYSTEM_KEYSPACE, createColumnFamilyDefinition(
-                SYSTEM_KEYSPACE, PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
+        cass.createColumnFamily( getApplicationKeyspace(), createColumnFamilyDefinition(
+                getApplicationKeyspace(), PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE ) );
 
         logger.info( "System keyspace initialized" );
     }
@@ -115,7 +114,7 @@ public class SetupImpl implements Setup {
                     + applicationName + " application" );
 
             cass.createColumnFamily( app_keyspace, createColumnFamilyDefinition(
-                    SYSTEM_KEYSPACE, APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
+                    getApplicationKeyspace(), APPLICATIONS_CF, ComparatorType.BYTESTYPE ) );
 
             cass.createColumnFamilies( app_keyspace, getCfDefs( ApplicationCF.class, app_keyspace));
             cass.createColumnFamilies( app_keyspace, getCfDefs( QueuesCF.class, app_keyspace ) );
@@ -127,16 +126,16 @@ public class SetupImpl implements Setup {
 
         if ( USE_VIRTUAL_KEYSPACES ) {
 
-            logger.info( "Creating static application keyspace " + STATIC_APPLICATION_KEYSPACE );
+            logger.info( "Creating static application keyspace " + getApplicationKeyspace() );
 
-            cass.createColumnFamily( STATIC_APPLICATION_KEYSPACE,
-                    createColumnFamilyDefinition( STATIC_APPLICATION_KEYSPACE, APPLICATIONS_CF,
+            cass.createColumnFamily( getApplicationKeyspace(),
+                    createColumnFamilyDefinition( getApplicationKeyspace(), APPLICATIONS_CF,
                             ComparatorType.BYTESTYPE ) );
 
-            cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
-                    getCfDefs( ApplicationCF.class, STATIC_APPLICATION_KEYSPACE ) );
-            cass.createColumnFamilies( STATIC_APPLICATION_KEYSPACE,
-                    getCfDefs( QueuesCF.class, STATIC_APPLICATION_KEYSPACE ) );
+            cass.createColumnFamilies( getApplicationKeyspace(),
+                    getCfDefs( ApplicationCF.class, getApplicationKeyspace() ) );
+            cass.createColumnFamilies( getApplicationKeyspace(),
+                    getCfDefs( QueuesCF.class, getApplicationKeyspace() ) );
         }
     }
 
@@ -147,13 +146,13 @@ public class SetupImpl implements Setup {
 
 
     public static void logCFPermissions() {
-        System.out.println( SYSTEM_KEYSPACE + "." + APPLICATIONS_CF + ".<rw>=usergrid" );
-        System.out.println( SYSTEM_KEYSPACE + "." + PROPERTIES_CF + ".<rw>=usergrid" );
+        System.out.println( getApplicationKeyspace() + "." + APPLICATIONS_CF + ".<rw>=usergrid" );
+        System.out.println( getApplicationKeyspace() + "." + PROPERTIES_CF + ".<rw>=usergrid" );
         for ( CFEnum cf : ApplicationCF.values() ) {
-            System.out.println( STATIC_APPLICATION_KEYSPACE + "." + cf + ".<rw>=usergrid" );
+            System.out.println( getApplicationKeyspace() + "." + cf + ".<rw>=usergrid" );
         }
         for ( CFEnum cf : QueuesCF.values() ) {
-            System.out.println( STATIC_APPLICATION_KEYSPACE + "." + cf + ".<rw>=usergrid" );
+            System.out.println( getApplicationKeyspace() + "." + cf + ".<rw>=usergrid" );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml
index 60f69af..f0e5bd4 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -105,6 +105,7 @@
 		<constructor-arg ref="cassandraCluster" />
 		<constructor-arg ref="cassandraHostConfigurator" />
 		<constructor-arg ref="lockManager" />
+        <constructor-arg ref="injector"/>
 		<property name="consistencyLevelPolicy" ref="consistencyLevelPolicy"/>
 	</bean>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
index 8bd5a9f..5172331 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/astyanax/AstyanaxKeyspaceProvider.java
@@ -73,7 +73,7 @@ public class AstyanaxKeyspaceProvider implements Provider<Keyspace> {
 
         AstyanaxContext<Keyspace> context =
                 new AstyanaxContext.Builder().forCluster( cassandraFig.getClusterName() )
-                        .forKeyspace( cassandraFig.getKeyspaceName() )
+                        .forKeyspace( cassandraFig.getApplicationKeyspace())
 
                         /*
                          * TODO tnine Filter this by adding a host supplier.  We will get token discovery from cassandra

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/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 df94adc..1208a1a 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
@@ -53,9 +53,9 @@ public interface CassandraFig extends GuicyFig {
     @Default( "Usergrid" )
     String getClusterName();
 
-    @Key( "collections.keyspace" )
-    @Default( "Usergrid_Collections" )
-    String getKeyspaceName();
+    @Key( "cassandra.keyspace.application" )
+    @Default( "Usergrid_Applications" )
+    String getApplicationKeyspace();
 
     @Key( "cassandra.port" )
     @Default( "9160" )
@@ -71,8 +71,8 @@ public interface CassandraFig extends GuicyFig {
 
     @Key("cassandra.discovery")
     @Default( "RING_DESCRIBE" )
-    String getDiscoveryType();    
-    
+    String getDiscoveryType();
+
     @Key("cassandra.embedded")
     @Default( "false" )
     boolean isEmbedded();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f817f524/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
index 50156b5..4d8b987 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/tokens/cassandra/TokenServiceImpl.java
@@ -261,7 +261,7 @@ public class TokenServiceImpl implements TokenService {
 
         long maxTokenTtl = getMaxTtl( TokenCategory.getFromBase64String( token ), tokenInfo.getPrincipal() );
 
-        Mutator<UUID> batch = createMutator( cassandra.getSystemKeyspace(), ue );
+        Mutator<UUID> batch = createMutator( cassandra.getUsergridApplicationKeyspace(), ue );
 
         HColumn<String, Long> col =
                 createColumn( TOKEN_ACCESSED, now, calcTokenTime( tokenInfo.getExpiration( maxTokenTtl ) ),
@@ -326,7 +326,7 @@ public class TokenServiceImpl implements TokenService {
     public void removeTokens( AuthPrincipalInfo principal ) throws Exception {
         List<UUID> tokenIds = getTokenUUIDS( principal );
 
-        Mutator<ByteBuffer> batch = createMutator( cassandra.getSystemKeyspace(), be );
+        Mutator<ByteBuffer> batch = createMutator( cassandra.getUsergridApplicationKeyspace(), be );
 
         for ( UUID tokenId : tokenIds ) {
             batch.addDeletion( bytebuffer( tokenId ), TOKENS_CF );
@@ -359,7 +359,7 @@ public class TokenServiceImpl implements TokenService {
 
         UUID tokenId = info.getUuid();
 
-        Mutator<ByteBuffer> batch = createMutator( cassandra.getSystemKeyspace(), be );
+        Mutator<ByteBuffer> batch = createMutator( cassandra.getUsergridApplicationKeyspace(), be );
 
         // clean up the link in the principal -> token index if the principal is
         // on the token
@@ -380,7 +380,7 @@ public class TokenServiceImpl implements TokenService {
             throw new InvalidTokenException( "No token specified" );
         }
         Map<String, ByteBuffer> columns = getColumnMap( cassandra
-                .getColumns( cassandra.getSystemKeyspace(), TOKENS_CF, uuid, TOKEN_PROPERTIES, se,
+                .getColumns( cassandra.getUsergridApplicationKeyspace(), TOKENS_CF, uuid, TOKEN_PROPERTIES, se,
                         be ) );
         if ( !hasKeys( columns, REQUIRED_TOKEN_PROPERTIES ) ) {
             throw new InvalidTokenException( "Token not found in database" );
@@ -415,7 +415,7 @@ public class TokenServiceImpl implements TokenService {
 
         ByteBuffer tokenUUID = bytebuffer( tokenInfo.getUuid() );
 
-        Keyspace ko = cassandra.getSystemKeyspace();
+        Keyspace ko = cassandra.getUsergridApplicationKeyspace();
 
         Mutator<ByteBuffer> m = createMutator( ko, be );
 
@@ -449,7 +449,7 @@ public class TokenServiceImpl implements TokenService {
 
       /*
        * write to the PRINCIPAL+TOKEN The format is as follow
-       * 
+       *
        * appid+principalId+principalType :{ tokenuuid: 0x00}
        */
 
@@ -473,7 +473,7 @@ public class TokenServiceImpl implements TokenService {
         ByteBuffer rowKey = principalKey( principal );
 
         List<HColumn<ByteBuffer, ByteBuffer>> cols = cassandra
-                .getColumns( cassandra.getSystemKeyspace(), PRINCIPAL_TOKEN_CF, rowKey, null, null, Integer.MAX_VALUE,
+                .getColumns( cassandra.getUsergridApplicationKeyspace(), PRINCIPAL_TOKEN_CF, rowKey, null, null, Integer.MAX_VALUE,
                         false );
 
         List<UUID> results = new ArrayList<UUID>( cols.size() );


[2/3] incubator-usergrid git commit: Fixed CoreSchemaManager

Posted by gr...@apache.org.
Fixed CoreSchemaManager


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

Branch: refs/heads/USERGRID-409
Commit: aac4a2fc946f957261e7c4cf46838abb4bca4148
Parents: f817f52
Author: grey <gr...@apigee.com>
Authored: Mon Feb 23 12:05:56 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Feb 23 12:05:56 2015 -0800

----------------------------------------------------------------------
 .../java/org/apache/usergrid/persistence/CoreSchemaManager.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/aac4a2fc/stack/core/src/test/java/org/apache/usergrid/persistence/CoreSchemaManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CoreSchemaManager.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CoreSchemaManager.java
index 5b9adb8..723e971 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CoreSchemaManager.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CoreSchemaManager.java
@@ -85,7 +85,7 @@ public class CoreSchemaManager implements SchemaManager {
     public void destroy() {
         LOG.info( "dropping keyspaces" );
         try {
-            cluster.dropKeyspace( CassandraService.SYSTEM_KEYSPACE );
+            cluster.dropKeyspace( CassandraService.getApplicationKeyspace() );
         }
         catch ( RuntimeException ire ) {
             //swallow if it just doesn't exist
@@ -93,7 +93,7 @@ public class CoreSchemaManager implements SchemaManager {
 
 
         try {
-            cluster.dropKeyspace( CassandraService.STATIC_APPLICATION_KEYSPACE );
+            cluster.dropKeyspace( CassandraService.getApplicationKeyspace() );
         }
         catch ( RuntimeException ire ) {
             //swallow if it just doesn't exist


[3/3] incubator-usergrid git commit: Added fix for circular decencies and added support for multiple key spaces.

Posted by gr...@apache.org.
Added fix for circular decencies and added support for multiple key spaces.


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

Branch: refs/heads/USERGRID-409
Commit: 08c1f1d08c7c6bb9ce3a4cf979e09fb0d733ef46
Parents: aac4a2f
Author: grey <gr...@apigee.com>
Authored: Mon Feb 23 16:25:31 2015 -0800
Committer: grey <gr...@apigee.com>
Committed: Mon Feb 23 16:25:31 2015 -0800

----------------------------------------------------------------------
 .../usergrid/corepersistence/GuiceFactory.java  | 25 ++++++++------------
 .../main/resources/usergrid-core-context.xml    |  4 ++--
 2 files changed, 12 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/08c1f1d0/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
index 77831fe..566430f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceFactory.java
@@ -32,6 +32,7 @@ import org.springframework.context.ApplicationContextAware;
 import org.apache.commons.lang.StringUtils;
 
 import org.apache.usergrid.persistence.cassandra.CassandraService;
+import org.apache.usergrid.persistence.core.guice.CommonModule;
 
 import com.google.inject.Guice;
 import com.google.inject.Injector;
@@ -39,6 +40,7 @@ import com.google.inject.Singleton;
 import com.netflix.config.ConfigurationManager;
 
 import me.prettyprint.cassandra.service.CassandraHost;
+import me.prettyprint.cassandra.service.CassandraHostConfigurator;
 
 
 /**
@@ -49,8 +51,7 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
 
     private static final Logger logger = LoggerFactory.getLogger( GuiceFactory.class );
 
-
-    private final CassandraService cass;
+    private final CassandraHostConfigurator chc;
 
     private final Properties systemProperties;
 
@@ -61,8 +62,8 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
 
 
 
-    public GuiceFactory( final CassandraService cass, final Properties systemProperties ) {
-        this.cass = cass;
+    public GuiceFactory( final CassandraHostConfigurator chc, final Properties systemProperties  ) {
+        this.chc = chc;
         this.systemProperties = systemProperties;
     }
 
@@ -74,14 +75,12 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
             return injector;
         }
 
-
         try {
 
-            cass.init();
             logger.info( "Loading Core Persistence properties" );
 
             String hostsString = "";
-            CassandraHost[] hosts = cass.getCassandraHostConfigurator().buildCassandraHosts();
+            CassandraHost[] hosts = chc.buildCassandraHosts();
             if ( hosts.length == 0 ) {
                 throw new RuntimeException( "Fatal error: no Cassandra hosts configured" );
             }
@@ -101,9 +100,9 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
             // Some Usergrid properties must be mapped to Core Persistence properties
             cpProps.put( "cassandra.hosts", hostsString );
             cpProps.put( "cassandra.port", hosts[0].getPort() );
-            cpProps.put( "cassandra.cluster_name", cass.getProperties().get( "cassandra.cluster" ) );
+            cpProps.put( "cassandra.cluster_name",  systemProperties.getProperty( "cassandra.cluster" ) );
 
-            String cassRemoteString = ( String ) cass.getProperties().get( "cassandra.use_remote" );
+            String cassRemoteString = ( String ) systemProperties.getProperty( "cassandra.use_remote" );
             if ( cassRemoteString != null && cassRemoteString.equals( "false" ) ) {
                 cpProps.put( "cassandra.embedded", "true" );
             }
@@ -112,21 +111,17 @@ public class GuiceFactory implements FactoryBean<Injector>, ApplicationContextAw
             }
 
             cpProps.put( "collections.keyspace.strategy.class",
-                cass.getProperties().get( "cassandra.keyspace.strategy" ) );
+                systemProperties.getProperty( "cassandra.keyspace.strategy" ) );
 
             cpProps.put( "collections.keyspace.strategy.options",
-                cass.getProperties().get( "cassandra.keyspace.replication" ) );
-
+                systemProperties.getProperty( "cassandra.keyspace.replication" ) );
 
             logger.debug( "Set Cassandra properties for Core Persistence: " + cpProps.toString() );
 
             // Make all Usergrid properties into Core Persistence config
-            cpProps.putAll( cass.getProperties() );
             cpProps.putAll( systemProperties );
             //logger.debug("All properties fed to Core Persistence: " + cpProps.toString() );
 
-
-
             ConfigurationManager.loadProperties( cpProps );
         }
         catch ( Exception e ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/08c1f1d0/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml
index f0e5bd4..1c9aeb1 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -95,9 +95,9 @@
 
     <bean id="injector"
    		class="org.apache.usergrid.corepersistence.GuiceFactory">
-   		<constructor-arg ref="cassandraService" />
+   		<constructor-arg ref="cassandraHostConfigurator" />
         <constructor-arg ref="properties" />
-   	</bean>
+    </bean>
 
 	<bean id="cassandraService"
 		class="org.apache.usergrid.persistence.cassandra.CassandraService" init-method="init" destroy-method="destroy">