File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\node_monitors\AbstractDiskSpaceMonitor.java.html

1 package hudson.node_monitors;
2
3 import hudson.model.Computer;
4 import hudson.node_monitors.DiskSpaceMonitorDescriptor.DiskSpace;
5 import org.kohsuke.stapler.DataBoundConstructor;
6
7 import java.text.ParseException;
8 import java.util.logging.Logger;
9
10 /**
11 * @author Kohsuke Kawaguchi
12 */
13 public abstract class AbstractDiskSpaceMonitor extends NodeMonitor {
14 /**
15 * The free space threshold, below which the node monitor will be triggered.
16 * This is a human readable string representation as entered by the user, so that we can retain the original notation.
17 */
18 public final String freeSpaceThreshold;
19
20 @DataBoundConstructor
21 public AbstractDiskSpaceMonitor(String threshold) throws ParseException {
22 this.freeSpaceThreshold = threshold;
23 DiskSpace.parse(threshold); // make sure it parses
24 }
25
26 public AbstractDiskSpaceMonitor() {
27 this.freeSpaceThreshold = "1GB";
28 }
29
30 public long getThresholdBytes() {
31 if (freeSpaceThreshold==null)
32 return DEFAULT_THRESHOLD; // backward compatibility with the data format that didn't have 'freeSpaceThreshold'
33 try {
34 return DiskSpace.parse(freeSpaceThreshold).size;
35 } catch (ParseException e) {
36 return DEFAULT_THRESHOLD;
37 }
38 }
39
40 @Override
41 public Object data(Computer c) {
42 DiskSpace size = (DiskSpace) super.data(c);
43 if(size!=null && size.size < getThresholdBytes()) {
44 size.setTriggered(this.getClass(), true);
45 if(getDescriptor().markOffline(c,size)) {
46 LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOffline(c.getName()));
47 }
48 }
49 if(size!=null && size.size > getThresholdBytes() && c.isOffline() && c.getOfflineCause() instanceof DiskSpace)
50 if(this.getClass().equals(((DiskSpace)c.getOfflineCause()).getTrigger()))
51 if(getDescriptor().markOnline(c)) {
52 LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOnline(c.getName()));
53 }
54 return size;
55 }
56
57 private static final Logger LOGGER = Logger.getLogger(AbstractDiskSpaceMonitor.class.getName());
58 private static final long DEFAULT_THRESHOLD = 1024L*1024*1024;
59 }
60