Search in sources :

Example 26 with BulkChange

use of hudson.BulkChange in project kubernetes-plugin by jenkinsci.

the class PodTemplateAction method pop.

@Deprecated
public String pop() throws IOException {
    if (run == null) {
        LOGGER.warning("run is null, cannot pop");
        return null;
    }
    synchronized (run) {
        BulkChange bc = new BulkChange(run);
        try {
            PodTemplateAction action = run.getAction(PodTemplateAction.class);
            if (action == null) {
                action = new PodTemplateAction(run);
                run.addAction(action);
            }
            String template = action.stack.pop();
            bc.commit();
            return template;
        } finally {
            bc.abort();
        }
    }
}
Also used : BulkChange(hudson.BulkChange)

Example 27 with BulkChange

use of hudson.BulkChange in project hudson-2.x by hudson.

the class Hudson method doConfigExecutorsSubmit.

/**
 * Accepts submission from the configuration page.
 */
public synchronized void doConfigExecutorsSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    checkPermission(ADMINISTER);
    BulkChange bc = new BulkChange(this);
    try {
        JSONObject json = req.getSubmittedForm();
        setNumExecutors(Integer.parseInt(req.getParameter("numExecutors")));
        if (req.hasParameter("master.mode")) {
            mode = Mode.valueOf(req.getParameter("master.mode"));
        } else {
            mode = Mode.NORMAL;
        }
        setNodes(req.bindJSONToList(Slave.class, json.get("slaves")));
    } finally {
        bc.commit();
    }
    // go to the top page
    rsp.sendRedirect(req.getContextPath() + '/');
}
Also used : DumbSlave(hudson.slaves.DumbSlave) JSONObject(net.sf.json.JSONObject) BulkChange(hudson.BulkChange)

Example 28 with BulkChange

use of hudson.BulkChange in project hudson-2.x by hudson.

the class ComputerSet method doConfigSubmit.

/**
 * Accepts submission from the configuration page.
 */
public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    BulkChange bc = new BulkChange(MONITORS_OWNER);
    try {
        Hudson.getInstance().checkPermission(Hudson.ADMINISTER);
        monitors.rebuild(req, req.getSubmittedForm(), getNodeMonitorDescriptors());
        // add in the rest of instances are ignored instances
        for (Descriptor<NodeMonitor> d : NodeMonitor.all()) if (monitors.get(d) == null) {
            NodeMonitor i = createDefaultInstance(d, true);
            if (i != null)
                monitors.add(i);
        }
        rsp.sendRedirect2(".");
    } finally {
        bc.commit();
    }
}
Also used : BulkChange(hudson.BulkChange) NodeMonitor(hudson.node_monitors.NodeMonitor)

Example 29 with BulkChange

use of hudson.BulkChange in project support-core-plugin by jenkinsci.

the class SupportAutomatedBundleConfiguration method configure.

@Override
@POST
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    Jenkins.get().checkPermission(Jenkins.ADMINISTER);
    if (json.getBoolean("enabled") && !json.has("components")) {
        throw new Descriptor.FormException(Messages.SupportAutomatedBundleConfiguration_enabled_noComponents(), "components");
    }
    try (BulkChange bc = new BulkChange(this)) {
        setComponentIds(parseRequest(req, json));
        setPeriod(json.getInt("period"));
        setEnabled(json.getBoolean("enabled"));
        bc.commit();
    } catch (IOException e) {
        LOG.log(WARNING, "Failed to save " + getConfigFile(), e);
    }
    return true;
}
Also used : BulkChange(hudson.BulkChange) IOException(java.io.IOException) POST(org.kohsuke.stapler.verb.POST)

Example 30 with BulkChange

use of hudson.BulkChange in project workflow-job-plugin by jenkinsci.

the class WorkflowJob method addTrigger.

public void addTrigger(Trigger trigger) throws IOException {
    BulkChange bc = new BulkChange(this);
    try {
        PipelineTriggersJobProperty originalProp = getTriggersJobProperty();
        Trigger old = originalProp.getTriggerForDescriptor(trigger.getDescriptor());
        if (old != null) {
            originalProp.removeTrigger(old);
            old.stop();
        }
        originalProp.addTrigger(trigger);
        removeProperty(PipelineTriggersJobProperty.class);
        addProperty(originalProp);
        bc.commit();
    } finally {
        bc.abort();
    }
}
Also used : Trigger(hudson.triggers.Trigger) SCMTrigger(hudson.triggers.SCMTrigger) BulkChange(hudson.BulkChange) PipelineTriggersJobProperty(org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty)

Aggregations

BulkChange (hudson.BulkChange)38 IOException (java.io.IOException)11 JSONObject (net.sf.json.JSONObject)7 POST (org.kohsuke.stapler.verb.POST)7 RequirePOST (org.kohsuke.stapler.interceptor.RequirePOST)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 XStreamException (com.thoughtworks.xstream.XStreamException)2 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 Action (hudson.model.Action)2 Descriptor (hudson.model.Descriptor)2 FormException (hudson.model.Descriptor.FormException)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 Saveable (hudson.model.Saveable)2 NodeMonitor (hudson.node_monitors.NodeMonitor)2 List (java.util.List)2 ObjectMetadataAction (jenkins.scm.api.metadata.ObjectMetadataAction)2