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