update_controller.js 3.6 KB

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