component_config_mapper.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. App.componentConfigMapper = App.QuickDataMapper.create({
  19. model: App.HostComponent,
  20. config: {
  21. id: 'id',
  22. work_status: 'state',
  23. passive_state: 'maintenance_state',
  24. component_name: 'component_name',
  25. host_name: 'host_name',
  26. $ha_status: 'none',
  27. $display_name_advanced: '',
  28. stale_configs: 'stale_configs',
  29. host_id: 'host_name',
  30. service_id: 'service_name'
  31. },
  32. map: function (json) {
  33. console.time('App.componentConfigMapper execution time');
  34. var hostComponents = [];
  35. var serviceToHostComponentIdMap = {};
  36. json.items.forEach(function (item) {
  37. item.host_components.forEach(function (host_component) {
  38. host_component = host_component.HostRoles;
  39. host_component.id = host_component.component_name + '_' + host_component.host_name;
  40. hostComponents.push(this.parseIt(host_component, this.get('config')));
  41. if (!serviceToHostComponentIdMap[host_component.service_name]) {
  42. serviceToHostComponentIdMap[host_component.service_name] = [];
  43. }
  44. serviceToHostComponentIdMap[host_component.service_name].push(host_component.id);
  45. }, this);
  46. }, this);
  47. App.store.loadMany(this.get('model'), hostComponents);
  48. for (var serviceName in serviceToHostComponentIdMap) {
  49. if (serviceToHostComponentIdMap.hasOwnProperty(serviceName)) {
  50. var service = App.cache['services'].findProperty('ServiceInfo.service_name', serviceName);
  51. if (service) {
  52. for (var n in serviceToHostComponentIdMap[serviceName]) {
  53. if (serviceToHostComponentIdMap[serviceName].hasOwnProperty(n)) {
  54. if (!service.host_components.contains(serviceToHostComponentIdMap[serviceName][n])) {
  55. service.host_components.pushObject(serviceToHostComponentIdMap[serviceName][n]);
  56. }
  57. }
  58. }
  59. }
  60. }
  61. }
  62. console.timeEnd('App.componentConfigMapper execution time');
  63. }
  64. });