Search in sources :

Example 6 with Status

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

the class ConfigurablePublishWorkflowOperationHandlerTest method testNormal.

@Test
public void testNormal() throws WorkflowOperationException, URISyntaxException, DistributionException, MediaPackageException {
    String channelId = "engage-player";
    String attachmentId = "attachment-id";
    String catalogId = "catalog-id";
    String trackId = "track-id";
    Attachment attachment = new AttachmentImpl();
    attachment.addTag("engage-download");
    attachment.setIdentifier(attachmentId);
    attachment.setURI(new URI("http://api.com/attachment"));
    Catalog catalog = CatalogImpl.newInstance();
    catalog.addTag("engage-download");
    catalog.setIdentifier(catalogId);
    catalog.setURI(new URI("http://api.com/catalog"));
    Track track = new TrackImpl();
    track.addTag("engage-streaming");
    track.setIdentifier(trackId);
    track.setURI(new URI("http://api.com/track"));
    Publication publicationtest = new PublicationImpl(trackId, channelId, new URI("http://api.com/publication"), MimeType.mimeType(trackId, trackId));
    Track unrelatedTrack = new TrackImpl();
    unrelatedTrack.addTag("unrelated");
    Capture<MediaPackageElement> capturePublication = Capture.newInstance();
    MediaPackage mediapackageClone = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mediapackageClone.getElements()).andStubReturn(new MediaPackageElement[] { attachment, catalog, track, unrelatedTrack });
    EasyMock.expect(mediapackageClone.getIdentifier()).andStubReturn(new IdImpl("mp-id-clone"));
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackageClone);
    MediaPackage mediapackage = EasyMock.createNiceMock(MediaPackage.class);
    EasyMock.expect(mediapackage.getElements()).andStubReturn(new MediaPackageElement[] { attachment, catalog, track, unrelatedTrack });
    EasyMock.expect(mediapackage.clone()).andStubReturn(mediapackageClone);
    EasyMock.expect(mediapackage.getIdentifier()).andStubReturn(new IdImpl("mp-id"));
    mediapackage.add(EasyMock.capture(capturePublication));
    mediapackage.add(publicationtest);
    EasyMock.expect(mediapackage.getPublications()).andStubReturn(new Publication[] { publicationtest });
    EasyMock.expectLastCall();
    EasyMock.replay(mediapackage);
    WorkflowOperationInstance op = EasyMock.createNiceMock(WorkflowOperationInstance.class);
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.CHANNEL_ID_KEY)).andStubReturn(channelId);
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.MIME_TYPE)).andStubReturn("text/html");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.URL_PATTERN)).andStubReturn("http://api.opencast.org/api/events/${event_id}");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.SOURCE_TAGS)).andStubReturn("engage-download,engage-streaming");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.CHECK_AVAILABILITY)).andStubReturn("true");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.STRATEGY)).andStubReturn("retract");
    EasyMock.expect(op.getConfiguration(ConfigurablePublishWorkflowOperationHandler.MODE)).andStubReturn("single");
    EasyMock.replay(op);
    WorkflowInstance workflowInstance = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andStubReturn(mediapackage);
    EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(op);
    EasyMock.replay(workflowInstance);
    JobContext jobContext = EasyMock.createNiceMock(JobContext.class);
    EasyMock.replay(jobContext);
    Job attachmentJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(attachmentJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(attachment));
    EasyMock.replay(attachmentJob);
    Job catalogJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(catalogJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(catalog));
    EasyMock.replay(catalogJob);
    Job trackJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(trackJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(track));
    EasyMock.replay(trackJob);
    Job retractJob = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(retractJob.getPayload()).andReturn(MediaPackageElementParser.getAsXml(track));
    EasyMock.replay(retractJob);
    DownloadDistributionService distributionService = EasyMock.createNiceMock(DownloadDistributionService.class);
    // Make sure that all of the elements are distributed.
    EasyMock.expect(distributionService.distribute(channelId, mediapackage, attachmentId, true)).andReturn(attachmentJob);
    EasyMock.expect(distributionService.distribute(channelId, mediapackage, catalogId, true)).andReturn(catalogJob);
    EasyMock.expect(distributionService.distribute(channelId, mediapackage, trackId, true)).andReturn(trackJob);
    EasyMock.expect(distributionService.retract(channelId, mediapackage, channelId)).andReturn(retractJob);
    EasyMock.replay(distributionService);
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getOrganization()).andStubReturn(org);
    EasyMock.replay(securityService);
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.replay(serviceRegistry);
    // Override the waitForStatus method to not block the jobs
    ConfigurablePublishWorkflowOperationHandler configurePublish = new ConfigurablePublishWorkflowOperationHandler() {

        @Override
        protected Result waitForStatus(long timeout, Job... jobs) {
            HashMap<Job, Status> map = Stream.mk(jobs).foldl(new HashMap<Job, Status>(), new Fn2<HashMap<Job, Status>, Job, HashMap<Job, Status>>() {

                @Override
                public HashMap<Job, Status> apply(HashMap<Job, Status> a, Job b) {
                    a.put(b, Status.FINISHED);
                    return a;
                }
            });
            return new Result(map);
        }
    };
    configurePublish.setDownloadDistributionService(distributionService);
    configurePublish.setSecurityService(securityService);
    configurePublish.setServiceRegistry(serviceRegistry);
    WorkflowOperationResult result = configurePublish.start(workflowInstance, jobContext);
    assertNotNull(result.getMediaPackage());
    assertTrue("The publication element has not been added to the mediapackage.", capturePublication.hasCaptured());
    assertTrue("Some other type of element has been added to the mediapackage instead of the publication element.", capturePublication.getValue().getElementType().equals(MediaPackageElement.Type.Publication));
    Publication publication = (Publication) capturePublication.getValue();
    assertEquals(1, publication.getAttachments().length);
    assertNotEquals(attachment.getIdentifier(), publication.getAttachments()[0].getIdentifier());
    attachment.setIdentifier(publication.getAttachments()[0].getIdentifier());
    assertEquals(attachment, publication.getAttachments()[0]);
    assertEquals(1, publication.getCatalogs().length);
    assertNotEquals(catalog.getIdentifier(), publication.getCatalogs()[0].getIdentifier());
    catalog.setIdentifier(publication.getCatalogs()[0].getIdentifier());
    assertEquals(catalog, publication.getCatalogs()[0]);
    assertEquals(1, publication.getTracks().length);
    assertNotEquals(track.getIdentifier(), publication.getTracks()[0].getIdentifier());
    track.setIdentifier(publication.getTracks()[0].getIdentifier());
    assertEquals(track, publication.getTracks()[0]);
}
Also used : HashMap(java.util.HashMap) TrackImpl(org.opencastproject.mediapackage.track.TrackImpl) Attachment(org.opencastproject.mediapackage.Attachment) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) Result(org.opencastproject.job.api.JobBarrier.Result) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) SecurityService(org.opencastproject.security.api.SecurityService) JobContext(org.opencastproject.job.api.JobContext) Job(org.opencastproject.job.api.Job) Status(org.opencastproject.job.api.Job.Status) Publication(org.opencastproject.mediapackage.Publication) Catalog(org.opencastproject.mediapackage.Catalog) DownloadDistributionService(org.opencastproject.distribution.api.DownloadDistributionService) PublicationImpl(org.opencastproject.mediapackage.PublicationImpl) MediaPackage(org.opencastproject.mediapackage.MediaPackage) AttachmentImpl(org.opencastproject.mediapackage.attachment.AttachmentImpl) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Track(org.opencastproject.mediapackage.Track) Test(org.junit.Test)

