HTTPTaskMapper implements TaskMapper { @Override public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) throws TerminateWorkflowException { logger.debug("TaskMapperContext {} in HTTPTaskMapper", taskMapperContext); WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule(); taskToSchedule.getInputParameters().put("asyncComplete", taskToSchedule.isAsyncComplete()); Workflow workflowInstance = taskMapperContext.getWorkflowInstance(); String taskId = taskMapperContext.getTaskId(); int retryCount = taskMapperContext.getRetryCount(); TaskDef taskDefinition = Optional.ofNullable(taskMapperContext.getTaskDefinition()) .orElseGet(() -> Optional.ofNullable(metadataDAO.getTaskDef(taskToSchedule.getName())) .orElse(null)); Map<String, Object> input = parametersUtils.getTaskInputV2(taskToSchedule.getInputParameters(), workflowInstance, taskId, taskDefinition); Boolean asynComplete = (Boolean)input.get("asyncComplete"); Task httpTask = new Task(); httpTask.setTaskType(taskToSchedule.getType()); httpTask.setTaskDefName(taskToSchedule.getName()); httpTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName()); httpTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); httpTask.setWorkflowType(workflowInstance.getWorkflowName()); httpTask.setCorrelationId(workflowInstance.getCorrelationId()); httpTask.setScheduledTime(System.currentTimeMillis()); httpTask.setTaskId(taskId); httpTask.setInputData(input); httpTask.getInputData().put("asyncComplete", asynComplete); httpTask.setStatus(Task.Status.SCHEDULED); httpTask.setRetryCount(retryCount); httpTask.setCallbackAfterSeconds(taskToSchedule.getStartDelay()); httpTask.setWorkflowTask(taskToSchedule); httpTask.setWorkflowPriority(workflowInstance.getPriority()); if (Objects.nonNull(taskDefinition)) { httpTask.setRateLimitPerFrequency(taskDefinition.getRateLimitPerFrequency()); httpTask.setRateLimitFrequencyInSeconds(taskDefinition.getRateLimitFrequencyInSeconds()); httpTask.setIsolationGroupId(taskDefinition.getIsolationGroupId()); httpTask.setExecutionNameSpace(taskDefinition.getExecutionNameSpace()); } return Collections.singletonList(httpTask); } HTTPTaskMapper(ParametersUtils parametersUtils, MetadataDAO metadataDAO); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext); static final Logger logger; }
@Test public void getMappedTasks() { 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(); List<Task> mappedTasks = httpTaskMapper.getMappedTasks(taskMapperContext); assertEquals(1, mappedTasks.size()); assertEquals(TaskType.HTTP.name(), mappedTasks.get(0).getTaskType()); }
@Test public void getMappedTasks_WithoutTaskDef() { WorkflowTask taskToSchedule = new WorkflowTask(); taskToSchedule.setName("http_task"); taskToSchedule.setType(TaskType.HTTP.name()); 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(null) .withTaskToSchedule(taskToSchedule) .withTaskInput(new HashMap<>()) .withRetryCount(0) .withRetryTaskId(retriedTaskId) .withTaskId(taskId) .build(); List<Task> mappedTasks = httpTaskMapper.getMappedTasks(taskMapperContext); assertEquals(1, mappedTasks.size()); assertEquals(TaskType.HTTP.name(), mappedTasks.get(0).getTaskType()); }