Search in sources :

Example 36 with JobDetail

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

Example 37 with JobDetail

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

Example 38 with JobDetail

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]);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) EntitySeed(uk.gov.gchq.gaffer.operation.data.EntitySeed) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) Test(org.junit.jupiter.api.Test)

Example 39 with JobDetail

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);
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) Entity(uk.gov.gchq.gaffer.data.element.Entity) ResponseEntity(org.springframework.http.ResponseEntity) Element(uk.gov.gchq.gaffer.data.element.Element) Operation(uk.gov.gchq.gaffer.operation.Operation) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 40 with JobDetail

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());
        }
    }
}
Also used : Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) Response(javax.ws.rs.core.Response) 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) 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.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