update_controller.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 hostsUrl = this.getUrl('/data/hosts/hosts.json', '/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');
  44. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  45. complete: callback
  46. });
  47. },
  48. graphs: [],
  49. graphsUpdate: function (callback) {
  50. var existedGraphs = [];
  51. this.get('graphs').forEach(function (_graph) {
  52. var view = Em.View.views[_graph.id];
  53. if (view) {
  54. existedGraphs.push(_graph);
  55. //console.log('updated graph', _graph.name);
  56. view.loadData();
  57. //if graph opened as modal popup update it to
  58. if($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  59. view.loadData();
  60. }
  61. }
  62. });
  63. callback();
  64. this.set('graphs', existedGraphs);
  65. },
  66. /**
  67. * Updates the services information.
  68. *
  69. * @param callback
  70. * @param isInitialLoad If true, only basic information is loaded.
  71. */
  72. updateServiceMetric: function (callback, isInitialLoad) {
  73. var self = this;
  74. self.set('isUpdated', false);
  75. var conditionalFields = [];
  76. if (App.Service.find().findProperty('serviceName', 'FLUME')) {
  77. conditionalFields.push("components/host_components/metrics/flume/flume");
  78. }
  79. if (App.Service.find().findProperty('serviceName', 'YARN')) {
  80. conditionalFields.push("components/host_components/metrics/yarn/Queue");
  81. }
  82. var conditionalFieldsString = conditionalFields.length > 0 ? ',' + conditionalFields.join(',') : '';
  83. var methodStartTs = new Date().getTime();
  84. var testUrl = App.testHadoop2Stack ? '/data/dashboard/HDP2/services.json':'/data/dashboard/services.json';
  85. var servicesUrl = isInitialLoad ?
  86. //this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles') :
  87. 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) :
  88. 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);
  89. var callback = callback || function (jqXHR, textStatus) {
  90. self.set('isUpdated', true);
  91. };
  92. App.HttpClient.get(servicesUrl, App.servicesMapper, {
  93. complete: function(){
  94. console.log("UpdateServiceMetric() Finished in:"+ (new Date().getTime()-methodStartTs) + " ms");
  95. callback();
  96. }
  97. });
  98. }
  99. });