Skip to content

Commit

Permalink
[FIXED JENKINS-12240] Fixing handling of MatrixProjects and MatrixCon…
Browse files Browse the repository at this point in the history
…figurations.
  • Loading branch information
abayer committed Jan 30, 2012
1 parent 2a8ba55 commit 3aa86a8
Showing 1 changed file with 31 additions and 16 deletions.
Expand Up @@ -27,7 +27,10 @@ public class ThrottleQueueTaskDispatcher extends QueueTaskDispatcher {

@Override
public CauseOfBlockage canTake(Node node, Task task) {

if (task instanceof MatrixConfiguration) {
return null;
}

ThrottleJobProperty tjp = getThrottleJobProperty(task);
if (tjp!=null && tjp.getThrottleEnabled()) {
CauseOfBlockage cause = canRun(task, tjp);
Expand Down Expand Up @@ -93,6 +96,9 @@ public CauseOfBlockage canRun(Queue.Item item) {
}

public CauseOfBlockage canRun(Task task, ThrottleJobProperty tjp) {
if (task instanceof MatrixConfiguration) {
return null;
}
if (Hudson.getInstance().getQueue().isPending(task)) {
return CauseOfBlockage.fromMessage(Messages._ThrottleQueueTaskDispatcher_BuildPending());
}
Expand Down Expand Up @@ -164,14 +170,14 @@ private int buildsOfProjectOnNode(Node node, Task task) {
// I think this'll be more reliable than job.getBuilds(), which seemed to not always get
// a build right after it was launched, for some reason.
for (Executor e : node.toComputer().getExecutors()) {
if (e.getCurrentExecutable()!=null
&& e.getCurrentExecutable().getParent() == task) {
// This means we've got a build of this project already running on this node.
LOGGER.fine("Found one");
runCount++;
runCount += buildsOnExecutor(task, e);
}
if (task instanceof MatrixProject) {
for (Executor e : node.toComputer().getOneOffExecutors()) {
runCount += buildsOnExecutor(task, e);
}
}

return runCount;
}

Expand All @@ -180,16 +186,30 @@ private int buildsOfProjectOnAllNodes(Task task) {

for (Computer c : Hudson.getInstance().getComputers()) {
for (Executor e : c.getExecutors()) {
if (e.getCurrentExecutable() != null
&& e.getCurrentExecutable().getParent() == task) {
totalRunCount++;
totalRunCount += buildsOnExecutor(task, e);
}

if (task instanceof MatrixProject) {
for (Executor e : c.getOneOffExecutors()) {
totalRunCount += buildsOnExecutor(task, e);
}
}
}

return totalRunCount;
}


private int buildsOnExecutor(Task task, Executor exec) {
int runCount = 0;
if (exec.getCurrentExecutable() != null
&& exec.getCurrentExecutable().getParent() == task) {
runCount++;
}

return runCount;
}


private List<AbstractProject<?,?>> getCategoryProjects(String category) {
List<AbstractProject<?,?>> categoryProjects = new ArrayList<AbstractProject<?,?>>();

Expand All @@ -200,11 +220,6 @@ private List<AbstractProject<?,?>> getCategoryProjects(String category) {
if (t!=null && t.getThrottleEnabled()) {
if (t.getCategories()!=null && t.getCategories().contains(category)) {
categoryProjects.add(p);
if (p instanceof MatrixProject) {
for (MatrixConfiguration mc : ((MatrixProject)p).getActiveConfigurations()) {
categoryProjects.add((AbstractProject<?,?>)mc);
}
}
}
}
}
Expand Down

0 comments on commit 3aa86a8

Please sign in to comment.