use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class SimpleTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() throws Exception {
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setName("simple_task");
taskToSchedule.setTaskDefinition(new TaskDef("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();
List<Task> mappedTasks = simpleTaskMapper.getMappedTasks(taskMapperContext);
assertNotNull(mappedTasks);
assertEquals(1, mappedTasks.size());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class EventTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() throws Exception {
ParametersUtils parametersUtils = Mockito.mock(ParametersUtils.class);
EventTaskMapper eventTaskMapper = new EventTaskMapper(parametersUtils);
WorkflowTask taskToBeScheduled = new WorkflowTask();
taskToBeScheduled.setSink("SQSSINK");
String taskId = IDGenerator.generate();
Map<String, Object> eventTaskInput = new HashMap<>();
eventTaskInput.put("sink", "SQSSINK");
when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(TaskDef.class), anyString())).thenReturn(eventTaskInput);
WorkflowDef wd = new WorkflowDef();
Workflow w = new Workflow();
w.setWorkflowDefinition(wd);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToBeScheduled).withRetryCount(0).withTaskId(taskId).build();
List<Task> mappedTasks = eventTaskMapper.getMappedTasks(taskMapperContext);
assertEquals(1, mappedTasks.size());
Task eventTask = mappedTasks.get(0);
assertEquals(taskId, eventTask.getTaskId());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class HTTPTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() {
// Given
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setName("http_task");
taskToSchedule.setType(TaskType.HTTP.name());
taskToSchedule.setTaskDefinition(new TaskDef("http_task"));
String taskId = IDGenerator.generate();
String retriedTaskId = IDGenerator.generate();
Workflow workflow = new Workflow();
WorkflowDef workflowDef = new WorkflowDef();
workflow.setWorkflowDefinition(workflowDef);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
// when
List<Task> mappedTasks = httpTaskMapper.getMappedTasks(taskMapperContext);
// Then
assertEquals(1, mappedTasks.size());
assertEquals(TaskType.HTTP.name(), mappedTasks.get(0).getTaskType());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class CassandraDAOTest method testTaskDefLimitCRUD.
@Test
public void testTaskDefLimitCRUD() {
String taskDefName = "test_task_def";
String taskId = IDGenerator.generate();
TaskDef taskDef = new TaskDef();
taskDef.setConcurrentExecLimit(1);
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setTaskDefinition(taskDef);
Task task = new Task();
task.setTaskDefName(taskDefName);
task.setTaskId(taskId);
task.setWorkflowInstanceId(IDGenerator.generate());
task.setWorkflowTask(workflowTask);
task.setTaskType("test_task");
task.setWorkflowType("test_workflow");
task.setStatus(Task.Status.SCHEDULED);
Task newTask = new Task();
newTask.setTaskDefName(taskDefName);
newTask.setTaskId(IDGenerator.generate());
newTask.setWorkflowInstanceId(IDGenerator.generate());
newTask.setWorkflowTask(workflowTask);
newTask.setTaskType("test_task");
newTask.setWorkflowType("test_workflow");
newTask.setStatus(Task.Status.SCHEDULED);
// no tasks are IN_PROGRESS
executionDAO.updateTaskDefLimit(task, false);
assertFalse(executionDAO.exceedsInProgressLimit(task));
// set a task to IN_PROGRESS
task.setStatus(Status.IN_PROGRESS);
executionDAO.updateTaskDefLimit(task, false);
// when same task is checked
assertFalse(executionDAO.exceedsInProgressLimit(task));
// check if new task can be added
assertTrue(executionDAO.exceedsInProgressLimit(newTask));
// set IN_PROGRESS task to COMPLETED
task.setStatus(Status.COMPLETED);
executionDAO.updateTaskDefLimit(task, false);
// check new task again
assertFalse(executionDAO.exceedsInProgressLimit(newTask));
// set new task to IN_PROGRESS
newTask.setStatus(Status.IN_PROGRESS);
executionDAO.updateTaskDefLimit(newTask, false);
// check new task again
assertFalse(executionDAO.exceedsInProgressLimit(newTask));
// force remove from task def limit
executionDAO.updateTaskDefLimit(newTask, true);
assertFalse(executionDAO.exceedsInProgressLimit(task));
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class CassandraDAOTest method testTaskDefCrud.
@Test
public void testTaskDefCrud() {
String task1Name = "task1";
String task2Name = "task2";
// fetch all task defs
List<TaskDef> taskDefList = metadataDAO.getAllTaskDefs();
assertNotNull(taskDefList);
assertEquals(0, taskDefList.size());
TaskDef taskDef = new TaskDef();
taskDef.setName(task1Name);
// register a task definition
metadataDAO.createTaskDef(taskDef);
// fetch all task defs
taskDefList = metadataDAO.getAllTaskDefs();
assertNotNull(taskDefList);
assertEquals(1, taskDefList.size());
// fetch the task def
TaskDef def = metadataDAO.getTaskDef(task1Name);
assertEquals(taskDef, def);
// register another task definition
TaskDef taskDef1 = new TaskDef();
taskDef1.setName(task2Name);
metadataDAO.createTaskDef(taskDef1);
// fetch all task defs
taskDefList = metadataDAO.getAllTaskDefs();
assertNotNull(taskDefList);
assertEquals(2, taskDefList.size());
// update task def
taskDef.setOwnerEmail("juni@test.com");
metadataDAO.updateTaskDef(taskDef);
def = metadataDAO.getTaskDef(task1Name);
assertEquals(taskDef, def);
// delete task def
metadataDAO.removeTaskDef(task2Name);
taskDefList = metadataDAO.getAllTaskDefs();
assertNotNull(taskDefList);
assertEquals(1, taskDefList.size());
// fetch deleted task def
def = metadataDAO.getTaskDef(task2Name);
assertNull(def);
}
Aggregations