From fe9b035b2db257a891cce09561756031db763628 Mon Sep 17 00:00:00 2001 From: mindless Date: Sun, 7 Jun 2009 17:29:03 +0000 Subject: [PATCH] [FIXED HUDSON-2110] Improved validation and help text regarding when number of executors setting may be zero. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18731 71c3de6d-444a-0410-be80-ed276b4c234a --- core/src/main/java/hudson/model/Hudson.java | 4 ++++ core/src/main/java/hudson/model/Slave.java | 2 +- core/src/main/java/hudson/util/FormValidation.java | 13 +++++++++++++ .../main/resources/hudson/model/Messages.properties | 1 + .../hudson/model/Node/help-numExecutors.html | 5 +++-- 5 files changed, 22 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/Hudson.java b/core/src/main/java/hudson/model/Hudson.java index 2fcc327bd3..e126a00d54 100644 --- a/core/src/main/java/hudson/model/Hudson.java +++ b/core/src/main/java/hudson/model/Hudson.java @@ -1423,6 +1423,10 @@ public final class Hudson extends Node implements ItemGroup, Stapl return false; } + public FormValidation doCheckNumExecutors(@QueryParameter String value) { + return FormValidation.validateNonNegativeInteger(value); + } + // to route /descriptor/FQCN/xxx to getDescriptor(FQCN).xxx public Object getDynamic(String token) { return Hudson.getInstance().getDescriptor(token); diff --git a/core/src/main/java/hudson/model/Slave.java b/core/src/main/java/hudson/model/Slave.java index f563dde984..b50fa00f95 100644 --- a/core/src/main/java/hudson/model/Slave.java +++ b/core/src/main/java/hudson/model/Slave.java @@ -427,7 +427,7 @@ public abstract class Slave extends Node implements Serializable { public static abstract class SlaveDescriptor extends NodeDescriptor { public FormValidation doCheckNumExecutors(@QueryParameter String value) { - return FormValidation.validateNonNegativeInteger(value); + return FormValidation.validatePositiveInteger(value); } /** diff --git a/core/src/main/java/hudson/util/FormValidation.java b/core/src/main/java/hudson/util/FormValidation.java index c0bd3c4dc5..1fdbd833c7 100644 --- a/core/src/main/java/hudson/util/FormValidation.java +++ b/core/src/main/java/hudson/util/FormValidation.java @@ -299,6 +299,19 @@ public abstract class FormValidation extends IOException implements HttpResponse public static FormValidation validateNonNegativeInteger(String value) { try { if(Integer.parseInt(value)<0) + return error(hudson.model.Messages.Hudson_NotANonNegativeNumber()); + return ok(); + } catch (NumberFormatException e) { + return error(hudson.model.Messages.Hudson_NotANumber()); + } + } + + /** + * Makes sure that the given string is a positive integer. + */ + public static FormValidation validatePositiveInteger(String value) { + try { + if(Integer.parseInt(value)<=0) return error(hudson.model.Messages.Hudson_NotAPositiveNumber()); return ok(); } catch (NumberFormatException e) { diff --git a/core/src/main/resources/hudson/model/Messages.properties b/core/src/main/resources/hudson/model/Messages.properties index 42f7d61d86..16c531f0c9 100644 --- a/core/src/main/resources/hudson/model/Messages.properties +++ b/core/src/main/resources/hudson/model/Messages.properties @@ -88,6 +88,7 @@ Hudson.ViewAlreadyExists=A view already exists with the name "{0}" Hudson.ViewName=All Hudson.NotANumber=Not a number Hudson.NotAPositiveNumber=Not a positive number +Hudson.NotANonNegativeNumber=Number may not be negative Hudson.NotANegativeNumber=Not a negative number Hudson.NotUsesUTF8ToDecodeURL=\ Your container doesn''t use UTF-8 to decode URLs. If you use non-ASCII characters as a job name etc, \ diff --git a/core/src/main/resources/hudson/model/Node/help-numExecutors.html b/core/src/main/resources/hudson/model/Node/help-numExecutors.html index 4c8fe55c47..7e30307f29 100644 --- a/core/src/main/resources/hudson/model/Node/help-numExecutors.html +++ b/core/src/main/resources/hudson/model/Node/help-numExecutors.html @@ -10,5 +10,6 @@

When using Hudson in the master/slave mode, setting this value to 0 would prevent the master - to do any build on its own. - \ No newline at end of file + from doing any building on its own. Slaves may not have zero executors, but may be + temporarily disabled using the button on the slave's status page. + -- GitLab