You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/03/17 00:35:44 UTC

[01/12] incubator-usergrid git commit: incremental commit for unique index

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-466 03341191a -> b53cb07f3


incremental commit for unique index


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

Branch: refs/heads/USERGRID-466
Commit: 1bdfd108bc5a852404da6708c643bc17ac71ce03
Parents: 710a1a3
Author: Rod Simpson <ro...@rodsimpson.com>
Authored: Mon Mar 9 11:50:57 2015 -0600
Committer: Rod Simpson <ro...@rodsimpson.com>
Committed: Mon Mar 9 11:50:57 2015 -0600

----------------------------------------------------------------------
 .../collection/EntityCollectionManager.java     |  9 +++
 .../persistence/collection/FieldSet.java        | 48 ++++++++++++
 .../cache/CachedEntityCollectionManager.java    | 25 ++++++-
 .../impl/EntityCollectionManagerImpl.java       | 79 +++++++++++++++++---
 .../serialization/impl/FieldSetImpl.java        | 64 ++++++++++++++++
 .../collection/EntityCollectionManagerIT.java   | 58 ++++++++++++++
 6 files changed, 269 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1bdfd108/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
index 4de18fe..6bbe912 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
@@ -54,6 +54,9 @@ public interface EntityCollectionManager {
      * Return the latest versions of the specified entityIds
      */
     public Observable<VersionSet> getLatestVersion( Collection<Id> entityId );
+    
+    
+    public Observable<FieldSet> getAllEntities(Collection<Field> fields);
 
     /**
      * Gets the Id for a field
@@ -62,6 +65,12 @@ public interface EntityCollectionManager {
     public Observable<Id> getIdField(final Field field);
 
     /**
+     * Audit a unique field, and remove any stale entries in the system
+     * @param field The field to audit within this collection scope.
+
+    public Observable<Integer> auditUniqueField(final Field field);
+     */
+    /**
      * Load all the entityIds into the observable entity set
      */
     public Observable<EntitySet> load(Collection<Id> entityIds);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1bdfd108/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/FieldSet.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/FieldSet.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/FieldSet.java
new file mode 100644
index 0000000..c46fa3b
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/FieldSet.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+package org.apache.usergrid.persistence.collection;
+
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.field.Field;
+
+
+/**
+ * Represents a set of entities
+ */
+public interface FieldSet {
+
+    /**
+     * Get the entity from the result set
+     * @param field, Return the entity with the field
+     * @return
+     */
+    public MvccEntity getEntity(Field<?> field);
+
+    /**
+     * Get the number of entities in this set
+     * @return
+     */
+    public int size();
+
+    /**
+     * Return true if the set is empty
+     * @return
+     */
+    public boolean isEmpty();
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1bdfd108/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
index 186aafa..a111f8d 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
@@ -20,13 +20,19 @@
 package org.apache.usergrid.persistence.collection.cache;
 
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
-import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.EntitySet;
-import org.apache.usergrid.persistence.collection.VersionSet;
+import com.netflix.astyanax.MutationBatch;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
+import org.apache.usergrid.persistence.collection.*;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
+import org.apache.usergrid.persistence.collection.serialization.impl.FieldSetImpl;
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -39,8 +45,10 @@ import com.google.common.cache.LoadingCache;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import rx.Observable;
 import rx.functions.Action1;
+import rx.functions.Func1;
 
 
 @Singleton
@@ -74,6 +82,17 @@ public class CachedEntityCollectionManager implements EntityCollectionManager {
                                   .build();
     }
 
+    public Observable<FieldSet> getAllEntities(final Collection<Field> fields) {
+        return rx.Observable.just(fields).map( new Func1<Collection<Field>, FieldSet>() {
+            @Override
+            public FieldSet call( Collection<Field> fields ) {
+
+                    final FieldSet response = new FieldSetImpl(fields.size());
+
+                    return response;
+            }
+        } );
+    }
 
     @Override
     public Observable<Entity> write( final Entity entity ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1bdfd108/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 7c467c6..5505e3f 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -19,18 +19,15 @@
 package org.apache.usergrid.persistence.collection.impl;
 
 
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
+import java.util.*;
 
+import com.netflix.astyanax.MutationBatch;
+import org.apache.usergrid.persistence.collection.*;
+import org.apache.usergrid.persistence.collection.serialization.impl.FieldSetImpl;
+import org.apache.usergrid.persistence.core.rx.ObservableIterator;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.EntityCollectionManager;
-import org.apache.usergrid.persistence.collection.EntitySet;
-import org.apache.usergrid.persistence.collection.MvccEntity;
-import org.apache.usergrid.persistence.collection.VersionSet;
 import org.apache.usergrid.persistence.collection.guice.Write;
 import org.apache.usergrid.persistence.collection.guice.WriteUpdate;
 import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
@@ -65,9 +62,6 @@ import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.model.ColumnFamily;
 import com.netflix.astyanax.model.CqlResult;
 import com.netflix.astyanax.serializers.StringSerializer;
-import org.apache.usergrid.persistence.collection.EntityDeletedFactory;
-import org.apache.usergrid.persistence.collection.EntityVersionCleanupFactory;
-import org.apache.usergrid.persistence.collection.EntityVersionCreatedFactory;
 import org.apache.usergrid.persistence.collection.guice.CollectionTaskExecutor;
 import org.apache.usergrid.persistence.core.task.Task;
 import org.apache.usergrid.persistence.core.task.TaskExecutor;
@@ -293,6 +287,69 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         } );
     }
 
