/** * Create a search edge based on the type * * @param sourceId The id in the search */ public static SearchEdgeType createConnectionTypeSearch( final Id sourceId ) { return new SimpleSearchEdgeType( sourceId, EDGE_CONN_PREFIX, null ); }
@Override public Observable<Edge> edgesFromSourceDescending( final GraphManager gm, final Id sourceNode, final Optional<String> edgeTypeInput, final Optional<Edge> resume ) { final Observable<String> edgeTypes = edgeTypeInput.isPresent()? Observable.just( edgeTypeInput.get() ): gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( sourceNode, null, null ) ); return edgeTypes.flatMap( edgeType -> { if (logger.isTraceEnabled()) { logger.trace("Loading edges of edgeType {} from {}", edgeType, sourceNode); } return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( sourceNode, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, resume ) ); } ); }
/** * * @param sourceId * @param last * @return */ public static SearchEdgeType createSearchEdge( final Id sourceId, final String last ) { return new SimpleSearchEdgeType( sourceId, null, Optional.fromNullable(last) ); }
@Override public Observable<Edge> getEdgesFromSource( final GraphManager gm, final Id sourceNode, final String targetType ) { final Observable<String> edgeTypes = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( sourceNode, null, null ) ); return edgeTypes.flatMap( edgeType -> { if (logger.isTraceEnabled()) { logger.trace("Loading edges of edgeType {} from {}", edgeType, sourceNode); } return gm.loadEdgesFromSourceByType( new SimpleSearchByIdType( sourceNode, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, targetType, null ) ); } ); }
/** * Get all edges from the source */ @Override public Observable<Edge> edgesToTarget(final GraphManager gm, final Id targetNode, boolean filterMarked) { return gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( targetNode, null, null ) ) .flatMap( edgeType -> { if (logger.isTraceEnabled()) { logger.trace("Loading edges of edgeType {} to {}", edgeType, targetNode); } return gm.loadEdgesToTarget( new SimpleSearchByEdgeType( targetNode, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent(), filterMarked ) ); } ); }
/** * Get all edges from the source */ @Override public Observable<Edge> edgesFromSourceDescending(final GraphManager gm, final Id sourceNode, boolean filterMarked) { final Observable<String> edgeTypes = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( sourceNode, null, null ) ); return edgeTypes.flatMap( edgeType -> { if (logger.isTraceEnabled()) { logger.trace("Loading edges of edgeType {} from {}", edgeType, sourceNode); } return gm.loadEdgesFromSource( new SimpleSearchByEdgeType( sourceNode, edgeType, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent(), filterMarked ) ); } ); }
@Override public Set<String> getCollections() throws Exception { final Set<String> indexes = new HashSet<String>(); GraphManager gm = managerCache.getGraphManager( applicationScope ); Observable<String> str = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) ); Iterator<String> iter = str.toBlocking().getIterator(); while ( iter.hasNext() ) { String edgeType = iter.next(); indexes.add( getNameFromEdgeType( edgeType ) ); } return indexes; }
@Override public Set<String> getConnectionTypes( boolean filterConnection ) throws Exception { final GraphManager gm = managerCache.getGraphManager( applicationScope ); Observable<String> edges = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), null, null ) ); return edges.collect( () -> new HashSet<String>(), ( edgeSet, edge ) -> { edgeSet.add( CpNamingUtils.getNameFromEdgeType( edge ) ); } ).toBlocking().last(); }
@Override public Set<String> getCollectionIndexes( String collectionName ) throws Exception { GraphManager gm = managerCache.getGraphManager( applicationScope ); String edgeTypePrefix = CpNamingUtils.getEdgeTypeFromCollectionName( collectionName ); if (logger.isTraceEnabled()) { logger.trace("getCollectionIndexes(): Searching for edge type prefix {} to target {}:{}", edgeTypePrefix, cpHeadEntity.getId().getType(), cpHeadEntity.getId().getUuid() ); } Observable<Set<String>> types = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeTypePrefix, null ) ) .collect( () -> new HashSet<>(), ( set, type ) -> set.add( type ) ); return types.toBlocking().last(); }
@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(); }
new SimpleSearchEdgeType( entityId, CpNamingUtils.EDGE_CONN_PREFIX, Optional.absent() ) )
getEdgesTypesToTarget(scope, new SimpleSearchEdgeType(node, null, null)) .flatMap(edgeType -> Observable.create(new ObservableIterator<MarkedEdge>("getTargetEdges") { @Override getEdgesTypesFromSource(scope, new SimpleSearchEdgeType(node, null, null)) .flatMap(edgeType -> Observable.create(new ObservableIterator<MarkedEdge>("getSourceEdges") { @Override
@Override public Map<String, Long> getEachCollectionSize(ApplicationScope applicationScope) { final IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope); EntityIndex entityIndex = entityIndexFactory.createEntityIndex(indexLocationStrategy); GraphManager graphManager = graphManagerFactory.createEdgeManager(applicationScope); Map<String,Long> sumMap = ObservableTimer.time( graphManager.getEdgeTypesFromSource(new SimpleSearchEdgeType(applicationScope.getApplication(), CpNamingUtils.EDGE_COLL_PREFIX, Optional.<String>absent())) .collect(() -> new HashMap<String,Long>(), ((map, type) -> { SearchEdge edge = CpNamingUtils.createCollectionSearchEdge(applicationScope.getApplication(), type); final String collectionName = CpNamingUtils.getCollectionNameFromEdgeName(type); long sumType = entityIndex.getTotalEntitySizeInBytes(edge); map.put(collectionName,sumType); }) ) , sumTimer).toBlocking().last(); return sumMap; }
new SimpleSearchEdgeType( applicationId, edgeType, null ) ).flatMap( emittedEdgeType -> {
gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( cpHeadEntity.getId(), edgeType, null ) ) .flatMap( edgeType1 -> gm.loadEdgesToTarget( new SimpleSearchByEdgeType( cpHeadEntity.getId(), edgeType1, Long.MAX_VALUE,
@Test public void testWriteReadEdgeTypesSourceTypesPrefix() { final GraphManager gm = emf.createEdgeManager( scope ); Id sourceId = new SimpleId( "source" ); Id targetId = new SimpleId( "target" ); Edge testTargetEdge = createEdge( sourceId, "test1edge1", targetId, System.currentTimeMillis() ); gm.writeEdge( testTargetEdge ).toBlocking().singleOrDefault( null ); Edge testTarget2Edge = createEdge( sourceId, "test1edge2", targetId, System.currentTimeMillis() ); gm.writeEdge( testTarget2Edge ).toBlocking().singleOrDefault( null ); Edge test2TargetEdge = createEdge( sourceId, "test2edge1", targetId, System.currentTimeMillis() ); gm.writeEdge( test2TargetEdge ).toBlocking().singleOrDefault( null ); //get our 2 edge types Observable<String> edges = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test1", null ) ); Iterator<String> results = edges.toBlocking().getIterator(); assertEquals( "Edges correct", "test1edge1", results.next() ); assertEquals( "Edges correct", "test1edge2", results.next() ); assertFalse( "No more edges", results.hasNext() ); edges = gm.getEdgeTypesFromSource( new SimpleSearchEdgeType( testTargetEdge.getSourceNode(), "test2", null ) ); results = edges.toBlocking().getIterator(); assertEquals( "Edges correct", "test2edge1", results.next() ); assertFalse( "No more edges", results.hasNext() ); }
@Test public void testWriteReadEdgeTypesTargetTypesPrefix() { final GraphManager gm = emf.createEdgeManager( scope ); Id targetId = new SimpleId( "target" ); Id sourceId = new SimpleId( "source" ); Edge testTargetEdge = createEdge( sourceId, "test1edge1", targetId, System.currentTimeMillis() ); gm.writeEdge( testTargetEdge ).toBlocking().singleOrDefault( null ); Edge testTarget2Edge = createEdge( sourceId, "test1edge2", targetId, System.currentTimeMillis() ); gm.writeEdge( testTarget2Edge ).toBlocking().singleOrDefault( null ); Edge test2TargetEdge = createEdge( sourceId, "test2edge1", targetId, System.currentTimeMillis() ); gm.writeEdge( test2TargetEdge ).toBlocking().singleOrDefault( null ); //get our 2 edge types Observable<String> edges = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), "test1", null ) ); Iterator<String> results = edges.toBlocking().getIterator(); assertEquals( "Edges correct", "test1edge1", results.next() ); assertEquals( "Edges correct", "test1edge2", results.next() ); assertFalse( "No more edges", results.hasNext() ); edges = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), "test2", null ) ); results = edges.toBlocking().getIterator(); assertEquals( "Edges correct", "test2edge1", results.next() ); assertFalse( "No more edges", results.hasNext() ); }
@Test public void testGetEdgesToTarget() { final GraphManager gm = emf.createEdgeManager( scope ); Id sourceId1 = new SimpleId( "source1" ); Id sourceId2 = new SimpleId( "source2" ); Id targetId1 = new SimpleId( "target" ); Edge testTargetEdge = createEdge( sourceId1, "test", targetId1, System.currentTimeMillis() ); gm.writeEdge( testTargetEdge ).toBlocking().singleOrDefault( null ); Edge testTarget2Edge = createEdge( sourceId2, "edgeType1", targetId1, System.currentTimeMillis() ); gm.writeEdge( testTarget2Edge ).toBlocking().singleOrDefault( null ); Edge test2TargetEdge = createEdge( sourceId1, "edgeType1", targetId1, System.currentTimeMillis() ); gm.writeEdge( test2TargetEdge ).toBlocking().singleOrDefault( null ); Edge test3TargetEdge = createEdge( sourceId1, "edgeType2", targetId1, System.currentTimeMillis() ); gm.writeEdge( test3TargetEdge ).toBlocking().singleOrDefault( null ); int count = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(targetId1, null, null) ) .count().toBlocking().last(); assertEquals( 3, count ); count = gm.getEdgeTypesToTarget( new SimpleSearchEdgeType(targetId1, "edgeType", null) ) .count().toBlocking().last(); assertEquals( 2, count ); }
SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null, null ); edgeTypes = new SimpleSearchEdgeType( testTargetEdge2.getTargetNode(), null, Optional.fromNullable( "test" ) );
final SearchEdgeType edgeTypes = new SimpleSearchEdgeType( testTargetEdge.getTargetNode(), null, null );