app.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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. require('utils/ember_computed');
  21. var stringUtils = require('utils/string_utils');
  22. module.exports = Em.Application.create({
  23. name: 'Ambari Web',
  24. rootElement: '#wrapper',
  25. store: DS.Store.create({
  26. revision: 4,
  27. adapter: DS.FixtureAdapter.create({
  28. simulateRemoteResponse: false
  29. }),
  30. typeMaps: {},
  31. recordCache: []
  32. }),
  33. isAdmin: false,
  34. isOperator: false,
  35. isPermissionDataLoaded: false,
  36. /**
  37. * state of stack upgrade process
  38. * states:
  39. * - INIT
  40. * - PENDING
  41. * - IN_PROGRESS
  42. * - HOLDING
  43. * - COMPLETED
  44. * @type {String}
  45. */
  46. upgradeState: 'INIT',
  47. /**
  48. * flag is true when upgrade process is running
  49. * @returns {boolean}
  50. */
  51. upgradeInProgress: Em.computed.equal('upgradeState', 'IN_PROGRESS'),
  52. /**
  53. * flag is true when upgrade process is waiting for user action
  54. * to procced, retry, perform manual steps etc.
  55. * @returns {boolean}
  56. */
  57. upgradeHolding: function() {
  58. return this.get('upgradeState').contains("HOLDING");
  59. }.property('upgradeState'),
  60. /**
  61. * flag is true when upgrade process is aborted
  62. * @returns {boolean}
  63. */
  64. upgradeAborted: function () {
  65. return this.get('upgradeState') === "ABORTED" && !App.router.get('mainAdminStackAndUpgradeController.isSuspended');
  66. }.property('upgradeState', 'router.mainAdminStackAndUpgradeController.isSuspended'),
  67. /**
  68. * RU is running
  69. * @type {boolean}
  70. */
  71. upgradeIsRunning: function() {
  72. return this.get('upgradeInProgress') || this.get('upgradeHolding');
  73. }.property('upgradeInProgress', 'upgradeHolding'),
  74. /**
  75. * flag is true when upgrade process is running or aborted
  76. * or wizard used by another user
  77. * @returns {boolean}
  78. */
  79. wizardIsNotFinished: function () {
  80. return this.get('upgradeIsRunning') ||
  81. this.get('upgradeAborted') ||
  82. App.router.get('wizardWatcherController.isNonWizardUser') ||
  83. App.router.get('mainAdminStackAndUpgradeController.isSuspended');
  84. }.property('upgradeIsRunning', 'upgradeAborted', 'router.wizardWatcherController.isNonWizardUser', 'router.mainAdminStackAndUpgradeController.isSuspended'),
  85. /**
  86. * compute user access rights by permission type
  87. * types:
  88. * - ADMIN
  89. * - MANAGER
  90. * - OPERATOR
  91. * - ONLY_ADMIN
  92. * prefix "upgrade_" mean that element will not be unconditionally blocked while stack upgrade running
  93. * @param type {string}
  94. * @return {boolean}
  95. */
  96. isAccessible: function (type) {
  97. if (!App.router.get('mainAdminStackAndUpgradeController.isSuspended') &&
  98. !App.get('supports.opsDuringRollingUpgrade') &&
  99. !['INIT', 'COMPLETED'].contains(this.get('upgradeState')) &&
  100. !type.contains('upgrade_')) {
  101. return false;
  102. }
  103. if (App.router.get('wizardWatcherController.isNonWizardUser')) {
  104. return false;
  105. }
  106. if (type.contains('upgrade_')) {
  107. //slice off "upgrade_" prefix to have actual permission type
  108. type = type.slice(8);
  109. }
  110. switch (type) {
  111. case 'ADMIN':
  112. return this.get('isAdmin');
  113. case 'NON_ADMIN':
  114. return !this.get('isAdmin');
  115. case 'MANAGER':
  116. return this.get('isAdmin') || this.get('isOperator');
  117. case 'OPERATOR':
  118. return this.get('isOperator');
  119. case 'ONLY_ADMIN':
  120. return this.get('isAdmin') && !this.get('isOperator');
  121. default:
  122. return false;
  123. }
  124. },
  125. isStackServicesLoaded: false,
  126. /**
  127. * return url prefix with number value of version of HDP stack
  128. */
  129. stackVersionURL: function () {
  130. return '/stacks/{0}/versions/{1}'.format(this.get('currentStackName') || 'HDP', this.get('currentStackVersionNumber'));
  131. }.property('currentStackName','currentStackVersionNumber'),
  132. falconServerURL: function () {
  133. var falconService = this.Service.find().findProperty('serviceName', 'FALCON');
  134. if (falconService) {
  135. return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('hostName');
  136. }
  137. return '';
  138. }.property().volatile(),
  139. /* Determine if Application Timeline Service supports Kerberization.
  140. * Because this value is retrieved from the cardinality of the component, it is safe to keep in app.js
  141. * since its value will not change during the lifetime of the application.
  142. */
  143. doesATSSupportKerberos: function() {
  144. var YARNService = App.StackServiceComponent.find().filterProperty('serviceName', 'YARN');
  145. if (YARNService.length) {
  146. var ATS = App.StackServiceComponent.find().findProperty('componentName', 'APP_TIMELINE_SERVER');
  147. return (!!ATS && !!ATS.get('minToInstall'));
  148. }
  149. return false;
  150. }.property('router.clusterController.isLoaded'),
  151. clusterName: null,
  152. clockDistance: null, // server clock - client clock
  153. currentStackVersion: '',
  154. currentStackName: function() {
  155. return Em.get((this.get('currentStackVersion') || this.get('defaultStackVersion')).match(/(.+)-\d.+/), '1');
  156. }.property('currentStackVersion', 'defaultStackVersion'),
  157. /**
  158. * true if cluster has only 1 host
  159. * for now is used to disable move/HA actions
  160. * @type {boolean}
  161. */
  162. isSingleNode: function() {
  163. return this.get('allHostNames.length') === 1;
  164. }.property('allHostNames.length'),
  165. allHostNames: [],
  166. uiOnlyConfigDerivedFromTheme: [],
  167. currentStackVersionNumber: function () {
  168. var regExp = new RegExp(this.get('currentStackName') + '-');
  169. return (this.get('currentStackVersion') || this.get('defaultStackVersion')).replace(regExp, '');
  170. }.property('currentStackVersion', 'defaultStackVersion', 'currentStackName'),
  171. isHadoop23Stack: function () {
  172. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.3") > -1);
  173. }.property('currentStackVersionNumber'),
  174. isHadoop22Stack: function () {
  175. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.2") > -1);
  176. }.property('currentStackVersionNumber'),
  177. /**
  178. * Determines if current stack is 2.0.*
  179. * @type {boolean}
  180. */
  181. isHadoop20Stack: function () {
  182. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.1") == -1 && stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") > -1);
  183. }.property('currentStackVersionNumber'),
  184. isHadoopWindowsStack: function() {
  185. return this.get('currentStackName') == "HDPWIN";
  186. }.property('currentStackName'),
  187. /**
  188. * when working with enhanced configs we should rely on stack version
  189. * as version that is below 2.2 doesn't supports it
  190. * even if flag <code>supports.enhancedConfigs<code> is true
  191. * @type {boolean}
  192. */
  193. isClusterSupportsEnhancedConfigs: function() {
  194. return this.get('isHadoop22Stack') && this.get('supports.enhancedConfigs');
  195. }.property('isHadoop22Stack', 'supports.enhancedConfigs'),
  196. /**
  197. * If NameNode High Availability is enabled
  198. * Based on <code>clusterStatus.isInstalled</code>, stack version, <code>SNameNode</code> availability
  199. *
  200. * @type {bool}
  201. */
  202. isHaEnabled: function () {
  203. return App.Service.find('HDFS').get('isLoaded') && !App.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
  204. }.property('router.clusterController.dataLoadList.services', 'router.clusterController.isServiceContentFullyLoaded'),
  205. /**
  206. * If ResourceManager High Availability is enabled
  207. * Based on number of ResourceManager host components installed
  208. *
  209. * @type {bool}
  210. */
  211. isRMHaEnabled: function () {
  212. var result = false;
  213. var rmStackComponent = App.StackServiceComponent.find().findProperty('componentName','RESOURCEMANAGER');
  214. if (rmStackComponent && rmStackComponent.get('isMultipleAllowed')) {
  215. result = this.HostComponent.find().filterProperty('componentName', 'RESOURCEMANAGER').length > 1;
  216. }
  217. return result;
  218. }.property('router.clusterController.isLoaded', 'isStackServicesLoaded'),
  219. /**
  220. * If Ranger Admin High Availability is enabled
  221. * Based on number of Ranger Admin host components installed
  222. *
  223. * @type {bool}
  224. */
  225. isRAHaEnabled: function () {
  226. var result = false;
  227. var raStackComponent = App.StackServiceComponent.find().findProperty('componentName','RANGER_ADMIN');
  228. if (raStackComponent && raStackComponent.get('isMultipleAllowed')) {
  229. result = App.HostComponent.find().filterProperty('componentName', 'RANGER_ADMIN').length > 1;
  230. }
  231. return result;
  232. }.property('router.clusterController.isLoaded', 'isStackServicesLoaded'),
  233. /**
  234. * Object with utility functions for list of service names with similar behavior
  235. */
  236. services: Em.Object.create({
  237. all: function () {
  238. return App.StackService.find().mapProperty('serviceName');
  239. }.property('App.router.clusterController.isLoaded'),
  240. clientOnly: function () {
  241. return App.StackService.find().filterProperty('isClientOnlyService').mapProperty('serviceName');
  242. }.property('App.router.clusterController.isLoaded'),
  243. hasClient: function () {
  244. return App.StackService.find().filterProperty('hasClient').mapProperty('serviceName');
  245. }.property('App.router.clusterController.isLoaded'),
  246. hasMaster: function () {
  247. return App.StackService.find().filterProperty('hasMaster').mapProperty('serviceName');
  248. }.property('App.router.clusterController.isLoaded'),
  249. hasSlave: function () {
  250. return App.StackService.find().filterProperty('hasSlave').mapProperty('serviceName');
  251. }.property('App.router.clusterController.isLoaded'),
  252. noConfigTypes: function () {
  253. return App.StackService.find().filterProperty('isNoConfigTypes').mapProperty('serviceName');
  254. }.property('App.router.clusterController.isLoaded'),
  255. servicesWithHeatmapTab: function () {
  256. return App.StackService.find().filterProperty('hasHeatmapSection').mapProperty('serviceName');
  257. }.property('App.router.clusterController.isLoaded'),
  258. monitoring: function () {
  259. return App.StackService.find().filterProperty('isMonitoringService').mapProperty('serviceName');
  260. }.property('App.router.clusterController.isLoaded'),
  261. hostMetrics: function () {
  262. return App.StackService.find().filterProperty('isHostMetricsService').mapProperty('serviceName');
  263. }.property('App.router.clusterController.isLoaded'),
  264. serviceMetrics: function () {
  265. return App.StackService.find().filterProperty('isServiceMetricsService').mapProperty('serviceName');
  266. }.property('App.router.clusterController.isLoaded'),
  267. supportsServiceCheck: function() {
  268. return App.StackService.find().filterProperty('serviceCheckSupported').mapProperty('serviceName');
  269. }.property('App.router.clusterController.isLoaded')
  270. }),
  271. /**
  272. * List of components with allowed action for them
  273. * @type {Em.Object}
  274. */
  275. components: Em.Object.create({
  276. allComponents: function () {
  277. return App.StackServiceComponent.find().mapProperty('componentName')
  278. }.property('App.router.clusterController.isLoaded'),
  279. reassignable: function () {
  280. return App.StackServiceComponent.find().filterProperty('isReassignable').mapProperty('componentName')
  281. }.property('App.router.clusterController.isLoaded'),
  282. restartable: function () {
  283. return App.StackServiceComponent.find().filterProperty('isRestartable').mapProperty('componentName')
  284. }.property('App.router.clusterController.isLoaded'),
  285. deletable: function () {
  286. return App.StackServiceComponent.find().filterProperty('isDeletable').mapProperty('componentName')
  287. }.property('App.router.clusterController.isLoaded'),
  288. rollinRestartAllowed: function () {
  289. return App.StackServiceComponent.find().filterProperty('isRollinRestartAllowed').mapProperty('componentName')
  290. }.property('App.router.clusterController.isLoaded'),
  291. decommissionAllowed: function () {
  292. return App.StackServiceComponent.find().filterProperty('isDecommissionAllowed').mapProperty('componentName')
  293. }.property('App.router.clusterController.isLoaded'),
  294. refreshConfigsAllowed: function () {
  295. return App.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed').mapProperty('componentName')
  296. }.property('App.router.clusterController.isLoaded'),
  297. addableToHost: function () {
  298. return App.StackServiceComponent.find().filterProperty('isAddableToHost').mapProperty('componentName')
  299. }.property('App.router.clusterController.isLoaded'),
  300. addableMasterInstallerWizard: function () {
  301. return App.StackServiceComponent.find().filterProperty('isMasterAddableInstallerWizard').mapProperty('componentName')
  302. }.property('App.router.clusterController.isLoaded'),
  303. multipleMasters: function () {
  304. return App.StackServiceComponent.find().filterProperty('isMasterWithMultipleInstances').mapProperty('componentName')
  305. }.property('App.router.clusterController.isLoaded'),
  306. slaves: function () {
  307. return App.StackServiceComponent.find().filterProperty('isSlave').mapProperty('componentName')
  308. }.property('App.router.clusterController.isLoaded'),
  309. masters: function () {
  310. return App.StackServiceComponent.find().filterProperty('isMaster').mapProperty('componentName')
  311. }.property('App.router.clusterController.isLoaded'),
  312. clients: function () {
  313. return App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName')
  314. }.property('App.router.clusterController.isLoaded')
  315. })
  316. });