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 2014/10/02 22:49:48 UTC

[1/2] git commit: Added re-index to SystemResource

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 <to...@apache.org>
Authored: Thu Oct 2 14:48:51 2014 -0600
Committer: Todd Nine <to...@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();
+    }
 }


[2/2] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o

Posted by to...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o


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

Branch: refs/heads/two-dot-o
Commit: deaa46c3ae1e71dc904fcdef17c2a422553564ce
Parents: 7b63338 8930071
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 2 14:49:41 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 2 14:49:41 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 106 ++++++++++++-------
 .../corepersistence/CpEntityManagerFactory.java |   2 -
 .../corepersistence/CpEntityMapUtils.java       |   2 +-
 .../org/apache/usergrid/persistence/GeoIT.java  |   2 +-
 .../persistence/model/field/value/Location.java |  12 ++-
 .../index/impl/EsEntityIndexBatchImpl.java      |   2 +-
 .../index/impl/EntityIndexMapUtils.java         |   2 +-
 .../apache/usergrid/rest/PartialUpdateTest.java |  18 +++-
 8 files changed, 95 insertions(+), 51 deletions(-)
----------------------------------------------------------------------