You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/10/02 09:32:43 UTC

[12/13] git commit: Cleaned up IndexScope so that is no longer has an impedance mismatch with the batch API.

Cleaned up IndexScope so that is no longer has an impedance mismatch with the batch API.

Refactored edge naming for CP into it's own utility class

Moved categorization of edge types (collection|connection) into prefixes.  This will also type filtering in Cassandra when seeking edge types to populate meta data.


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

Branch: refs/heads/two-dot-o
Commit: e00551511413a0cd9a97621842294d0add331eb3
Parents: 0e18f57
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 2 01:23:51 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 2 01:23:51 2014 -0600

----------------------------------------------------------------------
 .../CpEntityIndexDeleteListener.java            |  5 +-
 .../corepersistence/CpEntityManager.java        | 22 ++------
 .../corepersistence/CpEntityManagerFactory.java | 21 +++-----
 .../usergrid/corepersistence/CpNamingUtils.java | 50 ++++++++---------
 .../corepersistence/CpRelationManager.java      | 35 ++++--------
 .../CpEntityIndexDeleteListenerTest.java        |  4 +-
 .../PerformanceEntityRebuildIndexTest.java      |  7 ++-
 .../collection/impl/CollectionScopeImpl.java    |  6 +--
 .../usergrid/persistence/index/IndexScope.java  |  2 +-
 .../index/impl/EsEntityIndexBatchImpl.java      | 27 +++++++---
 .../persistence/index/impl/IndexScopeImpl.java  |  8 +--
 .../persistence/index/impl/IndexingUtils.java   | 17 +++---
 .../index/utils/IndexValidationUtils.java       |  9 ----
 .../index/impl/CorePerformanceIT.java           | 56 ++++++++++++--------
 .../impl/EntityConnectionIndexImplTest.java     |  7 ++-
 .../persistence/index/impl/EntityIndexTest.java | 34 ++++++++----
 16 files changed, 150 insertions(+), 160 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListener.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListener.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListener.java
index cf3f4a6..3d4d661 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListener.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListener.java
@@ -27,6 +27,7 @@ import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityDel
 import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
 import org.apache.usergrid.persistence.core.entity.EntityVersion;
 import org.apache.usergrid.persistence.core.rx.ObservableIterator;
