@Override public Iterator<MarkedEdge> loadEdges( final ShardedEdgeSerialization serialization, final EdgeColumnFamilies edgeColumnFamilies, final ApplicationScope scope, final Collection<Shard> shards, final long maxValue, final SearchByEdgeType.Order order ) { final Id sourceId = nodes[0].id; final Id targetId = nodes[1].id; final String edgeType = types[0]; final SimpleSearchByEdge search = new SimpleSearchByEdge( sourceId, edgeType, targetId, maxValue, order, Optional.absent() ); return serialization.getEdgeVersions( edgeColumnFamilies, scope, search, shards ); }
public static SearchByEdge createEdgeFromCollectionName(Id source, String connectionName, Id target) { final String edgeType = CpNamingUtils.getEdgeTypeFromCollectionName(connectionName); return new SimpleSearchByEdge(source, edgeType, target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent()); }
public static SearchByEdge createEdgeFromConnectionType(Id source, String connectionType, Id target) { final String edgeType = CpNamingUtils.getEdgeTypeFromConnectionType(connectionType); return new SimpleSearchByEdge(source, edgeType, target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent()); }
/** * search for all versions of a connection between 2 entities in teh graph * * @param sourceId The source id of the edge * @param connectionType The connection type used in the edge * @param targetId The target id * * @return A search by edge command to search the graph */ public static SearchByEdge createConnectionSearchByEdge( final Id sourceId, final String connectionType, final Id targetId ) { final String edgeType = getEdgeTypeFromConnectionType( connectionType ); return new SimpleSearchByEdge( sourceId, edgeType, targetId, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); }
/** * Get the edge by type */ public static SearchByEdge createGetByEdge( final Id sourceId, final String type, final Id targetId, final long maxVersion, final Edge last ) { return new SimpleSearchByEdge( sourceId, type, targetId, maxVersion, SearchByEdgeType.Order.DESCENDING, Optional.fromNullable( last ) ); }
@Override protected Iterator<MarkedEdge> getIteratorFullRange( final Collection<Shard> readShards ) { final SearchByEdge searchFullRange = new SimpleSearchByEdge( search.sourceNode(), search.getType(),search.targetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent()); return shardedEdgeSerialization.getEdgeVersions( edgeColumnFamilies, scope, searchFullRange, readShards ); } };
@Override protected Iterator<MarkedEdge> getIterator() { return storageEdgeSerialization.getEdgeVersions( scope, new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ) ); } } ).filter( markedEdge -> markedEdge.isDeleted() ).flatMap( marked ->
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>> 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())); } ); }
private void removeDuplicateEdgesAsync(GraphManager gm, Edge edge){ //now read all older versions of an edge, and remove them. Finally calling delete final SearchByEdge searchByEdge = new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); //load our versions, only retain the most recent one gm.loadEdgeVersions(searchByEdge).skip(1).flatMap(edgeToDelete -> { if (logger.isDebugEnabled()) { logger.debug("Duplicate edge. Marking edge {} for deletion", edgeToDelete); } return gm.markEdge(edgeToDelete ); }).lastOrDefault(null).doOnNext(lastEdge -> { //no op if we hit our default if (lastEdge == null) { return; } //don't queue delete b/c that de-indexes, we need to delete the edges only since we have a version still existing to index. gm.deleteEdge(lastEdge).toBlocking().lastOrDefault(null); // this should throw an exception }).toBlocking().lastOrDefault(null);//this should throw an exception }
new SimpleSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); return gm.loadEdgeVersions( searchByEdge )
new SimpleSearchByEdge( applicationScope.getApplication(), edgeTypeName, candidateId, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() );
/** * Commit log tests */ @Test public void commitLogTest() throws ConnectionException { final Id sourceId = IdGenerator.createId( "source" ); final Id targetId = IdGenerator.createId( "target" ); final String edgeType = "edge"; final MarkedEdge edge1 = createEdge( sourceId, edgeType, targetId, System.currentTimeMillis(), true ); //write it as non deleted to storage storageEdgeSerialization.writeEdge( scope, edge1, UUIDGenerator.newTimeUUID() ).execute(); final MarkedEdge edge2 = createEdge( sourceId, edgeType, targetId ); storageEdgeSerialization.writeEdge( scope, edge2, UUIDGenerator.newTimeUUID() ).execute(); //now repair delete the first edge Iterator<MarkedEdge> itr = storageEdgeSerialization.getEdgeVersions( scope, new SimpleSearchByEdge( sourceId, edgeType, targetId, System.currentTimeMillis(), SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent() ) ); assertEquals( edge2, itr.next() ); assertEquals( edge1, itr.next() ); assertFalse( itr.hasNext() ); MarkedEdge deleted = edgeDeleteRepair.repair( scope, edge1, UUIDGenerator.newTimeUUID() ).toBlocking().single(); assertEquals( edge1, deleted ); itr = storageEdgeSerialization.getEdgeVersions( scope, new SimpleSearchByEdge( sourceId, edgeType, targetId, System.currentTimeMillis(), SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent() ) ); assertEquals( edge2, itr.next() ); assertFalse( itr.hasNext() ); }
new SimpleSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getTargetNode(), Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.<Edge>absent() ); new SimpleSearchByEdge( edge1.getSourceNode(), edge1.getType(), edge1.getTargetNode(), 0, SearchByEdgeType.Order.ASCENDING, Optional.<Edge>absent() );
@Test public void testSingleConnection() { final ApplicationScope applicationScope = new ApplicationScopeImpl( new SimpleId( "application" ) ); final GraphManager gm = graphManagerFactory.createEdgeManager( applicationScope ); //now write a single connection final Id source = new SimpleId( "source" ); //add to a collection final String collectionName = "testCollection"; final Edge collectionEdge = CpNamingUtils.createCollectionEdge( applicationScope.getApplication(), collectionName, source ); final Edge writtenCollection = gm.writeEdge( collectionEdge ).toBlocking().last(); assertNotNull("Collection edge written", writtenCollection); final Id target = new SimpleId( "target" ); final String connectionType = "testConnection"; final Edge connectionEdge = CpNamingUtils.createConnectionEdge( source, connectionType, target ); final Edge writtenConnection = gm.writeEdge( connectionEdge ).toBlocking().last(); //now run the cleanup final int count = connectionService.deDupeConnections( Observable.just( applicationScope ) ).count().toBlocking().last(); assertEquals( "No edges deleted", 0, count ); //now ensure we can read the edge. final SearchByEdge simpleSearchByEdge = new SimpleSearchByEdge( source, connectionEdge.getType(), target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() ); final List<MarkedEdge> edges = gm.loadEdgeVersions( simpleSearchByEdge ).toList().toBlocking().last(); assertEquals( 1, edges.size() ); assertEquals( writtenConnection, edges.get( 0 ) ); }
new SimpleSearchByEdge( source, connection1.getType(), target, Long.MAX_VALUE, SearchByEdgeType.Order.DESCENDING, Optional.absent() );