use of hudson.TcpSlaveAgentListener in project hudson-2.x by hudson.
the class Hudson method doConfigSubmit.
//
//
// actions
//
//
/**
* Accepts submission from the configuration page.
*/
public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
BulkChange bc = new BulkChange(this);
try {
checkPermission(ADMINISTER);
JSONObject json = req.getSubmittedForm();
// useSecurity = null;
if (json.has("use_security")) {
useSecurity = true;
JSONObject security = json.getJSONObject("use_security");
setSecurityRealm(SecurityRealm.all().newInstanceFromRadioList(security, "realm"));
setAuthorizationStrategy(AuthorizationStrategy.all().newInstanceFromRadioList(security, "authorization"));
if (security.has("markupFormatter")) {
markupFormatter = req.bindJSON(MarkupFormatter.class, security.getJSONObject("markupFormatter"));
} else {
markupFormatter = null;
}
} else {
useSecurity = null;
setSecurityRealm(SecurityRealm.NO_AUTHENTICATION);
authorizationStrategy = AuthorizationStrategy.UNSECURED;
markupFormatter = null;
}
if (json.has("csrf")) {
JSONObject csrf = json.getJSONObject("csrf");
setCrumbIssuer(CrumbIssuer.all().newInstanceFromRadioList(csrf, "issuer"));
} else {
setCrumbIssuer(null);
}
if (json.has("viewsTabBar")) {
viewsTabBar = req.bindJSON(ViewsTabBar.class, json.getJSONObject("viewsTabBar"));
} else {
viewsTabBar = new DefaultViewsTabBar();
}
if (json.has("myViewsTabBar")) {
myViewsTabBar = req.bindJSON(MyViewsTabBar.class, json.getJSONObject("myViewsTabBar"));
} else {
myViewsTabBar = new DefaultMyViewsTabBar();
}
primaryView = json.has("primaryView") ? json.getString("primaryView") : getViews().iterator().next().getViewName();
noUsageStatistics = json.has("usageStatisticsCollected") ? null : true;
{
String v = req.getParameter("slaveAgentPortType");
if (!isUseSecurity() || v == null || v.equals("random")) {
slaveAgentPort = 0;
} else if (v.equals("disable")) {
slaveAgentPort = -1;
} else {
try {
slaveAgentPort = Integer.parseInt(req.getParameter("slaveAgentPort"));
} catch (NumberFormatException e) {
throw new FormException(Messages.Hudson_BadPortNumber(req.getParameter("slaveAgentPort")), "slaveAgentPort");
}
}
// relaunch the agent
if (tcpSlaveAgentListener == null) {
if (slaveAgentPort != -1) {
tcpSlaveAgentListener = new TcpSlaveAgentListener(slaveAgentPort);
}
} else {
if (tcpSlaveAgentListener.configuredPort != slaveAgentPort) {
tcpSlaveAgentListener.shutdown();
tcpSlaveAgentListener = null;
if (slaveAgentPort != -1) {
tcpSlaveAgentListener = new TcpSlaveAgentListener(slaveAgentPort);
}
}
}
}
numExecutors = json.getInt("numExecutors");
if (req.hasParameter("master.mode")) {
mode = Mode.valueOf(req.getParameter("master.mode"));
} else {
mode = Mode.NORMAL;
}
label = json.optString("labelString", "");
quietPeriod = json.getInt("quiet_period");
scmCheckoutRetryCount = json.getInt("retry_count");
systemMessage = Util.nullify(req.getParameter("system_message"));
jdks.clear();
jdks.addAll(req.bindJSONToList(JDK.class, json.get("jdks")));
boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig()) {
result &= configureDescriptor(req, json, d);
}
for (JSONObject o : StructuredForm.toList(json, "plugin")) {
pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o);
}
clouds.rebuildHetero(req, json, Cloud.all(), "cloud");
JSONObject np = json.getJSONObject("globalNodeProperties");
if (np != null) {
globalNodeProperties.rebuild(req, np, NodeProperty.for_(this));
}
version = VERSION;
save();
updateComputerList();
if (result) {
// go to the top page
rsp.sendRedirect(req.getContextPath() + '/');
} else {
// back to config
rsp.sendRedirect("configure");
}
} finally {
bc.commit();
}
}
Aggregations