Search in sources :

Example 31 with Job

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

the class CompositeWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = InspectWorkflowOperationHandler.class.getResource("/composite_mediapackage.xml").toURI();
    URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/compound_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
    encodedTracks = mpEncode.getTracks();
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMPEncode);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/watermark.jpg").toURI()));
    EasyMock.replay(workspace);
    // set up mock receipt
    job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(job.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job.getDateStarted()).andReturn(new Date());
    EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
    EasyMock.replay(job);
    // set up mock service registry
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.replay(serviceRegistry);
    // set up service
    operationHandler = new CompositeWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) URI(java.net.URI) File(java.io.File) InspectWorkflowOperationHandler(org.opencastproject.workflow.handler.inspection.InspectWorkflowOperationHandler) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 32 with Job

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

the class CompositeWorkflowOperationHandlerTest method testSingleVideoStream.

@Test
public void testSingleVideoStream() throws URISyntaxException, MalformedURLException, MediaPackageException, IOException, IllegalArgumentException, NotFoundException, ServiceRegistryException {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = InspectWorkflowOperationHandler.class.getResource("/composite_mediapackage.xml").toURI();
    URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/compound_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
    encodedTracks = mpEncode.getTracks();
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMPEncode);
    EasyMock.expect(workspace.get((URI) EasyMock.anyObject())).andReturn(new File(getClass().getResource("/watermark.jpg").toURI()));
    EasyMock.replay(workspace);
    // set up mock receipt
    job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(job.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job.getDateStarted()).andReturn(new Date());
    EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
    EasyMock.replay(job);
    // set up mock service registry
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.replay(serviceRegistry);
    // set up service
    operationHandler = new CompositeWorkflowOperationHandler();
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) URI(java.net.URI) File(java.io.File) InspectWorkflowOperationHandler(org.opencastproject.workflow.handler.inspection.InspectWorkflowOperationHandler) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Example 33 with Job

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

the class ImageToVideoWorkflowOperationHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    MediaPackageBuilder builder = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder();
    // test resources
    URI uriMP = InspectWorkflowOperationHandler.class.getResource("/imagetovideo_mediapackage.xml").toURI();
    URI uriMPEncode = InspectWorkflowOperationHandler.class.getResource("/imagetovideo_converted_mediapackage.xml").toURI();
    mp = builder.loadFromXml(uriMP.toURL().openStream());
    mpEncode = builder.loadFromXml(uriMPEncode.toURL().openStream());
    encodedTracks = mpEncode.getTracks();
    // set up mock workspace
    workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.moveTo((URI) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject(), (String) EasyMock.anyObject())).andReturn(uriMP);
    EasyMock.replay(workspace);
    // set up mock receipt
    job = EasyMock.createNiceMock(Job.class);
    EasyMock.expect(job.getPayload()).andReturn(MediaPackageElementParser.getAsXml(encodedTracks[0])).anyTimes();
    EasyMock.expect(job.getStatus()).andReturn(Job.Status.FINISHED);
    EasyMock.expect(job.getDateCreated()).andReturn(new Date());
    EasyMock.expect(job.getDateStarted()).andReturn(new Date());
    EasyMock.expect(job.getQueueTime()).andReturn(new Long(0));
    EasyMock.replay(job);
    // set up mock service registry
    ServiceRegistry serviceRegistry = EasyMock.createNiceMock(ServiceRegistry.class);
    EasyMock.expect(serviceRegistry.getJob(EasyMock.anyLong())).andReturn(job);
    EasyMock.replay(serviceRegistry);
    // set up service
    operationHandler = new ImageToVideoWorkflowOperationHandler();
    operationHandler.setJobBarrierPollingInterval(0);
    operationHandler.setWorkspace(workspace);
    operationHandler.setServiceRegistry(serviceRegistry);
}
Also used : MediaPackageBuilder(org.opencastproject.mediapackage.MediaPackageBuilder) ServiceRegistry(org.opencastproject.serviceregistry.api.ServiceRegistry) Job(org.opencastproject.job.api.Job) URI(java.net.URI) InspectWorkflowOperationHandler(org.opencastproject.workflow.handler.inspection.InspectWorkflowOperationHandler) Date(java.util.Date) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 34 with Job

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

the class ComposerServiceImpl method encode.

/**
 * Encodes audio and video track to a file. If both an audio and a video track are given, they are muxed together into
 * one movie container.
 *
 * @param tracks
 *          tracks to use for processing
 * @param profileId
 *          the encoding profile
 * @param properties
 *          encoding properties
 * @return the encoded track or none if the operation does not return a track. This may happen for example when doing
 *         two pass encodings where the first pass only creates metadata for the second one
 * @throws EncoderException
 *           if encoding fails
 */
