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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Thomas J. Black
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.node_monitors;
25
26 import hudson.ExtensionPoint;
27 import hudson.DescriptorExtensionList;
28 import hudson.Extension;
29 import hudson.tasks.Publisher;
30 import hudson.model.Computer;
31 import hudson.model.ComputerSet;
32 import hudson.model.Describable;
33 import hudson.model.Node;
34 import jenkins.model.Jenkins;
35 import hudson.model.Descriptor;
36 import hudson.util.DescriptorList;
37
38 import java.util.List;
39
40 import org.kohsuke.stapler.export.Exported;
41 import org.kohsuke.stapler.export.ExportedBean;
42
43 /**
44 * Extension point for managing and monitoring {@link Node}s.
45 *
46 * <h2>Views</h2>
47 * <dl>
48 * <dt>column.jelly</dt>
49 * <dd>
50 * Invoked from {@link ComputerSet} <tt>index.jelly</tt> to render a column.
51 * The {@link NodeMonitor} instance is accessible through the "from" variable.
52 * Also see {@link #getColumnCaption()}.
53 *
54 * <dt>config.jelly (optional)</dt>
55 * <dd>
56 * Configuration fragment to be displayed in {@code http://server/hudson/computer/configure}.
57 * Used for configuring the threshold for taking nodes offline.
58 * </dl>
59 *
60 * <h2>Persistence</h2>
61 * <p>
62 * {@link NodeMonitor}s are persisted via XStream.
63 *
64 * @author Kohsuke Kawaguchi
65 * @since 1.123
66 */
67 @ExportedBean
68 public abstract class NodeMonitor implements ExtensionPoint, Describable<NodeMonitor> {
69 private volatile boolean ignored;
70
71 /**
72 * Returns the name of the column to be added to {@link ComputerSet} index.jelly.
73 *
74 * @return
75 * null to not render a column. The convention is to use capitalization like "Foo Bar Zot".
76 */
77 @Exported
78 public String getColumnCaption() {
79 return getDescriptor().getDisplayName();
80 }
81
82 public AbstractNodeMonitorDescriptor<?> getDescriptor() {
83 return (AbstractNodeMonitorDescriptor<?>) Jenkins.getInstance().getDescriptorOrDie(getClass());
84 }
85
86 /**
87 * Obtains the monitoring result currently available, or null if no data is available.
88 */
89 public Object data(Computer c) {
90 return getDescriptor().get(c);
91 }
92
93 /**
94 * Starts updating the data asynchronously.
95 * If there's any previous updating activity going on, it'll be interrupted and aborted.
96 *
97 * @return
98 * {@link Thread} object that carries out the update operation.
99 * You can use this to interrupt the execution or waits for the completion.
100 * Always non-null
101 * @since 1.232
102 */
103 public Thread triggerUpdate() {
104 return getDescriptor().triggerUpdate();
105 }
106
107 /**
108 * Obtains all the instances of {@link NodeMonitor}s that are alive.
109 * @since 1.187
110 */
111 public static List<NodeMonitor> getAll() {
112 return ComputerSet.getMonitors().toList();
113 }
114
115 /**
116 * True if this monitoring shouldn't mark the slaves offline.
117 *
118 * <p>
119 * Many {@link NodeMonitor}s implement a logic that if the value goes above/below
120 * a threshold, the slave will be marked offline as a preventive measure.
121 * This flag controls that.
122 *
123 * <p>
124 * Unlike {@link Publisher}, where the absence of an instance indicates that it's disengaged,
125 * in {@link NodeMonitor} this boolean flag is used to indicate the disengagement, so that
126 * monitors work in opt-out basis.
127 */
128 public boolean isIgnored() {
129 return ignored;
130 }
131
132 public void setIgnored(boolean ignored) {
133 this.ignored = ignored;
134 }
135
136 /**
137 * All registered {@link NodeMonitor}s.
138 * @deprecated as of 1.286.
139 * Use {@link #all()} for read access and {@link Extension} for registration.
140 */
141 public static final DescriptorList<NodeMonitor> LIST = new DescriptorList<NodeMonitor>(NodeMonitor.class);
142
143 /**
144 * Returns all the registered {@link NodeMonitor} descriptors.
145 */
146 public static DescriptorExtensionList<NodeMonitor,Descriptor<NodeMonitor>> all() {
147 return Jenkins.getInstance().<NodeMonitor,Descriptor<NodeMonitor>>getDescriptorList(NodeMonitor.class);
148 }
149 }
150