You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2014/11/13 23:14:23 UTC
[1/3] incubator-usergrid git commit: Refactored ManagerCache to be a
guice module for reuse in low level guice components.
Repository: incubator-usergrid
Updated Branches:
refs/heads/two-dot-o d70ca53b8 -> 7deba17fc
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservableIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservableIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservableIT.java
new file mode 100644
index 0000000..cd84e52
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservableIT.java
@@ -0,0 +1,162 @@
+/*
+ * 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.corepersistence.rx;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.ManagerCache;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+
+import rx.functions.Action1;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Tests that when we create a few entities, we get their data.
+ */
+public class EdgesToTargetObservableIT extends AbstractCoreIT {
+
+
+ @Test
+ public void testEntities() throws Exception {
+
+ final EntityManager em = app.getEntityManager();
+
+ final String type1 = "type1things";
+ final String type2 = "type2things";
+ final int size = 10;
+
+ final Set<Id> type1Identities = createTypes( em, type1, size );
+ final Set<Id> type2Identities = createTypes( em, type2, size );
+
+ //create a connection and put that in our connection types
+ final Id source = type1Identities.iterator().next();
+
+
+ final Set<Id> connections = new HashSet<>();
+
+ for ( Id target : type2Identities ) {
+ em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
+ connections.add( target );
+ }
+
+
+ //this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
+ //clean up our wiring
+ //
+ ManagerCache managerCache = CpSetup.getInjector().getInstance( ManagerCache.class );
+
+
+ final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );
+ final Id applicationId = scope.getApplication();
+
+
+ final GraphManager gm = managerCache.getGraphManager( scope );
+
+ EdgesFromSourceObservable.edgesFromSource( gm, applicationId ).doOnNext( new Action1<Edge>() {
+ @Override
+ public void call( final Edge edge ) {
+ final String edgeType = edge.getType();
+ final Id target = edge.getTargetNode();
+
+ //test if we're a collection, if so remove ourselves fro the types
+ if ( !CpNamingUtils.isCollectionEdgeType( edgeType ) ) {
+ fail( "Connections should be the only type encountered" );
+ }
+
+
+ final String collectionType = CpNamingUtils.getCollectionName( edgeType );
+
+ if ( collectionType.equals( type1 ) ) {
+ assertTrue( "Element should be present on removal", type1Identities.remove( target ) );
+ }
+ else if ( collectionType.equals( type2 ) ) {
+ assertTrue( "Element should be present on removal", type2Identities.remove( target ) );
+ }
+
+
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+
+ assertEquals( "Every element should have been encountered", 0, type1Identities.size() );
+ assertEquals( "Every element should have been encountered", 0, type2Identities.size() );
+
+
+ //test connections
+
+ EdgesFromSourceObservable.edgesFromSource( gm, source).doOnNext( new Action1<Edge>() {
+ @Override
+ public void call( final Edge edge ) {
+ final String edgeType = edge.getType();
+ final Id target = edge.getTargetNode();
+
+ if ( !CpNamingUtils.isConnectionEdgeType( edgeType ) ) {
+ fail( "Only connection edges should be encountered" );
+ }
+
+ final String connectionType = CpNamingUtils.getConnectionType( edgeType );
+
+ assertEquals( "Same connection type expected", "likes", connectionType );
+
+
+ assertTrue( "Element should be present on removal", connections.remove( target ) );
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+ assertEquals( "Every connection should have been encountered", 0, connections.size() );
+ }
+
+
+ private Set<Id> createTypes( final EntityManager em, final String type, final int size ) throws Exception {
+
+ final Set<Id> identities = new HashSet<>();
+
+ for ( int i = 0; i < size; i++ ) {
+ final Entity entity = em.create( type, new HashMap<String, Object>(){{put("property", "value");}} );
+ final Id createdId = new SimpleId( entity.getUuid(), entity.getType() );
+
+ identities.add( createdId );
+ }
+
+ return identities;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/TargetIdObservableTestIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/TargetIdObservableTestIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/TargetIdObservableTestIT.java
new file mode 100644
index 0000000..77949b9
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/TargetIdObservableTestIT.java
@@ -0,0 +1,143 @@
+/*
+ * 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.corepersistence.rx;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.ManagerCache;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+
+import rx.functions.Action1;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Tests that when we create a few entities, we get their data.
+ */
+public class TargetIdObservableTestIT extends AbstractCoreIT {
+
+
+ @Test
+ public void testEntities() throws Exception {
+
+ final EntityManager em = app.getEntityManager();
+
+
+ final String type1 = "type1thing";
+ final String type2 = "type2thing";
+ final int size = 10;
+
+ final Set<Id> type1Identities = createTypes( em, type1, size );
+ final Set<Id> type2Identities = createTypes( em, type2, size );
+
+ //create a connection and put that in our connection types
+ final Id source = type1Identities.iterator().next();
+
+
+ final Set<Id> connections = new HashSet<>();
+
+ for ( Id target : type2Identities ) {
+ em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
+ connections.add( target );
+ }
+
+
+ //this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
+ //clean up our wiring
+ //
+ ManagerCache managerCache = CpSetup.getInjector().getInstance( ManagerCache.class );
+
+
+ final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );
+ final Id applicationId = scope.getApplication();
+
+
+ final GraphManager gm = managerCache.getGraphManager( scope );
+
+ TargetIdObservable.getTargetNodes( gm, applicationId ).doOnNext( new Action1<Id>() {
+ @Override
+ public void call( final Id target ) {
+
+
+ if ( target.getType().equals( type1 ) ) {
+ assertTrue( "Element should be present on removal", type1Identities.remove( target ) );
+ }
+ else if ( target.getType().equals( type2 ) ) {
+ assertTrue( "Element should be present on removal", type2Identities.remove( target ) );
+ }
+
+
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+
+ assertEquals( "Every element should have been encountered", 0, type1Identities.size() );
+ assertEquals( "Every element should have been encountered", 0, type2Identities.size() );
+
+
+ //test connections
+
+ TargetIdObservable.getTargetNodes( gm, source ).doOnNext( new Action1<Id>() {
+ @Override
+ public void call( final Id target ) {
+
+ assertTrue( "Element should be present on removal", connections.remove( target ) );
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+ assertEquals( "Every connection should have been encountered", 0, connections.size() );
+ }
+
+
+ private Set<Id> createTypes( final EntityManager em, final String type, final int size ) throws Exception {
+
+ final Set<Id> identities = new HashSet<>();
+
+ for ( int i = 0; i < size; i++ ) {
+ final Entity entity = em.create( type, new HashMap<String, Object>(){{put("property", "value");}} );
+ final Id createdId = new SimpleId( entity.getUuid(), entity.getType() );
+
+ identities.add( createdId );
+ }
+
+ return identities;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
index 4b80e8b..e52e7f9 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/EntityConnectionsIT.java
@@ -299,7 +299,7 @@ public class EntityConnectionsIT extends AbstractCoreIT {
UUID applicationId = app.getId( );
assertNotNull( applicationId );
- EntityManager em = app.getEm();
+ EntityManager em = app.getEntityManager();
assertNotNull( em );
User fred = new User();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
index 16272af..28974ac 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/PerformanceEntityRebuildIndexTest.java
@@ -41,7 +41,7 @@ import java.util.Map;
import java.util.UUID;
import org.apache.usergrid.cassandra.Concurrent;
import org.apache.usergrid.corepersistence.CpSetup;
-import org.apache.usergrid.corepersistence.NamingUtils;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.index.EntityIndex;
@@ -165,7 +165,7 @@ public class PerformanceEntityRebuildIndexTest extends AbstractCoreIT {
// ----------------- delete the system and application indexes
logger.debug("Deleting app index and system app index");
- deleteIndex( NamingUtils.SYSTEM_APP_ID );
+ deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
deleteIndex( em.getApplicationId() );
// ----------------- test that we can read them, should fail
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
index 9989d9d..4d371fb 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/query/AbstractIteratingQueryIT.java
@@ -901,7 +901,7 @@ public abstract class AbstractIteratingQueryIT {
LOG.info( "Writes took {} ms", stop - start );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
Query query = new Query();
query.setLimit( 100 );
@@ -1002,7 +1002,7 @@ public abstract class AbstractIteratingQueryIT {
LOG.info( "Writes took {} ms", stop - start );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
Query query = Query.fromQL( "select * order by boolean desc, index asc" );
query.setLimit( queryLimit );
@@ -1108,7 +1108,7 @@ public abstract class AbstractIteratingQueryIT {
LOG.info( "Writes took {} ms", stop - start );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
Query query =
Query.fromQL( "select * where intersect = true OR intersect2 = true order by created, intersect desc" );
@@ -1253,7 +1253,7 @@ public abstract class AbstractIteratingQueryIT {
@Override
public Entity writeEntity( Map<String, Object> entity ) throws Exception {
- Entity e = app.getEm().create( "test", entity );
+ Entity e = app.getEntityManager().create( "test", entity );
if ( WRITE_DELAY > 0 ) {
Thread.sleep( WRITE_DELAY );
@@ -1265,8 +1265,8 @@ public abstract class AbstractIteratingQueryIT {
@Override
public Results getResults( Query query ) throws Exception {
- app.getEm().refreshIndex();
- return app.getEm().searchCollection( app.getEm().getApplicationRef(), "tests", query );
+ app.getEntityManager().refreshIndex();
+ return app.getEntityManager().searchCollection( app.getEntityManager().getApplicationRef(), "tests", query );
}
}
@@ -1289,7 +1289,7 @@ public abstract class AbstractIteratingQueryIT {
public void doSetup() throws Exception {
Map<String, Object> data = new HashMap<String, Object>();
data.put( "name", "rootentity" );
- rootEntity = app.getEm().create( "root", data );
+ rootEntity = app.getEntityManager().create( "root", data );
}
@@ -1298,7 +1298,7 @@ public abstract class AbstractIteratingQueryIT {
// write to the collection
Entity created = super.writeEntity( entity );
- app.getEm().createConnection( rootEntity, CONNECTION, created );
+ app.getEntityManager().createConnection( rootEntity, CONNECTION, created );
if ( WRITE_DELAY > 0 ) {
Thread.sleep( WRITE_DELAY );
@@ -1318,11 +1318,11 @@ public abstract class AbstractIteratingQueryIT {
@Override
public Results getResults( Query query ) throws Exception {
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
query.setConnectionType( CONNECTION );
query.setEntityType( "test" );
- return app.getEm().searchConnectedEntities( rootEntity, query );
+ return app.getEntityManager().searchConnectedEntities( rootEntity, query );
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
index d2764d0..6046962 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/query/AllInConnectionNoTypeIT.java
@@ -48,7 +48,7 @@ public class AllInConnectionNoTypeIT extends AbstractIteratingQueryIT {
query.setConnectionType( CONNECTION );
// don't set it on purpose
query.setEntityType( null );
- return app.getEm().searchConnectedEntities( rootEntity, query );
+ return app.getEntityManager().searchConnectedEntities( rootEntity, query );
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
index d16e2c1..4172327 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
@@ -73,7 +73,7 @@ public class ServiceApplication extends CoreApplication {
ServiceResults testRequest = testRequest( action, expectedCount, true, params );
if ( !action.equals( ServiceAction.GET )) {
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
return testRequest;
@@ -105,7 +105,7 @@ public class ServiceApplication extends CoreApplication {
dumpResults( results );
if ( !action.name().equals( ServiceAction.GET )) {
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
return results;
@@ -131,14 +131,14 @@ public class ServiceApplication extends CoreApplication {
put( "name", name );
Entity entity = testRequest( ServiceAction.POST, 1, pluralize( entityType ) ).getEntity();
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
return entity;
}
public void createConnection( Entity subject, String verb, Entity noun ) throws Exception {
sm.getEntityManager().createConnection( subject, verb, noun );
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
@@ -153,7 +153,7 @@ public class ServiceApplication extends CoreApplication {
dumpResults( results );
if ( !action.name().equals( ServiceAction.GET )) {
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
return results;
@@ -169,7 +169,7 @@ public class ServiceApplication extends CoreApplication {
assertNotNull( results.getData() );
if ( !action.name().equals( ServiceAction.GET )) {
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
// dump( results.getData() );
@@ -179,20 +179,20 @@ public class ServiceApplication extends CoreApplication {
public Entity createRole( String name, String title, int inactivity ) throws Exception {
Entity createRole = sm.getEntityManager().createRole( name, title, inactivity );
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
return createRole;
}
public void grantRolePermission( String role, String permission ) throws Exception {
sm.getEntityManager().grantRolePermission( role, permission );
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
public void grantUserPermission( UUID uuid, String permission ) throws Exception {
sm.getEntityManager().grantUserPermission( uuid, permission );
- getEm().refreshIndex();
+ getEntityManager().refreshIndex();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
index 9ba09d9..436f231 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
@@ -98,12 +98,12 @@ public class ConnectionsServiceIT extends AbstractServiceIT {
Entity bar = app.testRequest( ServiceAction.POST, 1, "bars" ).getEntity();
assertNotNull( bar );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
//POST users/conn-user1/user2/UUID
app.testRequest( ServiceAction.POST, 1, "foos", "foo", "bars", bar.getUuid() ); // should succeed
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
try {
//POST users/conn-user1/user2/bar
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
index 2c97921..1044e13 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
@@ -70,13 +70,13 @@ public class GroupServiceIT extends AbstractServiceIT {
app.createGroupRole( group.getUuid(), "admin", 0 );
app.createGroupRole( group.getUuid(), "author", 0 );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
app.grantGroupRolePermission( group.getUuid(), "admin", "users:access:*" );
app.grantGroupRolePermission( group.getUuid(), "admin", "groups:access:*" );
app.grantGroupRolePermission( group.getUuid(), "author", "assets:access:*" );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
app.testDataRequest( ServiceAction.GET, "groups", group.getUuid(), "rolenames" );
app.testDataRequest( ServiceAction.GET, "groups", group.getUuid(), "roles", "admin", "permissions" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
index 45a1403..04a900d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
@@ -199,7 +199,7 @@ public class RolesServiceIT extends AbstractServiceIT {
ServiceResults results = app.invokeService( ServiceAction.DELETE, "roles", "manager" );
assertEquals( 1, results.size() );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// check role is gone
Role role = app.get( app.getAlias( "role", "manager" ), Role.class );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
index c89b220..261d3d2 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
@@ -38,7 +38,7 @@ public class UsersServiceIT extends AbstractServiceIT {
Entity user = app.create( "user" );
assertNotNull( user );
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
app.testRequest( ServiceAction.POST, 1, "users", user.getUuid(), "roles", "admin" );
app.testRequest( ServiceAction.POST, 1, "users", user.getUuid(), "roles", "manager" );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index a9ca955..1fd6f3e 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -66,8 +66,8 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
long timeout = System.currentTimeMillis() + 60000;
while (System.currentTimeMillis() < timeout) {
Thread.sleep(200);
- app.getEm().refreshIndex();
- notification = app.getEm().get(notification.getUuid(), Notification.class);
+ app.getEntityManager().refreshIndex();
+ notification = app.getEntityManager().get(notification.getUuid(), Notification.class);
if (notification.getFinished() != null) {
return notification;
}
@@ -82,10 +82,10 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
query.setCollection("receipts");
query.setLimit(100);
PathQuery<Receipt> pathQuery = new PathQuery<Receipt>(
- new SimpleEntityRef(app.getEm().getApplicationRef()),
+ new SimpleEntityRef(app.getEntityManager().getApplicationRef()),
query
);
- Iterator<Receipt> it = pathQuery.iterator(app.getEm());
+ Iterator<Receipt> it = pathQuery.iterator(app.getEntityManager());
List<EntityRef> list =new ArrayList<EntityRef>();//get all
while(it.hasNext()){
Receipt receipt =it.next();
@@ -109,7 +109,7 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
}
assertEquals(expected, receipts.size());
for (EntityRef receipt : receipts) {
- Receipt r = app.getEm().get(receipt, Receipt.class);
+ Receipt r = app.getEntityManager().get(receipt, Receipt.class);
assertNotNull(r.getSent());
assertNotNull(r.getPayload());
assertNotNull(r.getNotifierId());
@@ -123,7 +123,7 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
long timeout = System.currentTimeMillis() + 10000;
while (System.currentTimeMillis() < timeout) {
Thread.sleep(200);
- statistics = app.getEm().get(notification.getUuid(), Notification.class).getStatistics();
+ statistics = app.getEntityManager().get(notification.getUuid(), Notification.class).getStatistics();
if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
break;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
index 7ced70c..f278f43 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
@@ -201,7 +201,7 @@ public class NotifiersServiceIT extends AbstractServiceIT {
f.set(Schema.class, originalSeed);
try {
- app.getEm().get(notifier.getUuid());
+ app.getEntityManager().get(notifier.getUuid());
fail("Should have failed to retrieve the encrypted entity.");
} catch (IllegalStateException e) {
// ok! This should happen.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index 02f881d..0a5375f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -85,7 +85,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
fis.close();
Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
- notifier = app.getEm().get(e.getUuid(), Notifier.class);
+ notifier = app.getEntityManager().get(e.getUuid(), Notifier.class);
final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
// create devices //
@@ -95,36 +95,36 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.put("name", "device1");
e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
- device1 = app.getEm().get(e.getUuid(), Device.class);
+ device1 = app.getEntityManager().get(e.getUuid(), Device.class);
assertEquals(device1.getProperty(notifierKey), PUSH_TOKEN);
app.clear();
app.put(notifierKey, PUSH_TOKEN);
app.put("name", "device2");
e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
- device2 = app.getEm().get(e.getUuid(), Device.class);
- Map<String, Object> props = app.getEm().getProperties(e);
+ device2 = app.getEntityManager().get(e.getUuid(), Device.class);
+ Map<String, Object> props = app.getEntityManager().getProperties(e);
assertEquals(device2.getProperty(notifierKey), PUSH_TOKEN);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// create User
user1 = new User();
user1.setUsername("user1");
user1.setEmail("user1@usergrid.org");
- user1 = app.getEm().create(user1);
+ user1 = app.getEntityManager().create(user1);
// create User
user2 = new User();
user2.setUsername("user2");
user2.setEmail("user2@usergrid.org");
- user2 = app.getEm().create(user2);
+ user2 = app.getEntityManager().create(user2);
ns = getNotificationService();
TestQueueManager qm = new TestQueueManager();
ns.TEST_QUEUE_MANAGER = qm;
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
listener = new QueueListener(ns.getServiceManagerFactory(),ns.getEntityManagerFactory(),ns.getMetricsFactory(), new Properties());
listener.TEST_QUEUE_MANAGER = qm;
@@ -145,7 +145,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// create push notification //
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// give queue manager a query for loading 100 devices from an application (why?)
app.clear();
@@ -164,7 +164,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
// ensure notification has expected name
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getName().toString()),
payload);
@@ -172,8 +172,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// verify Query for CREATED state
Query query = new Query();
query.addEqualityFilter("state", Notification.State.STARTED.toString());
- Results results = app.getEm().searchCollection(
- app.getEm().getApplicationRef(), "notifications", query);
+ Results results = app.getEntityManager().searchCollection(
+ app.getEntityManager().getApplicationRef(), "notifications", query);
Entity entity = results.getEntitiesMap().get(notification.getUuid());
//assertNotNull(entity);
@@ -181,12 +181,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
notification = scheduleNotificationAndWait(notification);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// verify Query for FINISHED state
query = new Query();
query.addEqualityFilter("state", Notification.State.FINISHED.toString());
- results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+ results = app.getEntityManager().searchCollection(app.getEntityManager().getApplicationRef(),
"notifications", query);
entity = results.getEntitiesMap().get(notification.getUuid());
assertNotNull(entity);
@@ -219,7 +219,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
- Device device = app.getEm().get(e.getUuid(), Device.class);
+ Device device = app.getEntityManager().get(e.getUuid(), Device.class);
assertEquals(device.getProperty(key), PUSH_TOKEN);
// create push notification //
@@ -238,7 +238,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
payload
@@ -248,7 +248,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// verify Query for CREATED state
Query query = new Query();
query.addEqualityFilter("state", Notification.State.FINISHED.toString());
- Results results = app.getEm().searchCollection(app.getEm().getApplicationRef(), "notifications", query);
+ Results results = app.getEntityManager().searchCollection(app.getEntityManager().getApplicationRef(), "notifications", query);
Entity entity = results.getEntitiesMap().get(notification.getUuid());
assertNotNull(entity);
@@ -257,12 +257,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// perform push //
//ns.getQueueManager().processBatchAndReschedule(notification, null);
- notification = app.getEm().get(e.getUuid(), Notification.class);
+ notification = app.getEntityManager().get(e.getUuid(), Notification.class);
// verify Query for FINISHED state
query = new Query();
query.addEqualityFilter("state", Notification.State.FINISHED.toString());
- results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+ results = app.getEntityManager().searchCollection(app.getEntityManager().getApplicationRef(),
"notifications", query);
entity = results.getEntitiesMap().get(notification.getUuid());
assertNotNull(entity);
@@ -289,9 +289,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
.getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -305,12 +305,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Query query = new Query();
query.addEqualityFilter("state",
Notification.State.SCHEDULED.toString());
- Results results = app.getEm().searchCollection(
- app.getEm().getApplicationRef(), "notifications", query);
+ Results results = app.getEntityManager().searchCollection(
+ app.getEntityManager().getApplicationRef(), "notifications", query);
Entity entity = results.getEntitiesMap().get(notification.getUuid());
assertNotNull(entity);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
try {
e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
@@ -318,7 +318,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
}catch (Exception deleteException){
LOG.error("Couldn't delete",deleteException);
}
- app.getEm().get(e.getUuid(), Notification.class);
+ app.getEntityManager().get(e.getUuid(), Notification.class);
}
@Test
@@ -365,7 +365,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
fis.close();
Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
.getEntity();
- Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+ Notifier notifier2 = app.getEntityManager().get(e.getUuid(), Notifier.class);
payloads.clear();
StringBuilder sb = new StringBuilder();
@@ -409,7 +409,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
.getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -421,11 +421,11 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
notification = scheduleNotificationAndWait(notification);
checkStatistics(notification, 0, 1);
- notification = (Notification) app.getEm().get(notification)
+ notification = (Notification) app.getEntityManager().get(notification)
.toTypedEntity();
checkReceipts(notification, 1);
List<EntityRef> receipts = getNotificationReceipts(notification);
- Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+ Receipt receipt = app.getEntityManager().get(receipts.get(0), Receipt.class);
assertEquals(8, ((Long) receipt.getErrorCode()).longValue());
}
@@ -444,7 +444,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "devices","notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(),Notification.class);
//assertEquals(notification.getPayloads().get(notifier.getUuid().toString()),payload);
@@ -471,11 +471,11 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
.getEntity();
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
app.testRequest(ServiceAction.GET, 1, "notifiers", "apNs2");
- Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+ Notifier notifier2 = app.getEntityManager().get(e.getUuid(), Notifier.class);
assertEquals(notifier2.getName(), "apNs2");
assertEquals(notifier2.getProvider(), PROVIDER);
assertEquals(notifier2.getEnvironment(), "development");
@@ -484,9 +484,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
String key2 = notifier2Name + NOTIFIER_ID_POSTFIX;
device2.setProperty(key, null);
device2.setProperty(key2, PUSH_TOKEN);
- app.getEm().update(device2);
+ app.getEntityManager().update(device2);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// create push notification //
@@ -502,15 +502,15 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
e = app.testRequest(ServiceAction.POST, 1, "devices","notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
assertEquals(notification.getPayloads().get(notifierName), payload);
// perform push //
notification = scheduleNotificationAndWait(notification);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
}
@@ -535,18 +535,18 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
- Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+ Notifier notifier2 = app.getEntityManager().get(e.getUuid(), Notifier.class);
assertEquals(notifier2.getName(), nameValue);
assertEquals(notifier2.getProvider(), PROVIDER);
assertEquals(notifier2.getEnvironment(), environValue);
String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
device1.setProperty(key2, PUSH_TOKEN);
- app.getEm().update(device1);
+ app.getEntityManager().update(device1);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// create push notification //
@@ -562,9 +562,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -572,12 +572,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
ns.addDevice(notification, device1);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// perform push //
notification = scheduleNotificationAndWait(notification);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
checkReceipts(notification, 1);
}
@@ -601,7 +601,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
.getEntity();
- notifier = app.getEm().get(e.getUuid(), Notifier.class);
+ notifier = app.getEntityManager().get(e.getUuid(), Notifier.class);
// mock error (based on verified actual behavior) //
if (!USE_REAL_CONNECTIONS) {
@@ -630,7 +630,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -650,8 +650,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// verify Query for FAILED state
Query query = new Query();
query.addEqualityFilter("state", Notification.State.FAILED.toString());
- Results results = app.getEm().searchCollection(
- app.getEm().getApplicationRef(), "notifications", query);
+ Results results = app.getEntityManager().searchCollection(
+ app.getEntityManager().getApplicationRef(), "notifications", query);
Entity entity = results.getEntitiesMap().get(notification.getUuid());
assertNotNull(entity);
}
@@ -679,7 +679,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
.getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -695,9 +695,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// check provider IDs //
- device1 = app.getEm().get(device1, Device.class);
+ device1 = app.getEntityManager().get(device1, Device.class);
assertNull(device1 .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
- device2 = app.getEm().get(device2, Device.class);
+ device2 = app.getEntityManager().get(device2, Device.class);
assertNull(device2 .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
}
@@ -710,17 +710,17 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.clear();
e = app.testRequest(ServiceAction.POST, 1, "users",user1.getUuid(),"devices",device2.getUuid()).getEntity();
- List device1Users = app.getEm().getCollection(device1,"users",null,100, Query.Level.REFS,false).getEntities();
+ List device1Users = app.getEntityManager().getCollection(device1,"users",null,100, Query.Level.REFS,false).getEntities();
assertEquals(device1Users.size(),1);
- List user1Devices = app.getEm().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
+ List user1Devices = app.getEntityManager().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
assertEquals(user1Devices.size(),2);
app.clear();
e = app.testRequest(ServiceAction.POST, 1, "users",user1.getUuid(),"devices",device2.getUuid()).getEntity();
- user1Devices = app.getEm().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
+ user1Devices = app.getEntityManager().getCollection(user1,"devices",null,100, Query.Level.REFS,false).getEntities();
assertEquals(user1Devices.size(),2);
// create push notification //
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// give queue manager a query for loading 100 devices from an application (why?)
app.clear();
@@ -739,7 +739,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
// ensure notification has expected name
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getName().toString()),
payload);
@@ -747,8 +747,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// verify Query for CREATED state
Query query = new Query();
query.addEqualityFilter("state", Notification.State.STARTED.toString());
- Results results = app.getEm().searchCollection(
- app.getEm().getApplicationRef(), "notifications", query);
+ Results results = app.getEntityManager().searchCollection(
+ app.getEntityManager().getApplicationRef(), "notifications", query);
Entity entity = results.getEntitiesMap().get(notification.getUuid());
//assertNotNull(entity);
@@ -756,12 +756,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
notification = scheduleNotificationAndWait(notification);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// verify Query for FINISHED state
query = new Query();
query.addEqualityFilter("state", Notification.State.FINISHED.toString());
- results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+ results = app.getEntityManager().searchCollection(app.getEntityManager().getApplicationRef(),
"notifications", query);
entity = results.getEntitiesMap().get(notification.getUuid());
assertNotNull(entity);
@@ -784,9 +784,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.put("provider","noop");
app.put("environment", "mock");
Entity entity = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
- Notifier notifier = app.getEm().get(entity.getUuid(), Notifier.class);
+ Notifier notifier = app.getEntityManager().get(entity.getUuid(), Notifier.class);
final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// create a bunch of devices and add them to the notification
@@ -795,7 +795,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.put(notifierKey, PUSH_TOKEN);
app.put("name", "device"+i*10);
app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
}
@@ -810,7 +810,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// create a notification
entity = app.testRequest(ServiceAction.POST, 1, "devices","notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", entity.getUuid());
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
final Notification notification = (Notification) entity.toTypedEntity();
@@ -846,7 +846,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
// Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
// path).getEntity();
// Thread.sleep(1000); // this sucks
- // Notification notification = app.getEm().get(e, Notification.class);
+ // Notification notification = app.getEntityManager().get(e, Notification.class);
// return notification;
// }
//
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index ad1c9f2..5228464 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -85,12 +85,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "devices") .getEntity();
app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
- device1 = app.getEm().get(e.getUuid(), Device.class);
+ device1 = app.getEntityManager().get(e.getUuid(), Device.class);
assertEquals(device1.getProperty(key), PUSH_TOKEN);
app.put(key, PUSH_TOKEN);
e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
- device2 = app.getEm().get(e.getUuid(), Device.class);
+ device2 = app.getEntityManager().get(e.getUuid(), Device.class);
ns = getNotificationService();
TestQueueManager qm = new TestQueueManager();
@@ -134,7 +134,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
.getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
// perform push //
@@ -156,7 +156,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "devices",device1.getUuid(),"notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
payload);
@@ -191,13 +191,13 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1,"users",user.getUuid(), "notifications").getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
// perform push //
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
notification = scheduleNotificationAndWait(notification);
- app.getEm().refreshIndex();
+ app.getEntityManager().refreshIndex();
checkReceipts(notification, 1);
}
@@ -216,7 +216,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
Entity e = app.testRequest(ServiceAction.POST, 1, "devices","notifications") .getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(), Notification.class);
+ Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
payload);
@@ -276,7 +276,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.put("apiKey", API_KEY);
Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
.getEntity();
- Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+ Notifier notifier2 = app.getEntityManager().get(e.getUuid(), Notifier.class);
payloads.clear();
StringBuilder sb = new StringBuilder();
@@ -320,7 +320,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
.getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -331,7 +331,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x");
e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
- device1 = app.getEm().get(e.getUuid(), Device.class);
+ device1 = app.getEntityManager().get(e.getUuid(), Device.class);
ns.addDevice(notification, device1);
@@ -340,7 +340,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
List<EntityRef> receipts = getNotificationReceipts(notification);
assertEquals(1, receipts.size());
- Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+ Receipt receipt = app.getEntityManager().get(receipts.get(0), Receipt.class);
assertEquals("InvalidRegistration", receipt.getErrorCode());
}
@@ -362,7 +362,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
.getEntity();
app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
- Notification notification = app.getEm().get(e.getUuid(),
+ Notification notification = app.getEntityManager().get(e.getUuid(),
Notification.class);
assertEquals(
notification.getPayloads().get(notifier.getUuid().toString()),
@@ -371,7 +371,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
ns.addDevice(notification, device1);
// save bad API key
- app.getEm().setProperty(notifier, "apiKey", API_KEY + "x");
+ app.getEntityManager().setProperty(notifier, "apiKey", API_KEY + "x");
// perform push //
[3/3] incubator-usergrid git commit: Merge branch 'two-dot-o' of
https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Posted by to...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/7deba17f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/7deba17f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/7deba17f
Branch: refs/heads/two-dot-o
Commit: 7deba17fc453747324388c1062fb0ac628546250
Parents: 92534be d70ca53
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Nov 13 15:14:15 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Nov 13 15:14:15 2014 -0700
----------------------------------------------------------------------
.../java/org/apache/usergrid/rest/BasicIT.java | 124 +++++++++++--------
1 file changed, 72 insertions(+), 52 deletions(-)
----------------------------------------------------------------------
[2/3] incubator-usergrid git commit: Refactored ManagerCache to be a
guice module for reuse in low level guice components.
Posted by to...@apache.org.
Refactored ManagerCache to be a guice module for reuse in low level guice components.
Added tests to obervable generatators for ensuring compatibility with current write logic
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/92534beb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/92534beb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/92534beb
Branch: refs/heads/two-dot-o
Commit: 92534beb95201b8174bb6fb790df11a183501923
Parents: 43b0ba6
Author: Todd Nine <tn...@apigee.com>
Authored: Thu Nov 13 15:13:59 2014 -0700
Committer: Todd Nine <tn...@apigee.com>
Committed: Thu Nov 13 15:13:59 2014 -0700
----------------------------------------------------------------------
.../corepersistence/CpEntityManager.java | 10 +-
.../corepersistence/CpEntityManagerFactory.java | 80 +++------
.../corepersistence/CpManagerCache.java | 132 +++++++--------
.../corepersistence/CpRelationManager.java | 7 +-
.../usergrid/corepersistence/CpSetup.java | 16 +-
.../usergrid/corepersistence/GuiceModule.java | 1 +
.../usergrid/corepersistence/ManagerCache.java | 69 ++++++++
.../usergrid/corepersistence/NamingUtils.java | 75 ---------
.../migration/EntityTypeMappingMigration.java | 20 +--
.../migration/GraphShardVersionMigration.java | 17 +-
.../results/FilteringLoader.java | 9 +-
.../results/ResultsLoaderFactoryImpl.java | 7 +-
.../rx/AllEntitiesInSystemObservable.java | 24 ++-
.../rx/ApplicationObservable.java | 62 ++++---
.../rx/EdgesFromSourceObservable.java | 14 +-
.../rx/EdgesToTargetObservable.java | 63 ++++++++
.../corepersistence/rx/TargetIdObservable.java | 9 +-
.../corepersistence/util/CpNamingUtils.java | 53 ++++++
.../usergrid/persistence/SimpleEntityRef.java | 6 +
.../org/apache/usergrid/CoreApplication.java | 4 -
.../rx/AllEntitiesInSystemObservableIT.java | 153 ++++++++++++++++++
.../rx/ApplicationObservableTestIT.java | 82 ++++++++++
.../rx/EdgesFromSourceObservableIT.java | 152 +++++++++++++++++
.../rx/EdgesToTargetObservableIT.java | 162 +++++++++++++++++++
.../rx/TargetIdObservableTestIT.java | 143 ++++++++++++++++
.../persistence/EntityConnectionsIT.java | 2 +-
.../PerformanceEntityRebuildIndexTest.java | 4 +-
.../query/AbstractIteratingQueryIT.java | 20 +--
.../query/AllInConnectionNoTypeIT.java | 2 +-
.../org/apache/usergrid/ServiceApplication.java | 18 +--
.../usergrid/services/ConnectionsServiceIT.java | 4 +-
.../usergrid/services/GroupServiceIT.java | 4 +-
.../usergrid/services/RolesServiceIT.java | 2 +-
.../usergrid/services/UsersServiceIT.java | 2 +-
.../AbstractServiceNotificationIT.java | 12 +-
.../notifications/NotifiersServiceIT.java | 2 +-
.../apns/NotificationsServiceIT.java | 132 +++++++--------
.../gcm/NotificationsServiceIT.java | 28 ++--
38 files changed, 1196 insertions(+), 406 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/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 84f9efe..2158bd1 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
@@ -180,7 +180,7 @@ public class CpEntityManager implements EntityManager {
private CpEntityManagerFactory emf;
- private CpManagerCache managerCache;
+ private ManagerCache managerCache;
private ApplicationScope applicationScope;
@@ -207,7 +207,7 @@ public class CpEntityManager implements EntityManager {
this.managerCache = this.emf.getManagerCache();
this.applicationId = applicationId;
- applicationScope = NamingUtils.getApplicationScope( applicationId );
+ applicationScope = CpNamingUtils.getApplicationScope( applicationId );
this.cass = this.emf.cass;
this.counterUtils = this.emf.counterUtils;
@@ -277,7 +277,7 @@ public class CpEntityManager implements EntityManager {
}
- public CpManagerCache getManagerCache() {
+ public ManagerCache getManagerCache() {
return managerCache;
}
@@ -2227,7 +2227,7 @@ public class CpEntityManager implements EntityManager {
*/
private MapManager getMapManagerForTypes() {
Id mapOwner = new SimpleId( applicationId, TYPE_APPLICATION );
- MapScope ms = new MapScopeImpl( mapOwner, NamingUtils.TYPES_BY_UUID_MAP );
+ MapScope ms = new MapScopeImpl( mapOwner, CpNamingUtils.TYPES_BY_UUID_MAP );
MapManager mm = managerCache.getMapManager( ms );
return mm;
@@ -2804,7 +2804,7 @@ public class CpEntityManager implements EntityManager {
@Override
public void flushManagerCaches() {
- managerCache.flush();
+ managerCache.invalidate();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 6393237..6da58bb 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -37,7 +37,6 @@ import org.apache.commons.lang.StringUtils;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.AbstractEntity;
-import org.apache.usergrid.persistence.DynamicEntity;
import org.apache.usergrid.persistence.Entity;
import org.apache.usergrid.persistence.EntityFactory;
import org.apache.usergrid.persistence.EntityManager;
@@ -110,7 +109,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
});
- private CpManagerCache managerCache;
+ private ManagerCache managerCache;
private DataMigrationManager dataMigrationManager;
CassandraService cass;
@@ -129,14 +128,14 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
private void init() {
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
try {
if ( em.getApplication() == null ) {
logger.info("Creating system application");
Map sysAppProps = new HashMap<String, Object>();
sysAppProps.put( PROPERTY_NAME, "systemapp");
- em.create( NamingUtils.SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps );
+ em.create( CpNamingUtils.SYSTEM_APP_ID, TYPE_APPLICATION, sysAppProps );
em.getApplication();
em.createIndex();
em.refreshIndex();
@@ -148,24 +147,14 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
}
- public CpManagerCache getManagerCache() {
+ public ManagerCache getManagerCache() {
if ( managerCache == null ) {
- // TODO: better solution for getting injector?
+ // TODO: better solution for getting injector?
Injector injector = CpSetup.getInjector();
- EntityCollectionManagerFactory ecmf;
- EntityIndexFactory eif;
- GraphManagerFactory gmf;
- MapManagerFactory mmf;
-
- ecmf = injector.getInstance( EntityCollectionManagerFactory.class );
- eif = injector.getInstance( EntityIndexFactory.class );
- gmf = injector.getInstance( GraphManagerFactory.class );
- mmf = injector.getInstance( MapManagerFactory.class );
-
- managerCache = new CpManagerCache( ecmf, eif, gmf, mmf );
+ managerCache = injector.getInstance( ManagerCache.class );
dataMigrationManager = injector.getInstance( DataMigrationManager.class );
}
@@ -244,7 +233,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
Map<String, Object> properties ) throws Exception {
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
final String appName = buildAppName( organizationName, name );
@@ -310,7 +299,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// Query q = Query.fromQL(PROPERTY_NAME + " = '" + name + "'");
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID );
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
final EntityRef alias = em.getAlias( "organizations", name );
@@ -340,10 +329,10 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
public UUID lookupApplication( String name ) throws Exception {
init();
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID );
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID );
- final EntityRef alias = em.getAlias( "appinfos", name );
+ final EntityRef alias = em.getAlias( CpNamingUtils.APPINFOS, name );
if ( alias == null ) {
return null;
@@ -359,25 +348,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
final UUID property = ( UUID ) entity.getProperty( "applicationUuid" );
return property;
-
-
- // Query q = Query.fromQL( PROPERTY_NAME + " = '" + name + "'");
- //
- // EntityManager em = getEntityManager(SYSTEM_APP_ID);
- //
- //
- // Results results = em.searchCollection( em.getApplicationRef(), "appinfos", q);
- //
- // if ( results.isEmpty() ) {
- // return null;
- // }
- //
- // Entity entity = results.iterator().next();
- // Object uuidObject = entity.getProperty("applicationUuid");
- // if ( uuidObject instanceof UUID ) {
- // return (UUID)uuidObject;
- // }
- // return UUIDUtils.tryExtractUUID( entity.getProperty("applicationUuid").toString() );
}
@@ -387,14 +357,14 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
Map<String, UUID> appMap = new HashMap<String, UUID>();
- ApplicationScope appScope = NamingUtils.getApplicationScope( NamingUtils.SYSTEM_APP_ID );
+ ApplicationScope appScope = CpNamingUtils.getApplicationScope( CpNamingUtils.SYSTEM_APP_ID );
GraphManager gm = managerCache.getGraphManager(appScope);
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
Application app = em.getApplication();
Id fromEntityId = new SimpleId( app.getUuid(), app.getType() );
- String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( "appinfos" );
+ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPINFOS );
logger.debug("getApplications(): Loading edges of edgeType {} from {}:{}",
new Object[] { edgeType, fromEntityId.getType(), fromEntityId.getUuid() } );
@@ -417,7 +387,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
CollectionScope collScope = new CollectionScopeImpl(
appScope.getApplication(),
appScope.getApplication(),
- CpNamingUtils.getCollectionScopeNameFromCollectionName( "appinfos" ));
+ CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPINFOS ));
org.apache.usergrid.persistence.model.entity.Entity e =
managerCache.getEntityCollectionManager( collScope ).load( targetId )
@@ -443,7 +413,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
Map<String, String> props = new HashMap<String,String>();
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
Query q = Query.fromQL("select *");
Results results = null;
try {
@@ -468,7 +438,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public boolean updateServiceProperties(Map<String, String> properties) {
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
Query q = Query.fromQL("select *");
Results results = null;
try {
@@ -517,7 +487,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public boolean deleteServiceProperty(String name) {
- EntityManager em = getEntityManager( NamingUtils.SYSTEM_APP_ID);
+ EntityManager em = getEntityManager( CpNamingUtils.SYSTEM_APP_ID);
Query q = Query.fromQL("select *");
@@ -575,13 +545,13 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public UUID getManagementAppId() {
- return NamingUtils.MANAGEMENT_APPLICATION_ID;
+ return CpNamingUtils.MANAGEMENT_APPLICATION_ID;
}
@Override
public UUID getDefaultAppId() {
- return NamingUtils.DEFAULT_APPLICATION_ID;
+ return CpNamingUtils.DEFAULT_APPLICATION_ID;
}
@@ -630,7 +600,7 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
return Arrays.asList(
getManagerCache().getEntityIndex(
- new ApplicationScopeImpl( new SimpleId( NamingUtils.SYSTEM_APP_ID, "application" ))),
+ new ApplicationScopeImpl( new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application" ))),
// management app
getManagerCache().getEntityIndex(
@@ -660,9 +630,9 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
@Override
public void rebuildInternalIndexes( ProgressObserver po ) throws Exception {
- rebuildApplicationIndexes( NamingUtils.SYSTEM_APP_ID, po);
- rebuildApplicationIndexes( NamingUtils.MANAGEMENT_APPLICATION_ID, po );
- rebuildApplicationIndexes( NamingUtils.DEFAULT_APPLICATION_ID, po );
+ rebuildApplicationIndexes( CpNamingUtils.SYSTEM_APP_ID, po);
+ rebuildApplicationIndexes( CpNamingUtils.MANAGEMENT_APPLICATION_ID, po );
+ rebuildApplicationIndexes( CpNamingUtils.DEFAULT_APPLICATION_ID, po );
}
@@ -719,8 +689,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
// could use any collection scope here, does not matter
EntityCollectionManager ecm = getManagerCache().getEntityCollectionManager(
new CollectionScopeImpl(
- new SimpleId( NamingUtils.SYSTEM_APP_ID, "application"),
- new SimpleId( NamingUtils.SYSTEM_APP_ID, "application"),
+ new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application"),
+ new SimpleId( CpNamingUtils.SYSTEM_APP_ID, "application"),
"dummy"
));
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
index a73dc6e..e29e5c2 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpManagerCache.java
@@ -15,11 +15,9 @@
*/
package org.apache.usergrid.corepersistence;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.CacheLoader;
-import com.google.common.cache.LoadingCache;
+
import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
+
import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
@@ -32,8 +30,13 @@ import org.apache.usergrid.persistence.map.MapManager;
import org.apache.usergrid.persistence.map.MapManagerFactory;
import org.apache.usergrid.persistence.map.MapScope;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import com.google.inject.Inject;
+
-public class CpManagerCache {
+public class CpManagerCache implements ManagerCache {
private final EntityCollectionManagerFactory ecmf;
private final EntityIndexFactory eif;
@@ -42,51 +45,40 @@ public class CpManagerCache {
// TODO: consider making these cache sizes and timeouts configurable
- private LoadingCache<CollectionScope, EntityCollectionManager> ecmCache =
- CacheBuilder.newBuilder()
- .maximumSize(1000)
- .build( new CacheLoader<CollectionScope, EntityCollectionManager>() {
- public EntityCollectionManager load( CollectionScope scope ) {
- return ecmf.createCollectionManager( scope );
- }
- }
- );
-
- private LoadingCache<ApplicationScope, EntityIndex> eiCache =
- CacheBuilder.newBuilder()
- .maximumSize(1000)
- .build( new CacheLoader<ApplicationScope, EntityIndex>() {
- public EntityIndex load( ApplicationScope scope ) {
- return eif.createEntityIndex( scope );
- }
- }
- );
-
- private LoadingCache<ApplicationScope, GraphManager> gmCache =
- CacheBuilder.newBuilder()
- .maximumSize(1000)
- .build( new CacheLoader<ApplicationScope, GraphManager>() {
- public GraphManager load( ApplicationScope scope ) {
- return gmf.createEdgeManager( scope );
- }
- }
- );
-
- private LoadingCache<MapScope, MapManager> mmCache =
- CacheBuilder.newBuilder()
- .maximumSize(1000)
- .build( new CacheLoader<MapScope, MapManager>() {
- public MapManager load( MapScope scope ) {
- return mmf.createMapManager( scope );
- }
- }
- );
-
- public CpManagerCache(
- EntityCollectionManagerFactory ecmf,
- EntityIndexFactory eif,
- GraphManagerFactory gmf,
- MapManagerFactory mmf) {
+ private LoadingCache<CollectionScope, EntityCollectionManager> ecmCache =
+ CacheBuilder.newBuilder().maximumSize( 1000 )
+ .build( new CacheLoader<CollectionScope, EntityCollectionManager>() {
+ public EntityCollectionManager load( CollectionScope scope ) {
+ return ecmf.createCollectionManager( scope );
+ }
+ } );
+
+ private LoadingCache<ApplicationScope, EntityIndex> eiCache =
+ CacheBuilder.newBuilder().maximumSize( 1000 ).build( new CacheLoader<ApplicationScope, EntityIndex>() {
+ public EntityIndex load( ApplicationScope scope ) {
+ return eif.createEntityIndex( scope );
+ }
+ } );
+
+ private LoadingCache<ApplicationScope, GraphManager> gmCache =
+ CacheBuilder.newBuilder().maximumSize( 1000 ).build( new CacheLoader<ApplicationScope, GraphManager>() {
+ public GraphManager load(
+ ApplicationScope scope ) {
+ return gmf.createEdgeManager( scope );
+ }
+ } );
+
+ private LoadingCache<MapScope, MapManager> mmCache =
+ CacheBuilder.newBuilder().maximumSize( 1000 ).build( new CacheLoader<MapScope, MapManager>() {
+ public MapManager load( MapScope scope ) {
+ return mmf.createMapManager( scope );
+ }
+ } );
+
+
+ @Inject
+ public CpManagerCache( final EntityCollectionManagerFactory ecmf, final EntityIndexFactory eif,
+ final GraphManagerFactory gmf, final MapManagerFactory mmf ) {
this.ecmf = ecmf;
this.eif = eif;
@@ -94,39 +86,53 @@ public class CpManagerCache {
this.mmf = mmf;
}
- public EntityCollectionManager getEntityCollectionManager(CollectionScope scope) {
+
+ @Override
+ public EntityCollectionManager getEntityCollectionManager( CollectionScope scope ) {
try {
return ecmCache.get( scope );
- } catch (ExecutionException ex) {
- throw new RuntimeException("Error getting manager", ex);
+ }
+ catch ( ExecutionException ex ) {
+ throw new RuntimeException( "Error getting manager", ex );
}
}
- public EntityIndex getEntityIndex(ApplicationScope appScope) {
+
+ @Override
+ public EntityIndex getEntityIndex( ApplicationScope appScope ) {
try {
return eiCache.get( appScope );
- } catch (ExecutionException ex) {
- throw new RuntimeException("Error getting manager", ex);
+ }
+ catch ( ExecutionException ex ) {
+ throw new RuntimeException( "Error getting manager", ex );
}
}
- public GraphManager getGraphManager(ApplicationScope appScope) {
+
+ @Override
+ public GraphManager getGraphManager( ApplicationScope appScope ) {
try {
return gmCache.get( appScope );
- } catch (ExecutionException ex) {
- throw new RuntimeException("Error getting manager", ex);
+ }
+ catch ( ExecutionException ex ) {
+ throw new RuntimeException( "Error getting manager", ex );
}
}
- public MapManager getMapManager( MapScope mapScope) {
+
+ @Override
+ public MapManager getMapManager( MapScope mapScope ) {
try {
return mmCache.get( mapScope );
- } catch (ExecutionException ex) {
- throw new RuntimeException("Error getting manager", ex);
+ }
+ catch ( ExecutionException ex ) {
+ throw new RuntimeException( "Error getting manager", ex );
}
}
- void flush() {
+
+ @Override
+ public void invalidate() {
ecmCache.invalidateAll();
eiCache.invalidateAll();
gmCache.invalidateAll();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
index 9943842..8514504 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpRelationManager.java
@@ -168,7 +168,7 @@ public class CpRelationManager implements RelationManager {
private CpEntityManagerFactory emf;
- private CpManagerCache managerCache;
+ private ManagerCache managerCache;
private EntityManager em;
@@ -213,7 +213,7 @@ public class CpRelationManager implements RelationManager {
this.applicationId = applicationId;
this.headEntity = headEntity;
this.managerCache = emf.getManagerCache();
- this.applicationScope = NamingUtils.getApplicationScope( applicationId );
+ this.applicationScope = CpNamingUtils.getApplicationScope( applicationId );
this.cass = em.getCass(); // TODO: eliminate need for this via Core Persistence
this.indexBucketLocator = indexBucketLocator; // TODO: this also
@@ -224,7 +224,6 @@ public class CpRelationManager implements RelationManager {
this.applicationScope.getApplication(),
CpNamingUtils.getCollectionScopeNameFromEntityType( headEntity.getType() ) );
- EntityCollectionManager ecm = managerCache.getEntityCollectionManager( headEntityScope );
if ( logger.isDebugEnabled() ) {
logger.debug( "Loading head entity {}:{} from scope\n app {}\n owner {}\n name {}",
new Object[] {
@@ -1023,8 +1022,6 @@ public class CpRelationManager implements RelationManager {
applicationScope.getApplication(),
CpNamingUtils.getCollectionScopeNameFromEntityType( connectedEntityRef.getType() ) );
- EntityCollectionManager targetEcm = managerCache.getEntityCollectionManager( targetScope );
-
if ( logger.isDebugEnabled() ) {
logger.debug("createConnection(): "
+ "Indexing connection type '{}'\n from source {}:{}]\n"
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
index 9a34114..d48a20c 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpSetup.java
@@ -27,6 +27,8 @@ import me.prettyprint.cassandra.service.CassandraHost;
import me.prettyprint.hector.api.ddl.ComparatorType;
import static me.prettyprint.hector.api.factory.HFactory.createColumnFamilyDefinition;
import org.apache.commons.lang.StringUtils;
+
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.mq.cassandra.QueuesCF;
import org.apache.usergrid.persistence.EntityManagerFactory;
import org.apache.usergrid.persistence.cassandra.ApplicationCF;
@@ -59,10 +61,14 @@ public class CpSetup implements Setup {
private static final Logger logger = LoggerFactory.getLogger( CpSetup.class );
+ private static Injector injector = null;
+
+
private final org.apache.usergrid.persistence.EntityManagerFactory emf;
private final CassandraService cass;
- private GuiceModule gm;
+
+
/**
@@ -76,7 +82,7 @@ public class CpSetup implements Setup {
}
- private static Injector injector = null;
+
public static Injector getInjector() {
if ( injector == null ) {
@@ -181,10 +187,6 @@ public class CpSetup implements Setup {
}
- /** @return staticly constructed reference to the management application */
- public static Application getManagementApp() {
- return SystemDefaults.managementApp;
- }
@Override
@@ -271,7 +273,7 @@ public class CpSetup implements Setup {
static class SystemDefaults {
private static final Application managementApp =
- new Application( NamingUtils.MANAGEMENT_APPLICATION_ID);
+ new Application( CpNamingUtils.MANAGEMENT_APPLICATION_ID);
// private static final Application defaultApp =
// new Application( CpEntityManagerFactory.DEFAULT_APPLICATION_ID );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
index beaeab4..2d80672 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/GuiceModule.java
@@ -51,6 +51,7 @@ public class GuiceModule extends AbstractModule {
bind(CpEntityDeleteListener.class).asEagerSingleton();
bind(CpEntityIndexDeleteListener.class).asEagerSingleton();
+ bind(ManagerCache.class).to( CpManagerCache.class );
Multibinder<DataMigration> dataMigrationMultibinder = Multibinder.newSetBinder( binder(), DataMigration.class );
dataMigrationMultibinder.addBinding().to( EntityTypeMappingMigration.class );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
new file mode 100644
index 0000000..c1b7b95
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ManagerCache.java
@@ -0,0 +1,69 @@
+/*
+ * 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.corepersistence;
+
+
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.persistence.map.MapManager;
+import org.apache.usergrid.persistence.map.MapScope;
+
+
+/**
+ * The cache of the manager
+ */
+public interface ManagerCache {
+ /**
+ * Get the entity collection manager for the specified scope
+ * @param scope
+ * @return
+ */
+ EntityCollectionManager getEntityCollectionManager( CollectionScope scope );
+
+ /**
+ * Get the entity index for the specified app scope
+ * @param appScope
+ * @return
+ */
+ EntityIndex getEntityIndex( ApplicationScope appScope );
+
+ /**
+ * Get the graph manager for the graph scope
+ * @param appScope
+ * @return
+ */
+ GraphManager getGraphManager( ApplicationScope appScope );
+
+ /**
+ * Get the map manager for the map scope
+ * @param mapScope
+ * @return
+ */
+ MapManager getMapManager( MapScope mapScope );
+
+ /**
+ * Invalidate all cache entries
+ */
+ void invalidate();
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/NamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/NamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/NamingUtils.java
deleted file mode 100644
index 580d128..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/NamingUtils.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.corepersistence;
-
-
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.core.scope.ApplicationScope;
-import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
-import org.apache.usergrid.persistence.entities.Application;
-import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-
-
-/**
- * Static class to encapsulate naming conventions used through the CP entity system
- */
-public class NamingUtils {
-
-
- /** The System Application where we store app and org metadata */
- public static final UUID SYSTEM_APP_ID =
- UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
- /** App where we store management info */
- public static final UUID MANAGEMENT_APPLICATION_ID =
- UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
- /** TODO Do we need this in two-dot-o? */
- public static final UUID DEFAULT_APPLICATION_ID =
- UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
-
- /**
- * The name of the map that holds our entity id->type mapping
- */
- public static String TYPES_BY_UUID_MAP = "zzz_typesbyuuid_zzz";
-
-
- /**
- * Get the application scope from the given uuid
- * @param applicationId The applicationId
- */
- public static ApplicationScope getApplicationScope( UUID applicationId ) {
-
- // We can always generate a scope, it doesn't matter if the application exists yet or not.
- final ApplicationScopeImpl scope = new ApplicationScopeImpl( generateApplicationId( applicationId ) );
-
- return scope;
- }
-
-
- /**
- * Generate an applicationId from the given UUID
- * @param applicationId the applicationId
- *
- */
- public static Id generateApplicationId( UUID applicationId ) {
- return new SimpleId( applicationId, Application.ENTITY_TYPE );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigration.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigration.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigration.java
index 36d2e60..f2712cc 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigration.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/EntityTypeMappingMigration.java
@@ -26,8 +26,10 @@ import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.corepersistence.NamingUtils;
+import org.apache.usergrid.corepersistence.ManagerCache;
import org.apache.usergrid.corepersistence.rx.AllEntitiesInSystemObservable;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
import org.apache.usergrid.persistence.core.migration.data.DataMigration;
import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.map.MapManager;
@@ -48,15 +50,13 @@ public class EntityTypeMappingMigration implements DataMigration {
private static final Logger logger = LoggerFactory.getLogger( EntityTypeMappingMigration.class );
- private final GraphManagerFactory graphManagerFactory;
- private final MapManagerFactory mapManagerFactory;
+ private final ManagerCache managerCache;
+
@Inject
- public EntityTypeMappingMigration( final GraphManagerFactory graphManagerFactory,
- final MapManagerFactory mapManagerFactory ) {
- this.graphManagerFactory = graphManagerFactory;
- this.mapManagerFactory = mapManagerFactory;
+ public EntityTypeMappingMigration( final ManagerCache managerCache) {
+ this.managerCache = managerCache;
}
@@ -65,7 +65,7 @@ public class EntityTypeMappingMigration implements DataMigration {
final AtomicLong atomicLong = new AtomicLong();
- AllEntitiesInSystemObservable.getAllEntitiesInSystem( graphManagerFactory )
+ AllEntitiesInSystemObservable.getAllEntitiesInSystem(managerCache )
.doOnNext( new Action1<AllEntitiesInSystemObservable.EntityData>() {
@@ -73,10 +73,10 @@ public class EntityTypeMappingMigration implements DataMigration {
public void call( final AllEntitiesInSystemObservable.EntityData entityData ) {
final MapScope ms = new MapScopeImpl( entityData.entityId,
- NamingUtils.TYPES_BY_UUID_MAP );
+ CpNamingUtils.TYPES_BY_UUID_MAP );
- final MapManager mapManager = mapManagerFactory.createMapManager( ms );
+ final MapManager mapManager = managerCache.getMapManager( ms );
final UUID entityUuid = entityData.entityId.getUuid();
final String entityType = entityData.entityId.getType();
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigration.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigration.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigration.java
index c2573e4..ad45dab 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigration.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/migration/GraphShardVersionMigration.java
@@ -23,19 +23,18 @@ package org.apache.usergrid.corepersistence.migration;
import java.util.List;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.apache.usergrid.corepersistence.ManagerCache;
import org.apache.usergrid.corepersistence.rx.AllEntitiesInSystemObservable;
import org.apache.usergrid.corepersistence.rx.EdgesFromSourceObservable;
import org.apache.usergrid.persistence.core.guice.CurrentImpl;
import org.apache.usergrid.persistence.core.migration.data.DataMigration;
import org.apache.usergrid.persistence.graph.Edge;
import org.apache.usergrid.persistence.graph.GraphManager;
-import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.graph.serialization.EdgeMetadataSerialization;
import com.google.inject.Inject;
@@ -59,15 +58,16 @@ public class GraphShardVersionMigration implements DataMigration {
private final EdgeMetadataSerialization v2Serialization;
- private final GraphManagerFactory graphManagerFactory;
+ private final ManagerCache managerCache;
private final Keyspace keyspace;
@Inject
public GraphShardVersionMigration( @CurrentImpl final EdgeMetadataSerialization v2Serialization,
- final GraphManagerFactory graphManagerFactory, final Keyspace keyspace ) {
+ final ManagerCache managerCache, final
+ Keyspace keyspace ) {
this.v2Serialization = v2Serialization;
- this.graphManagerFactory = graphManagerFactory;
+ this.managerCache = managerCache;
this.keyspace = keyspace;
}
@@ -77,7 +77,7 @@ public class GraphShardVersionMigration implements DataMigration {
final AtomicLong counter = new AtomicLong();
- AllEntitiesInSystemObservable.getAllEntitiesInSystem( graphManagerFactory ).flatMap(
+ AllEntitiesInSystemObservable.getAllEntitiesInSystem( managerCache).flatMap(
new Func1<AllEntitiesInSystemObservable.EntityData, Observable<List<Edge>>>() {
@@ -86,11 +86,10 @@ public class GraphShardVersionMigration implements DataMigration {
logger.info( "Migrating edges from node {} in scope {}", entityData.entityId,
entityData.applicationScope );
- final GraphManager gm = graphManagerFactory.createEdgeManager( entityData.applicationScope );
+ final GraphManager gm = managerCache.getGraphManager( entityData.applicationScope );
//get each edge from this node as a source
- return EdgesFromSourceObservable.edgesFromSource( entityData.applicationScope,
- entityData.entityId, gm )
+ return EdgesFromSourceObservable.edgesFromSource( gm, entityData.entityId )
//for each edge, re-index it in v2 every 1000 edges or less
.buffer( 1000 ).doOnNext( new Action1<List<Edge>>() {
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
index d6e63aa..c1d42ea 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/FilteringLoader.java
@@ -33,9 +33,8 @@ import javax.annotation.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.corepersistence.CpManagerCache;
+import org.apache.usergrid.corepersistence.ManagerCache;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
-import org.apache.usergrid.persistence.EntityRef;
import org.apache.usergrid.persistence.Results;
import org.apache.usergrid.persistence.collection.CollectionScope;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
@@ -44,11 +43,9 @@ import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.index.EntityIndex;
import org.apache.usergrid.persistence.index.EntityIndexBatch;
import org.apache.usergrid.persistence.index.IndexScope;
-import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
import org.apache.usergrid.persistence.index.query.CandidateResult;
import org.apache.usergrid.persistence.index.query.CandidateResults;
import org.apache.usergrid.persistence.model.entity.Id;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
import com.fasterxml.uuid.UUIDComparator;
import com.google.common.base.Function;
@@ -60,7 +57,7 @@ public class FilteringLoader implements ResultsLoader {
private static final Logger logger = LoggerFactory.getLogger( FilteringLoader.class );
- private final CpManagerCache managerCache;
+ private final ManagerCache managerCache;
private final ResultsVerifier resultsVerifier;
private final ApplicationScope applicationScope;
private final IndexScope indexScope;
@@ -74,7 +71,7 @@ public class FilteringLoader implements ResultsLoader {
* @param applicationScope The application scope to perform the load
* @param indexScope The index scope used in the search
*/
- protected FilteringLoader( final CpManagerCache managerCache, final ResultsVerifier resultsVerifier, final ApplicationScope applicationScope, final IndexScope indexScope ) {
+ protected FilteringLoader( final ManagerCache managerCache, final ResultsVerifier resultsVerifier, final ApplicationScope applicationScope, final IndexScope indexScope ) {
this.managerCache = managerCache;
this.resultsVerifier = resultsVerifier;
this.applicationScope = applicationScope;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactoryImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactoryImpl.java
index 96928fb..892b736 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactoryImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/results/ResultsLoaderFactoryImpl.java
@@ -20,8 +20,7 @@
package org.apache.usergrid.corepersistence.results;
-import org.apache.usergrid.corepersistence.CpManagerCache;
-import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.corepersistence.ManagerCache;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.index.IndexScope;
import org.apache.usergrid.persistence.index.query.Query;
@@ -34,11 +33,11 @@ import com.google.inject.Inject;
*/
public class ResultsLoaderFactoryImpl implements ResultsLoaderFactory {
- private final CpManagerCache managerCache;
+ private final ManagerCache managerCache;
@Inject
- public ResultsLoaderFactoryImpl( final CpManagerCache managerCache ) {
+ public ResultsLoaderFactoryImpl( final ManagerCache managerCache ) {
this.managerCache = managerCache;
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservable.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservable.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservable.java
index dcd6c89..291bbe9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservable.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservable.java
@@ -20,13 +20,10 @@
package org.apache.usergrid.corepersistence.rx;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import org.apache.usergrid.corepersistence.ManagerCache;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
import org.apache.usergrid.persistence.graph.GraphManager;
-import org.apache.usergrid.persistence.graph.GraphManagerFactory;
import org.apache.usergrid.persistence.model.entity.Id;
import rx.Observable;
@@ -35,7 +32,7 @@ import rx.functions.Func1;
/**
* An observable that will emit every entity Id stored in our entire system across all apps.
- * Note that this only walks each application id graph, and emits edges from the applicationId and it's edges as the s
+ * Note that this only walks each application applicationId graph, and emits edges from the applicationId and it's edges as the s
* source node
*/
public class AllEntitiesInSystemObservable {
@@ -44,29 +41,30 @@ public class AllEntitiesInSystemObservable {
/**
* Return an observable that emits all entities in the system.
*/
- public static Observable<EntityData> getAllEntitiesInSystem( final GraphManagerFactory graphManagerFactory ) {
+ public static Observable<EntityData> getAllEntitiesInSystem( final ManagerCache managerCache) {
//traverse all nodes in the graph, load all source edges from them, then re-save the meta data
- return ApplicationObservable.getAllApplicationIds( graphManagerFactory )
+ return ApplicationObservable.getAllApplicationIds( managerCache )
.flatMap( new Func1<Id, Observable<EntityData>>() {
@Override
- public Observable<EntityData> call( final Id id ) {
+ public Observable<EntityData> call( final Id applicationId ) {
//set up our application scope and graph manager
- final ApplicationScope applicationScope = new ApplicationScopeImpl( id );
+ final ApplicationScope applicationScope = new ApplicationScopeImpl(
+ applicationId );
final GraphManager gm =
- graphManagerFactory.createEdgeManager( applicationScope );
+ managerCache.getGraphManager( applicationScope );
//load all nodes that are targets of our application node. I.E.
// entities that have been saved
final Observable<Id> entityNodes =
- TargetIdObservable.getTargetNodes( applicationScope, id, gm );
+ TargetIdObservable.getTargetNodes(gm, applicationId );
- //create our application node
- final Observable<Id> applicationNode = Observable.just( id );
+ //create our application node to emit since it's an entity as well
+ final Observable<Id> applicationNode = Observable.just( applicationId );
//merge both the specified application node and the entity node
// so they all get used
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
index 93ba9f0..898812b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/ApplicationObservable.java
@@ -21,12 +21,14 @@ package org.apache.usergrid.corepersistence.rx;
import java.util.Arrays;
+import java.util.UUID;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import org.apache.usergrid.corepersistence.NamingUtils;
+import org.apache.usergrid.corepersistence.ManagerCache;
import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManager;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.graph.Edge;
import org.apache.usergrid.persistence.graph.GraphManager;
@@ -36,12 +38,10 @@ import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
import org.apache.usergrid.persistence.model.entity.Id;
import rx.Observable;
-import rx.Subscriber;
-import rx.functions.Action1;
import rx.functions.Func1;
-import static org.apache.usergrid.corepersistence.NamingUtils.generateApplicationId;
-import static org.apache.usergrid.corepersistence.NamingUtils.getApplicationScope;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.generateApplicationId;
+import static org.apache.usergrid.corepersistence.util.CpNamingUtils.getApplicationScope;
/**
@@ -53,36 +53,60 @@ public class ApplicationObservable {
/**
* Get all applicationIds as an observable
- * @param graphManagerFactory
+ * @param managerCache
* @return
*/
- public static Observable<Id> getAllApplicationIds( final GraphManagerFactory graphManagerFactory ) {
+ public static Observable<Id> getAllApplicationIds( final ManagerCache managerCache ) {
//emit our 3 hard coded applications that are used the manage the system first.
//this way consumers can perform whatever work they need to on the root system first
- final Observable<Id> systemIds = Observable.from( Arrays.asList( generateApplicationId( NamingUtils.DEFAULT_APPLICATION_ID ),
- generateApplicationId( NamingUtils.MANAGEMENT_APPLICATION_ID ),
- generateApplicationId( NamingUtils.SYSTEM_APP_ID ) ) );
+ final Observable<Id> systemIds = Observable.from( Arrays.asList( generateApplicationId( CpNamingUtils.DEFAULT_APPLICATION_ID ),
+ generateApplicationId( CpNamingUtils.MANAGEMENT_APPLICATION_ID ),
+ generateApplicationId( CpNamingUtils.SYSTEM_APP_ID ) ) );
+
+
+
+
+ final ApplicationScope appScope = getApplicationScope( CpNamingUtils.SYSTEM_APP_ID );
+ final CollectionScope appInfoCollectionScope = new CollectionScopeImpl(
+ appScope.getApplication(),
+ appScope.getApplication(),
+ CpNamingUtils.getCollectionScopeNameFromCollectionName( CpNamingUtils.APPINFOS ));
+ final EntityCollectionManager
+ collectionManager = managerCache.getEntityCollectionManager( appInfoCollectionScope );
- ApplicationScope appScope = getApplicationScope( NamingUtils.SYSTEM_APP_ID );
- GraphManager gm = graphManagerFactory.createEdgeManager( appScope );
+ final GraphManager gm = managerCache.getGraphManager( appScope );
- String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( "appinfos" );
+
+ String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPINFOS );
Id rootAppId = appScope.getApplication();
+ //we have app infos. For each of these app infos, we have to load the application itself
Observable<Id> appIds = gm.loadEdgesFromSource(
new SimpleSearchByEdgeType( rootAppId, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING,
- null ) ).map( new Func1<Edge, Id>() {
+ null ) ).flatMap( new Func1<Edge, Observable<Id>>() {
@Override
- public Id call( final Edge edge ) {
- return edge.getTargetNode();
+ public Observable<Id> call( final Edge edge ) {
+ //get the app info and load it
+ final Id appInfo = edge.getTargetNode();
+
+ return collectionManager.load( appInfo ).map( new Func1<org.apache.usergrid.persistence.model.entity.Entity, Id>() {
+
+
+ @Override
+ public Id call( final org.apache.usergrid.persistence.model.entity.Entity entity ) {
+ final UUID uuid = (UUID )entity.getField( "applicationUuid" ).getValue();
+
+ return CpNamingUtils.generateApplicationId(uuid);
+ }
+ } );
}
} );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservable.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservable.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservable.java
index 88efc7b..d3e2ee5 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservable.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservable.java
@@ -36,7 +36,7 @@ import rx.functions.Func1;
/**
- * Emits the id of all nodes that are target nodes for the given source node
+ * Emits the edges that are edges from the specified source node
*/
public class EdgesFromSourceObservable {
@@ -46,22 +46,16 @@ public class EdgesFromSourceObservable {
/**
* Get all edges from the source
*/
- public static Observable<Edge> edgesFromSource( final ApplicationScope applicationScope, final Id sourceNode,
- final GraphManager gm ) {
- final Id applicationId = applicationScope.getApplication();
- //only search edge types that start with collections
-
-
+ public static Observable<Edge> edgesFromSource( final GraphManager gm, final Id sourceNode){
Observable<String> edgeTypes = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( sourceNode, null, null ) );
return edgeTypes.flatMap( new Func1<String, Observable<Edge>>() {
@Override
public Observable<Edge> call( final String edgeType ) {
- logger.debug( "Loading edges of edgeType {} from {}\n scope {}",
- new Object[] { edgeType, sourceNode, applicationScope } );
+ logger.debug( "Loading edges of edgeType {} from {}", edgeType, sourceNode );
- return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( applicationId, edgeType, Long.MAX_VALUE,
+ return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( sourceNode, edgeType, Long.MAX_VALUE,
SearchByEdgeType.Order.DESCENDING, null ) );
}
} );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservable.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservable.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservable.java
new file mode 100644
index 0000000..c5dc54d
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/EdgesToTargetObservable.java
@@ -0,0 +1,63 @@
+/*
+ * 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.corepersistence.rx;
+
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import rx.Observable;
+import rx.functions.Func1;
+
+
+/**
+ * Emits the id of all edges where the given node is the target node
+ */
+public class EdgesToTargetObservable {
+
+ private static final Logger logger = LoggerFactory.getLogger( EdgesToTargetObservable.class );
+
+
+ /**
+ * Get all edges from the source
+ */
+ public static Observable<Edge> getEdgesToTarget(final GraphManager gm, final Id targetNode) {
+ Observable<String> edgeTypes = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( targetNode, null, null ) );
+
+ return edgeTypes.flatMap( new Func1<String, Observable<Edge>>() {
+ @Override
+ public Observable<Edge> call( final String edgeType ) {
+
+ logger.debug( "Loading edges of edgeType {} to {}", edgeType, targetNode);
+
+ return gm.loadEdgesToTarget( new SimpleSearchByEdgeType( targetNode, edgeType, Long.MAX_VALUE,
+ SearchByEdgeType.Order.DESCENDING, null ) );
+ }
+ } );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/TargetIdObservable.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/TargetIdObservable.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/TargetIdObservable.java
index 91ba741..3925aae 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/TargetIdObservable.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/rx/TargetIdObservable.java
@@ -23,7 +23,6 @@ package org.apache.usergrid.corepersistence.rx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.usergrid.persistence.core.scope.ApplicationScope;
import org.apache.usergrid.persistence.graph.Edge;
import org.apache.usergrid.persistence.graph.GraphManager;
import org.apache.usergrid.persistence.model.entity.Id;
@@ -42,15 +41,15 @@ public class TargetIdObservable {
/**
* Get all nodes that are target nodes from the sourceNode
- * @param applicationScope
- * @param sourceNode
* @param gm
+ * @param sourceNode
+ *
* @return
*/
- public static Observable<Id> getTargetNodes(final ApplicationScope applicationScope, final Id sourceNode, final GraphManager gm) {
+ public static Observable<Id> getTargetNodes( final GraphManager gm, final Id sourceNode) {
//only search edge types that start with collections
- return EdgesFromSourceObservable.edgesFromSource( applicationScope, sourceNode, gm ).map( new Func1<Edge, Id>() {
+ return EdgesFromSourceObservable.edgesFromSource(gm, sourceNode ).map( new Func1<Edge, Id>() {
@Override
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
index 9154752..52449de 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpNamingUtils.java
@@ -19,7 +19,14 @@ package org.apache.usergrid.corepersistence.util;
*/
+import java.util.UUID;
+
import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
/**
@@ -28,6 +35,12 @@ import org.apache.usergrid.persistence.Schema;
public class CpNamingUtils {
/**
+ * TODO: Why do we have 3? Can we merge this into a single management app? It would make administration much
+ * easier and cleaner on the ES side
+ *
+ */
+
+ /**
* Edge types for collection suffix
*/
public static final String EDGE_COLL_SUFFIX = "zzzcollzzz";
@@ -36,6 +49,23 @@ public class CpNamingUtils {
* Edge types for connection suffix
*/
public static final String EDGE_CONN_SUFFIX = "zzzconnzzz";
+ /** The System Application where we store app and org metadata */
+ public static final UUID SYSTEM_APP_ID =
+ UUID.fromString("b6768a08-b5d5-11e3-a495-10ddb1de66c3");
+ /** App where we store management info */
+ public static final UUID MANAGEMENT_APPLICATION_ID =
+ UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c8");
+ /** TODO Do we need this in two-dot-o? */
+ public static final UUID DEFAULT_APPLICATION_ID =
+ UUID.fromString("b6768a08-b5d5-11e3-a495-11ddb1de66c9");
+ /**
+ * The app infos entity object type. This holds the app name, appId, and org name
+ */
+ public static final String APPINFOS = "appinfos";
+ /**
+ * The name of the map that holds our entity id->type mapping
+ */
+ public static String TYPES_BY_UUID_MAP = "zzz_typesbyuuid_zzz";
public static String getCollectionScopeNameFromEntityType( String type ) {
@@ -99,4 +129,27 @@ public class CpNamingUtils {
return null;
}
+
+
+ /**
+ * Get the application scope from the given uuid
+ * @param applicationId The applicationId
+ */
+ public static ApplicationScope getApplicationScope( UUID applicationId ) {
+
+ // We can always generate a scope, it doesn't matter if the application exists yet or not.
+ final ApplicationScopeImpl scope = new ApplicationScopeImpl( generateApplicationId( applicationId ) );
+
+ return scope;
+ }
+
+
+ /**
+ * Generate an applicationId from the given UUID
+ * @param applicationId the applicationId
+ *
+ */
+ public static Id generateApplicationId( UUID applicationId ) {
+ return new SimpleId( applicationId, Application.ENTITY_TYPE );
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java b/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
index 65f093f..f5949af 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/SimpleEntityRef.java
@@ -22,6 +22,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.UUID;
+import org.apache.usergrid.persistence.model.entity.Id;
+
public class SimpleEntityRef implements EntityRef {
@@ -51,6 +53,10 @@ public class SimpleEntityRef implements EntityRef {
}
+ public static SimpleEntityRef fromId(final Id id){
+ return new SimpleEntityRef(id.getType(), id.getUuid() );
+ }
+
public static EntityRef ref() {
return new SimpleEntityRef( null, null );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index f6d9132..edc887d 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -160,10 +160,6 @@ public class CoreApplication implements Application, TestRule {
}
- public EntityManager getEm() {
- return em;
- }
-
public QueueManager getQm() {
return setup.getQmf().getQueueManager( getId() );
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
new file mode 100644
index 0000000..c6a4572
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/AllEntitiesInSystemObservableIT.java
@@ -0,0 +1,153 @@
+/*
+ * 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.corepersistence.rx;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.ManagerCache;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+
+import rx.functions.Action1;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * Tests that when we create a few entities, we get their data.
+ */
+public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {
+
+ private final Logger logger = LoggerFactory.getLogger( AllEntitiesInSystemObservableIT.class );
+
+ @Test
+ public void testEntities() throws Exception {
+
+ final EntityManager em = app.getEntityManager();
+
+ final String type1 = "type1thing";
+ final String type2 = "type2thing";
+ final int size = 10;
+
+ final Set<Id> type1Identities = createTypes( em, type1, size );
+ final Set<Id> type2Identities = createTypes( em, type2, size );
+
+ //create a connection and put that in our connection types
+ final Id source = type1Identities.iterator().next();
+
+
+ final Set<Id> allEntities = new HashSet<>();
+ allEntities.addAll( type1Identities );
+ allEntities.addAll( type2Identities );
+
+ final Set<Id> connections = new HashSet<>();
+
+ for ( Id target : type2Identities ) {
+ em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
+ connections.add( target );
+ }
+
+
+ //this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
+ //clean up our wiring
+ //
+ ManagerCache managerCache = CpSetup.getInjector().getInstance( ManagerCache.class );
+
+
+ final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );
+ final Id applicationId = scope.getApplication();
+
+
+ final GraphManager gm = managerCache.getGraphManager( scope );
+
+ AllEntitiesInSystemObservable.getAllEntitiesInSystem( managerCache ).doOnNext( new Action1<AllEntitiesInSystemObservable.EntityData>() {
+ @Override
+ public void call( final AllEntitiesInSystemObservable.EntityData entity ) {
+
+ assertNotNull(entity);
+ assertNotNull(entity.applicationScope);
+ assertNotNull(entity.entityId);
+
+ //not from our test, don't check it
+ if(!applicationId.equals( entity.applicationScope.getApplication() )){
+ return;
+ }
+
+
+ //we should only emit each node once
+ if ( entity.entityId.getType().equals( type1 ) ) {
+ assertTrue( "Element should be present on removal", type1Identities.remove( entity.entityId ) );
+ }
+ else if ( entity.entityId.getType().equals( type2 ) ) {
+ assertTrue( "Element should be present on removal", type2Identities.remove( entity.entityId ) );
+ }
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+
+ assertEquals( "Every element should have been encountered", 0, type1Identities.size() );
+ assertEquals( "Every element should have been encountered", 0, type2Identities.size() );
+
+
+ //test connections
+
+ TargetIdObservable.getTargetNodes( gm, source ).doOnNext( new Action1<Id>() {
+ @Override
+ public void call( final Id target ) {
+
+ assertTrue( "Element should be present on removal", connections.remove( target ) );
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+ assertEquals( "Every connection should have been encountered", 0, connections.size() );
+ }
+
+
+ private Set<Id> createTypes( final EntityManager em, final String type, final int size ) throws Exception {
+
+ final Set<Id> identities = new HashSet<>();
+
+ for ( int i = 0; i < size; i++ ) {
+ final Entity entity = em.create( type, new HashMap<String, Object>(){{put("property", "value");}} );
+ final Id createdId = new SimpleId( entity.getUuid(), entity.getType() );
+
+ identities.add( createdId );
+ }
+
+ return identities;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
new file mode 100644
index 0000000..f8f3c50
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/ApplicationObservableTestIT.java
@@ -0,0 +1,82 @@
+/*
+ * 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.corepersistence.rx;
+
+
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.ManagerCache;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import rx.Observable;
+import rx.functions.Action1;
+
+import static junit.framework.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+
+
+/**
+ * Test we see our applications
+ */
+public class ApplicationObservableTestIT extends AbstractCoreIT {
+
+ @Test
+ public void getAllApplications() throws Exception {
+
+ final Application createdApplication = app.getEntityManager().getApplication();
+
+
+ //now our get all apps we expect. There may be more, but we don't care about those.
+ final Set<UUID> applicationIds = new HashSet<UUID>() {{
+ add( CpNamingUtils.DEFAULT_APPLICATION_ID );
+ add( CpNamingUtils.MANAGEMENT_APPLICATION_ID );
+ add( CpNamingUtils.SYSTEM_APP_ID );
+ add( createdApplication.getUuid() );
+ }};
+
+
+ //this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
+ //clean up our wiring
+ ManagerCache managerCache = CpSetup.getInjector().getInstance( ManagerCache.class );
+
+ Observable<Id> appObservable = ApplicationObservable.getAllApplicationIds( managerCache );
+
+ appObservable.doOnNext( new Action1<Id>() {
+ @Override
+ public void call( final Id id ) {
+ applicationIds.remove( id.getUuid() );
+ assertEquals("Correct application type expected" , Application.ENTITY_TYPE, id.getType() );
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+
+ assertEquals( "Every element should have been encountered" , 0, applicationIds.size() );
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/92534beb/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservableIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservableIT.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservableIT.java
new file mode 100644
index 0000000..4fa669c
--- /dev/null
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/rx/EdgesFromSourceObservableIT.java
@@ -0,0 +1,152 @@
+/*
+ * 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.corepersistence.rx;
+
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+
+import org.junit.Test;
+
+import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.CpSetup;
+import org.apache.usergrid.corepersistence.ManagerCache;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.GraphManager;
+import org.apache.usergrid.persistence.graph.GraphManagerFactory;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+
+import rx.functions.Action1;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Tests that when we create a few entities, we get their data.
+ */
+public class EdgesFromSourceObservableIT extends AbstractCoreIT {
+
+
+ @Test
+ public void testEntities() throws Exception {
+
+ final EntityManager em = app.getEntityManager();
+ final Application createdApplication = em.getApplication();
+
+
+
+ final String type1 = "targetthings";
+ final String type2 = "sourcethings";
+ final int size = 10;
+
+
+
+ final Set<Id> sourceIdentities = createTypes( em, type2, size );
+
+
+ final Entity entity = em.create( type1, new HashMap<String, Object>(){{put("property", "value");}} );
+ final Id target = new SimpleId( entity.getUuid(), entity.getType() );
+
+
+
+
+ for ( Id source : sourceIdentities ) {
+ em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
+ }
+
+
+ //this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
+ //clean up our wiring
+ //
+ ManagerCache managerCache = CpSetup.getInjector().getInstance( ManagerCache.class );
+
+
+ final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );
+
+
+ final GraphManager gm = managerCache.getGraphManager( scope );
+
+ EdgesToTargetObservable.getEdgesToTarget( gm, target ).doOnNext( new Action1<Edge>() {
+ @Override
+ public void call( final Edge edge ) {
+ final String edgeType = edge.getType();
+ final Id source = edge.getSourceNode();
+
+ //test if we're a collection, if so
+ if ( CpNamingUtils.isCollectionEdgeType( edgeType ) ) {
+ final String collectionName = CpNamingUtils.getCollectionName( edgeType );
+
+ assertEquals("application source returned", createdApplication.getUuid(), source.getUuid());
+
+ final String expectedCollection = Schema.defaultCollectionName( target.getType() );
+
+ assertEquals("right type returned", expectedCollection, collectionName);
+
+ return;
+ }
+
+
+
+ if ( !CpNamingUtils.isConnectionEdgeType( edgeType ) ) {
+ fail( "Only connection edges should be encountered" );
+ }
+
+ final String connectionType = CpNamingUtils.getConnectionType( edgeType );
+
+ assertEquals( "Same connection type expected", "likes", connectionType );
+
+
+ assertTrue( "Element should be present on removal", sourceIdentities.remove( source ) );
+
+
+
+ }
+ } ).toBlocking().lastOrDefault( null );
+
+
+ }
+
+
+ private Set<Id> createTypes( final EntityManager em, final String type, final int size ) throws Exception {
+
+ final Set<Id> identities = new HashSet<>();
+
+ for ( int i = 0; i < size; i++ ) {
+ final Entity entity = em.create( type, new HashMap<String, Object>(){{put("property", "value");}} );
+ final Id createdId = new SimpleId( entity.getUuid(), entity.getType() );
+
+ identities.add( createdId );
+ }
+
+ return identities;
+ }
+}