You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/06/09 18:16:41 UTC

[1/6] incubator-usergrid git commit: refactor index cardinality in cp entitymanager

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-652 5267d483c -> 79d7fe9cb


refactor index cardinality in cp entitymanager


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

Branch: refs/heads/USERGRID-652
Commit: 588cd1f6b926f54c684c825403c42362cbbf17f9
Parents: 5267d48
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jun 8 13:47:45 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jun 8 13:47:45 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 25 +++++-
 .../corepersistence/CpEntityManagerFactory.java | 52 ++++++------
 .../usergrid/persistence/EntityManager.java     | 12 +++
 .../persistence/EntityManagerFactory.java       | 11 +--
 .../org/apache/usergrid/CoreITSetupImpl.java    |  2 +-
 .../corepersistence/index/IndexNamingTest.java  | 83 ++++++++++++++++++++
 .../org/apache/usergrid/rest/IndexResource.java | 10 ++-
 .../org/apache/usergrid/rest/RootResource.java  |  4 -
 8 files changed, 149 insertions(+), 50 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 513f257..c18a514 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -34,6 +34,10 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.UUID;
 
+import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory;
+import org.apache.usergrid.persistence.index.AliasedEntityIndex;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
+import org.apache.usergrid.persistence.index.IndexRefreshCommand;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.util.Assert;
@@ -231,13 +235,14 @@ public class CpEntityManager implements EntityManager {
      * @param applicationId
      */
     public CpEntityManager( final CassandraService cass, final CounterUtils counterUtils, final AsyncEventService indexService, final ManagerCache managerCache,
-                            final MetricsFactory metricsFactory, final EntityManagerFig entityManagerFig,
+                            final MetricsFactory metricsFactory,
+                            final EntityManagerFig entityManagerFig,
                             final PipelineBuilderFactory pipelineBuilderFactory ,
-                            final GraphManagerFactory graphManagerFactory,final UUID applicationId ) {
+                            final GraphManagerFactory graphManagerFactory,
+                            final UUID applicationId ) {
 
         this.entityManagerFig = entityManagerFig;
 
-
         Preconditions.checkNotNull( cass, "cass must not be null" );
         Preconditions.checkNotNull( counterUtils, "counterUtils must not be null" );
         Preconditions.checkNotNull( managerCache, "managerCache must not be null" );
@@ -2909,6 +2914,20 @@ public class CpEntityManager implements EntityManager {
     }
 
 
+    @Override
+    public void addIndex(final String indexSuffix,final int shards,final int replicas, final String writeConsistency){
+        managerCache.getEntityIndex(applicationScope).addIndex( indexSuffix, shards, replicas, writeConsistency);
+    }
+
+    /**
+     * TODO, these 3 methods are super janky.  During refactoring we should clean this model up
+     */
+    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex() {
+
+        // refresh special indexes without calling EntityManager refresh because stack overflow
+
+        return managerCache.getEntityIndex(applicationScope).refreshAsync().toBlocking().first();
+    }
 
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/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 c79ea4a..9948b77 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
@@ -26,10 +26,11 @@ import java.util.UUID;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory;
 import org.apache.usergrid.corepersistence.index.ReIndexRequestBuilder;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
-import org.apache.usergrid.persistence.index.AliasedEntityIndex;
+import org.apache.usergrid.persistence.index.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.BeansException;
@@ -61,9 +62,6 @@ import org.apache.usergrid.persistence.graph.GraphManager;
 import org.apache.usergrid.persistence.graph.GraphManagerFactory;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
-import org.apache.usergrid.persistence.index.EntityIndex;
-import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.IndexRefreshCommand;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -95,14 +93,12 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private static final Logger logger = LoggerFactory.getLogger( CpEntityManagerFactory.class );
     private final EntityIndexFactory entityIndexFactory;
     private final EntityManagerFig entityManagerFig;
+    private final IndexLocationStrategyFactory indexLocationFactory;
 
     private ApplicationContext applicationContext;
 
     private Setup setup = null;
 
-    /** Have we already initialized the index for the management app? */
-    private AtomicBoolean indexInitialized = new AtomicBoolean(  );
-
     // cache of already instantiated entity managers
     private LoadingCache<UUID, EntityManager> entityManagers
         = CacheBuilder.newBuilder().maximumSize(100).build(new CacheLoader<UUID, EntityManager>() {
@@ -119,7 +115,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private CounterUtils counterUtils;
     private Injector injector;
     private final ReIndexService reIndexService;
-    private final EntityIndex entityIndex;
     private final MetricsFactory metricsFactory;
     private final AsyncEventService indexService;
     private final PipelineBuilderFactory pipelineBuilderFactory;
@@ -133,7 +128,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.injector = injector;
         this.reIndexService = injector.getInstance(ReIndexService.class);
         this.entityManagerFig = injector.getInstance(EntityManagerFig.class);
-        this.entityIndex = injector.getInstance(EntityIndex.class);
         this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
         this.managerCache = injector.getInstance( ManagerCache.class );
         this.metricsFactory = injector.getInstance( MetricsFactory.class );
@@ -142,6 +136,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.graphManagerFactory = injector.getInstance( GraphManagerFactory.class );
         this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
             getManagementEntityManager() );
+        this.indexLocationFactory = injector.getInstance(IndexLocationStrategyFactory.class);
 
 
     }
@@ -383,7 +378,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
         }
         final Id managementAppId = CpNamingUtils.getManagementApplicationId();
-        final AliasedEntityIndex aei = managerCache.getEntityIndex(applicationScope);
+        final AliasedEntityIndex aei = getManagementIndex();
         final GraphManager managementGraphManager = managerCache.getGraphManager(managementAppScope);
         final Edge createEdge = CpNamingUtils.createCollectionEdge(managementAppId, collectionToName, applicationId);
 
@@ -405,7 +400,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                         managementEm.delete(oldAppEntity);
                         applicationIdCache.evictAppId(oldAppEntity.getName());
                     }
-                    entityIndex.refreshAsync().toBlocking().last();
+                    AliasedEntityIndex ei = getManagementIndex();
+                    ei.refreshAsync().toBlocking().last();
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
@@ -670,28 +666,28 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     /**
      * TODO, these 3 methods are super janky.  During refactoring we should clean this model up
      */
