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()));
}
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());
}
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());
}
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);
}
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);
}
Aggregations