components_state_mapper.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. display_name: 'ServiceComponentInfo.display_name',
  28. service_name: 'ServiceComponentInfo.service_name',
  29. installed_count: 'ServiceComponentInfo.installed_count',
  30. started_count: 'ServiceComponentInfo.started_count',
  31. total_count: 'ServiceComponentInfo.total_count',
  32. host_names: 'host_names'
  33. },
  34. slaveModel: App.SlaveComponent,
  35. masterModel: App.MasterComponent,
  36. paths: {
  37. INSTALLED_PATH: 'ServiceComponentInfo.installed_count',
  38. STARTED_PATH: 'ServiceComponentInfo.started_count',
  39. TOTAL_PATH: 'ServiceComponentInfo.total_count'
  40. },
  41. configMap: {
  42. 'DATANODE': {
  43. data_nodes_started: 'STARTED_PATH',
  44. data_nodes_installed: 'INSTALLED_PATH',
  45. data_nodes_total: 'TOTAL_PATH'
  46. },
  47. 'NFS_GATEWAY': {
  48. nfs_gateways_started: 'STARTED_PATH',
  49. nfs_gateways_installed: 'INSTALLED_PATH',
  50. nfs_gateways_total: 'TOTAL_PATH'
  51. },
  52. 'NODEMANAGER': {
  53. node_managers_started: 'STARTED_PATH',
  54. node_managers_installed: 'INSTALLED_PATH',
  55. node_managers_total: 'TOTAL_PATH'
  56. },
  57. 'HAWQSEGMENT': {
  58. hawq_segments_started: 'STARTED_PATH',
  59. hawq_segments_installed: 'INSTALLED_PATH',
  60. hawq_segments_total: 'TOTAL_PATH'
  61. },
  62. 'PXF': {
  63. pxfs_started: 'STARTED_PATH',
  64. pxfs_installed: 'INSTALLED_PATH',
  65. pxfs_total: 'TOTAL_PATH'
  66. },
  67. 'HBASE_REGIONSERVER': {
  68. region_servers_started: 'STARTED_PATH',
  69. region_servers_installed: 'INSTALLED_PATH',
  70. region_servers_total: 'TOTAL_PATH'
  71. },
  72. 'PHOENIX_QUERY_SERVER': {
  73. phoenix_servers_started: 'STARTED_PATH',
  74. phoenix_servers_installed: 'INSTALLED_PATH',
  75. phoenix_servers_total: 'TOTAL_PATH'
  76. },
  77. 'GANGLIA_MONITOR': {
  78. ganglia_monitors_started: 'STARTED_PATH',
  79. ganglia_monitors_installed: 'INSTALLED_PATH',
  80. ganglia_monitors_total: 'TOTAL_PATH'
  81. },
  82. 'SUPERVISOR': {
  83. super_visors_started: 'STARTED_PATH',
  84. super_visors_installed: 'INSTALLED_PATH',
  85. super_visors_total: 'TOTAL_PATH'
  86. },
  87. 'MAPREDUCE2_CLIENT': {
  88. map_reduce2_clients: 'INSTALLED_PATH'
  89. },
  90. 'TEZ_CLIENT': {
  91. installed_clients: 'INSTALLED_PATH'
  92. },
  93. 'HIVE_CLIENT': {
  94. installed_clients: 'INSTALLED_PATH'
  95. },
  96. 'FALCON_CLIENT': {
  97. installed_clients: 'INSTALLED_PATH'
  98. },
  99. 'OOZIE_CLIENT': {
  100. installed_clients: 'INSTALLED_PATH'
  101. },
  102. 'ZOOKEEPER_CLIENT': {
  103. installed_clients: 'INSTALLED_PATH'
  104. },
  105. 'PIG': {
  106. installed_clients: 'INSTALLED_PATH'
  107. },
  108. 'SQOOP': {
  109. installed_clients: 'INSTALLED_PATH'
  110. },
  111. 'YARN_CLIENT': {
  112. installed_clients: 'INSTALLED_PATH'
  113. },
  114. 'HDFS_CLIENT': {
  115. installed_clients: 'INSTALLED_PATH'
  116. },
  117. 'FLUME_HANDLER': {
  118. flume_handlers_total: 'TOTAL_PATH'
  119. }
  120. },
  121. /**
  122. * get formatted component config
  123. * @param componentName
  124. * @return {Object}
  125. */
  126. getComponentConfig: function (componentName) {
  127. var config = {};
  128. var componentConfig = this.get('configMap')[componentName];
  129. var paths = this.get('paths');
  130. for (var property in componentConfig) {
  131. if (paths[componentConfig[property]]) {
  132. config[property] = paths[componentConfig[property]];
  133. }
  134. }
  135. return config;
  136. },
  137. /**
  138. * get service extended model if it has one
  139. * @param serviceName
  140. * @return {Object|null}
  141. */
  142. getExtendedModel: function (serviceName) {
  143. if (App[App.Service.extendedModel[serviceName]]) {
  144. return App[App.Service.extendedModel[serviceName]].find(serviceName);
  145. }
  146. return null;
  147. },
  148. map: function (json) {
  149. console.time('App.componentsStateMapper execution time');
  150. var clients = [];
  151. var slaves = [];
  152. var masters = [];
  153. if (json.items) {
  154. json.items.forEach(function (item) {
  155. var componentConfig = this.getComponentConfig(item.ServiceComponentInfo.component_name);
  156. var parsedItem = this.parseIt(item, componentConfig);
  157. var service = App.Service.find(item.ServiceComponentInfo.service_name);
  158. var extendedModel = this.getExtendedModel(item.ServiceComponentInfo.service_name);
  159. var cacheService = App.cache['services'].findProperty('ServiceInfo.service_name', item.ServiceComponentInfo.service_name);
  160. if (item.ServiceComponentInfo.category === 'CLIENT') {
  161. item.host_names = item.host_components.mapProperty('HostRoles.host_name');
  162. clients.push(this.parseIt(item, this.clientMap));
  163. } else if (item.ServiceComponentInfo.category === 'SLAVE') {
  164. // for now map for slaves and clients are equal but it may vary in future.
  165. item.host_names = item.host_components.mapProperty('HostRoles.host_name');
  166. slaves.push(this.parseIt(item, this.clientMap));
  167. } else if (item.ServiceComponentInfo.category === 'MASTER') {
  168. item.host_names = item.host_components.mapProperty('HostRoles.host_name');
  169. masters.push(this.parseIt(item, this.clientMap));
  170. }
  171. if (cacheService) {
  172. cacheService.client_components = clients.filterProperty('service_name', cacheService.ServiceInfo.service_name).mapProperty('component_name');
  173. cacheService.slave_components = slaves.filterProperty('service_name', cacheService.ServiceInfo.service_name).mapProperty('component_name');
  174. cacheService.master_components = masters.filterProperty('service_name', cacheService.ServiceInfo.service_name).mapProperty('component_name');
  175. for (var i in parsedItem) {
  176. if (service.get('isLoaded')) {
  177. cacheService[i] = parsedItem[i];
  178. service.set(stringUtils.underScoreToCamelCase(i), parsedItem[i]);
  179. if (extendedModel && extendedModel.get('isLoaded')) {
  180. extendedModel.set(stringUtils.underScoreToCamelCase(i), parsedItem[i]);
  181. }
  182. }
  183. }
  184. }
  185. }, this)
  186. }
  187. App.store.loadMany(this.clientModel, clients);
  188. App.store.loadMany(this.slaveModel, slaves);
  189. App.store.loadMany(this.masterModel, masters);
  190. console.timeEnd('App.componentsStateMapper execution time');
  191. }
  192. });