hosts_mapper.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. App.hostsMapper = App.QuickDataMapper.create({
  19. model : App.Host,
  20. config : {
  21. id : 'Hosts.host_name',
  22. host_name : 'Hosts.host_name',
  23. cluster_id: 'Hosts.cluster_name',//1
  24. components_key: 'host_components',
  25. components_type: 'array',
  26. components: {
  27. item : 'HostRoles.component_name'
  28. },
  29. rack: 'Hosts.rack_info',
  30. host_components_key: 'host_components',
  31. host_components_type: 'array',
  32. host_components: {
  33. item: 'id'
  34. },
  35. cpu : 'Hosts.cpu_count',
  36. memory : 'Hosts.total_mem',
  37. disk_info: 'Hosts.disk_info',
  38. $disk_usage: '-',
  39. health_status: 'Hosts.host_status',
  40. $load_avg: '-',
  41. $cpu_usage: 33,
  42. $memory_usage: 26,
  43. $network_usage: 36,
  44. $io_usage: 39,
  45. last_heart_beat_time : "Hosts.last_heartbeat_time",
  46. os_arch : 'Hosts.os_arch',
  47. os_type : 'Hosts.os_type',
  48. ip : 'Hosts.ip'
  49. },
  50. map: function (json) {
  51. if (!this.get('model')) {
  52. return;
  53. }
  54. if (json.items) {
  55. var result = [];
  56. json.items.forEach(function (item) {
  57. item.host_components.forEach(function(host_component){
  58. host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
  59. }, this);
  60. result.push(this.parseIt(item, this.config));
  61. }, this);
  62. //console.log(this.get('model'), result);
  63. App.store.loadMany(this.get('model'), result);
  64. }
  65. }
  66. });