
hudson.slaves.NodeDescriptor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hudson-core Show documentation
Show all versions of hudson-core Show documentation
Contains the core Hudson code and view files to render HTML.
The newest version!
/*******************************************************************************
*
* Copyright (c) 2004-2009 Oracle Corporation.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*
* Kohsuke Kawaguchi
*
*
*******************************************************************************/
package hudson.slaves;
import hudson.Extension;
import hudson.model.ComputerSet;
import hudson.model.Descriptor;
import hudson.model.Slave;
import hudson.model.Node;
import hudson.model.Hudson;
import hudson.util.DescriptorList;
import hudson.util.FormValidation;
import hudson.DescriptorExtensionList;
import hudson.Util;
import hudson.model.Failure;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import javax.servlet.ServletException;
/**
* {@link Descriptor} for {@link Slave}.
*
* Views
This object needs to have newInstanceDetail.jelly
* view, which shows up in http://server/hudson/computers/new page as
* an explanation of this job type.
*
*
Other Implementation Notes
*
* @author Kohsuke Kawaguchi
*/
public abstract class NodeDescriptor extends Descriptor {
protected NodeDescriptor(Class extends Node> clazz) {
super(clazz);
}
protected NodeDescriptor() {
}
/**
* Can the administrator create this type of nodes from UI?
*
* Return false if it only makes sense for programs to create it, not
* through the "new node" UI.
*/
public boolean isInstantiable() {
return true;
}
public final String newInstanceDetailPage() {
return '/' + clazz.getName().replace('.', '/').replace('$', '/') + "/newInstanceDetail.jelly";
}
/**
* Handles the form submission from the "/computer/new" page, which is the
* first form for creating a new node. By default, it shows the
* configuration page for entering details, but subtypes can override this
* differently.
*
* @param name Name of the new node.
*/
public void handleNewNodePage(ComputerSet computerSet, String name, StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
computerSet.checkName(name);
req.setAttribute("descriptor", this);
req.getView(computerSet, "_new.jelly").forward(req, rsp);
}
@Override
public String getConfigPage() {
return getViewPage(clazz, "configure-entries.jelly");
}
public FormValidation doCheckName(@QueryParameter String value) {
String name = Util.fixEmptyAndTrim(value);
if (name == null) {
return FormValidation.error(Messages.NodeDescripter_CheckName_Mandatory());
}
try {
Hudson.checkGoodName(name);
} catch (Failure f) {
return FormValidation.error(f.getMessage());
}
return FormValidation.ok();
}
/**
* Returns all the registered {@link NodeDescriptor} descriptors.
*/
public static DescriptorExtensionList all() {
return Hudson.getInstance().getDescriptorList(Node.class);
}
/**
* All the registered instances.
*
* @deprecated as of 1.286 Use {@link #all()} for read access, and
* {@link Extension} for registration.
*/
public static final DescriptorList ALL = new DescriptorList(Node.class);
public static List allInstantiable() {
List r = new ArrayList();
for (NodeDescriptor d : all()) {
if (d.isInstantiable()) {
r.add(d);
}
}
return r;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy