Search in sources :

Example 16 with WorkflowOperationInstanceImpl

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

the class WorkflowServiceImplTest method setupWorkflowInstanceImpl.

private WorkflowInstanceImpl setupWorkflowInstanceImpl(long id, String operation, WorkflowState state, Date startDate) throws ConfigurationException, MediaPackageException, NotFoundException, ServiceRegistryException {
    Job job = new JobImpl(id);
    job = serviceRegistry.updateJob(job);
    MediaPackage mediapackage = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mediapackage.setDate(startDate);
    mediapackage.setDuration(7200L);
    WorkflowOperationInstanceImpl workflowOperation = new WorkflowOperationInstanceImpl(operation, OperationState.PAUSED);
    workflowOperation.setId(id);
    List<WorkflowOperationInstance> workflowOperationInstanceList = new LinkedList<WorkflowOperationInstance>();
    workflowOperationInstanceList.add(workflowOperation);
    WorkflowInstanceImpl workflowInstanceImpl = new WorkflowInstanceImpl();
    workflowInstanceImpl.setMediaPackage(mediapackage);
    workflowInstanceImpl.setState(state);
    workflowInstanceImpl.setId(id);
    workflowInstanceImpl.setOperations(workflowOperationInstanceList);
    return workflowInstanceImpl;
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) JobImpl(org.opencastproject.job.api.JobImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) Job(org.opencastproject.job.api.Job) LinkedList(java.util.LinkedList)

Example 17 with WorkflowOperationInstanceImpl

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

the class CloneWorkflowOperationHandlerTest method getWorkflowOperationResult.

private WorkflowOperationResult getWorkflowOperationResult(MediaPackage mp, Map<String, String> configurations) throws WorkflowOperationException {
    // Add the mediapackage to a workflow instance
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", OperationState.RUNNING);
    operation.setTemplate("clone");
    operation.setState(OperationState.RUNNING);
    for (String key : configurations.keySet()) {
        operation.setConfiguration(key, configurations.get(key));
    }
    List<WorkflowOperationInstance> operationsList = new ArrayList<WorkflowOperationInstance>();
    operationsList.add(operation);
    workflowInstance.setOperations(operationsList);
    // Run the media package through the operation handler, ensuring that metadata gets added
    return operationHandler.start(workflowInstance, null);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Example 18 with WorkflowOperationInstanceImpl

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

the class CleanupWorkflowOperationHandlerTest method createWorkflowInstance.

private WorkflowInstance createWorkflowInstance(Map<String, String> configuration, MediaPackage mp) {
    WorkflowOperationInstance wfOpInst = new WorkflowOperationInstanceImpl();
    if (configuration != null) {
        for (String confKey : configuration.keySet()) {
            wfOpInst.setConfiguration(confKey, configuration.get(confKey));
        }
    }
    wfOpInst.setId(1L);
    wfOpInst.setState(WorkflowOperationInstance.OperationState.RUNNING);
    WorkflowInstance wfInst = EasyMock.createNiceMock(WorkflowInstance.class);
    EasyMock.expect(wfInst.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(wfInst.getCurrentOperation()).andReturn(wfOpInst).anyTimes();
    EasyMock.expect(wfInst.getOperations()).andReturn(Arrays.asList(wfOpInst)).anyTimes();
    EasyMock.replay(wfInst);
    return wfInst;
}
Also used : WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance)

Example 19 with WorkflowOperationInstanceImpl

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

the class WorkflowServiceImpl method handleOperationException.

/**
 * Callback for workflow operations that were throwing an exception. This implementation assumes that the operation
 * worker has already adjusted the current operation's state appropriately.
 *
 * @param workflow
 *          the workflow instance
 * @param operation
 *          the current workflow operation
 * @return the workflow instance
 * @throws WorkflowParsingException
 */
protected WorkflowInstance handleOperationException(WorkflowInstance workflow, WorkflowOperationInstance operation) throws WorkflowDatabaseException, WorkflowParsingException, UnauthorizedException {
    WorkflowOperationInstanceImpl currentOperation = (WorkflowOperationInstanceImpl) operation;
    int failedAttempt = currentOperation.getFailedAttempts() + 1;
    currentOperation.setFailedAttempts(failedAttempt);
    currentOperation.addToExecutionHistory(currentOperation.getId());
    // Operation was aborted by the user, after going into hold state
    if (ERROR_RESOLUTION_HANDLER_ID.equals(currentOperation.getTemplate()) && OperationState.FAILED.equals(currentOperation.getState())) {
        int position = currentOperation.getPosition();
        // Advance to operation that actually failed
        if (workflow.getOperations().size() > position + 1) {
            // This should always be true...
            currentOperation = (WorkflowOperationInstanceImpl) workflow.getOperations().get(position + 1);
            // It's currently in RETRY state, change to FAILED
            currentOperation.setState(OperationState.FAILED);
        }
        handleFailedOperation(workflow, currentOperation);
    } else if (currentOperation.getMaxAttempts() != -1 && failedAttempt == currentOperation.getMaxAttempts()) {
        handleFailedOperation(workflow, currentOperation);
    } else {
        switch(currentOperation.getRetryStrategy()) {
            case NONE:
                handleFailedOperation(workflow, currentOperation);
                break;
            case RETRY:
                currentOperation.setState(OperationState.RETRY);
                break;
            case HOLD:
                currentOperation.setState(OperationState.RETRY);
                List<WorkflowOperationInstance> operations = workflow.getOperations();
                WorkflowOperationDefinitionImpl errorResolutionDefinition = new WorkflowOperationDefinitionImpl(ERROR_RESOLUTION_HANDLER_ID, "Error Resolution Operation", "error", false);
                WorkflowOperationInstanceImpl errorResolutionInstance = new WorkflowOperationInstanceImpl(errorResolutionDefinition, currentOperation.getPosition());
                errorResolutionInstance.setExceptionHandlingWorkflow(currentOperation.getExceptionHandlingWorkflow());
                operations.add(currentOperation.getPosition(), errorResolutionInstance);
                workflow.setOperations(operations);
                break;
            default:
                break;
        }
    }
    return workflow;
}
Also used : WorkflowOperationDefinitionImpl(org.opencastproject.workflow.api.WorkflowOperationDefinitionImpl) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List)

