diff --git a/core/src/main/java/hudson/model/AbstractCIBase.java b/core/src/main/java/hudson/model/AbstractCIBase.java index 21249a77d792f3e69c320213cdcf801a85686aa3..69328fa4c963a1eb2ac675021516f047b5c8f947 100644 --- a/core/src/main/java/hudson/model/AbstractCIBase.java +++ b/core/src/main/java/hudson/model/AbstractCIBase.java @@ -140,6 +140,7 @@ public abstract class AbstractCIBase extends Node implements ItemGroup e : computers.entrySet()) { if (e.getValue() == computer) { computers.remove(e.getKey()); + computer.onRemoved(); return; } } diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index 32bee752b2e56e38043c0ff9386cc994ed800fb2..51113870a681da5cea7f8e4f13eb7c1f2c5d9509 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -663,11 +663,26 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces /** * Called by {@link Jenkins#updateComputerList()} to notify {@link Computer} that it will be discarded. + * + * @see #onRemoved() */ protected void kill() { setNumExecutors(0); } + /** + * Called by {@link Jenkins} when this computer is removed. + * + * This happens when list of nodes are updated (for example by {@link Jenkins#setNodes(List)} and + * the computer becomes redundant. Such {@link Computer}s get {@linkplain #kill() killed}, then + * after all its executors are finished, this method is called. + * + * @see #kill() + * @since 1.510 + */ + protected void onRemoved(){ + } + private synchronized void setNumExecutors(int n) { if(numExecutors==n) return; // no-op @@ -1076,8 +1091,8 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces offlineMessage = Util.fixEmptyAndTrim(offlineMessage); setTemporarilyOffline(true, OfflineCause.create(hudson.slaves.Messages._SlaveComputer_DisconnectedBy( - Jenkins.getAuthentication().getName(), - offlineMessage!=null ? " : " + offlineMessage : ""))); + Jenkins.getAuthentication().getName(), + offlineMessage != null ? " : " + offlineMessage : ""))); return HttpResponses.redirectToDot(); }