Search in sources :

Example 96 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class JobTest method testCountPerHostService.

@Test
public void testCountPerHostService() throws Exception {
    // create some test data
    testGetHostsCount();
    // Add an additional dispatchable job. This is important as it leaves the processing host field empty.
    Job localRunning1 = serviceRegistry.createJob(JOB_TYPE_2, OPERATION_NAME, null, null, true);
    localRunning1.setStatus(Status.RUNNING);
    localRunning1 = serviceRegistry.updateJob(localRunning1);
    // 
    final Monadics.ListMonadic<String> jpql = resultToString(new Function.X<EntityManager, List<Object[]>>() {

        @Override
        public List<Object[]> xapply(EntityManager em) throws Exception {
            return serviceRegistry.getCountPerHostService(em);
        }
    });
    assertTrue(jpql.exists(eq("http://remotehost:8080,testing1,2,1")));
    // <-- 2 jobs, one of them is the
    assertTrue(jpql.exists(eq("http://localhost:8080,testing2,2,2")));
    // dispatchable job
    assertTrue(jpql.exists(eq("http://remotehost:8080,testing1,3,1")));
    assertTrue(jpql.exists(eq("http://localhost:8080,testing2,3,1")));
    assertTrue(jpql.exists(eq("http://localhost:8080,testing1,3,1")));
    assertTrue(jpql.exists(eq("http://localhost:8080,testing1,2,2")));
    assertEquals(6, jpql.value().size());
}
Also used : Function(org.opencastproject.util.data.Function) EntityManager(javax.persistence.EntityManager) Monadics(org.opencastproject.util.data.Monadics) List(java.util.List) Arrays.mkString(org.opencastproject.util.data.Arrays.mkString) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 97 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class JobTest method testMarshallingWithJsonPayload.

@Test
public void testMarshallingWithJsonPayload() throws Exception {
    final String payload = "{'foo' : 'bar'}";
    Job job = new JobImpl();
    job.setPayload(payload);
    String marshalledJob = JobParser.toXml(new JaxbJob(job));
    Job unmarshalledJob = JobParser.parseJob(marshalledJob);
    assertEquals("json from unmarshalled job should remain unchanged", StringUtils.trim(payload), StringUtils.trim(unmarshalledJob.getPayload()));
}
Also used : JobImpl(org.opencastproject.job.api.JobImpl) JaxbJob(org.opencastproject.job.api.JaxbJob) Arrays.mkString(org.opencastproject.util.data.Arrays.mkString) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 98 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class JobTest method testGetActiveJobs.

@Test
public void testGetActiveJobs() throws Exception {
    Job job = serviceRegistry.createJob(LOCALHOST, JOB_TYPE_1, OPERATION_NAME, null, null, false, null);
    job.setStatus(Status.RUNNING);
    job = serviceRegistry.updateJob(job);
    job = serviceRegistry.createJob(LOCALHOST, JOB_TYPE_2, OPERATION_NAME, null, null, false, null);
    job.setStatus(Status.RUNNING);
    job = serviceRegistry.updateJob(job);
    // Search using both the job type and status
    List<Job> jobs = serviceRegistry.getActiveJobs();
    assertEquals(2, jobs.size());
    long jobId = jobs.get(0).getId();
    for (Status status : Status.values()) {
        job = serviceRegistry.getJob(jobId);
        job.setStatus(status);
        serviceRegistry.updateJob(job);
        jobs = serviceRegistry.getActiveJobs();
        if (status.isActive())
            assertEquals(2, jobs.size());
        else
            assertEquals(1, jobs.size());
    }
}
Also used : Status(org.opencastproject.job.api.Job.Status) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 99 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class JobTest method testVersionIncrements.

