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());
}
}
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);
}
}
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);
}
}
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();
}
}
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;
}
Aggregations