@@ -1107,7 +1107,7 @@ private String validateConfigurationValue(final String name, String value, final
11071107 Class <?> type = null ;
11081108 final Config configuration = Config .getConfig (name );
11091109 if (configuration == null ) {
1110- s_logger .warn (String . format ( "Configuration [%s] could not be found in Config.java. Perhaps moved to ConfigDepot." , name ) );
1110+ s_logger .warn ("Did not find configuration " + name + " in Config.java. Perhaps moved to ConfigDepot" );
11111111 final ConfigKey <?> configKey = _configDepot .get (name );
11121112 if (configKey == null ) {
11131113 s_logger .warn (String .format ("Configuration [%s] could not be found in ConfigDepot." ));
@@ -1224,7 +1224,7 @@ private String validateConfigurationValue(final String name, String value, final
12241224 }
12251225 }
12261226
1227- if (configuration == null ) {
1227+ if (configuration == null ) {
12281228 //range validation has to be done per case basis, for now
12291229 //return in case of Configkey parameters
12301230 return null ;
@@ -1246,35 +1246,29 @@ private String validateConfigurationValue(final String name, String value, final
12461246 protected String validateIfIntValueIsInRange (String name , String value , String range ) {
12471247 final String [] options = range .split ("-" );
12481248 if (options .length != 2 ) {
1249- final String msg = String .format ("Configuration range [%1$ s] for [%2$ s] is invalid." , range , name );
1249+ String msg = String .format ("Configuration range [%s] for [%s] is invalid." , range , name );
12501250 s_logger .error (msg );
12511251 return msg ;
12521252 }
12531253 final int min = Integer .parseInt (options [0 ]);
12541254 final int max = Integer .parseInt (options [1 ]);
12551255 final int val = Integer .parseInt (value );
12561256 if (val < min || val > max ) {
1257- s_logger .error (String .format ("Configuration value for [%s] is invalid . Please enter a value in the range: [%s]." , name , range ));
1258- return String .format ("Please enter a value in the range: [%s]. " , range );
1257+ s_logger .error (String .format ("Invalid value for configuration [%s]. Please enter a value in the range [%s]." , name , range ));
1258+ return String .format ("The provided value is not valid for this configuration. Please enter an integer in the range: [%s]" , range );
12591259 }
12601260 return null ;
12611261 }
12621262
12631263
12641264 private String validateIfStringValueIsInRange (String name , String value , String ... range ) {
1265- String message = "" ;
1265+ List < String > message = new ArrayList < String >() ;
12661266 String errMessage = "" ;
12671267 for (String rangeOption : range ) {
1268- if (StringUtils .isNotBlank (message )) {
1269- message = String .format ("%s|| " , message );
1270- }
12711268 switch (rangeOption ) {
12721269 case "privateip" :
12731270 errMessage = validateRangePrivateIp (name , value );
12741271 break ;
1275- case "netmask" :
1276- errMessage = validateRangeNetmask (name , value );
1277- break ;
12781272 case "hypervisorList" :
12791273 errMessage = validateRangeHypervisorList (value );
12801274 break ;
@@ -1284,45 +1278,41 @@ private String validateIfStringValueIsInRange(String name, String value, String.
12841278 case "domainName" :
12851279 errMessage = validateRangeDomainName (value );
12861280 break ;
1287- case "routes" :
1288- errMessage = validateRangeRoutes (value );
1289- break ;
12901281 default :
12911282 errMessage = validateRangeOther (name , value , rangeOption );
12921283 }
1293- if (errMessage == null ) {
1284+ if (StringUtils . isEmpty ( errMessage ) ) {
12941285 return null ;
12951286 }
1296- message = String . format ( "%1$s%2$s" , message , errMessage );
1287+ message . add ( errMessage );
12971288 }
1298- return message ;
1289+ if (message .size () == 1 ) {
1290+ return String .format ("The provided value is not %s." , message .get (0 ));
1291+ }
1292+ return String .format ("The provided value is neither %s." , String .join (" NOR " , message ));
12991293 }
13001294
13011295 protected String validateRangePrivateIp (String name , String value ) {
13021296 try {
13031297 if (NetUtils .isSiteLocalAddress (value )) {
13041298 return null ;
13051299 }
1306- s_logger .error (String .format ("The private IP range [%1$ s] is not a site local address for the configuration variable [%2$ s]." , value , name ));
1300+ s_logger .error (String .format ("Value [% s] is not a valid private IP range for configuration [% s]." , value , name ));
13071301 } catch (final NullPointerException e ) {
13081302 s_logger .error (String .format ("Error while parsing IP address for [%s]." , name ));
13091303 }
1310- return "Please enter a site local IP address." ;
1311- }
1312-
1313- protected String validateRangeNetmask (String name , String value ) {
1314- if (NetUtils .isValidIp4Netmask (value )) {
1315- return null ;
1316- }
1317- s_logger .error (String .format ("Netmask [%1$s] is not a valid netmask for configuration variable [%2$s]." , value , name ));
1318- return "Please enter a valid netmask." ;
1304+ return "a valid site local IP address" ;
13191305 }
13201306
1307+ /**
1308+ * Valid values are XenServer, KVM, VMware, Hyperv, VirtualBox, Parralels, BareMetal, Simulator, Ovm, Ovm3, LXC
1309+ * Inputting "Any" will return the hypervisor type Any, other inputs will result in the hypervisor type none. Both of these are invalid values and will return an error message.
1310+ */
13211311 protected String validateRangeHypervisorList (String value ) {
13221312 final String [] hypervisors = value .split ("," );
13231313 for (final String hypervisor : hypervisors ) {
13241314 if (HypervisorType .getType (hypervisor ) == HypervisorType .Any || HypervisorType .getType (hypervisor ) == HypervisorType .None ) {
1325- return String . format ( "Please enter a valid hypervisor type." ) ;
1315+ return " a valid hypervisor type" ;
13261316 }
13271317 }
13281318 return null ;
@@ -1332,46 +1322,36 @@ protected String validateRangeInstanceName(String value) {
13321322 if (NetUtils .verifyInstanceName (value )) {
13331323 return null ;
13341324 }
1335- return "Instance name can not contain hyphen, space or plus sign. " ;
1325+ return "a valid instance name (instance names cannot contain hyphen, space or plus sign) " ;
13361326 }
13371327
1328+ /**
1329+ * max length for FQDN is 253 + 2, code adds xxx-xxx-xxx-xxx to domain name when creating URL.
1330+ * If it starts with "*.", these two symbols are ignored and do not count towards the character limit.
1331+ */
13381332 protected String validateRangeDomainName (String value ) {
13391333 String domainName = value ;
13401334 if (value .startsWith ("*" )) {
13411335 domainName = value .substring (2 ); //skip the "*."
13421336 }
1343- //max length for FQDN is 253 + 2, code adds xxx-xxx-xxx-xxx to domain name when creating URL
13441337 if (domainName .length () >= 238 || !domainName .matches (DOMAIN_NAME_PATTERN )) {
1345- return "Please enter a valid string for domain name, prefixed with '*.' if applicable. " ;
1338+ return "a valid domain name" ;
13461339 }
13471340 return null ;
13481341 }
13491342
1350- protected String validateRangeRoutes (String value ) {
1351- final String [] routes = value .split ("," );
1352- String message = "" ;
1353- for (final String route : routes ) {
1354- final String routeToVerify = route .trim ();
1355- if (!NetUtils .isValidIp4Cidr (routeToVerify )) {
1356- message = String .format ("%1$sInvalid value for route: route [%2$s] is in the deny list. Valid format is a list of CIDRs separated by comma. Example: 10.1.1.0/24,192.168.0.0/24." , message , route );
1357- } else {
1358- return null ;
1359- }
1360- }
1361- return message ;
1362- }
1363-
13641343 protected String validateRangeOther (String name , String value , String rangeOption ) {
13651344 final String [] options = rangeOption .split ("," );
13661345 for (final String option : options ) {
13671346 if (option .trim ().equalsIgnoreCase (value )) {
13681347 return null ;
13691348 }
13701349 }
1371- s_logger .error (String .format ("Configuration value for [%s] is invalid ." , name ));
1372- return String .format ("Invalid value, please enter [%s]. " , rangeOption );
1350+ s_logger .error (String .format ("Invalid value for configuration [%s]." , name ));
1351+ return String .format ("a valid value for this configuration (Options are: [%s]) " , rangeOption );
13731352 }
13741353
1354+
13751355 private boolean podHasAllocatedPrivateIPs (final long podId ) {
13761356 final HostPodVO pod = _podDao .findById (podId );
13771357 final int count = _privateIpAddressDao .countIPs (podId , pod .getDataCenterId (), true );
0 commit comments