Search in sources :

Example 16 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class NodeProvisionerTest method labels.

/**
 * Scenario: loads on one label shouldn't translate to load on another label.
 */
// TODO fragile
@Test
public void labels() 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);
        Label blue = r.jenkins.getLabel("blue");
        Label red = r.jenkins.getLabel("red");
        cloud.label = red;
        // red jobs
        List<FreeStyleProject> redJobs = create5SlowJobs(new Latch(5));
        for (FreeStyleProject p : redJobs) p.setAssignedLabel(red);
        // blue jobs
        List<FreeStyleProject> blueJobs = create5SlowJobs(new Latch(5));
        for (FreeStyleProject p : blueJobs) p.setAssignedLabel(blue);
        // build all
        List<Future<FreeStyleBuild>> blueBuilds = buildAll(blueJobs);
        verifySuccessfulCompletion(buildAll(redJobs));
        // cloud should only give us 5 nodes for 5 red jobs
        assertEquals(5, cloud.numProvisioned);
        // and all blue jobs should be still stuck in the queue
        for (Future<FreeStyleBuild> bb : blueBuilds) assertFalse(bb.isDone());
    }
}
Also used : Label(hudson.model.Label) CountDownLatch(java.util.concurrent.CountDownLatch) BulkChange(hudson.BulkChange) QueueTaskFuture(hudson.model.queue.QueueTaskFuture) Future(java.util.concurrent.Future) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 17 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class NodeProvisionerTest method loadSpike.

/**
 * Scenario: we got a lot of jobs all of the sudden, and we need to fire up a few nodes.
 */
// TODO fragile
@Test
public void loadSpike() 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);
        verifySuccessfulCompletion(buildAll(create5SlowJobs(new Latch(5))));
        // the time it takes to complete a job is eternally long compared to the time it takes to launch
        // a new slave, so in this scenario we end up allocating 5 slaves for 5 jobs.
        assertEquals(5, cloud.numProvisioned);
    }
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) BulkChange(hudson.BulkChange) Test(org.junit.Test)

Example 18 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class NodeProvisionerTest method autoProvision.

/**
 * Scenario: schedule a build and see if one agent is provisioned.
 */
// TODO fragile
@Test
public void autoProvision() throws Exception {
    try (BulkChange bc = new BulkChange(r.jenkins)) {
        DummyCloudImpl cloud = initHudson(10);
        FreeStyleProject p = createJob(new SleepBuilder(10));
        Future<FreeStyleBuild> f = p.scheduleBuild2(0);
        // if it's taking too long, abort.
        f.get(30, TimeUnit.SECONDS);
        // since there's only one job, we expect there to be just one slave
        assertEquals(1, cloud.numProvisioned);
    }
}
Also used : BulkChange(hudson.BulkChange) SleepBuilder(org.jvnet.hudson.test.SleepBuilder) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 19 with BulkChange

use of hudson.BulkChange in project jenkins by jenkinsci.

the class ComputerSet method doConfigSubmit.

/**
 * Accepts submission from the configuration page.
 */
@POST
public synchronized HttpResponse doConfigSubmit(StaplerRequest req) throws IOException, ServletException, FormException {
    BulkChange bc = new BulkChange(MONITORS_OWNER);
    try {
        Jenkins.get().checkPermission(Jenkins.MANAGE);
        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);
        }
        // recompute the data
        for (NodeMonitor nm : monitors) {
            nm.triggerUpdate();
        }
        return FormApply.success(".");
    } finally {
        bc.commit();
    }
}
Also used : BulkChange(hudson.BulkChange) NodeMonitor(hudson.node_monitors.NodeMonitor) RequirePOST(org.kohsuke.stapler.interceptor.RequirePOST) POST(org.kohsuke.stapler.verb.POST)

Example 20 with BulkChange

use of hudson.BulkChange in project lockable-resources-plugin by jenkinsci.

the class LockableResourcesManager method configure.

@Override
public boolean configure(StaplerRequest req, JSONObject json) {
    final List<LockableResource> oldDeclaredResources = new ArrayList<>(getDeclaredResources());
    try (BulkChange bc = new BulkChange(this)) {
        // reset resources to default which are not currently locked
        this.resources.removeIf(resource -> !resource.isLocked());
        req.bindJSON(this, json);
        bc.commit();
    } catch (IOException exception) {
        LOGGER.log(Level.WARNING, "Exception occurred while committing bulkchange operation.", exception);
        return false;
    }
    // Copy unconfigurable properties from old instances
    boolean updated = false;
    for (LockableResource oldDeclaredResource : oldDeclaredResources) {
        final LockableResource updatedResource = fromName(oldDeclaredResource.getName());
        if (updatedResource != null) {
            updatedResource.copyUnconfigurableProperties(oldDeclaredResource);
            updated = true;
        }
    }
    if (updated) {
        save();
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) BulkChange(hudson.BulkChange) IOException(java.io.IOException)

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