From f07fb85352b7cce0b6acaa39bfac4773c7608e5a Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Fri, 17 Oct 2014 09:38:32 +0100 Subject: [PATCH] Allow Node and RetentionStrategy to contribute to Computer#isAcceptingTasks --- core/src/main/java/hudson/model/Computer.java | 8 +++++++- core/src/main/java/hudson/model/Node.java | 13 +++++++++++++ .../main/java/hudson/slaves/RetentionStrategy.java | 13 +++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/hudson/model/Computer.java b/core/src/main/java/hudson/model/Computer.java index ce3efaba3a..fff4a7765e 100644 --- a/core/src/main/java/hudson/model/Computer.java +++ b/core/src/main/java/hudson/model/Computer.java @@ -24,6 +24,8 @@ */ package hudson.model; +import edu.umd.cs.findbugs.annotations.OverrideMustInvoke; +import edu.umd.cs.findbugs.annotations.When; import hudson.EnvVars; import hudson.Launcher.ProcStarter; import hudson.Util; @@ -1318,9 +1320,13 @@ public /*transient*/ abstract class Computer extends Actionable implements Acces * scheduling that does not overlap with being offline. * * @return {@code true} if the computer is accepting tasks + * @see hudson.slaves.RetentionStrategy#isAcceptingTasks(Computer) + * @see hudson.model.Node#isAcceptingTasks() */ + @OverrideMustInvoke(When.ANYTIME) public boolean isAcceptingTasks() { - return true; + final Node node = getNode(); + return getRetentionStrategy().isAcceptingTasks(this) && (node == null || node.isAcceptingTasks()); } /** diff --git a/core/src/main/java/hudson/model/Node.java b/core/src/main/java/hudson/model/Node.java index f5f9f04b59..ff73a2fb9d 100644 --- a/core/src/main/java/hudson/model/Node.java +++ b/core/src/main/java/hudson/model/Node.java @@ -194,6 +194,19 @@ public abstract class Node extends AbstractModelObject implements Reconfigurable */ protected abstract Computer createComputer(); + /** + * Returns {@code true} if the node is accepting tasks. Needed to allow slaves programmatic suspension of task + * scheduling that does not overlap with being offline. Called by {@link Computer#isAcceptingTasks()}. + * This method is distinct from {@link Computer#isAcceptingTasks()} as sometimes the {@link Node} concrete + * class may not have control over the {@link hudson.model.Computer} concrete class associated with it. + * + * @return {@code true} if the node is accepting tasks. + * @see Computer#isAcceptingTasks() + */ + public boolean isAcceptingTasks() { + return true; + } + /** * Let Nodes be aware of the lifecycle of their own {@link Computer}. */ diff --git a/core/src/main/java/hudson/slaves/RetentionStrategy.java b/core/src/main/java/hudson/slaves/RetentionStrategy.java index 95cb99b375..474afa45a1 100644 --- a/core/src/main/java/hudson/slaves/RetentionStrategy.java +++ b/core/src/main/java/hudson/slaves/RetentionStrategy.java @@ -67,6 +67,19 @@ public abstract class RetentionStrategy extends AbstractDesc return true; } + /** + * Returns {@code true} if the computer is accepting tasks. Needed to allow retention strategies programmatic + * suspension of task scheduling that in preparation for going offline. Called by + * {@link hudson.model.Computer#isAcceptingTasks()} + * + * @param c the computer. + * @return {@code true} if the computer is accepting tasks + * @see hudson.model.Computer#isAcceptingTasks() + */ + public boolean isAcceptingTasks(T c) { + return true; + } + /** * Called when a new {@link Computer} object is introduced (such as when Hudson started, or when * a new slave is added.)