usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [3/7] usergrid git commit: Organize the /system/database/setup and /system/database/bootstrap flows.
Date Tue, 29 Mar 2016 19:49:08 GMT
Organize the /system/database/setup and /system/database/bootstrap flows.


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

Branch: refs/heads/release-2.1.1
Commit: 75eb278aaff7298d0339af41f772268e8561a7f2
Parents: 9b9f835
Author: Michael Russo <mrusso@apigee.com>
Authored: Mon Mar 28 17:46:45 2016 -0700
Committer: Michael Russo <mrusso@apigee.com>
Committed: Mon Mar 28 17:46:45 2016 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  30 +++---
 .../usergrid/corepersistence/CpSetup.java       | 100 ++++++-------------
 .../persistence/cassandra/CassandraService.java |   2 -
 .../usergrid/persistence/cassandra/Setup.java   |  28 ++----
 .../usergrid/persistence/CoreSchemaManager.java |  14 +--
 .../usergrid/cassandra/SchemaManager.java       |   3 -
 .../usergrid/cassandra/FakeSchemaManager.java   |   8 +-
 7 files changed, 62 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 0462ac6..1488ae1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -157,7 +157,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
 
 
-    private void init() {
+    private void initMgmtAppInternal() {
 
         EntityManager em = getEntityManager(getManagementAppId());
         indexService.queueInitializeApplicationIndex(CpNamingUtils.getApplicationScope(getManagementAppId()));
@@ -171,8 +171,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                 em.getApplication();
             }
 
-//            entityIndex.refreshAsync();
-
         } catch (Exception ex) {
             throw new RuntimeException("Fatal error creating management application", ex);
         }
@@ -246,8 +244,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public Entity initializeApplicationV2(String organizationName, final UUID applicationId,
String name,
                                           Map<String, Object> properties, boolean forMigration)
throws Exception {
 
-        // Ensure our management system exists before creating our application
-        init();
+        // Ensure the management application is initialized
+        initMgmtAppInternal();
 
         EntityManager managementEm = getEntityManager( getManagementAppId() );
         EntityManager appEm = getEntityManager(applicationId);
@@ -260,7 +258,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             throw new ApplicationAlreadyExistsException( appName );
         }
 
