@Override public GraphManager getGraphManager( ApplicationScope appScope ) { return gmf.createEdgeManager( appScope ); }
@Override public Observable<EdgeScope> getEdgesToEntities( final Observable<ApplicationScope> appScopes, final Optional<String> edgeType, final Optional<Edge> lastEdge) { return appScopes.flatMap( applicationScope -> { final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); return edgesObservable.edgesFromSourceDescending( gm, applicationScope.getApplication(), edgeType, lastEdge ) .map( edge -> new EdgeScope(applicationScope, edge )); } ); } }
@Override public Set<String> getConnectionsAsSource( final EntityRef entityRef ) { Preconditions.checkNotNull(entityRef, "entityRef cannot be null"); final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope ); final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() ); return graphManager.getEdgeTypesFromSource( searchByEdgeType ).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) ) .collect( () -> new HashSet<String>(), ( r, s ) -> r.add( s ) ).toBlocking().last(); }
@Override public Set<String> getConnectionsAsTarget( final EntityRef entityRef ) { Preconditions.checkNotNull( entityRef, "entityRef cannot be null" ); final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope ); final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() ); return graphManager.getEdgeTypesToTarget(searchByEdgeType).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) ) .collect( () -> new HashSet<String>( ), ( r, s ) -> r.add(s) ).toBlocking().last(); }
@Override public Observable<EntityIdScope> getEntities( final Observable<ApplicationScope> appScopes ) { return appScopes.flatMap( applicationScope -> { final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); final Id applicationId = applicationScope.getApplication(); //load all nodes that are targets of our application node. I.E. // entities that have been saved final Observable<Id> entityNodes = targetIdObservable.getTargetNodes( gm, applicationId ); //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 return Observable.merge( applicationNode, entityNodes ). map( id -> new EntityIdScope( applicationScope, id ) ); } ); }
@Override public Observable<FilterResult<Id>> call( final Observable<FilterResult<Id>> filterValueObservable ) { final GraphManager gm = graphManagerFactory.createEdgeManager( pipelineContext.getApplicationScope() ); return filterValueObservable.flatMap( filterValue -> { final String edgeTypeName = getEdgeName(); final Id id = filterValue.getValue(); //create our search final SearchByEdge searchByEdge = new SimpleSearchByEdge( id, edgeTypeName, targetId, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); //load the versions of the edge, take the first since that's all we need to validate existence, then emit the target node return gm.loadEdgeVersions( searchByEdge ).take( 1 ).map( edge -> edge.getTargetNode() ).map( targetId -> new FilterResult<>(targetId, filterValue.getPath())); } ); }
@Override public long getApplicationSize(ApplicationScope applicationScope) { final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope); EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy); GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope); Long sum = ObservableTimer.time( MathObservable.sumLong( graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent())) .map(type -> CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type)) .map(edge -> entityIndex.getTotalEntitySizeInBytes(edge)) ), sumTimer).toBlocking().last(); return sum.longValue(); }
public Observable<MarkedEdge> getApplicationInfoEdges( final UUID applicationId ) { final ApplicationScope managementAppScope = getApplicationScope( CpNamingUtils.MANAGEMENT_APPLICATION_ID ); final GraphManager gm = graphManagerFactory.createEdgeManager( managementAppScope ); String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName( CpNamingUtils.APPLICATION_INFOS ); final SimpleSearchByEdge simpleSearchByEdgeType = new SimpleSearchByEdge( CpNamingUtils.generateApplicationId( CpNamingUtils.MANAGEMENT_APPLICATION_ID ), edgeType, CpNamingUtils.generateApplicationId( applicationId ), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); return gm.loadEdgeVersions( simpleSearchByEdgeType ); } }
@Override public Observable<FilterResult<Id>> call( final Observable<FilterResult<Id>> filterResultObservable ) { //get the graph manager final GraphManager graphManager = graphManagerFactory.createEdgeManager( pipelineContext.getApplicationScope() ); final String edgeName = getEdgeTypeFromConnectionType( connectionName ); //return all ids that are emitted from this edge return filterResultObservable.flatMap( idFilterResult -> { //set our our constant state final Optional<MarkedEdge> startFromCursor = getSeekValue(); final Id id = idFilterResult.getValue(); final Optional<Edge> typeWrapper = Optional.fromNullable(startFromCursor.orNull()); final SimpleSearchByIdType search = new SimpleSearchByIdType( id, edgeName, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, entityType, typeWrapper ); return graphManager.loadEdgesFromSourceByType( search ).map( edge -> createFilterResult( edge.getTargetNode(), edge, idFilterResult.getPath() )); } ); }
@Test( expected = NullPointerException.class ) public void invalidEdgeTypesWrite() { final GraphManager em = emf.createEdgeManager( scope ); em.writeEdge( null ); }
@Test( expected = NullPointerException.class ) public void invalidEdgeTypesDelete() { final GraphManager em = emf.createEdgeManager( scope ); em.markEdge( null ); }
@Override public Long call() throws Exception { GraphManager gm = factory.createEdgeManager( scope ); while ( !Thread.currentThread().isInterrupted() ) { //do a read to eventually trigger our group compaction. Take 2 pages of columns final long returnedEdgeCount = generator.doSearch( gm ) .doOnNext( edge -> readMeter.mark() ) .countLong().toBlocking().last(); logger.info( "Completed reading {} edges", returnedEdgeCount ); if ( writeCount != returnedEdgeCount ) { logger.warn( "Unexpected edge count returned!!! Expected {} but was {}", writeCount, returnedEdgeCount ); } assertEquals( "Expected to read same edge count", writeCount, returnedEdgeCount ); } return 0L; } }
@Override public Boolean call() throws Exception { GraphManager manager = factory.createEdgeManager( scope ); final long startTime = System.currentTimeMillis(); for ( long i = 1; i < writeLimit +1 && System.currentTimeMillis() - startTime < minExecutionTime; i++ ) { Edge edge = generator.newEdge(); Edge returned = manager.writeEdge( edge ).toBlocking().last(); assertNotNull( "Returned has a version", returned.getTimestamp() ); writeCounter.incrementAndGet(); if ( i % 100 == 0 ) { logger.info( "wrote: " + i ); } } return true; } }
@Before public void setup() { applicationScope = getApplicationScope( UUIDGenerator.newTimeUUID() ); graphManager = graphManagerFactory.createEdgeManager( applicationScope ); initAkka( 2555, actorSystemManager, uniqueValuesService ); }
/** * Marks entity for deletion in entity collection manager and graph. * Convert this method to return a list of observables that we can crunch through on return. * Returns merged obversable that will mark the edges in the ecm and the graph manager. * @param entityRef * @return */ private Observable markEntity(EntityRef entityRef){ if(applicationScope == null || entityRef == null){ return Observable.empty(); } GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); EntityCollectionManager ecm = managerCache.getEntityCollectionManager( applicationScope ); Id entityId = new SimpleId( entityRef.getUuid(), entityRef.getType() ); //Step 1 & 2 of delete String region = this.lookupAuthoritativeRegionForType( entityRef.getType() ); return ecm.mark( entityId, region ).mergeWith( gm.markNode( entityId, createGraphOperationTimestamp() ) ); }
/** * Simple test case that tests a single edge and removing the node. The other target node should be removed as well * since it has no other targets */ @Test public void testNoDeletionMarked() { GraphManager em = emf.createEdgeManager( scope ); Edge edge = createEdge( "source", "test", "target" ); //write the edge Edge last = em.writeEdge( edge ).toBlocking().last(); assertEquals( edge, last ); Id sourceNode = edge.getSourceNode(); UUID eventTime = UUIDGenerator.newTimeUUID(); int count = deleteListener.receive( scope, sourceNode, eventTime ).count().toBlocking().last(); assertEquals( "Mark was not set, no delete should be executed", 0, count ); }
@Test public void testWriteReadEdgeTypeVersionSource() throws TimeoutException, InterruptedException { GraphManager gm = emf.createEdgeManager( scope ); final long earlyVersion = 1000l; Edge edge = createEdge( "source", "test", "target", earlyVersion ); gm.writeEdge( edge ).toBlocking().last(); //now test retrieving it SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), null ); Observable<MarkedEdge> edges = gm.loadEdgesFromSource( search ); //implicitly blows up if more than 1 is returned from "single" Edge returned = edges.toBlocking().single(); assertEquals( "Correct edge returned", edge, returned ); //now test with an earlier version, we shouldn't get the edge back search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion - 1, null ); edges = gm.loadEdgesFromSource( search ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().singleOrDefault( null ); assertNull( "Earlier version should not be returned", returned ); }
@Test public void testWriteReadEdgeTypeTarget() throws TimeoutException, InterruptedException { GraphManager gm = emf.createEdgeManager( scope ); Edge edge = createEdge( "source", "test", "target" ); gm.writeEdge( edge ).toBlocking().last(); //now test retrieving it SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), null ); Observable<MarkedEdge> edges = gm.loadEdgesToTarget( search ); //implicitly blows up if more than 1 is returned from "single" Edge returned = edges.toBlocking().single(); assertEquals( "Correct edge returned", edge, returned ); //change edge type to be invalid, shouldn't get a result search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getTimestamp(), null ); edges = gm.loadEdgesToTarget( search ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().singleOrDefault( null ); assertNull( "Invalid type should not be returned", returned ); }
@Test public void testWriteReadEdgeTypeSource() throws TimeoutException, InterruptedException { GraphManager gm = emf.createEdgeManager( scope ); Edge edge = createEdge( "source", "test", "target" ); gm.writeEdge( edge ).toBlocking().last(); //now test retrieving it SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), null ); Observable<MarkedEdge> edges = gm.loadEdgesFromSource( search ); //implicitly blows up if more than 1 is returned from "single" Edge returned = edges.toBlocking().last(); assertEquals( "Correct edge returned", edge, returned ); //change edge type to be invalid, shouldn't get a result search = createSearchByEdge( edge.getSourceNode(), edge.getType() + "invalid", edge.getTimestamp(), null ); edges = gm.loadEdgesFromSource( search ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().singleOrDefault( null ); assertNull( "Invalid type should not be returned", returned ); }
@Test public void testWriteReadEdgeTypeTargetTypeSource() { GraphManager gm = emf.createEdgeManager( scope ); Edge edge = createEdge( "source", "test", "target" ); gm.writeEdge( edge ).toBlocking().last(); //now test retrieving it SearchByIdType search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), edge.getTargetNode().getType(), null ); Observable<MarkedEdge> edges = gm.loadEdgesFromSourceByType( search ); //implicitly blows up if more than 1 is returned from "single" Edge returned = edges.toBlocking().single(); assertEquals( "Correct edge returned", edge, returned ); //change edge type to be invalid, shouldn't get a result search = createSearchByEdgeAndId( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), edge.getTargetNode().getType() + "invalid", null ); edges = gm.loadEdgesFromSourceByType( search ); //implicitly blows up if more than 1 is returned from "single" returned = edges.toBlocking().singleOrDefault( null ); assertNull( "Invalid type should not be returned", returned ); }