Search in sources :

Example 91 with Job

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

the class JobTest method testGetHostsCount.

@Test
public void testGetHostsCount() throws Exception {
    Job localRunning1 = serviceRegistry.createJob(JOB_TYPE_1, OPERATION_NAME, null, null, false);
    localRunning1.setStatus(Status.RUNNING);
    localRunning1.setJobType(regType1Localhost.getServiceType());
    localRunning1.setProcessingHost(regType1Localhost.getHost());
    localRunning1 = serviceRegistry.updateJob(localRunning1);
    Job localRunning2 = serviceRegistry.createJob(JOB_TYPE_1, OPERATION_NAME, null, null, false);
    localRunning2.setStatus(Status.RUNNING);
    localRunning2.setJobType(regType1Localhost.getServiceType());
    localRunning2.setProcessingHost(regType1Localhost.getHost());
    localRunning2 = serviceRegistry.updateJob(localRunning2);
    Job localFinished = serviceRegistry.createJob(JOB_TYPE_1, OPERATION_NAME, null, null, false);
    // Simulate starting the job
    localFinished.setStatus(Status.RUNNING);
    localFinished.setJobType(regType1Localhost.getServiceType());
    localFinished.setProcessingHost(regType1Localhost.getHost());
    localFinished = serviceRegistry.updateJob(localFinished);
    // Finish the job
    localFinished = serviceRegistry.getJob(localFinished.getId());
    localFinished.setStatus(Status.FINISHED);
    localFinished = serviceRegistry.updateJob(localFinished);
    Job remoteRunning = serviceRegistry.createJob(regType1Remotehost.getHost(), regType1Remotehost.getServiceType(), OPERATION_NAME, null, null, false, null);
    remoteRunning.setStatus(Status.RUNNING);
    remoteRunning.setJobType(regType1Remotehost.getServiceType());
    remoteRunning.setProcessingHost(regType1Remotehost.getHost());
    remoteRunning = serviceRegistry.updateJob(remoteRunning);
    Job remoteFinished = serviceRegistry.createJob(regType1Remotehost.getHost(), regType1Remotehost.getServiceType(), OPERATION_NAME, null, null, false, null);
    // Simulate starting the job
    remoteFinished.setStatus(Status.RUNNING);
    remoteFinished.setJobType(regType1Remotehost.getServiceType());
    remoteFinished.setProcessingHost(regType1Remotehost.getHost());
    remoteFinished = serviceRegistry.updateJob(remoteFinished);
    // Finish the job
    remoteFinished = serviceRegistry.getJob(remoteFinished.getId());
    remoteFinished.setStatus(Status.FINISHED);
    remoteFinished = serviceRegistry.updateJob(remoteFinished);
    Job otherTypeRunning = serviceRegistry.createJob(JOB_TYPE_2, OPERATION_NAME, null, null, false);
    otherTypeRunning.setStatus(Status.RUNNING);
    otherTypeRunning.setJobType(regType2Localhost.getServiceType());
    otherTypeRunning.setProcessingHost(regType2Localhost.getHost());
    otherTypeRunning = serviceRegistry.updateJob(otherTypeRunning);
    Job otherTypeFinished = serviceRegistry.createJob(JOB_TYPE_2, OPERATION_NAME, null, null, false);
    // Simulate starting the job
    otherTypeFinished.setStatus(Status.RUNNING);
    otherTypeFinished.setJobType(regType2Localhost.getServiceType());
    otherTypeFinished.setProcessingHost(regType2Localhost.getHost());
    otherTypeFinished = serviceRegistry.updateJob(otherTypeFinished);
    // Finish the job
    otherTypeFinished = serviceRegistry.getJob(otherTypeFinished.getId());
    otherTypeFinished.setStatus(Status.FINISHED);
    otherTypeFinished = serviceRegistry.updateJob(otherTypeFinished);
    List<ServiceRegistration> type1Hosts = serviceRegistry.getServiceRegistrationsByLoad(JOB_TYPE_1);
    List<ServiceRegistration> type2Hosts = serviceRegistry.getServiceRegistrationsByLoad(JOB_TYPE_2);
    // The number of service registrations is equal on both hosts
    assertEquals(2, type1Hosts.size());
    assertEquals(2, type2Hosts.size());
    // Count the number of jobs that are runnging
    assertEquals(3, serviceRegistry.count(JOB_TYPE_1, Status.RUNNING));
    assertEquals(1, serviceRegistry.count(JOB_TYPE_2, Status.RUNNING));
    // Localhost has more jobs running than remotehost
    assertEquals(REMOTEHOST, type1Hosts.get(0).getHost());
    assertEquals(LOCALHOST, type1Hosts.get(1).getHost());
    assertEquals(REMOTEHOST, type2Hosts.get(0).getHost());
    assertEquals(LOCALHOST, type2Hosts.get(1).getHost());
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) ServiceRegistration(org.opencastproject.serviceregistry.api.ServiceRegistration) Test(org.junit.Test)

