use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class SeriesUpdatedEventHandler method handleEvent.
public void handleEvent(final SeriesItem seriesItem) {
// A series or its ACL has been updated. Find any mediapackages with that series, and update them.
logger.debug("Handling {}", seriesItem);
String seriesId = seriesItem.getSeriesId();
// We must be an administrative user to make this query
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
SearchQuery q = new SearchQuery().withSeriesId(seriesId);
SearchResult result = searchService.getForAdministrativeRead(q);
for (SearchResultItem item : result.getItems()) {
MediaPackage mp = item.getMediaPackage();
Organization org = organizationDirectoryService.getOrganization(item.getOrganization());
securityService.setOrganization(org);
// to the distribution channels as well
if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
// Build a new XACML file for this mediapackage
Attachment fileRepoCopy = authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl()).getB();
// Distribute the updated XACML file
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, fileRepoCopy.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(fileRepoCopy);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute XACML {}", fileRepoCopy.getIdentifier());
continue;
}
}
// Update the series dublin core
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
// Update the series dublin core
Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
if (seriesCatalogs.length == 1) {
Catalog c = seriesCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
// Distribute the updated series dc
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, c.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(c);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute series catalog {}", c.getIdentifier());
continue;
}
}
}
// Remove the series catalog and isPartOf from episode catalog
if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
mp.setSeries(null);
mp.setSeriesTitle(null);
boolean retractSeriesCatalog = retractSeriesCatalog(mp);
boolean updateEpisodeCatalog = updateEpisodeCatalog(mp);
if (!retractSeriesCatalog || !updateEpisodeCatalog)
continue;
}
// Update the search index with the modified mediapackage
Job searchJob = searchService.add(mp);
JobBarrier barrier = new JobBarrier(null, serviceRegistry, searchJob);
barrier.waitForJobs();
}
} catch (SearchException e) {
logger.warn("Unable to find mediapackages in search: ", e.getMessage());
} catch (UnauthorizedException e) {
logger.warn(e.getMessage());
} catch (MediaPackageException e) {
logger.warn(e.getMessage());
} catch (ServiceRegistryException e) {
logger.warn(e.getMessage());
} catch (NotFoundException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.warn(e.getMessage());
} catch (DistributionException e) {
logger.warn(e.getMessage());
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method retract.
/**
* {@inheritDoc}
*
* @see org.opencastproject.distribution.api.StreamingDistributionService#retract(java.lang.String,
* org.opencastproject.mediapackage.MediaPackage, java.util.Set)
*/
@Override
public Job retract(String channelId, MediaPackage mediaPackage, Set<String> elementIds) throws DistributionException {
RequireUtil.notNull(mediaPackage, "mediaPackage");
RequireUtil.notNull(elementIds, "elementIds");
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 WowzaAdaptiveStreamingDistributionService method saveSmilFile.
private void saveSmilFile(File smilFile, Document doc) throws DistributionException {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult stream = new StreamResult(smilFile);
transformer.transform(source, stream);
logger.info("SMIL file for Wowza server saved at {}", smilFile);
} catch (TransformerConfigurationException ex) {
logger.error("Could not write SMIL file {} for distribution", smilFile);
throw new DistributionException(format("Could not write SMIL file %s for distribution", smilFile));
} catch (TransformerException ex) {
logger.error("Could not write SMIL file {} for distribution", smilFile);
throw new DistributionException(format("Could not write SMIL file %s for distribution", smilFile));
}
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class WowzaAdaptiveStreamingDistributionService method retractElement.
/**
* Retracts the mediapackage with the given identifier from the distribution channel.
*
* @param channelId
* the channel id
* @param mediapackage
* the mediapackage
* @param elementId
* the element identifier
* @return the retracted element or <code>null</code> if the element was not retracted
*/
protected MediaPackageElement[] retractElement(String channelId, final MediaPackage mediapackage, String elementId) throws DistributionException {
notNull(mediapackage, "mediapackage");
notNull(elementId, "elementId");
notNull(channelId, "channelId");
// Make sure the element exists
final MediaPackageElement element = mediapackage.getElementById(elementId);
if (element == null)
throw new IllegalStateException("No element " + elementId + " found in mediapackage" + mediapackage.getIdentifier());
logger.debug("Start element retraction for element \"{}\" with URI {}", elementId, element.getURI());
ArrayList<MediaPackageElement> retractedElements = new ArrayList<MediaPackageElement>();
// Has this element been distributed?
if (element == null || (!(element instanceof TrackImpl)))
return null;
try {
// Get the distribution path on the disk for this mediapackage element
File elementFile = getDistributionFile(channelId, mediapackage, element);
final File smilFile = getSmilFile(element, mediapackage, channelId);
logger.debug("delete elementFile {}", elementFile);
// or has been removed otherwise
if (elementFile == null || !elementFile.exists()) {
logger.warn("Deleting element file: File does not exist. Perhaps was it already deleted?: {}", elementFile);
retractedElements.add(element);
return retractedElements.toArray(new MediaPackageElement[0]);
} else {
// If a SMIL file is referenced by this element, delete first all the elements within
if (elementFile.equals(smilFile)) {
Document smilXml = getSmilDocument(smilFile);
NodeList videoList = smilXml.getElementsByTagName("video");
for (int i = 0; i < videoList.getLength(); i++) {
if (videoList.item(i) instanceof Element) {
String smilPathStr = ((Element) videoList.item(i)).getAttribute("src");
// Patch the streaming tags
if (smilPathStr.contains("mp4:"))
smilPathStr = smilPathStr.replace("mp4:", "");
if (!smilPathStr.endsWith(".mp4"))
smilPathStr += ".mp4";
elementFile = smilFile.toPath().resolveSibling(smilPathStr).toFile();
deleteElementFile(elementFile);
}
}
if (smilFile.isFile() && !smilFile.delete()) {
logger.warn("The SMIL file {} could not be succesfully deleted. Forcing quite deletion...");
}
} else {
deleteElementFile(elementFile);
}
}
logger.info("Finished rectracting element {} of media package {}", elementId, mediapackage);
retractedElements.add(element);
return retractedElements.toArray(new MediaPackageElement[0]);
} catch (Exception e) {
logger.warn("Error retracting element " + elementId + " of mediapackage " + mediapackage, e);
if (e instanceof DistributionException) {
throw (DistributionException) e;
} else {
throw new DistributionException(e);
}
}
}
use of org.opencastproject.distribution.api.DistributionException in project opencast by opencast.
the class AwsS3DistributionServiceImpl method retractElement.
/**
* Retracts the media package element with the given identifier from the distribution channel.
*
* @param channelId
* the channel id
* @param mediaPackage
* the media package
* @param element
* the element
* @return the retracted element or <code>null</code> if the element was not retracted
*/
protected MediaPackageElement retractElement(String channelId, MediaPackage mediaPackage, MediaPackageElement element) throws DistributionException {
notNull(mediaPackage, "mediaPackage");
notNull(element, "element");
try {
String objectName = getDistributedObjectName(element);
if (objectName != null) {
s3.deleteObject(bucketName, objectName);
logger.info("Retracted element {}, object {}", element.getIdentifier(), objectName);
}
return element;
} catch (AmazonClientException e) {
throw new DistributionException("AWS error: " + e.getMessage(), e);
}
}
Aggregations