main.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. App.router.get('clusterController').set('isWorking', true);
  63. }
  64. }.observes('App.router.clusterController.isLoaded'),
  65. stopPolling: function(){
  66. App.router.get('updateController').set('isWorking', false);
  67. App.router.get('backgroundOperationsController').set('isWorking', false);
  68. App.router.get('clusterController').set('isWorking', false);
  69. },
  70. reloadTimeOut: null,
  71. pageReload: function () {
  72. clearTimeout(this.get("reloadTimeOut"));
  73. this.set('reloadTimeOut',
  74. setTimeout(function () {
  75. if (App.clusterStatus.get('isInstalled')) {
  76. location.reload();
  77. }
  78. }, App.pageReloadTime)
  79. );
  80. }.observes("App.router.location.lastSetURL", "App.clusterStatus.isInstalled"),
  81. scRequest: function(request) {
  82. return App.router.get('mainServiceController').get(request);
  83. },
  84. isAllServicesInstalled: function() {
  85. return this.scRequest('isAllServicesInstalled');
  86. }.property('App.router.mainServiceController.content.content.@each',
  87. 'App.router.mainServiceController.content.content.length'),
  88. isStartAllDisabled: function() {
  89. return this.scRequest('isStartAllDisabled');
  90. }.property('App.router.mainServiceController.isStartStopAllClicked',
  91. 'App.router.mainServiceController.content.@each.healthStatus'),
  92. isStopAllDisabled: function() {
  93. return this.scRequest('isStopAllDisabled');
  94. }.property('App.router.mainServiceController.isStartStopAllClicked',
  95. 'App.router.mainServiceController.content.@each.healthStatus'),
  96. gotoAddService: function() {
  97. App.router.get('mainServiceController').gotoAddService();
  98. },
  99. startAllService: function(event){
  100. App.router.get('mainServiceController').startAllService(event);
  101. },
  102. stopAllService: function(event){
  103. App.router.get('mainServiceController').stopAllService(event);
  104. },
  105. /**
  106. * check server version and web client version
  107. */
  108. checkServerClientVersion: function () {
  109. var dfd = $.Deferred();
  110. var self = this;
  111. self.getServerVersion().done(function () {
  112. dfd.resolve();
  113. });
  114. return dfd.promise();
  115. },
  116. getServerVersion: function(){
  117. return App.ajax.send({
  118. name: 'ambari.service.load_server_version',
  119. sender: this,
  120. success: 'getServerVersionSuccessCallback',
  121. error: 'getServerVersionErrorCallback'
  122. });
  123. },
  124. getServerVersionSuccessCallback: function (data) {
  125. var clientVersion = App.get('version');
  126. var serverVersion = (data.RootServiceComponents.component_version).toString();
  127. this.set('ambariServerVersion', serverVersion);
  128. if (clientVersion) {
  129. this.set('versionConflictAlertBody', Em.I18n.t('app.versionMismatchAlert.body').format(serverVersion, clientVersion));
  130. this.set('isServerClientVersionMismatch', clientVersion != serverVersion);
  131. } else {
  132. this.set('isServerClientVersionMismatch', false);
  133. }
  134. },
  135. getServerVersionErrorCallback: function () {
  136. console.log('ERROR: Cannot load Ambari server version');
  137. }
  138. });