Search in sources :

Example 1 with GetAllEdges

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.

the class JcsJobTrackerIT method shouldAddJobIdToJobTrackerWhenExecute.

@Test
public void shouldAddJobIdToJobTrackerWhenExecute() throws OperationException, IOException, InterruptedException {
    // Given
    final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new GetJobDetails()).build();
    final User user = new User("user01");
    // When
    final JobDetail jobDetails = graph.execute(opChain, user);
    final String jobId = jobDetails.getJobId();
    final JobDetail expectedJobDetail = new JobDetail(jobId, user.getUserId(), opChain, JobStatus.RUNNING, null);
    expectedJobDetail.setStartTime(jobDetails.getStartTime());
    expectedJobDetail.setEndTime(jobDetails.getEndTime());
    // Then
    assertEquals(expectedJobDetail, jobDetails);
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 2 with GetAllEdges

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.

the class JcsJobTrackerIT method shouldAddJobIdToJobTrackerWhenExecuteJob.

@Test
public void shouldAddJobIdToJobTrackerWhenExecuteJob() throws OperationException, IOException, InterruptedException {
    // Given
    final OperationChain<CloseableIterable<Edge>> opChain = new OperationChain<>(new GetAllEdges());
    final User user = new User("user01");
    // When
    JobDetail jobDetails = graph.executeJob(opChain, user);
    final String jobId = jobDetails.getJobId();
    final JobDetail expectedJobDetail = new JobDetail(jobId, user.getUserId(), opChain, JobStatus.FINISHED, null);
    expectedJobDetail.setStartTime(jobDetails.getStartTime());
    int count = 0;
    while (JobStatus.RUNNING == jobDetails.getStatus() && ++count < 20) {
        Thread.sleep(100);
        jobDetails = graph.execute(new GetJobDetails.Builder().jobId(jobId).build(), user);
    }
    expectedJobDetail.setEndTime(jobDetails.getEndTime());
    // Then
    assertEquals(expectedJobDetail, jobDetails);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Test(org.junit.Test)

Example 3 with GetAllEdges

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.

the class ExamplesService method getAllEdges.

@Override
public GetAllEdges getAllEdges() {
    final GetAllEdges op = new GetAllEdges();
    populateOperation(op);
    return op;
}
Also used : GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)

Example 4 with GetAllEdges

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.

the class LoadAndQuery12 method run.

public Iterable<Entity> run() throws OperationException {
    // [user] Create a user
    // ---------------------------------------------------------
    final User user = new User("user01");
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] add the edges to the graph
    // ---------------------------------------------------------
    final Set<String> dummyData = Collections.singleton("");
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator12()).objects(dummyData).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    log("Added the edge A-B 1000 times each time with a ReservoirItemsUnion<String> containing a random string." + " Also added 500 edges X-Y0, X-Y1, ..., X-Y499 each and for each an Entity on X with a" + " ReservoirItemsUnion<String> containing the destination node.");
    // [get red edge] Get the red edge
    // ---------------------------------------------------------
    final GetAllEdges getAllEdges = new GetAllEdges.Builder().view(new View.Builder().edge("red").build()).build();
    final Iterable<Edge> allEdges = graph.execute(getAllEdges, user);
    // ---------------------------------------------------------
    log("\nThe red edge A-B:");
    for (final Edge edge : allEdges) {
        log("GET_A-B_EDGE_RESULT", edge.toString());
    }
    // [get strings sample from the red edge] Get the edge A-B and print out the sample of strings
    // ---------------------------------------------------------
    final GetEdges<EdgeSeed> query = new GetEdges.Builder<EdgeSeed>().addSeed(new EdgeSeed("A", "B", false)).build();
    final Iterable<Edge> edges = graph.execute(query, user);
    final Edge edge = edges.iterator().next();
    final ReservoirItemsSketch<String> stringsSketch = ((ReservoirItemsUnion<String>) edge.getProperty("stringsSample")).getResult();
    final String[] samples = stringsSketch.getSamples();
    final StringBuilder sb = new StringBuilder("10 samples: ");
    for (int i = 0; i < 10 && i < samples.length; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        sb.append(samples[i]);
    }
    // ---------------------------------------------------------
    log("\nEdge A-B with a sample of the strings");
    log("GET_SAMPLE_FOR_RED_EDGE", sb.toString());
    // [get sample from the blue entity] Get the entity Y and print a sample of the neighbours
    // ---------------------------------------------------------
    final GetEntities<EntitySeed> query2 = new GetEntities.Builder<EntitySeed>().addSeed(new EntitySeed("X")).build();
    final Iterable<Entity> entities = graph.execute(query2, user);
    final Entity entity = entities.iterator().next();
    final ReservoirItemsSketch<String> neighboursSketch = ((ReservoirItemsUnion<String>) entity.getProperty("neighboursSample")).getResult();
    final String[] neighboursSample = neighboursSketch.getSamples();
    sb.setLength(0);
    sb.append("10 samples: ");
    for (int i = 0; i < 10 && i < neighboursSample.length; i++) {
        if (i > 0) {
            sb.append(", ");
        }
        sb.append(neighboursSample[i]);
    }
    // ---------------------------------------------------------
    log("\nEntity for vertex X with a sample of its neighbouring vertices");
    log("GET_SAMPLES_FOR_X_RESULT", sb.toString());
    return null;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) User(uk.gov.gchq.gaffer.user.User) DataGenerator12(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator12) Graph(uk.gov.gchq.gaffer.graph.Graph) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EdgeSeed(uk.gov.gchq.gaffer.operation.data.EdgeSeed) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) Edge(uk.gov.gchq.gaffer.data.element.Edge) ReservoirItemsUnion(com.yahoo.sketches.sampling.ReservoirItemsUnion)

