use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class PersistentCachingJobServiceV2IT method scheduleJob.
private JobDetail scheduleJob(final Repeat repeat) throws IOException {
final Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
final Response scheduleResponse = client.scheduleJob(job);
return scheduleResponse.readEntity(new GenericType<JobDetail>() {
});
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class JobControllerIT method shouldCorrectlyDoAndThenCancelScheduledJob.
@Test
public void shouldCorrectlyDoAndThenCancelScheduledJob() throws IOException, InterruptedException {
// When
final Repeat repeat = new Repeat(1, 2, TimeUnit.SECONDS);
Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
final ResponseEntity<JobDetail> jobSchedulingResponse = post("/graph/jobs/schedule", job, JobDetail.class);
JobDetail jobDetailParent = jobSchedulingResponse.getBody();
// Then
assertEquals(201, jobSchedulingResponse.getStatusCode().value());
String parentJobId = jobDetailParent.getJobId();
// Wait for first scheduled to run
Thread.sleep(1500);
final ResponseEntity<List> getAllJobDetailsResponse = post("/graph/operations/execute", new GetAllJobDetails(), List.class);
Iterable<JobDetail> jobDetails = deserialiseJobDetailIterable(getAllJobDetailsResponse.getBody());
for (JobDetail jobDetail : jobDetails) {
if (null != jobDetail.getParentJobId() && jobDetail.getParentJobId().equals(parentJobId)) {
assertEquals(JobStatus.FINISHED, jobDetail.getStatus());
}
if (jobDetail.getJobId().equals(parentJobId)) {
assertEquals(JobStatus.SCHEDULED_PARENT, jobDetail.getStatus());
}
}
post("/graph/operations/execute", new CancelScheduledJob.Builder().jobId(parentJobId).build(), Set.class);
final Iterable<JobDetail> cancelledJobDetails = deserialiseJobDetailIterable(post("/graph/operations/execute", new GetAllJobDetails(), List.class).getBody());
for (JobDetail jobDetail : cancelledJobDetails) {
if (parentJobId.equals(jobDetail.getJobId())) {
assertEquals(JobStatus.CANCELLED, jobDetail.getStatus());
}
}
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class JobController method scheduleJob.
@Override
public ResponseEntity<JobDetail> scheduleJob(@RequestBody final Job job) throws OperationException {
JobDetail jobDetail = graphFactory.getGraph().executeJob(job, userFactory.createContext());
URI jobUri = ServletUriComponentsBuilder.fromCurrentRequest().pathSegment(jobDetail.getJobId()).build().toUri();
return ResponseEntity.created(jobUri).header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE).header(JOB_ID_HEADER, jobDetail.getJobId()).body(jobDetail);
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class GraphTest method shouldAddSchemaGroupsIfNotIncludedInJob.
@Test
public void shouldAddSchemaGroupsIfNotIncludedInJob() throws OperationException {
// given
final Job job = new Job(null, new OperationChain.Builder().first(new GetAllElements()).build());
final Store store = mock(Store.class);
given(store.getSchema()).willReturn(new Schema.Builder().entity(TestGroups.ENTITY, new SchemaEntityDefinition()).edge(TestGroups.EDGE, new SchemaEdgeDefinition()).edge(TestGroups.EDGE_2, new SchemaEdgeDefinition()).build());
given(store.getProperties()).willReturn(new StoreProperties());
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).build();
final ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class);
final ArgumentCaptor<Context> contextCaptor = ArgumentCaptor.forClass(Context.class);
given(store.executeJob(jobCaptor.capture(), contextCaptor.capture())).willReturn(new JobDetail());
// when
graph.executeJob(job, context);
// then
final GetAllElements operation = (GetAllElements) ((OperationChain) jobCaptor.getValue().getOperation()).getOperations().get(0);
assertEquals(new View.Builder().entity(TestGroups.ENTITY, new ViewElementDefinition()).edge(TestGroups.EDGE, new ViewElementDefinition()).edge(TestGroups.EDGE_2, new ViewElementDefinition()).build(), operation.getView());
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class GraphTest method shouldCallAllGraphHooksOnGraphHookPostExecuteFailureWhenRunningJob.
@Test
public void shouldCallAllGraphHooksOnGraphHookPostExecuteFailureWhenRunningJob() throws OperationException {
// Given
final GraphHook hook1 = mock(GraphHook.class);
final GraphHook hook2 = mock(GraphHook.class);
final Store store = mock(Store.class);
final JobDetail result1 = mock(JobDetail.class);
final JobDetail result2 = mock(JobDetail.class);
final JobDetail result3 = mock(JobDetail.class);
final Schema schema = new Schema();
given(store.getSchema()).willReturn(schema);
given(store.getProperties()).willReturn(new StoreProperties());
given(hook1.postExecute(result1, clonedOpChain, clonedContext)).willReturn(result2);
final RuntimeException e = new RuntimeException("Hook2 failed in postExecute");
given(hook2.postExecute(result2, clonedOpChain, clonedContext)).willThrow(e);
given(hook1.onFailure(result2, clonedOpChain, clonedContext, e)).willThrow(new RuntimeException("Hook1 failed in onFailure"));
given(hook2.onFailure(result2, clonedOpChain, clonedContext, e)).willReturn(result3);
final Graph graph = new Graph.Builder().config(new GraphConfig.Builder().graphId(GRAPH_ID).addHook(hook1).addHook(hook2).build()).storeProperties(StreamUtil.storeProps(getClass())).store(store).addSchema(schema).build();
final ArgumentCaptor<OperationChain> captor = ArgumentCaptor.forClass(OperationChain.class);
given(store.executeJob(captor.capture(), eq(clonedContext))).willReturn(result1);
// When / Then
try {
graph.executeJob(opChain, context);
fail("Exception expected");
} catch (final RuntimeException runtimeE) {
final InOrder inOrder = inOrder(context, hook1, hook2);
inOrder.verify(context).setOriginalOpChain(opChain);
inOrder.verify(hook1).postExecute(result1, captor.getValue(), clonedContext);
inOrder.verify(hook2).postExecute(result2, captor.getValue(), clonedContext);
inOrder.verify(hook1).onFailure(result2, captor.getValue(), clonedContext, e);
inOrder.verify(hook2).onFailure(result2, captor.getValue(), clonedContext, e);
final List<Operation> ops = captor.getValue().getOperations();
assertThat(ops).hasSize(1);
assertSame(operation, ops.get(0));
}
}
Aggregations