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;
}
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;
}
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();
}
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);
}
}
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;
}
Aggregations