Skip to content

Commit

Permalink
[Fixed JENKINS-8043] "Reload Configuration from Disk" broke swarm cli…
Browse files Browse the repository at this point in the history
…ents

When Reloading Configuration from Disk in Jenkins, all swarm clients
were in an unusable state afterwards (eg. missing their labels).
This happened because Swarm Clients were not written into the
configuration file, and got removed when reloading the config.

This patch re-adds all previously existing swarm clients after
reloading the config file.
  • Loading branch information
marc-guenther authored and ssogabe committed Mar 18, 2012
1 parent 3ddd6bf commit 24c31d1
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions core/src/main/java/jenkins/model/Jenkins.java
Expand Up @@ -149,6 +149,7 @@
import hudson.slaves.Cloud;
import hudson.slaves.ComputerListener;
import hudson.slaves.DumbSlave;
import hudson.slaves.EphemeralNode;
import hudson.slaves.NodeDescriptor;
import hudson.slaves.NodeList;
import hudson.slaves.NodeProperty;
Expand Down Expand Up @@ -212,9 +213,6 @@
import org.jvnet.hudson.reactor.TaskGraphBuilder;
import org.jvnet.hudson.reactor.Reactor;
import org.jvnet.hudson.reactor.TaskGraphBuilder.Handle;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.kohsuke.stapler.Ancestor;
Expand Down Expand Up @@ -2396,6 +2394,10 @@ public boolean accept(File child) {
TaskGraphBuilder g = new TaskGraphBuilder();
Handle loadHudson = g.requires(EXTENSIONS_AUGMENTED).attains(JOB_LOADED).add("Loading global config", new Executable() {
public void run(Reactor session) throws Exception {
// JENKINS-8043: some slaves (eg. swarm slaves) are not saved into the config file
// and will get overwritten when reloading. Make a backup copy now, and re-add them later
NodeList oldSlaves = slaves;

XmlFile cfg = getConfigFile();
if (cfg.exists()) {
// reset some data that may not exist in the disk file
Expand All @@ -2412,6 +2414,20 @@ public void run(Reactor session) throws Exception {

clouds.setOwner(Jenkins.this);
items.clear();

// JENKINS-8043: re-add the slaves which were not saved into the config file
// and are now missing, but still connected.
if (oldSlaves != null) {
ArrayList<Node> newSlaves = new ArrayList<Node>(slaves);
for (Node n: oldSlaves) {
if (n instanceof EphemeralNode) {
if(!newSlaves.contains(n)) {
newSlaves.add(n);
}
}
}
setNodes(newSlaves);
}
}
});

Expand Down

0 comments on commit 24c31d1

Please sign in to comment.