예제 #1
0
    @Test
    public void testGetQueueItems() throws IOException, Exception{
        ListView view1 = listView("view1");
        view1.filterQueue = true;
        ListView view2 = listView("view2");
        view2.filterQueue = true;

        FreeStyleProject inView1 = j.createFreeStyleProject("in-view1");
        inView1.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view1.add(inView1);

        MatrixProject inView2 = j.createMatrixProject("in-view2");
        inView2.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view2.add(inView2);

        FreeStyleProject notInView = j.createFreeStyleProject("not-in-view");
        notInView.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));

        FreeStyleProject inBothViews = j.createFreeStyleProject("in-both-views");
        inBothViews.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view1.add(inBothViews);
        view2.add(inBothViews);

        Queue.getInstance().schedule(notInView, 0);
        Queue.getInstance().schedule(inView1, 0);
        Queue.getInstance().schedule(inView2, 0);
        Queue.getInstance().schedule(inBothViews, 0);

        Thread.sleep(1000);

        assertContainsItems(view1, inView1, inBothViews);
        assertNotContainsItems(view1, notInView, inView2);
        assertContainsItems(view2, inView2, inBothViews);
        assertNotContainsItems(view2, notInView, inView1);
    }
예제 #2
0
 private void assertNotContainsItems(View view, Task... items) {
     for (Task job: items) {
         assertFalse(
                 "Queued items for " + view.getDisplayName() + " should not contain " + job.getDisplayName(),
                 view.getQueueItems().contains(Queue.getInstance().getItem(job))
         );
     }
 }
예제 #3
0
    @Override
    @GuardedBy("hudson.model.Queue.lock")
    public long check(final SlaveComputer c) {
      if (c.isOffline() && c.isLaunchSupported()) {
        final HashMap<Computer, Integer> availableComputers = new HashMap<Computer, Integer>();
        for (Computer o : Jenkins.getInstance().getComputers()) {
          if ((o.isOnline() || o.isConnecting()) && o.isPartiallyIdle() && o.isAcceptingTasks()) {
            final int idleExecutors = o.countIdle();
            if (idleExecutors > 0) availableComputers.put(o, idleExecutors);
          }
        }

        boolean needComputer = false;
        long demandMilliseconds = 0;
        for (Queue.BuildableItem item : Queue.getInstance().getBuildableItems()) {
          // can any of the currently idle executors take this task?
          // assume the answer is no until we can find such an executor
          boolean needExecutor = true;
          for (Computer o : Collections.unmodifiableSet(availableComputers.keySet())) {
            Node otherNode = o.getNode();
            if (otherNode != null && otherNode.canTake(item) == null) {
              needExecutor = false;
              final int availableExecutors = availableComputers.remove(o);
              if (availableExecutors > 1) {
                availableComputers.put(o, availableExecutors - 1);
              } else {
                availableComputers.remove(o);
              }
              break;
            }
          }

          // this 'item' cannot be built by any of the existing idle nodes, but it can be built by
          // 'c'
          Node checkedNode = c.getNode();
          if (needExecutor && checkedNode != null && checkedNode.canTake(item) == null) {
            demandMilliseconds = System.currentTimeMillis() - item.buildableStartMilliseconds;
            needComputer = demandMilliseconds > inDemandDelay * 1000 * 60 /*MINS->MILLIS*/;
            break;
          }
        }

        if (needComputer) {
          // we've been in demand for long enough
          logger.log(
              Level.INFO,
              "Launching computer {0} as it has been in demand for {1}",
              new Object[] {c.getName(), Util.getTimeSpanString(demandMilliseconds)});
          c.connect(false);
        }
      } else if (c.isIdle()) {
        final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds();
        if (idleMilliseconds > idleDelay * 1000 * 60 /*MINS->MILLIS*/) {
          // we've been idle for long enough
          logger.log(
              Level.INFO,
              "Disconnecting computer {0} as it has been idle for {1}",
              new Object[] {c.getName(), Util.getTimeSpanString(idleMilliseconds)});
          c.disconnect(new OfflineCause.IdleOfflineCause());
        } else {
          // no point revisiting until we can be confident we will be idle
          return TimeUnit.MILLISECONDS.toMinutes(
              TimeUnit.MINUTES.toMillis(idleDelay) - idleMilliseconds);
        }
      }
      return 1;
    }