app.js 11 KB

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