hosts_mapper.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. map: function (json, isAll) {
  54. console.time('App.hostsMapper execution time');
  55. if (json.items) {
  56. var hostsWithFullInfo = [];
  57. var hostIds = {};
  58. json.items.forEach(function (item) {
  59. item.host_components = item.host_components || [];
  60. item.host_components.forEach(function (host_component) {
  61. host_component.id = host_component.HostRoles.component_name + "_" + item.Hosts.host_name;
  62. }, this);
  63. item.critical_alerts_count = (item.alerts) ? item.alerts.summary.CRITICAL + item.alerts.summary.WARNING : 0;
  64. item.cluster_id = App.get('clusterName');
  65. var parsedItem = this.parseIt(item, this.config);
  66. parsedItem.is_requested = !isAll;
  67. hostIds[item.Hosts.host_name] = parsedItem;
  68. hostsWithFullInfo.push(parsedItem);
  69. }, this);
  70. hostsWithFullInfo = hostsWithFullInfo.sortProperty('public_host_name');
  71. App.Host.find().forEach(function (host) {
  72. if (isAll && host.get('isRequested')) {
  73. hostIds[host.get('hostName')].is_requested = true;
  74. } else if (!hostIds[host.get('hostName')]) {
  75. host.set('isRequested', false);
  76. }
  77. });
  78. App.store.loadMany(App.Host, hostsWithFullInfo);
  79. }
  80. console.timeEnd('App.hostsMapper execution time');
  81. }
  82. });