You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/20 15:46:29 UTC

[01/50] [abbrv] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into cloudformation-update

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o-events d9ace9e09 -> 3551f3c63


Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into cloudformation-update


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

Branch: refs/heads/two-dot-o-events
Commit: b84bbc16b0bea09a2bb55fd0b8166267691da24a
Parents: e8e6d1c d52ad4c
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 15 17:47:26 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 15 17:47:26 2014 -0600

----------------------------------------------------------------------
 .../notifications/apns/NotificationsServiceIT.java   | 12 ++++++------
 .../notifications/gcm/NotificationsServiceIT.java    | 15 +++++----------
 2 files changed, 11 insertions(+), 16 deletions(-)
----------------------------------------------------------------------



[46/50] [abbrv] git commit: Changed health check to 10 seconds

Posted by sn...@apache.org.
Changed health check to 10 seconds


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

Branch: refs/heads/two-dot-o-events
Commit: e361ea8ef61f2d94a120b0b66203e7d46c4bdc9e
Parents: 0177202
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 18:17:40 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 18:17:40 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/ugcluster-cf.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e361ea8e/stack/awscluster/ugcluster-cf.json
----------------------------------------------------------------------
diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json
index dea9694..0e5570d 100644
--- a/stack/awscluster/ugcluster-cf.json
+++ b/stack/awscluster/ugcluster-cf.json
@@ -1089,7 +1089,7 @@
                     "Target": "HTTP:8080/status",
                     "HealthyThreshold": "2",
                     "UnhealthyThreshold": "8",
-                    "Interval": "30",
+                    "Interval": "10",
                     "Timeout": "5"
                 },
                 "CrossZone": "true"


[25/50] [abbrv] git commit: Fixes incorrect seek value on edge types

Posted by sn...@apache.org.
Fixes incorrect seek value on edge types


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

Branch: refs/heads/two-dot-o-events
Commit: 5a0410780858836506207287ac984a7331f06aa6
Parents: 059a952
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 10:34:07 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 10:34:07 2014 -0600

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


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5a041078/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index 636cc91..ecf7787 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -81,7 +81,7 @@ public class CpWalker {
         //only search edge types that start with collections
 
         Observable<String> edgeTypes = gm.getEdgeTypesFromSource(
-                       new SimpleSearchEdgeType( applicationId, CpNamingUtils.EDGE_COLL_SUFFIX+"users", null ) );
+                       new SimpleSearchEdgeType( applicationId, CpNamingUtils.EDGE_COLL_SUFFIX, null ) );
 
         edgeTypes.flatMap( new Func1<String, Observable<Edge>>() {
             @Override


[48/50] [abbrv] git commit: Fixes cassandra heap

Posted by sn...@apache.org.
Fixes cassandra heap


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

Branch: refs/heads/two-dot-o-events
Commit: f7b751393b50c357ec3061f19009220aa9beae09
Parents: fc6ac11
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 20:06:46 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 20:06:46 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/src/main/dist/init_instance/install_cassandra.sh | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f7b75139/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh b/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
index 280ae40..0e7c465 100644
--- a/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
+++ b/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
@@ -39,6 +39,9 @@ cd /usr/share/usergrid/scripts
 groovy registry_register.groovy cassandra
 groovy wait_for_instances.groovy cassandra ${CASSANDRA_NUM_SERVERS}
 
+#Set or min/max heap to 8GB
+sed -i.bak s/calculate_heap_sizes\(\)/MAX_HEAP_SIZE="8G"\\nHEAP_NEWSIZE="1200M"\\n\ncalculate_heap_sizes\(\)/g /etc/cassandra/cassandra-env.sh
+
 cd /usr/share/usergrid/scripts
 groovy configure_cassandra.groovy > /etc/cassandra/cassandra.yaml
 /etc/init.d/cassandra start


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

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

Conflicts:
	stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
	stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java


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

Branch: refs/heads/two-dot-o-events
Commit: 68bd94fd0d2672054fc28734837e0b80849259c9
Parents: 6f040c7
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Oct 17 15:12:07 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Oct 17 15:12:07 2014 -0400

----------------------------------------------------------------------
 .../org/apache/usergrid/corepersistence/CpWalker.java    |  4 ----
 .../persistence/PerformanceEntityRebuildIndexTest.java   | 11 ++++-------
 2 files changed, 4 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68bd94fd/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index ecf7787..27d4224 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -15,9 +15,6 @@
  */
 package org.apache.usergrid.corepersistence;
 
-
-import java.util.Stack;
-
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,7 +35,6 @@ import rx.Observable;
 import rx.functions.Action1;
 import rx.functions.Func1;
 
-import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/68bd94fd/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index 619fb89..837dd9d 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -21,7 +21,6 @@ import java.util.concurrent.TimeUnit;
 
 import org.junit.After;
 import org.junit.Before;
-import org.junit.Ignore;
 import org.junit.Rule;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -47,9 +46,7 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
 import org.apache.usergrid.persistence.index.EntityIndex;
 import org.apache.usergrid.persistence.index.EntityIndexFactory;
-import org.apache.usergrid.persistence.index.IndexScope;
 import org.apache.usergrid.persistence.index.impl.EsEntityIndexImpl;
-import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
@@ -66,9 +63,9 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
     private static final MetricRegistry registry = new MetricRegistry();
     private Slf4jReporter reporter;
 
-    private static final long RUNTIME = TimeUnit.SECONDS.toMillis( 5 );
+    private static final long RUNTIME_MS = TimeUnit.SECONDS.toMillis( 5 );
 
-    private static final long writeDelayMs = 10;
+    private static final long WRITE_DELAY_MS = 10;
 
     @Rule
     public Application app = new CoreApplication( setup );
@@ -126,7 +123,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
         Entity cat2 = em.create("cat", cat2map );
         Entity cat3 = em.create("cat", cat3map );
 
-        final long stopTime = System.currentTimeMillis() + RuntimeMs;
+        final long stopTime = System.currentTimeMillis() + RUNTIME_MS;
 
         List<EntityRef> entityRefs = new ArrayList<EntityRef>();
         int entityCount = 0;
@@ -154,7 +151,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
             }
 
             entityCount++;
-            try { Thread.sleep( writeDelayMs ); } catch (InterruptedException ignored ) {}
+            try { Thread.sleep( WRITE_DELAY_MS ); } catch (InterruptedException ignored ) {}
         }
 
         logger.info("Created {} entities", entityCount);


[12/50] [abbrv] git commit: Work in progress on refactoring visitor to only update entities since connections are handled internally

Posted by sn...@apache.org.
Work in progress on refactoring visitor to only update entities since connections are handled internally


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

Branch: refs/heads/two-dot-o-events
Commit: 163fa9adf163226521d5724dce1cdac974de3b38
Parents: 9da529b
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 11:39:12 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 11:39:12 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  83 ++--------
 .../corepersistence/CpEntityManagerFactory.java |  22 +--
 .../usergrid/corepersistence/CpVisitor.java     |  11 +-
 .../usergrid/corepersistence/CpWalker.java      | 155 +++++++------------
 .../persistence/EntityManagerFactory.java       |   8 +-
 .../org/apache/usergrid/CoreApplication.java    |   1 +
 .../PerformanceEntityRebuildIndexTest.java      |  20 ++-
 .../apache/usergrid/rest/SystemResource.java    |  47 +++---
 8 files changed, 135 insertions(+), 212 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/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 8753670..4015014 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
@@ -109,6 +109,7 @@ import static org.apache.usergrid.persistence.cassandra.Serializers.ue;
 import org.apache.usergrid.persistence.cassandra.util.TraceParticipant;
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.exception.WriteOptimisticVerifyException;
 import org.apache.usergrid.persistence.collection.exception.WriteUniqueVerifyException;
 import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
@@ -2869,94 +2870,32 @@ public class CpEntityManager implements EntityManager {
      */
     public void reindex( final EntityManagerFactory.ProgressObserver po ) throws Exception {
 
-        CpWalker walker = new CpWalker();
+        CpWalker walker = new CpWalker(po.getWriteDelayTime());
 
         walker.walkCollections( this, application, new CpVisitor() {
 
             @Override
             public void visitCollectionEntry(
-                    EntityManager em, String collName, Entity source, Entity target) {
+                    EntityManager em, String collName, Entity entity) {
 
                 try {
-                    em.update( target);
-                    po.onProgress(source, target, collName);
-
-                } catch (Exception ex) {
-                    logger.error("Error repersisting entity", ex);
+                    em.update( entity);
+                    po.onProgress(entity);
                 }
-            }
-
-            @Override
-            public void visitConnectionEntry(
-                    EntityManager em, String connType, Entity source, Entity target) {
-
-                try {
-                    em.update( target);
-                    po.onProgress(source, target, connType);
-
-                } catch (Exception ex) {
+                catch(WriteOptimisticVerifyException wo ){
+                    //swallow this, it just means this was already updated, which accomplishes our task.  Just ignore.
+                    logger.warn( "Someone beat us to updating entity {} in collection {}.  Ignoring.", entity.getName(), collName );
+                }
+                catch (Exception ex) {
                     logger.error("Error repersisting entity", ex);
                 }
             }
 
-        });
-    }
-
-
-    private void indexEntityIntoCollections( 
-            org.apache.usergrid.persistence.model.entity.Entity collectionEntity, 
-            org.apache.usergrid.persistence.model.entity.Entity memberEntity, 
-            String collName, 
-            boolean connectBack ) {
-
-        logger.debug("Indexing into collections {} {}:{} member {}:{}", new Object[] { 
-            collName, collectionEntity.getId().getType(), collectionEntity.getId().getUuid(),
-            memberEntity.getId().getType(), memberEntity.getId().getUuid() });
-
-        indexEntityIntoCollection( collectionEntity, memberEntity, collName);
 
-        CollectionInfo collection = getDefaultSchema()
-                .getCollection( memberEntity.getId().getType(), collName);
-
-        if (connectBack && collection != null && collection.getLinkedCollection() != null) {
-
-            logger.debug("Linking back from entity in collection {} to collection {}", 
-                collection.getName(), collection.getLinkedCollection());
-
-            indexEntityIntoCollections( 
-                memberEntity, collectionEntity, collection.getLinkedCollection(), false );
-        }
+        });
     }
 
 
-    void indexEntityIntoConnection(
-            org.apache.usergrid.persistence.model.entity.Entity sourceEntity,
-            org.apache.usergrid.persistence.model.entity.Entity targetEntity,
-            String connType) {
-
-        logger.debug("Indexing into connection {} source {}:{} target {}:{}", new Object[] { 
-            connType, sourceEntity.getId().getType(), sourceEntity.getId().getUuid(),
-            targetEntity.getId().getType(), targetEntity.getId().getUuid() });
-
-
-        final EntityIndex ei = getManagerCache().getEntityIndex(getApplicationScope());
-        final EntityIndexBatch batch = ei.createBatch();
-
-        // Index the new connection in app|source|type context
-        IndexScope indexScope = new IndexScopeImpl(
-                sourceEntity.getId(),
-                CpNamingUtils.getConnectionScopeName( targetEntity.getId().getType(), connType ));
-        batch.index(indexScope, targetEntity);
-        
-        // Index the new connection in app|scope|all-types context
-        IndexScope allTypesIndexScope = new IndexScopeImpl(
-                sourceEntity.getId(),
-                CpNamingUtils.ALL_TYPES);
-
-        batch.index(allTypesIndexScope, targetEntity);
-
-        batch.execute();
-    }
 
 
     void indexEntityIntoCollection(

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/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 2abe83f..8ab0b7f 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
@@ -101,7 +101,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public static final  UUID DEFAULT_APPLICATION_ID =
             UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
 
-    private static AtomicBoolean INIT_SYSTEM = new AtomicBoolean(  );
+    private AtomicBoolean init_indexes = new AtomicBoolean(  );
 
 
     // cache of already instantiated entity managers
@@ -201,6 +201,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private EntityManager _getEntityManager( UUID applicationId ) {
         EntityManager em = new CpEntityManager();
         em.init( this, applicationId );
+        //TODO T.N. Can we remove this?  Seems like we should fix our lifecycle instead...
+        em.createIndex();
         return em;
     }
 
@@ -628,7 +630,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
 
     private void maybeCreateIndexes() {
         // system app
-        if ( INIT_SYSTEM.getAndSet( true ) ) {
+        if ( init_indexes.getAndSet( true ) ) {
             return;
         }
 
@@ -641,16 +643,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" ) ) ),
+               getManagerCache().getEntityIndex(
+                       new ApplicationScopeImpl( new SimpleId( getManagementAppId(), "application" ) ) ),
 
                 // management app
-               getManagerCache().getEntityIndex( new ApplicationScopeImpl(
-                        new SimpleId( getDefaultAppId(), "application" ) ) ) );
+               getManagerCache().getEntityIndex(
+                       new ApplicationScopeImpl( new SimpleId( getDefaultAppId(), "application" ) ) ) );
     }
 
 
@@ -682,8 +684,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager em = getEntityManager( appId );
         Application app = em.getApplication();
 
-        ((CpEntityManager)em).reindex( po );
-        em.refreshIndex();
+        em.reindex( po );
+//        em.refreshIndex();
 
         logger.info("\n\nRebuilt index for application {} id {}\n", app.getName(), appId );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpVisitor.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpVisitor.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpVisitor.java
index 5d32235..aa06744 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpVisitor.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpVisitor.java
@@ -24,9 +24,12 @@ import org.apache.usergrid.persistence.EntityManager;
  */
 public interface CpVisitor {
 
+    /**
+     * Visit the entity as we're walking the structure
+     * @param em
+     * @param collName
+     * @param visitedEntity
+     */
     public void visitCollectionEntry( 
-        EntityManager em, String collName, Entity sourceEntity, Entity targetEntity );
-
-    public void visitConnectionEntry( 
-        EntityManager em, String connType, Entity sourceEntity, Entity targetEntity );
+        EntityManager em, String collName, Entity visitedEntity );
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index b507edd..d491d3d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -15,12 +15,15 @@
  */
 package org.apache.usergrid.corepersistence;
 
+
 import java.util.Stack;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.Entity;
 import org.apache.usergrid.persistence.EntityRef;
-import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.graph.Edge;
@@ -30,10 +33,12 @@ import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+
 import rx.Observable;
 import rx.functions.Action1;
+import rx.functions.Func1;
+
+import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 
 
 /**
@@ -43,125 +48,83 @@ public class CpWalker {
 
     private static final Logger logger = LoggerFactory.getLogger( CpWalker.class );
 
-    private long writeDelayMs = 100;
+    private final long writeDelayMs;
+
 
+    /**
+     * Wait the set amount of time between successive writes.
+     * @param writeDelayMs
+     */
+    public CpWalker(final long writeDelayMs){
+         this.writeDelayMs = writeDelayMs;
+    }
 
