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/06/11 00:29:32 UTC

[1/2] incubator-usergrid git commit: Fixes bugs in migration with edge existence checks

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-dev d66402d2f -> c93a0fcc0


Fixes bugs in migration with edge existence checks

Fixes bug in test assertion for incorrect count

Fixes bug with indexing on adding to collection


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

Branch: refs/heads/two-dot-o-dev
Commit: c81d21c6bc89f25537155e9a0c33ab825b150600
Parents: daedb92
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Jun 10 16:24:09 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Jun 10 16:24:09 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 28 ++++---------------
 .../migration/AppInfoMigrationPlugin.java       | 14 +++++-----
 .../migration/AppInfoMigrationPluginTest.java   | 29 +++++++++++++++++---
 3 files changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c81d21c6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 9e2c0bf..2445699 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -83,6 +83,7 @@ import rx.functions.Func1;
 
 import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createCollectionEdge;
 import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createCollectionSearchEdge;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createConnectionEdge;
 import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createConnectionSearchByEdge;
 import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createSearchEdgeFromSource;
 import static org.apache.usergrid.corepersistence.util.CpNamingUtils.generateScopeFromSource;
@@ -688,33 +689,16 @@ public class CpRelationManager implements RelationManager {
             } );
         }
 
-        Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() );
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity = ( ( CpEntityManager ) em ).load( entityId );
-
-        String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
+        final Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() );
+        final org.apache.usergrid.persistence.model.entity.Entity targetEntity = ( ( CpEntityManager ) em ).load( entityId );
 
         // create graph edge connection from head entity to member entity
-        Edge edge = new SimpleEdge( cpHeadEntity.getId(), edgeType, targetEntity.getId(), System.currentTimeMillis() );
+        final Edge edge = createConnectionEdge( cpHeadEntity.getId(), connectionType, targetEntity.getId() );
 
-        GraphManager gm = managerCache.getGraphManager( applicationScope );
+        final GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.writeEdge( edge ).toBlocking().last();
 
-        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
-        EntityIndexBatch batch = ei.createBatch();
-
-        // Index the new connection in app|source|type context
-        IndexEdge edgeIndex = generateScopeFromSource( edge );
-
-        batch.index( edgeIndex, targetEntity );
-
-        batch.execute();
-
-        // Index the new connection in app|scope|all-types context
-        //TODO REMOVE INDEX CODE
-        //        IndexScope allTypesIndexScope = new IndexScopeImpl( cpHeadEntity.getId(), CpNamingUtils.ALL_TYPES,
-        // entityType );
-        //        batch.index( allTypesIndexScope, targetEntity );
-
+        indexService.queueNewEdge( applicationScope, targetEntity, edge );
 
         return connection;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c81d21c6/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
index 97b87b3..8f18ba3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPlugin.java
@@ -36,6 +36,7 @@ import org.apache.usergrid.persistence.graph.Edge;
 import org.apache.usergrid.persistence.graph.GraphManager;
 import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
 import org.apache.usergrid.persistence.model.entity.*;
 import org.apache.usergrid.utils.UUIDUtils;
