Search in sources :

Example 36 with WorkflowDatabaseException

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

the class WorkflowServiceSolrIndex method remove.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.impl.WorkflowServiceIndex#remove(long)
 */
@Override
public void remove(long id) throws WorkflowDatabaseException, NotFoundException {
    try {
        synchronized (solrServer) {
            solrServer.deleteById(Long.toString(id));
            solrServer.commit();
        }
    } catch (Exception e) {
        throw new WorkflowDatabaseException(e);
    }
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) ServiceException(org.osgi.framework.ServiceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) ServiceRegistryException(org.opencastproject.serviceregistry.api.ServiceRegistryException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) WorkflowParsingException(org.opencastproject.workflow.api.WorkflowParsingException) NotFoundException(org.opencastproject.util.NotFoundException) MalformedURLException(java.net.MalformedURLException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) IOException(java.io.IOException)

Example 37 with WorkflowDatabaseException

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

the class WorkflowRestService method getConfigurationPanel.

/**
 * Returns the workflow configuration panel HTML snippet for the workflow definition specified by
 *
 * @param definitionId
 * @return config panel HTML snippet
 */
@GET
@Produces(MediaType.TEXT_HTML)
@Path("configurationPanel")
@RestQuery(name = "configpanel", description = "Get the configuration panel for a specific workflow", returnDescription = "The HTML workflow configuration panel", restParameters = { @RestParameter(name = "definitionId", isRequired = false, description = "The workflow definition identifier", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The workflow configuration panel.") })
public Response getConfigurationPanel(@QueryParam("definitionId") String definitionId) throws NotFoundException {
    WorkflowDefinition def = null;
    try {
        def = service.getWorkflowDefinitionById(definitionId);
        String out = def.getConfigurationPanel();
        return Response.ok(out).build();
    } catch (WorkflowDatabaseException e) {
        throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) WebApplicationException(javax.ws.rs.WebApplicationException) WorkflowDefinition(org.opencastproject.workflow.api.WorkflowDefinition) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Example 38 with WorkflowDatabaseException

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

the class WorkflowServiceImpl method handleOperationResult.

/**
 * Callback for workflow operation handlers that executed and finished without exception. This implementation assumes
 * that the operation worker has already adjusted the current operation's state appropriately.
 *
 * @param workflow
 *          the workflow instance
 * @param result
 *          the workflow operation result
 * @return the workflow instance
 * @throws WorkflowDatabaseException
 *           if updating the workflow fails
 */
protected WorkflowInstance handleOperationResult(WorkflowInstance workflow, WorkflowOperationResult result) throws WorkflowDatabaseException {
    // Get the operation and its handler
    WorkflowOperationInstanceImpl currentOperation = (WorkflowOperationInstanceImpl) workflow.getCurrentOperation();
    WorkflowOperationHandler handler = getWorkflowOperationHandler(currentOperation.getTemplate());
    // Create an operation result for the lazy or else update the workflow's media package
    if (result == null) {
        logger.warn("Handling a null operation result for workflow %s in operation %s", workflow.getId(), currentOperation.getTemplate());
        result = new WorkflowOperationResultImpl(workflow.getMediaPackage(), null, Action.CONTINUE, 0);
    } else {
        MediaPackage mp = result.getMediaPackage();
        if (mp != null) {
            workflow.setMediaPackage(mp);
        }
    }
    // The action to take
    Action action = result.getAction();
    // Update the workflow configuration. Update the reference to the current operation as well, since the workflow has
    // been serialized and deserialized in the meantime.
    int currentOperationPosition = currentOperation.getPosition();
    workflow = updateConfiguration(workflow, result.getProperties());
    currentOperation = (WorkflowOperationInstanceImpl) workflow.getOperations().get(currentOperationPosition);
    // Adjust workflow statistics
    currentOperation.setTimeInQueue(result.getTimeInQueue());
    // Adjust the operation state
    switch(action) {
        case CONTINUE:
            currentOperation.setState(OperationState.SUCCEEDED);
            break;
        case PAUSE:
            if (!(handler instanceof ResumableWorkflowOperationHandler)) {
                throw new IllegalStateException("Operation " + currentOperation.getTemplate() + " is not resumable");
            }
            // Set abortable and continuable to default values
            currentOperation.setContinuable(result.allowsContinue());
            currentOperation.setAbortable(result.allowsAbort());
            ResumableWorkflowOperationHandler resumableHandler = (ResumableWorkflowOperationHandler) handler;
            try {
                String url = resumableHandler.getHoldStateUserInterfaceURL(workflow);
                if (url != null) {
                    String holdActionTitle = resumableHandler.getHoldActionTitle();
                    currentOperation.setHoldActionTitle(holdActionTitle);
                    currentOperation.setHoldStateUserInterfaceUrl(url);
                }
            } catch (WorkflowOperationException e) {
                logger.warn(e, "unable to replace workflow ID in the hold state URL");
            }
            workflow.setState(PAUSED);
            currentOperation.setState(OperationState.PAUSED);
            break;
        case SKIP:
            currentOperation.setState(OperationState.SKIPPED);
            break;
        default:
            throw new IllegalStateException("Unknown action '" + action + "' returned");
    }
    if (ERROR_RESOLUTION_HANDLER_ID.equals(currentOperation.getTemplate()) && result.getAction() == Action.CONTINUE) {
        Map<String, String> resultProperties = result.getProperties();
        if (resultProperties == null || StringUtils.isBlank(resultProperties.get(RETRY_STRATEGY)))
            throw new WorkflowDatabaseException("Retry strategy not present in properties!");
        RetryStrategy retryStrategy = RetryStrategy.valueOf(resultProperties.get(RETRY_STRATEGY));
        switch(retryStrategy) {
            case NONE:
                handleFailedOperation(workflow, workflow.getCurrentOperation());
                break;
            case RETRY:
                currentOperation = (WorkflowOperationInstanceImpl) workflow.getCurrentOperation();
                break;
            default:
                throw new WorkflowDatabaseException("Retry strategy not implemented yet!");
        }
    }
    return workflow;
}
Also used : Action(org.opencastproject.workflow.api.WorkflowOperationResult.Action) ResumableWorkflowOperationHandler(org.opencastproject.workflow.api.ResumableWorkflowOperationHandler) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) WorkflowOperationResultImpl(org.opencastproject.workflow.api.WorkflowOperationResultImpl) Collections.mkString(org.opencastproject.util.data.Collections.mkString) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) ResumableWorkflowOperationHandler(org.opencastproject.workflow.api.ResumableWorkflowOperationHandler) WorkflowOperationHandler(org.opencastproject.workflow.api.WorkflowOperationHandler) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationException(org.opencastproject.workflow.api.WorkflowOperationException) RetryStrategy(org.opencastproject.workflow.api.RetryStrategy)

Example 39 with WorkflowDatabaseException

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

the class WorkflowServiceRemoteImpl method suspend.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowService#suspend(long)
 */
@Override
public WorkflowInstance suspend(long workflowInstanceId) throws WorkflowDatabaseException, NotFoundException {
    HttpPost post = new HttpPost("/suspend");
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("id", Long.toString(workflowInstanceId)));
    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, SC_NOT_FOUND);
    try {
        if (response != null) {
            if (response.getStatusLine().getStatusCode() == SC_NOT_FOUND) {
                throw new NotFoundException("Workflow instance with id='" + workflowInstanceId + "' not found");
            } else {
                logger.info("Workflow '{}' suspended", workflowInstanceId);
                return WorkflowParser.parseWorkflowInstance(response.getEntity().getContent());
            }
        }
    } catch (NotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new WorkflowDatabaseException(e);
    } finally {
        closeConnection(response);
    }
    throw new WorkflowDatabaseException("Unable to suspend workflow instance " + workflowInstanceId);
}
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) 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 40 with WorkflowDatabaseException

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

the class WorkflowServiceRemoteImpl method unregisterWorkflowDefinition.

/**
 * {@inheritDoc}
 *
 * @see org.opencastproject.workflow.api.WorkflowService#unregisterWorkflowDefinition(java.lang.String)
 */
@Override
public void unregisterWorkflowDefinition(String workflowDefinitionId) throws NotFoundException, WorkflowDatabaseException {
    HttpDelete delete = new HttpDelete("/definition/" + workflowDefinitionId);
    HttpResponse response = getResponse(delete, SC_NO_CONTENT, SC_NOT_FOUND);
    try {
        if (response != null) {
            if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
                throw new NotFoundException("Workflow definition '" + workflowDefinitionId + "' not found.");
            } else {
                logger.info("Workflow definition '{}' unregistered", workflowDefinitionId);
                return;
            }
        }
    } finally {
        closeConnection(response);
    }
    throw new WorkflowDatabaseException("Unable to delete workflow definition '" + workflowDefinitionId + "'");
}
Also used : WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) HttpDelete(org.apache.http.client.methods.HttpDelete) HttpResponse(org.apache.http.HttpResponse) NotFoundException(org.opencastproject.util.NotFoundException)

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