Search in sources :

Example 1 with BluePipelineNode

use of io.jenkins.blueocean.rest.model.BluePipelineNode in project blueocean-plugin by jenkinsci.

the class LinkResolverImpl method resolve.

@Override
public Link resolve(Object modelObject) {
    if (modelObject instanceof FlowNode) {
        FlowNode flowNode = (FlowNode) modelObject;
        BlueRun r = resolveFlowNodeRun(flowNode);
        if (PipelineNodeUtil.isParallelBranch(flowNode) || PipelineNodeUtil.isStage(flowNode)) {
            // its Node
            if (r != null) {
                return r.getLink().rel("nodes/" + flowNode.getId());
            }
        } else if (flowNode instanceof StepAtomNode && !PipelineNodeUtil.isStage(flowNode)) {
            if (r != null) {
                return r.getLink().rel("steps/" + flowNode.getId());
            }
        }
    } else if (modelObject instanceof BluePipelineNode || modelObject instanceof BluePipelineStep) {
        return ((Resource) modelObject).getLink();
    }
    return null;
}
Also used : BlueRun(io.jenkins.blueocean.rest.model.BlueRun) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 2 with BluePipelineNode

use of io.jenkins.blueocean.rest.model.BluePipelineNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeGraphVisitor method union.

@Override
public List<BluePipelineNode> union(List<FlowNodeWrapper> that, Link parent) {
    List<FlowNodeWrapper> currentNodes = new ArrayList<>(nodes);
    int currentNodeSize = nodes.size();
    int futureNodeSize = that.size();
    if (currentNodeSize < futureNodeSize) {
        for (int i = currentNodeSize; i < futureNodeSize; i++) {
            FlowNodeWrapper futureNode = that.get(i);
            //stitch future nodes to last nodes of current incomplete heads
            if (currentNodeSize > 0 && i == currentNodeSize) {
                FlowNodeWrapper latestNode = currentNodes.get(i - 1);
                if (latestNode.type == FlowNodeWrapper.NodeType.STAGE) {
                    if (futureNode.type == FlowNodeWrapper.NodeType.STAGE) {
                        latestNode.addEdge(futureNode.getId());
                    } else if (futureNode.type == FlowNodeWrapper.NodeType.PARALLEL) {
                        FlowNodeWrapper thatStage = futureNode.getFirstParent();
                        if (thatStage.equals(latestNode)) {
                            for (String edge : thatStage.edges) {
                                if (!latestNode.edges.contains(edge)) {
                                    latestNode.addEdge(edge);
                                }
                            }
                        }
                    }
                } else if (latestNode.type == FlowNodeWrapper.NodeType.PARALLEL) {
                    String futureNodeId = null;
                    FlowNodeWrapper thatStage = null;
                    if (futureNode.type == FlowNodeWrapper.NodeType.STAGE) {
                        thatStage = futureNode;
                        futureNodeId = futureNode.getId();
                    } else if (futureNode.type == FlowNodeWrapper.NodeType.PARALLEL && futureNode.getFirstParent().equals(latestNode.getFirstParent())) {
                        thatStage = futureNode.getFirstParent();
                        if (futureNode.edges.size() > 0) {
                            futureNodeId = futureNode.edges.get(0);
                        }
                    }
                    FlowNodeWrapper stage = latestNode.getFirstParent();
                    if (stage != null) {
                        //Add future node as edge to all edges of last stage
                        for (String id : stage.edges) {
                            FlowNodeWrapper node = nodeMap.get(id);
                            if (node != null && futureNodeId != null) {
                                node.addEdge(futureNodeId);
                            }
                        }
                        //now patch edges in case its partial
                        if (thatStage != null && futureNode.type == FlowNodeWrapper.NodeType.PARALLEL) {
                            for (String edge : thatStage.edges) {
                                if (!stage.edges.contains(edge)) {
                                    stage.addEdge(edge);
                                }
                            }
                        }
                    }
                }
            }
            FlowNodeWrapper n = new FlowNodeWrapper(futureNode.getNode(), new NodeRunStatus(null, null), new TimingInfo(), run);
            n.addEdges(futureNode.edges);
            n.addParents(futureNode.getParents());
            currentNodes.add(n);
        }
    }
    List<BluePipelineNode> newNodes = new ArrayList<>();
    for (FlowNodeWrapper n : currentNodes) {
        newNodes.add(new PipelineNodeImpl(n, parent, run));
    }
    return newNodes;
}
Also used : TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) ArrayList(java.util.ArrayList) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode)

Aggregations

BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)2 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 ArrayList (java.util.ArrayList)1 StepAtomNode (org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1 TimingInfo (org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo)1