AMBARI-23801 Unable to add Hive Metastore from Host detail Page. (ababiichuk)
authorababiichuk <ababiichuk@hortonworks.com>
Fri, 11 May 2018 12:00:15 +0000 (15:00 +0300)
committeraBabiichuk <ababiichuk@hortonworks.com>
Fri, 11 May 2018 13:15:49 +0000 (16:15 +0300)
ambari-web/app/controllers/main/host/details.js
ambari-web/test/controllers/main/host/details_test.js

index 72a0010..b517e61 100644 (file)
@@ -1159,20 +1159,16 @@ App.MainHostDetailsController = Em.Controller.extend(App.SupportClientConfigsDow
    * @method loadWebHCatConfigs
    */
   loadWebHCatConfigs: function (data, opt, params) {
-    var request = App.ajax.send({
-      name: 'admin.get.all_configurations',
-      sender: this,
-      data: {
-        webHCat: true,
-        urlParams: [
-          '(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')',
-          '(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')',
-          '(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag + ')',
-          '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')'
-        ].join('|')
-      },
-      success: params.callback
-    });
+    const urlParams = this.getUrlParamsForConfigsRequest(data, ['hive-site', 'webhcat-site', 'hive-env', 'core-site']),
+      request = App.ajax.send({
+        name: 'admin.get.all_configurations',
+        sender: this,
+        data: {
+          webHCat: true,
+          urlParams
+        },
+        success: params.callback
+      });
     this.trackRequest(request);
     return request;
   },
@@ -1185,19 +1181,15 @@ App.MainHostDetailsController = Em.Controller.extend(App.SupportClientConfigsDow
    * @method loadHiveConfigs
    */
   loadHiveConfigs: function (data, opt, params) {
-    var request = App.ajax.send({
-      name: 'admin.get.all_configurations',
-      sender: this,
-      data: {
-        urlParams: [
-          '(type=hive-site&tag=' + data.Clusters.desired_configs['hive-site'].tag + ')',
-          '(type=webhcat-site&tag=' + data.Clusters.desired_configs['webhcat-site'].tag + ')',
-          '(type=hive-env&tag=' + data.Clusters.desired_configs['hive-env'].tag + ')',
-          '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')'
-        ].join('|')
-      },
-      success: params.callback
-    });
+    const urlParams = this.getUrlParamsForConfigsRequest(data, ['hive-site', 'webhcat-site', 'hive-env', 'core-site']),
+      request = App.ajax.send({
+        name: 'admin.get.all_configurations',
+        sender: this,
+        data: {
+          urlParams
+        },
+        success: params.callback
+      });
     this.trackRequest(request);
     return request;
   },
@@ -1406,17 +1398,15 @@ App.MainHostDetailsController = Em.Controller.extend(App.SupportClientConfigsDow
    * @method loadRangerConfigs
    */
   loadRangerConfigs: function (data, opt, params) {
-    var request = App.ajax.send({
-      name: 'admin.get.all_configurations',
-      sender: this,
-      data: {
-        urlParams: '(type=core-site&tag=' + data.Clusters.desired_configs['core-site'].tag + ')|' +
-        '(type=hdfs-site&tag=' + data.Clusters.desired_configs['hdfs-site'].tag + ')|' +
-        '(type=kms-env&tag=' + data.Clusters.desired_configs['kms-env'].tag + ')|' +
-        '(type=kms-site&tag=' + data.Clusters.desired_configs['kms-site'].tag + ')'
-      },
-      success: params.callback
-    });
+    const urlParams = this.getUrlParamsForConfigsRequest(data, ['core-site', 'hdfs-site', 'kms-env', 'kms-site']),
+      request = App.ajax.send({
+        name: 'admin.get.all_configurations',
+        sender: this,
+        data: {
+          urlParams
+        },
+        success: params.callback
+      });
     this.trackRequest(request);
   },
 
@@ -3232,4 +3222,17 @@ App.MainHostDetailsController = Em.Controller.extend(App.SupportClientConfigsDow
     App.showAlertPopup(Em.I18n.t('common.error'), Em.I18n.t('alerts.notifications.regenerateKeytab.host.error').format(this.content.get('hostName')));
   },
 
+  /**
+   * Returns URL parameters for configs request by certain tags
+   * @param {object} data - object with desired configs tags received from API
+   * @param {string[]} configTypes - list of config types
+   * @returns {string}
+   */
+  getUrlParamsForConfigsRequest: function (data, configTypes) {
+    return configTypes.map(type => {
+      const tag = Em.get(data, `Clusters.desired_configs.${type}.tag`);
+      return tag ? `(type=${type}&tag=${tag})` : null;
+    }).compact().join('|');
+  }
+
 });
index 2d6056e..845c811 100644 (file)
@@ -4362,4 +4362,80 @@ describe('App.MainHostDetailsController', function () {
       expect(controller.get('hdfsUser')).to.be.equal('val')
     });
   });
+
+  describe('#getUrlParamsForConfigsRequest', function () {
+    var cases = [
+      {
+        data: {
+          Clusters: {
+            desired_configs: {
+              't0-site': {
+                tag: 'v0'
+              },
+              't0-env': {
+                tag: 'v1'
+              },
+              't0-log4j': {
+                tag: 'v2'
+              },
+              't2-site': {
+                tag: 'v3'
+              }
+            }
+          }
+        },
+        types: ['t0-site', 't0-env', 't0-log4j', 't1-site'],
+        result: '(type=t0-site&tag=v0)|(type=t0-env&tag=v1)|(type=t0-log4j&tag=v2)',
+        title: 'several types available'
+      },
+      {
+        data: {
+          Clusters: {
+            desired_configs: {
+              't1-site': {
+                tag: 'v4'
+              },
+              't2-env': {
+                tag: 'v5'
+              },
+              't2-log4j': {
+                tag: 'v6'
+              }
+            }
+          }
+        },
+        types: ['t1-site', 't1-env', 't1-log4j'],
+        result: '(type=t1-site&tag=v4)',
+        title: 'single type available'
+      },
+      {
+        data: {
+          Clusters: {
+            desired_configs: {
+              't3-site': {
+                tag: 'v7'
+              },
+              't3-env': {
+                tag: 'v8'
+              },
+              't3-log4j': {
+                tag: 'v9'
+              }
+            }
+          }
+        },
+        types: ['t2-site', 't2-env', 't2-log4j'],
+        result: '',
+        title: 'no types available'
+      }
+    ];
+
+    cases.forEach(function (test) {
+      describe(test.title, function () {
+        it('should return ' + test.result, function () {
+          expect(controller.getUrlParamsForConfigsRequest(test.data, test.types)).to.equal(test.result);
+        });
+      });
+    });
+  });
 });