Search in sources :

Example 11 with WorkflowDefinition

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

the class WorkflowServiceRemoteImpl method listAvailableWorkflowDefinitions.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowService#listAvailableWorkflowDefinitions()
 */
@Override
public List<WorkflowDefinition> listAvailableWorkflowDefinitions() throws WorkflowDatabaseException {
    HttpGet get = new HttpGet("/definitions.xml");
    HttpResponse response = getResponse(get);
    try {
        if (response != null) {
            List<WorkflowDefinition> list = WorkflowParser.parseWorkflowDefinitions(response.getEntity().getContent());
            // sorts by title
            Collections.sort(list);
            return list;
        }
    } catch (Exception e) {
        throw new IllegalStateException("Unable to parse workflow definitions");
    } finally {
        closeConnection(response);
    }
    throw new WorkflowDatabaseException("Unable to read the registered workflow definitions from the remote workflow service");
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) ParseException(org.apache.http.ParseException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 12 with WorkflowDefinition

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

the class IncludeWorkflowOperationHandler method insertWorkflow.

/**
 * Adds the operations found in the workflow defined by <code>workflowDefinitionId</code> to the workflow instance and
 * returns <code>true</code> if everything worked fine, <code>false</code> otherwise.
 *
 * @param wi
 *         the instance to insert the workflow identified by <code>workflowDefinitionId</code> into
 * @param workflowDefinitionId
 *         id of the workflow definition to insert
 * @throws WorkflowOperationException
 *         in case of any error
 */
public void insertWorkflow(final WorkflowInstance wi, final String workflowDefinitionId) throws WorkflowOperationException {
    try {
        final WorkflowDefinition definition = workflowService.getWorkflowDefinitionById(workflowDefinitionId);
        if (definition != null) {
            logger.info(format("Insert workflow %s into the current workflow instance", workflowDefinitionId));
            wi.insert(definition, wi.getCurrentOperation());
        } else {
            logger.warn(format("Workflow definition %s cannot be found", workflowDefinitionId));
        }
    } catch (Exception e) {
        throw new WorkflowOperationException("Error inserting workflow " + workflowDefinitionId, e);
    }
}
Also used : WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException)

Example 13 with WorkflowDefinition

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

the class WorkflowDefinitionScanner method install.

/**
 * {@inheritDoc}
 *
 * @see org.apache.felix.fileinstall.ArtifactInstaller#install(java.io.File)
 */
public void install(File artifact) throws Exception {
    WorkflowDefinition def = currentWFD;
    // If the current workflow definition is null, it means this is a first install and not an update...
    if (def == null) {
        // ... so we have to load the definition first
        def = parseWorkflowDefinitionFile(artifact);
        if (def == null) {
            logger.warn("Unable to install workflow from '{}'", artifact.getName());
            artifactsWithError.add(artifact);
            return;
        }
    }
    logger.debug("Installing workflow from file '{}'", artifact.getName());
    artifactsWithError.remove(artifact);
    artifactIds.put(artifact, def.getId());
    putWorkflowDefinition(def.getId(), def);
    // Determine the number of available profiles
    String[] filesInDirectory = artifact.getParentFile().list(new FilenameFilter() {

        public boolean accept(File arg0, String name) {
            return name.endsWith(".xml");
        }
    });
    logger.info("Worfkflow definition '{}' from file '{}' installed", def.getId(), artifact.getName());
    // Once all profiles have been loaded, announce readiness
    if ((filesInDirectory.length - artifactsWithError.size()) == artifactIds.size() && !isWFSinitiliazed) {
        logger.info("{} Workflow definitions loaded, activating Workflow service", filesInDirectory.length - artifactsWithError.size());
        Dictionary<String, String> properties = new Hashtable<String, String>();
        properties.put(ARTIFACT, "workflowdefinition");
        logger.debug("Indicating readiness of workflow definitions");
        bundleCtx.registerService(ReadinessIndicator.class.getName(), new ReadinessIndicator(), properties);
        isWFSinitiliazed = true;
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) ReadinessIndicator(org.opencastproject.util.ReadinessIndicator) Hashtable(java.util.Hashtable) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) File(java.io.File)

Example 14 with WorkflowDefinition

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

the class WorkflowDefinitionScanner method parseWorkflowDefinitionFile.

/**
 * Parse the given workflow definition file and return the related workflow definition
 *
 * @param artifact
 *          The workflow definition file to parse
 * @return the workflow definition if the given contained a valid one, or null if the file can not be parsed.
 */
public WorkflowDefinition parseWorkflowDefinitionFile(File artifact) {
    InputStream stream = null;
    try {
        stream = new FileInputStream(artifact);
        WorkflowDefinition def = WorkflowParser.parseWorkflowDefinition(stream);
        if (def.getOperations().size() == 0)
            logger.warn("Workflow '{}' has no operations", def.getId());
        return def;
    } catch (Exception e) {
        logger.warn("Unable to parse workflow from file '{}', {}", artifact.getName(), e.getMessage());
        return null;
    } finally {
        IOUtils.closeQuietly(stream);
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) FileInputStream(java.io.FileInputStream)

Example 15 with WorkflowDefinition

use of org.opencastproject.workflow.api.WorkflowDefinition 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)

Aggregations

WorkflowDefinition (org.opencastproject.workflow.api.WorkflowDefinition)22 ArrayList (java.util.ArrayList)9 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)6 WorkflowInstance (org.opencastproject.workflow.api.WorkflowInstance)6 Path (javax.ws.rs.Path)5 Test (org.junit.Test)5 NotFoundException (org.opencastproject.util.NotFoundException)5 RestQuery (org.opencastproject.util.doc.rest.RestQuery)5 InputStream (java.io.InputStream)4 GET (javax.ws.rs.GET)4 JValue (com.entwinemedia.fn.data.json.JValue)3 IOException (java.io.IOException)3 Set (java.util.Set)3 Before (org.junit.Before)3 Workflows (org.opencastproject.assetmanager.util.Workflows)3 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)3 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)3 File (java.io.File)2 URI (java.net.URI)2 HashMap (java.util.HashMap)2