Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit of priority sorter

The priority sorter allows for jobs in the build queue to be
sorted by priority rather than just FIFO.
  • Loading branch information...
commit f416dba2ff536c36c0e5d41528000a008fc6b248 0 parents
Brad Larson authored
2  .gitignore
@@ -0,0 +1,2 @@
+target
+work
22 LICENSE.txt
@@ -0,0 +1,22 @@
+The MIT License
+
+Copyright (c) 2010-, Brad Larson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+
11 README.txt
@@ -0,0 +1,11 @@
+This plugin adds a Job Priority field to each Hudson job. Jobs with higher
+priorities will be ran before jobs with lower priorities when there are jobs
+waiting in the build queue. This can be very helpful when one wants to add
+low priority jobs but wants to have higher-priority jobs run first when
+hardware is limited.
+
+=============
+
+Maintainer
+
+Brad Larson - bklarson@gmail.com
54 pom.xml
@@ -0,0 +1,54 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.jvnet.hudson.plugins</groupId>
+ <artifactId>plugin</artifactId>
+ <version>1.343</version><!-- which version of Hudson is this plugin built against? -->
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>hudson.queueSorter</groupId>
+ <artifactId>PrioritySorter</artifactId>
+ <version>1.0</version>
+ <packaging>hpi</packaging>
+ <name>Priority Sorter</name>
+ <description>This plugin allows for the build queue to be sorted based on pre-assigned priorities for each job.</description>
+
+ <licenses>
+ <license>
+ <name>MIT</name>
+ <url>http://www.opensource.org/licenses/mit-license.php</url>
+ <comments>Copyright 2010 Brad Larson. All rights reserved.</comments>
+ </license>
+ </licenses>
+
+ <developers>
+ <developer>
+ <id>bklarson</id>
+ <name>Brad Larson</name>
+ <email>bklarson@gmail.com</email>
+ <roles>
+ <role>developer</role>
+ <role>maintainer</role>
+ </roles>
+ <timezone>-6</timezone>
+ </developer>
+ </developers>
+
+ <!-- get every artifact through maven.glassfish.org, which proxies all the artifacts that we need -->
+ <repositories>
+ <repository>
+ <id>m.g.o-public</id>
+ <url>http://maven.glassfish.org/content/groups/public/</url>
+ </repository>
+ </repositories>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>m.g.o-public</id>
+ <url>http://maven.glassfish.org/content/groups/public/</url>
+ </pluginRepository>
+ </pluginRepositories>
+</project>
59 src/main/java/hudson/queueSorter/PrioritySorterJobProperty.java
@@ -0,0 +1,59 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2010, Brad Larson
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package hudson.queueSorter;
+
+import hudson.Extension;
+import hudson.model.JobProperty;
+import hudson.model.JobPropertyDescriptor;
+import hudson.model.AbstractProject;
+
+import org.kohsuke.stapler.DataBoundConstructor;
+
+public class PrioritySorterJobProperty extends
+ JobProperty<AbstractProject<?, ?>> {
+
+ public final int priority;
+
+ @DataBoundConstructor
+ public PrioritySorterJobProperty(int priority) {
+ this.priority = priority;
+ }
+
+ public int getPriority() {
+ return priority;
+ }
+
+ @Override
+ public DescriptorImpl getDescriptor() {
+ return (DescriptorImpl) super.getDescriptor();
+ }
+
+ @Extension
+ public static final class DescriptorImpl extends JobPropertyDescriptor {
+ @Override
+ public String getDisplayName() {
+ return "Job Priority";
+ }
+ }
+}
68 src/main/java/hudson/queueSorter/PrioritySorterQueueSorter.java
@@ -0,0 +1,68 @@
+/*
+ * The MIT License
+ *
+ * Copyright (c) 2010, Brad Larson
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+package hudson.queueSorter;
+
+import hudson.Extension;
+import hudson.model.AbstractProject;
+import hudson.model.Queue.BuildableItem;
+import hudson.model.queue.QueueSorter;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+@Extension
+public class PrioritySorterQueueSorter extends QueueSorter {
+
+ private static final class BuildableComparitor implements
+ Comparator<BuildableItem> {
+
+ public int compare(BuildableItem arg0, BuildableItem arg1) {
+ // Note that we sort these backwards because we want to return
+ // higher-numbered items first.
+ Integer priority1 = getPriority(arg1);
+ return priority1.compareTo(getPriority(arg0));
+ }
+
+ private static int getPriority(BuildableItem buildable) {
+ if (!(buildable.task instanceof AbstractProject)) {
+ // This shouldn't happen... but just in case, let's give this
+ // task a really low priority so jobs with valid priorities
+ // which do work will get built first.
+ return 0;
+ }
+ AbstractProject<?, ?> project = (AbstractProject<?, ?>) buildable.task;
+ PrioritySorterJobProperty priority = project
+ .getProperty(PrioritySorterJobProperty.class);
+ return priority.priority;
+ }
+ }
+
+ private static final BuildableComparitor comparitor = new BuildableComparitor();
+
+ @Override
+ public void sortBuildableItems(List<BuildableItem> buildables) {
+ Collections.sort(buildables, comparitor);
+ }
+}
16 src/main/resources/hudson/queueSorter/PrioritySorterJobProperty/config.jelly
@@ -0,0 +1,16 @@
+<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">
+
+ <f:entry title="Job Priority" field="priority">
+ <f:textbox name="prioritySorter.priority" value="${instance.priority}"
+ clazz="required number"
+ default="100"
+ />
+ </f:entry>
+
+</j:jelly>
4 src/main/resources/hudson/queueSorter/PrioritySorterJobProperty/help-priority.html
@@ -0,0 +1,4 @@
+<div>
+ The priority for this job. Priorities are used when all executors are busy to decide which job
+ in the build queue to run next. A job with higher priority is ran before jobs with lower priorities.
+</div>
8 src/main/resources/index.jelly
@@ -0,0 +1,8 @@
+<!--
+ This view is used to render the plugin list page.
+
+ Since we don't really have anything dynamic here, let's just use static HTML.
+-->
+<div>
+ This plugin allows for the build queue to be sorted based on pre-assigned priorities for each job.
+</div>
Please sign in to comment.
Something went wrong with that request. Please try again.