components_state_mapper.js 5.9 KB

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