usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject incubator-usergrid git commit: adding new route for migration
Date Tue, 11 Aug 2015 20:33:56 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-908 [created] 2ec1d237d


adding new route for migration


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

Branch: refs/heads/USERGRID-908
Commit: 2ec1d237dc51f5a2a6dd62a86b0e3109e6905e88
Parents: f71be80
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Aug 11 14:33:45 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Tue Aug 11 14:33:45 2015 -0600

----------------------------------------------------------------------
 .../migration/data/DataMigrationManager.java    |  6 ++-
 .../data/DataMigrationManagerImpl.java          | 15 +++++++
 .../data/DataMigrationManagerImplTest.java      | 42 +++++++++++++++++++
 .../apache/usergrid/rest/MigrateResource.java   | 43 +++++++++++++++++---
 4 files changed, 99 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ec1d237/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManager.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManager.java
index 7ddc6e1..3e24e6b 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManager.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManager.java
@@ -35,7 +35,11 @@ public interface DataMigrationManager {
      * not exist
      */
     public void migrate() throws MigrationException;
-
+    /**
+     * Perform any migration necessary in the application.  Will only create keyspaces and
column families if they do
+     * not exist
+     */
+    public void migrate(final String name) throws MigrationException;
     /**
      * Returns true if a migration is running.  False otherwise
      * @return

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ec1d237/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
index 5d41abe..ecf271a 100644
--- a/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
+++ b/stack/corepersistence/common/src/main/java/org/apache/usergrid/persistence/core/migration/data/DataMigrationManagerImpl.java
@@ -96,6 +96,21 @@ public class DataMigrationManagerImpl implements DataMigrationManager {
 
 
     @Override
+    public void migrate(final String name) throws MigrationException {
+        /**
+         * Invoke each plugin to attempt a migration
+         */
+        final MigrationPlugin plugin = migrationPlugins.get( name );
+        if(plugin != null){
+            final ProgressObserver observer = new CassandraProgressObserver(plugin.getName());
+            plugin.run(observer);
+            migrationInfoCache.invalidateAll();
+        }else {
+            throw new IllegalArgumentException(name + " does not match a current plugin.");
+        }
+    }
+
+    @Override
     public void migrate() throws MigrationException {
 
         /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ec1d237/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 e942be1..2012191 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
@@ -106,6 +106,48 @@ public class DataMigrationManagerImplTest {
     }
 
     @Test
+    public void testPluginByName() throws MigrationException {
+
+        final Set<MigrationPlugin> plugins = new HashSet<>();
+
+        MigrationPlugin plugin1 = mock( MigrationPlugin.class );
+        when( plugin1.getPhase() ).thenReturn( PluginPhase.MIGRATE );
+
+        when( plugin1.getName() ).thenReturn( "plugin1" );
+
+        MigrationPlugin plugin2 = mock( MigrationPlugin.class );
+        when( plugin2.getPhase() ).thenReturn( PluginPhase.MIGRATE );
+
+        when( plugin2.getName() ).thenReturn( "plugin2" );
+
+        plugins.add( plugin1 );
+        plugins.add( plugin2 );
+
+
+        final MigrationInfoSerialization migrationInfoSerialization = mock( MigrationInfoSerialization.class
);
+        final MigrationInfoCache migrationInfoCache = mock(MigrationInfoCache.class);
+
+
+        DataMigrationManagerImpl migrationManager = new DataMigrationManagerImpl( plugins,
migrationInfoSerialization,migrationInfoCache );
+
+
+        Set<String> pluginNames = migrationManager.getPluginNames();
+
+        assertEquals(2, pluginNames.size());
+
+        assertTrue( pluginNames.contains( "plugin1" ) );
+
+        assertTrue(pluginNames.contains("plugin2"));
+
+        //now run them
+
+        migrationManager.migrate("plugin1");
+
+        verify( plugin1 ).run(any(ProgressObserver.class));
+
+    }
+
+    @Test
       public void test2PluginsPhaseOrder() throws MigrationException {
 
         final Set<MigrationPlugin> plugins = new HashSet<>();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2ec1d237/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 da0ba0f..dad74f4 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
@@ -22,12 +22,7 @@ package org.apache.usergrid.rest;
 import java.util.Map;
 import java.util.Set;
 
-import javax.ws.rs.DefaultValue;
-import javax.ws.rs.GET;
-import javax.ws.rs.PUT;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
+import javax.ws.rs.*;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
@@ -116,6 +111,42 @@ public class MigrateResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
+    @RequireSystemAccess
+    @PUT
+    @Path( "run/{pluginName}" )
+    public JSONWithPadding migrateData(@PathParam("pluginName") String pluginName ,  @Context
UriInfo ui,
+                                        @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+        throws Exception {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "Migrate Data: "+ pluginName );
+        //TODO make this use the task scheduler
+
+
+        final Thread migrate = new Thread() {
+
+            @Override
+            public void run() {
+
+                logger.info( "Migrating Data for plugin: " + pluginName );
+
+                try {
+                    getDataMigrationManager().migrate(pluginName);
+                }
+                catch ( Exception e ) {
+                    logger.error( "Unable to migrate data for plugin: " + pluginName, e );
+                }
+            }
+        };
+
+        migrate.setName( "Index migrate data formats: "+pluginName );
+        migrate.setDaemon( true );
+        migrate.start();
+
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+    }
 
     @RequireSystemAccess
     @PUT


Mime
View raw message