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