Search in sources :

Example 76 with Job

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

the class StreamingDistributionServiceTest method testDistribution.

@Test
public void testDistribution() throws Exception {
    // Distribute the mediapackage and all of its elements
    Job job1 = service.distribute("engage-player", mp, "track-1");
    Job job2 = service.distribute("oai-pmh", mp, "track-1");
    JobBarrier jobBarrier = new JobBarrier(null, serviceRegistry, 500, job1, job2);
    jobBarrier.waitForJobs();
    // Add the new elements to the mediapackage
    mp.add(MediaPackageElementParser.getFromXml(job1.getPayload()));
    mp.add(MediaPackageElementParser.getFromXml(job2.getPayload()));
    File mpDir = new File(distributionRoot, PathSupport.path(defaultOrganization.getId(), "engage-player", mp.getIdentifier().compact()));
    File mediaDir = new File(mpDir, "track-1");
    Assert.assertTrue(mediaDir.exists());
    // the filenames are changed to reflect the element ID
    Assert.assertTrue(new File(mediaDir, "media.mov").exists());
}
Also used : Job(org.opencastproject.job.api.Job) JobBarrier(org.opencastproject.job.api.JobBarrier) File(java.io.File) Test(org.junit.Test)

Example 77 with Job

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

the class StreamingDistributionRestService method distribute.

@POST
@Path("/")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "distribute", description = "Distribute a media package element to this distribution channel", returnDescription = "The job that can be used to track the distribution", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementIds", isRequired = true, description = "The elements to distribute as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the distribution job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response distribute(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementIds") String elementIds) throws Exception {
    Job job = null;
    try {
        Gson gson = new Gson();
        Set<String> setElementIds = gson.fromJson(elementIds, new TypeToken<Set<String>>() {
        }.getType());
        MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.distribute(channelId, mediapackage, setElementIds);
        if (job == null)
            return Response.noContent().build();
        return Response.ok(new JaxbJob(job)).build();
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to distribute element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Error distributing element", e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Gson(com.google.gson.Gson) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 78 with Job

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

the class StreamingDistributionRestService method retract.

@POST
@Path("/retract")
@Produces(MediaType.TEXT_XML)
@RestQuery(name = "retract", description = "Retract a media package element from this distribution channel", returnDescription = "The job that can be used to track the retraction", restParameters = { @RestParameter(name = "mediapackage", isRequired = true, description = "The mediapackage", type = Type.TEXT), @RestParameter(name = "channelId", isRequired = true, description = "The publication channel ID", type = Type.TEXT), @RestParameter(name = "elementIds", isRequired = true, description = "The elements to retract as Json Array['IdOne','IdTwo']", type = Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "An XML representation of the retraction job"), @RestResponse(responseCode = SC_NO_CONTENT, description = "There is no streaming distribution service available") })
public Response retract(@FormParam("mediapackage") String mediaPackageXml, @FormParam("channelId") String channelId, @FormParam("elementIds") String elementIds) throws Exception {
    Job job = null;
    try {
        Gson gson = new Gson();
        Set<String> setElementIds = gson.fromJson(elementIds, new TypeToken<Set<String>>() {
        }.getType());
        MediaPackage mediapackage = MediaPackageParser.getFromXml(mediaPackageXml);
        job = service.retract(channelId, mediapackage, setElementIds);
        if (job == null)
            return Response.noContent().build();
        return Response.ok(new JaxbJob(job)).build();
    } catch (IllegalArgumentException e) {
        logger.debug("Unable to retract element: {}", e.getMessage());
        return status(Status.BAD_REQUEST).build();
    } catch (Exception e) {
        logger.warn("Unable to retract mediapackage '{}' from streaming channel: {}", mediaPackageXml, e);
        return Response.serverError().status(Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) JaxbJob(org.opencastproject.job.api.JaxbJob) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Gson(com.google.gson.Gson) JaxbJob(org.opencastproject.job.api.JaxbJob) Job(org.opencastproject.job.api.Job) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 79 with Job

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

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

the class AwsS3DistributionServiceRemoteImpl method restore.

@Override
public Job restore(String channelId, MediaPackage mediaPackage, String elementId, String fileName) throws DistributionException {
    logger.info(format("Restoring %s from %s@%s", elementId, channelId, distributionChannel));
    final HttpPost req = post("/restore", param(PARAM_MEDIAPACKAGE, MediaPackageParser.getAsXml(mediaPackage)), param(PARAM_ELEMENT_ID, elementId), param(PARAM_CHANNEL_ID, channelId), param(PARAM_FILENAME, fileName));
    for (Job job : join(runRequest(req, jobFromHttpResponse))) {
        return job;
    }
    throw new DistributionException(format("Unable to restore element '%s' of " + "mediapackage '%s' using a remote destribution service proxy", elementId, mediaPackage.getIdentifier().toString()));
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) DistributionException(org.opencastproject.distribution.api.DistributionException) Job(org.opencastproject.job.api.Job)

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