app.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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. /**
  35. * state of stack upgrade process
  36. * states:
  37. * - INIT
  38. * - PENDING
  39. * - IN_PROGRESS
  40. * - STOPPED
  41. * - COMPLETED
  42. * @type {String}
  43. */
  44. upgradeState: 'INIT',
  45. /**
  46. * compute user access rights by permission type
  47. * types:
  48. * - ADMIN
  49. * - MANAGER
  50. * - OPERATOR
  51. * - ONLY_ADMIN
  52. * prefix "upgrade_" mean that element will not be unconditionally blocked while stack upgrade running
  53. * @param type {string}
  54. * @return {boolean}
  55. */
  56. isAccessible: function (type) {
  57. if (this.get('upgradeState') !== 'INIT' && !type.contains('upgrade_')) {
  58. return false;
  59. }
  60. if (type.contains('upgrade_')) {
  61. //slice off "upgrade_" prefix to have actual permission type
  62. type = type.slice(8);
  63. }
  64. switch (type) {
  65. case 'ADMIN':
  66. return this.get('isAdmin');
  67. case 'NON_ADMIN':
  68. return !this.get('isAdmin');
  69. case 'MANAGER':
  70. return this.get('isAdmin') || this.get('isOperator');
  71. case 'OPERATOR':
  72. return this.get('isOperator');
  73. case 'ONLY_ADMIN':
  74. return this.get('isAdmin') && !this.get('isOperator');
  75. default:
  76. return false;
  77. }
  78. },
  79. isStackServicesLoaded: false,
  80. /**
  81. * return url prefix with number value of version of HDP stack
  82. */
  83. stackVersionURL: function () {
  84. return '/stacks/{0}/versions/{1}'.format(this.get('currentStackName') || 'HDP', this.get('currentStackVersionNumber'));
  85. }.property('currentStackName','currentStackVersionNumber'),
  86. falconServerURL: function () {
  87. var falconService = this.Service.find().findProperty('serviceName', 'FALCON');
  88. if (falconService) {
  89. return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('hostName');
  90. }
  91. return '';
  92. }.property().volatile(),
  93. /* Determine if Application Timeline Service supports Kerberization.
  94. * Because this value is retrieved from the cardinality of the component, it is safe to keep in app.js
  95. * since its value will not change during the lifetime of the application.
  96. */
  97. doesATSSupportKerberos: function() {
  98. var YARNService = App.StackServiceComponent.find().filterProperty('serviceName', 'YARN');
  99. if (YARNService.length) {
  100. var ATS = App.StackServiceComponent.find().findProperty('componentName', 'APP_TIMELINE_SERVER');
  101. return (!!ATS && !!ATS.get('minToInstall'));
  102. }
  103. return false;
  104. }.property('router.clusterController.isLoaded'),
  105. clusterName: null,
  106. clockDistance: null, // server clock - client clock
  107. currentStackVersion: '',
  108. currentStackName: function() {
  109. return Em.get((this.get('currentStackVersion') || this.get('defaultStackVersion')).match(/(.+)-\d.+/), '1');
  110. }.property('currentStackVersion', 'defaultStackVersion'),
  111. allHostNames: [],
  112. currentStackVersionNumber: function () {
  113. var regExp = new RegExp(this.get('currentStackName') + '-');
  114. return (this.get('currentStackVersion') || this.get('defaultStackVersion')).replace(regExp, '');
  115. }.property('currentStackVersion', 'defaultStackVersion', 'currentStackName'),
  116. isHadoop2Stack: function () {
  117. var result = true;
  118. var hdfsService = App.StackService.find().findProperty('serviceName','HDFS');
  119. if (hdfsService) {
  120. result = stringUtils.compareVersions(hdfsService.get('serviceVersion'), "2.0") > -1;
  121. } else {
  122. result = stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") > -1;
  123. }
  124. return result;
  125. }.property('router.clusterController.isLoaded', 'isStackServicesLoaded','currentStackVersionNumber'),
  126. isHadoop22Stack: function () {
  127. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.2") > -1);
  128. }.property('currentStackVersionNumber'),
  129. isHadoopWindowsStack: function() {
  130. return this.get('currentStackName') == "HDPWIN";
  131. }.property('currentStackName'),
  132. /**
  133. * If NameNode High Availability is enabled
  134. * Based on <code>clusterStatus.isInstalled</code>, stack version, <code>SNameNode</code> availability
  135. *
  136. * @type {bool}
  137. */
  138. isHaEnabled: function () {
  139. if (!this.get('isHadoop2Stack')) return false;
  140. var isHDFSInstalled = App.Service.find().findProperty('serviceName','HDFS');
  141. return !!isHDFSInstalled && !this.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
  142. }.property('router.clusterController.isLoaded', 'isHadoop2Stack'),
  143. /**
  144. * If ResourceManager High Availability is enabled
  145. * Based on number of ResourceManager components host components installed
  146. *
  147. * @type {bool}
  148. */
  149. isRMHaEnabled: function () {
  150. var result = false;
  151. var rmStackComponent = App.StackServiceComponent.find().findProperty('componentName','RESOURCEMANAGER');
  152. if (rmStackComponent && rmStackComponent.get('isMultipleAllowed')) {
  153. result = this.HostComponent.find().filterProperty('componentName', 'RESOURCEMANAGER').length > 1;
  154. }
  155. return result;
  156. }.property('router.clusterController.isLoaded'),
  157. /**
  158. * Object with utility functions for list of service names with similar behavior
  159. */
  160. services: Em.Object.create({
  161. all: function () {
  162. return App.StackService.find().mapProperty('serviceName');
  163. }.property('App.router.clusterController.isLoaded'),
  164. clientOnly: function () {
  165. return App.StackService.find().filterProperty('isClientOnlyService').mapProperty('serviceName');
  166. }.property('App.router.clusterController.isLoaded'),
  167. hasClient: function () {
  168. return App.StackService.find().filterProperty('hasClient').mapProperty('serviceName');
  169. }.property('App.router.clusterController.isLoaded'),
  170. hasMaster: function () {
  171. return App.StackService.find().filterProperty('hasMaster').mapProperty('serviceName');
  172. }.property('App.router.clusterController.isLoaded'),
  173. hasSlave: function () {
  174. return App.StackService.find().filterProperty('hasSlave').mapProperty('serviceName');
  175. }.property('App.router.clusterController.isLoaded'),
  176. noConfigTypes: function () {
  177. return App.StackService.find().filterProperty('isNoConfigTypes').mapProperty('serviceName');
  178. }.property('App.router.clusterController.isLoaded'),
  179. monitoring: function () {
  180. return App.StackService.find().filterProperty('isMonitoringService').mapProperty('serviceName');
  181. }.property('App.router.clusterController.isLoaded'),
  182. hostMetrics: function () {
  183. return App.StackService.find().filterProperty('isHostMetricsService').mapProperty('serviceName');
  184. }.property('App.router.clusterController.isLoaded'),
  185. serviceMetrics: function () {
  186. return App.StackService.find().filterProperty('isServiceMetricsService').mapProperty('serviceName');
  187. }.property('App.router.clusterController.isLoaded'),
  188. alerting: function () {
  189. return App.StackService.find().filterProperty('isAlertingService').mapProperty('serviceName');
  190. }.property('App.router.clusterController.isLoaded'),
  191. supportsServiceCheck: function() {
  192. return App.StackService.find().filterProperty('serviceCheckSupported').mapProperty('serviceName');
  193. }.property('App.router.clusterController.isLoaded')
  194. }),
  195. /**
  196. * List of components with allowed action for them
  197. * @type {Em.Object}
  198. */
  199. components: Em.Object.create({
  200. allComponents: function () {
  201. return App.StackServiceComponent.find().mapProperty('componentName')
  202. }.property('App.router.clusterController.isLoaded'),
  203. reassignable: function () {
  204. return App.StackServiceComponent.find().filterProperty('isReassignable').mapProperty('componentName')
  205. }.property('App.router.clusterController.isLoaded'),
  206. restartable: function () {
  207. return App.StackServiceComponent.find().filterProperty('isRestartable').mapProperty('componentName')
  208. }.property('App.router.clusterController.isLoaded'),
  209. deletable: function () {
  210. return App.StackServiceComponent.find().filterProperty('isDeletable').mapProperty('componentName')
  211. }.property('App.router.clusterController.isLoaded'),
  212. rollinRestartAllowed: function () {
  213. return App.StackServiceComponent.find().filterProperty('isRollinRestartAllowed').mapProperty('componentName')
  214. }.property('App.router.clusterController.isLoaded'),
  215. decommissionAllowed: function () {
  216. return App.StackServiceComponent.find().filterProperty('isDecommissionAllowed').mapProperty('componentName')
  217. }.property('App.router.clusterController.isLoaded'),
  218. refreshConfigsAllowed: function () {
  219. return App.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed').mapProperty('componentName')
  220. }.property('App.router.clusterController.isLoaded'),
  221. addableToHost: function () {
  222. return App.StackServiceComponent.find().filterProperty('isAddableToHost').mapProperty('componentName')
  223. }.property('App.router.clusterController.isLoaded'),
  224. addableMasterInstallerWizard: function () {
  225. return App.StackServiceComponent.find().filterProperty('isMasterAddableInstallerWizard').mapProperty('componentName')
  226. }.property('App.router.clusterController.isLoaded'),
  227. multipleMasters: function () {
  228. return App.StackServiceComponent.find().filterProperty('isMasterWithMultipleInstances').mapProperty('componentName')
  229. }.property('App.router.clusterController.isLoaded'),
  230. slaves: function () {
  231. return App.StackServiceComponent.find().filterProperty('isSlave').mapProperty('componentName')
  232. }.property('App.router.clusterController.isLoaded'),
  233. masters: function () {
  234. return App.StackServiceComponent.find().filterProperty('isMaster').mapProperty('componentName')
  235. }.property('App.router.clusterController.isLoaded'),
  236. clients: function () {
  237. return App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName')
  238. }.property('App.router.clusterController.isLoaded')
  239. })
  240. });