usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdun...@apache.org
Subject [40/44] usergrid git commit: Fixed bugs in migration of apps
Date Sat, 26 Sep 2015 01:42:45 GMT
Fixed bugs in migration of apps


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

Branch: refs/heads/USERGRID-933
Commit: 521fc03e556af47d110f0a7d98f2af215cb3fda1
Parents: 8281430
Author: Todd Nine <tnine@apigee.com>
Authored: Thu Sep 24 11:07:24 2015 -0600
Committer: Todd Nine <tnine@apigee.com>
Committed: Thu Sep 24 11:07:24 2015 -0600

----------------------------------------------------------------------
 .../management/AppInfoMigrationPlugin.java      | 47 +++++++++++---------
 1 file changed, 25 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/521fc03e/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java
b/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java
index 54779b9..d0f39e9 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/AppInfoMigrationPlugin.java
@@ -164,10 +164,18 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
                     throw new RuntimeException( e );
                 }
             }
-        } ).doOnCompleted( () -> {
-            migrationInfoSerialization.setVersion( getName(), getMaxVersion() );
-            observer.complete();
-        } ).toBlocking().lastOrDefault( null );
+        } )
+            //we want a doOnError to catch something going wrong, otherwise we'll mark as
complete
+            .doOnError( error -> {
+                logger.error( "Unable to migrate applications, an error occurred.  Please
try again", error );
+                observer.failed( getMaxVersion(), "Unable to migrate applications", error
);
+            } )
+
+                //if we complete successfully, set the version and notify the observer
+            .doOnCompleted( () -> {
+                migrationInfoSerialization.setVersion( getName(), getMaxVersion() );
+                observer.complete();
+            } ).subscribe();
     }
 
 
@@ -186,28 +194,23 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
             UUID applicationId = getUuid( oldAppInfoMap, "applicationUuid" );
             applicationId = applicationId == null ? getUuid( oldAppInfoMap, "appUuid" ) :
applicationId;
             //get app info from graph to see if it has been migrated already
-            org.apache.usergrid.persistence.Entity appInfo = getApplicationInfo( applicationId
);
-            if ( appInfo == null ) {
 
-                observer.update( getMaxVersion(), "Created application_info for " + appName
);
-                // create org->app connections, but not for apps in dummy "usergrid" internal
organization
-                if ( !orgName.equals( "usergrid" ) ) { //avoid management org
 
-                    EntityRef orgRef = managementEm.getAlias( Group.ENTITY_TYPE, orgName
);
-                    // create and connect new APPLICATION_INFO oldAppInfo to Organization
-                    managementService.createApplication( orgRef.getUuid(), name, applicationId,
null );
-                }
-            }
-            else {
-                //already migrated don't do anything
-                observer.update( getMaxVersion(),
-                    "Received existing application_info for " + appName + " don't do anything"
);
-            }
+
+            // create org->app connections, but not for apps in dummy "usergrid" internal
organization
+            //avoid management org
+
+            EntityRef orgRef = managementEm.getAlias( Group.ENTITY_TYPE, orgName );
+            // create and connect new APPLICATION_INFO oldAppInfo to Organization
+            managementService.createApplication( orgRef.getUuid(), name, applicationId, null
);
+
+            observer.update( getMaxVersion(), "Created application_info for " + appName );
+        }
+        //swallow
+        catch ( ApplicationAlreadyExistsException appExists ) {
+            logger.info( "Application {} already migrated.  Ignoring.", name );
         }
         catch ( Exception e ) {
-            String msg = "Exception writing application_info for " + name;
-            logger.error( msg, e );
-            observer.failed( getMaxVersion(), msg );
             throw new RuntimeException( e );
         }
     }


Mime
View raw message