-    public void walkCollections( final CpEntityManager em, final EntityRef start, 
-            final CpVisitor visitor ) throws Exception {
 
-        Stack stack = new Stack();
-        Id appId = new SimpleId( em.getApplicationId(), TYPE_APPLICATION );
-        stack.push( appId );
+    public void walkCollections( final CpEntityManager em, final EntityRef start, final CpVisitor visitor )
+            throws Exception {
 
-        doWalkCollections(em, new SimpleId(start.getUuid(), start.getType()), visitor, new Stack());
+        doWalkCollections( em, new SimpleId( start.getUuid(), start.getType() ), visitor );
     }
 
 
-    private void doWalkCollections( final CpEntityManager em, final Id start, 
-            final CpVisitor visitor, final Stack stack ) {
+    private void doWalkCollections( final CpEntityManager em, final Id start, final CpVisitor visitor ) {
 
         final Id fromEntityId = new SimpleId( start.getUuid(), start.getType() );
 
         final ApplicationScope applicationScope = em.getApplicationScope();
 
-        final GraphManager gm = em.getManagerCache().getGraphManager(applicationScope);
-
-        logger.debug("Loading edges types from {}:{}\n   scope {}:{}",
-            new Object[] { start.getType(), start.getUuid(),
-                applicationScope.getApplication().getType(),
-                applicationScope.getApplication().getUuid()
-            });
+        final GraphManager gm = em.getManagerCache().getGraphManager( applicationScope );
 
-        Observable<String> edgeTypes = gm.getEdgeTypesFromSource( 
-                new SimpleSearchEdgeType( fromEntityId, null , null ));
+        logger.debug( "Loading edges types from {}:{}\n   scope {}:{}", new Object[] {
+                        start.getType(), start.getUuid(), applicationScope.getApplication().getType(),
+                        applicationScope.getApplication().getUuid()
+                } );
 
-        edgeTypes.forEach( new Action1<String>() {
+        Observable<String> edgeTypes = gm.getEdgeTypesFromSource(
+                new SimpleSearchEdgeType( fromEntityId, CpNamingUtils.EDGE_COLL_SUFFIX, null ) );
 
+        edgeTypes.flatMap( new Func1<String, Observable<Edge>>() {
             @Override
-            public void call( final String edgeType ) {
-
-                try {
-                    Thread.sleep( writeDelayMs );
-                } catch ( InterruptedException ignored ) {}
+            public Observable<Edge> call( final String edgeType ) {
 
-                logger.debug("Loading edges of edgeType {} from {}:{}\n   scope {}:{}",
-                    new Object[] { edgeType, start.getType(), start.getUuid(),
-                        applicationScope.getApplication().getType(),
+                logger.debug( "Loading edges of edgeType {} from {}:{}\n   scope {}:{}", new Object[] {
+                        edgeType, start.getType(), start.getUuid(), applicationScope.getApplication().getType(),
                         applicationScope.getApplication().getUuid()
-                });
+                } );
 
+                return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( fromEntityId, edgeType, Long.MAX_VALUE,
+                                SearchByEdgeType.Order.DESCENDING, null ) );
+            }
+        } ).doOnNext( new Action1<Edge>() {
 
-                Observable<String> edgeTypes = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType(fromEntityId, CpNamingUtils.EDGE_COLL_SUFFIX, null ));
-
-
-
-                Observable<Edge> edges = gm.loadEdgesFromSource( new SimpleSearchByEdgeType( 
-                        fromEntityId, edgeType, Long.MAX_VALUE, 
-                        SearchByEdgeType.Order.DESCENDING, null ));
-
-                edges.forEach( new Action1<Edge>() {
-
-                    @Override
-                    public void call( Edge edge ) {
-
-                        EntityRef sourceEntityRef = new SimpleEntityRef( 
-                            edge.getSourceNode().getType(), edge.getSourceNode().getUuid());
-                        Entity sourceEntity;
-                        try {
-                            sourceEntity = em.get( sourceEntityRef );
-                        } catch (Exception ex) {
-                            logger.error( "Error getting sourceEntity {}:{}, continuing", 
-                                    sourceEntityRef.getType(), sourceEntityRef.getUuid());
-                            return;
-                        }
-
-                        EntityRef targetEntityRef = new SimpleEntityRef( 
-                            edge.getTargetNode().getType(), edge.getTargetNode().getUuid());
-                        Entity targetEntity;
-                        try {
-                            targetEntity = em.get( targetEntityRef );
-                        } catch (Exception ex) {
-                            logger.error( "Error getting sourceEntity {}:{}, continuing", 
-                                    sourceEntityRef.getType(), sourceEntityRef.getUuid());
-                            return;
-                        }
-                            
-                        if ( CpNamingUtils.isCollectionEdgeType( edge.getType() )) {
-
-                            String collName = CpNamingUtils.getCollectionName( edgeType );
-
-                            visitor.visitCollectionEntry( 
-                                    em, collName, sourceEntity, targetEntity );
-
-                            // recursion
-                            if ( !stack.contains( targetEntity.getUuid() )) {
-                                stack.push( targetEntity.getUuid() );
-                                doWalkCollections( em, edge.getSourceNode(), visitor, stack );
-                                stack.pop(); 
-                            }
+            @Override
+            public void call( Edge edge ) {
 
-                        } else {
+                EntityRef sourceEntityRef =
+                        new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
 
-                            String collName = CpNamingUtils.getConnectionType(edgeType);
+                Entity entity;
+                try {
+                    entity = em.get( sourceEntityRef );
+                }
+                catch ( Exception ex ) {
+                    logger.error( "Error getting sourceEntity {}:{}, continuing", sourceEntityRef.getType(),
+                            sourceEntityRef.getUuid() );
+                    return;
+                }
 
-                            visitor.visitConnectionEntry( 
-                                    em, collName, sourceEntity, targetEntity );
 
-                            // recursion
-                            if ( !stack.contains( targetEntity.getUuid() )) {
-                                stack.push( targetEntity.getUuid() );
-                                doWalkCollections( em, edge.getTargetNode(), visitor, stack );
-                                stack.pop(); 
-                            }
-                        }
-                    }
+                String collName = CpNamingUtils.getCollectionName( edge.getType() );
 
-                }); // end foreach on edges
+                visitor.visitCollectionEntry( em, collName, entity );
 
+                try {
+                    Thread.sleep( writeDelayMs );
+                }
+                catch ( InterruptedException e ) {
+                    throw new RuntimeException( "Unable to wait" );
+                }
             }
-
-        }); // end foreach on edgeTypes
-
+        } ).toBlocking().lastOrDefault( null ); // end foreach on edges
     }
-    
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 06c3114..e57aa69 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -131,6 +131,12 @@ public interface EntityManagerFactory {
     public void rebuildCollectionIndex(UUID appId, String collection, ProgressObserver object);
 
     public interface ProgressObserver {
-        public void onProgress( EntityRef source, EntityRef target, String edgeType );
+        public void onProgress( EntityRef entity);
+
+        /**
+         * Get the write delay time from the progress observer.  Used to throttle writes
+         * @return
+         */
+        public long getWriteDelayTime();
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index c790f64..51e825b 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -150,6 +150,7 @@ public class CoreApplication implements Application, TestRule {
         id = setup.createApplication( orgName, appName );
         assertNotNull( id );
 
+        setup.getEmf().refreshIndex();
         em = setup.getEmf().getEntityManager( id );
         em.createIndex();
         assertNotNull( em );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index 8de520a..d2f7fef 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -60,14 +60,13 @@ import static org.junit.Assert.fail;
 //@RunWith(JukitoRunner.class)
 //@UseModules({ GuiceModule.class })
 @Concurrent()
-@Ignore("Temporary ignore")
 public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
     private static final Logger logger = LoggerFactory.getLogger(PerformanceEntityRebuildIndexTest.class );
 
     private static final MetricRegistry registry = new MetricRegistry();
     private Slf4jReporter reporter;
 
-    private static final long RUNTIME = TimeUnit.MINUTES.toMillis( 1 );
+    private static final long RUNTIME = TimeUnit.SECONDS.toMillis( 5 );
 
     private static final long writeDelayMs = 100;
     //private static final long readDelayMs = 7;
@@ -192,18 +191,26 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
         EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver() {
             int counter = 0;
             @Override
-            public void onProgress( EntityRef s, EntityRef t, String etype ) {
+               public void onProgress( final EntityRef entity ) {
+
                 meter.mark();
-                logger.debug("Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
-                    s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype });
+                logger.debug("Indexing from {}:{}", entity.getType(), entity.getUuid());
                 if ( !logger.isDebugEnabled() && counter % 100 == 0 ) {
                     logger.info("Reindexed {} entities", counter );
                 }
                 counter++;
             }
+
+
+
+            @Override
+            public long getWriteDelayTime() {
+                return 0;
+            }
         };
 
         try {
+//            setup.getEmf().refreshIndex();
             setup.getEmf().rebuildAllIndexes( po );
 
             registry.remove( meterName );
@@ -236,9 +243,6 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
         eeii.deleteIndex();
     }
 
-    private int readData( String collectionName ) throws Exception {
-        return readData( collectionName, -1 );
-    }
 
     private int readData( String collectionName, int expected ) throws Exception {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/163fa9ad/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
index ceec656..28a7120 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
@@ -124,11 +124,17 @@ public class SystemResource extends AbstractContextResource {
 
 
         final ProgressObserver po = new ProgressObserver() {
+
+
+            @Override
+            public void onProgress( final EntityRef entity ) {
+                logger.info( "Indexing from {}:{} ", entity.getType(), entity.getUuid() );
+            }
+
+
             @Override
-            public void onProgress( EntityRef s, EntityRef t, String etype ) {
-                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
-                        s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype
-                } );
+            public long getWriteDelayTime() {
+                return 0;
             }
         };
 
@@ -168,7 +174,8 @@ public class SystemResource extends AbstractContextResource {
     public JSONWithPadding rebuildIndexes( 
                 @Context UriInfo ui, 
                 @PathParam( "applicationId" ) String applicationIdStr,
-                @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
+                @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback,
+                @QueryParam( "delay" ) @DefaultValue( "10" ) final long delay)
 
             throws Exception {
 
@@ -177,14 +184,6 @@ public class SystemResource extends AbstractContextResource {
         response.setAction( "rebuild indexes" );
 
 
-        final ProgressObserver po = new ProgressObserver() {
-            @Override
-            public void onProgress( EntityRef s, EntityRef t, String etype ) {
-                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
-                        s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype
-                } );
-            }
-        };
 
 
         final EntityManager em = emf.getEntityManager( appId );
@@ -199,7 +198,7 @@ public class SystemResource extends AbstractContextResource {
 
 
                 {
-                    rebuildCollection( appId, collectionName );
+                    rebuildCollection( appId, collectionName, delay );
                 }
             }
         };
@@ -221,7 +220,8 @@ public class SystemResource extends AbstractContextResource {
                 @Context UriInfo ui,
                 @PathParam( "applicationId" ) final String applicationIdStr,
                 @PathParam( "collectionName" ) final String collectionName,
-                @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback )
+                @QueryParam( "callback" ) @DefaultValue( "callback" ) String callback,
+                @QueryParam( "delay" ) @DefaultValue( "10" ) final long delay )
             throws Exception {
 
         final UUID appId = UUIDUtils.tryExtractUUID( applicationIdStr );
@@ -232,7 +232,7 @@ public class SystemResource extends AbstractContextResource {
 
             public void run() {
 
-                rebuildCollection( appId, collectionName );
+                rebuildCollection( appId, collectionName, delay );
             }
         };
 
@@ -247,13 +247,18 @@ public class SystemResource extends AbstractContextResource {
     }
 
 
-    private void rebuildCollection( final UUID applicationId, final String collectionName ) {
+    private void rebuildCollection( final UUID applicationId, final String collectionName, final long delay ) {
         EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver() {
+
+            @Override
+            public void onProgress( final EntityRef entity ) {
+                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", entity.getType(), entity.getUuid());
+            }
+
+
             @Override
-            public void onProgress( EntityRef s, EntityRef t, String etype ) {
-                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
-                        s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype
-                } );
+            public long getWriteDelayTime() {
+                return delay;
             }
         };
 


[06/50] [abbrv] git commit: fix bug if you have other devices

Posted by sn...@apache.org.
fix bug if you have other devices


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

Branch: refs/heads/two-dot-o-events
Commit: 5b1c06ac88b3b46a93b399bcbfae53285364c978
Parents: d52ad4c
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 16 09:13:31 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 16 09:13:31 2014 -0600

----------------------------------------------------------------------
 .../services/devices/DevicesService.java        | 30 +++++++++++++-------
 .../services/users/devices/DevicesService.java  |  8 +++---
 .../apns/NotificationsServiceIT.java            |  5 +++-
 3 files changed, 27 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5b1c06ac/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java b/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
index d1bb3db..0911865 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
@@ -61,27 +61,35 @@ public class DevicesService extends AbstractCollectionService {
         return super.postItemById( context, id );
     }
 
-    protected void deleteEntityConnection(final EntityRef entityRef){
-        if(entityRef == null) {
+    protected void deleteEntityConnection(final EntityRef deviceRef, final EntityRef owner){
+        if(deviceRef == null) {
             return;
         }
         try {
-            Results entities = em.getCollection(entityRef,"users",null,100, Query.Level.REFS,false);
+            Results entities = em.getCollection(deviceRef,"users",null,100, Query.Level.REFS,false);
             Observable.from(entities.getEntities())
-                    .map(new Func1<Entity, Entity>() {
+                    .map(new Func1<Entity, Boolean>() {
                         @Override
-                        public Entity call(Entity user) {
+                        public Boolean call(Entity user) {
+                            boolean removed = false;
                             try {
-                                Results devicesResults = em.getCollection(user,"devices",null,100,Query.Level.REFS,false);
-                                List<Entity> devices = devicesResults.getEntities();
-                                for(EntityRef device : devices){
-                                    em.removeFromCollection(user, "devices",device);
+                                if(!user.getUuid().equals(owner.getUuid())) { //skip current user
+                                    Results devicesResults = em.getCollection(user, "devices", null, 100, Query.Level.REFS, false);
+                                    List<Entity> userDevices = devicesResults.getEntities();
+                                    for (EntityRef userDevice : userDevices) {
+                                        if(userDevice.getUuid().equals(deviceRef.getUuid())) { //only remove the current device from user
+                                            em.removeFromCollection(user, "devices", userDevice);
+                                        }
+                                    }
+                                    em.removeFromCollection(deviceRef, "users", user);
+                                    removed = true;
+                                }else{
+                                    removed = false;
                                 }
-                                em.removeFromCollection(entityRef, "users",user);
                             } catch (Exception e) {
                                 logger.error("Failed to delete connection " + user.toString(), e);
                             }
-                            return user;
+                            return removed;
                         }
                     }).toBlocking().lastOrDefault(null);
         }catch (Exception e){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5b1c06ac/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java b/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
index bdcd574..4556eaa 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/users/devices/DevicesService.java
@@ -40,7 +40,7 @@ public class DevicesService extends org.apache.usergrid.services.devices.Devices
     @Override
     public ServiceResults putItemById( ServiceContext context, UUID id ) throws Exception {
         logger.debug("Registering device {}", id);
-        unregisterDeviceToUsers(id);
+        unregisterDeviceToUsers(id,context.getOwner());
         ServiceResults results = super.putItemById( context, id );
         return results;
     }
@@ -49,15 +49,15 @@ public class DevicesService extends org.apache.usergrid.services.devices.Devices
     @Override
     public ServiceResults postItemById( ServiceContext context, UUID id ) throws Exception {
         logger.info( "Attempting to connect an entity to device {}", id );
-        unregisterDeviceToUsers(id);
+        unregisterDeviceToUsers(id,context.getOwner());
         ServiceResults results = super.postItemById( context, id );
         return results;
     }
 
-    protected void unregisterDeviceToUsers(UUID deviceId){
+    protected void unregisterDeviceToUsers(UUID deviceId, EntityRef owner){
         try {
             EntityRef device = new SimpleEntityRef("device",deviceId);
-            deleteEntityConnection(device);
+            deleteEntityConnection(device,owner);
         } catch (Exception e) {
             logger.error("Failed to delete connection for " + deviceId.toString(), e);
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5b1c06ac/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index 8805b93..a834400 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -751,7 +751,10 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         assertEquals(device1Users.size(),1);
         List user1Devices = app.getEm().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
         assertEquals(user1Devices.size(),2);
-
+        app.clear();
+        e = app.testRequest(ServiceAction.POST, 1, "users",user1.getUuid(),"devices",device2.getUuid()).getEntity();
+        user1Devices = app.getEm().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
+        assertEquals(user1Devices.size(),2);
         // create push notification //
 
         app.getEm().refreshIndex();


[21/50] [abbrv] git commit: Added verification to init to catch NPE issues

Posted by sn...@apache.org.
Added verification to init to catch NPE issues

Updated index creation to write a document and delete to verify correct functionality


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

Branch: refs/heads/two-dot-o-events
Commit: 722c43b731a80c810916a09af8e50c19ac7c6891
Parents: 83200bf
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 20:53:59 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 20:53:59 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  20 +--
 .../usergrid/persistence/EntityManager.java     |   2 +-
 .../index/impl/EsEntityIndexImpl.java           | 144 ++++++++++++++-----
 3 files changed, 121 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/722c43b7/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 2498dda..751b9e2 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
@@ -16,6 +16,7 @@
 package org.apache.usergrid.corepersistence;
 
 
+import com.google.common.base.Preconditions;
 import com.netflix.hystrix.exception.HystrixRuntimeException;
 import com.yammer.metrics.annotation.Metered;
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
@@ -191,6 +192,9 @@ public class CpEntityManager implements EntityManager {
     @Override
     public void init( EntityManagerFactory emf, UUID applicationId ) {
 
+        Preconditions.checkNotNull(emf, "emf must not be null");
+        Preconditions.checkNotNull( applicationId, "applicationId must not be null"  );
+
         this.emf = ( CpEntityManagerFactory ) emf;
         this.managerCache = this.emf.getManagerCache();
         this.applicationId = applicationId;
@@ -202,9 +206,6 @@ public class CpEntityManager implements EntityManager {
 
         // set to false for now
         this.skipAggregateCounters = false;
-
-
-        applicationScope = this.emf.getApplicationScope( applicationId );
     }
 
 
@@ -643,11 +644,11 @@ public class CpEntityManager implements EntityManager {
         return getRelationManager( entityRef ).searchCollection( collectionName, query );
     }
 
-
-    @Override
-    public void setApplicationId( UUID applicationId ) {
-        this.applicationId = applicationId;
-    }
+//
+//    @Override
+//    public void setApplicationId( UUID applicationId ) {
+//        this.applicationId = applicationId;
+//    }
 
 
     @Override
@@ -2884,7 +2885,8 @@ public class CpEntityManager implements EntityManager {
                 }
                 catch(WriteOptimisticVerifyException wo ){
                     //swallow this, it just means this was already updated, which accomplishes our task.  Just ignore.
-                    logger.warn( "Someone beat us to updating entity {} in collection {}.  Ignoring.", entity.getName(), collName );
+                    logger.warn( "Someone beat us to updating entity {} in collection {}.  Ignoring.", entity.getName(),
+                            collName );
                 }
                 catch (Exception ex) {
                     logger.error("Error repersisting entity", ex);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/722c43b7/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 3684d7e..cd92729 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -41,7 +41,7 @@ import org.apache.usergrid.persistence.index.query.Query.Level;
  */
 public interface EntityManager {
 
-    public void setApplicationId( UUID applicationId );
+//    public void setApplicationId( UUID applicationId );
 
     public GeoIndexManager getGeoIndexManager();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/722c43b7/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index b562d8a..7584386 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -26,7 +26,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
 import org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse;
-import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
 import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
 import org.elasticsearch.action.search.SearchRequestBuilder;
 import org.elasticsearch.action.search.SearchResponse;
@@ -36,7 +35,9 @@ import org.elasticsearch.client.Client;
 import org.elasticsearch.common.xcontent.XContentBuilder;
 import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.query.FilterBuilder;
+import org.elasticsearch.index.query.MatchAllQueryBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
+import org.elasticsearch.index.query.QueryBuilders;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.indices.IndexMissingException;
 import org.elasticsearch.search.SearchHit;
@@ -58,7 +59,9 @@ import org.apache.usergrid.persistence.index.query.CandidateResults;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 
+import com.google.common.collect.ImmutableMap;
 import com.google.inject.Inject;
 import com.google.inject.assistedinject.Assisted;
 
@@ -88,11 +91,18 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     private final IndexFig config;
 
-    //number of times to wait for the index to refresh propertly. Is an N+1, so 9 = 10
-    private static final int MAX_WAITS = 9;
+    //number of times to wait for the index to refresh properly.
+    private static final int MAX_WAITS = 10;
     //number of milliseconds to try again before sleeping
     private static final int WAIT_TIME = 250;
 
+    private static final String VERIFY_TYPE = "verification";
+
+    private static final ImmutableMap<String, Object> DEFAULT_PAYLOAD =
+            ImmutableMap.<String, Object>of( "field", "test" );
+
+    private static final MatchAllQueryBuilder MATCH_ALL_QUERY_BUILDER = QueryBuilders.matchAllQuery();
+
 
     @Inject
     public EsEntityIndexImpl( @Assisted final ApplicationScope appScope, final IndexFig config,
@@ -120,21 +130,16 @@ public class EsEntityIndexImpl implements EntityIndex {
             CreateIndexResponse cir = admin.indices().prepareCreate( indexName ).execute().actionGet();
             log.info( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged() );
 
-            RefreshResponse response;
-
-            do {
-                response = admin.indices().prepareRefresh( indexName ).execute().actionGet();
-            }
-            while ( response.getFailedShards() != 0 );
 
+            //create the document, this ensures the index is ready
             /**
-             * Immediately refresh to ensure the entire cluster is ready to receive this write.  Occasionally we see
+             * Immediately create a document and remove it to ensure the entire cluster is ready to receive documents
+             * .  Occasionally we see
              * errors.  See this post.
-             * http://elasticsearch-users.115913.n3.nabble
-             * .com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
+             * http://elasticsearch-users.115913.n3.nabble.com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
              *
              */
-            refresh();
+            testNewIndex();
         }
         catch ( IndexAlreadyExistsException expected ) {
             // this is expected to happen if index already exists, it's a no-op and swallow
@@ -146,6 +151,44 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
     /**
+     * Tests writing a document to a new index to ensure it's working correctly.  Comes from email
+     *
+     * http://elasticsearch-users.115913.n3.nabble
+     * .com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
+     */
+
+    private void testNewIndex() {
+
+
+        log.info( "Refreshing Created new Index Name [{}]", indexName );
+
+        final RetryOperation retryOperation = new RetryOperation() {
+            @Override
+            public boolean doOp() {
+                final String tempId = UUIDGenerator.newTimeUUID().toString();
+
+
+                client.prepareIndex( indexName, VERIFY_TYPE, tempId ).setSource( DEFAULT_PAYLOAD ).get();
+
+                log.info( "Successfully created new document with docId {} in index {} and type {}", tempId, indexName,
+                        VERIFY_TYPE );
+
+                //delete all types, this way if we miss one it will get cleaned up
+
+                client.prepareDeleteByQuery( indexName ).setTypes( VERIFY_TYPE ).setQuery( MATCH_ALL_QUERY_BUILDER )
+                      .get();
+
+                log.info( "Successfully deleted all documents in index {} and type {}", indexName, VERIFY_TYPE );
+
+                return true;
+            }
+        };
+
+        doInRetry( retryOperation );
+    }
+
+
+    /**
      * Setup ElasticSearch type mappings as a template that applies to all new indexes. Applies to all indexes that
      * start with our prefix.
      */
@@ -277,30 +320,22 @@ public class EsEntityIndexImpl implements EntityIndex {
 
         log.info( "Refreshing Created new Index Name [{}]", indexName );
 
-        //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
-        //before we can write.
-        for ( int i = 0; i < MAX_WAITS; i++ ) {
-            try {
-                client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
-                log.debug( "Refreshed index: " + indexName );
-                return;
-            }
-            catch ( IndexMissingException e ) {
-                log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
-            }
-
-            try {
-                Thread.sleep( WAIT_TIME );
-            }
-            catch ( InterruptedException e ) {
-                //swallow it
+        final RetryOperation retryOperation = new RetryOperation() {
+            @Override
+            public boolean doOp() {
+                try {
+                    client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+                    log.debug( "Refreshed index: " + indexName );
+                    return true;
+                }
+                catch ( IndexMissingException e ) {
+                    log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
+                    throw e;
+                }
             }
-        }
+        };
 
-        /**
-         * Try the refresh one last time if we get here
-         */
-        client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+        doInRetry( retryOperation );
 
         log.debug( "Refreshed index: " + indexName );
     }
@@ -328,4 +363,43 @@ public class EsEntityIndexImpl implements EntityIndex {
             log.info( "Failed to delete index " + indexName );
         }
     }
+
+
+    /**
+     * Do the retry operation
+     * @param operation
+     */
+    private void doInRetry( final RetryOperation operation ) {
+        for ( int i = 0; i < MAX_WAITS; i++ ) {
+
+            try {
+                if(operation.doOp()){
+                    return;
+                }
+            }
+            catch ( Exception e ) {
+                log.error( "Unable to execute operation, retrying", e );
+            }
+
+
+            try {
+                Thread.sleep( WAIT_TIME );
+            }
+            catch ( InterruptedException e ) {
+                //swallow it
+            }
+        }
+    }
+
+
+    /**
+     * Interface for operations
+     */
+    private static interface RetryOperation {
+
+        /**
+         * Return true if done, false if there should be a retry
+         */
+        public boolean doOp();
+    }
 }


[24/50] [abbrv] git commit: Merge branch 'index-rebuild' into cloudformation-update

Posted by sn...@apache.org.
Merge branch 'index-rebuild' into cloudformation-update


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

Branch: refs/heads/two-dot-o-events
Commit: 059a9523360eb543c3adfc42059a4c9e52e4efbb
Parents: 704c09d 8d9d4dc
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 08:57:14 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 08:57:14 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  107 +-
 .../corepersistence/CpEntityManagerFactory.java |   40 +-
 .../corepersistence/CpRelationManager.java      | 1427 ++++++++----------
 .../usergrid/corepersistence/CpVisitor.java     |   11 +-
 .../usergrid/corepersistence/CpWalker.java      |  157 +-
 .../usergrid/persistence/EntityManager.java     |    2 +-
 .../persistence/EntityManagerFactory.java       |    8 +-
 .../org/apache/usergrid/CoreApplication.java    |    1 -
 .../PerformanceEntityRebuildIndexTest.java      |   23 +-
 .../index/impl/EsEntityIndexImpl.java           |  146 +-
 .../persistence/index/impl/EsProvider.java      |   21 +-
 .../apache/usergrid/rest/SystemResource.java    |   50 +-
 .../AbstractServiceNotificationIT.java          |    4 -
 13 files changed, 954 insertions(+), 1043 deletions(-)
----------------------------------------------------------------------



[28/50] [abbrv] git commit: fixing dependency tree for httpcomponents

Posted by sn...@apache.org.
fixing dependency tree for httpcomponents


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

Branch: refs/heads/two-dot-o-events
Commit: 3907a77fc2d255a45677965bd1a7236bebe28809
Parents: 5a04107
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 12:09:01 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 12:09:01 2014 -0600

----------------------------------------------------------------------
 stack/corepersistence/common/pom.xml | 13 +++----------
 stack/corepersistence/pom.xml        |  1 +
 stack/corepersistence/queue/pom.xml  |  8 +++++++-
 stack/pom.xml                        | 19 +++++++++++++++++--
 4 files changed, 28 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3907a77f/stack/corepersistence/common/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/common/pom.xml b/stack/corepersistence/common/pom.xml
index 42511c8..ee6a67b 100644
--- a/stack/corepersistence/common/pom.xml
+++ b/stack/corepersistence/common/pom.xml
@@ -131,18 +131,11 @@
 
     <!-- aws sdks -->
     <dependency>
-         <groupId>com.amazonaws</groupId>
-         <artifactId>aws-java-sdk</artifactId>
-         <version>1.7.5</version>
-         <exclusions>
-            <exclusion>
-                <artifactId>jackson-databind</artifactId>
-                <groupId>com.fasterxml.jackson.core</groupId>
-            </exclusion>
-         </exclusions>
+      <groupId>com.amazonaws</groupId>
+      <artifactId>aws-java-sdk</artifactId>
+      <version>${aws.version}</version>
     </dependency>
 
-
     <dependency>
       <groupId>org.jukito</groupId>
       <artifactId>jukito</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3907a77f/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index fac5db9..d57b86f 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -74,6 +74,7 @@ limitations under the License.
         <rx.version>0.19.6</rx.version>
         <slf4j.version>1.7.2</slf4j.version>
         <surefire.version>2.16</surefire.version>
+        <aws.version>1.9.0</aws.version>
 
     </properties>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3907a77f/stack/corepersistence/queue/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queue/pom.xml b/stack/corepersistence/queue/pom.xml
index 94f11a8..a2e3c2d 100644
--- a/stack/corepersistence/queue/pom.xml
+++ b/stack/corepersistence/queue/pom.xml
@@ -82,7 +82,13 @@
     <dependency>
       <groupId>com.amazonaws</groupId>
       <artifactId>aws-java-sdk</artifactId>
-      <version>1.8.11</version>
+      <version>${aws.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.apache.httpcomponents</groupId>
+      <artifactId>httpclient</artifactId>
+      <version>4.2</version>
     </dependency>
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3907a77f/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index df656c0..2217a93 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -278,7 +278,7 @@
       <dependency>
         <groupId>org.apache.httpcomponents</groupId>
         <artifactId>httpclient</artifactId>
-        <version>4.1.3</version>
+        <version>4.2</version>
         <exclusions>
           <exclusion>
             <groupId>commons-codec</groupId>
@@ -355,7 +355,22 @@
             <groupId>org.antlr</groupId>
             <artifactId>antlr-runtime</artifactId>
           </exclusion>
-
+          <exclusion>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcomponents-client</artifactId>
+          </exclusion>
+          <exclusion>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcomponents-core</artifactId>
+          </exclusion>
           <exclusion>
             <groupId>jline</groupId>
             <artifactId>jline</artifactId>


[14/50] [abbrv] git commit: Adds explicit refresh after create to ensure the index is actually ready to receive data.

Posted by sn...@apache.org.
Adds explicit refresh after create to ensure the index is actually ready to receive data.


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

Branch: refs/heads/two-dot-o-events
Commit: 54b9a1197edc6498629f3bdb78f95408c24c566d
Parents: f24f3ea
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 15:11:45 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 15:11:45 2014 -0600

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 23 ++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/54b9a119/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index e55f7e0..495b9e1 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -87,6 +87,9 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     private final IndexFig config;
 
+    private static final int MAX_WAITS = 10;
+    private static final int WAIT_TIME = 250;
+
 
     @Inject
     public EsEntityIndexImpl( @Assisted final ApplicationScope appScope, final IndexFig config,
@@ -120,6 +123,26 @@ public class EsEntityIndexImpl implements EntityIndex {
                 response = admin.indices().prepareRefresh( indexName ).execute().actionGet();
             }
             while ( response.getFailedShards() != 0 );
+
+            //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
+            //before we can write.
+            for(int i = 0 ; i < MAX_WAITS; i++ ){
+                try{
+                    refresh();
+                    break;
+
+                }catch(Exception e){
+                   log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
+                }
+
+                try {
+                    Thread.sleep( WAIT_TIME );
+                }
+                catch ( InterruptedException e ) {
+                    //swallow it
+                }
+            }
+
             //
             //            response.getFailedShards();
             //


[47/50] [abbrv] git commit: Removed tokens and using vnodes

Posted by sn...@apache.org.
Removed tokens and using vnodes


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

Branch: refs/heads/two-dot-o-events
Commit: fc6ac11bfa814fedb2cb66d131b113fa91016723
Parents: e361ea8
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 19:27:53 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 19:27:53 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/pom.xml                        |  2 +-
 .../src/main/groovy/configure_cassandra.groovy  | 26 +-------------------
 2 files changed, 2 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fc6ac11b/stack/awscluster/pom.xml
----------------------------------------------------------------------
diff --git a/stack/awscluster/pom.xml b/stack/awscluster/pom.xml
index 84142d7..2971e3c 100644
--- a/stack/awscluster/pom.xml
+++ b/stack/awscluster/pom.xml
@@ -30,7 +30,7 @@
 
     <properties>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-        <aws.s3.release-bucket>todd-cloudformation</aws.s3.release-bucket>
+        <aws.s3.release-bucket>ug-cloudformation-todd</aws.s3.release-bucket>
         <stack.war>../rest/target/ROOT.war</stack.war>
         <portal.dir>../../portal/dist/usergrid-portal</portal.dir>
     </properties>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/fc6ac11b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_cassandra.groovy b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
index 9e5ded2..946e801 100644
--- a/stack/awscluster/src/main/groovy/configure_cassandra.groovy
+++ b/stack/awscluster/src/main/groovy/configure_cassandra.groovy
@@ -29,7 +29,6 @@ import com.amazonaws.services.simpledb.model.*
 
 String hostName  = (String)System.getenv().get("PUBLIC_HOSTNAME")
 String clusterName  = (String)System.getenv().get("CASSANDRA_CLUSTER_NAME")
-int cassNumServers = ((String)System.getenv().get("CASSANDRA_NUM_SERVERS")).toInteger()
 
 
 // build seed list by listing all Cassandra nodes found in SimpleDB domain with our stackName
@@ -45,29 +44,6 @@ for (host in selectResult) {
 }
 
 
-int index = 0;
-int count = 0;
-
-for (name in selectResult) {
-
-    //get our index so that we know which token to get
-    if (name == hostName) {
-        index = count
-        break
-    }
-
-    count++
-}
-
-long[] tokens = new long[cassNumServers]
-
-for(int i =0; i < cassNumServers; i ++){
-    tokens[i] =  ((2**64 / cassNumServers) * i) - 2**63
-}
-
-String token = tokens[index]
-
-
 def cassandraConfig = """
 
 
@@ -78,7 +54,7 @@ seed_provider:
       parameters:
           - seeds: "${seeds}"
 auto_bootstrap: false 
-initial_token: ${token}
+num_tokens: 256
 hinted_handoff_enabled: true
 hinted_handoff_throttle_in_kb: 1024
 max_hints_delivery_threads: 2


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: 3914d6874b29a744051682df3f3768807c9306ee
Parents: c27a090 3119319
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 18:07:27 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 18:07:27 2014 -0600

----------------------------------------------------------------------
 .../src/main/dist/init_instance/create_raid0.sh | 19 +++----
 .../dist/init_instance/create_raid0_2disks.sh   | 54 --------------------
 .../main/dist/init_instance/init_db_server.sh   |  2 +-
 .../main/dist/init_instance/init_es_server.sh   |  2 +-
 .../dist/init_instance/init_graphite_server.sh  |  4 +-
 .../main/dist/init_instance/init_rest_server.sh | 18 +++++--
 .../dist/init_instance/install_elasticsearch.sh |  3 ++
 .../main/groovy/configure_elasticsearch.groovy  |  5 +-
 .../src/main/groovy/configure_usergrid.groovy   | 13 ++---
 stack/awscluster/ugcluster-cf.json              | 28 ++++++++--
 10 files changed, 64 insertions(+), 84 deletions(-)
----------------------------------------------------------------------



[37/50] [abbrv] git commit: add comments for all devices query

Posted by sn...@apache.org.
add comments for all devices query


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

Branch: refs/heads/two-dot-o-events
Commit: 955b5870adda07a5af76712323bff2d1e8a49dde
Parents: 09faf5b
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 17:03:39 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 17:03:39 2014 -0600

----------------------------------------------------------------------
 .../usergrid/services/notifications/NotificationsService.java  | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/955b5870/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index d63ef7d..f98ebfc 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -176,7 +176,11 @@ public class NotificationsService extends AbstractCollectionService {
             org.apache.usergrid.persistence.index.query.Query query = sp.getQuery();
             if (query == null) {
                 query = new Query();
-                query.addIdentifier(sp.getIdentifier());
+                if(!sp.isName() ||
+                        (collection == "devices" && sp.isName() && !sp.getName().equals("notifications"))) {
+                        //look for queries to /devices;ql=/notifications
+                    query.addIdentifier(sp.getIdentifier());
+                }
             }
             query.setLimit(PAGE);
             query.setCollection(collection);


[26/50] [abbrv] git commit: Fixes missing env variable for graphite server

Posted by sn...@apache.org.
Fixes missing env variable for graphite server


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

Branch: refs/heads/two-dot-o-events
Commit: 6a6791cfdeafef6c80768ee6ef0be7c3dd760e67
Parents: 5a04107
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 11:04:24 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 11:04:24 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/ugcluster-cf.json | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6a6791cf/stack/awscluster/ugcluster-cf.json
----------------------------------------------------------------------
diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json
index efef0f9..47d1b64 100644
--- a/stack/awscluster/ugcluster-cf.json
+++ b/stack/awscluster/ugcluster-cf.json
@@ -285,6 +285,7 @@
                       "\n",
                       "export REST_SECURITY_GROUP_NAME=", { "Ref":"RestSecurityGroup" }, "\n",
                       "export GRAPHITE_NUM_SERVERS=", { "Ref":"GraphiteNumServers" }, "\n",
+                      "export RELEASE_BUCKET=", { "Ref":"ReleaseBucket" }, "\n",
                       "EOF\n",
                       "\n",
                       "# put AWS creds in environment\n",


[02/50] [abbrv] git commit: Fixes bug with us region naming

Posted by sn...@apache.org.
Fixes bug with us region naming


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

Branch: refs/heads/two-dot-o-events
Commit: c9ac3e27a9b47dd47d411b54d931a95b02f79bed
Parents: b84bbc1
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 15 22:07:34 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 15 22:07:34 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/src/main/groovy/configure_usergrid.groovy | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c9ac3e27/stack/awscluster/src/main/groovy/configure_usergrid.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_usergrid.groovy b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
index 03b3077..35a0262 100644
--- a/stack/awscluster/src/main/groovy/configure_usergrid.groovy
+++ b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
@@ -43,7 +43,8 @@ def testAdminUserEmail = System.getenv().get("TEST_ADMIN_USER_EMAIL")
 def cassThreads = System.getenv().get("TOMCAT_THREADS")
 def hystrixThreads = Integer.parseInt(cassThreads) / 100
 
-def ec2Region = System.getenv().get("EC2_REGION")
+//if we end in -1, we remove it
+def ec2Region = System.getenv().get("EC2_REGION").replace("-1", "")
 
 
 NodeRegistry registry = new NodeRegistry();


[36/50] [abbrv] git commit: removing all devices hack

Posted by sn...@apache.org.
removing all devices hack


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

Branch: refs/heads/two-dot-o-events
Commit: 09faf5b1947c541f48210016addb37febcced2bb
Parents: f7ab174
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 16:51:42 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 16:51:42 2014 -0600

----------------------------------------------------------------------
 .../usergrid/services/notifications/NotificationsService.java    | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/09faf5b1/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index ee5c1cb..d63ef7d 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -176,9 +176,7 @@ public class NotificationsService extends AbstractCollectionService {
             org.apache.usergrid.persistence.index.query.Query query = sp.getQuery();
             if (query == null) {
                 query = new Query();
-                if(!sp.isName() ||  (sp.isName() && !sp.getName().equals("notifications"))) {
-                    query.addIdentifier(sp.getIdentifier());
-                }
+                query.addIdentifier(sp.getIdentifier());
             }
             query.setLimit(PAGE);
             query.setCollection(collection);


[27/50] [abbrv] git commit: Added kopf and bigdesk to elasticsearch

Posted by sn...@apache.org.
Added kopf and bigdesk to elasticsearch


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

Branch: refs/heads/two-dot-o-events
Commit: 3bae36b015f762ef2787c1d21b7a80750092950a
Parents: 6a6791c
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 11:49:57 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 11:49:57 2014 -0600

----------------------------------------------------------------------
 .../main/dist/init_instance/install_elasticsearch.sh   | 13 +++++++++++++
 stack/awscluster/ugcluster-cf.json                     |  7 +++++++
 2 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3bae36b0/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
index e5c6473..a3c0b64 100644
--- a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
+++ b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
@@ -92,6 +92,19 @@ groovy ./configure_elasticsearch.groovy > /etc/elasticsearch/elasticsearch.yml
 
 update-rc.d elasticsearch defaults 95 10
 
+pushd /usr/share/elasticsearch/bin
+
+#Install kopf
+
+./plugin --install lmenezes/elasticsearch-kopf/1.2
+
+#Install bigdesk
+
+./plugin --install lukas-vlcek/bigdesk
+
+popd
+
+
 # Go!
 /etc/init.d/elasticsearch start
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3bae36b0/stack/awscluster/ugcluster-cf.json
----------------------------------------------------------------------
diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json
index 47d1b64..b4d5a0b 100644
--- a/stack/awscluster/ugcluster-cf.json
+++ b/stack/awscluster/ugcluster-cf.json
@@ -1196,6 +1196,13 @@
                         "FromPort": "22",
                         "ToPort": "22",
                         "CidrIp": "0.0.0.0/0"
+                    },
+
+                    {
+                        "IpProtocol": "tcp",
+                        "FromPort": "9200",
+                        "ToPort": "9200",
+                        "CidrIp": "0.0.0.0/0"
                     }
                 ]
             }


[08/50] [abbrv] git commit: taking extra line out

Posted by sn...@apache.org.
taking extra line out


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

Branch: refs/heads/two-dot-o-events
Commit: ce2db8a34dd827377144886851bf1dfab6a3276d
Parents: 96f48e4
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 16 09:23:00 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 16 09:23:00 2014 -0600

----------------------------------------------------------------------
 .../java/org/apache/usergrid/services/devices/DevicesService.java  | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ce2db8a3/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java b/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
index 0911865..9e73e0a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/devices/DevicesService.java
@@ -83,8 +83,6 @@ public class DevicesService extends AbstractCollectionService {
                                     }
                                     em.removeFromCollection(deviceRef, "users", user);
                                     removed = true;
-                                }else{
-                                    removed = false;
                                 }
                             } catch (Exception e) {
                                 logger.error("Failed to delete connection " + user.toString(), e);


[11/50] [abbrv] git commit: Merge branch 'two-dot-o' into cloudformation-update

Posted by sn...@apache.org.
Merge branch 'two-dot-o' into cloudformation-update


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

Branch: refs/heads/two-dot-o-events
Commit: 704c09d7865edfa7914e39a5a0324bca78803932
Parents: 0ddecd1 9da529b
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 09:50:47 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 09:50:47 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  6 ++---
 .../services/devices/DevicesService.java        | 28 ++++++++++++--------
 .../services/users/devices/DevicesService.java  |  8 +++---
 .../apns/NotificationsServiceIT.java            |  5 +++-
 4 files changed, 28 insertions(+), 19 deletions(-)
----------------------------------------------------------------------



[30/50] [abbrv] git commit: Fix some issues found during testing.

Posted by sn...@apache.org.
Fix some issues found during testing.


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

Branch: refs/heads/two-dot-o-events
Commit: bdcf80509e662442ccad312e19b878812f467eac
Parents: 7c06f6b
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Oct 17 15:01:54 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Oct 17 15:01:54 2014 -0400

----------------------------------------------------------------------
 stack/core/pom.xml                         | 21 ---------------------
 stack/pom.xml                              |  4 ++--
 stack/rest/src/main/webapp/WEB-INF/web.xml |  2 +-
 3 files changed, 3 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bdcf8050/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index 30a14d1..7bd4da4 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -540,14 +540,6 @@
       <type>jar</type>
     </dependency>
 
-
-    <!--<dependency>-->
-      <!--<artifactId>lucene-core</artifactId>-->
-      <!--<groupId>org.apache.lucene</groupId>-->
-      <!--<type>jar</type>-->
-      <!--<version>4.7.2</version>-->
-    <!--</dependency>-->
-
     <dependency>
         <groupId>org.jukito</groupId>
         <artifactId>jukito</artifactId>
@@ -555,19 +547,6 @@
         <scope>test</scope>
     </dependency>
 
-<!--    <dependency>
-        <groupId>org.apache.usergrid.chop</groupId>
-        <artifactId>chop-api</artifactId>
-        <version>2.0.0-SNAPSHOT</version>
-    </dependency>
-
-        <dependency>
-            <groupId>org.apache.usergrid.chop</groupId>
-            <artifactId>chop-stack</artifactId>
-            <version>2.0.0-SNAPSHOT</version>
-        </dependency>
-    -->
-
     <dependency>
       <groupId>com.codahale.metrics</groupId>
       <artifactId>metrics-core</artifactId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bdcf8050/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index 9231a2f..94135e8 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -115,7 +115,7 @@
     <tomcat-version>7.0.52</tomcat-version>
     <antlr.version>3.4</antlr.version>
     <tika.version>1.4</tika.version>
-    <elasticsearch.version>1.2.4</elasticsearch.version>
+    <elasticsearch.version>1.3.2</elasticsearch.version>
 
     <usergrid.it.forkCount>3</usergrid.it.forkCount>
     <usergrid.it.reuseForks>false</usergrid.it.reuseForks>
@@ -208,7 +208,7 @@
     https://issues.apache.org/jira/browse/USERGRID-224
     <module>launcher</module>
     -->
-    <!-- <module>mongo-emulator</module> -->
+    <module>mongo-emulator</module> 
     <!--  
     Re-enable when query-validator updated to work with Core Persistence.
     https://issues.apache.org/jira/browse/USERGRID-221

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bdcf8050/stack/rest/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/webapp/WEB-INF/web.xml b/stack/rest/src/main/webapp/WEB-INF/web.xml
index 92753de..24a82ca 100644
--- a/stack/rest/src/main/webapp/WEB-INF/web.xml
+++ b/stack/rest/src/main/webapp/WEB-INF/web.xml
@@ -59,7 +59,7 @@
         <filter-name>contentTypeFilter</filter-name>
         <url-pattern>/*</url-pattern>
     </filter-mapping>
-    `
+    
     <filter>
         <filter-name>shiroFilter</filter-name>
         <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>


[42/50] [abbrv] git commit: Fixed source execution order

Posted by sn...@apache.org.
Fixed source execution order


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

Branch: refs/heads/two-dot-o-events
Commit: 31193199e767a660baa8b58431e48e202e6d98c1
Parents: 06dd703
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 17:50:21 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 17:50:21 2014 -0600

----------------------------------------------------------------------
 .../src/main/dist/init_instance/init_rest_server.sh         | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/31193199/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
index 6df1f59..b370f34 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
@@ -41,14 +41,17 @@ cp /usr/share/aws-java-sdk-*/third-party/*/*.jar /home/ubuntu/.groovy/lib
 cp /usr/share/aws-java-sdk-*/lib/* /home/ubuntu/.groovy/lib 
 ln -s /home/ubuntu/.groovy /root/.groovy
 
+# Build environment for Groovy scripts
+. /etc/profile.d/aws-credentials.sh
+. /etc/profile.d/usergrid-env.sh
+
+
 # tag last so we can see in the console so that we know what's running
 cd /usr/share/usergrid/scripts
 groovy tag_instance.groovy -BUILD-IN-PROGRESS
 
 
-# Build environment for Groovy scripts
-. /etc/profile.d/aws-credentials.sh
-. /etc/profile.d/usergrid-env.sh
+
 chmod +x /usr/share/usergrid/update.sh
 
 cd /usr/share/usergrid/init_instance


[39/50] [abbrv] git commit: add graphite

Posted by sn...@apache.org.
add graphite


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

Branch: refs/heads/two-dot-o-events
Commit: c522a93d842ef4b519b4c7656b6b16e0e0a2f88d
Parents: 955b587
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 17:37:05 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 17:37:05 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/metrics/MetricsFactory.java | 21 ++++++++++----------
 1 file changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c522a93d/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java b/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
index 7209b02..bad07ad 100644
--- a/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
@@ -49,18 +49,17 @@ public class MetricsFactory {
     @PostConstruct
     void init() {
         registry = new MetricRegistry();
-        String badHost = "badhost";
+        String badHost = "false";
         String metricsHost = properties.getProperty("usergrid.metrics.graphite.host", badHost);
-
-        if(metricsHost!=badHost) {
-//            Graphite graphite = new Graphite(new InetSocketAddress(metricsHost, 2003));
-//            graphiteReporter = GraphiteReporter.forRegistry(registry)
-//                    .prefixedWith("notifications")
-//                    .convertRatesTo(TimeUnit.SECONDS)
-//                    .convertDurationsTo(TimeUnit.MILLISECONDS)
-//                    .filter(MetricFilter.ALL)
-//                    .build(graphite);
-//            graphiteReporter.start(30, TimeUnit.SECONDS);
+        if(!metricsHost.equals(badHost)) {
+            Graphite graphite = new Graphite(new InetSocketAddress(metricsHost, 2003));
+            graphiteReporter = GraphiteReporter.forRegistry(registry)
+                    .prefixedWith("notifications")
+                    .convertRatesTo(TimeUnit.SECONDS)
+                    .convertDurationsTo(TimeUnit.MILLISECONDS)
+                    .filter(MetricFilter.ALL)
+                    .build(graphite);
+            graphiteReporter.start(30, TimeUnit.SECONDS);
         }else {
             LOG.warn("MetricsService:Logger not started.");
         }


[50/50] [abbrv] git commit: Merge branch 'two-dot-o' into two-dot-o-events

Posted by sn...@apache.org.
Merge branch 'two-dot-o' into two-dot-o-events

Conflicts:
	stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java


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

Branch: refs/heads/two-dot-o-events
Commit: 3551f3c6331e7edafc871727d0f1bdeeb2c7cb39
Parents: d9ace9e ee0f28c
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Oct 20 09:46:03 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Oct 20 09:46:03 2014 -0400

----------------------------------------------------------------------
 stack/awscluster/pom.xml                        |    2 +-
 stack/awscluster/src/main/cql/create_locks.cql  |   24 +-
 .../awscluster/src/main/cql/create_usergrid.cql |   80 +-
 .../main/cql/create_usergrid_applications.cql   |  411 +----
 .../main/dist/init_instance/create_keyspaces.sh |   28 +-
 .../src/main/dist/init_instance/create_raid0.sh |   19 +-
 .../dist/init_instance/create_raid0_2disks.sh   |   54 -
 .../src/main/dist/init_instance/init_cass.sh    |   70 -
 .../main/dist/init_instance/init_db_server.sh   |   11 +-
 .../main/dist/init_instance/init_es_server.sh   |   67 +
 .../dist/init_instance/init_graphite_server.sh  |   11 +-
 .../main/dist/init_instance/init_rest_server.sh |   24 +
 .../dist/init_instance/install_cassandra.sh     |    6 +-
 .../dist/init_instance/install_elasticsearch.sh |   22 +-
 .../init_instance/install_opscenter_agent.sh    |    1 +
 .../main/dist/init_instance/install_yourkit.sh  |    6 +-
 .../src/main/groovy/configure_cassandra.groovy  |   26 +-
 .../main/groovy/configure_elasticsearch.groovy  |   26 +-
 .../src/main/groovy/configure_usergrid.groovy   |   22 +-
 .../src/main/groovy/tag_instance.groovy         |   10 +-
 stack/awscluster/ugcluster-cf.json              |  345 ++++-
 stack/core/pom.xml                              |   21 -
 .../corepersistence/CpEntityManager.java        |  213 +--
 .../corepersistence/CpEntityManagerFactory.java |   73 +-
 .../corepersistence/CpRelationManager.java      | 1434 ++++++++----------
 .../usergrid/corepersistence/CpSetup.java       |    3 +
 .../usergrid/corepersistence/CpVisitor.java     |   15 +-
 .../usergrid/corepersistence/CpWalker.java      |  242 +--
 .../HybridEntityManagerFactory.java             |   10 -
 .../corepersistence/results/EntityVerifier.java |    3 +-
 .../results/FilteringLoader.java                |   74 +-
 .../corepersistence/results/ResultsLoader.java  |   11 +-
 .../results/VersionVerifier.java                |    5 +-
 .../apache/usergrid/metrics/MetricsFactory.java |   21 +-
 .../usergrid/persistence/EntityManager.java     |    5 +-
 .../persistence/EntityManagerFactory.java       |   12 +-
 .../cassandra/EntityManagerFactoryImpl.java     |   10 -
 .../cassandra/EntityManagerImpl.java            |    7 +-
 .../org/apache/usergrid/CoreApplication.java    |    1 -
 .../usergrid/batch/job/SchedulerRuntime8IT.java |    3 +
 .../corepersistence/StaleIndexCleanupTest.java  |    2 +
 .../PerformanceEntityRebuildIndexTest.java      |   36 +-
 .../PerformanceEntityRepersistTest.java         |  240 ---
 .../query/AbstractIteratingQueryIT.java         |    3 +
 .../impl/EntityCollectionManagerImpl.java       |   37 +-
 .../mvcc/stage/write/WriteCommit.java           |    2 +-
 .../collection/mvcc/stage/write/WriteStart.java |    7 +-
 .../serialization/impl/FieldSerializer.java     |    3 +-
 .../MvccEntitySerializationStrategyImpl.java    |    2 +-
 .../UniqueValueSerializationStrategyImpl.java   |    6 +-
 .../collection/EntityCollectionManagerIT.java   |  139 +-
 ...niqueValueSerializationStrategyImplTest.java |   63 +-
 stack/corepersistence/common/pom.xml            |   13 +-
 stack/corepersistence/pom.xml                   |    1 +
 .../index/impl/EsEntityIndexBatchImpl.java      |    2 +-
 .../index/impl/EsEntityIndexImpl.java           |  146 +-
 .../persistence/index/impl/EsProvider.java      |   21 +-
 .../persistence/index/impl/IndexScopeImpl.java  |   37 +
 stack/corepersistence/queue/pom.xml             |    8 +-
 .../queue/impl/SQSQueueManagerImpl.java         |   21 +-
 stack/pom.xml                                   |   31 +-
 .../apache/usergrid/rest/SystemResource.java    |   74 +-
 stack/rest/src/main/webapp/WEB-INF/web.xml      |    2 +-
 .../usergrid/rest/management/AccessTokenIT.java |  381 ++---
 .../usergrid/services/ServiceManager.java       |    7 +-
 .../services/devices/DevicesService.java        |   55 +-
 .../notifications/ApplicationQueueManager.java  |    5 +-
 .../notifications/NotificationsService.java     |    9 +-
 .../services/notifications/QueueListener.java   |    2 +-
 .../services/users/devices/DevicesService.java  |   33 +
 .../cassandra/ManagementServiceIT.java          |    2 +-
 .../usergrid/services/TestQueueManager.java     |    4 +-
 .../AbstractServiceNotificationIT.java          |   10 +-
 .../notifications/NotifiersServiceIT.java       |    1 +
 .../apns/NotificationsServiceIT.java            |  176 +--
 .../gcm/NotificationsServiceIT.java             |  164 +-
 .../src/test/resources/log4j.properties         |    4 +
 .../org/apache/usergrid/tools/RepersistAll.java |   98 --
 78 files changed, 2407 insertions(+), 2868 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3551f3c6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3551f3c6/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------


[43/50] [abbrv] git commit: change access key logic

Posted by sn...@apache.org.
change access key logic


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

Branch: refs/heads/two-dot-o-events
Commit: c27a090fa492093774848412a66307b82c948afc
Parents: c522a93
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 18:06:38 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 18:06:38 2014 -0600

----------------------------------------------------------------------
 .../persistence/queue/impl/SQSQueueManagerImpl.java      | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c27a090f/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/SQSQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/SQSQueueManagerImpl.java b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/SQSQueueManagerImpl.java
index 4b86a52..caf5691 100644
--- a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/SQSQueueManagerImpl.java
+++ b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/impl/SQSQueueManagerImpl.java
@@ -221,7 +221,7 @@ public class SQSQueueManagerImpl implements QueueManager {
                 @Override
                 public String getAWSAccessKeyId() {
                     String accessKey = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR);
-                    if(accessKey == null){
+                    if(StringUtils.isEmpty(accessKey)){
                         accessKey = System.getProperty(SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR);
                     }
                     return StringUtils.trim(accessKey);
@@ -230,14 +230,17 @@ public class SQSQueueManagerImpl implements QueueManager {
                 @Override
                 public String getAWSSecretKey() {
                     String secret = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR);
-                    if(secret==null){
+                    if(StringUtils.isEmpty(secret)){
                         secret = System.getProperty(SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR);
                     }
                     return StringUtils.trim(secret);
                 }
             };
-            if(StringUtils.isEmpty(creds.getAWSAccessKeyId()) || StringUtils.isEmpty(creds.getAWSSecretKey()) ){
-                throw new AmazonClientException("could not retrieve credentials from system properties");
+            if(StringUtils.isEmpty(creds.getAWSAccessKeyId())){
+                throw new AmazonClientException("could not get aws access key from system properties");
+            }
+            if(StringUtils.isEmpty(creds.getAWSSecretKey())){
+                throw new AmazonClientException("could not get aws secret key from system properties");
             }
         }
 


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: 2cdcf6240df2ac13dbcbfbf6e55f358854261bfa
Parents: 3907a77 3bae36b
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Oct 17 12:09:22 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Oct 17 12:09:22 2014 -0600

----------------------------------------------------------------------
 .../main/dist/init_instance/install_elasticsearch.sh   | 13 +++++++++++++
 stack/awscluster/ugcluster-cf.json                     |  8 ++++++++
 2 files changed, 21 insertions(+)
----------------------------------------------------------------------



[19/50] [abbrv] git commit: Fixed index refresh issue.

Posted by sn...@apache.org.
Fixed index refresh issue.

Fixed source/target switch on entity rebuild

Added performance comments as encountered


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

Branch: refs/heads/two-dot-o-events
Commit: c31c553f9b3c16deda28fc0125d5b1a86a654d14
Parents: f807627
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 18:22:05 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 18:22:05 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |    6 +-
 .../corepersistence/CpEntityManagerFactory.java |   13 +-
 .../corepersistence/CpRelationManager.java      | 1427 ++++++++----------
 .../usergrid/corepersistence/CpWalker.java      |   11 +-
 .../PerformanceEntityRebuildIndexTest.java      |    3 +-
 .../index/impl/EsEntityIndexImpl.java           |   44 +-
 6 files changed, 692 insertions(+), 812 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/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 4015014..2498dda 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
@@ -514,7 +514,7 @@ public class CpEntityManager implements EntityManager {
 
         // update in all containing collections and connection indexes
         CpRelationManager rm = (CpRelationManager)getRelationManager( entity );
-        rm.updateContainingCollectionAndCollectionIndexes( entity, cpEntity );
+        rm.updateContainingCollectionAndCollectionIndexes( cpEntity );
     }
 
 
@@ -995,7 +995,7 @@ public class CpEntityManager implements EntityManager {
 //        }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity =
-                ecm.load( entityId ).toBlockingObservable().last();
+                ecm.load( entityId ).toBlocking().last();
 
         cpEntity.removeField( propertyName );
 
@@ -1012,7 +1012,7 @@ public class CpEntityManager implements EntityManager {
 
         // update in all containing collections and connection indexes
         CpRelationManager rm = (CpRelationManager)getRelationManager( entityRef );
-        rm.updateContainingCollectionAndCollectionIndexes( get( entityRef ), cpEntity );
+        rm.updateContainingCollectionAndCollectionIndexes( cpEntity );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/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 2514e20..e013957 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
@@ -147,6 +147,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                 sysAppProps.put( PROPERTY_NAME, "systemapp");
                 em.create( SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps );
                 em.getApplication();
+                em.createIndex();
                 em.refreshIndex();
             }
 
@@ -200,7 +201,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private EntityManager _getEntityManager( UUID applicationId ) {
         EntityManager em = new CpEntityManager();
         em.init( this, applicationId );
-        //TODO T.N. Can we remove this?  Seems like we should fix our lifecycle instead...
+        //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();
         return em;
     }
@@ -286,7 +290,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager appEm = getEntityManager( applicationId );
 
         //create our ES index since we're initializing this application
-//  TODO T.N, pushed this down into the cache load      appEm.createIndex();
+//  TODO PERFORMANCE  pushed this down into the cache load can we do this here?
+//        appEm.createIndex();
 
         appEm.create( applicationId, TYPE_APPLICATION, properties );
         appEm.resetRoles();
@@ -681,10 +686,12 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public void rebuildApplicationIndexes( UUID appId, ProgressObserver po ) throws Exception {
 
         EntityManager em = getEntityManager( appId );
+
+        //explicitly invoke create index, we don't know if it exists or not in ES during a rebuild.
+        em.createIndex();
         Application app = em.getApplication();
 
         em.reindex( po );
-//        em.refreshIndex();
 
         logger.info("\n\nRebuilt index for application {} id {}\n", app.getName(), appId );
     }


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: f737927b6c5cde4c2ee10c4a3e09cadd5b45cfa6
Parents: d553e77 955b587
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 17:37:10 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 17:37:10 2014 -0600

----------------------------------------------------------------------
 .../usergrid/services/notifications/NotificationsService.java    | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[33/50] [abbrv] git commit: Fixes graphite installation

Posted by sn...@apache.org.
Fixes graphite installation


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

Branch: refs/heads/two-dot-o-events
Commit: e41021d0c55863a79a43ecc793e5a3b02a1bb6e6
Parents: 2cdcf62
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 13:39:33 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 13:39:33 2014 -0600

----------------------------------------------------------------------
 .../src/main/dist/init_instance/init_graphite_server.sh           | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e41021d0/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh b/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
index b095f2b..6b1c81a 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
@@ -58,6 +58,9 @@ groovy tag_instance.groovy BUILD-IN-PROGRESS
 cd /usr/share/usergrid/init_instance
 ./install_oraclejdk.sh
 
+#Install graphite
+sudo docker run -d --name graphite -p 80:80 -p 2003:2003 -p 8125:8125/udp hopsoft/graphite-statsd
+
 cd /usr/share/usergrid/scripts
 groovy registry_register.groovy graphite
 


[20/50] [abbrv] git commit: Added logging

Posted by sn...@apache.org.
Added logging


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

Branch: refs/heads/two-dot-o-events
Commit: 83200bf52f276c89f4351cf6fc8988414646507a
Parents: c31c553
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 19:29:01 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 19:30:08 2014 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/index/impl/EsEntityIndexImpl.java      | 5 ++++-
 .../services/notifications/AbstractServiceNotificationIT.java   | 4 ----
 2 files changed, 4 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/83200bf5/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 821f7b9..b562d8a 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -88,7 +88,9 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     private final IndexFig config;
 
-    private static final int MAX_WAITS = 10;
+    //number of times to wait for the index to refresh propertly. Is an N+1, so 9 = 10
+    private static final int MAX_WAITS = 9;
+    //number of milliseconds to try again before sleeping
     private static final int WAIT_TIME = 250;
 
 
@@ -280,6 +282,7 @@ public class EsEntityIndexImpl implements EntityIndex {
         for ( int i = 0; i < MAX_WAITS; i++ ) {
             try {
                 client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+                log.debug( "Refreshed index: " + indexName );
                 return;
             }
             catch ( IndexMissingException e ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/83200bf5/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index e16f111..a9ca955 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -41,11 +41,7 @@ import static org.junit.Assert.fail;
 
 public class AbstractServiceNotificationIT extends AbstractServiceIT {
     private NotificationsService ns;
-    @Autowired
-    private ServiceManagerFactory smf;
 
-    @Autowired
-    private EntityManagerFactory emf;
     @Rule
     public TestName name = new TestName();
 


[03/50] [abbrv] git commit: Fixes issue with setup not creating indexes correctly

Posted by sn...@apache.org.
Fixes issue with setup not creating indexes correctly


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

Branch: refs/heads/two-dot-o-events
Commit: dbdba300d9f690cfa6fd7738bc58955488b177ba
Parents: d52ad4c
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 15 22:28:48 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 15 22:28:48 2014 -0600

----------------------------------------------------------------------
 .../main/java/org/apache/usergrid/corepersistence/CpSetup.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dbdba300/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index 9063775..c1bab12 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -156,6 +156,9 @@ public class CpSetup implements Setup {
 
         setupStaticKeyspace();
 
+        //force the EMF creation of indexes before creating the default applications
+        emf.refreshIndex();
+
         createDefaultApplications();
     }
 


[49/50] [abbrv] git commit: Fixes cassandra heap

Posted by sn...@apache.org.
Fixes cassandra heap


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

Branch: refs/heads/two-dot-o-events
Commit: ee0f28c7a55b6e6d986b74fdb696e80fb6116fd3
Parents: f7b7513
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 20:07:13 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 20:14:57 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/src/main/dist/init_instance/install_cassandra.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ee0f28c7/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh b/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
index 0e7c465..3d55c6d 100644
--- a/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
+++ b/stack/awscluster/src/main/dist/init_instance/install_cassandra.sh
@@ -39,8 +39,9 @@ cd /usr/share/usergrid/scripts
 groovy registry_register.groovy cassandra
 groovy wait_for_instances.groovy cassandra ${CASSANDRA_NUM_SERVERS}
 
+#TODO make this configurable for the box sizes
 #Set or min/max heap to 8GB
-sed -i.bak s/calculate_heap_sizes\(\)/MAX_HEAP_SIZE="8G"\\nHEAP_NEWSIZE="1200M"\\n\ncalculate_heap_sizes\(\)/g /etc/cassandra/cassandra-env.sh
+sed -i.bak s/calculate_heap_sizes\(\)/MAX_HEAP_SIZE=\"8G\"\\nHEAP_NEWSIZE=\"1200M\"\\n\\ncalculate_heap_sizes\(\)/g /etc/cassandra/cassandra-env.sh
 
 cd /usr/share/usergrid/scripts
 groovy configure_cassandra.groovy > /etc/cassandra/cassandra.yaml


[22/50] [abbrv] git commit: Explicitly made node a client

Posted by sn...@apache.org.
Explicitly made node a client


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

Branch: refs/heads/two-dot-o-events
Commit: bd00ee0012352b5cadecedbbccd92b8c5f2622dd
Parents: 722c43b
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 21:48:57 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 21:48:57 2014 -0600

----------------------------------------------------------------------
 .../java/org/apache/usergrid/persistence/index/impl/EsProvider.java | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/bd00ee00/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
index a9228ee..aac9ff5 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
@@ -163,6 +163,7 @@ public class EsProvider {
                     .put("client.transport.ping_timeout", 2000) // milliseconds
                     .put("client.transport.nodes_sampler_interval", 100)
                     .put("network.tcp.blocking", true)
+                    .put("node.client", true)
                     .put("node.name",  nodeName )
 
                     .build();


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: 7c06f6bbba61fb5df7647a7dcbe77efa000a7d16
Parents: 2c5e6f5 dbdba30
Author: Dave Johnson <dm...@apigee.com>
Authored: Thu Oct 16 07:51:31 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Thu Oct 16 07:51:31 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpRelationManager.java      |  10 +-
 .../usergrid/corepersistence/CpSetup.java       |   3 +
 .../queue/impl/SQSQueueManagerImpl.java         |   2 +-
 .../services/devices/DevicesService.java        |  49 +++++-
 .../notifications/ApplicationQueueManager.java  |   5 +-
 .../notifications/NotificationsService.java     |   7 +-
 .../services/notifications/QueueListener.java   |   2 +-
 .../services/users/devices/DevicesService.java  |  33 ++++
 .../AbstractServiceNotificationIT.java          |   6 +-
 .../apns/NotificationsServiceIT.java            | 173 ++++++++++---------
 .../gcm/NotificationsServiceIT.java             | 164 ++----------------
 11 files changed, 202 insertions(+), 252 deletions(-)
----------------------------------------------------------------------



[18/50] [abbrv] Fixed index refresh issue.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/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 2a790ab..96f0e1e 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
@@ -16,14 +16,10 @@
 
 package org.apache.usergrid.corepersistence;
 
-import static me.prettyprint.hector.api.factory.HFactory.createMutator;
 
-import com.clearspring.analytics.hash.MurmurHash;
-import com.yammer.metrics.annotation.Metered;
 import java.nio.ByteBuffer;
 import java.util.AbstractMap;
 import java.util.ArrayList;
-import static java.util.Arrays.asList;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -33,21 +29,18 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.util.Assert;
+
 import org.apache.usergrid.corepersistence.results.ResultsLoader;
 import org.apache.usergrid.corepersistence.results.ResultsLoaderFactory;
 import org.apache.usergrid.corepersistence.results.ResultsLoaderFactoryImpl;
 import org.apache.usergrid.corepersistence.util.CpEntityMapUtils;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.index.EntityIndexBatch;
-import org.apache.usergrid.utils.UUIDUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.util.Assert;
-
 import org.apache.usergrid.persistence.ConnectedEntityRef;
 import org.apache.usergrid.persistence.ConnectionRef;
 import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityFactory;
 import org.apache.usergrid.persistence.EntityManager;
 import org.apache.usergrid.persistence.EntityRef;
 import org.apache.usergrid.persistence.IndexBucketLocator;
@@ -56,43 +49,12 @@ import org.apache.usergrid.persistence.RelationManager;
 import org.apache.usergrid.persistence.Results;
 import org.apache.usergrid.persistence.RoleRef;
 import org.apache.usergrid.persistence.Schema;
-import static org.apache.usergrid.persistence.Schema.COLLECTION_ROLES;
-import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_ENTITIES;
-import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_TYPES;
-import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTING_ENTITIES;
-import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTING_TYPES;
-import static org.apache.usergrid.persistence.Schema.INDEX_CONNECTIONS;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_CREATED;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_INACTIVITY;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
-import static org.apache.usergrid.persistence.Schema.PROPERTY_TITLE;
-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.TYPE_ROLE;
-import static org.apache.usergrid.persistence.Schema.getDefaultSchema;
 import org.apache.usergrid.persistence.SimpleEntityRef;
 import org.apache.usergrid.persistence.SimpleRoleRef;
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_COMPOSITE_DICTIONARIES;
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_DICTIONARIES;
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_INDEX;
-import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_INDEX_ENTRIES;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addDeleteToMutator;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addInsertToMutator;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.batchExecute;
-import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
 import org.apache.usergrid.persistence.cassandra.CassandraService;
-import static org.apache.usergrid.persistence.cassandra.CassandraService.INDEX_ENTRY_LIST_COUNT;
 import org.apache.usergrid.persistence.cassandra.ConnectionRefImpl;
-import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchDeleteLocationInConnectionsIndex;
-import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchRemoveLocationFromCollectionIndex;
-import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchStoreLocationInCollectionIndex;
-import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchStoreLocationInConnectionsIndex;
 import org.apache.usergrid.persistence.cassandra.IndexUpdate;
-import static org.apache.usergrid.persistence.cassandra.IndexUpdate.indexValueCode;
-import static org.apache.usergrid.persistence.cassandra.IndexUpdate.toIndexableValue;
-import static org.apache.usergrid.persistence.cassandra.IndexUpdate.validIndexableValue;
 import org.apache.usergrid.persistence.cassandra.QueryProcessorImpl;
-import static org.apache.usergrid.persistence.cassandra.Serializers.be;
 import org.apache.usergrid.persistence.cassandra.index.ConnectedIndexScanner;
 import org.apache.usergrid.persistence.cassandra.index.IndexBucketScanner;
 import org.apache.usergrid.persistence.cassandra.index.IndexScanner;
@@ -114,6 +76,7 @@ import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
 import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.index.EntityIndexBatch;
 import org.apache.usergrid.persistence.index.IndexScope;
 import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
 import org.apache.usergrid.persistence.index.query.CandidateResult;
@@ -138,19 +101,59 @@ import org.apache.usergrid.persistence.query.ir.result.GeoIterator;
 import org.apache.usergrid.persistence.query.ir.result.SliceIterator;
 import org.apache.usergrid.persistence.query.ir.result.StaticIdIterator;
 import org.apache.usergrid.persistence.schema.CollectionInfo;
-import static org.apache.usergrid.utils.ClassUtils.cast;
-import static org.apache.usergrid.utils.CompositeUtils.setGreaterThanEqualityFlag;
 import org.apache.usergrid.utils.IndexUtils;
-import static org.apache.usergrid.utils.InflectionUtils.singularize;
 import org.apache.usergrid.utils.MapUtils;
-import static org.apache.usergrid.utils.MapUtils.addMapSet;
-import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMicros;
+import org.apache.usergrid.utils.UUIDUtils;
+
+import com.yammer.metrics.annotation.Metered;
 
 import me.prettyprint.hector.api.Keyspace;
 import me.prettyprint.hector.api.beans.DynamicComposite;
 import me.prettyprint.hector.api.beans.HColumn;
 import me.prettyprint.hector.api.mutation.Mutator;
 import rx.Observable;
+import rx.functions.Action1;
+import rx.functions.Func1;
+
+import static java.util.Arrays.asList;
+
+import static me.prettyprint.hector.api.factory.HFactory.createMutator;
+import static org.apache.usergrid.persistence.Schema.COLLECTION_ROLES;
+import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_ENTITIES;
+import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTED_TYPES;
+import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTING_ENTITIES;
+import static org.apache.usergrid.persistence.Schema.DICTIONARY_CONNECTING_TYPES;
+import static org.apache.usergrid.persistence.Schema.INDEX_CONNECTIONS;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_CREATED;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_INACTIVITY;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_NAME;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_TITLE;
+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.TYPE_ROLE;
+import static org.apache.usergrid.persistence.Schema.getDefaultSchema;
+import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_COMPOSITE_DICTIONARIES;
+import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_DICTIONARIES;
+import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_INDEX;
+import static org.apache.usergrid.persistence.cassandra.ApplicationCF.ENTITY_INDEX_ENTRIES;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addDeleteToMutator;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.addInsertToMutator;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.batchExecute;
+import static org.apache.usergrid.persistence.cassandra.CassandraPersistenceUtils.key;
+import static org.apache.usergrid.persistence.cassandra.CassandraService.INDEX_ENTRY_LIST_COUNT;
+import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchDeleteLocationInConnectionsIndex;
+import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchRemoveLocationFromCollectionIndex;
+import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchStoreLocationInCollectionIndex;
+import static org.apache.usergrid.persistence.cassandra.GeoIndexManager.batchStoreLocationInConnectionsIndex;
+import static org.apache.usergrid.persistence.cassandra.IndexUpdate.indexValueCode;
+import static org.apache.usergrid.persistence.cassandra.IndexUpdate.toIndexableValue;
+import static org.apache.usergrid.persistence.cassandra.IndexUpdate.validIndexableValue;
+import static org.apache.usergrid.persistence.cassandra.Serializers.be;
+import static org.apache.usergrid.utils.ClassUtils.cast;
+import static org.apache.usergrid.utils.CompositeUtils.setGreaterThanEqualityFlag;
+import static org.apache.usergrid.utils.InflectionUtils.singularize;
+import static org.apache.usergrid.utils.MapUtils.addMapSet;
+import static org.apache.usergrid.utils.UUIDUtils.getTimestampInMicros;
 
 
 /**
@@ -161,9 +164,8 @@ public class CpRelationManager implements RelationManager {
     private static final Logger logger = LoggerFactory.getLogger( CpRelationManager.class );
 
 
-
     private CpEntityManagerFactory emf;
-    
+
     private CpManagerCache managerCache;
 
     private EntityManager em;
@@ -184,23 +186,18 @@ public class CpRelationManager implements RelationManager {
     private ResultsLoaderFactory resultsLoaderFactory;
 
 
-
     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" );
         Assert.notNull( applicationId, "Application Id cannot be null" );
         Assert.notNull( headEntity, "Head entity cannot be null" );
         Assert.notNull( headEntity.getUuid(), "Head entity uuid cannot be null" );
-       
+
         // TODO: this assert should not be failing
         //Assert.notNull( indexBucketLocator, "indexBucketLocator cannot be null" );
 
@@ -209,31 +206,27 @@ public class CpRelationManager implements RelationManager {
         this.applicationId = applicationId;
         this.headEntity = headEntity;
         this.managerCache = emf.getManagerCache();
-        this.applicationScope = emf.getApplicationScope(applicationId);
+        this.applicationScope = emf.getApplicationScope( applicationId );
 
         this.cass = em.getCass(); // TODO: eliminate need for this via Core Persistence
         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);
+        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()
+                    } );
         }
-        
-        this.cpHeadEntity = ecm.load( new SimpleId( 
-            headEntity.getUuid(), headEntity.getType() )).toBlocking().lastOrDefault(null);
+
+        //TODO PERFORMANCE why are we loading this again here?
+        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" );
@@ -243,22 +236,21 @@ public class CpRelationManager implements RelationManager {
         return this;
     }
 
-    
+
     @Override
     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() ) {
@@ -275,8 +267,7 @@ 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 );
@@ -296,6 +287,7 @@ 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
@@ -304,44 +296,43 @@ 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();
+        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() )) {
+                if ( CpNamingUtils.isConnectionEdgeType( edge.getType() ) ) {
                     name = CpNamingUtils.getConnectionType( edge.getType() );
-                } else {
+                }
+                else {
                     name = CpNamingUtils.getCollectionName( edge.getType() );
                 }
                 addMapSet( results, eref, name );
@@ -356,183 +347,161 @@ public class CpRelationManager implements RelationManager {
     }
 
 
-    public List<String> updateContainingCollectionAndCollectionIndexes( 
-        Entity entity, org.apache.usergrid.persistence.model.entity.Entity cpEntity ) {
-
-        List<String> results = new ArrayList<String>();
+    public void updateContainingCollectionAndCollectionIndexes(
+            final org.apache.usergrid.persistence.model.entity.Entity cpEntity ) {
 
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
 
-        Iterator<String> edgeTypesToTarget = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( 
-            cpHeadEntity.getId(), null, null) ).toBlockingObservable().getIterator();
+        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(),
-                edgeTypesToTarget.hasNext()
-        });
+        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
-        int count = 0;
+
 
         final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
         final EntityIndexBatch entityIndexBatch = ei.createBatch();
 
-        while ( edgeTypesToTarget.hasNext() ) {
-
-            // get all edges of the type
-            String etype = edgeTypesToTarget.next();
+        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 ) );
+                                }
+                            } )
 
-            Observable<Edge> edges = 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 ) {
 
-            // loop through edges of that type
-            Iterator<Edge> iter = edges.toBlockingObservable().getIterator();
-            while ( iter.hasNext() ) {
 
-                Edge edge = iter.next();
+                        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
 
-                // reindex the entity in the source entity's collection or connection index
+                        IndexScope indexScope;
+                        if ( CpNamingUtils.isCollectionEdgeType( edge.getType() ) ) {
 
-                IndexScope indexScope;
-                if ( CpNamingUtils.isCollectionEdgeType( edge.getType() )) {
+                            String collName = CpNamingUtils.getCollectionName( edge.getType() );
+                            indexScope =
+                                    new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
+                                            CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ) );
+                        }
+                        else {
 
-                    String collName = CpNamingUtils.getCollectionName( edge.getType() );
-                    indexScope = new IndexScopeImpl(
-                        new SimpleId(sourceEntity.getUuid(), sourceEntity.getType()),
-                        CpNamingUtils.getCollectionScopeNameFromCollectionName( collName ));
+                            String connName = CpNamingUtils.getCollectionName( edge.getType() );
+                            indexScope =
+                                    new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
+                                            CpNamingUtils.getConnectionScopeName( cpEntity.getId().getType(),
+                                                    connName ) );
+                        }
 
-                } else {
+                        entityIndexBatch.index( indexScope, cpEntity );
 
-                    String connName = CpNamingUtils.getCollectionName( edge.getType() );
-                    indexScope = new IndexScopeImpl(
-                        new SimpleId(sourceEntity.getUuid(), sourceEntity.getType()),
-                        CpNamingUtils.getConnectionScopeName( cpHeadEntity.getId().getType(), connName ));
-                }
+                        // reindex the entity in the source entity's all-types index
 
-                entityIndexBatch.index(indexScope, cpEntity);
+                        indexScope = new IndexScopeImpl( new SimpleId( sourceEntity.getUuid(), sourceEntity.getType() ),
+                                CpNamingUtils.ALL_TYPES );
 
-                // reindex the entity in the source entity's all-types index
-                
-                indexScope = new IndexScopeImpl(
-                    new SimpleId(sourceEntity.getUuid(), sourceEntity.getType()),
-                        CpNamingUtils.ALL_TYPES);
-
-                entityIndexBatch.index(indexScope, cpEntity);
+                        entityIndexBatch.index( indexScope, cpEntity );
+                    }
+                } ).count().toBlocking().lastOrDefault( 0 );
 
-                count++;
-            }
-        }
 
         entityIndexBatch.execute();
 
-        logger.debug("updateContainingCollectionsAndCollections() updated {} indexes", count);
-        return results;
+        logger.debug( "updateContainingCollectionsAndCollections() updated {} indexes", count );
     }
 
 
     @Override
-    public boolean isConnectionMember(String connectionType, EntityRef entity) throws Exception {
+    public boolean isConnectionMember( String connectionType, EntityRef entity ) throws Exception {
 
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
 
         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() });
-
-        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));
-
-        return edges.toBlockingObservable().firstOrDefault(null) != null;
+        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 ) );
+
+        return edges.toBlockingObservable().firstOrDefault( null ) != null;
     }
 
 
-    @SuppressWarnings("unchecked")
-    @Metered(group = "core", name = "RelationManager_isOwner")
+    @SuppressWarnings( "unchecked" )
+    @Metered( group = "core", name = "RelationManager_isOwner" )
     @Override
-    public boolean isCollectionMember(String collName, EntityRef entity) throws Exception {
+    public boolean isCollectionMember( String collName, EntityRef entity ) throws Exception {
 
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
 
         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() });
-
-        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));
-
-        return edges.toBlockingObservable().firstOrDefault(null) != null;
+        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 ) );
+
+        return edges.toBlockingObservable().firstOrDefault( null ) != null;
     }
 
 
-   private boolean moreThanOneInboundConnection( 
-           EntityRef target, String connectionType ) {
+    private boolean moreThanOneInboundConnection( EntityRef target, String connectionType ) {
 
         Id targetId = new SimpleId( target.getUuid(), target.getType() );
 
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
+        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;
         while ( iterator.hasNext() ) {
             iterator.next();
-            if ( count++ > 1 ) { 
+            if ( count++ > 1 ) {
                 return true;
             }
-        } 
+        }
         return false;
-   } 
+    }
 
-   private boolean moreThanOneOutboundConnection( 
-           EntityRef source, String connectionType ) {
+
+    private boolean moreThanOneOutboundConnection( EntityRef source, String connectionType ) {
 
         Id sourceId = new SimpleId( source.getUuid(), source.getType() );
 
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
+        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();
 
         return count > 1;
-   } 
+    }
 
 
     @Override
@@ -540,10 +509,10 @@ public class CpRelationManager implements RelationManager {
 
         final Set<String> indexes = new HashSet<String>();
 
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
+        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() ) {
@@ -552,52 +521,53 @@ public class CpRelationManager implements RelationManager {
         }
 
         return indexes;
-
     }
 
+
     @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);
-        query.setReversed(reversed);
+        Query query = Query.fromQL( "select *" );
+        query.setLimit( count );
+        query.setReversed( reversed );
 
         if ( startResult != null ) {
-            query.addGreaterThanEqualFilter("created", startResult.timestamp());
+            query.addGreaterThanEqualFilter( "created", startResult.timestamp() );
         }
 
-        return searchCollection(collectionName, query);
+        return searchCollection( collectionName, query );
     }
 
+
     @Override
-    public Results getCollection(
-            String collName, Query query, Level level) throws Exception {
+    public Results getCollection( String collName, Query query, Level level ) throws Exception {
 
-        return searchCollection(collName, query);
+        return searchCollection( collName, query );
     }
 
 
     // add to a named collection of the head entity
     @Override
-    public Entity addToCollection(String collName, EntityRef itemRef) throws Exception {
-       
+    public Entity addToCollection( String collName, EntityRef itemRef ) throws Exception {
+
         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 ) );
     }
 
-    public Entity addToCollection(String collName, EntityRef itemRef, boolean connectBack ) throws Exception {
+
+    public Entity addToCollection( String collName, EntityRef itemRef, boolean connectBack ) throws Exception {
 
         // don't fetch entity if we've already got one
         final Entity itemEntity;
         if ( itemRef instanceof Entity ) {
-            itemEntity = (Entity)itemRef;
-        } else {
+            itemEntity = ( Entity ) itemRef;
+        }
+        else {
             itemEntity = em.get( itemRef );
         }
 
@@ -611,70 +581,61 @@ 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);
+        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("Unable to load entity uuid=" 
-                + itemRef.getUuid() + " type=" + itemRef.getType());
+            throw new RuntimeException(
+                    "Unable to load entity uuid=" + itemRef.getUuid() + " type=" + itemRef.getType() );
         }
 
         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);
+        long uuidHash = UUIDUtils.getUUIDLong( timeStampUuid );
 
         // create graph edge connection from head entity to member entity
-        Edge edge = new SimpleEdge(
-            cpHeadEntity.getId(),
-            edgeType,
-            memberEntity.getId(),
-           uuidHash);
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
-        gm.writeEdge(edge).toBlockingObservable().last();
+        Edge edge = new SimpleEdge( cpHeadEntity.getId(), edgeType, memberEntity.getId(), uuidHash );
+        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 );
+        ( ( CpEntityManager ) em ).indexEntityIntoCollection( cpHeadEntity, memberEntity, collName );
 
-        logger.debug("Added entity {}:{} to collection {}", new Object[] { 
-            itemRef.getUuid().toString(), itemRef.getType(), collName }); 
+        logger.debug( "Added entity {}:{} to collection {}", new Object[] {
+                itemRef.getUuid().toString(), itemRef.getType(), collName
+        } );
 
-//        logger.debug("With head entity scope is {}:{}:{}", new Object[] { 
-//            headEntityScope.getApplication().toString(), 
-//            headEntityScope.getOwner().toString(),
-//            headEntityScope.getName()}); 
+        //        logger.debug("With head entity scope is {}:{}:{}", new Object[] {
+        //            headEntityScope.getApplication().toString(),
+        //            headEntityScope.getOwner().toString(),
+        //            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;
@@ -682,11 +643,11 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    public Entity addToCollections(List<EntityRef> owners, String collName) throws Exception {
+    public Entity addToCollections( List<EntityRef> owners, String collName ) throws Exception {
 
         // TODO: this addToCollections() implementation seems wrong.
         for ( EntityRef eref : owners ) {
-            addToCollection( collName, eref ); 
+            addToCollection( collName, eref );
         }
 
         return null;
@@ -694,9 +655,9 @@ 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 {
+    @Metered( group = "core", name = "RelationManager_createItemInCollection" )
+    public Entity createItemInCollection( String collName, String itemType, Map<String, Object> properties )
+            throws Exception {
 
         if ( headEntity.getUuid().equals( applicationId ) ) {
             if ( itemType.equals( TYPE_ENTITY ) ) {
@@ -714,14 +675,13 @@ 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 ) );
         }
 
-        CollectionInfo collection = getDefaultSchema().getCollection(headEntity.getType(),collName);
+        CollectionInfo collection = getDefaultSchema().getCollection( headEntity.getType(), collName );
         if ( ( collection != null ) && !collection.getType().equals( itemType ) ) {
             return null;
         }
@@ -735,16 +695,16 @@ 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 );
             }
         }
 
-        return itemEntity;  
+        return itemEntity;
     }
 
+
     @Override
-    public void removeFromCollection(String collName, EntityRef itemRef) throws Exception {
+    public void removeFromCollection( String collName, EntityRef itemRef ) throws Exception {
 
         // special handling for roles collection of the application
         if ( headEntity.getUuid().equals( applicationId ) ) {
@@ -760,102 +720,86 @@ public class CpRelationManager implements RelationManager {
             }
             em.delete( itemRef );
             return;
-       }
+        }
 
         // load the entity to be removed to the collection
-        CollectionScope memberScope = new CollectionScopeImpl( 
-            this.applicationScope.getApplication(), 
-            this.applicationScope.getApplication(), 
-            CpNamingUtils.getCollectionScopeNameFromEntityType( itemRef.getType() ));
-        EntityCollectionManager memberMgr = managerCache.getEntityCollectionManager(memberScope);
+        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 EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         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 );
+        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 );
+        batch.deindex( itemScope, cpHeadEntity );
 
         batch.execute();
 
         // 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())
-            );
-        gm.deleteEdge(collectionToItemEdge).toBlockingObservable().last();
+        GraphManager gm = managerCache.getGraphManager( applicationScope );
+        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()));
-        gm.deleteEdge(itemToCollectionEdge).toBlockingObservable().last();
+        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
         if ( headEntity.getType().equals( Group.ENTITY_TYPE ) ) {
 
             if ( collName.equals( COLLECTION_ROLES ) ) {
-                String path = (String)( (Entity)itemRef ).getMetadata( "path" );
+                String path = ( String ) ( ( Entity ) itemRef ).getMetadata( "path" );
 
                 if ( path.startsWith( "/roles/" ) ) {
 
-                    Entity itemEntity = em.get( new SimpleEntityRef( 
-                        memberEntity.getId().getType(), memberEntity.getId().getUuid() ) );
+                    Entity itemEntity = em.get( new SimpleEntityRef( memberEntity.getId().getType(),
+                            memberEntity.getId().getUuid() ) );
 
                     RoleRef roleRef = SimpleRoleRef.forRoleEntity( itemEntity );
                     em.deleteRole( roleRef.getApplicationRoleName() );
                 }
-
-            } 
+            }
         }
     }
 
 
     @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 );
 
-        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 {
@@ -881,8 +825,9 @@ public class CpRelationManager implements RelationManager {
         while ( ( results != null ) && ( results.hasMoreResults() ) );
     }
 
+
     @Override
-    public Results searchCollection(String collName, Query query) throws Exception {
+    public Results searchCollection( String collName, Query query ) throws Exception {
 
         if ( query == null ) {
             query = new Query();
@@ -890,24 +835,22 @@ 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() );
+            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);
-      
-        logger.debug("Searching scope {}:{}",
+        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
 
-                indexScope.getOwner().toString(),
-                indexScope.getName() );
+        logger.debug( "Searching scope {}:{}",
+
+                indexScope.getOwner().toString(), indexScope.getName() );
 
         query.setEntityType( collection.getType() );
         query = adjustQuery( query );
@@ -929,22 +872,22 @@ public class CpRelationManager implements RelationManager {
             CandidateResults crs = ei.search( indexScope, query );
 
             if ( results == null ) {
-                logger.debug("Calling build results 1");
+                logger.debug( "Calling build results 1" );
                 results = buildResults( query, crs, collName );
-
-            } else {
-                logger.debug("Calling build results 2");
+            }
+            else {
+                logger.debug( "Calling build results 2" );
                 Results newResults = buildResults( query, crs, collName );
                 results.merge( newResults );
             }
 
             if ( crs.isEmpty() || !crs.hasCursor() ) { // no results, no cursor, can't get more
                 satisfied = true;
-
-            } else if ( results.size() == originalLimit )  { // got what we need
+            }
+            else if ( results.size() == originalLimit ) { // got what we need
                 satisfied = true;
-
-            } else if ( crs.hasCursor() ) {
+            }
+            else if ( crs.hasCursor() ) {
                 satisfied = false;
 
                 // need to query for more
@@ -952,10 +895,10 @@ public class CpRelationManager implements RelationManager {
                 query.setCursor( results.getCursor() );
                 query.setLimit( originalLimit - results.size() );
 
-                logger.warn("Satisfy query limit {}, new limit {} query count {}", new Object[] {
-                    originalLimit, query.getLimit(), queryCount 
-                });
-            } 
+                logger.warn( "Satisfy query limit {}, new limit {} query count {}", new Object[] {
+                        originalLimit, query.getLimit(), queryCount
+                } );
+            }
         }
 
         return results;
@@ -963,78 +906,60 @@ public class CpRelationManager implements RelationManager {
 
 
     @Override
-    @Metered(group = "core", name = "RelationManager_createConnection_connection_ref")
+    @Metered( group = "core", name = "RelationManager_createConnection_connection_ref" )
     public ConnectionRef createConnection( ConnectionRef connection ) throws Exception {
-        
+
         return createConnection( connection.getConnectionType(), connection.getConnectedEntity() );
     }
 
 
     @Override
-    @Metered(group = "core", name = "RelationManager_createConnection_connectionType")
-    public ConnectionRef createConnection( 
-            String connectionType, EntityRef connectedEntityRef ) throws Exception {
+    @Metered( group = "core", name = "RelationManager_createConnection_connectionType" )
+    public ConnectionRef createConnection( String connectionType, EntityRef connectedEntityRef ) throws Exception {
 
         headEntity = em.validate( headEntity );
         connectedEntityRef = em.validate( connectedEntityRef );
 
-        ConnectionRefImpl connection = new ConnectionRefImpl( 
-            headEntity, connectionType, connectedEntityRef );
+        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);
+        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() 
-            });
-        }
-
-        org.apache.usergrid.persistence.model.entity.Entity targetEntity = targetEcm.load(
-            new SimpleId( connectedEntityRef.getUuid(), connectedEntityRef.getType() ))
-                .toBlockingObservable().last();
-
-        String edgeType = CpNamingUtils
-                .getEdgeTypeFromConnectionType( connectionType );
+            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();
+
+        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() );
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
-        gm.writeEdge(edge).toBlockingObservable().last();
-
-        EntityIndex ei = managerCache.getEntityIndex(applicationScope);
+        Edge edge = new SimpleEdge( cpHeadEntity.getId(), edgeType, targetEntity.getId(), System.currentTimeMillis() );
+        GraphManager gm = managerCache.getGraphManager( applicationScope );
+        gm.writeEdge( edge ).toBlockingObservable().last();
+
+        EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         EntityIndexBatch batch = ei.createBatch();
 
         // Index the new connection in app|source|type context
-        IndexScope indexScope = new IndexScopeImpl(
-            cpHeadEntity.getId(), 
-            CpNamingUtils.getConnectionScopeName( connectedEntityRef.getType(), connectionType ));
+        IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(),
+                CpNamingUtils.getConnectionScopeName( connectedEntityRef.getType(), connectionType ) );
 
-        batch.index(indexScope, targetEntity );
+        batch.index( indexScope, targetEntity );
 
         // Index the new connection in app|scope|all-types context
-        IndexScope allTypesIndexScope = new IndexScopeImpl(
-            cpHeadEntity.getId(), 
-                CpNamingUtils.ALL_TYPES);
-        batch.index(allTypesIndexScope,  targetEntity );
+        IndexScope allTypesIndexScope = new IndexScopeImpl( cpHeadEntity.getId(), CpNamingUtils.ALL_TYPES );
+        batch.index( allTypesIndexScope, targetEntity );
 
 
         batch.execute();
@@ -1047,16 +972,17 @@ public class CpRelationManager implements RelationManager {
         return connection;
     }
 
-    
-    @SuppressWarnings("unchecked")
-    @Metered(group = "core", name = "CpRelationManager_batchUpdateEntityConnection")
-    public Mutator<ByteBuffer> batchUpdateEntityConnection( Mutator<ByteBuffer> batch, 
-        boolean disconnect, ConnectionRefImpl connection, UUID timestampUuid ) throws Exception {
+
+    @SuppressWarnings( "unchecked" )
+    @Metered( group = "core", name = "CpRelationManager_batchUpdateEntityConnection" )
+    public Mutator<ByteBuffer> batchUpdateEntityConnection( Mutator<ByteBuffer> batch, boolean disconnect,
+                                                            ConnectionRefImpl connection, UUID timestampUuid )
+            throws Exception {
 
         long timestamp = getTimestampInMicros( timestampUuid );
 
-        Entity connectedEntity = em.get( new SimpleEntityRef( 
-                connection.getConnectedEntityType(), connection.getConnectedEntityId()) );
+        Entity connectedEntity =
+                em.get( new SimpleEntityRef( connection.getConnectedEntityType(), connection.getConnectedEntityId() ) );
 
         if ( connectedEntity == null ) {
             return batch;
@@ -1065,64 +991,60 @@ public class CpRelationManager implements RelationManager {
         // Create connection for requested params
 
         if ( disconnect ) {
-            
+
             addDeleteToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
-                    connection.getConnectionType() ),
-                asList( connection.getConnectedEntityId(), 
-                        connection.getConnectedEntityType() ), timestamp );
+                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
+                            connection.getConnectionType() ),
+                    asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), timestamp );
 
             addDeleteToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
-                    connection.getConnectionType() ),
-                asList( connection.getConnectingEntityId(), 
-                        connection.getConnectingEntityType() ), timestamp );
+                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
+                            connection.getConnectionType() ),
+                    asList( connection.getConnectingEntityId(), connection.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( connection.getConnectingEntity(), connection.getConnectionType() ) ) {
 
                 addDeleteToMutator( batch, ENTITY_DICTIONARIES,
-                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
-                    connection.getConnectionType(), timestamp );
+                        key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
+                        connection.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( connection.getConnectingEntity(), connection.getConnectionType() ) ) {
 
                 addDeleteToMutator( batch, ENTITY_DICTIONARIES,
                         key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
                         connection.getConnectionType(), timestamp );
             }
-
-        } else {
+        }
+        else {
 
             addInsertToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
-                    connection.getConnectionType() ),
-                asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), 
-                    timestamp, timestamp );
+                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_ENTITIES,
+                            connection.getConnectionType() ),
+                    asList( connection.getConnectedEntityId(), connection.getConnectedEntityType() ), timestamp,
+                    timestamp );
 
             addInsertToMutator( batch, ENTITY_COMPOSITE_DICTIONARIES,
-                key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
-                    connection.getConnectionType() ),
-                asList( connection.getConnectingEntityId(), connection.getConnectingEntityType() ), 
-                    timestamp, timestamp );
+                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_ENTITIES,
+                            connection.getConnectionType() ),
+                    asList( connection.getConnectingEntityId(), connection.getConnectingEntityType() ), timestamp,
+                    timestamp );
 
             // Add connection type to connections set
             addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
-                connection.getConnectionType(), null, timestamp );
+                    key( connection.getConnectingEntityId(), DICTIONARY_CONNECTED_TYPES ),
+                    connection.getConnectionType(), null, timestamp );
 
             // Add connection type to connections set
             addInsertToMutator( batch, ENTITY_DICTIONARIES,
-                key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
-                connection.getConnectionType(), null, timestamp );
+                    key( connection.getConnectedEntityId(), DICTIONARY_CONNECTING_TYPES ),
+                    connection.getConnectionType(), null, timestamp );
         }
 
         // Add indexes for the connected entity's list properties
@@ -1137,15 +1059,15 @@ public class CpRelationManager implements RelationManager {
 
         for ( String dictionaryName : dictionaryNames ) {
             boolean has_dictionary = schema.hasDictionary( connectedEntity.getType(), dictionaryName );
-            boolean dictionary_indexed = schema.isDictionaryIndexedInConnections( 
-                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 );
+                            batchStartIndexUpdate( batch, connectedEntity, dictionaryName, elementValue, timestampUuid,
+                                    has_dictionary, true, disconnect, false );
                     batchUpdateConnectionIndex( indexUpdate, connection );
                 }
             }
@@ -1156,127 +1078,118 @@ 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 {
-        
-        throw new UnsupportedOperationException("Paired connections not supported"); 
+    @Metered( group = "core", name = "RelationManager_createConnection_paired_connection_type" )
+    public ConnectionRef createConnection( String pairedConnectionType, EntityRef pairedEntity, String connectionType,
+                                           EntityRef connectedEntityRef ) throws Exception {
+
+        throw new UnsupportedOperationException( "Paired connections not supported" );
     }
 
 
     @Override
-    @Metered(group = "core", name = "RelationManager_createConnection_connected_entity_ref")
+    @Metered( group = "core", name = "RelationManager_createConnection_connected_entity_ref" )
     public ConnectionRef createConnection( ConnectedEntityRef... connections ) throws Exception {
 
-        throw new UnsupportedOperationException("Paired connections not supported"); 
+        throw new UnsupportedOperationException( "Paired connections not supported" );
     }
 
+
     @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 );
+        ConnectionRef connection = new ConnectionRefImpl( headEntity, connectionType, connectedEntityRef );
 
         return connection;
     }
 
+
     @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"); 
+        throw new UnsupportedOperationException( "Paired connections not supported" );
     }
 
+
     @Override
-    public ConnectionRef connectionRef(ConnectedEntityRef... connections) {
+    public ConnectionRef connectionRef( ConnectedEntityRef... connections ) {
 
-        throw new UnsupportedOperationException("Paired connections not supported"); 
+        throw new UnsupportedOperationException( "Paired connections not supported" );
     }
 
+
     @Override
-    public void deleteConnection(ConnectionRef connectionRef) throws Exception {
-       
+    public void deleteConnection( ConnectionRef connectionRef ) throws Exception {
+
         // 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
         EntityRef connectedEntityRef = connectionRef.getConnectedEntity();  // target
 
         String connectionType = connectionRef.getConnectedEntity().getConnectionType();
-        
-        CollectionScope targetScope = new CollectionScopeImpl( 
-            applicationScope.getApplication(), 
-            applicationScope.getApplication(), 
-            CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ));
 
-        EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager(targetScope);
+        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() );
-        GraphManager gm = managerCache.getGraphManager(applicationScope);
-        gm.deleteEdge(edge).toBlockingObservable().last();
-
-        final EntityIndex ei = managerCache.getEntityIndex( applicationScope )  ;
+        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();
+
+        final EntityIndex ei = managerCache.getEntityIndex( applicationScope );
         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 ));
-        batch.deindex( indexScope , targetEntity );
+        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 );
+        batch.deindex( allTypesIndexScope, targetEntity );
 
         batch.execute();
-
     }
 
 
     @Override
-    public Set<String> getConnectionTypes(UUID connectedEntityId) throws Exception {
-        throw new UnsupportedOperationException("Cannot specify entity by UUID alone."); 
+    public Set<String> getConnectionTypes( UUID connectedEntityId ) throws Exception {
+        throw new UnsupportedOperationException( "Cannot specify entity by UUID alone." );
     }
 
+
     @Override
     public Set<String> getConnectionTypes() throws Exception {
         return getConnectionTypes( false );
     }
 
+
     @Override
-    public Set<String> getConnectionTypes(boolean filterConnection) throws Exception {
-        Set<String> connections = cast( 
-                em.getDictionaryAsSet( headEntity, Schema.DICTIONARY_CONNECTED_TYPES ) );
+    public Set<String> getConnectionTypes( boolean filterConnection ) throws Exception {
+        Set<String> connections = cast( em.getDictionaryAsSet( headEntity, Schema.DICTIONARY_CONNECTED_TYPES ) );
 
         if ( connections == null ) {
             return null;
@@ -1289,47 +1202,45 @@ 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;
 
         Query query = new Query();
-        query.setConnectionType(connectionType);
-        query.setEntityType(connectedEntityType);
+        query.setConnectionType( connectionType );
+        query.setEntityType( connectedEntityType );
 
         if ( connectionType == null ) {
             raw = searchConnectedEntities( query );
-
-        } else {
+        }
+        else {
 
             headEntity = em.validate( headEntity );
 
             String scopeName = null;
             if ( connectedEntityType != null ) {
                 scopeName = CpNamingUtils.getConnectionScopeName( connectedEntityType, connectionType );
-            } else {
+            }
+            else {
                 scopeName = CpNamingUtils.ALL_TYPES;
             }
 
-            IndexScope indexScope = new IndexScopeImpl(
-                cpHeadEntity.getId(), 
-                scopeName);
+            IndexScope indexScope = new IndexScopeImpl( cpHeadEntity.getId(), scopeName );
 
-            final EntityIndex ei = managerCache.getEntityIndex(applicationScope);
+            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 );
 
-            raw = buildResults( query , crs, query.getConnectionType() );
+            raw = buildResults( query, crs, query.getConnectionType() );
         }
 
-        if ( Level.ALL_PROPERTIES.equals(level ) ) {
+        if ( Level.ALL_PROPERTIES.equals( level ) ) {
             List<Entity> entities = new ArrayList<Entity>();
             for ( EntityRef ref : raw.getEntities() ) {
                 Entity entity = em.get( ref );
@@ -1349,29 +1260,28 @@ 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 );
+        String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType( connType );
 
-        Map<EntityRef, Set<String>> containers = 
-            getContainers( count, edgeType, fromEntityType );
+        Map<EntityRef, Set<String>> containers = getContainers( count, edgeType, fromEntityType );
 
-        if ( Level.REFS.equals(level ) ) {
+        if ( Level.REFS.equals( level ) ) {
             List<EntityRef> refList = new ArrayList<EntityRef>( containers.keySet() );
             return Results.fromRefList( refList );
-        } 
+        }
 
-        if ( Level.IDS.equals(level ) ) {
+        if ( Level.IDS.equals( level ) ) {
             // TODO: someday this should return a list of Core Persistence Ids
             List<UUID> idList = new ArrayList<UUID>();
             for ( EntityRef ref : containers.keySet() ) {
@@ -1383,7 +1293,7 @@ public class CpRelationManager implements RelationManager {
         List<Entity> entities = new ArrayList<Entity>();
         for ( EntityRef ref : containers.keySet() ) {
             Entity entity = em.get( ref );
-            logger.debug("   Found connecting entity: " + entity.getProperties());
+            logger.debug( "   Found connecting entity: " + entity.getProperties() );
             entities.add( entity );
         }
         return Results.fromEntities( entities );
@@ -1402,35 +1312,30 @@ 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 );
 
-            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 );
+            CandidateResults crs = ei.search( indexScope, query );
 
-            return buildConnectionResults(query , crs, query.getConnectionType() );
+            return buildConnectionResults( query, crs, 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());
+        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() );
 
         query = adjustQuery( query );
         CandidateResults crs = ei.search( indexScope, query );
 
-        return buildConnectionResults(query , crs, query.getConnectionType() );
+        return buildConnectionResults( query, crs, query.getConnectionType() );
     }
 
 
@@ -1448,47 +1353,44 @@ 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() ) {
 
-            } 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 );
+    

<TRUNCATED>

[38/50] [abbrv] git commit: Fixes raid configuration to mount ephemeral drives in autoscaling instances

Posted by sn...@apache.org.
Fixes raid configuration to mount ephemeral drives in autoscaling instances


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

Branch: refs/heads/two-dot-o-events
Commit: d553e77e403e1d9f15c4bd9afdab888770ed28f0
Parents: af29b4b
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 17:35:22 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 17:35:22 2014 -0600

----------------------------------------------------------------------
 .../src/main/dist/init_instance/create_raid0.sh | 19 +++----
 .../dist/init_instance/create_raid0_2disks.sh   | 54 --------------------
 .../main/dist/init_instance/init_db_server.sh   |  2 +-
 .../main/dist/init_instance/init_es_server.sh   |  2 +-
 .../dist/init_instance/init_graphite_server.sh  |  4 +-
 .../main/dist/init_instance/init_rest_server.sh |  2 +-
 .../dist/init_instance/install_elasticsearch.sh |  3 ++
 .../main/groovy/configure_elasticsearch.groovy  |  5 +-
 stack/awscluster/ugcluster-cf.json              | 28 ++++++++--
 9 files changed, 46 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/create_raid0.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/create_raid0.sh b/stack/awscluster/src/main/dist/init_instance/create_raid0.sh
index 296cb9f..43d9f37 100644
--- a/stack/awscluster/src/main/dist/init_instance/create_raid0.sh
+++ b/stack/awscluster/src/main/dist/init_instance/create_raid0.sh
@@ -18,6 +18,12 @@
 #  directory of this distribution.
 #
 
+
+
+# WARNING: this does not work yet (and is not used by any other script)
+
+
+
 # install postfix first and prevent it from prompting the user
 debconf-set-selections <<< "postfix postfix/mailname string your.hostname.com"
 debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
@@ -30,15 +36,10 @@ apt-get -y --force-yes install mdadm
 # unmount /dev/xvdb so we can use it in our setup
 umount /mnt
 
-# create & format partition on each of our four disks
-(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdb
-(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdc
-(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdd
-(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvde
 
+#We only support 2 ephemeral disks.  Most c3.x instances only have 2 disks and they're our target
 # create striped RAID0 device with our four disks
-mdadm --create --verbose /dev/md0 --level=stripe \
---raid-devices=4 /dev/xvdb1 /dev/xvdc1 /dev/xvdd1 /dev/xvde1
+yes | mdadm --create --verbose /dev/md0 --level=stripe --raid-devices=2 -c 256  /dev/xvdb /dev/xvdc
 
 # save config
 mdadm --detail --scan | tee /etc/mdadm/mdadm.conf
@@ -46,5 +47,5 @@ mdadm --detail --scan | tee /etc/mdadm/mdadm.conf
 # create, mount and save disk to stab
 mkfs.ext4 -b 4096 -E stride=32,stripe-width=128 -L Stripe /dev/md0
 mkdir -p /mnt
-echo "/dev/md0  /mnt  auto  defaults,nobootwait,noatime 0 2" | tee /etc/fstab
-mount /mnt 
+echo "/dev/md0  /mnt/  ext4    defaults,noatime,nofail 0 0" >> /etc/fstab
+mount /dev/md0 /mnt

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/create_raid0_2disks.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/create_raid0_2disks.sh b/stack/awscluster/src/main/dist/init_instance/create_raid0_2disks.sh
deleted file mode 100644
index 25733d3..0000000
--- a/stack/awscluster/src/main/dist/init_instance/create_raid0_2disks.sh
+++ /dev/null
@@ -1,54 +0,0 @@
-#!/bin/bash
-
-# 
-#  Licensed to the Apache Software Foundation (ASF) under one or more
-#   contributor license agreements.  The ASF licenses this file to You
-#  under the Apache License, Version 2.0 (the "License"); you may not
-#  use this file except in compliance with the License.
-#  You may obtain a copy of the License at
-# 
-#      http://www.apache.org/licenses/LICENSE-2.0
-# 
-#  Unless required by applicable law or agreed to in writing, software
-#  distributed under the License is distributed on an "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-#  See the License for the specific language governing permissions and
-#  limitations under the License.  For additional information regarding
-#  copyright in this work, please see the NOTICE file in the top level
-#  directory of this distribution.
-#
-
-
-
-# WARNING: this does not work yet (and is not used by any other script)
-
-
-
-# install postfix first and prevent it from prompting the user
-debconf-set-selections <<< "postfix postfix/mailname string your.hostname.com"
-debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
-apt-get install -y postfix
-
-# install mdadm RAID controller
-apt-get -y --force-yes install mdadm
-
-# m1.xlarge has four 414GB disks, but only /dev/xvdb is mounted
-# unmount /dev/xvdb so we can use it in our setup
-umount /mnt
-
-# create & format partition on each of our four disks
-(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdb
-(echo o; echo n; echo p; echo 1; echo ; echo; echo w) | fdisk /dev/xvdc
-
-# create striped RAID0 device with our four disks
-mdadm --create --verbose /dev/md0 --level=stripe \
---raid-devices=4 /dev/xvdb1 /dev/xvdc1 /dev/xvdd1 /dev/xvde1
-
-# save config
-mdadm --detail --scan | tee /etc/mdadm/mdadm.conf
-
-# create, mount and save disk to stab
-mkfs.ext4 -b 4096 -E stride=32,stripe-width=128 -L Stripe /dev/md0
-mkdir -p /mnt
-echo "/dev/md0  /mnt  auto  defaults,nobootwait,noatime 0 2" | tee /etc/fstab
-mount /mnt 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
index a46e7f9..42a7ebf 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_db_server.sh
@@ -54,7 +54,7 @@ ln -s /home/ubuntu/.groovy /root/.groovy
 
 # tag last so we can see in the console so that we know what's running
 cd /usr/share/usergrid/scripts
-groovy tag_instance.groovy BUILD-IN-PROGRESS
+groovy tag_instance.groovy -BUILD-IN-PROGRESS
 
 cd /usr/share/usergrid/init_instance
 ./install_oraclejdk.sh 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/init_es_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_es_server.sh b/stack/awscluster/src/main/dist/init_instance/init_es_server.sh
index fbe41ab..4b6a7ec 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_es_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_es_server.sh
@@ -53,7 +53,7 @@ ln -s /home/ubuntu/.groovy /root/.groovy
 
 # tag last so we can see in the console so that we know what's running
 cd /usr/share/usergrid/scripts
-groovy tag_instance.groovy BUILD-IN-PROGRESS
+groovy tag_instance.groovy -BUILD-IN-PROGRESS
 
 cd /usr/share/usergrid/init_instance
 ./install_oraclejdk.sh 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh b/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
index 6b1c81a..64d82bc 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_graphite_server.sh
@@ -31,8 +31,6 @@ dpkg-reconfigure -f noninteractive tzdata
 . /etc/profile.d/aws-credentials.sh
 . /etc/profile.d/usergrid-env.sh
 
-cd /usr/share/usergrid/init_instance
-./create_raid0.sh
 
 # Install the easy stuff
 PKGS="ntp unzip groovy tomcat7 curl"
@@ -53,7 +51,7 @@ ln -s /home/ubuntu/.groovy /root/.groovy
 
 # tag last so we can see in the console so that we know what's running
 cd /usr/share/usergrid/scripts
-groovy tag_instance.groovy BUILD-IN-PROGRESS
+groovy tag_instance.groovy -BUILD-IN-PROGRESS
 
 cd /usr/share/usergrid/init_instance
 ./install_oraclejdk.sh

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
index dde1a00..6df1f59 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
@@ -43,7 +43,7 @@ ln -s /home/ubuntu/.groovy /root/.groovy
 
 # tag last so we can see in the console so that we know what's running
 cd /usr/share/usergrid/scripts
-groovy tag_instance.groovy BUILD-IN-PROGRESS
+groovy tag_instance.groovy -BUILD-IN-PROGRESS
 
 
 # Build environment for Groovy scripts

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
index a3c0b64..06ca60b 100644
--- a/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
+++ b/stack/awscluster/src/main/dist/init_instance/install_elasticsearch.sh
@@ -38,6 +38,9 @@ chown elasticsearch /mnt/log/elasticsearch
 # Configure ElasticSearch
 cd /usr/share/usergrid/scripts
 
+echo "vm.swappiness = 0" >> /etc/sysctl.conf
+sysctl -p
+
 # No need to do this, elasticsearch nodes are also cassandra nodes
 groovy registry_register.groovy elasticsearch
 groovy wait_for_instances.groovy elasticsearch ${ES_NUM_SERVERS}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy b/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy
index 549a23b..845f9d1 100644
--- a/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy
+++ b/stack/awscluster/src/main/groovy/configure_elasticsearch.groovy
@@ -32,6 +32,9 @@ import com.amazonaws.services.simpledb.model.*
 String hostName  = (String)System.getenv().get("PUBLIC_HOSTNAME")
 def clusterName  = (String)System.getenv().get("ES_CLUSTER_NAME")
 
+int esNumServers = ((String)System.getenv().get("ES_NUM_SERVERS")).toInteger()
+int quorum = esNumServers/2+1;
+
 NodeRegistry registry = new NodeRegistry();
 
 // build seed list by listing all Elasticsearch nodes found in SimpleDB domain with our stackName
@@ -45,7 +48,7 @@ for (hostname in selectResult) {
 
 def elasticSearchConfig = """
 cluster.name: ${clusterName}
-discovery.zen.minimum_master_nodes: 4
+discovery.zen.minimum_master_nodes: ${quorum}
 discovery.zen.ping.multicast.enabled: false
 discovery.zen.ping.unicast.hosts: [${esnodes}]
 node:

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d553e77e/stack/awscluster/ugcluster-cf.json
----------------------------------------------------------------------
diff --git a/stack/awscluster/ugcluster-cf.json b/stack/awscluster/ugcluster-cf.json
index b4d5a0b..dea9694 100644
--- a/stack/awscluster/ugcluster-cf.json
+++ b/stack/awscluster/ugcluster-cf.json
@@ -505,7 +505,7 @@
                         "export TYPE=cass\n",
                         "export STACK_NAME=", { "Ref":"AWS::StackName" }, "\n", "\n",
                         "export PUBLIC_HOSTNAME=`(curl -s http://169.254.169.254/latest/meta-data/public-hostname)`\n",
-                        "export INTERNAL_HOSTNAME=`(curl http://169.254.169.254/latest/meta-data/local-ipv4)`\n", 
+                        "export INTERNAL_HOSTNAME=`(curl http://169.254.169.254/latest/meta-data/local-ipv4)`\n",
                         "\n",
                         "export EC2_INSTANCE_ID=`ec2metadata --instance-id`\n",
                         "export EC2_REGION=", { "Ref":"AWS::Region" },
@@ -595,7 +595,18 @@
                     {
                         "Ref": "CassSecurityGroup"
                     }
-                ]
+                ],
+
+                 "BlockDeviceMappings": [
+                     {
+                         "DeviceName": "/dev/sdb",
+                         "VirtualName": "ephemeral0"
+                     },
+                     {
+                         "DeviceName": "/dev/sdc",
+                         "VirtualName": "ephemeral1"
+                      }
+                    ]
             }
       },
         "CassAutoScalingGroup": {
@@ -745,7 +756,18 @@
                     {
                         "Ref": "ESSecurityGroup"
                     }
-                ]
+                ],
+
+                 "BlockDeviceMappings": [
+                     {
+                         "DeviceName": "/dev/sdb",
+                         "VirtualName": "ephemeral0"
+                     },
+                     {
+                         "DeviceName": "/dev/sdc",
+                         "VirtualName": "ephemeral1"
+                      }
+                    ]
             }
       },
         "ESAutoScalingGroup": {


[45/50] [abbrv] git commit: Fixes issue with AWS props location

Posted by sn...@apache.org.
Fixes issue with AWS props location


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

Branch: refs/heads/two-dot-o-events
Commit: 017720278d987353d502a69f3fcf13c0f7fb7bb5
Parents: 3914d68
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 18:16:24 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 18:16:24 2014 -0600

----------------------------------------------------------------------
 .../awscluster/src/main/dist/init_instance/init_rest_server.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/01772027/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
index b370f34..28fbc48 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
@@ -114,6 +114,11 @@ export TOMCAT_CONNECTIONS=10000
 sed -i.bak "s/Xmx128m/Xmx${TOMCAT_RAM} -Xms${TOMCAT_RAM} -Dlog4j\.configuration=file:\/usr\/share\/usergrid\/lib\/log4j\.properties/g" /etc/default/tomcat7
 sed -i.bak "s/<Connector/<Connector maxThreads=\"${TOMCAT_THREADS}\" acceptCount=\"${TOMCAT_THREADS}\" maxConnections=\"${TOMCAT_CONNECTIONS}\"/g" /var/lib/tomcat7/conf/server.xml
 
+
+#Append our java opts for secret key
+echo "JAVA_OPTS=\"\${JAVA_OPTS} -DAWS_SECRET_KEY=${AWS_SECRET_KEY} -DAWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY}\"" >> /etc/default/tomcat7
+
+
 # set file limits
 sed -i.bak "s/# \/etc\/init\.d\/tomcat7 -- startup script for the Tomcat 6 servlet engine/ulimit -n ${NOFILE}/" /etc/init.d/tomcat7
 sed -i.bak "s/@student/a *\t\thard\tnofile\t\t${NOFILE}\n*\t\tsoft\tnofile\t\t${NOFILE}" /etc/security/limits.conf
@@ -148,7 +153,6 @@ mkdir -p /usr/share/tomcat7/lib
 groovy configure_usergrid.groovy > /usr/share/tomcat7/lib/usergrid-deployment.properties 
 groovy configure_portal_new.groovy >> /var/lib/tomcat7/webapps/portal/config.js
 
-sudo sed -i '98i export CATALINA_OPTS=\"-DAWS_SECRET_KEY=${AWS_SECRET_KEY} -DAWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY} ${CATALINA_OPTS}\"' /usr/share/tomcat7/bin/catalina.sh
 
 
 #Install postfix so that we can send mail


[13/50] [abbrv] git commit: Moved create index down to cache init. Not ideal, but lowest least called point in the code until setup is refactored.

Posted by sn...@apache.org.
Moved create index down to cache init.  Not ideal, but lowest least called point in the code until setup is refactored.


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

Branch: refs/heads/two-dot-o-events
Commit: f24f3ea7cc70efa18de83308d4eb9011548517e4
Parents: 163fa9a
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 13:40:32 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 13:40:32 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/corepersistence/CpEntityManagerFactory.java   | 3 +--
 stack/core/src/test/java/org/apache/usergrid/CoreApplication.java | 2 --
 2 files changed, 1 insertion(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f24f3ea7/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 8ab0b7f..2514e20 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
@@ -146,7 +146,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
                 Map sysAppProps = new HashMap<String, Object>();
                 sysAppProps.put( PROPERTY_NAME, "systemapp");
                 em.create( SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps );
-                em.createIndex();
                 em.getApplication();
                 em.refreshIndex();
             }
@@ -287,7 +286,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager appEm = getEntityManager( applicationId );
 
         //create our ES index since we're initializing this application
-        appEm.createIndex();
+//  TODO T.N, pushed this down into the cache load      appEm.createIndex();
 
         appEm.create( applicationId, TYPE_APPLICATION, properties );
         appEm.resetRoles();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f24f3ea7/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index 51e825b..fd8ca9b 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -150,9 +150,7 @@ public class CoreApplication implements Application, TestRule {
         id = setup.createApplication( orgName, appName );
         assertNotNull( id );
 
-        setup.getEmf().refreshIndex();
         em = setup.getEmf().getEntityManager( id );
-        em.createIndex();
         assertNotNull( em );
 
         LOG.info( "Created new application {} in organization {}", appName, orgName );


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: f7ab17460e4915a5593f635e0d2939deac3ef868
Parents: e41021d 68bd94f
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 13:39:41 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 13:39:41 2014 -0600

----------------------------------------------------------------------
 stack/core/pom.xml                              |  21 -
 .../corepersistence/CpEntityManager.java        |   2 +-
 .../usergrid/corepersistence/CpWalker.java      |   4 -
 .../PerformanceEntityRebuildIndexTest.java      |  17 +-
 stack/pom.xml                                   |   4 +-
 stack/rest/src/main/webapp/WEB-INF/web.xml      |   2 +-
 .../usergrid/rest/management/AccessTokenIT.java | 381 ++++++++++---------
 7 files changed, 218 insertions(+), 213 deletions(-)
----------------------------------------------------------------------



[16/50] [abbrv] git commit: Explicitly catch IndexMissingException

Posted by sn...@apache.org.
Explicitly catch IndexMissingException


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

Branch: refs/heads/two-dot-o-events
Commit: f807627b954b1554b0004c9e18555a867186657e
Parents: e5efa67
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 15:38:04 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 15:38:04 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/f807627b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 6ed9b86..9ea14a1 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -38,6 +38,7 @@ import org.elasticsearch.common.xcontent.XContentFactory;
 import org.elasticsearch.index.query.FilterBuilder;
 import org.elasticsearch.index.query.QueryBuilder;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
+import org.elasticsearch.indices.IndexMissingException;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
 import org.elasticsearch.search.sort.FieldSortBuilder;
@@ -278,7 +279,7 @@ public class EsEntityIndexImpl implements EntityIndex {
                     client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
                     break;
 
-                }catch(Exception e){
+                }catch(IndexMissingException e){
                    log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
                 }
 


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

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

Conflicts:
	stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
	stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java


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

Branch: refs/heads/two-dot-o-events
Commit: 6f040c746c96b401743a15ea95a0805eac38ac6e
Parents: bdcf805 2cdcf62
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Oct 17 15:11:41 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Oct 17 15:11:41 2014 -0400

----------------------------------------------------------------------
 stack/awscluster/pom.xml                        |    2 +-
 stack/awscluster/src/main/cql/create_locks.cql  |   24 +-
 .../awscluster/src/main/cql/create_usergrid.cql |   80 +-
 .../main/cql/create_usergrid_applications.cql   |  411 +----
 .../main/dist/init_instance/create_keyspaces.sh |   28 +-
 .../src/main/dist/init_instance/init_cass.sh    |   70 -
 .../main/dist/init_instance/init_db_server.sh   |   11 +-
 .../main/dist/init_instance/init_es_server.sh   |   67 +
 .../dist/init_instance/init_graphite_server.sh  |    6 +
 .../main/dist/init_instance/init_rest_server.sh |   10 +
 .../dist/init_instance/install_cassandra.sh     |    2 +-
 .../dist/init_instance/install_elasticsearch.sh |   19 +-
 .../init_instance/install_opscenter_agent.sh    |    1 +
 .../main/dist/init_instance/install_yourkit.sh  |    6 +-
 .../main/groovy/configure_elasticsearch.groovy  |   23 +-
 .../src/main/groovy/configure_usergrid.groovy   |    9 +-
 .../src/main/groovy/tag_instance.groovy         |   10 +-
 stack/awscluster/ugcluster-cf.json              |  317 +++-
 .../corepersistence/CpEntityManager.java        |  107 +-
 .../corepersistence/CpEntityManagerFactory.java |   40 +-
 .../corepersistence/CpRelationManager.java      | 1427 ++++++++----------
 .../usergrid/corepersistence/CpVisitor.java     |   11 +-
 .../usergrid/corepersistence/CpWalker.java      |  145 +-
 .../usergrid/persistence/EntityManager.java     |    2 +-
 .../persistence/EntityManagerFactory.java       |    8 +-
 .../org/apache/usergrid/CoreApplication.java    |    1 -
 .../PerformanceEntityRebuildIndexTest.java      |   26 +-
 stack/corepersistence/common/pom.xml            |   13 +-
 stack/corepersistence/pom.xml                   |    1 +
 .../index/impl/EsEntityIndexImpl.java           |  146 +-
 .../persistence/index/impl/EsProvider.java      |   21 +-
 stack/corepersistence/queue/pom.xml             |    8 +-
 stack/pom.xml                                   |   25 +-
 .../apache/usergrid/rest/SystemResource.java    |   50 +-
 .../services/devices/DevicesService.java        |   28 +-
 .../services/users/devices/DevicesService.java  |    8 +-
 .../AbstractServiceNotificationIT.java          |    4 -
 .../apns/NotificationsServiceIT.java            |    5 +-
 38 files changed, 1525 insertions(+), 1647 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6f040c74/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6f040c74/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --cc stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index a759f48,ed3fd61..619fb89
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@@ -66,9 -66,10 +66,9 @@@ public class PerformanceEntityRebuildIn
      private static final MetricRegistry registry = new MetricRegistry();
      private Slf4jReporter reporter;
  
-     private static final long RuntimeMs = 10000;  
+     private static final long RUNTIME = TimeUnit.SECONDS.toMillis( 5 );
  
 -    private static final long writeDelayMs = 100;
 -    //private static final long readDelayMs = 7;
 +    private static final long writeDelayMs = 10;
  
      @Rule
      public Application app = new CoreApplication( setup );
@@@ -189,15 -190,12 +189,13 @@@
          
          EntityManagerFactory.ProgressObserver po = new EntityManagerFactory.ProgressObserver() {
              int counter = 0;
 +
              @Override
-             public void onProgress( EntityRef s, EntityRef t, String etype ) {
-                 meter.mark();
- 
- //                logger.debug("Indexing from {}:{} to {}:{} edgeType {}", new Object[] {
- //                    s.getType(), s.getUuid(), t.getType(), t.getUuid(), etype });
+                public void onProgress( final EntityRef entity ) {
  
-                 if ( !logger.isDebugEnabled() && counter % 10 == 0 ) {
+                 meter.mark();
+                 logger.debug("Indexing {}:{}", entity.getType(), entity.getUuid());
+                 if ( !logger.isDebugEnabled() && counter % 100 == 0 ) {
                      logger.info("Reindexed {} entities", counter );
                  }
                  counter++;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/6f040c74/stack/pom.xml
----------------------------------------------------------------------


[10/50] [abbrv] git commit: Fixes bug with lifecycle manager cache lazy loading

Posted by sn...@apache.org.
Fixes bug with lifecycle manager cache lazy loading


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

Branch: refs/heads/two-dot-o-events
Commit: 9da529b98dfa7c7996bdcfe2623732cb823d3907
Parents: ce2db8a
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 09:50:15 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 09:50:15 2014 -0600

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpEntityManagerFactory.java       | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9da529b9/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 4d296ba..2abe83f 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
@@ -641,15 +641,15 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     private List<EntityIndex> getManagementIndexes() {
 
         return Arrays.asList(
-                managerCache.getEntityIndex( new ApplicationScopeImpl( 
+                getManagerCache().getEntityIndex( new ApplicationScopeImpl(
                         new SimpleId( SYSTEM_APP_ID, "application" ) ) ),
 
                 // default app
-                managerCache.getEntityIndex( new ApplicationScopeImpl( 
+               getManagerCache().getEntityIndex( new ApplicationScopeImpl(
                         new SimpleId( getManagementAppId(), "application" ) ) ),
 
                 // management app
-                managerCache.getEntityIndex( new ApplicationScopeImpl( 
+               getManagerCache().getEntityIndex( new ApplicationScopeImpl(
                         new SimpleId( getDefaultAppId(), "application" ) ) ) );
     }
 


[23/50] [abbrv] git commit: Fixes migration bug

Posted by sn...@apache.org.
Fixes migration bug


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

Branch: refs/heads/two-dot-o-events
Commit: 8d9d4dcf043240a9c53902b27e3daa23cd9987de
Parents: bd00ee0
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 23:24:50 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 23:24:50 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java |  8 +++++++
 .../usergrid/corepersistence/CpWalker.java      | 15 ++++++-------
 .../PerformanceEntityRebuildIndexTest.java      |  2 +-
 .../persistence/index/impl/EsProvider.java      | 22 +++++++++++++-------
 .../apache/usergrid/rest/SystemResource.java    |  7 ++-----
 5 files changed, 33 insertions(+), 21 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8d9d4dcf/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 e013957..bc45769 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
@@ -95,9 +95,15 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     public static final UUID SYSTEM_APP_ID =
             UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
 
+    /**
+     * 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?
+     */
     public static final  UUID DEFAULT_APPLICATION_ID =
             UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
 
@@ -679,6 +685,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     @Override
     public void rebuildInternalIndexes( ProgressObserver po ) throws Exception {
         rebuildApplicationIndexes(SYSTEM_APP_ID, po);
+        rebuildApplicationIndexes( MANAGEMENT_APPLICATION_ID, po );
+        rebuildApplicationIndexes( DEFAULT_APPLICATION_ID, po );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8d9d4dcf/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index 908e6bc..636cc91 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -67,33 +67,32 @@ public class CpWalker {
     }
 
 
-    private void doWalkCollections( final CpEntityManager em, final Id start, final CpVisitor visitor ) {
-
-        final Id fromEntityId = new SimpleId( start.getUuid(), start.getType() );
+    private void doWalkCollections( final CpEntityManager em, final Id applicationId, final CpVisitor visitor ) {
 
         final ApplicationScope applicationScope = em.getApplicationScope();
 
         final GraphManager gm = em.getManagerCache().getGraphManager( applicationScope );
 
         logger.debug( "Loading edges types from {}:{}\n   scope {}:{}", new Object[] {
-                        start.getType(), start.getUuid(), applicationScope.getApplication().getType(),
+                applicationId.getType(), applicationId.getUuid(), applicationScope.getApplication().getType(),
                         applicationScope.getApplication().getUuid()
                 } );
 
         //only search edge types that start with collections
+
         Observable<String> edgeTypes = gm.getEdgeTypesFromSource(
-                new SimpleSearchEdgeType( fromEntityId, CpNamingUtils.EDGE_COLL_SUFFIX, null ) );
+                       new SimpleSearchEdgeType( applicationId, CpNamingUtils.EDGE_COLL_SUFFIX+"users", null ) );
 
         edgeTypes.flatMap( new Func1<String, Observable<Edge>>() {
             @Override
             public Observable<Edge> call( final String edgeType ) {
 
                 logger.debug( "Loading edges of edgeType {} from {}:{}\n   scope {}:{}", new Object[] {
-                        edgeType, start.getType(), start.getUuid(), applicationScope.getApplication().getType(),
+                        edgeType, applicationId.getType(), applicationId.getUuid(), applicationScope.getApplication().getType(),
                         applicationScope.getApplication().getUuid()
                 } );
 
-                return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( fromEntityId, edgeType, Long.MAX_VALUE,
+                return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( applicationId, edgeType, Long.MAX_VALUE,
                                 SearchByEdgeType.Order.DESCENDING, null ) );
             }
         } ).doOnNext( new Action1<Edge>() {
@@ -101,6 +100,8 @@ public class CpWalker {
             @Override
             public void call( Edge edge ) {
 
+                logger.info( "Re-indexing edge {}", edge );
+
                 EntityRef targetNodeEntityRef =
                         new SimpleEntityRef( edge.getTargetNode().getType(), edge.getTargetNode().getUuid() );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8d9d4dcf/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index 2ef65ef..ed3fd61 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -194,7 +194,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
                public void onProgress( final EntityRef entity ) {
 
                 meter.mark();
-                logger.debug("Indexing from {}:{}", entity.getType(), entity.getUuid());
+                logger.debug("Indexing {}:{}", entity.getType(), entity.getUuid());
                 if ( !logger.isDebugEnabled() && counter % 100 == 0 ) {
                     logger.info("Reindexed {} entities", counter );
                 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8d9d4dcf/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
index aac9ff5..9b37952 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsProvider.java
@@ -31,8 +31,10 @@ import org.apache.commons.lang.RandomStringUtils;
 import org.apache.usergrid.persistence.core.util.AvailablePortFinder;
 import org.apache.usergrid.persistence.index.IndexFig;
 import org.elasticsearch.client.Client;
+import org.elasticsearch.client.transport.TransportClient;
 import org.elasticsearch.common.settings.ImmutableSettings;
 import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.common.transport.InetSocketTransportAddress;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeBuilder;
 import org.slf4j.Logger;
@@ -152,24 +154,28 @@ public class EsProvider {
 
                 Settings settings = ImmutableSettings.settingsBuilder()
 
-                    .put("cluster.name", fig.getClusterName())
+                    .put( "cluster.name", fig.getClusterName() )
 
                     // this assumes that we're using zen for host discovery.  Putting an 
                     // explicit set of bootstrap hosts ensures we connect to a valid cluster.
-                    .put("discovery.zen.ping.unicast.hosts", allHosts)
-                    .put("discovery.zen.ping.multicast.enabled","false")
+                    .put( "discovery.zen.ping.unicast.hosts", allHosts )
+                    .put( "discovery.zen.ping.multicast.enabled", "false" )
                     .put("http.enabled", false) 
 
-                    .put("client.transport.ping_timeout", 2000) // milliseconds
-                    .put("client.transport.nodes_sampler_interval", 100)
-                    .put("network.tcp.blocking", true)
-                    .put("node.client", true)
-                    .put("node.name",  nodeName )
+                    .put( "client.transport.ping_timeout", 2000 ) // milliseconds
+                    .put( "client.transport.nodes_sampler_interval", 100 )
+                    .put( "network.tcp.blocking", true )
+                    .put( "node.client", true )
+                    .put( "node.name", nodeName )
 
                     .build();
 
                 log.debug("Creating ElasticSearch client with settings: " +  settings.getAsMap());
 
+                //use this client when connecting via socket only, such as ssh tunnel or other firewall issues
+//                newClient  = new TransportClient(settings).addTransportAddress( new InetSocketTransportAddress("localhost", 9300) );
+
+                //use this client for quick connectivity
                 Node node = NodeBuilder.nodeBuilder().settings(settings)
                     .client(true).node();
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8d9d4dcf/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
index 28a7120..d068846 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/SystemResource.java
@@ -128,7 +128,7 @@ public class SystemResource extends AbstractContextResource {
 
             @Override
             public void onProgress( final EntityRef entity ) {
-                logger.info( "Indexing from {}:{} ", entity.getType(), entity.getUuid() );
+                logger.info( "Indexing entity {}:{} ", entity.getType(), entity.getUuid() );
             }
 
 
@@ -146,9 +146,6 @@ public class SystemResource extends AbstractContextResource {
                 logger.info( "Rebuilding all indexes" );
 
                 try {
-                    emf.rebuildInternalIndexes( po );
-                    emf.refreshIndex();
-
                     emf.rebuildAllIndexes( po );
                 }
                 catch ( Exception e ) {
@@ -252,7 +249,7 @@ public class SystemResource extends AbstractContextResource {
 
             @Override
             public void onProgress( final EntityRef entity ) {
-                logger.info( "Indexing from {}:{} to {}:{} edgeType {}", entity.getType(), entity.getUuid());
+                logger.info( "Indexing entity {}:{}", entity.getType(), entity.getUuid());
             }
 
 


[17/50] [abbrv] Fixed index refresh issue.

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
index d491d3d..908e6bc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpWalker.java
@@ -80,6 +80,7 @@ public class CpWalker {
                         applicationScope.getApplication().getUuid()
                 } );
 
+        //only search edge types that start with collections
         Observable<String> edgeTypes = gm.getEdgeTypesFromSource(
                 new SimpleSearchEdgeType( fromEntityId, CpNamingUtils.EDGE_COLL_SUFFIX, null ) );
 
@@ -100,16 +101,16 @@ public class CpWalker {
             @Override
             public void call( Edge edge ) {
 
-                EntityRef sourceEntityRef =
-                        new SimpleEntityRef( edge.getSourceNode().getType(), edge.getSourceNode().getUuid() );
+                EntityRef targetNodeEntityRef =
+                        new SimpleEntityRef( edge.getTargetNode().getType(), edge.getTargetNode().getUuid() );
 
                 Entity entity;
                 try {
-                    entity = em.get( sourceEntityRef );
+                    entity = em.get( targetNodeEntityRef );
                 }
                 catch ( Exception ex ) {
-                    logger.error( "Error getting sourceEntity {}:{}, continuing", sourceEntityRef.getType(),
-                            sourceEntityRef.getUuid() );
+                    logger.error( "Error getting sourceEntity {}:{}, continuing", targetNodeEntityRef.getType(),
+                            targetNodeEntityRef.getUuid() );
                     return;
                 }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index d2f7fef..2ef65ef 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -213,6 +213,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
 //            setup.getEmf().refreshIndex();
             setup.getEmf().rebuildAllIndexes( po );
 
+            reporter.report();
             registry.remove( meterName );
             logger.info("Rebuilt index");
 
@@ -236,7 +237,6 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
 
         Id appId = new SimpleId( appUuid, "application");
         ApplicationScope scope = new ApplicationScopeImpl( appId );
-        IndexScope is = new IndexScopeImpl( appId, "application");
         EntityIndex ei = eif.createEntityIndex(scope);
         EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;
 
@@ -247,6 +247,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
     private int readData( String collectionName, int expected ) throws Exception {
 
         EntityManager em = app.getEntityManager();
+        em.refreshIndex();
 
         Query q = Query.fromQL("select * where key1=1000");
         q.setLimit(40);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c31c553f/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 9ea14a1..821f7b9 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -116,7 +116,7 @@ public class EsEntityIndexImpl implements EntityIndex {
 
             AdminClient admin = client.admin();
             CreateIndexResponse cir = admin.indices().prepareCreate( indexName ).execute().actionGet();
-            log.debug( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged() );
+            log.info( "Created new Index Name [{}] ACK=[{}]", indexName, cir.isAcknowledged() );
 
             RefreshResponse response;
 
@@ -128,11 +128,11 @@ public class EsEntityIndexImpl implements EntityIndex {
             /**
              * Immediately refresh to ensure the entire cluster is ready to receive this write.  Occasionally we see
              * errors.  See this post.
-             * http://elasticsearch-users.115913.n3.nabble.com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
+             * http://elasticsearch-users.115913.n3.nabble
+             * .com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
              *
              */
             refresh();
-
         }
         catch ( IndexAlreadyExistsException expected ) {
             // this is expected to happen if index already exists, it's a no-op and swallow
@@ -272,25 +272,33 @@ public class EsEntityIndexImpl implements EntityIndex {
 
     public void refresh() {
 
-            //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
-            //before we can write.
-            for(int i = 0 ; i < MAX_WAITS; i++ ){
-                try{
-                    client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
-                    break;
 
-                }catch(IndexMissingException e){
-                   log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
-                }
+        log.info( "Refreshing Created new Index Name [{}]", indexName );
 
-                try {
-                    Thread.sleep( WAIT_TIME );
-                }
-                catch ( InterruptedException e ) {
-                    //swallow it
-                }
+        //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
+        //before we can write.
+        for ( int i = 0; i < MAX_WAITS; i++ ) {
+            try {
+                client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+                return;
+            }
+            catch ( IndexMissingException e ) {
+                log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
             }
 
+            try {
+                Thread.sleep( WAIT_TIME );
+            }
+            catch ( InterruptedException e ) {
+                //swallow it
+            }
+        }
+
+        /**
+         * Try the refresh one last time if we get here
+         */
+        client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+
         log.debug( "Refreshed index: " + indexName );
     }
 


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: 96f48e4da9d91b2de2afd57c400926e0cf5414c3
Parents: 5b1c06a dbdba30
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Oct 16 09:13:50 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Oct 16 09:13:50 2014 -0600

----------------------------------------------------------------------
 .../main/java/org/apache/usergrid/corepersistence/CpSetup.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------



[04/50] [abbrv] git commit: Merge branch 'two-dot-o' into cloudformation-update

Posted by sn...@apache.org.
Merge branch 'two-dot-o' into cloudformation-update


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

Branch: refs/heads/two-dot-o-events
Commit: c920eca03621a7cf94d75d105be1e46418cd6464
Parents: c9ac3e2 dbdba30
Author: Todd Nine <to...@apache.org>
Authored: Wed Oct 15 22:30:48 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Wed Oct 15 22:30:48 2014 -0600

----------------------------------------------------------------------
 .../main/java/org/apache/usergrid/corepersistence/CpSetup.java    | 3 +++
 1 file changed, 3 insertions(+)
----------------------------------------------------------------------



[09/50] [abbrv] git commit: Fixed incorrect strategy

Posted by sn...@apache.org.
Fixed incorrect strategy


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

Branch: refs/heads/two-dot-o-events
Commit: 0ddecd1340e36e212ce8c89ab2990bc5dc163bd9
Parents: c920eca
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 09:44:57 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 09:44:57 2014 -0600

----------------------------------------------------------------------
 stack/awscluster/src/main/groovy/configure_usergrid.groovy | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0ddecd13/stack/awscluster/src/main/groovy/configure_usergrid.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_usergrid.groovy b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
index 35a0262..fc19b74 100644
--- a/stack/awscluster/src/main/groovy/configure_usergrid.groovy
+++ b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
@@ -83,7 +83,7 @@ def usergridConfig = """
 
 cassandra.url=${cassandras}
 cassandra.cluster=${clusterName}
-cassandra.keyspace.strategy=org.apache.cassandra.locator.SimpleStrategy
+cassandra.keyspace.strategy=org.apache.cassandra.locator.NetworkTopologyStrategy
 cassandra.keyspace.replication=${ec2Region}:${replFactor}
 
 cassandra.timeout=5000


[35/50] [abbrv] git commit: Fix syntax for installation and configure to use smtp

Posted by sn...@apache.org.
Fix syntax for installation and configure to use smtp


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

Branch: refs/heads/two-dot-o-events
Commit: af29b4bef1a48eafb08395f0815791c9ce125f03
Parents: f7ab174
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 14:47:35 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 14:47:35 2014 -0600

----------------------------------------------------------------------
 .../src/main/dist/init_instance/init_rest_server.sh    |  7 +++++++
 .../src/main/groovy/configure_usergrid.groovy          | 13 +++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/af29b4be/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
index 75edc16..dde1a00 100644
--- a/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
+++ b/stack/awscluster/src/main/dist/init_instance/init_rest_server.sh
@@ -147,6 +147,13 @@ groovy configure_portal_new.groovy >> /var/lib/tomcat7/webapps/portal/config.js
 
 sudo sed -i '98i export CATALINA_OPTS=\"-DAWS_SECRET_KEY=${AWS_SECRET_KEY} -DAWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY} ${CATALINA_OPTS}\"' /usr/share/tomcat7/bin/catalina.sh
 
+
+#Install postfix so that we can send mail
+echo "postfix postfix/mailname string your.hostname.com" | debconf-set-selections
+echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
+apt-get install -y postfix
+
+
 # Go
 sh /etc/init.d/tomcat7 start
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/af29b4be/stack/awscluster/src/main/groovy/configure_usergrid.groovy
----------------------------------------------------------------------
diff --git a/stack/awscluster/src/main/groovy/configure_usergrid.groovy b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
index fc19b74..62452e3 100644
--- a/stack/awscluster/src/main/groovy/configure_usergrid.groovy
+++ b/stack/awscluster/src/main/groovy/configure_usergrid.groovy
@@ -99,17 +99,14 @@ elasticsearch.port=9300
 ######################################################
 # Custom mail transport 
 
-mail.transport.protocol=smtps
-mail.smtps.host=smtp.gmail.com
-mail.smtps.port=465
-mail.smtps.auth=true
-mail.smtps.quitwait=false
+mail.transport.protocol=smtp
+mail.smtp.host=localhost
+mail.smtp.port=25
+mail.smtp.auth=false
+mail.smtp.quitwait=false
 
 # TODO: make all usernames and passwords configurable via Cloud Formation parameters.
 
-# CAUTION: THERE IS A PASSWORD HERE!
-mail.smtps.username=usergridtest@gmail.com
-mail.smtps.password=pw123
 
 ######################################################
 # Admin and test user setup


[15/50] [abbrv] git commit: Changed refresh logic to catch an issue when the Index has not yet replicated across the cluster.

Posted by sn...@apache.org.
Changed refresh logic to catch an issue when the Index has not yet replicated across the cluster.


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

Branch: refs/heads/two-dot-o-events
Commit: e5efa674bf71cda99d9958186962b0691ac4d6c2
Parents: 54b9a11
Author: Todd Nine <to...@apache.org>
Authored: Thu Oct 16 15:30:54 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Thu Oct 16 15:30:54 2014 -0600

----------------------------------------------------------------------
 .../index/impl/EsEntityIndexImpl.java           | 55 ++++++++++----------
 1 file changed, 27 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e5efa674/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 495b9e1..6ed9b86 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -124,34 +124,14 @@ public class EsEntityIndexImpl implements EntityIndex {
             }
             while ( response.getFailedShards() != 0 );
 
-            //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
-            //before we can write.
-            for(int i = 0 ; i < MAX_WAITS; i++ ){
-                try{
-                    refresh();
-                    break;
-
-                }catch(Exception e){
-                   log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
-                }
+            /**
+             * Immediately refresh to ensure the entire cluster is ready to receive this write.  Occasionally we see
+             * errors.  See this post.
+             * http://elasticsearch-users.115913.n3.nabble.com/IndexMissingException-on-create-index-followed-by-refresh-td1832793.html
+             *
+             */
+            refresh();
 
-                try {
-                    Thread.sleep( WAIT_TIME );
-                }
-                catch ( InterruptedException e ) {
-                    //swallow it
-                }
-            }
-
-            //
-            //            response.getFailedShards();
-            //
-            //            try {
-            //                // TODO: figure out what refresh above is not enough to ensure index is ready
-            //                Thread.sleep( 500 );
-            //            }
-            //            catch ( InterruptedException ex ) {
-            //            }
         }
         catch ( IndexAlreadyExistsException expected ) {
             // this is expected to happen if index already exists, it's a no-op and swallow
@@ -290,7 +270,26 @@ public class EsEntityIndexImpl implements EntityIndex {
 
 
     public void refresh() {
-        client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+
+            //now try to refresh, to ensure that it's recognized by everyone.  Occasionally we can get a success
+            //before we can write.
+            for(int i = 0 ; i < MAX_WAITS; i++ ){
+                try{
+                    client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+                    break;
+
+                }catch(Exception e){
+                   log.error( "Unable to refresh index after create. Waiting before sleeping.", e );
+                }
+
+                try {
+                    Thread.sleep( WAIT_TIME );
+                }
+                catch ( InterruptedException e ) {
+                    //swallow it
+                }
+            }
+
         log.debug( "Refreshed index: " + indexName );
     }
 


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

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


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

Branch: refs/heads/two-dot-o-events
Commit: 06dd7036c534a300824ed6c6d8f5c34371538566
Parents: f737927 c522a93
Author: Todd Nine <to...@apache.org>
Authored: Fri Oct 17 17:37:23 2014 -0600
Committer: Todd Nine <to...@apache.org>
Committed: Fri Oct 17 17:37:23 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/metrics/MetricsFactory.java | 21 ++++++++++----------
 1 file changed, 10 insertions(+), 11 deletions(-)
----------------------------------------------------------------------