usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [1/3] incubator-usergrid git commit: WIP overwrite
Date Mon, 09 Mar 2015 20:56:13 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-405 b6351134e -> 1eca2718d


WIP overwrite


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

Branch: refs/heads/USERGRID-405
Commit: ade9714955600c9f23198ad18ff5d23d960b216d
Parents: 0c3b439
Author: Todd Nine <tnine@apigee.com>
Authored: Sun Mar 8 16:53:32 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Sun Mar 8 16:53:32 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 36 +-------------
 .../persistence/EntityManagerFactory.java       | 20 --------
 .../cassandra/EntityManagerFactoryImpl.java     | 23 ---------
 .../data/DataMigrationManagerImplTest.java      | 34 +++++++++++--
 .../apache/usergrid/rest/MigrateResource.java   | 52 +++++++++++++-------
 5 files changed, 63 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ade97149/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 3b39bc9..8a1b0c4 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
@@ -109,7 +109,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private ManagerCache managerCache;
 
 
-    private DataMigrationManager dataMigrationManager;
+
 
     private CassandraService cassandraService;
     private CounterUtils counterUtils;
@@ -123,9 +123,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.counterUtils = counterUtils;
         this.injector = injector;
         this.managerCache = injector.getInstance( ManagerCache.class );
-        this.dataMigrationManager = injector.getInstance( DataMigrationManager.class );
-
-
     }
 
 
@@ -165,8 +162,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
         if ( managerCache == null ) {
             managerCache = injector.getInstance( ManagerCache.class );
-
-            dataMigrationManager = injector.getInstance( DataMigrationManager.class );
         }
         return managerCache;
     }
@@ -779,35 +774,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
     }
 
 
