config.js 36 KB

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