You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/08/28 00:15:56 UTC

[01/10] usergrid git commit: add entity size

Repository: usergrid
Updated Branches:
  refs/heads/two-dot-o-dev ac9da14ba -> a11aaa03d


add entity size


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

Branch: refs/heads/two-dot-o-dev
Commit: 5e56f1b9cdec740c9907350ed1b585f09f06752a
Parents: 72016ea
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Aug 20 12:59:22 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Aug 20 12:59:22 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  5 ++--
 .../usergrid/persistence/AbstractEntity.java    |  7 ++++++
 .../org/apache/usergrid/persistence/Entity.java |  3 +++
 .../persistence/collection/MvccEntity.java      |  6 +++++
 .../mvcc/entity/impl/MvccEntityImpl.java        | 25 +++++++++++++++++---
 .../collection/mvcc/stage/delete/MarkStart.java |  2 +-
 .../MvccEntitySerializationStrategyImpl.java    |  4 ++--
 .../MvccEntitySerializationStrategyV3Impl.java  | 24 +++++++++++++------
 ...ccEntitySerializationStrategyV3ImplTest.java |  1 -
 .../persistence/model/entity/Entity.java        |  9 +++++++
 .../index/impl/EntityToMapConverter.java        |  5 +++-
 .../persistence/index/impl/IndexingUtils.java   |  2 ++
 12 files changed, 76 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/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 6611b6f..92464f8 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
@@ -2615,7 +2615,8 @@ public class CpEntityManager implements EntityManager {
                 } );
             }
 
-             cpEntity = ecm .write( cpEntity ).toBlocking().last();
+             cpEntity = ecm.write( cpEntity ).toBlocking().last();
+            entity.setSize(cpEntity.getSize());
 
             if(logger.isDebugEnabled()) {
                 logger.debug( "Wrote {}:{} version {}", new Object[] {
@@ -2647,7 +2648,7 @@ public class CpEntityManager implements EntityManager {
 
             String collectionName = Schema.defaultCollectionName( eType );
             CpRelationManager cpr = ( CpRelationManager ) getRelationManager( getApplication() );
-            cpr.addToCollection( collectionName, entity);
+            cpr.addToCollection( collectionName, entity );
 
             // Invoke counters
             incrementEntityCollection( collectionName, timestamp );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/core/src/main/java/org/apache/usergrid/persistence/AbstractEntity.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/AbstractEntity.java b/stack/core/src/main/java/org/apache/usergrid/persistence/AbstractEntity.java
index afe246d..59106ba 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/AbstractEntity.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/AbstractEntity.java
@@ -62,6 +62,7 @@ public abstract class AbstractEntity implements Entity {
     protected Map<String, Object> dynamic_properties = new TreeMap<String, Object>( String.CASE_INSENSITIVE_ORDER );
 
     protected Map<String, Set<Object>> dynamic_sets = new TreeMap<String, Set<Object>>( String.CASE_INSENSITIVE_ORDER );
+    protected long size;
 
 
     @Override
@@ -96,7 +97,12 @@ public abstract class AbstractEntity implements Entity {
         return new SimpleId( uuid, getType() );
     }
 
+    @Override
+    public void setSize(final long size){this.size = size;}
+
 
+    @Override
+    public long getSize(){return size;}
 
     @Override
     @EntityProperty(indexed = true, required = true, mutable = false)
@@ -363,4 +369,5 @@ public abstract class AbstractEntity implements Entity {
         }
         return true;
     }
+
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/core/src/main/java/org/apache/usergrid/persistence/Entity.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Entity.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Entity.java
index 2030bd1..b6176b8 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Entity.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Entity.java
@@ -102,4 +102,7 @@ public interface Entity extends EntityRef, Comparable<Entity> {
 
     @JsonAnyGetter
     public abstract Map<String, Object> getDynamicProperties();
+
+    long getSize();
+    void setSize(long size);
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
index c89838e..53142c8 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
@@ -68,4 +68,10 @@ public interface MvccEntity extends EntityVersion{
      * Get the status of the entity
      */
     Status getStatus();
+
+    /**
+     * entity byte size
+     * @return
+     */
+    long getSize();
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
index 14889bd..e0066ba 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
@@ -38,24 +38,34 @@ public class MvccEntityImpl implements MvccEntity {
     private final UUID version;
     private final Optional<Entity> entity;
     private final Status status;
+    private final long size;
 
 
     public MvccEntityImpl( final Id entityId, final UUID version, final Status status, final Entity entity ) {
-        this( entityId, version, status, Optional.of( entity ) );
+        this( entityId, version, status, entity, 0 );
     }
 
-
+    public MvccEntityImpl( final Id entityId, final UUID version, final Status status, final Entity entity, final long size ) {
+        this( entityId, version, status, Optional.of( entity ), size);
+    }
     public MvccEntityImpl(
-            final Id entityId, final UUID version, final Status status, final Optional<Entity> entity ) {
+        final Id entityId, final UUID version, final Status status, final Optional<Entity> entity ) {
+        this( entityId, version, status,   entity , 0);
+    }
+
+        public MvccEntityImpl(
+            final Id entityId, final UUID version, final Status status, final Optional<Entity> entity, final long size ) {
         Preconditions.checkNotNull( entityId, "entity id is required" );
         Preconditions.checkNotNull( version, "version id is required" );
         Preconditions.checkNotNull( status, "status  is required" );
         Preconditions.checkNotNull( entity, "entity  is required" );
+        Preconditions.checkNotNull( size, "size  is required" );
 
         this.entityId = entityId;
         this.version = version;
         this.entity = entity;
         this.status = status;
+        this.size = size;
     }
 
 
@@ -82,6 +92,11 @@ public class MvccEntityImpl implements MvccEntity {
         return status;
     }
 
+    @Override
+    public long getSize() {
+        return size;
+    }
+
 
     @Override
     public boolean equals( final Object o ) {
@@ -104,6 +119,10 @@ public class MvccEntityImpl implements MvccEntity {
             return false;
         }
 
+        if( size != that.size){
+            return false;
+        }
+
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkStart.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkStart.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkStart.java
index 040e893..3c4ea95 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkStart.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/stage/delete/MarkStart.java
@@ -106,7 +106,7 @@ public class MarkStart implements Func1<CollectionIoEvent<Id>, CollectionIoEvent
 
         //create the mvcc entity for the next stage
         final MvccEntityImpl nextStage = new MvccEntityImpl(
-            entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent() );
+            entityId, version, MvccEntity.Status.COMPLETE, Optional.<Entity>absent(), 0 );
 
 
         return new CollectionIoEvent<MvccEntity>( applicationScope, nextStage );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
index 6fa539a..457664f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
@@ -424,7 +424,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
                                 + " write was truncated.", id, version, e );
                 //return an empty entity, we can never load this one, and we don't want it to bring the system
                 //to a grinding halt
-                return new MvccEntityImpl( id, version, MvccEntity.Status.DELETED, Optional.<Entity>absent() );
+                return new MvccEntityImpl( id, version, MvccEntity.Status.DELETED, Optional.<Entity>absent(),0 );
             }
 
             //Inject the id into it.
@@ -432,7 +432,7 @@ public abstract class MvccEntitySerializationStrategyImpl implements MvccEntityS
                 EntityUtils.setId( deSerialized.entity.get(), id );
             }
 
-            return new MvccEntityImpl( id, version, deSerialized.status, deSerialized.entity );
+            return new MvccEntityImpl( id, version, deSerialized.status, deSerialized.entity, 0 );
         }
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
index 81a0e6d..2f4c625 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
@@ -112,7 +112,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
         Optional<EntityMap> map =  EntityMap.fromEntity(entity.getEntity());
         return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE,
-                entitySerializer.toByteBuffer( new EntityWrapper(entityId,entity.getVersion(), entity.getStatus(), map.isPresent() ? map.get() : null ) ) ) );
+                entitySerializer.toByteBuffer( new EntityWrapper(entityId,entity.getVersion(), entity.getStatus(), map.isPresent() ? map.get() : null, 0 ) ) ) );
     }
 
 
@@ -268,7 +268,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
         return doWrite(applicationScope, entityId, version, colMutation ->
                 colMutation.putColumn(COL_VALUE,
-                    entitySerializer.toByteBuffer(new EntityWrapper(entityId, version, MvccEntity.Status.DELETED, null))
+                    entitySerializer.toByteBuffer(new EntityWrapper(entityId, version, MvccEntity.Status.DELETED, null, 0))
                 )
         );
     }
@@ -355,10 +355,10 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 //return an empty entity, we can never load this one, and we don't want it to bring the system
                 //to a grinding halt
                 //TODO fix this
-                return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent() );
+                return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent(),0 );
             }
             Optional<Entity> entity = deSerialized.getOptionalEntity() ;
-            return new MvccEntityImpl( id, deSerialized.getVersion(), deSerialized.getStatus(), entity );
+            return new MvccEntityImpl( id, deSerialized.getVersion(), deSerialized.getStatus(), entity, deSerialized.getSize());
         }
     }
 
@@ -453,6 +453,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 byte[] arr = byteBuffer.array();
                 bytesOutHistorgram.update( arr == null ? 0 : arr.length);
                 entityWrapper = MAPPER.readValue(arr, EntityWrapper.class);