Example 7 with Status

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

the class JobsStatistics method updateJobCount.

public void updateJobCount(List<Object[]> perHostServiceCount) {
    jobCounts.clear();
    for (Object[] result : perHostServiceCount) {
        Status status = Status.values()[((Number) result[2]).intValue()];
        jobCounts.put(Tuple3.tuple3((String) result[0], (String) result[1], status), (Long) result[3]);
    }
    sendNotification(JmxUtil.createUpdateNotification(this, sequenceNumber++, "Job updated"));
}
Also used : Status(org.opencastproject.job.api.Job.Status)

Example 8 with Status

use of org.opencastproject.job.api.Job.Status 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 9 with Status

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

the class ServiceRegistryJpaImpl method getJobsByStatus.

/**
 * Get the list of jobs with status from the given statuses.
 *
 * @param em
 *          the entity manager
 * @param statuses
 *          variable sized array of status values to test on jobs
 * @return list of jobs with status from statuses
 * @throws ServiceRegistryException
 *           if there is a problem communicating with the jobs database
 */
public List<JpaJob> getJobsByStatus(EntityManager em, Status... statuses) throws ServiceRegistryException {
    if (statuses == null || statuses.length < 1)
        throw new IllegalArgumentException("At least one job status must be given.");
    List<Integer> ordinalStatuses = new ArrayList<>();
    for (Status status : statuses) {
        ordinalStatuses.add(status.ordinal());
    }
    TypedQuery<JpaJob> query = null;
    try {
        query = em.createNamedQuery("Job.statuses", JpaJob.class);
        query.setParameter("statuses", ordinalStatuses);
        List<JpaJob> jpaJobs = query.getResultList();
        for (JpaJob jpaJob : jpaJobs) {
            setJobUri(jpaJob);
        }
        return jpaJobs;
    } catch (Exception e) {
        throw new ServiceRegistryException(e);
    }
}
Also used : HttpStatus(org.apache.http.HttpStatus) Status(org.opencastproject.job.api.Job.Status) ArrayList(java.util.ArrayList) 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)

