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