app.js 14 KB

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