app.js 13 KB

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