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/17 21:12:51 UTC
[41/50] [abbrv] incubator-usergrid git commit: Refactored
ManagerCache to be a guice module for reuse in low level guice components.
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-events
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;
+ }
+}