Search in sources :

Example 61 with Workflow

use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.

the class TestDeciderService method testGetTaskInputV2Partial.

@Test
public void testGetTaskInputV2Partial() {
    Workflow workflow = createDefaultWorkflow();
    System.setProperty("EC2_INSTANCE", "i-123abcdef990");
    Map<String, Object> wfi = new HashMap<>();
    Map<String, Object> wfmap = new HashMap<>();
    wfmap.put("input", workflow.getInput());
    wfmap.put("output", workflow.getOutput());
    wfi.put("workflow", wfmap);
    workflow.getTasks().stream().map(Task::getReferenceTaskName).forEach(ref -> {
        Map<String, Object> taskInput = workflow.getTaskByRefName(ref).getInputData();
        Map<String, Object> taskOutput = workflow.getTaskByRefName(ref).getOutputData();
        Map<String, Object> io = new HashMap<>();
        io.put("input", taskInput);
        io.put("output", taskOutput);
        wfi.put(ref, io);
    });
    workflow.getWorkflowDefinition().setSchemaVersion(2);
    Map<String, Object> ip = new HashMap<>();
    ip.put("workflowInputParam", "${workflow.input.requestId}");
    ip.put("workfowOutputParam", "${workflow.output.name}");
    ip.put("taskOutputParam", "${task2.output.location}");
    ip.put("taskOutputParam2", "${task2.output.locationBad}");
    ip.put("taskOutputParam3", "${task3.output.location}");
    ip.put("constParam", "Some String value   &");
    ip.put("partial", "${task2.output.location}/something?host=${EC2_INSTANCE}");
    ip.put("jsonPathExtracted", "${workflow.output.names[*].year}");
    ip.put("secondName", "${workflow.output.names[1].name}");
    ip.put("concatenatedName", "The Band is: ${workflow.output.names[1].name}-\t${EC2_INSTANCE}");
    TaskDef taskDef = new TaskDef();
    taskDef.getInputTemplate().put("opname", "${workflow.output.name}");
    List<Object> listParams = new LinkedList<>();
    List<Object> listParams2 = new LinkedList<>();
    listParams2.add("${workflow.input.requestId}-10-${EC2_INSTANCE}");
    listParams.add(listParams2);
    Map<String, Object> map = new HashMap<>();
    map.put("name", "${workflow.output.names[0].name}");
    map.put("hasAwards", "${workflow.input.hasAwards}");
    listParams.add(map);
    taskDef.getInputTemplate().put("listValues", listParams);
    Map<String, Object> taskInput = parametersUtils.getTaskInput(ip, workflow, taskDef, null);
    assertNotNull(taskInput);
    assertTrue(taskInput.containsKey("workflowInputParam"));
    assertTrue(taskInput.containsKey("taskOutputParam"));
    assertTrue(taskInput.containsKey("taskOutputParam2"));
    assertTrue(taskInput.containsKey("taskOutputParam3"));
    assertNull(taskInput.get("taskOutputParam2"));
    assertNotNull(taskInput.get("jsonPathExtracted"));
    assertTrue(taskInput.get("jsonPathExtracted") instanceof List);
    assertNotNull(taskInput.get("secondName"));
    assertTrue(taskInput.get("secondName") instanceof String);
    assertEquals("The Doors", taskInput.get("secondName"));
    assertEquals("The Band is: The Doors-\ti-123abcdef990", taskInput.get("concatenatedName"));
    assertEquals("request id 001", taskInput.get("workflowInputParam"));
    assertEquals("http://location", taskInput.get("taskOutputParam"));
    assertNull(taskInput.get("taskOutputParam3"));
    assertNotNull(taskInput.get("partial"));
    assertEquals("http://location/something?host=i-123abcdef990", taskInput.get("partial"));
}
Also used : HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 62 with Workflow

use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.

the class TestDeciderService method createDefaultWorkflow.

