Skip to content
This repository has been archived by the owner on Dec 15, 2021. It is now read-only.

Commit

Permalink
[JENKINS-26090] Using Executables.getExecutor.
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick committed Mar 19, 2015
1 parent 3f7c488 commit 5cef1a7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 26 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -28,7 +28,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.596.1</version>
<version>1.606-SNAPSHOT</version>
</parent>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-pom</artifactId>
Expand Down
Expand Up @@ -28,13 +28,12 @@
import org.jenkinsci.plugins.workflow.support.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Executor;
import hudson.model.Node;
import hudson.model.OneOffExecutor;
import hudson.model.Queue;
import hudson.model.queue.Executables;
import hudson.model.queue.SubTask;
import jenkins.model.Jenkins;

import java.util.concurrent.Future;

Expand Down Expand Up @@ -80,17 +79,9 @@ protected Executor tryResolve() throws Exception {
}

Queue.Executable exec = future.get();

Jenkins j = Jenkins.getInstance();
if (j == null) {
return null;
}
for (Computer c : j.getComputers()) {
for (Executor e : c.getExecutors()) {
if (e.getCurrentExecutable() == exec) {
return e;
}
}
Executor e = Executables.getExecutor(exec);
if (e != null) {
return e;
}

// TODO this could happen as a race condition if the executable takes <1s to run; how could that be prevented?
Expand Down
Expand Up @@ -16,6 +16,7 @@
import hudson.model.TaskListener;
import hudson.model.TopLevelItem;
import hudson.model.queue.CauseOfBlockage;
import hudson.model.queue.Executables;
import hudson.model.queue.SubTask;
import hudson.remoting.ChannelClosedException;
import hudson.remoting.RequestAbortedException;
Expand Down Expand Up @@ -468,18 +469,7 @@ private final class PlaceholderExecutable implements ContinuableExecutable {

@Restricted(DoNotUse.class) // for Jelly
public @CheckForNull Executor getExecutor() {
Jenkins j = Jenkins.getInstance();
if (j == null) {
return null;
}
for (Computer c : j.getComputers()) {
for (Executor e : c.getExecutors()) {
if (e.getCurrentExecutable() == this) {
return e;
}
}
}
return null;
return Executables.getExecutor(this);
}

@Restricted(NoExternalUse.class) // for Jelly and toString
Expand Down

0 comments on commit 5cef1a7

Please sign in to comment.