+                entityWrapper.size = arr.length;
                 time.stop();
             }
             catch ( Exception e ) {
@@ -464,7 +465,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
             // it's been deleted, remove it
             if ( entityWrapper.getEntityMap() == null) {
-                return new EntityWrapper( entityWrapper.getId(), entityWrapper.getVersion(),MvccEntity.Status.DELETED,null );
+                return new EntityWrapper( entityWrapper.getId(), entityWrapper.getVersion(),MvccEntity.Status.DELETED,null,0 );
             }
 
             entityWrapper.setStatus(MvccEntity.Status.COMPLETE);
@@ -482,15 +483,17 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
         private MvccEntity.Status status;
         private UUID version;
         private EntityMap entityMap;
+        private long size;
 
 
         public EntityWrapper( ) {
         }
-        public EntityWrapper( final Id id , final UUID version, final MvccEntity.Status status, final EntityMap entity ) {
+        public EntityWrapper( final Id id , final UUID version, final MvccEntity.Status status, final EntityMap entity, final long size ) {
             this.setStatus(status);
             this.version=  version;
             this.entityMap = entity;
             this.id = id;
+            this.size = size;
         }
 
         /**
@@ -525,7 +528,9 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
 
         @JsonIgnore
         public Optional<Entity> getOptionalEntity() {
-            Optional<Entity> entityReturn = Optional.fromNullable(Entity.fromMap(getEntityMap()));
+            Entity entity = Entity.fromMap(getEntityMap());
+            entity.setSize(getSize());
+            Optional<Entity> entityReturn = Optional.fromNullable(entity);
             //Inject the id into it.
             if (entityReturn.isPresent()) {
                 EntityUtils.setId(entityReturn.get(), getId());
@@ -534,6 +539,11 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
             ;
             return entityReturn;
         }
+
+        @JsonIgnore
+        public long getSize() {
+            return size;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3ImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3ImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3ImplTest.java
index 1df22f6..d55894b 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3ImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3ImplTest.java
@@ -54,7 +54,6 @@ public class MvccEntitySerializationStrategyV3ImplTest extends MvccEntitySeriali
     @Test( expected = UnsupportedOperationException.class )
     public void loadDescendingHistory() throws ConnectionException {
 
-
         final String name = "test";
 
         final Id applicationId = new SimpleId( "application" );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
index cd75544..013b37a 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
@@ -59,6 +59,9 @@ public class Entity extends EntityObject {
     @JsonProperty
     private UUID version;
 
+    @JsonIgnore
+    private long size;
+
 
     /**
      * Create an entity with the given type and id.  Should be used for all update operations to an existing entity
@@ -155,4 +158,10 @@ public class Entity extends EntityObject {
         return getVersion() != null;
     }
 
+    public long getSize() {
+        return this.size;
+    }
+    public void setSize(long size) {
+        this.size = size;
+    }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
index 567068c..1b0d110 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EntityToMapConverter.java
@@ -35,6 +35,7 @@ import static org.apache.usergrid.persistence.index.impl.IndexingUtils.EDGE_SEAR
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.EDGE_TIMESTAMP_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_FIELDS;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_ID_FIELDNAME;
+import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_SIZE_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_TYPE_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.ENTITY_VERSION_FIELDNAME;
 import static org.apache.usergrid.persistence.index.impl.IndexingUtils.applicationId;
@@ -71,7 +72,7 @@ public class EntityToMapConverter {
 
         outputEntity.put( ENTITY_VERSION_FIELDNAME, entity.getVersion() );
 
-        outputEntity.put( ENTITY_TYPE_FIELDNAME, getType( applicationScope, entityId ) );
+        outputEntity.put( ENTITY_TYPE_FIELDNAME, getType( applicationScope, entityId));
 
         outputEntity.put( APPLICATION_ID_FIELDNAME, applicationId( applicationScope.getApplication() ) );
 
@@ -83,6 +84,8 @@ public class EntityToMapConverter {
 
         outputEntity.put( EDGE_TIMESTAMP_FIELDNAME, indexEdge.getTimestamp()  );
 
+        outputEntity.put( ENTITY_SIZE_FIELDNAME, entity.getSize() );
+
         //add the context for filtering later
         outputEntity.put( EDGE_SEARCH_FIELDNAME, IndexingUtils.createContextName( applicationScope, indexEdge ) );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5e56f1b9/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
index e82a082..9e06fa6 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java
@@ -84,6 +84,8 @@ public class IndexingUtils {
 
     public static final String ENTITY_ID_FIELDNAME = "entityId";
 
+    public static final String ENTITY_SIZE_FIELDNAME = "entitySize";
+
     public static final String ENTITY_VERSION_FIELDNAME = "entityVersion";
 
     public static final String ENTITY_TYPE_FIELDNAME = "entityType";


[04/10] usergrid git commit: add aggregation service

Posted by to...@apache.org.
add aggregation service


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

Branch: refs/heads/two-dot-o-dev
Commit: 198f489155b3f9d4346d62c0fe7ba859be917b70
Parents: c47b02d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 09:36:32 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 09:36:32 2015 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/index/EntityIndex.java |  61 ++++++---
 .../index/impl/EsEntityIndexImpl.java           |  51 +++++++-
 .../persistence/index/impl/EntityIndexTest.java | 129 ++++++++++++++++---
 3 files changed, 193 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/198f4891/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index 7fa2f07..6d563ff 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -39,34 +39,47 @@ public interface EntityIndex extends CPManager {
 
     /**
      * Create an index and add to alias, will create alias and remove any old index from write alias if alias already exists
-     * @param indexSuffix index name
+     *
+     * @param indexSuffix      index name
      * @param shards
      * @param replicas
      * @param writeConsistency
      */
-     void addIndex(
-         final String indexSuffix,
-         final int shards,
-         final int replicas,
-         final String writeConsistency
-     );
+    void addIndex(
+        final String indexSuffix,
+        final int shards,
+        final int replicas,
+        final String writeConsistency
+    );
 
     /**
      * Refresh the index.
      */
-     Observable<IndexRefreshCommand.IndexRefreshCommandInfo> refreshAsync();
+    Observable<IndexRefreshCommand.IndexRefreshCommandInfo> refreshAsync();
 
 
     /**
      * Check health of cluster.
      */
-     Health getClusterHealth();
+    Health getClusterHealth();
 
     /**
      * Check health of this specific index.
      */
-     Health getIndexHealth();
+    Health getIndexHealth();
 
+    /**
+     * get total entity size
+     * @return
+     */
+    long getEntitySize();
+
+    /**
+     * get total entity size by an edge ->   "term":{"edgeName":"zzzcollzzz|roles"}
+     * @param edge
+     * @return
+     */
+    long getEntitySize(final String edge);
 
     /**
      * Initialize the index if necessary.  This is an idempotent operation and should not create an index
@@ -82,48 +95,54 @@ public interface EntityIndex extends CPManager {
 
     /**
      * Search on every document in the specified search edge.  Also search by the types if specified
-     * @param searchEdge The edge to search on
+     *
+     * @param searchEdge  The edge to search on
      * @param searchTypes The search types to search
-     * @param query The query to execute
-     * @param limit The limit of values to return
-     * @param offset The offset to query on
+     * @param query       The query to execute
+     * @param limit       The limit of values to return
+     * @param offset      The offset to query on
      * @return
      */
-    CandidateResults search( final SearchEdge searchEdge, final SearchTypes searchTypes, final String query,
-                             final int limit, final int offset );
+    CandidateResults search(final SearchEdge searchEdge, final SearchTypes searchTypes, final String query,
+                            final int limit, final int offset);
 
 
     /**
      * Same as search, just iterates all documents that match the index edge exactly.
-     * @param edge The edge to search on
+     *
+     * @param edge     The edge to search on
      * @param entityId The entity that the searchEdge is connected to.
      * @return
      */
-    CandidateResults getAllEdgeDocuments( final IndexEdge edge, final Id entityId );
+    CandidateResults getAllEdgeDocuments(final IndexEdge edge, final Id entityId);
 
     /**
      * Returns all entity documents that match the entityId and come before the marked version
-     * @param entityId The entityId to match when searching
+     *
+     * @param entityId      The entityId to match when searching
      * @param markedVersion The version that has been marked for deletion. All version before this one must be deleted.
      * @return
      */
-    CandidateResults getAllEntityVersionsBeforeMarkedVersion( final Id entityId, final UUID markedVersion );
+    CandidateResults getAllEntityVersionsBeforeMarkedVersion(final Id entityId, final UUID markedVersion);
 
     /**
      * delete all application records
+     *
      * @return
      */
     Observable deleteApplication();
 
     /**
      * Get the indexes for an alias
+     *
      * @param aliasType name of alias
      * @return list of index names
      */
-    String[] getIndexes( final AliasType aliasType );
+    String[] getIndexes(final AliasType aliasType);
 
     /**
      * get all unique indexes
+     *
      * @return
      */
     String[] getIndexes();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/198f4891/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 87e2dbd..800dac3 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
@@ -62,6 +62,10 @@ import org.elasticsearch.index.query.*;
 import org.elasticsearch.indices.IndexAlreadyExistsException;
 import org.elasticsearch.search.SearchHit;
 import org.elasticsearch.search.SearchHits;
+import org.elasticsearch.search.aggregations.Aggregation;
+import org.elasticsearch.search.aggregations.AggregationBuilder;
+import org.elasticsearch.search.aggregations.metrics.sum.Sum;
+import org.elasticsearch.search.aggregations.metrics.sum.SumBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -424,7 +428,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
          and query Es directly for matches
 
          */
-        IndexValidationUtils.validateSearchEdge( edge );
+        IndexValidationUtils.validateSearchEdge(edge);
         Preconditions.checkNotNull( entityId, "entityId cannot be null" );
 
         SearchResponse searchResponse;
@@ -505,12 +509,12 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
 
         final SearchRequestBuilder srb = searchRequestBuilderStrategyV2.getBuilder();
 
-        FilterBuilder entityIdFilter = FilterBuilders.termFilter( IndexingUtils.ENTITY_ID_FIELDNAME,
-            IndexingUtils.entityId( entityId ) );
+        FilterBuilder entityIdFilter = FilterBuilders.termFilter(IndexingUtils.ENTITY_ID_FIELDNAME,
+            IndexingUtils.entityId(entityId));
 
-        FilterBuilder entityVersionFilter = FilterBuilders.rangeFilter( IndexingUtils.ENTITY_VERSION_FIELDNAME ).lte( markedVersion );
+        FilterBuilder entityVersionFilter = FilterBuilders.rangeFilter( IndexingUtils.ENTITY_VERSION_FIELDNAME ).lte(markedVersion);
 
-        FilterBuilder andFilter = FilterBuilders.andFilter(entityIdFilter,entityVersionFilter  );
+        FilterBuilder andFilter = FilterBuilders.andFilter(entityIdFilter, entityVersionFilter);
 
         srb.setPostFilter(andFilter);
 
@@ -570,7 +574,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
      * Completely delete an index.
      */
     public Observable deleteApplication() {
-        String idString = applicationId( applicationScope.getApplication() );
+        String idString = applicationId(applicationScope.getApplication());
         final TermQueryBuilder tqb = QueryBuilders.termQuery(APPLICATION_ID_FIELDNAME, idString);
         final String[] indexes = getIndexes();
         //Added For Graphite Metrics
@@ -734,6 +738,41 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
     }
 
     @Override
+    public long getEntitySize(){
+
+
+        SearchRequestBuilder builder = searchRequestBuilderStrategyV2.getBuilder();
+        return  getEntitySizeAggregation(builder);
+    }
+
+
+    @Override
+    public long getEntitySize(final String edge){
+        //"term":{"edgeName":"zzzcollzzz|roles"}
+        SearchRequestBuilder builder = searchRequestBuilderStrategyV2.getBuilder();
+        builder.setQuery(new TermQueryBuilder("edgeName",edge));
+        return  getEntitySizeAggregation(builder);
+    }
+
+    private long getEntitySizeAggregation(  SearchRequestBuilder builder) {
+        final String key = "entitySize";
+        SumBuilder sumBuilder = new SumBuilder(key);
+        sumBuilder.field("entitySize");
+        builder.addAggregation(sumBuilder);
+        Observable<Number> o = Observable.from(builder.execute())
+            .map(response -> {
+                Sum aggregation = (Sum) response.getAggregations().get(key);
+                if(aggregation == null){
+                    return -1;
+                }else{
+                    return aggregation.getValue();
+                }
+            });
+        Number val =  o.toBlocking().first();
+        return val.longValue();
+    }
+
+    @Override
     public int getImplementationVersion() {
         return IndexDataVersions.SINGLE_INDEX.getVersion();
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/198f4891/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 9154382..564e5e7 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -270,7 +270,7 @@ public class EntityIndexTest extends BaseIT {
         insertJsonBlob(  entityType, searchEdge, "/sample-large.json", 1, 0 );
 
 
-        entityIndex.addIndex(UUID.randomUUID()+ "v2", 1, 0, "one" );
+        entityIndex.addIndex(UUID.randomUUID() + "v2", 1, 0, "one");
         entityIndex.refreshAsync().toBlocking().first();
 
         insertJsonBlob(  entityType, searchEdge, "/sample-large.json", 1, 1 );
@@ -278,12 +278,12 @@ public class EntityIndexTest extends BaseIT {
         CandidateResults crs = testQuery( searchEdge, searchTypes, "name = 'Bowers Oneil'", 1 );
 
         EntityIndexBatch entityIndexBatch = entityIndex.createBatch();
-        entityIndexBatch.deindex( searchEdge, crs.get( 0 ) );
+        entityIndexBatch.deindex(searchEdge, crs.get(0));
         entityIndexBatch.execute().toBlocking().last();
         entityIndex.refreshAsync().toBlocking().first();
 
         //Hilda Youn
-        testQuery( searchEdge, searchTypes, "name = 'Bowers Oneil'", 0 );
+        testQuery(searchEdge, searchTypes, "name = 'Bowers Oneil'", 0);
     }
 
 
@@ -291,13 +291,14 @@ public class EntityIndexTest extends BaseIT {
                                  String filePath, final int max, final int startIndex ) throws IOException {
         InputStream is = this.getClass().getResourceAsStream( filePath );
         ObjectMapper mapper = new ObjectMapper();
-        List<Object> sampleJson = mapper.readValue( is, new TypeReference<List<Object>>() {} );
+        List<Object> sampleJson = mapper.readValue(is, new TypeReference<List<Object>>() {
+        });
         EntityIndexBatch batch = entityIndex.createBatch();
-        insertJsonBlob( sampleJson, batch, entityType, indexEdge, max, startIndex );
+        insertJsonBlob(sampleJson, batch, entityType, indexEdge, max, startIndex);
         batch.execute().toBlocking().last();
         IndexRefreshCommandImpl.IndexRefreshCommandInfo info =  entityIndex.refreshAsync().toBlocking().first();
         long time = info.getExecutionTime();
-        log.info( "refresh took ms:" + time );
+        log.info("refresh took ms:" + time);
     }
 
 
@@ -366,7 +367,7 @@ public class EntityIndexTest extends BaseIT {
 
         candidateResults = entityIndex
             .search(searchEdge, SearchTypes.fromTypes( entity.getId().getType() ), "name contains 'Ferrari*'", 10, 0 );
-        assertEquals( 0, candidateResults.size() );
+        assertEquals(0, candidateResults.size());
     }
 
 
@@ -420,8 +421,8 @@ public class EntityIndexTest extends BaseIT {
 
         timer.stop();
 
-        assertEquals( num, candidateResults.size() );
-        log.debug( "Query time {}ms", timer.getTime() );
+        assertEquals(num, candidateResults.size());
+        log.debug("Query time {}ms", timer.getTime());
         return candidateResults;
     }
 
@@ -609,13 +610,13 @@ public class EntityIndexTest extends BaseIT {
         assertEquals( bill.getId(), r.get( 0 ).getId() );
 
         r = entityIndex.search( indexScope, searchTypes, "where username = 'fred'", 10, 0);
-        assertEquals( fred.getId(), r.get( 0 ).getId() );
+        assertEquals(fred.getId(), r.get(0).getId());
 
         r = entityIndex.search( indexScope, searchTypes, "where age = 41", 10, 0);
-        assertEquals( fred.getId(), r.get( 0 ).getId() );
+        assertEquals(fred.getId(), r.get(0).getId());
 
         r = entityIndex.search( indexScope, searchTypes, "where age = 'thirtysomething'", 10, 0);
-        assertEquals( bill.getId(), r.get( 0 ).getId() );
+        assertEquals(bill.getId(), r.get(0).getId());
     }
 
 
@@ -749,8 +750,8 @@ public class EntityIndexTest extends BaseIT {
         final String query = "where searchUUID = " + searchUUID;
 
         final CandidateResults r =
-            entityIndex.search( indexSCope, SearchTypes.fromTypes( entityId.getType() ), query, 10, 0);
-        assertEquals( user.getId(), r.get( 0 ).getId() );
+            entityIndex.search( indexSCope, SearchTypes.fromTypes(entityId.getType()), query, 10, 0);
+        assertEquals(user.getId(), r.get(0).getId());
     }
 
 
@@ -781,7 +782,7 @@ public class EntityIndexTest extends BaseIT {
 
         EntityIndexBatch batch = entityIndex.createBatch();
 
-        batch.index( indexSCope, user );
+        batch.index(indexSCope, user);
         batch.execute().toBlocking().last();
         entityIndex.refreshAsync().toBlocking().first();
 
@@ -790,7 +791,7 @@ public class EntityIndexTest extends BaseIT {
         final CandidateResults r =
             entityIndex.search( indexSCope, SearchTypes.fromTypes( entityId.getType() ), query, 10, 0);
 
-        assertEquals(user.getId(), r.get(0).getId() );
+        assertEquals(user.getId(), r.get(0).getId());
 
         //shouldn't match
         final String queryNoWildCard = "where string = 'I am'";
@@ -830,7 +831,7 @@ public class EntityIndexTest extends BaseIT {
 
         final Entity second = new Entity( "search" );
 
-        second.setField( new StringField( "string", "bravo long string" ) );
+        second.setField(new StringField("string", "bravo long string"));
 
 
         EntityUtils.setVersion( second, UUIDGenerator.newTimeUUID() );
@@ -897,11 +898,11 @@ public class EntityIndexTest extends BaseIT {
 
         //get ordering, so 2 is before 1 when both match
         IndexEdge indexScope1 = new IndexEdgeImpl( ownerId, "searches", SearchEdge.NodeType.SOURCE, 10 );
-        batch.index( indexScope1, first );
+        batch.index(indexScope1, first);
 
 
         IndexEdge indexScope2 = new IndexEdgeImpl( ownerId, "searches", SearchEdge.NodeType.SOURCE, 11 );
-        batch.index( indexScope2, second);
+        batch.index(indexScope2, second);
 
 
         batch.execute().toBlocking().last();
@@ -914,8 +915,8 @@ public class EntityIndexTest extends BaseIT {
             entityIndex.search(indexScope1, SearchTypes.fromTypes( first.getId().getType() ), singleMatchQuery, 10, 0 );
 
 
-        assertEquals( 1, singleResults.size() );
-        assertEquals( first.getId(), singleResults.get( 0 ).getId() );
+        assertEquals(1, singleResults.size());
+        assertEquals(first.getId(), singleResults.get(0).getId());
 
 
         //search in reversed
@@ -1213,6 +1214,92 @@ public class EntityIndexTest extends BaseIT {
         assertEquals( 0, noMatchesContainsOrResults.size() );
     }
 
+    @Test
+    public void testSize(){
+        final String type = UUID.randomUUID().toString();
+
+        Id ownerId = new SimpleId( type );
+
+
+        final Entity first = new Entity( "search" );
+
+        first.setField( new StringField( "string", "I ate a sammich" ) );
+        first.setSize(100);
+
+        EntityUtils.setVersion( first, UUIDGenerator.newTimeUUID() );
+
+
+        final Entity second = new Entity( "search" );
+        second.setSize(100);
+
+        second.setField( new StringField( "string", "I drank a beer" ) );
+
+
+        EntityUtils.setVersion( second, UUIDGenerator.newTimeUUID() );
+
+
+        EntityIndexBatch batch = entityIndex.createBatch();
+
+
+        //get ordering, so 2 is before 1 when both match
+        IndexEdge indexScope1 = new IndexEdgeImpl( ownerId, "searches", SearchEdge.NodeType.SOURCE, 10 );
+        batch.index( indexScope1, first );
+
+
+        IndexEdge indexScope2 = new IndexEdgeImpl( ownerId, "searches", SearchEdge.NodeType.SOURCE, 11 );
+        batch.index( indexScope2, second);
+
+
+        batch.execute().toBlocking().last();
+        entityIndex.refreshAsync().toBlocking().first();
+        long size = entityIndex.getEntitySize();
+        assertTrue( size >= 200 );
+
+    }
+
+    @Test
+    public void testSizeByEdge(){
+        final String type = UUID.randomUUID().toString();
+
+        Id ownerId = new SimpleId( "owner" );
+
+
+        final Entity first = new Entity( type );
+
+        first.setField( new StringField( "string", "I ate a sammich" ) );
+        first.setSize(100);
+
+        EntityUtils.setVersion( first, UUIDGenerator.newTimeUUID() );
+
+
+        final Entity second = new Entity( type );
+        second.setSize(100);
+
+        second.setField( new StringField( "string", "I drank a beer" ) );
+
+
+        EntityUtils.setVersion( second, UUIDGenerator.newTimeUUID() );
+
+
+        EntityIndexBatch batch = entityIndex.createBatch();
+
+
+        //get ordering, so 2 is before 1 when both match
+        IndexEdge indexScope1 = new IndexEdgeImpl( ownerId,type , SearchEdge.NodeType.SOURCE, 10 );
+        batch.index( indexScope1, first );
+
+
+        IndexEdge indexScope2 = new IndexEdgeImpl( ownerId, type+"er", SearchEdge.NodeType.SOURCE, 11 );
+        batch.index( indexScope2, second);
+
+
+        batch.execute().toBlocking().last();
+        entityIndex.refreshAsync().toBlocking().first();
+        long size = entityIndex.getEntitySize(type);
+        assertTrue( size == 100 );
+
+    }
+
 
 }
 


[10/10] usergrid git commit: adding rest test

Posted by to...@apache.org.
adding rest test


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

Branch: refs/heads/two-dot-o-dev
Commit: a11aaa03d2237d0d2c8fa02ba1f8e32b44e37ee7
Parents: bed924f
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 17:50:15 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 17:50:15 2015 -0600

----------------------------------------------------------------------
 .../applications/ApplicationResource.java       | 13 +++---
 .../rest/management/ManagementResourceIT.java   | 44 ++++++++++++++------
 .../rest/test/resource/model/Entity.java        |  2 +
 3 files changed, 41 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/a11aaa03/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index fcb01d7..df98b43 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -50,10 +50,7 @@ import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriInfo;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-import java.util.UUID;
+import java.util.*;
 
 import static javax.servlet.http.HttpServletResponse.SC_ACCEPTED;
 import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
@@ -175,7 +172,9 @@ public class ApplicationResource extends AbstractContextResource {
         long size = management.getApplicationSize(this.applicationId);
         Map<String,Object> map = new HashMap<>();
         Map<String,Object> innerMap = new HashMap<>();
-        innerMap.put("application",size);
+        Map<String,Object> sumMap = new HashMap<>();
+        sumMap.put("sum",size);
+        innerMap.put("application",sumMap);
         map.put("aggregation",innerMap);
         response.setMetadata(map);
         return new JSONWithPadding( response, callback );
@@ -194,7 +193,9 @@ public class ApplicationResource extends AbstractContextResource {
         long size = management.getCollectionSize(this.applicationId ,collection_name);
         Map<String,Object> map = new HashMap<>();
         Map<String,Object> innerMap = new HashMap<>();
-        innerMap.put(collection_name,size);
+        Map<String,Object> sumMap = new HashMap<>();
+        sumMap.put("sum",size);
+        innerMap.put(collection_name,sumMap);
         map.put("aggregation",innerMap);
         response.setMetadata(map);
         return new JSONWithPadding( response, callback );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a11aaa03/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
index 1fe4974..99d2089 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/management/ManagementResourceIT.java
@@ -89,7 +89,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         data.clear();
         data.put( "oldpassword", "foo" );
         data.put( "newpassword", "test" );
-        management.users().user("test"+uuid).password().post(Entity.class,data);
+        management.users().user("test"+uuid).password().post(Entity.class, data);
     }
 
 
@@ -111,7 +111,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         Organization organization = new Organization(orgName,username,email,name,password,payload);
 
         Organization node = management().orgs().post(  organization );
-        management.token().get(clientSetup.getUsername(),clientSetup.getPassword());
+        management.token().get(clientSetup.getUsername(), clientSetup.getPassword());
 
         // check that the test admin cannot access the new org info
 
@@ -125,8 +125,8 @@ public class ManagementResourceIT extends AbstractRestIT {
             status = uie.getResponse().getClientResponseStatus();
         }
 
-        assertNotNull( status );
-        assertEquals( Status.UNAUTHORIZED, status );
+        assertNotNull(status);
+        assertEquals(Status.UNAUTHORIZED, status);
 
         // this admin should have access to test org
         status = null;
@@ -137,7 +137,7 @@ public class ManagementResourceIT extends AbstractRestIT {
             status = uie.getResponse().getClientResponseStatus();
         }
 
-        assertNull( status );
+        assertNull(status);
 
         //test getting the organization by org
 
@@ -149,7 +149,7 @@ public class ManagementResourceIT extends AbstractRestIT {
             status = uie.getResponse().getClientResponseStatus();
         }
 
-        assertNull( status );
+        assertNull(status);
     }
 
 
@@ -238,10 +238,10 @@ public class ManagementResourceIT extends AbstractRestIT {
         //post follow
         Entity entity = this.app()
             .collection( "users" )
-            .entity( user )
-            .collection( "following" )
-            .collection( "users" )
-            .entity( followUser )
+            .entity(user)
+            .collection("following")
+            .collection("users")
+            .entity(followUser)
             .post();
     }
 
@@ -256,8 +256,8 @@ public class ManagementResourceIT extends AbstractRestIT {
         activityPayload.put("actor", actorMap);
         Entity entity = this.app()
             .collection( "users" )
-            .entity( user )
-            .collection( "activities" )
+            .entity(user)
+            .collection("activities")
             .post( new Entity( activityPayload ) );
     }
 
@@ -306,6 +306,26 @@ public class ManagementResourceIT extends AbstractRestIT {
 
         assertEquals( "Roles", roles.get("title").toString() );
         assertEquals(4, roles.size());
+
+    }
+
+    @Test
+    public void checkSizes() throws Exception {
+        final String appname = clientSetup.getAppName();
+        this.app().collection("testCollection").post(new Entity().chainPut("name","test"));
+        refreshIndex();
+        Entity size = management().orgs().org( clientSetup.getOrganizationName() ).app().addToPath(appname).addToPath("size").get();
+        Entity rolesSize = management().orgs().org(clientSetup.getOrganizationName()).app().addToPath(appname).addToPath("size/roles").get();
+        assertTrue(size != null);
+        assertTrue(rolesSize != null);
+        int sum =  (int)((LinkedHashMap)((LinkedHashMap)size.metadata().get("aggregation")).get("application")).get("sum");
+        int sumRoles = (int)((LinkedHashMap)((LinkedHashMap)rolesSize.metadata().get("aggregation")).get("roles")).get("sum");
+
+        assertTrue(size != null);
+        assertTrue(rolesSize != null);
+
+        assertNotEquals(sum,sumRoles);
+        assertTrue(sum>sumRoles);
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/usergrid/blob/a11aaa03/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
index 3707967..a56e398 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/test/resource/model/Entity.java
@@ -193,6 +193,8 @@ public class Entity implements Serializable, Map<String,Object> {
         return getDynamicProperties().entrySet();
     }
 
+    public Map<String,Object> metadata(){return (Map<String,Object>)get("metadata");}
+
     public UUID getUuid(){
         return UUID.fromString( ( String ) get( "uuid" ) );
     }


[06/10] usergrid git commit: add timer

Posted by to...@apache.org.
add timer


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

Branch: refs/heads/two-dot-o-dev
Commit: c726129bd08fa9b6be6a102b4e6d0536e1d017af
Parents: c08ad51
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 09:45:01 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 09:45:01 2015 -0600

----------------------------------------------------------------------
 .../persistence/index/impl/EsEntityIndexImpl.java         | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/c726129b/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 800dac3..3ada5b9 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
@@ -27,6 +27,7 @@ import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
 import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
+import org.apache.usergrid.persistence.core.metrics.ObservableTimer;
 import org.apache.usergrid.persistence.core.migration.data.VersionedData;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.core.util.Health;
@@ -119,6 +120,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
     private final long queryTimeout;
     private final IndexBufferConsumer indexBatchBufferProducer;
     private final FailureMonitorImpl failureMonitor;
+    private final Timer aggregationTimer;
 
     private IndexCache aliasCache;
     private Timer mappingTimer;
@@ -153,8 +155,9 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
         this.addTimer = metricsFactory.getTimer(EsEntityIndexImpl.class, "index.add");
         this.updateAliasTimer = metricsFactory.getTimer(EsEntityIndexImpl.class, "index.update_alias");
         this.mappingTimer = metricsFactory.getTimer(EsEntityIndexImpl.class, "index.create_mapping");
-        this.refreshIndexMeter = metricsFactory.getMeter( EsEntityIndexImpl.class, "index.refresh_index" );
-        this.searchTimer = metricsFactory.getTimer( EsEntityIndexImpl.class, "search" );
+        this.refreshIndexMeter = metricsFactory.getMeter(EsEntityIndexImpl.class, "index.refresh_index");
+        this.searchTimer = metricsFactory.getTimer(EsEntityIndexImpl.class, "search");
+        this.aggregationTimer = metricsFactory.getTimer( EsEntityIndexImpl.class, "aggregations" );
 
     }
 
@@ -759,6 +762,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
         SumBuilder sumBuilder = new SumBuilder(key);
         sumBuilder.field("entitySize");
         builder.addAggregation(sumBuilder);
+
         Observable<Number> o = Observable.from(builder.execute())
             .map(response -> {
                 Sum aggregation = (Sum) response.getAggregations().get(key);
@@ -768,7 +772,7 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
                     return aggregation.getValue();
                 }
             });
-        Number val =  o.toBlocking().first();
+        Number val =   ObservableTimer.time(o,aggregationTimer).toBlocking().lastOrDefault(-1);
         return val.longValue();
     }
 


[05/10] usergrid git commit: Merge branch 'two-dot-o-dev' of https://git-wip-us.apache.org/repos/asf/usergrid into entity-size

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


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

Branch: refs/heads/two-dot-o-dev
Commit: c08ad512568f68d32b37bfd110729318db8778e6
Parents: 198f489 ac9da14
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 09:39:55 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 09:39:55 2015 -0600

----------------------------------------------------------------------
 DISCLAIMER                                      |    9 -
 NOTICE                                          |    2 +-
 README.md                                       |    9 +-
 content/community/index.html                    |   48 +-
 content/docs/README.html                        |   35 +-
 content/docs/_images/asapp.png                  |  Bin 0 -> 73593 bytes
 content/docs/_images/asemu.png                  |  Bin 0 -> 34744 bytes
 content/docs/_images/assettings.png             |  Bin 0 -> 120338 bytes
 content/docs/_images/gcmsetting.png             |  Bin 0 -> 101084 bytes
 content/docs/_images/googleproj0.png            |  Bin 0 -> 62311 bytes
 content/docs/_images/ios-cert.png               |  Bin 0 -> 41925 bytes
 content/docs/_images/iospgapp.png               |  Bin 0 -> 29796 bytes
 content/docs/_images/iospgcert.png              |  Bin 0 -> 41925 bytes
 content/docs/_images/iospgsettings.png          |  Bin 0 -> 384425 bytes
 content/docs/_images/iospushauth.png            |  Bin 0 -> 42175 bytes
 content/docs/_images/iospushfinal.png           |  Bin 0 -> 29573 bytes
 content/docs/_images/iospushsettings.png        |  Bin 0 -> 137812 bytes
 content/docs/_images/iphonemessage.png          |  Bin 0 -> 80970 bytes
 content/docs/_images/pgaapp.png                 |  Bin 0 -> 74807 bytes
 content/docs/_images/pgasettings.png            |  Bin 0 -> 95052 bytes
 content/docs/_images/pgaspath.png               |  Bin 0 -> 34744 bytes
 content/docs/_images/pushmiddleandroid0.png     |  Bin 0 -> 106080 bytes
 content/docs/_images/pushmiddleios0.png         |  Bin 0 -> 105175 bytes
 content/docs/_images/pushsslcertificate.png     |  Bin 0 -> 53445 bytes
 content/docs/_images/sendnotification.png       |  Bin 0 -> 47353 bytes
 content/docs/_sources/README.txt                |   11 +-
 .../file-storage-configuration.txt              |   39 +
 .../docs/_sources/assets-and-files/folders.txt  |   85 +
 .../assets-and-files/legacy-asset-support.txt   |    0
 .../assets-and-files/retrieving-assets.txt      |   27 +
 .../assets-and-files/uploading-assets.txt       |   86 +
 .../data-queries/operators-and-types.txt        |    2 +-
 .../_sources/data-queries/query-parameters.txt  |    2 +-
 .../data-queries/querying-your-data.txt         |    2 +-
 .../docs/_sources/data-storage/collections.txt  |    8 +-
 .../_sources/data-storage/data-store-dbms.txt   |   12 +-
 content/docs/_sources/data-storage/entities.txt |   10 +-
 .../entity-connections/retrieving-entities.txt  |    9 +-
 .../docs/_sources/geolocation/geolocation.txt   |    2 +-
 .../creating-a-new-application.txt              |    6 +-
 .../getting-started/creating-account.txt        |    6 +-
 .../getting-started/using-a-sandbox-app.txt     |    2 +-
 .../_sources/getting-started/using-the-api.txt  |    2 +-
 content/docs/_sources/index.txt                 |   30 +-
 .../installation/ug1-deploy-to-tomcat.txt       |    6 +-
 .../installation/ug1-launcher-quick-start.txt   |    2 +-
 .../installation/ug2-deploy-to-tomcat.txt       |    4 +-
 .../docs/_sources/introduction/data-model.txt   |   30 +-
 content/docs/_sources/introduction/overview.txt |   17 +
 .../_sources/introduction/usergrid-features.txt |   28 +-
 .../docs/_sources/orgs-and-apps/admin-user.txt  |    2 +-
 .../docs/_sources/orgs-and-apps/application.txt |    2 +-
 .../push-notifications/adding-push-support.txt  |  158 +
 .../creating-and-managing-notifications.txt     |  269 ++
 .../push-notifications/creating-notifiers.txt   |   69 +
 .../push-notifications/getting-started.txt      |  102 +
 .../managing-users-and-devices.txt              |  313 ++
 .../_sources/push-notifications/overview.txt    |   58 +
 .../_sources/push-notifications/registering.txt |  102 +
 .../push-notifications/troubleshooting.txt      |   93 +
 .../_sources/push-notifications/tutorial.txt    |  251 +
 .../docs/_sources/reference/contribute-code.txt |    2 +-
 .../docs/_sources/rest-endpoints/api-docs.txt   | 4385 +++++++++--------
 content/docs/_sources/sdks/ios-new.txt          |  982 ++++
 content/docs/_sources/sdks/sdk-outline.txt      |  111 +
 content/docs/_sources/sdks/usage.txt            |   16 -
 .../authenticating-api-requests.txt             |    6 +-
 ...enticating-users-and-application-clients.txt |    6 +-
 .../security-and-auth/facebook-sign.txt         |    2 +-
 .../user-authentication-types.txt               |    6 +-
 .../security-and-auth/using-permissions.txt     |    4 +-
 .../_sources/security-and-auth/using-roles.txt  |  304 ++
 .../docs/_sources/user-management/activity.txt  |   17 +-
 content/docs/_sources/user-management/group.txt |   12 +-
 .../user-management/messagee-example.txt        |    8 +-
 .../user-management/working-user-data.txt       |   12 +-
 content/docs/_static/css/theme.css              |  168 +-
 .../file-storage-configuration.html             |  335 ++
 content/docs/assets-and-files/folders.html      |  404 ++
 .../assets-and-files/legacy-asset-support.html  |  293 ++
 .../assets-and-files/retrieving-assets.html     |  372 ++
 .../docs/assets-and-files/uploading-assets.html |  432 ++
 .../creating-and-incrementing-counters.html     |   24 +-
 .../events-and-counters.html                    |   28 +-
 .../retrieving-counters.html                    |   24 +-
 .../docs/data-queries/advanced-query-usage.html |   24 +-
 .../docs/data-queries/operators-and-types.html  |   28 +-
 content/docs/data-queries/query-parameters.html |   27 +-
 .../docs/data-queries/querying-your-data.html   |   28 +-
 content/docs/data-storage/collections.html      |   48 +-
 content/docs/data-storage/data-store-dbms.html  |   44 +-
 content/docs/data-storage/entities.html         |   51 +-
 .../docs/data-storage/optimizing-access.html    |   24 +-
 .../entity-connections/connecting-entities.html |   24 +-
 .../disconnecting-entities.html                 |   28 +-
 .../entity-connections/retrieving-entities.html |   38 +-
 content/docs/genindex.html                      |   24 +-
 content/docs/geolocation/geolocation.html       |   30 +-
 .../creating-a-new-application.html             |   42 +-
 .../docs/getting-started/creating-account.html  |   41 +-
 .../getting-started/using-a-sandbox-app.html    |   39 +-
 content/docs/getting-started/using-the-api.html |   27 +-
 content/docs/index.html                         |  202 +-
 .../docs/installation/ug1-deploy-to-tomcat.html |   35 +-
 .../installation/ug1-launcher-quick-start.html  |   30 +-
 .../docs/installation/ug2-deploy-to-tomcat.html |   29 +-
 content/docs/introduction/async-vs-sync.html    |   28 +-
 content/docs/introduction/data-model.html       |   54 +-
 content/docs/introduction/overview.html         |  333 ++
 .../docs/introduction/usergrid-features.html    |   91 +-
 content/docs/objects.inv                        |  Bin 663 -> 692 bytes
 content/docs/orgs-and-apps/admin-user.html      |  104 +-
 content/docs/orgs-and-apps/application.html     |   39 +-
 content/docs/orgs-and-apps/managing.html        |   24 +-
 content/docs/orgs-and-apps/organization.html    |   24 +-
 .../push-notifications/adding-push-support.html |  581 +++
 .../creating-and-managing-notifications.html    |  742 +++
 .../push-notifications/creating-notifiers.html  |  425 ++
 .../push-notifications/getting-started.html     |  497 ++
 .../managing-users-and-devices.html             |  688 +++
 content/docs/push-notifications/overview.html   |  393 ++
 .../docs/push-notifications/registering.html    |  484 ++
 content/docs/push-notifications/tbd.html        |   24 +-
 .../push-notifications/troubleshooting.html     |  466 ++
 content/docs/push-notifications/tutorial.html   |  666 +++
 .../docs/push-notifications/users-devices.html  |   24 +-
 content/docs/reference/contribute-code.html     |   28 +-
 content/docs/reference/presos-and-videos.html   |   24 +-
 content/docs/rest-endpoints/api-docs.html       | 4417 +++++++++---------
 content/docs/sdks/ios-new.html                  | 1323 ++++++
 content/docs/sdks/sdk-outline.html              |  516 ++
 content/docs/sdks/tbd.html                      |   24 +-
 content/docs/sdks/usage.html                    |  308 --
 content/docs/search.html                        |   24 +-
 content/docs/searchindex.js                     |    2 +-
 .../docs/security-and-auth/app-security.html    |   28 +-
 .../authenticating-api-requests.html            |   36 +-
 ...nticating-users-and-application-clients.html |   46 +-
 .../changing-token-time-live-ttl.html           |   24 +-
 .../docs/security-and-auth/facebook-sign.html   |   26 +-
 .../revoking-tokens-logout.html                 |   24 +-
 .../security-and-auth/securing-your-app.html    |   24 +-
 .../user-authentication-types.html              |   45 +-
 .../security-and-auth/using-permissions.html    |   36 +-
 content/docs/security-and-auth/using-roles.html |  753 +++
 content/docs/user-management/activity.html      |   63 +-
 content/docs/user-management/group.html         |   51 +-
 content/docs/user-management/groups.html        |   24 +-
 .../docs/user-management/messagee-example.html  |   34 +-
 .../docs/user-management/user-connections.html  |   24 +-
 .../docs/user-management/user-management.html   |   24 +-
 .../docs/user-management/working-user-data.html |   59 +-
 content/index.html                              |   48 +-
 content/releases/index.html                     |   44 +-
 docs/installation/ug1-deploy-to-tomcat.md       |    6 +-
 docs/installation/ug1-launcher-quick-start.md   |    2 +-
 docs/installation/ug2-deploy-to-tomcat.md       |    4 +-
 docs/reference/contribute-code.md               |    2 +-
 docs/rest-endpoints/api-docs.html               | 1254 ++---
 docs/rest-endpoints/api-docs.md                 | 3434 ++++++++------
 .../main/groovy/usergrid/ApiDocGenerator.groovy |   23 +-
 docs/src/main/resources/html/model.mustache     |    6 +-
 docs/src/main/resources/markdown/model.mustache |   41 +-
 .../main/resources/markdown/operation.mustache  |    2 +
 docs/user-management/messagee-example.md        |    6 +-
 portal/README.md                                |    4 +-
 portal/index-template.html                      |   14 +-
 release/release-candidate.sh                    |   12 +-
 release/release.sh                              |   16 +-
 sdks/android/NOTICE                             |    2 +-
 sdks/android/pom.xml                            |    2 +-
 sdks/dotnet/NOTICE                              |    2 +-
 sdks/dotnet/README.md                           |    4 +-
 sdks/html5-javascript/README.md                 |   10 +-
 sdks/html5-javascript/index.html                |    2 +-
 sdks/java/pom.xml                               |    6 +-
 sdks/perl/README.md                             |    2 +-
 sdks/perl/lib/Usergrid/Client.pm                |    2 +-
 sdks/php/README.md                              |    6 +-
 sdks/ruby-on-rails/README.md                    |    2 +-
 stack/README.md                                 |    4 +-
 .../corepersistence/CpEntityMapUtilsTest.java   |   79 +
 .../model/entity/MapToEntityConverter.java      |   10 +-
 .../java/org/apache/usergrid/launcher/App.java  |    2 +-
 website/README.md                               |    2 +-
 website/content/community/index.html            |   12 +-
 website/content/index.html                      |   97 +
 website/content/releases/index.html             |   65 +
 website/layouts/footer.html                     |   32 +-
 website/layouts/header.html                     |    4 +-
 website/tmp/checksums                           |    4 +-
 website/tmp/compiled_content                    |  204 +-
 192 files changed, 22559 insertions(+), 7354 deletions(-)
----------------------------------------------------------------------



[08/10] usergrid git commit: passing tests

Posted by to...@apache.org.
passing tests


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

Branch: refs/heads/two-dot-o-dev
Commit: e6b6c0789b73696040282b364cb1c4c3206a391d
Parents: 8a71973
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 15:53:47 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 15:53:47 2015 -0600

----------------------------------------------------------------------
 .../service/AggregationServiceImpl.java         | 10 ++++++----
 .../corepersistence/util/CpNamingUtils.java     |  2 +-
 .../corepersistence/AggregationServiceTest.java | 21 ++++++++++++++------
 3 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/e6b6c078/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
index 5635bee..b8786d1 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
@@ -72,10 +72,12 @@ public class AggregationServiceImpl implements AggregationService {
         final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
         EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy);
         GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope);
-        Long sum = ObservableTimer.time( MathObservable.sumLong(graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent()))
-                .map(type -> CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type))
-                .map(edge -> entityIndex.getEntitySize(edge))
-        ), sumTimer).toBlocking().last();
+        Long sum = ObservableTimer.time(
+            MathObservable.sumLong(
+                graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent()))
+                    .map(type -> CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type))
+                    .map(edge -> entityIndex.getEntitySize(edge))
+            ), sumTimer).toBlocking().last();
 
         return sum.longValue();
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/e6b6c078/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index d5b05a2..acda51f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -110,7 +110,7 @@ public class CpNamingUtils {
      * To be used only for searching DO NOT use for creation. Use the createCollectionEdge instead.
      */
     public static String getEdgeTypeFromCollectionName( String collectionName ) {
-        return ( EDGE_COLL_PREFIX + "|" + collectionName ).toLowerCase();
+        return ((collectionName.startsWith(EDGE_COLL_PREFIX) ? collectionName  : EDGE_COLL_PREFIX + "|" + collectionName) ).toLowerCase();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/e6b6c078/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
index aa3615d..cc8adf1 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
@@ -46,7 +46,7 @@ public class AggregationServiceTest extends AbstractCoreIT {
         Map<String,Object> props = new HashMap<>();
          props.put("test", 1234);
         props.put("name", "myname");
-        Entity entity1 = this.app.getEntityManager().create("test",props);
+        Entity entity1 = this.app.getEntityManager().create("test", props);
         Entity entity2 = this.app.getEntityManager().create("test2", props);
         this.app.refreshIndex();
         Thread.sleep(500);
@@ -54,13 +54,22 @@ public class AggregationServiceTest extends AbstractCoreIT {
         long sum = aggregationService.sumAllCollections(applicationScope);
 
         Assert.assertTrue( sum >= 0 );
-        Assert.assertEquals(sum,entity1.getSize() + entity2.getSize());
+        Assert.assertTrue(sum > (entity1.getSize() + entity2.getSize()));
 
-        long sum1 = aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),"test"));
-        Assert.assertEquals(sum1,entity1.getSize());
+        long sum1 = aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),"tests"));
+        Assert.assertEquals(sum1, entity1.getSize());
 