Example 5 with GetAllEdges

use of uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges in project Gaffer by gchq.

the class LoadAndQuery8 method run.

public Iterable<Edge> run() throws OperationException {
    // [user] Create a user who can see public and private data
    // ---------------------------------------------------------
    final User user = new User.Builder().userId("user").dataAuths("public", "private").build();
    // ---------------------------------------------------------
    // [graph] create a graph using our schema and store properties
    // ---------------------------------------------------------
    final Graph graph = new Graph.Builder().addSchemas(getSchemas()).storeProperties(getStoreProperties()).build();
    // ---------------------------------------------------------
    // [add] add the edges to the graph
    // ---------------------------------------------------------
    final OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator8()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [get] Get all edges
    // ---------------------------------------------------------
    final GetAllEdges allEdgesOperation = new GetAllEdges();
    final Iterable<Edge> edges = graph.execute(allEdgesOperation, user);
    // ---------------------------------------------------------
    log("\nAll edges in daily time buckets:");
    for (final Edge edge : edges) {
        log("GET_ALL_EDGES_RESULT", edge.toString());
    }
    // [get all edges summarised] Get all edges summarised (merge all time windows together)
    // This is achieved by overriding the 'groupBy' start and end time properties.
    // ---------------------------------------------------------
    final GetAllEdges edgesSummarisedOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().groupBy().build()).build()).build();
    final Iterable<Edge> edgesSummarised = graph.execute(edgesSummarisedOperation, user);
    // ---------------------------------------------------------
    log("\nAll edges summarised:");
    for (final Edge edge : edgesSummarised) {
        log("GET_ALL_EDGES_SUMMARISED_RESULT", edge.toString());
    }
    // [get all edges summarised in time window] Get all edges summarised over a provided 2 day time period
    // This is achieved by overriding the 'groupBy' start and end time properties
    // and providing a filter.
    // ---------------------------------------------------------
    final GetAllEdges edgesSummarisedInTimeWindowOperation = new GetAllEdges.Builder().view(new View.Builder().edge("data", new ViewElementDefinition.Builder().preAggregationFilter(new ElementFilter.Builder().select("startDate").execute(new IsMoreThan(JAN_01_16, true)).select("endDate").execute(new IsLessThan(JAN_02_16, true)).build()).groupBy().build()).build()).build();
    final Iterable<Edge> edgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, user);
    // ---------------------------------------------------------
    log("\nEdges in 2 day time window:");
    for (final Edge edge : edgesSummarisedInTimeWindow) {
        log("GET_ALL_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
    }
    // Repeat with a public user and you will see the private edges are not part of the summarised edges
    final User publicUser = new User.Builder().userId("public user").dataAuths("public").build();
    final Iterable<Edge> publicEdgesSummarisedInTimeWindow = graph.execute(edgesSummarisedInTimeWindowOperation, publicUser);
    log("\nPublic edges in 2 day time window:");
    for (final Edge edge : publicEdgesSummarisedInTimeWindow) {
        log("GET_PUBLIC_EDGES_SUMMARISED_IN_TIME_WINDOW_RESULT", edge.toString());
    }
    return publicEdgesSummarisedInTimeWindow;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) User(uk.gov.gchq.gaffer.user.User) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) DataGenerator8(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator8) Graph(uk.gov.gchq.gaffer.graph.Graph) IsLessThan(uk.gov.gchq.gaffer.function.filter.IsLessThan) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) IsMoreThan(uk.gov.gchq.gaffer.function.filter.IsMoreThan) Edge(uk.gov.gchq.gaffer.data.element.Edge)

Aggregations

GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)13 User (uk.gov.gchq.gaffer.user.User)9 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)8 Edge (uk.gov.gchq.gaffer.data.element.Edge)6 Graph (uk.gov.gchq.gaffer.graph.Graph)6 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)6 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)5 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)5 Test (org.junit.Test)3 EdgeSeed (uk.gov.gchq.gaffer.operation.data.EdgeSeed)3 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)3 Entity (uk.gov.gchq.gaffer.data.element.Entity)2 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)2 HyperLogLogPlus (com.clearspring.analytics.stream.cardinality.HyperLogLogPlus)1 LongsSketch (com.yahoo.sketches.frequencies.LongsSketch)1 DoublesSketch (com.yahoo.sketches.quantiles.DoublesSketch)1 DoublesUnion (com.yahoo.sketches.quantiles.DoublesUnion)1 ReservoirItemsUnion (com.yahoo.sketches.sampling.ReservoirItemsUnion)1 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 ElementFilter (uk.gov.gchq.gaffer.data.element.function.ElementFilter)1