update_controller.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. getUrl:function (testUrl, url) {
  29. return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
  30. },
  31. /**
  32. * Start polling, when <code>isWorking</code> become true
  33. */
  34. updateAll:function(){
  35. if(this.get('isWorking')) {
  36. App.updater.run(this, 'updateServices', 'isWorking');
  37. App.updater.run(this, 'updateHostConditionally', 'isWorking');
  38. App.updater.run(this, 'updateServiceMetricConditionally', 'isWorking', App.componentsUpdateInterval);
  39. App.updater.run(this, 'graphsUpdate', 'isWorking');
  40. if (App.supports.hostOverrides) {
  41. App.updater.run(this, 'updateComponentConfig', 'isWorking');
  42. }
  43. }
  44. }.observes('isWorking'),
  45. /**
  46. * Update hosts depending on which page is open
  47. * Make a call only on follow pages:
  48. * /main/hosts
  49. * /main/hosts/*
  50. * /main/charts/heatmap
  51. * @param callback
  52. */
  53. updateHostConditionally: function (callback) {
  54. var location = App.router.get('location.lastSetURL');
  55. if (/\/main\/(hosts|charts\/heatmap).*/.test(location)) {
  56. this.updateHost(callback);
  57. } else {
  58. callback();
  59. }
  60. },
  61. /**
  62. * Update service metrics depending on which page is open
  63. * Make a call only on follow pages:
  64. * /main/dashboard
  65. * /main/services/*
  66. * @param callback
  67. */
  68. updateServiceMetricConditionally: function(callback){
  69. var location = App.router.get('location.lastSetURL');
  70. if (/\/main\/(dashboard|services).*/.test(location)) {
  71. this.updateServiceMetric(callback);
  72. } else {
  73. callback();
  74. }
  75. },
  76. updateHost:function(callback) {
  77. var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
  78. var hostsUrl = this.getUrl(testUrl, '/hosts?fields=Hosts/host_name,Hosts/host_status,Hosts/last_heartbeat_time,Hosts/disk_info,Hosts/passive_state,' +
  79. 'metrics/disk,metrics/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free'+
  80. '&minimal_response=true');
  81. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  82. complete: callback
  83. });
  84. },
  85. graphs: [],
  86. graphsUpdate: function (callback) {
  87. var existedGraphs = [];
  88. this.get('graphs').forEach(function (_graph) {
  89. var view = Em.View.views[_graph.id];
  90. if (view) {
  91. existedGraphs.push(_graph);
  92. //console.log('updated graph', _graph.name);
  93. view.loadData();
  94. //if graph opened as modal popup update it to
  95. if($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  96. view.loadData();
  97. }
  98. }
  99. });
  100. callback();
  101. this.set('graphs', existedGraphs);
  102. },
  103. /**
  104. * Updates the services information.
  105. *
  106. * @param callback
  107. * @param isInitialLoad If true, only basic information is loaded.
  108. */
  109. updateServiceMetric: function (callback, isInitialLoad) {
  110. var self = this;
  111. self.set('isUpdated', false);
  112. var conditionalFields = [];
  113. var initialFields = [];
  114. var serviceSpecificParams = {
  115. 'FLUME': "host_components/metrics/flume/flume",
  116. 'YARN': "host_components/metrics/yarn/Queue," +
  117. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  118. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  119. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  120. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount",
  121. 'HBASE': "host_components/metrics/hbase/master/IsActiveMaster," +
  122. "ServiceComponentInfo/MasterStartTime," +
  123. "ServiceComponentInfo/MasterActiveTime," +
  124. "ServiceComponentInfo/AverageLoad," +
  125. "ServiceComponentInfo/Revision," +
  126. "ServiceComponentInfo/RegionsInTransition",
  127. 'MAPREDUCE': "ServiceComponentInfo/AliveNodes," +
  128. "ServiceComponentInfo/GrayListedNodes," +
  129. "ServiceComponentInfo/BlackListedNodes," +
  130. "ServiceComponentInfo/jobtracker/*,"
  131. };
  132. var services = App.cache['services'];
  133. services.forEach(function (service) {
  134. var urlParams = serviceSpecificParams[service.ServiceInfo.service_name];
  135. if (urlParams) {
  136. conditionalFields.push(urlParams);
  137. }
  138. });
  139. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  140. var initialFieldsString = initialFields.length > 0 ? ',' + initialFields.join(',') : '';
  141. var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/master_components.json':'/data/dashboard/services.json';
  142. var realUrl = '/components/?ServiceComponentInfo/category=MASTER&fields=' +
  143. 'ServiceComponentInfo/Version,' +
  144. 'ServiceComponentInfo/StartTime,' +
  145. 'ServiceComponentInfo/HeapMemoryUsed,' +
  146. 'ServiceComponentInfo/HeapMemoryMax,' +
  147. 'ServiceComponentInfo/service_name,' +
  148. 'host_components/HostRoles/host_name,' +
  149. 'host_components/HostRoles/state,' +
  150. 'host_components/HostRoles/passive_state,' +
  151. 'host_components/HostRoles/stale_configs,' +
  152. 'host_components/metrics/jvm/memHeapUsedM,' +
  153. 'host_components/metrics/jvm/HeapMemoryMax,' +
  154. 'host_components/metrics/jvm/HeapMemoryUsed,' +
  155. 'host_components/metrics/jvm/memHeapCommittedM,' +
  156. 'host_components/metrics/mapred/jobtracker/trackers_decommissioned,' +
  157. 'host_components/metrics/cpu/cpu_wio,' +
  158. 'host_components/metrics/rpc/RpcQueueTime_avg_time,' +
  159. 'host_components/metrics/dfs/FSNamesystem/*,' +
  160. 'host_components/metrics/dfs/namenode/Version,' +
  161. 'host_components/metrics/dfs/namenode/DecomNodes,' +
  162. 'host_components/metrics/dfs/namenode/TotalFiles,' +
  163. 'host_components/metrics/dfs/namenode/UpgradeFinalized,' +
  164. 'host_components/metrics/dfs/namenode/Safemode,' +
  165. 'host_components/metrics/runtime/StartTime' +
  166. conditionalFieldsString +
  167. '&minimal_response=true';
  168. var servicesUrl = isInitialLoad ? this.getUrl(testUrl, realUrl + initialFieldsString) : this.getUrl(testUrl, realUrl);
  169. callback = callback || function () {
  170. self.set('isUpdated', true);
  171. };
  172. App.HttpClient.get(servicesUrl, App.serviceMetricsMapper, {
  173. complete: function(){
  174. callback();
  175. }
  176. });
  177. },
  178. updateServices: function (callback) {
  179. var testUrl = '/data/services/HDP2/services.json';
  180. var componentConfigUrl = this.getUrl(testUrl, '/services?fields=alerts/summary,ServiceInfo/state,ServiceInfo/passive_state&minimal_response=true');
  181. App.HttpClient.get(componentConfigUrl, App.serviceMapper, {
  182. complete: callback
  183. });
  184. },
  185. updateComponentConfig: function (callback) {
  186. var testUrl = '/data/services/host_component_stale_configs.json';
  187. var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/host_name&HostRoles/stale_configs=true&minimal_response=true');
  188. App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
  189. complete: callback
  190. });
  191. }
  192. });