Search in sources :

Example 1 with BluePipelineStep

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

the class PipelineNodeGraphVisitor method getPipelineNodeSteps.

@Override
public List<BluePipelineStep> getPipelineNodeSteps(final String nodeId, Link parent) {
    FlowExecution execution = run.getExecution();
    if (execution == null) {
        logger.debug(String.format("Pipeline %s, runid %s  has null execution", run.getParent().getName(), run.getId()));
        return Collections.emptyList();
    }
    DepthFirstScanner depthFirstScanner = new DepthFirstScanner();
    // If blocked scope, get the end node
    FlowNode n = depthFirstScanner.findFirstMatch(execution.getCurrentHeads(), input -> (input != null && input.getId().equals(nodeId) && (PipelineNodeUtil.isStage(input) || PipelineNodeUtil.isParallelBranch(input))));
    if (n == null) {
        // if no node found or the node is not stage or parallel we return empty steps
        return Collections.emptyList();
    }
    PipelineStepVisitor visitor = new PipelineStepVisitor(run, n);
    ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
    return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
Also used : DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) Arrays(java.util.Arrays) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) LoggerFactory(org.slf4j.LoggerFactory) LabelAction(org.jenkinsci.plugins.workflow.actions.LabelAction) StringUtils(org.apache.commons.lang3.StringUtils) GenericStatus(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) ExecutionModelAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Action(hudson.model.Action) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) StepStartNode(org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode) List(java.util.List) PauseAction(org.jenkinsci.plugins.workflow.support.actions.PauseAction) Optional(java.util.Optional) FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) TimingAction(org.jenkinsci.plugins.workflow.actions.TimingAction) HashMap(java.util.HashMap) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) StandardChunkVisitor(org.jenkinsci.plugins.workflow.graphanalysis.StandardChunkVisitor) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) StatusAndTiming(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) NotExecutedNodeAction(org.jenkinsci.plugins.workflow.actions.NotExecutedNodeAction) IOException(java.io.IOException) ForkScanner(org.jenkinsci.plugins.workflow.graphanalysis.ForkScanner) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 2 with BluePipelineStep

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

the class NodeLogResource method doIndex.

public void doIndex(StaplerRequest req, StaplerResponse rsp, @Header("Accept") AcceptHeader accept) {
    String download = req.getParameter("download");
    if ("true".equalsIgnoreCase(download)) {
        rsp.setHeader("Content-Disposition", "attachment; filename=log.txt");
    }
    rsp.setContentType("text/plain;charset=UTF-8");
    rsp.setStatus(HttpServletResponse.SC_OK);
    long count = 0;
    try (CharSpool spool = new CharSpool()) {
        for (BluePipelineStep blueStep : steps) {
            if (blueStep instanceof PipelineStepImpl) {
                PipelineStepImpl step = (PipelineStepImpl) blueStep;
                final FlowNodeWrapper node = step.getFlowNodeWrapper();
                if (node.isLoggable()) {
                    LogAction logAction = node.getNode().getAction(LogAction.class);
                    if (logAction != null) {
                        count += logAction.getLogText().writeLogTo(0, spool);
                        String errorLog = node.blockError();
                        if (errorLog != null) {
                            count += appendError(errorLog, new WriterOutputStream(spool));
                        }
                    }
                } else {
                    String errorLog = step.getFlowNodeWrapper().nodeError();
                    if (errorLog == null) {
                        errorLog = step.getFlowNodeWrapper().blockError();
                    }
                    if (errorLog != null) {
                        count += appendError(errorLog, new WriterOutputStream(spool));
                    }
                }
            }
        }
        Writer writer;
        if (count > 0) {
            writer = (count > 4096) ? rsp.getCompressedWriter(req) : rsp.getWriter();
            spool.flush();
            spool.writeTo(new LineEndNormalizingWriter(writer));
            rsp.addHeader("X-Text-Size", String.valueOf(count));
            writer.close();
        }
    } catch (IOException e) {
        throw new ServiceException.UnexpectedErrorException("Error reading log");
    }
}
Also used : IOException(java.io.IOException) WriterOutputStream(org.kohsuke.stapler.framework.io.WriterOutputStream) LineEndNormalizingWriter(org.kohsuke.stapler.framework.io.LineEndNormalizingWriter) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) LogAction(org.jenkinsci.plugins.workflow.actions.LogAction) ServiceException(io.jenkins.blueocean.commons.ServiceException) CharSpool(org.kohsuke.stapler.framework.io.CharSpool) LineEndNormalizingWriter(org.kohsuke.stapler.framework.io.LineEndNormalizingWriter) Writer(java.io.Writer)

Example 3 with BluePipelineStep

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

the class PipelineNodeTest method checkConsistencyWhileBuilding.

