usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [21/27] incubator-usergrid git commit: fix index name
Date Wed, 03 Dec 2014 22:32:05 GMT
fix index name


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

Branch: refs/heads/USERGRID-252
Commit: c083e6b424ed35a2e60748843cf6d83430c40ccd
Parents: 5c2235f
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Tue Dec 2 16:56:58 2014 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Tue Dec 2 16:56:58 2014 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java    |  4 ++--
 .../HybridEntityManagerFactory.java                |  4 ++--
 .../usergrid/persistence/EntityManagerFactory.java |  5 +++--
 .../cassandra/EntityManagerFactoryImpl.java        |  2 +-
 .../usergrid/persistence/index/EntityIndex.java    |  5 +++--
 .../persistence/index/IndexIdentifier.java         |  2 +-
 .../persistence/index/impl/EsEntityIndexImpl.java  | 17 ++++-------------
 .../persistence/index/impl/EntityIndexTest.java    |  6 +-----
 .../org/apache/usergrid/rest/IndexResource.java    | 13 +++++++++----
 .../org/apache/usergrid/rest/AbstractRestIT.java   |  2 +-
 10 files changed, 27 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 5a09423..f6b0df8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -701,8 +701,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
     @Override
-    public void addIndex(final UUID applicationId,final String indexSuffix,final  Map<String,Object>
config){
-        getManagerCache().getEntityIndex(CpNamingUtils.getApplicationScope( applicationId
)).addIndex(indexSuffix,config);
+    public void addIndex(final UUID applicationId,final String indexSuffix,final int shards,final
int replicas){
+        getManagerCache().getEntityIndex(CpNamingUtils.getApplicationScope( applicationId
)).addIndex(indexSuffix,shards,replicas);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
index 0f1fbed..42dc805 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/HybridEntityManagerFactory.java
@@ -198,8 +198,8 @@ public class HybridEntityManagerFactory implements EntityManagerFactory,
Applica
     }
 
     @Override
-    public void addIndex(UUID appId, String suffix, Map<String, Object> config) {
-        factory.addIndex(appId,suffix,config);
+    public void addIndex(UUID appId, String suffix,final int shards,final int replicas) {
+        factory.addIndex(appId,suffix,shards,replicas);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 33413a0..3d4827b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -165,9 +165,10 @@ public interface EntityManagerFactory {
      * Add a new index to the application for scale
      * @param appId application id
      * @param suffix unique indentifier for additional index
-     * @param config {"replicas":num,"shards":num}
+     * @param shards number of shards
+     * @param replicas number of replicas
      */
-    public void addIndex(final UUID appId,final String suffix, Map<String,Object> config);
+    public void addIndex(final UUID appId,final String suffix,final int shards,final int
replicas);
 
     public Health getEntityStoreHealth();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
index 68abf2e..f073da7 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImpl.java
@@ -472,7 +472,7 @@ public class EntityManagerFactoryImpl implements EntityManagerFactory,
Applicati
     }
 
     @Override
-    public void addIndex(UUID appId, String suffix, Map<String, Object> config) {
+    public void addIndex(UUID appId, String suffix,final int shards,final int replicas) {
         throw new UnsupportedOperationException("Not supported in v1");
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index 93dd3ea..4a653b3 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -41,9 +41,10 @@ public interface EntityIndex {
     /**
      * Create an index and add to alias, will create alias and remove any old index from
write alias if alias already exists
      * @param indexSuffix index name
-     * @param config {"replicas":num,"shards":num}
+     * @param shards
+     * @param replicas
      */
-    public void addIndex(final String indexSuffix, final Map<String,Object> config);
+    public void addIndex(final String indexSuffix, final int shards, final int replicas);
 
     /**
      * Create the index batch.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
index 54a02d6..86b5611 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexIdentifier.java
@@ -50,7 +50,7 @@ public class IndexIdentifier{
      */
     public String getIndex(String suffix) {
         if (suffix != null) {
-            return getIndexBase() + "_" + (suffix + 1);
+            return getIndexBase() + "_" + suffix;
         } else {
             return getIndexBase();
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/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 0b1cb0c..d546092 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
@@ -139,17 +139,8 @@ public class EsEntityIndexImpl implements EntityIndex {
     }
 
     @Override
-    public void addIndex(final String indexSuffix, final Map<String,Object> config)
{
-        if(!config.containsKey("replicas") || !config.containsKey("shards") ||
-                !(config.get("replicas") instanceof Integer) || !(config.get("shards") instanceof
Integer)){
-            throw new IllegalArgumentException("config must contains 'replicas' of type int
and 'shards' of type int");
-        }
-       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)
{
-
+    public void addIndex(final String indexSuffix,final int numberOfShards, final int numberOfReplicas)
{
+        String normalizedSuffix =  StringUtils.isNotEmpty(indexSuffix) ? indexSuffix : null;
         try {
 
             if (!mappingsCreated.getAndSet(true)) {
@@ -157,7 +148,7 @@ public class EsEntityIndexImpl implements EntityIndex {
             }
 
             //get index name with suffix attached
-            String indexName = indexIdentifier.getIndex(indexSuffix);
+            String indexName = indexIdentifier.getIndex(normalizedSuffix);
 
             //Create index
             try {
@@ -170,7 +161,7 @@ public class EsEntityIndexImpl implements EntityIndex {
                 logger.info("Index Name [{}] already exists", indexName);
             }
 
-            addAlias(indexSuffix);
+            addAlias(normalizedSuffix);
 
             testNewIndex();
         } catch (IndexAlreadyExistsException expected) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 360347a..13d1552 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -127,11 +127,7 @@ public class EntityIndexTest extends BaseIT {
 
         testQueries( indexScope, searchTypes,  entityIndex );
 
-        HashMap<String,Object> config = new HashMap<>();
-        config.put("replicas",0);
-        config.put("shards",1);
-
-        entityIndex.addIndex("v2", config);
+        entityIndex.addIndex("v2", 1,0);
 
         insertJsonBlob(entityIndex, entityType, indexScope, "/sample-large.json",100,100);
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/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 02e2923..5cbc499 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
@@ -188,13 +188,18 @@ public class IndexResource extends AbstractContextResource {
         ApiResponse response = createApiResponse();
         final UUID appId = UUIDUtils.tryExtractUUID(applicationIdStr);
 
-        if(config.containsKey("indexSuffix")) {
-            emf.addIndex(appId, config.get("indexSuffix").toString(), config);
-            response.setAction("Add index to alias");
+        if(!config.containsKey("replicas") || !config.containsKey("shards") ||
+                !(config.get("replicas") instanceof Integer) || !(config.get("shards") instanceof
Integer)){
+            throw new IllegalArgumentException("body must contains 'replicas' of type int
and 'shards' of type int");
         }
-        else{
+
+        if(!config.containsKey("indexSuffix")) {
             throw new IllegalArgumentException("Please add an indexSuffix to your post");
         }
+
+        emf.addIndex(appId, config.get("indexSuffix").toString(), (int) config.get("shards"),(int)
config.get("replicas"));
+        response.setAction("Add index to alias");
+
         return new JSONWithPadding(response, callback);
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c083e6b4/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
index 1a18568..6ccb923 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/AbstractRestIT.java
@@ -276,7 +276,7 @@ public abstract class AbstractRestIT extends JerseyTest {
 
     /** Get the super user's access token */
     protected String superAdminToken() {
-        return mgmtToken( "superuser", "superpassword" );
+        return mgmtToken( "superuser", "test" );
     }
 
 


Mime
View raw message