main.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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(App.router.get('clusterInstallCompleted')) {
  25. if (name && App.router.get('clusterController').get('isLoaded')) {
  26. name = name.length > 13 ? name.substr(0, 10) + "..." : name;
  27. } else {
  28. name = Em.I18n.t('common.loading');
  29. }
  30. $('title').text(Em.I18n.t('app.name.subtitle').format(name));
  31. }
  32. }.observes('App.router.clusterController.clusterName, App.router.clusterInstallCompleted', 'App.router.clusterController.isLoaded'),
  33. isClusterDataLoaded: function(){
  34. return App.router.get('clusterController.isLoaded');
  35. }.property('App.router.clusterController.isLoaded'),
  36. clusterDataLoadedPercent: function(){
  37. return App.router.get('clusterController.clusterDataLoadedPercent');
  38. }.property('App.router.clusterController.clusterDataLoadedPercent'),
  39. /**
  40. * run all processes and cluster's data loading
  41. */
  42. initialize: function(){
  43. App.router.get('clusterController').loadClusterData();
  44. },
  45. dataLoading: function () {
  46. var self = this;
  47. var dfd = $.Deferred();
  48. if (App.router.get('clusterController.isLoaded')) {
  49. dfd.resolve();
  50. } else {
  51. var interval = setInterval(function () {
  52. if (self.get('isClusterDataLoaded')) {
  53. dfd.resolve();
  54. clearInterval(interval);
  55. }
  56. }, 50);
  57. }
  58. return dfd.promise();
  59. },
  60. startPolling: function () {
  61. if (App.router.get('applicationController.isExistingClusterDataLoaded')) {
  62. App.router.get('updateController').set('isWorking', true);
  63. App.router.get('backgroundOperationsController').set('isWorking', true);
  64. }
  65. }.observes('App.router.applicationController.isExistingClusterDataLoaded'),
  66. stopPolling: function(){
  67. App.router.get('updateController').set('isWorking', false);
  68. App.router.get('backgroundOperationsController').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. App.set('isManagedMySQLForHiveEnabled', App.config.isManagedMySQLForHiveAllowed(data.RootServiceComponents.properties['server.os_type']));
  135. },
  136. getServerVersionErrorCallback: function () {
  137. console.log('ERROR: Cannot load Ambari server version');
  138. }
  139. });