app.js 12 KB

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