Example 92 with Job

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

the class JobTest method testJobsQueuedOnServiceUnregistration.

@Test
public void testJobsQueuedOnServiceUnregistration() throws Exception {
    // Create a job
    Job job = serviceRegistry.createJob(JOB_TYPE_1, "some operation", null, null, false, 1.0f);
    // Set its status to running on a localhost
    job.setStatus(Status.RUNNING);
    job.setDispatchable(true);
    job.setJobType(regType1Localhost.getServiceType());
    job.setProcessingHost(regType1Localhost.getHost());
    job = serviceRegistry.updateJob(job);
    // Ensure that we get the job back from the service in its running state
    assertEquals("Job should be running", Status.RUNNING, serviceRegistry.getJob(job.getId()).getStatus());
    // Now unregister regType1Host1, and the job should go back to queued
    serviceRegistry.unRegisterService(regType1Localhost.getServiceType(), regType1Localhost.getHost());
    // Ensure that the job is queued now
    assertEquals("Job should be queued", Status.RESTART, serviceRegistry.getJob(job.getId()).getStatus());
    Assert.assertNull("Job's processing service should be null", serviceRegistry.getJob(job.getId()).getProcessingHost());
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 93 with Job

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

the class JobTest method testOptimisticLocking.

@Test
public void testOptimisticLocking() throws Exception {
    // Disable job dispatching by setting both hosts to be in maintenance mode
    serviceRegistry.setMaintenanceStatus(LOCALHOST, true);
    serviceRegistry.setMaintenanceStatus(REMOTEHOST, true);
    // Create a job
    String arg1 = "arg1";
    String arg2 = "<some>xml</some>";
    Job job = serviceRegistry.createJob(JOB_TYPE_1, "some_operation", Arrays.asList(arg1, arg2), null, false);
    // Grab another reference to this job
    Job jobFromDb = serviceRegistry.getJob(job.getId());
    // Modify the job and save it
    job.setPayload("something produced by this client");
    job = serviceRegistry.updateJob(job);
    job = serviceRegistry.getJob(job.getId());
    // Ensure that the job version is higher than the snapshot we loaded from the database
    assertTrue("Version not incremented", job.getVersion() > jobFromDb.getVersion());
    // Try to modify and save the outdated reference
    try {
        jobFromDb = serviceRegistry.updateJob(jobFromDb);
        Assert.fail();
    } catch (Exception e) {
    // do nothinng
    }
}
Also used : 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 94 with Job

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

the class JobTest method testHostUnregistration.

@Test
public void testHostUnregistration() throws Exception {
    // Create a job
    Job job = serviceRegistry.createJob(JOB_TYPE_1, "some operation", null, null, false);
    // Set its status to running on a localhost
    job.setStatus(Status.RUNNING);
    job.setDispatchable(true);
    job.setJobType(regType1Localhost.getServiceType());
    job.setProcessingHost(regType1Localhost.getHost());
    job = serviceRegistry.updateJob(job);
    // Unregister the host that's running the service responsible for this job
    serviceRegistry.unregisterHost(LOCALHOST);
    // Ensure that the job is once again queued, so it can be dispatched to a server ready to accept it
    assertEquals("Job should be queued", Status.RESTART, serviceRegistry.getJob(job.getId()).getStatus());
    Assert.assertNull("Job should have no associated processor", serviceRegistry.getJob(job.getId()).getProcessingHost());
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Test(org.junit.Test)

Example 95 with Job

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

the class JobTest method testGetJob.

@Test
public void testGetJob() throws Exception {
    // Start a job, but don't allow it to be dispatched
    Job job = serviceRegistry.createJob(JOB_TYPE_1, OPERATION_NAME, null, null, false, 4.0f);
    Assert.assertNotNull(job.getUri());
    Job jobFromDb = serviceRegistry.getJob(job.getId());
    assertEquals(Status.INSTANTIATED, jobFromDb.getStatus());
    assertEquals(new Float(4.0f), job.getJobLoad());
    // Simulate starting the job
    job.setStatus(Status.RUNNING);
    job = serviceRegistry.updateJob(job);
    // Finish the job
    job = serviceRegistry.getJob(job.getId());
    Track t = (Track) MediaPackageElementBuilderFactory.newInstance().newElementBuilder().elementFromURI(new URI("file://test.mov"), Track.TYPE, MediaPackageElements.PRESENTATION_SOURCE);
    t.setIdentifier("track-1");
    job.setPayload(MediaPackageElementParser.getAsXml(t));
    job.setStatus(Status.FINISHED);
    job = serviceRegistry.updateJob(job);
    jobFromDb = serviceRegistry.getJob(job.getId());
    Assert.assertNotNull(jobFromDb.getUri());
    assertEquals(job.getPayload(), jobFromDb.getPayload());
}
Also used : JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) Track(org.opencastproject.mediapackage.Track) 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