Search in sources :

Example 96 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflow.

private WorkflowDef createWorkflowWithInlineSubWorkflow() {
    WorkflowDef subWorkflowDef = createInlineSubWorkflow();
    WorkflowTask subWfTask = new WorkflowTask();
    subWfTask.setName("subWorkflowTask");
    subWfTask.setType(SUB_WORKFLOW.name());
    SubWorkflowParams swp = new SubWorkflowParams();
    swp.setName("does-not-existing-wf");
    swp.setWorkflowDefinition(subWorkflowDef);
    subWfTask.setSubWorkflowParam(swp);
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("test", "test value");
    inputParam.put("param1", "sub workflow input param1");
    inputParam.put("param2", subWorkflowDef.getVersion());
    subWfTask.setInputParameters(inputParam);
    subWfTask.setTaskReferenceName("sw1");
    WorkflowDef main = new WorkflowDef();
    main.setVersion(2);
    main.setSchemaVersion(2);
    main.setInputParameters(Arrays.asList("param1", "param2"));
    main.setName(WF_WITH_INLINE_SUB_WF);
    main.getTasks().add(subWfTask);
    return main;
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 97 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflowWithInlineSubWorkflow.

private void createWorkflowWithInlineSubWorkflowWithInlineSubWorkflow() {
    WorkflowDef subWorkflowDef = createWorkflowWithInlineSubWorkflow();
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("subWorkflowTask");
    workflowTask.setType(SUB_WORKFLOW.name());
    SubWorkflowParams swp = new SubWorkflowParams();
    swp.setName("dummy-name");
    swp.setWorkflowDef(subWorkflowDef);
    workflowTask.setSubWorkflowParam(swp);
    Map<String, Object> input = new HashMap<>();
    input.put("test", "test value");
    input.put("param1", "sub workflow task input param1");
    input.put("param2", 21);
    workflowTask.setInputParameters(input);
    workflowTask.setTaskReferenceName("sw2");
    WorkflowDef main = new WorkflowDef();
    main.setSchemaVersion(2);
    main.setInputParameters(Arrays.asList("param1", "param2"));
    main.setName(WF_WITH_INLINE_SUB_WF_WITH_INLINE_SUB_WF);
    main.getTasks().add(workflowTask);
    Map<String, Object> outputParameters = new HashMap<>();
    outputParameters.put("o1", "${workflow.input.param1}");
    outputParameters.put("o2", "${sw2.output.o2}");
    main.setOutputParameters(outputParameters);
    metadataService.updateWorkflowDef(Collections.singletonList(main));
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 98 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class WorkflowServiceTest method createInlineSubWorkflow.

private WorkflowDef createInlineSubWorkflow() {
    // create inline subworkflow
    WorkflowDef subWorkflowDef = new WorkflowDef();
    subWorkflowDef.setName("inline_sw_1");
    subWorkflowDef.setDescription(subWorkflowDef.getName());
    subWorkflowDef.setVersion(3);
    subWorkflowDef.setSchemaVersion(2);
    Map<String, Object> outputParameters = new HashMap<>();
    outputParameters.put("o1", "${workflow.input.param1}");
    outputParameters.put("o2", "${isw_t1.output.uuid}");
    subWorkflowDef.setOutputParameters(outputParameters);
    WorkflowTask wft1 = new WorkflowTask();
    wft1.setName("junit_task_1");
    wft1.setTaskReferenceName("isw_t1");
    subWorkflowDef.setTasks(Collections.singletonList(wft1));
    return subWorkflowDef;
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 99 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class RedisMetadataDAOTest method testDup.

@Test(expected = ApplicationException.class)
public void testDup() {
    WorkflowDef def = new WorkflowDef();
    def.setName("testDup");
    def.setVersion(1);
    redisMetadataDAO.createWorkflowDef(def);
    redisMetadataDAO.createWorkflowDef(def);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Test(org.junit.Test)

Example 100 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testRetry.

@Test
public void testRetry() {
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = taskDef.getRetryCount();
    taskDef.setRetryCount(1);
    int retryDelay = taskDef.getRetryDelaySeconds();
    taskDef.setRetryDelaySeconds(0);
    metadataService.updateTaskDef(taskDef);
    WorkflowDef workflowDef = metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2, 1);
    assertNotNull(workflowDef.getFailureWorkflow());
    assertFalse(StringUtils.isBlank(workflowDef.getFailureWorkflow()));
    String correlationId = "retry_test_" + UUID.randomUUID().toString();
    Map<String, Object> input = new HashMap<>();
    input.put("param1", "p1 value");
    input.put("param2", "p2 value");
    String workflowId = startOrLoadWorkflowExecution("retry", LINEAR_WORKFLOW_T1_T2, 1, correlationId, input, null, null);
    assertNotNull(workflowId);
    printTaskStatuses(workflowId, "initial");
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    Task task = getTask("junit_task_1");
    assertNotNull(task);
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    task = getTask("junit_task_1");
    assertNotNull(task);
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    printTaskStatuses(workflowId, "before retry");
    workflowExecutor.retry(workflowId, false);
    printTaskStatuses(workflowId, "after retry");
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(3, workflow.getTasks().size());
    task = getTask("junit_task_1");
    assertNotNull(task);
    assertEquals(workflowId, task.getWorkflowInstanceId());
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    task = getTask("junit_task_2");
    assertNotNull(task);
    assertEquals(workflowId, task.getWorkflowInstanceId());
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    assertEquals(3, workflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_1")).count());
    taskDef.setRetryCount(retryCount);
    taskDef.setRetryDelaySeconds(retryDelay);
    metadataService.updateTaskDef(taskDef);
    printTaskStatuses(workflowId, "final");
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Aggregations

WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)246 Test (org.junit.Test)185 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)172 Workflow (com.netflix.conductor.common.run.Workflow)128 HashMap (java.util.HashMap)122 Task (com.netflix.conductor.common.metadata.tasks.Task)100 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)71 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)49 ArrayList (java.util.ArrayList)42 LinkedList (java.util.LinkedList)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 List (java.util.List)33 UserTask (com.netflix.conductor.tests.utils.UserTask)28 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)20 ConstraintViolation (javax.validation.ConstraintViolation)14 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 ValidatorFactory (javax.validation.ValidatorFactory)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)12