/** Scenario: loads on one label shouldn't translate to load on another label. */
  public void testLabels() throws Exception {
    BulkChange bc = new BulkChange(hudson);
    try {
      DummyCloudImpl cloud = initHudson(0);
      Label blue = hudson.getLabel("blue");
      Label red = hudson.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());
    } finally {
      bc.abort();
    }
  }
  /** Scenario: we got a lot of jobs all of the sudden, and we need to fire up a few nodes. */
  public void testLoadSpike() throws Exception {
    BulkChange bc = new BulkChange(hudson);
    try {
      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);
    } finally {
      bc.abort();
    }
  }
  /** Scenario: schedule a build and see if one slave is provisioned. */
  public void testAutoProvision() throws Exception {
    BulkChange bc = new BulkChange(hudson);
    try {
      DummyCloudImpl cloud = initHudson(10);

      FreeStyleProject p = createJob(new SleepBuilder(10));

      Future<FreeStyleBuild> f = p.scheduleBuild2(0);
      f.get(30, TimeUnit.SECONDS); // if it's taking too long, abort.

      // since there's only one job, we expect there to be just one slave
      assertEquals(1, cloud.numProvisioned);
    } finally {
      bc.abort();
    }
  }
  /** Scenario: make sure we take advantage of statically configured slaves. */
  public void testBaselineSlaveUsage() throws Exception {
    BulkChange bc = new BulkChange(hudson);
    try {
      DummyCloudImpl cloud = initHudson(0);
      // add slaves statically upfront
      createSlave().toComputer().connect(false).get();
      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);
    } finally {
      bc.abort();
    }
  }
Beispiel #5
0
 /** {@inheritDoc} */
 @Override
 public void save() throws IOException {
   if (BulkChange.contains(this)) {
     return;
   }
   final File nodesDir = getNodesDir();
   final Set<String> existing = new HashSet<String>();
   for (Node n : nodes.values()) {
     if (n instanceof EphemeralNode) {
       continue;
     }
     existing.add(n.getNodeName());
     XmlFile xmlFile =
         new XmlFile(Jenkins.XSTREAM, new File(new File(nodesDir, n.getNodeName()), "config.xml"));
     xmlFile.write(n);
     SaveableListener.fireOnChange(this, xmlFile);
   }
   for (File forDeletion :
       nodesDir.listFiles(
           new FileFilter() {
             @Override
             public boolean accept(File pathname) {
               return pathname.isDirectory() && !existing.contains(pathname.getName());
             }
           })) {
     Util.deleteRecursive(forDeletion);
   }
 }
Beispiel #6
0
 public void save() throws IOException {
   if (BulkChange.contains(this)) return;
   try {
     getConfigFile().write(this);
     SaveableListener.fireOnChange(this, getConfigFile());
   } catch (IOException e) {
     LOGGER.log(Level.WARNING, "Failed to save " + getConfigFile(), e);
   }
 }
Beispiel #7
0
  /** Save the settings to a file. */
  public synchronized void save() throws IOException {
    if (BulkChange.contains(this)) return;

    long start = 0;
    if (logger.isLoggable(Level.FINE)) start = System.currentTimeMillis();

    File file = getFingerprintFile(md5sum);
    save(file);
    SaveableListener.fireOnChange(this, getConfigFile(file));

    if (logger.isLoggable(Level.FINE))
      logger.fine(
          "Saving fingerprint " + file + " took " + (System.currentTimeMillis() - start) + "ms");
  }
Beispiel #8
0
  /** Persists the queue contents to the disk. */
  public synchronized void save() {
    if (BulkChange.contains(this)) return;

    // write out the tasks on the queue
    ArrayList<Queue.Item> items = new ArrayList<Queue.Item>();
    for (Item item : getItems()) {
      if (item.task instanceof TransientTask) continue;
      items.add(item);
    }

    try {
      new XmlFile(XSTREAM, getXMLQueueFile()).write(items);
    } catch (IOException e) {
      LOGGER.log(Level.WARNING, "Failed to write out the queue file " + getQueueFile(), e);
    }
  }
Beispiel #9
0
 /** Save the settings to a file. */
 public synchronized void save() throws IOException {
   if (BulkChange.contains(this)) return;
   getConfigFile().write(this);
   SaveableListener.fireOnChange(this, getConfigFile());
 }