Search in sources :

Example 16 with WorkflowDatabaseException

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());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) 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 17 with WorkflowDatabaseException

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");
}
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 18 with WorkflowDatabaseException

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.");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity) 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 19 with WorkflowDatabaseException

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");
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpResponse(org.apache.http.HttpResponse) UrlEncodedFormEntity(org.apache.http.client.entity.UrlEncodedFormEntity)

Example 20 with WorkflowDatabaseException

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);
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) IngestException(org.opencastproject.ingest.api.IngestException)

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