@Provides @Singleton public ParametersUtils getParameterUtils() { return new ParametersUtils(); }
/** * This method is used to get the List of dynamic workflow tasks and their input based on the {@link WorkflowTask#getDynamicForkTasksParam()} * * @param taskToSchedule: The Task of type FORK_JOIN_DYNAMIC that needs to scheduled, which has the input parameters * @param workflowInstance: The instance of the {@link Workflow} which represents the workflow being executed. * @param dynamicForkTaskParam: The key representing the dynamic fork join json payload which is available in {@link WorkflowTask#getInputParameters()} * @throws TerminateWorkflowException : In case of input parameters of the dynamic fork tasks not represented as {@link Map} * @return a {@link Pair} representing the list of dynamic fork tasks in {@link Pair#getLeft()} and the input for the dynamic fork tasks in {@link Pair#getRight()} */ @SuppressWarnings("unchecked") @VisibleForTesting Pair<List<WorkflowTask>, Map<String, Map<String, Object>>> getDynamicForkTasksAndInput(WorkflowTask taskToSchedule, Workflow workflowInstance, String dynamicForkTaskParam) throws TerminateWorkflowException { Map<String, Object> input = parametersUtils.getTaskInput(taskToSchedule.getInputParameters(), workflowInstance, null, null); Object dynamicForkTasksJson = input.get(dynamicForkTaskParam); List<WorkflowTask> dynamicForkWorkflowTasks = objectMapper.convertValue(dynamicForkTasksJson, ListOfWorkflowTasks); for (WorkflowTask workflowTask : dynamicForkWorkflowTasks) { if (MetadataMapperService.shouldPopulateDefinition(workflowTask)) { workflowTask.setTaskDefinition(metadataDAO.getTaskDef(workflowTask.getName())); } } Object dynamicForkTasksInput = input.get(taskToSchedule.getDynamicForkTasksInputParamName()); if (!(dynamicForkTasksInput instanceof Map)) { throw new TerminateWorkflowException("Input to the dynamically forked tasks is not a map -> expecting a map of K,V but found " + dynamicForkTasksInput); } return new ImmutablePair<>(dynamicForkWorkflowTasks, (Map<String, Map<String, Object>>) dynamicForkTasksInput); }
private Map<String, Object> getSubWorkflowInputParameters(Workflow workflowInstance, SubWorkflowParams subWorkflowParams) { Map<String, Object> params = new HashMap<>(); params.put("name", subWorkflowParams.getName()); Integer version = subWorkflowParams.getVersion(); if (version != null) { params.put("version", version); } return parametersUtils.getTaskInputV2(params, workflowInstance, null, null); }
public Map<String, Object> getTaskInput(Map<String, Object> inputParams, Workflow workflow, TaskDef taskDefinition, String taskId) { if (workflow.getSchemaVersion() > 1) { return getTaskInputV2(inputParams, workflow, taskId, taskDefinition); } return getTaskInputV1(workflow, inputParams); }
@SuppressWarnings("unchecked") private Object replaceList(List<?> values, String taskId, DocumentContext io) { List<Object> replacedList = new LinkedList<>(); for (Object listVal : values) { if (listVal instanceof String) { Object replaced = replaceVariables(listVal.toString(), io, taskId); replacedList.add(replaced); } else if (listVal instanceof Map) { Object replaced = replace((Map<String, Object>) listVal, io, taskId); replacedList.add(replaced); } else if (listVal instanceof List) { Object replaced = replaceList((List<?>) listVal, taskId, io); replacedList.add(replaced); } else { replacedList.add(listVal); } } return replacedList; }
public ObservableQueue getQueue(String eventType) { String event = parametersUtils.replace(eventType).toString(); int index = event.indexOf(':'); if (index == -1) { logger.error("Queue cannot be configured for illegal event: {}", event); throw new IllegalArgumentException("Illegal event " + event); } String type = event.substring(0, index); String queueURI = event.substring(index + 1); EventQueueProvider provider = providers.get(type); if (provider != null) { return provider.getQueue(queueURI); } else { logger.error("Queue {} is not configured for event:{}", type, eventType); throw new IllegalArgumentException("Unknown queue type " + type); } } }
public Object replace(String paramString) { Configuration option = Configuration.defaultConfiguration().addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(Collections.emptyMap(), option); return replaceVariables(paramString, documentContext, null); }
@SuppressWarnings("unchecked") private Map<String, Object> replace(Map<String, Object> input, DocumentContext documentContext, String taskId) { for (Entry<String, Object> e : input.entrySet()) { Object value = e.getValue(); if (value instanceof String) { Object replaced = replaceVariables(value.toString(), documentContext, taskId); e.setValue(replaced); } else if (value instanceof Map) { //recursive call Object replaced = replace((Map<String, Object>) value, documentContext, taskId); e.setValue(replaced); } else if (value instanceof List) { Object replaced = replaceList((List<?>) value, taskId, documentContext); e.setValue(replaced); } else { e.setValue(value); } } return input; }
public Map<String, Object> replace(Map<String, Object> input, Object json) { Object doc; if (json instanceof String) { doc = JsonPath.parse(json.toString()); } else { doc = json; } Configuration option = Configuration.defaultConfiguration().addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(doc, option); return replace(input, documentContext, null); }
public Map<String, Object> getTaskInput(Map<String, Object> inputParams, Workflow workflow, TaskDef taskDefinition, String taskId) { if (workflow.getSchemaVersion() > 1) { return getTaskInputV2(inputParams, workflow, taskId, taskDefinition); } return getTaskInputV1(workflow, inputParams); }
public Object replace(String paramString) { Configuration option = Configuration.defaultConfiguration().addOptions(Option.SUPPRESS_EXCEPTIONS); DocumentContext documentContext = JsonPath.parse(Collections.emptyMap(), option); return replaceVariables(paramString, documentContext, null); }
Pair<List<WorkflowTask>, Map<String, Map<String, Object>>> getDynamicForkJoinTasksAndInput(WorkflowTask taskToSchedule, Workflow workflowInstance) throws TerminateWorkflowException { String dynamicForkJoinTaskParam = taskToSchedule.getDynamicForkJoinTasksParam(); Map<String, Object> input = parametersUtils.getTaskInput(taskToSchedule.getInputParameters(), workflowInstance, null, null); Object paramValue = input.get(dynamicForkJoinTaskParam); DynamicForkJoinTaskList dynamicForkJoinTaskList = objectMapper.convertValue(paramValue, DynamicForkJoinTaskList.class);
@SuppressWarnings("unchecked") private Object replaceList(List<?> values, String taskId, DocumentContext io) { List<Object> replacedList = new LinkedList<>(); for (Object listVal : values) { if (listVal instanceof String) { Object replaced = replaceVariables(listVal.toString(), io, taskId); replacedList.add(replaced); } else if (listVal instanceof Map) { Object replaced = replace((Map<String, Object>) listVal, io, taskId); replacedList.add(replaced); } else if (listVal instanceof List) { Object replaced = replaceList((List<?>) listVal, taskId, io); replacedList.add(replaced); } else { replacedList.add(listVal); } } return replacedList; }
Map<String, Object> input = new HashMap<>(); input.put("sink", sinkValueRaw); Map<String, Object> replaced = parametersUtils.getTaskInputV2(input, workflow, task.getTaskId(), null); String sinkValue = (String)replaced.get("sink"); String queueName = sinkValue;
private Map<String, Object> startWorkflow(Action action, Object payload, String event, String messageId) { StartWorkflow params = action.getStart_workflow(); Map<String, Object> output = new HashMap<>(); try { Map<String, Object> inputParams = params.getInput(); Map<String, Object> workflowInput = parametersUtils.replace(inputParams, payload); workflowInput.put("conductor.event.messageId", messageId); workflowInput.put("conductor.event.name", event); String id = executor.startWorkflow(params.getName(), params.getVersion(), params.getCorrelationId(), workflowInput, null, event, params.getTaskToDomain()); output.put("workflowId", id); } catch (RuntimeException e) { logger.error("Error starting workflow: {}, version: {}, for event: {} for message: {}", params.getName(), params.getVersion(), event, messageId, e); output.put("error", e.getMessage()); throw e; } return output; } }
@Before public void setup() { workflowExecutor = mock(WorkflowExecutor.class); actionProcessor = new ActionProcessor(workflowExecutor, new ParametersUtils(), new JsonUtils()); }
/** * Updates the workflow output. * * @param workflow the workflow instance * @param task if not null, the output of this task will be copied to workflow output if no output parameters are specified in the workflow defintion * if null, the output of the last task in the workflow will be copied to workflow output of no output parameters are specified in the workflow definition */ void updateWorkflowOutput(final Workflow workflow, @Nullable Task task) { List<Task> allTasks = workflow.getTasks(); if (allTasks.isEmpty()) { return; } Task last = Optional.ofNullable(task).orElse(allTasks.get(allTasks.size() - 1)); WorkflowDef workflowDef = workflow.getWorkflowDefinition(); Map<String, Object> output; if (workflowDef.getOutputParameters() != null && !workflowDef.getOutputParameters().isEmpty()) { Workflow workflowInstance = populateWorkflowAndTaskData(workflow); output = parametersUtils.getTaskInput(workflowDef.getOutputParameters(), workflowInstance, null, null); } else if (StringUtils.isNotBlank(last.getExternalOutputPayloadStoragePath())) { output = externalPayloadStorageUtils.downloadPayload(last.getExternalOutputPayloadStoragePath()); Monitors.recordExternalPayloadStorageUsage(last.getTaskDefName(), ExternalPayloadStorage.Operation.READ.toString(), ExternalPayloadStorage.PayloadType.TASK_OUTPUT.toString()); } else { output = last.getOutputData(); } workflow.setOutput(output); externalPayloadStorageUtils.verifyAndUpload(workflow, ExternalPayloadStorage.PayloadType.WORKFLOW_OUTPUT); }
@SuppressWarnings("unchecked") private Map<String, Object> replace(Map<String, Object> input, DocumentContext documentContext, String taskId) { for (Entry<String, Object> e : input.entrySet()) { Object value = e.getValue(); if (value instanceof String) { Object replaced = replaceVariables(value.toString(), documentContext, taskId); e.setValue(replaced); } else if (value instanceof Map) { //recursive call Object replaced = replace((Map<String, Object>) value, documentContext, taskId); e.setValue(replaced); } else if (value instanceof List) { Object replaced = replaceList((List<?>) value, taskId, documentContext); e.setValue(replaced); } else { e.setValue(value); } } return input; }