Search in sources :

Example 36 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class UploadToS3 method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    String fileLocation = (String) task.getInputData().get("fileLocation");
    try {
        openImage(fileLocation);
        String s3BucketName = "image-processing-sandbox";
        String url = S3Utils.uploadToS3(fileLocation, Regions.US_EAST_1, s3BucketName);
        result.setStatus(TaskResult.Status.COMPLETED);
        result.addOutputData("fileLocation", url);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) IOException(java.io.IOException)

Example 37 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project orkesworkers by orkes-io.

the class WidgetShipping method execute.

@Override
public TaskResult execute(Task task) {
    TaskResult result = new TaskResult(task);
    String name = (String) task.getInputData().get("name");
    String street = (String) task.getInputData().get("street");
    String city = (String) task.getInputData().get("city");
    String state = (String) task.getInputData().get("state");
    String zip = (String) task.getInputData().get("zip");
    String fullAddress = name + "\n" + street + "\n" + city + ", " + state + " " + zip;
    try {
        // generate 16 number shipping label
        int eightdigit1 = (int) (Math.floor(Math.random() * 100000000));
        int eightdigit2 = (int) (Math.floor(Math.random() * 100000000));
        String tracking = Integer.toString(eightdigit1) + " " + Integer.toString(eightdigit2);
        // magic that creates the label and prints it in the shipping bay
        result.setStatus(TaskResult.Status.COMPLETED);
        result.addOutputData("fullAddress", fullAddress);
        result.addOutputData("trackingNumber", tracking);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
Also used : TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult)

Example 38 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class TestSimpleActionProcessor method testCompleteTask.

@Test
public void testCompleteTask() throws Exception {
    TaskDetails taskDetails = new TaskDetails();
    taskDetails.setWorkflowId("${workflowId}");
    taskDetails.setTaskRefName("testTask");
    taskDetails.getOutput().put("someNEKey", "${Message.someNEKey}");
    taskDetails.getOutput().put("someKey", "${Message.someKey}");
    taskDetails.getOutput().put("someNullKey", "${Message.someNullKey}");
    Action action = new Action();
    action.setAction(Type.complete_task);
    action.setComplete_task(taskDetails);
    String payloadJson = "{\"workflowId\":\"workflow_1\",\"Message\":{\"someKey\":\"someData\",\"someNullKey\":null}}";
    Object payload = objectMapper.readValue(payloadJson, Object.class);
    Task task = new Task();
    task.setReferenceTaskName("testTask");
    Workflow workflow = new Workflow();
    workflow.getTasks().add(task);
    when(workflowExecutor.getWorkflow(eq("workflow_1"), anyBoolean())).thenReturn(workflow);
    actionProcessor.execute(action, payload, "testEvent", "testMessage");
    ArgumentCaptor<TaskResult> argumentCaptor = ArgumentCaptor.forClass(TaskResult.class);
    verify(workflowExecutor).updateTask(argumentCaptor.capture());
    assertEquals(Status.COMPLETED, argumentCaptor.getValue().getStatus());
    assertEquals("testMessage", argumentCaptor.getValue().getOutputData().get("conductor.event.messageId"));
    assertEquals("testEvent", argumentCaptor.getValue().getOutputData().get("conductor.event.name"));
    assertEquals("workflow_1", argumentCaptor.getValue().getOutputData().get("workflowId"));
    assertEquals("testTask", argumentCaptor.getValue().getOutputData().get("taskRefName"));
    assertEquals("someData", argumentCaptor.getValue().getOutputData().get("someKey"));
    // Assert values not in message are evaluated to null
    assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNEKey"));
    // Assert null values from message are kept
    assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNullKey"));
    assertNull("testTask", argumentCaptor.getValue().getOutputData().get("someNullKey"));
}
Also used : Action(com.netflix.conductor.common.metadata.events.EventHandler.Action) Task(com.netflix.conductor.common.metadata.tasks.Task) TaskDetails(com.netflix.conductor.common.metadata.events.EventHandler.TaskDetails) StartWorkflow(com.netflix.conductor.common.metadata.events.EventHandler.StartWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 39 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testWaitTimeout.

@Test
public void testWaitTimeout() throws Exception {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("waitTimeout");
    taskDef.setTimeoutSeconds(2);
    taskDef.setRetryCount(1);
    taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_wait_timeout");
    workflowDef.setSchemaVersion(2);
    WorkflowTask waitWorkflowTask = new WorkflowTask();
    waitWorkflowTask.setWorkflowTaskType(TaskType.WAIT);
    waitWorkflowTask.setName("waitTimeout");
    waitWorkflowTask.setTaskReferenceName("wait0");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("junit_task_1");
    workflowTask.setTaskReferenceName("t1");
    workflowDef.getTasks().add(waitWorkflowTask);
    workflowDef.getTasks().add(workflowTask);
    metadataService.registerWorkflowDef(workflowDef);
    String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "", new HashMap<>(), null, null);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(1, workflow.getTasks().size());
    assertEquals(RUNNING, workflow.getStatus());
    // timeout the wait task and ensure it is retried
    Thread.sleep(3000);
    workflowExecutor.decide(workflowId);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    assertEquals(TIMED_OUT, workflow.getTasks().get(0).getStatus());
    assertEquals(IN_PROGRESS, workflow.getTasks().get(1).getStatus());
    Task waitTask = workflow.getTasks().get(1);
    assertEquals(TaskType.WAIT.name(), waitTask.getTaskType());
    waitTask.setStatus(COMPLETED);
    workflowExecutor.updateTask(new TaskResult(waitTask));
    Task task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("tasks:" + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
}
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) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 40 with TaskResult

use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testForkJoinWithOptionalSubworkflows.

@Test
public void testForkJoinWithOptionalSubworkflows() {
    createForkJoinWorkflowWithOptionalSubworkflowForks();
    Map<String, Object> workflowInput = new HashMap<>();
    workflowInput.put("param1", "p1 value");
    workflowInput.put("param2", "p2 value");
    String workflowId = startOrLoadWorkflowExecution(WORKFLOW_FORK_JOIN_OPTIONAL_SW, 1, "", workflowInput, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals("found " + workflow.getTasks().stream().map(Task::toString).collect(Collectors.toList()), 4, workflow.getTasks().size());
    // Simulating SystemTaskWorkerCoordinator to execute async system tasks
    String subWorkflowTaskId1 = workflow.getTaskByRefName("st1").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId1, 1);
    String subWorkflowTaskId2 = workflow.getTaskByRefName("st2").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId2, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    String subWorkflowId1 = workflow.getTasks().get(1).getSubWorkflowId();
    Workflow subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
    assertNotNull(subWorkflow1);
    assertEquals(RUNNING, subWorkflow1.getStatus());
    assertEquals(1, subWorkflow1.getTasks().size());
    String subWorkflowId2 = workflow.getTasks().get(2).getSubWorkflowId();
    Workflow subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
    assertNotNull(subWorkflow2);
    assertEquals(RUNNING, subWorkflow2.getStatus());
    assertEquals(1, subWorkflow2.getTasks().size());
    // fail sub-workflow 1
    Task task = new Task();
    while (!subWorkflowId1.equals(task.getWorkflowInstanceId())) {
        task = workflowExecutionService.poll("simple_task_in_sub_wf", "junit.worker");
    }
    assertNotNull(task);
    assertEquals("simple_task_in_sub_wf", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(subWorkflowId1, task.getWorkflowInstanceId());
    TaskResult taskResult = new TaskResult(task);
    taskResult.setReasonForIncompletion("fail task 1");
    taskResult.setStatus(TaskResult.Status.FAILED);
    workflowExecutionService.updateTask(taskResult);
    subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
    assertNotNull(subWorkflow1);
    assertEquals(WorkflowStatus.FAILED, subWorkflow1.getStatus());
    subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
    assertNotNull(subWorkflow2);
    assertEquals(RUNNING, subWorkflow2.getStatus());
    // Execute again to re-evaluate the Subworkflow task.
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId1, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
    assertEquals(IN_PROGRESS, workflow.getTasks().get(2).getStatus());
    // fail sub workflow 2
    task = new Task();
    while (!subWorkflowId2.equals(task.getWorkflowInstanceId())) {
        task = workflowExecutionService.poll("simple_task_in_sub_wf", "junit.worker");
    }
    assertNotNull(task);
    assertEquals("simple_task_in_sub_wf", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(subWorkflowId2, task.getWorkflowInstanceId());
    taskResult = new TaskResult(task);
    taskResult.setReasonForIncompletion("fail task 2");
    taskResult.setStatus(TaskResult.Status.FAILED);
    workflowExecutionService.updateTask(taskResult);
    subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
    assertNotNull(subWorkflow1);
    assertEquals(WorkflowStatus.FAILED, subWorkflow1.getStatus());
    subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
    assertNotNull(subWorkflow2);
    assertEquals(WorkflowStatus.FAILED, subWorkflow2.getStatus());
    // Execute again to re-evaluate the Subworkflow task.
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId2, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
    assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(2).getStatus());
}
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) HashMap(java.util.HashMap) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Aggregations

TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)66 Test (org.junit.Test)29 Task (com.netflix.conductor.common.metadata.tasks.Task)22 Workflow (com.netflix.conductor.common.run.Workflow)17 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)13 TaskClient (com.netflix.conductor.client.http.TaskClient)11 Worker (com.netflix.conductor.client.worker.Worker)11 CountDownLatch (java.util.concurrent.CountDownLatch)9 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)8 HashMap (java.util.HashMap)8 StartWorkflowRequest (com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest)7 UserTask (com.netflix.conductor.tests.utils.UserTask)7 Map (java.util.Map)7 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)6 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 List (java.util.List)5 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)4 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2