Search in sources :

Example 6 with WorkflowException

use of org.opencastproject.workflow.api.WorkflowException in project opencast by opencast.

the class WorkflowOperationWorker method start.

/**
 * Starts executing the workflow operation.
 *
 * @return the workflow operation result
 * @throws WorkflowOperationException
 *           if executing the workflow operation handler fails
 * @throws WorkflowException
 *           if there is a problem processing the workflow
 */
public WorkflowOperationResult start() throws WorkflowOperationException, WorkflowException, UnauthorizedException {
    final WorkflowOperationInstance operation = workflow.getCurrentOperation();
    // Do we need to execute the operation?
    // if
    final String executionCondition = operation.getExecutionCondition();
    final boolean execute;
    if (executionCondition == null) {
        execute = true;
    } else {
        final Result<Boolean> parsed = booleanExpressionEvaluator.eval(executionCondition);
        if (parsed.isDefined() && parsed.getRest().isEmpty()) {
            execute = parsed.getResult();
        } else {
            operation.setState(OperationState.FAILED);
            throw new WorkflowOperationException(format("Unable to parse execution condition '%s'. Result is '%s'", executionCondition, parsed.toString()));
        }
    }
    operation.setState(OperationState.RUNNING);
    service.update(workflow);
    try {
        WorkflowOperationResult result = null;
        if (execute) {
            if (handler == null) {
                // If there is no handler for the operation, yet we are supposed to run it, we must fail
                logger.warn("No handler available to execute operation '{}'", operation.getTemplate());
                throw new IllegalStateException("Unable to find a workflow handler for '" + operation.getTemplate() + "'");
            }
            result = handler.start(workflow, null);
        } else {
            // Allow for null handlers when we are skipping an operation
            if (handler != null) {
                result = handler.skip(workflow, null);
                result.setAction(Action.SKIP);
            }
        }
        return result;
    } catch (Exception e) {
        operation.setState(OperationState.FAILED);
        if (e instanceof WorkflowOperationException)
            throw (WorkflowOperationException) e;
        throw new WorkflowOperationException(e);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) JobCanceledException(org.opencastproject.util.JobCanceledException) WorkflowOperationAbortedException(org.opencastproject.workflow.api.WorkflowOperationAbortedException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException)

Example 7 with WorkflowException

use of org.opencastproject.workflow.api.WorkflowException in project opencast by opencast.

the class WorkflowOperationWorker method resume.

/**
 * Resumes a previously suspended workflow operation. Note that only workflow operation handlers that implement
 * {@link ResumableWorkflowOperationHandler} can be resumed.
 *
 * @return the workflow operation result
 * @throws WorkflowOperationException
 *           if executing the workflow operation handler fails
 * @throws WorkflowException
 *           if there is a problem processing the workflow
 * @throws IllegalStateException
 *           if the workflow operation cannot be resumed
 */
public WorkflowOperationResult resume() throws WorkflowOperationException, WorkflowException, IllegalStateException, UnauthorizedException {
    WorkflowOperationInstance operation = workflow.getCurrentOperation();
    // Make sure we have a (suitable) handler
    if (handler == null) {
        // If there is no handler for the operation, yet we are supposed to run it, we must fail
        logger.warn("No handler available to resume operation '{}'", operation.getTemplate());
        throw new IllegalStateException("Unable to find a workflow handler for '" + operation.getTemplate() + "'");
    } else if (!(handler instanceof ResumableWorkflowOperationHandler)) {
        throw new IllegalStateException("An attempt was made to resume a non-resumable operation");
    }
    ResumableWorkflowOperationHandler resumableHandler = (ResumableWorkflowOperationHandler) handler;
    operation.setState(OperationState.RUNNING);
    service.update(workflow);
    try {
        WorkflowOperationResult result = resumableHandler.resume(workflow, null, properties);
        return result;
    } catch (Exception e) {
        operation.setState(OperationState.FAILED);
        if (e instanceof WorkflowOperationException)
            throw (WorkflowOperationException) e;
        throw new WorkflowOperationException(e);
    }
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ResumableWorkflowOperationHandler(org.opencastproject.workflow.api.ResumableWorkflowOperationHandler) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) WorkflowOperationResult(org.opencastproject.workflow.api.WorkflowOperationResult) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) JobCanceledException(org.opencastproject.util.JobCanceledException) WorkflowOperationAbortedException(org.opencastproject.workflow.api.WorkflowOperationAbortedException) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException)