private Workflow createDefaultWorkflow() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("TestDeciderService");
    workflowDef.setVersion(1);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.getInput().put("requestId", "request id 001");
    workflow.getInput().put("hasAwards", true);
    workflow.getInput().put("channelMapping", 5);
    Map<String, Object> name = new HashMap<>();
    name.put("name", "The Who");
    name.put("year", 1970);
    Map<String, Object> name2 = new HashMap<>();
    name2.put("name", "The Doors");
    name2.put("year", 1975);
    List<Object> names = new LinkedList<>();
    names.add(name);
    names.add(name2);
    workflow.getOutput().put("name", name);
    workflow.getOutput().put("names", names);
    workflow.getOutput().put("awards", 200);
    Task task = new Task();
    task.setReferenceTaskName("task2");
    task.getOutputData().put("location", "http://location");
    task.setStatus(Status.COMPLETED);
    Task task2 = new Task();
    task2.setReferenceTaskName("task3");
    task2.getOutputData().put("refId", "abcddef_1234_7890_aaffcc");
    task2.setStatus(Status.SCHEDULED);
    workflow.getTasks().add(task);
    workflow.getTasks().add(task2);
    return workflow;
}
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) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) LinkedList(java.util.LinkedList)

Example 63 with Workflow

use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.

the class ExecutionDAOFacade method getWorkflowById.

/**
 * Fetches the {@link Workflow} object from the data store given the id.
 * Attempts to fetch from {@link ExecutionDAO} first,
 * if not found, attempts to fetch from {@link IndexDAO}.
 *
 * @param workflowId   the id of the workflow to be fetched
 * @param includeTasks if true, fetches the {@link Task} data in the workflow.
 * @return the {@link Workflow} object
 * @throws ApplicationException if
 *                              <ul>
 *                              <li>no such {@link Workflow} is found</li>
 *                              <li>parsing the {@link Workflow} object fails</li>
 *                              </ul>
 */
public Workflow getWorkflowById(String workflowId, boolean includeTasks) {
    Workflow workflow = executionDAO.getWorkflow(workflowId, includeTasks);
    if (workflow == null) {
        LOGGER.debug("Workflow {} not found in executionDAO, checking indexDAO", workflowId);
        String json = indexDAO.get(workflowId, RAW_JSON_FIELD);
        if (json == null) {
            String errorMsg = String.format("No such workflow found by id: %s", workflowId);
            LOGGER.error(errorMsg);
            throw new ApplicationException(ApplicationException.Code.NOT_FOUND, errorMsg);
        }
        try {
            workflow = objectMapper.readValue(json, Workflow.class);
            if (!includeTasks) {
                workflow.getTasks().clear();
            }
        } catch (IOException e) {
            String errorMsg = String.format("Error reading workflow: %s", workflowId);
            LOGGER.error(errorMsg);
            throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, errorMsg, e);
        }
    }
    return workflow;
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Workflow(com.netflix.conductor.common.run.Workflow) IOException(java.io.IOException)

Example 64 with Workflow

use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.

the class ExecutionDAOFacade method removeWorkflowWithExpiry.

public void removeWorkflowWithExpiry(String workflowId, boolean archiveWorkflow, int ttlSeconds) {
    try {
        Workflow workflow = getWorkflowById(workflowId, true);
        removeWorkflowIndex(workflow, archiveWorkflow);
        // remove workflow from DAO with TTL
        try {
            executionDAO.removeWorkflowWithExpiry(workflowId, ttlSeconds);
        } catch (Exception ex) {
            Monitors.recordDaoError("executionDao", "removeWorkflow");
            throw ex;
        }
    } catch (ApplicationException ae) {
        throw ae;
    } catch (Exception e) {
        throw new ApplicationException(ApplicationException.Code.BACKEND_ERROR, "Error removing workflow: " + workflowId, e);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Workflow(com.netflix.conductor.common.run.Workflow) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

Example 65 with Workflow

use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.

the class TestDeciderService method testGetTaskByRef.

@Test
public void testGetTaskByRef() {
    Workflow workflow = new Workflow();
    Task t1 = new Task();
    t1.setReferenceTaskName("ref");
    t1.setSeq(0);
    t1.setStatus(Status.TIMED_OUT);
    Task t2 = new Task();
    t2.setReferenceTaskName("ref");
    t2.setSeq(1);
    t2.setStatus(Status.FAILED);
    Task t3 = new Task();
    t3.setReferenceTaskName("ref");
    t3.setSeq(2);
    t3.setStatus(Status.COMPLETED);
    workflow.getTasks().add(t1);
    workflow.getTasks().add(t2);
    workflow.getTasks().add(t3);
    Task task = workflow.getTaskByRefName("ref");
    assertNotNull(task);
    assertEquals(Status.COMPLETED, task.getStatus());
    assertEquals(t3.getSeq(), task.getSeq());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

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