-        long sum2 = aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),"test2"));
-        Assert.assertEquals(sum2,entity2.getSize());
+        long sum2 = aggregationService.sum(applicationScope, CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), "test2s"));
+        Assert.assertEquals(sum2, entity2.getSize());
+
+        props = new HashMap<>();
+        props.put("test", 1234);
+        props.put("name", "myname2");
+        Entity entity3 = this.app.getEntityManager().create("test", props);
+
+        this.app.refreshIndex();
+        long sum3 = aggregationService.sum(applicationScope, CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), "tests"));
+        Assert.assertEquals(sum3, entity1.getSize()+entity3.getSize());
 
     }
 }


[07/10] usergrid git commit: add aggregation factory

Posted by to...@apache.org.
add aggregation factory


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

Branch: refs/heads/two-dot-o-dev
Commit: 8a719733cc782fc82ce448ea9778440e103b4976
Parents: c726129
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 11:47:31 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 11:47:31 2015 -0600

----------------------------------------------------------------------
 .../usergrid/corepersistence/CoreModule.java    | 16 ++--
 .../service/AggregationService.java             | 47 +++++++++++
 .../service/AggregationServiceFactory.java      | 27 ++++++
 .../service/AggregationServiceImpl.java         | 89 ++++++++++++++++++++
 .../corepersistence/AggregationServiceTest.java | 66 +++++++++++++++
 .../persistence/collection/MvccEntity.java      |  2 +
 .../mvcc/entity/impl/MvccEntityImpl.java        |  7 ++
 .../MvccEntitySerializationStrategyV3Impl.java  |  9 +-
 .../graph/impl/SimpleSearchEdgeType.java        |  4 +-
 .../graph/impl/SimpleSearchIdType.java          |  3 +-
 .../persistence/graph/GraphManagerIT.java       |  5 +-
 .../graph/test/util/EdgeTestUtils.java          |  2 +-
 .../usergrid/persistence/index/EntityIndex.java |  7 +-
 .../index/impl/EsEntityIndexImpl.java           | 14 +--
 .../persistence/index/impl/EntityIndexTest.java | 44 +---------
 15 files changed, 267 insertions(+), 75 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
