@Override @GuardedBy("hudson.model.Queue.lock") public long check(final AbstractCloudComputer c) { final AbstractCloudSlave computerNode = c.getNode(); if (c.isIdle() && !disabled && computerNode != null) { final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds(); if (idleMilliseconds > MINUTES.toMillis(idleMinutes)) { LOGGER.log(Level.INFO, "Disconnecting {0}", c.getName()); try { computerNode.terminate(); } catch (InterruptedException | IOException e) { LOGGER.log(WARNING, "Failed to terminate " + c.getName(), e); } } } return 1; }
/** * Try to connect to it ASAP. */ @Override public void start(AbstractCloudComputer c) { c.connect(false); }
/** * When the agent is deleted, free the node right away. */ @Override @RequirePOST public HttpResponse doDoDelete() throws IOException { checkPermission(DELETE); try { T node = getNode(); if (node != null) { // No need to terminate nodes again node.terminate(); } return new HttpRedirect(".."); } catch (InterruptedException e) { return HttpResponses.error(500,e); } } }
@Override @GuardedBy("hudson.model.Queue.lock") public long check(final AbstractCloudComputer acc) { // When the slave is idle we should disable accepting tasks and check to see if it is already trying to // terminate. If it's not already trying to terminate then lets terminate manually. if (acc.isIdle() && !disabled) { final long idleMilliseconds = System.currentTimeMillis() - acc.getIdleStartMilliseconds(); if (idleMilliseconds > TimeUnit2.MINUTES.toMillis(idleMinutes)) { LOG.debug("Disconnecting {}", acc.getName()); done(acc); } } // Return one because we want to check every minute if idle. return 1; }
protected void done(final AbstractCloudComputer<?> c) { c.setAcceptingTasks(false); // just in case synchronized (this) { if (terminating) { return; } terminating = true; } final Future<?> submit = Computer.threadPoolForRemoting.submit(() -> { try { AbstractCloudSlave node = c.getNode(); if (node != null) { node.terminate(); } } catch (InterruptedException | IOException e) { LOG.warn("Failed to terminate " + c.getName(), e); synchronized (DockerOnceRetentionStrategy.this) { terminating = false; } } } ); }
@Override public void run() { try { AbstractCloudSlave node = computer.getNode(); if (node != null) { node.terminate(); } } catch (InterruptedException e) { LOGGER.log(Level.WARNING, "Failed to terminate " + computer.getName(), e); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to terminate " + computer.getName(), e); } } });
@Override public OpenShiftSlave getNode() { return (OpenShiftSlave) super.getNode(); }
@Override public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems) { super.taskCompletedWithProblems(executor, task, durationMS, problems); LOGGER.log(Level.FINE, " Computer " + this + " taskCompletedWithProblems"); }
@Override public void taskAccepted(Executor executor, Queue.Task task) { super.taskAccepted(executor, task); used = true; }
@Override public void taskCompleted(Executor executor, Queue.Task task, long durationMS) { LOGGER.log(Level.FINE, " Computer " + this + " taskCompleted"); // May take the agent offline and remove it, in which case getNode() // above would return null and we'd not find our DockerSlave anymore. super.taskCompleted(executor, task, durationMS); }
private void terminate(final AbstractCloudComputer<?> computer) { LOGGER.info("Terminating computer: " + computer.getName() ); computer.setAcceptingTasks(false); // just in case Computer.threadPoolForRemoting.submit(new Runnable() { @Override public void run() { try { AbstractCloudSlave node = computer.getNode(); if (node != null) { node.terminate(); } } catch (InterruptedException e) { LOGGER.log(Level.WARNING, "Failed to terminate " + computer.getName(), e); } catch (IOException e) { LOGGER.log(Level.WARNING, "Failed to terminate " + computer.getName(), e); } } }); } }
protected void done(Executor executor) { final AbstractCloudComputer<?> c = (AbstractCloudComputer) executor.getOwner(); Queue.Executable exec = executor.getCurrentExecutable(); if (executor instanceof OneOffExecutor) { LOG.debug("Not terminating {} because {} was a flyweight task", c.getName(), exec); return; } if (exec instanceof ContinuableExecutable && ((ContinuableExecutable) exec).willContinue()) { LOG.debug("not terminating {} because {} says it will be continued", c.getName(), exec); return; } LOG.debug("terminating {} since {} seems to be finished", c.getName(), exec); done(c); }
@Override public @CheckForNull JCloudsSlave getNode() { return super.getNode(); }
@Override public void taskCompletedWithProblems(Executor executor, Queue.Task task, long durationMS, Throwable problems) { super.taskCompletedWithProblems(executor, task, durationMS, problems); LOGGER.log(Level.FINE, "[{0}]: taskCompletedWithProblems", this); }
@Override public void taskAccepted(Executor executor, Queue.Task task) { super.taskAccepted(executor, task); LOGGER.fine(" Computer " + this + " taskAccepted"); }
@Override public void taskCompleted(Executor executor, Queue.Task task, long durationMS) { super.taskCompleted(executor, task, durationMS); LOGGER.log(Level.FINE, "[{0}]: taskCompleted", this); }
@Override public String toString() { return MoreObjects.toStringHelper(this) .add("name", super.getName()) .add("slave", getNode()) .toString(); }
public synchronized long check(AbstractCloudComputer c) { if (c.isIdle() && !disabled) { final long idleMilliseconds = System.currentTimeMillis() - c.getIdleStartMilliseconds(); if (idleMilliseconds > MINUTES.toMillis(idleMinutes)) { LOGGER.info("Disconnecting "+c.getName()); try { c.getNode().terminate(); } catch (InterruptedException e) { LOGGER.log(WARNING,"Failed to terminate "+c.getName(),e); } catch (IOException e) { LOGGER.log(WARNING,"Failed to terminate "+c.getName(),e); } } } return 1; }
/** * When the slave is deleted, free the node. */ @Override public HttpResponse doDoDelete() throws IOException { checkPermission(DELETE); try { getNode().terminate(); return new HttpRedirect(".."); } catch (InterruptedException e) { return HttpResponses.error(500,e); } } }
@Override public void start(AbstractCloudComputer c) { if (c.getNode() instanceof EphemeralNode) { throw new IllegalStateException("May not use OnceRetentionStrategy on an EphemeralNode: " + c); } super.start(c); }