Bläddra i källkod

AMBARI-9148 Adding a Hive metastore creates 3 new versions of configs each time. (atkach)

Andrii Tkach 10 år sedan
förälder
incheckning
261f04b7d0

+ 45 - 25
ambari-web/app/controllers/main/host/details.js

@@ -614,19 +614,44 @@ App.MainHostDetailsController = Em.Controller.extend({
     configs['webhcat-site']['templeton.hive.properties'] = configs['webhcat-site']['templeton.hive.properties'].replace(/thrift.+[0-9]{2,},/i, hiveMSHosts.join('\\,') + ",");
     configs['core-site']['hadoop.proxyuser.' + hiveUser + '.hosts'] = hiveMasterHosts;
     configs['core-site']['hadoop.proxyuser.' + webhcatUser + '.hosts'] = hiveMasterHosts;
+    var groups = [
+      {
+        'hive-site': configs['hive-site'],
+        'webhcat-site': configs['webhcat-site'],
+        'hive-env': configs['hive-env']
+      },
+      {'core-site': configs['core-site']}
+    ];
+    this.saveConfigsBatch(groups);
+  },
 
-    for (var site in configs) {
-      if (!configs.hasOwnProperty(site)) continue;
-      App.ajax.send({
-        name: 'reassign.save_configs',
-        sender: this,
-        data: {
-          siteName: site,
-          properties: configs[site],
-          service_config_version_note: Em.I18n.t('hosts.host.hive.configs.save.note')
-        }
-      });
-    }
+  /**
+   * save configs' sites in batch
+   * @param groups
+   */
+  saveConfigsBatch: function (groups) {
+    groups.forEach(function (configs) {
+      var desiredConfigs = [];
+      var tag = 'version' + (new Date).getTime();
+      for (var site in configs) {
+        if (!configs.hasOwnProperty(site)) continue;
+        desiredConfigs.push({
+          "type": site,
+          "tag": tag,
+          "properties": configs[site],
+          "service_config_version_note": Em.I18n.t('hosts.host.hive.configs.save.note')
+        });
+      }
+      if (desiredConfigs.length > 0) {
+        App.ajax.send({
+          name: 'common.service.configurations',
+          sender: this,
+          data: {
+            desired_config: desiredConfigs
+          }
+        });
+      }
+    }, this);
   },
 
   /**
@@ -782,19 +807,14 @@ App.MainHostDetailsController = Em.Controller.extend({
     var zks = this.getZkServerHosts();
     var zksWithPort = this.concatZkNames(zks);
     this.setZKConfigs(configs, zksWithPort, zks);
-
-    for (var site in configs) {
-      if (!configs.hasOwnProperty(site)) continue;
-      App.ajax.send({
-        name: 'reassign.save_configs',
-        sender: this,
-        data: {
-          siteName: site,
-          properties: configs[site],
-          service_config_version_note: Em.I18n.t('hosts.host.zooKeeper.configs.save.note')
-        }
-      });
-    }
+    var groups = [
+      {
+        'hive-site': configs['hive-site'],
+        'webhcat-site': configs['webhcat-site']
+      },
+      {'yarn-site': configs['yarn-site']}
+    ];
+    this.saveConfigsBatch(groups);
   },
   /**
    *

+ 16 - 23
ambari-web/test/controllers/main/host/details_test.js

@@ -718,41 +718,34 @@ describe('App.MainHostDetailsController', function () {
       sinon.stub(controller, "getZkServerHosts", Em.K);
       sinon.stub(controller, "concatZkNames", Em.K);
       sinon.stub(controller, "setZKConfigs", Em.K);
+      sinon.stub(controller, 'saveConfigsBatch', Em.K);
     });
     afterEach(function () {
       controller.getZkServerHosts.restore();
       controller.concatZkNames.restore();
       controller.setZKConfigs.restore();
+      controller.saveConfigsBatch.restore();
     });
 
-    it('data.items is empty', function () {
+    it('call saveConfigsBatch()', function () {
       var data = {items: []};
       controller.saveZkConfigs(data);
+      expect(controller.saveConfigsBatch.calledOnce).to.be.true;
+    });
+  });
+
+  describe("#saveConfigsBatch()", function() {
+    it("no groups", function() {
+      controller.saveConfigsBatch([]);
       expect(App.ajax.send.called).to.be.false;
     });
-    it('data.items has one item', function () {
-      var data = {items: [
-        {
-          type: 'type1',
-          properties: {}
-        }
-      ]};
-      controller.saveZkConfigs(data);
-      expect(App.ajax.send.calledOnce).to.be.true;
+    it("configs is empty", function() {
+      controller.saveConfigsBatch([{}]);
+      expect(App.ajax.send.called).to.be.false;
     });
-    it('data.items has two items', function () {
-      var data = {items: [
-        {
-          type: 'type1',
-          properties: {}
-        },
-        {
-          type: 'type2',
-          properties: {}
-        }
-      ]};
-      controller.saveZkConfigs(data);
-      expect(App.ajax.send.calledTwice).to.be.true;
+    it("configs is correct", function() {
+      controller.saveConfigsBatch([{'site': {}}]);
+      expect(App.ajax.send.calledOnce).to.be.true;
     });
   });