Search in sources :

Example 71 with Workflow

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);
        }
    });
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) Arrays(java.util.Arrays) INVALID_INPUT(com.netflix.conductor.core.execution.ApplicationException.Code.INVALID_INPUT) NOT_FOUND(com.netflix.conductor.core.execution.ApplicationException.Code.NOT_FOUND) QueueUtils(com.netflix.conductor.core.utils.QueueUtils) LoggerFactory(org.slf4j.LoggerFactory) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) CANCELED(com.netflix.conductor.common.metadata.tasks.Task.Status.CANCELED) Task(com.netflix.conductor.common.metadata.tasks.Task) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) StringUtils(org.apache.commons.lang3.StringUtils) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) PollData(com.netflix.conductor.common.metadata.tasks.PollData) SKIPPED(com.netflix.conductor.common.metadata.tasks.Task.Status.SKIPPED) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Status.valueOf(com.netflix.conductor.common.metadata.tasks.Task.Status.valueOf) Trace(com.netflix.conductor.annotations.Trace) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) Objects(java.util.Objects) QueueDAO(com.netflix.conductor.dao.QueueDAO) List(java.util.List) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) Optional(java.util.Optional) Status(com.netflix.conductor.common.metadata.tasks.TaskResult.Status) Configuration(com.netflix.conductor.core.config.Configuration) CONFLICT(com.netflix.conductor.core.execution.ApplicationException.Code.CONFLICT) WorkflowContext(com.netflix.conductor.core.WorkflowContext) IDGenerator(com.netflix.conductor.core.utils.IDGenerator) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) SkipTaskRequest(com.netflix.conductor.common.metadata.workflow.SkipTaskRequest) FAILED_WITH_TERMINAL_ERROR(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED_WITH_TERMINAL_ERROR) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) Monitors(com.netflix.conductor.metrics.Monitors) TERMINATE(com.netflix.conductor.common.metadata.workflow.TaskType.TERMINATE) Preconditions(com.google.common.base.Preconditions) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow)

Example 72 with Workflow

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);
    }
}
Also used : SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow)

Example 73 with Workflow

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);
}
Also used : SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow)

Example 74 with Workflow

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;
}
Also used : SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 75 with 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);
}
Also used : SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow)

Aggregations

Workflow (com.netflix.conductor.common.run.Workflow)360 Test (org.junit.Test)259 Task (com.netflix.conductor.common.metadata.tasks.Task)246 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)206 HashMap (java.util.HashMap)154 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)149 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)130 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)97 UserTask (com.netflix.conductor.tests.utils.UserTask)73 LinkedList (java.util.LinkedList)57 Map (java.util.Map)55 List (java.util.List)54 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)52 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)50 Collections (java.util.Collections)36 Collectors (java.util.stream.Collectors)35 Logger (org.slf4j.Logger)35 LoggerFactory (org.slf4j.LoggerFactory)35 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)34 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)34