Example 8 with WorkflowException

use of org.opencastproject.workflow.api.WorkflowException in project opencast by opencast.

the class IngestServiceImpl method ingest.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.ingest.api.IngestService#ingest(org.opencastproject.mediapackage.MediaPackage,
 *      java.lang.String, java.util.Map, java.lang.Long)
 */
@Override
public WorkflowInstance ingest(MediaPackage mp, String workflowDefinitionId, Map<String, String> properties, Long workflowInstanceId) throws IngestException, NotFoundException, UnauthorizedException {
    // Check for legacy media package id
    mp = checkForLegacyMediaPackageId(mp, properties);
    try {
        mp = createSmil(mp);
    } catch (IOException e) {
        throw new IngestException("Unable to add SMIL Catalog", e);
    }
    // Done, update the job status and return the created workflow instance
    if (workflowInstanceId != null) {
        logger.warn("Resuming workflow {} with ingested mediapackage {} is deprecated, skip resuming and start new workflow", workflowInstanceId, mp);
    }
    if (workflowDefinitionId == null) {
        logger.info("Starting a new workflow with ingested mediapackage {} based on the default workflow definition '{}'", mp, defaultWorkflowDefinionId);
    } else {
        logger.info("Starting a new workflow with ingested mediapackage {} based on workflow definition '{}'", mp, workflowDefinitionId);
    }
    try {
        // Determine the workflow definition
        WorkflowDefinition workflowDef = getWorkflowDefinition(workflowDefinitionId, mp);
        // Get the final set of workflow properties
        properties = mergeWorkflowConfiguration(properties, mp.getIdentifier().compact());
        // Remove potential workflow configuration prefixes from the workflow properties
        properties = removePrefixFromProperties(properties);
        // Merge scheduled mediapackage with ingested
        mp = mergeScheduledMediaPackage(mp);
        // Set public ACL if empty
        setPublicAclIfEmpty(mp);
        ingestStatistics.successful();
        if (workflowDef != null) {
            logger.info("Starting new workflow with ingested mediapackage '{}' using the specified template '{}'", mp.getIdentifier().toString(), workflowDefinitionId);
        } else {
            logger.info("Starting new workflow with ingested mediapackage '{}' using the default template '{}'", mp.getIdentifier().toString(), defaultWorkflowDefinionId);
        }
        return workflowService.start(workflowDef, mp, properties);
    } catch (WorkflowException e) {
        ingestStatistics.failed();
        throw new IngestException(e);
    }
}
Also used : WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) IngestException(org.opencastproject.ingest.api.IngestException) IOException(java.io.IOException)

Example 9 with WorkflowException

use of org.opencastproject.workflow.api.WorkflowException in project opencast by opencast.

the class IndexServiceImpl method removeEvent.

@Override
public boolean removeEvent(String id) throws NotFoundException, UnauthorizedException {
    boolean unauthorizedScheduler = false;
    boolean notFoundScheduler = false;
    boolean removedScheduler = true;
    try {
        schedulerService.removeEvent(id);
    } catch (NotFoundException e) {
        notFoundScheduler = true;
    } catch (UnauthorizedException e) {
        unauthorizedScheduler = true;
    } catch (SchedulerException e) {
        removedScheduler = false;
        logger.error("Unable to remove the event '{}' from scheduler service: {}", id, getStackTrace(e));
    }
    boolean unauthorizedWorkflow = false;
    boolean notFoundWorkflow = false;
    boolean removedWorkflow = true;
    try {
        WorkflowQuery workflowQuery = new WorkflowQuery().withMediaPackage(id);
        WorkflowSet workflowSet = workflowService.getWorkflowInstances(workflowQuery);
        if (workflowSet.size() == 0)
            notFoundWorkflow = true;
        for (WorkflowInstance instance : workflowSet.getItems()) {
            workflowService.stop(instance.getId());
            workflowService.remove(instance.getId());
        }
    } catch (NotFoundException e) {
        notFoundWorkflow = true;
    } catch (UnauthorizedException e) {
        unauthorizedWorkflow = true;
    } catch (WorkflowDatabaseException e) {
        removedWorkflow = false;
        logger.error("Unable to remove the event '{}' because removing workflow failed: {}", id, getStackTrace(e));
    } catch (WorkflowException e) {
        removedWorkflow = false;
        logger.error("Unable to remove the event '{}' because removing workflow failed: {}", id, getStackTrace(e));
    }
    boolean unauthorizedArchive = false;
    boolean notFoundArchive = false;
    boolean removedArchive = true;
    try {
        final AQueryBuilder q = assetManager.createQuery();
        final Predicate p = q.organizationId().eq(securityService.getOrganization().getId()).and(q.mediaPackageId(id));
        final AResult r = q.select(q.nothing()).where(p).run();
        if (r.getSize() > 0)
            q.delete(DEFAULT_OWNER, q.snapshot()).where(p).run();
    } catch (AssetManagerException e) {
        if (e.getCause() instanceof UnauthorizedException) {
            unauthorizedArchive = true;
        } else if (e.getCause() instanceof NotFoundException) {
            notFoundArchive = true;
        } else {
            removedArchive = false;
            logger.error("Unable to remove the event '{}' from the archive: {}", id, getStackTrace(e));
        }
    }
    if (notFoundScheduler && notFoundWorkflow && notFoundArchive)
        throw new NotFoundException("Event id " + id + " not found.");
    if (unauthorizedScheduler || unauthorizedWorkflow || unauthorizedArchive)
        throw new UnauthorizedException("Not authorized to remove event id " + id);
    try {
        eventCommentService.deleteComments(id);
    } catch (EventCommentException e) {
        logger.error("Unable to remove comments for event '{}': {}", id, getStackTrace(e));
    }
    return removedScheduler && removedWorkflow && removedArchive;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) NotFoundException(org.opencastproject.util.NotFoundException) AQueryBuilder(org.opencastproject.assetmanager.api.query.AQueryBuilder) EventCommentException(org.opencastproject.event.comment.EventCommentException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) Predicate(org.opencastproject.assetmanager.api.query.Predicate) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) AResult(org.opencastproject.assetmanager.api.query.AResult)

