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