update_controller.js 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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, 'updateHostConditionally', 'isWorking');
  37. App.updater.run(this, 'updateServiceMetricConditionally', 'isWorking', App.componentsUpdateInterval);
  38. App.updater.run(this, 'graphsUpdate', 'isWorking');
  39. if (App.supports.hostOverrides) {
  40. App.updater.run(this, 'updateComponentConfig', 'isWorking');
  41. }
  42. }
  43. }.observes('isWorking'),
  44. /**
  45. * Update hosts depending on which page is open
  46. * Make a call only on follow pages:
  47. * /main/hosts
  48. * /main/hosts/*
  49. * /main/charts/heatmap
  50. * @param callback
  51. */
  52. updateHostConditionally: function (callback) {
  53. var location = App.router.get('location.lastSetURL');
  54. if (/\/main\/(hosts|charts\/heatmap).*/.test(location)) {
  55. this.updateHost(callback);
  56. } else {
  57. callback();
  58. }
  59. },
  60. /**
  61. * Update service metrics depending on which page is open
  62. * Make a call only on follow pages:
  63. * /main/dashboard
  64. * /main/services/*
  65. * @param callback
  66. */
  67. updateServiceMetricConditionally: function(callback){
  68. var location = App.router.get('location.lastSetURL');
  69. if (/\/main\/(dashboard|services).*/.test(location)) {
  70. this.updateServiceMetric(callback);
  71. } else {
  72. callback();
  73. }
  74. },
  75. updateHost:function(callback) {
  76. var testUrl = App.get('isHadoop2Stack') ? '/data/hosts/HDP2/hosts.json' : '/data/hosts/hosts.json';
  77. var hostsUrl = this.getUrl(testUrl, '/hosts?fields=Hosts/host_name,Hosts/host_status,Hosts/last_heartbeat_time,Hosts/disk_info,' +
  78. 'metrics/disk,metrics/load/load_one,metrics/cpu/cpu_system,metrics/cpu/cpu_user,metrics/memory/mem_total,metrics/memory/mem_free');
  79. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  80. complete: callback
  81. });
  82. },
  83. graphs: [],
  84. graphsUpdate: function (callback) {
  85. var existedGraphs = [];
  86. this.get('graphs').forEach(function (_graph) {
  87. var view = Em.View.views[_graph.id];
  88. if (view) {
  89. existedGraphs.push(_graph);
  90. //console.log('updated graph', _graph.name);
  91. view.loadData();
  92. //if graph opened as modal popup update it to
  93. if($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  94. view.loadData();
  95. }
  96. }
  97. });
  98. callback();
  99. this.set('graphs', existedGraphs);
  100. },
  101. /**
  102. * Updates the services information.
  103. *
  104. * @param callback
  105. * @param isInitialLoad If true, only basic information is loaded.
  106. */
  107. updateServiceMetric: function (callback, isInitialLoad) {
  108. var self = this;
  109. self.set('isUpdated', false);
  110. var conditionalFields = [];
  111. var initialFields = [];
  112. var services = [
  113. {
  114. name: 'FLUME',
  115. urlParam: 'flume/flume'
  116. },
  117. {
  118. name: 'YARN',
  119. urlParam: 'yarn/Queue'
  120. },
  121. {
  122. name: 'HBASE',
  123. urlParam: 'hbase/master/IsActiveMaster'
  124. }
  125. ];
  126. services.forEach(function(service) {
  127. if (App.Service.find(service.name)) {
  128. conditionalFields.push("host_components/metrics/" + service.urlParam);
  129. }
  130. });
  131. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  132. var initialFieldsString = initialFields.length > 0 ? ',' + initialFields.join(',') : '';
  133. var methodStartTs = new Date().getTime();
  134. var testUrl = App.get('isHadoop2Stack') ? '/data/dashboard/HDP2/services.json':'/data/dashboard/services.json';
  135. var realUrl = '/components/?ServiceComponentInfo/category=MASTER' +
  136. '|ServiceComponentInfo/component_name=SQOOP|ServiceComponentInfo/component_name=HCAT|ServiceComponentInfo/component_name=PIG&fields=' +
  137. 'ServiceComponentInfo,' +
  138. 'host_components/HostRoles/state,' +
  139. 'host_components/HostRoles/stale_configs,' +
  140. 'host_components/metrics/jvm/memHeapUsedM,' +
  141. 'host_components/metrics/jvm/memMaxM,' +
  142. 'host_components/metrics/jvm/memHeapCommittedM,' +
  143. 'host_components/metrics/mapred/jobtracker/trackers_decommissioned,' +
  144. 'host_components/metrics/cpu/cpu_wio,' +
  145. 'host_components/metrics/rpc/RpcQueueTime_avg_time,' +
  146. 'host_components/metrics/dfs/FSNamesystem/HAState,' +
  147. 'host_components/metrics/dfs/FSNamesystem/CapacityUsed,' +
  148. 'host_components/metrics/dfs/FSNamesystem/CapacityTotal,' +
  149. 'host_components/metrics/dfs/FSNamesystem/CapacityRemaining,' +
  150. 'host_components/metrics/dfs/FSNamesystem/BlocksTotal,' +
  151. 'host_components/metrics/dfs/FSNamesystem/CorruptBlocks,' +
  152. 'host_components/metrics/dfs/FSNamesystem/MissingBlocks,' +
  153. 'host_components/metrics/dfs/FSNamesystem/UnderReplicatedBlocks,' +
  154. 'host_components/metrics/dfs/namenode/Version,' +
  155. 'host_components/metrics/dfs/namenode/LiveNodes,' +
  156. 'host_components/metrics/dfs/namenode/DeadNodes,' +
  157. 'host_components/metrics/dfs/namenode/DecomNodes,' +
  158. 'host_components/metrics/dfs/namenode/TotalFiles,' +
  159. 'host_components/metrics/dfs/namenode/UpgradeFinalized,' +
  160. 'host_components/metrics/dfs/namenode/Safemode,' +
  161. 'host_components/metrics/runtime/StartTime' +
  162. conditionalFieldsString;
  163. var servicesUrl = isInitialLoad ? this.getUrl(testUrl, realUrl + initialFieldsString) : this.getUrl(testUrl, realUrl);
  164. var callback = callback || function (jqXHR, textStatus) {
  165. self.set('isUpdated', true);
  166. };
  167. App.HttpClient.get(servicesUrl, App.servicesMapper, {
  168. complete: function(){
  169. console.log("UpdateServiceMetric() Finished in:"+ (new Date().getTime()-methodStartTs) + " ms");
  170. callback();
  171. }
  172. });
  173. },
  174. updateComponentConfig: function (callback) {
  175. var testUrl = '/data/services/host_component_stale_configs.json';
  176. var componentConfigUrl = this.getUrl(testUrl, '/host_components?fields=HostRoles/component_name&HostRoles/stale_configs=true');
  177. App.HttpClient.get(componentConfigUrl, App.componentConfigMapper, {
  178. complete: callback
  179. });
  180. }
  181. });