Search in sources :

Example 26 with JobStatus

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"));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ElementTransformer(org.candlepin.util.ElementTransformer) ArrayList(java.util.ArrayList) TransformedCandlepinQuery(org.candlepin.model.TransformedCandlepinQuery) CandlepinQuery(org.candlepin.model.CandlepinQuery) Test(org.junit.Test)

Example 27 with JobStatus

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");
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 28 with JobStatus

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);
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 29 with JobStatus

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;
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus)

Example 30 with JobStatus

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);
        }
    }
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) JobExecutionException(org.quartz.JobExecutionException) HibernateException(org.hibernate.HibernateException) JobExecutionException(org.quartz.JobExecutionException) HibernateException(org.hibernate.HibernateException)

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