components_state_mapper.js 7.0 KB

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