Ver código fonte

AMBARI-12405. Host value not saved when going back in RM HA wizard (onechiporenko)

Oleg Nechiporenko 10 anos atrás
pai
commit
798357d81e

+ 0 - 25
ambari-web/app/controllers/main/admin/highAvailability/nameNode/wizard_controller.js

@@ -81,31 +81,6 @@ App.HighAvailabilityWizardController = App.WizardController.extend({
     this.save('cluster');
     this.save('cluster');
   },
   },
 
 
-  /**
-   * Save Master Component Hosts data to Main Controller
-   * @param stepController App.WizardStep5Controller
-   */
-  saveMasterComponentHosts: function (stepController) {
-    var obj = stepController.get('selectedServicesMasters');
-    var masterComponentHosts = [];
-    obj.forEach(function (_component) {
-      masterComponentHosts.push({
-        display_name: _component.get('display_name'),
-        component: _component.get('component_name'),
-        hostName: _component.get('selectedHost'),
-        serviceId: _component.get('serviceId'),
-        isInstalled:  _component.get('isInstalled')
-      });
-    });
-    this.setDBProperty('masterComponentHosts', masterComponentHosts);
-    this.set('content.masterComponentHosts', masterComponentHosts);
-  },
-
-  clearMasterComponentHosts: function() {
-    this.set('content.masterComponentHosts', null);
-    this.setDBProperty('masterComponentHosts', null);
-  },
-
   saveHdfsUser: function () {
   saveHdfsUser: function () {
     App.db.setHighAvailabilityWizardHdfsUser(this.get('content.hdfsUser'));
     App.db.setHighAvailabilityWizardHdfsUser(this.get('content.hdfsUser'));
   },
   },

+ 1 - 0
ambari-web/app/controllers/main/service/reassign_controller.js

@@ -184,6 +184,7 @@ App.ReassignMasterController = App.WizardController.extend({
     });
     });
     App.db.setMasterComponentHosts(masterComponentHosts);
     App.db.setMasterComponentHosts(masterComponentHosts);
     this.set('content.masterComponentHosts', masterComponentHosts);
     this.set('content.masterComponentHosts', masterComponentHosts);
+    this.setDBProperty('masterComponentHosts', masterComponentHosts);
   },
   },
 
 
   loadComponentToReassign: function () {
   loadComponentToReassign: function () {

+ 26 - 0
ambari-web/app/controllers/wizard.js

@@ -1078,6 +1078,32 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM
     }
     }
     this.set("content.masterComponentHosts", masterComponentHosts);
     this.set("content.masterComponentHosts", masterComponentHosts);
   },
   },
+
+  /**
+   * Save Master Component Hosts data to Main Controller
+   * @param stepController App.WizardStep5Controller
+   */
+  saveMasterComponentHosts: function (stepController) {
+    var obj = stepController.get('selectedServicesMasters');
+    var masterComponentHosts = [];
+    obj.forEach(function (_component) {
+      masterComponentHosts.push({
+        display_name: _component.get('display_name'),
+        component: _component.get('component_name'),
+        hostName: _component.get('selectedHost'),
+        serviceId: _component.get('serviceId'),
+        isInstalled:  _component.get('isInstalled')
+      });
+    });
+    this.setDBProperty('masterComponentHosts', masterComponentHosts);
+    this.set('content.masterComponentHosts', masterComponentHosts);
+  },
+
+  clearMasterComponentHosts: function() {
+    this.set('content.masterComponentHosts', null);
+    this.setDBProperty('masterComponentHosts', null);
+  },
+
   /**
   /**
    * Load information about hosts with clients components
    * Load information about hosts with clients components
    */
    */

+ 13 - 7
ambari-web/app/mixins/wizard/assign_master_components.js

@@ -537,8 +537,8 @@ App.AssignMasterComponents = Em.Mixin.create({
       var mastersLength = this.get("selectedServicesMasters").filterProperty("component_name", componentName).length;
       var mastersLength = this.get("selectedServicesMasters").filterProperty("component_name", componentName).length;
       if (mastersLength < this.getMaxNumberOfMasters(componentName)) {
       if (mastersLength < this.getMaxNumberOfMasters(componentName)) {
         component.set('showAddControl', true);
         component.set('showAddControl', true);
-      } else if (mastersLength == 1) {
-        component.set('showRemoveControl', false);
+      } else {
+        component.set('showRemoveControl', mastersLength != 1);
       }
       }
     }
     }
   },
   },
