فهرست منبع

AMBARI-9629. General issues on Recommendations/Validations functionality (alexantonenko)

Alex Antonenko 10 سال پیش
والد
کامیت
73416b6a7b

+ 19 - 12
ambari-web/app/controllers/wizard/step5_controller.js

@@ -161,6 +161,12 @@ App.WizardStep5Controller = Em.Controller.extend(App.BlueprintMixin, {
    */
   generalWarningMessages: [],
 
+  /**
+   * Is masters-hosts layout initial one
+   * @type {bool}
+   */
+  isInitialLayout: true,
+
   /**
    * true if any error exists
    */
@@ -243,32 +249,33 @@ App.WizardStep5Controller = Em.Controller.extend(App.BlueprintMixin, {
    * @metohd updateIsSubmitDisabled
    */
   updateIsSubmitDisabled: function () {
-    var self = this;
 
-    if (self.thereIsNoMasters()) {
+    if (this.thereIsNoMasters()) {
       return false;
     }
 
-    if (this.get('useServerValidation')) {
-      self.set('submitDisabled', true);
+    var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
 
-      // reset previous recommendations
-      this.clearRecommendations();
+    if (this.get('useServerValidation')) {
+      this.set('submitDisabled', true);
 
-      if (self.get('servicesMasters').length === 0) {
+      if (this.get('servicesMasters').length === 0) {
         return;
       }
 
-      var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
       if (!isSubmitDisabled) {
-        self.recommendAndValidate();
+        if (!this.get('isInitialLayout')) {
+          this.clearRecommendations(); // reset previous recommendations
+        } else {
+          this.set('isInitialLayout', false);
+        }
+        this.recommendAndValidate();
       }
     } else {
-      var isSubmitDisabled = this.get('servicesMasters').someProperty('isHostNameValid', false);
-      self.set('submitDisabled', isSubmitDisabled);
+      this.set('submitDisabled', isSubmitDisabled);
       return isSubmitDisabled;
     }
-  }.observes('servicesMasters.@each.selectedHost', 'servicesMasters.@each.isHostNameValid'),
+  }.observes('servicesMasters.@each.selectedHost'),
 
   /**
    * Send AJAX request to validate current host layout

+ 2 - 0
ambari-web/app/routes/add_service_routes.js

@@ -128,8 +128,10 @@ module.exports = App.WizardRoute.extend({
     connectOutlets: function (router) {
       console.log('in addService.step2:connectOutlets');
       var controller = router.get('addServiceController');
+      var wizardStep2Controller = router.get('wizardStep5Controller');
       controller.setCurrentStep('2');
       controller.set('hideBackButton', false);
+      wizardStep2Controller.set('isInitialLayout', true);
       controller.dataLoading().done(function () {
         controller.loadAllPriorSteps().done(function () {
           controller.connectOutlet('wizardStep5', controller.get('content'));

+ 5 - 1
ambari-web/app/routes/installer.js

@@ -263,7 +263,11 @@ module.exports = Em.Route.extend({
       router.setNavigationFlow('step5');
 
       var controller = router.get('installerController');
-      router.get('wizardStep5Controller').set('servicesMasters', []);
+      var wizardStep5Controller = router.get('wizardStep5Controller');
+      wizardStep5Controller.setProperties({
+        servicesMasters: [],
+        isInitialLayout: true
+      });
       controller.setCurrentStep('5');
       controller.loadAllPriorSteps().done(function () {
         controller.connectOutlet('wizardStep5', controller.get('content'));

+ 47 - 0
ambari-web/test/controllers/wizard/step5_test.js

@@ -843,10 +843,44 @@ describe('App.WizardStep5Controller', function () {
 
   describe('#updateIsSubmitDisabled', function () {
 
+    var clearCases = [
+      {
+        isHostNameValid: true,
+        isInitialLayout: true,
+        isInitialLayoutResulting: false,
+        clearRecommendationsCallCount: 0,
+        recommendAndValidateCallCount: 1,
+        title: 'initial masters-hosts layout'
+      },
+      {
+        isHostNameValid: true,
+        isInitialLayout: false,
+        isInitialLayoutResulting: false,
+        clearRecommendationsCallCount: 1,
+        recommendAndValidateCallCount: 1,
+        title: 'master-hosts layout changed'
+      },
+      {
+        isHostNameValid: false,
+        isInitialLayout: false,
+        isInitialLayoutResulting: false,
+        clearRecommendationsCallCount: 0,
+        recommendAndValidateCallCount: 0,
+        title: 'invalid host name specified'
+      }
+    ];
+
     beforeEach(function () {
       c.set('selectedServicesMasters', [
         {isInstalled: false}
       ]);
+      sinon.stub(c, 'clearRecommendations', Em.K);
+      sinon.stub(c, 'recommendAndValidate', Em.K);
+    });
+
+    afterEach(function () {
+      c.clearRecommendations.restore();
+      c.recommendAndValidate.restore();
     });
 
     it('shouldn\'t change submitDisabled if thereIsNoMasters returns false', function () {
@@ -879,6 +913,19 @@ describe('App.WizardStep5Controller', function () {
 
     });
 
+    clearCases.forEach(function (item) {
+      it(item.title, function () {
+        c.setProperties({
+          isInitialLayout: item.isInitialLayout,
+          servicesMasters: [{
+            isHostNameValid: item.isHostNameValid
+          }]
+        });
+        expect(c.get('isInitialLayout')).to.equal(item.isInitialLayoutResulting);
+        expect(c.clearRecommendations.callCount).to.equal(item.clearRecommendationsCallCount);
+        expect(c.recommendAndValidate.callCount).to.equal(item.recommendAndValidateCallCount);
+      });
+    });
 
   });