Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Extension for Job Restriction Plugin
This extension will enable Node usage based on Job Priority, addressing [JENKINS-23640].
- Loading branch information
Showing
3 changed files
with
107 additions
and
4 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
84 changes: 84 additions & 0 deletions
84
src/main/java/jenkins/advancedqueue/jobrestrictions/PrioritySorterRestriction.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,84 @@ | ||
package jenkins.advancedqueue.jobrestrictions; | ||
|
||
import hudson.Extension; | ||
import hudson.model.Queue.BuildableItem; | ||
import hudson.model.Run; | ||
import hudson.util.ListBoxModel; | ||
import jenkins.advancedqueue.PrioritySorterConfiguration; | ||
import jenkins.advancedqueue.sorter.ItemInfo; | ||
import jenkins.advancedqueue.sorter.QueueItemCache; | ||
import jenkins.advancedqueue.util.PrioritySorterUtil; | ||
|
||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.QueryParameter; | ||
|
||
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestriction; | ||
import com.synopsys.arc.jenkinsci.plugins.jobrestrictions.restrictions.JobRestrictionDescriptor; | ||
|
||
/** | ||
* @since 3.3 | ||
*/ | ||
public class PrioritySorterRestriction extends JobRestriction { | ||
|
||
@Extension(optional = true) | ||
public static class DescriptorImpl extends JobRestrictionDescriptor { | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return "Priority from PrioritySorter"; | ||
} | ||
|
||
public ListBoxModel doFillFromPriorityItems() { | ||
return PrioritySorterUtil.fillPriorityItems(PrioritySorterConfiguration.get().getStrategy() | ||
.getNumberOfPriorities()); | ||
} | ||
|
||
public ListBoxModel doFillToPriorityItems() { | ||
return PrioritySorterUtil.fillPriorityItems(PrioritySorterConfiguration.get().getStrategy() | ||
.getNumberOfPriorities()); | ||
} | ||
|
||
public ListBoxModel doUpdateFromPriorityItems(@QueryParameter("value") String strValue) { | ||
int value = 1; | ||
try { | ||
value = Integer.valueOf(strValue); | ||
} catch (NumberFormatException e) { | ||
// Use default value | ||
} | ||
ListBoxModel items = PrioritySorterUtil.fillPriorityItems(value, PrioritySorterConfiguration.get() | ||
.getStrategy().getNumberOfPriorities()); | ||
return items; | ||
} | ||
|
||
} | ||
|
||
private int fromPriority; | ||
|
||
private int toPriority; | ||
|
||
public int getFromPriority() { | ||
return fromPriority; | ||
} | ||
|
||
public int getToPriority() { | ||
return toPriority; | ||
} | ||
|
||
@DataBoundConstructor | ||
public PrioritySorterRestriction(int fromPriority, int toPriority) { | ||
this.fromPriority = fromPriority; | ||
this.toPriority = toPriority; | ||
} | ||
|
||
@Override | ||
public boolean canTake(BuildableItem buildableItem) { | ||
ItemInfo item = QueueItemCache.get().getItem(buildableItem.id); | ||
int priority = item.getPriority(); | ||
return priority >= fromPriority && priority <= toPriority; | ||
} | ||
|
||
@Override | ||
public boolean canTake(Run run) { | ||
return true; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...in/resources/jenkins/advancedqueue/jobrestrictions/PrioritySorterRestriction/config.jelly
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,12 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:sl="/hudson/plugins/sidebar_link"> | ||
<f:entry title="From Priority (inclusive)" field="fromPriority"> | ||
<f:select | ||
id="fromPriority" | ||
default="${descriptor.defaultPriority}" | ||
onchange="updateListBox('toPriority','${rootURL}/descriptorByName/jenkins.advancedqueue.jobrestrictions.PrioritySorterRestriction/updateFromPriorityItems?value='+encode(this.value))" /> | ||
</f:entry> | ||
<f:entry title="To Priority (inclusive)" field="toPriority"> | ||
<f:select id="toPriority" default="${descriptor.defaultPriority}"/> | ||
</f:entry> | ||
</j:jelly> |