AMBARI-23912. Ambari should mark HSI hosts as ACTIVE or STANDBY
authorAlex Antonenko <aantonenko@hortonworks.com>
Mon, 21 May 2018 14:31:33 +0000 (17:31 +0300)
committerAlex Antonenko <aantonenko@hortonworks.com>
Mon, 21 May 2018 14:31:33 +0000 (17:31 +0300)
ambari-web/app/mappers/service_metrics_mapper.js
ambari-web/app/utils/ajax/ajax.js

index 8d14ede..4d79c53 100644 (file)
@@ -207,7 +207,9 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
    * @type {Array}
    * @const
    */
-  ADVANCED_COMPONENTS: ['SECONDARY_NAMENODE', 'RESOURCEMANAGER', 'NAMENODE', 'HBASE_MASTER', 'RESOURCEMANAGER'],
+  ADVANCED_COMPONENTS: ['SECONDARY_NAMENODE', 'RESOURCEMANAGER', 'NAMENODE', 'HBASE_MASTER', 'RESOURCEMANAGER', 'HIVE_SERVER_INTERACTIVE'],
+
+  hostNameIpMap: {},
 
   map: function (json) {
     console.time('App.serviceMetricsMapper execution time');
@@ -222,6 +224,7 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
       var result = [];
       var advancedHostComponents = [];
       var hostComponentIdsMap = {};
+      var hiveInteractiveServers = [];
 
       /**
        * services contains constructed service-components structure from components array
@@ -244,6 +247,9 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
           var comp = this.parseIt(host_component, this.config3);
           comp.id = id;
           comp.service_id = serviceName;
+          if (comp.component_name === 'HIVE_SERVER_INTERACTIVE') {
+            hiveInteractiveServers.push(comp);
+          }
           hostComponents.push(comp);
           if (this.get('ADVANCED_COMPONENTS').contains(comp.component_name)) {
             advancedHostComponents.push(comp);
@@ -275,6 +281,9 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
 
       App.store.safeLoadMany(this.get('model3'), hostComponents);
 
+      if (hiveInteractiveServers.length > 1) {
+        this.loadInteractiveServerStatuses(hiveInteractiveServers);
+      }
       //parse service metrics from components
       services.forEach(function (item) {
         hostComponents.filterProperty('service_id', item.ServiceInfo.service_name).mapProperty('id').forEach(function (hostComponent) {
@@ -307,6 +316,64 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
     console.timeEnd('App.serviceMetricsMapper execution time');
   },
 
+  loadInteractiveServerStatuses: function (hiveInteractiveServers) {
+    var self = this;
+    App.router.get('configurationController').getCurrentConfigsBySites(['hive-site', 'hive-interactive-site']).done(function (configs) {
+      var hiveWebUiPort = configs.findProperty('type', 'hive-interactive-site').properties['hive.server2.webui.port'];
+      var hostNames = hiveInteractiveServers.mapProperty('host_name');
+      var notDefinedHostIp = hostNames.find(function (hostName) {
+        return !self.get('hostNameIpMap')[hostName];
+      });
+      if (notDefinedHostIp) {
+        self.getHostNameIpMap(hostNames).done(function () {
+          self.getHiveServersInteractiveStatus(hiveInteractiveServers, hiveWebUiPort);
+        });
+      } else {
+        self.getHiveServersInteractiveStatus(hiveInteractiveServers, hiveWebUiPort);
+      }
+    });
+  },
+
+  getHostNameIpMap: function (hostNames) {
+    var self = this;
+    return App.ajax.send({
+      name: 'hosts.ips',
+      data: {
+        hostNames: hostNames
+      },
+      sender: self
+    }).success(function (data) {
+      data.items.forEach(function(hostData) {
+        var ip = hostData.Hosts.ip;
+        var hostName = hostData.Hosts.host_name;
+        self.get('hostNameIpMap')[hostName] = ip;
+      })
+    });
+  },
+
+  getHiveServersInteractiveStatus: function(hiveInteractiveServers, hiveWebUiPort) {
+    var self = this;
+    hiveInteractiveServers.forEach(function (hiveInteractiveServer) {
+      App.ajax.send({
+        name: 'hiveServerInteractive.getStatus',
+        data: {
+          hsiHost: self.hostNameIpMap[hiveInteractiveServer.host_name],
+          port: hiveWebUiPort
+        },
+        sender: self
+      }).success(function (isActive) {
+
+        var advancedName = Em.I18n.t('quick.links.label.' +  (isActive ? 'active': 'standby')) + ' ' + hiveInteractiveServer.display_name;
+        var hiveInteractiveServerComponent = App.HostComponent.find().find(function (component) {
+          return component.get('hostName') === hiveInteractiveServer.host_name && component.get('componentName') === 'HIVE_SERVER_INTERACTIVE';
+        });
+        if (hiveInteractiveServerComponent){
+          hiveInteractiveServerComponent.set('displayNameAdvanced', advancedName);
+        }
+      });
+    });
+  },
+
   /**
    * verify that service component has host components
    * @param {object} component
@@ -426,6 +493,11 @@ App.serviceMetricsMapper = App.QuickDataMapper.create({
               hostComponent.display_name_advanced = Em.I18n.t('dashboard.services.yarn.resourceManager.standby');
               break;
           }
+        } else if (hostComponent.component_name === 'HIVE_SERVER_INTERACTIVE') {
+          var hiveInteractiveServerComponent = App.HostComponent.find().find(function (component) {
+            return component.get('hostName') === hostComponent.host_name && component.get('componentName') === 'HIVE_SERVER_INTERACTIVE';
+          });
+          hostComponent.display_name_advanced = hiveInteractiveServerComponent.get('displayNameAdvanced');
         }
         if (service) {
           if (hostComponent.display_name_advanced) {
index 7d80193..5fdd205 100644 (file)
@@ -2820,6 +2820,10 @@ var urls = {
     'real': '/hosts?Hosts/host_name.in({hostNames})&fields=Hosts/cpu_count,Hosts/disk_info,Hosts/total_mem,Hosts/ip,Hosts/os_type,Hosts/os_arch,Hosts/public_host_name&minimal_response=true',
     'mock': ''
   },
+  'hosts.ips': {
+    'real': '/hosts?Hosts/host_name.in({hostNames})&fields=Hosts/ip',
+    'mock': ''
+  },
   'hosts.host_components.pre_load': {
     real: '',
     mock: '/data/hosts/HDP2/hosts.json',
@@ -3193,6 +3197,15 @@ var urls = {
         })
       }
     }
+  },
+  'hiveServerInteractive.getStatus': {
+    real: '',
+    mock: '',
+    format: function (data) {
+      return {
+        url: 'http://' + data.hsiHost + ':' + data.port + '/leader'
+      }
+    }
   }
 };
 /**