示例#1
0
  /** Debug command to attach to a running instance. */
  public void doAttach(StaplerRequest req, StaplerResponse rsp, @QueryParameter String id)
      throws ServletException, IOException, AmazonClientException {
    checkPermission(PROVISION);
    SlaveTemplate t = getTemplates().get(0);

    StringWriter sw = new StringWriter();
    StreamTaskListener listener = new StreamTaskListener(sw);
    EC2AbstractSlave node = t.attach(id, listener);
    Hudson.getInstance().addNode(node);

    rsp.sendRedirect2(req.getContextPath() + "/computer/" + node.getNodeName());
  }
示例#2
0
  public HttpResponse doProvision(@QueryParameter String template)
      throws ServletException, IOException {
    checkPermission(PROVISION);
    if (template == null) {
      throw HttpResponses.error(SC_BAD_REQUEST, "The 'template' query parameter is missing");
    }
    SlaveTemplate t = getTemplate(template);
    if (t == null) {
      throw HttpResponses.error(SC_BAD_REQUEST, "No such template: " + template);
    }

    StringWriter sw = new StringWriter();
    StreamTaskListener listener = new StreamTaskListener(sw);
    try {
      EC2AbstractSlave node = t.provision(listener);
      Hudson.getInstance().addNode(node);

      return HttpResponses.redirectViaContextPath("/computer/" + node.getNodeName());
    } catch (AmazonClientException e) {
      throw HttpResponses.error(SC_INTERNAL_SERVER_ERROR, e);
    }
  }