use of io.boomerang.mongo.model.next.DAGTask in project flow.service.workflow by boomerang-io.
the class FlowActivityServiceImpl method setupTaskOutputResults.
private void setupTaskOutputResults(TaskExecutionEntity task, TaskExecutionResponse response, List<TaskOutputResult> results) {
if (task.getTemplateId() == null) {
return;
}
Integer templateVersion = task.getTemplateRevision();
FlowTaskTemplateEntity flowTaskTemplate = templateService.getTaskTemplateWithId(task.getTemplateId());
String templateType = flowTaskTemplate.getNodetype();
if ("templateTask".equals(templateType)) {
List<Revision> revisions = flowTaskTemplate.getRevisions();
if (revisions != null) {
Optional<Revision> result = revisions.stream().parallel().filter(revision -> revision.getVersion().equals(templateVersion)).findAny();
if (result.isPresent()) {
Revision revision = result.get();
List<TaskResult> taskResults = revision.getResults();
if (taskResults != null) {
for (TaskResult resultItem : taskResults) {
extractOutputProperty(task, results, resultItem);
}
}
} else {
Optional<Revision> latestRevision = revisions.stream().sorted(Comparator.comparingInt(Revision::getVersion).reversed()).findFirst();
if (latestRevision.isPresent()) {
List<TaskResult> taskResults = latestRevision.get().getResults();
if (taskResults != null) {
for (TaskResult resultItem : taskResults) {
extractOutputProperty(task, results, resultItem);
}
}
}
}
}
} else {
String activityId = task.getActivityId();
ActivityEntity activity = workflowActivityService.findWorkflowActivtyById(activityId);
String revisionId = activity.getWorkflowRevisionid();
Optional<RevisionEntity> revisionEntity = this.revisionService.getRevision(revisionId);
if (revisionEntity.isPresent()) {
RevisionEntity revision = revisionEntity.get();
List<DAGTask> tasks = revision.getDag().getTasks();
DAGTask dagTask = tasks.stream().filter(x -> x.getTaskId().equals(task.getTaskId())).findFirst().orElse(null);
if (dagTask != null) {
dagTask.getResults();
List<TaskResult> dagResults = dagTask.getResults();
if (dagResults != null) {
for (TaskResult taskResult : dagResults) {
TaskOutputResult outputResult = new TaskOutputResult();
String key = taskResult.getName();
outputResult.setName(key);
outputResult.setDescription(taskResult.getDescription());
if (task.getOutputs() != null && task.getOutputs().containsKey(key)) {
outputResult.setValue(task.getOutputs().get(key));
}
results.add(outputResult);
}
}
}
}
}
response.setResults(results);
}
use of io.boomerang.mongo.model.next.DAGTask in project flow.service.workflow by boomerang-io.
the class TaskServiceImpl method createTaskList.
private List<Task> createTaskList(RevisionEntity revisionEntity, ActivityEntity activity) {
// NOSONAR
final Dag dag = revisionEntity.getDag();
final List<Task> taskList = new LinkedList<>();
for (final DAGTask dagTask : dag.getTasks()) {
final Task newTask = new Task();
newTask.setTaskId(dagTask.getTaskId());
newTask.setTaskType(dagTask.getType());
newTask.setTaskName(dagTask.getLabel());
final String workFlowId = revisionEntity.getWorkFlowId();
newTask.setWorkflowId(workFlowId);
if (dagTask.getType() == TaskType.script || dagTask.getType() == TaskType.template || dagTask.getType() == TaskType.customtask) {
TaskExecutionEntity task = taskActivityService.findByTaskIdAndActivityId(dagTask.getTaskId(), activity.getId());
if (task != null) {
newTask.setTaskActivityId(task.getId());
}
String templateId = dagTask.getTemplateId();
final FlowTaskTemplateEntity flowTaskTemplate = templateService.getTaskTemplateWithId(templateId);
newTask.setTemplateId(flowTaskTemplate.getId());
Integer templateVersion = dagTask.getTemplateVersion();
List<Revision> revisions = flowTaskTemplate.getRevisions();
if (revisions != null) {
Optional<Revision> result = revisions.stream().parallel().filter(revision -> revision.getVersion().equals(templateVersion)).findAny();
if (result.isPresent()) {
Revision revision = result.get();
newTask.setRevision(revision);
newTask.setResults(revision.getResults());
} else {
Optional<Revision> latestRevision = revisions.stream().sorted(Comparator.comparingInt(Revision::getVersion).reversed()).findFirst();
if (latestRevision.isPresent()) {
newTask.setRevision(latestRevision.get());
newTask.setResults(newTask.getRevision().getResults());
}
}
} else {
throw new IllegalArgumentException("Invalid task template selected: " + templateId);
}
Map<String, String> properties = new HashMap<>();
if (dagTask.getProperties() != null) {
for (KeyValuePair property : dagTask.getProperties()) {
properties.put(property.getKey(), property.getValue());
}
}
newTask.setInputs(properties);
if (newTask.getResults() == null) {
newTask.setResults(dagTask.getResults());
}
} else if (dagTask.getType() == TaskType.decision) {
TaskExecutionEntity task = taskActivityService.findByTaskIdAndActivityId(dagTask.getTaskId(), activity.getId());
if (task != null) {
newTask.setTaskActivityId(task.getId());
}
newTask.setDecisionValue(dagTask.getDecisionValue());
} else if (dagTask.getType() == TaskType.manual || dagTask.getType() == TaskType.runworkflow || dagTask.getType() == TaskType.runscheduledworkflow || dagTask.getType() == TaskType.setwfproperty || dagTask.getType() == TaskType.setwfstatus || dagTask.getType() == TaskType.acquirelock || dagTask.getType() == TaskType.releaselock) {
TaskExecutionEntity task = taskActivityService.findByTaskIdAndActivityId(dagTask.getTaskId(), activity.getId());
if (task != null) {
newTask.setTaskActivityId(task.getId());
}
Map<String, String> properties = new HashMap<>();
if (dagTask.getProperties() != null) {
for (KeyValuePair property : dagTask.getProperties()) {
properties.put(property.getKey(), property.getValue());
}
}
newTask.setInputs(properties);
}
final List<String> taskDepedancies = new LinkedList<>();
for (Dependency dependency : dagTask.getDependencies()) {
taskDepedancies.add(dependency.getTaskId());
}
newTask.setDetailedDepednacies(dagTask.getDependencies());
newTask.setDependencies(taskDepedancies);
taskList.add(newTask);
}
return taskList;
}
use of io.boomerang.mongo.model.next.DAGTask in project flow.service.workflow by boomerang-io.
the class WorkflowServiceImpl method buildAvailableParamList.
private List<String> buildAvailableParamList(String workFlowId, RevisionEntity revision) {
List<String> parameters = new ArrayList<>();
WorkflowEntity workflow = workflowRepository.getWorkflow(workFlowId);
if (flowSettingsService.getConfiguration("features", "globalParameters").getBooleanValue()) {
Map<String, String> globalProperties = new HashMap<>();
propertyManager.buildGlobalProperties(globalProperties);
for (Map.Entry<String, String> globalProperty : globalProperties.entrySet()) {
parameters.add("global.params." + globalProperty.getKey());
parameters.add("params." + globalProperty.getKey());
}
}
if (flowSettingsService.getConfiguration("features", "teamParameters").getBooleanValue() && workflow.getScope() != null && WorkflowScope.team.equals(workflow.getScope())) {
Map<String, String> teamProperties = new HashMap<>();
propertyManager.buildTeamProperties(teamProperties, workflow.getId());
for (Map.Entry<String, String> teamProperty : teamProperties.entrySet()) {
parameters.add("team.params." + teamProperty.getKey());
parameters.add("params." + teamProperty.getKey());
}
}
Map<String, String> workflowProperties = new HashMap<>();
propertyManager.buildWorkflowProperties(workflowProperties, null, workflow.getId());
for (Map.Entry<String, String> workflowProperty : workflowProperties.entrySet()) {
parameters.add("workflow.params." + workflowProperty.getKey());
parameters.add("params." + workflowProperty.getKey());
}
Map<String, String> systemProperties = new HashMap<>();
propertyManager.buildSystemProperties(null, null, workflow.getId(), systemProperties);
for (Map.Entry<String, String> systemProperty : systemProperties.entrySet()) {
parameters.add("system.params." + systemProperty.getKey());
parameters.add("params." + systemProperty.getKey());
}
if (revision != null) {
Dag dag = revision.getDag();
List<DAGTask> dagkTasks = dag.getTasks();
if (dagkTasks != null) {
for (DAGTask task : dagkTasks) {
String taskName = task.getLabel();
if (task.getTemplateId() != null) {
String templateId = task.getTemplateId();
FlowTaskTemplateEntity taskTemplate = templateService.getTaskTemplateWithId(templateId);
if (taskTemplate != null) {
if ("templateTask".equals(taskTemplate.getNodetype())) {
int revisionCount = taskTemplate.getRevisions().size();
Revision latestRevision = taskTemplate.getRevisions().stream().filter(x -> x.getVersion() == revisionCount).findFirst().orElse(null);
if (latestRevision != null) {
List<TaskResult> results = latestRevision.getResults();
if (results != null) {
for (TaskResult result : results) {
String key = "tasks." + taskName + ".results." + result.getName();
parameters.add(key);
}
}
}
} else {
List<TaskResult> results = task.getResults();
if (results != null) {
for (TaskResult result : results) {
String key = "tasks." + taskName + ".results." + result.getName();
parameters.add(key);
}
}
}
}
}
}
}
}
return parameters;
}
use of io.boomerang.mongo.model.next.DAGTask in project flow.service.workflow by boomerang-io.
the class DAGUtility method createTaskList.
private List<Task> createTaskList(RevisionEntity revisionEntity, ActivityEntity activity) {
final Dag dag = revisionEntity.getDag();
final List<Task> taskList = new LinkedList<>();
for (final DAGTask dagTask : dag.getTasks()) {
final Task newTask = new Task();
newTask.setTaskId(dagTask.getTaskId());
newTask.setTaskType(dagTask.getType());
newTask.setTaskName(dagTask.getLabel());
TaskExecutionEntity task = taskActivityService.findByTaskIdAndActivityId(dagTask.getTaskId(), activity.getId());
if (task != null) {
newTask.setTaskActivityId(task.getId());
}
final String workFlowId = revisionEntity.getWorkFlowId();
newTask.setWorkflowId(workFlowId);
if (dagTask.getType() == TaskType.script || dagTask.getType() == TaskType.template || dagTask.getType() == TaskType.customtask) {
String templateId = dagTask.getTemplateId();
final FlowTaskTemplateEntity flowTaskTemplate = templateService.getTaskTemplateWithId(templateId);
newTask.setTemplateId(flowTaskTemplate.getId());
Integer templateVersion = dagTask.getTemplateVersion();
List<Revision> revisions = flowTaskTemplate.getRevisions();
if (revisions != null) {
Optional<Revision> result = revisions.stream().parallel().filter(revision -> revision.getVersion().equals(templateVersion)).findAny();
if (result.isPresent()) {
Revision revision = result.get();
newTask.setRevision(revision);
newTask.setResults(revision.getResults());
} else {
Optional<Revision> latestRevision = revisions.stream().sorted(Comparator.comparingInt(Revision::getVersion).reversed()).findFirst();
if (latestRevision.isPresent()) {
newTask.setRevision(latestRevision.get());
newTask.setResults(newTask.getRevision().getResults());
}
}
} else {
throw new IllegalArgumentException("Invalid task template selected: " + templateId);
}
Map<String, String> properties = new HashMap<>();
if (dagTask.getProperties() != null) {
for (KeyValuePair property : dagTask.getProperties()) {
properties.put(property.getKey(), property.getValue());
}
}
newTask.setInputs(properties);
if (newTask.getResults() == null) {
newTask.setResults(dagTask.getResults());
}
} else if (dagTask.getType() == TaskType.decision) {
newTask.setDecisionValue(dagTask.getDecisionValue());
}
final List<String> taskDepedancies = new LinkedList<>();
for (Dependency dependency : dagTask.getDependencies()) {
taskDepedancies.add(dependency.getTaskId());
}
newTask.setDetailedDepednacies(dagTask.getDependencies());
newTask.setDependencies(taskDepedancies);
taskList.add(newTask);
}
return taskList;
}
use of io.boomerang.mongo.model.next.DAGTask in project flow.service.workflow by boomerang-io.
the class ModelConverterV5 method convertToEntityModel.
public static RevisionEntity convertToEntityModel(WorkflowRevision revision) {
RevisionEntity entity = new RevisionEntity();
entity.setVersion(revision.getVersion());
entity.setMarkdown(revision.getMarkdown());
entity.setConfig(revision.getConfig());
if (revision.getDag() == null) {
return entity;
}
mapBaseData(revision, entity);
List<Link> links = revision.getDag().getLinks();
List<ConfigNodes> configNodes = revision.getConfig().getNodes();
Dag dag = new Dag();
entity.setDag(dag);
List<DAGTask> tasks = new LinkedList<>();
dag.setTasks(tasks);
for (TaskNode node : revision.getDag().getNodes()) {
DAGTask dagTask = new DAGTask();
dagTask.setId(node.getNodeId());
dagTask.setTemplateId(node.getTaskId());
if ("startend".equals(node.getType())) {
if ("Start".equals(node.getPassedName())) {
dagTask.setType(TaskType.start);
} else if ("End".equals(node.getPassedName())) {
dagTask.setType(TaskType.end);
}
} else if (TEMPLATETASKNAME.equals(node.getType())) {
dagTask.setType(TaskType.template);
} else if (CUSTOMTASKNAME.equals(node.getType())) {
dagTask.setType(TaskType.customtask);
} else {
dagTask.setType(TaskType.valueOf(node.getType()));
}
List<Dependency> dependencies = new LinkedList<>();
dagTask.setDependencies(dependencies);
List<Port> ports = node.getPorts();
ConfigNodes config = configNodes.stream().parallel().filter(c -> node.getNodeId().equals(c.getNodeId())).findFirst().orElse(null);
dagTask.setLabel(node.getTaskName());
buildConfig(dagTask, config);
caclulateDependncies(links, dependencies, ports);
buildMetadataSection(node, dagTask);
tasks.add(dagTask);
}
return entity;
}
Aggregations