diff --git a/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java b/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java new file mode 100644 index 0000000000..d288b3f940 --- /dev/null +++ b/core/src/main/java/hudson/node_monitors/ArchitectureMonitor.java @@ -0,0 +1,50 @@ +package hudson.node_monitors; + +import hudson.model.Computer; +import hudson.remoting.Callable; +import net.sf.json.JSONObject; +import org.kohsuke.stapler.StaplerRequest; + +import java.io.IOException; + +/** + * Discovers the architecture of the system to display in the slave list page. + * + * @author Kohsuke Kawaguchi + */ +public class ArchitectureMonitor extends NodeMonitor { + public AbstractNodeMonitorDescriptor getDescriptor() { + return DESCRIPTOR; + } + + public static final AbstractNodeMonitorDescriptor DESCRIPTOR = new AbstractNodeMonitorDescriptor(ArchitectureMonitor.class) { + protected String monitor(Computer c) throws IOException, InterruptedException { + return c.getChannel().call(new GetArchTask()); + } + + public String getDisplayName() { + return Messages.ArchitectureMonitor_displayName(); + } + + public NodeMonitor newInstance(StaplerRequest req, JSONObject formData) throws FormException { + return new ArchitectureMonitor(); + } + }; + + /** + * Obtains the string that represents the architecture. + */ + private static class GetArchTask implements Callable { + public String call() { + String os = System.getProperty("os.name"); + String arch = System.getProperty("os.arch"); + return os+" ("+arch+')'; + } + + private static final long serialVersionUID = 1L; + } + + static { + LIST.add(DESCRIPTOR); + } +} diff --git a/core/src/main/java/hudson/node_monitors/ClockMonitor.java b/core/src/main/java/hudson/node_monitors/ClockMonitor.java index 2124b20ce9..8e9e129e4a 100644 --- a/core/src/main/java/hudson/node_monitors/ClockMonitor.java +++ b/core/src/main/java/hudson/node_monitors/ClockMonitor.java @@ -16,7 +16,7 @@ import java.io.IOException; * @since 1.123 */ public class ClockMonitor extends NodeMonitor { - public Descriptor getDescriptor() { + public AbstractNodeMonitorDescriptor getDescriptor() { return DESCRIPTOR; } @@ -32,11 +32,15 @@ public class ClockMonitor extends NodeMonitor { } public String getDisplayName() { - return "Clock Difference"; + return Messages.ClockMonitor_displayName(); } public NodeMonitor newInstance(StaplerRequest req) throws FormException { return new ClockMonitor(); } }; + + static { + LIST.add(DESCRIPTOR); + } } diff --git a/core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java b/core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java index 5610dd244e..fc1136f5d4 100644 --- a/core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java +++ b/core/src/main/java/hudson/node_monitors/DiskSpaceMonitor.java @@ -20,7 +20,7 @@ import java.math.BigDecimal; * @since 1.123 */ public class DiskSpaceMonitor extends NodeMonitor { - public Descriptor getDescriptor() { + public AbstractNodeMonitorDescriptor getDescriptor() { return DESCRIPTOR; } @@ -51,7 +51,7 @@ public class DiskSpaceMonitor extends NodeMonitor { } public String getDisplayName() { - return "Free Disk Space"; + return Messages.DiskSpaceMonitor_displayName(); } public NodeMonitor newInstance(StaplerRequest req) throws FormException { @@ -65,4 +65,8 @@ public class DiskSpaceMonitor extends NodeMonitor { } private static final long serialVersionUID = 1L; } + + static { + LIST.add(DESCRIPTOR); + } } diff --git a/core/src/main/java/hudson/node_monitors/NodeMonitor.java b/core/src/main/java/hudson/node_monitors/NodeMonitor.java index 715ac63168..b6c55397f6 100644 --- a/core/src/main/java/hudson/node_monitors/NodeMonitor.java +++ b/core/src/main/java/hudson/node_monitors/NodeMonitor.java @@ -2,15 +2,14 @@ package hudson.node_monitors; import hudson.ExtensionPoint; import hudson.Functions; +import hudson.model.Computer; import hudson.model.ComputerSet; import hudson.model.Describable; -import hudson.model.Descriptor; import hudson.model.Node; +import hudson.util.DescriptorList; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Logger; import java.util.logging.Level; +import java.util.logging.Logger; /** * Extension point for managing and monitoring {@link Node}s. @@ -38,16 +37,24 @@ public abstract class NodeMonitor implements ExtensionPoint, Describable getDescriptor(); + + public Object data(Computer c) { + return getDescriptor().get(c); + } + + /** * All registered {@link NodeMonitor}s. */ - public static final List> LIST = new ArrayList>(); + public static final DescriptorList LIST = new DescriptorList(); static { try { - LIST.add(ClockMonitor.DESCRIPTOR); + LIST.load(ClockMonitor.class); if(Functions.isMustangOrAbove()) - LIST.add(DiskSpaceMonitor.DESCRIPTOR); + LIST.load(DiskSpaceMonitor.class); + LIST.load(ArchitectureMonitor.class); } catch (Throwable e) { Logger.getLogger(NodeMonitor.class.getName()).log(Level.SEVERE, "Failed to load built-in monitors",e); } diff --git a/core/src/main/resources/hudson/model/ComputerSet/index.jelly b/core/src/main/resources/hudson/model/ComputerSet/index.jelly index ff31624f19..49bdc5e09d 100644 --- a/core/src/main/resources/hudson/model/ComputerSet/index.jelly +++ b/core/src/main/resources/hudson/model/ComputerSet/index.jelly @@ -24,6 +24,7 @@ ${c.displayName} + diff --git a/core/src/main/resources/hudson/node_monitors/ArchitectureMonitor/column.jelly b/core/src/main/resources/hudson/node_monitors/ArchitectureMonitor/column.jelly new file mode 100644 index 0000000000..c9ac3ca84f --- /dev/null +++ b/core/src/main/resources/hudson/node_monitors/ArchitectureMonitor/column.jelly @@ -0,0 +1,3 @@ + + ${data} + diff --git a/core/src/main/resources/hudson/node_monitors/ClockMonitor/column.jelly b/core/src/main/resources/hudson/node_monitors/ClockMonitor/column.jelly index 431e65f154..d83f2b582f 100644 --- a/core/src/main/resources/hudson/node_monitors/ClockMonitor/column.jelly +++ b/core/src/main/resources/hudson/node_monitors/ClockMonitor/column.jelly @@ -1,11 +1,10 @@ - - + N/A - ${diff.toHtml()} + ${data.toHtml()} diff --git a/core/src/main/resources/hudson/node_monitors/DiskSpaceMonitor/column.jelly b/core/src/main/resources/hudson/node_monitors/DiskSpaceMonitor/column.jelly index 96b12037c9..14c6feb590 100644 --- a/core/src/main/resources/hudson/node_monitors/DiskSpaceMonitor/column.jelly +++ b/core/src/main/resources/hudson/node_monitors/DiskSpaceMonitor/column.jelly @@ -1,11 +1,10 @@ - - + N/A - ${from.toHtml(space)} + ${from.toHtml(data)} diff --git a/core/src/main/resources/hudson/node_monitors/Messages.properties b/core/src/main/resources/hudson/node_monitors/Messages.properties new file mode 100644 index 0000000000..23c0ee5852 --- /dev/null +++ b/core/src/main/resources/hudson/node_monitors/Messages.properties @@ -0,0 +1,3 @@ +ArchitectureMonitor.displayName=Architecture +ClockMonitor.displayName=Clock Difference +DiskSpaceMonitor.displayName=Free Disk Space