Example 10 with Status

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

the class ExecuteOnceWorkflowOperationHandlerTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    // Mocking just about everything, just testing the mediapackage parse
    String expectedTypeString = "catalog";
    String catalogId = "catalog-id";
    URI catUri = new URI("http://api.com/catalog");
    catalog = CatalogImpl.newInstance();
    catalog.addTag("engage-download");
    catalog.setIdentifier(catalogId);
    catalog.setURI(catUri);
    WorkflowOperationInstance operation = EasyMock.createMock(WorkflowOperationInstance.class);
    EasyMock.expect(operation.getId()).andReturn(123L).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXEC_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.PARAMS_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.LOAD_PROPERTY)).andReturn("123").anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_FLAVOR_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.TARGET_TAGS_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.OUTPUT_FILENAME_PROPERTY)).andReturn(null).anyTimes();
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.SET_WF_PROPS_PROPERTY)).andReturn("false").anyTimes();
    // these two need to supply a real string
    EasyMock.expect(operation.getConfiguration(ExecuteOnceWorkflowOperationHandler.EXPECTED_TYPE_PROPERTY)).andReturn(expectedTypeString).anyTimes();
    EasyMock.replay(operation);
    Id mpId = EasyMock.createMock(Id.class);
    MediaPackage mediaPackage = EasyMock.createMock(MediaPackage.class);
    mediaPackage.add((MediaPackageElement) EasyMock.anyObject());
    EasyMock.expect(mediaPackage.getIdentifier()).andReturn(mpId).anyTimes();
    EasyMock.replay(mediaPackage);
    workspaceService = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspaceService.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(catUri).anyTimes();
    EasyMock.replay(workspaceService);
    workflowInstance = EasyMock.createMock(WorkflowInstance.class);
    EasyMock.expect(workflowInstance.getMediaPackage()).andReturn(mediaPackage).anyTimes();
    EasyMock.expect(workflowInstance.getCurrentOperation()).andStubReturn(operation);
    EasyMock.replay(workflowInstance);
    // Override the waitForStatus method to not block the jobs
    execOnceWOH = new ExecuteOnceWorkflowOperationHandler() {

        @Override
        protected Result waitForStatus(long timeout, Job... jobs) {
            HashMap<Job, Status> map = Stream.mk(jobs).foldl(new HashMap<Job, Status>(), new Fn2<HashMap<Job, Status>, Job, HashMap<Job, Status>>() {

                @Override
                public HashMap<Job, Status> apply(HashMap<Job, Status> a, Job b) {
                    a.put(b, Status.FINISHED);
                    return a;
                }
            });
            return new Result(map);
        }
    };
    execOnceWOH.setWorkspace(workspaceService);
}
Also used : Status(org.opencastproject.job.api.Job.Status) HashMap(java.util.HashMap) Fn2(com.entwinemedia.fn.Fn2) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) Result(org.opencastproject.job.api.JobBarrier.Result) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Id(org.opencastproject.mediapackage.identifier.Id) Job(org.opencastproject.job.api.Job) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Aggregations

Status (org.opencastproject.job.api.Job.Status)13 Job (org.opencastproject.job.api.Job)8 ArrayList (java.util.ArrayList)6 HttpStatus (org.apache.http.HttpStatus)6 URISyntaxException (java.net.URISyntaxException)4 HashMap (java.util.HashMap)4 NoResultException (javax.persistence.NoResultException)4 PersistenceException (javax.persistence.PersistenceException)4 RollbackException (javax.persistence.RollbackException)4 JpaJob (org.opencastproject.job.jpa.JpaJob)4 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)4 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)4 NotFoundException (org.opencastproject.util.NotFoundException)4 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)4 ConfigurationException (org.osgi.service.cm.ConfigurationException)4 Date (java.util.Date)3 LinkedList (java.util.LinkedList)3 List (java.util.List)3 Test (org.junit.Test)3 JaxbJob (org.opencastproject.job.api.JaxbJob)3