use of com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest in project conductor by Netflix.
the class TestWorkflowExecutor method testRerunWorkflowWithTaskId.
@Test
public void testRerunWorkflowWithTaskId() {
// setup
Workflow workflow = new Workflow();
workflow.setWorkflowId("testRerunWorkflowId");
workflow.setWorkflowType("testRerunWorkflowId");
workflow.setVersion(1);
workflow.setOwnerApp("junit_testRerunWorkflowId");
workflow.setStartTime(10L);
workflow.setEndTime(100L);
// noinspection unchecked
workflow.setOutput(Collections.EMPTY_MAP);
workflow.setStatus(Workflow.WorkflowStatus.FAILED);
workflow.setReasonForIncompletion("task1 failed");
workflow.setFailedReferenceTaskNames(new HashSet<String>() {
{
add("task1_ref1");
}
});
Task task_1_1 = new Task();
task_1_1.setTaskId(UUID.randomUUID().toString());
task_1_1.setSeq(20);
task_1_1.setRetryCount(1);
task_1_1.setTaskType(TaskType.SIMPLE.toString());
task_1_1.setStatus(Status.FAILED);
task_1_1.setRetried(true);
task_1_1.setTaskDefName("task1");
task_1_1.setWorkflowTask(new WorkflowTask());
task_1_1.setReferenceTaskName("task1_ref1");
Task task_2_1 = new Task();
task_2_1.setTaskId(UUID.randomUUID().toString());
task_2_1.setSeq(22);
task_2_1.setRetryCount(1);
task_2_1.setStatus(Status.CANCELED);
task_2_1.setTaskType(TaskType.SIMPLE.toString());
task_2_1.setTaskDefName("task2");
task_2_1.setWorkflowTask(new WorkflowTask());
task_2_1.setReferenceTaskName("task2_ref1");
workflow.getTasks().addAll(Arrays.asList(task_1_1, task_2_1));
// end of setup
// when:
when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
WorkflowDef workflowDef = new WorkflowDef();
when(metadataDAO.getWorkflowDef(anyString(), anyInt())).thenReturn(Optional.of(workflowDef));
RerunWorkflowRequest rerunWorkflowRequest = new RerunWorkflowRequest();
rerunWorkflowRequest.setReRunFromWorkflowId(workflow.getWorkflowId());
rerunWorkflowRequest.setReRunFromTaskId(task_1_1.getTaskId());
workflowExecutor.rerun(rerunWorkflowRequest);
// when:
when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(null, workflow.getReasonForIncompletion());
assertEquals(new HashSet<>(), workflow.getFailedReferenceTaskNames());
}
use of com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest in project conductor by Netflix.
the class TestWorkflowExecutor method testRerunWorkflow.
@Test
public void testRerunWorkflow() {
// setup
Workflow workflow = new Workflow();
workflow.setWorkflowId("testRerunWorkflowId");
workflow.setWorkflowType("testRerunWorkflowId");
workflow.setVersion(1);
workflow.setOwnerApp("junit_testRerunWorkflowId");
workflow.setStartTime(10L);
workflow.setEndTime(100L);
// noinspection unchecked
workflow.setOutput(Collections.EMPTY_MAP);
workflow.setStatus(Workflow.WorkflowStatus.FAILED);
workflow.setReasonForIncompletion("task1 failed");
workflow.setFailedReferenceTaskNames(new HashSet<String>() {
{
add("task1_ref1");
}
});
Task task_1_1 = new Task();
task_1_1.setTaskId(UUID.randomUUID().toString());
task_1_1.setSeq(20);
task_1_1.setRetryCount(1);
task_1_1.setTaskType(TaskType.SIMPLE.toString());
task_1_1.setStatus(Status.FAILED);
task_1_1.setRetried(true);
task_1_1.setTaskDefName("task1");
task_1_1.setWorkflowTask(new WorkflowTask());
task_1_1.setReferenceTaskName("task1_ref1");
Task task_2_1 = new Task();
task_2_1.setTaskId(UUID.randomUUID().toString());
task_2_1.setSeq(22);
task_2_1.setRetryCount(1);
task_2_1.setStatus(Status.CANCELED);
task_2_1.setTaskType(TaskType.SIMPLE.toString());
task_2_1.setTaskDefName("task2");
task_2_1.setWorkflowTask(new WorkflowTask());
task_2_1.setReferenceTaskName("task2_ref1");
workflow.getTasks().addAll(Arrays.asList(task_1_1, task_2_1));
// end of setup
// when:
when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
WorkflowDef workflowDef = new WorkflowDef();
when(metadataDAO.getWorkflowDef(anyString(), anyInt())).thenReturn(Optional.of(workflowDef));
RerunWorkflowRequest rerunWorkflowRequest = new RerunWorkflowRequest();
rerunWorkflowRequest.setReRunFromWorkflowId(workflow.getWorkflowId());
workflowExecutor.rerun(rerunWorkflowRequest);
// when:
when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(null, workflow.getReasonForIncompletion());
assertEquals(new HashSet<>(), workflow.getFailedReferenceTaskNames());
}
use of com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testReruns.
@Test
public void testReruns() {
metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2, 1);
String correlationId = "unit_test_1" + UUID.randomUUID().toString();
Map<String, Object> input = new HashMap<String, Object>();
String inputParam1 = "p1 value";
input.put("param1", inputParam1);
input.put("param2", "p2 value");
String wfid = startOrLoadWorkflowExecution(LINEAR_WORKFLOW_T1_T2, 1, correlationId, input, null, null);
assertNotNull(wfid);
Workflow es = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(es);
assertEquals(RUNNING, es.getStatus());
// Check the tasks, at this time there should be 1 task
assertEquals(es.getTasks().size(), 1);
Task t = es.getTasks().get(0);
assertEquals(SCHEDULED, t.getStatus());
Task task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
assertNotNull(task);
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(t.getTaskId(), task.getTaskId());
String param1 = (String) task.getInputData().get("p1");
String param2 = (String) task.getInputData().get("p2");
assertNotNull(param1);
assertNotNull(param2);
assertEquals("p1 value", param1);
assertEquals("p2 value", param2);
String task1Op = "task1.output->" + param1 + "." + param2;
task.getOutputData().put("op", task1Op);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
// If we get the full workflow here then, last task should be completed and the next task should be scheduled
es = workflowExecutionService.getExecutionStatus(wfid, true);
es.getTasks().forEach(wfTask -> {
if (wfTask.getTaskId().equals(t.getTaskId())) {
assertEquals(wfTask.getStatus(), COMPLETED);
} else {
assertEquals(wfTask.getStatus(), SCHEDULED);
}
});
task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker");
assertNotNull(task);
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
String task2Input = (String) task.getInputData().get("tp2");
assertNotNull(task2Input);
assertEquals(task1Op, task2Input);
task2Input = (String) task.getInputData().get("tp1");
assertNotNull(task2Input);
assertEquals(inputParam1, task2Input);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
es = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(es);
assertEquals(WorkflowStatus.COMPLETED, es.getStatus());
// Now rerun lets rerun the workflow from the second task
RerunWorkflowRequest request = new RerunWorkflowRequest();
request.setReRunFromWorkflowId(wfid);
request.setReRunFromTaskId(es.getTasks().get(1).getTaskId());
String reRunwfid = workflowExecutor.rerun(request);
Workflow esRR = workflowExecutionService.getExecutionStatus(reRunwfid, true);
assertNotNull(esRR);
assertEquals(esRR.getReasonForIncompletion(), RUNNING, esRR.getStatus());
// Check the tasks, at this time there should be 2 tasks
// first one is skipped and the second one is scheduled
assertEquals(esRR.getTasks().toString(), 2, esRR.getTasks().size());
assertEquals(COMPLETED, esRR.getTasks().get(0).getStatus());
Task tRR = esRR.getTasks().get(1);
assertEquals(esRR.getTasks().toString(), SCHEDULED, tRR.getStatus());
assertEquals(tRR.getTaskType(), "junit_task_2");
task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker");
assertNotNull(task);
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
task2Input = (String) task.getInputData().get("tp2");
assertNotNull(task2Input);
assertEquals(task1Op, task2Input);
task2Input = (String) task.getInputData().get("tp1");
assertNotNull(task2Input);
assertEquals(inputParam1, task2Input);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
es = workflowExecutionService.getExecutionStatus(reRunwfid, true);
assertNotNull(es);
assertEquals(WorkflowStatus.COMPLETED, es.getStatus());
// ////////////////////
// Now rerun the entire workflow
RerunWorkflowRequest request1 = new RerunWorkflowRequest();
request1.setReRunFromWorkflowId(wfid);
String reRunwfid1 = workflowExecutor.rerun(request1);
es = workflowExecutionService.getExecutionStatus(reRunwfid1, true);
assertNotNull(es);
assertEquals(RUNNING, es.getStatus());
// Check the tasks, at this time there should be 1 task
assertEquals(es.getTasks().size(), 1);
assertEquals(SCHEDULED, es.getTasks().get(0).getStatus());
task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
assertNotNull(task);
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
task.getOutputData().put("op", task1Op);
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker");
assertNotNull(task);
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
task.setStatus(COMPLETED);
workflowExecutionService.updateTask(task);
es = workflowExecutionService.getExecutionStatus(wfid, true);
assertNotNull(es);
assertEquals(WorkflowStatus.COMPLETED, es.getStatus());
}
use of com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest in project conductor by Netflix.
the class WorkflowServiceTest method testRerunWorkflow.
@Test
public void testRerunWorkflow() {
RerunWorkflowRequest request = new RerunWorkflowRequest();
workflowService.rerunWorkflow("test", request);
verify(mockWorkflowExecutor, times(1)).rerun(any(RerunWorkflowRequest.class));
}
use of com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest in project conductor by Netflix.
the class WorkflowServiceTest method testRerunWorkflowReturnWorkflowId.
@Test
public void testRerunWorkflowReturnWorkflowId() {
RerunWorkflowRequest request = new RerunWorkflowRequest();
String workflowId = "w123";
when(mockWorkflowExecutor.rerun(any(RerunWorkflowRequest.class))).thenReturn(workflowId);
assertEquals(workflowId, workflowService.rerunWorkflow("test", request));
}
Aggregations