index d31099b..1a7f794 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CoreModule.java
@@ -16,7 +16,9 @@
 package org.apache.usergrid.corepersistence;
 
 
+import com.google.inject.assistedinject.FactoryModuleBuilder;
 import org.apache.usergrid.corepersistence.index.*;
+import org.apache.usergrid.corepersistence.service.*;
 import org.safehaus.guicyfig.GuicyFigModule;
 
 import org.apache.usergrid.corepersistence.asyncevents.AsyncEventService;
@@ -34,10 +36,6 @@ import org.apache.usergrid.corepersistence.rx.impl.AllEntitiesInSystemImpl;
 import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservable;
 import org.apache.usergrid.corepersistence.rx.impl.AllEntityIdsObservableImpl;
 import org.apache.usergrid.corepersistence.rx.impl.AllNodesInGraphImpl;
-import org.apache.usergrid.corepersistence.service.CollectionService;
-import org.apache.usergrid.corepersistence.service.CollectionServiceImpl;
-import org.apache.usergrid.corepersistence.service.ConnectionService;
-import org.apache.usergrid.corepersistence.service.ConnectionServiceImpl;
 import org.apache.usergrid.persistence.collection.guice.CollectionModule;
 import org.apache.usergrid.persistence.collection.serialization.impl.migration.EntityIdScope;
 import org.apache.usergrid.persistence.core.guice.CommonModule;
