Search in sources :

Example 11 with WorkflowDef

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

the class WorkflowDefValidatorTest method testWorkflowDefConstraintsDualEnvVariable.

@Test
public void testWorkflowDefConstraintsDualEnvVariable() {
    // name is null
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setSchemaVersion(2);
    workflowDef.setName("test_env");
    workflowDef.setOwnerEmail("owner@test.com");
    WorkflowTask workflowTask_1 = new WorkflowTask();
    workflowTask_1.setName("task_1");
    workflowTask_1.setTaskReferenceName("task_1");
    workflowTask_1.setType(TaskType.TASK_TYPE_SIMPLE);
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("taskId", "${CPEWF_TASK_ID} ${NETFLIX_STACK}");
    workflowTask_1.setInputParameters(inputParam);
    List<WorkflowTask> tasks = new ArrayList<>();
    tasks.add(workflowTask_1);
    workflowDef.setTasks(tasks);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
    assertEquals(0, result.size());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 12 with WorkflowDef

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

the class WorkflowDefValidatorTest method testWorkflowOwnerValidEmail.

@Test
public void testWorkflowOwnerValidEmail() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_env");
    workflowDef.setOwnerEmail("owner@test.com");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("t1");
    workflowTask.setWorkflowTaskType(TaskType.SIMPLE);
    workflowTask.setTaskReferenceName("t1");
    Map<String, Object> map = new HashMap<>();
    map.put("blabla", "");
    workflowTask.setInputParameters(map);
    workflowDef.getTasks().add(workflowTask);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
    assertEquals(0, result.size());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ConstraintViolation(javax.validation.ConstraintViolation) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 13 with WorkflowDef

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

the class SimpleTaskMapperTest method getMappedTasksException.

@Test
public void getMappedTasksException() throws Exception {
    // Given
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("simple_task");
    String taskId = IDGenerator.generate();
    String retriedTaskId = IDGenerator.generate();
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
    // then
    expectedException.expect(TerminateWorkflowException.class);
    expectedException.expectMessage(String.format("Invalid task. Task %s does not have a definition", taskToSchedule.getName()));
    // when
    simpleTaskMapper.getMappedTasks(taskMapperContext);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 14 with WorkflowDef

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

the class SubWorkflowTaskMapperTest method getMappedTasks.

@SuppressWarnings("unchecked")
@Test
public void getMappedTasks() {
    // Given
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflowInstance = new Workflow();
    workflowInstance.setWorkflowDefinition(workflowDef);
    WorkflowTask taskToSchedule = new WorkflowTask();
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName("Foo");
    subWorkflowParams.setVersion(2);
    taskToSchedule.setSubWorkflowParam(subWorkflowParams);
    Map<String, Object> taskInput = new HashMap<>();
    Map<String, String> taskToDomain = new HashMap<String, String>() {

        {
            put("*", "unittest");
        }
    };
    Map<String, Object> subWorkflowParamMap = new HashMap<>();
    subWorkflowParamMap.put("name", "FooWorkFlow");
    subWorkflowParamMap.put("version", 2);
    subWorkflowParamMap.put("taskToDomain", taskToDomain);
    when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), any(), any())).thenReturn(subWorkflowParamMap);
    // When
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflowInstance).withTaskToSchedule(taskToSchedule).withTaskInput(taskInput).withRetryCount(0).withTaskId(IDGenerator.generate()).withDeciderService(deciderService).build();
    List<Task> mappedTasks = subWorkflowTaskMapper.getMappedTasks(taskMapperContext);
    // Then
    assertTrue(!mappedTasks.isEmpty());
    assertEquals(1, mappedTasks.size());
    Task subWorkFlowTask = mappedTasks.get(0);
    assertEquals(Task.Status.SCHEDULED, subWorkFlowTask.getStatus());
    assertEquals(SubWorkflow.NAME, subWorkFlowTask.getTaskType());
    assertEquals(taskToDomain, subWorkFlowTask.getInputData().get("subWorkflowTaskToDomain"));
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 15 with WorkflowDef

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

the class TerminateTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.TASK_TYPE_TERMINATE);
    String taskId = IDGenerator.generate();
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = new TerminateTaskMapper(parametersUtils).getMappedTasks(taskMapperContext);
    Assert.assertNotNull(mappedTasks);
    Assert.assertEquals(1, mappedTasks.size());
    Assert.assertEquals(TaskType.TASK_TYPE_TERMINATE, mappedTasks.get(0).getTaskType());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) 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