<commit_before>(function () {
  "use strict";

  angular
    .module('mnServers', [
      'mnPoolDefault',
      'ui.router',
      'ui.bootstrap',
      'mnServersService',
      'mnHelper',
      'mnVerticalBar',
      'mnBarUsage',
      'mnServersListItemDetailsService',
      'mnFilters',
      'mnSortableTable',
      'mnServices',
      'mnSpinner',
      'ngMessages',
      'mnMemoryQuotaService',
      'mnGsiService',
      'mnPromiseHelper',
      'mnGroupsService',
      'mnPoll',
      'mnFocus',
      'mnPools'
    ])
    .controller('mnServersController', mnServersController)
    .filter("formatFailoverWarnings", formatFailoverWarnings);

  function formatFailoverWarnings() {
    return function (warning) {
      switch (warning) {
        case 'rebalanceNeeded': return 'Rebalance required, some data is not currently replicated!';
        case 'hardNodesNeeded': return 'At least two servers with the data service are required to provide replication!';
        case 'softNodesNeeded': return 'Additional active servers required to provide the desired number of replicas!';
        case 'softRebalanceNeeded': return 'Rebalance recommended, some data does not have the desired replicas configuration!';
      }
    };
  }

  function mnServersController($scope, $state, $uibModal, $q, $interval, mnMemoryQuotaService, mnGsiService, $stateParams, $timeout, mnPoolDefault, mnPoller, mnServersService, mnHelper, mnGroupsService, mnPromiseHelper, mnPools, mnSortableTable) {
    var vm = this;
    vm.sortableTableProperties = mnSortableTable.get();
    vm.mnPoolDefault = mnPoolDefault.latestValue();

    vm.isServerGroupsDisabled = isServerGroupsDisabled;
    vm.isAddServerDisabled = isAddServerDisabled;
    vm.isRebalanceDisabled = isRebalanceDisabled;
    vm.stopRebalanceDisabled = stopRebalanceDisabled;
    vm.stopRecoveryDisabled = stopRecoveryDisabled;

    vm.isReAddPossible = isReAddPossible;
    vm.isNodeUnhealthy = isNodeUnhealthy;
    vm.showInactiveNodeHostname = showInactiveNodeHostname;
    vm.showActiveNodeHostname = showActiveNodeHostname;
    vm.showPendingRecoveryControls = showPendingRecoveryControls;
    vm.showPendingRemovalControls = showPendingRemovalControls;
    vm.showPendingAddControls = showPendingAddControls;
    vm.showFailedOverControls = showFailedOverControls;
    vm.isLastActiveData = isLastActiveData;
    vm.isDataDiskUsageAvailable = isDataDiskUsageAvailable;
    vm.couchDataSize = couchDataSize;
    vm.couchDiskUsage = couchDiskUsage;
    vm.getRebalanceProgress = getRebalanceProgress;
    vm.disableRemoveBtn = disableRemoveBtn;
    vm.isFailOverDisabled = isFailOverDisabled;
    vm.showRebalanceProgressPerItem = showRebalanceProgressPerItem;

    vm.getRamUsageConf = getRamUsageConf;
    vm.getSwapUsageConf = getSwapUsageConf;
    vm.getCpuUsageConf = getCpuUsageConf;

    vm.cancelEjectServer = cancelEjectServer;
    vm.cancelFailOverNode = cancelFailOverNode;
    vm.reAddNode = reAddNode;
    vm.failOverNode = failOverNode;
    vm.ejectServer = ejectServer;
    vm.stopRebalance = stopRebalance;
    vm.onStopRecovery = onStopRecovery;
    vm.postRebalance = postRebalance;
    vm.addServer = addServer;

    activate();

    function activate() {
      mnHelper.initializeDetailsHashObserver(vm, 'openedServers', 'app.admin.servers');
      vm.poller = new mnPoller($scope, function () {
          return mnServersService.getServersState($stateParams.list);
        })
        .subscribe("state", vm)
        .keepIn("app.admin.servers", vm)
        .cancelOnScopeDestroy()
        .cycle()
        .showSpinner(vm);
    }

    var ramUsageConf = {};
    var swapUsageConf = {};
    var cpuUsageConf = {};

    function getRamUsageConf(node) {
      var total = node.memoryTotal;
      var free = node.memoryFree;
      var used = total - free;
      cpuUsageConf.exist = (total > 0) && _.isFinite(free);
      cpuUsageConf.height = used / total * 100;
      cpuUsageConf.top = 105 - used / total * 100;
      cpuUsageConf.value = used / total * 100;
      return cpuUsageConf;
    }
    function getSwapUsageConf(node) {
      var swapTotal = node.systemStats.swap_total;
      var swapUsed = node.systemStats.swap_used;
      swapUsageConf.exist = swapTotal > 0 && _.isFinite(swapUsed);
      swapUsageConf.height = swapUsed / swapTotal * 100;
      swapUsageConf.top = 105 - (swapUsed / swapTotal * 100);
      swapUsageConf.value = (swapUsed / swapTotal) * 100;
      return swapUsageConf;
    }
    function getCpuUsageConf(node) {
      var cpuRate = node.systemStats.cpu_utilization_rate;
      cpuUsageConf.exist = _.isFinite(cpuRate);
      cpuUsageConf.height = Math.floor(cpuRate * 100) / 100;
      cpuUsageConf.top = 105 - (Math.floor(cpuRate * 100) / 100);
      cpuUsageConf.value = Math.floor(cpuRate * 100) / 100;
      return cpuUsageConf;
    }
    function isFailOverDisabled(node) {<commit_msg>MB-12222: fixed ram usage bar<commit_after>(function () {
  "use strict";

  angular
    .module('mnServers', [
      'mnPoolDefault',
      'ui.router',
      'ui.bootstrap',
      'mnServersService',
      'mnHelper',
      'mnVerticalBar',
      'mnBarUsage',
      'mnServersListItemDetailsService',
      'mnFilters',
      'mnSortableTable',
      'mnServices',
      'mnSpinner',
      'ngMessages',
      'mnMemoryQuotaService',
      'mnGsiService',
      'mnPromiseHelper',
      'mnGroupsService',
      'mnPoll',
      'mnFocus',
      'mnPools'
    ])
    .controller('mnServersController', mnServersController)
    .filter("formatFailoverWarnings", formatFailoverWarnings);

  function formatFailoverWarnings() {
    return function (warning) {
      switch (warning) {
        case 'rebalanceNeeded': return 'Rebalance required, some data is not currently replicated!';
        case 'hardNodesNeeded': return 'At least two servers with the data service are required to provide replication!';
        case 'softNodesNeeded': return 'Additional active servers required to provide the desired number of replicas!';
        case 'softRebalanceNeeded': return 'Rebalance recommended, some data does not have the desired replicas configuration!';
      }
    };
  }

  function mnServersController($scope, $state, $uibModal, $q, $interval, mnMemoryQuotaService, mnGsiService, $stateParams, $timeout, mnPoolDefault, mnPoller, mnServersService, mnHelper, mnGroupsService, mnPromiseHelper, mnPools, mnSortableTable) {
    var vm = this;
    vm.sortableTableProperties = mnSortableTable.get();
    vm.mnPoolDefault = mnPoolDefault.latestValue();

    vm.isServerGroupsDisabled = isServerGroupsDisabled;
    vm.isAddServerDisabled = isAddServerDisabled;
    vm.isRebalanceDisabled = isRebalanceDisabled;
    vm.stopRebalanceDisabled = stopRebalanceDisabled;
    vm.stopRecoveryDisabled = stopRecoveryDisabled;

    vm.isReAddPossible = isReAddPossible;
    vm.isNodeUnhealthy = isNodeUnhealthy;
    vm.showInactiveNodeHostname = showInactiveNodeHostname;
    vm.showActiveNodeHostname = showActiveNodeHostname;
    vm.showPendingRecoveryControls = showPendingRecoveryControls;
    vm.showPendingRemovalControls = showPendingRemovalControls;
    vm.showPendingAddControls = showPendingAddControls;
    vm.showFailedOverControls = showFailedOverControls;
    vm.isLastActiveData = isLastActiveData;
    vm.isDataDiskUsageAvailable = isDataDiskUsageAvailable;
    vm.couchDataSize = couchDataSize;
    vm.couchDiskUsage = couchDiskUsage;
    vm.getRebalanceProgress = getRebalanceProgress;
    vm.disableRemoveBtn = disableRemoveBtn;
    vm.isFailOverDisabled = isFailOverDisabled;
    vm.showRebalanceProgressPerItem = showRebalanceProgressPerItem;

    vm.getRamUsageConf = getRamUsageConf;
    vm.getSwapUsageConf = getSwapUsageConf;
    vm.getCpuUsageConf = getCpuUsageConf;

    vm.cancelEjectServer = cancelEjectServer;
    vm.cancelFailOverNode = cancelFailOverNode;
    vm.reAddNode = reAddNode;
    vm.failOverNode = failOverNode;
    vm.ejectServer = ejectServer;
    vm.stopRebalance = stopRebalance;
    vm.onStopRecovery = onStopRecovery;
    vm.postRebalance = postRebalance;
    vm.addServer = addServer;

    activate();

    function activate() {
      mnHelper.initializeDetailsHashObserver(vm, 'openedServers', 'app.admin.servers');
      vm.poller = new mnPoller($scope, function () {
          return mnServersService.getServersState($stateParams.list);
        })
        .subscribe("state", vm)
        .keepIn("app.admin.servers", vm)
        .cancelOnScopeDestroy()
        .cycle()
        .showSpinner(vm);
    }

    var ramUsageConf = {};
    var swapUsageConf = {};
    var cpuUsageConf = {};

    function getRamUsageConf(node) {
      var total = node.memoryTotal;
      var free = node.memoryFree;
      var used = total - free;
      ramUsageConf.exist = (total > 0) && _.isFinite(free);
      ramUsageConf.height = used / total * 100;
      ramUsageConf.top = 105 - used / total * 100;
      ramUsageConf.value = used / total * 100;
      return ramUsageConf;
    }
    function getSwapUsageConf(node) {
      var swapTotal = node.systemStats.swap_total;
      var swapUsed = node.systemStats.swap_used;
      swapUsageConf.exist = swapTotal > 0 && _.isFinite(swapUsed);
      swapUsageConf.height = swapUsed / swapTotal * 100;
      swapUsageConf.top = 105 - (swapUsed / swapTotal * 100);
      swapUsageConf.value = (swapUsed / swapTotal) * 100;
      return swapUsageConf;
    }
    function getCpuUsageConf(node) {
      var cpuRate = node.systemStats.cpu_utilization_rate;
      cpuUsageConf.exist = _.isFinite(cpuRate);
      cpuUsageConf.height = Math.floor(cpuRate * 100) / 100;
      cpuUsageConf.top = 105 - (Math.floor(cpuRate * 100) / 100);
      cpuUsageConf.value = Math.floor(cpuRate * 100) / 100;
      return cpuUsageConf;
    }
    function isFailOverDisabled(node) {
{'fraction_non_alphanumeric': 0.0964787299002646, 'fraction_numerical': 0.010075310400977, 'mean_word_length': 3.483120437956204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1692887', 'n_tokens_mistral': 3094, 'n_tokens_neox': 2936, 'n_words': 582}