Search in sources :

Example 41 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus 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 42 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class PinsetterTriggerListener method triggerMisfired.

@Override
public void triggerMisfired(Trigger trigger) {
    log.warn("Trigger misfired for for Job: \nKey: {}\nJob Key: {}\nStart: {}\nEnd: {}\n" + "Final Fire Time: {}\nNext Fire Time: {}\nMisfire Instruction: {}\nPriority: {}", trigger.getKey(), trigger.getJobKey(), trigger.getStartTime(), trigger.getEndTime(), trigger.getFinalFireTime(), trigger.getNextFireTime(), trigger.getMisfireInstruction(), trigger.getPriority());
    try {
        String id = trigger.getJobKey().getName();
        JobStatus js = jobCurator.find(id);
        if (js == null) {
            throw new RuntimeException("No JobStatus for job with id of " + id);
        }
        // if may not refire again, change to fail
        if (!trigger.mayFireAgain()) {
            log.warn("Job {} not allowed to fire again. Setting state to FAILED.", id);
            js.setState(JobStatus.JobState.FAILED);
            js.setResult("Failed run. Will not attempt again.");
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            js.setResult("Will reattempt job at or after " + sdf.format(trigger.getNextFireTime()));
            js.setState(JobStatus.JobState.PENDING);
        }
        jobCurator.merge(js);
    } catch (Exception e) {
        log.error("Unable to capture misfire into job status: {}", e.getMessage());
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) SimpleDateFormat(java.text.SimpleDateFormat)

Example 43 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class UniqueByEntityJob method scheduleJob.

@SuppressWarnings("unchecked")
public static JobStatus scheduleJob(JobCurator jobCurator, Scheduler scheduler, JobDetail detail, Trigger trigger) throws SchedulerException {
    JobStatus result = jobCurator.getByClassAndTarget(detail.getJobDataMap().getString(JobStatus.TARGET_ID), (Class<? extends KingpinJob>) detail.getJobClass());
    if (result == null) {
        return KingpinJob.scheduleJob(jobCurator, scheduler, detail, trigger);
    }
    if (result.getState() == JobStatus.JobState.PENDING || result.getState() == JobStatus.JobState.CREATED || result.getState() == JobStatus.JobState.WAITING) {
        log.debug("Returning existing job id: {}", result.getId());
        return result;
    }
    log.debug("Scheduling job without a trigger: {}", detail.getKey().getName());
    JobStatus status = KingpinJob.scheduleJob(jobCurator, scheduler, detail, null);
    return status;
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus)

Example 44 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class JobResourceTest method getStatusAndDeleteIfFinishedTest.

@Test
public void getStatusAndDeleteIfFinishedTest() {
    // nothing to delete..
    when(jobCurator.find("bogus_id")).thenReturn(new JobStatus());
    jobResource.getStatusAndDeleteIfFinished("foobar");
    verify(jobCurator, never()).delete(any(JobStatus.class));
    // now lets make a deletable JobStatus
    JobStatus finishedJobStatus = new JobStatus();
    finishedJobStatus.setState(JobState.FINISHED);
    when(jobCurator.find("deletable_id")).thenReturn(finishedJobStatus);
    jobResource.getStatusAndDeleteIfFinished("deletable_id");
    verify(jobCurator, atLeastOnce()).delete(finishedJobStatus);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 45 with JobStatus

use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.

the class JobResourceTest method getStatusesByPrincipal.

@Test
public void getStatusesByPrincipal() {
    List<JobStatus> statuses = new ArrayList<>();
    JobStatus status = new JobStatus();
    statuses.add(status);
    CandlepinQuery query = mock(CandlepinQuery.class);
    when(query.list()).thenReturn(statuses);
    when(query.iterate()).thenReturn(new MockResultIterator(statuses.iterator()));
    when(query.iterate(anyInt(), anyBoolean())).thenReturn(new MockResultIterator(statuses.iterator()));
    when(jobCurator.findByPrincipalName(eq("admin"))).thenReturn(query);
    this.mockCPQueryTransform(query);
    Collection<JobStatusDTO> real = jobResource.getStatuses(null, null, "admin").list();
    assertNotNull(real);
    assertEquals(1, real.size());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) JobStatusDTO(org.candlepin.dto.api.v1.JobStatusDTO) MockResultIterator(org.candlepin.test.MockResultIterator) Test(org.junit.Test)

Aggregations

JobStatus (org.candlepin.pinsetter.core.model.JobStatus)56 Test (org.junit.Test)43 JobDetail (org.quartz.JobDetail)22 JobKey (org.quartz.JobKey)10 ArrayList (java.util.ArrayList)7 CandlepinQuery (org.candlepin.model.CandlepinQuery)7 JobDataMap (org.quartz.JobDataMap)7 JobExecutionException (org.quartz.JobExecutionException)7 Trigger (org.quartz.Trigger)6 JobStatusDTO (org.candlepin.dto.api.v1.JobStatusDTO)5 TransformedCandlepinQuery (org.candlepin.model.TransformedCandlepinQuery)5 SchedulerException (org.quartz.SchedulerException)5 Principal (org.candlepin.auth.Principal)4 Date (java.util.Date)3 HashSet (java.util.HashSet)3 ConsumerPrincipal (org.candlepin.auth.ConsumerPrincipal)3 JobCurator (org.candlepin.model.JobCurator)3 MockResultIterator (org.candlepin.test.MockResultIterator)3 CronTrigger (org.quartz.CronTrigger)3 Transactional (com.google.inject.persist.Transactional)2