-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #154 from orkes-io/workflow_state_update_api
Workflow state update api
- Loading branch information
Showing
7 changed files
with
257 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/io/orkes/conductor/client/model/WorkflowStateUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright 2024 Orkes, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package io.orkes.conductor.client.model; | ||
|
||
import java.util.Map; | ||
|
||
import com.netflix.conductor.common.metadata.tasks.TaskResult; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class WorkflowStateUpdate { | ||
private String taskReferenceName; | ||
private Map<String, Object> variables; | ||
private TaskResult taskResult; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/test/java/io/orkes/conductor/client/api/WorkflowStateUpdateTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2024 Orkes, Inc. | ||
* <p> | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
package io.orkes.conductor.client.api; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.netflix.conductor.common.metadata.tasks.Task; | ||
import com.netflix.conductor.common.metadata.tasks.TaskResult; | ||
import com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest; | ||
import com.netflix.conductor.common.run.Workflow; | ||
|
||
import io.orkes.conductor.client.WorkflowClient; | ||
import io.orkes.conductor.client.model.WorkflowStateUpdate; | ||
import io.orkes.conductor.common.model.WorkflowRun; | ||
|
||
import lombok.SneakyThrows; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class WorkflowStateUpdateTests extends ClientTest { | ||
|
||
private static WorkflowClient workflowClient; | ||
|
||
@BeforeAll | ||
public static void init() { | ||
workflowClient = orkesClients.getWorkflowClient(); | ||
} | ||
|
||
@SneakyThrows | ||
public String startWorkflow() { | ||
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); | ||
startWorkflowRequest.setName("sync_task_variable_updates"); | ||
startWorkflowRequest.setVersion(1); | ||
var run = workflowClient.executeWorkflow(startWorkflowRequest, "wait_task_ref"); | ||
return run.get(10, TimeUnit.SECONDS) | ||
.getWorkflowId(); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
String workflowId = startWorkflow(); | ||
System.out.println(workflowId); | ||
|
||
TaskResult taskResult = new TaskResult(); | ||
taskResult.setOutputData(Map.of("a", "b")); | ||
|
||
WorkflowStateUpdate request = new WorkflowStateUpdate(); | ||
request.setTaskReferenceName("wait_task_ref"); | ||
request.setTaskResult(taskResult); | ||
|
||
request.setVariables(Map.of("case", "case1")); | ||
|
||
WorkflowRun workflowRun = workflowClient.updateWorkflow(workflowId, List.of("wait_task_ref_1", "wait_task_ref_2"), 10, request); | ||
|
||
System.out.println(workflowRun); | ||
System.out.println(workflowRun.getStatus()); | ||
System.out.println(workflowRun.getTasks() | ||
.stream() | ||
.map(task -> task.getReferenceTaskName() + ":" + task.getStatus()) | ||
.collect(Collectors.toList())); | ||
|
||
request = new WorkflowStateUpdate(); | ||
request.setTaskReferenceName("wait_task_ref_2"); | ||
request.setTaskResult(taskResult); | ||
workflowRun = workflowClient.updateWorkflow(workflowId, List.of(), 10, request); | ||
|
||
assertEquals(Workflow.WorkflowStatus.COMPLETED, workflowRun.getStatus()); | ||
Set<Task.Status> allTaskStatus = workflowRun.getTasks() | ||
.stream() | ||
.map(t -> t.getStatus()) | ||
.collect(Collectors.toSet()); | ||
assertEquals(1, allTaskStatus.size()); | ||
assertEquals(Task.Status.COMPLETED, allTaskStatus.iterator().next()); | ||
|
||
System.out.println(workflowRun.getStatus()); | ||
System.out.println(workflowRun.getTasks() | ||
.stream() | ||
.map(task -> task.getReferenceTaskName() + ":" + task.getStatus()) | ||
.collect(Collectors.toList())); | ||
|
||
} | ||
} |