From d4bd806c42f4fa0dfd9e8e874f5a3414896d1e2b Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 11 Feb 2009 00:22:18 +0000 Subject: [PATCH] added a mechanism for AdministariveMonitor to be disabled. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15225 71c3de6d-444a-0410-be80-ed276b4c234a --- .../hudson/model/AdministrativeMonitor.java | 40 ++++++++++++++++++- core/src/main/java/hudson/model/Hudson.java | 3 ++ .../hudson/model/Hudson/manage.jelly | 2 +- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/AdministrativeMonitor.java b/core/src/main/java/hudson/model/AdministrativeMonitor.java index 122974dc43..b32d854e6f 100644 --- a/core/src/main/java/hudson/model/AdministrativeMonitor.java +++ b/core/src/main/java/hudson/model/AdministrativeMonitor.java @@ -27,6 +27,12 @@ import hudson.ExtensionPoint; import hudson.triggers.SCMTrigger; import hudson.triggers.TimerTrigger; +import java.util.Set; +import java.io.IOException; + +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; + /** * Checks the health of a subsystem of Hudson and if there's something * that requires administrator's attention, notify the administrator. @@ -66,8 +72,7 @@ public abstract class AdministrativeMonitor implements ExtensionPoint { * Human-readable ID of this monitor, which needs to be unique within the system. * *

- * In the future we intend to have some persistable user preference about - * monitors (such as disabling it or configuring it for e-mail notification), + * This ID is used to remember persisted setting for this monitor, * so the ID should remain consistent beyond the Hudson JVM lifespan. */ public final String id; @@ -76,6 +81,28 @@ public abstract class AdministrativeMonitor implements ExtensionPoint { this.id = id; } + /** + * Mark this monitor as disabled, to prevent this from showing up in the UI. + */ + public void disable(boolean value) throws IOException { + Hudson hudson = Hudson.getInstance(); + Set set = hudson.disabledAdministrativeMonitors; + if(value) set.add(id); + else set.remove(id); + hudson.save(); + } + + /** + * Returns true if this monitor {@link #disable(boolean) isn't disabled} earlier. + * + *

+ * This flag implements the ability for the admin to say "no thank you" to the monitor that + * he wants to ignore. + */ + public boolean isEnabled() { + return !Hudson.getInstance().disabledAdministrativeMonitors.contains(id); + } + /** * Returns true if this monitor is activated and * wants to produce a warning message. @@ -85,4 +112,13 @@ public abstract class AdministrativeMonitor implements ExtensionPoint { * so it should run efficiently. */ public abstract boolean isActivated(); + + /** + * URL binding to disable this monitor. + */ + public void doDisable(StaplerRequest req, StaplerResponse rsp) throws IOException { + Hudson.getInstance().checkPermission(Hudson.ADMINISTER); + disable(true); + rsp.sendRedirect2(req.getContextPath()+"/manage"); + } } diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 2d36dcada3..be8d47ba44 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -173,6 +173,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeoutException; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; @@ -392,6 +393,8 @@ public final class Hudson extends AbstractModelObject implements ItemGroup administrativeMonitors = new CopyOnWriteArrayList(); + /*package*/ final Set disabledAdministrativeMonitors = new CopyOnWriteArraySet(); + /** * {@link AdjunctManager} */ diff --git a/core/src/main/resources/hudson/model/Hudson/manage.jelly b/core/src/main/resources/hudson/model/Hudson/manage.jelly index d8b5c34e06..0bea50c800 100644 --- a/core/src/main/resources/hudson/model/Hudson/manage.jelly +++ b/core/src/main/resources/hudson/model/Hudson/manage.jelly @@ -58,7 +58,7 @@ THE SOFTWARE. - +