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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc.
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.diagnosis;
25
26 import hudson.model.AdministrativeMonitor;
27 import jenkins.model.Jenkins;
28 import hudson.model.AbstractModelObject;
29 import hudson.Extension;
30 import hudson.ExtensionPoint;
31 import hudson.ExtensionList;
32 import org.kohsuke.stapler.HttpResponse;
33 import org.kohsuke.stapler.HttpResponses;
34 import org.kohsuke.stapler.QueryParameter;
35
36 import java.io.IOException;
37 import java.util.List;
38
39 /**
40 * Monitors the disk usage of <tt>JENKINS_HOME</tt>, and if it's almost filled up, warn the user.
41 *
42 * @author Kohsuke Kawaguchi
43 */
44 @Extension
45 public final class HudsonHomeDiskUsageMonitor extends AdministrativeMonitor {
46 /**
47 * Value updated by {@link HudsonHomeDiskUsageChecker}.
48 */
49 /*package*/ boolean activated;
50
51 public HudsonHomeDiskUsageMonitor() {
52 super("hudsonHomeIsFull");
53 }
54
55 public boolean isActivated() {
56 return activated;
57 }
58
59 /**
60 * Depending on whether the user said "yes" or "no", send him to the right place.
61 */
62 public HttpResponse doAct(@QueryParameter String no) throws IOException {
63 if(no!=null) {
64 disable(true);
65 return HttpResponses.redirectViaContextPath("/manage");
66 } else {
67 return HttpResponses.redirectToDot();
68 }
69 }
70
71 public List<Solution> getSolutions() {
72 return Solution.all();
73 }
74
75 /**
76 * Binds a solution to the URL.
77 */
78 public Solution getSolution(String id) {
79 for( Solution s : Solution.all() )
80 if(s.id.equals(id))
81 return s;
82 return null;
83 }
84
85 /**
86 * Short cut for getting the singleton instance.
87 */
88 public static HudsonHomeDiskUsageMonitor get() {
89 return all().get(HudsonHomeDiskUsageMonitor.class);
90 }
91
92 /**
93 * Extension point for suggesting solutions for full JENKINS_HOME.
94 *
95 * <h3>Views</h3>
96 * <dl>
97 * <dt>message.jelly</dt>
98 * <dd>
99 * This view is rendered inside an LI tag as a possible solution to the full JENKINS_HOME problem.
100 * </dd>
101 * </dl>
102 */
103 public static abstract class Solution extends AbstractModelObject implements ExtensionPoint {
104 /**
105 * Human-readable ID of this monitor, which needs to be unique within the system.
106 *
107 * <p>
108 * This ID is used to remember persisted setting for this monitor,
109 * so the ID should remain consistent beyond the Hudson JVM lifespan.
110 */
111 public final String id;
112
113 protected Solution(String id) {
114 this.id = id;
115 }
116
117 protected Solution() {
118 this.id = this.getClass().getName();
119 }
120
121 /**
122 * Returns the URL of this monitor, relative to the context path.
123 */
124 public String getUrl() {
125 return HudsonHomeDiskUsageMonitor.get().getUrl()+"/solution/"+id;
126 }
127
128 /**
129 * All registered {@link Solution}s.
130 */
131 public static ExtensionList<Solution> all() {
132 return Jenkins.getInstance().getExtensionList(Solution.class);
133 }
134 }
135 }
136