You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by yu...@apache.org on 2013/06/13 19:14:11 UTC
svn commit: r1492768 - in /incubator/ambari/trunk/ambari-web:
app/controllers/wizard/step2_controller.js app/messages.js
app/utils/validator.js test/installer/step2_test.js test/utils/misc_test.js
test/utils/string_utils_test.js
Author: yusaku
Date: Thu Jun 13 17:14:10 2013
New Revision: 1492768
URL: http://svn.apache.org/r1492768
Log:
AMBARI-2376. Install Options page: add warnings for invalid hostnames or IP addresses. (Oleg Nechiporenko via yusaku)
Modified:
incubator/ambari/trunk/ambari-web/app/controllers/wizard/step2_controller.js
incubator/ambari/trunk/ambari-web/app/messages.js
incubator/ambari/trunk/ambari-web/app/utils/validator.js
incubator/ambari/trunk/ambari-web/test/installer/step2_test.js
incubator/ambari/trunk/ambari-web/test/utils/misc_test.js
incubator/ambari/trunk/ambari-web/test/utils/string_utils_test.js
Modified: incubator/ambari/trunk/ambari-web/app/controllers/wizard/step2_controller.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/controllers/wizard/step2_controller.js?rev=1492768&r1=1492767&r2=1492768&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/controllers/wizard/step2_controller.js (original)
+++ incubator/ambari/trunk/ambari-web/app/controllers/wizard/step2_controller.js Thu Jun 13 17:14:10 2013
@@ -52,10 +52,7 @@ App.WizardStep2Controller = Em.Controlle
}.property('manualInstall'),
isHostNameValid: function (hostname) {
- // disabling hostname validation as we don't want to be too restrictive and disallow
- // user's hostnames
- // return validator.isHostname(hostname) && (!(/^\-/.test(hostname) || /\-$/.test(hostname)));
- return true;
+ return validator.isHostname(hostname);
},
/**
* set not installed hosts to the hostNameArr
@@ -75,20 +72,23 @@ App.WizardStep2Controller = Em.Controlle
}
this.set('hostNameArr', tempArr);
},
+
+ invalidHostNames: [],
+
/**
* validate host names
* @return {Boolean}
*/
isAllHostNamesValid: function () {
- var self = this;
var result = true;
this.updateHostNameArr();
-
+ this.get('invalidHostNames').clear();
this.hostNameArr.forEach(function(hostName){
- if (!self.isHostNameValid(hostName)) {
+ if (!this.isHostNameValid(hostName)) {
+ this.get('invalidHostNames').push(hostName);
result = false;
}
- });
+ }, this);
return result;
},
@@ -102,12 +102,7 @@ App.WizardStep2Controller = Em.Controlle
this.set('hostsError', Em.I18n.t('installer.step2.hostName.error.required'));
}
else {
- if (this.isAllHostNamesValid() === false) {
- this.set('hostsError', Em.I18n.t('installer.step2.hostName.error.invalid'));
- }
- else {
- this.set('hostsError', null);
- }
+ this.set('hostsError', null);
}
},
@@ -236,7 +231,12 @@ App.WizardStep2Controller = Em.Controlle
* and save already registered hosts
* @return {Boolean}
*/
- proceedNext: function(){
+ proceedNext: function(warningConfirmed){
+ if (this.isAllHostNamesValid() !== true && !warningConfirmed) {
+ this.warningPopup();
+ return false;
+ }
+
if (this.get('manualInstall') === true) {
this.manualInstallPopup();
return false;
@@ -260,6 +260,23 @@ App.WizardStep2Controller = Em.Controlle
},
/**
+ * show warning for host names without dots or IP addresses
+ */
+ warningPopup: function () {
+ var self = this;
+ App.ModalPopup.show({
+ header: Em.I18n.t('common.warning'),
+ onPrimary: function () {
+ this.hide();
+ self.proceedNext(true);
+ },
+ bodyClass: Ember.View.extend({
+ template: Ember.Handlebars.compile(Em.I18n.t('installer.step2.warning.popup.body').format(self.get('invalidHostNames').join(', ')))
+ })
+ });
+ },
+
+ /**
* show popup with the list of hosts that are already part of the cluster
*/
installedHostsPopup: function () {
Modified: incubator/ambari/trunk/ambari-web/app/messages.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/messages.js?rev=1492768&r1=1492767&r2=1492768&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/messages.js (original)
+++ incubator/ambari/trunk/ambari-web/app/messages.js Thu Jun 13 17:14:10 2013
@@ -286,6 +286,7 @@ Em.I18n.translations = {
'installer.step2.manualInstall.tooltip.content':'Manually registering the Ambari Agent on each host eliminates the need for SSH and should be performed prior to continuing cluster installation.',
'installer.step2.manualInstall.popup.header':'Before You Proceed',
'installer.step2.manualInstall.popup.body':'You must install Ambari Agents on each host you want to manage before you proceed.',
+ 'installer.step2.warning.popup.body':'<p>The following hostnames are not valid FQDNs:</p><p> {0} </p><p>This may cause problems during installation. Do you want to continue?</p>',
'installer.step2.orUse':'Or use',
'installer.step2.registerAndConfirm':'Register and Confirm',
'installer.step2.evaluateStep.installedHosts':'These hosts are already installed on the cluster and will be ignored:',
Modified: incubator/ambari/trunk/ambari-web/app/utils/validator.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/app/utils/validator.js?rev=1492768&r1=1492767&r2=1492768&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/app/utils/validator.js (original)
+++ incubator/ambari/trunk/ambari-web/app/utils/validator.js Thu Jun 13 17:14:10 2013
@@ -72,7 +72,7 @@ module.exports = {
* @return {Boolean}
*/
isHostname: function(value) {
- var regex = /^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])$/;
+ var regex = /(?=^.{3,254}$)(^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*(\.[a-zA-Z]{1,62})$)/;
return regex.test(value);
},
Modified: incubator/ambari/trunk/ambari-web/test/installer/step2_test.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/installer/step2_test.js?rev=1492768&r1=1492767&r2=1492768&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/installer/step2_test.js (original)
+++ incubator/ambari/trunk/ambari-web/test/installer/step2_test.js Thu Jun 13 17:14:10 2013
@@ -49,14 +49,25 @@ describe('App.WizardStep2Controller', fu
});
it('should return true if all host names are valid', function(){
- controller.set('hostNames', 'amache ambari');
+ controller.set('hostNames', 'amache.org ambari.com');
expect(controller.isAllHostNamesValid()).to.equal(true);
})
- /*it('should return false if there is invalid host names', function(){
- controller.set('hostNames', 'amache #@$ ambari');
- expect(controller.isAllHostNamesValid()).to.equal(false);
- })*/
+ var tests = [
+ 'hostname',
+ '-hostname.com',
+ 'hostname-.com',
+ 'host_name.com',
+ '123.123.123.123',
+ 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname',
+ 'hostnamehostnamehostnamehostnamehostnamehostnamehostnamehostnamehostname.hostname'
+ ];
+ tests.forEach(function (test) {
+ it('should return false for invalid host names ' + test + ' ', function () {
+ controller.set('hostNames', test);
+ expect(controller.isAllHostNamesValid()).to.equal(false);
+ });
+ });
})
describe('#checkHostError()', function () {
@@ -214,12 +225,13 @@ describe('App.WizardStep2Controller', fu
it('should call manualInstallPopup if manualInstall is true', function (done) {
var controller = App.WizardStep2Controller.create({
+ hostNames: '',
manualInstall: true,
manualInstallPopup: function () {
done();
}
});
- controller.proceedNext();
+ controller.proceedNext(true);
})
})
Modified: incubator/ambari/trunk/ambari-web/test/utils/misc_test.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/misc_test.js?rev=1492768&r1=1492767&r2=1492768&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/utils/misc_test.js (original)
+++ incubator/ambari/trunk/ambari-web/test/utils/misc_test.js Thu Jun 13 17:14:10 2013
@@ -41,4 +41,19 @@ describe('misc', function () {
});
});
+ describe('#ipToInt', function () {
+ var tests = [
+ {m:'0.0.0.0 to 0',i:'0.0.0.0',e:0},
+ {m:'255.255.255.255 to 4294967295',i:'255.255.255.255',e:4294967295},
+ {m:'"" to false',i:'',e:false},
+ {m:'255.255.255.256 to false',i:'255.255.255.256',e:false},
+ {m:'255.255.255 to false',i:'255.255.255',e:false}
+ ];
+ tests.forEach(function(test) {
+ it(test.m + ' ', function () {
+ expect(misc.ipToInt(test.i)).to.equal(test.e);
+ });
+ });
+ });
+
});
Modified: incubator/ambari/trunk/ambari-web/test/utils/string_utils_test.js
URL: http://svn.apache.org/viewvc/incubator/ambari/trunk/ambari-web/test/utils/string_utils_test.js?rev=1492768&r1=1492767&r2=1492768&view=diff
==============================================================================
--- incubator/ambari/trunk/ambari-web/test/utils/string_utils_test.js (original)
+++ incubator/ambari/trunk/ambari-web/test/utils/string_utils_test.js Thu Jun 13 17:14:10 2013
@@ -69,4 +69,17 @@ describe('string_utils', function () {
});
});
+ describe('#isSingleLine', function () {
+ var tests = [
+ {m: 'is single line text', t: 'a b', e: true},
+ {m: 'is single line text', t: 'a b\n', e: true},
+ {m: 'is single line text', t: '\na b', e: true},
+ {m: 'is not single line text', t: 'a\nb', e: false}
+ ];
+ tests.forEach(function(test) {
+ it(test.t + ' ' + test.m + ' ', function () {
+ expect(string_utils.isSingleLine(test.t)).to.equal(test.e);
+ });
+ });
+ });
});