Search in sources :

Example 31 with JobDetail

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

the class StoreTest method shouldRescheduleJobsCorrectlyWhenInitialisationCountIs.

private void shouldRescheduleJobsCorrectlyWhenInitialisationCountIs(final int initialisationCount) throws Exception {
    // Given
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJobTrackerEnabled()).willReturn(true);
    given(properties.getJobExecutorThreadCount()).willReturn(1);
    final Repeat repeat = new Repeat(0, 100, TimeUnit.SECONDS);
    final OperationChain opChain = new OperationChain.Builder().first(new DiscardOutput()).build();
    final User user = new User.Builder().userId("testUser").opAuth("opAuth").dataAuth("dataAuth").build();
    final JobDetail scheduledJobDetail = new JobDetail.Builder().jobId("jobId").user(user).opChain(opChain.toOverviewString()).serialisedOperationChain(opChain).repeat(repeat).build();
    given(jobTracker.getAllScheduledJobs()).willReturn(new WrappedCloseableIterable(singletonList(scheduledJobDetail)));
    StoreImpl2 store = new StoreImpl2();
    // When - initialise store
    for (int i = 0; i < initialisationCount; i++) {
        store.initialise("graphId", schema, properties);
    }
    ScheduledExecutorService service = store.getExecutorService();
    // Then - assert scheduled
    final ArgumentCaptor<ScheduledJobRunnable> scheduledJobRunnableCaptor = ArgumentCaptor.forClass(ScheduledJobRunnable.class);
    verify(service).scheduleAtFixedRate(scheduledJobRunnableCaptor.capture(), eq(repeat.getInitialDelay()), eq(repeat.getRepeatPeriod()), eq(repeat.getTimeUnit()));
    assertEquals(scheduledJobDetail, scheduledJobRunnableCaptor.getValue().getJobDetail());
    assertEquals(user, scheduledJobRunnableCaptor.getValue().getContext().getUser());
    assertArrayEquals(JSONSerialiser.serialise(opChain), JSONSerialiser.serialise(scheduledJobRunnableCaptor.getValue().getOperationChain()));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) User(uk.gov.gchq.gaffer.user.User) WrappedCloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.WrappedCloseableIterable) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ScheduledJobRunnable(uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput)

Example 32 with JobDetail

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

the class StoreTest method shouldCorrectlySetUpScheduledJobDetail.

@Test
public void shouldCorrectlySetUpScheduledJobDetail() throws Exception {
    // Given
    final StoreProperties properties = mock(StoreProperties.class);
    given(properties.getJobTrackerEnabled()).willReturn(true);
    given(properties.getJobExecutorThreadCount()).willReturn(1);
    StoreImpl2 store = new StoreImpl2();
    store.initialise("graphId", schema, properties);
    final Repeat repeat = new Repeat(0, 100, TimeUnit.SECONDS);
    final OperationChain opChain = new OperationChain.Builder().first(new DiscardOutput()).build();
    final Context context = new Context(user);
    final String operationChainOverviewString = opChain.toOverviewString();
    final String serialisedOperationChain = new String(JSONSerialiser.serialise(opChain), Charset.forName(CommonConstants.UTF_8));
    // When - setup job
    JobDetail parentJobDetail = store.executeJob(new Job(repeat, opChain), context);
    ScheduledExecutorService service = store.getExecutorService();
    // Then - assert scheduled
    verify(service).scheduleAtFixedRate(any(Runnable.class), eq(repeat.getInitialDelay()), eq(repeat.getRepeatPeriod()), eq(repeat.getTimeUnit()));
    // Then - assert job detail is as expected
    assertEquals(JobStatus.SCHEDULED_PARENT, parentJobDetail.getStatus());
    assertEquals(operationChainOverviewString, parentJobDetail.getOpChain());
    assertEquals(serialisedOperationChain, parentJobDetail.getSerialisedOperationChain());
    assertEquals(context.getUser(), parentJobDetail.getUser());
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain) ScheduledJobRunnable(uk.gov.gchq.gaffer.store.Store.ScheduledJobRunnable) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) Repeat(uk.gov.gchq.gaffer.jobtracker.Repeat) Job(uk.gov.gchq.gaffer.jobtracker.Job) CancelScheduledJob(uk.gov.gchq.gaffer.operation.impl.job.CancelScheduledJob) Test(org.junit.jupiter.api.Test)

Example 33 with JobDetail

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

the class OperationChainTest method shouldBuildOperationChain.

