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);
}
}
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);
}
}
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);
}
}
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;
}
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);
}
}
Aggregations