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 2014/10/29 17:29:39 UTC

[1/9] git commit: Restoring some semblance of my original formatting, take it easy with that auto-formatter folks!

Repository: incubator-usergrid
Updated Branches:
  refs/heads/pushy_4-0 25e36e69c -> 78e34b2bf


Restoring some semblance of my original formatting, take it easy with that auto-formatter folks!


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

Branch: refs/heads/pushy_4-0
Commit: 3771e3f933f4d13963b16507389a750c08024c90
Parents: 960ce6b
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Oct 28 11:21:05 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Oct 28 11:21:05 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 889 ++++++++++++-------
 1 file changed, 555 insertions(+), 334 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3771e3f9/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 96f0e1e..8c0d886 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
@@ -189,8 +189,11 @@ public class CpRelationManager implements RelationManager {
     public CpRelationManager() {}
 
 
-    public CpRelationManager init( EntityManager em, CpEntityManagerFactory emf, UUID applicationId,
-                                   EntityRef headEntity, IndexBucketLocator indexBucketLocator ) {
+    public CpRelationManager init( EntityManager em,
+            CpEntityManagerFactory emf,
+            UUID applicationId,
+            EntityRef headEntity, 
+            IndexBucketLocator indexBucketLocator ) {
 
         Assert.notNull( em, "Entity manager cannot be null" );
         Assert.notNull( emf, "Entity manager factory cannot be null" );
@@ -212,21 +215,25 @@ public class CpRelationManager implements RelationManager {
         this.indexBucketLocator = indexBucketLocator; // TODO: this also
 
         // load the Core Persistence version of the head entity as well
-        this.headEntityScope =
-                new CollectionScopeImpl( this.applicationScope.getApplication(), this.applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
+        this.headEntityScope = new CollectionScopeImpl( 
+            this.applicationScope.getApplication(), 
+            this.applicationScope.getApplication(),
+            CpNamingUtils.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
 
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( headEntityScope );
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Loading head entity {}:{} from scope\n   app {}\n   owner {}\n   name {}", new Object[] {
-                            headEntity.getType(), headEntity.getUuid(), headEntityScope.getApplication(),
-                            headEntityScope.getOwner(), headEntityScope.getName()
-                    } );
+            logger.debug( "Loading head entity {}:{} from scope\n   app {}\n   owner {}\n   name {}",
+                new Object[] { headEntity.getType(),
+                    headEntity.getUuid(),
+                    headEntityScope.getApplication(),
+                    headEntityScope.getOwner(),
+                    headEntityScope.getName()
+                } );
         }
 
         //TODO PERFORMANCE why are we loading this again here?
-        this.cpHeadEntity = ecm.load( new SimpleId( headEntity.getUuid(), headEntity.getType() ) ).toBlocking()
-                               .lastOrDefault( null );
+        this.cpHeadEntity = ecm.load( new SimpleId( 
+                headEntity.getUuid(), headEntity.getType() ) ).toBlocking() .lastOrDefault( null );
 
         // commented out because it is possible that CP entity has not been created yet
         Assert.notNull( cpHeadEntity, "cpHeadEntity cannot be null" );
@@ -245,12 +252,14 @@ public class CpRelationManager implements RelationManager {
 
         String edgeTypePrefix = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName );
 
-        logger.debug( "getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}", new Object[] {
-                        edgeTypePrefix, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid()
-                } );
+        logger.debug( "getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}",
+            new Object[] { edgeTypePrefix,
+                cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid() 
+            } ); 
 
-        Observable<String> types =
-                gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix, null ) );
+        Observable<String> types = gm.getEdgeTypesFromSource( 
+            new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix, null ) );
 
         Iterator<String> iter = types.toBlockingObservable().getIterator();
         while ( iter.hasNext() ) {
@@ -267,7 +276,8 @@ public class CpRelationManager implements RelationManager {
         //Map<EntityRef, Set<String>> containerEntities = getContainers(-1, "owns", null);
         Map<EntityRef, Set<String>> containerEntities = getContainers();
 
-        Map<String, Map<UUID, Set<String>>> owners = new LinkedHashMap<String, Map<UUID, Set<String>>>();
+        Map<String, Map<UUID, Set<String>>> owners = 
+                new LinkedHashMap<String, Map<UUID, Set<String>>>();
 
         for ( EntityRef owner : containerEntities.keySet() ) {
             Set<String> collections = containerEntities.get( owner );
@@ -298,35 +308,38 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Iterator<String> edgeTypes =
-                gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeType, null ) ).toBlocking()
-                  .getIterator();
+        Iterator<String> edgeTypes = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( 
+                cpHeadEntity.getId(), edgeType, null ) ).toBlocking() .getIterator();
 
-        logger.debug(
-                "getContainers(): " + "Searched for edges of type {}\n   to target {}:{}\n   in scope {}\n   found: {}",
-                new Object[] {
-                        edgeType, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid(),
-                        applicationScope.getApplication(), edgeTypes.hasNext()
-                } );
+        logger.debug( "getContainers(): "
+                + "Searched for edges of type {}\n   to target {}:{}\n   in scope {}\n   found: {}",
+            new Object[] { edgeType,
+                cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid(),
+                applicationScope.getApplication(),
+                edgeTypes.hasNext() 
+            } );
 
         while ( edgeTypes.hasNext() ) {
 
             String etype = edgeTypes.next();
 
-            Observable<Edge> edges = gm.loadEdgesToTarget(
-                    new SimpleSearchByEdgeType( cpHeadEntity.getId(), etype, Long.MAX_VALUE,
-                            SearchByEdgeType.Order.DESCENDING, null ) );
+            Observable<Edge> edges = gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
+                cpHeadEntity.getId(), etype, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null ) );
 
             Iterator<Edge> iter = edges.toBlockingObservable().getIterator();
             while ( iter.hasNext() ) {
                 Edge edge = iter.next();
 
-                if ( fromEntityType != null && !fromEntityType.equals( edge.getSourceNode().getType() ) ) {
-                    logger.debug( "Ignoring edge from entity type {}", edge.getSourceNode().getType() );
+                if (     fromEntityType != null 
+                     && !fromEntityType.equals( edge.getSourceNode().getType() ) ) {
+                    logger.debug( "Ignoring edge from entity type {}", 
+                            edge.getSourceNode().getType() );
                     continue;
                 }
 
-                EntityRef eref = new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
+                EntityRef eref = new SimpleEntityRef( 
+                        edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
 
                 String name = null;
                 if ( CpNamingUtils.isConnectionEdgeType( edge.getType() ) ) {
@@ -353,11 +366,11 @@ public class CpRelationManager implements RelationManager {
 
         final GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        logger.debug( "updateContainingCollectionsAndCollections(): "
-                        + "Searched for edges to target {}:{}\n   in scope {}\n   found: {}", new Object[] {
-                        cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid(),
-                        applicationScope.getApplication()
-                } );
+        logger.debug( "updateContainingCollectionsAndCollections(): " + "Searched for edges to target {}:{}\n   in scope {}\n   found: {}",
+            new Object[] { cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid(),
+                applicationScope.getApplication() 
+            } );
 
         // loop through all types of edge to target
 
@@ -367,25 +380,25 @@ public class CpRelationManager implements RelationManager {
         final EntityIndexBatch entityIndexBatch = ei.createBatch();
 
         final int count = gm.getEdgeTypesToTarget(
-                new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) )
-                //for each edge type, emit all the edges of that type
-                            .flatMap( new Func1<String, Observable<Edge>>() {
-                                @Override
-                                public Observable<Edge> call( final String etype ) {
-                                    return gm.loadEdgesToTarget(
-                                            new SimpleSearchByEdgeType( cpHeadEntity.getId(), etype, Long.MAX_VALUE,
-                                                    SearchByEdgeType.Order.DESCENDING, null ) );
-                                }
-                            } )
-
-                            //for each edge we receive index and add to the batch
-                            .doOnNext( new Action1<Edge>() {
+            new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) )
+
+                // for each edge type, emit all the edges of that type
+                .flatMap( new Func1<String, Observable<Edge>>() {
                     @Override
-                    public void call( final Edge edge ) {
+                    public Observable<Edge> call( final String etype ) {
+                        return gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
+                            cpHeadEntity.getId(), etype, Long.MAX_VALUE, 
+                            SearchByEdgeType.Order.DESCENDING, null ) );
+                    }
+                } )
 
+                //for each edge we receive index and add to the batch
+                .doOnNext( new Action1<Edge>() {
+                    @Override
+                    public void call( final Edge edge ) {
 
-                        EntityRef sourceEntity =
-                                new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
+                        EntityRef sourceEntity = new SimpleEntityRef( 
+                                edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
 
                         // reindex the entity in the source entity's collection or connection index
 
@@ -393,29 +406,29 @@ public class CpRelationManager implements RelationManager {
                         if ( CpNamingUtils.isCollectionEdgeType( edge.getType() ) ) {
 
                             String collName = CpNamingUtils.getCollectionName( edge.getType() );
-                            indexScope =
-                                    new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
-                                            CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
+                            indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(),
+                                sourceEntity.getType() ),
+                                CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
                         }
                         else {
 
                             String connName = CpNamingUtils.getCollectionName( edge.getType() );
-                            indexScope =
-                                    new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
-                                            CpNamingUtils.getConnectionScopeName( cpEntity.getId().getType(),
-                                                    connName ) );
+                            indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(),
+                                sourceEntity.getType() ),
+                                CpNamingUtils.getConnectionScopeName( cpEntity.getId().getType(),
+                                connName ) );
                         }
 
                         entityIndexBatch.index( indexScope, cpEntity );
 
                         // reindex the entity in the source entity's all-types index
 
-                        indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
-                                CpNamingUtils.ALL_TYPES );
+                        indexScope = new IndexScopeImpl( new SimpleId( 
+                            sourceEntity.getUuid(), sourceEntity.getType() ), CpNamingUtils.ALL_TYPES );
 
                         entityIndexBatch.index( indexScope, cpEntity );
                     }
-                } ).count().toBlocking().lastOrDefault( 0 );
+            } ).count().toBlocking().lastOrDefault( 0 );
 
 
         entityIndexBatch.execute();
@@ -431,14 +444,22 @@ public class CpRelationManager implements RelationManager {
 
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
 
-        logger.debug( "isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}", new Object[] {
-                        edgeType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
-                } );
+        logger.debug( "isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}",
+            new Object[] { 
+                edgeType,
+                headEntity.getType(),
+                headEntity.getUuid(),
+                entity.getType(), entity.getUuid() 
+            } );
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
-        Observable<Edge> edges = gm.loadEdgeVersions(
-                new SimpleSearchByEdge( new SimpleId( headEntity.getUuid(), headEntity.getType() ), edgeType, entityId,
-                        Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null ) );
+        Observable<Edge> edges = gm.loadEdgeVersions( new SimpleSearchByEdge( 
+            new SimpleId( headEntity.getUuid(), headEntity.getType() ), 
+            edgeType,
+            entityId,
+            Long.MAX_VALUE,
+            SearchByEdgeType.Order.DESCENDING, 
+            null ) );
 
         return edges.toBlockingObservable().firstOrDefault( null ) != null;
     }
@@ -453,14 +474,22 @@ public class CpRelationManager implements RelationManager {
 
         String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collName );
 
-        logger.debug( "isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}", new Object[] {
-                        edgeType, headEntity.getType(), headEntity.getUuid(), entity.getType(), entity.getUuid()
-                } );
+        logger.debug( "isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}",
+            new Object[] { 
+                edgeType,
+                headEntity.getType(),
+                headEntity.getUuid(),
+                entity.getType(), entity.getUuid() 
+            } );
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
-        Observable<Edge> edges = gm.loadEdgeVersions(
-                new SimpleSearchByEdge( new SimpleId( headEntity.getUuid(), headEntity.getType() ), edgeType, entityId,
-                        Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null ) );
+        Observable<Edge> edges = gm.loadEdgeVersions( new SimpleSearchByEdge( 
+            new SimpleId( headEntity.getUuid(), headEntity.getType() ), 
+            edgeType,
+            entityId,
+            Long.MAX_VALUE,
+            SearchByEdgeType.Order.DESCENDING,
+            null ) );
 
         return edges.toBlockingObservable().firstOrDefault( null ) != null;
     }
@@ -472,9 +501,12 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Observable<Edge> edgesToTarget = gm.loadEdgesToTarget(
-                new SimpleSearchByEdgeType( targetId, CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
-                        System.currentTimeMillis(), SearchByEdgeType.Order.DESCENDING, null ) ); // last
+        Observable<Edge> edgesToTarget = gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
+            targetId,
+            CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
+            System.currentTimeMillis(),
+            SearchByEdgeType.Order.DESCENDING, 
+            null ) ); // last
 
         Iterator<Edge> iterator = edgesToTarget.toBlockingObservable().getIterator();
         int count = 0;
@@ -494,9 +526,12 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Observable<Edge> edgesFromSource = gm.loadEdgesFromSource(
-                new SimpleSearchByEdgeType( sourceId, CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
-                        System.currentTimeMillis(), SearchByEdgeType.Order.DESCENDING, null ) ); // last
+        Observable<Edge> edgesFromSource = gm.loadEdgesFromSource( new SimpleSearchByEdgeType( 
+            sourceId,
+            CpNamingUtils.getEdgeTypeFromConnectionType( connectionType ),
+            System.currentTimeMillis(),
+            SearchByEdgeType.Order.DESCENDING,
+            null ) ); // last
 
         int count = edgesFromSource.take( 2 ).count().toBlocking().last();
 
