app.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. // Application bootstrapper
  19. require('utils/ember_reopen');
  20. var stringUtils = require('utils/string_utils');
  21. module.exports = Em.Application.create({
  22. name: 'Ambari Web',
  23. rootElement: '#wrapper',
  24. store: DS.Store.create({
  25. revision: 4,
  26. adapter: DS.FixtureAdapter.create({
  27. simulateRemoteResponse: false
  28. }),
  29. typeMaps: {},
  30. recordCache: []
  31. }),
  32. isAdmin: false,
  33. isOperator: false,
  34. isManager: function() {
  35. return this.get('isAdmin') || this.get('isOperator');
  36. }.property('isAdmin','isOperator'),
  37. isStackServicesLoaded: false,
  38. /**
  39. * return url prefix with number value of version of HDP stack
  40. */
  41. stackVersionURL: function () {
  42. return '/stacks/{0}/versions/{1}'.format(this.get('currentStackName') || 'HDP', this.get('currentStackVersionNumber'));
  43. }.property('currentStackName','currentStackVersionNumber'),
  44. falconServerURL: function () {
  45. var falconService = this.Service.find().findProperty('serviceName', 'FALCON');
  46. if (falconService) {
  47. return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('hostName');
  48. }
  49. return '';
  50. }.property().volatile(),
  51. /* Determine if Application Timeline Service supports Kerberization.
  52. * Because this value is retrieved from the cardinality of the component, it is safe to keep in app.js
  53. * since its value will not change during the lifetime of the application.
  54. */
  55. doesATSSupportKerberos: function() {
  56. var YARNService = App.StackServiceComponent.find().filterProperty('serviceName', 'YARN');
  57. if (YARNService.length) {
  58. var ATS = App.StackServiceComponent.find().findProperty('componentName', 'APP_TIMELINE_SERVER');
  59. return (!!ATS && !!ATS.get('minToInstall'));
  60. }
  61. return false;
  62. }.property('router.clusterController.isLoaded'),
  63. clusterName: null,
  64. clockDistance: null, // server clock - client clock
  65. currentStackVersion: '',
  66. currentStackName: function() {
  67. return Em.get((this.get('currentStackVersion') || this.get('defaultStackVersion')).match(/(.+)-\d.+/), '1');
  68. }.property('currentStackVersion', 'defaultStackVersion'),
  69. allHostNames: [],
  70. currentStackVersionNumber: function () {
  71. var regExp = new RegExp(this.get('currentStackName') + '-');
  72. return (this.get('currentStackVersion') || this.get('defaultStackVersion')).replace(regExp, '');
  73. }.property('currentStackVersion', 'defaultStackVersion', 'currentStackName'),
  74. isHadoop2Stack: function () {
  75. var result = true;
  76. var hdfsService = App.StackService.find().findProperty('serviceName','HDFS');
  77. if (hdfsService) {
  78. result = stringUtils.compareVersions(hdfsService.get('serviceVersion'), "2.0") > -1;
  79. } else {
  80. result = stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") > -1;
  81. }
  82. return result;
  83. }.property('router.clusterController.isLoaded', 'isStackServicesLoaded','currentStackVersionNumber'),
  84. isHadoop22Stack: function () {
  85. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.2") > -1);
  86. }.property('currentStackVersionNumber'),
  87. isHadoopWindowsStack: function() {
  88. return this.get('currentStackName') == "HDPWIN";
  89. }.property('currentStackName'),
  90. /**
  91. * If NameNode High Availability is enabled
  92. * Based on <code>clusterStatus.isInstalled</code>, stack version, <code>SNameNode</code> availability
  93. *
  94. * @type {bool}
  95. */
  96. isHaEnabled: function () {
  97. if (!this.get('isHadoop2Stack')) return false;
  98. var isHDFSInstalled = App.Service.find().findProperty('serviceName','HDFS');
  99. return !!isHDFSInstalled && !this.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
  100. }.property('router.clusterController.isLoaded', 'isHadoop2Stack'),
  101. /**
  102. * If ResourceManager High Availability is enabled
  103. * Based on number of ResourceManager components host components installed
  104. *
  105. * @type {bool}
  106. */
  107. isRMHaEnabled: function () {
  108. var result = false;
  109. var rmStackComponent = App.StackServiceComponent.find().findProperty('componentName','RESOURCEMANAGER');
  110. if (rmStackComponent && rmStackComponent.get('isMultipleAllowed')) {
  111. result = this.HostComponent.find().filterProperty('componentName', 'RESOURCEMANAGER').length > 1;
  112. }
  113. return result;
  114. }.property('router.clusterController.isLoaded'),
  115. /**
  116. * Object with utility functions for list of service names with similar behavior
  117. */
  118. services: Em.Object.create({
  119. all: function () {
  120. return App.StackService.find().mapProperty('serviceName');
  121. }.property('App.router.clusterController.isLoaded'),
  122. clientOnly: function () {
  123. return App.StackService.find().filterProperty('isClientOnlyService').mapProperty('serviceName');
  124. }.property('App.router.clusterController.isLoaded'),
  125. hasClient: function () {
  126. return App.StackService.find().filterProperty('hasClient').mapProperty('serviceName');
  127. }.property('App.router.clusterController.isLoaded'),
  128. hasMaster: function () {
  129. return App.StackService.find().filterProperty('hasMaster').mapProperty('serviceName');
  130. }.property('App.router.clusterController.isLoaded'),
  131. hasSlave: function () {
  132. return App.StackService.find().filterProperty('hasSlave').mapProperty('serviceName');
  133. }.property('App.router.clusterController.isLoaded'),
  134. noConfigTypes: function () {
  135. return App.StackService.find().filterProperty('isNoConfigTypes').mapProperty('serviceName');
  136. }.property('App.router.clusterController.isLoaded'),
  137. monitoring: function () {
  138. return App.StackService.find().filterProperty('isMonitoringService').mapProperty('serviceName');
  139. }.property('App.router.clusterController.isLoaded'),
  140. hostMetrics: function () {
  141. return App.StackService.find().filterProperty('isHostMetricsService').mapProperty('serviceName');
  142. }.property('App.router.clusterController.isLoaded'),
  143. serviceMetrics: function () {
  144. return App.StackService.find().filterProperty('isServiceMetricsService').mapProperty('serviceName');
  145. }.property('App.router.clusterController.isLoaded'),
  146. alerting: function () {
  147. return App.StackService.find().filterProperty('isAlertingService').mapProperty('serviceName');
  148. }.property('App.router.clusterController.isLoaded'),
  149. supportsServiceCheck: function() {
  150. return App.StackService.find().filterProperty('serviceCheckSupported').mapProperty('serviceName');
  151. }.property('App.router.clusterController.isLoaded')
  152. }),
  153. /**
  154. * List of components with allowed action for them
  155. * @type {Em.Object}
  156. */
  157. components: Em.Object.create({
  158. allComponents: function () {
  159. return App.StackServiceComponent.find().mapProperty('componentName')
  160. }.property('App.router.clusterController.isLoaded'),
  161. reassignable: function () {
  162. return App.StackServiceComponent.find().filterProperty('isReassignable').mapProperty('componentName')
  163. }.property('App.router.clusterController.isLoaded'),
  164. restartable: function () {
  165. return App.StackServiceComponent.find().filterProperty('isRestartable').mapProperty('componentName')
  166. }.property('App.router.clusterController.isLoaded'),
  167. deletable: function () {
  168. return App.StackServiceComponent.find().filterProperty('isDeletable').mapProperty('componentName')
  169. }.property('App.router.clusterController.isLoaded'),
  170. rollinRestartAllowed: function () {
  171. return App.StackServiceComponent.find().filterProperty('isRollinRestartAllowed').mapProperty('componentName')
  172. }.property('App.router.clusterController.isLoaded'),
  173. decommissionAllowed: function () {
  174. return App.StackServiceComponent.find().filterProperty('isDecommissionAllowed').mapProperty('componentName')
  175. }.property('App.router.clusterController.isLoaded'),
  176. refreshConfigsAllowed: function () {
  177. return App.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed').mapProperty('componentName')
  178. }.property('App.router.clusterController.isLoaded'),
  179. addableToHost: function () {
  180. return App.StackServiceComponent.find().filterProperty('isAddableToHost').mapProperty('componentName')
  181. }.property('App.router.clusterController.isLoaded'),
  182. addableMasterInstallerWizard: function () {
  183. return App.StackServiceComponent.find().filterProperty('isMasterAddableInstallerWizard').mapProperty('componentName')
  184. }.property('App.router.clusterController.isLoaded'),
  185. multipleMasters: function () {
  186. return App.StackServiceComponent.find().filterProperty('isMasterWithMultipleInstances').mapProperty('componentName')
  187. }.property('App.router.clusterController.isLoaded'),
  188. slaves: function () {
  189. return App.StackServiceComponent.find().filterProperty('isSlave').mapProperty('componentName')
  190. }.property('App.router.clusterController.isLoaded'),
  191. masters: function () {
  192. return App.StackServiceComponent.find().filterProperty('isMaster').mapProperty('componentName')
  193. }.property('App.router.clusterController.isLoaded'),
  194. clients: function () {
  195. return App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName')
  196. }.property('App.router.clusterController.isLoaded')
  197. })
  198. });