Search in sources :

Example 1 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class IngestServiceImpl method addCatalog.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addCatalog(java.io.InputStream, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addCatalog(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_CATALOG, null, null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding catalog {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        if (MediaPackageElements.SERIES.equals(flavor)) {
            updateSeries(newUrl);
        }
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Catalog, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getCatalog(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added catalog {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 2 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class IngestServiceImpl method addTrack.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addTrack(java.net.URI,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, String[] ,
 *      org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addTrack(URI uri, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK_FROM_URI, Arrays.asList(uri.toString(), flavor == null ? null : flavor.toString(), MediaPackageParser.getAsXml(mediaPackage)), null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding track {} from URL {} on mediapackage {}", elementId, uri, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, uri);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getTrack(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (IOException e) {
        throw e;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 3 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class IngestServiceImpl method addPartialTrack.

@Override
public MediaPackage addPartialTrack(InputStream in, String fileName, MediaPackageElementFlavor flavor, long startTime, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_TRACK, null, null, false);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding partial track {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Track, flavor);
        job.setStatus(Job.Status.FINISHED);
        // store startTime
        partialTrackStartTimes.put(elementId, startTime);
        logger.debug("Added start time {} for track {}", startTime, elementId);
        logger.info("Successful added partial track {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 4 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class IngestServiceImpl method addAttachment.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addAttachment(java.io.InputStream, java.lang.String,
 *      org.opencastproject.mediapackage.MediaPackageElementFlavor, org.opencastproject.mediapackage.MediaPackage)
 */
@Override
public MediaPackage addAttachment(InputStream in, String fileName, MediaPackageElementFlavor flavor, String[] tags, MediaPackage mediaPackage) throws IOException, IngestException {
    Job job = null;
    try {
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_ATTACHMENT, null, null, false, ingestFileJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        String elementId = UUID.randomUUID().toString();
        logger.info("Start adding attachment {} from input stream on mediapackage {}", elementId, mediaPackage);
        URI newUrl = addContentToRepo(mediaPackage, elementId, fileName, in);
        MediaPackage mp = addContentToMediaPackage(mediaPackage, elementId, newUrl, MediaPackageElement.Type.Attachment, flavor);
        if (tags != null && tags.length > 0) {
            MediaPackageElement trackElement = mp.getAttachment(elementId);
            for (String tag : tags) {
                logger.info("Adding Tag: " + tag + " to Element: " + elementId);
                trackElement.addTag(tag);
            }
        }
        job.setStatus(Job.Status.FINISHED);
        logger.info("Successful added attachment {} on mediapackage {} at URL {}", elementId, mediaPackage, newUrl);
        return mp;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (NotFoundException e) {
        throw new IngestException("Unable to update ingest job", e);
    } finally {
        finallyUpdateJob(job);
    }
}
Also used : MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException)

Example 5 with ServiceRegistryException

use of org.opencastproject.serviceregistry.api.ServiceRegistryException in project opencast by opencast.

the class IngestServiceImpl method addZippedMediaPackage.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#addZippedMediaPackage(java.io.InputStream, java.lang.String,
 *      java.util.Map, java.lang.Long)
 */
@Override
public WorkflowInstance addZippedMediaPackage(InputStream zipStream, String workflowDefinitionId, Map<String, String> workflowConfig, Long workflowInstanceId) throws MediaPackageException, IOException, IngestException, NotFoundException, UnauthorizedException {
    // Start a job synchronously. We can't keep the open input stream waiting around.
    Job job = null;
    if (StringUtils.isNotBlank(workflowDefinitionId)) {
        try {
            workflowService.getWorkflowDefinitionById(workflowDefinitionId);
        } catch (WorkflowDatabaseException e) {
            throw new IngestException(e);
        } catch (NotFoundException nfe) {
            logger.warn("Workflow definition {} not found, using default workflow {} instead", workflowDefinitionId, defaultWorkflowDefinionId);
            workflowDefinitionId = defaultWorkflowDefinionId;
        }
    }
    if (workflowInstanceId != null) {
        logger.warn("Deprecated method! Ingesting zipped mediapackage with workflow {}", workflowInstanceId);
    } else {
        logger.info("Ingesting zipped mediapackage");
    }
    ZipArchiveInputStream zis = null;
    Set<String> collectionFilenames = new HashSet<>();
    try {
        // We don't need anybody to do the dispatching for us. Therefore we need to make sure that the job is never in
        // QUEUED state but set it to INSTANTIATED in the beginning and then manually switch it to RUNNING.
        job = serviceRegistry.createJob(JOB_TYPE, INGEST_ZIP, null, null, false, ingestZipJobLoad);
        job.setStatus(Status.RUNNING);
        job = serviceRegistry.updateJob(job);
        // Create the working file target collection for this ingest operation
        String wfrCollectionId = Long.toString(job.getId());
        zis = new ZipArchiveInputStream(zipStream);
        ZipArchiveEntry entry;
        MediaPackage mp = null;
        Map<String, URI> uris = new HashMap<>();
        // Sequential number to append to file names so that, if two files have the same
        // name, one does not overwrite the other (see MH-9688)
        int seq = 1;
        // Folder name to compare with next one to figure out if there's a root folder
        String folderName = null;
        // Indicates if zip has a root folder or not, initialized as true
        boolean hasRootFolder = true;
        // While there are entries write them to a collection
        while ((entry = zis.getNextZipEntry()) != null) {
            try {
                if (entry.isDirectory() || entry.getName().contains("__MACOSX"))
                    continue;
                if (entry.getName().endsWith("manifest.xml") || entry.getName().endsWith("index.xml")) {
                    // Build the mediapackage
                    mp = loadMediaPackageFromManifest(new ZipEntryInputStream(zis, entry.getSize()));
                } else {
                    logger.info("Storing zip entry {}/{} in working file repository collection '{}'", job.getId(), entry.getName(), wfrCollectionId);
                    // Since the directory structure is not being mirrored, makes sure the file
                    // name is different than the previous one(s) by adding a sequential number
                    String fileName = FilenameUtils.getBaseName(entry.getName()) + "_" + seq++ + "." + FilenameUtils.getExtension(entry.getName());
                    URI contentUri = workingFileRepository.putInCollection(wfrCollectionId, fileName, new ZipEntryInputStream(zis, entry.getSize()));
                    collectionFilenames.add(fileName);
                    // Key is the zip entry name as it is
                    String key = entry.getName();
                    uris.put(key, contentUri);
                    ingestStatistics.add(entry.getSize());
                    logger.info("Zip entry {}/{} stored at {}", job.getId(), entry.getName(), contentUri);
                    // Figures out if there's a root folder. Does entry name starts with a folder?
                    int pos = entry.getName().indexOf('/');
                    if (pos == -1) {
                        // No, we can conclude there's no root folder
                        hasRootFolder = false;
                    } else if (hasRootFolder && folderName != null && !folderName.equals(entry.getName().substring(0, pos))) {
                        // Folder name different from previous so there's no root folder
                        hasRootFolder = false;
                    } else if (folderName == null) {
                        // Just initialize folder name
                        folderName = entry.getName().substring(0, pos);
                    }
                }
            } catch (IOException e) {
                logger.warn("Unable to process zip entry {}: {}", entry.getName(), e);
                throw e;
            }
        }
        if (mp == null)
            throw new MediaPackageException("No manifest found in this zip");
        // Determine the mediapackage identifier
        if (mp.getIdentifier() == null || isBlank(mp.getIdentifier().toString()))
            mp.setIdentifier(new UUIDIdBuilderImpl().createNew());
        String mediaPackageId = mp.getIdentifier().toString();
        logger.info("Ingesting mediapackage {} is named '{}'", mediaPackageId, mp.getTitle());
        // Make sure there are tracks in the mediapackage
        if (mp.getTracks().length == 0) {
            logger.warn("Mediapackage {} has no media tracks", mediaPackageId);
        }
        // Update the element uris to point to their working file repository location
        for (MediaPackageElement element : mp.elements()) {
            // Key has root folder name if there is one
            URI uri = uris.get((hasRootFolder ? folderName + "/" : "") + element.getURI().toString());
            if (uri == null)
                throw new MediaPackageException("Unable to map element name '" + element.getURI() + "' to workspace uri");
            logger.info("Ingested mediapackage element {}/{} located at {}", mediaPackageId, element.getIdentifier(), uri);
            URI dest = workingFileRepository.moveTo(wfrCollectionId, FilenameUtils.getName(uri.toString()), mediaPackageId, element.getIdentifier(), FilenameUtils.getName(element.getURI().toString()));
            element.setURI(dest);
            // TODO: This should be triggered somehow instead of being handled here
            if (MediaPackageElements.SERIES.equals(element.getFlavor())) {
                logger.info("Ingested mediapackage {} contains updated series information", mediaPackageId);
                updateSeries(element.getURI());
            }
        }
        // Now that all elements are in place, start with ingest
        logger.info("Initiating processing of ingested mediapackage {}", mediaPackageId);
        WorkflowInstance workflowInstance = ingest(mp, workflowDefinitionId, workflowConfig, workflowInstanceId);
        logger.info("Ingest of mediapackage {} done", mediaPackageId);
        job.setStatus(Job.Status.FINISHED);
        return workflowInstance;
    } catch (ServiceRegistryException e) {
        throw new IngestException(e);
    } catch (MediaPackageException e) {
        job.setStatus(Job.Status.FAILED, Job.FailureReason.DATA);
        throw e;
    } catch (Exception e) {
        if (e instanceof IngestException)
            throw (IngestException) e;
        throw new IngestException(e);
    } finally {
        IOUtils.closeQuietly(zis);
        finallyUpdateJob(job);
        for (String filename : collectionFilenames) {
            workingFileRepository.deleteFromCollection(Long.toString(job.getId()), filename, true);
        }
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) HashMap(java.util.HashMap) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) IngestException(org.opencastproject.ingest.api.IngestException) HandleException(org.opencastproject.mediapackage.identifier.HandleException) ConfigurationException(org.opencastproject.util.ConfigurationException) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ZipArchiveEntry(org.apache.commons.compress.archivers.zip.ZipArchiveEntry) IngestException(org.opencastproject.ingest.api.IngestException) JobUtil.waitForJob(org.opencastproject.util.JobUtil.waitForJob) Job(org.opencastproject.job.api.Job) HashSet(java.util.HashSet) UUIDIdBuilderImpl(org.opencastproject.mediapackage.identifier.UUIDIdBuilderImpl)

Aggregations

ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)99 NotFoundException (org.opencastproject.util.NotFoundException)61 ConfigurationException (org.osgi.service.cm.ConfigurationException)41 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)30 URISyntaxException (java.net.URISyntaxException)29 Job (org.opencastproject.job.api.Job)29 PersistenceException (javax.persistence.PersistenceException)26 RollbackException (javax.persistence.RollbackException)26 TrustedHttpClientException (org.opencastproject.security.api.TrustedHttpClientException)26 NoResultException (javax.persistence.NoResultException)25 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)25 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)24 EntityManager (javax.persistence.EntityManager)22 MediaPackage (org.opencastproject.mediapackage.MediaPackage)20 URI (java.net.URI)16 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)14 DistributionException (org.opencastproject.distribution.api.DistributionException)13 Attachment (org.opencastproject.mediapackage.Attachment)12 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)12