components_state_mapper.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. 'HBASE_REGIONSERVER': {
  63. region_servers_started: 'STARTED_PATH',
  64. region_servers_installed: 'INSTALLED_PATH',
  65. region_servers_total: 'TOTAL_PATH'
  66. },
  67. 'PHOENIX_QUERY_SERVER': {
  68. phoenix_servers_started: 'STARTED_PATH',
  69. phoenix_servers_installed: 'INSTALLED_PATH',
  70. phoenix_servers_total: 'TOTAL_PATH'
  71. },
  72. 'GANGLIA_MONITOR': {
  73. ganglia_monitors_started: 'STARTED_PATH',
  74. ganglia_monitors_installed: 'INSTALLED_PATH',
  75. ganglia_monitors_total: 'TOTAL_PATH'
  76. },
  77. 'SUPERVISOR': {
  78. super_visors_started: 'STARTED_PATH',
  79. super_visors_installed: 'INSTALLED_PATH',
  80. super_visors_total: 'TOTAL_PATH'
  81. },
  82. 'MAPREDUCE2_CLIENT': {
  83. map_reduce2_clients: 'INSTALLED_PATH'
  84. },
  85. 'TEZ_CLIENT': {
  86. installed_clients: 'INSTALLED_PATH'
  87. },
  88. 'HIVE_CLIENT': {
  89. installed_clients: 'INSTALLED_PATH'
  90. },
  91. 'FALCON_CLIENT': {
  92. installed_clients: 'INSTALLED_PATH'
  93. },
  94. 'OOZIE_CLIENT': {
  95. installed_clients: 'INSTALLED_PATH'
  96. },
  97. 'ZOOKEEPER_CLIENT': {
  98. installed_clients: 'INSTALLED_PATH'
  99. },
  100. 'PIG': {
  101. installed_clients: 'INSTALLED_PATH'
  102. },
  103. 'SQOOP': {
  104. installed_clients: 'INSTALLED_PATH'
  105. },
  106. 'YARN_CLIENT': {
  107. installed_clients: 'INSTALLED_PATH'
  108. },
  109. 'HDFS_CLIENT': {
  110. installed_clients: 'INSTALLED_PATH'
  111. },
  112. 'FLUME_HANDLER': {
  113. flume_handlers_total: 'TOTAL_PATH'
  114. }
  115. },
  116. /**
  117. * get formatted component config
  118. * @param componentName
  119. * @return {Object}
  120. */
  121. getComponentConfig: function (componentName) {
  122. var config = {};
  123. var componentConfig = this.get('configMap')[componentName];
  124. var paths = this.get('paths');
  125. for (var property in componentConfig) {
  126. if (paths[componentConfig[property]]) {
  127. config[property] = paths[componentConfig[property]];
  128. }
  129. }
  130. return config;
  131. },
  132. /**
  133. * get service extended model if it has one
  134. * @param serviceName
  135. * @return {Object|null}
  136. */
  137. getExtendedModel: function (serviceName) {
  138. if (App[App.Service.extendedModel[serviceName]]) {
  139. return App[App.Service.extendedModel[serviceName]].find(serviceName);
  140. }
  141. return null;
  142. },
  143. map: function (json) {
  144. console.time('App.componentsStateMapper execution time');
  145. var clients = [];
  146. var slaves = [];
  147. var masters = [];
  148. if (json.items) {
  149. json.items.forEach(function (item) {
  150. var componentConfig = this.getComponentConfig(item.ServiceComponentInfo.component_name);
  151. var parsedItem = this.parseIt(item, componentConfig);
  152. var service = App.Service.find(item.ServiceComponentInfo.service_name);
  153. var extendedModel = this.getExtendedModel(item.ServiceComponentInfo.service_name);
  154. var cacheService = App.cache['services'].findProperty('ServiceInfo.service_name', item.ServiceComponentInfo.service_name);
  155. if (item.ServiceComponentInfo.category === 'CLIENT') {
  156. item.host_names = item.host_components.mapProperty('HostRoles.host_name');
  157. clients.push(this.parseIt(item, this.clientMap));
  158. } else if (item.ServiceComponentInfo.category === 'SLAVE') {
  159. // for now map for slaves and clients are equal but it may vary in future.
  160. item.host_names = item.host_components.mapProperty('HostRoles.host_name');
  161. slaves.push(this.parseIt(item, this.clientMap));
  162. } else if (item.ServiceComponentInfo.category === 'MASTER') {
  163. item.host_names = item.host_components.mapProperty('HostRoles.host_name');
  164. masters.push(this.parseIt(item, this.clientMap));
  165. }
  166. if (cacheService) {
  167. cacheService.client_components = clients.filterProperty('service_name', cacheService.ServiceInfo.service_name).mapProperty('component_name');
  168. cacheService.slave_components = slaves.filterProperty('service_name', cacheService.ServiceInfo.service_name).mapProperty('component_name');
  169. cacheService.master_components = masters.filterProperty('service_name', cacheService.ServiceInfo.service_name).mapProperty('component_name');
  170. for (var i in parsedItem) {
  171. if (service.get('isLoaded')) {
  172. cacheService[i] = parsedItem[i];
  173. service.set(stringUtils.underScoreToCamelCase(i), parsedItem[i]);
  174. if (extendedModel && extendedModel.get('isLoaded')) {
  175. extendedModel.set(stringUtils.underScoreToCamelCase(i), parsedItem[i]);
  176. }
  177. }
  178. }
  179. }
  180. }, this)
  181. }
  182. App.store.loadMany(this.clientModel, clients);
  183. App.store.loadMany(this.slaveModel, slaves);
  184. App.store.loadMany(this.masterModel, masters);
  185. console.timeEnd('App.componentsStateMapper execution time');
  186. }
  187. });