private @CheckForNull String running(@Nonnull Executor e) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof Run) { Run<?,?> run = (Run) exec; for (BuildTriggerAction.Trigger trigger : BuildTriggerAction.triggersFor(run)) { if (trigger.context.equals(getContext())) { return "running " + run; } } } return null; }
private static boolean maybeInterrupt(Executor e, Throwable cause, StepContext context) { boolean interrupted = false; Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof Run) { for (BuildTriggerAction.Trigger trigger : BuildTriggerAction.triggersFor((Run) exec)) { if (trigger.context.equals(context)) { e.interrupt(Result.ABORTED, new BuildTriggerCancelledCause(cause)); trigger.interruption = cause; try { ((Run) exec).save(); } catch (IOException x) { LOGGER.log(Level.WARNING, "failed to save interrupt cause on " + exec, x); } interrupted = true; } } } return interrupted; }
if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { LOGGER.log(FINE, "Queue item for node block in {0} is still waiting after reload", run); return; for (Executor e : c.getExecutors()) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof PlaceholderTask.PlaceholderExecutable && ((PlaceholderTask.PlaceholderExecutable) exec).getParent().context.equals(getContext())) { LOGGER.log(FINE, "Node block in {0} is running on {1} after reload", new Object[] {run, c.getName()}); return;
if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { LOGGER.log(FINE, "Queue item for node block in {0} is still waiting after reload", run); return; for (Executor e : c.getExecutors()) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof PlaceholderTask.PlaceholderExecutable && ((PlaceholderTask.PlaceholderExecutable) exec).getParent().context.equals(getContext())) { LOGGER.log(FINE, "Node block in {0} is running on {1} after reload", new Object[] {run, c.getName()}); return;
Run<?, ?> run = getContext().get(Run.class); for (Queue.Item item : Queue.getInstance().getItems()) { if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { LOGGER.log(FINE, "Queue item for node block in {0} is still waiting after reload", run); return; for (Executor e : c.getExecutors()) { Queue.Executable exec = e.getCurrentExecutable(); if (exec instanceof PlaceholderTask.PlaceholderExecutable && ((PlaceholderTask.PlaceholderExecutable) exec).getParent().context.equals(getContext())) { LOGGER.log(FINE, "Node block in {0} is running on {1} after reload", new Object[] {run, c.getName()}); return;
@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"; }
@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"; }
@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"; }
@Override public void stop(Throwable cause) throws Exception { for (Queue.Item item : Queue.getInstance().getItems()) { // if we are still in the queue waiting to be scheduled, just retract that if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { Queue.getInstance().cancel(item); break; } } Jenkins j = Jenkins.getInstance(); if (j != null) { // if we are already running, kill the ongoing activities, which releases PlaceholderExecutable from its sleep loop // Similar to Executor.of, but distinct since we do not have the Executable yet: 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())) { PlaceholderTask.finish(((PlaceholderTask.PlaceholderExecutable) exec).getParent().cookie); break COMPUTERS; } } } } // Whether or not either of the above worked (and they would not if for example our item were canceled), make sure we die. super.stop(cause); }
@Override public void stop(Throwable cause) { for (Queue.Item item : Queue.getInstance().getItems()) { // if we are still in the queue waiting to be scheduled, just retract that if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { Queue.getInstance().cancel(item); break; } } Jenkins j = Jenkins.getInstance(); if (j != null) { // if we are already running, kill the ongoing activities, which releases PlaceholderExecutable from its sleep loop // Similar to Executor.of, but distinct since we do not have the Executable yet: 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())) { PlaceholderTask.finish(((PlaceholderTask.PlaceholderExecutable) exec).getParent().cookie); break COMPUTERS; } } } } // Whether or not either of the above worked (and they would not if for example our item were canceled), make sure we die. getContext().onFailure(cause); }
@Override public void stop(Throwable cause) { for (Queue.Item item : Queue.getInstance().getItems()) { // if we are still in the queue waiting to be scheduled, just retract that if (item.task instanceof PlaceholderTask && ((PlaceholderTask) item.task).context.equals(getContext())) { Queue.getInstance().cancel(item); break; } } Jenkins j = Jenkins.getInstance(); if (j != null) { // if we are already running, kill the ongoing activities, which releases PlaceholderExecutable from its sleep loop // Similar to Executor.of, but distinct since we do not have the Executable yet: 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())) { PlaceholderTask.finish(((PlaceholderTask.PlaceholderExecutable) exec).getParent().cookie); break COMPUTERS; } } } } // Whether or not either of the above worked (and they would not if for example our item were canceled), make sure we die. getContext().onFailure(cause); }
@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) {
if (trigger.context.equals(context)) {