-        getSetup().setupApplicationKeyspace( applicationId, appName );
+        // Initialize the index for this new application
         appEm.initializeIndex();
         indexService.queueInitializeApplicationIndex(CpNamingUtils.getApplicationScope(applicationId));
         if ( properties == null ) {
@@ -517,19 +515,25 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
 
     @Override
     public void setup() throws Exception {
-        getSetup().initSubsystems();
+        getSetup().initSchema();
     }
 
 
     @Override
     public void boostrap() throws Exception {
 
-        //we want to make sure our keyspaces exist
-        setup();
-        //create the defautl applications
-        getSetup().createDefaultApplications();
-        //init any other data we need
-        init();
+        // Always make sure the database schema is initialized
+        getSetup().initSchema();
+
+        // Make sure the management application is created
+        initMgmtAppInternal();
+
+        // Roll the new 2.x Migration classes to the latest version supported
+        getSetup().runDataMigration();
+
+        // Ensure management app is initialized
+        getSetup().initMgmtApp();
+
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/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 e97be3f..623400d 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
@@ -17,8 +17,6 @@
 package org.apache.usergrid.corepersistence;
 
 
-import java.util.UUID;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,11 +37,9 @@ import me.prettyprint.hector.api.ddl.ComparatorType;
 
 import static me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition;
 import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.getCfDefs;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.APPLICATIONS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.DEFAULT_ORGANIZATION;
 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.TOKENS_CF;
 import static org.apache.usergrid.persistence.cassandra.CassandraService.getApplicationKeyspace;
 
@@ -79,23 +75,21 @@ public class CpSetup implements Setup {
 
 
     @Override
-    public void initSubsystems() throws Exception {
-        //a no op, creating the injector creates the connections
-        //init our index if required
-        this.emf.initializeManagementIndex();
-        setupStaticKeyspace();
-        setupSystemKeyspace();
+    public void initSchema() throws Exception {
 
-    }
+        // Initialize the management app index in Elasticsearch
+        this.emf.initializeManagementIndex();
 
+        // Create the schema (including keyspace) in Cassandra
+        setupSchema();
+        setupLegacySchema();
 
-    public void createDefaultApplications() throws Exception {
+    }
 
-        setupSystemKeyspace();
 
-        setupStaticKeyspace();
+    @Override
+    public void initMgmtApp() throws Exception {
 
-        injector.getInstance( DataMigrationManager.class ).migrate();
 
         try {
             emf.initializeApplicationV2( DEFAULT_ORGANIZATION, emf.getManagementAppId(),
@@ -108,36 +102,20 @@ public class CpSetup implements Setup {
             logger.warn( "Organization {} already exists", DEFAULT_ORGANIZATION );
         }
 
-        injector.getInstance( DataMigrationManager.class ).migrate();
-    }
-
-
-    /**
-     * Perform migration of the 2.0 code
-     */
-    private void migrate() {
-        MigrationManager m = injector.getInstance( MigrationManager.class );
-        try {
-            m.migrate();
-        }
-        catch ( MigrationException ex ) {
-            throw new RuntimeException( "Error migrating Core Persistence", ex );
-        }
     }
 
 
     @Override
-    public void setupSystemKeyspace() throws Exception {
+    public void runDataMigration() throws Exception {
+
+        injector.getInstance( DataMigrationManager.class ).migrate();
 
-        logger.info( "Initialize system keyspace" );
+    }
 
-        migrate();
 
-        cass.createColumnFamily( getApplicationKeyspace(),
-            createColumnFamilyDefinition( getApplicationKeyspace(), APPLICATIONS_CF, ComparatorType.BYTESTYPE
) );
+    private void setupLegacySchema() throws Exception {
 
-        cass.createColumnFamily( getApplicationKeyspace(),
-            createColumnFamilyDefinition( getApplicationKeyspace(), PROPERTIES_CF, ComparatorType.BYTESTYPE
) );
+        logger.info( "Initialize keyspace and legacy column families" );
 
         cass.createColumnFamily( getApplicationKeyspace(),
             createColumnFamilyDefinition( getApplicationKeyspace(), TOKENS_CF, ComparatorType.BYTESTYPE
) );
@@ -145,49 +123,33 @@ public class CpSetup implements Setup {
         cass.createColumnFamily( getApplicationKeyspace(),
             createColumnFamilyDefinition( getApplicationKeyspace(), PRINCIPAL_TOKEN_CF, ComparatorType.UUIDTYPE
) );
 
-        logger.info( "System keyspace initialized" );
+        cass.createColumnFamilies( getApplicationKeyspace(),
+            getCfDefs( ApplicationCF.class, getApplicationKeyspace() ) );
+
+        cass.createColumnFamilies( getApplicationKeyspace(),
+            getCfDefs( QueuesCF.class, getApplicationKeyspace() ) );
+
+        logger.info( "Keyspace and legacy column families initialized" );
     }
 
 
     /**
-     * Initialize application keyspace.
-     *
-     * @param applicationId the application id
-     * @param applicationName the application name
+     * Initialize schema from the new 2.x Migration classes which contain schema individually
      *
-     * @throws Exception the exception
      */
 
-    public void setupApplicationKeyspace( final UUID applicationId, String applicationName
) throws Exception {
+    private void setupSchema() throws Exception {
 
-        migrate();
+        MigrationManager m = injector.getInstance( MigrationManager.class );
+        try {
+            m.migrate();
+        }
+        catch ( MigrationException ex ) {
+            throw new RuntimeException( "Error migrating Core Persistence", ex );
+        }
     }
 
 
-    @Override
-    public void setupStaticKeyspace() throws Exception {
-
-        migrate();
-
-        // Need this legacy stuff for queues
 
-        logger.info( "Creating static application keyspace {}", getApplicationKeyspace()
);
 
-        cass.createColumnFamily( getApplicationKeyspace(),
-            createColumnFamilyDefinition( getApplicationKeyspace(), APPLICATIONS_CF,
-                ComparatorType.BYTESTYPE ) );
-
-        cass.createColumnFamilies( getApplicationKeyspace(),
-            getCfDefs( ApplicationCF.class, getApplicationKeyspace() ) );
-
-        cass.createColumnFamilies( getApplicationKeyspace(),
-            getCfDefs( QueuesCF.class, getApplicationKeyspace() ) );
-
-    }
-
-
-    @Override
-    public boolean keyspacesExist() {
-        return true;
-    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/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 2431533..ff4f252 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
@@ -65,8 +65,6 @@ public class CassandraService {
 
     public static final boolean USE_VIRTUAL_KEYSPACES = true;
 
-    public static final String APPLICATIONS_CF = "Applications";
-    public static final String PROPERTIES_CF = "Properties";
     public static final String TOKENS_CF = "Tokens";
     public static final String PRINCIPAL_TOKEN_CF = "PrincipalTokens";
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/Setup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/Setup.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/Setup.java
index 2efbb62..697cd21 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/Setup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/Setup.java
@@ -16,39 +16,29 @@
 
 package org.apache.usergrid.persistence.cassandra;
 
-import java.util.UUID;
-
 public interface Setup {
 
     /**
-     * Initialize all configuration for the system setup. Creates keyspaces, and elasticsearch
indexes
+     * Initialize all configuration for the system setup. Creates keyspaces and elasticsearch
indexes
      * @throws Exception
      */
-    void initSubsystems() throws Exception;
+    void initSchema() throws Exception;
 
-    /**
-     * Setup the management keyspaces
-     * @throws Exception
-     */
-    void setupSystemKeyspace() throws Exception;
 
     /**
-     * Setup the application keyspaces
+     * Bootstrap the root application to allow the system to function.
      * @throws Exception
      */
-    void setupStaticKeyspace() throws Exception;
+    void initMgmtApp() throws Exception;
 
-    /**
-     * Returns true if both keyspaces exist
-     * @return
-     */
-    boolean keyspacesExist();
 
     /**
-     * Bootstrap the root application to allow the system to function.
+     *
+     * Separate interface for triggering the data migration to role new 2.x Migration classes
to the latest
+     *
      * @throws Exception
      */
-    void createDefaultApplications() throws Exception;
+    void runDataMigration() throws Exception;
+
 
-    void setupApplicationKeyspace( UUID applicationId, String appName ) throws Exception;
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/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 5f8f2f2..c6c2d26 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
@@ -48,7 +48,7 @@ public class CoreSchemaManager implements SchemaManager {
     @Override
     public void create() {
         try {
-            setup.initSubsystems();
+            setup.initSchema();
         }
         catch ( Exception ex ) {
             logger.error( "Could not setup usergrid core schema", ex );
@@ -58,18 +58,12 @@ public class CoreSchemaManager implements SchemaManager {
 
 
     @Override
-    public boolean exists() {
-        return setup.keyspacesExist();
-    }
-
-
-    @Override
     public void populateBaseData() {
         try {
 
-            setup.setupStaticKeyspace();
-            setup.setupSystemKeyspace();
-            setup.createDefaultApplications();
+            setup.initSchema();
+            setup.runDataMigration();
+            setup.initMgmtApp();
         }
 
         catch ( Exception ex ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/SchemaManager.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/SchemaManager.java
b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/SchemaManager.java
index d5e5f2f..7e87ba1 100644
--- a/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/SchemaManager.java
+++ b/stack/test-utils/src/main/java/org/apache/usergrid/cassandra/SchemaManager.java
@@ -23,9 +23,6 @@ public interface SchemaManager {
     /** Create any schema necessary for test execution. */
     void create();
 
-    /** @return true if the schema defined by this manager already exists */
-    boolean exists();
-
     /** Any breath-of-life data needed for the base system */
     void populateBaseData();
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/75eb278a/stack/test-utils/src/test/java/org/apache/usergrid/cassandra/FakeSchemaManager.java
----------------------------------------------------------------------
diff --git a/stack/test-utils/src/test/java/org/apache/usergrid/cassandra/FakeSchemaManager.java
b/stack/test-utils/src/test/java/org/apache/usergrid/cassandra/FakeSchemaManager.java
index bb6a933..cdbdc9f 100644
--- a/stack/test-utils/src/test/java/org/apache/usergrid/cassandra/FakeSchemaManager.java
+++ b/stack/test-utils/src/test/java/org/apache/usergrid/cassandra/FakeSchemaManager.java
@@ -23,13 +23,7 @@ public class FakeSchemaManager implements SchemaManager {
     public void create() {
 
     }
-
-
-    @Override
-    public boolean exists() {
-        return false;  //To change body of implemented methods use File | Settings | File
Templates.
-    }
-
+    
 
     @Override
     public void populateBaseData() {


Mime
View raw message