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 re-index to SystemResource
Date Thu, 02 Oct 2014 20:49:48 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o 8930071fc -> deaa46c3a


Added re-index to SystemResource


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

Branch: refs/heads/two-dot-o
Commit: 7b63338013bc67ad27753d7c4a10caf1369def4a
Parents: b644cc0
Author: Todd Nine <toddnine@apache.org>
Authored: Thu Oct 2 14:48:51 2014 -0600
Committer: Todd Nine <toddnine@apache.org>
Committed: Thu Oct 2 14:48:51 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/rest/SystemResource.java    | 120 +++++++++++++++++++
 1 file changed, 120 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b633380/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 952574d..9a67032 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
@@ -17,9 +17,14 @@
 package org.apache.usergrid.rest;
 
 
+import java.util.Set;
+import java.util.UUID;
+
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.Context;
@@ -31,6 +36,10 @@ import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Component;
 
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
 
 import com.sun.jersey.api.json.JSONWithPadding;
@@ -100,4 +109,115 @@ public class SystemResource extends AbstractContextResource {
 
         return new JSONWithPadding( response, callback );
     }
+
+
+    @RequireSystemAccess
+    @PUT
+    @Path( "index/rebuild" )
+    public JSONWithPadding rebuildIndexes( @Context UriInfo ui,
+                                           @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+            throws Exception {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "rebuild indexes" );
+
+
+        EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
+            @Override
+            public void onProgress( EntityRef s, EntityRef t, String etype ) {
+                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
+                        s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype
+                } );
+            }
+        };
+
+
+        logger.info( "Rebuilding all indexes" );
+
+        emf.rebuildInternalIndexes( po );
+        emf.refreshIndex();
+
+        emf.rebuildAllIndexes( po );
+
+
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+    }
+
+
+    @RequireSystemAccess
+    @PUT
+    @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 {
+
+        final UUID appId = UUIDUtils.tryExtractUUID( applicationIdStr );
+        ApiResponse response = createApiResponse();
+        response.setAction( "rebuild indexes" );
+
+
+        EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
+            @Override
+            public void onProgress( EntityRef s, EntityRef t, String etype ) {
+                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
+                        s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype
+                } );
+            }
+        };
+
+
+        EntityManager em = emf.getEntityManager( appId );
+
+        Set<String> collectionNames = em.getApplicationCollections();
+
+
+        for(String collectionName: collectionNames){
+            rebuildCollection(appId, collectionName);
+        }
+
+
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+    }
+
+
+    @RequireSystemAccess
+    @PUT
+    @Path( "index/rebuild/" + RootResource.APPLICATION_ID_PATH + "/{collectionName}" )
+    public JSONWithPadding rebuildIndexes( @Context UriInfo ui, @PathParam( "applicationId"
) String applicationIdStr,
+                                           @PathParam( "collectionName" ) String collectionName,
+                                           @QueryParam( "callback" ) @DefaultValue( "callback"
) String callback )
+            throws Exception {
+
+        final UUID appId = UUIDUtils.tryExtractUUID( applicationIdStr );
+        ApiResponse response = createApiResponse();
+        response.setAction( "rebuild indexes" );
+
+        rebuildCollection( appId, collectionName );
+
+        response.setSuccess();
+
+        return new JSONWithPadding( response, callback );
+    }
+
+
+    private void rebuildCollection( final UUID applicationId, final String collectionName
) {
+        EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver()
{
+            @Override
+            public void onProgress( EntityRef s, EntityRef t, String etype ) {
+                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
+                        s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype
+                } );
+            }
+        };
+
+
+        logger.info( "Reindexing for app id: {} and collection {}", applicationId, collectionName
);
+
+        emf.rebuildCollectionIndex( applicationId, collectionName, po );
+        emf.refreshIndex();
+    }
 }


Mime
View raw message