parseHostCheckWarnings: function()

in ambari-web/app/mixins/main/host/details/actions/check_host.js [531:765]


  parseHostCheckWarnings: function (data) {
    data = App.get('testMode') ? data : this.filterHostsData(data);
    var warnings = [];
    var warning;
    var hosts = [];
    var warningCategories = {
      fileFoldersWarnings: {},
      packagesWarnings: {},
      processesWarnings: {},
      servicesWarnings: {},
      usersWarnings: {},
      alternativeWarnings: {}
    };

    var hostsPackagesData = this.get('hostsPackagesData');
    data.tasks.sortPropertyLight('Tasks.host_name').forEach(function (_task) {
      var hostName = _task.Tasks.host_name;
      var host = {
        name: hostName,
        warnings: []
      };

      if (!_task.Tasks.structured_out || !_task.Tasks.structured_out.last_agent_env_check) {
        return;
      }

      var lastAgentEnvCheck = _task.Tasks.structured_out.last_agent_env_check;

      //parse all directories and files warnings for host
      var stackFoldersAndFiles = lastAgentEnvCheck.stackFoldersAndFiles || [];
      stackFoldersAndFiles.forEach(function (path) {
        warning = warningCategories.fileFoldersWarnings[path.name];
        if (warning) {
          warning.hosts.push(hostName);
          warning.hostsLong.push(hostName);
        } else {
          warningCategories.fileFoldersWarnings[path.name] = warning = {
            name: path.name,
            hosts: [hostName],
            hostsLong: [hostName],
            category: 'fileFolders'
          };
        }
        host.warnings.push(warning);
      }, this);

      //parse all package warnings for host
      var _hostPackagesData = hostsPackagesData.findProperty('hostName', hostName);

      if (_hostPackagesData) {
        _hostPackagesData.installedPackages.forEach(function (_package) {
          warning = warningCategories.packagesWarnings[_package.name];
          if (warning) {
            warning.hosts.push(hostName);
            warning.hostsLong.push(hostName);
            warning.version = _package.version;
          } else {
            warningCategories.packagesWarnings[_package.name] = warning = {
              name: _package.name,
              version: _package.version,
              hosts: [hostName],
              hostsLong: [hostName],
              category: 'packages'
            };
          }
          host.warnings.push(warning);
        }, this);
      }

      //parse all process warnings for host
      var hostHealth = lastAgentEnvCheck.hostHealth;

      var liveServices = null;
      var javaProcs = null;

      if(hostHealth) {
        if(hostHealth.activeJavaProcs)
          javaProcs = hostHealth.activeJavaProcs;
        if(hostHealth.liveServices)
          liveServices = hostHealth.liveServices;
      }

      if (javaProcs) {
        javaProcs.forEach(function (process) {
          warning = warningCategories.processesWarnings[process.pid];
          if (warning) {
            warning.hosts.push(hostName);
            warning.hostsLong.push(hostName);
          } else {
            var command = 'pid=' + process.pid + ', user=' + process.user;
            warningCategories.processesWarnings[process.pid] = warning = {
              name: command.length > 36 ? (command.substr(0, 35) + '...') : command,
              hosts: [hostName],
              hostsLong: [hostName],
              category: 'processes',
              user: process.user,
              pid: process.pid,
              command: command
            };
          }
          host.warnings.push(warning);
        }, this);
      }

      //parse all service warnings for host
      if (liveServices) {
        liveServices.forEach(function (service) {
          if (service.status === 'Unhealthy') {
            warning = warningCategories.servicesWarnings[service.name];
            if (warning) {
              warning.hosts.push(hostName);
              warning.hostsLong.push(hostName);
            } else {
              warningCategories.servicesWarnings[service.name] = warning = {
                name: service.name,
                hosts: [hostName],
                hostsLong: [hostName],
                category: 'services'
              };
            }
            host.warnings.push(warning);
          }
        }, this);
      }
      //parse all user warnings for host
      var existingUsers = lastAgentEnvCheck.existingUsers;
      if (existingUsers) {
        existingUsers.forEach(function (user) {
          warning = warningCategories.usersWarnings[user.name];
          if (warning) {
            warning.hosts.push(hostName);
            warning.hostsLong.push(hostName);
          } else {
            warningCategories.usersWarnings[user.name] = warning = {
              name: user.name,
              hosts: [hostName],
              hostsLong: [hostName],
              category: 'users'
            };
          }
          host.warnings.push(warning);
        }, this);
      }

      //parse misc warnings for host
      var umask = lastAgentEnvCheck.umask;
      if (umask && umask > 23) {
        warning = warnings.filterProperty('category', 'misc').findProperty('name', umask);
        if (warning) {
          warning.hosts.push(hostName);
          warning.hostsLong.push(hostName);
        } else {
          warning = {
            name: umask,
            hosts: [hostName],
            hostsLong: [hostName],
            category: 'misc'
          };
          warnings.push(warning);
        }
        host.warnings.push(warning);
      }

      var firewallRunning = lastAgentEnvCheck.firewallRunning;
      if (firewallRunning !== null && firewallRunning) {
        var name = lastAgentEnvCheck.firewallName + " Running";
        warning = warnings.filterProperty('category', 'firewall').findProperty('name', name);
        if (warning) {
          warning.hosts.push(hostName);
          warning.hostsLong.push(hostName);
        } else {
          warning = {
            name: name,
            hosts: [hostName],
            hostsLong: [hostName],
            category: 'firewall'
          };
          warnings.push(warning);
        }
        host.warnings.push(warning);
      }

      if (lastAgentEnvCheck.alternatives) {
        lastAgentEnvCheck.alternatives.forEach(function (alternative) {
          warning = warningCategories.alternativeWarnings[alternative.name];
          if (warning) {
            warning.hosts.push(hostName);
            warning.hostsLong.push(hostName);
          } else {
            warningCategories.alternativeWarnings[alternative.name] = warning = {
              name: alternative.name,
              target: alternative.target,
              hosts: [hostName],
              hostsLong: [hostName],
              category: 'alternatives'
            };
          }
          host.warnings.push(warning);
        }, this);
      }

      if (lastAgentEnvCheck.reverseLookup === false) {
        var name = Em.I18n.t('installer.step3.hostWarningsPopup.reverseLookup.name');
        warning = warnings.filterProperty('category', 'reverseLookup').findProperty('name', name);
        if (warning) {
          warning.hosts.push(hostName);
          warning.hostsLong.push(hostName);
        } else {
          warning = {
            name: name,
            hosts: [hostName],
            hostsLong: [hostName],
            category: 'reverseLookup'
          };
          warnings.push(warning);
        }
        host.warnings.push(warning);
      }
      hosts.push(host);
    }, this);

    for (var categoryId in warningCategories) {
      var category = warningCategories[categoryId];
      for (var warningId in category) {
        warnings.push(category[warningId]);
      }
    }

    hosts.unshift({
      name: 'All Hosts',
      warnings: warnings
    });
    this.set('warnings', warnings);
    this.set('warningsByHost', hosts);
  },