use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project gaffer-doc by gchq.
the class Jobs method run.
public CloseableIterable<? extends Element> run() throws OperationException, IOException {
// / [graph] create a graph using our schema and store properties
// ---------------------------------------------------------
final Graph graph = new Graph.Builder().config(getDefaultGraphConfig()).addSchemas(StreamUtil.openStreams(getClass(), schemaPath)).storeProperties(getDefaultStoreProperties()).build();
// ---------------------------------------------------------
// [user] Create a user
// ---------------------------------------------------------
final User user = new User("user01");
// ---------------------------------------------------------
// [add] Create a data generator and add the edges to the graph using an operation chain consisting of:
// generateElements - generating edges from the data (note these are directed edges)
// addElements - add the edges to the graph
// ---------------------------------------------------------
final OperationChain<Void> addOpChain = new OperationChain.Builder().first(new GenerateElements.Builder<String>().generator(new RoadAndRoadUseWithTimesAndCardinalitiesElementGenerator()).input(IOUtils.readLines(StreamUtil.openStream(getClass(), "RoadAndRoadUseWithTimesAndCardinalities/data.txt"))).build()).then(new AddElements()).build();
graph.execute(addOpChain, user);
// ---------------------------------------------------------
// [job] create an operation chain to be executed as a job
// ---------------------------------------------------------
final OperationChain<CloseableIterable<? extends Element>> job = new OperationChain.Builder().first(new GetElements.Builder().input(new EntitySeed("10")).view(new View.Builder().edge("RoadUse").build()).build()).build();
// ---------------------------------------------------------
// [execute job] execute the job
// ---------------------------------------------------------
final JobDetail initialJobDetail = graph.executeJob(job, user);
final String jobId = initialJobDetail.getJobId();
// ---------------------------------------------------------
print("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);
// ---------------------------------------------------------
print("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) {
print("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) {
print("JOB_RESULTS", result.toString());
}
return (CloseableIterable) jobResults;
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project gaffer-doc by gchq.
the class GetGafferResultCacheExportExample method exportAndGetJobDetails.
public JobDetail exportAndGetJobDetails() {
// ---------------------------------------------------------
final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllElements()).then(new ExportToGafferResultCache<>()).then(new DiscardOutput()).then(new GetJobDetails()).build();
// ---------------------------------------------- -----------
jobDetail = runExample(opChain, null);
return jobDetail;
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project gaffer-doc by gchq.
the class GetJobDetailsExample method getJobDetailsInOperationChain.
public JobDetail getJobDetailsInOperationChain() {
// ---------------------------------------------------------
final OperationChain<JobDetail> opChain = new OperationChain.Builder().first(new GetAllElements()).then(new DiscardOutput()).then(new GetJobDetails()).build();
// ---------------------------------------------------------
final JobDetail jobDetail = runExample(opChain, null);
jobId = jobDetail.getJobId();
return jobDetail;
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class GetJobDetailsHandlerTest method shouldGetJobDetailsByDelegatingToJobTrackerWithOperationJobId.
@Test
public void shouldGetJobDetailsByDelegatingToJobTrackerWithOperationJobId() throws OperationException {
// Given
final String jobId = "jobId";
final GetJobDetailsHandler handler = new GetJobDetailsHandler();
final GetJobDetails operation = new GetJobDetails.Builder().jobId(jobId).build();
final Store store = mock(Store.class);
final JobTracker jobTracker = mock(JobTracker.class);
final User user = mock(User.class);
final JobDetail jobsDetail = mock(JobDetail.class);
final Context context = new Context(user);
given(store.getJobTracker()).willReturn(jobTracker);
given(jobTracker.getJob(jobId, user)).willReturn(jobsDetail);
// When
final JobDetail result = handler.doOperation(operation, context, store);
// Then
assertSame(jobsDetail, result);
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class Graph method executeJob.
/**
* Performs the given Job on the store.
* This should be used for Scheduled Jobs,
* although if no repeat is set it
* will act as a normal Job.
*
* @param job the {@link Job} to execute, which contains the {@link OperationChain} and the {@link uk.gov.gchq.gaffer.jobtracker.Repeat}
* @param context the user context for the execution of the operation
* @return the job detail
* @throws OperationException thrown if the job fails to run.
*/
public JobDetail executeJob(final Job job, final Context context) throws OperationException {
if (null == context) {
throw new IllegalArgumentException("A context is required");
}
if (null == job) {
throw new IllegalArgumentException("A job is required");
}
OperationChain wrappedOriginal = OperationChain.wrap(job.getOperation());
context.setOriginalOpChain(wrappedOriginal);
final Context clonedContext = context.shallowClone();
final OperationChain clonedOpChain = wrappedOriginal.shallowClone();
JobDetail result = null;
try {
updateOperationChainView(clonedOpChain);
for (final GraphHook graphHook : config.getHooks()) {
graphHook.preExecute(clonedOpChain, clonedContext);
}
updateOperationChainView(clonedOpChain);
job.setOperation(clonedOpChain);
result = store.executeJob(job, context);
for (final GraphHook graphHook : config.getHooks()) {
graphHook.postExecute(result, clonedOpChain, clonedContext);
}
} catch (final Exception e) {
for (final GraphHook graphHook : config.getHooks()) {
try {
result = graphHook.onFailure(result, clonedOpChain, clonedContext, e);
} catch (final Exception graphHookE) {
LOGGER.warn("Error in graphHook " + graphHook.getClass().getSimpleName() + ": " + graphHookE.getMessage(), graphHookE);
}
}
CloseableUtil.close(clonedOpChain);
CloseableUtil.close(result);
throw e;
}
return result;
}
Aggregations