@@ -797,16 +797,22 @@ App.AssignMasterComponents = Em.Mixin.create({
    * @returns {masterComponents[]}
    * @returns {masterComponents[]}
    */
    */
   addNewMasters: function (masterComponents) {
   addNewMasters: function (masterComponents) {
-    this.get('mastersToAdd').forEach(function(masterName){
-      var hostName = this.getHostForMaster(masterName, masterComponents);
-      var serviceName = this.getServiceByMaster(masterName);
-      masterComponents.push(this.createComponentInstallationObject(
+    this.get('mastersToAdd').forEach(function (masterName, index, mastersToAdd) {
+      var toBeAddedNumber = mastersToAdd.filter(function (name) {
+          return name === masterName;
+        }).length,
+        alreadyAddedNumber = masterComponents.filterProperty('component_name', masterName).rejectProperty('isInstalled').length;
+      if (toBeAddedNumber > alreadyAddedNumber) {
+        var hostName = this.getHostForMaster(masterName, masterComponents),
+          serviceName = this.getServiceByMaster(masterName);
+        masterComponents.push(this.createComponentInstallationObject(
           Em.Object.create({
           Em.Object.create({
             componentName: masterName,
             componentName: masterName,
             serviceName: serviceName
             serviceName: serviceName
           }),
           }),
           hostName
           hostName
-      ));
+        ));
+      }
     }, this);
     }, this);
     return masterComponents;
     return masterComponents;
   },
   },

+ 1 - 4
ambari-web/app/routes/high_availability_routes.js

@@ -124,16 +124,13 @@ module.exports = App.WizardRoute.extend({
     next: function (router) {
     next: function (router) {
       var controller = router.get('highAvailabilityWizardController');
       var controller = router.get('highAvailabilityWizardController');
       controller.saveNameServiceId(router.get('highAvailabilityWizardStep1Controller.content.nameServiceId'));
       controller.saveNameServiceId(router.get('highAvailabilityWizardStep1Controller.content.nameServiceId'));
+      controller.clearMasterComponentHosts();
       router.transitionTo('step2');
       router.transitionTo('step2');
     }
     }
   }),
   }),
 
 
   step2: Em.Route.extend({
   step2: Em.Route.extend({
     route: '/step2',
     route: '/step2',
-    enter: function(router) {
-      var controller = router.get('highAvailabilityWizardController');
-      controller.clearMasterComponentHosts();
-    },
     connectOutlets: function (router) {
     connectOutlets: function (router) {
       var controller = router.get('highAvailabilityWizardController');
       var controller = router.get('highAvailabilityWizardController');
       controller.dataLoading().done(function () {
       controller.dataLoading().done(function () {

+ 4 - 1
ambari-web/app/routes/ra_high_availability_routes.js

@@ -109,7 +109,9 @@ module.exports = App.WizardRoute.extend({
       });
       });
     },
     },
     next: function (router) {
     next: function (router) {
-      router.get('rAHighAvailabilityWizardController').save('loadBalancerURL');
+      var controller = router.get('rAHighAvailabilityWizardController');
+      controller.save('loadBalancerURL');
+      controller.clearMasterComponentHosts();
       router.transitionTo('step2');
       router.transitionTo('step2');
     }
     }
   }),
   }),
@@ -136,6 +138,7 @@ module.exports = App.WizardRoute.extend({
       };
       };
       wizardController.set('content.raHosts', raHosts);
       wizardController.set('content.raHosts', raHosts);
       wizardController.save('raHosts');
       wizardController.save('raHosts');
+      wizardController.saveMasterComponentHosts(stepController);
       router.transitionTo('step3');
       router.transitionTo('step3');
     },
     },
     back: function (router) {
     back: function (router) {

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

@@ -127,7 +127,9 @@ module.exports = App.WizardRoute.extend({
       })
       })
     },
     },
     next: function (router) {
     next: function (router) {
+      var controller = router.get('reassignMasterController');
       App.db.setMasterComponentHosts(undefined);
       App.db.setMasterComponentHosts(undefined);
+      controller.clearMasterComponentHosts();
       router.transitionTo('step2');
       router.transitionTo('step2');
     },
     },
 
 

+ 4 - 1
ambari-web/app/routes/rm_high_availability_routes.js

@@ -110,7 +110,9 @@ module.exports = App.WizardRoute.extend({
       return false;
       return false;
     },
     },
     next: function (router) {
     next: function (router) {
-      router.get('rMHighAvailabilityWizardController').setDBProperty('rmHosts', undefined);
+      var controller = router.get('rMHighAvailabilityWizardController');
+      controller.setDBProperty('rmHosts', undefined);
+      controller.clearMasterComponentHosts();
       router.transitionTo('step2');
       router.transitionTo('step2');
     }
     }
   }),
   }),
@@ -138,6 +140,7 @@ module.exports = App.WizardRoute.extend({
         additionalRM: additionalRM.get('selectedHost')
         additionalRM: additionalRM.get('selectedHost')
       };
       };
       wizardController.saveRmHosts(rmHost);
       wizardController.saveRmHosts(rmHost);
