Search in sources :

Example 51 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class WorkflowTaskTypeConstraintTest method testWorkflowTaskTypeForJoinDynamicWithForJoinTaskParam.

@Test
public void testWorkflowTaskTypeForJoinDynamicWithForJoinTaskParam() {
    WorkflowTask workflowTask = createSampleWorkflowTask();
    workflowTask.setType("FORK_JOIN_DYNAMIC");
    workflowTask.setDynamicForkJoinTasksParam("taskList");
    workflowTask.setDynamicForkTasksInputParamName("ForkTaskInputParam");
    when(mockMetadataDao.getTaskDef(anyString())).thenReturn(new TaskDef());
    Set<ConstraintViolation<WorkflowTask>> result = validator.validate(workflowTask);
    assertEquals(1, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("dynamicForkJoinTasksParam or combination of dynamicForkTasksInputParamName and dynamicForkTasksParam cam be used for taskType: FORK_JOIN_DYNAMIC taskName: encode"));
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 52 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class MetadataServiceTest method testRegisterTaskDef.

@Test
public void testRegisterTaskDef() {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("somename");
    taskDef.setOwnerEmail("sample@test.com");
    // wrong
    taskDef.setResponseTimeoutSeconds(60 * 60);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    verify(metadataDAO, times(1)).createTaskDef(any(TaskDef.class));
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 53 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class PostgresMetadataDAOTest method testTaskDefOperations.

@Test
public void testTaskDefOperations() throws Exception {
    TaskDef def = new TaskDef("taskA");
    def.setDescription("description");
    def.setCreatedBy("unit_test");
    def.setCreateTime(1L);
    def.setInputKeys(Arrays.asList("a", "b", "c"));
    def.setOutputKeys(Arrays.asList("01", "o2"));
    def.setOwnerApp("ownerApp");
    def.setRetryCount(3);
    def.setRetryDelaySeconds(100);
    def.setRetryLogic(RetryLogic.FIXED);
    def.setTimeoutPolicy(TaskDef.TimeoutPolicy.ALERT_ONLY);
    def.setUpdatedBy("unit_test2");
    def.setUpdateTime(2L);
    dao.createTaskDef(def);
    TaskDef found = dao.getTaskDef(def.getName());
    assertTrue(EqualsBuilder.reflectionEquals(def, found));
    def.setDescription("updated description");
    dao.updateTaskDef(def);
    found = dao.getTaskDef(def.getName());
    assertTrue(EqualsBuilder.reflectionEquals(def, found));
    assertEquals("updated description", found.getDescription());
    for (int i = 0; i < 9; i++) {
        TaskDef tdf = new TaskDef("taskA" + i);
        dao.createTaskDef(tdf);
    }
    List<TaskDef> all = dao.getAllTaskDefs();
    assertNotNull(all);
    assertEquals(10, all.size());
    Set<String> allnames = all.stream().map(TaskDef::getName).collect(Collectors.toSet());
    assertEquals(10, allnames.size());
    List<String> sorted = allnames.stream().sorted().collect(Collectors.toList());
    assertEquals(def.getName(), sorted.get(0));
    for (int i = 0; i < 9; i++) {
        assertEquals(def.getName() + i, sorted.get(i + 1));
    }
    for (int i = 0; i < 9; i++) {
        dao.removeTaskDef(def.getName() + i);
    }
    all = dao.getAllTaskDefs();
    assertNotNull(all);
    assertEquals(1, all.size());
    assertEquals(def.getName(), all.get(0).getName());
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 54 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class MySQLMetadataDAO method getTaskDef.

@Override
public TaskDef getTaskDef(String name) {
    Preconditions.checkNotNull(name, "TaskDef name cannot be null");
    TaskDef taskDef = taskDefCache.get(name);
    if (taskDef == null) {
        if (logger.isTraceEnabled()) {
            logger.trace("Cache miss: {}", name);
        }
        taskDef = getTaskDefFromDB(name);
    }
    return taskDef;
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef)

Example 55 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class PostgresExecutionDAO method exceedsInProgressLimit.

@Override
public boolean exceedsInProgressLimit(Task task) {
    Optional<TaskDef> taskDefinition = task.getTaskDefinition();
    if (!taskDefinition.isPresent()) {
        return false;
    }
    TaskDef taskDef = taskDefinition.get();
    int limit = taskDef.concurrencyLimit();
    if (limit <= 0) {
        return false;
    }
    long current = getInProgressTaskCount(task.getTaskDefName());
    if (current >= limit) {
        Monitors.recordTaskConcurrentExecutionLimited(task.getTaskDefName(), limit);
        return true;
    }
    logger.info("Task execution count for {}: limit={}, current={}", task.getTaskDefName(), limit, getInProgressTaskCount(task.getTaskDefName()));
    String taskId = task.getTaskId();
    List<String> tasksInProgressInOrderOfArrival = findAllTasksInProgressInOrderOfArrival(task, limit);
    boolean rateLimited = !tasksInProgressInOrderOfArrival.contains(taskId);
    if (rateLimited) {
        logger.info("Task execution count limited. {}, limit {}, current {}", task.getTaskDefName(), limit, getInProgressTaskCount(task.getTaskDefName()));
        Monitors.recordTaskConcurrentExecutionLimited(task.getTaskDefName(), limit);
    }
    return rateLimited;
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef)

Aggregations

TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)172 Test (org.junit.Test)128 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)121 Task (com.netflix.conductor.common.metadata.tasks.Task)77 Workflow (com.netflix.conductor.common.run.Workflow)76 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)73 HashMap (java.util.HashMap)56 ArrayList (java.util.ArrayList)32 ConstraintViolation (javax.validation.ConstraintViolation)31 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)30 UserTask (com.netflix.conductor.tests.utils.UserTask)28 LinkedList (java.util.LinkedList)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 List (java.util.List)22 Map (java.util.Map)19 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)18 Before (org.junit.Before)14 ExpectedException (org.junit.rules.ExpectedException)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Collectors (java.util.stream.Collectors)11