hosts_mapper.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. var stringUtils = require('utils/string_utils');
  19. App.hostsMapper = App.QuickDataMapper.create({
  20. model: App.Host,
  21. config: {
  22. id: 'Hosts.host_name',
  23. host_name: 'Hosts.host_name',
  24. public_host_name: 'Hosts.public_host_name',
  25. cluster_id: 'cluster_id',// Hosts.cluster_name
  26. rack: 'Hosts.rack_info',
  27. host_components_key: 'host_components',
  28. host_components_type: 'array',
  29. host_components: {
  30. item: 'id'
  31. },
  32. critical_alerts_count: 'critical_alerts_count',
  33. cpu: 'Hosts.cpu_count',
  34. cpu_physical: 'Hosts.ph_cpu_count',
  35. memory: 'Hosts.total_mem',
  36. disk_info: 'Hosts.disk_info',
  37. disk_total: 'metrics.disk.disk_total',
  38. disk_free: 'metrics.disk.disk_free',
  39. health_status: 'Hosts.host_status',
  40. load_one: 'metrics.load.load_one',
  41. load_five: 'metrics.load.load_five',
  42. load_fifteen: 'metrics.load.load_fifteen',
  43. cpu_system: 'metrics.cpu.cpu_system',
  44. cpu_user: 'metrics.cpu.cpu_user',
  45. mem_total: 'metrics.memory.mem_total',
  46. mem_free: 'metrics.memory.mem_free',
  47. last_heart_beat_time: "Hosts.last_heartbeat_time",
  48. os_arch: 'Hosts.os_arch',
  49. os_type: 'Hosts.os_type',
  50. ip: 'Hosts.ip',
  51. passive_state: 'Hosts.maintenance_state'
  52. },
  53. hostComponentConfig: {
  54. component_name: 'HostRoles.component_name',
  55. service_id: 'HostRoles.service_name',
  56. passive_state: 'HostRoles.maintenance_state',
  57. work_status: 'HostRoles.state',
  58. stale_configs: 'HostRoles.stale_configs',
  59. host_name: 'host_name'
  60. },
  61. map: function (json, isAll) {
  62. console.time('App.hostsMapper execution time');
  63. if (json.items) {
  64. var hostsWithFullInfo = [];
  65. var hostIds = {};
  66. var components = [];
  67. json.items.forEach(function (item) {
  68. item.host_components = item.host_components || [];
  69. item.host_components.forEach(function (host_component) {
  70. host_component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;
  71. var component = this.parseIt(host_component, this.hostComponentConfig);
  72. component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;
  73. component.host_id = item.Hosts.host_name;
  74. component.host_name = item.Hosts.host_name;
  75. components.push(component);
  76. }, this);
  77. item.critical_alerts_count = (item.alerts) ? item.alerts.summary.CRITICAL + item.alerts.summary.WARNING : 0;
  78. item.cluster_id = App.get('clusterName');
  79. var parsedItem = this.parseIt(item, this.config);
  80. parsedItem.is_requested = !isAll;
  81. hostIds[item.Hosts.host_name] = parsedItem;
  82. hostsWithFullInfo.push(parsedItem);
  83. }, this);
  84. hostsWithFullInfo = hostsWithFullInfo.sortProperty('public_host_name');
  85. App.Host.find().forEach(function (host) {
  86. if (isAll && host.get('isRequested')) {
  87. hostIds[host.get('hostName')].is_requested = true;
  88. } else if (!hostIds[host.get('hostName')]) {
  89. host.set('isRequested', false);
  90. }
  91. });
  92. App.store.loadMany(App.HostComponent, components);
  93. App.store.loadMany(App.Host, hostsWithFullInfo);
  94. App.router.set('mainHostController.filteredCount', parseInt(json.itemTotal));
  95. }
  96. console.timeEnd('App.hostsMapper execution time');
  97. }
  98. });