main.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. require('models/background_operation');
  20. App.MainController = Em.Controller.extend({
  21. name: 'mainController',
  22. updateTitle: function(){
  23. var name = App.router.get('clusterController.clusterName');
  24. if (name) {
  25. name = name.length > 13 ? name.substr(0, 10) + "..." : name;
  26. } else {
  27. name = Em.I18n.t('common.loading');
  28. }
  29. $('title').text('Ambari - ' + name);
  30. }.observes('App.router.clusterController.clusterName'),
  31. isClusterDataLoaded: function(){
  32. return App.router.get('clusterController.isLoaded');
  33. }.property('App.router.clusterController.isLoaded'),
  34. clusterDataLoadedPercent: function(){
  35. return App.router.get('clusterController.clusterDataLoadedPercent');
  36. }.property('App.router.clusterController.clusterDataLoadedPercent'),
  37. /**
  38. * run all processes and cluster's data loading
  39. */
  40. initialize: function(){
  41. App.router.get('clusterController').loadClusterData();
  42. },
  43. dataLoading: function () {
  44. var self = this;
  45. var dfd = $.Deferred();
  46. if (App.router.get('clusterController.isLoaded')) {
  47. dfd.resolve();
  48. } else {
  49. var interval = setInterval(function () {
  50. if (self.get('isClusterDataLoaded')) {
  51. dfd.resolve();
  52. clearInterval(interval);
  53. }
  54. }, 50);
  55. }
  56. return dfd.promise();
  57. },
  58. startPolling: function () {
  59. if (App.router.get('clusterController.isLoaded')) {
  60. App.router.get('updateController').set('isWorking', true);
  61. App.router.get('backgroundOperationsController').set('isWorking', true);
  62. }
  63. }.observes('App.router.clusterController.isLoaded'),
  64. stopPolling: function(){
  65. App.router.get('updateController').set('isWorking', false);
  66. App.router.get('backgroundOperationsController').set('isWorking', false);
  67. },
  68. reloadTimeOut: null,
  69. pageReload: function () {
  70. clearTimeout(this.get("reloadTimeOut"));
  71. this.set('reloadTimeOut',
  72. setTimeout(function () {
  73. if (App.clusterStatus.get('isInstalled')) {
  74. location.reload();
  75. }
  76. }, App.pageReloadTime)
  77. );
  78. }.observes("App.router.location.lastSetURL", "App.clusterStatus.isInstalled"),
  79. scRequest: function(request) {
  80. return App.router.get('mainServiceController').get(request);
  81. },
  82. isAllServicesInstalled: function() {
  83. return this.scRequest('isAllServicesInstalled');
  84. }.property('App.router.mainServiceController.content.content.@each',
  85. 'App.router.mainServiceController.content.content.length'),
  86. isStartAllDisabled: function() {
  87. return this.scRequest('isStartAllDisabled');
  88. }.property('App.router.mainServiceController.isStartStopAllClicked',
  89. 'App.router.mainServiceController.content.@each.healthStatus'),
  90. isStopAllDisabled: function() {
  91. return this.scRequest('isStopAllDisabled');
  92. }.property('App.router.mainServiceController.isStartStopAllClicked',
  93. 'App.router.mainServiceController.content.@each.healthStatus'),
  94. gotoAddService: function() {
  95. App.router.get('mainServiceController').gotoAddService();
  96. },
  97. startAllService: function(event){
  98. App.router.get('mainServiceController').startAllService(event);
  99. },
  100. stopAllService: function(event){
  101. App.router.get('mainServiceController').stopAllService(event);
  102. },
  103. /**
  104. * check server version and web client version
  105. */
  106. checkServerClientVersion: function () {
  107. var dfd = $.Deferred();
  108. var self = this;
  109. self.getServerVersion().done(function () {
  110. dfd.resolve();
  111. });
  112. return dfd.promise();
  113. },
  114. getServerVersion: function(){
  115. return App.ajax.send({
  116. name: 'ambari.service.load_server_version',
  117. sender: this,
  118. success: 'getServerVersionSuccessCallback',
  119. error: 'getServerVersionErrorCallback'
  120. });
  121. },
  122. getServerVersionSuccessCallback: function (data) {
  123. var clientVersion = App.get('version');
  124. var serverVersion = (data.RootServiceComponents.component_version).toString();
  125. this.set('ambariServerVersion', serverVersion);
  126. if (clientVersion) {
  127. this.set('versionConflictAlertBody', Em.I18n.t('app.versionMismatchAlert.body').format(serverVersion, clientVersion));
  128. this.set('isServerClientVersionMismatch', clientVersion != serverVersion);
  129. } else {
  130. this.set('isServerClientVersionMismatch', false);
  131. }
  132. },
  133. getServerVersionErrorCallback: function () {
  134. console.log('ERROR: Cannot load Ambari server version');
  135. }
  136. });