提交 660c0f6e 编写于 作者: K Kohsuke Kawaguchi

Added programmatic config.xml submission/retrieval support.

上级 d9097678
......@@ -57,6 +57,8 @@ Upcoming changes</a>
<ul class=image>
<li class=bug>
Fixed NPE in Groovy script execution via CLI (<a href="https://issues.jenkins-ci.org/browse/JENKINS-12302">issue 12302</a>)
<li class=rfe>
Supported programmatic retrieval/update of slave <tt>config.xml</tt>
<li class=rfe>
Breadcrumb now supports drop-down menu for faster navigation
(<a href="https://groups.google.com/forum/#!topic/jenkinsci-dev/j9uCKnQB-Xw/discussion">discussion</a>)
......
......@@ -64,6 +64,7 @@ import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.HttpResponses;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.WebMethod;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.args4j.Option;
......@@ -87,6 +88,8 @@ import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.Inet4Address;
import static javax.servlet.http.HttpServletResponse.*;
/**
* Represents the running state of a remote computer that holds {@link Executor}s.
*
......@@ -1069,27 +1072,57 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces
String name = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name"));
Jenkins.checkGoodName(name);
final Jenkins app = Jenkins.getInstance();
Node result = getNode().reconfigure(req, req.getSubmittedForm());
replaceBy(result);
// take the user back to the slave top page.
rsp.sendRedirect2("../"+result.getNodeName()+'/');
}
/**
* Accepts <tt>config.xml</tt> submission, as well as serve it.
*/
@WebMethod(name = "config.xml")
public void doConfigDotXml(StaplerRequest req, StaplerResponse rsp)
throws IOException, ServletException {
checkPermission(Jenkins.ADMINISTER);
if (req.getMethod().equals("GET")) {
// read
rsp.setContentType("application/xml");
Jenkins.XSTREAM2.toXML(getNode(), rsp.getOutputStream());
return;
}
if (req.getMethod().equals("POST")) {
// submission
Node result = (Node)Jenkins.XSTREAM2.fromXML(req.getReader());
replaceBy(result);
return;
}
// huh?
rsp.sendError(SC_BAD_REQUEST);
}
/**
* Replaces the current {@link Node} by another one.
*/
private void replaceBy(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());
int i = nodes.indexOf(getNode());
if(i<0) {
sendError("This slave appears to be removed while you were editing the configuration",req,rsp);
return;
throw new IOException("This slave appears to be removed while you were editing the configuration");
}
nodes.set(i,result);
nodes.set(i, newNode);
app.setNodes(nodes);
}
// take the user back to the slave top page.
rsp.sendRedirect2("../"+result.getNodeName()+'/');
}
/**
* Really deletes the slave.
*/
......
......@@ -28,4 +28,12 @@ THE SOFTWARE.
<p>
Load statistics of this computer has <a href="../loadStatistics/api/">its own separate API</a>.
</p>
<h2>Fetch/Update config.xml</h2>
<p>
To programmatically obtain <tt>config.xml</tt>, hit <a href="../config.xml">this URL</a>.
You can also POST an updated <tt>config.xml</tt> to the same URL to programmatically
update the configuration of a node.
</p>
</j:jelly>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册