Search in sources :

Example 31 with JobStatus

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

the class JobCuratorTest method cancelOrphanedJobs.

@Test
public void cancelOrphanedJobs() throws InterruptedException {
    JobStatus status1 = newJobStatus().state(JobStatus.JobState.WAITING).id("1").create();
    JobStatus status2 = newJobStatus().state(JobStatus.JobState.WAITING).id("2").create();
    JobStatus status3 = newJobStatus().state(JobStatus.JobState.RUNNING).id("3").create();
    JobStatus status4 = newJobStatus().state(JobStatus.JobState.CREATED).id("4").create();
    JobStatus status5 = newJobStatus().state(JobStatus.JobState.RUNNING).id("5").create();
    List<String> activeIds = new LinkedList<>();
    activeIds.add(status1.getId());
    activeIds.add(status3.getId());
    activeIds.add(status4.getId());
    int updated = curator.cancelOrphanedJobs(activeIds, 0L);
    assertEquals(2, updated);
    curator.refresh(status1);
    curator.refresh(status2);
    curator.refresh(status3);
    curator.refresh(status4);
    curator.refresh(status5);
    assertEquals(JobStatus.JobState.WAITING, status1.getState());
    assertEquals(JobStatus.JobState.CANCELED, status2.getState());
    assertEquals(JobStatus.JobState.RUNNING, status3.getState());
    assertEquals(JobStatus.JobState.CREATED, status4.getState());
    assertEquals(JobStatus.JobState.CANCELED, status5.getState());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 32 with JobStatus

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

the class JobCuratorTest method findByUserFiltersByOwnerAccessWhenRequestedByBasicUser.

@Test
public void findByUserFiltersByOwnerAccessWhenRequestedByBasicUser() {
    newJobStatus().principalName("p1").owner("owner1").create();
    newJobStatus().principalName("p2").owner("owner1").create();
    newJobStatus().principalName("p3").owner("owner2").create();
    setupPrincipal("goofy", new Owner("owner1"), Access.READ_ONLY);
    List<JobStatus> jobs = this.curator.findByOwnerKey("owner1").list();
    assertNotNull(jobs);
    assertEquals(2, jobs.size());
    for (JobStatus job : jobs) {
        assertEquals("owner1", job.getOwnerId());
    }
    assertTrue(this.curator.findByOwnerKey("owner2").list().isEmpty());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 33 with JobStatus

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

the class JobCuratorTest method findByConsumerUuidRestrictsByConsumerUuidEnforcesOwnerMatchWhenRequestedByConsumer.

@Test
public void findByConsumerUuidRestrictsByConsumerUuidEnforcesOwnerMatchWhenRequestedByConsumer() {
    Owner owner = new Owner("testowner");
    owner.setId(TestUtil.randomString());
    Consumer consumer = TestUtil.createConsumer(owner);
    JobStatus job = newJobStatus().principalName(consumer.getUuid()).consumer(consumer.getUuid(), "testowner").create();
    // Technically this case shoरावणuld not happen since a consumer
    // can belong to one org, but adding just to make sure that
    // it gets filtered.
    newJobStatus().principalName(consumer.getUuid()).consumer(consumer.getUuid(), "owner1").create();
    newJobStatus().principalName("p2").consumer("c2", "owner1").create();
    newJobStatus().principalName("p3").owner("owner2").create();
    setupPrincipal(new ConsumerPrincipal(consumer, owner));
    List<JobStatus> jobs = curator.findByConsumerUuid(consumer.getUuid()).list();
    assertEquals(1, jobs.size());
    assertEquals(job, jobs.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) ConsumerPrincipal(org.candlepin.auth.ConsumerPrincipal) Test(org.junit.Test)

Example 34 with JobStatus

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

the class JobCuratorTest method findByPrincipalNameRestrictsUserToAccessableOrgs.

@Test
public void findByPrincipalNameRestrictsUserToAccessableOrgs() {
    JobStatus job = newJobStatus().principalName("donald").owner("ducks").create();
    newJobStatus().principalName("donald").owner("marley").create();
    setupPrincipal("goofy", new Owner("ducks"), Access.READ_ONLY);
    List<JobStatus> jobs = this.curator.findByPrincipalName("donald").list();
    assertNotNull(jobs);
    assertEquals(1, jobs.size());
    assertEquals("donald", job.getPrincipalName());
    assertEquals(job, jobs.get(0));
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

Example 35 with JobStatus

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

the class JobCuratorTest method cancel.

@Test
public void cancel() {
    String jobid = newJobStatus().owner("ducks").startTime(Util.yesterday()).create().getId();
    JobStatus job = curator.cancel(jobid);
    assertNotNull(job);
    assertEquals(jobid, job.getId());
    assertEquals(JobStatus.JobState.CANCELED, job.getState());
}
Also used : JobStatus(org.candlepin.pinsetter.core.model.JobStatus) Test(org.junit.Test)

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