app.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. /**
  68. * If High Availability is enabled
  69. * Based on <code>clusterStatus.isInstalled</code>, stack version, <code>SNameNode</code> availability
  70. *
  71. * @type {Boolean}
  72. */
  73. isHaEnabled: function() {
  74. if (!this.get('isHadoop2Stack')) return false;
  75. return !this.HostComponent.find().someProperty('componentName', 'SECONDARY_NAMENODE');
  76. }.property('router.clusterController.isLoaded'),
  77. /**
  78. * List of disabled components for the current stack with related info.
  79. * Each element has followed structure:
  80. * @type {Em.Object}
  81. * @property componentName {String} - name of the component
  82. * @property properties {Object} - mapped properties by site files,
  83. * for example:
  84. * properties: { global_properties: [], site_properties: [], etc. }
  85. * @property reviewConfigs {Ember.Object} - reference review_configs.js
  86. * @property serviceComponent {Object} - reference service_components.js
  87. *
  88. * @type {Array}
  89. */
  90. stackDependedComponents: [],
  91. /**
  92. * Restore component data that was excluded from stack.
  93. *
  94. * @param component {Ember.Object} - #stackDependedComponents item
  95. */
  96. enableComponent: function(component) {
  97. var propertyFileNames = ['global_properties', 'site_properties'];
  98. var requirePrefix = this.get('isHadoop2Stack') ? 'data/HDP2/' : 'data/';
  99. // add component to service_components list
  100. require('data/service_components').push(component.get('serviceComponent'));
  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('serviceComponent.service_name'));
  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} - component info reference service_components.js
  115. *
  116. * @return {Ember.Object} - item of <code>stackDependedComponents</code> property
  117. */
  118. disableComponent: function(component) {
  119. var componentCopy, propertyFileNames;
  120. propertyFileNames = ['global_properties', 'site_properties'];
  121. componentCopy = Em.Object.create({
  122. componentName: component.component_name,
  123. properties: {},
  124. reviewConfigs: {},
  125. configCategory: {},
  126. serviceComponent: {}
  127. });
  128. componentCopy.set('serviceComponent', require('data/service_components').findProperty('component_name', component.component_name));
  129. // remove component from service_components list
  130. require('data/service_components').removeObject(componentCopy.get('serviceComponent'));
  131. var serviceConfigsCategoryName, requirePrefix, serviceConfig;
  132. // get service category name related to component
  133. serviceConfig = require('data/service_configs').findProperty('serviceName', component.service_name);
  134. serviceConfig.configCategories = serviceConfig.configCategories.filter(function(configCategory) {
  135. if (configCategory.get('hostComponentNames')) {
  136. serviceConfigsCategoryName = configCategory.get('name');
  137. if (configCategory.get('hostComponentNames').contains(component.component_name)) {
  138. componentCopy.set('configCategory', configCategory);
  139. }
  140. }
  141. return true;
  142. });
  143. requirePrefix = this.get('isHadoop2Stack') ? 'data/HDP2/' : 'data/';
  144. var propertyObj = {};
  145. propertyFileNames.forEach(function(propertyFileName) {
  146. propertyObj[propertyFileName] = [];
  147. });
  148. // remove config properties related to this component
  149. propertyFileNames.forEach(function(propertyFileName) {
  150. var properties = require(requirePrefix + propertyFileName);
  151. properties.configProperties = properties.configProperties.filter(function(property) {
  152. if (property.category == serviceConfigsCategoryName) {
  153. propertyObj[propertyFileName].push(property);
  154. return false;
  155. } else {
  156. return true;
  157. }
  158. });
  159. });
  160. componentCopy.set('properties', propertyObj);
  161. // remove component from review configs
  162. var reviewConfigsService = require('data/review_configs')
  163. .findProperty('config_name', 'services').config_value
  164. .findProperty('service_name', component.service_name);
  165. reviewConfigsService.set('service_components', reviewConfigsService.get('service_components').filter(function (serviceComponent) {
  166. if (serviceComponent.get('component_name') != component.component_name) {
  167. return true;
  168. } else {
  169. componentCopy.set('reviewConfigs', serviceComponent);
  170. return false;
  171. }
  172. }));
  173. return componentCopy;
  174. },
  175. /**
  176. * Resolve dependency in components. Check forbidden/allowed components and
  177. * remove/restore related data.
  178. */
  179. handleStackDependedComponents: function() {
  180. // need for unit testing and test mode
  181. if (this.get('handleStackDependencyTest') || this.testMode) return;
  182. var stackVersion, stackDependedComponents;
  183. stackVersion = this.get('currentStackVersionNumber');
  184. stackDependedComponents = [];
  185. // disable components
  186. require('data/service_components').filterProperty('stackVersions').forEach(function(component) {
  187. if (!component.stackVersions.contains(stackVersion))
  188. stackDependedComponents.push(this.disableComponent(component));
  189. }, this);
  190. // enable components
  191. if (this.get('stackDependedComponents').length > 0) {
  192. this.get('stackDependedComponents').forEach(function(component) {
  193. if (component.get('serviceComponent').stackVersions.contains(this.get('currentStackVersionNumber'))) {
  194. this.enableComponent(component);
  195. stackDependedComponents = this.get('stackDependedComponents').removeObject(component);
  196. }
  197. }, this);
  198. }
  199. this.set('stackDependedComponents', this.get('stackDependedComponents').concat(stackDependedComponents));
  200. }.observes('currentStackVersionNumber'),
  201. /**
  202. * List of components with allowed action for them
  203. * @type {Em.Object}
  204. */
  205. components: Ember.Object.create({
  206. reassignable: ['NAMENODE', 'SECONDARY_NAMENODE', 'JOBTRACKER', 'RESOURCEMANAGER'],
  207. restartable: function() {
  208. return this.get('masters').concat(this.get('slaves'));
  209. }.property('masters'),
  210. deletable: ['SUPERVISOR', 'HBASE_MASTER', 'DATANODE', 'TASKTRACKER', 'NODEMANAGER', 'HBASE_REGIONSERVER'],
  211. rollinRestartAllowed: ["DATANODE", "TASKTRACKER", "NODEMANAGER", "HBASE_REGIONSERVER", "SUPERVISOR"],
  212. decommissionAllowed: ["DATANODE", "TASKTRACKER", "NODEMANAGER", "HBASE_REGIONSERVER"],
  213. addableToHost: ["DATANODE", "TASKTRACKER", "NODEMANAGER", "HBASE_REGIONSERVER", "HBASE_MASTER", "ZOOKEEPER_SERVER", "SUPERVISOR"],
  214. slaves: function() {
  215. return require('data/service_components').filter(function(component){
  216. return !component.isClient && !component.isMaster;
  217. }).mapProperty('component_name').uniq().without("DASHBOARD").without("MYSQL_SERVER");
  218. }.property().cacheable(),
  219. masters: function() {
  220. return require('data/service_components').filterProperty('isMaster', true)
  221. .mapProperty('component_name').concat(['MYSQL_SERVER']).uniq();
  222. }.property().cacheable(),
  223. clients: function() {
  224. return require('data/service_components').filterProperty('isClient', true).mapProperty('component_name').uniq();
  225. }.property().cacheable()
  226. })
  227. });