cluster_controller.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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: function(){
  23. return true;
  24. var loadList = this.get('dataLoadList');
  25. var loaded = true;
  26. for(var i in loadList){
  27. if(loadList.hasOwnProperty(i) && !loadList[i]){
  28. loaded = false;
  29. }
  30. }
  31. return loaded;
  32. }.property('dataLoadList'),
  33. dataLoadList: Em.Object.create({
  34. 'hosts': true,
  35. 'services': false
  36. }),
  37. /**
  38. * load cluster name
  39. */
  40. loadClusterName: function(){
  41. var self = this;
  42. var url = (App.testMode) ? '/data/clusters/info.json' : '/api/clusters';
  43. $.ajax({
  44. type: "GET",
  45. url: url,
  46. dataType: 'json',
  47. timeout: 5000,
  48. success: function (data) {
  49. self.set('cluster', data.items[0]);
  50. self.loadClusterData();
  51. },
  52. error: function (request, ajaxOptions, error) {
  53. //do something
  54. console.log('failed on loading cluster name')
  55. },
  56. statusCode: require('data/statusCodes')
  57. });
  58. },
  59. /**
  60. *
  61. * load all data and update load status
  62. */
  63. loadClusterData: function(){
  64. var self = this;
  65. if(!this.get('clusterName')){
  66. return;
  67. }
  68. // TODO: load all models
  69. /*App.HttpClient.get("/data/hosts/hosts.json", App.hostsMapper,{
  70. complete:function(jqXHR, textStatus){
  71. self.set('dataLoadList.hosts', true);
  72. }
  73. });*/
  74. App.HttpClient.get("/data/dashboard/services.json", App.servicesMapper,{
  75. complete:function(jqXHR, textStatus){
  76. self.set('dataLoadList.services', true);
  77. }
  78. });
  79. }.observes('clusterName'),
  80. clusterName: function(){
  81. return (this.get('cluster')) ? this.get('cluster').Clusters.cluster_name : 'mycluster';
  82. }.property('cluster')
  83. })