private String checkConsistencyWhileBuilding(String jenkinsFileName) throws Exception {
    /*
            Run a complex pipeline to completion, then start a new build and inspect it while it's running, to exercise
            the code that merges incomplete runs with previous builds to generate a complete graph
         */
    WorkflowJob p = createWorkflowJobWithJenkinsfile(getClass(), jenkinsFileName);
    // Do an initial run, collect the nodes
    final WorkflowRun run1 = p.scheduleBuild2(0).waitForStart();
    j.waitForCompletion(run1);
    final List<BluePipelineNode> completeNodes = new PipelineNodeContainerImpl(run1, new Link("foo")).getNodes();
    final String completeNodeNames = completeNodes.stream().map(BluePipelineStep::getDisplayName).sorted().collect(Collectors.joining(", "));
    // Start another build...
    final WorkflowRun run2 = p.scheduleBuild2(0).waitForStart();
    // ... then watch while it runs, checking for the same graph nodes
    int loopCount = 0;
    do {
        Thread.sleep(1000);
        List<BluePipelineNode> runningNodes = new PipelineNodeContainerImpl(run2, new Link("foo")).getNodes();
        String runningNodeNames = runningNodes.stream().map(BluePipelineStep::getDisplayName).sorted().collect(Collectors.joining(", "));
        assertEquals("running node names", completeNodeNames, runningNodeNames);
        loopCount++;
    } while (run2.isBuilding());
    // Sanity check, make sure we're *actually* checking stuff.
    assertTrue("Checked multiple times while building", loopCount > 5);
    // So caller can do any additional checks
    return completeNodeNames;
}
Also used : WorkflowJob(org.jenkinsci.plugins.workflow.job.WorkflowJob) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep)

Example 4 with BluePipelineStep

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

the class PipelineNodeGraphVisitor method getPipelineNodeSteps.

@Override
public List<BluePipelineStep> getPipelineNodeSteps(Link parent) {
    FlowExecution execution = run.getExecution();
    if (execution == null) {
        return Collections.emptyList();
    }
    PipelineStepVisitor visitor = new PipelineStepVisitor(run, null);
    ForkScanner.visitSimpleChunks(execution.getCurrentHeads(), visitor, new StageChunkFinder());
    return visitor.getSteps().stream().map(node -> new PipelineStepImpl(node, parent)).collect(Collectors.toList());
}
Also used : DepthFirstScanner(org.jenkinsci.plugins.workflow.graphanalysis.DepthFirstScanner) Arrays(java.util.Arrays) InputAction(org.jenkinsci.plugins.workflow.support.steps.input.InputAction) LoggerFactory(org.slf4j.LoggerFactory) LabelAction(org.jenkinsci.plugins.workflow.actions.LabelAction) StringUtils(org.apache.commons.lang3.StringUtils) GenericStatus(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.GenericStatus) MemoryFlowChunk(org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk) Map(java.util.Map) ExecutionModelAction(org.jenkinsci.plugins.pipeline.modeldefinition.actions.ExecutionModelAction) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BluePipelineNode(io.jenkins.blueocean.rest.model.BluePipelineNode) Action(hudson.model.Action) Collection(java.util.Collection) Set(java.util.Set) Collectors(java.util.stream.Collectors) StepStartNode(org.jenkinsci.plugins.workflow.cps.nodes.StepStartNode) List(java.util.List) PauseAction(org.jenkinsci.plugins.workflow.support.actions.PauseAction) Optional(java.util.Optional) FlowStartNode(org.jenkinsci.plugins.workflow.graph.FlowStartNode) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) WorkflowRun(org.jenkinsci.plugins.workflow.job.WorkflowRun) Link(io.jenkins.blueocean.rest.hal.Link) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode) TimingAction(org.jenkinsci.plugins.workflow.actions.TimingAction) HashMap(java.util.HashMap) Stack(java.util.Stack) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) TimingInfo(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.TimingInfo) BlockEndNode(org.jenkinsci.plugins.workflow.graph.BlockEndNode) StandardChunkVisitor(org.jenkinsci.plugins.workflow.graphanalysis.StandardChunkVisitor) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) StatusAndTiming(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming) BluePipelineStep(io.jenkins.blueocean.rest.model.BluePipelineStep) BlueRun(io.jenkins.blueocean.rest.model.BlueRun) NotExecutedNodeAction(org.jenkinsci.plugins.workflow.actions.NotExecutedNodeAction) IOException(java.io.IOException) ForkScanner(org.jenkinsci.plugins.workflow.graphanalysis.ForkScanner) StepAtomNode(org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode) StepEndNode(org.jenkinsci.plugins.workflow.cps.nodes.StepEndNode) ArrayDeque(java.util.ArrayDeque) Comparator(java.util.Comparator) CheckForNull(javax.annotation.CheckForNull) Collections(java.util.Collections) StageChunkFinder(org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StageChunkFinder) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution)

Example 5 with BluePipelineStep

use of io.jenkins.blueocean.rest.model.BluePipelineStep 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

BluePipelineStep (io.jenkins.blueocean.rest.model.BluePipelineStep)5 BluePipelineNode (io.jenkins.blueocean.rest.model.BluePipelineNode)4 Link (io.jenkins.blueocean.rest.hal.Link)3 BlueRun (io.jenkins.blueocean.rest.model.BlueRun)3 IOException (java.io.IOException)3 StepAtomNode (org.jenkinsci.plugins.workflow.cps.nodes.StepAtomNode)3 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)3 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Action (hudson.model.Action)2 ArrayDeque (java.util.ArrayDeque)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Comparator (java.util.Comparator)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2