提交 5e9492d1 编写于 作者: J James Nord

Merge pull request #1807 from jtnord/JENKINS-30057

[FIXED JENKINS-30057] NodeProperties should be owned by the corresponding Saveable
......@@ -28,7 +28,6 @@ import edu.umd.cs.findbugs.annotations.OverrideMustInvoke;
import edu.umd.cs.findbugs.annotations.When;
import hudson.EnvVars;
import hudson.Extension;
import hudson.Functions;
import hudson.Launcher.ProcStarter;
import hudson.Util;
import hudson.cli.declarative.CLIMethod;
......@@ -64,9 +63,10 @@ import hudson.util.RunList;
import hudson.util.Futures;
import hudson.util.NamingThreadFactory;
import jenkins.model.Jenkins;
import jenkins.model.queue.AsynchronousExecution;
import jenkins.util.ContextResettingExecutorService;
import jenkins.security.MasterToSlaveCallable;
import jenkins.security.NotReallyRoleSensitiveCallable;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.DoNotUse;
import org.kohsuke.accmod.restrictions.NoExternalUse;
......@@ -87,6 +87,7 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
import javax.annotation.concurrent.GuardedBy;
import javax.servlet.ServletException;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
......@@ -108,6 +109,7 @@ import java.net.NetworkInterface;
import java.net.Inet4Address;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
......@@ -1426,21 +1428,23 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
/**
* Replaces the current {@link Node} by another one.
*/
private void replaceBy(Node newNode) throws ServletException, IOException {
private void replaceBy(final Node newNode) throws ServletException, IOException {
final Jenkins app = Jenkins.getInstance();
// replace the old Node object by the new one
synchronized (app) {
List<Node> nodes = new ArrayList<Node>(app.getNodes());
Node node = getNode();
int i = (node != null) ? nodes.indexOf(node) : -1;
if(i<0) {
throw new IOException("This slave appears to be removed while you were editing the configuration");
// use the queue lock until Nodes has a way of directly modifying a single node.
Queue.withLock(new NotReallyRoleSensitiveCallable<Void, IOException>() {
public Void call() throws IOException {
List<Node> nodes = new ArrayList<Node>(app.getNodes());
Node node = getNode();
int i = (node != null) ? nodes.indexOf(node) : -1;
if(i<0) {
throw new IOException("This slave appears to be removed while you were editing the configuration");
}
nodes.set(i, newNode);
app.setNodes(nodes);
return null;
}
nodes.set(i, newNode);
app.setNodes(nodes);
}
});
}
/**
......
......@@ -127,7 +127,8 @@ public abstract class Slave extends Node implements Serializable {
*/
private String label="";
private /*almost final*/ DescribableList<NodeProperty<?>,NodePropertyDescriptor> nodeProperties = new DescribableList<NodeProperty<?>,NodePropertyDescriptor>(Jenkins.getInstance());
private /*almost final*/ DescribableList<NodeProperty<?>,NodePropertyDescriptor> nodeProperties =
new DescribableList<NodeProperty<?>,NodePropertyDescriptor>(Jenkins.getInstance().getNodesObject());
/**
* Lazily computed set of labels from {@link #label}.
......@@ -408,7 +409,7 @@ public abstract class Slave extends Node implements Serializable {
: new CommandLauncher(agentCommand);
}
if(nodeProperties==null)
nodeProperties = new DescribableList<NodeProperty<?>,NodePropertyDescriptor>(Jenkins.getInstance());
nodeProperties = new DescribableList<NodeProperty<?>,NodePropertyDescriptor>(Jenkins.getInstance().getNodesObject());
return this;
}
......
......@@ -1710,6 +1710,16 @@ public class Jenkins extends AbstractCIBase implements DirectlyModifiableTopLeve
return nodes.getNodes();
}
/**
* Get the {@link Nodes} object that handles maintaining individual {@link Node}s.
* @return The Nodes object.
*/
@Restricted(NoExternalUse.class)
public Nodes getNodesObject() {
// TODO replace this with something better when we properly expose Nodes.
return nodes;
}
/**
* Adds one more {@link Node} to Jenkins.
*/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册