@@ -511,8 +546,8 @@ public class CpRelationManager implements RelationManager {
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        Observable<String> str =
-                gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) );
+        Observable<String> str = gm.getEdgeTypesFromSource( 
+                new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) );
 
         Iterator<String> iter = str.toBlockingObservable().getIterator();
         while ( iter.hasNext() ) {
@@ -525,8 +560,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Results getCollection( String collectionName, UUID startResult, int count, Level resultsLevel,
-                                  boolean reversed ) throws Exception {
+    public Results getCollection( String collectionName,
+            UUID startResult,
+            int count,
+            Level resultsLevel,
+            boolean reversed ) throws Exception {
 
         Query query = Query.fromQL( "select *" );
         query.setLimit( count );
@@ -551,12 +589,14 @@ public class CpRelationManager implements RelationManager {
     @Override
     public Entity addToCollection( String collName, EntityRef itemRef ) throws Exception {
 
-        CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collName );
+        CollectionInfo collection = 
+                getDefaultSchema().getCollection( headEntity.getType(), collName );
         if ( ( collection != null ) && !collection.getType().equals( itemRef.getType() ) ) {
             return null;
         }
 
-        return addToCollection( collName, itemRef, ( collection != null && collection.getLinkedCollection() != null ) );
+        return addToCollection( collName, itemRef, 
+                ( collection != null && collection.getLinkedCollection() != null ) );
     }
 
 
@@ -581,15 +621,16 @@ public class CpRelationManager implements RelationManager {
         }
 
         // load the new member entity to be added to the collection from its default scope
-        CollectionScope memberScope =
-                new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
+        CollectionScope memberScope = new CollectionScopeImpl( 
+                applicationScope.getApplication(),
+                applicationScope.getApplication(),
+                CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
 
         EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
 
         //TODO, this double load should disappear once events are in
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity =
-                memberMgr.load( new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlocking().last();
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load( 
+                new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlocking().last();
 
         if ( memberEntity == null ) {
             throw new RuntimeException(
@@ -597,18 +638,23 @@ public class CpRelationManager implements RelationManager {
         }
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Loaded member entity {}:{} from scope\n   app {}\n   " + "owner {}\n   name {} data {}",
-                    new Object[] {
-                            itemRef.getType(), itemRef.getUuid(), memberScope.getApplication(), memberScope.getOwner(),
-                            memberScope.getName(), CpEntityMapUtils.toMap( memberEntity )
-                    } );
+            logger.debug( "Loaded member entity {}:{} from scope\n   app {}\n   " 
+                + "owner {}\n   name {} data {}",
+                new Object[] {
+                    itemRef.getType(),
+                    itemRef.getUuid(),
+                    memberScope.getApplication(),
+                    memberScope.getOwner(),
+                    memberScope.getName(),
+                    CpEntityMapUtils.toMap( memberEntity )
+                } );
         }
 
         String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collName );
 
-        UUID timeStampUuid =
-                memberEntity.getId().getUuid() != null && UUIDUtils.isTimeBased( memberEntity.getId().getUuid() ) ?
-                memberEntity.getId().getUuid() : UUIDUtils.newTimeUUID();
+        UUID timeStampUuid = memberEntity.getId().getUuid() != null 
+                && UUIDUtils.isTimeBased( memberEntity.getId().getUuid() ) 
+                ?  memberEntity.getId().getUuid() : UUIDUtils.newTimeUUID();
 
         long uuidHash = UUIDUtils.getUUIDLong( timeStampUuid );
 
@@ -617,10 +663,15 @@ public class CpRelationManager implements RelationManager {
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.writeEdge( edge ).toBlockingObservable().last();
 
-        logger.debug( "Wrote edgeType {}\n   from {}:{}\n   to {}:{}\n   scope {}:{}", new Object[] {
-                edgeType, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid(),
-                memberEntity.getId().getType(), memberEntity.getId().getUuid(),
-                applicationScope.getApplication().getType(), applicationScope.getApplication().getUuid()
+        logger.debug( "Wrote edgeType {}\n   from {}:{}\n   to {}:{}\n   scope {}:{}", 
+            new Object[] { 
+                edgeType,
+                cpHeadEntity.getId().getType(),
+                cpHeadEntity.getId().getUuid(),
+                memberEntity.getId().getType(),
+                memberEntity.getId().getUuid(),
+                applicationScope.getApplication().getType(),
+                applicationScope.getApplication().getUuid()
         } );
 
         ( ( CpEntityManager ) em ).indexEntityIntoCollection( cpHeadEntity, memberEntity, collName );
@@ -635,7 +686,8 @@ public class CpRelationManager implements RelationManager {
         //            headEntityScope.getName()});
 
         if ( connectBack && collection != null && collection.getLinkedCollection() != null ) {
-            getRelationManager( itemEntity ).addToCollection( collection.getLinkedCollection(), headEntity, false );
+            getRelationManager( itemEntity ).addToCollection( 
+                    collection.getLinkedCollection(), headEntity, false );
         }
 
         return itemEntity;
@@ -656,7 +708,8 @@ public class CpRelationManager implements RelationManager {
 
     @Override
     @Metered( group = "core", name = "RelationManager_createItemInCollection" )
-    public Entity createItemInCollection( String collName, String itemType, Map<String, Object> properties )
+    public Entity createItemInCollection( 
+            String collName, String itemType, Map<String, Object> properties )
             throws Exception {
 
         if ( headEntity.getUuid().equals( applicationId ) ) {
@@ -675,7 +728,9 @@ public class CpRelationManager implements RelationManager {
             return em.create( itemType, properties );
         }
 
-        else if ( headEntity.getType().equals( Group.ENTITY_TYPE ) && ( collName.equals( COLLECTION_ROLES ) ) ) {
+        else if ( headEntity.getType().equals( Group.ENTITY_TYPE ) 
+                && ( collName.equals( COLLECTION_ROLES ) ) ) {
+
             UUID groupId = headEntity.getUuid();
             String roleName = ( String ) properties.get( PROPERTY_NAME );
             return em.createGroupRole( groupId, roleName, ( Long ) properties.get( PROPERTY_INACTIVITY ) );
@@ -695,7 +750,8 @@ public class CpRelationManager implements RelationManager {
             addToCollection( collName, itemEntity );
 
             if ( collection != null && collection.getLinkedCollection() != null ) {
-                getRelationManager( getHeadEntity() ).addToCollection( collection.getLinkedCollection(), itemEntity );
+                getRelationManager( getHeadEntity() )
+                        .addToCollection( collection.getLinkedCollection(), itemEntity );
             }
         }
 
@@ -723,21 +779,26 @@ public class CpRelationManager implements RelationManager {
         }
 
         // load the entity to be removed to the collection
-        CollectionScope memberScope =
-                new CollectionScopeImpl( this.applicationScope.getApplication(), this.applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
+        CollectionScope memberScope = new CollectionScopeImpl( 
+                this.applicationScope.getApplication(),
+                this.applicationScope.getApplication(),
+                CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
         EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Loading entity to remove from collection "
-                            + "{}:{} from scope\n   app {}\n   owner {}\n   name {}", new Object[] {
-                            itemRef.getType(), itemRef.getUuid(), memberScope.getApplication(), memberScope.getOwner(),
-                            memberScope.getName()
-                    } );
+            logger.debug( "Loading entity to remove from collection " 
+                + "{}:{} from scope\n   app {}\n   owner {}\n   name {}", 
+                new Object[] {
+                    itemRef.getType(),
+                    itemRef.getUuid(),
+                    memberScope.getApplication(),
+                    memberScope.getOwner(),
+                    memberScope.getName()
+               });
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity =
-                memberMgr.load( new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlockingObservable().last();
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load( 
+            new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlockingObservable().last();
 
         final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         final EntityIndexBatch batch = ei.createBatch();
@@ -760,15 +821,20 @@ public class CpRelationManager implements RelationManager {
 
         // remove edge from collection to item 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
-        Edge collectionToItemEdge =
-                new SimpleEdge( cpHeadEntity.getId(), CpNamingUtils.getEdgeTypeFromCollectionName( collName ),
-                        memberEntity.getId(), UUIDUtils.getUUIDLong( memberEntity.getId().getUuid() ) );
+        Edge collectionToItemEdge = new SimpleEdge( 
+                cpHeadEntity.getId(), 
+                CpNamingUtils.getEdgeTypeFromCollectionName( collName ), 
+                memberEntity.getId(), UUIDUtils.getUUIDLong( memberEntity.getId().getUuid() ) );
         gm.deleteEdge( collectionToItemEdge ).toBlockingObservable().last();
 
         // remove edge from item to collection
-        Edge itemToCollectionEdge = new SimpleEdge( memberEntity.getId(), CpNamingUtils
-                .getEdgeTypeFromCollectionName( Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ),
-                cpHeadEntity.getId(), UUIDUtils.getUUIDLong( cpHeadEntity.getId().getUuid() ) );
+        Edge itemToCollectionEdge = new SimpleEdge( 
+                memberEntity.getId(), 
+                CpNamingUtils.getEdgeTypeFromCollectionName( 
+                    Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ), 
+                cpHeadEntity.getId(), 
+                UUIDUtils.getUUIDLong( cpHeadEntity.getId().getUuid() ) );
+
         gm.deleteEdge( itemToCollectionEdge ).toBlockingObservable().last();
 
         // special handling for roles collection of a group
@@ -797,9 +863,11 @@ public class CpRelationManager implements RelationManager {
         headEntity = em.validate( headEntity );
         dstEntityRef = em.validate( dstEntityRef );
 
-        CollectionInfo srcCollection = getDefaultSchema().getCollection( headEntity.getType(), srcRelationName );
+        CollectionInfo srcCollection = 
+                getDefaultSchema().getCollection( headEntity.getType(), srcRelationName );
 
-        CollectionInfo dstCollection = getDefaultSchema().getCollection( dstEntityRef.getType(), dstRelationName );
+        CollectionInfo dstCollection = 
+                getDefaultSchema().getCollection( dstEntityRef.getType(), dstRelationName );
 
         Results results = null;
         do {
@@ -838,9 +906,8 @@ public class CpRelationManager implements RelationManager {
         CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collName );
 
         if ( collection == null ) {
-            throw new RuntimeException(
-                    "Cannot find collection-info for '" + collName + "' of " + headEntity.getType() + ":" + headEntity
-                            .getUuid() );
+            throw new RuntimeException( "Cannot find collection-info for '" + collName 
+                    + "' of " + headEntity.getType() + ":" + headEntity .getUuid() );
         }
 
         IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
@@ -922,29 +989,39 @@ public class CpRelationManager implements RelationManager {
 
         ConnectionRefImpl connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef );
 
-        CollectionScope targetScope =
-                new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
+        CollectionScope targetScope = new CollectionScopeImpl( 
+            applicationScope.getApplication(), 
+            applicationScope.getApplication(),
+            CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
 
         EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "createConnection(): " + "Indexing connection type '{}'\n   from source {}:{}]\n"
-                            + "   to target {}:{}\n   from scope\n   app {}\n   owner {}\n   name {}", new Object[] {
-                            connectionType, headEntity.getType(), headEntity.getUuid(), connectedEntityRef.getType(),
-                            connectedEntityRef.getUuid(), targetScope.getApplication(), targetScope.getOwner(),
-                            targetScope.getName()
-                    } );
+            logger.debug( "createConnection(): " 
+                + "Indexing connection type '{}'\n   from source {}:{}]\n"
+                + "   to target {}:{}\n   from scope\n   app {}\n   owner {}\n   name {}", 
+                new Object[] {
+                    connectionType,
+                    headEntity.getType(),
+                    headEntity.getUuid(),
+                    connectedEntityRef.getType(),
+                    connectedEntityRef.getUuid(),
+                    targetScope.getApplication(), 
+                    targetScope.getOwner(), 
+                    targetScope.getName()
+                } );
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity =
-                targetEcm.load( new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
-                         .toBlockingObservable().last();
+        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
+            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
+                .toBlockingObservable().last();
 
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
 
         // create graph edge connection from head entity to member entity
-        Edge edge = new SimpleEdge( cpHeadEntity.getId(), edgeType, targetEntity.getId(), System.currentTimeMillis() );
+        Edge edge = new SimpleEdge( 
+                cpHeadEntity.getId(), edgeType, targetEntity.getId(), System.currentTimeMillis() );
+
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.writeEdge( edge ).toBlockingObservable().last();
 
@@ -975,14 +1052,16 @@ public class CpRelationManager implements RelationManager {
 
     @SuppressWarnings( "unchecked" )
     @Metered( group = "core", name = "CpRelationManager_batchUpdateEntityConnection" )
-    public Mutator<ByteBuffer> batchUpdateEntityConnection( Mutator<ByteBuffer> batch, boolean disconnect,
-                                                            ConnectionRefImpl connection, UUID timestampUuid )
-            throws Exception {
+    public Mutator<ByteBuffer> batchUpdateEntityConnection( 
+            Mutator<ByteBuffer> batch, 
+            boolean disconnect, 
+            ConnectionRefImpl conn, 
+            UUID timestampUuid ) throws Exception {
 
         long timestamp = getTimestampInMicros( timestampUuid );
 
-        Entity connectedEntity =
-                em.get( new SimpleEntityRef( connection.getConnectedEntityType(), connection.getConnectedEntityId() ) );
+        Entity connectedEntity = em.get(new SimpleEntityRef( 
+                conn.getConnectedEntityType(), conn.getConnectedEntityId() ) );
 
         if ( connectedEntity == null ) {
             return batch;
@@ -992,59 +1071,59 @@ public class CpRelationManager implements RelationManager {
 
         if ( disconnect ) {
 
-            addDeleteToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), timestamp );
+            addDeleteToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
+                        conn.getConnectionType() ),
+                asList(conn.getConnectedEntityId(), conn.getConnectedEntityType() ), timestamp );
 
-            addDeleteToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectingEntityId(), connection.getConnectingEntityType() ), timestamp );
+            addDeleteToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
+                        conn.getConnectionType() ),
+                asList(conn.getConnectingEntityId(), conn.getConnectingEntityType() ), timestamp );
 
             // delete the connection path if there will be no connections left
 
             // check out outbound edges of the given type.  If we have more than the 1 specified,
             // we shouldn't delete the connection types from our outbound index
-            if ( !moreThanOneOutboundConnection( connection.getConnectingEntity(), connection.getConnectionType() ) ) {
+            if ( !moreThanOneOutboundConnection(conn.getConnectingEntity(), conn.getConnectionType() ) ) {
 
-                addDeleteToMutator( batch, ENTITY_DICTIONARIES,
-                        key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
-                        connection.getConnectionType(), timestamp );
+                addDeleteToMutator(batch, ENTITY_DICTIONARIES,
+                        key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
+                        conn.getConnectionType(), timestamp );
             }
 
             //check out inbound edges of the given type.  If we have more than the 1 specified,
             // we shouldn't delete the connection types from our outbound index
-            if ( !moreThanOneInboundConnection( connection.getConnectingEntity(), connection.getConnectionType() ) ) {
+            if ( !moreThanOneInboundConnection(conn.getConnectingEntity(), conn.getConnectionType() ) ) {
 
-                addDeleteToMutator( batch, ENTITY_DICTIONARIES,
-                        key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
-                        connection.getConnectionType(), timestamp );
-            }
+                addDeleteToMutator(batch, ENTITY_DICTIONARIES,
+                    key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
+                    conn.getConnectionType(), timestamp );
+        }
         }
         else {
 
-            addInsertToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), timestamp,
+            addInsertToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                    key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
+                            conn.getConnectionType() ),
+                    asList(conn.getConnectedEntityId(), conn.getConnectedEntityType() ), timestamp,
                     timestamp );
 
-            addInsertToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
-                            connection.getConnectionType() ),
-                    asList( connection.getConnectingEntityId(), connection.getConnectingEntityType() ), timestamp,
+            addInsertToMutator(batch, ENTITY_COMPOSITE_DICTIONARIES,
+                    key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
+                            conn.getConnectionType() ),
+                    asList(conn.getConnectingEntityId(), conn.getConnectingEntityType() ), timestamp,
                     timestamp );
 
             // Add connection type to connections set
-            addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
-                    connection.getConnectionType(), null, timestamp );
+            addInsertToMutator(batch, ENTITY_DICTIONARIES,
+                    key(conn.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
+                    conn.getConnectionType(), null, timestamp );
 
             // Add connection type to connections set
-            addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
-                    connection.getConnectionType(), null, timestamp );
+            addInsertToMutator(batch, ENTITY_DICTIONARIES,
+                    key(conn.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
+                    conn.getConnectionType(), null, timestamp );
         }
 
         // Add indexes for the connected entity's list properties
@@ -1058,17 +1137,20 @@ public class CpRelationManager implements RelationManager {
         Schema schema = getDefaultSchema();
 
         for ( String dictionaryName : dictionaryNames ) {
-            boolean has_dictionary = schema.hasDictionary( connectedEntity.getType(), dictionaryName );
-            boolean dictionary_indexed =
-                    schema.isDictionaryIndexedInConnections( connectedEntity.getType(), dictionaryName );
+
+            boolean has_dictionary = schema.hasDictionary( 
+                    connectedEntity.getType(), dictionaryName );
+
+            boolean dictionary_indexed = schema.isDictionaryIndexedInConnections( 
+                    connectedEntity.getType(), dictionaryName );
 
             if ( dictionary_indexed || !has_dictionary ) {
                 Set<Object> elementValues = em.getDictionaryAsSet( connectedEntity, dictionaryName );
                 for ( Object elementValue : elementValues ) {
-                    IndexUpdate indexUpdate =
-                            batchStartIndexUpdate( batch, connectedEntity, dictionaryName, elementValue, timestampUuid,
-                                    has_dictionary, true, disconnect, false );
-                    batchUpdateConnectionIndex( indexUpdate, connection );
+                    IndexUpdate indexUpdate = batchStartIndexUpdate( 
+                            batch, connectedEntity, dictionaryName, elementValue, 
+                            timestampUuid, has_dictionary, true, disconnect, false );
+                    batchUpdateConnectionIndex(indexUpdate, conn );
                 }
             }
         }
@@ -1079,8 +1161,11 @@ public class CpRelationManager implements RelationManager {
 
     @Override
     @Metered( group = "core", name = "RelationManager_createConnection_paired_connection_type" )
-    public ConnectionRef createConnection( String pairedConnectionType, EntityRef pairedEntity, String connectionType,
-                                           EntityRef connectedEntityRef ) throws Exception {
+    public ConnectionRef createConnection( 
+            String pairedConnectionType,
+            EntityRef pairedEntity,
+            String connectionType,
+            EntityRef connectedEntityRef ) throws Exception {
 
         throw new UnsupportedOperationException( "Paired connections not supported" );
     }
@@ -1095,7 +1180,8 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public ConnectionRef connectionRef( String connectionType, EntityRef connectedEntityRef ) throws Exception {
+    public ConnectionRef connectionRef( 
+            String connectionType, EntityRef connectedEntityRef ) throws Exception {
 
         ConnectionRef connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef );
 
@@ -1104,8 +1190,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public ConnectionRef connectionRef( String pairedConnectionType, EntityRef pairedEntity, String connectionType,
-                                        EntityRef connectedEntityRef ) throws Exception {
+    public ConnectionRef connectionRef( 
+            String pairedConnectionType,
+            EntityRef pairedEntity,
+            String connectionType,
+            EntityRef connectedEntityRef ) throws Exception {
 
         throw new UnsupportedOperationException( "Paired connections not supported" );
     }
@@ -1124,7 +1213,8 @@ public class CpRelationManager implements RelationManager {
         // First, clean up the dictionary records of the connection
         Keyspace ko = cass.getApplicationKeyspace( applicationId );
         Mutator<ByteBuffer> m = createMutator( ko, be );
-        batchUpdateEntityConnection( m, true, ( ConnectionRefImpl ) connectionRef, UUIDGenerator.newTimeUUID() );
+        batchUpdateEntityConnection( 
+                m, true, ( ConnectionRefImpl ) connectionRef, UUIDGenerator.newTimeUUID() );
         batchExecute( m, CassandraService.RETRY_COUNT );
 
         EntityRef connectingEntityRef = connectionRef.getConnectingEntity();  // source
@@ -1132,26 +1222,36 @@ public class CpRelationManager implements RelationManager {
 
         String connectionType = connectionRef.getConnectedEntity().getConnectionType();
 
-        CollectionScope targetScope =
-                new CollectionScopeImpl( applicationScope.getApplication(), applicationScope.getApplication(),
-                        CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
+        CollectionScope targetScope = new CollectionScopeImpl( 
+                applicationScope.getApplication(),
+                applicationScope.getApplication(),
+                CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType()) );
 
         EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "Deleting connection '{}' from source {}:{} \n   to target {}:{}", new Object[] {
-                            connectionType, connectingEntityRef.getType(), connectingEntityRef.getUuid(),
-                            connectedEntityRef.getType(), connectedEntityRef.getUuid()
+            logger.debug( "Deleting connection '{}' from source {}:{} \n   to target {}:{}", 
+                new Object[] {
+                    connectionType,
+                    connectingEntityRef.getType(),
+                    connectingEntityRef.getUuid(),
+                    connectedEntityRef.getType(),
+                    connectedEntityRef.getUuid()
                     } );
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity =
-                targetEcm.load( new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
-                         .toBlockingObservable().last();
+        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
+            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) ) 
+                .toBlockingObservable().last();
 
         // Delete graph edge connection from head entity to member entity
-        Edge edge = new SimpleEdge( new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
-                connectionType, targetEntity.getId(), System.currentTimeMillis() );
+        Edge edge = new SimpleEdge( 
+            new SimpleId( connectingEntityRef.getUuid(),
+                connectingEntityRef.getType() ),
+                connectionType,
+                targetEntity.getId(),
+                System.currentTimeMillis() );
+
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         gm.deleteEdge( edge ).toBlockingObservable().last();
 
@@ -1159,15 +1259,18 @@ public class CpRelationManager implements RelationManager {
         final EntityIndexBatch batch = ei.createBatch();
 
         // Deindex the connection in app|source|type context
-        IndexScope indexScope =
-                new IndexScopeImpl( new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
-                        CpNamingUtils.getConnectionScopeName( targetEntity.getId().getType(), connectionType ) );
+        IndexScope indexScope = new IndexScopeImpl( 
+            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( new SimpleId( connectingEntityRef.getUuid(), connectingEntityRef.getType() ),
-                        CpNamingUtils.ALL_TYPES );
+        IndexScope allTypesIndexScope = new IndexScopeImpl( 
+            new SimpleId( connectingEntityRef.getUuid(),
+                connectingEntityRef.getType() ),
+                CpNamingUtils.ALL_TYPES );
 
         batch.deindex( allTypesIndexScope, targetEntity );
 
@@ -1189,7 +1292,8 @@ public class CpRelationManager implements RelationManager {
 
     @Override
     public Set<String> getConnectionTypes( boolean filterConnection ) throws Exception {
-        Set<String> connections = cast( em.getDictionaryAsSet( headEntity, Schema.DICTIONARY_CONNECTED_TYPES ) );
+        Set<String> connections = cast( 
+                em.getDictionaryAsSet( headEntity, Schema.DICTIONARY_CONNECTED_TYPES ) );
 
         if ( connections == null ) {
             return null;
@@ -1202,8 +1306,8 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Results getConnectedEntities( String connectionType, String connectedEntityType, Level level )
-            throws Exception {
+    public Results getConnectedEntities( 
+            String connectionType, String connectedEntityType, Level level ) throws Exception {
 
         Results raw = null;
 
@@ -1231,8 +1335,8 @@ public class CpRelationManager implements RelationManager {
             final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
 
-            logger.debug( "Searching connected entities from scope {}:{}", indexScope.getOwner().toString(),
-                    indexScope.getName() );
+            logger.debug( "Searching connected entities from scope {}:{}", 
+                    indexScope.getOwner().toString(), indexScope.getName() );
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1260,16 +1364,16 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Results getConnectingEntities( String connType, String fromEntityType, Level resultsLevel )
-            throws Exception {
+    public Results getConnectingEntities( 
+            String connType, String fromEntityType, Level resultsLevel ) throws Exception {
 
         return getConnectingEntities( connType, fromEntityType, resultsLevel, -1 );
     }
 
 
     @Override
-    public Results getConnectingEntities( String connType, String fromEntityType, Level level, int count )
-            throws Exception {
+    public Results getConnectingEntities( 
+            String connType, String fromEntityType, Level level, int count ) throws Exception {
 
         // looking for edges to the head entity
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connType );
@@ -1312,12 +1416,14 @@ public class CpRelationManager implements RelationManager {
         if ( query.getEntityType() == null ) {
 
             // search across all types of collections of the head-entity
-            IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(), CpNamingUtils.ALL_TYPES );
+            IndexScope indexScope = new IndexScopeImpl( 
+                cpHeadEntity.getId(), 
+                CpNamingUtils.ALL_TYPES );
 
             EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
-            logger.debug( "Searching connections from the all-types scope {}:{}", indexScope.getOwner().toString(),
-                    indexScope.getName() );
+            logger.debug( "Searching connections from the all-types scope {}:{}", 
+                    indexScope.getOwner().toString(), indexScope.getName() );
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1325,12 +1431,14 @@ public class CpRelationManager implements RelationManager {
             return buildConnectionResults( query, crs, query.getConnectionType() );
         }
 
-        IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
-                CpNamingUtils.getConnectionScopeName( query.getEntityType(), query.getConnectionType() ) );
+        IndexScope indexScope = new IndexScopeImpl( 
+            cpHeadEntity.getId(), 
+            CpNamingUtils.getConnectionScopeName( query.getEntityType(), 
+            query.getConnectionType() ) );
         EntityIndex ei = managerCache.getEntityIndex( applicationScope );
-
-        logger.debug( "Searching connections from the scope {}:{}", indexScope.getOwner().toString(),
-                indexScope.getName() );
+        
+        logger.debug( "Searching connections from the scope {}:{}", 
+                indexScope.getOwner().toString(), indexScope.getName() );
 
         query = adjustQuery( query );
         CandidateResults crs = ei.search( indexScope, query );
@@ -1353,29 +1461,31 @@ public class CpRelationManager implements RelationManager {
                 // This is fulgy to put here, but required.
                 if ( query.getEntityType().equals( User.ENTITY_TYPE ) && ident.isEmail() ) {
 
-                    Query newQuery =
-                            Query.fromQL( "select * where email='" + query.getSingleNameOrEmailIdentifier() + "'" );
+                    Query newQuery = Query.fromQL( "select * where email='" 
+                            + query.getSingleNameOrEmailIdentifier() + "'" );
                     query.setRootOperand( newQuery.getRootOperand() );
                 }
 
                 // use the ident with the default alias. could be an email
                 else {
 
-                    Query newQuery =
-                            Query.fromQL( "select * where name='" + query.getSingleNameOrEmailIdentifier() + "'" );
+                    Query newQuery = Query.fromQL( "select * where name='" 
+                            + query.getSingleNameOrEmailIdentifier() + "'" );
                     query.setRootOperand( newQuery.getRootOperand() );
                 }
             }
             else if ( query.containsSingleUuidIdentifier() ) {
 
-                Query newQuery = Query.fromQL( "select * where uuid='" + query.getSingleUuidIdentifier() + "'" );
+                Query newQuery = Query.fromQL( 
+                        "select * where uuid='" + query.getSingleUuidIdentifier() + "'" );
                 query.setRootOperand( newQuery.getRootOperand() );
             }
         }
 
         if ( query.isReversed() ) {
 
-            Query.SortPredicate desc = new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING );
+            Query.SortPredicate desc = 
+                new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING );
 
             try {
                 query.addSort( desc );
@@ -1387,8 +1497,8 @@ public class CpRelationManager implements RelationManager {
 
         if ( query.getSortPredicates().isEmpty() ) {
 
-            //TODO, should this be descending?
-            Query.SortPredicate asc = new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.ASCENDING );
+            Query.SortPredicate asc = 
+                new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING);
 
             query.addSort( asc );
         }
@@ -1424,7 +1534,8 @@ public class CpRelationManager implements RelationManager {
     }
 
 
-    private Results buildConnectionResults( Query query, CandidateResults crs, String connectionType ) {
+    private Results buildConnectionResults( 
+            Query query, CandidateResults crs, String connectionType ) {
 
         if ( query.getLevel().equals( Level.ALL_PROPERTIES ) ) {
             return buildResults( query, crs, connectionType );
@@ -1436,9 +1547,11 @@ public class CpRelationManager implements RelationManager {
 
         for ( CandidateResult cr : crs ) {
 
-            SimpleEntityRef targetRef = new SimpleEntityRef( cr.getId().getType(), cr.getId().getUuid() );
+            SimpleEntityRef targetRef = 
+                    new SimpleEntityRef( cr.getId().getType(), cr.getId().getUuid() );
 
-            final ConnectionRef ref = new ConnectionRefImpl( sourceRef, connectionType, targetRef );
+            final ConnectionRef ref = 
+                    new ConnectionRefImpl( sourceRef, connectionType, targetRef );
 
             refs.add( ref );
         }
@@ -1459,8 +1572,8 @@ public class CpRelationManager implements RelationManager {
         logger.debug( "buildResults() for {} from {} candidates", collName, crs.size() );
 
         //get an instance of our results loader
-        final ResultsLoader resultsLoader =
-                this.resultsLoaderFactory.getLoader( applicationScope, this.headEntity, query.getResultsLevel() );
+        final ResultsLoader resultsLoader = this.resultsLoaderFactory.getLoader( 
+                applicationScope, this.headEntity, query.getResultsLevel() );
 
         //load the results
         final Results results = resultsLoader.loadResults( crs );
@@ -1484,11 +1597,11 @@ public class CpRelationManager implements RelationManager {
 
         Entity entity = getHeadEntity();
 
-        elementValue = getDefaultSchema().validateEntitySetValue( entity.getType(), setName, elementValue );
+        elementValue = getDefaultSchema()
+                .validateEntitySetValue( entity.getType(), setName, elementValue );
 
-        IndexUpdate indexUpdate =
-                batchStartIndexUpdate( batch, entity, setName, elementValue, timestampUuid, true, true, removeFromSet,
-                        false );
+        IndexUpdate indexUpdate = batchStartIndexUpdate( batch, entity, setName, elementValue, 
+                timestampUuid, true, true, removeFromSet, false );
 
         // Update collections 
 
@@ -1498,8 +1611,8 @@ public class CpRelationManager implements RelationManager {
         if ( containers != null ) {
             Map<EntityRef, Set<String>> containerEntities = getContainers();
             for ( EntityRef containerEntity : containerEntities.keySet() ) {
-                if ( containerEntity.getType().equals( TYPE_APPLICATION ) && Schema
-                        .isAssociatedEntityType( entity.getType() ) ) {
+                if ( containerEntity.getType().equals( TYPE_APPLICATION ) 
+                        && Schema.isAssociatedEntityType( entity.getType() ) ) {
                     logger.debug( "Extended properties for {} not indexed by application", entity.getType() );
                     continue;
                 }
@@ -1525,25 +1638,28 @@ public class CpRelationManager implements RelationManager {
      * Batch update collection index.
      *
      * @param indexUpdate The update to apply
-     * @param owner The entity that is the owner context of this entity update. Can either be an application, or another
-     * entity
+     * @param owner The entity that is the owner context of this entity update. Can either be an 
+     * application, or another * entity
      * @param collectionName the collection name
-     *
+     * 
      * @return The indexUpdate with batch mutations
-     *
      * @throws Exception the exception
      */
     @Metered( group = "core", name = "RelationManager_batchUpdateCollectionIndex" )
-    public IndexUpdate batchUpdateCollectionIndex( IndexUpdate indexUpdate, EntityRef owner, String collectionName )
+    public IndexUpdate batchUpdateCollectionIndex( 
+            IndexUpdate indexUpdate, EntityRef owner, String collectionName )
             throws Exception {
 
         logger.debug( "batchUpdateCollectionIndex" );
 
         Entity indexedEntity = indexUpdate.getEntity();
 
-        String bucketId = indexBucketLocator
-                .getBucket( applicationId, IndexBucketLocator.IndexType.COLLECTION, indexedEntity.getUuid(),
-                        indexedEntity.getType(), indexUpdate.getEntryName() );
+        String bucketId = indexBucketLocator.getBucket( 
+                applicationId, 
+                IndexBucketLocator.IndexType.COLLECTION, 
+                indexedEntity.getUuid(),
+                indexedEntity.getType(), 
+                indexUpdate.getEntryName() );
 
         // the root name without the bucket
         // entity_id,collection_name,prop_name,
@@ -1561,14 +1677,14 @@ public class CpRelationManager implements RelationManager {
 
                 index_key = key( index_name, bucketId );
 
-                addDeleteToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, entry.getIndexComposite(),
-                        indexUpdate.getTimestamp() );
+                addDeleteToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, 
+                        entry.getIndexComposite(), indexUpdate.getTimestamp() );
 
                 if ( "location.coordinates".equals( entry.getPath() ) ) {
-                    EntityLocationRef loc = new EntityLocationRef( indexUpdate.getEntity(), entry.getTimestampUuid(),
-                            entry.getValue().toString() );
-                    batchRemoveLocationFromCollectionIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_name, loc );
+                    EntityLocationRef loc = new EntityLocationRef( indexUpdate.getEntity(), 
+                            entry.getTimestampUuid(), entry.getValue().toString() );
+                    batchRemoveLocationFromCollectionIndex( indexUpdate.getBatch(), 
+                            indexBucketLocator, applicationId, index_name, loc );
                 }
             }
             else {
@@ -1576,8 +1692,9 @@ public class CpRelationManager implements RelationManager {
             }
         }
 
-        if ( ( indexUpdate.getNewEntries().size() > 0 ) && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue()
-                && !indexUpdate.isRemoveListEntry() ) ) ) {
+        if ( ( indexUpdate.getNewEntries().size() > 0 ) 
+                && ( !indexUpdate.isMultiValue() 
+                || ( indexUpdate.isMultiValue() && !indexUpdate.isRemoveListEntry() ) ) ) {
 
             for ( IndexUpdate.IndexEntry indexEntry : indexUpdate.getNewEntries() ) {
 
@@ -1589,15 +1706,21 @@ public class CpRelationManager implements RelationManager {
 
                 // int i = 0;
 
-                addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, indexEntry.getIndexComposite(),
-                        null, indexUpdate.getTimestamp() );
+                addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, index_key, 
+                        indexEntry.getIndexComposite(), null, indexUpdate.getTimestamp() );
 
                 if ( "location.coordinates".equals( indexEntry.getPath() ) ) {
-                    EntityLocationRef loc =
-                            new EntityLocationRef( indexUpdate.getEntity(), indexEntry.getTimestampUuid(),
-                                    indexEntry.getValue().toString() );
-                    batchStoreLocationInCollectionIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_name, indexedEntity.getUuid(), loc );
+                    EntityLocationRef loc = new EntityLocationRef( 
+                            indexUpdate.getEntity(), 
+                            indexEntry.getTimestampUuid(), 
+                            indexEntry.getValue().toString() );
+                    batchStoreLocationInCollectionIndex( 
+                            indexUpdate.getBatch(),
+                            indexBucketLocator,
+                            applicationId,
+                            index_name,
+                            indexedEntity.getUuid(),
+                            loc );
                 }
 
                 // i++;
@@ -1614,26 +1737,56 @@ public class CpRelationManager implements RelationManager {
     }
 
 
-    public IndexUpdate batchStartIndexUpdate( Mutator<ByteBuffer> batch, Entity entity, String entryName,
-                                              Object entryValue, UUID timestampUuid, boolean schemaHasProperty,
-                                              boolean isMultiValue, boolean removeListEntry, boolean fulltextIndexed )
+    public IndexUpdate batchStartIndexUpdate( 
+            Mutator<ByteBuffer> batch,
+            Entity entity,
+            String entryName,
+            Object entryValue,
+            UUID timestampUuid,
+            boolean schemaHasProperty,
+            boolean isMultiValue,
+            boolean removeListEntry,
+            boolean fulltextIndexed )
             throws Exception {
-        return batchStartIndexUpdate( batch, entity, entryName, entryValue, timestampUuid, schemaHasProperty,
-                isMultiValue, removeListEntry, fulltextIndexed, false );
+
+        return batchStartIndexUpdate( 
+                batch,
+                entity,
+                entryName,
+                entryValue,
+                timestampUuid,
+                schemaHasProperty,
+                isMultiValue,
+                removeListEntry,
+                fulltextIndexed,
+                false );
     }
 
 
     @Metered( group = "core", name = "RelationManager_batchStartIndexUpdate" )
-    public IndexUpdate batchStartIndexUpdate( Mutator<ByteBuffer> batch, Entity entity, String entryName,
-                                              Object entryValue, UUID timestampUuid, boolean schemaHasProperty,
-                                              boolean isMultiValue, boolean removeListEntry, boolean fulltextIndexed,
-                                              boolean skipRead ) throws Exception {
+    public IndexUpdate batchStartIndexUpdate( 
+            Mutator<ByteBuffer> batch,
+            Entity entity,
+            String entryName,
+            Object entryValue,
+            UUID timestampUuid,
+            boolean schemaHasProperty,
+            boolean isMultiValue,
+            boolean removeListEntry,
+            boolean fulltextIndexed,
+            boolean skipRead ) throws Exception {
 
         long timestamp = getTimestampInMicros( timestampUuid );
 
-        IndexUpdate indexUpdate =
-                new IndexUpdate( batch, entity, entryName, entryValue, schemaHasProperty, isMultiValue, removeListEntry,
-                        timestampUuid );
+        IndexUpdate indexUpdate = new IndexUpdate( 
+                batch,
+                entity,
+                entryName,
+                entryValue,
+                schemaHasProperty,
+                isMultiValue,
+                removeListEntry,
+                timestampUuid );
 
         // entryName = entryName.toLowerCase();
 
@@ -1644,17 +1797,30 @@ public class CpRelationManager implements RelationManager {
             List<HColumn<ByteBuffer, ByteBuffer>> entries = null;
 
             if ( isMultiValue && validIndexableValue( entryValue ) ) {
-                entries = cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_INDEX_ENTRIES,
+                entries = cass.getColumns( 
+                    cass.getApplicationKeyspace( applicationId ), 
+                        ENTITY_INDEX_ENTRIES,
                         entity.getUuid(),
-                        new DynamicComposite( entryName, indexValueCode( entryValue ), toIndexableValue( entryValue ) ),
-                        setGreaterThanEqualityFlag( new DynamicComposite( entryName, indexValueCode( entryValue ),
-                                        toIndexableValue( entryValue ) ) ), INDEX_ENTRY_LIST_COUNT, false );
+                        new DynamicComposite( 
+                            entryName, 
+                            indexValueCode( entryValue ), 
+                            toIndexableValue( entryValue ) ),
+                        setGreaterThanEqualityFlag( 
+                            new DynamicComposite( 
+                                entryName, indexValueCode( entryValue ),
+                                toIndexableValue( entryValue ) ) ), 
+                        INDEX_ENTRY_LIST_COUNT, 
+                        false );
             }
             else {
-                entries = cass.getColumns( cass.getApplicationKeyspace( applicationId ), ENTITY_INDEX_ENTRIES,
-                        entity.getUuid(), new DynamicComposite( entryName ),
-                        setGreaterThanEqualityFlag( new DynamicComposite( entryName ) ), INDEX_ENTRY_LIST_COUNT,
-                        false );
+                entries = cass.getColumns( 
+                    cass.getApplicationKeyspace( applicationId ), 
+                    ENTITY_INDEX_ENTRIES, 
+                    entity.getUuid(), 
+                    new DynamicComposite( entryName ), 
+                    setGreaterThanEqualityFlag( new DynamicComposite( entryName ) ), 
+                    INDEX_ENTRY_LIST_COUNT, 
+                    false );
             }
 
             if ( logger.isDebugEnabled() ) {
@@ -1672,7 +1838,8 @@ public class CpRelationManager implements RelationManager {
                 // new format:
                 // composite(entryName,
                 // value_code,prev_value,prev_timestamp,prev_obj_path) = null
-                DynamicComposite composite = DynamicComposite.fromByteBuffer( entry.getName().duplicate() );
+                DynamicComposite composite = 
+                        DynamicComposite.fromByteBuffer( entry.getName().duplicate() );
                 prev_value = composite.get( 2 );
                 prev_timestamp = ( UUID ) composite.get( 3 );
                 if ( composite.size() > 4 ) {
@@ -1686,7 +1853,8 @@ public class CpRelationManager implements RelationManager {
                         entryPath = entryName + "." + prev_obj_path;
                     }
 
-                    indexUpdate.addPrevEntry( entryPath, prev_value, prev_timestamp, entry.getName().duplicate() );
+                    indexUpdate.addPrevEntry( 
+                            entryPath, prev_value, prev_timestamp, entry.getName().duplicate() );
 
                     // composite(property_value,connected_entity_id,entry_timestamp)
                     // addDeleteToMutator(batch, ENTITY_INDEX_ENTRIES,
@@ -1701,7 +1869,8 @@ public class CpRelationManager implements RelationManager {
 
         if ( !isMultiValue || ( isMultiValue && !removeListEntry ) ) {
 
-            List<Map.Entry<String, Object>> list = IndexUtils.getKeyValueList( entryName, entryValue, fulltextIndexed );
+            List<Map.Entry<String, Object>> list = 
+                    IndexUtils.getKeyValueList( entryName, entryValue, fulltextIndexed );
 
             if ( entryName.equalsIgnoreCase( "location" ) && ( entryValue instanceof Map ) ) {
                 @SuppressWarnings( "rawtypes" ) double latitude =
@@ -1715,14 +1884,15 @@ public class CpRelationManager implements RelationManager {
             for ( Map.Entry<String, Object> indexEntry : list ) {
 
                 if ( validIndexableValue( indexEntry.getValue() ) ) {
-                    indexUpdate.addNewEntry( indexEntry.getKey(), toIndexableValue( indexEntry.getValue() ) );
+                    indexUpdate.addNewEntry( 
+                            indexEntry.getKey(), toIndexableValue( indexEntry.getValue() ) );
                 }
             }
 
             if ( isMultiValue ) {
                 addInsertToMutator( batch, ENTITY_INDEX_ENTRIES, entity.getUuid(),
-                        asList( entryName, indexValueCode( entryValue ), toIndexableValue( entryValue ),
-                                indexUpdate.getTimestampUuid() ), null, timestamp );
+                    asList( entryName, indexValueCode( entryValue ), 
+                    toIndexableValue( entryValue ), indexUpdate.getTimestampUuid() ), null, timestamp );
             }
             else {
                 // int i = 0;
@@ -1740,7 +1910,8 @@ public class CpRelationManager implements RelationManager {
                     byte code = indexValueCode( indexEntry.getValue() );
                     Object val = toIndexableValue( indexEntry.getValue() );
                     addInsertToMutator( batch, ENTITY_INDEX_ENTRIES, entity.getUuid(),
-                            asList( entryName, code, val, indexUpdate.getTimestampUuid(), name ), null, timestamp );
+                            asList( entryName, code, val, indexUpdate.getTimestampUuid(), name ), 
+                            null, timestamp );
 
                     indexUpdate.addIndex( indexEntry.getKey() );
                 }
@@ -1844,10 +2015,17 @@ public class CpRelationManager implements RelationManager {
                 batchDeleteConnectionIndexEntries( indexUpdate, entry, connection, index_keys );
 
                 if ( "location.coordinates".equals( entry.getPath() ) ) {
-                    EntityLocationRef loc = new EntityLocationRef( indexUpdate.getEntity(), entry.getTimestampUuid(),
-                            entry.getValue().toString() );
-                    batchDeleteLocationInConnectionsIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_keys, entry.getPath(), loc );
+                    EntityLocationRef loc = new EntityLocationRef( 
+                        indexUpdate.getEntity(),
+                        entry.getTimestampUuid(),
+                        entry.getValue().toString() );
+                    batchDeleteLocationInConnectionsIndex( 
+                        indexUpdate.getBatch(),
+                        indexBucketLocator,
+                        applicationId,
+                        index_keys,
+                        entry.getPath(),
+                        loc );
                 }
             }
             else {
@@ -1855,19 +2033,25 @@ public class CpRelationManager implements RelationManager {
             }
         }
 
-        if ( ( indexUpdate.getNewEntries().size() > 0 ) && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue()
-                && !indexUpdate.isRemoveListEntry() ) ) ) {
+        if ( ( indexUpdate.getNewEntries().size() > 0 ) 
+                && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue() && !indexUpdate.isRemoveListEntry() ) ) ) {
 
             for ( IndexUpdate.IndexEntry indexEntry : indexUpdate.getNewEntries() ) {
 
                 batchAddConnectionIndexEntries( indexUpdate, indexEntry, connection, index_keys );
 
                 if ( "location.coordinates".equals( indexEntry.getPath() ) ) {
-                    EntityLocationRef loc =
-                            new EntityLocationRef( indexUpdate.getEntity(), indexEntry.getTimestampUuid(),
-                                    indexEntry.getValue().toString() );
-                    batchStoreLocationInConnectionsIndex( indexUpdate.getBatch(), indexBucketLocator, applicationId,
-                            index_keys, indexEntry.getPath(), loc );
+                    EntityLocationRef loc = new EntityLocationRef( 
+                        indexUpdate.getEntity(),
+                        indexEntry.getTimestampUuid(),
+                        indexEntry.getValue().toString() );
+                    batchStoreLocationInConnectionsIndex( 
+                        indexUpdate.getBatch(),
+                            indexBucketLocator,
+                            applicationId,
+                            index_keys,
+                            indexEntry.getPath(),
+                            loc );
                 }
             }
 
@@ -1897,10 +2081,11 @@ public class CpRelationManager implements RelationManager {
      *
      * @return connectionType The name of the edges to search
      */
-    private PagingResultsIterator getReversedConnectionsIterator( EntityRef targetEntity, String connectionType )
-            throws Exception {
+    private PagingResultsIterator getReversedConnectionsIterator( 
+            EntityRef targetEntity, String connectionType ) throws Exception {
 
-        return new PagingResultsIterator( getConnectingEntities( targetEntity, connectionType, null, Level.REFS ) );
+        return new PagingResultsIterator( 
+                getConnectingEntities( targetEntity, connectionType, null, Level.REFS ) );
     }
 
 
@@ -1912,8 +2097,11 @@ public class CpRelationManager implements RelationManager {
      * @param connectedEntityType The connected entity type, if not specified all types are returned
      * @param resultsLevel The results level to return
      */
-    private Results getConnectingEntities( EntityRef targetEntity, String connectionType, String connectedEntityType,
-                                           Level resultsLevel ) throws Exception {
+    private Results getConnectingEntities( 
+        EntityRef targetEntity,
+            String connectionType,
+            String connectedEntityType,
+            Level resultsLevel ) throws Exception {
 
         return getConnectingEntities( targetEntity, connectionType, connectedEntityType, resultsLevel, 0 );
     }
@@ -1927,16 +2115,21 @@ public class CpRelationManager implements RelationManager {
      * @param connectedEntityType The connected entity type, if not specified all types are returned
      * @param count result limit
      */
-    private Results getConnectingEntities( EntityRef targetEntity, String connectionType, String connectedEntityType,
-                                           Level level, int count ) throws Exception {
+    private Results getConnectingEntities( 
+            EntityRef targetEntity,
+            String connectionType,
+            String connectedEntityType,
+            Level level,
+            int count ) throws Exception {
 
         Query query = new Query();
         query.setResultsLevel( level );
         query.setLimit( count );
 
-        final ConnectionRefImpl connectionRef =
-                new ConnectionRefImpl( new SimpleEntityRef( connectedEntityType, null ), connectionType, targetEntity );
-        final ConnectionResultsLoaderFactory factory = new ConnectionResultsLoaderFactory( connectionRef );
+        final ConnectionRefImpl connectionRef = new ConnectionRefImpl( 
+                new SimpleEntityRef( connectedEntityType, null ), connectionType, targetEntity );
+        final ConnectionResultsLoaderFactory factory = 
+                new ConnectionResultsLoaderFactory( connectionRef );
 
         QueryProcessorImpl qp = new QueryProcessorImpl( query, null, em, factory );
         SearchConnectionVisitor visitor = new SearchConnectionVisitor( qp, connectionRef, false );
@@ -1946,9 +2139,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Metered( group = "core", name = "RelationManager_batchDeleteConnectionIndexEntries" )
-    public Mutator<ByteBuffer> batchDeleteConnectionIndexEntries( IndexUpdate indexUpdate, IndexUpdate.IndexEntry entry,
-                                                                  ConnectionRefImpl connection, UUID[] index_keys )
-            throws Exception {
+    public Mutator<ByteBuffer> batchDeleteConnectionIndexEntries( 
+            IndexUpdate indexUpdate,
+            IndexUpdate.IndexEntry entry,
+            ConnectionRefImpl connection,
+            UUID[] index_keys ) throws Exception {
 
         logger.debug( "batchDeleteConnectionIndexEntries" );
 
@@ -2059,15 +2254,16 @@ public class CpRelationManager implements RelationManager {
 
         private final ConnectionRefImpl connection;
 
-        /** True if we should search from source->target edges.  False if we should search from target<-source edges */
+        /** True if we should search from source->target edges.  
+         * False if we should search from target<-source edges */
         private final boolean outgoing;
 
 
         /**
          * @param queryProcessor They query processor to use
          * @param connection The connection refernce
-         * @param outgoing The direction to search.  True if we should search from source->target edges.  False if we
-         * should search from target<-source edges
+         * @param outgoing The direction to search.  True if we should search from source->target 
+         * edges.  False if we * should search from target<-source edges
          */
         public SearchConnectionVisitor( QueryProcessorImpl queryProcessor, ConnectionRefImpl connection,
                                         boolean outgoing ) {
@@ -2085,8 +2281,12 @@ public class CpRelationManager implements RelationManager {
         @Override
         protected IndexScanner secondaryIndexScan( QueryNode node, QuerySlice slice ) throws Exception {
 
-            UUID id = ConnectionRefImpl.getIndexId( ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE, headEntity,
-                    connection.getConnectionType(), connection.getConnectedEntityType(), new ConnectedEntityRef[0] );
+            UUID id = ConnectionRefImpl.getIndexId( 
+                    ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE,
+                    headEntity,
+                    connection.getConnectionType(),
+                    connection.getConnectedEntityType(),
+                    new ConnectedEntityRef[0] );
 
             Object key = key( id, INDEX_CONNECTIONS );
 
@@ -2120,10 +2320,13 @@ public class CpRelationManager implements RelationManager {
 
             queryProcessor.applyCursorAndSort( slice );
 
-            GeoIterator itr =
-                    new GeoIterator( new ConnectionGeoSearch( em, indexBucketLocator, cass, connection.getIndexId() ),
-                            query.getLimit(), slice, node.getPropertyName(),
-                            new Point( node.getLattitude(), node.getLongitude() ), node.getDistance() );
+            GeoIterator itr = new GeoIterator( 
+                new ConnectionGeoSearch( em, indexBucketLocator, cass, connection.getIndexId() ), 
+                query.getLimit(),
+                slice,
+                node.getPropertyName(),
+                new Point( node.getLattitude(), node.getLongitude() ),
+                node.getDistance() );
 
             results.push( itr );
         }
@@ -2181,12 +2384,20 @@ public class CpRelationManager implements RelationManager {
 
             //we need to iterate all connection types
             else {
-                connectionTypes = new ConnectionTypesIterator( cass, applicationId, entityIdToUse, outgoing, size );
+                connectionTypes = new ConnectionTypesIterator( 
+                        cass, applicationId, entityIdToUse, outgoing, size );
             }
 
-            IndexScanner connectionScanner =
-                    new ConnectedIndexScanner( cass, dictionaryType, applicationId, entityIdToUse, connectionTypes,
-                            start, slice.isReversed(), size, skipFirst );
+            IndexScanner connectionScanner = new ConnectedIndexScanner( 
+                    cass,
+                    dictionaryType,
+                    applicationId,
+                    entityIdToUse,
+                    connectionTypes,
+                    start,
+                    slice.isReversed(),
+                    size,
+                    skipFirst );
 
             this.results.push( new SliceIterator( slice, connectionScanner, connectionParser ) );
         }
@@ -2214,9 +2425,19 @@ public class CpRelationManager implements RelationManager {
 
         Object keyPrefix = key( indexKey, slice.getPropertyName() );
 
-        IndexScanner scanner = new IndexBucketScanner( cass, indexBucketLocator, ENTITY_INDEX, applicationId,
-                IndexBucketLocator.IndexType.CONNECTION, keyPrefix, range[0], range[1], slice.isReversed(), pageSize,
-                slice.hasCursor(), slice.getPropertyName() );
+        IndexScanner scanner = new IndexBucketScanner( 
+                cass,
+                indexBucketLocator,
+                ENTITY_INDEX,
+                applicationId,
+                IndexBucketLocator.IndexType.CONNECTION,
+                keyPrefix,
+                range[0],
+                range[1],
+                slice.isReversed(),
+                pageSize,
+                slice.hasCursor(),
+                slice.getPropertyName() );
 
         return scanner;
     }


[4/9] git commit: adding gatling script

Posted by sf...@apache.org.
adding gatling script


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

Branch: refs/heads/pushy_4-0
Commit: 8df2185a4a8530a63fe8ea7382e5db758437605d
Parents: 744e5a8
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Oct 28 12:43:19 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Oct 28 12:43:19 2014 -0600

----------------------------------------------------------------------
 stack/loadtests/src/main/scripts/gatling-mvn.sh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8df2185a/stack/loadtests/src/main/scripts/gatling-mvn.sh
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scripts/gatling-mvn.sh b/stack/loadtests/src/main/scripts/gatling-mvn.sh
new file mode 100644
index 0000000..ad02feb
--- /dev/null
+++ b/stack/loadtests/src/main/scripts/gatling-mvn.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+URL="$1"
+ORG="$2"
+APP="$3"
+NOTIFIER="$4"
+USERS="$5"
+RAMP="$6"
+shift 6
+rm -rf usergrid
+git clone https://github.com/apache/incubator-usergrid.git usergrid
+cd usergrid/stack
+git checkout -b two-dot-o origin/two-dot-o
+cd loadtests
+mvn clean install
+mvn gatling:execute -Dthrottle=3000 -Dduration=300 -DnumEntities=5000 -DnumUsers=${USERS} -DrampTime=${RAMP} -Dbaseurl=${URL} -Dorg=${ORG} -Dapp=${APP} -DpushNotifier=${NOTIFIER} -DpushProvider=noop


[6/9] git commit: Add a short-term cache to avoid redundant Entity reloading in CpEntityManager & CpRelationManager.

Posted by sf...@apache.org.
Add a short-term cache to avoid redundant Entity reloading in CpEntityManager & CpRelationManager.


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

Branch: refs/heads/pushy_4-0
Commit: c57196546f8c278b3eda3789015caa26d0c45229
Parents: 3d3f189
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 10:38:14 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 10:38:14 2014 -0400

----------------------------------------------------------------------
 .../main/resources/usergrid-default.properties  |  3 +
 .../corepersistence/CpEntityManager.java        | 73 +++++++++++++++++---
 .../corepersistence/CpRelationManager.java      | 31 +++++----
 .../persistence/index/query/EntityResults.java  |  6 +-
 4 files changed, 87 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/stack/config/src/main/resources/usergrid-default.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/main/resources/usergrid-default.properties b/stack/config/src/main/resources/usergrid-default.properties
index a4760dd..fb043d4 100644
--- a/stack/config/src/main/resources/usergrid-default.properties
+++ b/stack/config/src/main/resources/usergrid-default.properties
@@ -62,6 +62,9 @@ elasticsearch.port=9300
 
 index.query.limit.default=1000
 
+usergrid.entity_cache_size=200
+usergrid.entity_cache_timeout_ms=500
+
 
 ###############################################################################
 #

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/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 c9ad87b..78c9433 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
@@ -17,6 +17,10 @@ package org.apache.usergrid.corepersistence;
 
 
 import com.google.common.base.Preconditions;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
+import com.google.common.cache.LoadingCache;
 import com.netflix.hystrix.exception.HystrixRuntimeException;
 import com.yammer.metrics.annotation.Metered;
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
@@ -37,6 +41,8 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.UUID;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import me.prettyprint.hector.api.Keyspace;
 import me.prettyprint.hector.api.beans.ColumnSlice;
 import me.prettyprint.hector.api.beans.CounterRow;
@@ -86,10 +92,8 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_TYPE;
 import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
 import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 import static org.apache.usergrid.persistence.Schema.TYPE_ENTITY;
-import static org.apache.usergrid.persistence.Schema.getDefaultSchema;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import static org.apache.usergrid.persistence.SimpleEntityRef.getUuid;
-import static org.apache.usergrid.persistence.SimpleEntityRef.ref;
 import org.apache.usergrid.persistence.SimpleRoleRef;
 import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.cassandra.ApplicationCF;
@@ -131,7 +135,6 @@ import org.apache.usergrid.persistence.index.query.CounterResolution;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.index.query.Query.Level;
-import static org.apache.usergrid.persistence.index.query.Query.Level.REFS;
 import org.apache.usergrid.persistence.map.MapManager;
 import org.apache.usergrid.persistence.map.MapScope;
 import org.apache.usergrid.persistence.map.impl.MapScopeImpl;
@@ -140,7 +143,6 @@ import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.persistence.model.field.Field;
 import org.apache.usergrid.persistence.model.field.StringField;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.persistence.schema.CollectionInfo;
 import org.apache.usergrid.utils.ClassUtils;
 import static org.apache.usergrid.utils.ClassUtils.cast;
 import org.apache.usergrid.utils.CompositeUtils;
@@ -185,6 +187,9 @@ public class CpEntityManager implements EntityManager {
 
     private String TYPES_BY_UUID_MAP = "zzz_typesbyuuid_zzz";
 
+    /** Short-term cache to keep us from reloading same Entity during single request. */
+    private LoadingCache<EntityScope, org.apache.usergrid.persistence.model.entity.Entity> entityCache;
+
 
     public CpEntityManager() {}
 
@@ -206,6 +211,56 @@ public class CpEntityManager implements EntityManager {
 
         // set to false for now
         this.skipAggregateCounters = false;
+
+        int entityCacheSize = Integer.parseInt( 
+            cass.getProperties().getProperty("usergrid.entity_cache_size", "100"));
+
+        int entityCacheTimeout = Integer.parseInt( 
+            cass.getProperties().getProperty("usergrid.entity_cache_timeout_ms", "500"));
+
+        this.entityCache = CacheBuilder.newBuilder()
+            .maximumSize( entityCacheSize )
+            .expireAfterWrite( entityCacheTimeout, TimeUnit.MILLISECONDS )
+            .build( new CacheLoader<EntityScope, org.apache.usergrid.persistence.model.entity.Entity>() {
+                public org.apache.usergrid.persistence.model.entity.Entity load( EntityScope entityScope ) { 
+                    return managerCache.getEntityCollectionManager( 
+                        entityScope.scope ).load( entityScope.entityId ).toBlocking().lastOrDefault(null);
+                }
+            }
+        );
+    }
+
+
+    /** Needed to support short-term Entity cache. */ 
+    public static class EntityScope {
+        CollectionScope scope;
+        Id entityId;
+        public EntityScope( CollectionScope scope, Id entityId ) {
+            this.scope = scope;
+            this.entityId = entityId;
+        }
+    }
+
+
+    /**
+     * Load entity from short-term cache. 
+     * Package scope so that CpRelationManager can use it too.
+     * 
+     * @param es Carries Entity Id and CollectionScope from which to load Entity.
+     * @return Entity or null if not found
+     */
+    org.apache.usergrid.persistence.model.entity.Entity load( EntityScope es ) {
+        try {
+            return entityCache.get( es );
+            
+        } catch ( InvalidCacheLoadException icle ) { 
+            // fine, entity not found
+            return null;
+
+        } catch ( ExecutionException exex ) { 
+            // uh-oh, more serious problem
+            throw new RuntimeException( "Error loading entity", exex );
+        }
     }
 
 
@@ -320,7 +375,7 @@ public class CpEntityManager implements EntityManager {
 //        }
 
        org.apache.usergrid.persistence.model.entity.Entity cpEntity = 
-                ecm.load( id ).toBlockingObservable().last();
+               load( new EntityScope( collectionScope, id ) );
 
         if ( cpEntity == null ) {
             if ( logger.isDebugEnabled() ) {
@@ -407,7 +462,7 @@ public class CpEntityManager implements EntityManager {
 //        }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity = 
-                ecm.load( id ).toBlocking().last();
+            load( new EntityScope( collectionScope, id ) );
 
         if ( cpEntity == null ) {
             if ( logger.isDebugEnabled() ) {
@@ -497,6 +552,8 @@ public class CpEntityManager implements EntityManager {
 
         try {
             cpEntity = ecm.update( cpEntity ).toBlockingObservable().last();
+
+            // need to reload entity so bypass entity cache
             cpEntity = ecm.load( entityId ).toBlockingObservable().last();
 
             logger.debug("Wrote {}:{} version {}", new Object[] { 
@@ -545,7 +602,7 @@ public class CpEntityManager implements EntityManager {
 //        }
 
         org.apache.usergrid.persistence.model.entity.Entity entity = 
-                ecm.load( entityId ).toBlockingObservable().last();
+            load( new EntityScope( collectionScope, entityId ) );
 
         if ( entity != null ) {
 
@@ -996,7 +1053,7 @@ public class CpEntityManager implements EntityManager {
 //        }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity =
-                ecm.load( entityId ).toBlocking().last();
+            load( new EntityScope( collectionScope, entityId ) );
 
         cpEntity.removeField( propertyName );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/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 d0da90f..1e8dcc3 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
@@ -234,9 +234,9 @@ public class CpRelationManager implements RelationManager {
                 } );
         }
 
-        //TODO PERFORMANCE why are we loading this again here?
-        this.cpHeadEntity = ecm.load( new SimpleId( 
-            headEntity.getUuid(), headEntity.getType() )).toBlocking().lastOrDefault(null);
+        Id entityId = new SimpleId( headEntity.getUuid(), headEntity.getType() );
+        this.cpHeadEntity = ((CpEntityManager)em).load( 
+            new CpEntityManager.EntityScope( headEntityScope, entityId));
 
         // commented out because it is possible that CP entity has not been created yet
         Assert.notNull( cpHeadEntity, "cpHeadEntity cannot be null" );
@@ -626,12 +626,12 @@ public class CpRelationManager implements RelationManager {
                 applicationScope.getApplication(),
                 applicationScope.getApplication(),
                 CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ) );
-
         EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager( memberScope );
 
         //TODO, this double load should disappear once events are in
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load( 
-                new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlocking().last();
+        Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() ); 
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = 
+            ((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
 
         if ( memberEntity == null ) {
             throw new RuntimeException(
@@ -796,8 +796,9 @@ public class CpRelationManager implements RelationManager {
                });
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity memberEntity = memberMgr.load( 
-            new SimpleId( itemRef.getUuid(), itemRef.getType() ) ).toBlockingObservable().last();
+        Id entityId = new SimpleId( itemRef.getUuid(), itemRef.getType() ); 
+        org.apache.usergrid.persistence.model.entity.Entity memberEntity = 
+            ((CpEntityManager)em).load( new CpEntityManager.EntityScope( memberScope, entityId));
 
         final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         final EntityIndexBatch batch = ei.createBatch();
@@ -1015,9 +1016,9 @@ public class CpRelationManager implements RelationManager {
             });
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
-            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) )
-                .toBlockingObservable().last();
+        Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType()); 
+        org.apache.usergrid.persistence.model.entity.Entity targetEntity = 
+            ((CpEntityManager)em).load( new CpEntityManager.EntityScope( targetScope, entityId));
 
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
 
@@ -1240,12 +1241,12 @@ public class CpRelationManager implements RelationManager {
                     connectingEntityRef.getUuid(),
                     connectedEntityRef.getType(),
                     connectedEntityRef.getUuid()
-                    } );
+                });
         }
 
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
-            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ) ) 
-                .toBlockingObservable().last();
+        Id entityId = new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() );
+        org.apache.usergrid.persistence.model.entity.Entity targetEntity = 
+            ((CpEntityManager)em).load( new CpEntityManager.EntityScope( targetScope, entityId));
 
         // Delete graph edge connection from head entity to member entity
         Edge edge = new SimpleEdge( 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c5719654/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
index 4ce3848..b2aef93 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/EntityResults.java
@@ -67,18 +67,18 @@ public class EntityResults implements Iterable<Entity>, Iterator<Entity> {
 
 
     /**
-     * Advance to our next candidate so that it is avaiablel
+     * Advance to our next candidate so that it is available
      */
     private void doAdvance(){
         while(itr.hasNext() && next == null){
             CandidateResult candidate = itr.next();
 
-            //our candidate is > our max, we can't use it
+            // our candidate is > our max, we can't use it
             if( UUIDUtils.compare( candidate.getVersion(), maxVersion ) > 0){
                 continue;
             }
 
-            //our candidate was too new, ignore it
+            // our candidate was too new, ignore it
             next = ecm.load( candidate.getId() ).toBlocking().single();
         }
     }


[3/9] git commit: Backing out a test breaking change inadvertently made during formatting.

Posted by sf...@apache.org.
Backing out a test breaking change inadvertently made during formatting.


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

Branch: refs/heads/pushy_4-0
Commit: 744e5a814205b07522748d46f73291bd90aba0c0
Parents: 09d4ba4
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Oct 28 13:55:07 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Oct 28 13:55:07 2014 -0400

----------------------------------------------------------------------
 .../org/apache/usergrid/corepersistence/CpRelationManager.java     | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/744e5a81/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 180d08c..d0da90f 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
@@ -1504,7 +1504,7 @@ public class CpRelationManager implements RelationManager {
         if ( query.getSortPredicates().isEmpty() ) {
 
             Query.SortPredicate asc = 
-                new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.DESCENDING);
+                new Query.SortPredicate( PROPERTY_CREATED, Query.SortDirection.ASCENDING);
 
             query.addSort( asc );
         }


[9/9] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into pushy_4-0

Posted by sf...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into pushy_4-0


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

Branch: refs/heads/pushy_4-0
Commit: 78e34b2bfba8e699a4525426f0888b82f5f8b597
Parents: 25e36e6 a100c07
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Oct 29 10:29:06 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Oct 29 10:29:06 2014 -0600

----------------------------------------------------------------------
 .../main/resources/usergrid-default.properties  |   3 +
 .../corepersistence/CpEntityManager.java        |  73 +-
 .../corepersistence/CpEntityManagerFactory.java |  53 +-
 .../corepersistence/CpManagerCache.java         | 117 ++-
 .../corepersistence/CpRelationManager.java      | 944 +++++++++++--------
 .../persistence/index/query/EntityResults.java  |   6 +-
 stack/loadtests/src/main/scripts/gatling-mvn.sh |  28 +
 7 files changed, 767 insertions(+), 457 deletions(-)
----------------------------------------------------------------------



[5/9] git commit: Use Guava Cache for manager caches.

Posted by sf...@apache.org.
Use Guava Cache for manager caches.


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

Branch: refs/heads/pushy_4-0
Commit: 3d3f1897953bffa96b18a9012b34c0480c849cee
Parents: 8df2185
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 09:07:05 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 09:07:05 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpManagerCache.java         | 117 +++++++++++--------
 1 file changed, 70 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3d3f1897/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
index 62ea81f..99bde22 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
@@ -15,6 +15,11 @@
  */
 package org.apache.usergrid.corepersistence;
 
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
 import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
@@ -26,7 +31,7 @@ import org.apache.usergrid.persistence.index.EntityIndexFactory;
 import org.apache.usergrid.persistence.map.MapManager;
 import org.apache.usergrid.persistence.map.MapManagerFactory;
 import org.apache.usergrid.persistence.map.MapScope;
-import org.apache.usergrid.utils.LRUCache2;
+
 
 public class CpManagerCache {
 
@@ -36,19 +41,50 @@ public class CpManagerCache {
     private final MapManagerFactory mmf;
 
     // TODO: consider making these cache sizes and timeouts configurable
-    // TODO: replace with Guava cache
-    private final LRUCache2<CollectionScope, EntityCollectionManager> ecmCache
-            = new LRUCache2<CollectionScope, EntityCollectionManager>(50, 1 * 60 * 60 * 1000);
-
-    private final LRUCache2<ApplicationScope, EntityIndex> eiCache
-            = new LRUCache2<>(50, 1 * 60 * 60 * 1000);
-
-    private final LRUCache2<ApplicationScope, GraphManager> gmCache
-            = new LRUCache2<ApplicationScope, GraphManager>(50, 1 * 60 * 60 * 1000);
-
-    private final LRUCache2<MapScope, MapManager> mmCache
-            = new LRUCache2<MapScope, MapManager>(50, 1 * 60 * 60 * 1000);
 
+    private LoadingCache<CollectionScope, EntityCollectionManager> ecmCache = 
+        CacheBuilder.newBuilder()
+            .maximumSize(100)
+            .expireAfterWrite( 1, TimeUnit.HOURS)
+            .build( new CacheLoader<CollectionScope, EntityCollectionManager>() {
+                public EntityCollectionManager load( CollectionScope scope ) { 
+                    return ecmf.createCollectionManager( scope );
+                }
+            }
+        );
+
+    private LoadingCache<ApplicationScope, EntityIndex> eiCache = 
+        CacheBuilder.newBuilder()
+            .maximumSize(100)
+            .expireAfterWrite( 1, TimeUnit.HOURS )
+            .build( new CacheLoader<ApplicationScope, EntityIndex>() {
+                public EntityIndex load( ApplicationScope scope ) { 
+                    return eif.createEntityIndex( scope );
+                }
+            }
+        );
+
+    private LoadingCache<ApplicationScope, GraphManager> gmCache = 
+        CacheBuilder.newBuilder()
+            .maximumSize(100)
+            .expireAfterWrite( 1, TimeUnit.HOURS )
+            .build( new CacheLoader<ApplicationScope, GraphManager>() {
+                public GraphManager load( ApplicationScope scope ) { 
+                    return gmf.createEdgeManager( scope );
+                }
+            }
+        );
+
+    private LoadingCache<MapScope, MapManager> mmCache = 
+        CacheBuilder.newBuilder()
+            .maximumSize(100)
+            .expireAfterWrite( 1, TimeUnit.HOURS )
+            .build( new CacheLoader<MapScope, MapManager>() {
+                public MapManager load( MapScope scope ) { 
+                    return mmf.createMapManager( scope );
+                }
+            }
+        );
 
     public CpManagerCache(
             EntityCollectionManagerFactory ecmf, 
@@ -63,54 +99,41 @@ public class CpManagerCache {
     }
 
     public EntityCollectionManager getEntityCollectionManager(CollectionScope scope) {
-
-        EntityCollectionManager ecm = ecmCache.get(scope);
-
-        if (ecm == null) {
-            ecm = ecmf.createCollectionManager(scope);
-            ecmCache.put(scope, ecm);
+        try {
+            return ecmCache.get( scope );
+        } catch (ExecutionException ex) {
+            throw new RuntimeException("Error getting manager", ex);
         }
-        return ecm;
     }
 
-    public EntityIndex getEntityIndex(ApplicationScope applicationScope) {
-
-        EntityIndex ei = eiCache.get(applicationScope);
-
-        if (ei == null) {
-            ei = eif.createEntityIndex(applicationScope);
-            eiCache.put(applicationScope, ei);
+    public EntityIndex getEntityIndex(ApplicationScope appScope) {
+        try {
+            return eiCache.get( appScope );
+        } catch (ExecutionException ex) {
+            throw new RuntimeException("Error getting manager", ex);
         }
-        return ei;
     }
 
     public GraphManager getGraphManager(ApplicationScope appScope) {
-
-        GraphManager gm = gmCache.get(appScope);
-
-        if (gm == null) {
-            gm = gmf.createEdgeManager(appScope);
-            gmCache.put(appScope, gm);
+        try {
+            return gmCache.get( appScope );
+        } catch (ExecutionException ex) {
+            throw new RuntimeException("Error getting manager", ex);
         }
-        return gm;
     }
 
     public MapManager getMapManager( MapScope mapScope) {
-
-        MapManager mm = mmCache.get(mapScope);
-
-        if (mm == null) {
-            mm = mmf.createMapManager(mapScope);
-            mmCache.put(mapScope, mm);
+        try {
+            return mmCache.get( mapScope );
+        } catch (ExecutionException ex) {
+            throw new RuntimeException("Error getting manager", ex);
         }
-        return mm;
     }
 
     void flush() {
-        gmCache.purge();
-        ecmCache.purge();
-        eiCache.purge();
+        ecmCache.invalidateAll();
+        eiCache.invalidateAll();
+        gmCache.invalidateAll();
+        mmCache.invalidateAll();
     }
-
-
 }


[7/9] git commit: Only init application index at most once per JVM.

Posted by sf...@apache.org.
Only init application index at most once per JVM.


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

Branch: refs/heads/pushy_4-0
Commit: 89cf61f08f795bea8d8bf23d5213644f1e1eac3d
Parents: c571965
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 11:26:45 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 11:26:45 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 53 ++++++++++----------
 1 file changed, 27 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/89cf61f0/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 bc45769..6e6b461 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
@@ -24,9 +24,11 @@ import static java.lang.String.CASE_INSENSITIVE_ORDER;
 
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -91,23 +93,23 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     public static final Class<DynamicEntity> APPLICATION_ENTITY_CLASS = DynamicEntity.class;
 
-    // The System Application where we store app and org metadata
+    /** The System Application where we store app and org metadata */
     public static final UUID SYSTEM_APP_ID =
             UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
 
-    /**
-     * App where we store management info
-     */
+    /** App where we store management info */
     public static final  UUID MANAGEMENT_APPLICATION_ID =
             UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
 
-    /**
-     * TODO Dave what is this?
-     */
+    /** TODO Do we need this in two-dot-o? */
     public static final  UUID DEFAULT_APPLICATION_ID =
             UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
 
-    private AtomicBoolean init_indexes = new AtomicBoolean(  );
+    /** Have we already initialized the index for the management app? */
+    private AtomicBoolean indexInitialized = new AtomicBoolean(  );
+
+    /** Keep track of applications that already have indexes to avoid redundant re-creation. */
+    private static final Set<UUID> applicationIndexesCreated = new HashSet<UUID>();
 
 
     // cache of already instantiated entity managers
@@ -205,13 +207,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
 
     private EntityManager _getEntityManager( UUID applicationId ) {
+
         EntityManager em = new CpEntityManager();
         em.init( this, applicationId );
-        //TODO PERFORMANCE  Can we remove this?  Seems like we should fix our lifecycle instead...
-        //if this is the first time we've loaded this entity manager in the JVM, create it's indexes, it may be new
-        //not sure how to handle other than this if the system dies after the application em has been created
-        //but before the create call can create the index
-        em.createIndex();
+
+        // only need to do this once 
+        if ( !applicationIndexesCreated.contains( applicationId ) ) {
+            em.createIndex();
+            applicationIndexesCreated.add( applicationId );
+        }
+
         return em;
     }
 
@@ -295,10 +300,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         properties.put( PROPERTY_NAME, appName );
         EntityManager appEm = getEntityManager( applicationId );
 
-        //create our ES index since we're initializing this application
-//  TODO PERFORMANCE  pushed this down into the cache load can we do this here?
-//        appEm.createIndex();
-
         appEm.create( applicationId, TYPE_APPLICATION, properties );
         appEm.resetRoles();
         appEm.refreshIndex();
@@ -640,7 +641,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     private void maybeCreateIndexes() {
         // system app
-        if ( init_indexes.getAndSet( true ) ) {
+        if ( indexInitialized.getAndSet( true ) ) {
             return;
         }
 
@@ -653,16 +654,16 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private List<EntityIndex> getManagementIndexes() {
 
         return Arrays.asList(
-                getManagerCache().getEntityIndex(
-                        new ApplicationScopeImpl( new SimpleId( SYSTEM_APP_ID, "application" ) ) ),
+            getManagerCache().getEntityIndex(
+                new ApplicationScopeImpl( new SimpleId( SYSTEM_APP_ID, "application" ))),
 
-                // default app
-               getManagerCache().getEntityIndex(
-                       new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) ),
+            // management app
+            getManagerCache().getEntityIndex(
+                new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ))),
 
-                // management app
-               getManagerCache().getEntityIndex(
-                       new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) ) );
+            // default app TODO: do we need this in two-dot-o
+            getManagerCache().getEntityIndex(
+                new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ))));
     }
 
 


[2/9] git commit: Restoring some semblance of my original formatting, take it easy with that auto-formatter folks!

Posted by sf...@apache.org.
Restoring some semblance of my original formatting, take it easy with that auto-formatter folks!


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

Branch: refs/heads/pushy_4-0
Commit: 09d4ba444a20421316adfa3efd3e064d93a5fbb6
Parents: 3771e3f
Author: Dave Johnson <dm...@apigee.com>
Authored: Tue Oct 28 12:10:42 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Tue Oct 28 12:10:42 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      | 274 +++++++++----------
 1 file changed, 125 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09d4ba44/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 8c0d886..180d08c 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
@@ -186,10 +186,12 @@ public class CpRelationManager implements RelationManager {
     private ResultsLoaderFactory resultsLoaderFactory;
 
 
+
     public CpRelationManager() {}
 
 
-    public CpRelationManager init( EntityManager em,
+    public CpRelationManager init( 
+        EntityManager em, 
             CpEntityManagerFactory emf,
             UUID applicationId,
             EntityRef headEntity, 
@@ -223,7 +225,8 @@ public class CpRelationManager implements RelationManager {
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( headEntityScope );
         if ( logger.isDebugEnabled() ) {
             logger.debug( "Loading head entity {}:{} from scope\n   app {}\n   owner {}\n   name {}",
-                new Object[] { headEntity.getType(),
+                new Object[] {
+                    headEntity.getType(), 
                     headEntity.getUuid(),
                     headEntityScope.getApplication(),
                     headEntityScope.getOwner(),
@@ -233,7 +236,7 @@ public class CpRelationManager implements RelationManager {
 
         //TODO PERFORMANCE why are we loading this again here?
         this.cpHeadEntity = ecm.load( new SimpleId( 
-                headEntity.getUuid(), headEntity.getType() ) ).toBlocking() .lastOrDefault( null );
+            headEntity.getUuid(), headEntity.getType() )).toBlocking().lastOrDefault(null);
 
         // commented out because it is possible that CP entity has not been created yet
         Assert.notNull( cpHeadEntity, "cpHeadEntity cannot be null" );
@@ -248,18 +251,17 @@ public class CpRelationManager implements RelationManager {
     public Set<String> getCollectionIndexes( String collectionName ) throws Exception {
         final Set<String> indexes = new HashSet<String>();
 
-        GraphManager gm = managerCache.getGraphManager( applicationScope );
+        GraphManager gm = managerCache.getGraphManager(applicationScope);
 
         String edgeTypePrefix = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName );
 
-        logger.debug( "getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}",
-            new Object[] { edgeTypePrefix,
-                cpHeadEntity.getId().getType(),
-                cpHeadEntity.getId().getUuid() 
-            } ); 
+        logger.debug("getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}", 
+            new Object[] {
+                edgeTypePrefix, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid()
+        });
 
-        Observable<String> types = gm.getEdgeTypesFromSource( 
-            new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix, null ) );
+        Observable<String> types= gm.getEdgeTypesFromSource( 
+            new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix,  null ));
 
         Iterator<String> iter = types.toBlockingObservable().getIterator();
         while ( iter.hasNext() ) {
@@ -297,7 +299,6 @@ public class CpRelationManager implements RelationManager {
 
     /**
      * Gets containing collections and/or connections depending on the edge type you pass in
-     *
      * @param limit Max number to return
      * @param edgeType Edge type, edge type prefix or null to allow any edge type
      * @param fromEntityType Only consider edges from entities of this type
@@ -306,35 +307,34 @@ public class CpRelationManager implements RelationManager {
 
         Map<EntityRef, Set<String>> results = new LinkedHashMap<EntityRef, Set<String>>();
 
-        GraphManager gm = managerCache.getGraphManager( applicationScope );
+        GraphManager gm = managerCache.getGraphManager(applicationScope);
 
         Iterator<String> edgeTypes = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( 
-                cpHeadEntity.getId(), edgeType, null ) ).toBlocking() .getIterator();
+            cpHeadEntity.getId(), edgeType, null) ).toBlocking().getIterator();
 
-        logger.debug( "getContainers(): "
+        logger.debug("getContainers(): "
                 + "Searched for edges of type {}\n   to target {}:{}\n   in scope {}\n   found: {}",
-            new Object[] { edgeType,
+            new Object[] {
+                edgeType,
                 cpHeadEntity.getId().getType(),
                 cpHeadEntity.getId().getUuid(),
                 applicationScope.getApplication(),
                 edgeTypes.hasNext() 
-            } );
+        });
 
         while ( edgeTypes.hasNext() ) {
 
             String etype = edgeTypes.next();
 
             Observable<Edge> edges = gm.loadEdgesToTarget( new SimpleSearchByEdgeType( 
-                cpHeadEntity.getId(), etype, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null ) );
+                cpHeadEntity.getId(), etype, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, null ));
 
             Iterator<Edge> iter = edges.toBlockingObservable().getIterator();
             while ( iter.hasNext() ) {
                 Edge edge = iter.next();
 
-                if (     fromEntityType != null 
-                     && !fromEntityType.equals( edge.getSourceNode().getType() ) ) {
-                    logger.debug( "Ignoring edge from entity type {}", 
-                            edge.getSourceNode().getType() );
+                if ( fromEntityType != null && !fromEntityType.equals( edge.getSourceNode().getType() )) {
+                    logger.debug("Ignoring edge from entity type {}", edge.getSourceNode().getType());
                     continue;
                 }
 
@@ -342,10 +342,9 @@ public class CpRelationManager implements RelationManager {
                         edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
 
                 String name = null;
-                if ( CpNamingUtils.isConnectionEdgeType( edge.getType() ) ) {
+                if ( CpNamingUtils.isConnectionEdgeType( edge.getType() )) {
                     name = CpNamingUtils.getConnectionType( edge.getType() );
-                }
-                else {
+                } else {
                     name = CpNamingUtils.getCollectionName( edge.getType() );
                 }
                 addMapSet( results, eref, name );
@@ -366,11 +365,17 @@ public class CpRelationManager implements RelationManager {
 
         final GraphManager gm = managerCache.getGraphManager( applicationScope );
 
-        logger.debug( "updateContainingCollectionsAndCollections(): " + "Searched for edges to target {}:{}\n   in scope {}\n   found: {}",
-            new Object[] { cpHeadEntity.getId().getType(),
+        Iterator<String> edgeTypesToTarget = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( 
+            cpHeadEntity.getId(), null, null) ).toBlockingObservable().getIterator();
+
+        logger.debug("updateContainingCollectionsAndCollections(): "
+                + "Searched for edges to target {}:{}\n   in scope {}\n   found: {}", 
+            new Object[] {
+                cpHeadEntity.getId().getType(), 
                 cpHeadEntity.getId().getUuid(),
-                applicationScope.getApplication() 
-            } );
+                applicationScope.getApplication(),
+                edgeTypesToTarget.hasNext()
+        });
 
         // loop through all types of edge to target
 
@@ -444,13 +449,11 @@ public class CpRelationManager implements RelationManager {
 
         String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connectionType );
 
-        logger.debug( "isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}",
+        logger.debug("isConnectionMember(): Checking for edge type {} from {}:{} to {}:{}", 
             new Object[] { 
                 edgeType,
-                headEntity.getType(),
-                headEntity.getUuid(),
-                entity.getType(), entity.getUuid() 
-            } );
+                headEntity.getType(), headEntity.getUuid(), 
+                entity.getType(), entity.getUuid() });
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         Observable<Edge> edges = gm.loadEdgeVersions( new SimpleSearchByEdge( 
@@ -474,13 +477,11 @@ public class CpRelationManager implements RelationManager {
 
         String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( collName );
 
-        logger.debug( "isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}",
+        logger.debug("isCollectionMember(): Checking for edge type {} from {}:{} to {}:{}", 
             new Object[] { 
                 edgeType,
-                headEntity.getType(),
-                headEntity.getUuid(),
-                entity.getType(), entity.getUuid() 
-            } );
+                headEntity.getType(), headEntity.getUuid(), 
+                entity.getType(), entity.getUuid() });
 
         GraphManager gm = managerCache.getGraphManager( applicationScope );
         Observable<Edge> edges = gm.loadEdgeVersions( new SimpleSearchByEdge( 
@@ -709,8 +710,7 @@ public class CpRelationManager implements RelationManager {
     @Override
     @Metered( group = "core", name = "RelationManager_createItemInCollection" )
     public Entity createItemInCollection( 
-            String collName, String itemType, Map<String, Object> properties )
-            throws Exception {
+        String collName, String itemType, Map<String, Object> properties) throws Exception {
 
         if ( headEntity.getUuid().equals( applicationId ) ) {
             if ( itemType.equals( TYPE_ENTITY ) ) {
@@ -730,7 +730,6 @@ public class CpRelationManager implements RelationManager {
 
         else if ( headEntity.getType().equals( Group.ENTITY_TYPE ) 
                 && ( collName.equals( COLLECTION_ROLES ) ) ) {
-
             UUID groupId = headEntity.getUuid();
             String roleName = ( String ) properties.get( PROPERTY_NAME );
             return em.createGroupRole( groupId, roleName, ( Long ) properties.get( PROPERTY_INACTIVITY ) );
@@ -804,15 +803,17 @@ public class CpRelationManager implements RelationManager {
         final EntityIndexBatch batch = ei.createBatch();
 
         // remove item from collection index
-        IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
-                CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
+        IndexScope indexScope = new IndexScopeImpl(
+            cpHeadEntity.getId(), 
+            CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
 
         batch.deindex( indexScope, memberEntity );
 
         // remove collection from item index 
-        IndexScope itemScope = new IndexScopeImpl( memberEntity.getId(), CpNamingUtils
-                .getCollectionScopeNameFromCollectionName(
-                        Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ) );
+        IndexScope itemScope = new IndexScopeImpl(
+            memberEntity.getId(), 
+            CpNamingUtils.getCollectionScopeNameFromCollectionName(
+                    Schema.defaultCollectionName( cpHeadEntity.getId().getType() ) ));
 
 
         batch.deindex( itemScope, cpHeadEntity );
@@ -857,8 +858,8 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public void copyRelationships( String srcRelationName, EntityRef dstEntityRef, String dstRelationName )
-            throws Exception {
+    public void copyRelationships(String srcRelationName, EntityRef dstEntityRef, 
+            String dstRelationName) throws Exception {
 
         headEntity = em.validate( headEntity );
         dstEntityRef = em.validate( dstEntityRef );
@@ -903,15 +904,17 @@ public class CpRelationManager implements RelationManager {
 
         headEntity = em.validate( headEntity );
 
-        CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collName );
+        CollectionInfo collection = 
+            getDefaultSchema().getCollection( headEntity.getType(), collName );
 
         if ( collection == null ) {
             throw new RuntimeException( "Cannot find collection-info for '" + collName 
                     + "' of " + headEntity.getType() + ":" + headEntity .getUuid() );
         }
 
-        IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
-                CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
+        IndexScope indexScope = new IndexScopeImpl(
+            cpHeadEntity.getId(), 
+            CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
 
         EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
@@ -997,7 +1000,7 @@ public class CpRelationManager implements RelationManager {
         EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
 
         if ( logger.isDebugEnabled() ) {
-            logger.debug( "createConnection(): " 
+            logger.debug("createConnection(): "
                 + "Indexing connection type '{}'\n   from source {}:{}]\n"
                 + "   to target {}:{}\n   from scope\n   app {}\n   owner {}\n   name {}", 
                 new Object[] {
@@ -1009,7 +1012,7 @@ public class CpRelationManager implements RelationManager {
                     targetScope.getApplication(), 
                     targetScope.getOwner(), 
                     targetScope.getName()
-                } );
+            });
         }
 
         org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load( 
@@ -1335,8 +1338,9 @@ public class CpRelationManager implements RelationManager {
             final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
 
-            logger.debug( "Searching connected entities from scope {}:{}", 
-                    indexScope.getOwner().toString(), indexScope.getName() );
+            logger.debug("Searching connected entities from scope {}:{}",
+                indexScope.getOwner().toString(),
+                indexScope.getName());
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1422,8 +1426,9 @@ public class CpRelationManager implements RelationManager {
 
             EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
-            logger.debug( "Searching connections from the all-types scope {}:{}", 
-                    indexScope.getOwner().toString(), indexScope.getName() );
+            logger.debug("Searching connections from the all-types scope {}:{}",
+                indexScope.getOwner().toString(),
+                indexScope.getName());
 
             query = adjustQuery( query );
             CandidateResults crs = ei.search( indexScope, query );
@@ -1437,8 +1442,9 @@ public class CpRelationManager implements RelationManager {
             query.getConnectionType() ) );
         EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         
-        logger.debug( "Searching connections from the scope {}:{}", 
-                indexScope.getOwner().toString(), indexScope.getName() );
+        logger.debug("Searching connections from the scope {}:{}",
+            indexScope.getOwner().toString(),
+            indexScope.getName());
 
         query = adjustQuery( query );
         CandidateResults crs = ei.search( indexScope, query );
@@ -1738,55 +1744,26 @@ public class CpRelationManager implements RelationManager {
 
 
     public IndexUpdate batchStartIndexUpdate( 
-            Mutator<ByteBuffer> batch,
-            Entity entity,
-            String entryName,
-            Object entryValue,
-            UUID timestampUuid,
-            boolean schemaHasProperty,
-            boolean isMultiValue,
-            boolean removeListEntry,
-            boolean fulltextIndexed )
+            Mutator<ByteBuffer> batch, Entity entity, String entryName,
+            Object entryValue, UUID timestampUuid, boolean schemaHasProperty,
+             boolean isMultiValue, boolean removeListEntry, boolean fulltextIndexed )
             throws Exception {
-
-        return batchStartIndexUpdate( 
-                batch,
-                entity,
-                entryName,
-                entryValue,
-                timestampUuid,
-                schemaHasProperty,
-                isMultiValue,
-                removeListEntry,
-                fulltextIndexed,
-                false );
+        return batchStartIndexUpdate( batch, entity, entryName, entryValue, timestampUuid, 
+                schemaHasProperty, isMultiValue, removeListEntry, fulltextIndexed, false );
     }
 
 
-    @Metered( group = "core", name = "RelationManager_batchStartIndexUpdate" )
+    @Metered(group = "core", name = "RelationManager_batchStartIndexUpdate")
     public IndexUpdate batchStartIndexUpdate( 
-            Mutator<ByteBuffer> batch,
-            Entity entity,
-            String entryName,
-            Object entryValue,
-            UUID timestampUuid,
-            boolean schemaHasProperty,
-            boolean isMultiValue,
-            boolean removeListEntry,
-            boolean fulltextIndexed,
+        Mutator<ByteBuffer> batch, Entity entity, String entryName,
+        Object entryValue, UUID timestampUuid, boolean schemaHasProperty,
+        boolean isMultiValue, boolean removeListEntry, boolean fulltextIndexed,
             boolean skipRead ) throws Exception {
 
         long timestamp = getTimestampInMicros( timestampUuid );
 
-        IndexUpdate indexUpdate = new IndexUpdate( 
-                batch,
-                entity,
-                entryName,
-                entryValue,
-                schemaHasProperty,
-                isMultiValue,
-                removeListEntry,
-                timestampUuid );
+        IndexUpdate indexUpdate = new IndexUpdate( batch, entity, entryName, entryValue, 
+                schemaHasProperty, isMultiValue, removeListEntry, timestampUuid );
 
         // entryName = entryName.toLowerCase();
 
@@ -1891,8 +1868,11 @@ public class CpRelationManager implements RelationManager {
 
             if ( isMultiValue ) {
                 addInsertToMutator( batch, ENTITY_INDEX_ENTRIES, entity.getUuid(),
-                    asList( entryName, indexValueCode( entryValue ), 
-                    toIndexableValue( entryValue ), indexUpdate.getTimestampUuid() ), null, timestamp );
+                        asList( entryName, 
+                            indexValueCode( entryValue ), 
+                            toIndexableValue( entryValue ),
+                            indexUpdate.getTimestampUuid() ),
+                        null, timestamp );
             }
             else {
                 // int i = 0;
@@ -1933,13 +1913,15 @@ public class CpRelationManager implements RelationManager {
      *
      * @throws Exception the exception
      */
-    @Metered( group = "core", name = "RelationManager_batchUpdateBackwardConnectionsDictionaryIndexes" )
-    public IndexUpdate batchUpdateBackwardConnectionsDictionaryIndexes( IndexUpdate indexUpdate ) throws Exception {
+    @Metered(group = "core", name = "RelationManager_batchUpdateBackwardConnectionsDictionaryIndexes")
+    public IndexUpdate batchUpdateBackwardConnectionsDictionaryIndexes( 
+            IndexUpdate indexUpdate ) throws Exception {
 
         logger.debug( "batchUpdateBackwardConnectionsListIndexes" );
 
         boolean entityHasDictionary = getDefaultSchema()
-                .isDictionaryIndexedInConnections( indexUpdate.getEntity().getType(), indexUpdate.getEntryName() );
+                .isDictionaryIndexedInConnections( 
+                        indexUpdate.getEntity().getType(), indexUpdate.getEntryName() );
 
         if ( !entityHasDictionary ) {
             return indexUpdate;
@@ -1951,8 +1933,8 @@ public class CpRelationManager implements RelationManager {
 
 
     /**
-     * Search each reverse connection type in the graph for connections. If one is found, update the index
-     * appropriately
+     * Search each reverse connection type in the graph for connections.  
+     * If one is found, update the index appropriately
      *
      * @param indexUpdate The index update to use
      *
@@ -1968,7 +1950,8 @@ public class CpRelationManager implements RelationManager {
 
         for ( String connectionType : connectionTypes ) {
 
-            PagingResultsIterator itr = getReversedConnectionsIterator( targetEntity, connectionType );
+            PagingResultsIterator itr = 
+                    getReversedConnectionsIterator( targetEntity, connectionType );
 
             for ( Object connection : itr ) {
 
@@ -1997,9 +1980,9 @@ public class CpRelationManager implements RelationManager {
      *
      * @throws Exception the exception
      */
-    @Metered( group = "core", name = "RelationManager_batchUpdateConnectionIndex" )
-    public IndexUpdate batchUpdateConnectionIndex( IndexUpdate indexUpdate, ConnectionRefImpl connection )
-            throws Exception {
+    @Metered(group = "core", name = "RelationManager_batchUpdateConnectionIndex")
+    public IndexUpdate batchUpdateConnectionIndex( 
+            IndexUpdate indexUpdate, ConnectionRefImpl connection ) throws Exception {
 
         logger.debug( "batchUpdateConnectionIndex" );
 
@@ -2015,17 +1998,12 @@ public class CpRelationManager implements RelationManager {
                 batchDeleteConnectionIndexEntries( indexUpdate, entry, connection, index_keys );
 
                 if ( "location.coordinates".equals( entry.getPath() ) ) {
-                    EntityLocationRef loc = new EntityLocationRef( 
-                        indexUpdate.getEntity(),
-                        entry.getTimestampUuid(),
+                    EntityLocationRef loc = 
+                        new EntityLocationRef( indexUpdate.getEntity(), entry.getTimestampUuid(),
                         entry.getValue().toString() );
                     batchDeleteLocationInConnectionsIndex( 
-                        indexUpdate.getBatch(),
-                        indexBucketLocator,
-                        applicationId,
-                        index_keys,
-                        entry.getPath(),
-                        loc );
+                        indexUpdate.getBatch(), indexBucketLocator, applicationId,
+                        index_keys, entry.getPath(), loc );
                 }
             }
             else {
@@ -2034,24 +2012,22 @@ public class CpRelationManager implements RelationManager {
         }
 
         if ( ( indexUpdate.getNewEntries().size() > 0 ) 
-                && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue() && !indexUpdate.isRemoveListEntry() ) ) ) {
+                && ( !indexUpdate.isMultiValue() || ( indexUpdate.isMultiValue()
+                && !indexUpdate.isRemoveListEntry() ) ) ) {
 
             for ( IndexUpdate.IndexEntry indexEntry : indexUpdate.getNewEntries() ) {
 
                 batchAddConnectionIndexEntries( indexUpdate, indexEntry, connection, index_keys );
 
                 if ( "location.coordinates".equals( indexEntry.getPath() ) ) {
-                    EntityLocationRef loc = new EntityLocationRef( 
+                    EntityLocationRef loc =
+                            new EntityLocationRef( 
                         indexUpdate.getEntity(),
                         indexEntry.getTimestampUuid(),
                         indexEntry.getValue().toString() );
                     batchStoreLocationInConnectionsIndex( 
-                        indexUpdate.getBatch(),
-                            indexBucketLocator,
-                            applicationId,
-                            index_keys,
-                            indexEntry.getPath(),
-                            loc );
+                            indexUpdate.getBatch(), indexBucketLocator, applicationId,
+                            index_keys, indexEntry.getPath(), loc );
                 }
             }
 
@@ -2066,7 +2042,7 @@ public class CpRelationManager implements RelationManager {
 
         for ( String index : indexUpdate.getIndexesSet() ) {
             addInsertToMutator( indexUpdate.getBatch(), ENTITY_DICTIONARIES,
-                    key( connection.getConnectingIndexId(), Schema.DICTIONARY_INDEXES ), index, null,
+                    key( connection.getConnectingIndexId(), Schema.DICTIONARY_INDEXES), index, null,
                     indexUpdate.getTimestamp() );
         }
 
@@ -2098,12 +2074,11 @@ public class CpRelationManager implements RelationManager {
      * @param resultsLevel The results level to return
      */
     private Results getConnectingEntities( 
-        EntityRef targetEntity,
-            String connectionType,
-            String connectedEntityType,
+            EntityRef targetEntity, String connectionType, String connectedEntityType,
             Level resultsLevel ) throws Exception {
 
-        return getConnectingEntities( targetEntity, connectionType, connectedEntityType, resultsLevel, 0 );
+        return getConnectingEntities(
+                targetEntity, connectionType, connectedEntityType, resultsLevel, 0);
     }
 
 
@@ -2115,12 +2090,8 @@ public class CpRelationManager implements RelationManager {
      * @param connectedEntityType The connected entity type, if not specified all types are returned
      * @param count result limit
      */
-    private Results getConnectingEntities( 
-            EntityRef targetEntity,
-            String connectionType,
-            String connectedEntityType,
-            Level level,
-            int count ) throws Exception {
+    private Results getConnectingEntities( EntityRef targetEntity, String connectionType, 
+            String connectedEntityType, Level level, int count) throws Exception {
 
         Query query = new Query();
         query.setResultsLevel( level );
@@ -2200,9 +2171,11 @@ public class CpRelationManager implements RelationManager {
         logger.debug( "batchAddConnectionIndexEntries" );
 
         // entity_id,prop_name
-        Object property_index_key = key( index_keys[ConnectionRefImpl.ALL], INDEX_CONNECTIONS, entry.getPath(),
-                indexBucketLocator.getBucket( applicationId, IndexBucketLocator.IndexType.CONNECTION,
-                        index_keys[ConnectionRefImpl.ALL], entry.getPath() ) );
+        Object property_index_key = key( index_keys[ConnectionRefImpl.ALL], 
+                INDEX_CONNECTIONS, entry.getPath(),
+                indexBucketLocator.getBucket( applicationId, 
+                        IndexBucketLocator.IndexType.CONNECTION, index_keys[ConnectionRefImpl.ALL],
+                        entry.getPath() ) );
 
         // entity_id,entity_type,prop_name
         Object entity_type_prop_index_key =
@@ -2218,7 +2191,8 @@ public class CpRelationManager implements RelationManager {
 
         // entity_id,connection_type,entity_type,prop_name
         Object connection_type_and_entity_type_prop_index_key =
-                key( index_keys[ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE], INDEX_CONNECTIONS, entry.getPath(),
+            key( index_keys[ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE], 
+                INDEX_CONNECTIONS, entry.getPath(),
                         indexBucketLocator.getBucket( applicationId, IndexBucketLocator.IndexType.CONNECTION,
                                 index_keys[ConnectionRefImpl.BY_CONNECTION_AND_ENTITY_TYPE], entry.getPath() ) );
 
@@ -2229,17 +2203,19 @@ public class CpRelationManager implements RelationManager {
 
         // composite(property_value,connected_entity_id,connection_type,entry_timestamp)
         addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, entity_type_prop_index_key,
-                entry.getIndexComposite( conn.getConnectedEntityId(), conn.getConnectionType() ), conn.getUuid(),
-                indexUpdate.getTimestamp() );
+            entry.getIndexComposite( conn.getConnectedEntityId(), conn.getConnectionType() ),
+            conn.getUuid(), indexUpdate.getTimestamp() );
 
         // composite(property_value,connected_entity_id,entity_type,entry_timestamp)
         addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, connection_type_prop_index_key,
-                entry.getIndexComposite( conn.getConnectedEntityId(), conn.getConnectedEntityType() ), conn.getUuid(),
-                indexUpdate.getTimestamp() );
+            entry.getIndexComposite( conn.getConnectedEntityId(), conn.getConnectedEntityType() ),
+            conn.getUuid(), indexUpdate.getTimestamp() );
 
         // composite(property_value,connected_entity_id,entry_timestamp)
-        addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, connection_type_and_entity_type_prop_index_key,
-                entry.getIndexComposite( conn.getConnectedEntityId() ), conn.getUuid(), indexUpdate.getTimestamp() );
+        addInsertToMutator( indexUpdate.getBatch(), ENTITY_INDEX, 
+            connection_type_and_entity_type_prop_index_key,
+            entry.getIndexComposite( conn.getConnectedEntityId() ), conn.getUuid(),
+            indexUpdate.getTimestamp() );
 
         return indexUpdate.getBatch();
     }


[8/9] git commit: Add missing ASL header.

Posted by sf...@apache.org.
Add missing ASL header.


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

Branch: refs/heads/pushy_4-0
Commit: a100c0741f8900dff7cb786b7396962729ae4e6c
Parents: 89cf61f
Author: Dave Johnson <dm...@apigee.com>
Authored: Wed Oct 29 11:59:14 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Wed Oct 29 11:59:14 2014 -0400

----------------------------------------------------------------------
 stack/loadtests/src/main/scripts/gatling-mvn.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a100c074/stack/loadtests/src/main/scripts/gatling-mvn.sh
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scripts/gatling-mvn.sh b/stack/loadtests/src/main/scripts/gatling-mvn.sh
index ad02feb..531a638 100644
--- a/stack/loadtests/src/main/scripts/gatling-mvn.sh
+++ b/stack/loadtests/src/main/scripts/gatling-mvn.sh
@@ -1,4 +1,17 @@
 #!/bin/sh
+#
+# Licensed 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.
+#
 URL="$1"
 ORG="$2"
 APP="$3"