usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [28/36] usergrid git commit: Added a way to use the existing reindex code to reindex the collection rather than copying and pasting the reindex code.
Date Fri, 08 Apr 2016 20:21:15 GMT
Added a way to use the existing reindex code to reindex the collection rather than copying
and pasting the reindex code.


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

Branch: refs/heads/release-2.1.1
Commit: 37eca05b1d5f26d6d3e7125a2324ef62378b6070
Parents: 956a6f5
Author: George Reyes <grey@apache.org>
Authored: Thu Mar 31 15:59:55 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Thu Mar 31 15:59:55 2016 -0700

----------------------------------------------------------------------
 .../org/apache/usergrid/rest/ApiResponse.java   |  7 +++-
 .../rest/applications/CollectionResource.java   | 43 ++++----------------
 .../usergrid/rest/system/IndexResource.java     |  6 +++
 .../collection/CollectionsResourceIT.java       |  1 -
 4 files changed, 21 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/37eca05b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
index d5d3182..727d187 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/ApiResponse.java
@@ -118,7 +118,12 @@ public class ApiResponse {
     public ApiResponse( ServerEnvironmentProperties serverProperties, ManagementService management
) {
         this.serverEnvironmentProperties = serverProperties;
         this.management = management;
-        this.config = management.getOrganizationConfigDefaultsOnly();
+        if(management!=null) {
+            this.config = management.getOrganizationConfigDefaultsOnly();
+        }
+        else {
+            this.config = null;
+        }
         timestamp = System.currentTimeMillis();
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/37eca05b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
index b097469..c124f9d 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/CollectionResource.java
@@ -50,6 +50,7 @@ import org.apache.usergrid.rest.ApiResponse;
 import org.apache.usergrid.rest.RootResource;
 import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
 import org.apache.usergrid.rest.security.annotations.RequireSystemAccess;
+import org.apache.usergrid.rest.system.IndexResource;
 import org.apache.usergrid.services.AbstractCollectionService;
 import org.apache.usergrid.services.ServiceAction;
 import org.apache.usergrid.services.ServiceParameter;
@@ -120,6 +121,8 @@ public class CollectionResource extends ServiceResource {
 
     private void addItemToServiceContext( final @Context UriInfo ui,
                                           final @PathParam( "itemName" ) PathSegment itemName
) throws Exception {
+        //The below is duplicated because it could change in the future and is probably not
all needed but
+        //not determined yet.
         if ( itemName.getPath().startsWith( "{" ) ) {
             Query query = Query.fromJsonString( itemName.getPath() );
             if ( query != null ) {
@@ -203,40 +206,12 @@ public class CollectionResource extends ServiceResource {
 
         addItemToServiceContext( ui, itemName );
 
-        final ReIndexRequestBuilder request =
-            createRequest().withApplicationId( services.getApplicationId() ).withCollection(
-                String.valueOf( getServiceParameters().get( 0 ) ) ).withDelay( 50, TimeUnit.MILLISECONDS
);
-
-        return executeAndCreateResponse( request, callback );
-    }
-
-    private ReIndexService getReIndexService() {
-        return injector.getInstance( ReIndexService.class );
-    }
-
-    private ReIndexRequestBuilder createRequest() {
-        //TODO: wire this up through spring, and in the future guice.
-        return new ReIndexRequestBuilderImpl();
-    }
-
-    /**
-     * Execute the request and return the response.
-     */
-    private ApiResponse executeAndCreateResponse( final ReIndexRequestBuilder request, final
String callback ) {
-
-
-        final ReIndexService.ReIndexStatus status = getReIndexService().rebuildIndex( request
);
-
-        final ApiResponse response = createApiResponse();
-
-        response.setAction( "rebuild indexes" );
-        response.setProperty( "jobId", status.getJobId() );
-        response.setProperty( "status", status.getStatus() );
-        response.setProperty( "lastUpdatedEpoch", status.getLastUpdated() );
-        response.setProperty( "numberQueued", status.getNumberProcessed() );
-        response.setSuccess();
-
-        return response;
+//        final ReIndexRequestBuilder request =
+//            createRequest().withApplicationId( services.getApplicationId() ).withCollection(
+//                String.valueOf( getServiceParameters().get( 0 ) ) ).withDelay( 50, TimeUnit.MILLISECONDS
);
+//
+        IndexResource indexResource = new IndexResource(injector);
+        return indexResource.rebuildIndexesPost( services.getApplicationId().toString(),itemName.getPath(),false,callback
);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/37eca05b/stack/rest/src/main/java/org/apache/usergrid/rest/system/IndexResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/system/IndexResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/system/IndexResource.java
index 4a521b3..be60177 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/system/IndexResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/system/IndexResource.java
@@ -23,6 +23,8 @@ package org.apache.usergrid.rest.system;
 
 import com.fasterxml.jackson.jaxrs.json.annotation.JSONP;
 import com.google.common.base.Preconditions;
+import com.google.inject.Injector;
+
 import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilder;
 import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilderImpl;
 import org.apache.usergrid.corepersistence.index.ReIndexService;
@@ -67,6 +69,10 @@ public class IndexResource extends AbstractContextResource {
         super();
     }
 
+    public IndexResource( Injector injector) {
+        this.injector = injector;
+    }
+
 
     @RequireSystemAccess
     @POST

http://git-wip-us.apache.org/repos/asf/usergrid/blob/37eca05b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index 8ec4a3a..d814f55 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -279,7 +279,6 @@ public class CollectionsResourceIT extends AbstractRestIT {
             this.app().collection( "testCollection" ).post( testEntity );
         }
 
-
         //Creating schema.
         //this could be changed to a hashmap.
         ArrayList<String> indexingArray = new ArrayList<>(  );


Mime
View raw message