app.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. }),
  30. isAdmin: false,
  31. /**
  32. * return url prefix with number value of version of HDP stack
  33. */
  34. stackVersionURL:function(){
  35. var stackVersion = this.get('currentStackVersion') || this.get('defaultStackVersion');
  36. if(stackVersion.indexOf('HDPLocal') !== -1){
  37. return '/stacks/HDPLocal/version/' + stackVersion.replace(/HDPLocal-/g, '');
  38. }
  39. return '/stacks/HDP/version/' + stackVersion.replace(/HDP-/g, '');
  40. }.property('currentStackVersion'),
  41. /**
  42. * return url prefix with number value of version of HDP stack
  43. */
  44. stack2VersionURL:function(){
  45. var stackVersion = this.get('currentStackVersion') || this.get('defaultStackVersion');
  46. if(stackVersion.indexOf('HDPLocal') !== -1){
  47. return '/stacks2/HDPLocal/versions/' + stackVersion.replace(/HDPLocal-/g, '');
  48. }
  49. return '/stacks2/HDP/versions/' + stackVersion.replace(/HDP-/g, '');
  50. }.property('currentStackVersion'),
  51. falconServerURL: function () {
  52. var falconService = this.Service.find().findProperty('serviceName', 'FALCON');
  53. if (falconService) {
  54. return falconService.get('hostComponents').findProperty('componentName', 'FALCON_SERVER').get('host.hostName');
  55. }
  56. return '';
  57. }.property().volatile(),
  58. clusterName: null,
  59. clockDistance:null, // server clock - client clock
  60. currentStackVersion: '',
  61. currentStackVersionNumber: function(){
  62. return this.get('currentStackVersion').replace(/HDP(Local)?-/, '');
  63. }.property('currentStackVersion'),
  64. isHadoop2Stack: function(){
  65. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") === 1 ||
  66. stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.0") === 0)
  67. }.property('currentStackVersionNumber'),
  68. isHadoop21Stack: function(){
  69. return (stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.1") === 1 ||
  70. stringUtils.compareVersions(this.get('currentStackVersionNumber'), "2.1") === 0)
  71. }.property('currentStackVersionNumber'),
  72. /**
  73. * If High Availability is enabled
  74. * Based on <code>clusterStatus.isInstalled</code>, stack version, <code>SNameNode</code> availability
  75. *
  76. * @type {bool}
  77. */
  78. isHaEnabled: function() {
  79. if (!this.get('isHadoop2Stack')) return false;
  80. return !this.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
  81. }.property('router.clusterController.isLoaded', 'isHadoop2Stack'),
  82. /**
  83. * List of disabled components for the current stack with related info.
  84. * Each element has followed structure:
  85. * @type {Em.Enumerable.<Em.Object>}
  86. * @property componentName {String} - name of the component
  87. * @property properties {Object} - mapped properties by site files,
  88. * for example:
  89. * properties: { global_properties: [], site_properties: [], etc. }
  90. * @property reviewConfigs {Ember.Object} - reference review_configs.js
  91. */
  92. stackDependedComponents: [],
  93. /**
  94. * Restore component data that was excluded from stack.
  95. *
  96. * @param component {Ember.Object} - #stackDependedComponents item
  97. */
  98. enableComponent: function(component) {
  99. var propertyFileNames = ['global_properties', 'site_properties'];
  100. var requirePrefix = this.get('isHadoop2Stack') ? 'data/HDP2/' : 'data/';
  101. // add properties
  102. propertyFileNames.forEach(function(fileName) {
  103. require(requirePrefix + fileName).configProperties = require(requirePrefix + fileName).configProperties.concat(component.get('properties.'+fileName));
  104. });
  105. var reviewConfigsService = require('data/review_configs')
  106. .findProperty('config_name', 'services').config_value
  107. .findProperty('service_name', component.get('serviceName'));
  108. reviewConfigsService.get('service_components').pushObject(component.get('reviewConfigs'));
  109. },
  110. /**
  111. * Disabling component. Remove related data from lists such as
  112. * properties, review configs, service components.
  113. *
  114. * @param component {Object} - stack service component
  115. *
  116. * @return {Ember.Object} - item of <code>stackDependedComponents</code> property
  117. */
  118. disableComponent: function(component) {
  119. var componentCopy, propertyFileNames;
  120. var service_configs = require('data/service_configs');
  121. propertyFileNames = ['global_properties', 'site_properties'];
  122. componentCopy = Em.Object.create({
  123. componentName: component.get('componentName'),
  124. serviceName: component.get('serviceName'),
  125. properties: {},
  126. reviewConfigs: {},
  127. configCategory: {}
  128. });
  129. var serviceConfigsCategoryName, requirePrefix, serviceConfig;
  130. // get service category name related to component
  131. serviceConfig = service_configs.findProperty('serviceName', component.get('serviceName'));
  132. serviceConfig.configCategories = serviceConfig.configCategories.filter(function(configCategory) {
  133. if (configCategory.get('hostComponentNames')) {
  134. serviceConfigsCategoryName = configCategory.get('name');
  135. if (configCategory.get('hostComponentNames').contains(component.get('componentName'))) {
  136. componentCopy.set('configCategory', configCategory);
  137. }
  138. }
  139. return true;
  140. });
  141. requirePrefix = this.get('isHadoop2Stack') ? 'data/HDP2/' : 'data/';
  142. var propertyObj = {};
  143. propertyFileNames.forEach(function(propertyFileName) {
  144. propertyObj[propertyFileName] = [];
  145. });
  146. // remove config properties related to this component
  147. propertyFileNames.forEach(function(propertyFileName) {
  148. var properties = require(requirePrefix + propertyFileName);
  149. properties.configProperties = properties.configProperties.filter(function(property) {
  150. if (property.category == serviceConfigsCategoryName) {
  151. propertyObj[propertyFileName].push(property);
  152. return false;
  153. } else {
  154. return true;
  155. }
  156. });
  157. });
  158. componentCopy.set('properties', propertyObj);
  159. // remove component from review configs
  160. var reviewConfigsService = require('data/review_configs')
  161. .findProperty('config_name', 'services').config_value
  162. .findProperty('service_name', component.get('serviceName'));
  163. //review_configs might not contain particular service
  164. if (reviewConfigsService) {
  165. reviewConfigsService.set('service_components', reviewConfigsService.get('service_components').filter(function (serviceComponent) {
  166. if (serviceComponent.get('component_name') != component.get('componentName')) {
  167. return true;
  168. } else {
  169. componentCopy.set('reviewConfigs', serviceComponent);
  170. return false;
  171. }
  172. }));
  173. }
  174. return componentCopy;
  175. },
  176. /**
  177. * Resolve dependency in components.
  178. * if component with config category from "data/service_configs" doesn't match components from stack
  179. * then disable it and push to stackDependedComponents
  180. * otherwise enable component and remove it from stackDependedComponents
  181. * Check forbidden/allowed components and
  182. * remove/restore related data.
  183. *
  184. * @method handleStackDependedComponents
  185. */
  186. handleStackDependedComponents: function () {
  187. // need for unit testing and test mode
  188. if (this.get('handleStackDependencyTest') || this.testMode) return;
  189. var stackDependedComponents = this.get('stackDependedComponents');
  190. var service_configs = require('data/service_configs');
  191. var stackServiceComponents = this.StackServiceComponent.find();
  192. var stackServices = stackServiceComponents.mapProperty('serviceName').uniq();
  193. if (!stackServiceComponents.mapProperty('componentName').length) {
  194. return;
  195. }
  196. // disable components
  197. service_configs.forEach(function (service) {
  198. service.configCategories.forEach(function (serviceConfigCategory) {
  199. var categoryComponents = serviceConfigCategory.get('hostComponentNames');
  200. if (categoryComponents && categoryComponents.length) {
  201. categoryComponents.forEach(function (categoryComponent) {
  202. var stackServiceComponent = stackServiceComponents.findProperty('componentName', categoryComponent);
  203. // populate App.stackDependedComponents if the service config category for the serviceComponent
  204. // exists in the 'data/service_configs.js' and the service to which the component belongs also exists in the
  205. // stack but the serviceComponent does not exists in the stack. Also check App.stackDependedComponents doesn't already have the componentName
  206. if (!stackServiceComponent && stackServices.contains(service.serviceName) &&
  207. !stackDependedComponents.mapProperty('componentName').contains['categoryComponent']) {
  208. var _stackServiceComponent = Ember.Object.create({
  209. componentName: categoryComponent,
  210. serviceName: service.serviceName
  211. });
  212. stackDependedComponents.push(this.disableComponent(_stackServiceComponent));
  213. }
  214. }, this);
  215. }
  216. }, this);
  217. }, this);
  218. // enable components
  219. if (stackDependedComponents.length > 0) {
  220. stackDependedComponents.forEach(function (component) {
  221. if (stackServiceComponents.someProperty('componentName', component.get('componentName'))) {
  222. this.enableComponent(component);
  223. stackDependedComponents.removeObject(component);
  224. }
  225. }, this);
  226. }
  227. this.set('stackDependedComponents', stackDependedComponents);
  228. },
  229. /**
  230. * List of components with allowed action for them
  231. * @type {Em.Object}
  232. */
  233. components: function() {
  234. return Em.Object.create({
  235. allComponents:this.StackServiceComponent.find().mapProperty('componentName'),
  236. reassignable: this.StackServiceComponent.find().filterProperty('isReassignable',true).mapProperty('componentName'),
  237. restartable: this.StackServiceComponent.find().filterProperty('isRestartable',true).mapProperty('componentName'),
  238. deletable: this.StackServiceComponent.find().filterProperty('isDeletable',true).mapProperty('componentName'),
  239. rollinRestartAllowed: this.StackServiceComponent.find().filterProperty('isRollinRestartAllowed',true).mapProperty('componentName'),
  240. decommissionAllowed: this.StackServiceComponent.find().filterProperty('isDecommissionAllowed',true).mapProperty('componentName'),
  241. refreshConfigsAllowed: this.StackServiceComponent.find().filterProperty('isRefreshConfigsAllowed',true).mapProperty('componentName'),
  242. addableToHost: this.StackServiceComponent.find().filterProperty('isAddableToHost',true).mapProperty('componentName'),
  243. slaves: this.StackServiceComponent.find().filterProperty('isMaster',false).filterProperty('isClient',false).mapProperty('componentName'),
  244. masters: this.StackServiceComponent.find().filterProperty('isMaster',true).mapProperty('componentName'),
  245. clients: this.StackServiceComponent.find().filterProperty('isClient',true).mapProperty('componentName')
  246. });
  247. }.property('App.router.clusterController.isLoaded')
  248. });