Search in sources :

Example 1 with BlockEndNode

use of org.jenkinsci.plugins.workflow.graph.BlockEndNode in project workflow-job-plugin by jenkinsci.

the class GraphVizAction method writeDot.

private void writeDot(PrintWriter w) throws IOException {
    try {
        w.println("digraph G {");
        FlowGraphWalker walker = new FlowGraphWalker(run.getExecution());
        for (FlowNode n : walker) {
            for (FlowNode p : n.getParents()) {
                w.printf("%s -> %s%n", p.getId(), n.getId());
            }
            if (n instanceof BlockStartNode) {
                BlockStartNode sn = (BlockStartNode) n;
                w.printf("%s [shape=trapezium]%n", n.getId());
            } else if (n instanceof BlockEndNode) {
                BlockEndNode sn = (BlockEndNode) n;
                w.printf("%s [shape=invtrapezium]%n", n.getId());
                w.printf("%s -> %s [style=dotted]%n", sn.getStartNode().getId(), n.getId());
            }
            w.printf("%s [label=\"%s: %s\"]%n", n.getId(), n.getId(), n.getDisplayName());
        }
        w.println("}");
    } finally {
        w.close();
    }
}
Also used : BlockStartNode(org.jenkinsci.plugins.workflow.graph.BlockStartNode) FlowGraphWalker(org.jenkinsci.plugins.workflow.graph.FlowGraphWalker) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 2 with BlockEndNode

use of org.jenkinsci.plugins.workflow.graph.BlockEndNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeGraphVisitor method chunkEnd.

@Override
public void chunkEnd(@Nonnull FlowNode endNode, @CheckForNull FlowNode afterBlock, @Nonnull ForkScanner scanner) {
    super.chunkEnd(endNode, afterBlock, scanner);
    if (isNodeVisitorDumpEnabled) {
        dump(String.format("chunkEnd=> id: %s, name: %s, function: %s, type:%s", endNode.getId(), endNode.getDisplayName(), endNode.getDisplayFunctionName(), endNode.getClass()));
    }
    if (isNodeVisitorDumpEnabled && endNode instanceof StepEndNode) {
        dump("\tStartNode: " + ((StepEndNode) endNode).getStartNode());
    }
    if (endNode instanceof StepStartNode && PipelineNodeUtil.isAgentStart(endNode)) {
        agentNode = (StepStartNode) endNode;
    }
    // capture orphan branches
    captureOrphanParallelBranches();
    // if block stage node push it to stack as it may have nested stages
    if (parallelEnds.isEmpty() && endNode instanceof StepEndNode && // skip synthetic stages
    !PipelineNodeUtil.isSyntheticStage(((StepEndNode) endNode).getStartNode()) && PipelineNodeUtil.isStage(((StepEndNode) endNode).getStartNode())) {
        // XXX: There seems to be bug in eventing, chunkEnd is sent twice for the same FlowNode
        // Lets peek and if the last one is same as this endNode then skip adding it
        FlowNode node = null;
        if (!nestedStages.empty()) {
            node = nestedStages.peek();
        }
        if (node == null || !node.equals(endNode)) {
            nestedStages.push(endNode);
        }
    }
    firstExecuted = null;
    // if we're using marker-based (and not block-scoped) stages, add the last node as part of its contents
    if (!(endNode instanceof BlockEndNode)) {
        atomNode(null, endNode, afterBlock, scanner);
    }
}
Also used : StepStartNode(org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 3 with BlockEndNode

use of org.jenkinsci.plugins.workflow.graph.BlockEndNode in project blueocean-plugin by jenkinsci.

the class GraphDumpAction method doIndex.

public HttpResponse doIndex() throws IOException {
    JSONArray response = new JSONArray();
    FlowGraphWalker walker = new FlowGraphWalker(run.getExecution());
    for (FlowNode node : walker) {
        JSONObject outputNode = new JSONObject();
        outputNode.put("id", node.getId());
        outputNode.put("name", node.getDisplayName());
        outputNode.put("functionName", node.getDisplayFunctionName());
        outputNode.put("className", node.getClass().getName());
        outputNode.put("enclosingId", node.getEnclosingId());
        outputNode.put("isBegin", node instanceof BlockStartNode);
        outputNode.put("isEnd", node instanceof BlockEndNode);
        outputNode.put("isStepNode", node instanceof StepNode);
        if (node instanceof StepNode) {
            StepNode sn = (StepNode) node;
            StepDescriptor descriptor = sn.getDescriptor();
            if (descriptor != null) {
                JSONObject outputDescriptor = new JSONObject();
                outputDescriptor.put("getDisplayName", descriptor.getDisplayName());
                outputDescriptor.put("getFunctionName", descriptor.getFunctionName());
                outputNode.put("stepDescriptor", outputDescriptor);
            }
        }
        JSONArray parents = new JSONArray();
        for (FlowNode parent : node.getParents()) {
            parents.add(parent.getId());
        }
        outputNode.put("parents", parents);
        if (node instanceof BlockStartNode) {
            BlockStartNode startNode = (BlockStartNode) node;
            final BlockEndNode endNode = startNode.getEndNode();
            outputNode.put("endNodeId", endNode == null ? null : endNode.getId());
        } else if (node instanceof BlockEndNode) {
            BlockEndNode endNode = (BlockEndNode) node;
            outputNode.put("startNodeId", endNode.getStartNode().getId());
        }
        JSONArray actions = new JSONArray();
        for (Action action : node.getAllActions()) {
            JSONObject outputAction = new JSONObject();
            outputAction.put("className", action.getClass().getName());
            outputAction.put("displayName", action.getDisplayName());
            actions.add(outputAction);
        }
        outputNode.put("actions", actions);
        response.add(outputNode);
    }
    return HttpResponses.okJSON(response);
}
Also used : Action(hudson.model.Action) StepNode(org.jenkinsci.plugins.workflow.graph.StepNode) JSONObject(net.sf.json.JSONObject) BlockStartNode(org.jenkinsci.plugins.workflow.graph.BlockStartNode) JSONArray(net.sf.json.JSONArray) FlowGraphWalker(org.jenkinsci.plugins.workflow.graph.FlowGraphWalker) StepDescriptor(org.jenkinsci.plugins.workflow.steps.StepDescriptor) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Aggregations

BlockEndNode (org.jenkinsci.plugins.workflow.graph.BlockEndNode)3 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)3 BlockStartNode (org.jenkinsci.plugins.workflow.graph.BlockStartNode)2 FlowGraphWalker (org.jenkinsci.plugins.workflow.graph.FlowGraphWalker)2 Action (hudson.model.Action)1 JSONArray (net.sf.json.JSONArray)1 JSONObject (net.sf.json.JSONObject)1 StepEndNode (org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode)1 StepStartNode (org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode)1 StepNode (org.jenkinsci.plugins.workflow.graph.StepNode)1 StepDescriptor (org.jenkinsci.plugins.workflow.steps.StepDescriptor)1