Search in sources :

Example 6 with StartWorkflowRequest

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

the class WorkflowServiceTest method testStartWorkflow.

@Test
public void testStartWorkflow() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test");
    workflowDef.setVersion(1);
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();
    startWorkflowRequest.setName("test");
    startWorkflowRequest.setVersion(1);
    Map<String, Object> input = new HashMap<>();
    input.put("1", "abc");
    startWorkflowRequest.setInput(input);
    String workflowID = "w112";
    when(mockMetadata.getWorkflowDef(anyString(), anyInt())).thenReturn(workflowDef);
    when(mockWorkflowExecutor.startWorkflow(anyString(), anyInt(), isNull(), anyInt(), anyMap(), isNull(), isNull(), anyMap())).thenReturn(workflowID);
    assertEquals("w112", workflowService.startWorkflow(startWorkflowRequest));
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Example 7 with StartWorkflowRequest

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

the class WorkflowServiceImpl method startWorkflow.

@Override
public void startWorkflow(StartWorkflowRequestPb.StartWorkflowRequest pbRequest, StreamObserver<WorkflowServicePb.StartWorkflowResponse> response) {
    // TODO: better handling of optional 'version'
    final StartWorkflowRequest request = PROTO_MAPPER.fromProto(pbRequest);
    try {
        String id = workflowService.startWorkflow(pbRequest.getName(), GRPC_HELPER.optional(request.getVersion()), request.getCorrelationId(), request.getPriority(), request.getInput(), request.getExternalInputPayloadStoragePath(), request.getTaskToDomain(), request.getWorkflowDef());
        response.onNext(WorkflowServicePb.StartWorkflowResponse.newBuilder().setWorkflowId(id).build());
        response.onCompleted();
    } catch (ApplicationException ae) {
        if (ae.getCode().equals(ApplicationException.Code.NOT_FOUND)) {
            response.onError(Status.NOT_FOUND.withDescription("No such workflow found by name=" + request.getName()).asRuntimeException());
        } else {
            GRPC_HELPER.onError(response, ae);
        }
    }
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 8 with StartWorkflowRequest

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

the class WorkflowResourceTest method testStartWorkflow.

@Test
public void testStartWorkflow() {
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();
    startWorkflowRequest.setName("w123");
    Map<String, Object> input = new HashMap<>();
    input.put("1", "abc");
    startWorkflowRequest.setInput(input);
    String workflowID = "w112";
    when(mockWorkflowService.startWorkflow(any(StartWorkflowRequest.class))).thenReturn(workflowID);
    assertEquals("w112", workflowResource.startWorkflow(startWorkflowRequest));
}
Also used : StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with StartWorkflowRequest

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

the class AbstractGrpcEndToEndTest method testAll.

@Test
public void testAll() throws Exception {
    assertNotNull(taskClient);
    List<TaskDef> defs = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        TaskDef def = new TaskDef("t" + i, "task " + i, DEFAULT_EMAIL_ADDRESS, 3, 60, 60);
        def.setTimeoutPolicy(TimeoutPolicy.RETRY);
        defs.add(def);
    }
    metadataClient.registerTaskDefs(defs);
    for (int i = 0; i < 5; i++) {
        final String taskName = "t" + i;
        TaskDef def = metadataClient.getTaskDef(taskName);
        assertNotNull(def);
        assertEquals(taskName, def.getName());
    }
    WorkflowDef def = createWorkflowDefinition("test");
    WorkflowTask t0 = createWorkflowTask("t0");
    WorkflowTask t1 = createWorkflowTask("t1");
    def.getTasks().add(t0);
    def.getTasks().add(t1);
    metadataClient.registerWorkflowDef(def);
    WorkflowDef found = metadataClient.getWorkflowDef(def.getName(), null);
    assertNotNull(found);
    assertEquals(def, found);
    String correlationId = "test_corr_id";
    StartWorkflowRequest startWf = new StartWorkflowRequest();
    startWf.setName(def.getName());
    startWf.setCorrelationId(correlationId);
    String workflowId = workflowClient.startWorkflow(startWf);
    assertNotNull(workflowId);
    System.out.println("Started workflow id=" + workflowId);
    Workflow wf = workflowClient.getWorkflow(workflowId, false);
    assertEquals(0, wf.getTasks().size());
    assertEquals(workflowId, wf.getWorkflowId());
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
    assertEquals(1, wf.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
    assertEquals(workflowId, wf.getWorkflowId());
    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());
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
    assertEquals(2, wf.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
    assertEquals(t1.getTaskReferenceName(), wf.getTasks().get(1).getReferenceTaskName());
    assertEquals(Status.COMPLETED, wf.getTasks().get(0).getStatus());
    assertEquals(Status.SCHEDULED, wf.getTasks().get(1).getStatus());
    Task taskById = taskClient.getTaskDetails(task.getTaskId());
    assertNotNull(taskById);
    assertEquals(task.getTaskId(), taskById.getTaskId());
    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(wf.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
    SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
    assertNotNull(searchResultV2);
    assertEquals(1, searchResultV2.getTotalHits());
    assertEquals(wf.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(wf.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(wf.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
    workflowClient.terminateWorkflow(workflowId, "terminate reason");
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.TERMINATED, wf.getStatus());
    workflowClient.restart(workflowId, false);
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
    assertEquals(1, wf.getTasks().size());
}
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) LinkedList(java.util.LinkedList) StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 10 with StartWorkflowRequest

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

the class ExclusiveJoinEndToEndTest method testDecision1FalseAndDecision3True.

@Test
public void testDecision1FalseAndDecision3True() {
    workflowInput.put("decision_1", "false");
    workflowInput.put("decision_3", "true");
    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);
    taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task5").getTaskId();
    taskOutput.put("taskReferenceName", "task5");
    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("task5", 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)

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