Class StatusAndTiming
- java.lang.Object
-
- org.jenkinsci.plugins.workflow.pipelinegraphanalysis.StatusAndTiming
-
public class StatusAndTiming extends Object
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
FlowNode
s in the sameFlowExecution
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
FlowStartNode
for that execution - If a chunk has a null after node, then its last node must be the
FlowEndNode
for 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
WorkflowRun
is 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
- If a chunk has a null before node, then its first node must be the
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
StatusAndTiming.StatusApiVersion
Denotes the version of the status API supported, which marks the permittedGenericStatus
values it may return
-
Field Summary
Fields Modifier and Type Field Description static StatusAndTiming.StatusApiVersion
API_V1
static StatusAndTiming.StatusApiVersion
API_V2
static StatusAndTiming.StatusApiVersion
CURRENT_API_VERSION
static boolean
DISABLE_WARNING_ACTION_LOOKUP
-
Constructor Summary
Constructors Constructor Description StatusAndTiming()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static GenericStatus
coerceStatusApi(GenericStatus rawStatus, StatusAndTiming.StatusApiVersion desiredVersion)
Use this to permit consuming this API without having to be aware of newGenericStatus
codes.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 GenericStatus
computeChunkStatus(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 GenericStatus
computeChunkStatus(org.jenkinsci.plugins.workflow.job.WorkflowRun run, org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk)
Deprecated.static GenericStatus
computeChunkStatus2(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 GenericStatus
computeChunkStatus2(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 TimingInfo
computeChunkTiming(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 TimingInfo
computeChunkTiming(org.jenkinsci.plugins.workflow.job.WorkflowRun run, long internalPauseDuration, org.jenkinsci.plugins.workflow.graphanalysis.MemoryFlowChunk chunk)
static TimingInfo
computeOverallParallelTiming(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 GenericStatus
condenseStatus(Collection<GenericStatus> statuses)
Combines the status results from a list of parallel branches to report a single overall statusstatic org.jenkinsci.plugins.workflow.actions.WarningAction
findWorstWarningBetween(org.jenkinsci.plugins.workflow.graph.FlowNode start, org.jenkinsci.plugins.workflow.graph.FlowNode end)
Find the worst resultWarningAction
onFlowNode
s between the given start and end nodesstatic boolean
isPendingInput(org.jenkinsci.plugins.workflow.job.WorkflowRun run)
Return true if the run is paused on inputstatic void
printNodes(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 void
verifySameRun(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 Detail
-
API_V1
public static final StatusAndTiming.StatusApiVersion API_V1
-
API_V2
public static final StatusAndTiming.StatusApiVersion API_V2
-
CURRENT_API_VERSION
public static final StatusAndTiming.StatusApiVersion CURRENT_API_VERSION
-
DISABLE_WARNING_ACTION_LOOKUP
public static boolean DISABLE_WARNING_ACTION_LOOKUP
-
-
Method Detail
-
coerceStatusApi
public static GenericStatus coerceStatusApi(GenericStatus rawStatus, StatusAndTiming.StatusApiVersion desiredVersion)
Use this to permit consuming this API without having to be aware of newGenericStatus
codes. This will do a mapping from status codes to the closest equivalent in an older version of this API. For example,GenericStatus.QUEUED
was 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 coercesGenericStatus
values 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 coercesGenericStatus
values 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 resultWarningAction
onFlowNode
s 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
WarningAction
with 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
BlockEndNode
terminating 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
-
-
-