usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [29/50] incubator-usergrid git commit: fix restore issue, also don't use search
Date Mon, 13 Apr 2015 17:45:54 GMT
fix restore issue, also don't use search


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

Branch: refs/heads/USERGRID-536
Commit: 8856f05c8ff6d58d7dec680e8b184d3c0dc7be05
Parents: 06bcad6
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Apr 7 13:35:27 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Tue Apr 7 13:35:27 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/ApplicationIdCacheImpl.java | 11 ++--
 .../corepersistence/CpEntityManagerFactory.java | 25 ++++----
 .../corepersistence/CpRelationManager.java      |  2 +-
 .../events/EntityVersionDeletedHandler.java     |  2 +-
 .../cassandra/EntityManagerFactoryImplIT.java   | 65 ++++----------------
 5 files changed, 32 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8856f05c/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index 5f96b82..8fb4f6b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -89,7 +89,7 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
      */
     private UUID fetchApplicationId( final String applicationName ) {
 
-        final UUID value;
+        UUID value = null;
 
         EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
             new ApplicationScopeImpl(
@@ -110,9 +110,12 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
                 CpNamingUtils.APPLICATION_INFO, new StringField(Schema.PROPERTY_NAME, applicationName));
 
             Id id = idObs.toBlocking().lastOrDefault(null);
-            value = id.getUuid();
-
-            logger.debug("Loaded for key {} value {}", applicationName, value );
+            if(id != null) {
+                value = id.getUuid();
+                logger.debug("Loaded for key {} value {}", applicationName, value );
+            }else{
+                logger.debug("Could not load value for key {} ", applicationName );
+            }
             return value;
         }
         catch ( Exception e ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8856f05c/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 1be844d..3700003 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
@@ -326,8 +326,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             // make a copy of the app to delete application_info entity
             // and put it in a deleted_application_info collection
 
-            final Entity deletedApp = managementEm.create(
-                CpNamingUtils.DELETED_APPLICATION_INFO, appInfoToDelete.getProperties());
+            final Entity deletedApp = managementEm.create(new SimpleId(appInfoToDelete.getUuid(),
+                CpNamingUtils.DELETED_APPLICATION_INFO), appInfoToDelete.getProperties());
             // copy its connections too
 
             final Set<String> connectionTypes = managementEm.getConnectionTypes(appInfoToDelete);
@@ -369,36 +369,34 @@ public class CpEntityManagerFactory implements EntityManagerFactory,
Application
 
         // get the deleted_application_info for the deleted app
 
-        EntityManager em = getEntityManager(getManagementAppId());
+        final EntityManager managementEm = getEntityManager(getManagementAppId());
 
-        final Results results = em.searchCollection(
-            em.getApplicationRef(), CpNamingUtils.DELETED_APPLICATION_INFOS,
-            Query.fromQL("select * where " + PROPERTY_APPLICATION_ID + " = '" + applicationId.toString()
+ "'"));
-        Entity deletedAppInfo = results.getEntity();
+        final Entity deletedAppInfo = managementEm.get(new SimpleEntityRef(CpNamingUtils.DELETED_APPLICATION_INFO,applicationId));
 
         if ( deletedAppInfo == null ) {
             throw new EntityNotFoundException("Cannot restore. Deleted Application not found:
" + applicationId );
         }
 
+
         // create application_info for restored app
 
-        Entity restoredAppInfo = em.create(
-            deletedAppInfo.getUuid(), CpNamingUtils.APPLICATION_INFO, deletedAppInfo.getProperties());
+        Entity restoredAppInfo = managementEm.create(new SimpleId( deletedAppInfo.getUuid(),CpNamingUtils.APPLICATION_INFO)
+            , deletedAppInfo.getProperties());
 
         // copy connections from deleted app entity
 
-        final Set<String> connectionTypes = em.getConnectionTypes(deletedAppInfo);
+        final Set<String> connectionTypes = managementEm.getConnectionTypes(deletedAppInfo);
         for ( String connType : connectionTypes ) {
             final Results connResults =
-                em.getConnectedEntities(deletedAppInfo, connType, null, Query.Level.ALL_PROPERTIES);
+                managementEm.getConnectedEntities(deletedAppInfo, connType, null, Query.Level.ALL_PROPERTIES);
             for ( Entity entity : connResults.getEntities() ) {
-                em.createConnection( restoredAppInfo, connType, entity );
+                managementEm.createConnection( restoredAppInfo, connType, entity );
             }
         }
 
         // delete the deleted app entity rebuild the app index
+        managementEm.delete(deletedAppInfo);
 
-        em.delete(deletedAppInfo);
         entityIndex.refresh();
 
         this.rebuildApplicationIndexes(applicationId, new ProgressObserver() {
@@ -407,6 +405,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                 logger.info("Restored entity {}:{}", entity.getType(), entity.getUuid());
             }
         });
+        applicationIdCache.evictAppId(restoredAppInfo.getName());
 
         return restoredAppInfo;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8856f05c/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 e0bddad..67a1f19 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
@@ -242,7 +242,7 @@ public class CpRelationManager implements RelationManager {
         this.cpHeadEntity = ((CpEntityManager) em).load(entityId);
 
         // commented out because it is possible that CP entity has not been created yet
-        Assert.notNull(cpHeadEntity, "cpHeadEntity cannot be null for app id " + applicationScope.getApplication().getUuid());
+        Assert.notNull(cpHeadEntity, String.format("cpHeadEntity cannot be null for entity
id %s, app id %s" , entityId.getUuid(),applicationId));
 
         return this;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8856f05c/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
index a2e9b30..addf0bc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/events/EntityVersionDeletedHandler.java
@@ -124,7 +124,7 @@ public class EntityVersionDeletedHandler implements EntityVersionDeleted
{
 
 
         //execute the batches
-        batches.doOnNext( batch -> batch.execute() ).toBlocking().last();
+        batches.doOnNext( batch -> batch.execute() ).toBlocking().lastOrDefault(null);
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8856f05c/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index d3f2333..36d82be 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -141,6 +141,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         setup.getEmf().deleteApplication(deletedAppId);
         this.app.refreshIndex();
+        this.app.refreshIndex();
 
         // wait for it to appear in delete apps list
 
@@ -158,81 +159,37 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
                 return found;
             }
         };
-        this.app.refreshIndex();
 
-        boolean found = false;
-        for ( int i=0; i<maxRetries; i++) {
-            found = findApps.call( deletedAppId, emf.getDeletedApplications() );
-            if ( found ) {
-                break;
-            } else {
-                Thread.sleep( 500 );
-            }
-        }
-        assertTrue( "Deleted app must be found in in deleted apps collection", found );
-        this.app.refreshIndex();
+        boolean found = findApps.call( deletedAppId, emf.getDeletedApplications() );
+
+        assertTrue("Deleted app must be found in in deleted apps collection", found);
 
         // attempt to get entities in application's collections in various ways should all
fail
+        found =  setup.getEmf().lookupApplication( orgName + "/" + appName ) != null ;
 
-        for ( int i=0; i<maxRetries; i++ ) {
-            found = ( setup.getEmf().lookupApplication( orgName + "/" + appName ) != null
);
-            if ( found ) {
-                Thread.sleep( 500 );
-            } else {
-                break;
-            }
-        }
-        assertFalse( "Lookup of deleted app must fail", found );
+        assertFalse("Lookup of deleted app must fail", found);
 
         // app must not be found in apps collection
-        this.app.refreshIndex();
-
-        for ( int i=0; i<maxRetries; i++ ) {
-            found = findApps.call( deletedAppId, emf.getApplications() );
-            if ( found ) {
-                Thread.sleep( 500 );
-            } else {
-                break;
-            }
-        }
+        found = findApps.call( deletedAppId, emf.getApplications());
         assertFalse("Deleted app must not be found in apps collection", found);
 
         // restore the app
-
-        this.app.refreshIndex();
-
-
         emf.restoreApplication(deletedAppId);
-
         emf.rebuildAllIndexes(new EntityManagerFactory.ProgressObserver() {
             @Override
             public void onProgress(EntityRef entity) {
                 logger.debug("Reindexing {}:{}", entity.getType(), entity.getUuid());
             }
         });
+        this.app.refreshIndex();
 
         // test to see that app now works and is happy
 
         // it should not be found in the deleted apps collection
-        for ( int i=0; i<maxRetries; i++ ) {
-            found = findApps.call( deletedAppId, emf.getDeletedApplications() );
-            if ( !found ) {
-                break;
-            } else {
-                Thread.sleep( 500 );
-            }
-        }
+        found = findApps.call( deletedAppId, emf.getDeletedApplications());
         assertFalse("Restored app found in deleted apps collection", found);
-        this.app.refreshIndex();
-
-        for(int i=0;i<maxRetries;i++){
-            found = findApps.call(deletedAppId,setup.getEmf().getApplications());
-            if(!found){
-                break;
-            } else{
-                Thread.sleep(500);
-            }
-        }
+        Map<String,UUID> apps = setup.getEmf().getApplications();
+        found = findApps.call(deletedAppId, apps);
         assertTrue("Restored app not found in apps collection", found);
 
         // TODO: this assertion should work!


Mime
View raw message