Search in sources :

Example 1 with TaskGraphVO

use of com.epam.pipeline.controller.vo.TaskGraphVO in project cloud-pipeline by epam.

the class PipelineDocumentTemplateManager method applyTools.

private void applyTools(PipelineDocumentTemplate template) {
    TaskGraphVO taskGraph = pipelineVersionManager.getWorkflowGraph(template.getPipeline().getId(), template.getVersion().getName());
    template.setWorkflowGraph(taskGraph);
    List<Tool> tools = taskGraph.getTasks().stream().filter(t -> t.getTool() != null).map(TaskNode::getTool).collect(Collectors.toList());
    template.setOpenSourceSoftware(tools);
}
Also used : TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 2 with TaskGraphVO

use of com.epam.pipeline.controller.vo.TaskGraphVO in project cloud-pipeline by epam.

the class PipelineVersionManager method getWorkflowGraph.

public TaskGraphVO getWorkflowGraph(Long id, String version) {
    Pipeline pipeline = pipelineManager.load(id);
    try {
        gitManager.loadRevision(pipeline, version);
    } catch (GitClientException e) {
        LOGGER.error(e.getMessage(), e);
        throw new IllegalArgumentException(e.getMessage());
    }
    File config = gitManager.getConfigFile(pipeline, version);
    TaskGraphVO result = new GraphReader().readGraph(graphScript, config.getParentFile().getAbsolutePath(), CONFIG_FILE_NAME);
    mergeToolsRequirements(result);
    try {
        FileUtils.deleteDirectory(config.getParentFile());
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
    }
    return result;
}
Also used : GraphReader(com.epam.pipeline.manager.python.GraphReader) GitClientException(com.epam.pipeline.exception.git.GitClientException) TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) IOException(java.io.IOException) File(java.io.File) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline)

Example 3 with TaskGraphVO

use of com.epam.pipeline.controller.vo.TaskGraphVO in project cloud-pipeline by epam.

the class GraphReader method createGraphFromScriptOutput.

protected TaskGraphVO createGraphFromScriptOutput(String output) {
    String[] lines = output.split("\\n");
    if (lines.length == 0) {
        return new TaskGraphVO(new TaskNode(new PipelineTask()));
    }
    // first line is always name of the root task
    String mainTaskName = lines[0].trim();
    // important: for main task inputs and outputs are reverted, due
    // to luigi's approach to graph calculation
    TaskNode mainTask = new TaskNode(new PipelineTask(mainTaskName));
    TaskNode currentTask = mainTask;
    Map<String, TaskNode> tasks = new HashMap<>();
    tasks.put(mainTaskName, mainTask);
    mainTask.getTask().setId(1L);
    for (int i = 1; i < lines.length; i++) {
        String line = lines[i];
        if (line.isEmpty()) {
            continue;
        }
        if (line.startsWith(INPUT_START) && currentTask != null) {
            String value = line.substring(INPUT_START.length());
            parseValue(currentTask.getInputs(), value);
        } else if (line.startsWith(OUTPUT_START) && currentTask != null) {
            String value = line.substring(OUTPUT_START.length());
            parseValue(currentTask.getOutputs(), value);
        } else if (line.startsWith(TOOL_START) && currentTask != null) {
            parseTool(currentTask, line);
        } else if (line.contains(DEPENDENCY_DELIMITER)) {
            String[] dependency = line.split(DEPENDENCY_DELIMITER);
            TaskNode fromTask = getOrCreateNode(dependency[0].trim(), tasks);
            String secondTaskName = dependency.length > 1 ? dependency[1].trim() : "";
            // input to all pipeline
            if (dependency.length == 1 || secondTaskName.isEmpty()) {
                currentTask = null;
                mainTask.getOutputs().addAll(fromTask.getInputs());
            } else {
                TaskNode toTask = getOrCreateNode(secondTaskName, tasks);
                currentTask = toTask;
                toTask.addParent(fromTask.getTask().getId());
            }
        }
    }
    // switch output and input for main task
    mainTask.switchInputOutput();
    TaskGraphVO graph = new TaskGraphVO(mainTask);
    graph.setTasks(new ArrayList<>(tasks.values()));
    return graph;
}
Also used : TaskNode(com.epam.pipeline.entity.graph.TaskNode) HashMap(java.util.HashMap) TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) PipelineTask(com.epam.pipeline.entity.pipeline.PipelineTask)

Example 4 with TaskGraphVO

use of com.epam.pipeline.controller.vo.TaskGraphVO in project cloud-pipeline by epam.

the class GraphReaderTest method testParsing.

@Test
public void testParsing() {
    String output = "SimplePipeline(sample=&sample&, run_id=&run_id&)\n" + "IN:R1_001_fastqc.zip;L001_R2_001_fastqc.zip;AlignmentSummaryMetrics.txt;\n" + "OUT:\n" + "SimplePipeline(sample=&sample&, run_id=&run_id&) => " + "FastQC(sample=&sample&, run_id=&run_id&, first=True)\n" + "IN:L001_R1_001.fastq.gz;L001_R2_001.fastq.gz;\n" + "OUT:L001_R1_001_fastqc.zip;L001_R1_001_fastqc.html;\n" + "FastQC(sample=&sample&, run_id=&run_id&, first=True) => \n" + "IN:\n" + "OUT:L001_R1_001.fastq.gz;L001_R2_001.fastq.gz;\n" + "SimplePipeline(sample=&sample&, run_id=&run_id&) => " + "FastQC(sample=&sample&, run_id=&run_id&, first=False)\n" + "IN:L001_R1_001.fastq.gz;L001_R2_001.fastq.gz;\n" + "OUT:L001_R2_001_fastqc.zip;L001_R2_001_fastqc.html;\n" + "FastQC(sample=&sample&, run_id=&run_id&, first=False) => \n" + "IN:\n" + "OUT:L001_R1_001.fastq.gz;L001_R2_001.fastq.gz;\n" + "SimplePipeline(sample=&sample&, run_id=&run_id&) =>" + " AlignmentSummaryMetrics(sample=&sample&, run_id=&run_id&)\n" + "IN:sample.bai\n" + "OUT:AlignmentSummaryMetrics.txt\n";
    GraphReader reader = new GraphReader();
    TaskGraphVO graph = reader.createGraphFromScriptOutput(output);
    Assert.assertNotNull(graph);
    Assert.assertEquals(4, graph.getTasks().size());
}
Also used : TaskGraphVO(com.epam.pipeline.controller.vo.TaskGraphVO) Test(org.junit.Test)

Aggregations

TaskGraphVO (com.epam.pipeline.controller.vo.TaskGraphVO)4 TaskNode (com.epam.pipeline.entity.graph.TaskNode)1 Pipeline (com.epam.pipeline.entity.pipeline.Pipeline)1 PipelineTask (com.epam.pipeline.entity.pipeline.PipelineTask)1 Tool (com.epam.pipeline.entity.pipeline.Tool)1 GitClientException (com.epam.pipeline.exception.git.GitClientException)1 GraphReader (com.epam.pipeline.manager.python.GraphReader)1 File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1