config.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  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. var App = require('app');
  19. var stringUtils = require('utils/string_utils');
  20. var serviceComponents = {};
  21. var configGroupsByTag = [];
  22. var globalPropertyToServicesMap = null;
  23. App.config = Em.Object.create({
  24. preDefinedServiceConfigs: function(){
  25. var configs = this.get('preDefinedConfigProperties');
  26. var services = [];
  27. require('data/service_configs').forEach(function(service){
  28. service.configs = configs.filterProperty('serviceName', service.serviceName);
  29. services.push(service);
  30. });
  31. return services;
  32. }.property('preDefinedConfigProperties'),
  33. configMapping: function() {
  34. if (App.get('isHadoop2Stack')) {
  35. return require('data/HDP2/config_mapping');
  36. }
  37. return require('data/config_mapping');
  38. }.property('App.isHadoop2Stack'),
  39. preDefinedConfigProperties: function() {
  40. if (App.get('isHadoop2Stack')) {
  41. return require('data/HDP2/config_properties').configProperties;
  42. }
  43. return require('data/config_properties').configProperties;
  44. }.property('App.isHadoop2Stack'),
  45. preDefinedCustomConfigs: function () {
  46. if (App.get('isHadoop2Stack')) {
  47. return require('data/HDP2/custom_configs');
  48. }
  49. return require('data/custom_configs');
  50. }.property('App.isHadoop2Stack'),
  51. //categories which contain custom configs
  52. categoriesWithCustom: ['CapacityScheduler'],
  53. //configs with these filenames go to appropriate category not in Advanced
  54. customFileNames: function() {
  55. if (App.supports.capacitySchedulerUi) {
  56. if(App.get('isHadoop2Stack')){
  57. return ['capacity-scheduler.xml'];
  58. }
  59. return ['capacity-scheduler.xml', 'mapred-queue-acls.xml'];
  60. } else {
  61. return [];
  62. }
  63. }.property('App.isHadoop2Stack'),
  64. /**
  65. * Cache of loaded configurations. This is useful in not loading
  66. * same configuration multiple times. It is populated in multiple
  67. * places.
  68. *
  69. * Example:
  70. * {
  71. * 'global_version1': {...},
  72. * 'global_version2': {...},
  73. * 'hdfs-site_version3': {...},
  74. * }
  75. */
  76. loadedConfigurationsCache: {},
  77. /**
  78. * Array of global "service/desired_tag/actual_tag" strings which
  79. * indicate different configurations. We cache these so that
  80. * we dont have to recalculate if two tags are difference.
  81. */
  82. differentGlobalTagsCache:[],
  83. identifyCategory: function(config){
  84. var category = null;
  85. var serviceConfigMetaData = this.get('preDefinedServiceConfigs').findProperty('serviceName', config.serviceName);
  86. if (serviceConfigMetaData) {
  87. serviceConfigMetaData.configCategories.forEach(function (_category) {
  88. if (_category.siteFileNames && Array.isArray(_category.siteFileNames) && _category.siteFileNames.contains(config.filename)) {
  89. category = _category;
  90. }
  91. });
  92. category = (category == null) ? serviceConfigMetaData.configCategories.findProperty('siteFileName', config.filename) : category;
  93. }
  94. return category;
  95. },
  96. /**
  97. * additional handling for special properties such as
  98. * checkbox and digital which values with 'm' at the end
  99. * @param config
  100. */
  101. handleSpecialProperties: function(config){
  102. if (config.displayType === 'int' && /\d+m$/.test(config.value)) {
  103. config.value = config.value.slice(0, config.value.length - 1);
  104. config.defaultValue = config.value;
  105. }
  106. if (config.displayType === 'checkbox') {
  107. config.value = (config.value === 'true') ? config.defaultValue = true : config.defaultValue = false;
  108. }
  109. },
  110. /**
  111. * calculate config properties:
  112. * category, filename, isRequired, isUserProperty
  113. * @param config
  114. * @param isAdvanced
  115. * @param advancedConfigs
  116. */
  117. calculateConfigProperties: function(config, isAdvanced, advancedConfigs){
  118. if (!isAdvanced || this.get('customFileNames').contains(config.filename)) {
  119. var categoryMetaData = this.identifyCategory(config);
  120. if (categoryMetaData != null) {
  121. config.category = categoryMetaData.get('name');
  122. if(!isAdvanced) config.isUserProperty = true;
  123. }
  124. } else {
  125. config.category = 'Advanced';
  126. config.filename = isAdvanced && advancedConfigs.findProperty('name', config.name).filename;
  127. config.isRequired = true;
  128. }
  129. },
  130. capacitySchedulerFilter: function () {
  131. var yarnRegex = /^yarn\.scheduler\.capacity\.root\.(?!unfunded)([a-z]([\_\-a-z0-9]{0,50}))\.(acl_administer_jobs|acl_submit_jobs|state|user-limit-factor|maximum-capacity|capacity)$/i;
  132. var self = this;
  133. if(App.get('isHadoop2Stack')){
  134. return function (_config) {
  135. return (yarnRegex.test(_config.name));
  136. }
  137. } else {
  138. return function (_config) {
  139. return (_config.name.indexOf('mapred.capacity-scheduler.queue.') !== -1) ||
  140. (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
  141. }
  142. }
  143. }.property('App.isHadoop2Stack'),
  144. /**
  145. * return:
  146. * configs,
  147. * globalConfigs,
  148. * mappingConfigs
  149. *
  150. * @param configGroups
  151. * @param advancedConfigs
  152. * @param tags
  153. * @param serviceName
  154. * @return {object}
  155. */
  156. mergePreDefinedWithLoaded: function (configGroups, advancedConfigs, tags, serviceName) {
  157. var configs = [];
  158. var globalConfigs = [];
  159. var preDefinedConfigs = this.get('preDefinedConfigProperties');
  160. var mappingConfigs = [];
  161. tags.forEach(function (_tag) {
  162. var isAdvanced = null;
  163. var properties = configGroups.filter(function (serviceConfigProperties) {
  164. return _tag.tagName === serviceConfigProperties.tag && _tag.siteName === serviceConfigProperties.type;
  165. });
  166. properties = (properties.length) ? properties.objectAt(0).properties : {};
  167. for (var index in properties) {
  168. var configsPropertyDef = preDefinedConfigs.findProperty('name', index) || null;
  169. var serviceConfigObj = App.ServiceConfig.create({
  170. name: index,
  171. value: properties[index],
  172. defaultValue: properties[index],
  173. filename: _tag.siteName + ".xml",
  174. isUserProperty: false,
  175. isOverridable: true,
  176. serviceName: serviceName,
  177. belongsToService: []
  178. });
  179. if (configsPropertyDef) {
  180. serviceConfigObj.displayType = configsPropertyDef.displayType;
  181. serviceConfigObj.isRequired = (configsPropertyDef.isRequired !== undefined) ? configsPropertyDef.isRequired : true;
  182. serviceConfigObj.isReconfigurable = (configsPropertyDef.isReconfigurable !== undefined) ? configsPropertyDef.isReconfigurable : true;
  183. serviceConfigObj.isVisible = (configsPropertyDef.isVisible !== undefined) ? configsPropertyDef.isVisible : true;
  184. serviceConfigObj.unit = (configsPropertyDef.unit !== undefined) ? configsPropertyDef.unit : undefined;
  185. serviceConfigObj.description = (configsPropertyDef.description !== undefined) ? configsPropertyDef.description : undefined;
  186. serviceConfigObj.isOverridable = configsPropertyDef.isOverridable === undefined ? true : configsPropertyDef.isOverridable;
  187. serviceConfigObj.serviceName = configsPropertyDef ? configsPropertyDef.serviceName : null;
  188. serviceConfigObj.index = configsPropertyDef.index;
  189. serviceConfigObj.isSecureConfig = configsPropertyDef.isSecureConfig === undefined ? false : configsPropertyDef.isSecureConfig;
  190. serviceConfigObj.belongsToService = configsPropertyDef.belongsToService;
  191. }
  192. // MAPREDUCE contains core-site properties but doesn't show them
  193. if(serviceConfigObj.serviceName === 'MAPREDUCE' && serviceConfigObj.filename === 'core-site.xml'){
  194. serviceConfigObj.isVisible = false;
  195. }
  196. if (_tag.siteName === 'global') {
  197. if (configsPropertyDef) {
  198. this.handleSpecialProperties(serviceConfigObj);
  199. } else {
  200. serviceConfigObj.isVisible = false; // if the global property is not defined on ui metadata config_properties.js then it shouldn't be a part of errorCount
  201. }
  202. serviceConfigObj.id = 'puppet var';
  203. serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : null;
  204. serviceConfigObj.category = configsPropertyDef ? configsPropertyDef.category : null;
  205. serviceConfigObj.options = configsPropertyDef ? configsPropertyDef.options : null;
  206. globalConfigs.push(serviceConfigObj);
  207. } else if (!this.get('configMapping').computed().someProperty('name', index)) {
  208. isAdvanced = advancedConfigs.someProperty('name', index);
  209. serviceConfigObj.id = 'site property';
  210. serviceConfigObj.displayType = stringUtils.isSingleLine(serviceConfigObj.value) ? 'advanced' : 'multiLine';
  211. serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : index;
  212. this.calculateConfigProperties(serviceConfigObj, isAdvanced, advancedConfigs);
  213. configs.push(serviceConfigObj);
  214. } else {
  215. mappingConfigs.push(serviceConfigObj);
  216. }
  217. }
  218. }, this);
  219. return {
  220. configs: configs,
  221. globalConfigs: globalConfigs,
  222. mappingConfigs: mappingConfigs
  223. }
  224. },
  225. /**
  226. * merge stored configs with pre-defined
  227. * @param storedConfigs
  228. * @param advancedConfigs
  229. * @return {*}
  230. */
  231. mergePreDefinedWithStored: function (storedConfigs, advancedConfigs) {
  232. var mergedConfigs = [];
  233. var preDefinedConfigs = $.extend(true, [], this.get('preDefinedConfigProperties'));
  234. var preDefinedNames = [];
  235. var storedNames = [];
  236. var names = [];
  237. var categoryMetaData = null;
  238. storedConfigs = (storedConfigs) ? storedConfigs : [];
  239. preDefinedNames = this.get('preDefinedConfigProperties').mapProperty('name');
  240. storedNames = storedConfigs.mapProperty('name');
  241. names = preDefinedNames.concat(storedNames).uniq();
  242. names.forEach(function (name) {
  243. var stored = storedConfigs.findProperty('name', name);
  244. var preDefined = preDefinedConfigs.findProperty('name', name);
  245. var configData = {};
  246. var isAdvanced = advancedConfigs.someProperty('name', name);
  247. if (preDefined && stored) {
  248. configData = preDefined;
  249. configData.value = stored.value;
  250. configData.defaultValue = stored.defaultValue;
  251. configData.overrides = stored.overrides;
  252. } else if (!preDefined && stored) {
  253. configData = {
  254. id: stored.id,
  255. name: stored.name,
  256. displayName: stored.name,
  257. serviceName: stored.serviceName,
  258. value: stored.value,
  259. defaultValue: stored.defaultValue,
  260. displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
  261. filename: stored.filename,
  262. category: 'Advanced',
  263. isUserProperty: stored.isUserProperty === true,
  264. isOverridable: true,
  265. overrides: stored.overrides,
  266. isRequired: true
  267. };
  268. this.calculateConfigProperties(configData, isAdvanced, advancedConfigs);
  269. } else if (preDefined && !stored) {
  270. configData = preDefined;
  271. if (isAdvanced) {
  272. configData.filename = advancedConfigs.findProperty('name', configData.name).filename;
  273. }
  274. }
  275. mergedConfigs.push(configData);
  276. }, this);
  277. return mergedConfigs;
  278. },
  279. /**
  280. * look over advanced configs and add missing configs to serviceConfigs
  281. * filter fetched configs by service if passed
  282. * @param serviceConfigs
  283. * @param advancedConfigs
  284. * @param serviceName
  285. */
  286. addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
  287. var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs;
  288. advancedConfigs.forEach(function (_config) {
  289. var configCategory = 'Advanced';
  290. var categoryMetaData = null;
  291. if (_config) {
  292. if (this.get('configMapping').computed().someProperty('name', _config.name)) {
  293. } else if (!(configsToVerifying.someProperty('name', _config.name))) {
  294. if(this.get('customFileNames').contains(_config.filename)){
  295. categoryMetaData = this.identifyCategory(_config);
  296. if (categoryMetaData != null) {
  297. configCategory = categoryMetaData.get('name');
  298. }
  299. }
  300. _config.id = "site property";
  301. _config.category = configCategory;
  302. _config.displayName = _config.name;
  303. _config.defaultValue = _config.value;
  304. // make all advanced configs optional and populated by default
  305. /*
  306. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  307. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  308. * false; _config.value = ''; } else if
  309. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  310. */
  311. _config.isRequired = true;
  312. _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
  313. serviceConfigs.push(_config);
  314. }
  315. }
  316. }, this);
  317. },
  318. /**
  319. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  320. */
  321. addCustomConfigs: function (configs) {
  322. var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
  323. var stored = configs.filter(function (_config) {
  324. return this.get('categoriesWithCustom').contains(_config.category);
  325. }, this);
  326. if(App.supports.capacitySchedulerUi){
  327. var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
  328. if (queueProperties.length) {
  329. queueProperties.setEach('isQueue', true);
  330. }
  331. }
  332. },
  333. miscConfigVisibleProperty: function (configs, serviceToShow) {
  334. configs.forEach(function(item) {
  335. item.set("isVisible", item.belongsToService.some(function(cur){return serviceToShow.contains(cur)}));
  336. });
  337. return configs;
  338. },
  339. /**
  340. * render configs, distribute them by service
  341. * and wrap each in ServiceConfigProperty object
  342. * @param configs
  343. * @param allInstalledServiceNames
  344. * @param selectedServiceNames
  345. * @return {Array}
  346. */
  347. renderConfigs: function (configs, storedConfigs, allInstalledServiceNames, selectedServiceNames) {
  348. var renderedServiceConfigs = [];
  349. var localDB = {
  350. hosts: App.db.getHosts(),
  351. masterComponentHosts: App.db.getMasterComponentHosts(),
  352. slaveComponentHosts: App.db.getSlaveComponentHosts()
  353. };
  354. var services = [];
  355. this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  356. if (allInstalledServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  357. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  358. if (selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  359. serviceConfig.showConfig = true;
  360. }
  361. services.push(serviceConfig);
  362. }
  363. });
  364. services.forEach(function (service) {
  365. var serviceConfig = {};
  366. var configsByService = [];
  367. var serviceConfigs = configs.filterProperty('serviceName', service.serviceName);
  368. serviceConfigs.forEach(function (_config) {
  369. var serviceConfigProperty = {};
  370. _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
  371. serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  372. this.updateHostOverrides(serviceConfigProperty, _config);
  373. if (!storedConfigs) {
  374. serviceConfigProperty.initialValue(localDB);
  375. }
  376. this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
  377. serviceConfigProperty.validate();
  378. configsByService.pushObject(serviceConfigProperty);
  379. }, this);
  380. serviceConfig = this.createServiceConfig(service.serviceName);
  381. serviceConfig.set('showConfig', service.showConfig);
  382. serviceConfig.set('configs', configsByService);
  383. renderedServiceConfigs.push(serviceConfig);
  384. }, this);
  385. return renderedServiceConfigs;
  386. },
  387. /**
  388. Takes care of the "dynamic defaults" for the HCFS configs. Sets
  389. some of the config defaults to previously user-entered data.
  390. **/
  391. tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
  392. console.log("Step7: Tweaking Dynamic defaults");
  393. var firstHost = null;
  394. for(var host in localDB.hosts) {
  395. firstHost = host;
  396. break;
  397. }
  398. try {
  399. if (typeof(config == "string") && config.defaultValue.indexOf("{firstHost}") >= 0) {
  400. serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
  401. serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
  402. }
  403. } catch (err) {
  404. // Nothing to worry about here, most likely trying indexOf on a non-string
  405. }
  406. },
  407. /**
  408. * create new child configs from overrides, attach them to parent config
  409. * override - value of config, related to particular host(s)
  410. * @param configProperty
  411. * @param storedConfigProperty
  412. */
  413. updateHostOverrides: function (configProperty, storedConfigProperty) {
  414. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  415. var overrides = [];
  416. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  417. // create new override with new value
  418. var newSCP = App.ServiceConfigProperty.create(configProperty);
  419. newSCP.set('value', overrideEntry.value);
  420. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  421. newSCP.set('parentSCP', configProperty);
  422. var hostsArray = Ember.A([]);
  423. overrideEntry.hosts.forEach(function (host) {
  424. hostsArray.push(host);
  425. });
  426. newSCP.set('selectedHostOptions', hostsArray);
  427. overrides.pushObject(newSCP);
  428. });
  429. configProperty.set('overrides', overrides);
  430. }
  431. },
  432. /**
  433. * create new ServiceConfig object by service name
  434. * @param serviceName
  435. */
  436. createServiceConfig: function (serviceName) {
  437. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  438. var serviceConfig = App.ServiceConfig.create({
  439. filename: preDefinedServiceConfig.filename,
  440. serviceName: preDefinedServiceConfig.serviceName,
  441. displayName: preDefinedServiceConfig.displayName,
  442. configCategories: preDefinedServiceConfig.configCategories,
  443. configs: []
  444. });
  445. serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
  446. switch (category.name) {
  447. case 'CapacityScheduler':
  448. if(App.supports.capacitySchedulerUi){
  449. category.set('customView', App.ServiceConfigCapacityScheduler);
  450. } else {
  451. category.set('isCustomView', false);
  452. }
  453. break;
  454. }
  455. }, this);
  456. return serviceConfig;
  457. },
  458. /**
  459. * GETs all cluster level sites in one call.
  460. *
  461. * @return Array of all site configs
  462. */
  463. loadConfigsByTags: function (tags) {
  464. var urlParams = [];
  465. tags.forEach(function (_tag) {
  466. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  467. });
  468. var params = urlParams.join('|');
  469. App.ajax.send({
  470. name: 'config.on_site',
  471. sender: this,
  472. data: {
  473. params: params
  474. },
  475. success: 'loadConfigsByTagsSuccess'
  476. });
  477. return configGroupsByTag;
  478. },
  479. loadConfigsByTagsSuccess: function (data) {
  480. if (data.items) {
  481. configGroupsByTag = [];
  482. data.items.forEach(function (item) {
  483. this.loadedConfigurationsCache[item.type + "_" + item.tag] = item.properties;
  484. configGroupsByTag.push(item);
  485. }, this);
  486. }
  487. },
  488. /**
  489. * Generate serviceProperties save it to localDB
  490. * called form stepController step6WizardController
  491. *
  492. * @param serviceName
  493. * @return {*}
  494. */
  495. loadAdvancedConfig: function (serviceName) {
  496. App.ajax.send({
  497. name: 'config.advanced',
  498. sender: this,
  499. data: {
  500. serviceName: serviceName,
  501. stack2VersionUrl: App.get('stack2VersionURL'),
  502. stackVersion: App.get('currentStackVersionNumber')
  503. },
  504. success: 'loadAdvancedConfigSuccess'
  505. });
  506. return serviceComponents[serviceName];
  507. //TODO clean serviceComponents
  508. },
  509. loadAdvancedConfigSuccess: function (data, opt, params) {
  510. console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
  511. var properties = [];
  512. if (data.items.length) {
  513. data.items.forEach(function (item) {
  514. item = item.StackConfigurations;
  515. item.isVisible = item.type !== 'global.xml';
  516. properties.push({
  517. serviceName: item.service_name,
  518. name: item.property_name,
  519. value: item.property_value,
  520. description: item.property_description,
  521. isVisible: item.isVisible,
  522. filename: item.filename || item.type
  523. });
  524. }, this);
  525. serviceComponents[data.items[0].StackConfigurations.service_name] = properties;
  526. }
  527. },
  528. /**
  529. * Determine the map which shows which services
  530. * each global property effects.
  531. *
  532. * @return {*}
  533. * Example:
  534. * {
  535. * 'hive_pid_dir': ['HIVE'],
  536. * ...
  537. * }
  538. */
  539. loadGlobalPropertyToServicesMap: function () {
  540. if (globalPropertyToServicesMap == null) {
  541. App.ajax.send({
  542. name: 'config.advanced.global',
  543. sender: this,
  544. data: {
  545. stack2VersionUrl: App.get('stack2VersionURL')
  546. },
  547. success: 'loadGlobalPropertyToServicesMapSuccess'
  548. });
  549. }
  550. return globalPropertyToServicesMap;
  551. },
  552. loadGlobalPropertyToServicesMapSuccess: function (data) {
  553. globalPropertyToServicesMap = {};
  554. if(data.items!=null){
  555. data.items.forEach(function(service){
  556. service.configurations.forEach(function(config){
  557. if("global.xml" === config.StackConfigurations.type){
  558. if(!(config.StackConfigurations.property_name in globalPropertyToServicesMap)){
  559. globalPropertyToServicesMap[config.StackConfigurations.property_name] = [];
  560. }
  561. globalPropertyToServicesMap[config.StackConfigurations.property_name].push(service.StackServices.service_name);
  562. }
  563. });
  564. });
  565. }
  566. },
  567. /**
  568. * When global configuration changes, not all services are effected
  569. * by all properties. This method determines if a given service
  570. * is effected by the difference in desired and actual configs.
  571. *
  572. * This method might make a call to server to determine the actual
  573. * key/value pairs involved.
  574. */
  575. isServiceEffectedByGlobalChange: function (service, desiredTag, actualTag) {
  576. var effected = false;
  577. if (service != null && desiredTag != null && actualTag != null) {
  578. if(this.differentGlobalTagsCache.indexOf(service+"/"+desiredTag+"/"+actualTag) < 0){
  579. this.loadGlobalPropertyToServicesMap();
  580. var desiredConfigs = this.loadedConfigurationsCache['global_' + desiredTag];
  581. var actualConfigs = this.loadedConfigurationsCache['global_' + actualTag];
  582. var requestTags = [];
  583. if (!desiredConfigs) {
  584. requestTags.push({
  585. siteName: 'global',
  586. tagName: desiredTag
  587. });
  588. }
  589. if (!actualConfigs) {
  590. requestTags.push({
  591. siteName: 'global',
  592. tagName: actualTag
  593. });
  594. }
  595. if (requestTags.length > 0) {
  596. this.loadConfigsByTags(requestTags);
  597. desiredConfigs = this.loadedConfigurationsCache['global_' + desiredTag];
  598. actualConfigs = this.loadedConfigurationsCache['global_' + actualTag];
  599. }
  600. if (desiredConfigs != null && actualConfigs != null) {
  601. for ( var property in desiredConfigs) {
  602. if (!effected) {
  603. var dpv = desiredConfigs[property];
  604. var apv = actualConfigs[property];
  605. if (dpv !== apv && globalPropertyToServicesMap[property] != null) {
  606. effected = globalPropertyToServicesMap[property].indexOf(service) > -1;
  607. if(effected){
  608. this.differentGlobalTagsCache.push(service+"/"+desiredTag+"/"+actualTag);
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }else{
  615. effected = true; // We already know they are different
  616. }
  617. }
  618. return effected;
  619. },
  620. /**
  621. * Hosts can override service configurations per property. This method GETs
  622. * the overriden configurations and sets only the changed properties into
  623. * the 'overrides' of serviceConfig.
  624. *
  625. *
  626. */
  627. loadServiceConfigHostsOverrides: function (serviceConfigs, loadedHostToOverrideSiteToTagMap) {
  628. var configKeyToConfigMap = {};
  629. serviceConfigs.forEach(function (item) {
  630. configKeyToConfigMap[item.name] = item;
  631. });
  632. var typeTagToHostMap = {};
  633. var urlParams = [];
  634. for (var hostname in loadedHostToOverrideSiteToTagMap) {
  635. var overrideTypeTags = loadedHostToOverrideSiteToTagMap[hostname];
  636. for (var type in overrideTypeTags) {
  637. var tag = overrideTypeTags[type];
  638. typeTagToHostMap[type + "///" + tag] = hostname;
  639. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  640. }
  641. }
  642. var params = urlParams.join('|');
  643. if (urlParams.length) {
  644. App.ajax.send({
  645. name: 'config.host_overrides',
  646. sender: this,
  647. data: {
  648. params: params,
  649. configKeyToConfigMap: configKeyToConfigMap,
  650. typeTagToHostMap: typeTagToHostMap
  651. },
  652. success: 'loadServiceConfigHostsOverridesSuccess'
  653. });
  654. }
  655. },
  656. loadServiceConfigHostsOverridesSuccess: function (data, opt, params) {
  657. console.debug("loadServiceConfigHostsOverrides: Data=", data);
  658. data.items.forEach(function (config) {
  659. App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
  660. var hostname = params.typeTagToHostMap[config.type + "///" + config.tag];
  661. var properties = config.properties;
  662. for (var prop in properties) {
  663. var serviceConfig = params.configKeyToConfigMap[prop];
  664. var hostOverrideValue = properties[prop];
  665. if (serviceConfig && serviceConfig.displayType === 'int') {
  666. if (/\d+m$/.test(hostOverrideValue)) {
  667. hostOverrideValue = hostOverrideValue.slice(0, hostOverrideValue.length - 1);
  668. }
  669. } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
  670. switch (hostOverrideValue) {
  671. case 'true':
  672. hostOverrideValue = true;
  673. break;
  674. case 'false':
  675. hostOverrideValue = false;
  676. break;
  677. }
  678. }
  679. if (serviceConfig) {
  680. // Value of this property is different for this host.
  681. var overrides = 'overrides';
  682. if (!(overrides in serviceConfig)) {
  683. serviceConfig.overrides = {};
  684. }
  685. if (!(hostOverrideValue in serviceConfig.overrides)) {
  686. serviceConfig.overrides[hostOverrideValue] = [];
  687. }
  688. console.log("loadServiceConfigHostsOverrides(): [" + hostname + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
  689. serviceConfig.overrides[hostOverrideValue].push(hostname);
  690. }
  691. }
  692. });
  693. console.log("loadServiceConfigHostsOverrides(): Finished loading.");
  694. },
  695. /**
  696. * Set all site property that are derived from other site-properties
  697. */
  698. setConfigValue: function (mappedConfigs, allConfigs, config, globalConfigs) {
  699. var globalValue;
  700. if (config.value == null) {
  701. return;
  702. }
  703. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  704. var fkName = config.name.match(/<(foreignKey.*?)>/g);
  705. var templateValue = config.value.match(/<(templateName.*?)>/g);
  706. if (fkValue) {
  707. fkValue.forEach(function (_fkValue) {
  708. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  709. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  710. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  711. config.value = config.value.replace(_fkValue, globalValue);
  712. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  713. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  714. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  715. } else {
  716. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  717. }
  718. config.value = config.value.replace(_fkValue, globalValue);
  719. }
  720. }, this);
  721. }
  722. // config._name - formatted name from original config name
  723. if (fkName) {
  724. fkName.forEach(function (_fkName) {
  725. var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
  726. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  727. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  728. config._name = config.name.replace(_fkName, globalValue);
  729. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  730. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  731. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  732. } else {
  733. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  734. }
  735. config._name = config.name.replace(_fkName, globalValue);
  736. }
  737. }, this);
  738. }
  739. //For properties in the configMapping file having foreignKey and templateName properties.
  740. if (templateValue) {
  741. templateValue.forEach(function (_value) {
  742. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  743. if (globalConfigs.someProperty('name', config.templateName[index])) {
  744. var globalValue = globalConfigs.findProperty('name', config.templateName[index]).value;
  745. config.value = config.value.replace(_value, globalValue);
  746. } else {
  747. config.value = null;
  748. }
  749. }, this);
  750. }
  751. },
  752. complexConfigs: [
  753. {
  754. "id": "site property",
  755. "name": "capacity-scheduler",
  756. "displayName": "Capacity Scheduler",
  757. "value": "",
  758. "defaultValue": "",
  759. "description": "Capacity Scheduler properties",
  760. "displayType": "custom",
  761. "isOverridable": true,
  762. "isRequired": true,
  763. "isVisible": true,
  764. "serviceName": "YARN",
  765. "filename": "capacity-scheduler.xml",
  766. "category": "ResourceManager"
  767. }
  768. ],
  769. /**
  770. * transform set of configs from file
  771. * into one config with textarea content:
  772. * name=value
  773. * @param configs
  774. * @param filename
  775. * @return {*}
  776. */
  777. fileConfigsIntoTextarea: function(configs, filename){
  778. var fileConfigs = configs.filterProperty('filename', filename);
  779. var value = '';
  780. var defaultValue = '';
  781. var complexConfig = this.get('complexConfigs').findProperty('filename', filename);
  782. if(complexConfig){
  783. fileConfigs.forEach(function(_config){
  784. value += _config.name + '=' + _config.value + '\n';
  785. defaultValue += _config.name + '=' + _config.defaultValue + '\n';
  786. }, this);
  787. complexConfig.value = value;
  788. complexConfig.defaultValue = defaultValue;
  789. configs = configs.filter(function(_config){
  790. return _config.filename !== filename;
  791. });
  792. configs.push(complexConfig);
  793. }
  794. return configs;
  795. },
  796. /**
  797. * transform one config with textarea content
  798. * into set of configs of file
  799. * @param configs
  800. * @param filename
  801. * @return {*}
  802. */
  803. textareaIntoFileConfigs: function(configs, filename){
  804. var complexConfigName = this.get('complexConfigs').findProperty('filename', filename).name;
  805. var configsTextarea = configs.findProperty('name', complexConfigName);
  806. var properties = configsTextarea.get('value').replace(/( |\n)+/g, '\n').split('\n');
  807. properties.forEach(function(_property){
  808. var name, value;
  809. if(_property){
  810. _property = _property.split('=');
  811. name = _property[0];
  812. value = (_property[1]) ? _property[1] : "";
  813. configs.push(Em.Object.create({
  814. id: configsTextarea.get('id'),
  815. name: name,
  816. value: value,
  817. defaultValue: value,
  818. serviceName: configsTextarea.get('serviceName'),
  819. filename: filename
  820. }));
  821. }
  822. });
  823. return configs.without(configsTextarea);
  824. }
  825. });