Search in sources :

Example 1 with StartWorkflowRequest

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

the class AbstractProtoMapper method fromProto.

public StartWorkflowRequest fromProto(StartWorkflowRequestPb.StartWorkflowRequest from) {
    StartWorkflowRequest to = new StartWorkflowRequest();
    to.setName(from.getName());
    to.setVersion(from.getVersion());
    to.setCorrelationId(from.getCorrelationId());
    Map<String, Object> inputMap = new HashMap<String, Object>();
    for (Map.Entry<String, Value> pair : from.getInputMap().entrySet()) {
        inputMap.put(pair.getKey(), fromProto(pair.getValue()));
    }
    to.setInput(inputMap);
    to.setTaskToDomain(from.getTaskToDomainMap());
    if (from.hasWorkflowDef()) {
        to.setWorkflowDef(fromProto(from.getWorkflowDef()));
    }
    to.setExternalInputPayloadStoragePath(from.getExternalInputPayloadStoragePath());
    to.setPriority(from.getPriority());
    return to;
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) HashMap(java.util.HashMap) Value(com.google.protobuf.Value) Object(java.lang.Object) String(java.lang.String) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with StartWorkflowRequest

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

the class ExclusiveJoinEndToEndTest method testDecision1TrueAndDecision2Default.

@Test
public void testDecision1TrueAndDecision2Default() {
    workflowInput.put("decision_1", "true");
    workflowInput.put("decision_2", "null");
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(CONDUCTOR_WORKFLOW_DEF_NAME).withCorrelationId("").withInput(workflowInput).withVersion(1);
    String wfInstanceId = workflowClient.startWorkflow(startWorkflowRequest);
    String taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task1").getTaskId();
    taskOutput.put("taskReferenceName", "task1");
    TaskResult taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
    taskClient.updateTask(taskResult);
    taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task2").getTaskId();
    taskOutput.put("taskReferenceName", "task2");
    taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
    taskClient.updateTask(taskResult);
    Workflow workflow = workflowClient.getWorkflow(wfInstanceId, true);
    String taskReferenceName = workflow.getTaskByRefName("exclusiveJoin").getOutputData().get("taskReferenceName").toString();
    assertEquals("task2", taskReferenceName);
    assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 3 with StartWorkflowRequest

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

the class ExclusiveJoinEndToEndTest method testDecision1FalseAndDecision3Default.

@Test
public void testDecision1FalseAndDecision3Default() {
    workflowInput.put("decision_1", "false");
    workflowInput.put("decision_3", "null");
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(CONDUCTOR_WORKFLOW_DEF_NAME).withCorrelationId("").withInput(workflowInput).withVersion(1);
    String wfInstanceId = workflowClient.startWorkflow(startWorkflowRequest);
    String taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task1").getTaskId();
    taskOutput.put("taskReferenceName", "task1");
    TaskResult taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
    taskClient.updateTask(taskResult);
    taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task4").getTaskId();
    taskOutput.put("taskReferenceName", "task4");
    taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
    taskClient.updateTask(taskResult);
    Workflow workflow = workflowClient.getWorkflow(wfInstanceId, true);
    String taskReferenceName = workflow.getTaskByRefName("exclusiveJoin").getOutputData().get("taskReferenceName").toString();
    assertEquals("task4", taskReferenceName);
    assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 4 with StartWorkflowRequest

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

the class ExclusiveJoinEndToEndTest method testDecision1Default.

@Test
public void testDecision1Default() {
    workflowInput.put("decision_1", "null");
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(CONDUCTOR_WORKFLOW_DEF_NAME).withCorrelationId("").withInput(workflowInput).withVersion(1);
    String wfInstanceId = workflowClient.startWorkflow(startWorkflowRequest);
    String taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task1").getTaskId();
    taskOutput.put("taskReferenceName", "task1");
    TaskResult taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
    taskClient.updateTask(taskResult);
    Workflow workflow = workflowClient.getWorkflow(wfInstanceId, true);
    String taskReferenceName = workflow.getTaskByRefName("exclusiveJoin").getOutputData().get("taskReferenceName").toString();
    assertEquals("task1", taskReferenceName);
    assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 5 with StartWorkflowRequest

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

the class AbstractHttpEndToEndTest method testAll.

@Test
public void testAll() throws Exception {
    createAndRegisterTaskDefinitions("t", 5);
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    def.setOwnerEmail(DEFAULT_EMAIL_ADDRESS);
    WorkflowTask t0 = new WorkflowTask();
    t0.setName("t0");
    t0.setWorkflowTaskType(TaskType.SIMPLE);
    t0.setTaskReferenceName("t0");
    WorkflowTask t1 = new WorkflowTask();
    t1.setName("t1");
    t1.setWorkflowTaskType(TaskType.SIMPLE);
    t1.setTaskReferenceName("t1");
    def.getTasks().add(t0);
    def.getTasks().add(t1);
    metadataClient.registerWorkflowDef(def);
    WorkflowDef workflowDefinitionFromSystem = metadataClient.getWorkflowDef(def.getName(), null);
    assertNotNull(workflowDefinitionFromSystem);
    assertEquals(def, workflowDefinitionFromSystem);
    String correlationId = "test_corr_id";
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(def.getName()).withCorrelationId(correlationId).withPriority(50).withInput(new HashMap<>());
    String workflowId = workflowClient.startWorkflow(startWorkflowRequest);
    assertNotNull(workflowId);
    Workflow workflow = workflowClient.getWorkflow(workflowId, false);
    assertEquals(0, workflow.getTasks().size());
    assertEquals(workflowId, workflow.getWorkflowId());
    Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        List<Workflow> workflowList = workflowClient.getWorkflows(def.getName(), correlationId, false, false);
        assertEquals(1, workflowList.size());
        assertEquals(workflowId, workflowList.get(0).getWorkflowId());
    });
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
    assertEquals(workflowId, workflow.getWorkflowId());
    int queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(0).getTaskType());
    assertEquals(1, queueSize);
    List<String> runningIds = workflowClient.getRunningWorkflow(def.getName(), def.getVersion());
    assertNotNull(runningIds);
    assertEquals(1, runningIds.size());
    assertEquals(workflowId, runningIds.get(0));
    List<Task> polled = taskClient.batchPollTasksByTaskType("non existing task", "test", 1, 100);
    assertNotNull(polled);
    assertEquals(0, polled.size());
    polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
    assertNotNull(polled);
    assertEquals(1, polled.size());
    assertEquals(t0.getName(), polled.get(0).getTaskDefName());
    Task task = polled.get(0);
    Boolean acked = taskClient.ack(task.getTaskId(), "test");
    assertNotNull(acked);
    assertTrue(acked);
    task.getOutputData().put("key1", "value1");
    task.setStatus(Status.COMPLETED);
    taskClient.updateTask(new TaskResult(task));
    polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
    assertNotNull(polled);
    assertTrue(polled.toString(), polled.isEmpty());
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
    assertEquals(t1.getTaskReferenceName(), workflow.getTasks().get(1).getReferenceTaskName());
    assertEquals(Task.Status.COMPLETED, workflow.getTasks().get(0).getStatus());
    assertEquals(Task.Status.SCHEDULED, workflow.getTasks().get(1).getStatus());
    Task taskById = taskClient.getTaskDetails(task.getTaskId());
    assertNotNull(taskById);
    assertEquals(task.getTaskId(), taskById.getTaskId());
    queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(1).getTaskType());
    assertEquals(1, queueSize);
    List<Task> getTasks = taskClient.getPendingTasksByType(t0.getName(), null, 1);
    assertNotNull(getTasks);
    // getTasks only gives pending tasks
    assertEquals(0, getTasks.size());
    getTasks = taskClient.getPendingTasksByType(t1.getName(), null, 1);
    assertNotNull(getTasks);
    assertEquals(1, getTasks.size());
    Task pending = taskClient.getPendingTaskForWorkflow(workflowId, t1.getTaskReferenceName());
    assertNotNull(pending);
    assertEquals(t1.getTaskReferenceName(), pending.getReferenceTaskName());
    assertEquals(workflowId, pending.getWorkflowInstanceId());
    Thread.sleep(1000);
    SearchResult<WorkflowSummary> searchResult = workflowClient.search("workflowType='" + def.getName() + "'");
    assertNotNull(searchResult);
    assertEquals(1, searchResult.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
    SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
    assertNotNull(searchResultV2);
    assertEquals(1, searchResultV2.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResultV2.getResults().get(0).getWorkflowId());
    SearchResult<WorkflowSummary> searchResultAdvanced = workflowClient.search(0, 1, null, null, "workflowType='" + def.getName() + "'");
    assertNotNull(searchResultAdvanced);
    assertEquals(1, searchResultAdvanced.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResultAdvanced.getResults().get(0).getWorkflowId());
    SearchResult<Workflow> searchResultV2Advanced = workflowClient.searchV2(0, 1, null, null, "workflowType='" + def.getName() + "'");
    assertNotNull(searchResultV2Advanced);
    assertEquals(1, searchResultV2Advanced.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
    workflowClient.terminateWorkflow(workflowId, "terminate reason");
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.TERMINATED, workflow.getStatus());
    workflowClient.restart(workflowId, false);
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    workflowClient.skipTaskFromWorkflow(workflowId, "t1");
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Aggregations

StartWorkflowRequest (com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest)11 Test (org.junit.Test)9 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)7 Workflow (com.netflix.conductor.common.run.Workflow)7 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)3 Task (com.netflix.conductor.common.metadata.tasks.Task)2 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)2 WorkflowSummary (com.netflix.conductor.common.run.WorkflowSummary)2 HashMap (java.util.HashMap)2 Value (com.google.protobuf.Value)1 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)1 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)1 Object (java.lang.Object)1 String (java.lang.String)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Mockito.anyString (org.mockito.Mockito.anyString)1