@Test
public void shouldBuildOperationChain() {
    // Given
    final AddElements addElements1 = mock(AddElements.class);
    final AddElements addElements2 = mock(AddElements.class);
    final GetAdjacentIds getAdj1 = mock(GetAdjacentIds.class);
    final GetAdjacentIds getAdj2 = mock(GetAdjacentIds.class);
    final GetAdjacentIds getAdj3 = mock(GetAdjacentIds.class);
    final GetElements getElements1 = mock(GetElements.class);
    final GetElements getElements2 = mock(GetElements.class);
    final GetAllElements getAllElements = mock(GetAllElements.class);
    final DiscardOutput discardOutput = mock(DiscardOutput.class);
    final GetJobDetails getJobDetails = mock(GetJobDetails.class);
    final GenerateObjects<EntityId> generateEntitySeeds = mock(GenerateObjects.class);
    final Limit<Element> limit = mock(Limit.class);
    final ToSet<Element> deduplicate = mock(ToSet.class);
    final CountGroups countGroups = mock(CountGroups.class);
    final ExportToSet<GroupCounts> exportToSet = mock(ExportToSet.class);
    final ExportToGafferResultCache<CloseableIterable<? extends Element>> exportToGafferCache = mock(ExportToGafferResultCache.class);
    final If<Iterable<? extends EntityId>, Iterable<? extends EntityId>> ifOp = mock(If.class);
    // When
    final OperationChain<JobDetail> opChain = new Builder().first(addElements1).then(getAdj1).then(getAdj2).then(getElements1).then(generateEntitySeeds).then(getAdj3).then(ifOp).then(getElements2).then(deduplicate).then(limit).then(countGroups).then(exportToSet).then(discardOutput).then(getAllElements).then(exportToGafferCache).then(addElements2).then(getJobDetails).build();
    // Then
    final Operation[] expecteds = { addElements1, getAdj1, getAdj2, getElements1, generateEntitySeeds, getAdj3, ifOp, getElements2, deduplicate, limit, countGroups, exportToSet, discardOutput, getAllElements, exportToGafferCache, addElements2, getJobDetails };
    assertArrayEquals(expecteds, opChain.getOperationArray());
}
Also used : AddElements(uk.gov.gchq.gaffer.operation.impl.add.AddElements) GetJobDetails(uk.gov.gchq.gaffer.operation.impl.job.GetJobDetails) GetAdjacentIds(uk.gov.gchq.gaffer.operation.impl.get.GetAdjacentIds) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) CloseableIterable(uk.gov.gchq.gaffer.commonutil.iterable.CloseableIterable) Element(uk.gov.gchq.gaffer.data.element.Element) Builder(uk.gov.gchq.gaffer.operation.OperationChain.Builder) GetElements(uk.gov.gchq.gaffer.operation.impl.get.GetElements) EntityId(uk.gov.gchq.gaffer.data.element.id.EntityId) JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) CountGroups(uk.gov.gchq.gaffer.operation.impl.CountGroups) GetAllElements(uk.gov.gchq.gaffer.operation.impl.get.GetAllElements) DiscardOutput(uk.gov.gchq.gaffer.operation.impl.DiscardOutput) GroupCounts(uk.gov.gchq.gaffer.data.GroupCounts) Test(org.junit.jupiter.api.Test)

Example 34 with JobDetail

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

the class Store method executeJob.

protected JobDetail executeJob(final OperationChain<?> operationChain, final Context context, final String parentJobId) throws OperationException {
    JobDetail childJobDetail = addOrUpdateJobDetail(operationChain, context, null, JobStatus.RUNNING);
    childJobDetail.setParentJobId(parentJobId);
    return executeJob(operationChain, childJobDetail, context);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail)

Example 35 with JobDetail

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

the class Store method executeJob.

/**
 * Executes a given {@link Job} containing an Operation and/or
 * {@link uk.gov.gchq.gaffer.jobtracker.Repeat} and returns the job detail.
 *
 * @param job     the job to execute.
 * @param context the context executing the job.
 * @return the job detail.
 * @throws OperationException thrown if there is an error running the job.
 */
public JobDetail executeJob(final Job job, final Context context) throws OperationException {
    OperationChain opChain = OperationChain.wrap(job.getOperation());
    if (opChain.getOperations().isEmpty()) {
        throw new IllegalArgumentException("An operation is required");
    }
    final JobDetail jobDetail = addOrUpdateJobDetail(opChain, context, null, JobStatus.RUNNING);
    jobDetail.setRepeat(job.getRepeat());
    return executeJob(opChain, jobDetail, context);
}
Also used : JobDetail(uk.gov.gchq.gaffer.jobtracker.JobDetail) ValidateOperationChain(uk.gov.gchq.gaffer.operation.impl.ValidateOperationChain) OperationChain(uk.gov.gchq.gaffer.operation.OperationChain)

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