浏览代码

AMBARI-13385. Host name properties duplicate after several moving next/back on the step7/step8 (onechiporenko)

Oleg Nechiporenko 9 年之前
父节点
当前提交
15bdb71047

+ 5 - 2
ambari-web/app/controllers/wizard/step7_controller.js

@@ -822,7 +822,7 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
   },
 
   /**
-   * Add host name properties to appropriate categories (for installer only)
+   * Add host name properties to appropriate categories (for installer and add service)
    * @param serviceConfig
    * @param masterComponents
    * @param slaveComponents
@@ -843,7 +843,10 @@ App.WizardStep7Controller = Em.Controller.extend(App.ServerValidatorMixin, App.E
         }
         var stackComponent = App.StackServiceComponent.find(componentName);
         var hProperty = App.config.createHostNameProperty(serviceConfig.get('serviceName'), componentName, value, stackComponent);
-        serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
+        var newConfigName = Em.get(hProperty, 'name');
+        if (!serviceConfig.get('configs').someProperty('name', newConfigName)) {
+          serviceConfig.get('configs').push(App.ServiceConfigProperty.create(hProperty));
+        }
       }
     }, this);
   },

+ 39 - 0
ambari-web/test/controllers/wizard/step7_test.js

@@ -2052,4 +2052,43 @@ describe('App.InstallerStep7Controller', function () {
       });
     });
   });
+
+  describe('#addHostNamesToConfigs', function() {
+
+    beforeEach(function () {
+      sinon.stub(App.StackServiceComponent, 'find', function () {
+        return Em.Object.create({
+          id: 'NAMENODE',
+          displayName: 'NameNode'
+        });
+      });
+    });
+
+    afterEach(function () {
+      App.StackServiceComponent.find.restore();
+    });
+
+    it('should not create duplicate configs', function () {
+      var serviceConfig = Em.Object.create({
+        configs: [],
+        serviceName: 'HDFS',
+        configCategories: [
+          {
+            showHost: true,
+            name: 'NAMENODE'
+          }
+        ]
+      });
+      var masterComponents = [
+        {component: 'NAMENODE', hostName: 'h1'}
+      ];
+      var slaveComponents = [];
+      installerStep7Controller.addHostNamesToConfigs(serviceConfig, masterComponents, slaveComponents);
+      expect(serviceConfig.get('configs').filterProperty('name', 'namenode_host').length).to.equal(1);
+      installerStep7Controller.addHostNamesToConfigs(serviceConfig, masterComponents, slaveComponents);
+      expect(serviceConfig.get('configs').filterProperty('name', 'namenode_host').length).to.equal(1);
+    });
+
+  });
+
 });