Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-23552] Replace "Allow priorities directly on Jobs"
Browse files Browse the repository at this point in the history
 * Moved and renamed "AdvancedQueueSorterJobProperty"
  • Loading branch information
emsa23 committed Jun 25, 2014
1 parent bc8860e commit 9c6c54d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 10 deletions.
Expand Up @@ -36,6 +36,7 @@
import java.util.logging.Logger;

import jenkins.advancedqueue.JobGroup.PriorityStrategyHolder;
import jenkins.advancedqueue.priority.strategy.PriorityJobProperty;
import jenkins.advancedqueue.sorter.SorterStrategy;
import jenkins.advancedqueue.sorter.SorterStrategyDescriptor;
import jenkins.advancedqueue.sorter.strategy.AbsoluteStrategy;
Expand Down Expand Up @@ -206,14 +207,14 @@ private void updatePriorities(int prevNumberOfPriorities) {
for (AbstractProject<?, ?> project : allProjects) {
try {
// Scale any priority on the Job
AdvancedQueueSorterJobProperty priorityProperty = project
.getProperty(AdvancedQueueSorterJobProperty.class);
PriorityJobProperty priorityProperty = project
.getProperty(PriorityJobProperty.class);
if (priorityProperty != null && priorityProperty.getUseJobPriority()) {
int newPriority = PriorityCalculationsUtil.scale(prevNumberOfPriorities,
strategy.getNumberOfPriorities(), priorityProperty.priority);
if (newPriority != priorityProperty.getPriority()) {
project.removeProperty(priorityProperty);
project.addProperty(new AdvancedQueueSorterJobProperty(priorityProperty.getUseJobPriority(),
project.addProperty(new PriorityJobProperty(priorityProperty.getUseJobPriority(),
newPriority));
project.save();
}
Expand Down Expand Up @@ -256,7 +257,7 @@ private void convertFromLegacyToAdvanced() {
if (legacyPriorityProperty != null) {
int advancedPriority = legacyPriorityToAdvancedPriority(legacyMinPriority, legacyMaxPriority,
strategy.getNumberOfPriorities(), legacyPriorityProperty.priority);
AdvancedQueueSorterJobProperty advancedQueueSorterJobProperty = new AdvancedQueueSorterJobProperty(
PriorityJobProperty advancedQueueSorterJobProperty = new PriorityJobProperty(
true, advancedPriority);
try {
project.addProperty(advancedQueueSorterJobProperty);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/jenkins/advancedqueue/PrioritySorterPlugin.java
Expand Up @@ -24,12 +24,19 @@
package jenkins.advancedqueue;

import static hudson.init.InitMilestone.JOB_LOADED;
import static hudson.init.InitMilestone.PLUGINS_STARTED;
import hudson.Plugin;
import hudson.init.Initializer;
import hudson.model.Items;
import hudson.widgets.Widget;

import java.util.List;
import java.util.logging.Logger;

import jenkins.advancedqueue.priority.strategy.PriorityJobProperty;
import jenkins.advancedqueue.sorter.AdvancedQueueSorter;
import jenkins.advancedqueue.widgets.BuildQueueWidget;
import jenkins.model.Jenkins;

/**
* Plugin is the staring point of the Priority Sorter Plugin.
Expand All @@ -43,6 +50,12 @@ public class PrioritySorterPlugin extends Plugin {

private final static Logger LOGGER = Logger.getLogger(PrioritySorterPlugin.class.getName());

@Initializer(before=PLUGINS_STARTED)
public static void addAliases() {
// Moved in 3.0 when JobPropertyStrategy was added
Items.XSTREAM2.addCompatibilityAlias("jenkins.advancedqueue.AdvancedQueueSorterJobProperty", PriorityJobProperty.class);
}

@Initializer(after = JOB_LOADED)
public static void init() {
// Check for any Legacy Configuration and init the Configuration
Expand Down
Expand Up @@ -27,7 +27,6 @@
import hudson.model.Job;
import hudson.model.Queue;
import hudson.model.Queue.Item;
import jenkins.advancedqueue.AdvancedQueueSorterJobProperty;

import org.kohsuke.stapler.DataBoundConstructor;

Expand All @@ -54,7 +53,7 @@ public JobPropertyStrategy() {
private Integer getPriorityInternal(Queue.Item item) {
if(item.task instanceof Job<?, ?>) {
Job<?, ?> job = (Job<?, ?>) item.task;
AdvancedQueueSorterJobProperty priorityProperty = job.getProperty(AdvancedQueueSorterJobProperty.class);
PriorityJobProperty priorityProperty = job.getProperty(PriorityJobProperty.class);
if (priorityProperty != null && priorityProperty.getUseJobPriority()) {
return priorityProperty.priority;
}
Expand Down
Expand Up @@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package jenkins.advancedqueue;
package jenkins.advancedqueue.priority.strategy;

import hudson.Extension;
import hudson.model.AbstractProject;
Expand All @@ -33,6 +33,11 @@

import java.util.logging.Logger;

import jenkins.advancedqueue.JobGroup;
import jenkins.advancedqueue.Messages;
import jenkins.advancedqueue.PriorityConfiguration;
import jenkins.advancedqueue.PriorityConfigurationCallback;
import jenkins.advancedqueue.PrioritySorterConfiguration;
import jenkins.advancedqueue.priority.PriorityStrategy;
import net.sf.json.JSONObject;

Expand All @@ -43,9 +48,9 @@
* @author Magnus Sandberg
* @since 2.0
*/
public class AdvancedQueueSorterJobProperty extends JobProperty<AbstractProject<?, ?>> {
public class PriorityJobProperty extends JobProperty<AbstractProject<?, ?>> {

private final static Logger LOGGER = Logger.getLogger(AdvancedQueueSorterJobProperty.class.getName());
private final static Logger LOGGER = Logger.getLogger(PriorityJobProperty.class.getName());

public final boolean useJobPriority;
public final int priority;
Expand All @@ -56,7 +61,7 @@ public JobProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws Fo
}

@DataBoundConstructor
public AdvancedQueueSorterJobProperty(boolean useJobPriority, int priority) {
public PriorityJobProperty(boolean useJobPriority, int priority) {
this.useJobPriority = useJobPriority;
this.priority = priority;
}
Expand Down

0 comments on commit 9c6c54d

Please sign in to comment.