Search in sources :

Example 1 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestRestService method schedule.

@POST
@Path("schedule/{wdID}")
@RestQuery(name = "schedule", description = "Schedule an event based on the given media package", pathParameters = { @RestParameter(description = "Workflow definition id", isRequired = true, name = "wdID", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(description = "The media package", isRequired = true, name = "mediaPackage", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(description = "Event scheduled", responseCode = HttpServletResponse.SC_CREATED), @RestResponse(description = "Media package not valid", responseCode = HttpServletResponse.SC_BAD_REQUEST) }, returnDescription = "")
public Response schedule(@PathParam("wdID") String wdID, MultivaluedMap<String, String> formData) {
    if (StringUtils.isBlank(wdID)) {
        logger.trace("workflow definition id is not specified");
        return Response.status(Response.Status.BAD_REQUEST).build();
    }
    Map<String, String> wfConfig = getWorkflowConfig(formData);
    if (StringUtils.isNotBlank(wdID)) {
        wfConfig.put(CaptureParameters.INGEST_WORKFLOW_DEFINITION, wdID);
    }
    logger.debug("Schedule with workflow definition '{}'", wfConfig.get(WORKFLOW_DEFINITION_ID_PARAM));
    String mediaPackageXml = formData.getFirst("mediaPackage");
    if (StringUtils.isBlank(mediaPackageXml)) {
        logger.debug("Rejected schedule without media package");
        return Response.status(Status.BAD_REQUEST).build();
    }
    MediaPackage mp = null;
    try {
        mp = factory.newMediaPackageBuilder().loadFromXml(mediaPackageXml);
        if (MediaPackageSupport.sanityCheck(mp).isSome()) {
            throw new MediaPackageException("Insane media package");
        }
    } catch (MediaPackageException e) {
        logger.debug("Rejected ingest with invalid media package {}", mp);
        return Response.status(Status.BAD_REQUEST).build();
    }
    MediaPackageElement[] mediaPackageElements = mp.getElementsByFlavor(MediaPackageElements.EPISODE);
    if (mediaPackageElements.length != 1) {
        logger.debug("There can be only one (and exactly one) episode dublin core catalog: https://youtu.be/_J3VeogFUOs");
        return Response.status(Status.BAD_REQUEST).build();
    }
    try {
        ingestService.schedule(mp, wdID, wfConfig);
        return Response.status(Status.CREATED).build();
    } catch (IngestException e) {
        return Response.status(Status.BAD_REQUEST).entity(e.getMessage()).build();
    } catch (SchedulerConflictException e) {
        return Response.status(Status.CONFLICT).entity(e.getMessage()).build();
    } catch (NotFoundException | UnauthorizedException | SchedulerException e) {
        return Response.serverError().build();
    }
}
Also used : MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) MediaPackageElement(org.opencastproject.mediapackage.MediaPackageElement) MediaPackage(org.opencastproject.mediapackage.MediaPackage) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 2 with IngestException

use of org.opencastproject.ingest.api.IngestException 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 3 with IngestException

use of org.opencastproject.ingest.api.IngestException 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 4 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method mergeScheduledMediaPackage.

/**
 * Merges the ingested mediapackage with the scheduled mediapackage. The ingested mediapackage takes precedence over
 * the scheduled mediapackage.
 *
 * @param mp
 *          the ingested mediapackage
 * @return the merged mediapackage
 */
private MediaPackage mergeScheduledMediaPackage(MediaPackage mp) throws IngestException {
    if (schedulerService == null) {
        logger.warn("No scheduler service available to merge mediapackage!");
        return mp;
    }
    try {
        MediaPackage scheduledMp = schedulerService.getMediaPackage(mp.getIdentifier().compact());
        logger.info("Found matching scheduled event for id '{}', merging mediapackage...", mp.getIdentifier().compact());
        mergeMediaPackageElements(mp, scheduledMp);
        mergeMediaPackageMetadata(mp, scheduledMp);
        return mp;
    } catch (NotFoundException e) {
        logger.debug("No scheduler mediapackage found with id {}, skip merging", mp.getIdentifier().compact());
        return mp;
    } catch (Exception e) {
        logger.error("Unable to get event mediapackage from scheduler event {}", mp.getIdentifier().compact(), e);
        throw new IngestException(e);
    }
}
Also used : MediaPackage(org.opencastproject.mediapackage.MediaPackage) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException) 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)

Example 5 with IngestException

use of org.opencastproject.ingest.api.IngestException in project opencast by opencast.

the class IngestServiceImpl method updateSeries.

/**
 * Updates the persistent representation of a series based on a potentially modified dublin core document.
 *
 * @param uri
 *          the URI to the dublin core document containing series metadata.
 * @return
 *         true, if the series is created or overwritten, false if the existing series remains intact.
 */
protected boolean updateSeries(URI uri) throws IOException, IngestException {
    HttpResponse response = null;
    InputStream in = null;
    boolean isUpdated = false;
    try {
        HttpGet getDc = new HttpGet(uri);
        response = httpClient.execute(getDc);
        in = response.getEntity().getContent();
        DublinCoreCatalog dc = dublinCoreService.load(in);
        String id = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
        if (id == null) {
            logger.warn("Series dublin core document contains no identifier, rejecting ingested series cagtalog.");
        } else {
            try {
                try {
                    seriesService.getSeries(id);
                    if (isOverwriteSeries) {
                        // Update existing series
                        seriesService.updateSeries(dc);
                        isUpdated = true;
                        logger.debug("Ingest is overwriting the existing series {} with the ingested series", id);
                    } else {
                        logger.debug("Series {} already exists. Ignoring series catalog from ingest.", id);
                    }
                } catch (NotFoundException e) {
                    logger.info("Creating new series {} with default ACL", id);
                    seriesService.updateSeries(dc);
                    isUpdated = true;
                    String anonymousRole = securityService.getOrganization().getAnonymousRole();
                    AccessControlList acl = new AccessControlList(new AccessControlEntry(anonymousRole, "read", true));
                    seriesService.updateAccessControl(id, acl);
                }
            } catch (Exception e) {
                throw new IngestException(e);
            }
        }
        in.close();
    } catch (IOException e) {
        logger.error("Error updating series from DublinCoreCatalog: {}", e.getMessage());
    } finally {
        IOUtils.closeQuietly(in);
        httpClient.close(response);
    }
    return isUpdated;
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) ProgressInputStream(org.opencastproject.util.ProgressInputStream) ZipArchiveInputStream(org.apache.commons.compress.archivers.zip.ZipArchiveInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) 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)

Aggregations

IngestException (org.opencastproject.ingest.api.IngestException)19 NotFoundException (org.opencastproject.util.NotFoundException)14 MediaPackage (org.opencastproject.mediapackage.MediaPackage)12 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)11 URI (java.net.URI)10 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)10 Job (org.opencastproject.job.api.Job)9 JobUtil.waitForJob (org.opencastproject.util.JobUtil.waitForJob)9 IOException (java.io.IOException)8 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)6 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)5 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)5 WorkflowException (org.opencastproject.workflow.api.WorkflowException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ZipArchiveInputStream (org.apache.commons.compress.archivers.zip.ZipArchiveInputStream)4 JDOMException (org.jdom.JDOMException)4 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 HandleException (org.opencastproject.mediapackage.identifier.HandleException)3