usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject git commit: More complete implementation of EntityDeletedImpl, see the TODO item in there for next steps.
Date Mon, 20 Oct 2014 17:10:35 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-events cff9ee8c5 -> 6ca862fa5


More complete implementation of EntityDeletedImpl, see the TODO item in there for next steps.


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

Branch: refs/heads/two-dot-o-events
Commit: 6ca862fa56573061560d8bfdad273cf75f0bdc99
Parents: cff9ee8
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Mon Oct 20 13:10:17 2014 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Mon Oct 20 13:10:17 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 90 +++++++++----------
 .../events/EntityDeletedImpl.java               | 94 ++++++++++++++++++--
 2 files changed, 130 insertions(+), 54 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ca862fa/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 1ecf43d..b6e0745 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -86,10 +86,8 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_TYPE;
 import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
 import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 import static org.apache.usergrid.persistence.Schema.TYPE_ENTITY;
-import static org.apache.usergrid.persistence.Schema.getDefaultSchema;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import static org.apache.usergrid.persistence.SimpleEntityRef.getUuid;
-import static org.apache.usergrid.persistence.SimpleEntityRef.ref;
 import org.apache.usergrid.persistence.SimpleRoleRef;
 import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.cassandra.ApplicationCF;
@@ -131,7 +129,6 @@ import org.apache.usergrid.persistence.index.query.CounterResolution;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.index.query.Query.Level;
-import static org.apache.usergrid.persistence.index.query.Query.Level.REFS;
 import org.apache.usergrid.persistence.map.MapManager;
 import org.apache.usergrid.persistence.map.MapScope;
 import org.apache.usergrid.persistence.map.impl.MapScopeImpl;
@@ -140,7 +137,6 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.Field;
 import org.apache.usergrid.persistence.model.field.StringField;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.schema.CollectionInfo;
 import org.apache.usergrid.utils.ClassUtils;
 import static org.apache.usergrid.utils.ClassUtils.cast;
 import org.apache.usergrid.utils.CompositeUtils;
@@ -551,51 +547,47 @@ public class CpEntityManager implements EntityManager {
 
             // first, delete entity in every collection and connection scope in which it
is indexed 
 
-            RelationManager rm = getRelationManager( entityRef );
-            Map<String, Map<UUID, Set<String>>> owners = rm.getOwners();
-
-            logger.debug( "Deleting indexes of all {} collections owning the entity", 
-                    owners.keySet().size() );
-
-            final  EntityIndex ei = managerCache.getEntityIndex(getApplicationScope());
-
-            final EntityIndexBatch batch = ei.createBatch();
-
-
-
-            for ( String ownerType : owners.keySet() ) {
-                Map<UUID, Set<String>> collectionsByUuid = owners.get( ownerType
);
-
-                for ( UUID uuid : collectionsByUuid.keySet() ) {
-                    Set<String> collectionNames = collectionsByUuid.get( uuid );
-                    for ( String coll : collectionNames ) {
-
-                        IndexScope indexScope = new IndexScopeImpl(
-                                new SimpleId( uuid, ownerType ), 
-                                CpNamingUtils.getCollectionScopeNameFromCollectionName( coll
) );
-
-
-                        batch.index( indexScope, entity );
-                    }
-                }
-            }
-
-
-
-            // deindex from default index scope
-            IndexScope defaultIndexScope = new IndexScopeImpl(
-                    getApplicationScope().getApplication(),
-                    CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType()
) );
-
-            batch.deindex(defaultIndexScope,  entity );
-
-            IndexScope allTypesIndexScope = new IndexScopeImpl(
-                getApplicationScope().getApplication(), 
-                    CpNamingUtils.ALL_TYPES);
-
-            batch.deindex( allTypesIndexScope,  entity );
-
-            batch.execute();
+//            RelationManager rm = getRelationManager( entityRef );
+//            Map<String, Map<UUID, Set<String>>> owners = rm.getOwners();
+//
+//            logger.debug( "Deleting indexes of all {} collections owning the entity", 
+//                    owners.keySet().size() );
+//
+//            final  EntityIndex ei = managerCache.getEntityIndex(getApplicationScope());
+//
+//            final EntityIndexBatch batch = ei.createBatch();
+//
+//            for ( String ownerType : owners.keySet() ) {
+//                Map<UUID, Set<String>> collectionsByUuid = owners.get( ownerType
);
+//
+//                for ( UUID uuid : collectionsByUuid.keySet() ) {
+//                    Set<String> collectionNames = collectionsByUuid.get( uuid );
+//                    for ( String coll : collectionNames ) {
+//
+//                        IndexScope indexScope = new IndexScopeImpl(
+//                                new SimpleId( uuid, ownerType ), 
+//                                CpNamingUtils.getCollectionScopeNameFromCollectionName(
coll ) );
+//
+//
+//                        batch.index( indexScope, entity );
+//                    }
+//                }
+//            }
+//
+//            // deindex from default index scope
+//            IndexScope defaultIndexScope = new IndexScopeImpl(
+//                    getApplicationScope().getApplication(),
+//                    CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType()
) );
+//
+//            batch.deindex(defaultIndexScope,  entity );
+//
+//            IndexScope allTypesIndexScope = new IndexScopeImpl(
+//                getApplicationScope().getApplication(), 
+//                    CpNamingUtils.ALL_TYPES);
+//
+//            batch.deindex( allTypesIndexScope,  entity );
+//
+//            batch.execute();
 
             decrementEntityCollection( Schema.defaultCollectionName( entityId.getType() )
);
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6ca862fa/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
index befcc2e..bd21dc3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityDeletedImpl.java
@@ -18,6 +18,8 @@
 
 package org.apache.usergrid.corepersistence.events;
 
