update_controller.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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, 'updateHost', 'isWorking');
  37. App.updater.run(this, 'updateServiceMetric', 'isWorking');
  38. App.updater.run(this, 'graphsUpdate', 'isWorking');
  39. }
  40. }.observes('isWorking'),
  41. updateHost:function(callback) {
  42. var self = this;
  43. var testUrl = App.testHadoop2Stack ? '/data/hosts/HDP2/hosts.json':'/data/hosts/hosts.json';
  44. var hostsUrl = this.getUrl(testUrl, '/hosts?fields=Hosts/host_name,Hosts/public_host_name,Hosts/disk_info,Hosts/cpu_count,Hosts/total_mem,Hosts/host_status,Hosts/last_heartbeat_time,Hosts/os_arch,Hosts/os_type,Hosts/ip,host_components,metrics/disk,metrics/load/load_one');
  45. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  46. complete: callback
  47. });
  48. },
  49. graphs: [],
  50. graphsUpdate: function (callback) {
  51. var existedGraphs = [];
  52. this.get('graphs').forEach(function (_graph) {
  53. var view = Em.View.views[_graph.id];
  54. if (view) {
  55. existedGraphs.push(_graph);
  56. //console.log('updated graph', _graph.name);
  57. view.loadData();
  58. //if graph opened as modal popup update it to
  59. if($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  60. view.loadData();
  61. }
  62. }
  63. });
  64. callback();
  65. this.set('graphs', existedGraphs);
  66. },
  67. /**
  68. * Updates the services information.
  69. *
  70. * @param callback
  71. * @param isInitialLoad If true, only basic information is loaded.
  72. */
  73. updateServiceMetric: function (callback, isInitialLoad) {
  74. var self = this;
  75. self.set('isUpdated', false);
  76. var conditionalFields = [];
  77. var services = [
  78. {
  79. name: 'FLUME',
  80. urlParam: 'flume/flume'
  81. },
  82. {
  83. name: 'YARN',
  84. urlParam: 'yarn/Queue'
  85. }
  86. ];
  87. services.forEach(function(service) {
  88. if (App.Service.find(service.name)) {
  89. conditionalFields.push("components/host_components/metrics/" + service.urlParam);
  90. }
  91. });
  92. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  93. var methodStartTs = new Date().getTime();
  94. var testUrl = App.testHadoop2Stack ? '/data/dashboard/HDP2/services.json':'/data/dashboard/services.json';
  95. var servicesUrl = isInitialLoad ?
  96. //this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles') :
  97. this.getUrl(testUrl, '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles,components/host_components/metrics/jvm/memHeapUsedM,components/host_components/metrics/jvm/memHeapCommittedM,components/host_components/metrics/mapred/jobtracker/trackers_decommissioned,components/host_components/metrics/cpu/cpu_wio,components/host_components/metrics/rpc/RpcQueueTime_avg_time'+conditionalFieldsString) :
  98. this.getUrl(testUrl, '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles,components/host_components/metrics/jvm/memHeapUsedM,components/host_components/metrics/jvm/memHeapCommittedM,components/host_components/metrics/mapred/jobtracker/trackers_decommissioned,components/host_components/metrics/cpu/cpu_wio,components/host_components/metrics/rpc/RpcQueueTime_avg_time'+conditionalFieldsString);
  99. var callback = callback || function (jqXHR, textStatus) {
  100. self.set('isUpdated', true);
  101. };
  102. App.HttpClient.get(servicesUrl, App.servicesMapper, {
  103. complete: function(){
  104. console.log("UpdateServiceMetric() Finished in:"+ (new Date().getTime()-methodStartTs) + " ms");
  105. callback();
  106. }
  107. });
  108. }
  109. });