use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class SubWorkflowParamsTest method testWorkflowDefJson.
@Test
public void testWorkflowDefJson() throws Exception {
// name is null
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName("dummy-name");
WorkflowDef def = new WorkflowDef();
def.setName("test_workflow");
def.setVersion(1);
WorkflowTask task = new WorkflowTask();
task.setName("test_task");
task.setTaskReferenceName("t1");
def.getTasks().add(task);
subWorkflowParams.setWorkflowDefinition(def);
String expected = "{\n" + " \"name\" : \"test_workflow\",\n" + " \"version\" : 1,\n" + " \"workflowDefinition\" : {\n" + " \"inputParameters\" : [ ],\n" + " \"name\" : \"test_workflow\",\n" + " \"outputParameters\" : { },\n" + " \"restartable\" : true,\n" + " \"schemaVersion\" : 2,\n" + " \"tasks\" : [ {\n" + " \"asyncComplete\" : false,\n" + " \"decisionCases\" : { },\n" + " \"defaultCase\" : [ ],\n" + " \"defaultExclusiveJoinTask\" : [ ],\n" + " \"forkTasks\" : [ ],\n" + " \"inputParameters\" : { },\n" + " \"joinOn\" : [ ],\n" + " \"loopOver\" : [ ],\n" + " \"name\" : \"test_task\",\n" + " \"optional\" : false,\n" + " \"retryLogic\" : \"UNSPECIFIED\",\n" + " \"startDelay\" : 0,\n" + " \"taskReferenceName\" : \"t1\",\n" + " \"type\" : \"SIMPLE\"\n" + " } ],\n" + " \"timeoutPolicy\" : \"ALERT_ONLY\",\n" + " \"timeoutSeconds\" : 0,\n" + " \"variables\" : { },\n" + " \"version\" : 1,\n" + " \"workflowStatusListenerEnabled\" : false\n" + " }\n" + "}";
ObjectMapper objectMapper = new JsonMapperProvider().get();
objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
objectMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
assertEquals(expected, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(subWorkflowParams));
SubWorkflowParams actualSubWorkflowParam = objectMapper.readValue(expected, SubWorkflowParams.class);
assertEquals(subWorkflowParams, actualSubWorkflowParam);
assertEquals(def, actualSubWorkflowParam.getWorkflowDefinition());
assertEquals(def, actualSubWorkflowParam.getWorkflowDef());
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class SubWorkflowParamsTest method testWorkflowTaskName.
@Test
public void testWorkflowTaskName() {
// name is null
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Object>> result = validator.validate(subWorkflowParams);
assertEquals(2, result.size());
List<String> validationErrors = new ArrayList<>();
result.forEach(e -> validationErrors.add(e.getMessage()));
assertTrue(validationErrors.contains("SubWorkflowParams name cannot be null"));
assertTrue(validationErrors.contains("SubWorkflowParams name cannot be empty"));
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class SubWorkflowTaskMapperTest method getSubWorkflowParams.
@Test
public void getSubWorkflowParams() {
WorkflowTask workflowTask = new WorkflowTask();
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName("Foo");
subWorkflowParams.setVersion(2);
workflowTask.setSubWorkflowParam(subWorkflowParams);
assertEquals(subWorkflowParams, subWorkflowTaskMapper.getSubWorkflowParams(workflowTask));
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class SubWorkflowTaskMapperTest method getMappedTasks.
@SuppressWarnings("unchecked")
@Test
public void getMappedTasks() {
// Given
WorkflowDef workflowDef = new WorkflowDef();
Workflow workflowInstance = new Workflow();
workflowInstance.setWorkflowDefinition(workflowDef);
WorkflowTask taskToSchedule = new WorkflowTask();
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName("Foo");
subWorkflowParams.setVersion(2);
taskToSchedule.setSubWorkflowParam(subWorkflowParams);
Map<String, Object> taskInput = new HashMap<>();
Map<String, String> taskToDomain = new HashMap<String, String>() {
{
put("*", "unittest");
}
};
Map<String, Object> subWorkflowParamMap = new HashMap<>();
subWorkflowParamMap.put("name", "FooWorkFlow");
subWorkflowParamMap.put("version", 2);
subWorkflowParamMap.put("taskToDomain", taskToDomain);
when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), any(), any())).thenReturn(subWorkflowParamMap);
// When
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflowInstance).withTaskToSchedule(taskToSchedule).withTaskInput(taskInput).withRetryCount(0).withTaskId(IDGenerator.generate()).withDeciderService(deciderService).build();
List<Task> mappedTasks = subWorkflowTaskMapper.getMappedTasks(taskMapperContext);
// Then
assertTrue(!mappedTasks.isEmpty());
assertEquals(1, mappedTasks.size());
Task subWorkFlowTask = mappedTasks.get(0);
assertEquals(Task.Status.SCHEDULED, subWorkFlowTask.getStatus());
assertEquals(SubWorkflow.NAME, subWorkFlowTask.getTaskType());
assertEquals(taskToDomain, subWorkFlowTask.getInputData().get("subWorkflowTaskToDomain"));
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class TestDeciderService method createNestedWorkflow.
private WorkflowDef createNestedWorkflow() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("Nested Workflow");
workflowDef.setDescription(workflowDef.getName());
workflowDef.setVersion(1);
workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("p1", "workflow.input.param1");
inputParams.put("p2", "workflow.input.param2");
List<WorkflowTask> tasks = new ArrayList<>(10);
for (int i = 0; i < 10; i++) {
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("junit_task_" + i);
workflowTask.setInputParameters(inputParams);
workflowTask.setTaskReferenceName("t" + i);
workflowTask.setTaskDefinition(new TaskDef("junit_task_" + i));
tasks.add(workflowTask);
}
WorkflowTask decisionTask = new WorkflowTask();
decisionTask.setType(TaskType.DECISION.name());
decisionTask.setName("Decision");
decisionTask.setTaskReferenceName("d1");
decisionTask.setDefaultCase(Collections.singletonList(tasks.get(8)));
decisionTask.setCaseValueParam("case");
Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
decisionCases.put("a", Arrays.asList(tasks.get(6), tasks.get(9)));
decisionCases.put("b", Collections.singletonList(tasks.get(7)));
decisionTask.setDecisionCases(decisionCases);
WorkflowDef subWorkflowDef = createLinearWorkflow();
WorkflowTask subWorkflow = new WorkflowTask();
subWorkflow.setType(TaskType.SUB_WORKFLOW.name());
subWorkflow.setName("sw1");
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName(subWorkflowDef.getName());
subWorkflow.setSubWorkflowParam(subWorkflowParams);
subWorkflow.setTaskReferenceName("sw1");
WorkflowTask forkTask2 = new WorkflowTask();
forkTask2.setType(TaskType.FORK_JOIN.name());
forkTask2.setName("second fork");
forkTask2.setTaskReferenceName("fork2");
forkTask2.getForkTasks().add(Arrays.asList(tasks.get(2), tasks.get(4)));
forkTask2.getForkTasks().add(Arrays.asList(tasks.get(3), decisionTask));
WorkflowTask joinTask2 = new WorkflowTask();
joinTask2.setName("join2");
joinTask2.setType(TaskType.JOIN.name());
joinTask2.setTaskReferenceName("join2");
joinTask2.setJoinOn(Arrays.asList("t4", "d1"));
WorkflowTask forkTask1 = new WorkflowTask();
forkTask1.setType(TaskType.FORK_JOIN.name());
forkTask1.setName("fork1");
forkTask1.setTaskReferenceName("fork1");
forkTask1.getForkTasks().add(Collections.singletonList(tasks.get(1)));
forkTask1.getForkTasks().add(Arrays.asList(forkTask2, joinTask2));
forkTask1.getForkTasks().add(Collections.singletonList(subWorkflow));
WorkflowTask joinTask1 = new WorkflowTask();
joinTask1.setName("join1");
joinTask1.setType(TaskType.JOIN.name());
joinTask1.setTaskReferenceName("join1");
joinTask1.setJoinOn(Arrays.asList("t1", "fork2"));
workflowDef.getTasks().add(forkTask1);
workflowDef.getTasks().add(joinTask1);
workflowDef.getTasks().add(tasks.get(5));
return workflowDef;
}
Aggregations