update_controller.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. updateAll:function(){
  32. var timeIntervalId = this.get('timeIntervalId');
  33. var self = this;
  34. if(this.get('isWorking')){
  35. if(timeIntervalId) return;
  36. this.set('timeIntervalId', setInterval(function(){
  37. self.updateHost();
  38. self.updateServiceMetric();
  39. self.graphsUpdate();
  40. }, App.contentUpdateInterval));
  41. } else {
  42. clearInterval(timeIntervalId);
  43. this.set('timeIntervalId', null);
  44. }
  45. }.observes('isWorking'),
  46. updateHost:function(){
  47. var hostsUrl = this.getUrl('/data/hosts/hosts.json', '/hosts?fields=Hosts,host_components,metrics/cpu,metrics/disk,metrics/load,metrics/memory');
  48. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  49. complete:function (jqXHR, textStatus) {}
  50. });
  51. },
  52. graphs: [],
  53. graphsUpdate: function () {
  54. var existedGraphs = [];
  55. this.get('graphs').forEach(function (_graph) {
  56. var view = Em.View.views[_graph.id];
  57. if (view) {
  58. existedGraphs.push(_graph);
  59. //console.log('updated graph', _graph.name);
  60. view.loadData();
  61. //if graph opened as modal popup update it to
  62. if($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  63. view.loadData();
  64. }
  65. }
  66. });
  67. this.set('graphs', existedGraphs);
  68. },
  69. /**
  70. * Updates the services information.
  71. *
  72. * @param isInitialLoad If true, only basic information is loaded.
  73. */
  74. updateServiceMetric: function (callback, isInitialLoad) {
  75. var self = this;
  76. self.set('isUpdated', false);
  77. var servicesUrl = isInitialLoad ?
  78. this.getUrl('/data/dashboard/services.json', '/services?fields=components/ServiceComponentInfo,components/host_components,components/host_components/HostRoles') :
  79. this.getUrl('/data/dashboard/services.json', '/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');
  80. var callback = callback || function (jqXHR, textStatus) {
  81. self.set('isUpdated', true);
  82. };
  83. App.HttpClient.get(servicesUrl, App.servicesMapper, {
  84. complete: callback
  85. });
  86. }
  87. });