components_state_mapper.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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.componentsStateMapper = App.QuickDataMapper.create({
  20. model: App.Service,
  21. paths: {
  22. INSTALLED_PATH: 'ServiceComponentInfo.installed_count',
  23. STARTED_PATH: 'ServiceComponentInfo.started_count',
  24. TOTAL_PATH: 'ServiceComponentInfo.total_count'
  25. },
  26. configMap: {
  27. 'DATANODE': {
  28. data_nodes_started: 'STARTED_PATH',
  29. data_nodes_installed: 'INSTALLED_PATH',
  30. data_nodes_total: 'TOTAL_PATH'
  31. },
  32. 'NODEMANAGER': {
  33. node_managers_started: 'STARTED_PATH',
  34. node_managers_installed: 'INSTALLED_PATH',
  35. node_managers_total: 'TOTAL_PATH'
  36. },
  37. 'TASKTRACKER': {
  38. task_trackers_started: 'STARTED_PATH',
  39. task_trackers_installed: 'INSTALLED_PATH',
  40. task_trackers_total: 'TOTAL_PATH'
  41. },
  42. 'HBASE_REGIONSERVER': {
  43. region_servers_started: 'STARTED_PATH',
  44. region_servers_installed: 'INSTALLED_PATH',
  45. region_servers_total: 'TOTAL_PATH'
  46. },
  47. 'GANGLIA_MONITOR': {
  48. ganglia_monitors_started: 'STARTED_PATH',
  49. ganglia_monitors_installed: 'INSTALLED_PATH',
  50. ganglia_monitors_total: 'TOTAL_PATH'
  51. },
  52. 'SUPERVISOR': {
  53. super_visors_started: 'STARTED_PATH',
  54. super_visors_installed: 'INSTALLED_PATH',
  55. super_visors_total: 'TOTAL_PATH'
  56. },
  57. 'MAPREDUCE2_CLIENT': {
  58. map_reduce2_clients: 'INSTALLED_PATH'
  59. },
  60. 'TEZ_CLIENT': {
  61. installed_clients: 'INSTALLED_PATH'
  62. },
  63. 'HIVE_CLIENT': {
  64. installed_clients: 'INSTALLED_PATH'
  65. },
  66. 'FALCON_CLIENT': {
  67. installed_clients: 'INSTALLED_PATH'
  68. },
  69. 'OOZIE_CLIENT': {
  70. installed_clients: 'INSTALLED_PATH'
  71. },
  72. 'ZOOKEEPER_CLIENT': {
  73. installed_clients: 'INSTALLED_PATH'
  74. },
  75. 'PIG': {
  76. installed_clients: 'INSTALLED_PATH'
  77. },
  78. 'SQOOP': {
  79. installed_clients: 'INSTALLED_PATH'
  80. },
  81. 'YARN_CLIENT': {
  82. installed_clients: 'INSTALLED_PATH'
  83. },
  84. 'HDFS_CLIENT': {
  85. installed_clients: 'INSTALLED_PATH'
  86. },
  87. 'FLUME_HANDLER': {
  88. flume_handlers_total: 'TOTAL_PATH'
  89. }
  90. },
  91. /**
  92. * get formatted component config
  93. * @param componentName
  94. * @return {Object}
  95. */
  96. getComponentConfig: function (componentName) {
  97. var config = {};
  98. var componentConfig = this.get('configMap')[componentName];
  99. var paths = this.get('paths');
  100. for (var property in componentConfig) {
  101. if (paths[componentConfig[property]]) {
  102. config[property] = paths[componentConfig[property]];
  103. }
  104. }
  105. return config;
  106. },
  107. /**
  108. * get service extended model if it has one
  109. * @param serviceName
  110. * @return {Object|null}
  111. */
  112. getExtendedModel: function (serviceName) {
  113. if (App[App.Service.extendedModel[serviceName]]) {
  114. return App[App.Service.extendedModel[serviceName]].find(serviceName);
  115. }
  116. return null;
  117. },
  118. map: function (json) {
  119. console.time('App.componentsStateMapper execution time');
  120. if (json.items) {
  121. json.items.forEach(function (item) {
  122. var componentConfig = this.getComponentConfig(item.ServiceComponentInfo.component_name);
  123. var parsedItem = this.parseIt(item, componentConfig);
  124. var service = App.Service.find(item.ServiceComponentInfo.service_name);
  125. var extendedModel = this.getExtendedModel(item.ServiceComponentInfo.service_name);
  126. var cacheService = App.cache['services'].findProperty('ServiceInfo.service_name', item.ServiceComponentInfo.service_name);
  127. for (var i in parsedItem) {
  128. if (service.get('isLoaded')) {
  129. cacheService[i] = parsedItem[i];
  130. service.set(stringUtils.underScoreToCamelCase(i), parsedItem[i]);
  131. if (extendedModel) {
  132. extendedModel.set(stringUtils.underScoreToCamelCase(i), parsedItem[i]);
  133. }
  134. }
  135. }
  136. }, this)
  137. }
  138. console.timeEnd('App.componentsStateMapper execution time');
  139. }
  140. });