You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sr...@apache.org on 2014/01/20 19:40:08 UTC
git commit: AMBARI-4340. 'Trigger Restart' button is active if was
entered invalid data. (srimanth)
Updated Branches:
refs/heads/trunk 0edf889df -> 2949ce171
AMBARI-4340. 'Trigger Restart' button is active if was entered invalid data. (srimanth)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2949ce17
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2949ce17
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2949ce17
Branch: refs/heads/trunk
Commit: 2949ce171da6f280f19cb0d33f56b529a1923e10
Parents: 0edf889
Author: Srimanth Gunturi <sg...@hortonworks.com>
Authored: Fri Jan 17 14:54:14 2014 -0800
Committer: Srimanth Gunturi <sg...@hortonworks.com>
Committed: Mon Jan 20 10:40:00 2014 -0800
----------------------------------------------------------------------
ambari-web/app/messages.js | 14 ++++++----
ambari-web/app/utils/number_utils.js | 29 ++++++++++++++++++++
.../app/views/common/rolling_restart_view.js | 22 +++++++--------
3 files changed, 47 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/2949ce17/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index 1b11a06..fefaa33 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -1785,12 +1785,9 @@ Em.I18n.translations = {
'rollingrestart.dialog.msg.timegap.suffix': 'seconds between batches ',
'rollingrestart.dialog.msg.toleration.prefix': 'Tolerate up to ',
'rollingrestart.dialog.msg.toleration.suffix': 'failures',
- 'rollingrestart.dialog.err.empty.batchsize': 'Restart batch size cannot be empty',
- 'rollingrestart.dialog.err.empty.waittime': 'Wait interval cannot be empty',
- 'rollingrestart.dialog.err.empty.tolerate': 'Failure toleration size cannot be empty',
- 'rollingrestart.dialog.err.invalid.batchsize': 'Restart batch size should be between 1 and {0}',
- 'rollingrestart.dialog.err.invalid.waitTime': 'Wait time cannot be negative',
- 'rollingrestart.dialog.err.invalid.toleratesize': 'Failure toleration cannot be negative',
+ 'rollingrestart.dialog.err.invalid.batchsize': 'Invalid restart batch size: {0}',
+ 'rollingrestart.dialog.err.invalid.waitTime': 'Invalid wait time between batches: {0}',
+ 'rollingrestart.dialog.err.invalid.toleratesize': 'Invalid failure toleration count: {0}',
'rollingrestart.dialog.msg.staleConfigsOnly': 'Only restart {0}s with stale configs',
'rollingrestart.rest.context': 'Rolling Restart of {0}s - batch {1} of {2}',
@@ -1809,6 +1806,11 @@ Em.I18n.translations = {
'menu.item.jobs':'Jobs',
'menu.item.admin':'Admin',
+ 'number.validate.empty': 'cannot be empty',
+ 'number.validate.notValidNumber': 'not a valid number',
+ 'number.validate.lessThanMinumum': 'value less than {0}',
+ 'number.validate.moreThanMaximum': 'value greater than {0}',
+
'common.combobox.placeholder': 'Filter...',
'common.combobox.dropdown.1': 'Overridden properties',
//'common.combobox.dropdown.2': 'Modified properties',
http://git-wip-us.apache.org/repos/asf/ambari/blob/2949ce17/ambari-web/app/utils/number_utils.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/number_utils.js b/ambari-web/app/utils/number_utils.js
index 3101417..c201e52 100644
--- a/ambari-web/app/utils/number_utils.js
+++ b/ambari-web/app/utils/number_utils.js
@@ -52,5 +52,34 @@ module.exports = {
var parsedValue = window[parseType](value);
return parsedValue.toFixed(precision) + " " + sizes[posttxt];
}
+ },
+
+ /**
+ * Validates if the given string or number is an integer between the
+ * values of min and max (inclusive). The minimum and maximum
+ * checks are ignored if their valid is NaN.
+ */
+ validateInteger : function(str, min, max) {
+ if (!str || (str + "").trim().length < 1) {
+ return Em.I18n.t('number.validate.empty');
+ } else {
+ str = (str + "").trim();
+ var number = parseInt(str);
+ if (isNaN(number)) {
+ return Em.I18n.t('number.validate.notValidNumber');
+ } else {
+ if (str.length != (number + "").length) {
+ // parseInt("1abc") returns 1 as integer
+ return Em.I18n.t('number.validate.notValidNumber');
+ }
+ if (!isNaN(min) && number < min) {
+ return Em.I18n.t('number.validate.lessThanMinumum').format(min);
+ }
+ if (!isNaN(max) && number > max) {
+ return Em.I18n.t('number.validate.moreThanMaximum').format(max);
+ }
+ }
+ }
+ return null;
}
};
http://git-wip-us.apache.org/repos/asf/ambari/blob/2949ce17/ambari-web/app/views/common/rolling_restart_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/common/rolling_restart_view.js b/ambari-web/app/views/common/rolling_restart_view.js
index 2671ddd..1ca6066 100644
--- a/ambari-web/app/views/common/rolling_restart_view.js
+++ b/ambari-web/app/views/common/rolling_restart_view.js
@@ -16,6 +16,7 @@
*/
var App = require('app');
+var numberUtils = require('utils/number_utils');
/**
* View content of the rolling restart dialog.
@@ -53,21 +54,18 @@ App.RollingRestartView = Em.View.extend({
if (totalCount < 1) {
errors.push(Em.I18n.t('rollingrestart.dialog.msg.noRestartHosts').format(displayName));
} else {
- if (!bs) {
- errors.push(Em.I18n.t('rollingrestart.dialog.err.empty.batchsize'));
- } else if (bs > totalCount || bs < 0) {
- errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.batchsize').format(totalCount));
+ var bsError = numberUtils.validateInteger(bs, 1, totalCount);
+ var tsError = numberUtils.validateInteger(ts, 0, totalCount);
+ if (bsError != null) {
+ errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.batchsize').format(bsError));
}
- if (!ts) {
- errors.push(Em.I18n.t('rollingrestart.dialog.err.empty.waittime'));
- } else if (ts < 0) {
- errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.toleratesize'));
+ if (tsError != null) {
+ errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.toleratesize').format(tsError));
}
}
- if (!wait) {
- errors.push(Em.I18n.t('rollingrestart.dialog.err.empty.tolerate'));
- } else if (wait < 0) {
- errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.waitTime'));
+ var waitError = numberUtils.validateInteger(wait, 0, NaN);
+ if (waitError != null) {
+ errors.push(Em.I18n.t('rollingrestart.dialog.err.invalid.waitTime').format(waitError));
}
if (errors.length < 1) {
errors = null;