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 <[email protected]>
Authored: Wed Aug 26 11:47:31 2015 -0600
Committer: Shawn Feldman <[email protected]>
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 );
 
     }

Reply via email to