app.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  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. require('utils/bootstrap_reopen');
  22. var stringUtils = require('utils/string_utils');
  23. module.exports = Em.Application.create({
  24. name: 'Ambari Web',
  25. rootElement: '#wrapper',
  26. store: DS.Store.create({
  27. revision: 4,
  28. adapter: DS.FixtureAdapter.create({
  29. simulateRemoteResponse: false
  30. }),
  31. typeMaps: {},
  32. recordCache: []
  33. }),
  34. isAdmin: false,
  35. isOperator: false,
  36. isClusterUser: false,
  37. isPermissionDataLoaded: false,
  38. auth: undefined,
  39. isOnlyViewUser: function() {
  40. return App.auth && (App.auth.length == 0 || (App.isAuthorized('VIEW.USE') && App.auth.length == 1));
  41. }.property('auth'),
  42. /**
  43. * @type {boolean}
  44. * @default false
  45. */
  46. isKerberosEnabled: false,
  47. /**
  48. * state of stack upgrade process
  49. * states:
  50. * - INIT
  51. * - PENDING
  52. * - IN_PROGRESS
  53. * - HOLDING
  54. * - COMPLETED
  55. * - ABORTED
  56. * - HOLDING_FAILED
  57. * - HOLDING_TIMEDOUT
  58. * @type {String}
  59. */
  60. upgradeState: 'INIT',
  61. /**
  62. * flag is true when upgrade process is running
  63. * @returns {boolean}
  64. */
  65. upgradeInProgress: Em.computed.equal('upgradeState', 'IN_PROGRESS'),
  66. /**
  67. * Checks if update process is completed
  68. * @type {boolean}
  69. */
  70. upgradeCompleted: Em.computed.equal('upgradeState', 'COMPLETED'),
  71. /**
  72. * flag is true when upgrade process is waiting for user action
  73. * to proceed, retry, perform manual steps etc.
  74. * @returns {boolean}
  75. */
  76. upgradeHolding: function() {
  77. return this.get('upgradeState').contains("HOLDING") || this.get('upgradeAborted');
  78. }.property('upgradeState', 'upgradeAborted'),
  79. /**
  80. * flag is true when upgrade process is aborted
  81. * SHOULD behave similar to HOLDING_FAILED state
  82. * @returns {boolean}
  83. */
  84. upgradeAborted: function () {
  85. return this.get('upgradeState') === "ABORTED" && !App.router.get('mainAdminStackAndUpgradeController.isSuspended');
  86. }.property('upgradeState', 'router.mainAdminStackAndUpgradeController.isSuspended'),
  87. /**
  88. * flag is true when upgrade process is suspended
  89. * @returns {boolean}
  90. */
  91. upgradeSuspended: function () {
  92. return this.get('upgradeState') === "ABORTED" && App.router.get('mainAdminStackAndUpgradeController.isSuspended');
  93. }.property('upgradeState', 'router.mainAdminStackAndUpgradeController.isSuspended'),
  94. /**
  95. * RU is running
  96. * @type {boolean}
  97. */
  98. upgradeIsRunning: Em.computed.or('upgradeInProgress', 'upgradeHolding'),
  99. /**
  100. * flag is true when upgrade process is running or suspended
  101. * or wizard used by another user
  102. * @returns {boolean}
  103. */
  104. wizardIsNotFinished: function () {
  105. return this.get('upgradeIsRunning') ||
  106. this.get('upgradeSuspended') ||
  107. App.router.get('wizardWatcherController.isNonWizardUser');
  108. }.property('upgradeIsRunning', 'upgradeAborted', 'router.wizardWatcherController.isNonWizardUser', 'upgradeSuspended'),
  109. /**
  110. * Options:
  111. * - ignoreWizard: ignore when some wizard is running by another user (default `false`)
  112. *
  113. * @param {string} authRoles
  114. * @param {object} options
  115. * @returns {boolean}
  116. */
  117. isAuthorized: function (authRoles, options) {
  118. options = $.extend({ignoreWizard: false}, options);
  119. var result = false;
  120. authRoles = $.map(authRoles.split(","), $.trim);
  121. // When Upgrade running(not suspended) only operations related to upgrade should be allowed
  122. if ((!this.get('upgradeSuspended') && !authRoles.contains('CLUSTER.UPGRADE_DOWNGRADE_STACK')) &&
  123. !App.get('supports.opsDuringRollingUpgrade') &&
  124. !['INIT', 'COMPLETED'].contains(this.get('upgradeState')) ||
  125. !App.auth){
  126. return false;
  127. }
  128. if (!options.ignoreWizard && App.router.get('wizardWatcherController.isNonWizardUser')) {
  129. return false;
  130. }
  131. authRoles.forEach(function (auth) {
  132. result = result || App.auth.contains(auth);
  133. });
  134. return result;
  135. },
  136. isStackServicesLoaded: false,
  137. /**
  138. * return url prefix with number value of version of HDP stack
  139. */
  140. stackVersionURL: function () {
  141. return '/stacks/{0}/versions/{1}'.format(this.get('currentStackName') || 'HDP', this.get('currentStackVersionNumber'));
  142. }.property('currentStackName','currentStackVersionNumber'),
  143. falconServerURL: function () {
  144. var falconService = this.Service.find().findProperty('serviceName', 'FALCON');
  145. if (falconService) {
  146. return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('hostName');
  147. }
  148. return '';
  149. }.property().volatile(),
  150. /* Determine if Application Timeline Service supports Kerberization.
  151. * Because this value is retrieved from the cardinality of the component, it is safe to keep in app.js
  152. * since its value will not change during the lifetime of the application.
  153. */
  154. doesATSSupportKerberos: function() {
  155. var YARNService = App.StackServiceComponent.find().filterProperty('serviceName', 'YARN');
  156. if (YARNService.length) {
  157. var ATS = App.StackServiceComponent.find().findProperty('componentName', 'APP_TIMELINE_SERVER');
  158. return (!!ATS && !!ATS.get('minToInstall'));
  159. }
  160. return false;
  161. }.property('router.clusterController.isLoaded'),
  162. clusterName: null,
  163. clockDistance: null, // server clock - client clock
  164. currentStackVersion: '',
  165. currentStackName: function() {
  166. return Em.get((this.get('currentStackVersion') || this.get('defaultStackVersion')).match(/(.+)-\d.+/), '1');
  167. }.property('currentStackVersion', 'defaultStackVersion'),
  168. /**
  169. * true if cluster has only 1 host
  170. * for now is used to disable move/HA actions
  171. * @type {boolean}
  172. */
  173. isSingleNode: Em.computed.equal('allHostNames.length', 1),
  174. allHostNames: [],
  175. /**
  176. * This object is populated to keep track of uninstalled components to be included in the layout for recommendation/validation call
  177. * @type {object}
  178. * keys = componentName, hostName
  179. */
  180. componentToBeAdded: {},
  181. /**
  182. * This object is populated to keep track of installed components to be excluded in the layout for recommendation/validation call
  183. * @type {object}
  184. * keys = componentName, hostName
  185. */
  186. componentToBeDeleted: {},
  187. uiOnlyConfigDerivedFromTheme: [],
  188. currentStackVersionNumber: function () {
  189. var regExp = new RegExp(this.get('currentStackName') + '-');
  190. return (this.get('currentStackVersion') || this.get('defaultStackVersion')).replace(regExp, '');
  191. }.property('currentStackVersion', 'defaultStackVersion', 'currentStackName'),
  192. isHadoop23Stack: function () {
  193. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.3") > -1);
  194. }.property('currentStackVersionNumber'),
  195. isHadoopWindowsStack: Em.computed.equal('currentStackName', 'HDPWIN'),
  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. isMasterAddableOnlyOnHA: function () {
  277. return App.StackServiceComponent.find().filterProperty('isMasterAddableOnlyOnHA').mapProperty('componentName')
  278. }.property('App.router.clusterController.isLoaded'),
  279. allComponents: function () {
  280. return App.StackServiceComponent.find().mapProperty('componentName')
  281. }.property('App.router.clusterController.isLoaded'),
  282. reassignable: function () {
  283. return App.StackServiceComponent.find().filterProperty('isReassignable').mapProperty('componentName')
  284. }.property('App.router.clusterController.isLoaded'),
  285. restartable: function () {
  286. return App.StackServiceComponent.find().filterProperty('isRestartable').mapProperty('componentName')
  287. }.property('App.router.clusterController.isLoaded'),
  288. deletable: function () {
  289. return App.StackServiceComponent.find().filterProperty('isDeletable').mapProperty('componentName')
  290. }.property('App.router.clusterController.isLoaded'),
  291. rollinRestartAllowed: function () {
  292. return App.StackServiceComponent.find().filterProperty('isRollinRestartAllowed').mapProperty('componentName')
  293. }.property('App.router.clusterController.isLoaded'),
  294. decommissionAllowed: function () {
  295. return App.StackServiceComponent.find().filterProperty('isDecommissionAllowed').mapProperty('componentName')
  296. }.property('App.router.clusterController.isLoaded'),
  297. refreshConfigsAllowed: function () {
  298. return App.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed').mapProperty('componentName')
  299. }.property('App.router.clusterController.isLoaded'),
  300. addableToHost: function () {
  301. return App.StackServiceComponent.find().filterProperty('isAddableToHost').mapProperty('componentName')
  302. }.property('App.router.clusterController.isLoaded'),
  303. addableMasterInstallerWizard: function () {
  304. return App.StackServiceComponent.find().filterProperty('isMasterAddableInstallerWizard').mapProperty('componentName')
  305. }.property('App.router.clusterController.isLoaded'),
  306. multipleMasters: function () {
  307. return App.StackServiceComponent.find().filterProperty('isMasterWithMultipleInstances').mapProperty('componentName')
  308. }.property('App.router.clusterController.isLoaded'),
  309. slaves: function () {
  310. return App.StackServiceComponent.find().filterProperty('isSlave').mapProperty('componentName')
  311. }.property('App.router.clusterController.isLoaded'),
  312. masters: function () {
  313. return App.StackServiceComponent.find().filterProperty('isMaster').mapProperty('componentName')
  314. }.property('App.router.clusterController.isLoaded'),
  315. clients: function () {
  316. return App.StackServiceComponent.find().filterProperty('isClient').mapProperty('componentName')
  317. }.property('App.router.clusterController.isLoaded'),
  318. nonHDP: function () {
  319. return App.StackServiceComponent.find().filterProperty('isNonHDPComponent').mapProperty('componentName')
  320. }.property('App.router.clusterController.isLoaded')
  321. })
  322. });