@@ -130,7 +128,7 @@ public class CoreModule  extends AbstractModule {
          *****/
 
 
-        bind( IndexService.class ).to( IndexServiceImpl.class );
+        bind( IndexService.class ).to(IndexServiceImpl.class);
 
         //bind the event handlers
         bind( EventBuilder.class).to( EventBuilderImpl.class );
@@ -140,9 +138,13 @@ public class CoreModule  extends AbstractModule {
         bind( AsyncEventService.class ).toProvider( AsyncIndexProvider.class );
 
 
-        bind( ReIndexService.class).to( ReIndexServiceImpl.class );
+        bind( ReIndexService.class).to(ReIndexServiceImpl.class);
 
-        bind( IndexLocationStrategyFactory.class ).to( IndexLocationStrategyFactoryImpl.class );
+        install(new FactoryModuleBuilder()
+            .implement(AggregationService.class, AggregationServiceImpl.class)
+            .build(AggregationServiceFactory.class));
+
+        bind(IndexLocationStrategyFactory.class).to( IndexLocationStrategyFactoryImpl.class );
 
         install(new GuicyFigModule(IndexProcessorFig.class));
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
new file mode 100644
index 0000000..296b7d0
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationService.java
@@ -0,0 +1,47 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence.service;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.index.SearchEdge;
+
+/**
+ * Service to retrieve aggregations by application scope.
+ */
+public interface AggregationService {
+
+
+    /**
+     * get entity size for app
+     *
+     * @param applicationScope
+     * @return
+     */
+    long sumAllCollections(ApplicationScope applicationScope);
+
+    /**
+     * get total entity size for an edge
+     *
+     * @param applicationScope
+     * @param edge
+     * @return
+     */
+    long sum(final ApplicationScope applicationScope, final SearchEdge edge);
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceFactory.java
new file mode 100644
index 0000000..2c58b19
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceFactory.java
@@ -0,0 +1,27 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence.service;
+
+/**
+ * Generate AggregationService instances
+ */
+public interface AggregationServiceFactory {
+    AggregationService getAggregationService();
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
new file mode 100644
index 0000000..5635bee
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/service/AggregationServiceImpl.java
@@ -0,0 +1,89 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence.service;
+
+import com.codahale.metrics.Timer;
+import com.google.common.base.Optional;
+import com.google.inject.Inject;
+import com.google.inject.assistedinject.Assisted;
+import org.apache.usergrid.corepersistence.index.IndexLocationStrategyFactory;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
+import org.apache.usergrid.persistence.core.metrics.ObservableTimer;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.index.EntityIndexFactory;
+import org.apache.usergrid.persistence.index.IndexLocationStrategy;
+import org.apache.usergrid.persistence.index.SearchEdge;
+import org.apache.usergrid.persistence.index.impl.SearchEdgeImpl;
+import org.apache.usergrid.utils.IndexUtils;
+import rx.observables.MathObservable;
+
+import java.util.Observable;
+
+/**
+ * Aggregation Service get counts for an application
+ */
+public class AggregationServiceImpl implements AggregationService {
+
+    private final EntityIndexFactory entityIndexFactory;
+    private final IndexLocationStrategyFactory indexLocationStrategyFactory;
+    private final GraphManagerFactory graphManagerFactory;
+    private final MetricsFactory metricsFactory;
+    private final Timer sumTimer;
+
+    @Inject
+    public AggregationServiceImpl(
+        final EntityIndexFactory entityIndexFactory,
+        final IndexLocationStrategyFactory indexLocationStrategyFactory,
+        final GraphManagerFactory graphManagerFactory,
+        final MetricsFactory metricsFactory){
+
+        this.entityIndexFactory = entityIndexFactory;
+        this.indexLocationStrategyFactory = indexLocationStrategyFactory;
+        this.graphManagerFactory = graphManagerFactory;
+        this.metricsFactory = metricsFactory;
+        this.sumTimer = metricsFactory.getTimer(AggregationServiceImpl.class,"sum");
+    }
+
+
+    @Override
+    public long sumAllCollections(ApplicationScope applicationScope) {
+        final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
+        EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy);
+        GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope);
+        Long sum = ObservableTimer.time( MathObservable.sumLong(graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent()))
+                .map(type -> CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type))
+                .map(edge -> entityIndex.getEntitySize(edge))
+        ), sumTimer).toBlocking().last();
+
+        return sum.longValue();
+    }
+
+    @Override
+    public long sum(ApplicationScope applicationScope, SearchEdge edge) {
+        final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
+        EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy);
+        return entityIndex.getEntitySize(edge);
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
new file mode 100644
index 0000000..aa3615d
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/AggregationServiceTest.java
@@ -0,0 +1,66 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.corepersistence;
+
+import com.google.inject.Injector;
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.cassandra.SpringResource;
+import org.apache.usergrid.corepersistence.service.AggregationService;
+import org.apache.usergrid.corepersistence.service.AggregationServiceFactory;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Classy class class.
+ */
+public class AggregationServiceTest extends AbstractCoreIT {
+    @Test
+    public void testEntitySize() throws Exception {
+        ApplicationScope applicationScope = CpNamingUtils.getApplicationScope(this.app.getId());
+        Injector injector = SpringResource.getInstance().getBean(Injector.class);
+        AggregationServiceFactory factory = injector.getInstance(AggregationServiceFactory.class);
+        AggregationService aggregationService = factory.getAggregationService();
+        Map<String,Object> props = new HashMap<>();
+         props.put("test", 1234);
+        props.put("name", "myname");
+        Entity entity1 = this.app.getEntityManager().create("test",props);
+        Entity entity2 = this.app.getEntityManager().create("test2", props);
+        this.app.refreshIndex();
+        Thread.sleep(500);
+
+        long sum = aggregationService.sumAllCollections(applicationScope);
+
+        Assert.assertTrue( sum >= 0 );
+        Assert.assertEquals(sum,entity1.getSize() + entity2.getSize());
+
+        long sum1 = aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),"test"));
+        Assert.assertEquals(sum1,entity1.getSize());
+
+        long sum2 = aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),"test2"));
+        Assert.assertEquals(sum2,entity2.getSize());
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
index 53142c8..9d5e530 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/MvccEntity.java
@@ -74,4 +74,6 @@ public interface MvccEntity extends EntityVersion{
      * @return
      */
     long getSize();
+
+    void setSize(long size);
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
index 74074d4..b7154fe 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
@@ -93,6 +93,13 @@ public class MvccEntityImpl implements MvccEntity {
         return size;
     }
 
+    @Override
+    public void setSize(long size) {
+        this.size = size;
+        if(this.entity.isPresent()){
+            this.entity.get().setSize(size);
+        }
+    }
 
     @Override
     public boolean equals( final Object o ) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
index df268af..0fd82cc 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
@@ -111,8 +111,13 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
         final UUID version = entity.getVersion();
 
         Optional<EntityMap> map =  EntityMap.fromEntity(entity.getEntity());
-        return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE,
-                entitySerializer.toByteBuffer( new EntityWrapper(entityId,entity.getVersion(), entity.getStatus(), map.isPresent() ? map.get() : null, 0 ) ) ) );
+        ByteBuffer byteBuffer = entitySerializer.toByteBuffer(
+            new EntityWrapper(entityId,entity.getVersion(), entity.getStatus(), map.isPresent() ? map.get() : null, 0 )
+        );
+
+        entity.setSize(byteBuffer.array().length);
+
+        return doWrite( applicationScope, entityId, version, colMutation -> colMutation.putColumn( COL_VALUE, byteBuffer ) );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchEdgeType.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchEdgeType.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchEdgeType.java
index 375ba19..2902b13 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchEdgeType.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchEdgeType.java
@@ -43,11 +43,11 @@ public class SimpleSearchEdgeType implements SearchEdgeType {
      * @param prefix The optional prefix
      * @param last The optional last
      */
-    public SimpleSearchEdgeType( final Id node, final String prefix, final String last ) {
+    public SimpleSearchEdgeType( final Id node, final String prefix, final Optional<String> last ) {
         ValidationUtils.verifyIdentity( node );
         this.node = node;
         this.prefix =  Optional.fromNullable( prefix );
-        this.last = Optional.fromNullable( last );
+        this.last = last == null ? Optional.<String>absent() : last;
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchIdType.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchIdType.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchIdType.java
index aa1d930..57f4fd0 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchIdType.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchIdType.java
@@ -19,6 +19,7 @@
 package org.apache.usergrid.persistence.graph.impl;
 
 
+import com.google.common.base.Optional;
 import org.apache.usergrid.persistence.core.util.ValidationUtils;
 import org.apache.usergrid.persistence.graph.SearchIdType;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -34,7 +35,7 @@ public class SimpleSearchIdType extends SimpleSearchEdgeType implements SearchId
 
 
     public SimpleSearchIdType( final Id node, final String edgeType, final String prefix, final String last ) {
-        super( node, prefix, last );
+        super(node, prefix, Optional.fromNullable(last));
 
         ValidationUtils.verifyString( edgeType, "edgeType" );
         this.edgeType = edgeType;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
index 7e6d2f7..d416b1d 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/GraphManagerIT.java
@@ -22,6 +22,7 @@ package org.apache.usergrid.persistence.graph;
 import java.util.Iterator;
 import java.util.concurrent.TimeoutException;
 
+import com.google.common.base.Optional;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
@@ -835,7 +836,7 @@ public class GraphManagerIT {
         //now load the next page
 
         //tests that even if a prefix is specified, the last takes precedence
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null, "test" );
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), null, Optional.fromNullable("test") );
 
         edges = gm.getEdgeTypesFromSource( edgeTypes );
 
@@ -913,7 +914,7 @@ public class GraphManagerIT {
 
         //now load the next page
 
-        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), null, "test" );
+        edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), null,  Optional.fromNullable("test") );
 
         edges = gm.getEdgeTypesToTarget( edgeTypes );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
