update_controller.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. 'alerts/summary&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 services = [
  115. {
  116. name: 'FLUME',
  117. urlParam: 'flume/flume'
  118. },
  119. {
  120. name: 'YARN',
  121. urlParam: 'yarn/Queue'
  122. },
  123. {
  124. name: 'HBASE',
  125. urlParam: 'hbase/master/IsActiveMaster'
  126. }
  127. ];
  128. services.forEach(function(service) {
  129. if (App.Service.find(service.name)) {
  130. conditionalFields.push("host_components/metrics/" + service.urlParam);
  131. }
  132. });
  133. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  134. var initialFieldsString = initialFields.length > 0 ? ',' + initialFields.join(',') : '';
  135. var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/master_components.json':'/data/dashboard/services.json';
  136. var realUrl = '/components/?ServiceComponentInfo/category=MASTER&fields=' +
  137. 'ServiceComponentInfo,' +
  138. 'host_components/HostRoles/state,' +
  139. 'host_components/HostRoles/passive_state,' +
  140. 'host_components/HostRoles/stale_configs,' +
  141. 'host_components/metrics/jvm/memHeapUsedM,' +
  142. 'host_components/metrics/jvm/HeapMemoryMax,' +
  143. 'host_components/metrics/jvm/HeapMemoryUsed,' +
  144. 'host_components/metrics/jvm/memHeapCommittedM,' +
  145. 'host_components/metrics/mapred/jobtracker/trackers_decommissioned,' +
  146. 'host_components/metrics/cpu/cpu_wio,' +
  147. 'host_components/metrics/rpc/RpcQueueTime_avg_time,' +
  148. 'host_components/metrics/dfs/FSNamesystem/HAState,' +
  149. 'host_components/metrics/dfs/FSNamesystem/CapacityUsed,' +
  150. 'host_components/metrics/dfs/FSNamesystem/CapacityTotal,' +
  151. 'host_components/metrics/dfs/FSNamesystem/CapacityRemaining,' +
  152. 'host_components/metrics/dfs/FSNamesystem/BlocksTotal,' +
  153. 'host_components/metrics/dfs/FSNamesystem/CorruptBlocks,' +
  154. 'host_components/metrics/dfs/FSNamesystem/MissingBlocks,' +
  155. 'host_components/metrics/dfs/FSNamesystem/UnderReplicatedBlocks,' +
  156. 'host_components/metrics/dfs/namenode/Version,' +
  157. 'host_components/metrics/dfs/namenode/LiveNodes,' +
  158. 'host_components/metrics/dfs/namenode/DeadNodes,' +
  159. 'host_components/metrics/dfs/namenode/DecomNodes,' +
  160. 'host_components/metrics/dfs/namenode/TotalFiles,' +
  161. 'host_components/metrics/dfs/namenode/UpgradeFinalized,' +
  162. 'host_components/metrics/dfs/namenode/Safemode,' +
  163. 'host_components/metrics/runtime/StartTime' +
  164. conditionalFieldsString;
  165. var servicesUrl = isInitialLoad ? this.getUrl(testUrl, realUrl + initialFieldsString) : this.getUrl(testUrl, realUrl);
  166. callback = callback || function () {
  167. self.set('isUpdated', true);
  168. };
  169. App.HttpClient.get(servicesUrl, App.serviceMetricsMapper, {
  170. complete: function(){
  171. callback();
  172. }
  173. });
  174. },
  175. updateServices: function (callback) {
  176. var testUrl = '/data/services/HDP2/services.json';
  177. var componentConfigUrl = this.getUrl(testUrl, '/services?fields=alerts/summary,ServiceInfo/state&minimal_response=true');
  178. App.HttpClient.get(componentConfigUrl, App.serviceMapper, {
  179. complete: callback
  180. });
  181. },
  182. updateComponentConfig: function (callback) {
  183. var testUrl = '/data/services/host_component_stale_configs.json';
  184. var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/host_name&HostRoles/stale_configs=true&minimal_response=true');
  185. App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
  186. complete: callback
  187. });
  188. }
  189. });