Search in sources :

Example 41 with Workflow

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

the class TestWorkflowExecutor method testTerminateCompletedWorkflow.

@Test(expected = ApplicationException.class)
public void testTerminateCompletedWorkflow() {
    Workflow workflow = new Workflow();
    workflow.setWorkflowId("testTerminateTerminalWorkflow");
    workflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    workflowExecutor.terminateWorkflow(workflow.getWorkflowId(), "test terminating terminal workflow");
}
Also used : SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 42 with Workflow

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

the class WorkflowServiceImpl method getWorkflowStatus.

@Override
public void getWorkflowStatus(WorkflowServicePb.GetWorkflowStatusRequest req, StreamObserver<WorkflowPb.Workflow> response) {
    try {
        Workflow workflow = workflowService.getExecutionStatus(req.getWorkflowId(), req.getIncludeTasks());
        response.onNext(PROTO_MAPPER.toProto(workflow));
        response.onCompleted();
    } catch (Exception e) {
        GRPC_HELPER.onError(response, e);
    }
}
Also used : Workflow(com.netflix.conductor.common.run.Workflow) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 43 with Workflow

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

the class WorkflowServiceImplTest method searchV2Test.

@Test
public void searchV2Test() throws InterruptedException {
    CountDownLatch streamAlive = new CountDownLatch(1);
    AtomicReference<WorkflowServicePb.WorkflowSearchResult> result = new AtomicReference<>();
    SearchPb.Request req = SearchPb.Request.newBuilder().setStart(1).setSize(1).setSort("strings").setQuery("").setFreeText("").build();
    StreamObserver<WorkflowServicePb.WorkflowSearchResult> streamObserver = new StreamObserver<WorkflowServicePb.WorkflowSearchResult>() {

        @Override
        public void onNext(WorkflowServicePb.WorkflowSearchResult value) {
            result.set(value);
        }

        @Override
        public void onError(Throwable t) {
            streamAlive.countDown();
        }

        @Override
        public void onCompleted() {
            streamAlive.countDown();
        }
    };
    Workflow workflow = new Workflow();
    SearchResult<Workflow> searchResult = new SearchResult<>();
    searchResult.setTotalHits(1);
    searchResult.setResults(Collections.singletonList(workflow));
    when(workflowService.searchWorkflowsV2(1, 1, Collections.singletonList("strings"), "*", "")).thenReturn(searchResult);
    workflowServiceImpl.searchV2(req, streamObserver);
    streamAlive.await(10, TimeUnit.MILLISECONDS);
    WorkflowServicePb.WorkflowSearchResult workflowSearchResult = result.get();
    assertEquals(1, workflowSearchResult.getTotalHits());
    assertEquals(WorkflowPb.Workflow.newBuilder().build(), workflowSearchResult.getResultsList().get(0));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) SearchPb(com.netflix.conductor.grpc.SearchPb) Workflow(com.netflix.conductor.common.run.Workflow) AtomicReference(java.util.concurrent.atomic.AtomicReference) SearchResult(com.netflix.conductor.common.run.SearchResult) CountDownLatch(java.util.concurrent.CountDownLatch) WorkflowServicePb(com.netflix.conductor.grpc.WorkflowServicePb) Test(org.junit.Test)

Example 44 with Workflow

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

the class AbstractProtoMapper method fromProto.

