use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class JobServiceV2 method executeJob.
@Override
public Response executeJob(final Job job) throws OperationException {
final Context context = userFactory.createContext();
OperationChain chain = OperationChain.wrap(job.getOperation());
preOperationHook(chain, context);
try {
final JobDetail jobDetail = graphFactory.getGraph().executeJob(job, context);
LOGGER.info("Job started = {}", jobDetail);
final URI location = uriInfo.getAbsolutePathBuilder().path(jobDetail.getJobId()).build();
return Response.created(location).entity(jobDetail).header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE).header(JOB_ID_HEADER, context.getJobId()).build();
} finally {
postOperationHook(chain, context);
}
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class JobServiceV2 method executeJob.
@Override
public Response executeJob(final Operation operation) throws OperationException {
final Context context = userFactory.createContext();
final OperationChain opChain = OperationChain.wrap(operation);
preOperationHook(opChain, context);
try {
final JobDetail jobDetail = graphFactory.getGraph().executeJob(opChain, context);
LOGGER.info("Job started = {}", jobDetail);
final URI location = uriInfo.getAbsolutePathBuilder().path(jobDetail.getJobId()).build();
return Response.created(location).entity(jobDetail).header(GAFFER_MEDIA_TYPE_HEADER, GAFFER_MEDIA_TYPE).header(JOB_ID_HEADER, context.getJobId()).build();
} finally {
postOperationHook(opChain, context);
}
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class ProxyStoreBasicIT method shouldAddElementsViaAJob.
@Test
public void shouldAddElementsViaAJob() throws Exception {
// Add elements
final AddElements add = new AddElements.Builder().input(DEFAULT_ELEMENTS).build();
JobDetail jobDetail = graph.executeJob(new OperationChain<>(add), USER);
// Wait until the job status is not RUNNING
while (JobStatus.RUNNING.equals(jobDetail.getStatus())) {
jobDetail = graph.execute(new GetJobDetails.Builder().jobId(jobDetail.getJobId()).build(), USER);
Thread.sleep(100);
}
// Get elements
final GetElements getElements = new GetElements.Builder().view(new View.Builder().entity(TestGroups.ENTITY).edge(TestGroups.EDGE).build()).input(new EntitySeed("1")).build();
CloseableIterable<? extends Element> results = graph.execute(getElements, USER);
// Then
assertThat(results).hasSize(2);
assertThat((CloseableIterable<Element>) results).contains(DEFAULT_ELEMENTS[0], DEFAULT_ELEMENTS[2]);
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class JobControllerIT method shouldRunJob.
@Test
public void shouldRunJob() {
// Given
ArrayList<Element> elements = Lists.newArrayList(new Entity.Builder().group("BasicEntity").vertex("vertex1").property("count", 5).build(), new Entity.Builder().group("BasicEntity").vertex("vertex2").property("count", 5).build(), new Edge.Builder().group("BasicEdge").source("vertex1").dest("vertex2").directed(true).build());
AddElements addElements = new AddElements.Builder().input(elements).build();
post("/graph/operations/execute", addElements, Object.class);
// When
Operation operation = new GetAllElements();
ResponseEntity<JobDetail> jobResponse = post("/graph/jobs", operation, JobDetail.class);
String jobId = jobResponse.getBody().getJobId();
boolean jobCompleted = false;
ResponseEntity<JobDetail> jobStatusResponse = null;
while (!jobCompleted) {
jobStatusResponse = get("/graph/jobs/" + jobId, JobDetail.class);
jobCompleted = !jobStatusResponse.getBody().getStatus().equals(JobStatus.RUNNING);
}
// Then
assertNotNull(jobStatusResponse);
assertEquals(JobStatus.FINISHED, jobStatusResponse.getBody().getStatus());
ResponseEntity<List> resultResponse = get("/graph/jobs/" + jobId + "/results", List.class);
List<? extends Element> results = Lists.newArrayList(deserialiseElementIterable(resultResponse.getBody()));
Assertions.<Element>assertThat(results).hasSize(3).as("Results did not contain expected elements").containsAll(elements);
}
use of uk.gov.gchq.gaffer.jobtracker.JobDetail in project Gaffer by gchq.
the class JobServiceV2IT 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 Response jobSchedulingResponse = client.scheduleJob(job);
JobDetail jobSchedulingDetail = jobSchedulingResponse.readEntity(new GenericType<JobDetail>() {
});
// Then
assertEquals(201, jobSchedulingResponse.getStatus());
String parentJobId = jobSchedulingDetail.getJobId();
// Wait for first scheduled to run
Thread.sleep(1500);
final Response getAllJobDetailsResponse = client.executeOperation(new GetAllJobDetails());
List<JobDetail> jobDetails = getAllJobDetailsResponse.readEntity(new GenericType<List<JobDetail>>() {
});
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());
}
}
client.executeOperation(new CancelScheduledJob.Builder().jobId(parentJobId).build());
final Response getAllJobDetailsResponseAfterCancelled = client.executeOperation(new GetAllJobDetails());
List<JobDetail> jobDetailsAfterCancelled = getAllJobDetailsResponseAfterCancelled.readEntity(new GenericType<List<JobDetail>>() {
});
for (JobDetail jobDetail : jobDetailsAfterCancelled) {
if (parentJobId.equals(jobDetail.getJobId())) {
assertEquals(JobStatus.CANCELLED, jobDetail.getStatus());
}
}
}
Aggregations