+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.IndexScope;
@@ -60,8 +61,8 @@ public class CpEntityIndexDeleteListener {
 
     public Observable<EntityVersion> receive(final MvccEntityDeleteEvent event) {
         final CollectionScope collectionScope = event.getCollectionScope();
-        final IndexScope indexScope = new IndexScopeImpl(collectionScope.getApplication(), collectionScope.getOwner(), collectionScope.getName());
-        final EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexScope);
+        final IndexScope indexScope = new IndexScopeImpl(collectionScope.getOwner(), collectionScope.getName());
+        final EntityIndex entityIndex = entityIndexFactory.createEntityIndex(new ApplicationScopeImpl( collectionScope.getApplication()));
         return Observable.create(new ObservableIterator<CandidateResult>("deleteEsIndexVersions") {
             @Override
             protected Iterator<CandidateResult> getIterator() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/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 777b041..d729c97 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
@@ -562,8 +562,7 @@ public class CpEntityManager implements EntityManager {
                     Set<String> collectionNames = collectionsByUuid.get( uuid );
                     for ( String coll : collectionNames ) {
 
-                        IndexScope indexScope = new IndexScopeImpl( 
-                                applicationScope.getApplication(), 
+                        IndexScope indexScope = new IndexScopeImpl(
                                 new SimpleId( uuid, ownerType ), 
                                 CpNamingUtils.getCollectionScopeNameFromCollectionName( coll ) );
 
@@ -576,15 +575,13 @@ public class CpEntityManager implements EntityManager {
 
 
             // deindex from default index scope
-            IndexScope defaultIndexScope = new IndexScopeImpl( 
-                    applicationScope.getApplication(), 
+            IndexScope defaultIndexScope = new IndexScopeImpl(
                     applicationScope.getApplication(),
                     CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() ) );
 
             batch.deindex(defaultIndexScope,  entity );
 
-            IndexScope allTypesIndexScope = new IndexScopeImpl( 
-                applicationScope.getApplication(), 
+            IndexScope allTypesIndexScope = new IndexScopeImpl(
                 applicationScope.getApplication(), 
                     CpNamingUtils.ALL_TYPES);
 
@@ -971,8 +968,7 @@ public class CpEntityManager implements EntityManager {
                 applicationScope.getApplication(), 
                 collectionName );
 
-        IndexScope defaultIndexScope = new IndexScopeImpl( 
-                applicationScope.getApplication(), 
+        IndexScope defaultIndexScope = new IndexScopeImpl(
                 applicationScope.getApplication(), 
                 CpNamingUtils.getCollectionScopeNameFromEntityType( entityRef.getType() ) );
 
@@ -2755,10 +2751,7 @@ public class CpEntityManager implements EntityManager {
         emf.refreshIndex();
 
         // refresh this Entity Manager's application's index
-        IndexScope indexScope = new IndexScopeImpl( 
-                applicationScope.getApplication(), applicationScope.getApplication(), "dummy" );
-
-        EntityIndex ei = managerCache.getEntityIndex( indexScope );
+        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         ei.refresh();
     }
 
@@ -2991,14 +2984,12 @@ public class CpEntityManager implements EntityManager {
 
         // Index the new connection in app|source|type context
         IndexScope indexScope = new IndexScopeImpl(
-                applicationScope.getApplication(),
                 sourceEntity.getId(),
                 CpNamingUtils.getConnectionScopeName( targetEntityType, connType ));
         batch.index(indexScope, targetEntity);
         
         // Index the new connection in app|scope|all-types context
         IndexScope allTypesIndexScope = new IndexScopeImpl(
-                applicationScope.getApplication(),
                 sourceEntity.getId(),
                 CpNamingUtils.ALL_TYPES);
 
@@ -3018,7 +3009,6 @@ public class CpEntityManager implements EntityManager {
 
         // index member into entity collection | type scope
         IndexScope collectionIndexScope = new IndexScopeImpl(
-                applicationScope.getApplication(),
                 collectionEntity.getId(),
                 CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
 
@@ -3026,7 +3016,6 @@ public class CpEntityManager implements EntityManager {
         
         // index member into entity | all-types scope
         IndexScope entityAllTypesScope = new IndexScopeImpl(
-                applicationScope.getApplication(),
                 collectionEntity.getId(),
                 CpNamingUtils.ALL_TYPES);
 
@@ -3035,7 +3024,6 @@ public class CpEntityManager implements EntityManager {
         // index member into application | all-types scope
         IndexScope appAllTypesScope = new IndexScopeImpl(
                 applicationScope.getApplication(),
-                applicationScope.getApplication(),
                 CpNamingUtils.ALL_TYPES);
 
         batch.index(appAllTypesScope, memberEntity);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/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 f24f26b..845d798 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
@@ -558,22 +558,17 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         // refresh special indexes without calling EntityManager refresh because stack overflow 
        
         // system app
-        IndexScope sscope = new IndexScopeImpl( 
-            new SimpleId( SYSTEM_APP_ID, "application"), 
-            new SimpleId( SYSTEM_APP_ID, "application"), "dummy");
-        managerCache.getEntityIndex( sscope ).refresh();
-       
+
+        managerCache.getEntityIndex( new ApplicationScopeImpl( new SimpleId( SYSTEM_APP_ID, "application" ) ) )
+                    .refresh();
+
         // default app
-        IndexScope mscope = new IndexScopeImpl( 
-            new SimpleId( getManagementAppId(), "application"), 
-            new SimpleId( getManagementAppId(), "application"), "dummy");
-        managerCache.getEntityIndex( mscope ).refresh();
+        managerCache.getEntityIndex( new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) )
+                    .refresh();
 
         // management app
-        IndexScope dscope = new IndexScopeImpl( 
-            new SimpleId( getDefaultAppId(), "application"), 
-            new SimpleId( getDefaultAppId(), "application"), "dummy");
-        managerCache.getEntityIndex( dscope ).refresh();
+        managerCache.getEntityIndex( new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) )
+                    .refresh();
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpNamingUtils.java
index 60cec72..45c39ab 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpNamingUtils.java
@@ -41,47 +41,48 @@ public class CpNamingUtils {
      */
     static final String EDGE_CONN_SUFFIX = "zzzconnzzz";
 
+
     static String getCollectionScopeNameFromEntityType( String type ) {
-          String csn = EDGE_COLL_SUFFIX + Schema.defaultCollectionName( type );
-          return csn.toLowerCase();
-      }
+        String csn = EDGE_COLL_SUFFIX + Schema.defaultCollectionName( type );
+        return csn.toLowerCase();
+    }
 
 
-      static String getCollectionScopeNameFromCollectionName( String name ) {
-          String csn = EDGE_COLL_SUFFIX + name ;
-          return csn.toLowerCase();
-      }
+    static String getCollectionScopeNameFromCollectionName( String name ) {
+        String csn = EDGE_COLL_SUFFIX + name;
+        return csn.toLowerCase();
+    }
 
 
-      static String getConnectionScopeName( String entityType, String connectionType ) {
-          String csn = EDGE_CONN_SUFFIX + connectionType + entityType ;
-          return csn.toLowerCase();
-      }
+    static String getConnectionScopeName( String entityType, String connectionType ) {
+        String csn = EDGE_CONN_SUFFIX + connectionType + entityType;
+        return csn.toLowerCase();
+    }
 
-      static boolean isCollectionEdgeType( String type )  {
-          return type.startsWith( EDGE_COLL_SUFFIX );
-      }
 
-      static boolean isConnectionEdgeType( String type )  {
-          return type.startsWith( EDGE_CONN_SUFFIX );
-      }
+    static boolean isCollectionEdgeType( String type ) {
+        return type.startsWith( EDGE_COLL_SUFFIX );
+    }
 
 
+    static boolean isConnectionEdgeType( String type ) {
+        return type.startsWith( EDGE_CONN_SUFFIX );
+    }
+
 
     static public String getConnectionType( String edgeType ) {
-        String[] parts = edgeType.split("\\|");
+        String[] parts = edgeType.split( "\\|" );
         return parts[1];
     }
 
 
     static public String getCollectionName( String edgeType ) {
-        String[] parts = edgeType.split("\\|");
+        String[] parts = edgeType.split( "\\|" );
         return parts[1];
     }
 
 
-
-    static String getEdgeTypeFromConnectionType( String connectionType) {
+    static String getEdgeTypeFromConnectionType( String connectionType ) {
 
         if ( connectionType != null ) {
             String csn = EDGE_CONN_SUFFIX + "|" + connectionType;
@@ -91,16 +92,15 @@ public class CpNamingUtils {
         return null;
     }
 
-    static String getEdgeTypeFromCollectionName( String collectionName) {
 
-        if ( collectionName != null  ) {
+    static String getEdgeTypeFromCollectionName( String collectionName ) {
+
+        if ( collectionName != null ) {
             String csn = EDGE_COLL_SUFFIX + "|" + collectionName;
             return csn;
         }
 
 
-
         return null;
     }
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index ca01ddd..5f595f4 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -396,7 +396,6 @@ public class CpRelationManager implements RelationManager {
 
                     String collName = CpNamingUtils.getCollectionName( edge.getType() );
                     indexScope = new IndexScopeImpl(
-                        applicationScope.getApplication(),
                         new SimpleId(sourceEntity.getUuid(), sourceEntity.getType()),
                         CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
 
@@ -404,7 +403,6 @@ public class CpRelationManager implements RelationManager {
 
                     String connName = CpNamingUtils.getCollectionName( edge.getType() );
                     indexScope = new IndexScopeImpl(
-                        applicationScope.getApplication(),
                         new SimpleId(sourceEntity.getUuid(), sourceEntity.getType()),
                         CpNamingUtils.getConnectionScopeName( cpHeadEntity.getId().getType(), connName ));
                 }
@@ -414,7 +412,6 @@ public class CpRelationManager implements RelationManager {
                 // reindex the entity in the source entity's all-types index
                 
                 indexScope = new IndexScopeImpl(
-                    applicationScope.getApplication(),
                     new SimpleId(sourceEntity.getUuid(), sourceEntity.getType()),
                         CpNamingUtils.ALL_TYPES);
 
@@ -781,7 +778,6 @@ public class CpRelationManager implements RelationManager {
 
         // remove item from collection index
         IndexScope indexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
             CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
 
@@ -789,7 +785,6 @@ public class CpRelationManager implements RelationManager {
 
         // remove collection from item index 
         IndexScope itemScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             memberEntity.getId(), 
             CpNamingUtils.getCollectionScopeNameFromCollectionName(
                     Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ));
@@ -892,17 +887,15 @@ public class CpRelationManager implements RelationManager {
         }
 
         IndexScope indexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
             CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
 
         EntityIndex ei = managerCache.getEntityIndex(applicationScope);
       
-        logger.debug("Searching scope {}:{}:{}",
-            new String[] { 
-                indexScope.getApplication().toString(), 
+        logger.debug("Searching scope {}:{}",
+
                 indexScope.getOwner().toString(),
-                indexScope.getName() }); 
+                indexScope.getName() );
 
         query.setEntityType( collection.getType() );
         query = adjustQuery( query );
@@ -1016,7 +1009,6 @@ public class CpRelationManager implements RelationManager {
 
         // Index the new connection in app|source|type context
         IndexScope indexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
             CpNamingUtils.getConnectionScopeName( connectedEntityRef.getType(), connectionType ));
 
@@ -1024,7 +1016,6 @@ public class CpRelationManager implements RelationManager {
 
         // Index the new connection in app|scope|all-types context
         IndexScope allTypesIndexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
                 CpNamingUtils.ALL_TYPES);
         batch.index(allTypesIndexScope,  targetEntity );
@@ -1240,14 +1231,12 @@ public class CpRelationManager implements RelationManager {
 
         // Deindex the connection in app|source|type context
         IndexScope indexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
             CpNamingUtils.getConnectionScopeName( targetEntity.getId().getType(), connectionType ));
         batch.deindex( indexScope , targetEntity );
 
         // Deindex the connection in app|source|type context
         IndexScope allTypesIndexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
                 CpNamingUtils.ALL_TYPES);
 
@@ -1306,17 +1295,15 @@ public class CpRelationManager implements RelationManager {
             }
 
             IndexScope indexScope = new IndexScopeImpl(
-                applicationScope.getApplication(), 
                 cpHeadEntity.getId(), 
                 scopeName);
 
             final EntityIndex ei = managerCache.getEntityIndex(applicationScope);
 
         
-            logger.debug("Searching connected entities from scope {}:{}:{}", new String[] { 
-                indexScope.getApplication().toString(), 
+            logger.debug("Searching connected entities from scope {}:{}",
                 indexScope.getOwner().toString(),
-                indexScope.getName()}); 
+                indexScope.getName());
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1411,16 +1398,14 @@ public class CpRelationManager implements RelationManager {
 
             // search across all types of collections of the head-entity
             IndexScope indexScope = new IndexScopeImpl(
-                applicationScope.getApplication(), 
                 cpHeadEntity.getId(), 
                     CpNamingUtils.ALL_TYPES);
 
             EntityIndex ei = managerCache.getEntityIndex(applicationScope);
         
-            logger.debug("Searching connections from the all-types scope {}:{}:{}", new String[] { 
-                indexScope.getApplication().toString(), 
+            logger.debug("Searching connections from the all-types scope {}:{}",
                 indexScope.getOwner().toString(),
-                indexScope.getName()}); 
+                indexScope.getName());
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search(indexScope,  query );
@@ -1429,15 +1414,13 @@ public class CpRelationManager implements RelationManager {
         }
 
         IndexScope indexScope = new IndexScopeImpl(
-            applicationScope.getApplication(), 
             cpHeadEntity.getId(), 
             CpNamingUtils.getConnectionScopeName( query.getEntityType(), query.getConnectionType() ));
         EntityIndex ei = managerCache.getEntityIndex(applicationScope);
     
-        logger.debug("Searching connections from the '{}' scope {}:{}:{}", new String[] { 
-            indexScope.getApplication().toString(), 
+        logger.debug("Searching connections from the scope {}:{}",
             indexScope.getOwner().toString(),
-            indexScope.getName()}); 
+            indexScope.getName());
 
         query = adjustQuery( query );
         CandidateResults crs = ei.search( indexScope, query );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListenerTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListenerTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListenerTest.java
index d59432b..e7675d6 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListenerTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/CpEntityIndexDeleteListenerTest.java
@@ -28,12 +28,14 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import org.apache.usergrid.Application;
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.mvcc.entity.MvccEntity;
 import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityDeleteEvent;
 import org.apache.usergrid.persistence.collection.mvcc.entity.impl.MvccEntityImpl;
 import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
 import org.apache.usergrid.persistence.core.entity.EntityVersion;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndexBatch;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
@@ -81,7 +83,7 @@ public class CpEntityIndexDeleteListenerTest {
         when(scope.getOwner()).thenReturn(entityId);
         when(scope.getName()).thenReturn("test");
         when(scope.getApplication()).thenReturn(entityId);
-        when(eif.createEntityIndex(any(IndexScope.class))).thenReturn(entityIndex);
+        when(eif.createEntityIndex(any(ApplicationScope.class))).thenReturn(entityIndex);
 
         final EntityIndexBatch batch = mock(EntityIndexBatch.class);
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index acfb1e0..36113e1 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -42,6 +42,8 @@ import java.util.UUID;
 import org.apache.usergrid.cassandra.Concurrent;
 import org.apache.usergrid.corepersistence.CpEntityManagerFactory;
 import org.apache.usergrid.corepersistence.CpSetup;
+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.IndexScope;
@@ -224,8 +226,9 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
         EntityIndexFactory eif = injector.getInstance( EntityIndexFactory.class );
 
         Id appId = new SimpleId( appUuid, "application");
-        IndexScope is = new IndexScopeImpl( appId, appId, "application");
-        EntityIndex ei = eif.createEntityIndex(is);
+        ApplicationScope scope = new ApplicationScopeImpl( appId );
+        IndexScope is = new IndexScopeImpl( appId, "application");
+        EntityIndex ei = eif.createEntityIndex(scope);
         EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;
 
         eeii.deleteIndex();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionScopeImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionScopeImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionScopeImpl.java
index ce74f6a..9e96230 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionScopeImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/CollectionScopeImpl.java
@@ -68,12 +68,12 @@ public class CollectionScopeImpl extends ApplicationScopeImpl implements Collect
             return false;
         }
 
-        final CollectionScopeImpl that = ( CollectionScopeImpl ) o;
+        final CollectionScope that = ( CollectionScope ) o;
 
-        if ( !name.equals( that.name ) ) {
+        if ( !name.equals( that.getName() ) ) {
             return false;
         }
-        if ( !ownerId.equals( that.ownerId ) ) {
+        if ( !ownerId.equals( that.getOwner() ) ) {
             return false;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java
index e2361e3..9fbb7f5 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexScope.java
@@ -23,7 +23,7 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.model.entity.Id;
 
 
-public interface IndexScope extends ApplicationScope {
+public interface IndexScope {
 
     /**
      * @return The name of the index. If you use pluralization for you names vs types,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
index 93f0e41..a1a15dd 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.elasticsearch.action.bulk.BulkItemResponse;
 import org.elasticsearch.action.bulk.BulkRequestBuilder;
 import org.elasticsearch.action.bulk.BulkResponse;
 import org.elasticsearch.client.AdminClient;
@@ -114,13 +115,13 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
     public EntityIndexBatch index( final IndexScope indexScope, final Entity entity ) {
 
 
-        IndexValidationUtils.validateScopeMatch( indexScope, applicationScope );
+        IndexValidationUtils.validateIndexScope( indexScope );
 
         final String indexType = createCollectionScopeTypeName( indexScope );
 
         if ( log.isDebugEnabled() ) {
             log.debug( "Indexing entity {}:{} in scope\n   app {}\n   owner {}\n   name {}\n   type {}", new Object[] {
-                    entity.getId().getType(), entity.getId().getUuid(), indexScope.getApplication(),
+                    entity.getId().getType(), entity.getId().getUuid(), applicationScope.getApplication(),
                     indexScope.getOwner(), indexScope.getName(), indexType
             } );
         }
@@ -153,13 +154,13 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
     @Override
     public EntityIndexBatch deindex( final IndexScope indexScope, final Id id, final UUID version ) {
 
-        IndexValidationUtils.validateScopeMatch( indexScope, applicationScope );
+        IndexValidationUtils.validateIndexScope( indexScope );
 
         final String indexType = createCollectionScopeTypeName( indexScope );
 
         if ( log.isDebugEnabled() ) {
             log.debug( "De-indexing entity {}:{} in scope\n   app {}\n   owner {}\n   name {} type {}", new Object[] {
-                    id.getType(), id.getUuid(), indexScope.getApplication(), indexScope.getOwner(),
+                    id.getType(), id.getUuid(), applicationScope.getApplication(), indexScope.getOwner(),
                     indexScope.getName(), indexType
             } );
         }
@@ -201,10 +202,19 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
      * Execute the request, check for errors, then re-init the batch for future use
      */
     private void execute( final BulkRequestBuilder request ) {
-        final BulkResponse response = request.execute().actionGet();
 
-        if ( response.hasFailures() ) {
-            throw new RuntimeException( "Unable to index documents.  Errors are :" + response.buildFailureMessage() );
+        //nothing to do, we haven't added anthing to the index
+        if(request.numberOfActions() == 0){
+            return;
+        }
+
+        final BulkResponse responses = request.execute().actionGet();
+
+        for ( BulkItemResponse response : responses ) {
+            if ( response.isFailed() ) {
+                throw new RuntimeException(
+                        "Unable to index documents.  Errors are :" + response.getFailure().getMessage() );
+            }
         }
 
         initBatch();
@@ -259,7 +269,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch {
         }
         catch ( IOException ex ) {
             throw new RuntimeException(
-                    "Exception initing type " + typeName + " in app " + indexScope.getApplication().toString() );
+                    "Exception initializing type " + typeName + " in app " + applicationScope.getApplication()
+                                                                                             .toString() );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
index 738e734..45cc8dd 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexScopeImpl.java
@@ -24,13 +24,11 @@ import org.apache.usergrid.persistence.model.entity.Id;
 
 
 public class IndexScopeImpl implements IndexScope {
-    private final Id appId;
     private final Id ownerId;
     private final String type;
 
 
-    public IndexScopeImpl( final Id appId, final Id ownerId, final String type ) {
-        this.appId = appId;
+    public IndexScopeImpl( final Id ownerId, final String type ) {
         this.ownerId = ownerId;
         this.type = type;
 
@@ -50,8 +48,4 @@ public class IndexScopeImpl implements IndexScope {
     }
 
 
-    @Override
-    public Id getApplication() {
-        return appId;
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
index d607700..8dbaa0d 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
@@ -54,11 +54,8 @@ public class IndexingUtils {
       */
      public static String createCollectionScopeTypeName( IndexScope scope ) {
          StringBuilder sb = new StringBuilder();
-         String sep = DOC_TYPE_SEPARATOR;
-         sb.append( scope.getApplication().getUuid() ).append(sep);
-         sb.append( scope.getApplication().getType() ).append(sep);
-         sb.append( scope.getOwner().getUuid() ).append(sep);
-         sb.append( scope.getOwner().getType() ).append(sep);
+         sb.append( scope.getOwner().getUuid() ).append(DOC_TYPE_SEPARATOR);
+         sb.append( scope.getOwner().getType() ).append(DOC_TYPE_SEPARATOR);
          sb.append( scope.getName() );
          return sb.toString();
      }
@@ -74,9 +71,8 @@ public class IndexingUtils {
     public static String createIndexName(
             String prefix, ApplicationScope applicationScope) {
         StringBuilder sb = new StringBuilder();
-        String sep = INDEX_NAME_SEPARATOR;
-        sb.append( prefix ).append(sep);
-        sb.append( applicationScope.getApplication().getUuid() ).append(sep);
+        sb.append( prefix ).append(INDEX_NAME_SEPARATOR);
+        sb.append( applicationScope.getApplication().getUuid() ).append(INDEX_NAME_SEPARATOR);
         sb.append( applicationScope.getApplication().getType() );
         return sb.toString();
     }
@@ -101,9 +97,8 @@ public class IndexingUtils {
      */
     public static String createIndexDocId(Id entityId, UUID version) {
         StringBuilder sb = new StringBuilder();
-        String sep = DOC_ID_SEPARATOR;
-        sb.append( entityId.getUuid() ).append(sep);
-        sb.append( entityId.getType() ).append(sep);
+        sb.append( entityId.getUuid() ).append(DOC_ID_SEPARATOR);
+        sb.append( entityId.getType() ).append(DOC_ID_SEPARATOR);
         sb.append( version.toString() );
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
index d6080de..7ed546f 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/utils/IndexValidationUtils.java
@@ -47,17 +47,8 @@ public class IndexValidationUtils {
 
         verifyString( scope.getName(), "name" );
 
-        validateApplicationScope( scope );
     }
 
 
-    /**
-     * Validate the scope in the index matches the application scope
-     * @param indexScope
-     * @param scope
-     */
-    public static void validateScopeMatch(final IndexScope indexScope,final ApplicationScope scope){
-        Preconditions.checkArgument( scope.equals( indexScope ) );
-    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
index c4f8f44..f2aab2a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java
@@ -32,6 +32,8 @@ import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
 import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.core.cassandra.CassandraRule;
+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.EntityIndexBatch;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
@@ -54,6 +56,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
+
 /**
  * TODO: make CorePerformanceIT configurable, add CHOP markup.
  */
@@ -93,20 +96,26 @@ public class CorePerformanceIT extends BaseIT {
         ecmf = injector.getInstance( EntityCollectionManagerFactory.class );
         ecif = injector.getInstance( EntityIndexFactory.class );
 
+        final ApplicationScope scope = new ApplicationScopeImpl( new SimpleId( "application" ) );
+
         log.info("Start Data Load");
-        List<IndexScope> scopes = loadData();
+
+        List<IndexScope> scopes = loadData(scope);
+
         log.info("Finish Data Load");
 
         log.info("Start Data Read");
-        readData( scopes );
+
+
+        readData( scope, scopes );
         log.info("Finish Data Read");
 
-        runSelectedQueries( scopes );
+        runSelectedQueries( scope, scopes );
 
     }
 
 
-    private List<IndexScope> loadData() throws InterruptedException {
+    private List<IndexScope> loadData(final ApplicationScope applicationScope) throws InterruptedException {
 
         long time = new Date().getTime();
 
@@ -118,10 +127,10 @@ public class CorePerformanceIT extends BaseIT {
 
             String appName = "app-" + j + "-" + time;
             Id appId = new SimpleId( appName );
-            IndexScope indexScope = new IndexScopeImpl( appId, appId, "reviews" );
+            IndexScope indexScope = new IndexScopeImpl( appId, "reviews" );
             scopes.add( indexScope );
 
-            Thread t = new Thread( new DataLoader( indexScope ) );
+            Thread t = new Thread( new DataLoader( applicationScope, indexScope ) );
             t.start();
             threads.add( t );
         }
@@ -135,12 +144,12 @@ public class CorePerformanceIT extends BaseIT {
     }
 
 
-    private void readData( List<IndexScope> scopes ) throws InterruptedException {
+    private void readData(final ApplicationScope applicationScope,  List<IndexScope> scopes ) throws InterruptedException {
 
         List<Thread> threads = new ArrayList<Thread>();
         for ( IndexScope scope : scopes ) {
 
-            Thread t = new Thread( new DataReader( scope ));
+            Thread t = new Thread( new DataReader( applicationScope, scope ));
             t.start();
             threads.add(t);
         }
@@ -153,17 +162,18 @@ public class CorePerformanceIT extends BaseIT {
 
 
     static class DataReader implements Runnable {
-        IndexScope indexScope;
+        final ApplicationScope scope;
+       final  IndexScope indexScope;
 
-        public DataReader( IndexScope indexScope ) {
+        public DataReader( final ApplicationScope scope, IndexScope indexScope ) {
+            this.scope = scope;
             this.indexScope = indexScope;
         }
 
         public void run() {
 
-            EntityIndex eci =   ecif.createEntityIndex( indexScope );
-            EntityCollectionManager ecm = ecmf.createCollectionManager( new CollectionScopeImpl( 
-                indexScope.getApplication(), indexScope.getOwner(), indexScope.getName() ) );
+            EntityIndex eci =   ecif.createEntityIndex( scope);
+            EntityCollectionManager ecm = ecmf.createCollectionManager( new CollectionScopeImpl( scope.getApplication(), indexScope.getOwner(), indexScope.getName() ) );
 
             Query query = Query.fromQL( "review_score > 0"); // get all reviews;
             query.withLimit( maxEntities < 1000 ? maxEntities : 1000 );
@@ -192,18 +202,20 @@ public class CorePerformanceIT extends BaseIT {
 
 
     static class DataLoader implements Runnable {
-        IndexScope indexScope;
+        final ApplicationScope applicationScope;
+        final IndexScope indexScope;
 
-        public DataLoader( IndexScope indexScope ) {
+        public DataLoader( final ApplicationScope applicationScope, IndexScope indexScope ) {
+            this.applicationScope = applicationScope;
             this.indexScope = indexScope;
         }
 
         public void run() {
 
             CollectionScope collectionScope = new CollectionScopeImpl( 
-                    indexScope.getApplication(), indexScope.getOwner(), indexScope.getName() );
+                    applicationScope.getApplication(), indexScope.getOwner(), indexScope.getName() );
             EntityCollectionManager ecm = ecmf.createCollectionManager(collectionScope );
-            EntityIndex eci = ecif.createEntityIndex(indexScope );
+            EntityIndex eci = ecif.createEntityIndex(applicationScope );
 
             FileReader fr;
             try {
@@ -255,7 +267,7 @@ public class CorePerformanceIT extends BaseIT {
                                 log.info("Indexed {} reviews in {} / {} ", 
                                     new Object[] { 
                                         count, 
-                                        indexScope.getApplication(), 
+                                            applicationScope,
                                         indexScope.getOwner() } );
                             }
                             continue;
@@ -293,14 +305,14 @@ public class CorePerformanceIT extends BaseIT {
     }   
 
 
-    public void runSelectedQueries( List<IndexScope> indexScopes ) {
+    public void runSelectedQueries(final ApplicationScope scope,  List<IndexScope> indexScopes ) {
 
         for ( IndexScope indexScope : indexScopes ) {
 
 
-            CollectionScope scope = new CollectionScopeImpl( 
-                    indexScope.getApplication(), indexScope.getOwner(), indexScope.getName() );
-            EntityIndex eci = ecif.createEntityIndex(indexScope );
+            CollectionScope collectionScope = new CollectionScopeImpl(
+                    scope.getApplication(), indexScope.getOwner(), indexScope.getName() );
+            EntityIndex eci = ecif.createEntityIndex(scope );
 
             // TODO: come up with more and more complex queries for CorePerformanceIT
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
index 5fb02f2..62910bc 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java
@@ -35,6 +35,8 @@ import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.collection.util.EntityUtils;
 import org.apache.usergrid.persistence.core.cassandra.CassandraRule;
 import org.apache.usergrid.persistence.core.cassandra.ITRunner;
+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.EntityIndexBatch;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
@@ -76,6 +78,7 @@ public class EntityConnectionIndexImplTest extends BaseIT {
     public void testBasicOperation() throws IOException {
 
         Id appId = new SimpleId( "application" );
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
         // create a muffin
         CollectionScope muffinScope = new CollectionScopeImpl( appId, appId, "muffins" );
@@ -103,9 +106,9 @@ public class EntityConnectionIndexImplTest extends BaseIT {
 
         // index connection of "person Dave likes Large Blueberry muffin"
 
-        IndexScope scope = new IndexScopeImpl( appId, person.getId(), "likes" );
+        IndexScope scope = new IndexScopeImpl(  person.getId(), "likes" );
 
-        EntityIndex personLikesIndex = ecif.createEntityIndex( scope );
+        EntityIndex personLikesIndex = ecif.createEntityIndex( applicationScope );
 
         EntityIndexBatch batch = personLikesIndex.createBatch();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e0055151/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 e01c45d..78cb1ae 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
@@ -41,6 +41,8 @@ import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.collection.util.EntityUtils;
 import org.apache.usergrid.persistence.core.cassandra.CassandraRule;
 import org.apache.usergrid.persistence.core.cassandra.ITRunner;
+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.EntityIndexBatch;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
@@ -93,10 +95,12 @@ public class EntityIndexTest extends BaseIT {
 
         Id appId = new SimpleId( "application" );
 
-        IndexScope indexScope = new IndexScopeImpl( appId, appId, "things" );
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
+        IndexScope indexScope = new IndexScopeImpl( appId, "things" );
 
-        EntityIndex entityIndex = cif.createEntityIndex( indexScope );
+
+        EntityIndex entityIndex = cif.createEntityIndex( applicationScope );
 
         InputStream is = this.getClass().getResourceAsStream( "/sample-large.json" );
         ObjectMapper mapper = new ObjectMapper();
@@ -145,9 +149,12 @@ public class EntityIndexTest extends BaseIT {
     public void testDeindex() {
 
         Id appId = new SimpleId( "application" );
-        IndexScope indexScope = new IndexScopeImpl( appId, appId, "fastcars" );
 
-        EntityIndex entityIndex = cif.createEntityIndex( indexScope );
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
+
+        IndexScope indexScope = new IndexScopeImpl( appId, "fastcars" );
+
+        EntityIndex entityIndex = cif.createEntityIndex( applicationScope );
 
         Map entityMap = new HashMap() {{
             put( "name", "Ferrari 212 Inter" );
@@ -269,12 +276,13 @@ public class EntityIndexTest extends BaseIT {
         Id appId = new SimpleId( "application" );
         Id ownerId = new SimpleId( "owner" );
 
-        IndexScope indexScope = new IndexScopeImpl( appId, ownerId, "user" );
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
 
-        CollectionScope scope = new CollectionScopeImpl( appId, ownerId, "user" );
+        IndexScope indexScope = new IndexScopeImpl( ownerId, "user" );
 
 
-        EntityIndex entityIndex = cif.createEntityIndex( indexScope );
+
+        EntityIndex entityIndex = cif.createEntityIndex( applicationScope );
 
         final String middleName = "middleName" + UUIDUtils.newTimeUUID();
         Map<String, Object> properties = new LinkedHashMap<String, Object>();
@@ -319,9 +327,11 @@ public class EntityIndexTest extends BaseIT {
         Id appId = new SimpleId( "application" );
         Id ownerId = new SimpleId( "owner" );
 
-        IndexScope appScope = new IndexScopeImpl( appId, ownerId, "user" );
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
+
+        IndexScope appScope = new IndexScopeImpl( ownerId, "user" );
 
-        EntityIndex ei = cif.createEntityIndex( appScope );
+        EntityIndex ei = cif.createEntityIndex( applicationScope );
 
         final String middleName = "middleName" + UUIDUtils.newTimeUUID();
 
@@ -360,9 +370,11 @@ public class EntityIndexTest extends BaseIT {
 
         Id appId = new SimpleId( "entityindextest" );
         Id ownerId = new SimpleId( "multivaluedtype" );
-        IndexScope appScope = new IndexScopeImpl( appId, ownerId, "user" );
+        ApplicationScope applicationScope = new ApplicationScopeImpl( appId );
+
+        IndexScope appScope = new IndexScopeImpl( ownerId, "user" );
 
-        EntityIndex ei = cif.createEntityIndex( appScope );
+        EntityIndex ei = cif.createEntityIndex( applicationScope );
 
         // Bill has favorites as string, age as string and retirement goal as number
         Map billMap = new HashMap() {{