Search in sources :

Example 1 with DeciderService

use of com.netflix.conductor.core.execution.DeciderService in project conductor by Netflix.

the class DoWhileTest method setup.

@Before
public void setup() {
    workflow = Mockito.mock(Workflow.class);
    deciderService = Mockito.mock(DeciderService.class);
    metadataDAO = Mockito.mock(MetadataDAO.class);
    queueDAO = Mockito.mock(QueueDAO.class);
    parametersUtils = Mockito.mock(ParametersUtils.class);
    metadataMapperService = Mockito.mock(MetadataMapperService.class);
    workflowStatusListener = Mockito.mock(WorkflowStatusListener.class);
    executionDAOFacade = Mockito.mock(ExecutionDAOFacade.class);
    executionLockService = Mockito.mock(ExecutionLockService.class);
    config = Mockito.mock(Configuration.class);
    provider = spy(new WorkflowExecutor(deciderService, metadataDAO, queueDAO, metadataMapperService, workflowStatusListener, executionDAOFacade, config, executionLockService, parametersUtils));
    loopWorkflowTask1 = new WorkflowTask();
    loopWorkflowTask1.setTaskReferenceName("task1");
    loopWorkflowTask1.setName("task1");
    loopWorkflowTask2 = new WorkflowTask();
    loopWorkflowTask2.setTaskReferenceName("task2");
    loopWorkflowTask2.setName("task2");
    task1 = new Task();
    task1.setWorkflowTask(loopWorkflowTask1);
    task1.setReferenceTaskName("task1");
    task1.setStatus(Task.Status.COMPLETED);
    task1.setTaskType(TaskType.HTTP.name());
    task1.setInputData(new HashMap<>());
    task1.setIteration(1);
    task2 = new Task();
    task2.setWorkflowTask(loopWorkflowTask2);
    task2.setReferenceTaskName("task2");
    task2.setStatus(Task.Status.COMPLETED);
    task2.setTaskType(TaskType.HTTP.name());
    task2.setInputData(new HashMap<>());
    task2.setIteration(1);
    loopTask = new Task();
    loopTask.setReferenceTaskName("loopTask");
    loopTask.setTaskType(TaskType.DO_WHILE.name());
    loopTask.setInputData(new HashMap<>());
    loopTask.setIteration(1);
    loopWorkflowTask = new WorkflowTask();
    loopWorkflowTask.setTaskReferenceName("loopTask");
    loopWorkflowTask.setType(TaskType.DO_WHILE.name());
    loopWorkflowTask.setName("loopTask");
    loopWorkflowTask.setLoopCondition("if ($.loopTask['iteration'] < 1) { false; } else { true; }");
    loopWorkflowTask.setLoopOver(Arrays.asList(task1.getWorkflowTask(), task2.getWorkflowTask()));
    loopTask.setWorkflowTask(loopWorkflowTask);
    doWhile = new DoWhile();
    loopTaskDef = Mockito.mock(TaskDef.class);
    Mockito.doReturn(loopTaskDef).when(provider).getTaskDefinition(loopTask);
    Mockito.doReturn(task1).when(workflow).getTaskByRefName(task1.getReferenceTaskName());
    Mockito.doReturn(task2).when(workflow).getTaskByRefName(task2.getReferenceTaskName());
    Mockito.doReturn(task1).when(workflow).getTaskByRefName("task1__2");
    Mockito.doReturn(task2).when(workflow).getTaskByRefName("task2__2");
    Mockito.doReturn(new HashMap<>()).when(parametersUtils).getTaskInputV2(isA(Map.class), isA(Workflow.class), isA(String.class), isA(TaskDef.class));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Configuration(com.netflix.conductor.core.config.Configuration) DeciderService(com.netflix.conductor.core.execution.DeciderService) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) QueueDAO(com.netflix.conductor.dao.QueueDAO) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) WorkflowStatusListener(com.netflix.conductor.core.execution.WorkflowStatusListener) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) HashMap(java.util.HashMap) Map(java.util.Map) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 2 with DeciderService

use of com.netflix.conductor.core.execution.DeciderService in project conductor by Netflix.

the class DecisionTaskMapperTest method setUp.

@Before
public void setUp() {
    parametersUtils = new ParametersUtils();
    ip1 = new HashMap<>();
    ip1.put("p1", "${workflow.input.param1}");
    ip1.put("p2", "${workflow.input.param2}");
    ip1.put("case", "${workflow.input.case}");
    task1 = new WorkflowTask();
    task1.setName("Test1");
    task1.setInputParameters(ip1);
    task1.setTaskReferenceName("t1");
    task2 = new WorkflowTask();
    task2.setName("Test2");
    task2.setInputParameters(ip1);
    task2.setTaskReferenceName("t2");
    task3 = new WorkflowTask();
    task3.setName("Test3");
    task3.setInputParameters(ip1);
    task3.setTaskReferenceName("t3");
    deciderService = mock(DeciderService.class);
    decisionTaskMapper = new DecisionTaskMapper();
}
Also used : DeciderService(com.netflix.conductor.core.execution.DeciderService) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Before(org.junit.Before)

Example 3 with DeciderService

