Skip to content
Permalink
Browse files
[FIXED JENKINS-25910] Sort nodes for label for UI (#1498)
* [FIXED JENKINS-25910] Sort nodes for label for UI

* [JENKINS-25910] Sort Jenkins master at beginning

* Consistent sort order

* [JENKINS-25910] Instead use dedicated UI support method
  • Loading branch information
daniel-beck authored and oleg-nenashev committed Apr 7, 2018
1 parent b6dc503 commit 70c408cedf429ce79fdec8998635f58b4f7a02ca
Showing with 22 additions and 2 deletions.
  1. +21 −1 core/src/main/java/hudson/model/Label.java
  2. +1 −1 core/src/main/resources/hudson/model/Label/index.jelly
@@ -49,6 +49,8 @@
import jenkins.model.ModelObjectWithChildren;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.export.Exported;
@@ -58,6 +60,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -196,6 +199,16 @@ public boolean isSelfLabel() {
return nodes.size() == 1 && nodes.iterator().next().getSelfLabel() == this;
}

private static class NodeSorter implements Comparator<Node> {
@Override
public int compare(Node o1, Node o2) {
if (o1 == o2) {
return 0;
}
return o1 instanceof Jenkins ? -1 : (o2 instanceof Jenkins ? 1 : o1.getNodeName().compareTo(o2.getNodeName()));
}
}

/**
* Gets all {@link Node}s that belong to this label.
*/
@@ -204,7 +217,7 @@ public Set<Node> getNodes() {
Set<Node> nodes = this.nodes;
if(nodes!=null) return nodes;

Set<Node> r = new HashSet<Node>();
Set<Node> r = new HashSet<>();
Jenkins h = Jenkins.getInstance();
if(this.matches(h))
r.add(h);
@@ -215,6 +228,13 @@ public Set<Node> getNodes() {
return this.nodes = Collections.unmodifiableSet(r);
}

@Restricted(DoNotUse.class) // Jelly
public Set<Node> getSortedNodes() {
Set<Node> r = new TreeSet<>(new NodeSorter());
r.addAll(getNodes());
return r;
}

/**
* Gets all {@link Cloud}s that can launch for this label.
*/
@@ -42,7 +42,7 @@ THE SOFTWARE.

<div>
<h2>${%Nodes}</h2>
<j:forEach var="n" items="${it.nodes}">
<j:forEach var="n" items="${it.sortedNodes}">
<j:set var="c" value="${app.getComputer(n.nodeName)}"/>
<j:set var="url" value="${rootURL}/${c.url}"/>
<nobr>

0 comments on commit 70c408c

Please sign in to comment.