Refine search
/** * Convenience method that returns a read only view of the {@link Cause}s associated with this item in the queue. * * @return can be empty but never null * @since 1.343 */ public final List<Cause> getCauses() { CauseAction ca = getAction(CauseAction.class); if (ca!=null) return Collections.unmodifiableList(ca.getCauses()); return Collections.emptyList(); }
@Restricted(DoNotUse.class) // used from Jelly public String getCausesDescription() { List<Cause> causes = getCauses(); StringBuilder s = new StringBuilder(); for (Cause c : causes) { s.append(c.getShortDescription()).append('\n'); } return s.toString(); }
private boolean fitsSearchParams(@Nonnull Queue.Item item) { if (fitsSearchString(item.getDisplayName())) { return true; } else if (fitsSearchString(item.getId())) { return true; } // Non of the fuzzy matches "liked" the search term. return false; }
@Override public String getStatus() { // Yet another copy of the same logic; perhaps this should be factored into some method returning a union of Queue.Item and PlaceholderExecutable? for (Queue.Item item : Queue.getInstance().getItems()) { if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { return "waiting for " + item.task.getFullDisplayName() + " to be scheduled; blocked: " + item.getWhy(); } } Jenkins j = Jenkins.getInstance(); if (j != null) { COMPUTERS: for (Computer c : j.getComputers()) { for (Executor e : c.getExecutors()) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof PlaceholderTask.PlaceholderExecutable && ((PlaceholderTask.PlaceholderExecutable) exec).getParent().context.equals(getContext())) { return "running on " + c.getName(); } } } } return "node block appears to be neither running nor scheduled"; }
private void cancelPreviousJobsInQueueThatMatch(@Nonnull StashCause stashCause) { logger.fine("Looking for queued jobs that match PR ID: " + stashCause.getPullRequestId()); Queue queue = Jenkins.getInstance().getQueue(); for (Queue.Item item : queue.getItems()) { if (hasCauseFromTheSamePullRequest(item.getCauses(), stashCause)) { logger.info("Canceling item in queue: " + item); queue.cancel(item); } } }
public String getTooltip() { final Build r = getRun(); if (r != null) { return r.getIconColor().getDescription(); } final Queue.Item item = Jenkins.getInstance().getQueue().getItem(this.dynamicBuild.getParent().getItem(this.combination)); if (item != null) { return item.getWhy(); } return null; // fall back } }
boolean schedule(Cause cause) { if (!asJob().isBuildable()) { return false; } List<Action> queueActions = new LinkedList<Action>(); queueActions.add(new ParametersAction(getParameterValues())); queueActions.add(new CauseAction(cause)); int quiet = Math.max(MIN_QUIET, asJob().getQuietPeriod()); final Jenkins jenkins = Jenkins.getInstance(); if (jenkins == null) { logger.log(Level.WARNING, "Tried to schedule a build while Jenkins was gone."); return false; } final Queue queue = jenkins.getQueue(); if (queue == null) { throw new IllegalStateException("The queue is not initialized?!"); } Queue.Item i = queue.schedule2(asJob(), quiet, queueActions).getItem(); return i != null && i.getFuture() != null; }
@Override public CauseOfBlockage canRun(Queue.Item item) { if (item.task instanceof AbstractProject) { AbstractProject job = (AbstractProject) item.task; ContainerSetDefinition def = (ContainerSetDefinition) job.getProperty(ContainerSetDefinition.class); if (def == null) { return null; } int slaveCount = 0; DockerSlaves plugin = DockerSlaves.get(); for (Node node : Jenkins.getInstance().getNodes()) { if (node instanceof DockerSlave) { if (((DockerSlave)node).getQueueItemId() == item.getId()) { return null; } slaveCount++; } } if (slaveCount >= plugin.getMaxSlaves()) { return new WaitForADockerSlot(); } else { return null; } } else { return null; } }
@Override public String getStatus() { for (Queue.Item i : Queue.getInstance().getItems()) { for (BuildTriggerAction.Trigger trigger : BuildTriggerAction.triggersFor(i)) { if (trigger.context.equals(getContext())) { return "waiting to schedule " + i.task.getFullDisplayName() + "; blocked: " + i.getWhy(); } } } for (Computer c : Jenkins.getActiveInstance().getComputers()) { for (Executor e : c.getExecutors()) { String r = running(e); if (r != null) { return r; } } for (Executor e : c.getOneOffExecutors()) { String r = running(e); if (r != null) { return r; } } } // TODO QueueTaskFuture does not allow us to record the queue item ID return "unsure what happened to downstream build"; } private @CheckForNull String running(@Nonnull Executor e) {
private void cancelPreviousJobsInQueueThatMatch(@Nonnull BitbucketCause bitbucketCause) { logger.fine("Looking for queued jobs that match PR ID: " + bitbucketCause.getPullRequestId()); Queue queue = getInstance().getQueue(); for (Queue.Item item : queue.getItems()) { if (hasCauseFromTheSamePullRequest(item.getCauses(), bitbucketCause)) { logger.fine("Canceling item in queue: " + item); queue.cancel(item); } } }
CountDownLatch[] started = new CountDownLatch[ThrottleComputationQueueTaskDispatcher.LIMIT + 1]; for (int i = 0; i < d.length; i++) { d[i] = r.jenkins.createProject(SlowComputedFolder.class, "blockOneAboveLimit-" + i); d[i].started = started[i] = new CountDownLatch(1); d[i].finish = finished; q[i] = d[i].scheduleBuild2(0); f[i] = q[i].getFuture(); Future<?> maint = Queue.getInstance().scheduleMaintenance(); long waitForConditionNanos = TimeUnit.SECONDS.toNanos(10); while (System.nanoTime() - startNanoTime < waitForConditionNanos) { LOGGER.log(Level.INFO, "All {0} started", startedCount); assertThat(notStartedIndex, not(is(-1))); assertThat(q[notStartedIndex].getCauseOfBlockage(), notNullValue()); break; maint = Queue.getInstance().scheduleMaintenance(); f[i].get(); FolderComputation<?> computation = d[i].getComputation(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
@Override public void run() { Queue.Item item = Queue.getInstance().getItem(task); if (item != null) { PrintStream logger; try { logger = listener.getLogger(); } catch (Exception x) { // IOException, InterruptedException LOGGER.log(WARNING, null, x); return; } logger.println("Still waiting to schedule task"); String why = item.getWhy(); if (why != null) { logger.println(why); } } } }, 15, TimeUnit.SECONDS);
Queue.Item item = ParameterizedJobMixIn.scheduleBuild2(job, 0, new CauseAction(new CLICause(Jenkins.getAuthentication().getName())), a); QueueTaskFuture<? extends Run<?,?>> f = item != null ? (QueueTaskFuture)item.getFuture() : null; throw new IllegalStateException(BUILD_SCHEDULING_REFUSED); Run<?,?> b = f.waitForStart(); // wait for the start stdout.println("Started "+b.getFullDisplayName()); stdout.flush(); f.get(); // wait for the completion stdout.println("Completed "+b.getFullDisplayName()+" : "+b.getResult()); return b.getResult().ordinal; } else { f.cancel(true); Exception myException = new AbortException(); myException.initCause(e);
@Test @Issue("JENKINS-42511") public void concurrentEvents() throws Exception { CoordinatedComputedFolder d = r.jenkins.createProject(CoordinatedComputedFolder.class, "d"); d.kids.addAll(Arrays.asList("A", "B")); QueueTaskFuture<Queue.Executable> future = d.scheduleBuild2(0).getFuture(); d.onKid("B"); future.get(); waitUntilNoActivityIgnoringThreadDeathUpTo(10000); List<Throwable> deaths = new ArrayList<Throwable>(); for (Computer comp : r.jenkins.getComputers()) { for (Executor e : comp.getExecutors()) { if (e.getCauseOfDeath() != null) { deaths.add(e.getCauseOfDeath()); } } for (Executor e : comp.getOneOffExecutors()) { if (e.getCauseOfDeath() != null) { deaths.add(e.getCauseOfDeath()); } } } assertThat("None of the executors have died abnormally", deaths, containsInAnyOrder()); }
/** * Tests that event is properly removed if only two different projects are triggered * and one of them is cancelled while in the queue. * * @throws Exception if something goes wrong */ @Test public void testCancelledOneQueueItemOfTwo() throws Exception { FreeStyleProject project = jenkinsRule.createFreeStyleProject(); FreeStyleProject project2 = jenkinsRule.createFreeStyleProject(); PatchsetCreated event = Setup.createPatchsetCreated(); final GerritCause gerritCause = new GerritCause(event, false); ToGerritRunListener runListener = ToGerritRunListener.getInstance(); runListener.onTriggered(project, event); runListener.onTriggered(project2, event); project.scheduleBuild2(QUIET_PERIOD, gerritCause); QueueTaskFuture<FreeStyleBuild> future2 = project2.scheduleBuild2(QUIET_PERIOD, gerritCause); Item item = waitForBlockedItem(project, TIMEOUT_SECONDS); Queue queue = jenkinsRule.getInstance().getQueue(); queue.doCancelItem(item.getId()); FreeStyleBuild build = future2.get(); assertThat(queue.isEmpty(), equalTo(true)); assertThat(project.getBuilds().size(), equalTo(0)); assertThat(project2.getBuilds().size(), equalTo(1)); assertThat(runListener.isBuilding(event), equalTo(false)); }
@Issue("JENKINS-50561") @Test public void rateLimitBuilds() throws Exception { WorkflowRun b = expect("rateLimitBuilds") .go(); WorkflowJob p = b.getParent(); RateLimitBranchProperty.JobPropertyImpl prop = p.getProperty(RateLimitBranchProperty.JobPropertyImpl.class); assertNotNull(prop); assertEquals(1, prop.getCount()); assertEquals("day", prop.getDurationName()); assertFalse(prop.isUserBoost()); QueueTaskFuture<WorkflowRun> inQueue = p.scheduleBuild2(0); while (!Queue.getInstance().contains(p)) { Thread.yield(); } Queue.getInstance().maintain(); Queue.Item queued = Queue.getInstance().getItem(p); assertThat(queued.isBlocked(), is(true)); assertThat(queued.getCauseOfBlockage().getShortDescription().toLowerCase(), containsString("throttle")); inQueue.cancel(true); }
/** * Tests that event is properly removed if only one project is triggered * which is cancelled while in the queue. * * @throws Exception if something goes wrong */ @Test public void testCancelledQueueItemIsOnlyTriggeredProject() throws Exception { FreeStyleProject project = jenkinsRule.createFreeStyleProject(); PatchsetCreated event = Setup.createPatchsetCreated(); final GerritCause gerritCause = new GerritCause(event, false); ToGerritRunListener runListener = ToGerritRunListener.getInstance(); runListener.onTriggered(project, event); project.scheduleBuild2(QUIET_PERIOD, gerritCause); Item item = waitForBlockedItem(project, TIMEOUT_SECONDS); Queue queue = jenkinsRule.getInstance().getQueue(); queue.doCancelItem(item.getId()); assertThat(queue.isEmpty(), equalTo(true)); assertThat(project.getBuilds().size(), equalTo(0)); assertThat(runListener.isBuilding(event), equalTo(false)); }
@Test public void renameWhileComputing() throws Exception { CoordinatedComputedFolder d = r.jenkins.createProject(CoordinatedComputedFolder.class, "d"); d.kids.addAll(Arrays.asList("A", "B")); QueueTaskFuture<Queue.Executable> future = d.scheduleBuild2(0).getFuture(); future.waitForStart(); try { d.checkRename("d2"); fail("Should be blocked while computation is in progress"); } catch (Failure f) { assertThat(f.getMessage(), is(Messages.ComputedFolder_ComputationInProgress())); } d.onKid("B"); future.get(); waitUntilNoActivityIgnoringThreadDeathUpTo(10000); d.checkRename("d2"); }