Search in sources :

Example 21 with JobDetail

use of uk.gov.gchq.gaffer.jobtracker.JobDetail 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)

Example 22 with JobDetail

use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.

the class GetJobDetailsExample method getJobDetailsInOperationChain.

public JobDetail getJobDetailsInOperationChain() {
    // ---------------------------------------------------------
    final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new GetJobDetails()).build();
    // ---------------------------------------------------------
    final JobDetail jobDetail = runExample(opChain);
    jobId = jobDetail.getJobId();
    return jobDetail;
}
Also used : GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllEdges(uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain)

Example 23 with JobDetail

use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.

the class GetJobResultsExample method runExamples.

@Override
public void runExamples() {
    try {
        final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllEdges()).then(new ExportToGafferResultCache()).then(new GetJobDetails()).build();
        final JobDetail jobDetails = getGraph().execute(opChain, new User("user01"));
        jobId = jobDetails.getJobId();
    } catch (final OperationException e) {
        throw new RuntimeException(e);
    }
    getJobResults();
}
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) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 24 with JobDetail

use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.

the class JobService method executeJob.

@Override
public JobDetail executeJob(final OperationChain opChain) {
    final User user = userFactory.createUser();
    preOperationHook(opChain, user);
    try {
        final JobDetail jobDetail = graphFactory.getGraph().executeJob(opChain, user);
        LOGGER.info("Job started = " + jobDetail);
        return jobDetail;
    } catch (OperationException e) {
        throw new RuntimeException("Error executing opChain", e);
    } finally {
        postOperationHook(opChain, user);
    }
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) User(uk.gov.gchq.gaffer.user.User) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Example 25 with JobDetail

use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.

the class Store method executeJob.

/**
     * Executes a given operation chain job and returns the job detail.
     *
     * @param operationChain the operation chain to execute.
     * @param user           the user executing the job
     * @return the job detail
     * @throws OperationException thrown if jobs are not configured.
     */
public JobDetail executeJob(final OperationChain<?> operationChain, final User user) throws OperationException {
    if (null == jobTracker) {
        throw new OperationException("Running jobs has not configured.");
    }
    final Context context = createContext(user);
    if (isSupported(ExportToGafferResultCache.class)) {
        boolean hasExport = false;
        for (final Operation operation : operationChain.getOperations()) {
            if (operation instanceof ExportToGafferResultCache) {
                hasExport = true;
                break;
            }
        }
        if (!hasExport) {
            operationChain.getOperations().add(new ExportToGafferResultCache());
        }
    }
    final JobDetail initialJobDetail = addOrUpdateJobDetail(operationChain, context, null, JobStatus.RUNNING);
    new Thread(() -> {
        try {
            _execute(operationChain, context);
            addOrUpdateJobDetail(operationChain, context, null, JobStatus.FINISHED);
        } catch (final Throwable t) {
            LOGGER.warn("Operation chain job failed to execute", t);
            addOrUpdateJobDetail(operationChain, context, t.getMessage(), JobStatus.FAILED);
        }
    }).start();
    return initialJobDetail;
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ExportToGafferResultCache(uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache) Operation(uk.gov.gchq.gaffer.operation.Operation) OperationException(uk.gov.gchq.gaffer.operation.OperationException)

Aggregations

JobDetail (uk.gov.gchq.gaffer.jobtracker.JobDetail)42 OperationChain (uk.gov.gchq.gaffer.operation.OperationChain)22 Test (org.junit.jupiter.api.Test)14 GetJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails)14 GetAllElements (uk.gov.gchq.gaffer.operation.impl.get.GetAllElements)11 User (uk.gov.gchq.gaffer.user.User)11 ExportToGafferResultCache (uk.gov.gchq.gaffer.operation.impl.export.resultcache.ExportToGafferResultCache)10 Context (uk.gov.gchq.gaffer.store.Context)8 DiscardOutput (uk.gov.gchq.gaffer.operation.impl.DiscardOutput)7 Job (uk.gov.gchq.gaffer.jobtracker.Job)6 OperationException (uk.gov.gchq.gaffer.operation.OperationException)6 GetAllEdges (uk.gov.gchq.gaffer.operation.impl.get.GetAllEdges)6 GetAllJobDetails (uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails)6 Schema (uk.gov.gchq.gaffer.store.schema.Schema)6 List (java.util.List)5 CloseableIterable (uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable)5 Repeat (uk.gov.gchq.gaffer.jobtracker.Repeat)5 Operation (uk.gov.gchq.gaffer.operation.Operation)5 ValidateOperationChain (uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain)5 AddElements (uk.gov.gchq.gaffer.operation.impl.add.AddElements)5