index 718fc70..446af4c 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
@@ -202,7 +202,7 @@ public class EdgeTestUtils {
      * @return
      */
     public static SearchEdgeType createSearchEdge( final Id sourceId, final String last ) {
-        return new SimpleSearchEdgeType( sourceId, null, last );
+        return new SimpleSearchEdgeType( sourceId, null, Optional.fromNullable(last) );
     }
 
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
index 6d563ff..72300a5 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java
@@ -68,18 +68,13 @@ public interface EntityIndex extends CPManager {
      */
     Health getIndexHealth();
 
-    /**
-     * get total entity size
-     * @return
-     */
-    long getEntitySize();
 
     /**
      * get total entity size by an edge ->   "term":{"edgeName":"zzzcollzzz|roles"}
      * @param edge
      * @return
      */
-    long getEntitySize(final String edge);
+    long getEntitySize(final SearchEdge edge);
 
     /**
      * Initialize the index if necessary.  This is an idempotent operation and should not create an index

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/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 3ada5b9..1c63a7b 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
@@ -740,24 +740,16 @@ public class EsEntityIndexImpl implements EntityIndex,VersionedData {
         return Health.RED;
     }
 
-    @Override
-    public long getEntitySize(){
-
-
-        SearchRequestBuilder builder = searchRequestBuilderStrategyV2.getBuilder();
-        return  getEntitySizeAggregation(builder);
-    }
-
 
     @Override
-    public long getEntitySize(final String edge){
+    public long getEntitySize(final SearchEdge edge){
         //"term":{"edgeName":"zzzcollzzz|roles"}
         SearchRequestBuilder builder = searchRequestBuilderStrategyV2.getBuilder();
-        builder.setQuery(new TermQueryBuilder("edgeName",edge));
+        builder.setQuery(new TermQueryBuilder("edgeSearch",IndexingUtils.createContextName(applicationScope,edge)));
         return  getEntitySizeAggregation(builder);
     }
 
-    private long getEntitySizeAggregation(  SearchRequestBuilder builder) {
+    private long getEntitySizeAggregation( final SearchRequestBuilder builder ) {
         final String key = "entitySize";
         SumBuilder sumBuilder = new SumBuilder(key);
         sumBuilder.field("entitySize");

http://git-wip-us.apache.org/repos/asf/usergrid/blob/8a719733/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index 564e5e7..34256ca 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -1214,48 +1214,6 @@ public class EntityIndexTest extends BaseIT {
         assertEquals( 0, noMatchesContainsOrResults.size() );
     }
 
-    @Test
-    public void testSize(){
-        final String type = UUID.randomUUID().toString();
-
-        Id ownerId = new SimpleId( type );
-
-
-        final Entity first = new Entity( "search" );
-
-        first.setField( new StringField( "string", "I ate a sammich" ) );
-        first.setSize(100);
-
-        EntityUtils.setVersion( first, UUIDGenerator.newTimeUUID() );
-
-
-        final Entity second = new Entity( "search" );
-        second.setSize(100);
-
-        second.setField( new StringField( "string", "I drank a beer" ) );
-
-
-        EntityUtils.setVersion( second, UUIDGenerator.newTimeUUID() );
-
-
-        EntityIndexBatch batch = entityIndex.createBatch();
-
-
-        //get ordering, so 2 is before 1 when both match
-        IndexEdge indexScope1 = new IndexEdgeImpl( ownerId, "searches", SearchEdge.NodeType.SOURCE, 10 );
-        batch.index( indexScope1, first );
-
-
-        IndexEdge indexScope2 = new IndexEdgeImpl( ownerId, "searches", SearchEdge.NodeType.SOURCE, 11 );
-        batch.index( indexScope2, second);
-
-
-        batch.execute().toBlocking().last();
-        entityIndex.refreshAsync().toBlocking().first();
-        long size = entityIndex.getEntitySize();
-        assertTrue( size >= 200 );
-
-    }
 
     @Test
     public void testSizeByEdge(){
@@ -1295,7 +1253,7 @@ public class EntityIndexTest extends BaseIT {
 
         batch.execute().toBlocking().last();
         entityIndex.refreshAsync().toBlocking().first();
-        long size = entityIndex.getEntitySize(type);
+        long size = entityIndex.getEntitySize(new SearchEdgeImpl(ownerId,type, SearchEdge.NodeType.SOURCE));
         assertTrue( size == 100 );
 
     }


[02/10] usergrid git commit: fix mappings, equality

Posted by to...@apache.org.
fix mappings, equality


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

Branch: refs/heads/two-dot-o-dev
Commit: 81e0fbafde4dcf3c39530eb476f79e079bf66a33
Parents: 5e56f1b
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Aug 20 13:28:49 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Aug 20 13:28:49 2015 -0700

----------------------------------------------------------------------
 .../mvcc/entity/impl/MvccEntityImpl.java        | 28 +++++++-------------
 .../MvccEntitySerializationStrategyV3Impl.java  |  6 +++--
 .../persistence/index/usergrid-mappings.json    |  5 ++++
 3 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/81e0fbaf/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
index e0066ba..74074d4 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/mvcc/entity/impl/MvccEntityImpl.java
@@ -38,28 +38,24 @@ public class MvccEntityImpl implements MvccEntity {
     private final UUID version;
     private final Optional<Entity> entity;
     private final Status status;
-    private final long size;
+    private long size;
 
 
     public MvccEntityImpl( final Id entityId, final UUID version, final Status status, final Entity entity ) {
-        this( entityId, version, status, entity, 0 );
+        this(entityId, version, status, Optional.of(entity));
     }
 
-    public MvccEntityImpl( final Id entityId, final UUID version, final Status status, final Entity entity, final long size ) {
-        this( entityId, version, status, Optional.of( entity ), size);
-    }
     public MvccEntityImpl(
-        final Id entityId, final UUID version, final Status status, final Optional<Entity> entity ) {
-        this( entityId, version, status,   entity , 0);
+        final Id entityId, final UUID version, final Status status, final Optional<Entity> entity) {
+        this(entityId,version,status,entity,0);
     }
 
-        public MvccEntityImpl(
-            final Id entityId, final UUID version, final Status status, final Optional<Entity> entity, final long size ) {
-        Preconditions.checkNotNull( entityId, "entity id is required" );
-        Preconditions.checkNotNull( version, "version id is required" );
-        Preconditions.checkNotNull( status, "status  is required" );
-        Preconditions.checkNotNull( entity, "entity  is required" );
-        Preconditions.checkNotNull( size, "size  is required" );
+    public MvccEntityImpl(
+            final Id entityId, final UUID version, final Status status, final Optional<Entity> entity, final long size) {
+        Preconditions.checkNotNull(entityId, "entity id is required");
+        Preconditions.checkNotNull(version, "version id is required");
+        Preconditions.checkNotNull(status, "status  is required");
+        Preconditions.checkNotNull(entity, "entity  is required");
 
         this.entityId = entityId;
         this.version = version;
@@ -119,10 +115,6 @@ public class MvccEntityImpl implements MvccEntity {
             return false;
         }
 
-        if( size != that.size){
-            return false;
-        }
-
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/81e0fbaf/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
index 2f4c625..df268af 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyV3Impl.java
@@ -355,7 +355,7 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
                 //return an empty entity, we can never load this one, and we don't want it to bring the system
                 //to a grinding halt
                 //TODO fix this
-                return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent(),0 );
+                return new MvccEntityImpl( id, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, Optional.<Entity>absent() );
             }
             Optional<Entity> entity = deSerialized.getOptionalEntity() ;
             return new MvccEntityImpl( id, deSerialized.getVersion(), deSerialized.getStatus(), entity, deSerialized.getSize());
@@ -529,7 +529,9 @@ public class MvccEntitySerializationStrategyV3Impl implements MvccEntitySerializ
         @JsonIgnore
         public Optional<Entity> getOptionalEntity() {
             Entity entity = Entity.fromMap(getEntityMap());
-            entity.setSize(getSize());
+            if(entity!=null){
+                entity.setSize(getSize());
+            }
             Optional<Entity> entityReturn = Optional.fromNullable(entity);
             //Inject the id into it.
             if (entityReturn.isPresent()) {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/81e0fbaf/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json b/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
index da8e5d2..1b6a7f3 100644
--- a/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
+++ b/stack/corepersistence/queryindex/src/main/resources/org/apache/usergrid/persistence/index/usergrid-mappings.json
@@ -7,6 +7,11 @@
                 "index": "not_analyzed",
                 "doc_values": true
             },
+            "entitySize": {
+                "type": "long",
+                "index": "not_analyzed",
+                "doc_values": true
+            },
             "entityVersion": {
                 "type": "string",
                 "index": "not_analyzed",


[09/10] usergrid git commit: passing tests

Posted by to...@apache.org.
passing tests


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

Branch: refs/heads/two-dot-o-dev
Commit: bed924fcdff60732361db43b5f455cbe07ec4b17
Parents: e6b6c07
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 26 16:51:17 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 26 16:51:17 2015 -0600

----------------------------------------------------------------------
 .../apache/usergrid/persistence/EntityTest.java |  2 +-
 .../apache/usergrid/utils/IndexUtilsTest.java   |  2 +-
 .../applications/ApplicationResource.java       | 42 ++++++++++++++++++--
 .../usergrid/management/ManagementService.java  |  4 ++
 .../cassandra/ManagementServiceImpl.java        | 23 +++++++++++
 5 files changed, 68 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
index e9e6163..0e29a71 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityTest.java
@@ -81,7 +81,7 @@ public class EntityTest {
         User user = new User();
         // user.setId(UUIDUtils.newTimeUUID());
         user.setProperty( "foo", "bar" );
-        assertEquals( "{\"type\":\"user\",\"foo\":\"bar\"}", JsonUtils.mapToJsonString( user ) );
+        assertEquals( "{\"type\":\"user\",\"size\":0,\"foo\":\"bar\"}", JsonUtils.mapToJsonString( user ) );
 
         String json = "{\"username\":\"edanuff\", \"bar\" : \"baz\" }";
         Map<String, Object> p = ( Map<String, Object> ) JsonUtils.parse( json );

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java b/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
index c107f20..a727e3f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/utils/IndexUtilsTest.java
@@ -66,6 +66,6 @@ public class IndexUtilsTest {
             LOG.info( e.getKey() + " = " + e.getValue() );
         }
 
-        assertEquals( 7, l.size() );
+        assertEquals( 8, l.size() );
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
index bcec775..fcb01d7 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationResource.java
@@ -134,13 +134,13 @@ public class ApplicationResource extends AbstractContextResource {
         throws Exception {
 
         ApiResponse response = createApiResponse();
-        response.setAction( "get application client credentials" );
+        response.setAction("get application client credentials");
 
         ClientCredentialsInfo credentials =
                 new ClientCredentialsInfo( management.getClientIdForApplication( applicationId ),
                         management.getClientSecretForApplication( applicationId ) );
 
-        response.setCredentials( credentials );
+        response.setCredentials(credentials);
         return new JSONWithPadding( response, callback );
     }
 
@@ -157,12 +157,48 @@ public class ApplicationResource extends AbstractContextResource {
 
         ClientCredentialsInfo credentials =
                 new ClientCredentialsInfo( management.getClientIdForApplication( applicationId ),
-                        management.newClientSecretForApplication( applicationId ) );
+                        management.newClientSecretForApplication(applicationId) );
 
         response.setCredentials( credentials );
         return new JSONWithPadding( response, callback );
     }
 
+    @RequireOrganizationAccess
+    @GET
+    @Path("size")
+    public JSONWithPadding getApplicationSize(
+        @Context UriInfo ui, @QueryParam("callback") @DefaultValue("callback") String callback )
+        throws Exception {
+
+        ApiResponse response = createApiResponse();
+        response.setAction( "get application size for all entities" );
+        long size = management.getApplicationSize(this.applicationId);
+        Map<String,Object> map = new HashMap<>();
+        Map<String,Object> innerMap = new HashMap<>();
+        innerMap.put("application",size);
+        map.put("aggregation",innerMap);
+        response.setMetadata(map);
+        return new JSONWithPadding( response, callback );
+    }
+
+    @RequireOrganizationAccess
+    @GET
+    @Path("size/{collection_name}")
+    public JSONWithPadding getCollectionSize(
+        @Context UriInfo ui,
+        @PathParam( "collection_name" ) String collection_name,
+        @QueryParam("callback") @DefaultValue("callback") String callback )
+        throws Exception {
+        ApiResponse response = createApiResponse();
+        response.setAction("get collection size for all entities");
+        long size = management.getCollectionSize(this.applicationId ,collection_name);
+        Map<String,Object> map = new HashMap<>();
+        Map<String,Object> innerMap = new HashMap<>();
+        innerMap.put(collection_name,size);
+        map.put("aggregation",innerMap);
+        response.setMetadata(map);
+        return new JSONWithPadding( response, callback );
+    }
 
     @POST
     @Path("sia-provider")

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
index 9131e47..c822057 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ManagementService.java
@@ -332,4 +332,8 @@ public interface ManagementService {
     public void deleteApplication(UUID applicationId) throws Exception;
 
     public ApplicationInfo restoreApplication(UUID applicationId) throws Exception;
+
+    long getApplicationSize(final UUID applicationId);
+
+    long getCollectionSize(final UUID applicationId, final String collectionName);
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/bed924fc/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 32e4393..e36e31c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -20,9 +20,12 @@ package org.apache.usergrid.management.cassandra;
 import com.google.common.base.Optional;
 import com.google.common.collect.BiMap;
 import com.google.common.collect.HashBiMap;
+import com.google.inject.Injector;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.apache.commons.lang.text.StrSubstitutor;
 import org.apache.shiro.UnavailableSecurityManagerException;
+import org.apache.usergrid.corepersistence.service.AggregationService;
+import org.apache.usergrid.corepersistence.service.AggregationServiceFactory;
 import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.exception.ConflictException;
 import org.apache.usergrid.locking.Lock;
@@ -31,6 +34,7 @@ import org.apache.usergrid.management.*;
 import org.apache.usergrid.management.exceptions.*;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.Query.Level;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Group;
 import org.apache.usergrid.persistence.entities.User;
@@ -138,6 +142,9 @@ public class ManagementServiceImpl implements ManagementService {
     @Autowired
     protected MailUtils mailUtils;
 
+    @Autowired
+    protected Injector injector;
+
     protected EncryptionService encryptionService;
 
 
@@ -1709,6 +1716,22 @@ public class ManagementServiceImpl implements ManagementService {
         return new ApplicationInfo( applicationId, appInfo.getName() );
     }
 
+    @Override
+    public long getApplicationSize(final UUID applicationId) {
+        AggregationServiceFactory aggregationServiceFactory = injector.getInstance(AggregationServiceFactory.class);
+        AggregationService aggregationService = aggregationServiceFactory.getAggregationService();
+        ApplicationScope applicationScope =CpNamingUtils.getApplicationScope(applicationId);
+        return aggregationService.sumAllCollections(applicationScope);
+    }
+
+    @Override
+    public long getCollectionSize(final UUID applicationId, final String collectionName) {
+        AggregationServiceFactory aggregationServiceFactory = injector.getInstance(AggregationServiceFactory.class);
+        AggregationService aggregationService = aggregationServiceFactory.getAggregationService();
+        ApplicationScope applicationScope =CpNamingUtils.getApplicationScope(applicationId);
+        return aggregationService.sum(applicationScope,CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(),collectionName));
+    }
+
 
     @Override
     public OrganizationInfo getOrganizationForApplication( UUID applicationInfoId ) throws Exception {


[03/10] usergrid git commit: migration

Posted by to...@apache.org.
migration


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

Branch: refs/heads/two-dot-o-dev
Commit: c47b02d41910c524957149dbf2bf8f4a3dff051d
Parents: 81e0fba
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Aug 21 19:20:26 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Aug 21 19:20:26 2015 -0700

----------------------------------------------------------------------
 .../persistence/index/guice/IndexModule.java    |   6 +-
 .../EsIndexMappingMigrationPlugin.java          | 148 +++++++++++++++++++
 .../impl/EsIndexMappingMigrationPluginTest.java |  60 ++++++++
 3 files changed, 212 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/c47b02d4/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
index b22a461..d03bbf8 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/guice/IndexModule.java
@@ -28,6 +28,7 @@ import org.apache.usergrid.persistence.index.*;
 import com.google.inject.AbstractModule;
 
 import org.apache.usergrid.persistence.index.impl.*;
+import org.apache.usergrid.persistence.index.migration.EsIndexMappingMigrationPlugin;
 import org.apache.usergrid.persistence.index.migration.EsIndexMigrationPlugin;
 import org.apache.usergrid.persistence.index.migration.IndexMigration;
 import org.apache.usergrid.persistence.map.guice.MapModule;
@@ -61,8 +62,9 @@ public abstract class IndexModule extends AbstractModule {
 
 
         //wire up the collection migration plugin
-        Multibinder.newSetBinder( binder(), MigrationPlugin.class ).addBinding().to(EsIndexMigrationPlugin.class);
-
+        final Multibinder<MigrationPlugin> plugins = Multibinder.newSetBinder(binder(), MigrationPlugin.class);
+        plugins.addBinding().to(EsIndexMigrationPlugin.class);
+        plugins.addBinding().to(EsIndexMappingMigrationPlugin.class);
 
         //invoke the migration plugin config
         configureMigrationProvider();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c47b02d4/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexMappingMigrationPlugin.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexMappingMigrationPlugin.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexMappingMigrationPlugin.java
new file mode 100644
index 0000000..10acc46
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/migration/EsIndexMappingMigrationPlugin.java
@@ -0,0 +1,148 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.persistence.index.migration;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+import com.google.inject.Inject;
+import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
+import org.apache.usergrid.persistence.core.migration.data.MigrationPlugin;
+import org.apache.usergrid.persistence.core.migration.data.PluginPhase;
+import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.index.impl.EsProvider;
+import org.elasticsearch.action.ActionFuture;
+import org.elasticsearch.action.ListenableActionFuture;
+import org.elasticsearch.action.admin.indices.get.GetIndexRequest;
+import org.elasticsearch.action.admin.indices.get.GetIndexResponse;
+import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Classy class class.
+ */
+public class EsIndexMappingMigrationPlugin implements MigrationPlugin {
+
+    private static final Logger logger = LoggerFactory.getLogger(EsIndexMappingMigrationPlugin.class);
+
+    private final MigrationInfoSerialization migrationInfoSerialization;
+    private final EsProvider provider;
+
+    @Inject
+    public EsIndexMappingMigrationPlugin(
+        final MigrationInfoSerialization migrationInfoSerialization,
+        final EsProvider provider
+    ){
+
+        this.migrationInfoSerialization = migrationInfoSerialization;
+        this.provider = provider;
+    }
+
+    @Override
+    public String getName() {
+        return "index_mapping_migration";
+    }
+
+    @Override
+    public void run(ProgressObserver observer) {
+
+        final int version = migrationInfoSerialization.getVersion(getName());
+
+        if (version == getMaxVersion()) {
+            logger.debug("Skipping Migration Plugin: " + getName());
+            return;
+        }
+
+        try {
+            ActionFuture<GetIndexResponse> responseFuture = provider.getClient().admin().indices().getIndex(new GetIndexRequest());
+            Observable
+                .from(responseFuture)
+                .flatMap(response -> {
+                    List<String> indices = Arrays.asList(response.getIndices());
+                    return Observable.from(indices);
+                })
+
+                .doOnNext(index -> {
+                    createMappings(index);
+                    observer.update(getMaxVersion(), "running update for " + index);
+                })
+                .doOnError(t -> {
+                    observer.failed(getMaxVersion(),"failed to update",t);
+                })
+                .doOnCompleted(() -> {
+                    migrationInfoSerialization.setVersion(getName(), getMaxVersion());
+                    observer.complete();
+                })
+                .subscribe();
+
+
+        }catch (Exception ee){
+            observer.failed(getMaxVersion(),"failed to update",ee);
+            throw new RuntimeException(ee);
+        }
+
+    }
+
+
+    /**
+     * Setup ElasticSearch type mappings as a template that applies to all new indexes.
+     * Applies to all indexes that* start with our prefix.
+     */
+    private void createMappings(final String indexName)  {
+
+        //Added For Graphite Metrics
+        PutMappingResponse pitr = provider.getClient().admin().indices().preparePutMapping( indexName ).setType( "entity" ).setSource(
+            getMappingsContent() ).execute().actionGet();
+        if ( !pitr.isAcknowledged() ) {
+            throw new RuntimeException( "Unable to create default mappings" );
+        }
+    }
+
+
+    /**
+     * Get the content from our mappings file
+     * @return
+     */
+    private String getMappingsContent(){
+        URL url = Resources.getResource("org/apache/usergrid/persistence/index/usergrid-mappings.json");
+        try {
+            return Resources.toString(url, Charsets.UTF_8);
+        }
+        catch ( IOException e ) {
+            throw new RuntimeException( "Unable to read mappings file", e );
+        }
+    }
+
+    @Override
+    public int getMaxVersion() {
+        return 1;
+    }
+
+    @Override
+    public PluginPhase getPhase() {
+        return PluginPhase.BOOTSTRAP;
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/c47b02d4/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsIndexMappingMigrationPluginTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsIndexMappingMigrationPluginTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsIndexMappingMigrationPluginTest.java
new file mode 100644
index 0000000..e5d9380
--- /dev/null
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EsIndexMappingMigrationPluginTest.java
@@ -0,0 +1,60 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.persistence.index.impl;
+
+import com.google.inject.Inject;
+import org.apache.usergrid.persistence.core.migration.data.MigrationInfoSerialization;
+import org.apache.usergrid.persistence.core.migration.data.ProgressObserver;
+import org.apache.usergrid.persistence.core.migration.data.TestProgressObserver;
+import org.apache.usergrid.persistence.core.test.UseModules;
+import org.apache.usergrid.persistence.index.EntityIndexFactory;
+import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.index.migration.EsIndexMappingMigrationPlugin;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Classy class class.
+ */
+
+@RunWith( EsRunner.class )
+@UseModules( { TestIndexModule.class } )
+public class EsIndexMappingMigrationPluginTest extends BaseIT {
+    @Inject
+    public EntityIndexFactory eif;
+    @Inject
+    public MigrationInfoSerialization serialization;
+    @Inject
+    EsProvider provider;
+    @Test
+    public void runMigration(){
+        EsIndexMappingMigrationPlugin plugin = new EsIndexMappingMigrationPlugin(serialization,provider);
+        TestProgressObserver progressObserver = new TestProgressObserver();
+        plugin.run(progressObserver);
+        assertFalse( "Progress observer should not have failed", progressObserver.isFailed() );
+        assertTrue("Progress observer should have update messages", progressObserver.getUpdates().size() > 0);
+
+
+    }
+
+}