瀏覽代碼

AMBARI-6037. Load public host names for Quick Links. (Max Shepel via akovalenko)

Aleksandr Kovalenko 11 年之前
父節點
當前提交
4a11ff281f

+ 63 - 52
ambari-web/app/controllers/global/cluster_controller.js

@@ -29,6 +29,25 @@ App.ClusterController = Em.Controller.extend({
    * Whether we need to update statuses automatically or not
    */
   isWorking: false,
+  isGangliaUrlLoaded: false,
+  isNagiosUrlLoaded: false,
+
+  /**
+   * Provides the URL to use for Ganglia server. This URL
+   * is helpful in populating links in UI.
+   *
+   * If null is returned, it means GANGLIA service is not installed.
+   */
+  gangliaUrl: null,
+
+  /**
+   * Provides the URL to use for NAGIOS server. This URL
+   * is helpful in getting alerts data from server and also
+   * in populating links in UI.
+   *
+   * If null is returned, it means NAGIOS service is not installed.
+   */
+  nagiosUrl: null,
   updateLoadStatus: function (item) {
     var loadList = this.get('dataLoadList');
     var loaded = true;
@@ -130,71 +149,63 @@ App.ClusterController = Em.Controller.extend({
     return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
   },
 
-  /**
-   * Provides the URL to use for Ganglia server. This URL
-   * is helpful in populating links in UI.
-   *
-   * If null is returned, it means GANGLIA service is not installed.
-   */
-  gangliaUrl: function () {
+  setGangliaUrl: function () {
     if (App.testMode) {
       return 'http://gangliaserver/ganglia/?t=yes';
     } else {
       // We want live data here
-      var svcs = App.Service.find();
-      var gangliaSvc = svcs.findProperty("serviceName", "GANGLIA");
-      if (gangliaSvc) {
-        var svcComponents = gangliaSvc.get('hostComponents');
-        if (svcComponents) {
-          var gangliaSvcComponent = svcComponents.findProperty("componentName", "GANGLIA_SERVER");
-          if (gangliaSvcComponent) {
-            var hostName = gangliaSvcComponent.get('host.hostName');
-            if (hostName) {
-              var host = App.Host.find(hostName);
-              if (host) {
-                hostName = host.get('publicHostName');
-              }
-              return this.get('gangliaWebProtocol') + "://" + (App.singleNodeInstall ? App.singleNodeAlias + ":42080" : hostName) + "/ganglia";
-            }
-          }
-        }
+      if (this.get('isLoaded')) {
+        this.set('isGangliaUrlLoaded', true);
+        App.ajax.send({
+          name: 'hosts.for_quick_links',
+          sender: this,
+          data: {
+            clusterName: App.get('clusterName'),
+            masterComponents: 'GANGLIA_SERVER'
+          },
+          success: 'setGangliaUrlSuccessCallback'
+        });
       }
-      return null;
     }
-  }.property('App.router.updateController.isUpdated', 'dataLoadList.hosts', 'gangliaWebProtocol'),
+  }.observes('App.router.updateController.isUpdated', 'dataLoadList.hosts', 'gangliaWebProtocol', 'isLoaded'),
 
-  /**
-   * Provides the URL to use for NAGIOS server. This URL
-   * is helpful in getting alerts data from server and also
-   * in populating links in UI.
-   *
-   * If null is returned, it means NAGIOS service is not installed.
-   */
-  nagiosUrl: function () {
+  setGangliaUrlSuccessCallback: function (response) {
+    var url = null;
+    if (response.items.length > 0) {
+      url = this.get('gangliaWebProtocol') + "://" + (App.singleNodeInstall ? App.singleNodeAlias + ":42080" : response.items[0].Hosts.public_host_name) + "/ganglia";
+    }
+    this.set('gangliaUrl', url);
+    this.set('isGangliaUrlLoaded', true);
+  },
+
+  setNagiosUrl: function () {
     if (App.testMode) {
       return 'http://nagiosserver/nagios';
     } else {
       // We want live data here
-      var nagiosSvc = App.Service.find("NAGIOS");
-      if (nagiosSvc) {
-        var svcComponents = nagiosSvc.get('hostComponents');
-        if (svcComponents) {
-          var nagiosSvcComponent = svcComponents.findProperty("componentName", "NAGIOS_SERVER");
-          if (nagiosSvcComponent) {
-            var hostName = nagiosSvcComponent.get('host.hostName');
-            if (hostName) {
-              var host = App.Host.find(hostName);
-              if (host) {
-                hostName = host.get('publicHostName');
-              }
-              return this.get('nagiosWebProtocol') + "://" + (App.singleNodeInstall ? App.singleNodeAlias + ":42080" : hostName) + "/nagios";
-            }
-          }
-        }
+      if (this.get('isLoaded')) {
+        this.set('isNagiosUrlLoaded', false);
+        App.ajax.send({
+          name: 'hosts.for_quick_links',
+          sender: this,
+          data: {
+            clusterName: App.get('clusterName'),
+            masterComponents: 'NAGIOS_SERVER'
+          },
+          success: 'setNagiosUrlSuccessCallback'
+        });
       }
-      return null;
     }
-  }.property('App.router.updateController.isUpdated', 'dataLoadList.serviceMetrics', 'dataLoadList.hosts', 'nagiosWebProtocol'),
+  }.observes('App.router.updateController.isUpdated', 'dataLoadList.serviceMetrics', 'dataLoadList.hosts', 'nagiosWebProtocol', 'isLoaded'),
+
+  setNagiosUrlSuccessCallback: function (response) {
+    var url = null;
+    if (response.items.length > 0) {
+      url = this.get('nagiosWebProtocol') + "://" + (App.singleNodeInstall ? App.singleNodeAlias + ":42080" : response.items[0].Hosts.public_host_name) + "/nagios";
+    }
+    this.set('nagiosUrl', url);
+    this.set('isNagiosUrlLoaded', true);
+  },
 
   nagiosWebProtocol: function () {
     var properties = this.get('ambariProperties');

+ 19 - 15
ambari-web/app/templates/main/dashboard/widgets/hbase_links.hbs

@@ -60,22 +60,26 @@
                 <span class="caret"></span>
               </a>
                 <ul class="dropdown-menu">
-                  {{#if view.quickLinksArray}}
-                     <!--there are multiple masters eg, HBase multiple masters or HDFS HA enabled-->
-                    {{#each quickLinks in view.quickLinksArray}}
-                      <li class="dropdown-submenu">
-                        <a href="javascript:void(null)">{{quickLinks.publicHostNameLabel}} &nbsp;</a>
-                        <ul class="dropdown-menu">
-                          {{#each quickLinks}}
-                            <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
-                          {{/each}}
-                        </ul>
-                      </li>
-                    {{/each}}
-                  {{else}}
-                    {{#each view.quickLinks}}
+                  {{#if view.isLoaded}}
+                    {{#if view.quickLinksArray}}
+                      <!--there are multiple masters eg, HBase multiple masters or HDFS HA enabled-->
+                      {{#each quickLinks in view.quickLinksArray}}
+                        <li class="dropdown-submenu">
+                          <a href="javascript:void(null)">{{quickLinks.publicHostNameLabel}} &nbsp;</a>
+                          <ul class="dropdown-menu">
+                            {{#each quickLinks}}
+                              <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
+                            {{/each}}
+                          </ul>
+                        </li>
+                      {{/each}}
+                    {{else}}
+                      {{#each view.quickLinks}}
                         <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
-                    {{/each}}
+                      {{/each}}
+                    {{/if}}
+                  {{else}}
+                    <div class="spinner"></div>
                   {{/if}}
                 </ul>
             </div>

+ 18 - 14
ambari-web/app/templates/main/dashboard/widgets/hdfs_links.hbs

@@ -86,22 +86,26 @@
               <span class="caret"></span>
             </a>
               <ul class="dropdown-menu">
-                {{#if view.quickLinksArray}}
+                {{#if view.isLoaded}}
+                  {{#if view.quickLinksArray}}
                     <!--there are multiple masters eg, HBase multiple masters or HDFS HA enabled-->
-                  {{#each quickLinks in view.quickLinksArray}}
-                    <li class="dropdown-submenu">
-                      <a href="javascript:void(null)">{{quickLinks.publicHostNameLabel}} &nbsp;</a>
-                      <ul class="dropdown-menu">
-                        {{#each quickLinks}}
-                           <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
-                        {{/each}}
-                      </ul>
-                    </li>
-                  {{/each}}
-                {{else}}
-                  {{#each view.quickLinks}}
+                    {{#each quickLinks in view.quickLinksArray}}
+                      <li class="dropdown-submenu">
+                        <a href="javascript:void(null)">{{quickLinks.publicHostNameLabel}} &nbsp;</a>
+                        <ul class="dropdown-menu">
+                          {{#each quickLinks}}
+                            <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
+                          {{/each}}
+                        </ul>
+                      </li>
+                    {{/each}}
+                  {{else}}
+                    {{#each view.quickLinks}}
                       <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
-                  {{/each}}
+                    {{/each}}
+                  {{/if}}
+                {{else}}
+                  <div class="spinner"></div>
                 {{/if}}
               </ul>
           </div>

+ 19 - 15
ambari-web/app/templates/main/dashboard/widgets/mapreduce_links.hbs

@@ -42,21 +42,25 @@
       </div>
 
       <div class="link-button">
-        {{#if view.model.quickLinks.length}}
-          {{#view App.QuickViewLinks contentBinding="view.model"}}
-            <div class="btn-group">
-              <a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
-                {{t common.more}}
-                <span class="caret"></span>
-              </a>
-            <ul class="dropdown-menu">
-              {{#each view.quickLinks}}
-                <li><a {{bindAttr href="url"}} target="_blank">{{label}}</a></li>
-                {{/each}}
-              </ul>
-            </div>
-          {{/view}}
-        {{/if}}
+          {{#if view.model.quickLinks.length}}
+            {{#view App.QuickViewLinks contentBinding="view.model"}}
+              {{#if view.isLoaded}}
+                <div class="btn-group">
+                  <a class="btn btn-mini dropdown-toggle" data-toggle="dropdown" href="#">
+                    {{t common.more}}
+                    <span class="caret"></span>
+                  </a>
+                  <ul class="dropdown-menu">
+                    {{#each view.quickLinks}}
+                      <li><a {{bindAttr href="url"}} target="_blank">{{label}}</a></li>
+                    {{/each}}
+                  </ul>
+                </div>
+              {{else}}
+                <div class="spinner"></div>
+              {{/if}}
+            {{/view}}
+          {{/if}}
       </div>
     </li>
   </ul>

+ 5 - 1
ambari-web/app/templates/main/host/summary.hbs

@@ -131,7 +131,11 @@
         <div class="box-header">
           <h4>{{t hosts.host.summary.hostMetrics}}</h4>
           <div class="btn-group">
-            <a class="btn" rel="tooltip" title="Go to Ganglia" {{action "showGangliaCharts" target="view"}}><i class="icon-link"></i></a>
+            {{#if App.router.clusterController.isGangliaUrlLoaded}}
+              <a class="btn" rel="tooltip" title="Go to Ganglia" {{action "showGangliaCharts" target="view"}}><i class="icon-link"></i></a>
+            {{else}}
+              <div class="spinner"></div>
+            {{/if}}
           </div>
         </div>
         <div>

+ 10 - 2
ambari-web/app/templates/main/service/info/summary.hbs

@@ -93,7 +93,11 @@
           <h4>{{t services.alerts.headingOfList}}</h4>
           {{#if controller.isNagiosInstalled}}
             <div class="btn-group">
-              <a class="btn" target="_blank" rel="tooltip" title="Go to Nagios" {{bindAttr href="controller.nagiosUrl"}}><i class="icon-link"></i></a>
+              {{#if App.router.clusterController.isNagiosUrlLoaded}}
+                <a class="btn" target="_blank" rel="tooltip" title="Go to Nagios" {{bindAttr href="controller.nagiosUrl"}}><i class="icon-link"></i></a>
+              {{else}}
+                <div class="spinner"></div>
+              {{/if}}
             </div>
           {{/if}}
         </div>
@@ -161,7 +165,11 @@
       <h4>{{controller.content.label}} {{t common.metrics}}</h4>
         {{#if controller.isGangliaInstalled}}
           <div class="btn-group">
-            <a class="btn" target="_blank" rel="tooltip" title="Go to Ganglia" {{bindAttr href="view.gangliaUrl"}}><i class="icon-link"></i></a>
+            {{#if App.router.clusterController.isGangliaUrlLoaded}}
+              <a class="btn" target="_blank" rel="tooltip" title="Go to Ganglia" {{bindAttr href="view.gangliaUrl"}}><i class="icon-link"></i></a>
+            {{else}}
+              <div class="spinner"></div>
+            {{/if}}
           </div>
         {{/if}}
       </div>

+ 19 - 15
ambari-web/app/templates/main/service/item.hbs

@@ -24,22 +24,26 @@
           <li class="dropdown">
             <a class="dropdown-toggle" data-toggle="dropdown" href="#">{{t common.quickLinks}}<b class="caret"></b></a>
             <ul class="dropdown-menu">
-              {{#if view.quickLinksArray}}
-                <!--there are multiple masters eg, HBase multiple masters or HDFS HA enabled-->
-                {{#each quickLinks in view.quickLinksArray}}
-                   <li class="dropdown-submenu">
-                     <a href="javascript:void(null)">{{quickLinks.publicHostNameLabel}} &nbsp;</a>
-                     <ul class="dropdown-menu">
-                       {{#each quickLinks}}
-                         <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
-                       {{/each}}
-                     </ul>
-                   </li>
-                {{/each}}
+              {{#if view.isLoaded}}
+                {{#if view.quickLinksArray}}
+                  <!--there are multiple masters eg, HBase multiple masters or HDFS HA enabled-->
+                  {{#each quickLinks in view.quickLinksArray}}
+                    <li class="dropdown-submenu">
+                      <a href="javascript:void(null)">{{quickLinks.publicHostNameLabel}} &nbsp;</a>
+                      <ul class="dropdown-menu">
+                        {{#each quickLinks}}
+                          <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
+                        {{/each}}
+                      </ul>
+                    </li>
+                  {{/each}}
+                {{else}}
+                  {{#each view.quickLinks}}
+                    <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
+                  {{/each}}
+                {{/if}}
               {{else}}
-                {{#each view.quickLinks}}
-                   <li><a {{bindAttr href="url"}} {{bindAttr target="view.linkTarget"}}>{{label}}</a></li>
-                {{/each}}
+                <div class="spinner"></div>
               {{/if}}
            </ul>
           </li>

+ 4 - 0
ambari-web/app/utils/ajax/ajax.js

@@ -2135,6 +2135,10 @@ var urls = {
     'real': '/clusters/{clusterName}/hosts?fields=Hosts/public_host_name&minimal_response=true',
     'mock': ''
   },
+  'hosts.for_quick_links': {
+    'real': '/clusters/{clusterName}/hosts?host_components/HostRoles/component_name.in({masterComponents})&fields=Hosts/public_host_name,host_components&minimal_response=true',
+    'mock': ''
+  },
   'hosts.confirmed.install': {
     'real': '/hosts?fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem&minimal_response=true',
     'mock': ''

+ 34 - 14
ambari-web/app/views/common/quick_view_link_view.js

@@ -21,6 +21,8 @@ var stringUtils = require('utils/string_utils');
 
 App.QuickViewLinks = Em.View.extend({
 
+  isLoaded: false,
+
   loadTags: function () {
     App.ajax.send({
       name: 'config.tags.sync',
@@ -73,12 +75,25 @@ App.QuickViewLinks = Em.View.extend({
     this.setQuickLinks();
   },
 
-  findComponentHost: function (componentName) {
-    var components = this.get('content.hostComponents');
-    return App.singleNodeInstall ? App.singleNodeAlias : components.findProperty('componentName', componentName).get('host.publicHostName')
+  findComponentHost: function (components, componentName) {
+    return App.singleNodeInstall ? App.singleNodeAlias : components.find(function (item) {
+      return item.host_components.mapProperty('HostRoles.component_name').contains(componentName);
+    }).Hosts.public_host_name
   },
 
   setQuickLinks: function () {
+    App.ajax.send({
+      name: 'hosts.for_quick_links',
+      sender: this,
+      data: {
+        clusterName: App.get('clusterName'),
+        masterComponents: App.StackServiceComponent.find().filterProperty('isMaster', true).mapProperty('componentName').join(',')
+      },
+      success: 'setQuickLinksSuccessCallback'
+    });
+  }.observes('App.currentStackVersionNumber', 'App.singleNodeInstall'),
+
+  setQuickLinksSuccessCallback: function (response) {
     this.loadTags();
     var serviceName = this.get('content.serviceName');
     var components = this.get('content.hostComponents');
@@ -91,12 +106,14 @@ App.QuickViewLinks = Em.View.extend({
         var otherHost;
         if (this.get('content.snameNode')) {
           // not HA
-          hosts[0] = this.findComponentHost('NAMENODE');
+          hosts[0] = this.findComponentHost(response.items, 'NAMENODE');
         } else {
           // HA enabled, need both two namenodes hosts
-          var nameNodes = components.filterProperty('componentName', 'NAMENODE');
+          var nameNodes = response.items.filter(function (item) {
+            return item.host_components.mapProperty('HostRoles.component_name').contains('NAMENODE');
+          });
           nameNodes.forEach(function(item) {
-            hosts.push({'publicHostName': item.get('host.publicHostName')});
+            hosts.push({'publicHostName': item.Hosts.public_host_name});
           });
           // assign each namenode status label
           if (this.get('content.activeNameNode')) {
@@ -132,17 +149,17 @@ App.QuickViewLinks = Em.View.extend({
             // need all hbase_masters hosts in quick links
             if (activeMaster) {
               activeMaster.forEach(function(item) {
-                hosts.push({'publicHostName': item.get('host.publicHostName'), 'status': Em.I18n.t('quick.links.label.active')});
+                hosts.push({'publicHostName': response.items.mapProperty('Hosts').findProperty('host_name', item.get('host.hostName')).public_host_name, 'status': Em.I18n.t('quick.links.label.active')});
               });
             }
             if (standbyMasters) {
               standbyMasters.forEach(function(item) {
-                hosts.push({'publicHostName': item.get('host.publicHostName'), 'status': Em.I18n.t('quick.links.label.standby')});
+                hosts.push({'publicHostName': response.items.mapProperty('Hosts').findProperty('host_name', item.get('host.hostName')).public_host_name, 'status': Em.I18n.t('quick.links.label.standby')});
               });
             }
             if (otherMasters) {
               otherMasters.forEach(function(item) {
-                hosts.push({'publicHostName': item.get('host.publicHostName')});
+                hosts.push({'publicHostName': response.items.mapProperty('Hosts').findProperty('host_name', item.get('host.hostName')).public_host_name});
               });
             }
           } else {
@@ -151,16 +168,16 @@ App.QuickViewLinks = Em.View.extend({
         }
         break;
       case "YARN":
-        hosts[0] = this.findComponentHost('RESOURCEMANAGER');
+        hosts[0] = this.findComponentHost(response.items, 'RESOURCEMANAGER');
         break;
       case "MAPREDUCE2":
-        hosts[0] = this.findComponentHost('HISTORYSERVER');
+        hosts[0] = this.findComponentHost(response.items, 'HISTORYSERVER');
         break;
       case "FALCON":
-        hosts[0] = this.findComponentHost('FALCON_SERVER');
+        hosts[0] = this.findComponentHost(response.items, 'FALCON_SERVER');
         break;
       case "STORM":
-        hosts[0] = this.findComponentHost('STORM_UI_SERVER');
+        hosts[0] = this.findComponentHost(response.items, 'STORM_UI_SERVER');
         break;
     }
     if (!hosts) {
@@ -171,6 +188,7 @@ App.QuickViewLinks = Em.View.extend({
         }
       ];
       this.set('quickLinks', quickLinks);
+      this.set('isLoaded', true);
     } else if (hosts.length == 1) {
 
       quickLinks = this.get('content.quickLinks').map(function (item) {
@@ -182,6 +200,7 @@ App.QuickViewLinks = Em.View.extend({
         return item;
       });
       this.set('quickLinks', quickLinks);
+      this.set('isLoaded', true);
     } else {
       // multiple hbase masters or HDFS HA enabled
       var quickLinksArray = [];
@@ -207,7 +226,8 @@ App.QuickViewLinks = Em.View.extend({
 
       this.set('quickLinksArray', quickLinksArray);
     }
-  }.observes('App.currentStackVersionNumber', 'App.singleNodeInstall'),
+
+  },
 
   setProtocol: function (service_id) {
     var properties = this.ambariProperties();