+      wizardController.saveMasterComponentHosts(stepController);
       router.transitionTo('step3');
       router.transitionTo('step3');
     },
     },
     back: function (router) {
     back: function (router) {

+ 61 - 2
ambari-web/test/controllers/main/service/reassign_controller_test.js

@@ -23,14 +23,73 @@ require('controllers/main/service/reassign_controller');
 
 
 describe('App.ReassignMasterController', function () {
 describe('App.ReassignMasterController', function () {
 
 
-  var reassignMasterController = App.ReassignMasterController.create({});
+  var reassignMasterController;
+
+  beforeEach(function () {
+    reassignMasterController = App.ReassignMasterController.create({});
+  });
 
 
   describe('#totalSteps', function () {
   describe('#totalSteps', function () {
     it('check', function () {
     it('check', function () {
       expect(reassignMasterController.get('totalSteps')).to.equal(7);
       expect(reassignMasterController.get('totalSteps')).to.equal(7);
+      reassignMasterController.set('content.reassign', {service_id:null});
     });
     });
   });
   });
 
 
-  reassignMasterController.set('content.reassign', {service_id:null});
+  describe('#saveMasterComponentHosts', function () {
+
+    var stepController = Em.Object.create({
+        selectedServicesMasters: [
+          Em.Object.create({
+            display_name: 'd0',
+            component_name: 'c0',
+            selectedHost: 'h0',
+            serviceId: 's0'
+          }),
+          Em.Object.create({
+            display_name: 'd1',
+            component_name: 'c1',
+            selectedHost: 'h1',
+            serviceId: 's1'
+          })
+        ]
+      }),
+      masterComponentHosts = [
+        {
+          display_name: 'd0',
+          component: 'c0',
+          hostName: 'h0',
+          serviceId: 's0',
+          isInstalled: true
+        },
+        {
+          display_name: 'd1',
+          component: 'c1',
+          hostName: 'h1',
+          serviceId: 's1',
+          isInstalled: true
+        }
+      ];
+
+    beforeEach(function () {
+      sinon.stub(App.db, 'setMasterComponentHosts', Em.K);
+      sinon.stub(reassignMasterController, 'setDBProperty', Em.K);
+    });
+
+    afterEach(function () {
+      App.db.setMasterComponentHosts.restore();
+      reassignMasterController.setDBProperty.restore();
+    });
+
+    it('should save master component hosts', function () {
+      reassignMasterController.saveMasterComponentHosts(stepController);
+      expect(App.db.setMasterComponentHosts.calledOnce).to.be.true;
+      expect(reassignMasterController.setDBProperty.calledOnce).to.be.true;
+      expect(App.db.setMasterComponentHosts.calledWith(masterComponentHosts)).to.be.true;
+      expect(reassignMasterController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
+      expect(reassignMasterController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
+    });
+
+  });
 
 
 });
 });

+ 75 - 0
ambari-web/test/controllers/wizard_test.js

@@ -1387,4 +1387,79 @@ describe('App.WizardController', function () {
     });
     });
   });
   });
 
 
+  describe('#saveMasterComponentHosts', function () {
+
+    var stepController = Em.Object.create({
+        selectedServicesMasters: [
+          Em.Object.create({
+            display_name: 'd0',
+            component_name: 'c0',
+            selectedHost: 'h0',
+            serviceId: 's0',
+            isInstalled: true
+          }),
+          Em.Object.create({
+            display_name: 'd1',
+            component_name: 'c1',
+            selectedHost: 'h1',
+            serviceId: 's1',
+            isInstalled: false
+          })
+        ]
+      }),
+      masterComponentHosts = [
+        {
+          display_name: 'd0',
+          component: 'c0',
+          hostName: 'h0',
+          serviceId: 's0',
+          isInstalled: true
+        },
+        {
+          display_name: 'd1',
+          component: 'c1',
+          hostName: 'h1',
+          serviceId: 's1',
+          isInstalled: false
+        }
+      ];
+
+    beforeEach(function () {
+      sinon.stub(wizardController, 'setDBProperty', Em.K);
+    });
+
+    afterEach(function () {
+      wizardController.setDBProperty.restore();
+    });
+
+    it('should save master component hosts', function () {
+      wizardController.saveMasterComponentHosts(stepController);
+      expect(wizardController.setDBProperty.calledOnce).to.be.true;
+      expect(wizardController.setDBProperty.calledWith('masterComponentHosts', masterComponentHosts)).to.be.true;
+      expect(wizardController.get('content.masterComponentHosts')).to.eql(masterComponentHosts);
+    });
+
+  });
+
+  describe('#clearMasterComponentHosts', function () {
+
+    beforeEach(function () {
+      sinon.stub(wizardController, 'setDBProperty', Em.K);
+    });
+
+    afterEach(function () {
+      wizardController.setDBProperty.restore();
+    });
+
+    it('should clear master component hosts', function () {
+      wizardController.set('content.masterComponentHosts', {});
+      wizardController.clearMasterComponentHosts();
+      expect(wizardController.setDBProperty.calledOnce).to.be.true;
+      expect(wizardController.setDBProperty.calledWith('masterComponentHosts', null)).to.be.true;
+      expect(wizardController.get('content.masterComponentHosts')).to.be.null;
+    });
+
+  });
+
+
 });
 });