cluster_controller.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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.ClusterController = Em.Controller.extend({
  20. name: 'clusterController',
  21. cluster:null,
  22. isLoaded: false,
  23. updateLoadStatus: function(item){
  24. var loadList = this.get('dataLoadList');
  25. var loaded = true;
  26. loadList.set(item, true);
  27. for(var i in loadList){
  28. if(loadList.hasOwnProperty(i) && !loadList[i] && loaded){
  29. loaded = false;
  30. }
  31. }
  32. this.set('isLoaded', loaded);
  33. },
  34. dataLoadList: Em.Object.create({
  35. 'hosts': false,
  36. 'jobs': false,
  37. 'runs': false,
  38. 'services': false,
  39. 'cluster' : false,
  40. 'racks' : false,
  41. 'alerts' : false
  42. }),
  43. /**
  44. * load cluster name
  45. */
  46. loadClusterName: function(){
  47. var self = this;
  48. var url = (App.testMode) ? '/data/clusters/info.json' : '/api/clusters';
  49. $.ajax({
  50. type: "GET",
  51. url: url,
  52. dataType: 'json',
  53. timeout: 5000,
  54. success: function (data) {
  55. self.set('cluster', data.items[0]);
  56. },
  57. error: function (request, ajaxOptions, error) {
  58. //do something
  59. console.log('failed on loading cluster name');
  60. //hack skip loading when data ain't received
  61. if(!App.testMode) self.set('isLoaded', true);
  62. },
  63. statusCode: require('data/statusCodes')
  64. });
  65. },
  66. getUrl: function(testUrl, url){
  67. return (App.testMode) ? testUrl: '/api/clusters/' + this.get('clusterName') + url;
  68. },
  69. /**
  70. *
  71. * load all data and update load status
  72. */
  73. loadClusterData: function(){
  74. var self = this;
  75. if(!this.get('clusterName')){
  76. return;
  77. }
  78. var alertsUrl = "/data/alerts/alerts.json";
  79. var clusterUrl = this.getUrl('/data/clusters/cluster.json', '?fields=Clusters');
  80. var hostsUrl = this.getUrl('/data/hosts/hosts.json', '/hosts?fields=*');
  81. var servicesUrl = this.getUrl('/data/dashboard/services.json', '/services?ServiceInfo/service_name!=MISCELLANEOUS&ServiceInfo/service_name!=DASHBOARD&fields=components/host_components/*');
  82. var jobsUrl = "/data/apps/jobs.json";
  83. var runsUrl = "/data/apps/runs.json";
  84. var racksUrl = "/data/racks/racks.json";
  85. App.HttpClient.get(alertsUrl, App.alertsMapper,{
  86. complete:function(jqXHR, textStatus){
  87. self.updateLoadStatus('alerts');
  88. }
  89. });
  90. App.HttpClient.get(racksUrl, App.racksMapper,{
  91. complete:function(jqXHR, textStatus){
  92. self.updateLoadStatus('racks');
  93. }
  94. });
  95. App.HttpClient.get(clusterUrl, App.clusterMapper,{
  96. complete:function(jqXHR, textStatus){
  97. self.updateLoadStatus('cluster');
  98. }
  99. });
  100. App.HttpClient.get(jobsUrl, App.jobsMapper,{
  101. complete:function(jqXHR, textStatus) {
  102. self.updateLoadStatus('jobs');
  103. App.HttpClient.get(runsUrl, App.runsMapper,{
  104. complete:function(jqXHR, textStatus) {
  105. self.updateLoadStatus('runs');
  106. }
  107. });
  108. }
  109. });
  110. App.HttpClient.get(hostsUrl, App.hostsMapper,{
  111. complete:function(jqXHR, textStatus){
  112. self.updateLoadStatus('hosts');
  113. }
  114. });
  115. App.HttpClient.get(servicesUrl, App.servicesMapper,{
  116. complete:function(jqXHR, textStatus){
  117. self.updateLoadStatus('services');
  118. }
  119. });
  120. }.observes('clusterName'),
  121. clusterName: function(){
  122. return (this.get('cluster')) ? this.get('cluster').Clusters.cluster_name : 'mycluster';
  123. }.property('cluster')
  124. })