From 23139a8e8961720aeee9030cf14523f4621b0174 Mon Sep 17 00:00:00 2001 From: James Stuart Milne Date: Tue, 10 Dec 2024 19:20:45 -0300 Subject: [PATCH 1/3] fix: asume a common type --- ui/src/pages/execution/TaskDetails.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/src/pages/execution/TaskDetails.jsx b/ui/src/pages/execution/TaskDetails.jsx index 8cbfa192f..022894d8e 100644 --- a/ui/src/pages/execution/TaskDetails.jsx +++ b/ui/src/pages/execution/TaskDetails.jsx @@ -48,9 +48,9 @@ export default function TaskDetails({ const selectedTaskRefName = data?.data?.task?.executionData?.status === "PENDING" ? pendingTaskSelection(data?.data?.task)?.workflowTask - ?.taskReferenceName - : taskWithLatestIteration(execution?.tasks, data?.id) - ?.referenceTaskName; + ?.taskReferenceName + : taskWithLatestIteration(execution?.tasks, { ref: data.id }) + ?.referenceTaskName; setSelectedNode(data); setSelectedTask({ ref: selectedTaskRefName }); }} From 6696162fda9b06b9502893fd821d9a68c4e4aedb Mon Sep 17 00:00:00 2001 From: James Stuart Milne Date: Tue, 10 Dec 2024 19:22:14 -0300 Subject: [PATCH 2/3] fix: find task by id or taskReferenceName --- ui/src/pages/execution/RightPanel.jsx | 2 +- ui/src/utils/helpers.js | 28 ++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/ui/src/pages/execution/RightPanel.jsx b/ui/src/pages/execution/RightPanel.jsx index b3dc7b79e..839a2692c 100644 --- a/ui/src/pages/execution/RightPanel.jsx +++ b/ui/src/pages/execution/RightPanel.jsx @@ -46,7 +46,7 @@ export default function RightPanel({ const taskResult = selectedNode?.data?.task?.executionData?.status === "PENDING" ? pendingTaskSelection(selectedNode?.data?.task) - : taskWithLatestIteration(execution?.tasks, selectedTask?.ref); + : taskWithLatestIteration(execution?.tasks, selectedTask); const dfOptions = useMemo( () => dag && dag.getSiblings(selectedTask), diff --git a/ui/src/utils/helpers.js b/ui/src/utils/helpers.js index 407732f63..405ba06da 100644 --- a/ui/src/utils/helpers.js +++ b/ui/src/utils/helpers.js @@ -48,7 +48,7 @@ export function astToQuery(node) { return `${wrapper ? "(" : ""}${clauses.join(` ${combinator} `)}${ wrapper ? ")" : "" - }`; + }`; } else { return ""; } @@ -99,16 +99,24 @@ export function getBasename() { return _.isEmpty(basename) ? "/" : basename; } -export const taskWithLatestIteration = (tasksList, taskReferenceName) => { - const filteredTasks = tasksList?.filter( - (task) => - task?.workflowTask?.taskReferenceName === taskReferenceName || - task?.referenceTaskName === taskReferenceName - ); +export const taskWithLatestIteration = (tasksList = [], selectedTask) => { + const taskReferenceName = selectedTask?.ref; + + const findTaskByReferenceName = (task) => + task?.workflowTask?.taskReferenceName === taskReferenceName || + task?.referenceTaskName === taskReferenceName; + + const findTaskById = (task) => task?.taskId === selectedTask?.id; + + // If reference name is not provided, use taskId to find the task + const findTask = selectedTask?.ref == null ? findTaskById : findTaskByReferenceName; + + const filteredTasks = tasksList?.filter(findTask); if (filteredTasks && filteredTasks.length === 1) { // task without any retry/iteration - return _nth(filteredTasks, 0); + const targetTask = _nth(filteredTasks, 0); + return targetTask; } else if (filteredTasks && filteredTasks.length > 1) { const result = filteredTasks.reduce( (acc, task, idx) => { @@ -121,9 +129,11 @@ export const taskWithLatestIteration = (tasksList, taskReferenceName) => { ); if (result?.idx > -1) { - return _nth(filteredTasks, result.idx); + const targetTask = _nth(filteredTasks, result.idx); + return targetTask; } } + return undefined; }; From a6be214299a43b6531cf043ef79b580d1fc243c5 Mon Sep 17 00:00:00 2001 From: Yong Sheng Tan Date: Thu, 12 Dec 2024 10:10:06 +0800 Subject: [PATCH 3/3] Add testWorkflow to OrkesWorkflowClient --- .../client/http/OrkesWorkflowClient.java | 5 ++++ .../client/http/WorkflowClientTests.java | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java index 0b47c6ff3..6748409e4 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java @@ -36,6 +36,7 @@ import com.netflix.conductor.common.run.SearchResult; import com.netflix.conductor.common.run.Workflow; import com.netflix.conductor.common.run.WorkflowSummary; +import com.netflix.conductor.common.run.WorkflowTestRequest; import io.orkes.conductor.client.model.CorrelationIdsSearchRequest; import io.orkes.conductor.client.model.WorkflowRun; @@ -202,6 +203,10 @@ public void skipTaskFromWorkflow(String workflowId, String taskReferenceName) { workflowClient.skipTaskFromWorkflow(workflowId, taskReferenceName); } + public Workflow testWorkflow(WorkflowTestRequest testRequest) { + return workflowClient.testWorkflow(testRequest); + } + public SearchResult search(String query) { return workflowClient.search(query); } diff --git a/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java b/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java index 465ec03b8..7e8ec62cf 100644 --- a/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java +++ b/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java @@ -16,6 +16,9 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import com.netflix.conductor.common.metadata.tasks.TaskResult; +import com.netflix.conductor.common.metadata.workflow.WorkflowTask; +import com.netflix.conductor.common.run.WorkflowTestRequest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -184,6 +187,28 @@ void testExecuteWorkflow() { // TODO } + @Test + void testWorkflow() { + WorkflowTask task = new WorkflowTask(); + task.setName("testable-task"); + task.setTaskReferenceName("testable-task-ref"); + + WorkflowDef workflowDef = new WorkflowDef(); + workflowDef.setName("testable-flow"); + workflowDef.setTasks(List.of(task)); + + WorkflowTestRequest testRequest = new WorkflowTestRequest(); + testRequest.setName("testable-flow"); + testRequest.setWorkflowDef(workflowDef); + testRequest.setTaskRefToMockOutput(Map.of( + "testable-task-ref", + List.of(new WorkflowTestRequest.TaskMock(TaskResult.Status.COMPLETED, Map.of("result", "ok"))) + )); + + Workflow workflow = workflowClient.testWorkflow(testRequest); + Assertions.assertEquals("ok", workflow.getOutput().get("result")); + } + StartWorkflowRequest getStartWorkflowRequest() { StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); startWorkflowRequest.setName(Commons.WORKFLOW_NAME);