|
34 | 34 | import static hudson.init.InitMilestone.JOB_CONFIG_ADAPTED; |
35 | 35 | import static hudson.init.InitMilestone.JOB_LOADED; |
36 | 36 | import static hudson.init.InitMilestone.PLUGINS_PREPARED; |
| 37 | +import static hudson.init.InitMilestone.SYSTEM_CONFIG_ADAPTED; |
37 | 38 | import static hudson.init.InitMilestone.SYSTEM_CONFIG_LOADED; |
38 | 39 | import static jakarta.servlet.http.HttpServletResponse.SC_BAD_REQUEST; |
39 | 40 | import static jakarta.servlet.http.HttpServletResponse.SC_NOT_FOUND; |
40 | 41 | import static java.util.logging.Level.FINE; |
41 | 42 | import static java.util.logging.Level.INFO; |
42 | 43 | import static java.util.logging.Level.SEVERE; |
43 | 44 | import static java.util.logging.Level.WARNING; |
| 45 | +import static jenkins.model.Messages.Hudson_Computer_IncorrectNumberOfExecutors; |
44 | 46 |
|
45 | 47 | import com.google.common.annotations.VisibleForTesting; |
46 | 48 | import com.google.inject.Inject; |
@@ -3497,7 +3499,7 @@ public void run(Reactor session) throws Exception { |
3497 | 3499 |
|
3498 | 3500 | List<Handle> loadJobs = new ArrayList<>(); |
3499 | 3501 | for (final File subdir : subdirs) { |
3500 | | - loadJobs.add(g.requires(loadJenkins).attains(JOB_LOADED).notFatal().add("Loading item " + subdir.getName(), new Executable() { |
| 3502 | + loadJobs.add(g.requires(loadJenkins).requires(SYSTEM_CONFIG_ADAPTED).attains(JOB_LOADED).notFatal().add("Loading item " + subdir.getName(), new Executable() { |
3501 | 3503 | @Override |
3502 | 3504 | public void run(Reactor session) throws Exception { |
3503 | 3505 | if (!Items.getConfigFile(subdir).exists()) { |
@@ -4100,28 +4102,6 @@ private boolean configureDescriptor(StaplerRequest2 req, JSONObject json, Descri |
4100 | 4102 | return d.configure(req, js); |
4101 | 4103 | } |
4102 | 4104 |
|
4103 | | - /** |
4104 | | - * Accepts submission from the node configuration page. |
4105 | | - */ |
4106 | | - @POST |
4107 | | - public synchronized void doConfigExecutorsSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, FormException { |
4108 | | - checkPermission(ADMINISTER); |
4109 | | - |
4110 | | - try (BulkChange bc = new BulkChange(this)) { |
4111 | | - JSONObject json = req.getSubmittedForm(); |
4112 | | - |
4113 | | - ExtensionList.lookupSingleton(MasterBuildConfiguration.class).configure(req, json); |
4114 | | - |
4115 | | - getNodeProperties().rebuild(req, json.optJSONObject("nodeProperties"), NodeProperty.all()); |
4116 | | - |
4117 | | - bc.commit(); |
4118 | | - } |
4119 | | - |
4120 | | - updateComputers(this); |
4121 | | - |
4122 | | - FormApply.success(req.getContextPath() + '/' + toComputer().getUrl()).generateResponse(req, rsp, null); |
4123 | | - } |
4124 | | - |
4125 | 4105 | /** |
4126 | 4106 | * Accepts the new description. |
4127 | 4107 | */ |
@@ -5508,7 +5488,44 @@ public HttpResponse doDoDelete() throws IOException { |
5508 | 5488 | @Override |
5509 | 5489 | @POST |
5510 | 5490 | public void doConfigSubmit(StaplerRequest2 req, StaplerResponse2 rsp) throws IOException, ServletException, FormException { |
5511 | | - Jenkins.get().doConfigExecutorsSubmit(req, rsp); |
| 5491 | + checkPermission(ADMINISTER); |
| 5492 | + |
| 5493 | + Jenkins jenkins = Jenkins.get(); |
| 5494 | + |
| 5495 | + try (BulkChange bc = new BulkChange(jenkins)) { |
| 5496 | + JSONObject json = req.getSubmittedForm(); |
| 5497 | + |
| 5498 | + try { |
| 5499 | + // For compatibility reasons, this value is stored in Jenkins |
| 5500 | + String num = json.getString("numExecutors"); |
| 5501 | + if (!num.matches("\\d+")) { |
| 5502 | + throw new Descriptor.FormException(Hudson_Computer_IncorrectNumberOfExecutors(), "numExecutors"); |
| 5503 | + } |
| 5504 | + |
| 5505 | + jenkins.setNumExecutors(json.getInt("numExecutors")); |
| 5506 | + if (req.hasParameter("builtin.mode")) { |
| 5507 | + jenkins.setMode(Mode.valueOf(req.getParameter("builtin.mode"))); |
| 5508 | + } else { |
| 5509 | + jenkins.setMode(Mode.NORMAL); |
| 5510 | + } |
| 5511 | + |
| 5512 | + jenkins.setLabelString(json.optString("labelString", "")); |
| 5513 | + } catch (IOException e) { |
| 5514 | + throw new Descriptor.FormException(e, "numExecutors"); |
| 5515 | + } |
| 5516 | + |
| 5517 | + jenkins.getNodeProperties().rebuild(req, json.optJSONObject("nodeProperties"), NodeProperty.all()); |
| 5518 | + |
| 5519 | + bc.commit(); |
| 5520 | + } |
| 5521 | + |
| 5522 | + jenkins.updateComputers(jenkins); |
| 5523 | + |
| 5524 | + Computer computer = jenkins.toComputer(); |
| 5525 | + if (computer == null) { |
| 5526 | + throw new IllegalStateException("Cannot find the computer object for the controller node"); |
| 5527 | + } |
| 5528 | + FormApply.success(req.getContextPath() + '/' + computer.getUrl()).generateResponse(req, rsp, null); |
5512 | 5529 | } |
5513 | 5530 |
|
5514 | 5531 | @WebMethod(name = "config.xml") |
|
0 commit comments