@@ -211,7 +212,7 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
         final ApplicationScope managementAppScope = getApplicationScope(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
         final EntityCollectionManager managementCollectionManager = entityCollectionManagerFactory.createCollectionManager(managementAppScope);
 
-        Observable<Edge> edgesObservable = getApplicationInfoEdges();
+        Observable<Edge> edgesObservable = getApplicationInfoEdges(appId);
         //get the graph for all app infos
         Observable<org.apache.usergrid.persistence.model.entity.Entity> entityObs =
                 edgesObservable.flatMap(edge -> {
@@ -275,18 +276,17 @@ public class AppInfoMigrationPlugin implements MigrationPlugin {
         return entityObs;
     }
 
-    Observable<Edge> edgesObservable;
-    public Observable<Edge> getApplicationInfoEdges() {
+    public Observable<Edge> getApplicationInfoEdges(final UUID applicationId) {
         final ApplicationScope managementAppScope = getApplicationScope(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
         final GraphManager gm = graphManagerFactory.createEdgeManager(managementAppScope);
 
         String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(CpNamingUtils.APPLICATION_INFOS);
 
 
-        final SimpleSearchByEdgeType simpleSearchByEdgeType =  new SimpleSearchByEdgeType(
-            CpNamingUtils.generateApplicationId(CpNamingUtils.MANAGEMENT_APPLICATION_ID), edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
+        final SimpleSearchByEdge simpleSearchByEdgeType =  new SimpleSearchByEdge(
+            CpNamingUtils.generateApplicationId(CpNamingUtils.MANAGEMENT_APPLICATION_ID), edgeType, CpNamingUtils.generateApplicationId( applicationId ), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
             Optional.absent());
-        edgesObservable = edgesObservable !=null ? edgesObservable : gm.loadEdgesFromSource( simpleSearchByEdgeType );
-        return edgesObservable;
+
+        return gm.loadEdgeVersions(simpleSearchByEdgeType  );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c81d21c6/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
index 0fd1e52..f242318 100644
--- a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
@@ -31,8 +31,13 @@ import org.apache.usergrid.persistence.cassandra.CassandraService;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
 import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.graph.GraphManager;
 import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
+
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
@@ -43,10 +48,16 @@ import rx.Observable;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.UUID;
 
 import static org.apache.usergrid.TestHelper.*;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.createCollectionSearchEdge;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.generateApplicationId;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getApplicationScope;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getEdgeTypeFromCollectionName;
 import static org.junit.Assert.*;
 
 
@@ -86,6 +97,9 @@ public class AppInfoMigrationPluginTest {
 
         List<UUID> appIds = new ArrayList<>();
 
+        /***
+         * Create all 10 apps in the new format
+         */
         for ( int i=0; i<10; i++ ) {
 
             UUID appId = setup.getMgmtSvc().createApplication(
@@ -121,6 +135,11 @@ public class AppInfoMigrationPluginTest {
         EntityManager systemAppEm = setup.getEmf().getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
 
         int count = 0;
+
+        /**
+         * Now to ensure the process is idempotent, we "move" half of our app infos into the old system and remove them.
+         * Once they're migrated, we should get all 10
+         */
         for ( UUID appId : appIds ) {
 
             final Entity applicationInfo = getApplicationInfo( appId );
@@ -151,7 +170,7 @@ public class AppInfoMigrationPluginTest {
 
         // test that applications are now broken
 
-        checkApplicationsBroken(orgName, deletedApps);
+        checkApplicationsBroken(deletedApps);
 
         // run the migration, which should restore the application_info entities
 
@@ -173,15 +192,17 @@ public class AppInfoMigrationPluginTest {
 
         final Results applicationInfoResults =  rootEm.searchCollection(
             new SimpleEntityRef("application", mgmtAppId), "application_infos", Query.fromQL("select *"));
-        int appCount =  Observable.from(applicationInfoResults.getEntities()).filter(entity -> !entity.getName().startsWith("org.") && !entity.getName().startsWith("usergrid")).toList().toBlocking().last().size();
-        assertEquals( appIds.size() - deletedApps.size(),appCount );
+        int appCount =  Observable.from( applicationInfoResults.getEntities() ).filter(
+            entity -> !entity.getName().startsWith( "org." ) && !entity.getName().startsWith( "usergrid" ) ).doOnNext(
+            entity -> logger.info("counting entity {}", entity) ).count().toBlocking().last();
+        assertEquals( appIds.size() ,appCount );
 
         // test that 10 applications are no longer broken
 
         checkApplicationsOk( orgName );
     }
 
-    private void checkApplicationsBroken( String orgName, List<Entity> deletedApps ) throws Exception {
+    private void checkApplicationsBroken( List<Entity> deletedApps ) throws Exception {
 
         logger.debug("\n\nChecking applications broken\n");
 


[2/2] incubator-usergrid git commit: Merge commit 'c81d21c6bc89f25537155e9a0c33ab825b150600' into two-dot-o-dev

Posted by gr...@apache.org.
Merge commit 'c81d21c6bc89f25537155e9a0c33ab825b150600' into two-dot-o-dev

* commit 'c81d21c6bc89f25537155e9a0c33ab825b150600':
  Fixes bugs in migration with edge existence checks


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

Branch: refs/heads/two-dot-o-dev
Commit: c93a0fcc0bd9bc762fb6f699405b35b1f2d25cfe
Parents: d66402d c81d21c
Author: GERey <gr...@apigee.com>
Authored: Wed Jun 10 15:29:24 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Jun 10 15:29:24 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 28 ++++---------------
 .../migration/AppInfoMigrationPlugin.java       | 14 +++++-----
 .../migration/AppInfoMigrationPluginTest.java   | 29 +++++++++++++++++---
 3 files changed, 38 insertions(+), 33 deletions(-)
----------------------------------------------------------------------