提交 48fc05d2 编写于 作者: K Kohsuke Kawaguchi

Fixed a bug in executor/queue filtering for matrix projects.

上级 4f6f058e
......@@ -55,6 +55,9 @@ Upcoming changes</a>
<!-- Record your changes in the trunk here. -->
<div id="trunk" style="display:none"><!--=TRUNK-BEGIN=-->
<ul class=image>
<li class=bug>
Fixed a bug in executor/queue filtering for matrix projects.
(<a href="https://github.com/jenkinsci/jenkins/pull/394">pull 394</a>)
<li class=bug>
Some of the context menu items have wrong links
(<a href="https://issues.jenkins-ci.org/browse/JENKINS-12945">issue 12945</a>)
......
......@@ -160,7 +160,19 @@ public class MatrixProject extends AbstractProject<MatrixProject,MatrixBuild> im
public MatrixConfigurationSorter getSorter() {
return sorter;
}
/**
* {@link MatrixProject} is relevant with all the labels its configurations are relevant.
*/
@Override
public Set<Label> getRelevantLabels() {
Set<Label> r = new HashSet<Label>();
r.add(getAssignedLabel());
for (MatrixConfiguration c : getActiveConfigurations())
r.add(c.getAssignedLabel());
return super.getRelevantLabels();
}
public void setSorter(MatrixConfigurationSorter sorter) throws IOException {
this.sorter = sorter;
save();
......
......@@ -314,6 +314,21 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
return Jenkins.getInstance().getLabel(assignedNode);
}
/**
* Set of labels relevant to this job.
*
* This method is used to determine what slaves are relevant to jobs, for example by {@link View}s.
* It does not affect the scheduling. This information is informational and the best-effort basis.
*
* @since 1.456
* @return
* Minimally it should contain {@link #getAssignedLabel()}. The set can contain null element
* to correspond to the null return value from {@link #getAssignedLabel()}.
*/
public Set<Label> getRelevantLabels() {
return Collections.singleton(getAssignedLabel());
}
/**
* Gets the textual representation of the assigned label as it was entered by the user.
*/
......
......@@ -365,53 +365,52 @@ public abstract class View extends AbstractModelObject implements AccessControll
}
public List<Computer> getComputers() {
Computer[] computers = Jenkins.getInstance().getComputers();
if (!isFilterExecutors()) {
return Arrays.asList(computers);
}
List<Computer> result = new ArrayList<Computer>();
boolean roam = false;
HashSet<Label> labels = new HashSet<Label>();
for (Item item: getItems()) {
if (item instanceof AbstractProject<?,?>) {
AbstractProject<?,?> p = (AbstractProject<?, ?>) item;
Label l = p.getAssignedLabel();
if (l != null) {
labels.add(l);
} else {
roam = true;
}
}
}
for (Computer c: computers) {
Node n = c.getNode();
if (n != null) {
if (roam && n.getMode() == Mode.NORMAL || !Collections.disjoint(n.getAssignedLabels(), labels)) {
result.add(c);
}
}
}
return result;
Computer[] computers = Jenkins.getInstance().getComputers();
if (!isFilterExecutors()) {
return Arrays.asList(computers);
}
List<Computer> result = new ArrayList<Computer>();
HashSet<Label> labels = new HashSet<Label>();
for (Item item : getItems()) {
if (item instanceof AbstractProject<?, ?>) {
labels.addAll(((AbstractProject<?, ?>) item).getRelevantLabels());
}
}
for (Computer c : computers) {
Node n = c.getNode();
if (n != null) {
if (labels.contains(null) && n.getMode() == Mode.NORMAL || !Collections.disjoint(n.getAssignedLabels(), labels)) {
result.add(c);
}
}
}
return result;
}
public List<Queue.Item> getQueueItems() {
if (!isFilterQueue()) {
return Arrays.asList(Jenkins.getInstance().getQueue().getItems());
}
Collection<TopLevelItem> items = getItems();
List<Queue.Item> result = new ArrayList<Queue.Item>();
for (Queue.Item qi: Jenkins.getInstance().getQueue().getItems()) {
if (items.contains(qi.task)) {
result.add(qi);
}
}
return result;
if (!isFilterQueue()) {
return Arrays.asList(Jenkins.getInstance().getQueue().getItems());
}
Collection<TopLevelItem> items = getItems();
List<Queue.Item> result = new ArrayList<Queue.Item>();
for (Queue.Item qi : Jenkins.getInstance().getQueue().getItems()) {
if (items.contains(qi.task)) {
result.add(qi);
} else
if (qi.task instanceof AbstractProject<?, ?>) {
AbstractProject<?,?> project = (AbstractProject<?, ?>) qi.task;
if (items.contains(project.getRootProject())) {
result.add(qi);
}
}
}
return result;
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册