Search in sources :

Example 1 with NodeDescriptor

use of hudson.slaves.NodeDescriptor in project hudson-2.x by hudson.

the class ComputerSet method doCreateItem.

/**
 * First check point in creating a new slave.
 */
public synchronized void doCreateItem(StaplerRequest req, StaplerResponse rsp, @QueryParameter String name, @QueryParameter String mode, @QueryParameter String from) throws IOException, ServletException {
    final Hudson app = Hudson.getInstance();
    // TODO: new permission?
    app.checkPermission(Hudson.ADMINISTER);
    if (mode != null && mode.equals("copy")) {
        name = checkName(name);
        Node src = app.getNode(from);
        if (src == null) {
            rsp.setStatus(SC_BAD_REQUEST);
            if (Util.fixEmpty(from) == null)
                sendError(Messages.ComputerSet_SpecifySlaveToCopy(), req, rsp);
            else
                sendError(Messages.ComputerSet_NoSuchSlave(from), req, rsp);
            return;
        }
        // copy through XStream
        String xml = Hudson.XSTREAM.toXML(src);
        Node result = (Node) Hudson.XSTREAM.fromXML(xml);
        result.setNodeName(name);
        result.holdOffLaunchUntilSave = true;
        app.addNode(result);
        // send the browser to the config page
        rsp.sendRedirect2(result.getNodeName() + "/configure");
    } else {
        // proceed to step 2
        if (mode == null) {
            rsp.sendError(SC_BAD_REQUEST);
            return;
        }
        NodeDescriptor d = NodeDescriptor.all().find(mode);
        d.handleNewNodePage(this, name, req, rsp);
    }
}
Also used : NodeDescriptor(hudson.slaves.NodeDescriptor)

Aggregations

NodeDescriptor (hudson.slaves.NodeDescriptor)1