Search in sources :

Example 16 with JobStatus

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

the class JobCuratorTest method getLatestByClassAndOwner.

@Test
public void getLatestByClassAndOwner() {
    long offset = System.currentTimeMillis() - 7000;
    newJobStatus(new Date(offset + 1000)).state(JobStatus.JobState.WAITING).owner("my_owner").jobClass(HealEntireOrgJob.class).create();
    newJobStatus(new Date(offset + 2000)).state(JobStatus.JobState.RUNNING).owner("my_owner").jobClass(HealEntireOrgJob.class).create();
    newJobStatus(new Date(offset + 3000)).state(JobStatus.JobState.RUNNING).owner("my_owner").jobClass(HealEntireOrgJob.class).create();
    JobStatus expected = newJobStatus(new Date(offset + 4000)).state(JobStatus.JobState.CREATED).jobClass(HealEntireOrgJob.class).owner("my_owner").create();
    // Would be chosen if the job class was correct
    newJobStatus(new Date(offset + 5000)).state(JobStatus.JobState.WAITING).owner("my_owner").jobClass(RefreshPoolsJob.class).create();
    // Would be chosen if the owner was correct
    newJobStatus(new Date(offset + 6000)).state(JobStatus.JobState.WAITING).owner("some_owner").jobClass(HealEntireOrgJob.class).create();
    // Would be chosen if the jobstate wasn't done
    newJobStatus(new Date(offset + 7000)).state(JobStatus.JobState.FINISHED).jobClass(HealEntireOrgJob.class).owner("my_owner").create();
    JobStatus result = curator.getByClassAndTarget("my_owner", HealEntireOrgJob.class);
    assertEquals(expected, result);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) RefreshPoolsJob(org.candlepin.pinsetter.tasks.RefreshPoolsJob) HealEntireOrgJob(org.candlepin.pinsetter.tasks.HealEntireOrgJob) Date(java.util.Date) Test(org.junit.Test)

Example 17 with JobStatus

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

the class JobCuratorTest method findWaitingJobsTest.

@Test
public void findWaitingJobsTest() {
    JobStatus waitingJob1 = newJobStatus().state(JobStatus.JobState.WAITING).startTime(Util.yesterday()).create();
    JobStatus waitingJob2 = newJobStatus().state(JobStatus.JobState.WAITING).startTime(Util.yesterday()).create();
    JobStatus createdJob = newJobStatus().state(JobStatus.JobState.CREATED).startTime(Util.yesterday()).create();
    JobStatus finishedJob = newJobStatus().state(JobStatus.JobState.FINISHED).startTime(Util.yesterday()).create();
    List<JobStatus> waitingList = curator.findWaitingJobs().list();
    assertTrue(waitingList.contains(waitingJob1));
    assertTrue(waitingList.contains(waitingJob2));
    assertFalse(waitingList.contains(createdJob));
    assertFalse(waitingList.contains(finishedJob));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 18 with JobStatus

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

the class JobCuratorTest method findByPrincipalName.

@Test
public void findByPrincipalName() {
    JobStatus job = newJobStatus().principalName("donald").owner("ducks").create();
    List<JobStatus> jobs = this.curator.findByPrincipalName("donald").list();
    assertNotNull(jobs);
    assertEquals("donald", job.getPrincipalName());
    assertEquals(job, jobs.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 19 with JobStatus

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

the class JobCuratorTest method updateWithLargeResult.

@Test
public void updateWithLargeResult() {
    String longstr = RandomStringUtils.randomAlphanumeric(300);
    JobExecutionContext ctx = mock(JobExecutionContext.class);
    when(ctx.getFireTime()).thenReturn(new Date());
    when(ctx.getJobRunTime()).thenReturn(1000L);
    when(ctx.getResult()).thenReturn(longstr);
    JobStatus status = newJobStatus().owner("terps").create();
    status.update(ctx);
    curator.merge(status);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobExecutionContext(org.quartz.JobExecutionContext) Date(java.util.Date) Test(org.junit.Test)

Example 20 with JobStatus

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

the class PinsetterJobListener method updateJob.

@Transactional
private void updateJob(JobExecutionContext ctx, JobExecutionException exc) {
    JobStatus status = curator.find(ctx.getJobDetail().getKey().getName());
    if (status != null) {
        if (exc != null) {
            log.error("Job [" + status.getId() + "] failed.", exc);
            status.setState(JobState.FAILED);
            status.setResult(exc.getMessage());
            if (exc.getCause() instanceof CandlepinException) {
                status.setResultData(((CandlepinException) exc.getCause()).message());
            }
        } else {
            status.update(ctx);
        }
        curator.merge(status);
    } else {
        log.debug("No jobinfo found for job: " + ctx);
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) CandlepinException(org.candlepin.common.exceptions.CandlepinException) Transactional(com.google.inject.persist.Transactional)

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