update_controller.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 realUrl = '/components/?ServiceComponentInfo/category=MASTER&fields=' +
  116. 'ServiceComponentInfo/Version,' +
  117. 'ServiceComponentInfo/StartTime,' +
  118. 'ServiceComponentInfo/HeapMemoryUsed,' +
  119. 'ServiceComponentInfo/HeapMemoryMax,' +
  120. 'ServiceComponentInfo/service_name,' +
  121. 'host_components/HostRoles/host_name,' +
  122. 'host_components/HostRoles/state,' +
  123. 'host_components/HostRoles/maintenance_state,' +
  124. 'host_components/HostRoles/stale_configs,' +
  125. 'host_components/metrics/jvm/memHeapUsedM,' +
  126. 'host_components/metrics/jvm/HeapMemoryMax,' +
  127. 'host_components/metrics/jvm/HeapMemoryUsed,' +
  128. 'host_components/metrics/jvm/memHeapCommittedM,' +
  129. 'host_components/metrics/mapred/jobtracker/trackers_decommissioned,' +
  130. 'host_components/metrics/cpu/cpu_wio,' +
  131. 'host_components/metrics/rpc/RpcQueueTime_avg_time,' +
  132. 'host_components/metrics/dfs/FSNamesystem/*,' +
  133. 'host_components/metrics/dfs/namenode/Version,' +
  134. 'host_components/metrics/dfs/namenode/DecomNodes,' +
  135. 'host_components/metrics/dfs/namenode/TotalFiles,' +
  136. 'host_components/metrics/dfs/namenode/UpgradeFinalized,' +
  137. 'host_components/metrics/dfs/namenode/Safemode,' +
  138. 'host_components/metrics/runtime/StartTime' +
  139. conditionalFieldsString +
  140. '&minimal_response=true';
  141. var servicesUrl = this.getUrl(testUrl, realUrl);
  142. callback = callback || function () {
  143. self.set('isUpdated', true);
  144. };
  145. App.HttpClient.get(servicesUrl, App.serviceMetricsMapper, {
  146. complete: function () {
  147. callback();
  148. }
  149. });
  150. },
  151. /**
  152. * construct conditional parameters of query, depending on which services are installed
  153. * @return {Array}
  154. */
  155. getConditionalFields: function () {
  156. var conditionalFields = [];
  157. var serviceSpecificParams = {
  158. 'FLUME': "host_components/metrics/flume/flume",
  159. 'YARN': "host_components/metrics/yarn/Queue," +
  160. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  161. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  162. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  163. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount",
  164. 'HBASE': "host_components/metrics/hbase/master/IsActiveMaster," +
  165. "ServiceComponentInfo/MasterStartTime," +
  166. "ServiceComponentInfo/MasterActiveTime," +
  167. "ServiceComponentInfo/AverageLoad," +
  168. "ServiceComponentInfo/Revision," +
  169. "ServiceComponentInfo/RegionsInTransition",
  170. 'MAPREDUCE': "ServiceComponentInfo/AliveNodes," +
  171. "ServiceComponentInfo/GrayListedNodes," +
  172. "ServiceComponentInfo/BlackListedNodes," +
  173. "ServiceComponentInfo/jobtracker/*,",
  174. 'STORM': "metrics/api/cluster/summary,"
  175. };
  176. var services = App.cache['services'];
  177. services.forEach(function (service) {
  178. var urlParams = serviceSpecificParams[service.ServiceInfo.service_name];
  179. if (urlParams) {
  180. conditionalFields.push(urlParams);
  181. }
  182. });
  183. return conditionalFields;
  184. },
  185. updateServices: function (callback) {
  186. var testUrl = '/data/services/HDP2/services.json';
  187. var componentConfigUrl = this.getUrl(testUrl, '/services?fields=alerts/summary,ServiceInfo/state,ServiceInfo/maintenance_state&minimal_response=true');
  188. App.HttpClient.get(componentConfigUrl, App.serviceMapper, {
  189. complete: callback
  190. });
  191. },
  192. updateComponentConfig: function (callback) {
  193. var testUrl = '/data/services/host_component_stale_configs.json';
  194. var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/host_name&HostRoles/stale_configs=true&minimal_response=true');
  195. App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
  196. complete: callback
  197. });
  198. }
  199. });