Search in sources :

Example 1 with JobCurator

use of org.candlepin.model.JobCurator in project candlepin by candlepin.

the class PinsetterKernel method scheduleJob.

private JobStatus scheduleJob(JobDetail detail, String grpName, Trigger trigger) throws PinsetterException {
    JobDetailImpl detailImpl = (JobDetailImpl) detail;
    detailImpl.setGroup(grpName);
    try {
        JobStatus status = (JobStatus) (detail.getJobClass().getMethod("scheduleJob", JobCurator.class, Scheduler.class, JobDetail.class, Trigger.class).invoke(null, jobCurator, scheduler, detail, trigger));
        if (log.isDebugEnabled()) {
            log.debug("Scheduled " + detailImpl.getFullName());
        }
        return status;
    } catch (Exception e) {
        log.error("There was a problem scheduling " + detail.getKey().getName(), e);
        throw new PinsetterException("There was a problem scheduling " + detail.getKey().getName(), e);
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) CronTrigger(org.quartz.CronTrigger) Trigger(org.quartz.Trigger) TriggerBuilder.newTrigger(org.quartz.TriggerBuilder.newTrigger) JobDetailImpl(org.quartz.impl.JobDetailImpl) Scheduler(org.quartz.Scheduler) JobExecutionException(org.quartz.JobExecutionException) SchedulerException(org.quartz.SchedulerException) JobCurator(org.candlepin.model.JobCurator)

Example 2 with JobCurator

use of org.candlepin.model.JobCurator in project candlepin by candlepin.

the class HypervisorUpdateJobTest method monogamousJobTest.

/*
     * Make sure only one test is running at a time.
     */
@Test
public void monogamousJobTest() throws JobExecutionException, SchedulerException {
    JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
    JobStatus newJob = new JobStatus(detail);
    JobCurator jobCurator = mock(JobCurator.class);
    when(jobCurator.findNumRunningByClassAndTarget(owner.getKey(), HypervisorUpdateJob.class)).thenReturn(1L);
    assertFalse(HypervisorUpdateJob.isSchedulable(jobCurator, newJob));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) JobCurator(org.candlepin.model.JobCurator) Test(org.junit.Test)

Example 3 with JobCurator

use of org.candlepin.model.JobCurator in project candlepin by candlepin.

the class HypervisorUpdateJobTest method dontSkipIfExistsTest.

/*
     * Schedule the job to be executed later even if a similar job exists.
     */
@Test
public void dontSkipIfExistsTest() throws JobExecutionException, SchedulerException {
    JobDetail detail = HypervisorUpdateJob.forOwner(owner, hypervisorJson, true, principal, null);
    JobStatus preExistingJobStatus = new JobStatus();
    preExistingJobStatus.setState(JobState.WAITING);
    HypervisorUpdateJob job = new HypervisorUpdateJob(ownerCurator, consumerCurator, consumerTypeCurator, consumerResource, i18n, subAdapter, complianceRules);
    JobStatus newlyScheduledJobStatus = new JobStatus();
    JobCurator jobCurator = mock(JobCurator.class);
    Scheduler scheduler = mock(Scheduler.class);
    ListenerManager lm = mock(ListenerManager.class);
    when(jobCurator.getByClassAndTarget(anyString(), any(Class.class))).thenReturn(preExistingJobStatus);
    when(scheduler.getListenerManager()).thenReturn(lm);
    when(jobCurator.create(any(JobStatus.class))).thenReturn(newlyScheduledJobStatus);
    JobStatus resultStatus = job.scheduleJob(jobCurator, scheduler, detail, null);
    assertEquals(newlyScheduledJobStatus, resultStatus);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobDetail(org.quartz.JobDetail) Scheduler(org.quartz.Scheduler) JobCurator(org.candlepin.model.JobCurator) ListenerManager(org.quartz.ListenerManager) Test(org.junit.Test)

Example 4 with JobCurator

use of org.candlepin.model.JobCurator in project candlepin by candlepin.

the class JobCleanerTest method execute.

@Test
public void execute() throws Exception {
    JobCurator curator = mock(JobCurator.class);
    JobCleaner cleaner = new JobCleaner(curator);
    injector.injectMembers(cleaner);
    cleaner.execute(null);
    verify(curator).cleanUpOldCompletedJobs(any(Date.class));
    verify(curator).cleanupAllOldJobs(any(Date.class));
}
Also used : Date(java.util.Date) JobCurator(org.candlepin.model.JobCurator) Test(org.junit.Test)

Aggregations

JobCurator (org.candlepin.model.JobCurator)4 JobStatus (org.candlepin.pinsetter.core.model.JobStatus)3 Test (org.junit.Test)3 JobDetail (org.quartz.JobDetail)3 Scheduler (org.quartz.Scheduler)2 Date (java.util.Date)1 CronTrigger (org.quartz.CronTrigger)1 JobExecutionException (org.quartz.JobExecutionException)1 ListenerManager (org.quartz.ListenerManager)1 SchedulerException (org.quartz.SchedulerException)1 Trigger (org.quartz.Trigger)1 TriggerBuilder.newTrigger (org.quartz.TriggerBuilder.newTrigger)1 JobDetailImpl (org.quartz.impl.JobDetailImpl)1