usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [14/27] incubator-usergrid git commit: rest path changes, better parsing logic
Date Wed, 03 Dec 2014 22:31:58 GMT
rest path changes, better parsing logic


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

Branch: refs/heads/USERGRID-252
Commit: 4c12b6b1493bcd4ff92fc527db6ad0d41292f257
Parents: cfa73b4
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Nov 26 09:19:54 2014 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Nov 26 09:19:54 2014 -0700

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           |  4 +++-
 .../org/apache/usergrid/rest/IndexResource.java | 21 +++++++++++++-------
 2 files changed, 17 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4c12b6b1/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 623788e..588a5a1 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -26,6 +26,7 @@ import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.usergrid.persistence.index.*;
+import org.apache.usergrid.persistence.index.utils.StringUtils;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest;
 import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
 import org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest;
@@ -142,7 +143,8 @@ public class EsEntityIndexImpl implements EntityIndex {
         if(!config.containsKey("replicas") || !config.containsKey("shards")){
             throw new IllegalArgumentException("config must contains 'replicas' and 'shards'");
         }
-       addIndex(indexSuffix, (int) config.get("shards"),(int)config.get("replicas"));
+       String normalizedSuffix =  StringUtils.isNotEmpty(indexSuffix) ? indexSuffix : null;
+       addIndex(normalizedSuffix, (int) config.get("shards"),(int)config.get("replicas"));
     }
 
     private void addIndex(final String indexSuffix,final int numberOfShards, final int numberOfReplicas)
{

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4c12b6b1/stack/rest/src/main/java/org/apache/usergrid/rest/IndexResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/IndexResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/IndexResource.java
index f95d439..02e2923 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/IndexResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/IndexResource.java
@@ -178,18 +178,25 @@ public class IndexResource extends AbstractContextResource {
         return new JSONWithPadding( response, callback );
     }
 
+    @RequireSystemAccess
+    @POST
+    @Path( RootResource.APPLICATION_ID_PATH )
     public JSONWithPadding addIndex(@Context UriInfo ui,
                                     @PathParam( "applicationId" ) final String applicationIdStr,
-                                    @PathParam( "indexSuffix" ) final String indexSuffix,
-                                    @PathParam("shards") final int shards,
-                                    @PathParam("replicas") final int replicas,
                                     Map<String, Object> config,
-                                    @QueryParam( "callback" ) @DefaultValue( "callback" )
String callback) {
-        final UUID appId = UUIDUtils.tryExtractUUID(applicationIdStr);
-        emf.addIndex(appId, indexSuffix, config);
+                                    @QueryParam( "callback" ) @DefaultValue( "callback" )
String callback)  throws Exception{
         ApiResponse response = createApiResponse();
-        response.setAction("Add index to alias");
+        final UUID appId = UUIDUtils.tryExtractUUID(applicationIdStr);
+
+        if(config.containsKey("indexSuffix")) {
+            emf.addIndex(appId, config.get("indexSuffix").toString(), config);
+            response.setAction("Add index to alias");
+        }
+        else{
+            throw new IllegalArgumentException("Please add an indexSuffix to your post");
+        }
         return new JSONWithPadding(response, callback);
+
     }
 
     private void rebuildCollection( final UUID applicationId, final String collectionName,
final long delay ) {


Mime
View raw message