~ubuntu-branches/ubuntu/trusty/jenkins/trusty

« back to all changes in this revision

Viewing changes to core/src/main/java/hudson/model/ComputerSet.java

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-13 12:35:19 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20130813123519-tizgfxcr70trl7r0
Tags: 1.509.2+dfsg-1
* New upstream release (Closes: #706725):
  - d/control: Update versioned BD's:
    * jenkins-executable-war >= 1.28.
    * jenkins-instance-identity >= 1.3.
    * libjenkins-remoting-java >= 2.23.
    * libjenkins-winstone-java >= 0.9.10-jenkins-44.
    * libstapler-java >= 1.207.
    * libjenkins-json-java >= 2.4-jenkins-1.
    * libstapler-adjunct-timeline-java >= 1.4.
    * libstapler-adjunct-codemirror-java >= 1.2.
    * libmaven-hpi-plugin-java >= 1.93.
    * libjenkins-xstream-java >= 1.4.4-jenkins-3.
  - d/maven.rules: Map to older version of animal-sniffer-maven-plugin.
  - Add patch for compatibility with guava >= 0.14.
  - Add patch to exclude asm4 dependency via jnr-posix.
  - Fixes the following security vulnerabilities:
    CVE-2013-2034, CVE-2013-2033, CVE-2013-2034, CVE-2013-1808
* d/patches/*: Switch to using git patch-queue for managing patches.
* De-duplicate jars between libjenkins-java and jenkins-external-job-monitor
  (Closes: #701163):
  - d/control: Add dependency between jenkins-external-job-monitor ->
    libjenkins-java.
  - d/rules: 
    Drop installation of jenkins-core in jenkins-external-job-monitor.
  - d/jenkins-external-job-monitor.{links,install}: Link to jenkins-core
    in /usr/share/java instead of included version.
* Wait longer for jenkins to stop during restarts (Closes: #704848):
  - d/jenkins.init: Re-sync init script from upstream codebase.

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
import hudson.node_monitors.NodeMonitor;
34
34
import hudson.slaves.NodeDescriptor;
35
35
import hudson.util.DescribableList;
 
36
import hudson.util.FormApply;
36
37
import hudson.util.FormValidation;
37
38
import jenkins.model.Jenkins;
 
39
import org.kohsuke.stapler.HttpResponse;
38
40
import org.kohsuke.stapler.QueryParameter;
39
41
import org.kohsuke.stapler.StaplerRequest;
40
42
import org.kohsuke.stapler.StaplerResponse;
47
49
import java.io.File;
48
50
import java.io.IOException;
49
51
import java.util.AbstractList;
 
52
import java.util.ArrayList;
50
53
import java.util.HashMap;
51
54
import java.util.List;
52
55
import java.util.Map;
53
56
import java.util.logging.Level;
54
57
import java.util.logging.Logger;
 
58
import net.sf.json.JSONObject;
55
59
 
56
60
/**
57
61
 * Serves as the top of {@link Computer}s in the URL hierarchy.
167
171
    public int getIdleExecutors() {
168
172
        int r=0;
169
173
        for (Computer c : get_all())
170
 
            if(c.isOnline() || c.isConnecting())
 
174
            if((c.isOnline() || c.isConnecting()) && c.isAcceptingTasks())
171
175
                r += c.countIdle();
172
176
        return r;
173
177
    }
231
235
            String xml = Jenkins.XSTREAM.toXML(src);
232
236
            Node result = (Node) Jenkins.XSTREAM.fromXML(xml);
233
237
            result.setNodeName(name);
 
238
            if(result instanceof Slave){ //change userId too
 
239
                User user = User.current();
 
240
                ((Slave)result).setUserId(user==null ? "anonymous" : user.getId());
 
241
             }
234
242
            result.holdOffLaunchUntilSave = true;
235
243
 
236
244
            app.addNode(result);
257
265
                                           @QueryParameter String type ) throws IOException, ServletException, FormException {
258
266
        final Jenkins app = Jenkins.getInstance();
259
267
        app.checkPermission(Computer.CREATE);
260
 
        checkName(name);
 
268
        String fixedName = Util.fixEmptyAndTrim(name);
 
269
        checkName(fixedName);
261
270
 
262
 
        Node result = NodeDescriptor.all().find(type).newInstance(req, req.getSubmittedForm());
 
271
        JSONObject formData = req.getSubmittedForm();
 
272
        formData.put("name", fixedName);
 
273
        
 
274
        Node result = NodeDescriptor.all().find(type).newInstance(req, formData);
263
275
        app.addNode(result);
264
276
 
265
277
        // take the user back to the slave list top page
305
317
     * Accepts submission from the configuration page.
306
318
     */
307
319
    @RequirePOST
308
 
    public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
 
320
    public synchronized HttpResponse doConfigSubmit( StaplerRequest req) throws IOException, ServletException, FormException {
309
321
        BulkChange bc = new BulkChange(MONITORS_OWNER);
310
322
        try {
311
323
            Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
324
336
                nm.triggerUpdate();
325
337
            }
326
338
 
327
 
            rsp.sendRedirect2(".");
 
339
            return FormApply.success(".");
328
340
        } finally {
329
341
            bc.commit();
330
342
        }
384
396
            if(xf.exists()) {
385
397
                DescribableList<NodeMonitor,Descriptor<NodeMonitor>> persisted =
386
398
                        (DescribableList<NodeMonitor,Descriptor<NodeMonitor>>) xf.read();
387
 
                r.replaceBy(persisted.toList());
 
399
                List<NodeMonitor> sanitized = new ArrayList<NodeMonitor>();
 
400
                for (NodeMonitor nm : persisted) {
 
401
                    try {
 
402
                        nm.getDescriptor();
 
403
                        sanitized.add(nm);
 
404
                    } catch (Throwable e) {
 
405
                        // the descriptor didn't load? see JENKINS-15869
 
406
                    }
 
407
                }
 
408
                r.replaceBy(sanitized);
388
409
            }
389
410
 
390
411
            // if we have any new monitors, let's add them