Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Bug fix: re-running a sub workflow should update the parent state
Browse files Browse the repository at this point in the history
  • Loading branch information
jxu-nflx authored and aravindanr committed Sep 27, 2021
1 parent 66c6c84 commit 6e74001
Show file tree
Hide file tree
Showing 5 changed files with 1,403 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .gitignore
Expand Up @@ -26,3 +26,9 @@ node_modules

# publishing secrets
secrets/signing-key

# local builds
lib/
build/
*/build/

Expand Up @@ -1562,6 +1562,7 @@ private boolean rerunWF(String workflowId, String taskId, Map<String, Object> ta

// Get the workflow
Workflow workflow = executionDAOFacade.getWorkflowById(workflowId, true);
updateAndPushParents(workflow, "reran");

// If the task Id is null it implies that the entire workflow has to be rerun
if (taskId == null) {
Expand Down
Expand Up @@ -1134,7 +1134,7 @@ public void testRerunWorkflow() {
Workflow workflow = new Workflow();
workflow.setWorkflowId("testRerunWorkflowId");
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("testRetryWorkflowId");
workflowDef.setName("testRerunWorkflowId");
workflowDef.setVersion(1);
workflow.setWorkflowDefinition(workflowDef);
workflow.setOwnerApp("junit_testRerunWorkflowId");
Expand Down Expand Up @@ -1187,6 +1187,83 @@ public void testRerunWorkflow() {
assertEquals(new HashSet<>(), workflow.getFailedReferenceTaskNames());
}

@Test
public void testRerunSubWorkflow() {
//setup
String parentWorkflowId = IDGenerator.generate();
String subWorkflowId = IDGenerator.generate();

// sub workflow setup
Task task1 = new Task();
task1.setTaskType(TaskType.SIMPLE.name());
task1.setTaskDefName("task1");
task1.setReferenceTaskName("task1_ref");
task1.setWorkflowInstanceId(subWorkflowId);
task1.setScheduledTime(System.currentTimeMillis());
task1.setTaskId(IDGenerator.generate());
task1.setStatus(Status.COMPLETED);
task1.setWorkflowTask(new WorkflowTask());
task1.setOutputData(new HashMap<>());

Task task2 = new Task();
task2.setTaskType(TaskType.SIMPLE.name());
task2.setTaskDefName("task2");
task2.setReferenceTaskName("task2_ref");
task2.setWorkflowInstanceId(subWorkflowId);
task2.setScheduledTime(System.currentTimeMillis());
task2.setTaskId(IDGenerator.generate());
task2.setStatus(Status.COMPLETED);
task2.setWorkflowTask(new WorkflowTask());
task2.setOutputData(new HashMap<>());

Workflow subWorkflow = new Workflow();
subWorkflow.setParentWorkflowId(parentWorkflowId);
subWorkflow.setWorkflowId(subWorkflowId);
WorkflowDef subworkflowDef = new WorkflowDef();
subworkflowDef.setName("subworkflow");
subworkflowDef.setVersion(1);
subWorkflow.setWorkflowDefinition(subworkflowDef);
subWorkflow.setOwnerApp("junit_testRerunWorkflowId");
subWorkflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
subWorkflow.getTasks().addAll(Arrays.asList(task1, task2));

// parent workflow setup
Task task = new Task();
task.setWorkflowInstanceId(parentWorkflowId);
task.setScheduledTime(System.currentTimeMillis());
task.setTaskId(IDGenerator.generate());
task.setStatus(Status.COMPLETED);
task.setOutputData(new HashMap<>());
task.setSubWorkflowId(subWorkflowId);
task.setTaskType(TaskType.SUB_WORKFLOW.name());

Workflow workflow = new Workflow();
workflow.setWorkflowId(parentWorkflowId);
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("parentworkflow");
workflowDef.setVersion(1);
workflow.setWorkflowDefinition(workflowDef);
workflow.setOwnerApp("junit_testRerunWorkflowId");
workflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
workflow.getTasks().addAll(Arrays.asList(task));
//end of setup

//when:
when(executionDAOFacade.getWorkflowById(workflow.getWorkflowId(), true)).thenReturn(workflow);
when(executionDAOFacade.getWorkflowById(task.getSubWorkflowId(), true)).thenReturn(subWorkflow);
when(executionDAOFacade.getTaskById(subWorkflow.getParentWorkflowTaskId())).thenReturn(task);
when(executionDAOFacade.getWorkflowById(subWorkflow.getParentWorkflowId(), false)).thenReturn(workflow);

RerunWorkflowRequest rerunWorkflowRequest = new RerunWorkflowRequest();
rerunWorkflowRequest.setReRunFromWorkflowId(subWorkflow.getWorkflowId());
workflowExecutor.rerun(rerunWorkflowRequest);

//then:
assertEquals(Status.IN_PROGRESS, task.getStatus());
assertEquals(Workflow.WorkflowStatus.RUNNING, subWorkflow.getStatus());
assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
}

@Test
public void testRerunWorkflowWithTaskId() {
//setup
Expand Down Expand Up @@ -1247,6 +1324,85 @@ public void testRerunWorkflowWithTaskId() {
assertEquals(new HashSet<>(), workflow.getFailedReferenceTaskNames());
}

@Test
public void testRerunSubWorkflowWithTaskId() {
//setup
String parentWorkflowId = IDGenerator.generate();
String subWorkflowId = IDGenerator.generate();

// sub workflow setup
Task task1 = new Task();
task1.setTaskType(TaskType.SIMPLE.name());
task1.setTaskDefName("task1");
task1.setReferenceTaskName("task1_ref");
task1.setWorkflowInstanceId(subWorkflowId);
task1.setScheduledTime(System.currentTimeMillis());
task1.setTaskId(IDGenerator.generate());
task1.setStatus(Status.COMPLETED);
task1.setWorkflowTask(new WorkflowTask());
task1.setOutputData(new HashMap<>());

Task task2 = new Task();
task2.setTaskType(TaskType.SIMPLE.name());
task2.setTaskDefName("task2");
task2.setReferenceTaskName("task2_ref");
task2.setWorkflowInstanceId(subWorkflowId);
task2.setScheduledTime(System.currentTimeMillis());
task2.setTaskId(IDGenerator.generate());
task2.setStatus(Status.COMPLETED);
task2.setWorkflowTask(new WorkflowTask());
task2.setOutputData(new HashMap<>());

Workflow subWorkflow = new Workflow();
subWorkflow.setParentWorkflowId(parentWorkflowId);
subWorkflow.setWorkflowId(subWorkflowId);
WorkflowDef subworkflowDef = new WorkflowDef();
subworkflowDef.setName("subworkflow");
subworkflowDef.setVersion(1);
subWorkflow.setWorkflowDefinition(subworkflowDef);
subWorkflow.setOwnerApp("junit_testRerunWorkflowId");
subWorkflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
subWorkflow.getTasks().addAll(Arrays.asList(task1, task2));

// parent workflow setup
Task task = new Task();
task.setWorkflowInstanceId(parentWorkflowId);
task.setScheduledTime(System.currentTimeMillis());
task.setTaskId(IDGenerator.generate());
task.setStatus(Status.COMPLETED);
task.setOutputData(new HashMap<>());
task.setSubWorkflowId(subWorkflowId);
task.setTaskType(TaskType.SUB_WORKFLOW.name());

Workflow workflow = new Workflow();
workflow.setWorkflowId(parentWorkflowId);
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("parentworkflow");
workflowDef.setVersion(1);
workflow.setWorkflowDefinition(workflowDef);
workflow.setOwnerApp("junit_testRerunWorkflowId");
workflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
workflow.getTasks().addAll(Arrays.asList(task));
//end of setup

//when:
when(executionDAOFacade.getWorkflowById(workflow.getWorkflowId(), true)).thenReturn(workflow);
when(executionDAOFacade.getWorkflowById(task.getSubWorkflowId(), true)).thenReturn(subWorkflow);
when(executionDAOFacade.getTaskById(subWorkflow.getParentWorkflowTaskId())).thenReturn(task);
when(executionDAOFacade.getWorkflowById(subWorkflow.getParentWorkflowId(), false)).thenReturn(workflow);

RerunWorkflowRequest rerunWorkflowRequest = new RerunWorkflowRequest();
rerunWorkflowRequest.setReRunFromWorkflowId(subWorkflow.getWorkflowId());
rerunWorkflowRequest.setReRunFromTaskId(task2.getTaskId());
workflowExecutor.rerun(rerunWorkflowRequest);

//then:
assertEquals(Status.SCHEDULED, task2.getStatus());
assertEquals(Status.IN_PROGRESS, task.getStatus());
assertEquals(Workflow.WorkflowStatus.RUNNING, subWorkflow.getStatus());
assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
}

@Test
public void testGetActiveDomain() {
String taskType = "test-task";
Expand Down

0 comments on commit 6e74001

Please sign in to comment.