Example 20 with WorkflowOperationInstanceImpl

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

the class InspectWorkflowOperationHandlerTest method getWorkflowOperationResult.

private WorkflowOperationResult getWorkflowOperationResult(MediaPackage mp) throws WorkflowOperationException {
    // Add the mediapackage to a workflow instance
    WorkflowInstanceImpl workflowInstance = new WorkflowInstanceImpl();
    workflowInstance.setId(1);
    workflowInstance.setState(WorkflowState.RUNNING);
    workflowInstance.setMediaPackage(mp);
    WorkflowOperationInstanceImpl operation = new WorkflowOperationInstanceImpl("op", OperationState.RUNNING);
    List<WorkflowOperationInstance> operationsList = new ArrayList<WorkflowOperationInstance>();
    operationsList.add(operation);
    workflowInstance.setOperations(operationsList);
    // Run the media package through the operation handler, ensuring that metadata gets added
    return operationHandler.start(workflowInstance, null);
}
Also used : WorkflowInstanceImpl(org.opencastproject.workflow.api.WorkflowInstanceImpl) WorkflowOperationInstance(org.opencastproject.workflow.api.WorkflowOperationInstance) ArrayList(java.util.ArrayList) WorkflowOperationInstanceImpl(org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)

Aggregations

WorkflowOperationInstanceImpl (org.opencastproject.workflow.api.WorkflowOperationInstanceImpl)35 WorkflowOperationInstance (org.opencastproject.workflow.api.WorkflowOperationInstance)33 ArrayList (java.util.ArrayList)32 WorkflowInstanceImpl (org.opencastproject.workflow.api.WorkflowInstanceImpl)31 Test (org.junit.Test)11 WorkflowOperationResult (org.opencastproject.workflow.api.WorkflowOperationResult)11 Before (org.junit.Before)7 MediaPackage (org.opencastproject.mediapackage.MediaPackage)7 MediaPackageBuilder (org.opencastproject.mediapackage.MediaPackageBuilder)7 URI (java.net.URI)4 WorkflowDefinitionImpl (org.opencastproject.workflow.api.WorkflowDefinitionImpl)4 WorkflowOperationException (org.opencastproject.workflow.api.WorkflowOperationException)4 Workspace (org.opencastproject.workspace.api.Workspace)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 Job (org.opencastproject.job.api.Job)3 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)3 File (java.io.File)2 Date (java.util.Date)2 Incident (org.opencastproject.job.api.Incident)2