update_controller.js 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. * construct URL from real URL and query parameters
  36. * @param testUrl
  37. * @param realUrl
  38. * @param queryParams
  39. * @return {String}
  40. */
  41. getComplexUrl: function (testUrl, realUrl, queryParams) {
  42. var url = App.apiPrefix + '/clusters/' + App.get('clusterName');
  43. var params = '';
  44. if (App.testMode) {
  45. url = testUrl;
  46. } else {
  47. if (queryParams) {
  48. queryParams.forEach(function (param) {
  49. params += param.key + '=' + param.value + '&';
  50. });
  51. }
  52. url += realUrl.replace('<parameters>', params);
  53. }
  54. return url;
  55. },
  56. /**
  57. * depict query parameters of table
  58. */
  59. queryParams: Em.Object.create({
  60. 'Hosts': []
  61. }),
  62. /**
  63. * map describes relations between updater function and table
  64. */
  65. tableUpdaterMap: {
  66. 'Hosts': 'updateHost'
  67. },
  68. /**
  69. * Start polling, when <code>isWorking</code> become true
  70. */
  71. updateAll: function () {
  72. if (this.get('isWorking')) {
  73. App.updater.run(this, 'updateServices', 'isWorking');
  74. App.updater.run(this, 'updateHostConditionally', 'isWorking');
  75. App.updater.run(this, 'updateServiceMetricConditionally', 'isWorking', App.componentsUpdateInterval);
  76. App.updater.run(this, 'updateComponentsState', 'isWorking', App.componentsUpdateInterval);
  77. App.updater.run(this, 'graphsUpdate', 'isWorking');
  78. if (App.supports.hostOverrides) {
  79. App.updater.run(this, 'updateComponentConfig', 'isWorking');
  80. }
  81. }
  82. }.observes('isWorking'),
  83. /**
  84. * Update hosts depending on which page is open
  85. * Make a call only on follow pages:
  86. * /main/hosts
  87. * /main/hosts/*
  88. * /main/charts/heatmap
  89. * @param callback
  90. */
  91. updateHostConditionally: function (callback) {
  92. if (/\/main\/(hosts|charts\/heatmap).*/.test(this.get('location'))) {
  93. this.updateHost(callback);
  94. } else {
  95. callback();
  96. }
  97. },
  98. /**
  99. * Update service metrics depending on which page is open
  100. * Make a call only on follow pages:
  101. * /main/dashboard
  102. * /main/services/*
  103. * @param callback
  104. */
  105. updateServiceMetricConditionally: function (callback) {
  106. if (/\/main\/(dashboard|services).*/.test(this.get('location'))) {
  107. this.updateServiceMetric(callback);
  108. } else {
  109. callback();
  110. }
  111. },
  112. updateHost: function (callback) {
  113. var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
  114. var realUrl = '/hosts?<parameters>fields=Hosts/host_name,Hosts/maintenance_state,Hosts/public_host_name,Hosts/cpu_count,Hosts/ph_cpu_count,Hosts/total_mem,' +
  115. 'Hosts/host_status,Hosts/last_heartbeat_time,Hosts/os_arch,Hosts/os_type,Hosts/ip,host_components/HostRoles/state,host_components/HostRoles/maintenance_state,' +
  116. 'Hosts/disk_info,metrics/disk,metrics/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,' +
  117. 'metrics/memory/mem_total,metrics/memory/mem_free,alerts/summary&minimal_response=true';
  118. var hostsUrl = this.getComplexUrl(testUrl, realUrl, this.get('queryParams.Hosts'));
  119. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  120. complete: callback
  121. });
  122. },
  123. graphs: [],
  124. graphsUpdate: function (callback) {
  125. var existedGraphs = [];
  126. this.get('graphs').forEach(function (_graph) {
  127. var view = Em.View.views[_graph.id];
  128. if (view) {
  129. existedGraphs.push(_graph);
  130. //console.log('updated graph', _graph.name);
  131. view.loadData();
  132. //if graph opened as modal popup update it to
  133. if ($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  134. view.loadData();
  135. }
  136. }
  137. });
  138. callback();
  139. this.set('graphs', existedGraphs);
  140. },
  141. /**
  142. * Updates the services information.
  143. *
  144. * @param callback
  145. */
  146. updateServiceMetric: function (callback) {
  147. var self = this;
  148. self.set('isUpdated', false);
  149. var conditionalFields = this.getConditionalFields();
  150. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  151. var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/master_components.json' : '/data/dashboard/services.json';
  152. var isFlumeInstalled = App.cache['services'].mapProperty('ServiceInfo.service_name').contains('FLUME');
  153. var flumeHandlerParam = isFlumeInstalled ? 'ServiceComponentInfo/component_name=FLUME_HANDLER|' : '';
  154. var realUrl = '/components/?' + flumeHandlerParam +
  155. 'ServiceComponentInfo/category=MASTER&fields=' +
  156. 'ServiceComponentInfo/Version,' +
  157. 'ServiceComponentInfo/StartTime,' +
  158. 'ServiceComponentInfo/HeapMemoryUsed,' +
  159. 'ServiceComponentInfo/HeapMemoryMax,' +
  160. 'ServiceComponentInfo/service_name,' +
  161. 'host_components/HostRoles/host_name,' +
  162. 'host_components/HostRoles/state,' +
  163. 'host_components/HostRoles/maintenance_state,' +
  164. 'host_components/HostRoles/stale_configs,' +
  165. 'host_components/metrics/jvm/memHeapUsedM,' +
  166. 'host_components/metrics/jvm/HeapMemoryMax,' +
  167. 'host_components/metrics/jvm/HeapMemoryUsed,' +
  168. 'host_components/metrics/jvm/memHeapCommittedM,' +
  169. 'host_components/metrics/mapred/jobtracker/trackers_decommissioned,' +
  170. 'host_components/metrics/cpu/cpu_wio,' +
  171. 'host_components/metrics/rpc/RpcQueueTime_avg_time,' +
  172. 'host_components/metrics/dfs/FSNamesystem/*,' +
  173. 'host_components/metrics/dfs/namenode/Version,' +
  174. 'host_components/metrics/dfs/namenode/DecomNodes,' +
  175. 'host_components/metrics/dfs/namenode/TotalFiles,' +
  176. 'host_components/metrics/dfs/namenode/UpgradeFinalized,' +
  177. 'host_components/metrics/dfs/namenode/Safemode,' +
  178. 'host_components/metrics/runtime/StartTime' +
  179. conditionalFieldsString +
  180. '&minimal_response=true';
  181. var servicesUrl = this.getUrl(testUrl, realUrl);
  182. callback = callback || function () {
  183. self.set('isUpdated', true);
  184. };
  185. App.HttpClient.get(servicesUrl, App.serviceMetricsMapper, {
  186. complete: function () {
  187. callback();
  188. }
  189. });
  190. },
  191. /**
  192. * construct conditional parameters of query, depending on which services are installed
  193. * @return {Array}
  194. */
  195. getConditionalFields: function () {
  196. var conditionalFields = [];
  197. var serviceSpecificParams = {
  198. 'FLUME': "host_components/metrics/flume/flume," +
  199. "host_components/processes/HostComponentProcess",
  200. 'YARN': "host_components/metrics/yarn/Queue," +
  201. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  202. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  203. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  204. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount",
  205. 'HBASE': "host_components/metrics/hbase/master/IsActiveMaster," +
  206. "ServiceComponentInfo/MasterStartTime," +
  207. "ServiceComponentInfo/MasterActiveTime," +
  208. "ServiceComponentInfo/AverageLoad," +
  209. "ServiceComponentInfo/Revision," +
  210. "ServiceComponentInfo/RegionsInTransition",
  211. 'MAPREDUCE': "ServiceComponentInfo/AliveNodes," +
  212. "ServiceComponentInfo/GrayListedNodes," +
  213. "ServiceComponentInfo/BlackListedNodes," +
  214. "ServiceComponentInfo/jobtracker/*,",
  215. 'STORM': "metrics/api/cluster/summary,"
  216. };
  217. var services = App.cache['services'];
  218. services.forEach(function (service) {
  219. var urlParams = serviceSpecificParams[service.ServiceInfo.service_name];
  220. if (urlParams) {
  221. conditionalFields.push(urlParams);
  222. }
  223. });
  224. return conditionalFields;
  225. },
  226. updateServices: function (callback) {
  227. var testUrl = '/data/services/HDP2/services.json';
  228. var componentConfigUrl = this.getUrl(testUrl, '/services?fields=alerts/summary,ServiceInfo/state,ServiceInfo/maintenance_state&minimal_response=true');
  229. App.HttpClient.get(componentConfigUrl, App.serviceMapper, {
  230. complete: callback
  231. });
  232. },
  233. updateComponentConfig: function (callback) {
  234. var testUrl = '/data/services/host_component_stale_configs.json';
  235. var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/host_name&HostRoles/stale_configs=true&minimal_response=true');
  236. App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
  237. complete: callback
  238. });
  239. },
  240. updateComponentsState: function (callback) {
  241. var testUrl = '/data/services/HDP2/components_state.json';
  242. var realUrl = '/components/?ServiceComponentInfo/category.in(SLAVE,CLIENT)&fields=ServiceComponentInfo/service_name,' +
  243. 'ServiceComponentInfo/installed_count,ServiceComponentInfo/started_count,ServiceComponentInfo/total_count&minimal_response=true';
  244. var url = this.getUrl(testUrl, realUrl);
  245. App.HttpClient.get(url, App.componentsStateMapper, {
  246. complete: callback
  247. });
  248. }
  249. });