use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class PinsetterKernel method cancelJobs.
/**
* Cancels the specified jobs by deleting the jobs and all triggers from the scheduler.
* Assumes that the jobs are already marked as CANCELED in the JobStatus table.
*
* @param toCancel the JobStatus records of the jobs to cancel.
* @throws PinsetterException if there is an error deleting the jobs from the schedule.
*
* @return
* The number of jobs cancelled as a result of a call to this method
*/
public int cancelJobs(Collection<JobStatus> toCancel) throws PinsetterException {
List<JobKey> jobsToDelete = new LinkedList<>();
for (JobStatus status : toCancel) {
JobKey key = jobKey(status.getId(), status.getGroup());
log.debug("Job {} from group {} will be deleted from the scheduler.", key.getName(), key.getGroup());
jobsToDelete.add(key);
}
if (jobsToDelete.size() > 0) {
log.info("Deleting {} cancelled jobs from scheduler", jobsToDelete.size());
try {
scheduler.deleteJobs(jobsToDelete);
} catch (SchedulerException se) {
throw new PinsetterException("Problem canceling jobs.", se);
}
log.info("Finished deleting jobs from scheduler");
}
return jobsToDelete.size();
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class UnpauseJobTest method ensureJobCancelledWhenJobClassNoLongerExists.
@Test
public void ensureJobCancelledWhenJobClassNoLongerExists() throws Exception {
JobDetail detail = Mockito.mock(JobDetail.class);
JobKey key = new JobKey("fake-job");
when(detail.getKey()).thenReturn(key);
// Allowing setting the value of JobStatus.jobClass since it is private.
// Do not want to expose the setter.
Class<? extends JobStatus> statusClass = JobStatus.class;
Field jobClassField = statusClass.getDeclaredField("jobClass");
jobClassField.setAccessible(true);
JobStatus status = new JobStatus();
jobClassField.set(status, "unknown.class");
status.setState(JobStatus.JobState.CREATED);
assertEquals("unknown.class", status.getJobClass());
List<JobStatus> jl = new ArrayList<>();
jl.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(jl);
when(jobCurator.findWaitingJobs()).thenReturn(query);
unpauseJob.execute(ctx);
assertEquals(JobStatus.JobState.CANCELED, status.getState());
assertEquals("Job canceled because job class no longer exists.", status.getResult());
verify(jobCurator).merge(eq(status));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class UnpauseJobTest method unPauseTest.
@Test
public void unPauseTest() throws JobExecutionException, PinsetterException {
JobDetail jd = newJob(KingpinJob.class).withIdentity("Kayfabe", "Deluxe").build();
JobStatus js = new JobStatus(jd, true);
List<JobStatus> jl = new ArrayList<>();
jl.add(js);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(jl);
when(jobCurator.findWaitingJobs()).thenReturn(query);
unpauseJob.execute(ctx);
try {
verify(pk, atLeastOnce()).addTrigger(js);
} catch (SchedulerException e) {
fail("Should not throw an exception");
}
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method getStatusesByUuid.
@Test
public void getStatusesByUuid() {
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.findByConsumerUuid(eq("abcd"))).thenReturn(query);
this.mockCPQueryTransform(query);
Collection<JobStatusDTO> real = jobResource.getStatuses(null, "abcd", null).list();
assertNotNull(real);
assertEquals(1, real.size());
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method getStatusesByOwner.
@Test
public void getStatusesByOwner() {
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.findByOwnerKey(eq("admin"))).thenReturn(query);
this.mockCPQueryTransform(query);
Collection<JobStatusDTO> real = jobResource.getStatuses("admin", null, null).list();
assertNotNull(real);
assertEquals(1, real.size());
}
Aggregations