update_controller.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. App.UpdateController = Em.Controller.extend({
  20. name: 'updateController',
  21. isUpdated: false,
  22. cluster: null,
  23. isWorking: false,
  24. timeIntervalId: null,
  25. clusterName: function () {
  26. return App.router.get('clusterController.clusterName');
  27. }.property('App.router.clusterController.clusterName'),
  28. location: function () {
  29. return App.router.get('location.lastSetURL');
  30. }.property('App.router.location.lastSetURL'),
  31. getUrl: function (testUrl, url) {
  32. return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
  33. },
  34. /**
  35. * Start polling, when <code>isWorking</code> become true
  36. */
  37. updateAll: function () {
  38. if (this.get('isWorking')) {
  39. App.updater.run(this, 'updateServices', 'isWorking');
  40. App.updater.run(this, 'updateHostConditionally', 'isWorking');
  41. App.updater.run(this, 'updateServiceMetricConditionally', 'isWorking', App.componentsUpdateInterval);
  42. App.updater.run(this, 'graphsUpdate', 'isWorking');
  43. if (App.supports.hostOverrides) {
  44. App.updater.run(this, 'updateComponentConfig', 'isWorking');
  45. }
  46. }
  47. }.observes('isWorking'),
  48. /**
  49. * Update hosts depending on which page is open
  50. * Make a call only on follow pages:
  51. * /main/hosts
  52. * /main/hosts/*
  53. * /main/charts/heatmap
  54. * @param callback
  55. */
  56. updateHostConditionally: function (callback) {
  57. if (/\/main\/(hosts|charts\/heatmap).*/.test(this.get('location'))) {
  58. this.updateHost(callback);
  59. } else {
  60. callback();
  61. }
  62. },
  63. /**
  64. * Update service metrics depending on which page is open
  65. * Make a call only on follow pages:
  66. * /main/dashboard
  67. * /main/services/*
  68. * @param callback
  69. */
  70. updateServiceMetricConditionally: function (callback) {
  71. if (/\/main\/(dashboard|services).*/.test(this.get('location'))) {
  72. this.updateServiceMetric(callback);
  73. } else {
  74. callback();
  75. }
  76. },
  77. updateHost: function (callback) {
  78. var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
  79. var hostsUrl = this.getUrl(testUrl, '/hosts?fields=Hosts/host_name,Hosts/host_status,Hosts/last_heartbeat_time,Hosts/disk_info,Hosts/maintenance_state,' +
  80. 'metrics/disk,metrics/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free' +
  81. '&minimal_response=true');
  82. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  83. complete: callback
  84. });
  85. },
  86. graphs: [],
  87. graphsUpdate: function (callback) {
  88. var existedGraphs = [];
  89. this.get('graphs').forEach(function (_graph) {
  90. var view = Em.View.views[_graph.id];
  91. if (view) {
  92. existedGraphs.push(_graph);
  93. //console.log('updated graph', _graph.name);
  94. view.loadData();
  95. //if graph opened as modal popup update it to
  96. if ($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  97. view.loadData();
  98. }
  99. }
  100. });
  101. callback();
  102. this.set('graphs', existedGraphs);
  103. },
  104. /**
  105. * Updates the services information.
  106. *
  107. * @param callback
  108. */
  109. updateServiceMetric: function (callback) {
  110. var self = this;
  111. self.set('isUpdated', false);
  112. var conditionalFields = this.getConditionalFields();
  113. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  114. var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/master_components.json' : '/data/dashboard/services.json';
  115. var isFlumeInstalled = App.cache['services'].mapProperty('ServiceInfo.service_name').contains('FLUME');
  116. var flumeHandlerParam = isFlumeInstalled ? 'ServiceComponentInfo/component_name=FLUME_HANDLER|' : '';
  117. var realUrl = '/components/?' + flumeHandlerParam +
  118. 'ServiceComponentInfo/category=MASTER&fields=' +
  119. 'ServiceComponentInfo/Version,' +
  120. 'ServiceComponentInfo/StartTime,' +
  121. 'ServiceComponentInfo/HeapMemoryUsed,' +
  122. 'ServiceComponentInfo/HeapMemoryMax,' +
  123. 'ServiceComponentInfo/service_name,' +
  124. 'host_components/HostRoles/host_name,' +
  125. 'host_components/HostRoles/state,' +
  126. 'host_components/HostRoles/maintenance_state,' +
  127. 'host_components/HostRoles/stale_configs,' +
  128. 'host_components/metrics/jvm/memHeapUsedM,' +
  129. 'host_components/metrics/jvm/HeapMemoryMax,' +
  130. 'host_components/metrics/jvm/HeapMemoryUsed,' +
  131. 'host_components/metrics/jvm/memHeapCommittedM,' +
  132. 'host_components/metrics/mapred/jobtracker/trackers_decommissioned,' +
  133. 'host_components/metrics/cpu/cpu_wio,' +
  134. 'host_components/metrics/rpc/RpcQueueTime_avg_time,' +
  135. 'host_components/metrics/dfs/FSNamesystem/*,' +
  136. 'host_components/metrics/dfs/namenode/Version,' +
  137. 'host_components/metrics/dfs/namenode/DecomNodes,' +
  138. 'host_components/metrics/dfs/namenode/TotalFiles,' +
  139. 'host_components/metrics/dfs/namenode/UpgradeFinalized,' +
  140. 'host_components/metrics/dfs/namenode/Safemode,' +
  141. 'host_components/metrics/runtime/StartTime' +
  142. conditionalFieldsString +
  143. '&minimal_response=true';
  144. var servicesUrl = this.getUrl(testUrl, realUrl);
  145. callback = callback || function () {
  146. self.set('isUpdated', true);
  147. };
  148. App.HttpClient.get(servicesUrl, App.serviceMetricsMapper, {
  149. complete: function () {
  150. callback();
  151. }
  152. });
  153. },
  154. /**
  155. * construct conditional parameters of query, depending on which services are installed
  156. * @return {Array}
  157. */
  158. getConditionalFields: function () {
  159. var conditionalFields = [];
  160. var serviceSpecificParams = {
  161. 'FLUME': "host_components/metrics/flume/flume," +
  162. "host_components/processes/HostComponentProcess",
  163. 'YARN': "host_components/metrics/yarn/Queue," +
  164. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  165. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  166. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  167. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount",
  168. 'HBASE': "host_components/metrics/hbase/master/IsActiveMaster," +
  169. "ServiceComponentInfo/MasterStartTime," +
  170. "ServiceComponentInfo/MasterActiveTime," +
  171. "ServiceComponentInfo/AverageLoad," +
  172. "ServiceComponentInfo/Revision," +
  173. "ServiceComponentInfo/RegionsInTransition",
  174. 'MAPREDUCE': "ServiceComponentInfo/AliveNodes," +
  175. "ServiceComponentInfo/GrayListedNodes," +
  176. "ServiceComponentInfo/BlackListedNodes," +
  177. "ServiceComponentInfo/jobtracker/*,",
  178. 'STORM': "metrics/api/cluster/summary,"
  179. };
  180. var services = App.cache['services'];
  181. services.forEach(function (service) {
  182. var urlParams = serviceSpecificParams[service.ServiceInfo.service_name];
  183. if (urlParams) {
  184. conditionalFields.push(urlParams);
  185. }
  186. });
  187. return conditionalFields;
  188. },
  189. updateServices: function (callback) {
  190. var testUrl = '/data/services/HDP2/services.json';
  191. var componentConfigUrl = this.getUrl(testUrl, '/services?fields=alerts/summary,ServiceInfo/state,ServiceInfo/maintenance_state&minimal_response=true');
  192. App.HttpClient.get(componentConfigUrl, App.serviceMapper, {
  193. complete: callback
  194. });
  195. },
  196. updateComponentConfig: function (callback) {
  197. var testUrl = '/data/services/host_component_stale_configs.json';
  198. var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/host_name&HostRoles/stale_configs=true&minimal_response=true');
  199. App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
  200. complete: callback
  201. });
  202. }
  203. });