update_controller.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. clusterName:function () {
  24. return (this.get('cluster')) ? this.get('cluster').Clusters.cluster_name : null;
  25. }.property('cluster'),
  26. loadClusterName:function (reload) {
  27. if (this.get('clusterName') && !reload) {
  28. return;
  29. }
  30. var self = this;
  31. var url = (App.testMode) ? '/data/clusters/info.json' : App.apiPrefix + '/clusters';
  32. $.ajax({
  33. async:false,
  34. type:"GET",
  35. url:url,
  36. dataType:'json',
  37. timeout:App.timeout,
  38. success:function (data) {
  39. self.set('cluster', data.items[0]);
  40. },
  41. error:function (request, ajaxOptions, error) {
  42. console.log('failed on loading cluster name');
  43. },
  44. statusCode:require('data/statusCodes')
  45. });
  46. },
  47. getUrl:function (testUrl, url) {
  48. return (App.testMode) ? testUrl : App.apiPrefix + '/clusters/' + this.get('clusterName') + url;
  49. },
  50. updateAll:function(){
  51. this.updateHost();
  52. this.updateServiceMetric();
  53. this.graphsUpdate();
  54. },
  55. updateHost:function(){
  56. var hostsUrl = this.getUrl('/data/hosts/hosts.json', '/hosts?fields=*');
  57. App.HttpClient.get(hostsUrl, App.hostsMapper, {
  58. complete:function (jqXHR, textStatus) {
  59. }
  60. });
  61. },
  62. graphs: [],
  63. graphsUpdate: function () {
  64. var existedGraphs = [];
  65. this.get('graphs').forEach(function (_graph) {
  66. var view = Em.View.views[_graph.id];
  67. if (view) {
  68. existedGraphs.push(_graph);
  69. console.log('updated graph', _graph.name);
  70. view.loadData();
  71. //if graph opened as modal popup update it to
  72. if($(".modal-graph-line .modal-body #" + _graph.popupId + "-container-popup").length) {
  73. view.loadData();
  74. }
  75. }
  76. });
  77. this.set('graphs', existedGraphs);
  78. },
  79. updateServiceMetric:function(callback){
  80. var self = this;
  81. self.set('isUpdated', false);
  82. var servicesUrl = this.getUrl('/data/dashboard/services.json', '/services?ServiceInfo/service_name!=MISCELLANEOUS&ServiceInfo/service_name!=DASHBOARD&fields=*,components/host_components/*');
  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. });