use of com.netflix.conductor.core.execution.DeciderService in project conductor by Netflix.

the class DoWhileTaskMapperTest method setup.

@Before
public void setup() {
    taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.DO_WHILE.name());
    taskToSchedule.setTaskReferenceName("Test");
    task1 = new Task();
    task1.setReferenceTaskName("task1");
    task2 = new Task();
    task2.setReferenceTaskName("task2");
    workflowTask1 = new WorkflowTask();
    workflowTask1.setTaskReferenceName("task1");
    workflowTask2 = new WorkflowTask();
    workflowTask2.setTaskReferenceName("task2");
    task1.setWorkflowTask(workflowTask1);
    task2.setWorkflowTask(workflowTask2);
    taskToSchedule.setLoopOver(Arrays.asList(task1.getWorkflowTask(), task2.getWorkflowTask()));
    taskToSchedule.setLoopCondition("if ($.second_task + $.first_task > 10) { false; } else { true; }");
    String taskId = IDGenerator.generate();
    workflowDef = new WorkflowDef();
    workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    deciderService = Mockito.mock(DeciderService.class);
    metadataDAO = Mockito.mock(MetadataDAO.class);
    taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withDeciderService(deciderService).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
}
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) DeciderService(com.netflix.conductor.core.execution.DeciderService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 4 with DeciderService

use of com.netflix.conductor.core.execution.DeciderService in project conductor by Netflix.

the class TestHttpTask method testOptional.

@Test
public void testOptional() {
    Task task = new Task();
    Input input = new Input();
    input.setUri("http://localhost:7009/failure");
    input.setMethod("GET");
    task.getInputData().put(HttpTask.REQUEST_PARAMETER_NAME, input);
    httpTask.start(workflow, task, workflowExecutor);
    assertEquals("Task output: " + task.getOutputData(), Task.Status.FAILED, task.getStatus());
    assertEquals(ERROR_RESPONSE, task.getReasonForIncompletion());
    assertTrue(!task.getStatus().isSuccessful());
    task.setStatus(Status.SCHEDULED);
    task.getInputData().remove(HttpTask.REQUEST_PARAMETER_NAME);
    task.setReferenceTaskName("t1");
    httpTask.start(workflow, task, workflowExecutor);
    assertEquals(Task.Status.FAILED, task.getStatus());
    assertEquals(HttpTask.MISSING_REQUEST, task.getReasonForIncompletion());
    assertTrue(!task.getStatus().isSuccessful());
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setOptional(true);
    workflowTask.setName("HTTP");
    workflowTask.setWorkflowTaskType(TaskType.USER_DEFINED);
    workflowTask.setTaskReferenceName("t1");
    WorkflowDef def = new WorkflowDef();
    def.getTasks().add(workflowTask);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(def);
    workflow.getTasks().add(task);
    MetadataDAO metadataDAO = mock(MetadataDAO.class);
    ExternalPayloadStorageUtils externalPayloadStorageUtils = mock(ExternalPayloadStorageUtils.class);
    ParametersUtils parametersUtils = mock(ParametersUtils.class);
    Configuration configuration = mock(Configuration.class);
    Map<String, TaskMapper> taskMappers = new HashMap<>();
    new DeciderService(parametersUtils, metadataDAO, externalPayloadStorageUtils, taskMappers, configuration).decide(workflow);
    System.out.println(workflow.getTasks());
    System.out.println(workflow.getStatus());
}
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) Configuration(com.netflix.conductor.core.config.Configuration) HashMap(java.util.HashMap) DeciderService(com.netflix.conductor.core.execution.DeciderService) Workflow(com.netflix.conductor.common.run.Workflow) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Input(com.netflix.conductor.contribs.http.HttpTask.Input) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) TaskMapper(com.netflix.conductor.core.execution.mapper.TaskMapper) Test(org.junit.Test)

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)4 DeciderService (com.netflix.conductor.core.execution.DeciderService)4 Task (com.netflix.conductor.common.metadata.tasks.Task)3 Workflow (com.netflix.conductor.common.run.Workflow)3 ParametersUtils (com.netflix.conductor.core.execution.ParametersUtils)3 MetadataDAO (com.netflix.conductor.dao.MetadataDAO)3 Before (org.junit.Before)3 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)2 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)2 Configuration (com.netflix.conductor.core.config.Configuration)2 HashMap (java.util.HashMap)2 Input (com.netflix.conductor.contribs.http.HttpTask.Input)1 WorkflowExecutor (com.netflix.conductor.core.execution.WorkflowExecutor)1 WorkflowStatusListener (com.netflix.conductor.core.execution.WorkflowStatusListener)1 TaskMapper (com.netflix.conductor.core.execution.mapper.TaskMapper)1 MetadataMapperService (com.netflix.conductor.core.metadata.MetadataMapperService)1 ExecutionDAOFacade (com.netflix.conductor.core.orchestration.ExecutionDAOFacade)1 ExternalPayloadStorageUtils (com.netflix.conductor.core.utils.ExternalPayloadStorageUtils)1 QueueDAO (com.netflix.conductor.dao.QueueDAO)1 ExecutionLockService (com.netflix.conductor.service.ExecutionLockService)1