You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/05/28 14:53:45 UTC

[40/50] [abbrv] incubator-usergrid git commit: implementing restore

implementing restore


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

Branch: refs/heads/USERGRID-669
Commit: 4f1b4be1333d693a800ee29562dd073f590fc2ec
Parents: 6ebf920
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed May 27 11:18:12 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed May 27 11:18:12 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 27 +++++++++++++-----
 .../corepersistence/index/ReIndexService.java   |  4 +--
 .../index/ReIndexServiceImpl.java               |  2 +-
 .../cassandra/EntityManagerFactoryImplIT.java   | 30 +++++++++++++++-----
 4 files changed, 46 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4f1b4be1/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 5b4af6d..a2306db 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
@@ -23,8 +23,10 @@ import java.util.Map;
 import java.util.Set;
 import java.util.TreeMap;
 import java.util.UUID;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
@@ -123,6 +125,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private CassandraService cassandraService;
     private CounterUtils counterUtils;
     private Injector injector;
+    private final ReIndexService reIndexService;
     private final EntityIndex entityIndex;
     private final MetricsFactory metricsFactory;
     private final AsyncEventService indexService;
@@ -135,6 +138,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.cassandraService = cassandraService;
         this.counterUtils = counterUtils;
         this.injector = injector;
+        this.reIndexService = injector.getInstance(ReIndexService.class);
         this.entityManagerFig = injector.getInstance(EntityManagerFig.class);
         this.entityIndex = injector.getInstance(EntityIndex.class);
         this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
@@ -317,19 +321,28 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
             .lastOrDefault(null);
     }
 
+    //TODO: return status for restore
     @Override
     public Entity restoreApplication(UUID applicationId) throws Exception {
 
         // get the deleted_application_info for the deleted app
-
-        final EntityManager managementEm = getEntityManager(getManagementAppId());
-
-        migrateAppInfo(applicationId,CpNamingUtils.DELETED_APPLICATION_INFO,CpNamingUtils.APPLICATION_INFO)
+        return (Entity) migrateAppInfo(applicationId, CpNamingUtils.DELETED_APPLICATION_INFO, CpNamingUtils.APPLICATION_INFO)
+            .map(o -> {
+                final ReIndexRequestBuilder builder =
+                    reIndexService.getBuilder().withApplicationId(applicationId);
+                return reIndexService.rebuildIndex(builder);
+            })
+            .map(status -> {
+                final EntityManager managementEm = getEntityManager(getManagementAppId());
+                try {
+                    return managementEm.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationId));
+                } catch (Exception e) {
+                    logger.error("Failed to get entity", e);
+                    throw new RuntimeException(e);
+                }
+            })
             .toBlocking().lastOrDefault(null);
 
-        throw new UnsupportedOperationException( "Implement index rebuild" );
-
-//        return managementEm.get(new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO,applicationId));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4f1b4be1/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexService.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexService.java
index bae8d1f..b9238e5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexService.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexService.java
@@ -51,7 +51,7 @@ public interface ReIndexService {
     /**
      * The response when requesting a re-index operation
      */
-    class ReIndexStatus {
+    public class ReIndexStatus {
         final String jobId;
         final Status status;
         final long numberProcessed;
@@ -103,6 +103,6 @@ public interface ReIndexService {
     }
 
     enum Status{
-        STARTED, INPROGRESS, COMPLETE;
+        STARTED, INPROGRESS, COMPLETE, UNKNOWN;
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4f1b4be1/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
index ef03866..957a29f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ReIndexServiceImpl.java
@@ -292,7 +292,7 @@ public class ReIndexServiceImpl implements ReIndexService {
         final String stringStatus = mapManager.getString( jobId+MAP_STATUS_KEY );
 
         if(stringStatus == null){
-            throw new IllegalArgumentException( "Could not find a job with id " + jobId );
+           return new ReIndexStatus( jobId, Status.UNKNOWN, 0, 0 );
         }
 
         final Status status = Status.valueOf( stringStatus );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4f1b4be1/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 2452606..c42e250 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
@@ -25,6 +25,10 @@ import java.util.UUID;
 
 import org.apache.usergrid.Application;
 import org.apache.usergrid.CoreApplication;
+import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilder;
+import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilderImpl;
+import org.apache.usergrid.corepersistence.index.ReIndexService;
+import org.apache.usergrid.corepersistence.index.ReIndexServiceImpl;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.utils.UUIDUtils;
 import org.junit.*;
@@ -107,6 +111,7 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
     @Test
     public void testDeleteApplication() throws Exception {
+        ReIndexService reIndexService = setup.getInjector().getInstance( ReIndexService.class );
 
         int maxRetries = 10;
 
@@ -177,13 +182,22 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
 
         // restore the app
         emf.restoreApplication(deletedAppId);
-        fail( "Implement index rebuild" );
-//        emf.rebuildAllIndexes(new EntityManagerFactory.ProgressObserver() {
-//            @Override
-//            public void onProgress(EntityRef entity) {
-//                logger.debug("Reindexing {}:{}", entity.getType(), entity.getUuid());
-//            }
-//        });
+        final ReIndexRequestBuilder builder =
+            reIndexService.getBuilder().withApplicationId( deletedAppId );
+
+        ReIndexService.ReIndexStatus status = reIndexService.rebuildIndex(builder);
+        int count = 0;
+        do{
+            status = reIndexService.getStatus(status.getJobId());
+            count++;
+            if(count>0){
+                if(count>10){
+                    break;
+                }
+                Thread.sleep(1000);
+            }
+        }while (status.getStatus()!= ReIndexService.Status.COMPLETE);
+
         this.app.refreshIndex();
 
         // test to see that app now works and is happy
@@ -191,6 +205,8 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
         // it should not be found in the deleted apps collection
         found = findApps.call( deletedAppId, emf.getDeletedApplications());
         assertFalse("Restored app found in deleted apps collection", found);
+        this.app.refreshIndex();
+
         Map<String,UUID> apps = setup.getEmf().getApplications();
         found = findApps.call(deletedAppId, apps);
         assertTrue("Restored app not found in apps collection", found);