use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class StreamingDistributionServiceImpl method distribute.
@Override
public Job distribute(String channelId, MediaPackage mediapackage, Set<String> elementIds) throws DistributionException, MediaPackageException {
notNull(mediapackage, "mediapackage");
notNull(elementIds, "elementIds");
notNull(channelId, "channelId");
try {
return serviceRegistry.createJob(JOB_TYPE, Operation.Distribute.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediapackage), gson.toJson(elementIds)), distributeJobLoad);
} catch (ServiceRegistryException e) {
throw new DistributionException("Unable to create a job", e);
}
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class StreamingDistributionServiceImpl method retract.
/**
* {@inheritDoc}
*
* @see org.opencastproject.distribution.api.DistributionService#retract(String,
* org.opencastproject.mediapackage.MediaPackage, String) java.lang.String)
*/
@Override
public Job retract(String channelId, MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException {
if (locations.isNone())
return null;
RequireUtil.notNull(mediaPackage, "mediaPackage");
RequireUtil.notNull(elementIds, "elementId");
RequireUtil.notNull(channelId, "channelId");
//
try {
return serviceRegistry.createJob(JOB_TYPE, Operation.Retract.toString(), Arrays.asList(channelId, MediaPackageParser.getAsXml(mediaPackage), gson.toJson(elementIds)), retractJobLoad);
} catch (ServiceRegistryException e) {
throw new DistributionException("Unable to create a job", e);
}
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class ConfigurablePublishWorkflowOperationHandler method distribute.
private Set<MediaPackageElement> distribute(Collection<MediaPackageElement> elements, MediaPackage mediapackage, String channelId, String mode, boolean checkAvailability) throws WorkflowOperationException {
Set<MediaPackageElement> result = new HashSet<>();
Set<String> bulkElementIds = new HashSet<>();
Set<String> singleElementIds = new HashSet<>();
for (MediaPackageElement element : elements) {
if (MODE_BULK.equals(mode) || (MODE_MIXED.equals(mode) && (element.getElementType() != MediaPackageElement.Type.Track))) {
bulkElementIds.add(element.getIdentifier());
} else {
singleElementIds.add(element.getIdentifier());
}
}
Set<Job> jobs = new HashSet<>();
if (bulkElementIds.size() > 0) {
logger.info("Start bulk publishing of {} elements of media package '{}' to publication channel '{}'", bulkElementIds.size(), mediapackage, channelId);
try {
Job job = distributionService.distribute(channelId, mediapackage, bulkElementIds, checkAvailability);
jobs.add(job);
} catch (DistributionException | MediaPackageException e) {
logger.error("Creating the distribution job for {} elements of media package '{}' failed: {}", bulkElementIds.size(), mediapackage, getStackTrace(e));
throw new WorkflowOperationException(e);
}
}
if (singleElementIds.size() > 0) {
logger.info("Start single publishing of {} elements of media package '{}' to publication channel '{}'", singleElementIds.size(), mediapackage, channelId);
for (String elementId : singleElementIds) {
try {
Job job = distributionService.distribute(channelId, mediapackage, elementId, checkAvailability);
jobs.add(job);
} catch (DistributionException | MediaPackageException e) {
logger.error("Creating the distribution job for element '{}' of media package '{}' failed: {}", elementId, mediapackage, getStackTrace(e));
throw new WorkflowOperationException(e);
}
}
}
if (jobs.size() > 0) {
if (!waitForStatus(jobs.toArray(new Job[jobs.size()])).isSuccess()) {
throw new WorkflowOperationException("At least one of the distribution jobs did not complete successfully");
}
for (Job job : jobs) {
try {
List<? extends MediaPackageElement> elems = MediaPackageElementParser.getArrayFromXml(job.getPayload());
result.addAll(elems);
} catch (MediaPackageException e) {
logger.error("Job '{}' returned payload ({}) that could not be parsed to media package elements: {}", job, job.getPayload(), ExceptionUtils.getStackTrace(e));
throw new WorkflowOperationException(e);
}
}
logger.info("Published {} elements of media package {} to publication channel {}", bulkElementIds.size() + singleElementIds.size(), mediapackage, channelId);
}
return result;
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class ConfigurableWorkflowOperationHandlerBase method retractPublicationElements.
/**
* Remove the {@link Publication}'s {@link MediaPackageElement}s from a given channel.
*
* @param channelId
* The channel to remove the {@link MediaPackageElement}s from.
* @param publication
* The {@link Publication} that is being removed.
* @param mp
* The {@link MediaPackage} that the {@link Publication} is part of.
* @return the number of {@link MediaPackageElement}s that have been retracted
* @throws WorkflowOperationException
* Thrown if unable to retract the {@link MediaPackageElement}s.
*/
private int retractPublicationElements(String channelId, Publication publication, MediaPackage mp) throws WorkflowOperationException {
assert ((channelId != null) && (publication != null) && (mp != null));
MediaPackage mediapackageWithPublicationElements = (MediaPackage) mp.clone();
// Add the publications to the mediapackage so that we can use the standard retract
addPublicationElementsToMediaPackage(publication, mediapackageWithPublicationElements);
Set<String> elementIds = new HashSet<>();
for (Attachment attachment : publication.getAttachments()) {
elementIds.add(attachment.getIdentifier());
}
for (Catalog catalog : publication.getCatalogs()) {
elementIds.add(catalog.getIdentifier());
}
for (Track track : publication.getTracks()) {
elementIds.add(track.getIdentifier());
}
if (elementIds.size() > 0) {
logger.info("Retracting {} elements of media package {} from publication channel {}", elementIds.size(), mp, channelId);
Job job = null;
try {
job = getDistributionService().retract(channelId, mediapackageWithPublicationElements, elementIds);
} catch (DistributionException e) {
logger.error("Error while retracting '{}' elements from channel '{}' of distribution '{}': {}", elementIds.size(), channelId, getDistributionService(), getStackTrace(e));
throw new WorkflowOperationException("The retraction job did not complete successfully");
}
if (!waitForStatus(job).isSuccess()) {
throw new WorkflowOperationException("The retraction job did not complete successfully");
}
} else {
logger.debug("No publication elements were found for retraction");
}
return elementIds.size();
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method getSmilDocument.
private Document getSmilDocument(File smilFile) throws DistributionException {
if (!smilFile.isFile()) {
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.newDocument();
Element smil = doc.createElement("smil");
doc.appendChild(smil);
Element head = doc.createElement("head");
smil.appendChild(head);
Element body = doc.createElement("body");
smil.appendChild(body);
Element switchElement = doc.createElement("switch");
body.appendChild(switchElement);
return doc;
} catch (ParserConfigurationException ex) {
logger.error("Could not create XML file for {}.", smilFile);
throw new DistributionException("Could not create XML file for " + smilFile);
}
}
try {
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(smilFile);
if (!"smil".equalsIgnoreCase(doc.getDocumentElement().getNodeName())) {
logger.error("XML-File {} is not a SMIL file.", smilFile);
throw new DistributionException(format("XML-File %s is not an SMIL file.", smilFile.getName()));
}
return doc;
} catch (IOException e) {
logger.error("Could not open SMIL file {}", smilFile);
throw new DistributionException(format("Could not open SMIL file %s", smilFile));
} catch (ParserConfigurationException e) {
logger.error("Could not parse SMIL file {}", smilFile);
throw new DistributionException(format("Could not parse SMIL file %s", smilFile));
} catch (SAXException e) {
logger.error("Could not parse XML file {}", smilFile);
throw new DistributionException(format("Could not parse XML file %s", smilFile));
}
}
Aggregations