Repository: ambari Updated Branches: refs/heads/trunk c19b78966 -> 6065783b1
AMBARI-7932. UI fix Slider View: Verify using slider-client if application name can be used (Max Shepel via alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/16aa7da6 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/16aa7da6 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/16aa7da6 Branch: refs/heads/trunk Commit: 16aa7da623e1b923af879f4a5d6a6fac0be41950 Parents: c19b789 Author: Alex Antonenko <[email protected]> Authored: Thu Oct 23 21:13:21 2014 +0300 Committer: Alex Antonenko <[email protected]> Committed: Thu Oct 23 22:55:13 2014 +0300 ---------------------------------------------------------------------- .../createAppWizard/step1_controller.js | 53 ++++++++++++++++++-- .../src/main/resources/ui/app/helpers/ajax.js | 11 ++++ .../src/main/resources/ui/app/translations.js | 1 + .../createAppWizard/step1_controller_test.js | 28 +++++++++++ 4 files changed, 90 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/16aa7da6/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js index 0aa9893..0a59916 100644 --- a/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js +++ b/contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js @@ -16,7 +16,7 @@ * limitations under the License. */ -App.CreateAppWizardStep1Controller = Ember.Controller.extend({ +App.CreateAppWizardStep1Controller = Ember.Controller.extend(App.AjaxErrorHandler, { needs: "createAppWizard", @@ -136,6 +136,46 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend({ }.observes('newApp.name'), /** + * Proceed if app name has passed server validation + * @method {validateAppNameSuccessCallback} + */ + validateAppNameSuccessCallback: function () { + var self = this; + Em.run(function () { + self.saveApp(); + self.get('appWizardController').nextStep(); + }); + }, + + /** + * Proceed if app name has failed server validation + * @method {validateAppNameSuccessCallback} + */ + validateAppNameErrorCallback: function (request, ajaxOptions, error, opt, params) { + if (request.status == 409) { + var self = this; + Bootstrap.ModalManager.open( + 'app-name-conflict', + Em.I18n.t('common.error'), + Em.View.extend({ + template: Em.Handlebars.compile('<div class="alert alert-danger">' + + Em.I18n.t('wizard.step1.validateAppNameError').format(params.name) + '</div>') + }), + [ + Ember.Object.create({ + title: Em.I18n.t('ok'), + dismiss: 'modal', + type: 'success' + }) + ], + self + ); + } else { + this.defaultErrorHandler(request, opt.url, opt.type, true); + } + }, + + /** * Save new application data to wizard controller * @method saveApp */ @@ -149,8 +189,15 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend({ actions: { submit: function () { - this.saveApp(); - this.get('appWizardController').nextStep(); + return App.ajax.send({ + name: 'validateAppName', + sender: this, + data: { + name: this.get('newApp.name') + }, + success: 'validateAppNameSuccessCallback', + error: 'validateAppNameErrorCallback' + }); } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/16aa7da6/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js index 3738ea0..ed9575b 100644 --- a/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js +++ b/contrib/views/slider/src/main/resources/ui/app/helpers/ajax.js @@ -149,6 +149,17 @@ var urls = { } }, + 'validateAppName': { + real: 'apps?validateAppName={name}', + mock: '/data/resource/empty_json.json', + format: function () { + return { + dataType: 'text', + showErrorPopup: true + } + } + }, + 'createNewApp': { real: 'apps', mock: '/data/resource/empty_json.json', http://git-wip-us.apache.org/repos/asf/ambari/blob/16aa7da6/contrib/views/slider/src/main/resources/ui/app/translations.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/app/translations.js b/contrib/views/slider/src/main/resources/ui/app/translations.js index 54b5d51..15ccb36 100644 --- a/contrib/views/slider/src/main/resources/ui/app/translations.js +++ b/contrib/views/slider/src/main/resources/ui/app/translations.js @@ -142,6 +142,7 @@ Em.I18n.translations = { 'wizard.step1.typeDescription': 'Deploys {0} cluster on YARN.', 'wizard.step1.nameFormatError': 'App Name should consist only of letters, numbers, \'-\', \'_\' and first character should be a letter.', 'wizard.step1.nameRepeatError': 'App with entered Name already exists.', + 'wizard.step1.validateAppNameError': 'Application with name \'{0}\' already exists', 'wizard.step1.noAppTypesError': 'No Slider Application packages have been installed on this server. Please contact your Ambari server administrator to install Slider Application packages into /var/lib/ambari-server/resources/apps/ folder and restart Ambari server.', 'wizard.step2.name': 'Allocate Resources', 'wizard.step2.header': ' application requires resources to be allocated on the cluster. Provide resource allocation requests for each component of the application below.', http://git-wip-us.apache.org/repos/asf/ambari/blob/16aa7da6/contrib/views/slider/src/main/resources/ui/test/unit/controllers/createAppWizard/step1_controller_test.js ---------------------------------------------------------------------- diff --git a/contrib/views/slider/src/main/resources/ui/test/unit/controllers/createAppWizard/step1_controller_test.js b/contrib/views/slider/src/main/resources/ui/test/unit/controllers/createAppWizard/step1_controller_test.js index fef00be..aea7585 100644 --- a/contrib/views/slider/src/main/resources/ui/test/unit/controllers/createAppWizard/step1_controller_test.js +++ b/contrib/views/slider/src/main/resources/ui/test/unit/controllers/createAppWizard/step1_controller_test.js @@ -75,4 +75,32 @@ test('nameValidator', function() { equal(controller.get('isNameError'), true, 'Name `slider2` already exist'); equal(controller.get('nameErrorMessage'), Em.I18n.t('wizard.step1.nameRepeatError'), 'Error message should be shown'); +}); + +test('validateAppNameSuccessCallback', function () { + + var selectedType = Em.Object.create({ + id: 'HBASE', + configs: { + n0: 'v0' + } + }), + title = 'newApp should have {0} set'; + + var controller = this.subject({ + newApp: Em.Object.create(), + selectedType: selectedType + }); + + Em.run(function () { + controller.set('appWizardController.transitionToRoute', Em.K); + controller.validateAppNameSuccessCallback(); + }); + + deepEqual(controller.get('newApp.appType'), selectedType, title.format('appType')); + deepEqual(controller.get('newApp.configs'), selectedType.configs, title.format('configs')); + deepEqual(controller.get('newApp.predefinedConfigNames'), Em.keys(selectedType.configs), title.format('predefinedConfigNames')); + deepEqual(controller.get('appWizardController.newApp'), controller.get('newApp'), 'newApp should be set in CreateAppWizardController'); + equal(controller.get('appWizardController.currentStep'), 2, 'should proceed to the next step'); + }); \ No newline at end of file
