浏览代码

AMBARI-15257. Query Editor Hosts Fix for Grafana. (Prajwal Rao via yusaku)

Yusaku Sako 9 年之前
父节点
当前提交
19e29fd4da

+ 16 - 3
ambari-metrics/ambari-metrics-grafana/ambari-metrics/datasource.js

@@ -295,15 +295,28 @@ define([
          *
          *
          * Query Hosts on the cluster.
          * Query Hosts on the cluster.
          */
          */
-        AmbariMetricsDatasource.prototype.suggestHosts = function (query) {
+        AmbariMetricsDatasource.prototype.suggestHosts = function (query, app) {
           console.log(query);
           console.log(query);
           return this.doAmbariRequest({method: 'GET', url: '/ws/v1/timeline/metrics/hosts'})
           return this.doAmbariRequest({method: 'GET', url: '/ws/v1/timeline/metrics/hosts'})
             .then(function (results) {
             .then(function (results) {
+              var compToHostMap = {};
               //Remove fakehostname from the list of hosts on the cluster.
               //Remove fakehostname from the list of hosts on the cluster.
               var fake = "fakehostname"; delete results.data[fake];
               var fake = "fakehostname"; delete results.data[fake];
-              return _.map(Object.keys(results.data), function (hostName) {
-                return {text: hostName};
+              //Query hosts based on component name
+              _.forEach(results.data, function (comp, hostName) {
+                comp.forEach(function (component) {
+                  if (!compToHostMap[component]){
+                    compToHostMap[component] = [];
+                  }
+                  compToHostMap[component].push(hostName);
+                });
+              });
+              var compHosts = compToHostMap[app];
+              compHosts = _.map(compHosts, function (h) {
+                return {text: h};
               });
               });
+              compHosts = _.sortBy(compHosts, function (i) { return i.text.toLowerCase(); });
+              return $q.when(compHosts);
             });
             });
         };
         };
 
 

+ 1 - 1
ambari-metrics/ambari-metrics-grafana/ambari-metrics/queryCtrl.js

@@ -65,7 +65,7 @@ define([
         };
         };
 
 
         $scope.suggestHosts = function(query, callback) {
         $scope.suggestHosts = function(query, callback) {
-          $scope.datasource.suggestHosts(query)
+          $scope.datasource.suggestHosts(query, $scope.target.app)
             .then($scope.getTextValues)
             .then($scope.getTextValues)
             .then(callback);
             .then(callback);
         };
         };