usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [1/2] git commit: Added tests to forked thread for background processing.
Date Fri, 03 Oct 2014 19:01:44 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/essingledocument [created] 545619225


Added tests to forked thread for background processing.


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

Branch: refs/heads/essingledocument
Commit: 230870be215eb09add1c34383522798dc33324b2
Parents: deaa46c
Author: Todd Nine <toddnine@apache.org>
Authored: Thu Oct 2 15:35:03 2014 -0600
Committer: Todd Nine <toddnine@apache.org>
Committed: Thu Oct 2 15:35:03 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/rest/SystemResource.java    | 67 +++++++++++++++-----
 1 file changed, 52 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/230870be/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
index 9a67032..b037b96 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
@@ -122,7 +122,7 @@ public class SystemResource extends AbstractContextResource {
         response.setAction( "rebuild indexes" );
 
 
-        EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
+        final EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
             @Override
             public void onProgress( EntityRef s, EntityRef t, String etype ) {
                 logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
@@ -132,12 +132,27 @@ public class SystemResource extends AbstractContextResource {
         };
 
 
-        logger.info( "Rebuilding all indexes" );
+        final Thread rebuild = new Thread() {
 
-        emf.rebuildInternalIndexes( po );
-        emf.refreshIndex();
+            @Override
+            public void run() {
+                logger.info( "Rebuilding all indexes" );
+
+                try {
+                    emf.rebuildInternalIndexes( po );
+                    emf.refreshIndex();
+
+                    emf.rebuildAllIndexes( po );
+                }
+                catch ( Exception e ) {
+                    logger.error( "Unable to rebuild indexes", e );
+                }
+            }
+        };
 
-        emf.rebuildAllIndexes( po );
+        rebuild.setName( "Index rebuild all usergrid" );
+        rebuild.setDaemon( true );
+        rebuild.start();
 
 
         response.setSuccess();
@@ -148,7 +163,7 @@ public class SystemResource extends AbstractContextResource {
 
     @RequireSystemAccess
     @PUT
-    @Path( "index/rebuild/" + RootResource.APPLICATION_ID_PATH  )
+    @Path( "index/rebuild/" + RootResource.APPLICATION_ID_PATH )
     public JSONWithPadding rebuildIndexes( @Context UriInfo ui, @PathParam( "applicationId"
) String applicationIdStr,
                                            @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
             throws Exception {
@@ -158,7 +173,7 @@ public class SystemResource extends AbstractContextResource {
         response.setAction( "rebuild indexes" );
 
 
-        EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
+        final EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
             @Override
             public void onProgress( EntityRef s, EntityRef t, String etype ) {
                 logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
@@ -168,16 +183,27 @@ public class SystemResource extends AbstractContextResource {
         };
 
 
-        EntityManager em = emf.getEntityManager( appId );
+        final EntityManager em = emf.getEntityManager( appId );
 
-        Set<String> collectionNames = em.getApplicationCollections();
+        final Set<String> collectionNames = em.getApplicationCollections();
 
+        final Thread rebuild = new Thread() {
 
-        for(String collectionName: collectionNames){
-            rebuildCollection(appId, collectionName);
-        }
+            @Override
+            public void run() {
+                for ( String collectionName : collectionNames )
 
 
+                {
+                    rebuildCollection( appId, collectionName );
+                }
+            }
+        };
+
+        rebuild.setName( String.format( "Index rebuild for app %s", appId ) );
+        rebuild.setDaemon( true );
+        rebuild.start();
+
         response.setSuccess();
 
         return new JSONWithPadding( response, callback );
@@ -187,8 +213,9 @@ public class SystemResource extends AbstractContextResource {
     @RequireSystemAccess
     @PUT
     @Path( "index/rebuild/" + RootResource.APPLICATION_ID_PATH + "/{collectionName}" )
-    public JSONWithPadding rebuildIndexes( @Context UriInfo ui, @PathParam( "applicationId"
) String applicationIdStr,
-                                           @PathParam( "collectionName" ) String collectionName,
+    public JSONWithPadding rebuildIndexes( @Context UriInfo ui,
+                                           @PathParam( "applicationId" ) final String applicationIdStr,
+                                           @PathParam( "collectionName" ) final String collectionName,
                                            @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
             throws Exception {
 
@@ -196,7 +223,17 @@ public class SystemResource extends AbstractContextResource {
         ApiResponse response = createApiResponse();
         response.setAction( "rebuild indexes" );
 
-        rebuildCollection( appId, collectionName );
+        final Thread rebuild = new Thread() {
+
+            public void run() {
+
+                rebuildCollection( appId, collectionName );
+            }
+        };
+
+        rebuild.setName( String.format( "Index rebuild for app %s and collection %s", appId,
collectionName ) );
+        rebuild.setDaemon( true );
+        rebuild.start();
 
         response.setSuccess();
 


Mime
View raw message