Search in sources :

Example 41 with JobDetail

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

the class JobServiceV2IT method shouldNotKeepScheduledJobsRunningAfterRestartWhenUsingInMemoryCache.

@Test
public void shouldNotKeepScheduledJobsRunningAfterRestartWhenUsingInMemoryCache() throws IOException {
    // Given - schedule Job
    final Repeat repeat = new Repeat(1, 2, TimeUnit.SECONDS);
    Job job = new Job(repeat, new OperationChain.Builder().first(new GetAllElements()).build());
    final Response scheduleResponse = client.scheduleJob(job);
    String parentJobId = scheduleResponse.readEntity(new GenericType<JobDetail>() {
    }).getJobId();
    // When - get all JobDetails
    final Response allJobDetailsResponse = client.executeOperation(new GetAllJobDetails());
    List<JobDetail> allJobDetails = allJobDetailsResponse.readEntity(new GenericType<List<JobDetail>>() {
    });
    // then - assert parent is of Scheduled parent
    assertEquals(JobStatus.SCHEDULED_PARENT, allJobDetails.stream().filter(jobDetail -> jobDetail.getJobId().equals(parentJobId)).findFirst().get().getStatus());
    // Restart server to check Job still scheduled
    client.stopServer();
    client.reinitialiseGraph();
    // When - get all JobDetails
    final Response allJobDetailsResponse2 = client.executeOperation(new GetAllJobDetails());
    List<JobDetail> allJobDetails2 = allJobDetailsResponse2.readEntity(new GenericType<List<JobDetail>>() {
    });
    // Then - assert parent job id is not present
    assertTrue(allJobDetails2.stream().noneMatch(jobDetail -> jobDetail.getJobId().equals(parentJobId)));
}
Also used : Job(uk.gov.gchq.gaffer.jobtracker.Job) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) IOException(java.io.IOException) JobStatus(uk.gov.gchq.gaffer.jobtracker.JobStatus) Test(org.junit.jupiter.api.Test) GenericType(javax.ws.rs.core.GenericType) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) Response(javax.ws.rs.core.Response) ServiceConstants(uk.gov.gchq.gaffer.rest.ServiceConstants) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) GenericType(javax.ws.rs.core.GenericType) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) Response(javax.ws.rs.core.Response) GetAllJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetAllJobDetails) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) List(java.util.List) Job(uk.gov.gchq.gaffer.jobtracker.Job) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) Test(org.junit.jupiter.api.Test)

Example 42 with JobDetail

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

the class JobController method startJob.

@Override
public ResponseEntity<JobDetail> startJob(@RequestBody final Operation operation) throws OperationException {
    JobDetail jobDetail = graphFactory.getGraph().executeJob(OperationChain.wrap(operation), 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)

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