-    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex() {
+    public List<IndexRefreshCommand.IndexRefreshCommandInfo> refreshIndexes() {
 
-        // refresh special indexes without calling EntityManager refresh because stack overflow
-        maybeCreateIndexes();
+        try {
+            final Map<String, UUID> applications = getApplications();
 
-        return entityIndex.refreshAsync().toBlocking().first();
-    }
+            Observable<IndexRefreshCommand.IndexRefreshCommandInfo> appRefreshes =
+                Observable.merge( Observable.from(applications.values()),Observable.just(getManagementAppId()))
+                .map((UUID appId) -> getEntityManager(appId).refreshIndex());
 
-    private void maybeCreateIndexes() {
-        if ( indexInitialized.getAndSet( true ) ) {
-            return;
+            return appRefreshes.toList().toBlocking().last();
+        }catch (Exception e){
+            throw new RuntimeException(e);
         }
-
-//        entityIndex.initializeIndex();
     }
 
 
-    private List<AliasedEntityIndex> getManagementIndexes() {
 
-        return Arrays.asList(
+    private AliasedEntityIndex getManagementIndex() {
+
+        return
             managerCache.getEntityIndex( // management app
-                CpNamingUtils.getApplicationScope(getManagementAppId())));
+                CpNamingUtils.getApplicationScope(getManagementAppId()));
     }
 
 
@@ -713,11 +709,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
 
     @Override
-    public void addIndex(final String indexSuffix,final int shards,final int replicas, final String writeConsistency){
-        entityIndex.addIndex( indexSuffix, shards, replicas, writeConsistency);
-    }
-
-    @Override
     public Health getEntityStoreHealth() {
 
         // could use any collection scope here, does not matter
@@ -749,6 +740,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     @Override
     public Health getIndexHealth() {
-        return entityIndex.getIndexHealth();
+
+       return getManagementIndex().getIndexHealth();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index a6fa717..3f088f2 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -28,6 +28,7 @@ import org.apache.usergrid.persistence.Query.Level;
 import org.apache.usergrid.persistence.cassandra.CassandraService;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Role;
+import org.apache.usergrid.persistence.index.IndexRefreshCommand;
 import org.apache.usergrid.persistence.index.query.CounterResolution;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -716,4 +717,15 @@ public interface EntityManager {
      * @return
      */
     Set<String> getConnectionsAsTarget(final EntityRef entityRef);
+
+    /**
+     * Add a new index to the application for scale
+     * @param suffix unique indentifier for additional index
+     * @param shards number of shards
+     * @param replicas number of replicas
+     * @param writeConsistency only "one, quorum, or all"
+     */
+    void addIndex(final String suffix,final int shards,final int replicas, final String writeConsistency);
+
+    IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/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 cd7e515..13034d0 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
@@ -17,6 +17,7 @@
 package org.apache.usergrid.persistence;
 
 
+import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
@@ -163,7 +164,7 @@ public interface EntityManagerFactory {
 
     public UUID getManagementAppId();
 
-    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex();
+    public List<IndexRefreshCommand.IndexRefreshCommandInfo> refreshIndexes();
 
 
     /**
@@ -174,14 +175,6 @@ public interface EntityManagerFactory {
     /** For testing purposes */
     public void flushEntityManagerCaches();
 
-    /**
-     * Add a new index to the application for scale
-     * @param suffix unique indentifier for additional index
-     * @param shards number of shards
-     * @param replicas number of replicas
-     * @param writeConsistency only "one, quorum, or all"
-     */
-    public void addIndex(final String suffix,final int shards,final int replicas, final String writeConsistency);
 
     public Health getEntityStoreHealth();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
index 526d883..3688934 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@ -155,7 +155,7 @@ public class CoreITSetupImpl implements CoreITSetup, TestEntityIndex {
 
         }
 
-        emf.refreshIndex();
+        emf.refreshIndexes();
 
         try {
             Thread.sleep(50);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
new file mode 100644
index 0000000..e3b1d3f
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
@@ -0,0 +1,83 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence.index;
+
+import com.google.inject.Inject;
+import net.jcip.annotations.NotThreadSafe;
+import org.apache.usergrid.corepersistence.TestIndexModule;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.core.astyanax.CassandraFig;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.core.test.UseModules;
+import org.apache.usergrid.persistence.index.IndexFig;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
+import org.apache.usergrid.persistence.index.impl.EsRunner;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.UUID;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Classy class class.
+ */
+@RunWith( EsRunner.class )
+@UseModules( { TestIndexModule.class } )
+@NotThreadSafe
+public class IndexNamingTest {
+    @Inject
+    public CassandraFig cassandraFig;
+
+    @Inject
+    public IndexFig indexFig;
+
+    @Inject
+    public IndexLocationStrategyFactory indexLocationStrategyFactory;
+
+    private ApplicationScope applicationScope;
+    private ApplicationScope managementApplicationScope;
+    private ApplicationIndexLocationStrategy applicationLocationStrategy;
+    private ManagementIndexLocationStrategy managementLocationStrategy;
+
+    @Before
+    public void setup(){
+        this.applicationScope = CpNamingUtils.getApplicationScope(UUID.randomUUID());
+        this.managementApplicationScope = CpNamingUtils.getApplicationScope(CpNamingUtils.getManagementApplicationId().getUuid());
+        this.managementLocationStrategy = new ManagementIndexLocationStrategy(indexFig);
+        this.applicationLocationStrategy = new ApplicationIndexLocationStrategy(cassandraFig,indexFig,applicationScope);
+    }
+
+    @Test
+    public void managementNaming(){
+        IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(managementApplicationScope);
+        assertTrue(indexLocationStrategy.getIndex(null) == managementLocationStrategy.getIndex(null));
+
+    }
+    @Test
+    public void applicationNaming(){
+        IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
+        assertTrue(indexLocationStrategy.getIndex(null) == applicationLocationStrategy.getIndex(null));
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/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 ffb9700..5020f3b 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
@@ -35,6 +35,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.UriInfo;
 
+import org.apache.usergrid.persistence.EntityManager;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
@@ -217,7 +218,9 @@ public class IndexResource extends AbstractContextResource {
 
     @RequireSystemAccess
     @POST
-    public JSONWithPadding addIndex( @Context UriInfo ui, Map<String, Object> config,
+    public JSONWithPadding addIndex( @Context UriInfo ui,
+                                     @PathParam( "applicationId" ) final String applicationIdStr,
+                                     Map<String, Object> config,
                                      @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
         throws Exception {
 
@@ -234,9 +237,10 @@ public class IndexResource extends AbstractContextResource {
         if ( !config.containsKey( "indexSuffix" ) ) {
             throw new IllegalArgumentException( "Please add an indexSuffix to your post" );
         }
+        final UUID appId = UUIDUtils.tryExtractUUID( applicationIdStr );
 
-
-        emf.addIndex( config.get( "indexSuffix" ).toString(), ( int ) config.get( "shards" ),
+        EntityManager em = emf.getEntityManager(appId);
+        em.addIndex( config.get( "indexSuffix" ).toString(), ( int ) config.get( "shards" ),
             ( int ) config.get( "replicas" ), ( String ) config.get( "writeConsistency" ) );
         response.setAction( "Add index to alias" );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/588cd1f6/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
index c31ca9b..5b5e711 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/RootResource.java
@@ -208,10 +208,6 @@ public class RootResource extends AbstractContextResource implements MetricProce
         EntityManager em = emf.getEntityManager(emf.getManagementAppId());
         node.put( "managementAppIndexStatus", emf.getIndexHealth().toString() );
 
-        IndexRefreshCommand.IndexRefreshCommandInfo didRefresh = emf.refreshIndex();
-        node.put("refreshIndexTime", didRefresh.getExecutionTime());
-        node.put("refreshIndexSuccess", didRefresh.hasFinished());
-
         dumpMetrics(node);
         response.setProperty( "status", node );
         return new JSONWithPadding( response, callback );


[3/6] incubator-usergrid git commit: refactor refresh for a single index

Posted by sf...@apache.org.
refactor refresh for a single index


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

Branch: refs/heads/USERGRID-652
Commit: 9af1637ea3bbe69ec8b6449a4d83ca5bb9e0b88b
Parents: d936cf3
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jun 8 17:39:08 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jun 8 17:39:08 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 39 +-------
 .../index/ApplicationIndexLocationStrategy.java | 18 ++++
 .../index/ManagementIndexLocationStrategy.java  | 23 ++++-
 .../persistence/EntityManagerFactory.java       | 15 +--
 .../org/apache/usergrid/CoreApplication.java    |  2 +-
 .../org/apache/usergrid/CoreITSetupImpl.java    |  5 +-
 .../org/apache/usergrid/TestEntityIndex.java    |  4 +-
 .../index/AsyncIndexServiceTest.java            |  8 +-
 .../corepersistence/index/IndexNamingTest.java  |  4 +-
 .../persistence/query/IteratingQueryIT.java     |  1 +
 .../usergrid/persistence/index/IndexFig.java    |  2 +-
 .../index/impl/EsEntityIndexImpl.java           |  7 +-
 .../persistence/index/impl/EntityIndexTest.java |  2 -
 .../org/apache/usergrid/ServiceApplication.java | 16 ++--
 .../org/apache/usergrid/ServiceITSetup.java     |  3 +-
 .../org/apache/usergrid/ServiceITSetupImpl.java |  6 +-
 .../migration/AppInfoMigrationPluginTest.java   |  6 +-
 .../apache/usergrid/management/EmailFlowIT.java | 10 +-
 .../usergrid/management/OrganizationIT.java     |  9 +-
 .../org/apache/usergrid/management/RoleIT.java  |  4 +-
 .../cassandra/ApplicationCreatorIT.java         |  2 +-
 .../cassandra/ManagementServiceIT.java          | 22 ++---
 .../management/export/ExportServiceIT.java      | 12 +--
 .../management/importer/ImportCollectionIT.java | 10 +-
 .../usergrid/services/ConnectionsServiceIT.java |  4 +-
 .../usergrid/services/GroupServiceIT.java       |  4 +-
 .../usergrid/services/RolesServiceIT.java       |  2 +-
 .../usergrid/services/UsersServiceIT.java       |  2 +-
 .../apns/NotificationsServiceIT.java            | 99 ++++----------------
 .../gcm/NotificationsServiceIT.java             |  4 +-
 30 files changed, 141 insertions(+), 204 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/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 549426e..6ce17f0 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
@@ -91,9 +91,7 @@ import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 public class CpEntityManagerFactory implements EntityManagerFactory, ApplicationContextAware {
 
     private static final Logger logger = LoggerFactory.getLogger( CpEntityManagerFactory.class );
-    private final EntityIndexFactory entityIndexFactory;
     private final EntityManagerFig entityManagerFig;
-    private final IndexLocationStrategyFactory indexLocationFactory;
 
     private ApplicationContext applicationContext;
 
@@ -128,7 +126,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.injector = injector;
         this.reIndexService = injector.getInstance(ReIndexService.class);
         this.entityManagerFig = injector.getInstance(EntityManagerFig.class);
-        this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
         this.managerCache = injector.getInstance( ManagerCache.class );
         this.metricsFactory = injector.getInstance( MetricsFactory.class );
         this.indexService = injector.getInstance( AsyncEventService.class );
@@ -136,8 +133,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.graphManagerFactory = injector.getInstance( GraphManagerFactory.class );
         this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
             getManagementEntityManager() );
-        this.indexLocationFactory = injector.getInstance(IndexLocationStrategyFactory.class);
-
 
     }
 
@@ -262,7 +257,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager appEm = getEntityManager(applicationId);
         appEm.create(applicationId, TYPE_APPLICATION, properties);
         appEm.resetRoles();
-     //   entityIndex.refreshAsync();//.toBlocking().last();
 
 
         // create application info entity in the management app
@@ -666,19 +660,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     /**
      * TODO, these 3 methods are super janky.  During refactoring we should clean this model up
      */
-    public List<IndexRefreshCommand.IndexRefreshCommandInfo> refreshIndexes() {
-
-        try {
-            final Map<String, UUID> applications = getApplications();
-
-            Observable<IndexRefreshCommand.IndexRefreshCommandInfo> appRefreshes =
-                Observable.merge( Observable.from(applications.values()),Observable.just(getManagementAppId()))
-                .map((UUID appId) -> getEntityManager(appId).refreshIndex());
-
-            return appRefreshes.toList().toBlocking().last();
-        }catch (Exception e){
-            throw new RuntimeException(e);
-        }
+    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex(UUID applicationId) {
+        return getEntityManager(applicationId).refreshIndex();
     }
 
 
@@ -719,24 +702,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
 
-    @Override
-    public UUID createApplication(String organizationName, String name) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v2");
-    }
-
-
-    @Override
-    public UUID createApplication(
-        String organizationName, String name, Map<String, Object> properties) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v2");
-    }
-
-    @Override
-    public UUID initializeApplication(
-        String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v2");
-    }
-
 
     @Override
     public Health getIndexHealth() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
index 4c5d7a5..cad7e10 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
@@ -92,4 +92,22 @@ class ApplicationIndexLocationStrategy implements IndexLocationStrategy {
         return applicationScope;
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ApplicationIndexLocationStrategy that = (ApplicationIndexLocationStrategy) o;
+
+        if (!applicationScope.equals(that.applicationScope)) return false;
+        return prefix.equals(that.prefix);
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = applicationScope.hashCode();
+        result = 31 * result + prefix.hashCode();
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
index 969da1c..5dbaa54 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
@@ -40,9 +40,8 @@ class ManagementIndexLocationStrategy implements IndexLocationStrategy {
         this.indexFig = indexFig;
         this.managementAppId = CpNamingUtils.getManagementApplicationId();
         //remove usergrid
-        this.prefix = StringUtils.isNotEmpty(indexFig.getIndexPrefix())
-            ? indexFig.getIndexPrefix().toLowerCase() + "_" + indexFig.getManagementAppIndexName()  ////use lowercase value
-             :indexFig.getManagementAppIndexName() ;
+        this.prefix = indexFig.getManagementAppIndexName().toLowerCase();  ////use lowercase value
+
 
     }
     @Override
@@ -64,4 +63,22 @@ class ManagementIndexLocationStrategy implements IndexLocationStrategy {
         return new ApplicationScopeImpl(managementAppId);
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ManagementIndexLocationStrategy that = (ManagementIndexLocationStrategy) o;
+
+        if (!managementAppId.equals(that.managementAppId)) return false;
+        return prefix.equals(that.prefix);
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = managementAppId.hashCode();
+        result = 31 * result + prefix.hashCode();
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/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 6e77e6e..1ae2377 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
@@ -65,9 +65,6 @@ public interface EntityManagerFactory {
          */
     Entity createApplicationV2( String organizationName, String name ) throws Exception;
 
-    @Deprecated
-    UUID createApplication( String organizationName, String name ) throws Exception;
-
     /**
      * Creates a Application entity. All entities except for applications must be attached to a
      * Application.
@@ -82,9 +79,6 @@ public interface EntityManagerFactory {
     Entity createApplicationV2(
         String organizationName, String name, Map<String, Object> properties ) throws Exception;
 
-    @Deprecated
-    UUID createApplication(
-        String organizationName, String name, Map<String, Object> properties ) throws Exception;
 
     /**
      * Delete Application.
@@ -158,14 +152,11 @@ public interface EntityManagerFactory {
     public Entity initializeApplicationV2(
         String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception;
 
-    @Deprecated
-    public UUID initializeApplication(
-        String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception;
 
-    public UUID getManagementAppId();
 
-    public List<IndexRefreshCommand.IndexRefreshCommandInfo> refreshIndexes();
+    public UUID getManagementAppId();
 
+    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex(UUID applicationId);
 
     /**
      * Perform a realtime count of every entity in the system.  This can be slow as it traverses the entire system graph
@@ -184,7 +175,7 @@ public interface EntityManagerFactory {
 
     public interface ProgressObserver {
 
-     public void onProgress( EntityRef entity);
+        public void onProgress(EntityRef entity);
 
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index e85077f..f431a93 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -232,7 +232,7 @@ public class CoreApplication implements Application, TestRule {
     @Override
     public synchronized void refreshIndex() {
         //Insert test entity and find it
-        setup.getEmf().refreshIndexes();
+        setup.getEmf().refreshIndex(em.getApplicationId());
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
index 3688934..3b01d3c 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@ -148,14 +148,13 @@ public class CoreITSetupImpl implements CoreITSetup, TestEntityIndex {
     }
 
     @Override
-    public void refresh(){
+    public void refresh(UUID appId){
         try {
             Thread.sleep(50);
         } catch (InterruptedException ie){
 
         }
-
-        emf.refreshIndexes();
+        emf.refreshIndex(appId);
 
         try {
             Thread.sleep(50);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java b/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
index cdbae3f..7da187a 100644
--- a/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
+++ b/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
@@ -19,9 +19,11 @@
  */
 package org.apache.usergrid;
 
+import java.util.UUID;
+
 /**
  * abstract refresh implementation
  */
 public interface TestEntityIndex {
-    void refresh();
+    void refresh(UUID appId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
index 7096a4b..17c012e 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
@@ -23,6 +23,7 @@ package org.apache.usergrid.corepersistence.index;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.index.*;
 import org.junit.Before;
 import org.junit.Rule;
@@ -81,12 +82,13 @@ public abstract class AsyncIndexServiceTest {
     @Inject
     public EntityIndexFactory entityIndexFactory;
 
-    @Inject
-    public EntityIndex entityIndex;
 
     @Inject
     public IndexLocationStrategyFactory indexLocationStrategyFactory;
 
+    @Inject
+    public EntityManagerFactory emf;
+
 
     private AsyncEventService asyncEventService;
 
@@ -143,7 +145,7 @@ public abstract class AsyncIndexServiceTest {
 
         asyncEventService.queueEntityIndexUpdate( applicationScope, testEntity );
 
-        entityIndex.refreshAsync().toBlocking().last();
+        emf.refreshIndex(applicationScope.getApplication().getUuid());
 
         //        Thread.sleep( 1000000000000l );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
index e3b1d3f..893359e 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
@@ -71,13 +71,13 @@ public class IndexNamingTest {
     @Test
     public void managementNaming(){
         IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(managementApplicationScope);
-        assertTrue(indexLocationStrategy.getIndex(null) == managementLocationStrategy.getIndex(null));
+        assertTrue(indexLocationStrategy.getIndex(null).equals(managementLocationStrategy.getIndex(null)));
 
     }
     @Test
     public void applicationNaming(){
         IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
-        assertTrue(indexLocationStrategy.getIndex(null) == applicationLocationStrategy.getIndex(null));
+        assertTrue(indexLocationStrategy.getIndex(null).equals(applicationLocationStrategy.getIndex(null)));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
index c4a16b6..d882f78 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
@@ -438,6 +438,7 @@ public class IteratingQueryIT {
             }
         }
 
+        this.app.refreshIndex();
         long stop = System.currentTimeMillis();
 
         LOG.info( "Writes took {} ms", stop - start );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
index 651dc68..5c61928 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
@@ -199,7 +199,7 @@ public interface IndexFig extends GuicyFig {
     @Key( ELASTICSEARCH_WRITE_TIMEOUT )
     long getWriteTimeout();
 
-    @Default( "management" )
+    @Default( "usergrid_management" )
     @Key( "elasticsearch.managment_index" )
     String getManagementAppIndexName();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/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 9b39069..1fd20e9 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
@@ -262,11 +262,12 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
             }
             aliasesRequestBuilder = adminClient.indices().prepareAliases();
             //Added For Graphite Metrics
-            // add read alias
-            aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias());
-            //Added For Graphite Metrics
             //add write alias
             aliasesRequestBuilder.addAlias(indexName, alias.getWriteAlias());
+            //Added For Graphite Metrics
+            // add read alias
+            aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias());
+
             isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
             logger.info("Created new read and write aliases ACK=[{}]", isAck);
             aliasCache.invalidate(alias);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/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 bbd248e..55b61ac 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
@@ -96,8 +96,6 @@ public class EntityIndexTest extends BaseIT {
 
         IndexLocationStrategy strategy =  new TestIndexIdentifier(cassandraFig,fig,new ApplicationScopeImpl(appId));
 
-
-
         entityIndex = eif.createEntityIndex( strategy );
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
index 801a640..2c34deb 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
@@ -105,7 +105,7 @@ public class ServiceApplication extends CoreApplication {
         dumpResults( results );
 
         if ( !action.name().equals( ServiceAction.GET )) {
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(this.id);
         }
 
         return results;
@@ -131,14 +131,14 @@ public class ServiceApplication extends CoreApplication {
         put( "name", name );
 
         Entity entity = testRequest( ServiceAction.POST, 1, pluralize( entityType ) ).getEntity();
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
         return entity;
     }
 
 
     public void createConnection( Entity subject, String verb, Entity noun ) throws Exception {
         sm.getEntityManager().createConnection( subject, verb, noun );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
     }
 
 
@@ -153,7 +153,7 @@ public class ServiceApplication extends CoreApplication {
         dumpResults( results );
 
         if ( !action.name().equals( ServiceAction.GET )) {
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(id);
         }
 
         return results;
@@ -169,7 +169,7 @@ public class ServiceApplication extends CoreApplication {
         assertNotNull( results.getData() );
 
         if ( !action.name().equals( ServiceAction.GET )) {
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(id);
         }
 
         // dump( results.getData() );
@@ -179,20 +179,20 @@ public class ServiceApplication extends CoreApplication {
 
     public Entity createRole( String name, String title, int inactivity ) throws Exception {
         Entity createRole = sm.getEntityManager().createRole( name, title, inactivity );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
         return createRole;
     }
 
 
     public void grantRolePermission( String role, String permission ) throws Exception {
         sm.getEntityManager().grantRolePermission( role, permission );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
     }
 
 
     public void grantUserPermission( UUID uuid, String permission ) throws Exception {
         sm.getEntityManager().grantUserPermission( uuid, permission );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
index 07a6fe5..e9bb248 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
@@ -27,6 +27,7 @@ import org.apache.usergrid.security.tokens.TokenService;
 import org.apache.usergrid.services.ServiceManagerFactory;
 
 import java.util.Properties;
+import java.util.UUID;
 
 
 public interface ServiceITSetup extends CoreITSetup {
@@ -44,7 +45,7 @@ public interface ServiceITSetup extends CoreITSetup {
 
     ImportService getImportService();
 
-    void refreshIndex();
+    void refreshIndex(UUID appid);
 
     /**
      * Convenience method to set a property in the Properties object returned by getProps();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
index 8ae5322..c17ee92 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.config.PropertiesFactoryBean;
 
 import java.util.Properties;
+import java.util.UUID;
 
 
 /** A {@link org.junit.rules.TestRule} that sets up services. */
@@ -180,8 +181,7 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu
         return appInfoMigrationPlugin;
     }
 
-    @Override
-    public void refreshIndex(){
-        this.getEntityIndex().refresh();
+    public void refreshIndex(UUID appid){
+        this.getEntityIndex().refresh(appid);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
index 9c8f40f..0fd1e52 100644
--- a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
@@ -101,9 +101,9 @@ public class AppInfoMigrationPluginTest {
             }
         }
 
-        setup.refreshIndex();
 
         UUID mgmtAppId = setup.getEmf().getManagementAppId();
+        setup.refreshIndex(mgmtAppId);
         EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId );
 
         checkApplicationsOk( orgName );
@@ -143,7 +143,7 @@ public class AppInfoMigrationPluginTest {
             }
         }
 
-        setup.refreshIndex();
+        setup.refreshIndex(mgmtAppId);
 
         setup.getEmf().flushEntityManagerCaches();
 
@@ -165,7 +165,7 @@ public class AppInfoMigrationPluginTest {
         // test that expected calls were made the to progress observer (use mock library)
 
         Mockito.verify( po, Mockito.times(10) ).update( Mockito.anyInt(), Mockito.anyString() );
-        setup.refreshIndex();
+        setup.refreshIndex(mgmtAppId);
 
         final Results appInfoResults = rootEm.searchCollection(
             new SimpleEntityRef("application", mgmtAppId), "appinfos", Query.fromQL("select *"));

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java b/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
index b158568..d75638d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
@@ -285,7 +285,7 @@ public class EmailFlowIT {
         String activation_url = String.format( setup.get( PROPERTIES_USER_ACTIVATION_URL ), orgName, appName,
             appUser.getUuid().toString() );
 
-        setup.refreshIndex();
+        setup.refreshIndex(app.getId());
 
         // Activation
         setup.getMgmtSvc().startAppUserActivationFlow( app.getId(), appUser );
@@ -358,15 +358,15 @@ public class EmailFlowIT {
         orgOwner = createOwnerAndOrganization( orgName, appName, userName, email, passwd, false, false );
         assertNotNull( orgOwner );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         ApplicationInfo app = setup.getMgmtSvc().createApplication( orgOwner.getOrganization().getUuid(), appName );
-        setup.refreshIndex();
+        setup.refreshIndex(app.getId());
         assertNotNull( app );
         enableEmailConfirmation( app.getId() );
         enableAdminApproval( app.getId() );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         final String appUserEmail = uniqueEmail();
         final String appUserUsername = uniqueUsername();
@@ -470,7 +470,7 @@ public class EmailFlowIT {
         userProps.put( "activated", activated );
 
         User user = em.create( User.ENTITY_TYPE, User.class, userProps );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         return user;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
index 3c93fa3..e0561a2 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
@@ -70,7 +71,7 @@ public class OrganizationIT {
         //createOrganization( orgName, user, false );
         assertNotNull( organization );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
         Map<UUID, String> userOrganizations = setup.getMgmtSvc().getOrganizationsForAdminUser(
             organization.getOwner().getUuid() );
         assertEquals("wrong number of organizations", 1, userOrganizations.size());
@@ -83,7 +84,7 @@ public class OrganizationIT {
         assertNotNull(applicationInfo.getId());
 
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationInfo.getId());
 
         Map<UUID, String> applications = setup.getMgmtSvc().getApplicationsForOrganization( organization.getOrganization().getUuid() );
         assertEquals( "wrong number of applications", 1, applications.size() );
@@ -97,7 +98,7 @@ public class OrganizationIT {
 
         setup.getMgmtSvc().activateOrganization( organization2 );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
 
         UserInfo u = setup.getMgmtSvc().verifyAdminUserPasswordCredentials( organization.getOwner().getUuid().toString(), "test" );
         assertNotNull( u );
@@ -215,7 +216,7 @@ public class OrganizationIT {
         OrganizationInfo organization2 = setup.getMgmtSvc().createOrganization(uniqueOrg(), user, false );
         assertNotNull( organization2 );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
         Map<UUID, String> userOrganizations = setup.getMgmtSvc().getOrganizationsForAdminUser( user.getUuid() );
         assertEquals( "wrong number of organizations", 2, userOrganizations.size() );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java b/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
index 64109b2..783e67c 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
@@ -66,7 +66,7 @@ public class RoleIT {
         UUID applicationId = setup.getMgmtSvc().createApplication( organization.getUuid(), "test-app" ).getId();
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
         Map<String, Object> properties = new LinkedHashMap<String, Object>();
         properties.put( "username", "edanuff5" );
@@ -75,7 +75,7 @@ public class RoleIT {
         User user = em.create( User.ENTITY_TYPE, User.class, properties );
 
         em.createRole( "logged-in", "Logged In", 1000 );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
         em.addUserToRole( user.getUuid(), "logged-in" );
 
         String accessToken = setup.getMgmtSvc().getAccessTokenForAppUser( applicationId, user.getUuid(), 0 );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
index 0de8220..fd509c8 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
@@ -88,7 +88,7 @@ public class ApplicationCreatorIT {
         customCreator.setSampleAppName(sampleAppName);
         ApplicationInfo appInfo = customCreator.createSampleFor( orgOwner.getOrganization() );
         if(appInfo == null){
-            setup.refreshIndex();
+            setup.refreshIndex(setup.getEmf().getManagementAppId());
         }
         assertNotNull( appInfo );
         assertEquals( expectedName, appInfo.getName() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
index 884bfec..196400f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
@@ -98,7 +98,7 @@ public class ManagementServiceIT {
         adminUser = orgAppAdminRule.getAdminInfo();
         applicationId = orgAppAdminRule.getApplicationInfo().getId();
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
     }
 
 
@@ -196,7 +196,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().activateAppUser( applicationId, user.getUuid() );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         user = em.get( entity.getUuid(), User.class );
 
@@ -492,7 +492,7 @@ public class ManagementServiceIT {
                                           false, false );
 
         EntityManager em = setup.getEmf().getEntityManager( setup.getSmf().getManagementAppId() );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UserInfo authedUser = setup.getMgmtSvc().verifyAdminUserPasswordCredentials( username, password );
 
@@ -543,7 +543,7 @@ public class ManagementServiceIT {
 
         em.addToDictionary( storedUser, DICTIONARY_CREDENTIALS, "password", info );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
 
         //verify authorization works
@@ -581,7 +581,7 @@ public class ManagementServiceIT {
         EntityManager em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId() );
 
         User storedUser = em.create( user );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
 
         UUID userId = storedUser.getUuid();
@@ -650,7 +650,7 @@ public class ManagementServiceIT {
 
         User storedUser = em.create( user );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UUID userId = storedUser.getUuid();
 
@@ -667,7 +667,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //verify authorization works
         authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword );
@@ -696,7 +696,7 @@ public class ManagementServiceIT {
 
         User storedUser = em.create( user );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UUID userId = storedUser.getUuid();
 
@@ -726,7 +726,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //verify authorization works
         authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword );
@@ -757,7 +757,7 @@ public class ManagementServiceIT {
 
         User storedUser = em.create( user );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UUID userId = storedUser.getUuid();
 
@@ -794,7 +794,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //verify authorization works
         authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
index 0e69d21..95e8c7d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
@@ -118,7 +118,7 @@ public class ExportServiceIT {
         organization = newOrgAppAdminRule.getOrganizationInfo();
         applicationId = newOrgAppAdminRule.getApplicationInfo().getId();
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
     }
 
 
@@ -272,7 +272,7 @@ public class ExportServiceIT {
 
             entity[i] = em.create( "users", userProperties );
         }
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
         //creates connections
         em.createConnection( em.get( new SimpleEntityRef( "user", entity[0].getUuid() ) ), "Vibrations",
             em.get( new SimpleEntityRef( "user", entity[1].getUuid() ) ) );
@@ -506,7 +506,7 @@ public class ExportServiceIT {
         JobExecution jobExecution = mock( JobExecution.class );
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
-       setup.getEntityIndex().refresh();
+       setup.getEntityIndex().refresh(applicationId);
 
         exportService.doExport( jobExecution );
 
@@ -577,7 +577,7 @@ public class ExportServiceIT {
         JobExecution jobExecution = mock( JobExecution.class );
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         exportService.doExport( jobExecution );
 
@@ -612,7 +612,7 @@ public class ExportServiceIT {
 
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
         em.createApplicationCollection( "baconators" );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //initialize user object to be posted
         Map<String, Object> userProperties = null;
@@ -645,7 +645,7 @@ public class ExportServiceIT {
         JobExecution jobExecution = mock( JobExecution.class );
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         exportService.doExport( jobExecution );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
index 4c78a1e..10b6d28 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
@@ -239,7 +239,7 @@ public class ImportCollectionIT {
             for ( Entity importedThing : importedThings ) {
                 emApp1.delete( importedThing );
             }
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(appId2);
 
 
             importedThings = emApp2.getCollection(
@@ -532,7 +532,7 @@ public class ImportCollectionIT {
         if ( retries >= maxRetries ) {
             throw new RuntimeException("Max retries reached");
         }
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
 
         return importEntity.getUuid();
@@ -547,7 +547,7 @@ public class ImportCollectionIT {
 
         logger.debug("\n\nExporting {} collection from application {}\n",
             collectionName, em.getApplication().getName() );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
 
         ExportService exportService = setup.getExportService();
@@ -591,7 +591,7 @@ public class ImportCollectionIT {
         logger.debug("\n\nCreating new {} collection in application {}\n",
             type, em.getApplication().getName());
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
 
         List<Entity> created = new ArrayList<>();
@@ -613,7 +613,7 @@ public class ImportCollectionIT {
         em.createConnection(new SimpleEntityRef(type, created.get(1).getUuid()),
             "related", new SimpleEntityRef(type, created.get(0).getUuid()));
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
index 57fadca..a1f19d4 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
@@ -99,13 +99,13 @@ public class ConnectionsServiceIT extends AbstractServiceIT {
       Entity bar = app.testRequest( ServiceAction.POST, 1, "bars" ).getEntity();
       assertNotNull( bar );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         //POST users/conn-user1/user2/UUID
       app.testRequest( ServiceAction.POST, 1, "foos", "foo", "bars", bar.getUuid() ); // should succeed
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         try {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
index 8fd5da3..d3c2436 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
@@ -68,13 +68,13 @@ public class GroupServiceIT extends AbstractServiceIT {
         app.createGroupRole( group.getUuid(), "admin", 0 );
         app.createGroupRole( group.getUuid(), "author", 0 );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         app.grantGroupRolePermission( group.getUuid(), "admin", "users:access:*" );
         app.grantGroupRolePermission( group.getUuid(), "admin", "groups:access:*" );
         app.grantGroupRolePermission( group.getUuid(), "author", "assets:access:*" );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         app.testDataRequest( ServiceAction.GET, "groups", group.getUuid(), "rolenames" );
         app.testDataRequest( ServiceAction.GET, "groups", group.getUuid(), "roles", "admin", "permissions" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
index a6723b7..8a0560a 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
@@ -199,7 +199,7 @@ public class RolesServiceIT extends AbstractServiceIT {
         ServiceResults results = app.invokeService( ServiceAction.DELETE, "roles", "manager" );
         assertEquals( 1, results.size() );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         // check role is gone
         Role role = app.get( app.getAlias( "role", "manager" ), Role.class );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
index 94271ce..3bb996c 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
@@ -37,7 +37,7 @@ public class UsersServiceIT extends AbstractServiceIT {
 
         Entity user = app.create( "user" );
         assertNotNull( user );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         app.testRequest( ServiceAction.POST, 1, "users", user.getUuid(), "roles", "admin" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index 9c2385f..fc80fdf 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -103,7 +103,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device2 = app.getEntityManager().get(e.getUuid(), Device.class);
         Map<String, Object> props = app.getEntityManager().getProperties(e);
         assertEquals(device2.getProperty(notifierKey), PUSH_TOKEN);
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create User
         user1 = new User();
@@ -121,7 +121,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         DefaultQueueManager qm = new DefaultQueueManager();
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         listener = new QueueListener(ns.getServiceManagerFactory(),ns.getEntityManagerFactory(), new Properties());
         listener.TEST_QUEUE_MANAGER = qm;
@@ -142,7 +142,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // create push notification //
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // give queue manager a query for loading 100 devices from an application (why?)
         app.clear();
@@ -177,7 +177,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // verify Query for FINISHED state
         query = Query.fromEquals("state", Notification.State.FINISHED.toString());
@@ -282,7 +282,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 .getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notification notification = app.getEntityManager().get(e.getUuid(),
                 Notification.class);
@@ -302,7 +302,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity entity = results.getEntitiesMap().get(notification.getUuid());
         assertNotNull(entity);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         try {
             e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
@@ -463,7 +463,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
                 .getEntity();
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         app.testRequest(ServiceAction.GET, 1, "notifiers", "apNs2");
 
@@ -478,7 +478,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device2.setProperty(key2, PUSH_TOKEN);
         app.getEntityManager().update(device2);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create push notification //
 
@@ -494,7 +494,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         e = app.testRequest(ServiceAction.POST, 1, "devices","notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notification notification = app.getEntityManager().get(e.getUuid(),  Notification.class);
         assertEquals(notification.getPayloads().get(notifierName), payload);
@@ -502,7 +502,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         // perform push //
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
     }
@@ -527,7 +527,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notifier notifier2 = app.getEntityManager().get(e.getUuid(), Notifier.class);
         assertEquals(notifier2.getName(), nameValue);
@@ -538,7 +538,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device1.setProperty(key2, PUSH_TOKEN);
         app.getEntityManager().update(device1);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create push notification //
 
@@ -554,7 +554,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notification notification = app.getEntityManager().get(e.getUuid(),
                 Notification.class);
@@ -564,12 +564,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         ns.addDevice(notification, device1);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // perform push //
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         checkReceipts(notification, 2);
     }
@@ -711,7 +711,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         assertEquals(user1Devices.size(),2);
         // create push notification //
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // give queue manager a query for loading 100 devices from an application (why?)
         app.clear();
@@ -746,7 +746,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // verify Query for FINISHED state
         query = Query.fromEquals("state", Notification.State.FINISHED.toString());
@@ -775,7 +775,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity entity = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
         Notifier notifier = app.getEntityManager().get(entity.getUuid(), Notifier.class);
         final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create a bunch of devices and add them to the notification
 
@@ -784,7 +784,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
             app.put(notifierKey, PUSH_TOKEN);
             app.put("name", "device"+i*10);
             app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-                    setup.getEntityIndex().refresh();
+                    setup.getEntityIndex().refresh(app.getId());
 
         }
 
@@ -799,7 +799,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         // create a notification
         entity = app.testRequest(ServiceAction.POST, 1,  "devices","notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", entity.getUuid());
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         final Notification notification = (Notification) entity.toTypedEntity();
 
@@ -823,63 +823,4 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     }
 
 
-    // todo: can't do the following tests here. do it in the REST tier...
-    // private Notification postNotification(String path) throws Exception {
-    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-    // String payload =
-    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
-    // Map<String, String> payloads = new HashMap<String, String>(1);
-    // payloads.put(notifier.getUuid().toString(), payload);
-    // properties.put("payloads", payloads);
-    //
-    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
-    // path).getEntity();
-    // Thread.sleep(1000); // this sucks
-    // Notification notification = app.getEntityManager().get(e, Notification.class);
-    // return notification;
-    // }
-    //
-    // @Test
-    // public void matrixPushDevice() throws Exception {
-    //
-    // Notification notification = postNotification("devices/" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 1);
-    // checkStatistics(notification, 1, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushViaUser() throws Exception {
-    //
-    // Notification notification = postNotification("users/" + user1.getName() +
-    // "/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushViaGroup() throws Exception {
-    //
-    // Notification notification = postNotification("devices/" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushDeviceQuery() throws Exception {
-    //
-    // Notification notification = postNotification("devices;ql=name=" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 1);
-    // checkStatistics(notification, 1, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushUserQuery() throws Exception {
-    //
-    // Notification notification = postNotification("users;ql=/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 8dafddd..63869ca 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -192,13 +192,13 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity e = app.testRequest(ServiceAction.POST, 1,"users",user.getUuid(), "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         // perform push //
         Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
         notification = scheduleNotificationAndWait(notification);
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         checkReceipts(notification, 1);
     }


[5/6] incubator-usergrid git commit: rest passing

Posted by sf...@apache.org.
rest passing


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

Branch: refs/heads/USERGRID-652
Commit: 3e45e11c3f6faddbd6bc19e4923acfacfca003a2
Parents: ec3060b
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jun 9 10:00:41 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jun 9 10:00:41 2015 -0600

----------------------------------------------------------------------
 .../org/apache/usergrid/rest/AbstractContextResource.java    | 7 ++-----
 .../org/apache/usergrid/rest/test/RefreshIndexResource.java  | 8 +++++++-
 .../usergrid/rest/test/resource2point0/ClientSetup.java      | 2 +-
 .../usergrid/rest/test/resource2point0/RestClient.java       | 6 ++++--
 4 files changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3e45e11c/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java
index cd73991..1494814 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/AbstractContextResource.java
@@ -62,8 +62,6 @@ public abstract class AbstractContextResource {
     };
     protected static final ObjectMapper mapper = new ObjectMapper();
 
-    private EntityIndex entityIndex;
-
 
     protected AbstractContextResource parent;
 
@@ -198,9 +196,8 @@ public abstract class AbstractContextResource {
         return new ApiResponse(properties);
     }
 
-    protected EntityIndex getEntityIndex(){
-        entityIndex = entityIndex == null ? injector.getInstance(EntityIndex.class) : entityIndex;
-        return entityIndex;
+    protected EntityManagerFactory getEmf(){
+        return emf;
     }
     /**
      * Next three new methods necessary to work around inexplicable problems with EntityHolder.

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3e45e11c/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
index 555d00c..1fdcee0 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/test/RefreshIndexResource.java
@@ -31,6 +31,7 @@ import javax.ws.rs.core.Response;
 import com.google.common.base.Optional;
 import org.apache.usergrid.persistence.EntityManager;
 
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.Scope;
@@ -65,8 +66,13 @@ public class RefreshIndexResource extends AbstractContextResource {
                 throw new UnsupportedOperationException();
             }
 
+            UUID appid = UUIDUtils.tryExtractUUID(appIdString);
+            if(appid == null){
+                throw new IllegalArgumentException("app id is null");
+            }
             // refresh the system apps or app lookup below may fail
-            getEntityIndex().refreshAsync().toBlocking().first();
+            EntityManager em = this.getEmf().getEntityManager(appid);
+            em.refreshIndex();
 
         } catch (Exception e) {
             logger.error("Error in refresh", e);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3e45e11c/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
index 6a0a781..4cf28e5 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/ClientSetup.java
@@ -165,7 +165,7 @@ public class ClientSetup implements TestRule {
     }
 
     public void refreshIndex() {
-        this.restClient.refreshIndex(getOrganizationName(),getAppName());
+        this.restClient.refreshIndex(getOrganizationName(),getAppName(),getAppUuid());
     }
 
     public RestClient getRestClient(){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3e45e11c/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
index 152e546..0d8f981 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource2point0/RestClient.java
@@ -28,6 +28,7 @@ import com.sun.jersey.api.client.config.DefaultClientConfig;
 import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
 
 import javax.ws.rs.core.MediaType;
+import java.util.UUID;
 
 
 /**
@@ -97,12 +98,13 @@ public class RestClient implements UrlResource {
     public TokenResource token(){
         return new TokenResource(context,this);
     }
-    public void refreshIndex(String orgname, String appName) {
+    public void refreshIndex(String orgname, String appName, String appid) {
         //TODO: add error checking and logging
         this.getResource().path( "/refreshindex" )
                 .queryParam( "org_name", orgname )
                 .queryParam( "app_name",appName )
-                .accept( MediaType.APPLICATION_JSON ).post();
+                .queryParam("app_id", appid)
+            .accept( MediaType.APPLICATION_JSON ).post();
     }
 
     public NamedResource pathResource(String path){


[6/6] incubator-usergrid git commit: rest back to a good failing state

Posted by sf...@apache.org.
rest back to a good failing state


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

Branch: refs/heads/USERGRID-652
Commit: 79d7fe9cbc01350de6315b2fbfd8e69f1715f1bd
Parents: 3e45e11
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jun 9 10:16:28 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Jun 9 10:16:28 2015 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java  | 1 -
 .../apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java  | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/79d7fe9c/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
index a57c42a..3910b22 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexFactoryImpl.java
@@ -54,7 +54,6 @@ public class EsEntityIndexFactoryImpl implements EntityIndexFactory{
                     indexBufferConsumer,
                     locationStrategy
                 );
-                index.initialize();
                 return index;
             }
         } );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/79d7fe9c/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 ea11b7f..590baf9 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
@@ -161,7 +161,7 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
             metricsFactory.getMeter( EsEntityIndexImpl.class, "delete.application.meter" );
         this.refreshIndexMeter = metricsFactory.getMeter(EsEntityIndexImpl.class,"refresh.meter");
         this.searchTimer = metricsFactory.getTimer( EsEntityIndexImpl.class, "search.timer" );
-
+        initialize();
     }
 
     @Override


[4/6] incubator-usergrid git commit: core passing

Posted by sf...@apache.org.
core passing


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

Branch: refs/heads/USERGRID-652
Commit: ec3060b9966fdace55579a04d568ea8c4ba6bd4a
Parents: 9af1637
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jun 8 17:49:25 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jun 8 17:49:25 2015 -0600

----------------------------------------------------------------------
 .../apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java  | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ec3060b9/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 1fd20e9..ea11b7f 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
@@ -169,8 +169,6 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
         final int numberOfShards = indexFig.getNumberOfShards();
         final int numberOfReplicas = indexFig.getNumberOfReplicas();
 
-        aliasCache.invalidate(alias);
-
         if (shouldInitialize()) {
             addIndex( null, numberOfShards, numberOfReplicas, indexFig.getWriteConsistencyLevel() );
         }


[2/6] incubator-usergrid git commit: refactor index cardinality in cp entitymanager

Posted by sf...@apache.org.
refactor index cardinality in cp entitymanager


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

Branch: refs/heads/USERGRID-652
Commit: d936cf3db3499fcfcd90d2114082d831e2e5aa3e
Parents: 588cd1f
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jun 8 14:25:31 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jun 8 14:25:31 2015 -0600

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpEntityManagerFactory.java    | 5 +++++
 .../java/org/apache/usergrid/corepersistence/CpSetup.java   | 9 +++++----
 .../apache/usergrid/persistence/EntityManagerFactory.java   | 2 ++
 .../src/test/java/org/apache/usergrid/CoreApplication.java  | 4 +---
 4 files changed, 13 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d936cf3d/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 9948b77..549426e 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
@@ -743,4 +743,9 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
        return getManagementIndex().getIndexHealth();
     }
+
+    @Override
+    public void initializeManagementIndex(){
+        getManagementIndex().initialize();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d936cf3d/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index c93d443..aace825 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -20,11 +20,13 @@ package org.apache.usergrid.corepersistence;
 import java.util.UUID;
 
 import com.google.inject.Binding;
+import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -71,7 +73,6 @@ public class CpSetup implements Setup {
     private final CassandraService cass;
 
     private final EntityManagerFactory emf;
-    private final EntityIndex entityIndex;
 
 
     /**
@@ -79,11 +80,11 @@ public class CpSetup implements Setup {
      *
      * @param emf the emf
      */
-    public CpSetup( final EntityManagerFactory emf, final CassandraService cassandraService, final Injector injector ) {
+    public CpSetup( final EntityManagerFactory emf,
+                    final CassandraService cassandraService, final Injector injector ) {
         this.emf = emf;
         this.cass = cassandraService;
         this.injector = injector;
-        this.entityIndex = injector.getInstance(EntityIndex.class);
 
     }
 
@@ -92,7 +93,7 @@ public class CpSetup implements Setup {
     public void init() throws Exception {
         //a no op, creating the injector creates the connections
         //init our index if required
-        this.entityIndex.initialize();
+        this.emf.initializeManagementIndex();
         setupStaticKeyspace();
         setupSystemKeyspace();
         createDefaultApplications();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d936cf3d/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 13034d0..6e77e6e 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
@@ -180,6 +180,8 @@ public interface EntityManagerFactory {
 
     public Health getIndexHealth();
 
+    void initializeManagementIndex();
+
     public interface ProgressObserver {
 
      public void onProgress( EntityRef entity);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d936cf3d/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index 217aeb9..e85077f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -56,7 +56,6 @@ public class CoreApplication implements Application, TestRule {
     protected CoreITSetup setup;
     protected EntityManager em;
     protected Map<String, Object> properties = new LinkedHashMap<String, Object>();
-    private EntityIndex entityIndex;
     private EntityIndexFactory entityIndexFactory;
     private AliasedEntityIndex applicationIndex;
     private EntityManager managementEm;
@@ -178,7 +177,6 @@ public class CoreApplication implements Application, TestRule {
 
         em = setup.getEmf().getEntityManager(id);
         Injector injector = setup.getInjector();
-        entityIndex = injector.getInstance(EntityIndex.class);
         IndexLocationStrategyFactory indexLocationStrategyFactory = injector.getInstance(IndexLocationStrategyFactory.class);
         entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
         applicationIndex =  entityIndexFactory.createEntityIndex(
@@ -234,7 +232,7 @@ public class CoreApplication implements Application, TestRule {
     @Override
     public synchronized void refreshIndex() {
         //Insert test entity and find it
-        entityIndex.refreshAsync().toBlocking().first();
+        setup.getEmf().refreshIndexes();
     }