Skip to content
Permalink
Browse files

[JENKINS-27966] Priority Sorter must not require matrix-project

  • Loading branch information
emsa23 committed Apr 25, 2015
1 parent df5d722 commit fc9df24d710adaba6a6de1763ec142ea95b3ca60
@@ -66,7 +66,7 @@
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>matrix-project</artifactId>
<version>1.4</version>
<optional>false</optional> <!-- should be true but for now require this [JENKINS-27966] -->
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
@@ -26,6 +26,7 @@
import hudson.DescriptorExtensionList;
import hudson.Extension;
import hudson.ExtensionList;
import hudson.Plugin;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixProject;
import hudson.model.Describable;
@@ -79,6 +80,7 @@
private final static Logger LOGGER = Logger.getLogger(PriorityConfiguration.class.getName());

transient private Map<Integer, JobGroup> id2jobGroup;
transient private PriorityConfigurationMatrixHelper priorityConfigurationMatrixHelper;
private List<JobGroup> jobGroups;

public PriorityConfiguration() {
@@ -101,6 +103,13 @@ public int compare(JobGroup.PriorityStrategyHolder o1, JobGroup.PriorityStrategy
}
});
}
//
Plugin plugin = Jenkins.getInstance().getPlugin("matrix-project");
if(plugin == null || !plugin.getWrapper().isEnabled()){
priorityConfigurationMatrixHelper = null;
} else {
priorityConfigurationMatrixHelper = new PriorityConfigurationMatrixHelper();
}
}

public String getIconFileName() {
@@ -207,23 +216,9 @@ private PriorityConfigurationCallback getPriorityInternal(Queue.Item item, Prior
}

Job<?, ?> job = (Job<?, ?>) item.task;

// [JENKINS-8597]
// For MatrixConfiguration use the latest assigned Priority from the
// MatrixProject
if (job instanceof MatrixConfiguration) {
MatrixProject matrixProject = ((MatrixConfiguration) job).getParent();
priorityCallback.addDecisionLog(0, "Job is MatrixConfiguration [" + matrixProject.getName() + "] ...");
ItemInfo itemInfo = QueueItemCache.get().getItem(matrixProject.getName());
// Can be null (for example) at startup when the MatrixBuild got
// lost (was running at
// restart)
if (itemInfo != null) {
priorityCallback.addDecisionLog(0, "MatrixProject found in cache, using priority from queue-item [" + itemInfo.getItemId() + "]");
return priorityCallback.setPrioritySelection(itemInfo.getPriority(), itemInfo.getJobGroupId(), itemInfo.getPriorityStrategy());
}
priorityCallback.addDecisionLog(0, "MatrixProject not found in cache, assigning global default priority");
return priorityCallback.setPrioritySelection(PrioritySorterConfiguration.get().getStrategy().getDefaultPriority());

if (priorityConfigurationMatrixHelper != null && priorityConfigurationMatrixHelper.isMatrixConfiguration(job)) {
return priorityConfigurationMatrixHelper.getPriority((MatrixConfiguration) job, priorityCallback);
}

//
@@ -0,0 +1,37 @@
package jenkins.advancedqueue;

import jenkins.advancedqueue.sorter.ItemInfo;
import jenkins.advancedqueue.sorter.QueueItemCache;
import hudson.matrix.MatrixConfiguration;
import hudson.matrix.MatrixProject;
import hudson.model.Job;

class PriorityConfigurationMatrixHelper {

boolean isMatrixConfiguration(Job<?, ?> job) {
return job instanceof MatrixConfiguration;
}

PriorityConfigurationCallback getPriority(MatrixConfiguration matrixConfiguration,
PriorityConfigurationCallback priorityCallback) {
// [JENKINS-8597]
// For MatrixConfiguration use the latest assigned Priority from the
// MatrixProject
MatrixProject matrixProject = matrixConfiguration.getParent();
priorityCallback.addDecisionLog(0, "Job is MatrixConfiguration [" + matrixProject.getName() + "] ...");
ItemInfo itemInfo = QueueItemCache.get().getItem(matrixProject.getName());
// Can be null (for example) at startup when the MatrixBuild got
// lost (was running at
// restart)
if (itemInfo != null) {
priorityCallback.addDecisionLog(0, "MatrixProject found in cache, using priority from queue-item ["
+ itemInfo.getItemId() + "]");
return priorityCallback.setPrioritySelection(itemInfo.getPriority(), itemInfo.getJobGroupId(),
itemInfo.getPriorityStrategy());
}
priorityCallback.addDecisionLog(0, "MatrixProject not found in cache, assigning global default priority");
return priorityCallback.setPrioritySelection(PrioritySorterConfiguration.get().getStrategy()
.getDefaultPriority());

}
}
@@ -56,4 +56,18 @@ public void matrix_and_jobs_with_no_configuration() throws Exception {
j.waitUntilNoActivity();
TestRunListener.assertStartedItems();
}

@Test
@LocalData
public void matrix_and_jobs_with_no_configuration_reverse() throws Exception {
TestRunListener.init(
new ExpectedItem("Matrix 0", 1), new ExpectedItem("Matrix 1", 5),
new ExpectedItem("0A1=0A.", 1), new ExpectedItem("0A1=0A.", 1),
new ExpectedItem("1A1=1A.", 5), new ExpectedItem("1A1=1A.", 5),
new ExpectedItem("Job 0", 5)
);
jobHelper.scheduleMatrixProjects(new UserIdCause(), new CLICause()).scheduleProjects(new CLICause()).go();
j.waitUntilNoActivity();
TestRunListener.assertStartedItems();
}
}

0 comments on commit fc9df24

Please sign in to comment.
You can’t perform that action at this time.