+import java.util.Map;
+import java.util.Set;
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.event.EntityDeleted;
 import org.apache.usergrid.persistence.index.EntityIndexBatch;
@@ -27,12 +29,24 @@ import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 
 import java.util.UUID;
+import org.apache.usergrid.corepersistence.CpEntityManager;
+import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.RelationManager;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
  * purge most current entity
  */
 public class EntityDeletedImpl implements EntityDeleted {
+    private static final Logger logger = LoggerFactory.getLogger( EntityDeletedImpl.class
);
 
     private final EntityIndexBatch entityIndex;
 
@@ -42,11 +56,81 @@ public class EntityDeletedImpl implements EntityDeleted {
 
     @Override
     public void deleted(CollectionScope scope, Id entityId, UUID version) {
-        IndexScope indexScope = new IndexScopeImpl(
-                new SimpleId(scope.getOwner().getUuid(),scope.getOwner().getType()),
-                scope.getName()
-        );
-        entityIndex.deindex(indexScope,entityId,version);
 
+        logger.debug("Entering deleted for entity {}:{} v {} "
+                + "scope\n   name: {}\n   owner: {}\n   app: {}",
+            new Object[] { entityId.getType(), entityId.getUuid(), version,
+                scope.getName(), scope.getOwner(), scope.getApplication()});
+
+
+        CpEntityManagerFactory emf = (CpEntityManagerFactory)
+                CpSetup.getInjector().getInstance( EntityManagerFactory.class );
+
+        CpEntityManager em = (CpEntityManager)
+                emf.getEntityManager( scope.getOwner().getUuid() );
+
+        EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(scope);
+
+
+        // TODO: change this so that it gets every version of the entity that 
+        // exists as we need to de-index each and every one of them
+
+        org.apache.usergrid.persistence.model.entity.Entity entity = 
+            ecm.load( entityId ).toBlocking().last();
+
+
+        SimpleEntityRef entityRef = new SimpleEntityRef( entityId.getType(), entityId.getUuid());
+
+        if ( entity != null ) {
+
+            // first, delete entity in every collection and connection scope in which it
is indexed 
+
+            RelationManager rm = em.getRelationManager( entityRef );
+            Map<String, Map<UUID, Set<String>>> owners = null;
+            try {
+                owners = rm.getOwners();
+
+                logger.debug( "Deleting indexes of all {} collections owning the entity {}:{}",

+                    new Object[] { owners.keySet().size(), entityId.getType(), entityId.getUuid()});
+
+                final EntityIndex ei = emf.getManagerCache().getEntityIndex(scope);
+
+                final EntityIndexBatch batch = ei.createBatch();
+
+                for ( String ownerType : owners.keySet() ) {
+                    Map<UUID, Set<String>> collectionsByUuid = owners.get( ownerType
);
+
+                    for ( UUID uuid : collectionsByUuid.keySet() ) {
+                        Set<String> collectionNames = collectionsByUuid.get( uuid );
+                        for ( String coll : collectionNames ) {
+
+                            IndexScope indexScope = new IndexScopeImpl(
+                                new SimpleId( uuid, ownerType ), 
+                                CpNamingUtils.getCollectionScopeNameFromCollectionName( coll
));
+
+                            batch.index( indexScope, entity );
+                        }
+                    }
+                }
+
+                // deindex from default index scope
+                IndexScope defaultIndexScope = new IndexScopeImpl( scope.getApplication(),
+                    CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType()));
+
+                batch.deindex(defaultIndexScope,  entity );
+
+                IndexScope allTypesIndexScope = new IndexScopeImpl(
+                    scope.getApplication(), CpNamingUtils.ALL_TYPES);
+
+                batch.deindex( allTypesIndexScope,  entity );
+
+                batch.execute();
+
+            } catch (Exception e) {
+                logger.error("Cannot deindex from owners of entity {}:{}", 
+                        entityId.getType(), entityId.getUuid());
+                logger.error("The exception", e);
+            }
+        }
     }
 }


Mime
View raw message