status_mapper.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. App.statusMapper = App.QuickDataMapper.create({
  19. model: App.HostComponent,
  20. componentServiceMap: {
  21. 'NAMENODE': 'HDFS',
  22. 'SECONDARY_NAMENODE': 'HDFS',
  23. 'DATANODE': 'HDFS',
  24. 'HDFS_CLIENT': 'HDFS',
  25. 'JOBTRACKER': 'MAPREDUCE',
  26. 'TASKTRACKER': 'MAPREDUCE',
  27. 'MAPREDUCE_CLIENT': 'MAPREDUCE',
  28. 'MAPREDUCE2_CLIENT': 'MAPREDUCE2',
  29. 'HISTORYSERVER': 'MAPREDUCE2',
  30. 'TEZ_CLIENT': 'TEZ',
  31. 'RESOURCEMANAGER': 'YARN',
  32. 'YARN_CLIENT': 'YARN',
  33. 'NODEMANAGER': 'YARN',
  34. 'ZOOKEEPER_SERVER': 'ZOOKEEPER',
  35. 'ZOOKEEPER_CLIENT': 'ZOOKEEPER',
  36. 'HBASE_MASTER': 'HBASE',
  37. 'HBASE_REGIONSERVER': 'HBASE',
  38. 'HBASE_CLIENT': 'HBASE',
  39. 'PIG': 'PIG',
  40. 'SQOOP': 'SQOOP',
  41. 'OOZIE_SERVER': 'OOZIE',
  42. 'OOZIE_CLIENT': 'OOZIE',
  43. 'HIVE_SERVER': 'HIVE',
  44. 'HIVE_METASTORE': 'HIVE',
  45. 'HIVE_CLIENT': 'HIVE',
  46. 'MYSQL_SERVER': 'HIVE',
  47. 'HCAT': 'HCATALOG',
  48. 'WEBHCAT_SERVER': 'WEBHCAT',
  49. 'NAGIOS_SERVER': 'NAGIOS',
  50. 'GANGLIA_SERVER': 'GANGLIA',
  51. 'GANGLIA_MONITOR': 'GANGLIA',
  52. 'KERBEROS_SERVER': 'KERBEROS',
  53. 'KERBEROS_ADMIN_CLIENT': 'KERBEROS',
  54. 'KERBEROS_CLIENT': 'KERBEROS',
  55. 'HUE_SERVER': 'HUE',
  56. 'HCFS_CLIENT': 'HCFS'
  57. },
  58. map: function (json) {
  59. console.time('App.statusMapper execution time');
  60. if (json.items) {
  61. var hostsCache = App.cache['Hosts'];
  62. var hostStatuses = {};
  63. var hostComponentStatuses = {};
  64. var addedHostComponents = [];
  65. var componentServiceMap = this.get('componentServiceMap');
  66. var currentComponentStatuses = {};
  67. var currentHostStatuses = {};
  68. var previousHostStatuses = App.cache['previousHostStatuses'];
  69. var previousComponentStatuses = App.cache['previousComponentStatuses'];
  70. var hostComponentsOnService = {};
  71. json.items.forEach(function (host) {
  72. //update hosts, which have status changed
  73. if (previousHostStatuses[host.Hosts.host_name] !== host.Hosts.host_status) {
  74. hostStatuses[host.Hosts.host_name] = host.Hosts.host_status;
  75. }
  76. currentHostStatuses[host.Hosts.host_name] = host.Hosts.host_status;
  77. var hostComponentsOnHost = [];
  78. host.host_components.forEach(function (host_component) {
  79. host_component.id = host_component.HostRoles.component_name + "_" + host_component.HostRoles.host_name;
  80. var existedComponent = previousComponentStatuses[host_component.id];
  81. var service = componentServiceMap[host_component.HostRoles.component_name];
  82. if (existedComponent) {
  83. //update host-components, which have status changed
  84. if (existedComponent !== host_component.HostRoles.state) {
  85. hostComponentStatuses[host_component.id] = host_component.HostRoles.state;
  86. }
  87. } else {
  88. addedHostComponents.push({
  89. id: host_component.id,
  90. component_name: host_component.HostRoles.component_name,
  91. work_status: host_component.HostRoles.state,
  92. host_id: host.Hosts.host_name,
  93. service_id: service
  94. });
  95. //update host-components only on adding due to Ember Data features
  96. if (hostsCache[host.Hosts.host_name]) hostsCache[host.Hosts.host_name].is_modified = true;
  97. }
  98. currentComponentStatuses[host_component.id] = host_component.HostRoles.state;
  99. //host-components to host relations
  100. hostComponentsOnHost.push(host_component.id);
  101. //host-component to service relations
  102. if (!hostComponentsOnService[service]) {
  103. hostComponentsOnService[service] = {
  104. host_components: [],
  105. running_host_components: [],
  106. unknown_host_components: []
  107. };
  108. }
  109. if (host_component.HostRoles.state === App.HostComponentStatus.started) {
  110. hostComponentsOnService[service].running_host_components.push(host_component.id);
  111. }
  112. if (host_component.HostRoles.state === App.HostComponentStatus.unknown) {
  113. hostComponentsOnService[service].unknown_host_components.push(host_component.id);
  114. }
  115. hostComponentsOnService[service].host_components.push(host_component.id);
  116. }, this);
  117. /**
  118. * updating relation between Host and his host-components
  119. */
  120. if (hostsCache[host.Hosts.host_name]) {
  121. hostsCache[host.Hosts.host_name].host_components = hostComponentsOnHost;
  122. }
  123. }, this);
  124. var hostComponents = App.HostComponent.find();
  125. var hosts = App.Host.find();
  126. hostComponents.forEach(function (hostComponent) {
  127. if (hostComponent) {
  128. var status = currentComponentStatuses[hostComponent.get('id')];
  129. //check whether component present in current response
  130. if (status) {
  131. //check whether component has status changed
  132. if (hostComponentStatuses[hostComponent.get('id')]) {
  133. hostComponent.set('workStatus', status);
  134. }
  135. } else {
  136. hostComponent.deleteRecord();
  137. App.store.commit();
  138. hostComponent.get('stateManager').transitionTo('loading');
  139. }
  140. }
  141. }, this);
  142. if (addedHostComponents.length) {
  143. App.store.loadMany(this.get('model'), addedHostComponents);
  144. }
  145. App.cache['previousHostStatuses'] = currentHostStatuses;
  146. App.cache['previousComponentStatuses'] = currentComponentStatuses;
  147. App.cache['hostComponentsOnService'] = hostComponentsOnService;
  148. hosts.forEach(function (host) {
  149. var status = hostStatuses[host.get('id')];
  150. if (status) {
  151. host.set('healthStatus', status);
  152. }
  153. });
  154. }
  155. console.timeEnd('App.statusMapper execution time');
  156. }
  157. });