Search in sources :

Example 36 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class AwsS3DistributionServiceImpl method distributeElements.

/**
 * Distribute Mediapackage elements to the download distribution service.
 *
 * @param channelId
 *          # The id of the publication channel to be distributed to.
 * @param mediapackage
 *          The media package that contains the elements to be distributed.
 * @param elementIds
 *          The ids of the elements that should be distributed contained within the media package.
 * @param checkAvailability
 *          Check the availability of the distributed element via http.
 * @return A reference to the MediaPackageElements that have been distributed.
 * @throws DistributionException
 *           Thrown if the parent directory of the MediaPackageElement cannot be created, if the MediaPackageElement
 *           cannot be copied or another unexpected exception occurs.
 */
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability) throws DistributionException {
    notNull(mediapackage, "mediapackage");
    notNull(elementIds, "elementIds");
    notNull(channelId, "channelId");
    final Set<MediaPackageElement> elements = getElements(mediapackage, elementIds);
    List<MediaPackageElement> distributedElements = new ArrayList<>();
    for (MediaPackageElement element : elements) {
        MediaPackageElement distributedElement = distributeElement(channelId, mediapackage, element, checkAvailability);
        distributedElements.add(distributedElement);
    }
    return distributedElements.toArray(new MediaPackageElement[distributedElements.size()]);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList)

Example 37 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class AwsS3DistributionServiceImplTest method testGetDistributedObjectName.

@Test
public void testGetDistributedObjectName() {
    MediaPackageElement element = distributedMp.getElementById("presenter-delivery-distributed");
    Assert.assertEquals("channelId/efd6e4df-63b6-49af-be5f-15f598778877/presenter-delivery/video-presenter-delivery.mp4", service.getDistributedObjectName(element));
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Test(org.junit.Test)

Example 38 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class AwsS3DistributionServiceImplTest method testDistributeElement.

@Test
public void testDistributeElement() throws Exception {
    Upload upload = EasyMock.createNiceMock(Upload.class);
    EasyMock.expect(tm.upload(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class), EasyMock.anyObject(File.class))).andReturn(upload);
    EasyMock.replay(upload, tm);
    Set<String> mpeIds = new LinkedHashSet<String>();
    mpeIds.add("presenter-delivery");
    MediaPackageElement[] mpes = service.distributeElements("channelId", mp, mpeIds, false);
    MediaPackageElement mpe = mpes[0];
    Assert.assertEquals(new URI("http://XYZ.cloudfront.net/channelId/efd6e4df-63b6-49af-be5f-15f598778877/presenter-delivery/video-presenter-delivery.mp4"), mpe.getURI());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) Upload(com.amazonaws.services.s3.transfer.Upload) File(java.io.File) URI(java.net.URI) Test(org.junit.Test)

Example 39 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class DownloadDistributionServiceImpl method distributeElements.

/**
 * Distribute Mediapackage elements to the download distribution service.
 *
 * @param channelId
 *   #          The id of the publication channel to be distributed to.
 * @param mediapackage
 *          The media package that contains the elements to be distributed.
 * @param elementIds
 *          The ids of the elements that should be distributed contained within the media package.
 * @param checkAvailability
 *          Check the availability of the distributed element via http.
 * @param preserveReference
 *          copy actual Reference to the new distributed element
 * @return A reference to the MediaPackageElements that have been distributed.
 * @throws DistributionException
 *           Thrown if the parent directory of the MediaPackageElement cannot be created, if the MediaPackageElement
 *           cannot be copied or another unexpected exception occurs.
 */
public MediaPackageElement[] distributeElements(String channelId, MediaPackage mediapackage, Set<String> elementIds, boolean checkAvailability, boolean preserveReference) throws DistributionException {
    notNull(mediapackage, "mediapackage");
    notNull(elementIds, "elementIds");
    notNull(channelId, "channelId");
    final Set<MediaPackageElement> elements = getElements(mediapackage, elementIds);
    List<MediaPackageElement> distributedElements = new ArrayList<MediaPackageElement>();
    for (MediaPackageElement element : elements) {
        MediaPackageElement distributedElement = distributeElement(channelId, mediapackage, element, checkAvailability, preserveReference);
        distributedElements.add(distributedElement);
    }
    return distributedElements.toArray(new MediaPackageElement[distributedElements.size()]);
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) ArrayList(java.util.ArrayList)

Example 40 with MediaPackageElement

use of org.opencastproject.mediapackage.MediaPackageElement in project opencast by opencast.

the class DownloadDistributionServiceImpl method process.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.job.api.AbstractJobProducer#process(org.opencastproject.job.api.Job)
 */
@Override
protected String process(Job job) throws Exception {
    Operation op = null;
    String operation = job.getOperation();
    List<String> arguments = job.getArguments();
    try {
        op = Operation.valueOf(operation);
        String channelId = arguments.get(0);
        MediaPackage mediapackage = MediaPackageParser.getFromXml(arguments.get(1));
        Set<String> elementIds = gson.fromJson(arguments.get(2), new TypeToken<Set<String>>() {
        }.getType());
        switch(op) {
            case Distribute:
                Boolean checkAvailability = Boolean.parseBoolean(arguments.get(3));
                Boolean preserveReference = Boolean.parseBoolean(arguments.get(4));
                MediaPackageElement[] distributedElements = distributeElements(channelId, mediapackage, elementIds, checkAvailability, preserveReference);
                return (distributedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(distributedElements)) : null;
            case Retract:
                MediaPackageElement[] retractedElements = retractElements(channelId, mediapackage, elementIds);
                return (retractedElements != null) ? MediaPackageElementParser.getArrayAsXml(Arrays.asList(retractedElements)) : null;
            default:
                throw new IllegalStateException("Don't know how to handle operation '" + operation + "'");
        }
    } catch (IllegalArgumentException e) {
        throw new ServiceRegistryException("This service can't handle operations of type '" + op + "'", e);
    } catch (IndexOutOfBoundsException e) {
        throw new ServiceRegistryException("This argument list for operation '" + op + "' does not meet expectations", e);
    } catch (Exception e) {
        throw new ServiceRegistryException("Error handling operation '" + op + "'", e);
    }
}
Also used : ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(org.osgi.service.cm.ConfigurationException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) DistributionException(org.opencastproject.distribution.api.DistributionException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) TypeToken(com.google.gson.reflect.TypeToken) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage)

Aggregations

MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)153 MediaPackage (org.opencastproject.mediapackage.MediaPackage)72 NotFoundException (org.opencastproject.util.NotFoundException)50 Job (org.opencastproject.job.api.Job)49 URI (java.net.URI)48 IOException (java.io.IOException)39 ArrayList (java.util.ArrayList)39 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)39 Test (org.junit.Test)36 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)27 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)25 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)24 File (java.io.File)21 Track (org.opencastproject.mediapackage.Track)21 DistributionException (org.opencastproject.distribution.api.DistributionException)20 InputStream (java.io.InputStream)19 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)19 HashSet (java.util.HashSet)18 URISyntaxException (java.net.URISyntaxException)16 Path (javax.ws.rs.Path)16