-    @Override
-    public void migrateData() throws Exception {
-         dataMigrationManager.migrate();
-    }
-
-
-    @Override
-    public String getMigrateDataStatus() {
-    //TODO  USERGRID-405      return dataMigrationManager.getLastStatus();
-        return null;
-    }
-
-
-    @Override
-    public int getMigrateDataVersion() {
-        //TODO USERGRID-405
-        //return dataMigrationManager.getCurrentVersion();
-        return 0;
-    }
-
-
-    @Override
-    public void setMigrationVersion( final int version ) {
-        //TODO USERGRID-405
-//
-//        dataMigrationManager.resetToVersion( version );
-//        dataMigrationManager.invalidate();
-    }
-
 
     @Override
     public void flushEntityManagerCaches() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ade97149/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 880fe89..f706ac1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -127,26 +127,6 @@ public interface EntityManagerFactory {
 
     public void rebuildApplicationIndexes( UUID appId, ProgressObserver po ) throws Exception;
 
-    /**
-     * Perform any data migrations necessary in the system
-     * @throws Exception
-     */
-    public void migrateData() throws Exception;
-
-    /**
-     * Return the migration status message
-     */
-    public String getMigrateDataStatus();
-
-    /**
-     * Return the current migration version of the system
-     */
-    public int getMigrateDataVersion();
-
-    /**
-     * Force the migration version to the specified version
-     */
-    public void setMigrationVersion(int version);
 
     /**
      * Perform a realtime count of every entity in the system.  This can be slow as it traverses
the entire system graph

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ade97149/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 af1eabc..7b55e5b 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
@@ -443,29 +443,6 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory,
Applicati
 
 
     @Override
-    public void migrateData() throws Exception {
-
-    }
-
-
-    @Override
-    public String getMigrateDataStatus() {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-
-    @Override
-    public int getMigrateDataVersion() {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-
-    @Override
-    public void setMigrationVersion( final int version ) {
-        throw new UnsupportedOperationException("Not supported in v1");
-    }
-
-    @Override
     public void addIndex(UUID appId, String suffix,final int shards,final int replicas,final
String consistency) {
         throw new UnsupportedOperationException("Not supported in v1");
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ade97149/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImplTest.java
b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImplTest.java
index 319282c..c2eef3f 100644
--- a/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImplTest.java
+++ b/stack/corepersistence/common/src/test/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImplTest.java
@@ -299,12 +299,36 @@ public class DataMigrationManagerImplTest {
 
     @Test
     public void testLastStatus() {
-        fail( "writeme" );
-    }
 
+        final String name = "plugin1";
+        final String status = "some status";
 
-    @Test
-    public void testLastStatusNoPlugin() {
-        fail( "writeme" );
+        //linked hash set is intentional here.  For iteration order we can boostrap to come
second so we can
+        //verify it was actually run first
+        final Set<MigrationPlugin> plugins = new LinkedHashSet<>();
+
+        MigrationPlugin plugin1 = mock( MigrationPlugin.class );
+        when( plugin1.getPhase() ).thenReturn( PluginPhase.MIGRATE );
+
+
+        when( plugin1.getName() ).thenReturn( name );
+
+
+
+        plugins.add( plugin1 );
+
+
+        final MigrationInfoSerialization migrationInfoSerialization = mock( MigrationInfoSerialization.class
);
+        when(migrationInfoSerialization.getStatusMessage( name )).thenReturn( status  );
+
+
+        DataMigrationManagerImpl migrationManager = new DataMigrationManagerImpl( plugins,
migrationInfoSerialization );
+
+        final String returnedStatus = migrationManager.getLastStatus( name );
+
+
+        assertEquals(status, returnedStatus);
     }
+
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ade97149/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
index 9ab5dc3..702d134 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/MigrateResource.java
@@ -33,22 +33,25 @@ import javax.ws.rs.core.UriInfo;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
+import org.apache.usergrid.persistence.core.migration.schema.MigrationManager;
 import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 
 import com.fasterxml.jackson.databind.node.JsonNodeFactory;
 import com.fasterxml.jackson.databind.node.ObjectNode;
 import com.google.common.base.Preconditions;
+import com.google.inject.Injector;
 import com.sun.jersey.api.json.JSONWithPadding;
 
 
 @Component
 @Scope( "singleton" )
 @Produces( {
-        MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript",
"text/ecmascript",
-        "application/ecmascript", "text/jscript"
+    MediaType.APPLICATION_JSON, "application/javascript", "application/x-javascript", "text/ecmascript",
+    "application/ecmascript", "text/jscript"
 } )
 public class MigrateResource extends AbstractContextResource {
 
@@ -59,6 +62,8 @@ public class MigrateResource extends AbstractContextResource {
         logger.info( "SystemResource initialized" );
     }
 
+    @Autowired
+    private Injector guiceInjector;
 
 
     @RequireSystemAccess
@@ -66,13 +71,15 @@ public class MigrateResource extends AbstractContextResource {
     @Path( "run" )
     public JSONWithPadding migrateData( @Context UriInfo ui,
                                         @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-            throws Exception {
+        throws Exception {
 
         ApiResponse response = createApiResponse();
         response.setAction( "Migrate Data" );
         //TODO make this use the task scheduler
 
 
+
+
         final Thread migrate = new Thread() {
 
             @Override
@@ -80,7 +87,7 @@ public class MigrateResource extends AbstractContextResource {
                 logger.info( "Migrating Data " );
 
                 try {
-                    emf.migrateData();
+                    getMigrationManager().migrate();
                 }
                 catch ( Exception e ) {
                     logger.error( "Unable to migrate data", e );
@@ -99,21 +106,24 @@ public class MigrateResource extends AbstractContextResource {
     }
 
 
+
     @RequireSystemAccess
     @PUT
     @Path( "set" )
     public JSONWithPadding setMigrationVersion( @Context UriInfo ui, Map<String, Object>
json,
                                                 @QueryParam( "callback" ) @DefaultValue(
"" ) String callback )
-            throws Exception {
+        throws Exception {
 
         logger.debug( "newOrganization" );
 
         Preconditions.checkNotNull( json, "You must provide a json body" );
 
+        Preconditions.checke
+
         String version = ( String ) json.get( "version" );
 
-        Preconditions.checkArgument( version != null && version.length() > 0,
-                "You must specify a version field in your json" );
+        Preconditions
+            .checkArgument( version != null && version.length() > 0, "You must
specify a version field in your json" );
 
 
         int intVersion = Integer.parseInt( version );
@@ -130,7 +140,7 @@ public class MigrateResource extends AbstractContextResource {
     @Path( "status" )
     public JSONWithPadding migrateStatus( @Context UriInfo ui,
                                           @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-            throws Exception {
+        throws Exception {
 
         ApiResponse response = createApiResponse();
         response.setAction( "Migrate Schema indexes" );
@@ -145,21 +155,25 @@ public class MigrateResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
+
     @RequireSystemAccess
-       @GET
-       @Path( "count" )
-       public JSONWithPadding migrateCount( @Context UriInfo ui,
-                                             @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
-               throws Exception {
+    @GET
+    @Path( "count" )
+    public JSONWithPadding migrateCount( @Context UriInfo ui,
+                                         @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
 
-           ApiResponse response = createApiResponse();
-           response.setAction( "Current entity count in system" );
+        ApiResponse response = createApiResponse();
+        response.setAction( "Current entity count in system" );
 
-           response.setProperty( "count", emf.performEntityCount()  );
+        response.setProperty( "count", emf.performEntityCount() );
 
-           response.setSuccess();
+        response.setSuccess();
 
-           return new JSONWithPadding( response, callback );
-       }
+        return new JSONWithPadding( response, callback );
+    }
 
+    private MigrationManager getMigrationManager(){
+        return guiceInjector.getInstance( MigrationManager.class );
+    }
 }


Mime
View raw message