Search in sources :

Example 21 with JpaJob

use of org.opencastproject.job.jpa.JpaJob in project opencast by opencast.

the class ServiceRegistryJpaImpl method getChildJobs.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.serviceregistry.api.ServiceRegistry#getChildJobs(long)
 */
@Override
public List<Job> getChildJobs(long id) throws ServiceRegistryException {
    EntityManager em = null;
    try {
        em = emf.createEntityManager();
        TypedQuery<JpaJob> query = em.createNamedQuery("Job.root.children", JpaJob.class);
        query.setParameter("id", id);
        List<JpaJob> jobs = query.getResultList();
        if (jobs.size() == 0) {
            jobs = getChildren(em, id);
        }
        return $(jobs).sort(new Comparator<JpaJob>() {

            @Override
            public int compare(JpaJob job1, JpaJob job2) {
                if (job1.getDateCreated() == null || job2.getDateCreated() == null) {
                    return 0;
                } else {
                    return job1.getDateCreated().compareTo(job2.getDateCreated());
                }
            }
        }).map(fnSetJobUri()).map(fnToJob()).toList();
    } catch (Exception e) {
        throw new ServiceRegistryException(e);
    } finally {
        if (em != null)
            em.close();
    }
}
Also used : EntityManager(javax.persistence.EntityManager) JpaJob(org.opencastproject.job.jpa.JpaJob) URISyntaxException(java.net.URISyntaxException) NoResultException(javax.persistence.NoResultException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) TrustedHttpClientException(org.opencastproject.security.api.TrustedHttpClientException) PersistenceException(javax.persistence.PersistenceException) RollbackException(javax.persistence.RollbackException) NotFoundException(org.opencastproject.util.NotFoundException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) Comparator(java.util.Comparator)

Example 22 with JpaJob

use of org.opencastproject.job.jpa.JpaJob in project opencast by opencast.

the class DispatchableComparatorTest method createJob.

private JpaJob createJob(long id, String type, Job.Status status, Date created) {
    JpaJob job = EasyMock.createNiceMock(JpaJob.class);
    EasyMock.expect(job.getId()).andReturn(id).anyTimes();
    EasyMock.expect(job.getJobType()).andReturn(type).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(status).anyTimes();
    EasyMock.expect(job.getDateCreated()).andReturn(created).anyTimes();
    EasyMock.replay(job);
    return job;
}
Also used : JpaJob(org.opencastproject.job.jpa.JpaJob)

Example 23 with JpaJob

use of org.opencastproject.job.jpa.JpaJob in project opencast by opencast.

the class DispatchableComparatorTest method testGreaterThanByDateCreated.

@Test
public void testGreaterThanByDateCreated() {
    // Test first greater than second: same job type, same status, different date
    JpaJob j5 = createJob(5L, "non-wf", Status.RESTART, dtPlusOneHour);
    assertEquals("Jobs with earlier created date should be less than jobs with later created date", 1, dispatchableComparator.compare(j5, j1));
}
Also used : JpaJob(org.opencastproject.job.jpa.JpaJob) Test(org.junit.Test)

Example 24 with JpaJob

use of org.opencastproject.job.jpa.JpaJob in project opencast by opencast.

the class DispatchableComparatorTest method testGreaterThanByJobType.

@Test
public void testGreaterThanByJobType() {
    // Test first greater than second: different job type, same status, same date
    JpaJob j4 = createJob(4L, ServiceRegistryJpaImpl.TYPE_WORKFLOW, Status.RESTART, dt);
    assertEquals("Non-workflow jobs should be less than workflow jobs", 1, dispatchableComparator.compare(j4, j1));
}
Also used : JpaJob(org.opencastproject.job.jpa.JpaJob) Test(org.junit.Test)

Example 25 with JpaJob

use of org.opencastproject.job.jpa.JpaJob in project opencast by opencast.

the class ServiceRegistryJpaImpl method cancelAllChildren.

/**
 * Go through all the children recursively to set them in {@link Status#CANCELED} status
 *
 * @param job
 *          the parent job
 * @param em
 *          the entity manager
 */
private void cancelAllChildren(JpaJob job, EntityManager em) {
    for (JpaJob child : job.getChildJobs()) {
        em.refresh(child);
        if (Status.CANCELED.equals(job.getStatus()))
            continue;
        cancelAllChildren(child, em);
        child.setStatus(Status.CANCELED);
        em.merge(child);
    }
}
Also used : JpaJob(org.opencastproject.job.jpa.JpaJob)

Aggregations

JpaJob (org.opencastproject.job.jpa.JpaJob)29 NotFoundException (org.opencastproject.util.NotFoundException)13 PersistenceException (javax.persistence.PersistenceException)11 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)11 EntityManager (javax.persistence.EntityManager)10 NoResultException (javax.persistence.NoResultException)10 RollbackException (javax.persistence.RollbackException)10 URISyntaxException (java.net.URISyntaxException)9 Test (org.junit.Test)9 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)9 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)9 ConfigurationException (org.osgi.service.cm.ConfigurationException)9 Job (org.opencastproject.job.api.Job)7 ArrayList (java.util.ArrayList)6 EntityTransaction (javax.persistence.EntityTransaction)6 JpaJob.fnToJob (org.opencastproject.job.jpa.JpaJob.fnToJob)6 HttpStatus (org.apache.http.HttpStatus)4 Status (org.opencastproject.job.api.Job.Status)4 Date (java.util.Date)3 Query (javax.persistence.Query)2