app.js 12 KB

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