Skip to content

Commit

Permalink
Merge pull request #199 from jglick/FlowExecutionList-JENKINS-37998
Browse files Browse the repository at this point in the history
[JENKINS-37998] Avoid iterating `FlowExecutionList` to populate `InputAction.executions`
  • Loading branch information
jglick authored Jan 10, 2025
2 parents 9a98d24 + bd7b91b commit 584c0e9
Showing 1 changed file with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.jenkinsci.plugins.workflow.flow.FlowExecution;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionList;
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner;
import org.jenkinsci.plugins.workflow.steps.StepExecution;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
Expand Down Expand Up @@ -63,31 +62,29 @@ public void onLoad(Run<?, ?> r) {
private synchronized void loadExecutions() throws InterruptedException, TimeoutException {
if (executions == null) {
try {
FlowExecution execution = null;
for (FlowExecution _execution : FlowExecutionList.get()) {
if (_execution.getOwner().getExecutable() == run) {
execution = _execution;
break;
}
}
if (execution != null) {
List<StepExecution> candidateExecutions = execution.getCurrentExecutions(true).get(LOAD_EXECUTIONS_TIMEOUT, TimeUnit.SECONDS);
executions = new ArrayList<>(); // only set this if we know the answer
// JENKINS-37154 sometimes we must block here in order to get accurate results
for (StepExecution se : candidateExecutions) {
if (se instanceof InputStepExecution) {
InputStepExecution ise = (InputStepExecution) se;
if (ids.contains(ise.getId())) {
executions.add(ise);
if (run instanceof FlowExecutionOwner.Executable) {

Check warning on line 65 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/InputAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 65 is only partially covered, one branch is missing
var feo = ((FlowExecutionOwner.Executable) run).asFlowExecutionOwner();
if (feo != null) {

Check warning on line 67 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/InputAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 67 is only partially covered, one branch is missing
var candidateExecutions = feo.get().getCurrentExecutions(true).get(LOAD_EXECUTIONS_TIMEOUT, TimeUnit.SECONDS);
executions = new ArrayList<>(); // only set this if we know the answer
// JENKINS-37154 sometimes we must block here in order to get accurate results
for (StepExecution se : candidateExecutions) {
if (se instanceof InputStepExecution) {
InputStepExecution ise = (InputStepExecution) se;
if (ids.contains(ise.getId())) {
executions.add(ise);
}
}
}
if (executions.size() < ids.size()) {
LOGGER.log(Level.WARNING, "some input IDs not restored from {0}", run);
}
} else {
LOGGER.warning(() -> "no FlowExecutionOwner obtainable from " + run);

Check warning on line 83 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/InputAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 83 is not covered by tests
}
} else {
LOGGER.warning(() -> "unrecognized build type " + run);

Check warning on line 86 in src/main/java/org/jenkinsci/plugins/workflow/support/steps/input/InputAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 86 is not covered by tests
}
if (executions.size() < ids.size()) {
LOGGER.log(Level.WARNING, "some input IDs not restored from {0}", run);
}
} else {
LOGGER.log(Level.WARNING, "no flow execution found for {0}", run);
}
} catch (InterruptedException | TimeoutException x) {
throw x;
} catch (Exception x) {
Expand Down

0 comments on commit 584c0e9

Please sign in to comment.