提交 24c31d13 编写于 作者: M Marc Guenther 提交者: Seiji Sogabe

[Fixed JENKINS-8043] "Reload Configuration from Disk" broke swarm clients

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.
上级 3ddd6bfc
......@@ -149,6 +149,7 @@ import hudson.security.csrf.CrumbIssuer;
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;
......@@ -212,9 +213,6 @@ import org.jvnet.hudson.reactor.TaskBuilder;
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;
......@@ -2396,6 +2394,10 @@ public class Jenkins extends AbstractCIBase implements ModifiableItemGroup<TopLe
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
......@@ -2412,6 +2414,20 @@ public class Jenkins extends AbstractCIBase implements ModifiableItemGroup<TopLe
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);
}
}
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册