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

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
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.slaves;
25
26 import hudson.Extension;
27 import hudson.model.ComputerSet;
28 import hudson.model.Descriptor;
29 import hudson.model.Slave;
30 import hudson.model.Node;
31 import jenkins.model.Jenkins;
32 import hudson.util.DescriptorList;
33 import hudson.util.FormValidation;
34 import hudson.DescriptorExtensionList;
35 import hudson.Util;
36 import hudson.model.Failure;
37
38 import java.io.IOException;
39 import java.util.List;
40 import java.util.ArrayList;
41
42 import org.kohsuke.stapler.QueryParameter;
43 import org.kohsuke.stapler.StaplerRequest;
44 import org.kohsuke.stapler.StaplerResponse;
45
46 import javax.servlet.ServletException;
47
48 /**
49 * {@link Descriptor} for {@link Slave}.
50 *
51 * <h2>Views</h2>
52 * <p>
53 * This object needs to have <tt>newInstanceDetail.jelly</tt> view, which shows up in
54 * <tt>http://server/hudson/computers/new</tt> page as an explanation of this job type.
55 *
56 * <h2>Other Implementation Notes</h2>
57 *
58 * @author Kohsuke Kawaguchi
59 */
60 public abstract class NodeDescriptor extends Descriptor<Node> {
61 protected NodeDescriptor(Class<? extends Node> clazz) {
62 super(clazz);
63 }
64
65 protected NodeDescriptor() {
66 }
67
68 /**
69 * Can the administrator create this type of nodes from UI?
70 *
71 * Return false if it only makes sense for programs to create it, not through the "new node" UI.
72 */
73 public boolean isInstantiable() {
74 return true;
75 }
76
77 public final String newInstanceDetailPage() {
78 return '/'+clazz.getName().replace('.','/').replace('$','/')+"/newInstanceDetail.jelly";
79 }
80
81 /**
82 * Handles the form submission from the "/computer/new" page, which is the first form for creating a new node.
83 * By default, it shows the configuration page for entering details, but subtypes can override this differently.
84 *
85 * @param name
86 * Name of the new node.
87 */
88 public void handleNewNodePage(ComputerSet computerSet, String name, StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
89 computerSet.checkName(name);
90 req.setAttribute("descriptor", this);
91 req.getView(computerSet,"_new.jelly").forward(req,rsp);
92 }
93
94 @Override
95 public String getConfigPage() {
96 return getViewPage(clazz, "configure-entries.jelly");
97 }
98
99 public FormValidation doCheckName(@QueryParameter String value ) {
100 String name = Util.fixEmptyAndTrim(value);
101 if(name==null)
102 return FormValidation.error(Messages.NodeDescripter_CheckName_Mandatory());
103 try {
104 Jenkins.checkGoodName(name);
105 } catch (Failure f) {
106 return FormValidation.error(f.getMessage());
107 }
108 return FormValidation.ok();
109 }
110
111 /**
112 * Returns all the registered {@link NodeDescriptor} descriptors.
113 */
114 public static DescriptorExtensionList<Node,NodeDescriptor> all() {
115 return Jenkins.getInstance().<Node,NodeDescriptor>getDescriptorList(Node.class);
116 }
117
118 /**
119 * All the registered instances.
120 * @deprecated as of 1.286
121 * Use {@link #all()} for read access, and {@link Extension} for registration.
122 */
123 public static final DescriptorList<Node> ALL = new DescriptorList<Node>(Node.class);
124
125 public static List<NodeDescriptor> allInstantiable() {
126 List<NodeDescriptor> r = new ArrayList<NodeDescriptor>();
127 for (NodeDescriptor d : all())
128 if(d.isInstantiable())
129 r.add(d);
130 return r;
131 }
132 }
133