Search in sources :

Example 1 with StepAtomNode

use of org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode in project blueocean-plugin by jenkinsci.

the class PipelineNodeGraphVisitor method parallelStart.

@Override
public void parallelStart(@Nonnull FlowNode parallelStartNode, @Nonnull FlowNode branchNode, @Nonnull ForkScanner scanner) {
    if (isNodeVisitorDumpEnabled) {
        dump(String.format("parallelStart=> id: %s, name: %s, function: %s", parallelStartNode.getId(), parallelStartNode.getDisplayName(), parallelStartNode.getDisplayFunctionName()));
        dump(String.format("\tbranch=> id: %s, name: %s, function: %s", branchNode.getId(), branchNode.getDisplayName(), branchNode.getDisplayFunctionName()));
    }
    if (nestedbranches.size() != parallelBranchEndNodes.size()) {
        logger.error(String.format("nestedBranches size: %s not equal to parallelBranchEndNodes: %s", nestedbranches.size(), parallelBranchEndNodes.size()));
        return;
    }
    while (!nestedbranches.empty() && !parallelBranchEndNodes.empty()) {
        FlowNode branchStartNode = nestedbranches.pop();
        FlowNode endNode = parallelBranchEndNodes.pop();
        TimingInfo times;
        NodeRunStatus status;
        if (endNode != null) {
            times = StatusAndTiming.computeChunkTiming(run, chunk.getPauseTimeMillis(), branchStartNode, endNode, chunk.getNodeAfter());
            if (endNode instanceof StepAtomNode) {
                if (PipelineNodeUtil.isPausedForInputStep((StepAtomNode) endNode, inputAction)) {
                    status = new NodeRunStatus(BlueRun.BlueRunResult.UNKNOWN, BlueRun.BlueRunState.PAUSED);
                } else {
                    status = new NodeRunStatus(endNode);
                }
            } else {
                GenericStatus genericStatus = StatusAndTiming.computeChunkStatus(run, parallelStartNode, branchStartNode, endNode, parallelEnd);
                status = new NodeRunStatus(genericStatus);
            }
        } else {
            times = new TimingInfo(TimingAction.getStartTime(branchStartNode) + System.currentTimeMillis(), chunk.getPauseTimeMillis(), TimingAction.getStartTime(branchStartNode));
            status = new NodeRunStatus(BlueRun.BlueRunResult.UNKNOWN, BlueRun.BlueRunState.RUNNING);
        }
        FlowNodeWrapper branch = new FlowNodeWrapper(branchStartNode, status, times, run);
        if (nextStage != null) {
            branch.addEdge(nextStage.getId());
        }
        parallelBranches.push(branch);
    }
    FlowNodeWrapper[] sortedBranches = parallelBranches.toArray(new FlowNodeWrapper[parallelBranches.size()]);
    Arrays.sort(sortedBranches, new Comparator<FlowNodeWrapper>() {

        @Override
        public int compare(FlowNodeWrapper o1, FlowNodeWrapper o2) {
            return o1.getDisplayName().compareTo(o2.getDisplayName());
        }
    });
    parallelBranches.clear();
    for (int i = 0; i < sortedBranches.length; i++) {
        parallelBranches.push(sortedBranches[i]);
    }
    for (FlowNodeWrapper p : parallelBranches) {
        nodes.push(p);
        nodeMap.put(p.getId(), p);
    }
    //reset parallelEnd node for next parallel block
    this.parallelEnd = null;
}
Also used : GenericStatus(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus) TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 2 with StepAtomNode

use of org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode in project blueocean-plugin by jenkinsci.

the class PipelineStepVisitor method atomNode.

@Override
public void atomNode(@CheckForNull FlowNode before, @Nonnull FlowNode atomNode, @CheckForNull FlowNode after, @Nonnull ForkScanner scan) {
    if (stageStepsCollectionCompleted && !PipelineNodeUtil.isSyntheticStage(currentStage)) {
        return;
    }
    if (atomNode instanceof StepEndNode) {
        this.closestEndNode = (StepEndNode) atomNode;
    }
    if (atomNode instanceof StepAtomNode && !PipelineNodeUtil.isSkippedStage(currentStage)) {
        //if skipped stage, we don't collect its steps
        long pause = PauseAction.getPauseDuration(atomNode);
        chunk.setPauseTimeMillis(chunk.getPauseTimeMillis() + pause);
        TimingInfo times = StatusAndTiming.computeChunkTiming(run, pause, atomNode, atomNode, after);
        if (times == null) {
            times = new TimingInfo();
        }
        NodeRunStatus status;
        InputStep inputStep = null;
        if (PipelineNodeUtil.isPausedForInputStep((StepAtomNode) atomNode, inputAction)) {
            status = new NodeRunStatus(BlueRun.BlueRunResult.UNKNOWN, BlueRun.BlueRunState.PAUSED);
            try {
                for (InputStepExecution execution : inputAction.getExecutions()) {
                    FlowNode node = execution.getContext().get(FlowNode.class);
                    if (node != null && node.equals(atomNode)) {
                        inputStep = execution.getInput();
                        break;
                    }
                }
            } catch (IOException | InterruptedException | TimeoutException e) {
                logger.error("Error getting FlowNode from execution context: " + e.getMessage(), e);
            }
        } else {
            status = new NodeRunStatus(atomNode);
        }
        FlowNodeWrapper node = new FlowNodeWrapper(atomNode, status, times, inputStep, run);
        if (PipelineNodeUtil.isPreSyntheticStage(currentStage)) {
            preSteps.add(node);
        } else if (PipelineNodeUtil.isPostSyntheticStage(currentStage)) {
            postSteps.add(node);
        } else {
            if (!steps.contains(node)) {
                steps.push(node);
            }
        }
        stepMap.put(node.getId(), node);
        //If there is closest block boundary, we capture it's error to the last step encountered and prepare for next block.
        if (closestEndNode != null && closestEndNode.getError() != null) {
            node.setBlockErrorAction(closestEndNode.getError());
            //prepare for next block
            closestEndNode = null;
        }
    }
}
Also used : TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) IOException(java.io.IOException) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) InputStepExecution(org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution) InputStep(org.jenkinsci.plugins.workflow.support.steps.input.InputStep) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with StepAtomNode

use of org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode 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)

Aggregations

StepAtomNode (org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)3 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)3 TimingInfo (org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo)2 BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)1 BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)1 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)1 IOException (java.io.IOException)1 TimeoutException (java.util.concurrent.TimeoutException)1 StepEndNode (org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode)1 GenericStatus (org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus)1 InputStep (org.jenkinsci.plugins.workflow.support.steps.input.InputStep)1 InputStepExecution (org.jenkinsci.plugins.workflow.support.steps.input.InputStepExecution)1