Search in sources :

Example 11 with JobDetail

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>() {
    });
}
Also used : Response(javax.ws.rs.core.Response) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) Job(uk.gov.gchq.gaffer.jobtracker.Job)

Example 12 with 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());
        }
    }
}
Also used : Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ArrayList(java.util.ArrayList) List(java.util.List) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) Job(uk.gov.gchq.gaffer.jobtracker.Job) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) Test(org.junit.Test)

Example 13 with JobDetail

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);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) URI(java.net.URI)

Example 14 with 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());
}
Also used : Context(uk.gov.gchq.gaffer.store.Context) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) GlobalViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.GlobalViewElementDefinition) ViewElementDefinition(uk.gov.gchq.gaffer.data.elementdefinition.view.ViewElementDefinition) SchemaEntityDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEntityDefinition) OperationView(uk.gov.gchq.gaffer.operation.graph.OperationView) View(uk.gov.gchq.gaffer.data.elementdefinition.view.View) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) SchemaEdgeDefinition(uk.gov.gchq.gaffer.store.schema.SchemaEdgeDefinition) Job(uk.gov.gchq.gaffer.jobtracker.Job) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

Example 15 with JobDetail

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));
    }
}
Also used : InOrder(org.mockito.InOrder) GraphHook(uk.gov.gchq.gaffer.graph.hook.GraphHook) Schema(uk.gov.gchq.gaffer.store.schema.Schema) Store(uk.gov.gchq.gaffer.store.Store) TestStore(uk.gov.gchq.gaffer.integration.store.TestStore) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ArrayList(java.util.ArrayList) List(java.util.List) StoreProperties(uk.gov.gchq.gaffer.store.StoreProperties) Test(org.junit.jupiter.api.Test)

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