Search in sources :

Example 31 with BulkChange

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

the class WorkflowJob method setTriggers.

public void setTriggers(List<Trigger<?>> inputTriggers) throws IOException {
    triggers = null;
    BulkChange bc = new BulkChange(this);
    try {
        PipelineTriggersJobProperty originalProp = getTriggersJobProperty();
        removeProperty(PipelineTriggersJobProperty.class);
        PipelineTriggersJobProperty triggerProp = new PipelineTriggersJobProperty(null);
        triggerProp.setTriggers(inputTriggers);
        addProperty(triggerProp);
        bc.commit();
        originalProp.stopTriggers();
    // No longer need to start triggers here - that's done by when we add the property.
    } finally {
        bc.abort();
    }
}
Also used : BulkChange(hudson.BulkChange) PipelineTriggersJobProperty(org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty)

Example 32 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class GlobalSecurityConfiguration method doConfigure.

@POST
public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    // for compatibility reasons, the actual value is stored in Jenkins
    BulkChange bc = new BulkChange(Jenkins.get());
    try {
        boolean result = configure(req, req.getSubmittedForm());
        LOGGER.log(Level.FINE, "security saved: " + result);
        Jenkins.get().save();
        FormApply.success(req.getContextPath() + "/manage").generateResponse(req, rsp, null);
    } finally {
        bc.commit();
    }
}
Also used : BulkChange(hudson.BulkChange) POST(org.kohsuke.stapler.verb.POST)

Example 33 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class Jenkins method setViews.

/**
 * Completely replaces views.
 *
 * <p>
 * This operation is NOT provided as an atomic operation, but rather
 * the sole purpose of this is to define a setter for this to help
 * introspecting code, such as system-config-dsl plugin
 */
// even if we want to offer this atomic operation, CopyOnWriteArrayList
// offers no such operation
public void setViews(Collection<View> views) throws IOException {
    try (BulkChange bc = new BulkChange(this)) {
        this.views.clear();
        for (View v : views) {
            addView(v);
        }
        bc.commit();
    }
}
Also used : BulkChange(hudson.BulkChange) AllView(hudson.model.AllView) ListView(hudson.model.ListView) View(hudson.model.View)

Example 34 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class Jenkins method doConfigExecutorsSubmit.

/**
 * Accepts submission from the node configuration page.
 */
@POST
public synchronized void doConfigExecutorsSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
    checkPermission(ADMINISTER);
    try (BulkChange bc = new BulkChange(this)) {
        JSONObject json = req.getSubmittedForm();
        ExtensionList.lookupSingleton(MasterBuildConfiguration.class).configure(req, json);
        getNodeProperties().rebuild(req, json.optJSONObject("nodeProperties"), NodeProperty.all());
        bc.commit();
    }
    updateComputerList();
    // back to the computer page
    rsp.sendRedirect(req.getContextPath() + '/' + toComputer().getUrl());
}
Also used : JSONObject(net.sf.json.JSONObject) BulkChange(hudson.BulkChange) POST(org.kohsuke.stapler.verb.POST) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST)

Example 35 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class NodeProvisionerTest method baselineSlaveUsage.

/**
 * Scenario: make sure we take advantage of statically configured agents.
 */
// TODO fragile
@Test
public void baselineSlaveUsage() throws Exception {
    assumeFalse("TODO: Windows container agents do not have enough resources to run this test", Functions.isWindows() && System.getenv("CI") != null);
    try (BulkChange bc = new BulkChange(r.jenkins)) {
        DummyCloudImpl cloud = initHudson(0);
        // add agents statically upfront
        r.createSlave().toComputer().connect(false).get();
        r.createSlave().toComputer().connect(false).get();
        verifySuccessfulCompletion(buildAll(create5SlowJobs(new Latch(5))));
        // we should have used two static slaves, thus only 3 slaves should have been provisioned
        assertEquals(3, cloud.numProvisioned);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) BulkChange(hudson.BulkChange) Test(org.junit.Test)

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