Browse Source

AMBARI-7932. UI fix Slider View: Verify using slider-client if application name can be used (Max Shepel via alexantonenko)

Alex Antonenko 10 years ago
parent
commit
16aa7da623

+ 50 - 3
contrib/views/slider/src/main/resources/ui/app/controllers/createAppWizard/step1_controller.js

@@ -16,7 +16,7 @@
  * limitations under the License.
  * limitations under the License.
  */
  */
 
 
-App.CreateAppWizardStep1Controller = Ember.Controller.extend({
+App.CreateAppWizardStep1Controller = Ember.Controller.extend(App.AjaxErrorHandler, {
 
 
   needs: "createAppWizard",
   needs: "createAppWizard",
 
 
@@ -135,6 +135,46 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend({
     return true;
     return true;
   }.observes('newApp.name'),
   }.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
    * Save new application data to wizard controller
    * @method saveApp
    * @method saveApp
@@ -149,8 +189,15 @@ App.CreateAppWizardStep1Controller = Ember.Controller.extend({
 
 
   actions: {
   actions: {
     submit: function () {
     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'
+      });
     }
     }
   }
   }
 });
 });

+ 11 - 0
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': {
   'createNewApp': {
     real: 'apps',
     real: 'apps',
     mock: '/data/resource/empty_json.json',
     mock: '/data/resource/empty_json.json',

+ 1 - 0
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.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.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.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.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.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.',
   'wizard.step2.header': ' application requires resources to be allocated on the cluster. Provide resource allocation requests for each component of the application below.',

+ 28 - 0
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('isNameError'), true, 'Name `slider2` already exist');
   equal(controller.get('nameErrorMessage'), Em.I18n.t('wizard.step1.nameRepeatError'), 'Error message should be shown');
   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');
+
 });
 });