use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class WorkflowExecutor method resetCallbacksForWorkflow.
/**
* @param workflowId the id of the workflow for which task callbacks are to be reset
* @throws ApplicationException if the workflow is in terminal state
*/
public void resetCallbacksForWorkflow(String workflowId) {
Workflow workflow = executionDAOFacade.getWorkflowById(workflowId, true);
if (workflow.getStatus().isTerminal()) {
throw new ApplicationException(CONFLICT, "Workflow is in terminal state. Status =" + workflow.getStatus());
}
// Get SIMPLE tasks in SCHEDULED state that have callbackAfterSeconds > 0 and set the callbackAfterSeconds to 0
workflow.getTasks().stream().filter(task -> !isSystemTask.test(task) && SCHEDULED.equals(task.getStatus()) && task.getCallbackAfterSeconds() > 0).forEach(task -> {
if (queueDAO.resetOffsetTime(QueueUtils.getQueueName(task), task.getTaskId())) {
task.setCallbackAfterSeconds(0);
executionDAOFacade.updateTask(task);
}
});
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class WorkflowExecutor method updateParentWorkflowRecursively.
private void updateParentWorkflowRecursively(Workflow workflow) {
if (StringUtils.isNotEmpty(workflow.getParentWorkflowId())) {
updateParentWorkflow(workflow);
decide(workflow.getParentWorkflowId());
Workflow parentWorkflow = executionDAOFacade.getWorkflowById(workflow.getParentWorkflowId(), true);
updateParentWorkflowRecursively(parentWorkflow);
}
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class WorkflowExecutor method terminateWorkflow.
public void terminateWorkflow(String workflowId, String reason) {
Workflow workflow = executionDAOFacade.getWorkflowById(workflowId, true);
if (WorkflowStatus.COMPLETED.equals(workflow.getStatus())) {
throw new ApplicationException(CONFLICT, "Cannot terminate a COMPLETED workflow.");
}
workflow.setStatus(WorkflowStatus.TERMINATED);
terminateWorkflow(workflow, reason, null);
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class WorkflowExecutor method completeWorkflow.
/**
* @param wf the workflow to be completed
* @throws ApplicationException if workflow is not in terminal state
*/
@VisibleForTesting
Workflow completeWorkflow(Workflow wf) {
LOGGER.debug("Completing workflow execution for {}", wf.getWorkflowId());
Workflow workflow = executionDAOFacade.getWorkflowById(wf.getWorkflowId(), false);
if (workflow.getStatus().equals(WorkflowStatus.COMPLETED)) {
// remove from the sweep queue
queueDAO.remove(DECIDER_QUEUE, workflow.getWorkflowId());
executionDAOFacade.removeFromPendingWorkflow(workflow.getWorkflowName(), workflow.getWorkflowId());
LOGGER.debug("Workflow: {} has already been completed.", wf.getWorkflowId());
return wf;
}
if (workflow.getStatus().isTerminal()) {
String msg = "Workflow is already in terminal state. Current status: " + workflow.getStatus();
throw new ApplicationException(CONFLICT, msg);
}
// This code will be removed in a future version.
if (workflow.getWorkflowDefinition() == null) {
workflow = metadataMapperService.populateWorkflowWithDefinitions(workflow);
}
deciderService.updateWorkflowOutput(wf, null);
workflow.setStatus(WorkflowStatus.COMPLETED);
workflow.setTasks(wf.getTasks());
workflow.setOutput(wf.getOutput());
workflow.setReasonForIncompletion(wf.getReasonForIncompletion());
workflow.setExternalOutputPayloadStoragePath(wf.getExternalOutputPayloadStoragePath());
executionDAOFacade.updateWorkflow(workflow);
LOGGER.debug("Completed workflow execution for {}", workflow.getWorkflowId());
workflowStatusListener.onWorkflowCompletedIfEnabled(workflow);
Monitors.recordWorkflowCompletion(workflow.getWorkflowName(), workflow.getEndTime() - workflow.getStartTime(), workflow.getOwnerApp());
if (StringUtils.isNotEmpty(workflow.getParentWorkflowId())) {
updateParentWorkflowTask(workflow);
decide(workflow.getParentWorkflowId());
}
executionLockService.releaseLock(workflow.getWorkflowId());
executionLockService.deleteLock(workflow.getWorkflowId());
return workflow;
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class WorkflowExecutor method resumeWorkflow.
/**
* @param workflowId
* @throws IllegalStateException
*/
public void resumeWorkflow(String workflowId) {
Workflow workflow = executionDAOFacade.getWorkflowById(workflowId, false);
if (!workflow.getStatus().equals(WorkflowStatus.PAUSED)) {
throw new IllegalStateException("The workflow " + workflowId + " is not PAUSED so cannot resume. " + "Current status is " + workflow.getStatus().name());
}
workflow.setStatus(WorkflowStatus.RUNNING);
executionDAOFacade.updateWorkflow(workflow);
decide(workflowId);
}
Aggregations