config.js 38 KB

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