Skip to content

Commit

Permalink
Merge branch 'conductor-oss:main' into feature/add-opensearch
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbelval authored Dec 16, 2024
2 parents 04c8caa + 590aab3 commit 4d2d07e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WorkflowSummary> search(String query) {
return workflowClient.search(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion ui/src/pages/execution/RightPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 3 additions & 3 deletions ui/src/pages/execution/TaskDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}}
Expand Down
28 changes: 19 additions & 9 deletions ui/src/utils/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function astToQuery(node) {

return `${wrapper ? "(" : ""}${clauses.join(` ${combinator} `)}${
wrapper ? ")" : ""
}`;
}`;
} else {
return "";
}
Expand Down Expand Up @@ -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) => {
Expand All @@ -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;
};

Expand Down

0 comments on commit 4d2d07e

Please sign in to comment.