@Test
public void testVersionIncrements() throws Exception {
    Job job = serviceRegistry.createJob(JOB_TYPE_1, "some_operation", null, null, false);
    assertEquals("Newly created jobs should have a version of 1", 1, job.getVersion());
    job = serviceRegistry.getJob(job.getId());
    job.setPayload("update1");
    job = serviceRegistry.updateJob(job);
    job = serviceRegistry.getJob(job.getId());
    assertEquals("Updated job should have a version of 2", 2, job.getVersion());
    job = serviceRegistry.getJob(job.getId());
    job.setPayload("update2");
    job = serviceRegistry.updateJob(job);
    job = serviceRegistry.getJob(job.getId());
    assertEquals("Updated job should have a version of 3", 3, job.getVersion());
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 100 with Job

use of org.opencastproject.job.api.Job in project opencast by opencast.

the class ServiceRegistrationTest method testScenarioOneJobManyServices.

@Test
public void testScenarioOneJobManyServices() throws Exception {
    Job jobTry1 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
    Job jobTry2 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
    Job jobTry3 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
    Job jobTry4 = serviceRegistry.createJob(regType1Localhost.getHost(), regType1Localhost.getServiceType(), OPERATION_NAME_1, null, null, true, null);
    ServiceRegistrationJpaImpl updatedService1;
    ServiceRegistrationJpaImpl updatedService2;
    ServiceRegistrationJpaImpl updatedService3;
    // 1st try, failed on localhost
    jobTry1.setStatus(Status.FAILED);
    jobTry1.setJobType(regType1Localhost.getServiceType());
    jobTry1.setProcessingHost(regType1Localhost.getHost());
    jobTry1 = serviceRegistry.updateJob(jobTry1);
    updatedService1 = (ServiceRegistrationJpaImpl) serviceRegistry.getServiceRegistration(JOB_TYPE_1, regType1Localhost.getHost());
    Assert.assertEquals(ServiceState.WARNING, updatedService1.getServiceState());
    Assert.assertEquals(0, updatedService1.getErrorStateTrigger());
    // 2nd try, failed on remotehost1
    jobTry2.setStatus(Status.FAILED);
    jobTry2.setJobType(regType1Remotehost1.getServiceType());
    jobTry2.setProcessingHost(regType1Remotehost1.getHost());
    jobTry2 = serviceRegistry.updateJob(jobTry2);
    updatedService1 = getUpdatedService(regType1Localhost);
    updatedService2 = getUpdatedService(regType1Remotehost1);
    Assert.assertEquals(ServiceState.NORMAL, updatedService1.getServiceState());
    Assert.assertEquals(ServiceState.NORMAL, updatedService2.getServiceState());
    Assert.assertEquals(0, updatedService2.getWarningStateTrigger());
    Assert.assertEquals(0, updatedService2.getErrorStateTrigger());
    // 3rd try, failed on remotehost2
    jobTry3.setStatus(Status.FAILED);
    jobTry3.setJobType(regType1Remotehost2.getServiceType());
    jobTry3.setProcessingHost(regType1Remotehost2.getHost());
    jobTry3 = serviceRegistry.updateJob(jobTry3);
    updatedService1 = getUpdatedService(regType1Localhost);
    updatedService2 = getUpdatedService(regType1Remotehost1);
    updatedService3 = getUpdatedService(regType1Remotehost2);
    Assert.assertEquals(ServiceState.NORMAL, updatedService1.getServiceState());
    Assert.assertEquals(ServiceState.NORMAL, updatedService2.getServiceState());
    Assert.assertEquals(ServiceState.WARNING, updatedService3.getServiceState());
    Assert.assertEquals(0, updatedService2.getErrorStateTrigger());
    // 4th try, finished on localhost
    jobTry4.setStatus(Status.FINISHED);
    jobTry4.setJobType(regType1Localhost.getServiceType());
    jobTry4.setProcessingHost(regType1Localhost.getHost());
    jobTry4 = serviceRegistry.updateJob(jobTry4);
    updatedService1 = getUpdatedService(regType1Localhost);
    updatedService2 = getUpdatedService(regType1Remotehost1);
    updatedService3 = getUpdatedService(regType1Remotehost2);
    Assert.assertEquals(ServiceState.NORMAL, updatedService1.getServiceState());
    Assert.assertEquals(ServiceState.NORMAL, updatedService2.getServiceState());
    Assert.assertEquals(ServiceState.ERROR, updatedService3.getServiceState());
}
Also used : ServiceRegistrationJpaImpl(org.opencastproject.serviceregistry.impl.jpa.ServiceRegistrationJpaImpl) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Aggregations

Job (org.opencastproject.job.api.Job)282 MediaPackage (org.opencastproject.mediapackage.MediaPackage)89 ArrayList (java.util.ArrayList)82 Test (org.junit.Test)82 URI (java.net.URI)68 NotFoundException (org.opencastproject.util.NotFoundException)58 Track (org.opencastproject.mediapackage.Track)56 JaxbJob (org.opencastproject.job.api.JaxbJob)52 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)51 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)50 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)49 IOException (java.io.IOException)45 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)42 HttpPost (org.apache.http.client.methods.HttpPost)33 Path (javax.ws.rs.Path)31 Produces (javax.ws.rs.Produces)30 JobBarrier (org.opencastproject.job.api.JobBarrier)30 RestQuery (org.opencastproject.util.doc.rest.RestQuery)30 POST (javax.ws.rs.POST)29 HttpResponse (org.apache.http.HttpResponse)29