提交 d4bd806c 编写于 作者: K kohsuke

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
上级 ed2ca8f4
......@@ -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.
*
* <p>
* 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<String> 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.
*
* <p>
* 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");
}
}
......@@ -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<TopLe
*/
public transient final List<AdministrativeMonitor> administrativeMonitors = new CopyOnWriteArrayList<AdministrativeMonitor>();
/*package*/ final Set<String> disabledAdministrativeMonitors = new CopyOnWriteArraySet<String>();
/**
* {@link AdjunctManager}
*/
......
......@@ -58,7 +58,7 @@ THE SOFTWARE.
</j:if>
<j:forEach var="am" items="${app.administrativeMonitors}">
<j:if test="${am.isActivated()}">
<j:if test="${am.isActivated() and am.isEnabled()}">
<st:include page="message.jelly" it="${am}" />
</j:if>
</j:forEach>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册