@Override public Node newInstance(StaplerRequest req, JSONObject formData) throws FormException { EC2OndemandSlave ec2AbstractSlave = (EC2OndemandSlave) super.newInstance(req, formData); if (!ec2AbstractSlave.isAlive(true)) { LOGGER.info("EC2 instance terminated externally: " + ec2AbstractSlave.getInstanceId()); try { Hudson.getInstance().removeNode(ec2AbstractSlave); } catch (IOException ioe) { LOGGER.log(Level.WARNING, "Attempt to reconfigure EC2 instance which has been externally terminated: " + ec2AbstractSlave.getInstanceId(), ioe); } return null; } return ec2AbstractSlave; }
/** * Provisions a new EC2 slave based on the currently running instance on EC2, * instead of starting a new one. */ public EC2AbstractSlave attach(String instanceId, TaskListener listener) throws AmazonClientException, IOException { PrintStream logger = listener.getLogger(); AmazonEC2 ec2 = getParent().connect(); try { logger.println("Attaching to "+instanceId); LOGGER.info("Attaching to "+instanceId); DescribeInstancesRequest request = new DescribeInstancesRequest(); request.setInstanceIds(Collections.singletonList(instanceId)); Instance inst = ec2.describeInstances(request).getReservations().get(0).getInstances().get(0); return newOndemandSlave(inst); } catch (FormException e) { throw new AssertionError(); // we should have discovered all configuration issues upfront } }
@DataBoundConstructor public EC2AbstractSlave(String name, String instanceId, String description, String remoteFS, int numExecutors, Mode mode, String labelString, ComputerLauncher launcher, RetentionStrategy<EC2Computer> retentionStrategy, String initScript, String tmpDir, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, List<EC2Tag> tags, String cloudName, boolean usePrivateDnsName, boolean useDedicatedTenancy, int launchTimeout, AMITypeData amiType) throws FormException, IOException { super(name, "", remoteFS, numExecutors, mode, labelString, launcher, retentionStrategy, nodeProperties); this.instanceId = instanceId; this.initScript = initScript; this.tmpDir = tmpDir; this.remoteAdmin = remoteAdmin; this.jvmopts = jvmopts; this.stopOnTerminate = stopOnTerminate; this.idleTerminationMinutes = idleTerminationMinutes; this.tags = tags; this.usePrivateDnsName = usePrivateDnsName; this.useDedicatedTenancy = useDedicatedTenancy; this.cloudName = cloudName; this.launchTimeout = launchTimeout; this.amiType = amiType; readResolve(); }
/** {@inheritDoc} */ @Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { super.submit(req, rsp); final JSONObject json = req.getSubmittedForm(); setYamlPath(json.optString("yamlPath")); if (json.containsKey("restriction")) { setRestriction(req.bindJSON(AbstractRestriction.class, json.getJSONObject("restriction"))); } else { setRestriction(new NoRestriction()); } }
/** {@inheritDoc} */ @Override public <T extends Describable> T bind(JSONObject json) throws IOException, FormException { final String clazz = checkNotNull(json.optString("$class", null)); final Descriptor descriptor = getDescriptor(clazz); final Stapler stapler = getStapler(); final StaplerRequest request = getRequest(stapler, json); // We do this instead of 'request.bindJson' because this doesn't // require a DataBoundConstructor. // TODO(mattmoor): Should we do the rewrite of describable lists // here as well? return (T) descriptor.newInstance(request, json); }
@Override public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { super.doConfigSubmit(req, rsp); // set assigned node JSONObject json = req.getSubmittedForm(); String jsonStr = json.toString(); String leroyBuilderJson = JsonUtils.getLeroyConfigurationBuilderJSON(jsonStr); String leroyNode = JsonPath.read(leroyBuilderJson, "$.leroyNode"); String assignedNodeName = leroyNode == null ? "" : leroyNode; Node n = LeroyUtils.findNodeByName(assignedNodeName); if (n != null) { setAssignedNode(n); } save(); }
@Override protected void submit(StaplerRequest req) throws ServletException, IOException, FormException { super.submit(req); JSONObject json = req.getSubmittedForm(); synchronized (this) { String requestedOrdering = req.getParameter("order"); title = req.getParameter("title"); currentConfig().setDisplayCommitters(json.optBoolean("displayCommitters", true)); currentConfig().setBuildFailureAnalyzerDisplayedField(req.getParameter("buildFailureAnalyzerDisplayedField")); try { currentConfig().setOrder(orderIn(requestedOrdering)); } catch (Exception e) { throw new FormException("Can't order projects by " + requestedOrdering, "order"); } } }
public ContainerInfo copyWithDockerImage(String dockerImage) throws FormException { return new ContainerInfo( type, dockerImage, // custom docker image dockerPrivilegedMode, dockerForcePullImage, dockerImageCustomizable, useCustomDockerCommandShell, customDockerCommandShell, volumes, parameters, networking, portMappings, networkInfos ); }
public MesosSlave(MesosCloud cloud, String name, int numExecutors, MesosSlaveInfo slaveInfo) throws IOException, FormException { super(name, slaveInfo.getLabelString(), // node description. StringUtils.isBlank(slaveInfo.getRemoteFSRoot()) ? "jenkins" : slaveInfo.getRemoteFSRoot().trim(), // remoteFS. "" + numExecutors, slaveInfo.getMode(), slaveInfo.getLabelString(), // Label. new MesosComputerLauncher(cloud, name), new MesosRetentionStrategy(slaveInfo.getIdleTerminationMinutes()), slaveInfo.getNodeProperties()); this.cloud = cloud; this.cloudName = cloud.getDisplayName(); this.slaveInfo = slaveInfo; this.idleTerminationMinutes = slaveInfo.getIdleTerminationMinutes(); this.cpus = slaveInfo.getSlaveCpus() + (numExecutors * slaveInfo.getExecutorCpus()); this.mem = slaveInfo.getSlaveMem() + (numExecutors * slaveInfo.getExecutorMem()); this.diskNeeded = slaveInfo.getdiskNeeded(); LOGGER.fine("Constructing Mesos slave " + name + " from cloud " + cloud.getDescription()); }
public void doProjectsSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, UnsupportedEncodingException, ServletException, FormException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); CloudCIAuthorizationStrategy.DESCRIPTOR.doProjectsSubmit(req, rsp); rsp.sendRedirect("."); }
public void doAssignSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, UnsupportedEncodingException, ServletException, FormException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); CloudCIAuthorizationStrategy.DESCRIPTOR.doAssignSubmit(req, rsp); rsp.sendRedirect("."); }
/** * Used to persist the configuration form upon submission. * * @since 1.0 */ @Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { super.submit(req, rsp); JSONObject json = req.getSubmittedForm(); String key = "preTestConfig"; JSONObject viewObject; if (json.has(key)) { viewObject = json.getJSONObject(key); if (viewObject != null) { key = "testCaseList"; if (viewObject.has(key)) { this.testCaseList = viewObject.getString(key); } key = "testTargetScript"; if (viewObject.has(key)) { this.testTargetScript = viewObject.getString(key); } key = "testListIsRelOrAbs"; if (viewObject.has(key)) { this.testListIsRelOrAbs = viewObject.getString(key); } key = "targetScrIsRelOrAbs"; if (viewObject.has(key)) { this.targetScrIsRelOrAbs = viewObject.getString(key); } key = "slaveTestEnv"; if (viewObject.has(key)) { this.slaveTestEnv = viewObject.getString(key); } key = "statisticsFile"; if (viewObject.has(key)) { this.statisticsFile = viewObject.getString(key); } } } }
/** * Custom specified ID. When editing existed UI entry, UI sends it back. */ public DockerSlaveTemplate(@Nonnull String id) throws FormException { super(id); if (isNull(id)) { throw new FormException("Hidden id must not be null", "id"); } }
/** * FIXME DescribableList doesn't work with DBS https://gist.github.com/KostyaSha/3414f4f453ea7c7406b4 */ @DataBoundConstructor public DockerSlaveTemplate(@Nonnull String id, List<NodeProperty<?>> nodeProperties) throws FormException { this(id); setNodeProperties(nodeProperties); }
@DataBoundConstructor public EC2OndemandSlave(String name, String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, boolean usePrivateDnsName, boolean useDedicatedTenancy, int launchTimeout, AMITypeData amiType) throws FormException, IOException { super(name, instanceId, description, remoteFS, numExecutors, mode, labelString, amiType.isWindows() ? new EC2WindowsLauncher() : new EC2UnixLauncher(), new EC2RetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, jvmopts, stopOnTerminate, idleTerminationMinutes, tags, cloudName, usePrivateDnsName, useDedicatedTenancy, launchTimeout, amiType); this.publicDNS = publicDNS; this.privateDNS = privateDNS; }
@Override public Node newInstance(StaplerRequest req, JSONObject formData) throws FormException { EC2AbstractSlave ec2AbstractSlave = (EC2AbstractSlave) super.newInstance(req, formData); /* Get rid of the old tags, as represented by ourselves. */ ec2AbstractSlave.clearLiveInstancedata(); /* Set the new tags, as represented by our successor */ ec2AbstractSlave.pushLiveInstancedata(); return ec2AbstractSlave; }
@DataBoundConstructor public EC2SpotSlave(String name, String spotInstanceRequestId, String description, String remoteFS, int numExecutors, Mode mode, String initScript, String tmpDir, String labelString, List<? extends NodeProperty<?>> nodeProperties, String remoteAdmin, String jvmopts, String idleTerminationMinutes, List<EC2Tag> tags, String cloudName, boolean usePrivateDnsName, int launchTimeout, AMITypeData amiType) throws FormException, IOException { super(name, "", description, remoteFS, numExecutors, mode, labelString, new EC2SpotComputerLauncher(), new EC2SpotRetentionStrategy(idleTerminationMinutes), initScript, tmpDir, nodeProperties, remoteAdmin, jvmopts, false, idleTerminationMinutes, tags, cloudName, usePrivateDnsName, false, launchTimeout, amiType); this.name = name; this.spotInstanceRequestId = spotInstanceRequestId; }
@DataBoundConstructor public RavelloSlave(ComputerLauncher delegate, String name, String nodeDescription, String remoteFS, int numExecutors, String labelString, RetentionStrategy retentionStrategy) throws FormException, IOException { super(name, nodeDescription, remoteFS, numExecutors, Mode.EXCLUSIVE, labelString, new RavelloLauncher(delegate), retentionStrategy); }
public RavelloSlave(ComputerLauncher delegate, String name, String nodeDescription, String remoteFS, int numExecutors, String labelString, RetentionStrategy retentionStrategy, String vmName, String appId) throws IOException, FormException { this(delegate, name, nodeDescription, remoteFS, numExecutors, labelString,retentionStrategy); this.vmName = vmName; this.appId = appId; }
/** {@inheritDoc} */ @Override public boolean configure(StaplerRequest req, JSONObject json) throws FormException { json = json.getJSONObject(getDisplayName()); if (json.optBoolean("verboseLogging", false)) { verboseLogging = true; } else { verboseLogging = false; } save(); return true; }
/** {@inheritDoc} */ @Override public void rebuild(StaplerRequest req, JSONObject json, List<? extends Descriptor<T>> descriptors) throws FormException, IOException { // TODO(mattmoor): Add diagnostics if formData contains // uninstantiable classes. // NOTE: The way this works, I'm not sure this is possible, // since the potential class names are keys? // encoding is just replace('.', '-') super.rebuild(req, json, applyFilter(descriptors)); }
/** {@inheritDoc} */ @Override public void rebuildHetero(StaplerRequest req, JSONObject formData, Collection<? extends Descriptor<T>> descriptors, String key) throws FormException, IOException { // Detect references to classes that aren't installed. final Object array = formData.get(key); if (array != null) { for (Object o : JSONArray.fromObject(array)) { validateClass(((JSONObject) o).getString("$class"), descriptors); } } super.rebuildHetero(req, formData, applyFilter(descriptors), key); }
/** {@inheritDoc} */ @Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { super.submit(req, rsp); final JSONObject json = req.getSubmittedForm(); getBuildWrappersList().rebuild(req, json, BuildWrappers.getFor(this)); getPublishersList().rebuildHetero(req, json, Publisher.all(), "publisher"); }
@Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { super.submit(req, rsp); JSONObject json = req.getSubmittedForm(); getBuildWrappersList().rebuild(req, json, BuildWrappers.getFor(this)); getBuildersList().rebuildHetero(req, json, Builder.all(), "builder"); getPublishersList().rebuildHetero(req, json, Publisher.all(), "publisher"); }
@Override protected void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { JSONObject json = req.getSubmittedForm(); super.submit(req, rsp); getBuildWrappersList().rebuild(req, json, BuildWrappers.getFor(this)); getBuildersList().rebuildHetero(req, json, Builder.all(), "builder"); getPublishersList().rebuildHetero(req, json, Publisher.all(), "publisher"); }
@Override public UserProperty reconfigure(StaplerRequest req, JSONObject form) throws FormException { initPython(); if (pexec.isImplemented(1)) { return (UserProperty) pexec.execPython("reconfigure", req, form); } else { return super.reconfigure(req, form); } }
@Override @RequirePOST public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { initPython(); if (pexec.isImplemented(64)) { pexec.execPythonVoid("do_config_submit", req, rsp); } else { super.doConfigSubmit(req, rsp); } }
@Override public void submit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { initPython(); if (pexec.isImplemented(65)) { pexec.execPythonVoid("submit", req, rsp); } else { super.submit(req, rsp); } }
@Override public void rename(String newName) throws Failure, FormException { initPython(); if (pexec.isImplemented(2)) { pexec.execPythonVoid("rename", newName); } else { super.rename(newName); } }
@Override public JobProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws FormException { initPython(); if (pexec.isImplemented(8)) { return (JobProperty) pexec.execPython("reconfigure", req, form); } else { return super.reconfigure(req, form); } }
@Override public NodeProperty<?> reconfigure(StaplerRequest req, JSONObject form) throws FormException { initPython(); if (pexec.isImplemented(6)) { return (NodeProperty) pexec.execPython("reconfigure", req, form); } else { return super.reconfigure(req, form); } }
@Override @RequirePOST public HttpResponse doConfigSubmit(StaplerRequest req) throws IOException, ServletException, FormException { initPython(); if (pexec.isImplemented(83)) { return (HttpResponse) pexec.execPython("do_config_submit", req); } else { return super.doConfigSubmit(req); } }
@Override public Node reconfigure(final StaplerRequest req, JSONObject form) throws FormException { initPython(); if (pexec.isImplemented(13)) { return (Node) pexec.execPython("reconfigure", req, form); } else { return super.reconfigure(req, form); } }
@Override public void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { //Check if we're transient; in which case a submit does nothing if (this.isTransient) { return; } //Calling the super implementation; will ultimately call submit() super.doConfigSubmit(req, rsp); }
/** * This method is used, when the user wishes to build a very specific * version of this project or its parents. * <p> * This method comes in three stages: * <ol> * <li>The first that displays the current versions, and allows the user to * select the correct ones.</li> * <li>The second, that parses the version map from JSON and refreshes the page</li> * <li>The third, where the user actually wants to start the build.</li> * </ol> * Once the third phase is reached; the versioning information is encoded * in an URL parameter and passed to the normal build page and handled * via {@link #doBuild(StaplerRequest, StaplerResponse, TimeDuration)} * * @param req the incoming request from the user. * @param rsp the response that shall be sent to the user * * @throws IOException * @throws ServletException * @throws FormException */ public void doBuildSpecificVersion(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException { //Purge whatever's stored in the thread from a previous run //ThreadAssocStore.getInstance().clear(Thread.currentThread()); //If we did not submit a form; just display the initial data if(!req.getMethod().equals("POST")) { req.getView(this, "buildSpecificVersion").forward(req,rsp); return; } //Convert the request's JSON into a proper Map Map<String, Long> verMap = VersionHandler.getFromFormRequest(req); if (verMap == null) { throw new FormException( "Could not decode versioning table", VersionHandler.VERSIONING_KEY ); } //Now, filter the map, to allow an URL that is as short as possible this.filterVersionMap(verMap); //And turn the Map into an URL-safe string String verMapStr = VersionHandler.encodeUrlParameter(verMap); //TODO: Think about passing the verMapStr compressed String verUrlParm = VersionHandler.getFullUrlParameter(verMapStr); //Checking if the user wants to build or refresh the page if (req.hasParameter("doRefresh")) { //Refreshing the page with the newly selected versions rsp.sendRedirect("buildSpecificVersion?" + verUrlParm); } else { //Triggering a nice build with the given version map rsp.sendRedirect("build?" + verUrlParm); } }
@Test public void testGetDescriptor() throws FormException { final ProjectSpecificActionFactory psa = new ProjectSpecificActionFactory(); final DescriptorImplPSA d = (DescriptorImplPSA) psa.getDescriptor(); assertNotNull(d); d.getDisplayName(); d.newInstance((StaplerRequest)null, (JSONObject)null); d.configure((StaplerRequest)null, (JSONObject)null); DescriptorImplPSA.isShowGraph(); }
@DataBoundConstructor public ContainerInfo(String type, String dockerImage, boolean dockerPrivilegedMode, boolean dockerForcePullImage, boolean dockerImageCustomizable, boolean useCustomDockerCommandShell, String customDockerCommandShell, List<Volume> volumes, List<Parameter> parameters, String networking, List<PortMapping> portMappings, List<NetworkInfo> networkInfos) throws FormException { this.type = type; this.dockerImage = dockerImage; this.dockerPrivilegedMode = dockerPrivilegedMode; this.dockerForcePullImage = dockerForcePullImage; this.dockerImageCustomizable = dockerImageCustomizable; this.useCustomDockerCommandShell = useCustomDockerCommandShell; this.customDockerCommandShell = customDockerCommandShell; this.volumes = volumes; this.parameters = parameters; this.networkInfos = networkInfos; if (networking == null) { this.networking = DEFAULT_NETWORKING; } else { this.networking = networking; } if (Network.HOST.equals(Network.valueOf(networking))) { this.portMappings = Collections.emptyList(); } else { this.portMappings = portMappings; } }
@DataBoundConstructor public DockerSlave(DockerLauncher launcher, DockerCloud dockerCloud, String name, String dockerId, String nodeDescription, String remoteFS, Mode mode, String labelString, List<? extends NodeProperty<?>> nodeProperties) throws FormException, IOException { super(name, nodeDescription, remoteFS, 1, mode, labelString, launcher, new OnceRetentionStrategy(0), nodeProperties); this.dockerCloud = dockerCloud; this.dockerId = dockerId; }
public EC2OndemandSlave(String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, int launchTimeout, AMITypeData amiType) throws FormException, IOException { this(description + " (" + instanceId + ")", instanceId, description, remoteFS, numExecutors, labelString, mode, initScript, tmpDir, Collections.<NodeProperty<?>>emptyList(), remoteAdmin, jvmopts, stopOnTerminate, idleTerminationMinutes, publicDNS, privateDNS, tags, cloudName, false, false, launchTimeout, amiType); }
public EC2OndemandSlave(String instanceId, String description, String remoteFS, int numExecutors, String labelString, Mode mode, String initScript, String tmpDir, String remoteAdmin, String jvmopts, boolean stopOnTerminate, String idleTerminationMinutes, String publicDNS, String privateDNS, List<EC2Tag> tags, String cloudName, boolean usePrivateDnsName, boolean useDedicatedTenancy, int launchTimeout, AMITypeData amiType) throws FormException, IOException { this(description + " (" + instanceId + ")", instanceId, description, remoteFS, numExecutors, labelString, mode, initScript, tmpDir, Collections.<NodeProperty<?>>emptyList(), remoteAdmin, jvmopts, stopOnTerminate, idleTerminationMinutes, publicDNS, privateDNS, tags, cloudName, usePrivateDnsName, useDedicatedTenancy, launchTimeout, amiType); }