use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method update.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#update(org.opencastproject.workflow.api.WorkflowInstance)
*/
@Override
public void update(WorkflowInstance workflowInstance) throws WorkflowDatabaseException {
HttpPost post = new HttpPost("/update");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("workflow", WorkflowParser.toXml(workflowInstance)));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Unable to assemble a remote workflow service request", e);
} catch (Exception e) {
throw new IllegalStateException("unable to serialize workflow instance to xml");
}
HttpResponse response = getResponse(post, SC_NO_CONTENT);
try {
if (response != null) {
logger.info("Workflow '{}' updated", workflowInstance);
return;
}
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Unable to update workflow instance " + workflowInstance.getId());
}
use of org.opencastproject.workflow.api.WorkflowDatabaseException 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.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method start.
/**
* {@inheritDoc}
*
* @see org.opencastproject.workflow.api.WorkflowService#start(org.opencastproject.workflow.api.WorkflowDefinition,
* org.opencastproject.mediapackage.MediaPackage, Long, java.util.Map)
*/
@Override
public WorkflowInstance start(WorkflowDefinition workflowDefinition, MediaPackage mediaPackage, Long parentWorkflowId, Map<String, String> properties) throws WorkflowDatabaseException, NotFoundException {
HttpPost post = new HttpPost("/start");
try {
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
if (workflowDefinition != null)
params.add(new BasicNameValuePair("definition", WorkflowParser.toXml(workflowDefinition)));
params.add(new BasicNameValuePair("mediapackage", MediaPackageParser.getAsXml(mediaPackage)));
if (parentWorkflowId != null)
params.add(new BasicNameValuePair("parent", parentWorkflowId.toString()));
if (properties != null)
params.add(new BasicNameValuePair("properties", mapToString(properties)));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new IllegalStateException("Unable to assemble a remote workflow request", e);
}
HttpResponse response = getResponse(post, SC_NOT_FOUND, SC_OK);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Workflow instance " + parentWorkflowId + " does not exist.");
} else {
return WorkflowParser.parseWorkflowInstance(response.getEntity().getContent());
}
}
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new WorkflowDatabaseException("Unable to build a workflow from xml", e);
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Unable to start a remote workflow. The http response code was unexpected.");
}
use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class WorkflowServiceRemoteImpl method cleanupWorkflowInstances.
@Override
public void cleanupWorkflowInstances(int lifetime, WorkflowState state) throws WorkflowDatabaseException, UnauthorizedException {
HttpPost post = new HttpPost("/cleanup");
List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
params.add(new BasicNameValuePair("lifetime", String.valueOf(lifetime)));
if (state != null)
params.add(new BasicNameValuePair("state", state.toString()));
try {
post.setEntity(new UrlEncodedFormEntity(params));
} catch (UnsupportedEncodingException e) {
throw new IllegalStateException("Unable to assemble a remote workflow service request", e);
}
HttpResponse response = getResponse(post, SC_OK, HttpStatus.SC_UNAUTHORIZED);
try {
if (response != null) {
if (HttpStatus.SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
throw new UnauthorizedException("You do not have permission to cleanup");
} else {
logger.info("Successful request to workflow cleanup endpoint");
return;
}
}
} finally {
closeConnection(response);
}
throw new WorkflowDatabaseException("Unable to successfully request the workflow cleanup endpoint");
}
use of org.opencastproject.workflow.api.WorkflowDatabaseException in project opencast by opencast.
the class IngestServiceImpl method getWorkflowDefinition.
private WorkflowDefinition getWorkflowDefinition(String workflowDefinitionID, MediaPackage mediapackage) throws NotFoundException, WorkflowDatabaseException, IngestException {
// If the workflow definition and instance ID are null, use the default, or throw if there is none
if (isBlank(workflowDefinitionID)) {
String mediaPackageId = mediapackage.getIdentifier().compact();
if (schedulerService != null) {
logger.info("Determining workflow template for ingested mediapckage {} from capture event {}", mediapackage, mediaPackageId);
try {
Map<String, String> recordingProperties = schedulerService.getCaptureAgentConfiguration(mediaPackageId);
workflowDefinitionID = recordingProperties.get(CaptureParameters.INGEST_WORKFLOW_DEFINITION);
if (isBlank(workflowDefinitionID)) {
workflowDefinitionID = defaultWorkflowDefinionId;
logger.debug("No workflow set. Falling back to default.");
}
if (isBlank(workflowDefinitionID)) {
throw new IngestException("No value found for key '" + CaptureParameters.INGEST_WORKFLOW_DEFINITION + "' from capture event configuration of scheduler event '" + mediaPackageId + "'");
}
logger.info("Ingested event {} will be processed using workflow '{}'", mediapackage, workflowDefinitionID);
} catch (NotFoundException e) {
logger.warn("Specified capture event {} was not found", mediaPackageId);
} catch (UnauthorizedException e) {
throw new IllegalStateException(e);
} catch (SchedulerException e) {
logger.warn("Unable to get the workflow definition id from scheduler event {}: {}", mediaPackageId, ExceptionUtils.getMessage(e));
throw new IngestException(e);
}
} else {
logger.warn("Scheduler service not bound, unable to determine the workflow template to use for ingested mediapckage {}", mediapackage);
}
} else {
logger.info("Ingested mediapackage {} is processed using workflow template '{}', specified during ingest", mediapackage, workflowDefinitionID);
}
// Use the default workflow definition if nothing was determined
if (isBlank(workflowDefinitionID) && defaultWorkflowDefinionId != null) {
logger.info("Using default workflow definition '{}' to process ingested mediapackage {}", defaultWorkflowDefinionId, mediapackage);
workflowDefinitionID = defaultWorkflowDefinionId;
}
// Check if the workflow definition is valid
if (StringUtils.isNotBlank(workflowDefinitionID) && StringUtils.isNotBlank(defaultWorkflowDefinionId)) {
try {
workflowService.getWorkflowDefinitionById(workflowDefinitionID);
} catch (WorkflowDatabaseException e) {
throw new IngestException(e);
} catch (NotFoundException nfe) {
logger.warn("Workflow definition {} not found, using default workflow {} instead", workflowDefinitionID, defaultWorkflowDefinionId);
workflowDefinitionID = defaultWorkflowDefinionId;
}
}
// Have we been able to find a workflow definition id?
if (isBlank(workflowDefinitionID)) {
ingestStatistics.failed();
throw new IllegalStateException("Can not ingest a workflow without a workflow definition or an existing instance. No default definition is specified");
}
// Let's make sure the workflow definition exists
return workflowService.getWorkflowDefinitionById(workflowDefinitionID);
}
Aggregations