Search in sources :

Example 21 with WorkflowDatabaseException

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

the class AbstractEventEndpoint method getNewProcessing.

@GET
@Path("new/processing")
@RestQuery(name = "getNewProcessing", description = "Returns all the data related to the processing tab in the new event modal as JSON", returnDescription = "All the data related to the event processing tab as JSON", restParameters = { @RestParameter(name = "tags", isRequired = false, description = "A comma separated list of tags to filter the workflow definitions", type = RestParameter.Type.STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "Returns all the data related to the event processing tab as JSON") })
public Response getNewProcessing(@QueryParam("tags") String tagsString) {
    List<String> tags = RestUtil.splitCommaSeparatedParam(Option.option(tagsString)).value();
    List<JValue> workflows = new ArrayList<>();
    try {
        List<WorkflowDefinition> workflowsDefinitions = getWorkflowService().listAvailableWorkflowDefinitions();
        for (WorkflowDefinition wflDef : workflowsDefinitions) {
            if (wflDef.containsTag(tags)) {
                workflows.add(obj(f("id", v(wflDef.getId())), f("title", v(nul(wflDef.getTitle()).getOr(""))), f("description", v(nul(wflDef.getDescription()).getOr(""))), f("configuration_panel", v(nul(wflDef.getConfigurationPanel()).getOr("")))));
            }
        }
    } catch (WorkflowDatabaseException e) {
        logger.error("Unable to get available workflow definitions: {}", ExceptionUtils.getStackTrace(e));
        return RestUtil.R.serverError();
    }
    JValue data = obj(f("workflows", arr(workflows)), f("default_workflow_id", v(defaultWorkflowDefinionId, Jsons.NULL)));
    return okJson(data);
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) JValue(com.entwinemedia.fn.data.json.JValue) ArrayList(java.util.ArrayList) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 22 with WorkflowDatabaseException

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

the class IndexServiceImpl method getCurrentWorkflowInstance.

@Override
public Opt<WorkflowInstance> getCurrentWorkflowInstance(String mpId) throws IndexServiceException {
    WorkflowQuery query = new WorkflowQuery().withMediaPackage(mpId);
    WorkflowSet workflowInstances;
    try {
        workflowInstances = workflowService.getWorkflowInstances(query);
        if (workflowInstances.size() == 0) {
            logger.info("No workflow instance found for mediapackage {}.", mpId);
            return Opt.none();
        }
    } catch (WorkflowDatabaseException e) {
        logger.error("Unable to get workflows for event {} because {}", mpId, getStackTrace(e));
        throw new IndexServiceException("Unable to get current workflow for event " + mpId);
    }
    // Get the newest workflow instance
    // TODO This presuppose knowledge of the Database implementation and should be fixed sooner or later!
    WorkflowInstance workflowInstance = workflowInstances.getItems()[0];
    for (WorkflowInstance instance : workflowInstances.getItems()) {
        if (instance.getId() > workflowInstance.getId())
            workflowInstance = instance;
    }
    return Opt.some(workflowInstance);
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Example 23 with WorkflowDatabaseException

use of org.opencastproject.workflow.api.WorkflowDatabaseException 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 24 with WorkflowDatabaseException

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

the class IndexServiceImpl method startAddAssetWorkflow.

/**
 * Parses the processing information, including the workflowDefinitionId, from the metadataJson and starts the
 * workflow with the passed mediapackage.
 *
 * TODO NOTE: This checks for running workflows, then takes a snapshot prior to starting a new workflow. This causes a
 * potential race condition:
 *
 * 1. An existing workflow is running, the add asset workflow cannot start.
 *
 * 2. The snapshot(4x) archive(3x) is saved and the new workflow is started.
 *
 * 3. Possible race condition: No running workflow, a snapshot is saved but the workflow cannot start because another
 * workflow has started between the time of checking and starting running.
 *
 * 4. If race condition: the Admin UI shows error that the workflow could not start.
 *
 * 5. If race condition: The interim snapshot(4x) archive(3x) is updated(4x-3x) by the running workflow's snapshots
 * and resolves the inconsistency, eventually.
 *
 * Example of processing json:
 *
 * ...., "processing": { "workflow": "full", "configuration": { "videoPreview": "false", "trimHold": "false",
 * "captionHold": "false", "archiveOp": "true", "publishEngage": "true", "publishHarvesting": "true" } }, ....
 *
 * @param metadataJson
 * @param mp
 * @return the created workflow instance id
 * @throws IndexServiceException
 */
private String startAddAssetWorkflow(JSONObject metadataJson, MediaPackage mediaPackage) throws IndexServiceException {
    String wfId = null;
    String mpId = mediaPackage.getIdentifier().toString();
    JSONObject processing = (JSONObject) metadataJson.get("processing");
    if (processing == null)
        throw new IllegalArgumentException("No processing field in metadata");
    String workflowDefId = (String) processing.get("workflow");
    if (workflowDefId == null)
        throw new IllegalArgumentException("No workflow definition field in processing metadata");
    JSONObject configJson = (JSONObject) processing.get("configuration");
    try {
        // 1. Check if any active workflows are running for this mediapackage id
        WorkflowSet workflowSet = workflowService.getWorkflowInstances(new WorkflowQuery().withMediaPackage(mpId));
        for (WorkflowInstance wf : Arrays.asList(workflowSet.getItems())) {
            if (wf.isActive()) {
                logger.warn("Unable to start new workflow '{}' on archived media package '{}', existing workfow {} is running", workflowDefId, mediaPackage, wf.getId());
                throw new IllegalArgumentException("A workflow is already active for mp " + mpId + ", cannot start this workflow.");
            }
        }
        // 2. Save the snapshot
        assetManager.takeSnapshot(DEFAULT_OWNER, mediaPackage);
        // 3. start the new workflow on the snapshot
        // Workflow params are assumed to be String (not mixed with Number)
        Map<String, String> params = new HashMap<String, String>();
        if (configJson != null) {
            for (Object key : configJson.keySet()) {
                params.put((String) key, (String) configJson.get(key));
            }
        }
        Set<String> mpIds = new HashSet<String>();
        mpIds.add(mpId);
        final Workflows workflows = new Workflows(assetManager, workspace, workflowService);
        List<WorkflowInstance> wfList = workflows.applyWorkflowToLatestVersion(mpIds, ConfiguredWorkflow.workflow(workflowService.getWorkflowDefinitionById(workflowDefId), params)).toList();
        wfId = wfList.size() > 0 ? Long.toString(wfList.get(0).getId()) : "Unknown";
        logger.info("Asset update and publish workflow {} scheduled for mp {}", wfId, mpId);
    } catch (AssetManagerException e) {
        logger.warn("Unable to start workflow '{}' on archived media package '{}': {}", workflowDefId, mediaPackage, getStackTrace(e));
        throw new IndexServiceException("Unable to start workflow " + workflowDefId + " on " + mpId);
    } catch (WorkflowDatabaseException e) {
        logger.warn("Unable to load workflow '{}' from workflow service: {}", wfId, getStackTrace(e));
    } catch (NotFoundException e) {
        logger.warn("Workflow '{}' not found", wfId);
    }
    return wfId;
}
Also used : WorkflowSet(org.opencastproject.workflow.api.WorkflowSet) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Workflows(org.opencastproject.assetmanager.util.Workflows) NotFoundException(org.opencastproject.util.NotFoundException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) JSONObject(org.json.simple.JSONObject) JSONObject(org.json.simple.JSONObject) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) HashSet(java.util.HashSet)

