use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TaskTest method testTaskDefinitionIfAvailable.
@Test
public void testTaskDefinitionIfAvailable() {
Task task = new Task();
task.setStatus(Status.FAILED);
assertEquals(Status.FAILED, task.getStatus());
assertNull(task.getWorkflowTask());
assertFalse(task.getTaskDefinition().isPresent());
WorkflowTask workflowTask = new WorkflowTask();
TaskDef taskDefinition = new TaskDef();
workflowTask.setTaskDefinition(taskDefinition);
task.setWorkflowTask(workflowTask);
assertTrue(task.getTaskDefinition().isPresent());
assertEquals(taskDefinition, task.getTaskDefinition().get());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TaskDefTest method testTaskDef.
@Test
public void testTaskDef() {
TaskDef taskDef = new TaskDef();
taskDef.setName("task1");
taskDef.setRetryCount(-1);
taskDef.setTimeoutSeconds(1000);
taskDef.setResponseTimeoutSeconds(1001);
taskDef.setRetryLogic(RetryLogic.FIXED);
taskDef.setRetryDelaySeconds(10);
Set<ConstraintViolation<Object>> result = validator.validate(taskDef);
assertEquals(3, result.size());
List<String> validationErrors = new ArrayList<>();
result.forEach(e -> validationErrors.add(e.getMessage()));
assertTrue(validationErrors.contains("TaskDef: task1 responseTimeoutSeconds: 1001 must be less than timeoutSeconds: 1000"));
assertTrue(validationErrors.contains("TaskDef retryCount: 0 must be >= 0"));
assertTrue(validationErrors.contains("ownerEmail cannot be empty"));
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class SimpleTaskMapperTest method getMappedTasksException.
@Test
public void getMappedTasksException() throws Exception {
// Given
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setName("simple_task");
String taskId = IDGenerator.generate();
String retriedTaskId = IDGenerator.generate();
WorkflowDef wd = new WorkflowDef();
Workflow w = new Workflow();
w.setWorkflowDefinition(wd);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
// then
expectedException.expect(TerminateWorkflowException.class);
expectedException.expectMessage(String.format("Invalid task. Task %s does not have a definition", taskToSchedule.getName()));
// when
simpleTaskMapper.getMappedTasks(taskMapperContext);
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TerminateTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() throws Exception {
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setType(TaskType.TASK_TYPE_TERMINATE);
String taskId = IDGenerator.generate();
WorkflowDef workflowDef = new WorkflowDef();
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
List<Task> mappedTasks = new TerminateTaskMapper(parametersUtils).getMappedTasks(taskMapperContext);
Assert.assertNotNull(mappedTasks);
Assert.assertEquals(1, mappedTasks.size());
Assert.assertEquals(TaskType.TASK_TYPE_TERMINATE, mappedTasks.get(0).getTaskType());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestWorkflowExecutor method testRestartWorkflow.
@Test
public void testRestartWorkflow() {
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("test_task");
workflowTask.setTaskReferenceName("task_ref");
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("testDef");
workflowDef.setVersion(1);
workflowDef.setRestartable(true);
workflowDef.getTasks().addAll(Collections.singletonList(workflowTask));
Task task_1 = new Task();
task_1.setTaskId(UUID.randomUUID().toString());
task_1.setSeq(1);
task_1.setStatus(Status.FAILED);
task_1.setTaskDefName(workflowTask.getName());
task_1.setReferenceTaskName(workflowTask.getTaskReferenceName());
Task task_2 = new Task();
task_2.setTaskId(UUID.randomUUID().toString());
task_2.setSeq(2);
task_2.setStatus(Status.FAILED);
task_2.setTaskDefName(workflowTask.getName());
task_2.setReferenceTaskName(workflowTask.getTaskReferenceName());
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
workflow.setWorkflowId("test-workflow-id");
workflow.getTasks().addAll(Arrays.asList(task_1, task_2));
workflow.setStatus(Workflow.WorkflowStatus.FAILED);
when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
doNothing().when(executionDAOFacade).removeTask(any());
when(metadataDAO.getWorkflowDef(workflow.getWorkflowName(), workflow.getWorkflowVersion())).thenReturn(Optional.of(workflowDef));
when(metadataDAO.getTaskDef(workflowTask.getName())).thenReturn(new TaskDef());
when(executionDAOFacade.updateWorkflow(any())).thenReturn("");
workflowExecutor.rewind(workflow.getWorkflowId(), false);
assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
verify(metadataDAO, never()).getLatestWorkflowDef(any());
ArgumentCaptor<Workflow> argumentCaptor = ArgumentCaptor.forClass(Workflow.class);
verify(executionDAOFacade, times(1)).createWorkflow(argumentCaptor.capture());
assertEquals(workflow.getWorkflowId(), argumentCaptor.getAllValues().get(0).getWorkflowId());
assertEquals(workflow.getWorkflowDefinition(), argumentCaptor.getAllValues().get(0).getWorkflowDefinition());
// add a new version of the workflow definition and restart with latest
workflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
workflowDef = new WorkflowDef();
workflowDef.setName("testDef");
workflowDef.setVersion(2);
workflowDef.setRestartable(true);
workflowDef.getTasks().addAll(Collections.singletonList(workflowTask));
when(metadataDAO.getLatestWorkflowDef(workflow.getWorkflowName())).thenReturn(Optional.of(workflowDef));
workflowExecutor.rewind(workflow.getWorkflowId(), true);
assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
verify(metadataDAO, times(1)).getLatestWorkflowDef(anyString());
argumentCaptor = ArgumentCaptor.forClass(Workflow.class);
verify(executionDAOFacade, times(2)).createWorkflow(argumentCaptor.capture());
assertEquals(workflow.getWorkflowId(), argumentCaptor.getAllValues().get(1).getWorkflowId());
assertEquals(workflowDef, argumentCaptor.getAllValues().get(1).getWorkflowDefinition());
}
Aggregations