use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method verifyInput.
@Test
public void verifyInput() {
List<JobStatus> statuses = new ArrayList<>();
JobStatus status = new JobStatus();
statuses.add(status);
CandlepinQuery query = mock(CandlepinQuery.class);
when(query.list()).thenReturn(statuses);
when(jobCurator.findByOwnerKey(any(String.class))).thenReturn(query);
when(jobCurator.findByConsumerUuid(any(String.class))).thenReturn(query);
when(jobCurator.findByPrincipalName(any(String.class))).thenReturn(query);
when(query.transform(any(ElementTransformer.class))).thenReturn(query);
assertFalse(expectException("owner", "uuid", "pname"));
assertFalse(expectException("owner", null, "pname"));
assertFalse(expectException("owner", "uuid", null));
assertFalse(expectException(null, "uuid", "pname"));
assertTrue(expectException("owner", null, null));
assertTrue(expectException("owner", "", null));
assertTrue(expectException(null, "uuid", null));
assertTrue(expectException("", "uuid", null));
assertTrue(expectException(null, null, "pname"));
assertTrue(expectException(null, "", "pname"));
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResourceTest method cancelJob.
@Test
public void cancelJob() {
// we are just testing that the cancellation gets into the db
JobStatus createdJobStatus = new JobStatus();
createdJobStatus.setState(JobState.CREATED);
JobStatus canceledJobStatus = new JobStatus();
canceledJobStatus.setState(JobState.CANCELED);
when(jobCurator.find("cancel_id")).thenReturn(createdJobStatus);
when(jobCurator.cancel("cancel_id")).thenReturn(canceledJobStatus);
jobResource.cancel("cancel_id");
verify(jobCurator, atLeastOnce()).cancel("cancel_id");
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class JobResource method getStatus.
@ApiOperation(notes = "Retrieves a single Job Status", value = "getStatus")
@GET
@Path("/{job_id}")
@Produces(MediaType.APPLICATION_JSON)
public JobStatusDTO getStatus(@PathParam("job_id") @Verify(JobStatus.class) String jobId, @QueryParam("result_data") @DefaultValue("false") boolean resultData) {
JobStatus js = curator.find(jobId);
js.cloakResultData(!resultData);
return this.translator.translate(js, JobStatusDTO.class);
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class HypervisorUpdateJob method scheduleJob.
public static JobStatus scheduleJob(JobCurator jobCurator, Scheduler scheduler, JobDetail detail, Trigger trigger) throws SchedulerException {
JobStatus result = jobCurator.getByClassAndTarget(detail.getJobDataMap().getString(JobStatus.TARGET_ID), HypervisorUpdateJob.class);
if (result == null) {
return KingpinJob.scheduleJob(jobCurator, scheduler, detail, trigger);
}
log.debug("Scheduling job without a trigger: " + detail.getKey().getName());
JobStatus status = KingpinJob.scheduleJob(jobCurator, scheduler, detail, null);
return status;
}
use of org.candlepin.pinsetter.core.model.JobStatus in project candlepin by candlepin.
the class UnpauseJob method toExecute.
@Override
public void toExecute(JobExecutionContext ctx) throws JobExecutionException {
List<JobStatus> waitingJobs;
try {
waitingJobs = jobCurator.findWaitingJobs().list();
} catch (HibernateException e) {
log.error("Cannot execute query: ", e);
throw new JobExecutionException(e);
}
for (JobStatus j : waitingJobs) {
try {
Class jobClass = Class.forName(j.getJobClass());
boolean schedule = (Boolean) jobClass.getMethod("isSchedulable", JobCurator.class, JobStatus.class).invoke(null, jobCurator, j);
if (schedule) {
log.debug("Triggering waiting job: " + j.getId());
pinsetterKernel.addTrigger(j);
j.setState(JobState.CREATED);
jobCurator.merge(j);
}
} catch (ClassNotFoundException cnfe) {
log.warn("Job class {} not found. It was likely removed from candlepin and is no " + "longer valid.", j.getJobClass());
// Maintain job history. Mark it as CANCELED and update the status.
j.setState(JobState.CANCELED);
j.setResult("Job canceled because job class no longer exists.");
jobCurator.merge(j);
} catch (Exception e) {
log.error("Failed to schedule waiting job: " + j.getId(), e);
}
}
}
Aggregations