Example 25 with WorkflowDatabaseException

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

the class WorkflowsListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> workflowsList = new HashMap<String, String>();
    WorkflowQuery q = new WorkflowQuery();
    if (query != null) {
        if (query.getLimit().isSome())
            q.withCount(query.getLimit().get());
        if (query.getOffset().isSome())
            q.withStartPage(query.getOffset().get());
    }
    WorkflowInstance[] workflowInstances;
    try {
        workflowInstances = workflowService.getWorkflowInstances(q).getItems();
    } catch (WorkflowDatabaseException e) {
        logger.error("Error by querying the workflow instances from the DB: ", e);
        throw new ListProviderException(e.getMessage(), e.getCause());
    }
    for (WorkflowInstance w : workflowInstances) {
        workflowsList.put(Long.toString(w.getId()), w.getTitle() + " - " + w.getMediaPackage().getTitle());
    }
    return workflowsList;
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WorkflowQuery(org.opencastproject.workflow.api.WorkflowQuery) HashMap(java.util.HashMap) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Aggregations

WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)44 NotFoundException (org.opencastproject.util.NotFoundException)30 IOException (java.io.IOException)23 WorkflowParsingException (org.opencastproject.workflow.api.WorkflowParsingException)23 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)21 WorkflowException (org.opencastproject.workflow.api.WorkflowException)20 ArrayList (java.util.ArrayList)15 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)15 HttpResponse (org.apache.http.HttpResponse)14 ServiceRegistryException (org.opencastproject.serviceregistry.api.ServiceRegistryException)14 UnsupportedEncodingException (java.io.UnsupportedEncodingException)11 ParseException (org.apache.http.ParseException)11 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)8 WorkflowQuery (org.opencastproject.workflow.api.WorkflowQuery)8 SolrServerException (org.apache.solr.client.solrj.SolrServerException)7 UrlEncodedFormEntity (org.apache.http.client.entity.UrlEncodedFormEntity)6 Job (org.opencastproject.job.api.Job)6 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)6 Collections.mkString (org.opencastproject.util.data.Collections.mkString)6 WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)6