private Option<Track> encode(final Job job, Map<String, Track> tracks, String profileId) throws EncoderException, MediaPackageException {
    final String targetTrackId = idBuilder.createNew().toString();
    Map<String, File> files = new HashMap<>();
    // Get the tracks and make sure they exist
    for (Entry<String, Track> track : tracks.entrySet()) {
        files.put(track.getKey(), loadTrackIntoWorkspace(job, track.getKey(), track.getValue()));
    }
    // Get the encoding profile
    final EncodingProfile profile = getProfile(job, profileId);
    List<String> trackMsg = new LinkedList<>();
    for (Entry<String, Track> track : tracks.entrySet()) {
        trackMsg.add(String.format("%s: %s", track.getKey(), track.getValue().getIdentifier()));
    }
    logger.info("Encoding {} into {} using profile {}", StringUtils.join(trackMsg, ", "), targetTrackId, profileId);
    // Do the work
    final EncoderEngine encoder = getEncoderEngine();
    List<File> output;
    try {
        output = encoder.process(files, profile, null);
    } catch (EncoderException e) {
        Map<String, String> params = new HashMap<>();
        for (Entry<String, Track> track : tracks.entrySet()) {
            params.put(track.getKey(), track.getValue().getIdentifier());
        }
        params.put("profile", profile.getIdentifier());
        params.put("properties", "EMPTY");
        incident().recordFailure(job, ENCODING_FAILED, e, params, detailsFor(e, encoder));
        throw e;
    } finally {
        activeEncoder.remove(encoder);
    }
    // We expect zero or one file as output
    if (output.size() == 0) {
        return none();
    } else if (output.size() != 1) {
        // Ensure we do not leave behind old files in the workspace
        for (File file : output) {
            FileUtils.deleteQuietly(file);
        }
        throw new EncoderException("Composite does not support multiple files as output");
    }
    // Put the file in the workspace
    URI workspaceURI = putToCollection(job, output.get(0), "encoded file");
    // Have the encoded track inspected and return the result
    Job inspectionJob = inspect(job, workspaceURI);
    Track inspectedTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
    inspectedTrack.setIdentifier(targetTrackId);
    if (profile.getMimeType() != null)
        inspectedTrack.setMimeType(MimeTypes.parseMimeType(profile.getMimeType()));
    return some(inspectedTrack);
}
Also used : HashMap(java.util.HashMap) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) URI(java.net.URI) LinkedList(java.util.LinkedList) EncoderException(org.opencastproject.composer.api.EncoderException) Entry(java.util.Map.Entry) Job(org.opencastproject.job.api.Job) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Track(org.opencastproject.mediapackage.Track)

Example 35 with Job

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

the class ComposerServiceImpl method concat.

private Option<Track> concat(Job job, List<Track> tracks, String profileId, Dimension outputDimension, float outputFrameRate) throws EncoderException, MediaPackageException {
    if (tracks.size() < 2) {
        Map<String, String> params = new HashMap<>();
        params.put("tracks-size", Integer.toString(tracks.size()));
        params.put("tracks", StringUtils.join(tracks, ","));
        incident().recordFailure(job, CONCAT_LESS_TRACKS, params);
        throw new EncoderException("The track parameter must at least have two tracks present");
    }
    boolean onlyAudio = true;
    for (Track t : tracks) {
        if (t.hasVideo()) {
            onlyAudio = false;
            break;
        }
    }
    if (!onlyAudio && outputDimension == null) {
        Map<String, String> params = new HashMap<>();
        params.put("tracks", StringUtils.join(tracks, ","));
        incident().recordFailure(job, CONCAT_NO_DIMENSION, params);
        throw new EncoderException("The output dimension id parameter must not be null when concatenating video");
    }
    final String targetTrackId = idBuilder.createNew().toString();
    // Get the tracks and make sure they exist
    List<File> trackFiles = new ArrayList<>();
    int i = 0;
    for (Track track : tracks) {
        if (!track.hasAudio() && !track.hasVideo()) {
            Map<String, String> params = new HashMap<>();
            params.put("track-id", track.getIdentifier());
            params.put("track-url", track.getURI().toString());
            incident().recordFailure(job, NO_STREAMS, params);
            throw new EncoderException("Track has no audio or video stream available: " + track);
        }
        trackFiles.add(i++, loadTrackIntoWorkspace(job, "concat", track));
    }
    // Create the engine
    final EncoderEngine encoderEngine = getEncoderEngine();
    if (onlyAudio) {
        logger.info("Concatenating audio tracks {} into {}", trackFiles, targetTrackId);
    } else {
        logger.info("Concatenating video tracks {} into {}", trackFiles, targetTrackId);
    }
    // Get the encoding profile
    EncodingProfile profile = getProfile(job, profileId);
    // Creating video filter command for concat
    final String concatCommand = buildConcatCommand(onlyAudio, outputDimension, outputFrameRate, trackFiles, tracks);
    Map<String, String> properties = new HashMap<>();
    properties.put(EncoderEngine.CMD_SUFFIX + ".concatCommand", concatCommand);
    File output;
    try {
        output = encoderEngine.encode(trackFiles.get(0), profile, properties);
    } catch (EncoderException e) {
        Map<String, String> params = new HashMap<>();
        List<String> trackList = new ArrayList<>();
        for (Track t : tracks) {
            trackList.add(t.getURI().toString());
        }
        params.put("tracks", StringUtils.join(trackList, ","));
        params.put("profile", profile.getIdentifier());
        params.put("properties", properties.toString());
        incident().recordFailure(job, CONCAT_FAILED, e, params, detailsFor(e, encoderEngine));
        throw e;
    } finally {
        activeEncoder.remove(encoderEngine);
    }
    // concat did not return a file
    if (!output.exists() || output.length() == 0)
        return none();
    // Put the file in the workspace
    URI workspaceURI = putToCollection(job, output, "concatenated file");
    // Have the concat track inspected and return the result
    Job inspectionJob = inspect(job, workspaceURI);
    Track inspectedTrack = (Track) MediaPackageElementParser.getFromXml(inspectionJob.getPayload());
    inspectedTrack.setIdentifier(targetTrackId);
    if (profile.getMimeType() != null)
        inspectedTrack.setMimeType(MimeTypes.parseMimeType(profile.getMimeType()));
    return some(inspectedTrack);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EncodingProfile(org.opencastproject.composer.api.EncodingProfile) URI(java.net.URI) EncoderException(org.opencastproject.composer.api.EncoderException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) Job(org.opencastproject.job.api.Job) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Track(org.opencastproject.mediapackage.Track)

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