Example 10 with WorkflowException

use of org.opencastproject.workflow.api.WorkflowException in project opencast by opencast.

the class WorkflowPermissionsUpdatedEventHandler 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));
        // Note: getWorkflowInstances will only return a given number of results (default 20)
        WorkflowQuery q = new WorkflowQuery().withSeriesId(seriesId);
        WorkflowSet result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
        Integer offset = 0;
        while (result.size() > 0) {
            for (WorkflowInstance instance : result.getItems()) {
                if (!instance.isActive())
                    continue;
                Organization org = instance.getOrganization();
                securityService.setOrganization(org);
                MediaPackage mp = instance.getMediaPackage();
                // Update the series XACML file
                if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
                    // Build a new XACML file for this mediapackage
                    authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl());
                }
                // 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);
                    }
                }
                // Remove the series catalog and isPartOf from episode catalog
                if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
                    mp.setSeries(null);
                    mp.setSeriesTitle(null);
                    for (Catalog c : mp.getCatalogs(MediaPackageElements.SERIES)) {
                        mp.remove(c);
                        try {
                            workspace.delete(c.getURI());
                        } catch (NotFoundException e) {
                            logger.info("No series catalog to delete found {}", c.getURI());
                        }
                    }
                    for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
                        DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
                        episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
                        String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
                        URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
                        episodeCatalog.setURI(uri);
                        // setting the URI to a new source so the checksum will most like be invalid
                        episodeCatalog.setChecksum(null);
                    }
                }
                // Update the search index with the modified mediapackage
                workflowService.update(instance);
            }
            offset++;
            q = q.withStartPage(offset);
            result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
        }
    } catch (WorkflowException e) {
        logger.warn(e.getMessage());
    } catch (UnauthorizedException e) {
        logger.warn(e.getMessage());
    } catch (IOException e) {
        logger.warn(e.getMessage());
    } finally {
        securityService.setOrganization(prevOrg);
        securityService.setUser(prevUser);
    }
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) User(org.opencastproject.security.api.User) Organization(org.opencastproject.security.api.Organization) WorkflowException(org.opencastproject.workflow.api.WorkflowException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) URI(java.net.URI) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Aggregations

WorkflowException (org.opencastproject.workflow.api.WorkflowException)15 NotFoundException (org.opencastproject.util.NotFoundException)10 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)9 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)8 IOException (java.io.IOException)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)6 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)5 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)5 Lock (java.util.concurrent.locks.Lock)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)3 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)3 SeriesException (org.opencastproject.series.api.SeriesException)3 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)3 UndispatchableJobException (org.opencastproject.serviceregistry.api.UndispatchableJobException)3 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)3 WorkflowSet (org.opencastproject.workflow.api.WorkflowSet)3 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)3 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)3