Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-11997] Consider jobs in the Executors for priority sorter
Introducing "Run Exclusive", with "Run Exclusive" set on a JobGroup only Jobs from that JobGroup will be started until no more Jobs from that JobGroup is in queue being run.
- Loading branch information
Showing
4 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/main/java/jenkins/advancedqueue/RunExclusiveThrottler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package jenkins.advancedqueue; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import hudson.model.Queue.Item; | ||
import hudson.model.Queue.LeftItem; | ||
import hudson.model.listeners.RunListener; | ||
import hudson.model.queue.CauseOfBlockage; | ||
import hudson.model.queue.QueueTaskDispatcher; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import jenkins.advancedqueue.sorter.ItemInfo; | ||
import jenkins.advancedqueue.sorter.QueueItemCache; | ||
import jenkins.model.Jenkins; | ||
|
||
public class RunExclusiveThrottler { | ||
|
||
static private List<String> exclusiveJobs = Collections.synchronizedList(new ArrayList<String>()); | ||
static private int exclusiveJobGroupId = -1; | ||
static private String exclusiveJobName = ""; | ||
|
||
@Extension | ||
static public class RunExclusiveRunListener extends RunListener<Run> { | ||
|
||
@Override | ||
public void onStarted(Run r, TaskListener listener) { | ||
System.out.println("Started: " + r.getParent().getName()); | ||
ItemInfo item = QueueItemCache.get().getItem(r.getParent().getName()); | ||
if (PriorityConfiguration.get().getJobGroup(item.getJobGroupId()).isRunExclusive()) { | ||
System.out.println("Is Exclusive"); | ||
exclusiveJobGroupId = item.getJobGroupId(); | ||
exclusiveJobName = item.getJobName(); | ||
exclusiveJobs.add(item.getJobName()); | ||
} | ||
} | ||
|
||
@Override | ||
public void onCompleted(Run r, TaskListener listener) { | ||
exclusiveJobs.remove(r.getParent().getName()); | ||
} | ||
|
||
} | ||
|
||
private static class RunExclusiveMode extends CauseOfBlockage { | ||
|
||
@Override | ||
public String getShortDescription() { | ||
return "Run Exclusive (" + exclusiveJobName + ")"; | ||
} | ||
|
||
} | ||
|
||
@Extension | ||
static public class RunExclusiveDispatcher extends QueueTaskDispatcher { | ||
|
||
@Override | ||
public CauseOfBlockage canRun(Item item) { | ||
if(exclusiveJobs.size() > 0) { | ||
System.out.println(QueueItemCache.get().getItem(item.id).getJobGroupId() + " = " + exclusiveJobGroupId); | ||
if (QueueItemCache.get().getItem(item.id).getJobGroupId() != exclusiveJobGroupId) { | ||
System.out.println("dENY " + item.task.getName()); | ||
return new RunExclusiveMode(); | ||
} | ||
} | ||
System.out.println("Allow " + item.task.getName()); | ||
return null; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters