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();
}
}
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;
}
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));
}
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));
}
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);
}
}
Aggregations