+    @Override
+    public Observable<FieldSet> getAllEntities(final Collection<Field> fields) {
+        return rx.Observable.just(fields).map( new Func1<Collection<Field>, FieldSet>() {
+            @Override
+            public FieldSet call( Collection<Field> fields ) {
+                try {
+
+                    final UUID startTime = UUIDGenerator.newTimeUUID();
+
+                    UniqueValueSet set = uniqueValueSerializationStrategy.load( collectionScope, fields );
+
+
+                    //loop through each field, and construct an entity load
+                    List<Id> entityIds = new ArrayList<>(fields.size());
+                    List<UniqueValue> uniqueValues = new ArrayList<>(fields.size());
+
+                    for(final Field expectedField: fields) {
+
+                        UniqueValue value = set.getValue(expectedField.getName());
+
+                        entityIds.add(value.getEntityId());
+                        uniqueValues.add(value);
+                    }
+
+                    final EntitySet entitySet = entitySerializationStrategy.load(collectionScope, entityIds, startTime);
+
+                    //now loop through and ensure the entities are there.
+                    final MutationBatch deleteBatch = keyspace.prepareMutationBatch();
+
+                    final FieldSetImpl response = new FieldSetImpl(fields.size());
+
+                    for(final UniqueValue expectedUnique: uniqueValues) {
+                        final MvccEntity entity = entitySet.getEntity(expectedUnique.getEntityId());
+
+                        //bad unique value, delete this, it's inconsistent
+                        if(entity == null || !entity.getEntity().isPresent()){
+                            final MutationBatch valueDelete = uniqueValueSerializationStrategy.delete(collectionScope, expectedUnique);
+                            deleteBatch.mergeShallow(valueDelete);
+                            continue;
+                        }
+
+
+                        //else add it to our result set
+                        response.addEntity(expectedUnique.getField(),entity);
+
+                    }
+
+                    //fire and forget, we don't care.  We'll repair it again if we have to
+                    deleteBatch.executeAsync();
+
+                    return response;
+
+
+                }
+                catch ( ConnectionException e ) {
+                    logger.error( "Failed to getIdField", e );
+                    throw new RuntimeException( e );
+                }
+            }
+        } );
+    }
+
+   
 
     @Override
     public Observable<Entity> update( final Entity entity ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1bdfd108/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java
new file mode 100644
index 0000000..241d5c2
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java
@@ -0,0 +1,64 @@
+package org.apache.usergrid.persistence.collection.serialization.impl;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+
+
+import org.apache.usergrid.persistence.collection.FieldSet;
+import org.apache.usergrid.persistence.collection.MvccEntity;
+import org.apache.usergrid.persistence.model.field.Field;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class FieldSetImpl implements FieldSet {
+
+
+    private final Map<Field<?>, MvccEntity> entities;
+
+
+    public FieldSetImpl(
+            final int expectedSize) {
+        this.entities = new HashMap<>( expectedSize );
+    }
+
+
+    public void addEntity(final Field<?> field,  final MvccEntity entity ) {
+        entities.put( field, entity );
+    }
+
+
+    @Override
+    public MvccEntity getEntity( final Field<?> field) {
+        return entities.get( field );
+    }
+
+
+
+
+    @Override
+    public int size() {
+        return entities.size();
+    }
+
+
+    @Override
+    public boolean isEmpty() {
+        return entities.size() == 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1bdfd108/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 5eba979..f33b3d0 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -23,6 +23,9 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.core.guice.ProxyImpl;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -75,6 +78,14 @@ public class EntityCollectionManagerIT {
     private SerializationFig serializationFig;
 
 
+    @Inject
+    private UniqueValueSerializationStrategy uniqueValueSerializationStrategy;
+
+    @Inject
+    @ProxyImpl
+    private MvccEntitySerializationStrategy entitySerializationStrategy;
+
+
     @Test
     public void write() {
 
@@ -743,4 +754,51 @@ public class EntityCollectionManagerIT {
         //override our default
         SetConfigTestBypass.setValueByPass( serializationFig, "getMaxEntitySize", currentMaxSize + "" );
     }
+    
+    @Test
+    public void invalidNameRepair() {
+        
+        //write an entity with a unique field
+        CollectionScope context = 
+                new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
+
+        Entity newEntity = new Entity( new SimpleId( "test" ) );
+        
+        newEntity.setField( new IntegerField( "count", 5, true ) );
+        newEntity.setField( new StringField( "yes", "fred", true ) );
+
+        EntityCollectionManager manager = factory.createCollectionManager( context );
+
+        Observable<Entity> observable = manager.write( newEntity );
+
+        Entity createReturned = observable.toBlocking().lastOrDefault( null );
+
+
+        assertNotNull( "Id was assigned", createReturned.getId() );
+        assertNotNull( "Version was assigned", createReturned.getVersion() );
+
+
+        Observable<Entity> loadObservable = manager.load( createReturned.getId() );
+
+        Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null );
+
+        assertEquals( "Same value", createReturned, loadReturned );
+        //load an entity by it's unique field
+        
+        //verify the entity is correct.
+        
+        //use the entity serializationStrategy to remove the entity data.
+        
+        //try to load via the unique field
+        
+        //verify no entity returned
+        
+        //user the unique serialization to verify it's been deleted from cassandra
+        
+
+        
+                
+                
+                
+    }
 }


[11/12] incubator-usergrid git commit: Applied complains and refactored names to make the code clearer and checking for more null pointers. Removed redundant test.

Posted by sf...@apache.org.
Applied complains and refactored names to make the code clearer and checking for more null pointers.
Removed redundant test.


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

Branch: refs/heads/USERGRID-466
Commit: b0a07baa354f790d820d1a32b435502ef5b062a9
Parents: 24a48a7
Author: GERey <gr...@apigee.com>
Authored: Fri Mar 13 15:23:15 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Fri Mar 13 15:23:15 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 10 ++-
 .../usergrid/persistence/EntityManager.java     |  5 +-
 .../cassandra/EntityManagerImpl.java            |  2 +-
 .../usergrid/persistence/EntityManagerIT.java   | 23 -------
 .../collection/EntityCollectionManager.java     | 10 +--
 .../cache/CachedEntityCollectionManager.java    | 17 +-----
 .../impl/EntityCollectionManagerImpl.java       | 15 +++--
 .../serialization/impl/FieldSetImpl.java        | 64 --------------------
 .../serialization/impl/MutableFieldSet.java     | 63 +++++++++++++++++++
 .../collection/EntityCollectionManagerIT.java   |  7 +--
 .../services/AbstractCollectionService.java     | 10 +--
 .../services/AbstractConnectionsService.java    |  6 +-
 12 files changed, 100 insertions(+), 132 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/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 a108f25..e5223f0 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
@@ -809,7 +809,7 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Entity getAllEntityFromFields( String collectionType, String aliasType ){
+    public Entity getUniqueEntityFromAlias( String collectionType, String aliasType ){
         String collName = Schema.defaultCollectionName( collectionType );
 
         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
@@ -824,8 +824,13 @@ public class CpEntityManager implements EntityManager {
 
         StringField uniqueLookupRepairField =  new StringField( propertyName, aliasType.toString());
 
-        Observable<FieldSet> fieldSetObservable = ecm.getAllEntities( Arrays.<Field>asList( uniqueLookupRepairField) );
+        Observable<FieldSet> fieldSetObservable = ecm.getEntitiesFromFields(
+            Arrays.<Field>asList( uniqueLookupRepairField ) );
 
+        if(fieldSetObservable == null){
+            logger.debug( "Couldn't return the observable based on unique entities." );
+            return null;
+        }
         FieldSet fieldSet = fieldSetObservable.toBlocking().last();
 
         repairedEntityGet.stop();
@@ -2284,7 +2289,6 @@ public class CpEntityManager implements EntityManager {
             getApplicationScope().getApplication(), collectionName);
 
         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
-//TODO: can't we just sub in the getEntityRepair method here so for every read of a uniqueEntityField we can verify it is correct?
 
         //convert to a string, that's what we store
         final Id results = ecm.getIdField( new StringField(

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 5657d4f..65fac8d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -713,6 +713,5 @@ public interface EntityManager {
      */
     public Health getIndexHealth();
 
-    public Entity getAllEntityFromFields( String aliasType, String aliasValue );
-
-    }
+    public Entity getUniqueEntityFromAlias( String aliasType, String aliasValue );
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index 3993285..e505b8e 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -2949,7 +2949,7 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
-    public Entity getAllEntityFromFields( final String aliasType, final String aliasValue ) {
+    public Entity getUniqueEntityFromAlias( final String aliasType, final String aliasValue ) {
         throw new UnsupportedOperationException( "Not supported." );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
index cd08607..4896fc1 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
@@ -579,27 +579,4 @@ public class EntityManagerIT extends AbstractCoreIT {
 
         assertNotNull( em.get( user.getUuid() ));
     }
-
-    @Test
-    public void testInvalidNameRepair() throws Exception {
-        LOG.info("EntityManagerIT.testInvalidNameReapir");
-
-        EntityManager em = app.getEntityManager();
-
-        Map<String, Object> properties = new LinkedHashMap<String, Object>();
-        properties.put( "name", "XR-51B" );
-        properties.put( "fuel", "Nutrinox" );
-
-        Entity user = em.create( "robot", properties );
-        assertNotNull( user );
-
-        em.refreshIndex();
-
-        assertNotNull( em.get( user.getUuid() ));
-
-        em.delete( user );
-
-        assertNull( em.get( user.getUuid() ));
-
-    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
index 6bbe912..35fc5d4 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/EntityCollectionManager.java
@@ -54,9 +54,9 @@ public interface EntityCollectionManager {
      * Return the latest versions of the specified entityIds
      */
     public Observable<VersionSet> getLatestVersion( Collection<Id> entityId );
-    
-    
-    public Observable<FieldSet> getAllEntities(Collection<Field> fields);
+
+
+    public Observable<FieldSet> getEntitiesFromFields( Collection<Field> fields );
 
     /**
      * Gets the Id for a field
@@ -77,12 +77,12 @@ public interface EntityCollectionManager {
 
     /**
      * Takes the change and reloads an entity with all changes applied in this entity applied.
-     * The resulting entity from calling load will be the previous version of this entity plus 
+     * The resulting entity from calling load will be the previous version of this entity plus
      * the entity in this object applied to it.
      */
     public Observable<Entity> update ( Entity entity );
 
-    /** 
+    /**
      * Returns health of entity data store.
      */
     public Health getHealth();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
index d33f762..7d229e6 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
@@ -20,19 +20,10 @@
 package org.apache.usergrid.persistence.collection.cache;
 
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
-import java.util.UUID;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 
-import com.netflix.astyanax.MutationBatch;
-import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import org.apache.usergrid.persistence.collection.*;
-import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
-import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
-import org.apache.usergrid.persistence.collection.serialization.impl.FieldSetImpl;
 import org.apache.usergrid.persistence.core.util.Health;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.Id;
@@ -40,15 +31,11 @@ import org.apache.usergrid.persistence.model.field.Field;
 
 import com.google.common.cache.Cache;
 import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import rx.Observable;
 import rx.functions.Action1;
-import rx.functions.Func1;
 
 
 @Singleton
@@ -83,8 +70,8 @@ public class CachedEntityCollectionManager implements EntityCollectionManager {
     }
 
     @Override
-    public Observable<FieldSet> getAllEntities(final Collection<Field> fields) {
-        return targetEntityCollectionManager.getAllEntities( fields );
+    public Observable<FieldSet> getEntitiesFromFields( final Collection<Field> fields ) {
+        return targetEntityCollectionManager.getEntitiesFromFields( fields );
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 7db34aa..3c89280 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -23,8 +23,8 @@ import java.util.*;
 
 import com.netflix.astyanax.MutationBatch;
 import org.apache.usergrid.persistence.collection.*;
-import org.apache.usergrid.persistence.collection.serialization.impl.FieldSetImpl;
-import org.apache.usergrid.persistence.core.rx.ObservableIterator;
+import org.apache.usergrid.persistence.collection.serialization.impl.MutableFieldSet;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -41,7 +41,6 @@ import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteCommit;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteOptimisticVerify;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteStart;
 import org.apache.usergrid.persistence.collection.mvcc.stage.write.WriteUniqueVerify;
-import org.apache.usergrid.persistence.collection.serialization.SerializationFig;
 import org.apache.usergrid.persistence.collection.serialization.UniqueValue;
 import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
 import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
@@ -294,7 +293,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
      * @return
      */
     @Override
-    public Observable<FieldSet> getAllEntities(final Collection<Field> fields) {
+    public Observable<FieldSet> getEntitiesFromFields( final Collection<Field> fields ) {
         return rx.Observable.just(fields).map( new Func1<Collection<Field>, FieldSet>() {
             @Override
             public FieldSet call( Collection<Field> fields ) {
@@ -307,7 +306,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
                     //Short circut if we don't have any uniqueValues from the given fields.
                     if(!set.iterator().hasNext()){
-                        return new FieldSetImpl( 0 );
+                        return new MutableFieldSet( 0 );
                     }
 
 
@@ -319,6 +318,10 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
                         UniqueValue value = set.getValue(expectedField.getName());
 
+                        if(value ==null){
+                            logger.debug( "Field does not correspond to a unique value" );
+                        }
+
                         entityIds.add(value.getEntityId());
                         uniqueValues.add(value);
                     }
@@ -329,7 +332,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
                     //now loop through and ensure the entities are there.
                     final MutationBatch deleteBatch = keyspace.prepareMutationBatch();
 
-                    final FieldSetImpl response = new FieldSetImpl(fields.size());
+                    final MutableFieldSet response = new MutableFieldSet(fields.size());
 
                     for(final UniqueValue expectedUnique: uniqueValues) {
                         final MvccEntity entity = entitySet.getEntity(expectedUnique.getEntityId());

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java
deleted file mode 100644
index 241d5c2..0000000
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/FieldSetImpl.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package org.apache.usergrid.persistence.collection.serialization.impl;/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  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.
- */
-
-
-import org.apache.usergrid.persistence.collection.FieldSet;
-import org.apache.usergrid.persistence.collection.MvccEntity;
-import org.apache.usergrid.persistence.model.field.Field;
-
-import java.util.HashMap;
-import java.util.Map;
-
-
-public class FieldSetImpl implements FieldSet {
-
-
-    private final Map<Field<?>, MvccEntity> entities;
-
-
-    public FieldSetImpl(
-            final int expectedSize) {
-        this.entities = new HashMap<>( expectedSize );
-    }
-
-
-    public void addEntity(final Field<?> field,  final MvccEntity entity ) {
-        entities.put( field, entity );
-    }
-
-
-    @Override
-    public MvccEntity getEntity( final Field<?> field) {
-        return entities.get( field );
-    }
-
-
-
-
-    @Override
-    public int size() {
-        return entities.size();
-    }
-
-
-    @Override
-    public boolean isEmpty() {
-        return entities.size() == 0;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MutableFieldSet.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MutableFieldSet.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MutableFieldSet.java
new file mode 100644
index 0000000..ae921a7
--- /dev/null
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MutableFieldSet.java
@@ -0,0 +1,63 @@
+package org.apache.usergrid.persistence.collection.serialization.impl;/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  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.
+ */
+
+
+import org.apache.usergrid.persistence.collection.FieldSet;
+import org.apache.usergrid.persistence.collection.MvccEntity;
+import org.apache.usergrid.persistence.model.field.Field;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class MutableFieldSet implements FieldSet {
+
+
+    private final Map<Field<?>, MvccEntity> entities;
+
+
+    public MutableFieldSet( final int expectedSize ) {
+        this.entities = new HashMap<>( expectedSize );
+    }
+
+
+    public void addEntity(final Field<?> field,  final MvccEntity entity ) {
+        entities.put( field, entity );
+    }
+
+
+    @Override
+    public MvccEntity getEntity( final Field<?> field) {
+        return entities.get( field );
+    }
+
+
+
+
+    @Override
+    public int size() {
+        return entities.size();
+    }
+
+
+    @Override
+    public boolean isEmpty() {
+        return entities.size() == 0;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index 46e844d..a52486e 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -20,7 +20,6 @@ package org.apache.usergrid.persistence.collection;
 
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
 
@@ -780,12 +779,12 @@ public class EntityCollectionManagerIT {
 
         Entity createReturned = observable.toBlocking().lastOrDefault( null );
 
-
+        assertNotNull( "Need entity to be created before proceeding", createReturned );
         assertNotNull( "Id was assigned", createReturned.getId() );
         assertNotNull( "Version was assigned", createReturned.getVersion() );
 
         FieldSet
-            fieldResults = manager.getAllEntities( Arrays.<Field>asList( expectedInteger) ).toBlocking().last();
+            fieldResults = manager.getEntitiesFromFields( Arrays.<Field>asList( expectedInteger ) ).toBlocking().last();
 
         assertEquals(1,fieldResults.size());
 
@@ -800,7 +799,7 @@ public class EntityCollectionManagerIT {
 
         //try to load via the unique field, should have triggered repair
         final FieldSet
-            results = manager.getAllEntities( Arrays.<Field>asList( expectedInteger) ).toBlocking().last();
+            results = manager.getEntitiesFromFields( Arrays.<Field>asList( expectedInteger ) ).toBlocking().last();
 
 
         //verify no entity returned

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index e404321..dcd7557 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -72,7 +72,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
+        Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name );
         if ( entity != null ) {
             entity = importEntity( request, entity );
         }
@@ -144,7 +144,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
+        Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name );
 
         if ( entity == null ) {
             logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );
@@ -287,7 +287,7 @@ public class AbstractCollectionService extends AbstractService {
         }
 
        // EntityRef ref = em.getAlias( getEntityType(), name );
-        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
+        Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name );
         if ( entity == null ) {
             // null entity ref means we tried to put a non-existing entity
             // before we create a new entity for it, we should check for permission
@@ -431,7 +431,7 @@ public class AbstractCollectionService extends AbstractService {
             return super.postItemByName( context, name );
         }
 
-        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
+        Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name );
         if ( entity == null ) {
             throw new ServiceResourceNotFoundException( context );
         }
@@ -485,7 +485,7 @@ public class AbstractCollectionService extends AbstractService {
             return getItemByName( context, name );
         }
 
-        Entity entity = em.getAllEntityFromFields(getEntityType(), name );
+        Entity entity = em.getUniqueEntityFromAlias( getEntityType(), name );
         if ( entity == null ) {
             throw new ServiceResourceNotFoundException( context );
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b0a07baa/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
index 8a95e5c..1e4c4b8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
@@ -265,7 +265,7 @@ public class AbstractConnectionsService extends AbstractService {
 
             //TODO T.N. USERGRID-1919 actually validate this is connected
 
-            Entity entity = em.getAllEntityFromFields( query.getEntityType(),name );
+            Entity entity = em.getUniqueEntityFromAlias( query.getEntityType(), name );
             if ( entity == null ) {
                 return null;
             }
@@ -361,7 +361,7 @@ public class AbstractConnectionsService extends AbstractService {
             if ( query.containsSingleNameOrEmailIdentifier() ) {
                 String name = query.getSingleNameOrEmailIdentifier();
 
-                entity = em.getAllEntityFromFields( query.getEntityType(), name );
+                entity = em.getUniqueEntityFromAlias( query.getEntityType(), name );
                 if ( entity == null ) {
                     throw new ServiceResourceNotFoundException( context );
                 }
@@ -472,7 +472,7 @@ public class AbstractConnectionsService extends AbstractService {
                 nameProperty = "name";
             }
 
-            Entity entity = em.getAllEntityFromFields( query.getEntityType(), name );
+            Entity entity = em.getUniqueEntityFromAlias( query.getEntityType(), name );
             if ( entity == null ) {
                 throw new ServiceResourceNotFoundException( context );
             }


[05/12] incubator-usergrid git commit: Shorted to just get the Entity by Alias. Corrected spelling Added test that does a get, delete, get to make sure entities are removed. Refactored entities to getEntityByAlias Added getEntityByAlias that works based of

Posted by sf...@apache.org.
Shorted to just get the Entity by Alias.
Corrected spelling
Added test that does a get,delete,get to make sure entities are removed.
Refactored entities to getEntityByAlias
Added getEntityByAlias that works based off of existing entities.


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

Branch: refs/heads/USERGRID-466
Commit: a60d6aa31f089a8b63be7b66f1aed0224837c22b
Parents: d4eb288
Author: GERey <gr...@apigee.com>
Authored: Wed Mar 11 15:36:11 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Mar 11 15:36:11 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 30 ++++++++++++++++++--
 .../usergrid/persistence/EntityManager.java     |  4 ++-
 .../cassandra/EntityManagerImpl.java            |  6 ++--
 .../usergrid/persistence/EntityManagerIT.java   | 24 ++++++++++++++++
 .../UniqueValueSerializationStrategyImpl.java   |  2 +-
 .../services/AbstractCollectionService.java     | 14 ++++-----
 6 files changed, 62 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/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 4b62fbe..4ed37e5 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
@@ -730,11 +730,30 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields(CollectionScope collectionScope,Collection<Field> fields){
-        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
-        return ecm.getAllEntities( fields );
+    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue ){
+        return null;
+//        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( aliasType );
+//
+//        Schema.
+//        return ecm.getAllEntities( aliasValue );
+    }
+
+    @Override
+    public Entity getEntityByAlias(String collectionType, String aliasType) throws Exception {
+
+        EntityRef newEntityRef = getAlias(collectionType,aliasType);
+
+        if(newEntityRef == null) {
+            return null;
+        }
+
+        return get( newEntityRef );
+
+
+
     }
 
+
     @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {
 
@@ -2133,11 +2152,16 @@ public class CpEntityManager implements EntityManager {
             getApplicationScope().getApplication(), collectionName);
 
         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
+//TODO: can't we just sub in the getEntityRepair method here so for every read of a uniqueEntityField we can verify it is correct?
 
         //convert to a string, that's what we store
         final Id results = ecm.getIdField( new StringField(
                 propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null );
 
+        Observable<FieldSet> fieldSetObservable = ecm.getAllEntities( Arrays.<Field>asList( new StringField( propertyName, propertyValue.toString() ) );
+
+        FieldSet fieldSet = fieldSetObservable.toBlocking().last();
+        fieldSet.
         return results;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 459032c..4b85c0d 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -98,6 +98,8 @@ public interface EntityManager {
 
     public void createApplicationCollection( String entityType ) throws Exception;
 
+    Entity getEntityByAlias( String collectionType, String aliasType ) throws Exception;
+
     public EntityRef getAlias( String aliasType, String alias ) throws Exception;
 
     /**
@@ -717,6 +719,6 @@ public interface EntityManager {
      */
     public Health getIndexHealth();
 
-    public Observable<FieldSet> getAllEntityFromFields(CollectionScope collectionScope,Collection<Field> fields);
+    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue );
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index adf106a..42a588c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -69,7 +69,6 @@ import org.apache.usergrid.persistence.SimpleRoleRef;
 import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.cassandra.CounterUtils.AggregateCounterSelection;
 import org.apache.usergrid.persistence.cassandra.util.TraceParticipant;
-import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.FieldSet;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Event;
@@ -85,7 +84,6 @@ import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.index.query.Query.CounterFilterPredicate;
 import org.apache.usergrid.persistence.index.query.Query.Level;
-import org.apache.usergrid.persistence.model.field.Field;
 import org.apache.usergrid.persistence.schema.CollectionInfo;
 import org.apache.usergrid.utils.ClassUtils;
 import org.apache.usergrid.utils.CompositeUtils;
@@ -2954,8 +2952,8 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields( final CollectionScope collectionScope,
-                                                        final Collection<Field> fields ) {
+    public Observable<FieldSet> getAllEntityFromFields( final String aliasType,
+                                                        final String aliasValue ) {
         throw new UnsupportedOperationException( "Not supported." );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
index f8c667d..cd08607 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityManagerIT.java
@@ -44,6 +44,7 @@ import org.apache.usergrid.utils.UUIDUtils;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
 
@@ -578,4 +579,27 @@ public class EntityManagerIT extends AbstractCoreIT {
 
         assertNotNull( em.get( user.getUuid() ));
     }
+
+    @Test
+    public void testInvalidNameRepair() throws Exception {
+        LOG.info("EntityManagerIT.testInvalidNameReapir");
+
+        EntityManager em = app.getEntityManager();
+
+        Map<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put( "name", "XR-51B" );
+        properties.put( "fuel", "Nutrinox" );
+
+        Entity user = em.create( "robot", properties );
+        assertNotNull( user );
+
+        em.refreshIndex();
+
+        assertNotNull( em.get( user.getUuid() ));
+
+        em.delete( user );
+
+        assertNull( em.get( user.getUuid() ));
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
index be95b08..cf84215 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
@@ -176,7 +176,7 @@ public class UniqueValueSerializationStrategyImpl implements UniqueValueSerializ
             throws ConnectionException {
 
         Preconditions.checkNotNull( fields, "fields are required" );
-        Preconditions.checkArgument( fields.size() > 0, "More than 1 field msut be specified" );
+        Preconditions.checkArgument( fields.size() > 0, "More than 1 field must be specified" );
 
 
         final List<ScopedRowKey<CollectionPrefixedKey<Field>>> keys = new ArrayList<>( fields.size() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a60d6aa3/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index c3be45f..1117fbc 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -76,11 +76,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entityRef = em.getAlias( getEntityType(), name );
-        if ( entityRef == null ) {
-            return null;
-        }
-        Entity entity = em.get( entityRef );
+        Entity entity = em.getEntityByAlias( getEntityType(), name );
         if ( entity != null ) {
             entity = importEntity( request, entity );
         }
@@ -152,7 +148,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entity = em.getAlias( getEntityType(), name );
+        EntityRef entity = em.get( getEntityType(), name );
 
         if ( entity == null ) {
             logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );
@@ -178,7 +174,7 @@ public class AbstractCollectionService extends AbstractService {
     /*
      * Level level = Level.REFS; if (isEmpty(parameters)) {
      * level = Level.ALL_PROPERTIES; }
-     * 
+     *
      * Results results = em.searchCollectionForProperty(owner,
      * getCollectionName(), null, nameProperty, name, null, null, 1, level);
      * EntityRef entity = results.getRef();
@@ -248,9 +244,9 @@ public class AbstractCollectionService extends AbstractService {
         }
 
         logger.debug("Limiting collection to " + Query.DEFAULT_LIMIT);
-        int count = Query.DEFAULT_LIMIT; 
+        int count = Query.DEFAULT_LIMIT;
 
-        Results r = em.getCollection( context.getOwner(), context.getCollectionName(), 
+        Results r = em.getCollection( context.getOwner(), context.getCollectionName(),
             null, count, Level.ALL_PROPERTIES, isCollectionReversed( context ) );
 
         importEntities( context, r );


[10/12] incubator-usergrid git commit: [USERGRID-396] Added a timer to track how long repairing the entities takes. Fixed params in entity manager. Removed getEntityByAlias as it was just a filler method and is no longer used. Removed some useless commen

Posted by sf...@apache.org.
[USERGRID-396] Added a timer to track how long repairing the entities takes.
Fixed params in entity manager.
Removed getEntityByAlias as it was just a filler method and is no longer used.
Removed some useless comments in abstract collection service.


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

Branch: refs/heads/USERGRID-466
Commit: 24a48a756dbd56094a6c75cab8befc169b730776
Parents: c45a3ed
Author: GERey <gr...@apigee.com>
Authored: Fri Mar 13 11:07:06 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Fri Mar 13 11:07:06 2015 -0700

----------------------------------------------------------------------
 .../usergrid/corepersistence/CpEntityManager.java  | 17 +++++------------
 .../apache/usergrid/persistence/EntityManager.java | 15 ++++-----------
 .../persistence/cassandra/EntityManagerImpl.java   |  7 -------
 .../services/AbstractCollectionService.java        |  4 ----
 4 files changed, 9 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24a48a75/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 0f4fdc9..a108f25 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
@@ -207,6 +207,7 @@ public class CpEntityManager implements EntityManager {
     private Timer entGetEntityCountersTimer;
     private Timer esIndexEntityCollectionTimer;
     private Timer entRevokeRolePermissionsTimer;
+    private Timer entGetRepairedEntityTimer;
 
     //    /** Short-term cache to keep us from reloading same Entity during single request. */
 //    private LoadingCache<EntityScope, org.apache.usergrid.persistence.model.entity.Entity> entityCache;
@@ -267,6 +268,8 @@ public class CpEntityManager implements EntityManager {
             .getTimer( CpEntityManager.class, "cp.entity.es.index.entity.to.collection.timer" );
         this.entRevokeRolePermissionsTimer =
             this.metricsFactory.getTimer( CpEntityManager.class, "cp.entity.revoke.role.permissions.timer");
+        this.entGetRepairedEntityTimer = this.metricsFactory
+            .getTimer( CpEntityManager.class, "get.repaired.entity.timer" );
 
         // set to false for now
         this.skipAggregateCounters = false;
@@ -814,6 +817,7 @@ public class CpEntityManager implements EntityManager {
 
         String propertyName = Schema.getDefaultSchema().aliasProperty( collName );
 
+        Timer.Context repairedEntityGet = entGetRepairedEntityTimer.time();
 
         final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
         //TODO: can't we just sub in the getEntityRepair method here so for every read of a uniqueEntityField we can verify it is correct?
@@ -824,6 +828,7 @@ public class CpEntityManager implements EntityManager {
 
         FieldSet fieldSet = fieldSetObservable.toBlocking().last();
 
+        repairedEntityGet.stop();
         if(fieldSet.isEmpty()) {
             return null;
         }
@@ -832,18 +837,6 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Entity getEntityByAlias(String collectionType, String aliasType) throws Exception {
-        EntityRef newEntityRef = getAlias(collectionType,aliasType);
-
-        if(newEntityRef == null) {
-            return null;
-        }
-
-        return get( newEntityRef );
-    }
-
-
-    @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {
 
         return getAlias( new SimpleEntityRef( Application.ENTITY_TYPE, applicationId ), aliasType, alias );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24a48a75/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index eb6379b..5657d4f 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -17,9 +17,6 @@
 package org.apache.usergrid.persistence;
 
 
-import org.apache.usergrid.persistence.collection.CollectionScope;
-import org.apache.usergrid.persistence.collection.FieldSet;
-import org.apache.usergrid.persistence.collection.MvccEntity;
 import org.apache.usergrid.persistence.index.query.Query;
 import java.nio.ByteBuffer;
 import java.util.Collection;
@@ -28,7 +25,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import me.prettyprint.hector.api.mutation.Mutator;
-import rx.Observable;
 
 import org.apache.usergrid.persistence.cassandra.CassandraService;
 import org.apache.usergrid.persistence.cassandra.GeoIndexManager;
@@ -38,7 +34,6 @@ import org.apache.usergrid.persistence.entities.Role;
 import org.apache.usergrid.persistence.index.query.CounterResolution;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query.Level;
-import org.apache.usergrid.persistence.model.field.Field;
 
 
 /**
@@ -99,14 +94,12 @@ public interface EntityManager {
 
     public void createApplicationCollection( String entityType ) throws Exception;
 
-    Entity getEntityByAlias( String collectionType, String aliasType ) throws Exception;
-
     public EntityRef getAlias( String aliasType, String alias ) throws Exception;
 
     /**
      * Get the entity ref from the value
      *
-     * @param ownerId The owner Id of the collection
+     * @param ownerRef The owner Id of the collection
      * @param collectionName The name of the collection
      * @param aliasValue The value of the alias
      */
@@ -118,7 +111,7 @@ public interface EntityManager {
     /**
      * Get aliases from the index with the given value
      *
-     * @param ownerId The id of the collection owner
+     * @param ownerRef The id of the collection owner
      * @param collectionName The name of the collection
      * @param aliases The alias property
      */
@@ -454,7 +447,7 @@ public interface EntityManager {
      * Gets the entities of the specified type connected to the specified entity, optionally
      * matching the specified connection types and/or entity types. Returns a list of entity ids.
      *
-     * @param entityId an entity reference
+     * @param entityRef an entity reference
      * @param connectionType type of connection or null.
      * @param connectedEntityType type of entity or null.
      *
@@ -471,7 +464,7 @@ public interface EntityManager {
      * <p/>
      * e.g. "get users who have favorited this place"
      *
-     * @param entityId an entity reference
+     * @param entityRef an entity reference
      * @param connectionType type of connection or null.
      * @param connectedEntityType type of entity or null.
      *

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24a48a75/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index a019e86..3993285 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -1771,13 +1771,6 @@ public class EntityManagerImpl implements EntityManager {
         batchExecute( m, CassandraService.RETRY_COUNT );
     }
 
-
-    @Override
-    public Entity getEntityByAlias( final String collectionType, final String aliasType ) throws Exception {
-        throw new UnsupportedOperationException("Not supported.");
-    }
-
-
     @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {
         return getAlias( new SimpleEntityRef(Application.ENTITY_TYPE, applicationId), aliasType, alias );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/24a48a75/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index 0820737..e404321 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -46,13 +46,9 @@ public class AbstractCollectionService extends AbstractService {
 
 
     public AbstractCollectionService() {
-        // addSet("indexes");
         declareMetadataType( "indexes" );
     }
 
-    // cname/id/
-
-
     @Override
     public Entity getEntity( ServiceRequest request, UUID uuid ) throws Exception {
         if ( !isRootService() ) {


[08/12] incubator-usergrid git commit: [USERGRID-396] Everywhere that an alias is used, we now do the repair entity retrieval.

Posted by sf...@apache.org.
[USERGRID-396] Everywhere that an alias is used, we now do the repair entity retrieval.


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

Branch: refs/heads/USERGRID-466
Commit: 4c0102e678d67e235d877654f60ec9947e08c160
Parents: a6929ab
Author: GERey <gr...@apigee.com>
Authored: Thu Mar 12 15:40:42 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Thu Mar 12 15:40:42 2015 -0700

----------------------------------------------------------------------
 .../services/AbstractCollectionService.java     | 24 +++++-------
 .../services/AbstractConnectionsService.java    | 39 +++++++-------------
 2 files changed, 22 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4c0102e6/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index 26eb6b9..0820737 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -148,7 +148,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entity = em.getAlias( getEntityType(), name );
+        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
 
         if ( entity == null ) {
             logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );
@@ -165,8 +165,7 @@ public class AbstractCollectionService extends AbstractService {
         }
 
         if ( !context.moreParameters() ) {
-            entity = em.get( entity );
-            entity = importEntity( context, ( Entity ) entity );
+            entity = importEntity( context, entity );
         }
 
         checkPermissionsForEntity( context, entity );
@@ -291,9 +290,9 @@ public class AbstractCollectionService extends AbstractService {
             return getItemByName( context, name );
         }
 
-        EntityRef ref = em.getAlias( getEntityType(), name );
-        Entity entity;
-        if ( ref == null ) {
+       // EntityRef ref = em.getAlias( getEntityType(), name );
+        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
+        if ( entity == null ) {
             // null entity ref means we tried to put a non-existing entity
             // before we create a new entity for it, we should check for permission
             checkPermissionsForCollection(context);
@@ -305,7 +304,6 @@ public class AbstractCollectionService extends AbstractService {
             entity = em.create( getEntityType(), properties );
         }
         else {
-            entity = em.get( ref );
             entity = importEntity( context, entity );
             checkPermissionsForEntity( context, entity );
             updateEntity( context, entity );
@@ -437,12 +435,12 @@ public class AbstractCollectionService extends AbstractService {
             return super.postItemByName( context, name );
         }
 
-        EntityRef ref = em.getAlias( getEntityType(), name );
-        if ( ref == null ) {
+        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
+        if ( entity == null ) {
             throw new ServiceResourceNotFoundException( context );
         }
 
-        return postItemById( context, ref.getUuid() );
+        return postItemById( context, entity.getUuid() );
     }
 
 
@@ -491,11 +489,7 @@ public class AbstractCollectionService extends AbstractService {
             return getItemByName( context, name );
         }
 
-        EntityRef ref = em.getAlias( getEntityType(), name );
-        if ( ref == null ) {
-            throw new ServiceResourceNotFoundException( context );
-        }
-        Entity entity = em.get( ref );
+        Entity entity = em.getAllEntityFromFields(getEntityType(), name );
         if ( entity == null ) {
             throw new ServiceResourceNotFoundException( context );
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/4c0102e6/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
index 72be0a2..8a95e5c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
@@ -172,13 +172,13 @@ public class AbstractConnectionsService extends AbstractService {
         Results r = null;
 
         if ( connecting() ) {
-            r = em.getConnectingEntities( 
-                new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()), 
+            r = em.getConnectingEntities(
+                new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
                 context.getCollectionName(), null, Level.ALL_PROPERTIES );
         }
         else {
-            r = em.getConnectedEntities( 
-                new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()), 
+            r = em.getConnectedEntities(
+                new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
                 context.getCollectionName(), null, Level.ALL_PROPERTIES );
         }
 
@@ -239,7 +239,7 @@ public class AbstractConnectionsService extends AbstractService {
             throw new ServiceResourceNotFoundException( context );
         }
 
-        if ( results.size() == 1 && !em.isConnectionMember( 
+        if ( results.size() == 1 && !em.isConnectionMember(
                 context.getOwner(), context.getCollectionName(), results.getEntity() ) ) {
             throw new ServiceResourceNotFoundException( context );
         }
@@ -263,14 +263,9 @@ public class AbstractConnectionsService extends AbstractService {
                 nameProperty = "name";
             }
 
-            EntityRef ref = em.getAlias( query.getEntityType(), name );
-            if ( ref == null ) {
-                return null;
-            }
-
             //TODO T.N. USERGRID-1919 actually validate this is connected
 
-            Entity entity = em.get( ref );
+            Entity entity = em.getAllEntityFromFields( query.getEntityType(),name );
             if ( entity == null ) {
                 return null;
             }
@@ -294,7 +289,7 @@ public class AbstractConnectionsService extends AbstractService {
         }
 
 //        query.setLimit( count );
-        // usergrid-2389: User defined limit in the query is ignored. Fixed it by following 
+        // usergrid-2389: User defined limit in the query is ignored. Fixed it by following
         // same style in AstractCollectionService
         query.setLimit( query.getLimit( count ) );
         query.setResultsLevel( level );
@@ -309,11 +304,11 @@ public class AbstractConnectionsService extends AbstractService {
             else {
 //            	r = em.getConnectingEntities( context.getOwner().getUuid(), query.getConnectionType(),
 //            			query.getEntityType(), level );
-                // usergrid-2389: User defined limit in the query is ignored. Fixed it by adding 
+                // usergrid-2389: User defined limit in the query is ignored. Fixed it by adding
                 // the limit to the method parameter downstream.
-            	r = em.getConnectingEntities( 
-                    new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()), 
-                    query.getConnectionType(),query.getEntityType(), level , query.getLimit()); 
+            	r = em.getConnectingEntities(
+                    new SimpleEntityRef( context.getOwner().getType(), context.getOwner().getUuid()),
+                    query.getConnectionType(),query.getEntityType(), level , query.getLimit());
             }
         }
         else {
@@ -366,11 +361,7 @@ public class AbstractConnectionsService extends AbstractService {
             if ( query.containsSingleNameOrEmailIdentifier() ) {
                 String name = query.getSingleNameOrEmailIdentifier();
 
-                EntityRef ref = em.getAlias( query.getEntityType(), name );
-                if ( ref == null ) {
-                    throw new ServiceResourceNotFoundException( context );
-                }
-                entity = em.get( ref );
+                entity = em.getAllEntityFromFields( query.getEntityType(), name );
                 if ( entity == null ) {
                     throw new ServiceResourceNotFoundException( context );
                 }
@@ -481,11 +472,7 @@ public class AbstractConnectionsService extends AbstractService {
                 nameProperty = "name";
             }
 
-            EntityRef ref = em.getAlias( query.getEntityType(), name );
-            if ( ref == null ) {
-                throw new ServiceResourceNotFoundException( context );
-            }
-            Entity entity = em.get( ref );
+            Entity entity = em.getAllEntityFromFields( query.getEntityType(), name );
             if ( entity == null ) {
                 throw new ServiceResourceNotFoundException( context );
             }


[02/12] incubator-usergrid git commit: Filled out test that should prove the issue.

Posted by sf...@apache.org.
Filled out test that should prove the issue.


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

Branch: refs/heads/USERGRID-466
Commit: 5411fef0e80d848639fc140e3b6e48383cb05163
Parents: 1bdfd10
Author: GERey <gr...@apigee.com>
Authored: Mon Mar 9 13:09:49 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Mon Mar 9 13:09:49 2015 -0700

----------------------------------------------------------------------
 .../collection/EntityCollectionManagerIT.java   | 55 +++++++++++++-------
 1 file changed, 35 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5411fef0/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index f33b3d0..a52a9bb 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -25,6 +25,7 @@ import java.util.UUID;
 
 import org.apache.usergrid.persistence.collection.mvcc.MvccEntitySerializationStrategy;
 import org.apache.usergrid.persistence.collection.serialization.UniqueValueSerializationStrategy;
+import org.apache.usergrid.persistence.collection.serialization.UniqueValueSet;
 import org.apache.usergrid.persistence.core.guice.ProxyImpl;
 import org.junit.Rule;
 import org.junit.Test;
@@ -51,6 +52,7 @@ import org.apache.usergrid.persistence.model.field.StringField;
 
 import com.fasterxml.uuid.UUIDComparator;
 import com.google.inject.Inject;
+import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import rx.Observable;
 
@@ -422,7 +424,7 @@ public class EntityCollectionManagerIT {
     @Test
     public void updateVersioning() {
 
-        // create entity 
+        // create entity
         Entity origEntity = new Entity( new SimpleId( "testUpdate" ) );
         origEntity.setField( new StringField( "testField", "value" ) );
 
@@ -431,7 +433,7 @@ public class EntityCollectionManagerIT {
         EntityCollectionManager manager = factory.createCollectionManager( context );
         Entity returned = manager.write( origEntity ).toBlocking().lastOrDefault( null );
 
-        // note its version 
+        // note its version
         UUID oldVersion = returned.getVersion();
 
         // partial update entity but with new entity that has version = null
@@ -754,16 +756,16 @@ public class EntityCollectionManagerIT {
         //override our default
         SetConfigTestBypass.setValueByPass( serializationFig, "getMaxEntitySize", currentMaxSize + "" );
     }
-    
+
     @Test
     public void invalidNameRepair() {
-        
+
         //write an entity with a unique field
-        CollectionScope context = 
+        CollectionScope context =
                 new CollectionScopeImpl( new SimpleId( "organization" ), new SimpleId( "test" ), "test" );
 
         Entity newEntity = new Entity( new SimpleId( "test" ) );
-        
+
         newEntity.setField( new IntegerField( "count", 5, true ) );
         newEntity.setField( new StringField( "yes", "fred", true ) );
 
@@ -777,28 +779,41 @@ public class EntityCollectionManagerIT {
         assertNotNull( "Id was assigned", createReturned.getId() );
         assertNotNull( "Version was assigned", createReturned.getVersion() );
 
-
+        //load an entity by it's unique field
         Observable<Entity> loadObservable = manager.load( createReturned.getId() );
 
         Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null );
 
-        assertEquals( "Same value", createReturned, loadReturned );
-        //load an entity by it's unique field
-        
         //verify the entity is correct.
-        
+        assertEquals( "Same value", createReturned, loadReturned );
+
+
         //use the entity serializationStrategy to remove the entity data.
-        
+        try {
+            entitySerializationStrategy.delete( context,loadReturned.getId(),loadReturned.getVersion() ).execute();
+        }
+        catch ( ConnectionException e ) {
+            e.printStackTrace();
+            fail("Shouldn't have had trouble deleting entity");
+        }
+
+
         //try to load via the unique field
-        
+        loadObservable = manager.load( createReturned.getId() );
+
+        loadReturned = loadObservable.toBlocking().lastOrDefault( null );
+
         //verify no entity returned
-        
-        //user the unique serialization to verify it's been deleted from cassandra
-        
+        assertNull( loadReturned );
 
-        
-                
-                
-                
+        //user the unique serialization to verify it's been deleted from cassandra
+        try {
+            UniqueValueSet uniqueValues = uniqueValueSerializationStrategy.load( context, loadReturned.getFields() );
+            assertNull( uniqueValues );
+        }
+        catch ( ConnectionException e ) {
+            e.printStackTrace();
+            fail("Shouldn't have been able to load the unique entity");
+        }
     }
 }


[06/12] incubator-usergrid git commit: [USERGRID-386] Changed over to new method em.getAllEntityFromFields. Added unsupported messages to EntityManagerImpl Changed type of getAllEntityFromFields Added new method to CpEntityManager that converts a CpEntit

Posted by sf...@apache.org.
[USERGRID-386] Changed over to new method em.getAllEntityFromFields.
Added unsupported messages to EntityManagerImpl
Changed type of getAllEntityFromFields
Added new method to CpEntityManager that converts a CpEntity to a regular Entity.
Then adds method to use the getAllEntities method that repairs the entity incase it was deleted.


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

Branch: refs/heads/USERGRID-466
Commit: c872b694ed7f9b77220bad81813161ac11b9890f
Parents: a60d6aa
Author: GERey <gr...@apigee.com>
Authored: Wed Mar 11 16:52:04 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Mar 11 16:52:04 2015 -0700

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 49 ++++++++++++++------
 .../usergrid/persistence/EntityManager.java     |  3 +-
 .../cassandra/EntityManagerImpl.java            | 13 ++++--
 .../services/AbstractCollectionService.java     |  4 +-
 4 files changed, 46 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/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 4ed37e5..b7272f1 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
@@ -340,6 +340,17 @@ public class CpEntityManager implements EntityManager {
         return entity;
     }
 
+    public Entity convertMvccEntityToEntity( org.apache.usergrid.persistence.model.entity.Entity entity){
+        if(entity == null) {
+            return null;
+        }
+        Class clazz = Schema.getDefaultSchema().getEntityClass( entity.getId().getType() );
+
+        Entity oldFormatEntity = EntityFactory.newEntity(entity.getId().getUuid(),entity.getId().getType(),clazz);
+        oldFormatEntity.setProperties( CpEntityMapUtils.toMap( entity ) );
+
+        return oldFormatEntity;
+    }
 
     @Override
     public Entity get( EntityRef entityRef ) throws Exception {
@@ -730,17 +741,33 @@ public class CpEntityManager implements EntityManager {
     }
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue ){
-        return null;
-//        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( aliasType );
-//
-//        Schema.
-//        return ecm.getAllEntities( aliasValue );
+    public Entity getAllEntityFromFields( String collectionType, String aliasType ){
+        String collName = Schema.defaultCollectionName( collectionType );
+
+        CollectionScope collectionScope = getCollectionScopeNameFromEntityType(
+            getApplicationScope().getApplication(), collName);
+
+        String propertyName = Schema.getDefaultSchema().aliasProperty( collName );
+
+
+        final EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
+        //TODO: can't we just sub in the getEntityRepair method here so for every read of a uniqueEntityField we can verify it is correct?
+
+        StringField uniqueLookupRepairField =  new StringField( propertyName, aliasType.toString());
+
+        Observable<FieldSet> fieldSetObservable = ecm.getAllEntities( Arrays.<Field>asList( uniqueLookupRepairField) );
+
+        FieldSet fieldSet = fieldSetObservable.toBlocking().last();
+
+        if(fieldSet.isEmpty()) {
+            return null;
+        }
+
+        return convertMvccEntityToEntity( fieldSet.getEntity( uniqueLookupRepairField ).getEntity().get() );
     }
 
     @Override
     public Entity getEntityByAlias(String collectionType, String aliasType) throws Exception {
-
         EntityRef newEntityRef = getAlias(collectionType,aliasType);
 
         if(newEntityRef == null) {
@@ -748,9 +775,6 @@ public class CpEntityManager implements EntityManager {
         }
 
         return get( newEntityRef );
-
-
-
     }
 
 
@@ -2157,11 +2181,6 @@ public class CpEntityManager implements EntityManager {
         //convert to a string, that's what we store
         final Id results = ecm.getIdField( new StringField(
                 propertyName, propertyValue.toString() ) ).toBlocking() .lastOrDefault( null );
-
-        Observable<FieldSet> fieldSetObservable = ecm.getAllEntities( Arrays.<Field>asList( new StringField( propertyName, propertyValue.toString() ) );
-
-        FieldSet fieldSet = fieldSetObservable.toBlocking().last();
-        fieldSet.
         return results;
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 4b85c0d..eb6379b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -19,6 +19,7 @@ package org.apache.usergrid.persistence;
 
 import org.apache.usergrid.persistence.collection.CollectionScope;
 import org.apache.usergrid.persistence.collection.FieldSet;
+import org.apache.usergrid.persistence.collection.MvccEntity;
 import org.apache.usergrid.persistence.index.query.Query;
 import java.nio.ByteBuffer;
 import java.util.Collection;
@@ -719,6 +720,6 @@ public interface EntityManager {
      */
     public Health getIndexHealth();
 
-    public Observable<FieldSet> getAllEntityFromFields(String aliasType,String aliasValue );
+    public Entity getAllEntityFromFields( String aliasType, String aliasValue );
 
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index 42a588c..a019e86 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -69,7 +69,6 @@ import org.apache.usergrid.persistence.SimpleRoleRef;
 import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.cassandra.CounterUtils.AggregateCounterSelection;
 import org.apache.usergrid.persistence.cassandra.util.TraceParticipant;
-import org.apache.usergrid.persistence.collection.FieldSet;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Event;
 import org.apache.usergrid.persistence.entities.Group;
@@ -108,7 +107,6 @@ import me.prettyprint.hector.api.mutation.Mutator;
 import me.prettyprint.hector.api.query.MultigetSliceCounterQuery;
 import me.prettyprint.hector.api.query.QueryResult;
 import me.prettyprint.hector.api.query.SliceCounterQuery;
-import rx.Observable;
 
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
 import static java.util.Arrays.asList;
@@ -538,7 +536,7 @@ public class EntityManagerImpl implements EntityManager {
     /**
      * Return all UUIDs that have this unique value
      *
-     * @param ownerEntityId The entity id that owns this entity collection
+     * @param ownerEntityRef The entity id that owns this entity collection
      * @param collectionName The entity collection name
      * @param propertyName The name of the unique property
      * @param propertyValue The value of the unique property
@@ -1775,6 +1773,12 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
+    public Entity getEntityByAlias( final String collectionType, final String aliasType ) throws Exception {
+        throw new UnsupportedOperationException("Not supported.");
+    }
+
+
+    @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {
         return getAlias( new SimpleEntityRef(Application.ENTITY_TYPE, applicationId), aliasType, alias );
     }
@@ -2952,8 +2956,7 @@ public class EntityManagerImpl implements EntityManager {
 
 
     @Override
-    public Observable<FieldSet> getAllEntityFromFields( final String aliasType,
-                                                        final String aliasValue ) {
+    public Entity getAllEntityFromFields( final String aliasType, final String aliasValue ) {
         throw new UnsupportedOperationException( "Not supported." );
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c872b694/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
index 1117fbc..26eb6b9 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractCollectionService.java
@@ -76,7 +76,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        Entity entity = em.getEntityByAlias( getEntityType(), name );
+        Entity entity = em.getAllEntityFromFields( getEntityType(), name );
         if ( entity != null ) {
             entity = importEntity( request, entity );
         }
@@ -148,7 +148,7 @@ public class AbstractCollectionService extends AbstractService {
             nameProperty = "name";
         }
 
-        EntityRef entity = em.get( getEntityType(), name );
+        EntityRef entity = em.getAlias( getEntityType(), name );
 
         if ( entity == null ) {
             logger.info( "miss on entityType: {} with name: {}", getEntityType(), name );


[09/12] incubator-usergrid git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into USERGRID-396

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

# By Todd Nine (13) and others
# Via Todd Nine (3) and others
* 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid: (32 commits)
  Fixes ttl on map entry keys
  Addes Cache to MapMangerFactorImpl for efficiency
  Added a timeout to the map module
  change timer for buffer consumer
  change timer for buffer consumer
  Moved remaining CpEntityManager timers into the constructor.
  Changed log level to warn to catch issues with version mismatch in logging
  Changes index declaration to be explicit on the index
  Added operational logging to tasks
  Moved add alias and test new index into try so we don't keep moving the index alias
  Fixes merge error
  move timers up
  move timers up
  move timers up
  Adds put test to gatling
  Fixes lookup cache bug
  changing buffer impl to queue
  changing buffer impl to queue
  Added caching to org/app lookup
  Upgraded plexus utils and fixes build concurrency issues with surefire
  ...


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

Branch: refs/heads/USERGRID-466
Commit: c45a3ed0b08ac3b175d5e3cf214b8352c271ef77
Parents: 4c0102e 06e7ad6
Author: GERey <gr...@apigee.com>
Authored: Thu Mar 12 15:41:03 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Thu Mar 12 15:41:03 2015 -0700

----------------------------------------------------------------------
 .../Client/IUsergridClient.cs                   |   2 +-
 .../Usergrid.Notifications/Client/PushClient.cs |  24 ++
 .../Usergrid.Notifications/MainPage.xaml        |   1 +
 .../Usergrid.Notifications/MainPage.xaml.cs     |  29 ++-
 .../main/dist/init_instance/init_rest_server.sh |   3 -
 .../src/main/groovy/configure_usergrid.groovy   |   6 +-
 stack/awscluster/ugcluster-cf.json              |   8 +
 stack/core/pom.xml                              |   7 +-
 .../corepersistence/CpEntityManager.java        | 140 +++++++++-
 .../corepersistence/CpEntityManagerFactory.java | 156 ++++--------
 .../corepersistence/CpRelationManager.java      |  39 ++-
 .../corepersistence/OrgApplicationCache.java    |  67 +++++
 .../OrgApplicationCacheImpl.java                | 181 +++++++++++++
 .../corepersistence/results/EntityVerifier.java |   4 +-
 .../results/FilteringLoader.java                |   2 +-
 .../cassandra/CassandraPersistenceUtils.java    |   2 +-
 .../main/resources/usergrid-core-context.xml    |  14 +-
 .../cassandra/EntityManagerFactoryImplIT.java   |   1 +
 .../core/metrics/MetricsFactoryImpl.java        |   3 +-
 .../usergrid/persistence/map/MapManager.java    |   8 +
 .../persistence/map/MapManagerFactory.java      |   2 +
 .../persistence/map/guice/MapModule.java        |   6 +-
 .../map/impl/MapManagerFactoryImpl.java         |  67 +++++
 .../persistence/map/impl/MapManagerImpl.java    |   6 +
 .../persistence/map/impl/MapSerialization.java  |  20 +-
 .../map/impl/MapSerializationImpl.java          | 106 ++++++--
 .../persistence/map/MapManagerTest.java         |  49 +++-
 stack/corepersistence/queryindex/pom.xml        |  16 +-
 .../persistence/index/EntityIndexFactory.java   |   4 +-
 .../persistence/index/IndexBufferProducer.java  |  10 +-
 .../usergrid/persistence/index/IndexFig.java    |  12 +-
 .../persistence/index/guice/IndexModule.java    |  11 +-
 .../index/impl/EsEntityIndexBatchImpl.java      |  15 +-
 .../index/impl/EsEntityIndexFactoryImpl.java    |  85 +++++++
 .../index/impl/EsEntityIndexImpl.java           | 253 +++++++++++++++----
 .../index/impl/EsIndexBufferConsumerImpl.java   |  48 +++-
 .../index/impl/EsIndexBufferProducerImpl.java   |  30 ++-
 .../persistence/index/impl/IndexingUtils.java   |   3 -
 .../persistence/index/utils/StringUtils.java    | 126 +--------
 .../persistence/index/utils/UUIDUtils.java      |   4 -
 .../persistence/index/impl/EntityIndexTest.java | 101 +++++++-
 .../datagenerators/EntityDataGenerator.scala    |  25 ++
 .../datagenerators/FeederGenerator.scala        |  18 +-
 .../usergrid/scenarios/EntityScenarios.scala    |   8 +-
 .../org/apache/usergrid/settings/Settings.scala |   4 +-
 .../simulations/PutCustomEntitySimulation.scala |  75 ++++++
 stack/pom.xml                                   |  24 +-
 stack/rest/pom.xml                              |   2 +-
 .../org/apache/usergrid/rest/IndexResource.java |  19 ++
 stack/services/pom.xml                          |   7 +-
 .../services/notifications/wns/WNSAdapter.java  |  39 +++
 .../resources/usergrid-services-context.xml     |   8 +-
 .../usergrid/management/OrganizationIT.java     |   2 +-
 53 files changed, 1491 insertions(+), 411 deletions(-)
----------------------------------------------------------------------


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


[04/12] incubator-usergrid git commit: Added getAllEntityFromField to the entity manager so we can expose it in the service tier.

Posted by sf...@apache.org.
Added getAllEntityFromField to the entity manager so we can expose it in the service tier.


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

Branch: refs/heads/USERGRID-466
Commit: d4eb288c8a04bf73e79b64d1a06d12fca11260ee
Parents: acde0e4
Author: GERey <gr...@apigee.com>
Authored: Wed Mar 11 09:57:11 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Wed Mar 11 09:57:11 2015 -0700

----------------------------------------------------------------------
 .../apache/usergrid/corepersistence/CpEntityManager.java |  7 ++++++-
 .../org/apache/usergrid/persistence/EntityManager.java   |  9 ++++++++-
 .../persistence/cassandra/EntityManagerImpl.java         | 11 +++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d4eb288c/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 5619382..4b62fbe 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
@@ -33,6 +33,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.collection.FieldSet;
 import org.apache.usergrid.persistence.core.future.BetterFuture;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -500,7 +501,6 @@ public class CpEntityManager implements EntityManager {
 
         CollectionScope collectionScope = getCollectionScopeNameFromEntityType(appId, type );
         EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
-
         Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
 
         if ( logger.isDebugEnabled() ) {
@@ -729,6 +729,11 @@ public class CpEntityManager implements EntityManager {
         create( entityType, null );
     }
 
+    @Override
+    public Observable<FieldSet> getAllEntityFromFields(CollectionScope collectionScope,Collection<Field> fields){
+        EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
+        return ecm.getAllEntities( fields );
+    }
 
     @Override
     public EntityRef getAlias( String aliasType, String alias ) throws Exception {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d4eb288c/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
index 4054d77..459032c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManager.java
@@ -17,6 +17,8 @@
 package org.apache.usergrid.persistence;
 
 
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.FieldSet;
 import org.apache.usergrid.persistence.index.query.Query;
 import java.nio.ByteBuffer;
 import java.util.Collection;
@@ -25,6 +27,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 import me.prettyprint.hector.api.mutation.Mutator;
+import rx.Observable;
 
 import org.apache.usergrid.persistence.cassandra.CassandraService;
 import org.apache.usergrid.persistence.cassandra.GeoIndexManager;
@@ -34,6 +37,7 @@ import org.apache.usergrid.persistence.entities.Role;
 import org.apache.usergrid.persistence.index.query.CounterResolution;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.model.field.Field;
 
 
 /**
@@ -712,4 +716,7 @@ public interface EntityManager {
      * Get health status of application's index.
      */
     public Health getIndexHealth();
-}
+
+    public Observable<FieldSet> getAllEntityFromFields(CollectionScope collectionScope,Collection<Field> fields);
+
+    }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d4eb288c/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
index be43920..adf106a 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
@@ -69,6 +69,8 @@ import org.apache.usergrid.persistence.SimpleRoleRef;
 import org.apache.usergrid.persistence.TypedEntity;
 import org.apache.usergrid.persistence.cassandra.CounterUtils.AggregateCounterSelection;
 import org.apache.usergrid.persistence.cassandra.util.TraceParticipant;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.FieldSet;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Event;
 import org.apache.usergrid.persistence.entities.Group;
@@ -83,6 +85,7 @@ import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.persistence.index.query.Query.CounterFilterPredicate;
 import org.apache.usergrid.persistence.index.query.Query.Level;
+import org.apache.usergrid.persistence.model.field.Field;
 import org.apache.usergrid.persistence.schema.CollectionInfo;
 import org.apache.usergrid.utils.ClassUtils;
 import org.apache.usergrid.utils.CompositeUtils;
@@ -107,6 +110,7 @@ import me.prettyprint.hector.api.mutation.Mutator;
 import me.prettyprint.hector.api.query.MultigetSliceCounterQuery;
 import me.prettyprint.hector.api.query.QueryResult;
 import me.prettyprint.hector.api.query.SliceCounterQuery;
+import rx.Observable;
 
 import static java.lang.String.CASE_INSENSITIVE_ORDER;
 import static java.util.Arrays.asList;
@@ -2947,4 +2951,11 @@ public class EntityManagerImpl implements EntityManager {
     public Health getIndexHealth() {
         return Health.GREEN; // no good way to assess index status using old-school entity manager
     }
+
+
+    @Override
+    public Observable<FieldSet> getAllEntityFromFields( final CollectionScope collectionScope,
+                                                        final Collection<Field> fields ) {
+        throw new UnsupportedOperationException( "Not supported." );
+    }
 }


[03/12] incubator-usergrid git commit: Fixed cachedEntityCollectionManager getAllEntities method. Made the getAllEntities a synced process to ensure it runs and finishes within the scope of the task. Added test that proves the issue. and that it is fixed

Posted by sf...@apache.org.
Fixed cachedEntityCollectionManager getAllEntities method.
Made the getAllEntities a synced process to ensure it runs and finishes within the scope of the task.
Added test that proves the issue. and that it is fixed by the new method.


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

Branch: refs/heads/USERGRID-466
Commit: acde0e4b9b032a297b0bddaa874393ebb7083709
Parents: 5411fef
Author: GERey <gr...@apigee.com>
Authored: Tue Mar 10 12:47:40 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Tue Mar 10 12:47:40 2015 -0700

----------------------------------------------------------------------
 .../cache/CachedEntityCollectionManager.java    | 11 +----
 .../impl/EntityCollectionManagerImpl.java       |  4 +-
 .../collection/EntityCollectionManagerIT.java   | 50 +++++++++-----------
 3 files changed, 27 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/acde0e4b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
index a111f8d..d33f762 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/cache/CachedEntityCollectionManager.java
@@ -82,16 +82,9 @@ public class CachedEntityCollectionManager implements EntityCollectionManager {
                                   .build();
     }
 
+    @Override
     public Observable<FieldSet> getAllEntities(final Collection<Field> fields) {
-        return rx.Observable.just(fields).map( new Func1<Collection<Field>, FieldSet>() {
-            @Override
-            public FieldSet call( Collection<Field> fields ) {
-
-                    final FieldSet response = new FieldSetImpl(fields.size());
-
-                    return response;
-            }
-        } );
+        return targetEntityCollectionManager.getAllEntities( fields );
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/acde0e4b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 5505e3f..d95183d 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -335,7 +335,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
                     }
 
                     //fire and forget, we don't care.  We'll repair it again if we have to
-                    deleteBatch.executeAsync();
+                    deleteBatch.execute();
 
                     return response;
 
@@ -349,7 +349,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         } );
     }
 
-   
+
 
     @Override
     public Observable<Entity> update( final Entity entity ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/acde0e4b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
index a52a9bb..46e844d 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerIT.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.persistence.collection;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
 
@@ -758,7 +759,7 @@ public class EntityCollectionManagerIT {
     }
 
     @Test
-    public void invalidNameRepair() {
+    public void invalidNameRepair() throws ConnectionException {
 
         //write an entity with a unique field
         CollectionScope context =
@@ -766,8 +767,12 @@ public class EntityCollectionManagerIT {
 
         Entity newEntity = new Entity( new SimpleId( "test" ) );
 
-        newEntity.setField( new IntegerField( "count", 5, true ) );
-        newEntity.setField( new StringField( "yes", "fred", true ) );
+        //if we add a second field we get a second entity that is the exact same. Is this expected?
+        final IntegerField expectedInteger =  new IntegerField( "count", 5, true );
+       // final StringField expectedString = new StringField( "yes", "fred", true );
+
+        newEntity.setField( expectedInteger );
+       // newEntity.setField( expectedString );
 
         EntityCollectionManager manager = factory.createCollectionManager( context );
 
@@ -779,41 +784,32 @@ public class EntityCollectionManagerIT {
         assertNotNull( "Id was assigned", createReturned.getId() );
         assertNotNull( "Version was assigned", createReturned.getVersion() );
 
-        //load an entity by it's unique field
-        Observable<Entity> loadObservable = manager.load( createReturned.getId() );
+        FieldSet
+            fieldResults = manager.getAllEntities( Arrays.<Field>asList( expectedInteger) ).toBlocking().last();
 
-        Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null );
+        assertEquals(1,fieldResults.size());
 
-        //verify the entity is correct.
-        assertEquals( "Same value", createReturned, loadReturned );
 
+        //verify the entity is correct.
+        assertEquals( "Same value", createReturned, fieldResults.getEntity( expectedInteger ).getEntity().get()); //loadReturned );
 
         //use the entity serializationStrategy to remove the entity data.
-        try {
-            entitySerializationStrategy.delete( context,loadReturned.getId(),loadReturned.getVersion() ).execute();
-        }
-        catch ( ConnectionException e ) {
-            e.printStackTrace();
-            fail("Shouldn't have had trouble deleting entity");
-        }
 
+        //do a mark as one test, and a delete as another
+        entitySerializationStrategy.delete( context,createReturned.getId(),createReturned.getVersion() ).execute();
 
-        //try to load via the unique field
-        loadObservable = manager.load( createReturned.getId() );
+        //try to load via the unique field, should have triggered repair
+        final FieldSet
+            results = manager.getAllEntities( Arrays.<Field>asList( expectedInteger) ).toBlocking().last();
 
-        loadReturned = loadObservable.toBlocking().lastOrDefault( null );
 
         //verify no entity returned
-        assertNull( loadReturned );
+        assertTrue( results.isEmpty() );
 
         //user the unique serialization to verify it's been deleted from cassandra
-        try {
-            UniqueValueSet uniqueValues = uniqueValueSerializationStrategy.load( context, loadReturned.getFields() );
-            assertNull( uniqueValues );
-        }
-        catch ( ConnectionException e ) {
-            e.printStackTrace();
-            fail("Shouldn't have been able to load the unique entity");
-        }
+
+        UniqueValueSet uniqueValues = uniqueValueSerializationStrategy.load( context, createReturned.getFields() );
+        assertFalse( uniqueValues.iterator().hasNext() );
+
     }
 }


[12/12] incubator-usergrid git commit: merge from two-o

Posted by sf...@apache.org.
merge from two-o


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

Branch: refs/heads/USERGRID-466
Commit: b53cb07f376fcdff8ce0b3226bbb07843f12d4e9
Parents: 0334119 b0a07ba
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Mar 16 17:35:24 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Mar 16 17:35:24 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        | 49 ++++++++++-
 .../usergrid/persistence/EntityManager.java     | 10 ++-
 .../cassandra/EntityManagerImpl.java            |  8 +-
 .../usergrid/persistence/EntityManagerIT.java   |  1 +
 .../collection/EntityCollectionManager.java     | 13 ++-
 .../persistence/collection/FieldSet.java        | 48 ++++++++++
 .../cache/CachedEntityCollectionManager.java    | 11 ++-
 .../impl/EntityCollectionManagerImpl.java       | 92 +++++++++++++++++++-
 .../serialization/impl/MutableFieldSet.java     | 63 ++++++++++++++
 .../UniqueValueSerializationStrategyImpl.java   |  2 +-
 .../collection/EntityCollectionManagerIT.java   | 72 ++++++++++++++-
 .../services/AbstractCollectionService.java     | 40 +++------
 .../services/AbstractConnectionsService.java    | 39 +++------
 13 files changed, 374 insertions(+), 74 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b53cb07f/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index e2b7bd1,e5223f0..789e640
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@@ -33,7 -33,7 +33,8 @@@ import java.util.TreeMap
  import java.util.TreeSet;
  import java.util.UUID;
  
 +import com.codahale.metrics.Meter;
+ import org.apache.usergrid.persistence.collection.FieldSet;
  import org.apache.usergrid.persistence.core.future.BetterFuture;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
@@@ -206,8 -207,7 +207,9 @@@ public class CpEntityManager implement
      private Timer entGetEntityCountersTimer;
      private Timer esIndexEntityCollectionTimer;
      private Timer entRevokeRolePermissionsTimer;
+     private Timer entGetRepairedEntityTimer;
 +    private Timer updateEntityTimer;
 +    private Meter updateEntityMeter;
  
      //    /** Short-term cache to keep us from reloading same Entity during single request. */
  //    private LoadingCache<EntityScope, org.apache.usergrid.persistence.model.entity.Entity> entityCache;
@@@ -268,10 -268,9 +270,12 @@@
              .getTimer( CpEntityManager.class, "cp.entity.es.index.entity.to.collection.timer" );
          this.entRevokeRolePermissionsTimer =
              this.metricsFactory.getTimer( CpEntityManager.class, "cp.entity.revoke.role.permissions.timer");
+         this.entGetRepairedEntityTimer = this.metricsFactory
+             .getTimer( CpEntityManager.class, "get.repaired.entity.timer" );
  
 +        this.updateEntityMeter =this.metricsFactory.getMeter(CpEntityManager.class,"cp.entity.update.meter");
 +        this.updateEntityTimer =this.metricsFactory.getTimer(CpEntityManager.class, "cp.entity.update.timer");
 +
          // set to false for now
          this.skipAggregateCounters = false;
  
@@@ -566,12 -577,8 +581,11 @@@
          Preconditions.checkNotNull(appId,"app scope should never be null");
          // first, update entity index in its own collection scope
  
 +        updateEntityMeter.mark();
 +        Timer.Context timer = updateEntityTimer.time();
 +
          CollectionScope collectionScope = getCollectionScopeNameFromEntityType(appId, type );
          EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
- 
          Id entityId = new SimpleId( entity.getUuid(), entity.getType() );
  
          if ( logger.isDebugEnabled() ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b53cb07f/stack/core/src/main/java/org/apache/usergrid/persistence/cassandra/EntityManagerImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b53cb07f/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --cc stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index 92b07f0,3c89280..6ba4513
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@@ -70,11 -61,12 +72,14 @@@ import com.netflix.astyanax.connectionp
  import com.netflix.astyanax.model.ColumnFamily;
  import com.netflix.astyanax.model.CqlResult;
  import com.netflix.astyanax.serializers.StringSerializer;
+ import org.apache.usergrid.persistence.collection.guice.CollectionTaskExecutor;
+ import org.apache.usergrid.persistence.core.task.Task;
+ import org.apache.usergrid.persistence.core.task.TaskExecutor;
  
 +import rx.Notification;
  import rx.Observable;
  import rx.Subscriber;
 +import rx.functions.Action0;
  import rx.functions.Action1;
  import rx.functions.Func1;
  import rx.schedulers.Schedulers;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/b53cb07f/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/UniqueValueSerializationStrategyImpl.java
----------------------------------------------------------------------


[07/12] incubator-usergrid git commit: [USERGRID-396] Added ability to short circuit if not unique id's are found.

Posted by sf...@apache.org.
[USERGRID-396] Added ability to short circuit if not unique id's are found.


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

Branch: refs/heads/USERGRID-466
Commit: a6929ab249e88d85c6025660f44392ed2b9c93a7
Parents: c872b69
Author: GERey <gr...@apigee.com>
Authored: Thu Mar 12 12:07:46 2015 -0700
Committer: GERey <gr...@apigee.com>
Committed: Thu Mar 12 12:07:46 2015 -0700

----------------------------------------------------------------------
 .../impl/EntityCollectionManagerImpl.java           | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a6929ab2/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
index d95183d..7db34aa 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/impl/EntityCollectionManagerImpl.java
@@ -287,6 +287,12 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
         } );
     }
 
+
+    /**
+     * Retrieves all entities that correspond to each field given in the Collection.
+     * @param fields
+     * @return
+     */
     @Override
     public Observable<FieldSet> getAllEntities(final Collection<Field> fields) {
         return rx.Observable.just(fields).map( new Func1<Collection<Field>, FieldSet>() {
@@ -296,8 +302,14 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
                     final UUID startTime = UUIDGenerator.newTimeUUID();
 
+                    //Get back set of unique values that correspond to collection of fields
                     UniqueValueSet set = uniqueValueSerializationStrategy.load( collectionScope, fields );
 
+                    //Short circut if we don't have any uniqueValues from the given fields.
+                    if(!set.iterator().hasNext()){
+                        return new FieldSetImpl( 0 );
+                    }
+
 
                     //loop through each field, and construct an entity load
                     List<Id> entityIds = new ArrayList<>(fields.size());
@@ -311,6 +323,7 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
                         uniqueValues.add(value);
                     }
 
+                    //Load a entity for each entityId we retrieved.
                     final EntitySet entitySet = entitySerializationStrategy.load(collectionScope, entityIds, startTime);
 
                     //now loop through and ensure the entities are there.
@@ -334,7 +347,8 @@ public class EntityCollectionManagerImpl implements EntityCollectionManager {
 
                     }
 
-                    //fire and forget, we don't care.  We'll repair it again if we have to
+                    //TODO: explore making this an Async process
+                    //We'll repair it again if we have to
                     deleteBatch.execute();
 
                     return response;