public Workflow fromProto(WorkflowPb.Workflow from) {
    Workflow to = new Workflow();
    to.setStatus(fromProto(from.getStatus()));
    to.setEndTime(from.getEndTime());
    to.setWorkflowId(from.getWorkflowId());
    to.setParentWorkflowId(from.getParentWorkflowId());
    to.setParentWorkflowTaskId(from.getParentWorkflowTaskId());
    to.setTasks(from.getTasksList().stream().map(this::fromProto).collect(Collectors.toCollection(ArrayList::new)));
    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);
    Map<String, Object> outputMap = new HashMap<String, Object>();
    for (Map.Entry<String, Value> pair : from.getOutputMap().entrySet()) {
        outputMap.put(pair.getKey(), fromProto(pair.getValue()));
    }
    to.setOutput(outputMap);
    to.setWorkflowType(from.getWorkflowType());
    to.setVersion(from.getVersion());
    to.setCorrelationId(from.getCorrelationId());
    to.setReRunFromWorkflowId(from.getReRunFromWorkflowId());
    to.setReasonForIncompletion(from.getReasonForIncompletion());
    to.setSchemaVersion(from.getSchemaVersion());
    to.setEvent(from.getEvent());
    to.setTaskToDomain(from.getTaskToDomainMap());
    to.setFailedReferenceTaskNames(from.getFailedReferenceTaskNamesList().stream().collect(Collectors.toCollection(HashSet::new)));
    if (from.hasWorkflowDefinition()) {
        to.setWorkflowDefinition(fromProto(from.getWorkflowDefinition()));
    }
    to.setExternalInputPayloadStoragePath(from.getExternalInputPayloadStoragePath());
    to.setExternalOutputPayloadStoragePath(from.getExternalOutputPayloadStoragePath());
    to.setPriority(from.getPriority());
    Map<String, Object> variablesMap = new HashMap<String, Object>();
    for (Map.Entry<String, Value> pair : from.getVariablesMap().entrySet()) {
        variablesMap.put(pair.getKey(), fromProto(pair.getValue()));
    }
    to.setVariables(variablesMap);
    to.setLastRetriedTime(from.getLastRetriedTime());
    return to;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Value(com.google.protobuf.Value) Workflow(com.netflix.conductor.common.run.Workflow) Object(java.lang.Object) String(java.lang.String) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 45 with Workflow

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

the class AbstractProtoMapper method toProto.

public WorkflowPb.Workflow toProto(Workflow from) {
    WorkflowPb.Workflow.Builder to = WorkflowPb.Workflow.newBuilder();
    if (from.getStatus() != null) {
        to.setStatus(toProto(from.getStatus()));
    }
    to.setEndTime(from.getEndTime());
    if (from.getWorkflowId() != null) {
        to.setWorkflowId(from.getWorkflowId());
    }
    if (from.getParentWorkflowId() != null) {
        to.setParentWorkflowId(from.getParentWorkflowId());
    }
    if (from.getParentWorkflowTaskId() != null) {
        to.setParentWorkflowTaskId(from.getParentWorkflowTaskId());
    }
    for (Task elem : from.getTasks()) {
        to.addTasks(toProto(elem));
    }
    for (Map.Entry<String, Object> pair : from.getInput().entrySet()) {
        to.putInput(pair.getKey(), toProto(pair.getValue()));
    }
    for (Map.Entry<String, Object> pair : from.getOutput().entrySet()) {
        to.putOutput(pair.getKey(), toProto(pair.getValue()));
    }
    if (from.getWorkflowType() != null) {
        to.setWorkflowType(from.getWorkflowType());
    }
    to.setVersion(from.getVersion());
    if (from.getCorrelationId() != null) {
        to.setCorrelationId(from.getCorrelationId());
    }
    if (from.getReRunFromWorkflowId() != null) {
        to.setReRunFromWorkflowId(from.getReRunFromWorkflowId());
    }
    if (from.getReasonForIncompletion() != null) {
        to.setReasonForIncompletion(from.getReasonForIncompletion());
    }
    to.setSchemaVersion(from.getSchemaVersion());
    if (from.getEvent() != null) {
        to.setEvent(from.getEvent());
    }
    to.putAllTaskToDomain(from.getTaskToDomain());
    to.addAllFailedReferenceTaskNames(from.getFailedReferenceTaskNames());
    if (from.getWorkflowDefinition() != null) {
        to.setWorkflowDefinition(toProto(from.getWorkflowDefinition()));
    }
    if (from.getExternalInputPayloadStoragePath() != null) {
        to.setExternalInputPayloadStoragePath(from.getExternalInputPayloadStoragePath());
    }
    if (from.getExternalOutputPayloadStoragePath() != null) {
        to.setExternalOutputPayloadStoragePath(from.getExternalOutputPayloadStoragePath());
    }
    to.setPriority(from.getPriority());
    for (Map.Entry<String, Object> pair : from.getVariables().entrySet()) {
        to.putVariables(pair.getKey(), toProto(pair.getValue()));
    }
    to.setLastRetriedTime(from.getLastRetriedTime());
    return to.build();
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) DynamicForkJoinTask(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTask) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Workflow(com.netflix.conductor.common.run.Workflow) Object(java.lang.Object) String(java.lang.String) HashMap(java.util.HashMap) Map(java.util.Map)

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