main.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /**
  61. *
  62. * @param isLoaded {Boolean}
  63. * @param opts {Object}
  64. * {
  65. * period {Number}
  66. * }
  67. * @return {*|{then}}
  68. */
  69. isLoading: function(isLoaded, opts) {
  70. var dfd = $.Deferred();
  71. var self = this;
  72. opts = opts || {};
  73. var period = opts.period || 20;
  74. if (this.get(isLoaded)) {
  75. dfd.resolve();
  76. } else {
  77. var interval = setInterval(function () {
  78. if (self.get(isLoaded)) {
  79. dfd.resolve();
  80. clearInterval(interval);
  81. }
  82. }, period);
  83. }
  84. return dfd.promise();
  85. },
  86. startPolling: function () {
  87. if (App.router.get('applicationController.isExistingClusterDataLoaded')) {
  88. App.router.get('updateController').set('isWorking', true);
  89. App.router.get('backgroundOperationsController').set('isWorking', true);
  90. }
  91. }.observes('App.router.applicationController.isExistingClusterDataLoaded'),
  92. stopPolling: function(){
  93. App.router.get('updateController').set('isWorking', false);
  94. App.router.get('backgroundOperationsController').set('isWorking', false);
  95. },
  96. reloadTimeOut: null,
  97. pageReload: function () {
  98. clearTimeout(this.get("reloadTimeOut"));
  99. this.set('reloadTimeOut',
  100. setTimeout(function () {
  101. if (App.clusterStatus.get('isInstalled')) {
  102. location.reload();
  103. }
  104. }, App.pageReloadTime)
  105. );
  106. }.observes("App.router.location.lastSetURL", "App.clusterStatus.isInstalled"),
  107. scRequest: function(request) {
  108. return App.router.get('mainServiceController').get(request);
  109. },
  110. isAllServicesInstalled: function() {
  111. return this.scRequest('isAllServicesInstalled');
  112. }.property('App.router.mainServiceController.content.content.@each',
  113. 'App.router.mainServiceController.content.content.length'),
  114. isStartAllDisabled: function() {
  115. return this.scRequest('isStartAllDisabled');
  116. }.property('App.router.mainServiceController.isStartStopAllClicked',
  117. 'App.router.mainServiceController.content.@each.healthStatus'),
  118. isStopAllDisabled: function() {
  119. return this.scRequest('isStopAllDisabled');
  120. }.property('App.router.mainServiceController.isStartStopAllClicked',
  121. 'App.router.mainServiceController.content.@each.healthStatus'),
  122. gotoAddService: function() {
  123. App.router.get('mainServiceController').gotoAddService();
  124. },
  125. startAllService: function(event){
  126. App.router.get('mainServiceController').startAllService(event);
  127. },
  128. stopAllService: function(event){
  129. App.router.get('mainServiceController').stopAllService(event);
  130. },
  131. /**
  132. * check server version and web client version
  133. */
  134. checkServerClientVersion: function () {
  135. var dfd = $.Deferred();
  136. var self = this;
  137. self.getServerVersion().done(function () {
  138. dfd.resolve();
  139. });
  140. return dfd.promise();
  141. },
  142. getServerVersion: function(){
  143. return App.ajax.send({
  144. name: 'ambari.service',
  145. sender: this,
  146. data: {
  147. fields: '?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true'
  148. },
  149. success: 'getServerVersionSuccessCallback',
  150. error: 'getServerVersionErrorCallback'
  151. });
  152. },
  153. getServerVersionSuccessCallback: function (data) {
  154. var clientVersion = App.get('version');
  155. var serverVersion = (data.RootServiceComponents.component_version).toString();
  156. this.set('ambariServerVersion', serverVersion);
  157. if (clientVersion) {
  158. this.set('versionConflictAlertBody', Em.I18n.t('app.versionMismatchAlert.body').format(serverVersion, clientVersion));
  159. this.set('isServerClientVersionMismatch', clientVersion != serverVersion);
  160. } else {
  161. this.set('isServerClientVersionMismatch', false);
  162. }
  163. App.set('isManagedMySQLForHiveEnabled', App.config.isManagedMySQLForHiveAllowed(data.RootServiceComponents.properties['server.os_family']));
  164. },
  165. getServerVersionErrorCallback: function () {
  166. console.log('ERROR: Cannot load Ambari server version');
  167. }
  168. });