| author | Henrik Lynggaard Hansen | 2012-07-11 15:03:52 (EDT) |
|---|---|---|
| committer | Henrik Lynggaard Hansen | 2012-07-11 15:03:52 (EDT) |
| commit | e657bce46753bf86dbb70c0fce4010b3d4b08a3a (patch) (side-by-side diff) | |
| tree | 3475df9207d42fa005b636990e31245f7d00f7ad | |
| parent | 6b2a021db07f935226235132973fb64223c07d91 (diff) | |
| download | org.eclipse.hudson.core-e657bce46753bf86dbb70c0fce4010b3d4b08a3a.zip org.eclipse.hudson.core-e657bce46753bf86dbb70c0fce4010b3d4b08a3a.tar.gz org.eclipse.hudson.core-e657bce46753bf86dbb70c0fce4010b3d4b08a3a.tar.bz2 | |
Reformat of node_monitor packagerefs/changes/20/6720/1
Change-Id: Ic3107c6d42c2613cc8294b2d6c4affff06bd4f98
Signed-off-by: Henrik Lynggaard Hansen <henrik@hlyh.dk>
12 files changed, 266 insertions, 240 deletions
diff --git a/hudson-core/src/main/java/hudson/node_monitors/AbstractDiskSpaceMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/AbstractDiskSpaceMonitor.java index ec28185..b117495 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/AbstractDiskSpaceMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/AbstractDiskSpaceMonitor.java @@ -8,7 +8,7 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * + * * *******************************************************************************/ @@ -25,9 +25,11 @@ import java.util.logging.Logger; * @author Kohsuke Kawaguchi */ public abstract class AbstractDiskSpaceMonitor extends NodeMonitor { + /** * The free space threshold, below which the node monitor will be triggered. - * This is a human readable string representation as entered by the user, so that we can retain the original notation. + * This is a human readable string representation as entered by the user, so + * that we can retain the original notation. */ public final String freeSpaceThreshold; @@ -42,8 +44,9 @@ public abstract class AbstractDiskSpaceMonitor extends NodeMonitor { } public long getThresholdBytes() { - if (freeSpaceThreshold==null) + if (freeSpaceThreshold == null) { return DEFAULT_THRESHOLD; // backward compatibility with the data format that didn't have 'freeSpaceThreshold' + } try { return DiskSpace.parse(freeSpaceThreshold).size; } catch (ParseException e) { @@ -53,16 +56,15 @@ public abstract class AbstractDiskSpaceMonitor extends NodeMonitor { @Override public Object data(Computer c) { - DiskSpace size = (DiskSpace) super.data(c); - if(size!=null && size.size < getThresholdBytes()) { - size.setTriggered(true); - if(getDescriptor().markOffline(c,size)) { - LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOffline(c.getName())); - } + DiskSpace size = (DiskSpace) super.data(c); + if (size != null && size.size < getThresholdBytes()) { + size.setTriggered(true); + if (getDescriptor().markOffline(c, size)) { + LOGGER.warning(Messages.DiskSpaceMonitor_MarkedOffline(c.getName())); + } } return size; } - private static final Logger LOGGER = Logger.getLogger(AbstractDiskSpaceMonitor.class.getName()); - private static final long DEFAULT_THRESHOLD = 1024L*1024*1024; + private static final long DEFAULT_THRESHOLD = 1024L * 1024 * 1024; } diff --git a/hudson-core/src/main/java/hudson/node_monitors/AbstractNodeMonitorDescriptor.java b/hudson-core/src/main/java/hudson/node_monitors/AbstractNodeMonitorDescriptor.java index 2341409..32854e5 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/AbstractNodeMonitorDescriptor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/AbstractNodeMonitorDescriptor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi - * + * Contributors: + * + * Kohsuke Kawaguchi + * * *******************************************************************************/ @@ -33,16 +33,16 @@ import java.util.logging.Level; import java.util.logging.Logger; /** - * Convenient base class for common {@link NodeMonitor} implementation - * where the "monitoring" consists of executing something periodically on every node - * and taking some action based on its result. + * Convenient base class for common {@link NodeMonitor} implementation where the + * "monitoring" consists of executing something periodically on every node and + * taking some action based on its result. * - * <p> - * "T" represents the the result of the monitoring. + * <p> "T" represents the the result of the monitoring. * * @author Kohsuke Kawaguchi */ -public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<NodeMonitor> { +public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<NodeMonitor> { + protected AbstractNodeMonitorDescriptor() { this(HOUR); } @@ -53,7 +53,7 @@ public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<Node } protected AbstractNodeMonitorDescriptor(Class<? extends NodeMonitor> clazz) { - this(clazz,HOUR); + this(clazz, HOUR); } protected AbstractNodeMonitorDescriptor(Class<? extends NodeMonitor> clazz, long interval) { @@ -69,44 +69,43 @@ public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<Node } }, interval, interval); } - /** * Represents the last record of the update */ private volatile Record record = null; - /** * Represents the update activity in progress. */ private volatile Record inProgress = null; /** - * Performs monitoring of the given computer object. - * This method is invoked periodically to perform the monitoring of the computer. + * Performs monitoring of the given computer object. This method is invoked + * periodically to perform the monitoring of the computer. * - * @return - * Application-specific value that represents the observed monitoring value - * on the given node. This value will be returned from the {@link #get(Computer)} method. - * If null is returned, it will be interpreted as "no observed value." This is - * convenient way of abandoning the observation on a particular computer, - * whereas {@link IOException} is useful for indicating a hard error that needs to be - * corrected. + * @return Application-specific value that represents the observed + * monitoring value on the given node. This value will be returned from the + * {@link #get(Computer)} method. If null is returned, it will be + * interpreted as "no observed value." This is convenient way of abandoning + * the observation on a particular computer, whereas {@link IOException} is + * useful for indicating a hard error that needs to be corrected. */ - protected abstract T monitor(Computer c) throws IOException,InterruptedException; + protected abstract T monitor(Computer c) throws IOException, InterruptedException; /** - * Obtains the monitoring result currently available, or null if no data is available. + * Obtains the monitoring result currently available, or null if no data is + * available. * - * <p> - * If no data is available, a background task to collect data will be started. + * <p> If no data is available, a background task to collect data will be + * started. */ public T get(Computer c) { - if(record==null) { + if (record == null) { // if this is the first time, schedule the check now - if(inProgress==null) { - synchronized(this) { - if(inProgress==null) + if (inProgress == null) { + synchronized (this) { + if (inProgress == null) { new Record().start(); + } } } return null; @@ -119,34 +118,36 @@ public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<Node */ public boolean isIgnored() { NodeMonitor m = ComputerSet.getMonitors().get(this); - return m==null || m.isIgnored(); + return m == null || m.isIgnored(); } /** * Utility method to mark the computer offline for derived classes. * - * @return true - * if the node was actually taken offline by this act (as opposed to us deciding not to do it, - * or the computer already marked offline.) + * @return true if the node was actually taken offline by this act (as + * opposed to us deciding not to do it, or the computer already marked + * offline.) */ protected boolean markOffline(Computer c, OfflineCause oc) { - if(isIgnored() || c.isTemporarilyOffline()) return false; // noop - + if (isIgnored() || c.isTemporarilyOffline()) { + return false; // noop + } c.setTemporarilyOffline(true, oc); // notify the admin MonitorMarkedNodeOffline no = AdministrativeMonitor.all().get(MonitorMarkedNodeOffline.class); - if(no!=null) + if (no != null) { no.active = true; + } return true; } /** - * @deprecated as of 1.320 - * Use {@link #markOffline(Computer, OfflineCause)} to specify the cause. + * @deprecated as of 1.320 Use {@link #markOffline(Computer, OfflineCause)} + * to specify the cause. */ protected boolean markOffline(Computer c) { - return markOffline(c,null); + return markOffline(c, null); } /** @@ -159,21 +160,22 @@ public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<Node } /** - * Thread that monitors nodes, as well as the data structure to record - * the result. + * Thread that monitors nodes, as well as the data structure to record the + * result. */ private final class Record extends Thread { + /** * Last computed monitoring result. */ - private final Map<Computer,T> data = new HashMap<Computer,T>(); + private final Map<Computer, T> data = new HashMap<Computer, T>(); public Record() { - super("Monitoring thread for "+getDisplayName()+" started on "+new Date()); - synchronized(AbstractNodeMonitorDescriptor.this) { - if(inProgress!=null) { + super("Monitoring thread for " + getDisplayName() + " started on " + new Date()); + synchronized (AbstractNodeMonitorDescriptor.this) { + if (inProgress != null) { // maybe it got stuck? - LOGGER.warning("Previous "+getDisplayName()+" monitoring activity still in progress. Interrupting"); + LOGGER.warning("Previous " + getDisplayName() + " monitoring activity still in progress. Interrupting"); inProgress.interrupt(); } inProgress = this; @@ -185,33 +187,32 @@ public abstract class AbstractNodeMonitorDescriptor<T> extends Descriptor<Node long startTime = System.currentTimeMillis(); String oldName = getName(); - for( Computer c : Hudson.getInstance().getComputers() ) { + for (Computer c : Hudson.getInstance().getComputers()) { try { - setName("Monitoring "+c.getDisplayName()+" for "+getDisplayName()); + setName("Monitoring " + c.getDisplayName() + " for " + getDisplayName()); - if(c.getChannel()==null) - data.put(c,null); - else - data.put(c,monitor(c)); + if (c.getChannel() == null) { + data.put(c, null); + } else { + data.put(c, monitor(c)); + } } catch (IOException e) { - LOGGER.log(Level.WARNING, "Failed to monitor "+c.getDisplayName()+" for "+getDisplayName(), e); + LOGGER.log(Level.WARNING, "Failed to monitor " + c.getDisplayName() + " for " + getDisplayName(), e); } catch (InterruptedException e) { - LOGGER.log(Level.WARNING,"Node monitoring "+c.getDisplayName()+" for "+getDisplayName()+" aborted.",e); + LOGGER.log(Level.WARNING, "Node monitoring " + c.getDisplayName() + " for " + getDisplayName() + " aborted.", e); } } setName(oldName); - synchronized(AbstractNodeMonitorDescriptor.this) { - assert inProgress==this; + synchronized (AbstractNodeMonitorDescriptor.this) { + assert inProgress == this; inProgress = null; record = this; } - LOGGER.fine("Node monitoring "+getDisplayName()+" completed in "+(System.currentTimeMillis()-startTime)+"ms"); + LOGGER.fine("Node monitoring " + getDisplayName() + " completed in " + (System.currentTimeMillis() - startTime) + "ms"); } } - private final Logger LOGGER = Logger.getLogger(getClass().getName()); - - private static final long HOUR = 1000*60*60L; + private static final long HOUR = 1000 * 60 * 60L; } diff --git a/hudson-core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java index 5280549..d610b63 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi - * + * Contributors: + * + * Kohsuke Kawaguchi + * * *******************************************************************************/ @@ -31,8 +31,10 @@ import java.io.IOException; * @author Kohsuke Kawaguchi */ public class ArchitectureMonitor extends NodeMonitor { + @Extension public static final class DescriptorImpl extends AbstractNodeMonitorDescriptor<String> { + protected String monitor(Computer c) throws IOException, InterruptedException { return c.getChannel().call(new GetArchTask()); } @@ -49,13 +51,13 @@ public class ArchitectureMonitor extends NodeMonitor { /** * Obtains the string that represents the architecture. */ - private static class GetArchTask implements Callable<String,RuntimeException> { + private static class GetArchTask implements Callable<String, RuntimeException> { + public String call() { String os = System.getProperty("os.name"); String arch = System.getProperty("os.arch"); - return os+" ("+arch+')'; + return os + " (" + arch + ')'; } - private static final long serialVersionUID = 1L; } } diff --git a/hudson-core/src/main/java/hudson/node_monitors/ClockMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/ClockMonitor.java index e8ee826..8d562e6 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/ClockMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/ClockMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Thomas J. Black - * + * Contributors: + * + * Kohsuke Kawaguchi, Thomas J. Black + * * *******************************************************************************/ @@ -27,22 +27,24 @@ import java.io.IOException; import net.sf.json.JSONObject; /** - * {@link NodeMonitor} that checks clock of {@link Node} to - * detect out of sync clocks. + * {@link NodeMonitor} that checks clock of {@link Node} to detect out of sync + * clocks. * * @author Kohsuke Kawaguchi * @since 1.123 */ public class ClockMonitor extends NodeMonitor { + public ClockDifference getDifferenceFor(Computer c) { return DESCRIPTOR.get(c); } - @Extension public static final AbstractNodeMonitorDescriptor<ClockDifference> DESCRIPTOR = new AbstractNodeMonitorDescriptor<ClockDifference>() { protected ClockDifference monitor(Computer c) throws IOException, InterruptedException { Node n = c.getNode(); - if(n==null) return null; + if (n == null) { + return null; + } return n.getClockDifference(); } diff --git a/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java index 3f5e7f9..e6fb1e8 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi - * + * Contributors: + * + * Kohsuke Kawaguchi + * * *******************************************************************************/ @@ -28,20 +28,21 @@ import java.io.IOException; import java.text.ParseException; /** - * Checks available disk space of the remote FS root. - * Requires Mustang. + * Checks available disk space of the remote FS root. Requires Mustang. * * @author Kohsuke Kawaguchi * @since 1.123 */ public class DiskSpaceMonitor extends AbstractDiskSpaceMonitor { + @DataBoundConstructor - public DiskSpaceMonitor(String freeSpaceThreshold) throws ParseException { + public DiskSpaceMonitor(String freeSpaceThreshold) throws ParseException { super(freeSpaceThreshold); - } + } + + public DiskSpaceMonitor() { + } - public DiskSpaceMonitor() {} - public DiskSpace getFreeSpace(Computer c) { return DESCRIPTOR.get(c); } @@ -51,7 +52,6 @@ public class DiskSpaceMonitor extends AbstractDiskSpaceMonitor { // Hide this column from non-admins return Hudson.getInstance().hasPermission(Hudson.ADMINISTER) ? super.getColumnCaption() : null; } - public static final DiskSpaceMonitorDescriptor DESCRIPTOR = new DiskSpaceMonitorDescriptor() { public String getDisplayName() { return Messages.DiskSpaceMonitor_DisplayName(); @@ -59,7 +59,9 @@ public class DiskSpaceMonitor extends AbstractDiskSpaceMonitor { protected DiskSpace getFreeSpace(Computer c) throws IOException, InterruptedException { FilePath p = c.getNode().getRootPath(); - if(p==null) return null; + if (p == null) { + return null; + } return p.act(new GetUsableSpace()); } @@ -67,7 +69,9 @@ public class DiskSpaceMonitor extends AbstractDiskSpaceMonitor { @Extension public static DiskSpaceMonitorDescriptor install() { - if(Functions.isMustangOrAbove()) return DESCRIPTOR; + if (Functions.isMustangOrAbove()) { + return DESCRIPTOR; + } return null; } } diff --git a/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java b/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java index 0a66122..81a8d09 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/DiskSpaceMonitorDescriptor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -34,19 +34,21 @@ import org.kohsuke.stapler.export.ExportedBean; import org.kohsuke.stapler.export.Exported; /** - * {@link AbstractNodeMonitorDescriptor} for {@link NodeMonitor} that checks a free disk space of some directory. + * {@link AbstractNodeMonitorDescriptor} for {@link NodeMonitor} that checks a + * free disk space of some directory. * * @author Kohsuke Kawaguchi -*/ + */ /*package*/ abstract class DiskSpaceMonitorDescriptor extends AbstractNodeMonitorDescriptor<DiskSpace> { + /** * Value object that represents the disk space. */ @ExportedBean public static final class DiskSpace extends OfflineCause implements Serializable { + @Exported public final long size; - private boolean triggered; public DiskSpace(long size) { @@ -63,8 +65,8 @@ import org.kohsuke.stapler.export.Exported; */ public String getGbLeft() { long space = size; - space/=1024L; // convert to KB - space/=1024L; // convert to MB + space /= 1024L; // convert to KB + space /= 1024L; // convert to MB return new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString(); } @@ -74,52 +76,54 @@ import org.kohsuke.stapler.export.Exported; */ public String toHtml() { long space = size; - space/=1024L; // convert to KB - space/=1024L; // convert to MB - if(triggered) { + space /= 1024L; // convert to KB + space /= 1024L; // convert to MB + if (triggered) { // less than a GB - return Util.wrapToErrorSpan(new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString()+"GB"); + return Util.wrapToErrorSpan(new BigDecimal(space).scaleByPowerOfTen(-3).toPlainString() + "GB"); } - return space/1024+"GB"; + return space / 1024 + "GB"; } - + /** - * Sets whether this disk space amount should be treated as outside - * the acceptable conditions or not. + * Sets whether this disk space amount should be treated as outside the + * acceptable conditions or not. */ protected void setTriggered(boolean triggered) { - this.triggered = triggered; + this.triggered = triggered; } /** - * Parses a human readable size description like "1GB", "0.5m", etc. into {@link DiskSpace} + * Parses a human readable size description like "1GB", "0.5m", etc. + * into {@link DiskSpace} * - * @throws ParseException - * If failed to parse. + * @throws ParseException If failed to parse. */ public static DiskSpace parse(String size) throws ParseException { size = size.toUpperCase(Locale.ENGLISH).trim(); - if (size.endsWith("B")) // cut off 'B' from KB, MB, etc. - size = size.substring(0,size.length()-1); + if (size.endsWith("B")) // cut off 'B' from KB, MB, etc. + { + size = size.substring(0, size.length() - 1); + } - long multiplier=1; + long multiplier = 1; // look for the size suffix. The goal here isn't to detect all invalid size suffix, // so we ignore double suffix like "10gkb" or anything like that. String suffix = "KMGT"; - for (int i=0; i<suffix.length(); i++) { - if (size.endsWith(suffix.substring(i,i+1))) { + for (int i = 0; i < suffix.length(); i++) { + if (size.endsWith(suffix.substring(i, i + 1))) { multiplier = 1; - for (int j=0; j<=i; j++ ) - multiplier*=1024; - size = size.substring(0,size.length()-1); + for (int j = 0; j <= i; j++) { + multiplier *= 1024; + } + size = size.substring(0, size.length() - 1); } } - return new DiskSpace((long)(Double.parseDouble(size.trim())*multiplier)); + return new DiskSpace((long) (Double.parseDouble(size.trim()) * multiplier)); } - private static final long serialVersionUID = 2L; } @@ -133,10 +137,13 @@ import org.kohsuke.stapler.export.Exported; protected abstract DiskSpace getFreeSpace(Computer c) throws IOException, InterruptedException; protected static final class GetUsableSpace implements FileCallable<DiskSpace> { + public DiskSpace invoke(File f, VirtualChannel channel) throws IOException { try { long s = f.getUsableSpace(); - if(s<=0) return null; + if (s <= 0) { + return null; + } return new DiskSpace(s); } catch (LinkageError e) { // pre-mustang diff --git a/hudson-core/src/main/java/hudson/node_monitors/MonitorMarkedNodeOffline.java b/hudson-core/src/main/java/hudson/node_monitors/MonitorMarkedNodeOffline.java index 877ac35..046b091 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/MonitorMarkedNodeOffline.java +++ b/hudson-core/src/main/java/hudson/node_monitors/MonitorMarkedNodeOffline.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -20,16 +20,17 @@ import hudson.model.AdministrativeMonitor; import hudson.Extension; /** - * If {@link NodeMonitor} marks the node as offline, we'll show this to the admin to get their attention. + * If {@link NodeMonitor} marks the node as offline, we'll show this to the + * admin to get their attention. * - * <p> - * This also allows them to disable the monitoring if they don't like it. + * <p> This also allows them to disable the monitoring if they don't like it. * * @author Kohsuke Kawaguchi * @since 1.301 */ @Extension public class MonitorMarkedNodeOffline extends AdministrativeMonitor { + public boolean active = false; public boolean isActivated() { diff --git a/hudson-core/src/main/java/hudson/node_monitors/NodeMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/NodeMonitor.java index 6ece63c..8c31dfe 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/NodeMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/NodeMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Thomas J. Black - * + * Contributors: + * + * Kohsuke Kawaguchi, Thomas J. Black + * * *******************************************************************************/ @@ -36,36 +36,31 @@ import org.kohsuke.stapler.export.ExportedBean; /** * Extension point for managing and monitoring {@link Node}s. * - * <h2>Views</h2> - * <dl> - * <dt>column.jelly</dt> - * <dd> - * Invoked from {@link ComputerSet} <tt>index.jelly</tt> to render a column. - * The {@link NodeMonitor} instance is accessible through the "from" variable. - * Also see {@link #getColumnCaption()}. + * <h2>Views</h2> <dl> <dt>column.jelly</dt> <dd> Invoked from + * {@link ComputerSet} <tt>index.jelly</tt> to render a column. The + * {@link NodeMonitor} instance is accessible through the "from" variable. Also + * see {@link #getColumnCaption()}. * - * <dt>config.jelly (optional)</dt> - * <dd> - * Configuration fragment to be displayed in {@code http://server/hudson/computer/configure}. - * Used for configuring the threshold for taking nodes offline. - * </dl> + * <dt>config.jelly (optional)</dt> <dd> Configuration fragment to be displayed + * in {@code http://server/hudson/computer/configure}. Used for configuring the + * threshold for taking nodes offline. </dl> * - * <h2>Persistence</h2> - * <p> - * {@link NodeMonitor}s are persisted via XStream. + * <h2>Persistence</h2> <p> {@link NodeMonitor}s are persisted via XStream. * * @author Kohsuke Kawaguchi * @since 1.123 */ @ExportedBean public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMonitor> { + private volatile boolean ignored; /** - * Returns the name of the column to be added to {@link ComputerSet} index.jelly. + * Returns the name of the column to be added to {@link ComputerSet} + * index.jelly. * - * @return - * null to not render a column. The convention is to use capitalization like "Foo Bar Zot". + * @return null to not render a column. The convention is to use + * capitalization like "Foo Bar Zot". */ @Exported public String getColumnCaption() { @@ -73,7 +68,7 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon } public AbstractNodeMonitorDescriptor<?> getDescriptor() { - return (AbstractNodeMonitorDescriptor<?>)Hudson.getInstance().getDescriptorOrDie(getClass()); + return (AbstractNodeMonitorDescriptor<?>) Hudson.getInstance().getDescriptorOrDie(getClass()); } public Object data(Computer c) { @@ -81,13 +76,12 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon } /** - * Starts updating the data asynchronously. - * If there's any previous updating activity going on, it'll be interrupted and aborted. + * Starts updating the data asynchronously. If there's any previous updating + * activity going on, it'll be interrupted and aborted. * - * @return - * {@link Thread} object that carries out the update operation. - * You can use this to interrupt the execution or waits for the completion. - * Always non-null + * @return {@link Thread} object that carries out the update operation. You + * can use this to interrupt the execution or waits for the completion. + * Always non-null * @since 1.232 */ public Thread triggerUpdate() { @@ -96,6 +90,7 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon /** * Obtains all the instances of {@link NodeMonitor}s that are alive. + * * @since 1.187 */ public static List<NodeMonitor> getAll() { @@ -105,15 +100,13 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon /** * True if this monitoring shouldn't mark the slaves offline. * - * <p> - * Many {@link NodeMonitor}s implement a logic that if the value goes above/below - * a threshold, the slave will be marked offline as a preventive measure. - * This flag controls that. + * <p> Many {@link NodeMonitor}s implement a logic that if the value goes + * above/below a threshold, the slave will be marked offline as a preventive + * measure. This flag controls that. * - * <p> - * Unlike {@link Publisher}, where the absence of an instance indicates that it's disengaged, - * in {@link NodeMonitor} this boolean flag is used to indicate the disengagement, so that - * monitors work in opt-out basis. + * <p> Unlike {@link Publisher}, where the absence of an instance indicates + * that it's disengaged, in {@link NodeMonitor} this boolean flag is used to + * indicate the disengagement, so that monitors work in opt-out basis. */ public boolean isIgnored() { return ignored; @@ -122,18 +115,18 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMon public void setIgnored(boolean ignored) { this.ignored = ignored; } - /** * All registered {@link NodeMonitor}s. - * @deprecated as of 1.286. - * Use {@link #all()} for read access and {@link Extension} for registration. + * + * @deprecated as of 1.286. Use {@link #all()} for read access and + * {@link Extension} for registration. */ public static final DescriptorList<NodeMonitor> LIST = new DescriptorList<NodeMonitor>(NodeMonitor.class); /** * Returns all the registered {@link NodeMonitor} descriptors. */ - public static DescriptorExtensionList<NodeMonitor,Descriptor<NodeMonitor>> all() { - return Hudson.getInstance().<NodeMonitor,Descriptor<NodeMonitor>>getDescriptorList(NodeMonitor.class); + public static DescriptorExtensionList<NodeMonitor, Descriptor<NodeMonitor>> all() { + return Hudson.getInstance().<NodeMonitor, Descriptor<NodeMonitor>>getDescriptorList(NodeMonitor.class); } } diff --git a/hudson-core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java index 6720f64..8ed8eb2 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/ResponseTimeMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: -* -* Kohsuke Kawaguchi, Red Hat, Inc. - * + * Contributors: + * + * Kohsuke Kawaguchi, Red Hat, Inc. + * * *******************************************************************************/ @@ -42,6 +42,7 @@ import org.kohsuke.stapler.export.ExportedBean; * @author Kohsuke Kawaguchi */ public class ResponseTimeMonitor extends NodeMonitor { + @Extension public static final AbstractNodeMonitorDescriptor<Data> DESCRIPTOR = new AbstractNodeMonitorDescriptor<Data>() { protected Data monitor(Computer c) throws IOException, InterruptedException { @@ -53,15 +54,15 @@ public class ResponseTimeMonitor extends NodeMonitor { try { f.get(TIMEOUT, TimeUnit.MILLISECONDS); long end = System.nanoTime(); - d = new Data(old,TimeUnit2.NANOSECONDS.toMillis(end-start)); + d = new Data(old, TimeUnit2.NANOSECONDS.toMillis(end - start)); } catch (ExecutionException e) { throw new IOException2(e.getCause()); // I don't think this is possible } catch (TimeoutException e) { // special constant to indicate that the processing timed out. - d = new Data(old,-1L); + d = new Data(old, -1L); } - if(d.hasTooManyTimeouts() && !isIgnored()) { + if (d.hasTooManyTimeouts() && !isIgnored()) { // unlike other monitors whose failure still allow us to communicate with the slave, // the failure in this monitor indicates that we are just unable to make any requests // to this slave. So we should severe the connection, as opposed to marking it temporarily @@ -87,20 +88,21 @@ public class ResponseTimeMonitor extends NodeMonitor { */ @ExportedBean public static final class Data extends OfflineCause { + /** - * Record of the past 5 times. -1 if time out. Otherwise in milliseconds. - * Old ones first. + * Record of the past 5 times. -1 if time out. Otherwise in + * milliseconds. Old ones first. */ private final long[] past5; private Data(Data old, long newDataPoint) { - if(old==null) - past5 = new long[] {newDataPoint}; - else { - past5 = new long[Math.min(5,old.past5.length+1)]; + if (old == null) { + past5 = new long[]{newDataPoint}; + } else { + past5 = new long[Math.min(5, old.past5.length + 1)]; int copyLen = past5.length - 1; - System.arraycopy(old.past5, old.past5.length-copyLen, this.past5, 0, copyLen); - past5[past5.length-1] = newDataPoint; + System.arraycopy(old.past5, old.past5.length - copyLen, this.past5, 0, copyLen); + past5[past5.length - 1] = newDataPoint; } } @@ -108,27 +110,31 @@ public class ResponseTimeMonitor extends NodeMonitor { * Computes the recurrence of the time out */ private int failureCount() { - int cnt=0; - for(int i=past5.length-1; i>=0 && past5[i]<0; i--, cnt++) + int cnt = 0; + for (int i = past5.length - 1; i >= 0 && past5[i] < 0; i--, cnt++) ; return cnt; } /** - * Computes the average response time, by taking the time out into account. + * Computes the average response time, by taking the time out into + * account. */ @Exported public long getAverage() { - long total=0; + long total = 0; for (long l : past5) { - if(l<0) total += TIMEOUT; - else total += l; + if (l < 0) { + total += TIMEOUT; + } else { + total += l; + } } - return total/past5.length; + return total / past5.length; } public boolean hasTooManyTimeouts() { - return failureCount()>=5; + return failureCount() >= 5; } /** @@ -143,24 +149,23 @@ public class ResponseTimeMonitor extends NodeMonitor { // } // return buf.toString(); int fc = failureCount(); - if(fc>0) + if (fc > 0) { return Util.wrapToErrorSpan(Messages.ResponseTimeMonitor_TimeOut(fc)); - return getAverage()+"ms"; + } + return getAverage() + "ms"; } } - private static class NoopTask implements Callable<String,RuntimeException> { + private static class NoopTask implements Callable<String, RuntimeException> { + public String call() { return null; } - private static final long serialVersionUID = 1L; } - /** * Time out interval in milliseconds. */ private static final long TIMEOUT = 5000; - private static final Logger LOGGER = Logger.getLogger(ResponseTimeMonitor.class.getName()); } diff --git a/hudson-core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java index fda1289..958f92a 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/SwapSpaceMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: * * Inc., Kohsuke Kawaguchi, Seiji Sogabe, Winston Prakash - * + * * *******************************************************************************/ @@ -39,30 +39,33 @@ import java.io.IOException; * @sine 1.233 */ public class SwapSpaceMonitor extends NodeMonitor { + /** * Returns the HTML representation of the space. */ public String toHtml(NativeSystemMemory usage) { - if(usage.getAvailableSwapSpace() == -1) + if (usage.getAvailableSwapSpace() == -1) { return "N/A"; + } long free = usage.getAvailableSwapSpace(); - free/=1024L; // convert to KB - free/=1024L; // convert to MB - if(free>256 || usage.getTotalSwapSpace() < usage.getAvailableSwapSpace() * 5) - return free+"MB"; // if we have more than 256MB free or less than 80% filled up, it's OK - + free /= 1024L; // convert to KB + free /= 1024L; // convert to MB + if (free > 256 || usage.getTotalSwapSpace() < usage.getAvailableSwapSpace() * 5) { + return free + "MB"; // if we have more than 256MB free or less than 80% filled up, it's OK + } // Otherwise considered dangerously low. - return Util.wrapToErrorSpan(free+"MB"); + return Util.wrapToErrorSpan(free + "MB"); } public long toMB(NativeSystemMemory usage) { - if(usage.getAvailableSwapSpace() == -1) + if (usage.getAvailableSwapSpace() == -1) { return -1; + } long free = usage.getAvailableSwapSpace(); - free/=1024L; // convert to KB - free/=1024L; // convert to MB + free /= 1024L; // convert to KB + free /= 1024L; // convert to MB return free; } @@ -71,7 +74,6 @@ public class SwapSpaceMonitor extends NodeMonitor { // Hide this column from non-admins return Hudson.getInstance().hasPermission(Hudson.ADMINISTER) ? super.getColumnCaption() : null; } - @Extension public static final AbstractNodeMonitorDescriptor<NativeSystemMemory> DESCRIPTOR = new AbstractNodeMonitorDescriptor<NativeSystemMemory>() { protected NativeSystemMemory monitor(Computer c) throws IOException, InterruptedException { @@ -121,16 +123,15 @@ public class SwapSpaceMonitor extends NodeMonitor { /** * Memory Usage. * - * <p> - * {@link MemoryUsage} + stapler annotations. + * <p> {@link MemoryUsage} + stapler annotations. */ @ExportedBean - public static class MemoryUsage implements NativeSystemMemory{ - + public static class MemoryUsage implements NativeSystemMemory { + NativeSystemMemory systemMemory; - + public MemoryUsage(NativeSystemMemory mem) { - systemMemory = mem; + systemMemory = mem; } /** diff --git a/hudson-core/src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java b/hudson-core/src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java index 2f33711..6c2ebbc 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java +++ b/hudson-core/src/main/java/hudson/node_monitors/TemporarySpaceMonitor.java @@ -7,10 +7,10 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: + * Contributors: + * + * * - * - * * *******************************************************************************/ @@ -36,12 +36,14 @@ import java.text.ParseException; * @author Kohsuke Kawaguchi */ public class TemporarySpaceMonitor extends AbstractDiskSpaceMonitor { + @DataBoundConstructor - public TemporarySpaceMonitor(String freeSpaceThreshold) throws ParseException { + public TemporarySpaceMonitor(String freeSpaceThreshold) throws ParseException { super(freeSpaceThreshold); - } + } - public TemporarySpaceMonitor() {} + public TemporarySpaceMonitor() { + } public DiskSpace getFreeSpace(Computer c) { return DESCRIPTOR.get(c); @@ -52,7 +54,6 @@ public class TemporarySpaceMonitor extends AbstractDiskSpaceMonitor { // Hide this column from non-admins return Hudson.getInstance().hasPermission(Hudson.ADMINISTER) ? super.getColumnCaption() : null; } - public static final DiskSpaceMonitorDescriptor DESCRIPTOR = new DiskSpaceMonitorDescriptor() { public String getDisplayName() { return Messages.TemporarySpaceMonitor_DisplayName(); @@ -60,7 +61,9 @@ public class TemporarySpaceMonitor extends AbstractDiskSpaceMonitor { protected DiskSpace getFreeSpace(Computer c) throws IOException, InterruptedException { FilePath p = c.getNode().getRootPath(); - if(p==null) return null; + if (p == null) { + return null; + } return p.act(new GetTempSpace()); } @@ -68,18 +71,23 @@ public class TemporarySpaceMonitor extends AbstractDiskSpaceMonitor { @Extension public static DiskSpaceMonitorDescriptor install() { - if(Functions.isMustangOrAbove()) return DESCRIPTOR; + if (Functions.isMustangOrAbove()) { + return DESCRIPTOR; + } return null; } - + protected static final class GetTempSpace implements FileCallable<DiskSpace> { + public DiskSpace invoke(File f, VirtualChannel channel) throws IOException { try { // if the disk is really filled up we can't even create a single file, // so calling File.createTempFile and figuring out the directory won't reliably work. f = new File(System.getProperty("java.io.tmpdir")); long s = f.getUsableSpace(); - if(s<=0) return null; + if (s <= 0) { + return null; + } return new DiskSpace(s); } catch (LinkageError e) { // pre-mustang diff --git a/hudson-core/src/main/java/hudson/node_monitors/package.html b/hudson-core/src/main/java/hudson/node_monitors/package.html index 8b7b283..63379a4 100644 --- a/hudson-core/src/main/java/hudson/node_monitors/package.html +++ b/hudson-core/src/main/java/hudson/node_monitors/package.html @@ -16,5 +16,5 @@ --> <html><head/><body> -Code that monitors the health of slaves -</body></html>
\ No newline at end of file + Code that monitors the health of slaves + </body></html>
\ No newline at end of file |

