Search in sources :

Example 36 with JobStatus

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

the class JobCuratorTest method findByOwnerReturnsAllWhenRequestedBySuperAdmin.

@Test
public void findByOwnerReturnsAllWhenRequestedBySuperAdmin() {
    newJobStatus().principalName("p1").owner("owner1").create();
    newJobStatus().principalName("p2").owner("owner1").create();
    newJobStatus().principalName("p3").owner("owner2").create();
    setupAdminPrincipal("bob");
    List<JobStatus> jobs = this.curator.findByOwnerKey("owner1").list();
    assertNotNull(jobs);
    assertEquals(2, jobs.size());
    for (JobStatus job : jobs) {
        assertEquals("owner1", job.getOwnerId());
    }
    assertEquals(1, this.curator.findByOwnerKey("owner2").list().size());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 37 with JobStatus

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

the class JobCuratorTest method findByPrincipalNameRestrictsConsumerToOwnJobs.

@Test
public void findByPrincipalNameRestrictsConsumerToOwnJobs() {
    Owner owner = new Owner("ducks");
    Consumer consumer = TestUtil.createConsumer(owner);
    JobStatus job = newJobStatus().principalName(consumer.getUuid()).owner(owner.getKey()).create();
    newJobStatus().principalName("donald").owner(owner.getKey()).create();
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    assertTrue(this.curator.findByPrincipalName("donald").list().isEmpty());
    List<JobStatus> jobs = this.curator.findByPrincipalName(consumer.getUuid()).list();
    assertNotNull(jobs);
    assertEquals(1, jobs.size());
    assertEquals(consumer.getUuid(), job.getPrincipalName());
    assertEquals(job, jobs.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 38 with JobStatus

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

the class JobCurator method cancel.

@Transactional
public JobStatus cancel(String jobId) {
    this.cancelNoReturn(jobId);
    JobStatus result = this.find(jobId);
    if (result != null) {
        this.refresh(result);
    }
    return result;
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Transactional(com.google.inject.persist.Transactional)

Example 39 with JobStatus

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

the class KingpinJob method scheduleJob.

public static JobStatus scheduleJob(JobCurator jobCurator, Scheduler scheduler, JobDetail detail, Trigger trigger) throws SchedulerException {
    scheduler.getListenerManager().addJobListenerMatcher(PinsetterJobListener.LISTENER_NAME, jobNameEquals(detail.getKey().getName()));
    JobStatus status = null;
    try {
        status = jobCurator.create(new JobStatus(detail, trigger == null));
        if (trigger != null) {
            scheduler.scheduleJob(detail, trigger);
        } else {
            scheduler.addJob(detail, false);
        }
    } catch (EntityExistsException e) {
        // status exists, let's update it
        // in theory this should be the rare case
        status = jobCurator.find(detail.getKey().getName());
        jobCurator.merge(status);
    } catch (RuntimeException e) {
        failStatus(jobCurator, status);
        throw e;
    } catch (SchedulerException e) {
        failStatus(jobCurator, status);
        throw e;
    }
    return status;
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) SchedulerException(org.quartz.SchedulerException) EntityExistsException(javax.persistence.EntityExistsException)

Example 40 with JobStatus

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

the class CancelJobJob method toExecute.

@Override
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
    try {
        Set<JobKey> keys = pinsetterKernel.getSingleJobKeys();
        Set<String> statusIds = new HashSet<>();
        for (JobKey key : keys) {
            statusIds.add(key.getName());
        }
        try {
            Set<JobStatus> jobs = this.jobCurator.findCanceledJobs(statusIds);
            if (jobs.size() > 0) {
                pinsetterKernel.cancelJobs(jobs);
            }
        } catch (PinsetterException e) {
            log.error("Exception canceling jobs", e);
        }
    } catch (SchedulerException e) {
        log.error("Unable to cancel jobs", e);
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobKey(org.quartz.JobKey) SchedulerException(org.quartz.SchedulerException) PinsetterException(org.candlepin.pinsetter.core.PinsetterException) HashSet(java.util.HashSet)

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