Search in sources :

Example 1 with DataGenerator15

use of uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator15 in project Gaffer by gchq.

the class LoadAndQuery15 method run.

public CloseableIterable<?> 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 OperationChain addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new DataGenerator15()).objects(DataUtils.loadData(getData())).build()).then(new AddElements()).build();
    graph.execute(addOpChain, user);
    // ---------------------------------------------------------
    // [job] create an operation chain to be executed as a job
    // ---------------------------------------------------------
    final OperationChain<CloseableIterable<Edge>> job = new OperationChain.Builder().first(new GetEdges.Builder<EntitySeed>().addSeed(new EntitySeed("1")).build()).build();
    // ---------------------------------------------------------
    // [execute job] execute the job
    // ---------------------------------------------------------
    final JobDetail initialJobDetail = graph.executeJob(job, user);
    final String jobId = initialJobDetail.getJobId();
    // ---------------------------------------------------------
    log("JOB_DETAIL_START", initialJobDetail.toString());
    waitUntilJobHashFinished(user, graph, initialJobDetail);
    // [job details] Get the job details
    // ---------------------------------------------------------
    final JobDetail jobDetail = graph.execute(new GetJobDetails.Builder().jobId(jobId).build(), user);
    // ---------------------------------------------------------
    log("JOB_DETAIL_FINISH", jobDetail.toString());
    // [all job details] Get all job details
    // ---------------------------------------------------------
    final CloseableIterable<JobDetail> jobDetails = graph.execute(new GetAllJobDetails(), user);
    // ---------------------------------------------------------
    for (final JobDetail detail : jobDetails) {
        log("ALL_JOB_DETAILS", detail.toString());
    }
    // [get job results] Get the job results
    // ---------------------------------------------------------
    final CloseableIterable<?> jobResults = graph.execute(new GetJobResults.Builder().jobId(jobId).build(), user);
    // ---------------------------------------------------------
    for (final Object result : jobResults) {
        log("JOB_RESULTS", result.toString());
    }
    return jobResults;
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) User(uk.gov.gchq.gaffer.user.User) DataGenerator15(uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator15) GetJobResults(uk.gov.gchq.gaffer.operation.impl.job.GetJobResults) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) Graph(uk.gov.gchq.gaffer.graph.Graph) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed)

Aggregations

CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)1 DataGenerator15 (uk.gov.gchq.gaffer.example.gettingstarted.generator.DataGenerator15)1 Graph (uk.gov.gchq.gaffer.graph.Graph)1 JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)1 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)1 EntitySeed (uk.gov.gchq.gaffer.operation.data.EntitySeed)1 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)1 GetAllJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails)1 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)1 GetJobResults (uk.gov.gchq.gaffer.operation.impl.job.GetJobResults)1 User (uk.gov.gchq.gaffer.user.User)1