Class StatusAndTiming
java.lang.Object
io.jenkins.plugins.pipelinegraphview.analysis.StatusAndTiming
Provides common, comprehensive set of APIs for doing status and timing computations on pieces of a pipeline execution.
Concepts: a chunk, which is a set of FlowNodes in the same FlowExecution with a first and last node.
Chunks exist in a context: the FlowNode before and the FlowNode after. These follow common-sense rules:
- If a chunk has a null before node, then its first node must be the
FlowStartNodefor that execution - If a chunk has a null after node, then its last node must be the
FlowEndNodefor that execution - Both may be true at once (then the chunk contains the entire execution)
- First nodes must always occur before last nodes
- Where a
WorkflowRunis a parameter, it and the FlowNodes must all belong to the same execution
Parallel branch handling:
- Each branch is considered independent
- Branches may succeed, fail, or be in-progress/waiting for input.
- Author:
- Sam Van Oort
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classDenotes the version of the status API supported, which marks the permittedGenericStatusvalues it may return -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StatusAndTiming.StatusApiVersionstatic final StatusAndTiming.StatusApiVersionstatic final StatusAndTiming.StatusApiVersionstatic boolean -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic GenericStatuscoerceStatusApi(GenericStatus rawStatus, StatusAndTiming.StatusApiVersion desiredVersion) Use this to permit consuming this API without having to be aware of newGenericStatuscodes.static Map<String,GenericStatus> computeBranchStatuses(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, List<org.jenkinsci.plugins.workflow.graph.BlockStartNode> branchStarts, List<org.jenkinsci.plugins.workflow.graph.FlowNode> branchEnds, org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd) Deprecated.static Map<String,GenericStatus> computeBranchStatuses(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graphanalysis.ParallelMemoryFlowChunk parallel) Deprecated.static Map<String,GenericStatus> computeBranchStatuses2(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, List<org.jenkinsci.plugins.workflow.graph.BlockStartNode> branchStarts, List<org.jenkinsci.plugins.workflow.graph.FlowNode> branchEnds, org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd) Compute status codes for a set of parallel branches.static Map<String,GenericStatus> computeBranchStatuses2(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graphanalysis.ParallelMemoryFlowChunk parallel) Get statuses for each branch - note: some statuses may be null, API consumers MUST usecoerceStatusApi(GenericStatus, StatusApiVersion)on outputs to safely handle addition of new statuses.static GenericStatuscomputeChunkStatus(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graph.FlowNode before, org.jenkinsci.plugins.workflow.graph.FlowNode firstNode, org.jenkinsci.plugins.workflow.graph.FlowNode lastNode, org.jenkinsci.plugins.workflow.graph.FlowNode after) Deprecated.static GenericStatuscomputeChunkStatus(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk) Deprecated.static GenericStatuscomputeChunkStatus2(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graph.FlowNode before, org.jenkinsci.plugins.workflow.graph.FlowNode firstNode, org.jenkinsci.plugins.workflow.graph.FlowNode lastNode, org.jenkinsci.plugins.workflow.graph.FlowNode after) Compute the overall status for a chunk comprising firstNode through lastNode, inclusivestatic GenericStatuscomputeChunkStatus2(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk) Return status or null if not executed all (null FlowExecution) Note: API consumers MUST usecoerceStatusApi(GenericStatus, StatusApiVersion)on outputs to safely handle addition of new statuses.static TimingInfocomputeChunkTiming(org.jenkinsci.plugins.workflow.job.WorkflowRun run, long internalPauseDuration, org.jenkinsci.plugins.workflow.graph.FlowNode firstNode, org.jenkinsci.plugins.workflow.graph.FlowNode lastNode, org.jenkinsci.plugins.workflow.graph.FlowNode after) Compute timing for a chunk of nodesstatic TimingInfocomputeChunkTiming(org.jenkinsci.plugins.workflow.job.WorkflowRun run, long internalPauseDuration, org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk) static TimingInfocomputeOverallParallelTiming(org.jenkinsci.plugins.workflow.job.WorkflowRun run, Map<String, TimingInfo> branchTimings, org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd) Computes the branch timings for a set of parallel branches.static Map<String,TimingInfo> computeParallelBranchTimings(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, List<org.jenkinsci.plugins.workflow.graph.BlockStartNode> branchStarts, List<org.jenkinsci.plugins.workflow.graph.FlowNode> branchEnds, org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd, long[] pauseDurations) Compute timing for all branches of a parallelstatic GenericStatuscondenseStatus(Collection<GenericStatus> statuses) Combines the status results from a list of parallel branches to report a single overall statusstatic org.jenkinsci.plugins.workflow.actions.WarningActionfindWorstWarningBetween(org.jenkinsci.plugins.workflow.graph.FlowNode start, org.jenkinsci.plugins.workflow.graph.FlowNode end) Find the worst resultWarningActiononFlowNodes between the given start and end nodesstatic booleanisPendingInput(org.jenkinsci.plugins.workflow.job.WorkflowRun run) Return true if the run is paused on inputstatic voidprintNodes(org.jenkinsci.plugins.workflow.job.WorkflowRun run, boolean showTiming, boolean showActions) Helper, prints flow graph in some detail - now a common utility so others don't have to reinvent itstatic voidverifySameRun(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graph.FlowNode... nodes) Check that all the flownodes & run describe the same pipeline run/execution
-
Field Details
-
API_V1
-
API_V2
-
CURRENT_API_VERSION
-
DISABLE_WARNING_ACTION_LOOKUP
public static boolean DISABLE_WARNING_ACTION_LOOKUP
-
-
Constructor Details
-
StatusAndTiming
public StatusAndTiming()
-
-
Method Details
-
coerceStatusApi
public static GenericStatus coerceStatusApi(GenericStatus rawStatus, StatusAndTiming.StatusApiVersion desiredVersion) Use this to permit consuming this API without having to be aware of newGenericStatuscodes. This will do a mapping from status codes to the closest equivalent in an older version of this API. For example,GenericStatus.QUEUEDwas originally coded asGenericStatus.IN_PROGRESS- Parameters:
rawStatus- Input status from recent forms of this APIdesiredVersion- Defines the statuses supported by the API version we wish to consume- Returns:
- Input status correctly coerced to the best match among
StatusAndTiming.StatusApiVersion.allowedStatuses
-
verifySameRun
public static void verifySameRun(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode... nodes) throws IllegalArgumentException Check that all the flownodes & run describe the same pipeline run/execution- Parameters:
run- Run that nodes must belong tonodes- Nodes to match to run- Throws:
IllegalArgumentException- For the first flownode that doesn't belong to the FlowExecution of run
-
isPendingInput
public static boolean isPendingInput(org.jenkinsci.plugins.workflow.job.WorkflowRun run) Return true if the run is paused on input- Parameters:
run-- Returns:
-
computeChunkStatus
@CheckForNull @Deprecated public static GenericStatus computeChunkStatus(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk) Deprecated.Deprecated version that coercesGenericStatusvalues to the original set (withoutGenericStatus.QUEUED). Most consumers should switch tocomputeChunkStatus2(WorkflowRun, MemoryFlowChunk)and usecoerceStatusApi(GenericStatus, StatusApiVersion)to map new statuses to recognized ones. -
computeChunkStatus2
@CheckForNull public static GenericStatus computeChunkStatus2(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk) Return status or null if not executed all (null FlowExecution) Note: API consumers MUST usecoerceStatusApi(GenericStatus, StatusApiVersion)on outputs to safely handle addition of new statuses.- Parameters:
run-chunk-- Returns:
- Status or null if not executed all (null FlowExecution)
-
computeChunkStatus
@CheckForNull @Deprecated public static GenericStatus computeChunkStatus(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode before, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode firstNode, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode lastNode, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode after) Deprecated.Deprecated version that coercesGenericStatusvalues to the original set (withoutGenericStatus.QUEUED). Most consumers should switch tocomputeChunkStatus2(WorkflowRun, FlowNode, FlowNode, FlowNode, FlowNode)and handle unknown status codes. -
computeChunkStatus2
@CheckForNull public static GenericStatus computeChunkStatus2(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode before, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode firstNode, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode lastNode, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode after) Compute the overall status for a chunk comprising firstNode through lastNode, inclusiveAll nodes must be in the same execution
Note: for in-progress builds with parallel branches, if the branch is done, it has its own status.
Note: API consumers MUST usecoerceStatusApi(GenericStatus, StatusApiVersion)on outputs to safely handle addition of new statuses.- Parameters:
run- Run that nodes belong tobefore- Node before the first node in this piecefirstNode- First node of this piecelastNode- Last node of this piece (if lastNode==firstNode, it's a single FlowNode)after- Node after this piece, null if the lastNode is the currentHead of the flow- Returns:
- Status for the piece, or null if the FlowExecution is null.
-
findWorstWarningBetween
@CheckForNull public static org.jenkinsci.plugins.workflow.actions.WarningAction findWorstWarningBetween(@NonNull org.jenkinsci.plugins.workflow.graph.FlowNode start, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode end) Find the worst resultWarningActiononFlowNodes between the given start and end nodes- Parameters:
start- The flow node to start fromend- The flow node to end on- Returns:
- a possibly null
WarningActionwith the worst result
-
computeChunkTiming
@CheckForNull public static TimingInfo computeChunkTiming(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, long internalPauseDuration, @NonNull org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk) -
computeChunkTiming
@CheckForNull public static TimingInfo computeChunkTiming(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, long internalPauseDuration, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode firstNode, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode lastNode, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode after) Compute timing for a chunk of nodesNote: for in-progress builds with parallel branches, the running branches end at the current time. Completed branches use the time at which the
BlockEndNodeterminating the branch was created.- Parameters:
run- WorkflowRun they all belong tointernalPauseDuration- Millis paused in the chunk (including the ends)firstNode- First node in the chunklastNode- Last node in the chunkafter- Node after the chunk, if null we assume this chunk is at the end of the flow- Returns:
- Best guess at timing, or null if we can't compute anything (no FlowExecution exists)
-
computeOverallParallelTiming
@CheckForNull public static TimingInfo computeOverallParallelTiming(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull Map<String, TimingInfo> branchTimings, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd) Computes the branch timings for a set of parallel branches. This will comprise the longest pause time from any branch, and overall runtime.- Parameters:
run-branchTimings- Map of branch name : precomputed timing infoparallelStart-parallelEnd-- Returns:
-
computeParallelBranchTimings
@NonNull public static Map<String,TimingInfo> computeParallelBranchTimings(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, @NonNull List<org.jenkinsci.plugins.workflow.graph.BlockStartNode> branchStarts, @NonNull List<org.jenkinsci.plugins.workflow.graph.FlowNode> branchEnds, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd, @NonNull long[] pauseDurations) Compute timing for all branches of a parallel- Parameters:
run- Run the branches belong toparallelStart- Start of parallel blockbranchStarts- Nodes that begin each parallel branchbranchEnds- Nodes that represent the "tip" of each parallel branch (may be the end node, or just the latest)parallelEnd- End of parallel block (null if in progress)pauseDurations- Accumulated pause durations for each of the branches, in order- Returns:
- Map of branch name to timing.
-
computeBranchStatuses
@NonNull @Deprecated public static Map<String,GenericStatus> computeBranchStatuses(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graphanalysis.ParallelMemoryFlowChunk parallel) Deprecated.Get statuses for each branch - note: some statuses may be null. Retains compatibility with the original GenericStatus values. UsecomputeBranchStatuses2(WorkflowRun, ParallelMemoryFlowChunk)once you have a solid way to support new status codings. -
computeBranchStatuses2
@NonNull public static Map<String,GenericStatus> computeBranchStatuses2(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graphanalysis.ParallelMemoryFlowChunk parallel) Get statuses for each branch - note: some statuses may be null, API consumers MUST usecoerceStatusApi(GenericStatus, StatusApiVersion)on outputs to safely handle addition of new statuses. -
computeBranchStatuses
@Deprecated @NonNull public static Map<String,GenericStatus> computeBranchStatuses(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, @NonNull List<org.jenkinsci.plugins.workflow.graph.BlockStartNode> branchStarts, @NonNull List<org.jenkinsci.plugins.workflow.graph.FlowNode> branchEnds, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd) Deprecated.Get statuses for each branch - note: some statuses may be null. Retains compatibility with the original GenericStatus values. UsecomputeBranchStatuses2(WorkflowRun, FlowNode, List, List, FlowNode)once you support use ofcoerceStatusApi(GenericStatus, StatusApiVersion)to protect against changes. -
computeBranchStatuses2
@NonNull public static Map<String,GenericStatus> computeBranchStatuses2(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, @NonNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelStart, @NonNull List<org.jenkinsci.plugins.workflow.graph.BlockStartNode> branchStarts, @NonNull List<org.jenkinsci.plugins.workflow.graph.FlowNode> branchEnds, @CheckForNull org.jenkinsci.plugins.workflow.graph.FlowNode parallelEnd) Compute status codes for a set of parallel branches.Note per
Note: API consumers MUST usecomputeChunkStatus2(WorkflowRun, MemoryFlowChunk)for in-progress builds with parallel branches, if the branch is done, it has its own status.coerceStatusApi(GenericStatus, StatusApiVersion)on outputs to safely handle addition of new statuses.- Parameters:
run- Run containing these nodesbranchStarts- The nodes starting off each parallel branch (BlockStartNode)branchEnds- Last node in each parallel branch - might be the end of the branch, or might just be the latest step runparallelStart- Start node for overall parallel blockparallelEnd- End node for the overall parallelBlock (null if not complete)- Returns:
- Map of branch name to its status
-
condenseStatus
@CheckForNull public static GenericStatus condenseStatus(@NonNull Collection<GenericStatus> statuses) Combines the status results from a list of parallel branches to report a single overall status- Parameters:
statuses-- Returns:
- Status, or null if none can be defined
-
printNodes
@Restricted(org.kohsuke.accmod.restrictions.DoNotUse.class) public static void printNodes(@NonNull org.jenkinsci.plugins.workflow.job.WorkflowRun run, boolean showTiming, boolean showActions) Helper, prints flow graph in some detail - now a common utility so others don't have to reinvent it- Parameters:
run- Run to show nodes forshowTiming-showActions-
-