config.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630
  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 configGroupsByTag = [];
  21. App.config = Em.Object.create({
  22. /**
  23. * XML characters which should be escaped in values
  24. * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
  25. */
  26. xmlEscapeMap: {
  27. "&": "&",
  28. "<": "&lt;",
  29. ">": "&gt;",
  30. '"': '&quot;',
  31. "'": '&apos;'
  32. },
  33. xmlUnEscapeMap: {
  34. "&amp;": "&",
  35. "&lt;": "<",
  36. "&gt;": ">",
  37. "&quot;": '"',
  38. "&apos;": "'"
  39. },
  40. CONFIG_GROUP_NAME_MAX_LENGTH: 18,
  41. /**
  42. * filename exceptions used to support substandard sitenames which don't have "xml" extension
  43. */
  44. filenameExceptions: ['zoo.cfg'],
  45. /**
  46. * Since values end up in XML files (core-sit.xml, etc.), certain
  47. * XML sensitive characters should be escaped. If not we will have
  48. * an invalid XML document, and services will fail to start.
  49. *
  50. * Special characters in XML are defined at
  51. * http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references#Predefined_entities_in_XML
  52. *
  53. * @method escapeXMLCharacters
  54. * @param {*} value
  55. * @param toXml {Boolean}
  56. * @return {String}
  57. */
  58. escapeXMLCharacters: function (value, toXML) {
  59. var self = this;
  60. // To prevent double/triple replacing '&gt;' to '&amp;gt;' to '&amp;amp;gt;', we need
  61. // to first unescape all XML chars, and then escape them again.
  62. var newValue = String(value).replace(/(&amp;|&lt;|&gt;|&quot;|&apos;)/g, function (s) {
  63. return self.xmlUnEscapeMap[s];
  64. });
  65. if (toXML) {
  66. return String(newValue).replace(/[&<>"']/g, function (s) {
  67. return self.xmlEscapeMap[s];
  68. });
  69. } else {
  70. return newValue;
  71. }
  72. },
  73. preDefinedServiceConfigs: [],
  74. /**
  75. *
  76. * Returns file name version that stored on server.
  77. *
  78. * Example:
  79. * App.config.getOriginalFileName('core-site') // returns core-site.xml
  80. * App.config.getOriginalFileName('zoo.cfg') // returns zoo.cfg
  81. *
  82. * @param {String} fileName
  83. * @method getOriginalFileName
  84. **/
  85. getOriginalFileName: function(fileName) {
  86. if (/\.xml$/.test(fileName)) return fileName;
  87. return this.get('filenameExceptions').contains(fileName) ? fileName : fileName + '.xml';
  88. },
  89. setPreDefinedServiceConfigs: function () {
  90. var configs = this.get('preDefinedSiteProperties');
  91. var services = [];
  92. var nonServiceTab = require('data/service_configs');
  93. var stackServices = App.StackService.find().filterProperty('id');
  94. // Only include services that has configTypes related to them for service configuration page
  95. // Also Remove HCatalog from this list. HCatalog has and hive-site related to it but none of them should be exposed under HCatalog Service
  96. // HCatalog should be eventually made a part of Hive Service. See AMBARI-6302 description for further details
  97. var servicesWithConfigTypes = stackServices.filter(function (service) {
  98. var configtypes = service.get('configTypes');
  99. return configtypes && !!Object.keys(configtypes).length && service.get('serviceName') != 'HCATALOG';
  100. }, this);
  101. var allTabs = servicesWithConfigTypes.concat(nonServiceTab);
  102. allTabs.forEach(function (service) {
  103. var serviceConfigs = configs.filterProperty('serviceName', service.get('serviceName'));
  104. service.set('configs', serviceConfigs);
  105. services.push(service);
  106. });
  107. this.set('preDefinedServiceConfigs', services);
  108. },
  109. configMapping: function () {
  110. if (App.get('isHadoop2Stack')) {
  111. return require('data/HDP2/config_mapping');
  112. }
  113. return require('data/config_mapping');
  114. }.property('App.isHadoop2Stack'),
  115. preDefinedSiteProperties: function () {
  116. if (App.get('isHadoop2Stack')) {
  117. return require('data/HDP2/site_properties').configProperties;
  118. }
  119. return require('data/site_properties').configProperties;
  120. }.property('App.isHadoop2Stack'),
  121. preDefinedCustomConfigs: function () {
  122. if (App.get('isHadoop2Stack')) {
  123. return require('data/HDP2/custom_configs');
  124. }
  125. return require('data/custom_configs');
  126. }.property('App.isHadoop2Stack'),
  127. //categories which contain custom configs
  128. categoriesWithCustom: ['CapacityScheduler'],
  129. /**
  130. * Create array of service properties for Log4j files
  131. * @returns {Array}
  132. */
  133. createContentProperties: function () {
  134. var services = App.StackService.find();
  135. var contentProperties = [];
  136. services.forEach(function (service) {
  137. if (service.get('configTypes')) {
  138. Object.keys(service.get('configTypes')).forEach(function (type) {
  139. if (type.endsWith('-log4j') || type.endsWith('-env')) {
  140. var property = {
  141. "id": "site property",
  142. "name": "content",
  143. "displayName": "content",
  144. "value": "",
  145. "defaultValue": "",
  146. "description": type + " properties",
  147. "displayType": "content",
  148. "isOverridable": true,
  149. "isRequired": false,
  150. "isVisible": true,
  151. "showLabel": false,
  152. "serviceName": service.get('serviceName'),
  153. "filename": type + '.xml',
  154. "category": "Advanced " + type
  155. };
  156. contentProperties.pushObject(property);
  157. }
  158. }, this);
  159. }
  160. }, this);
  161. return contentProperties;
  162. },
  163. //configs with these filenames go to appropriate category not in Advanced
  164. customFileNames: function () {
  165. var customFiles = ['flume-conf.xml'];
  166. if (App.supports.capacitySchedulerUi) {
  167. if (App.get('isHadoop2Stack')) {
  168. return customFiles.concat(['capacity-scheduler.xml']);
  169. }
  170. return customFiles.concat(['capacity-scheduler.xml', 'mapred-queue-acls.xml']);
  171. }
  172. return customFiles;
  173. }.property('App.isHadoop2Stack'),
  174. /**
  175. * Function should be used post-install as precondition check should not be done only after installer wizard
  176. * @param siteNames {string|array}
  177. * @returns {Array}
  178. */
  179. getBySitename: function (siteNames) {
  180. var computedConfigs = this.get('configMapping').computed();
  181. var siteProperties = [];
  182. if (typeof siteNames === "string") {
  183. siteProperties = computedConfigs.filterProperty('filename', siteNames);
  184. } else if (siteNames instanceof Array) {
  185. siteNames.forEach(function (_siteName) {
  186. siteProperties = siteProperties.concat(computedConfigs.filterProperty('filename', _siteName));
  187. }, this);
  188. }
  189. return siteProperties;
  190. },
  191. /**
  192. * Cache of loaded configurations. This is useful in not loading
  193. * same configuration multiple times. It is populated in multiple
  194. * places.
  195. *
  196. * Example:
  197. * {
  198. * 'hdfs-site_version3': {...},
  199. * }
  200. */
  201. loadedConfigurationsCache: {},
  202. identifyCategory: function (config) {
  203. if(config.filename.indexOf("env")!=-1) return;
  204. var category = null;
  205. var serviceConfigMetaData = this.get('preDefinedServiceConfigs').findProperty('serviceName', config.serviceName);
  206. if (serviceConfigMetaData) {
  207. var configCategories = serviceConfigMetaData.get('configCategories');
  208. configCategories.forEach(function (_category) {
  209. if (_category.siteFileNames && Array.isArray(_category.siteFileNames) && _category.siteFileNames.contains(config.filename)) {
  210. category = _category;
  211. }
  212. });
  213. category = (category == null) ? configCategories.findProperty('siteFileName', this.getOriginalFileName(config.filename)) : category;
  214. }
  215. return category;
  216. },
  217. /**
  218. * additional handling for special properties such as
  219. * checkbox and digital which values with 'm' at the end
  220. * @param config
  221. */
  222. handleSpecialProperties: function (config) {
  223. if (config.displayType === 'int' && /\d+m$/.test(config.value)) {
  224. config.value = config.value.slice(0, config.value.length - 1);
  225. config.defaultValue = config.value;
  226. }
  227. if (config.displayType === 'checkbox') {
  228. config.value = (config.value === 'true') ? config.defaultValue = true : config.defaultValue = false;
  229. }
  230. },
  231. /**
  232. * calculate config properties:
  233. * category, filename, isUserProperty, description
  234. * @param config
  235. * @param isAdvanced
  236. * @param advancedConfigs
  237. */
  238. calculateConfigProperties: function (config, isAdvanced, advancedConfigs) {
  239. if (!isAdvanced || this.get('customFileNames').contains(config.filename)) {
  240. var categoryMetaData = this.identifyCategory(config);
  241. if (categoryMetaData != null) {
  242. config.category = categoryMetaData.get('name');
  243. if (!isAdvanced) config.isUserProperty = true;
  244. }
  245. } else {
  246. var advancedProperty = null;
  247. if (isAdvanced) {
  248. advancedProperty = advancedConfigs.findProperty('name', config.name);
  249. }
  250. config.category = config.category ? config.category : 'Advanced';
  251. config.description = isAdvanced && advancedProperty.description;
  252. }
  253. },
  254. capacitySchedulerFilter: function () {
  255. var yarnRegex = /^yarn\.scheduler\.capacity\.root\.([a-z]([\_\-a-z0-9]{0,50}))\.(acl_administer_jobs|acl_submit_jobs|state|user-limit-factor|maximum-capacity|capacity)$/i;
  256. if (App.get('isHadoop2Stack')) {
  257. return function (_config) {
  258. return (yarnRegex.test(_config.name));
  259. }
  260. } else {
  261. return function (_config) {
  262. return (_config.name.indexOf('mapred.capacity-scheduler.queue.') !== -1) ||
  263. (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
  264. }
  265. }
  266. }.property('App.isHadoop2Stack'),
  267. /**
  268. * return:
  269. * configs,
  270. * mappingConfigs
  271. *
  272. * @param configGroups
  273. * @param advancedConfigs
  274. * @param tags
  275. * @param serviceName
  276. * @return {object}
  277. */
  278. mergePreDefinedWithLoaded: function (configGroups, advancedConfigs, tags, serviceName) {
  279. var configs = [];
  280. var contentProperties = this.createContentProperties();
  281. var preDefinedConfigs = this.get('preDefinedSiteProperties').concat(contentProperties);
  282. var mappingConfigs = [];
  283. var filenameExceptions = this.get('filenameExceptions');
  284. var selectedServiceNames = App.Service.find().mapProperty('serviceName');
  285. tags.forEach(function (_tag) {
  286. var isAdvanced = null;
  287. var filename = (filenameExceptions.contains(_tag.siteName)) ? _tag.siteName : _tag.siteName + ".xml";
  288. var siteConfig = configGroups.filter(function (serviceConfigProperties) {
  289. return _tag.tagName === serviceConfigProperties.tag && _tag.siteName === serviceConfigProperties.type;
  290. });
  291. siteConfig = siteConfig[0] || {};
  292. var attributes = siteConfig['properties_attributes'] || {};
  293. var finalAttributes = attributes.final || {};
  294. var properties = siteConfig.properties || {};
  295. for (var index in properties) {
  296. var configsPropertyDef = preDefinedConfigs.filterProperty('name', index).findProperty('filename', filename);
  297. if (!configsPropertyDef) {
  298. preDefinedConfigs.filterProperty('name', index).forEach(function (_preDefinedConfig) {
  299. var isServiceInstalled = selectedServiceNames.contains(_preDefinedConfig.serviceName);
  300. if (isServiceInstalled || _preDefinedConfig.serviceName === 'MISC') {
  301. configsPropertyDef = _preDefinedConfig;
  302. }
  303. }, this);
  304. }
  305. var serviceConfigObj = App.ServiceConfig.create({
  306. name: index,
  307. value: properties[index],
  308. defaultValue: properties[index],
  309. filename: filename,
  310. isUserProperty: false,
  311. isOverridable: true,
  312. isRequired: true,
  313. isFinal: finalAttributes[index] === "true",
  314. defaultIsFinal: finalAttributes[index] === "true",
  315. showLabel: true,
  316. serviceName: serviceName,
  317. belongsToService: []
  318. });
  319. if (configsPropertyDef) {
  320. this.setServiceConfigUiAttributes(serviceConfigObj, configsPropertyDef);
  321. }
  322. if (!this.getBySitename(serviceConfigObj.get('filename')).someProperty('name', index)) {
  323. isAdvanced = advancedConfigs.someProperty('name', index);
  324. serviceConfigObj.id = 'site property';
  325. if (configsPropertyDef) {
  326. if (configsPropertyDef.isRequiredByAgent === false) {
  327. continue;
  328. }
  329. this.handleSpecialProperties(serviceConfigObj);
  330. } else {
  331. serviceConfigObj.displayType = stringUtils.isSingleLine(serviceConfigObj.value) ? 'advanced' : 'multiLine';
  332. }
  333. serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : index;
  334. serviceConfigObj.options = configsPropertyDef ? configsPropertyDef.options : null;
  335. this.calculateConfigProperties(serviceConfigObj, isAdvanced, advancedConfigs);
  336. if (serviceConfigObj.get('displayType') == 'directories'
  337. && (serviceConfigObj.get('category') == 'DataNode'
  338. || serviceConfigObj.get('category') == 'NameNode')) {
  339. var dirs = serviceConfigObj.get('value').split(',').sort();
  340. serviceConfigObj.set('value', dirs.join(','));
  341. serviceConfigObj.set('defaultValue', dirs.join(','));
  342. }
  343. if (serviceConfigObj.get('displayType') == 'directory'
  344. && serviceConfigObj.get('category') == 'SNameNode') {
  345. var dirs = serviceConfigObj.get('value').split(',').sort();
  346. serviceConfigObj.set('value', dirs[0]);
  347. serviceConfigObj.set('defaultValue', dirs[0]);
  348. }
  349. if (serviceConfigObj.get('displayType') == 'masterHosts') {
  350. if (typeof(serviceConfigObj.get('value')) == 'string') {
  351. var value = serviceConfigObj.get('value').replace(/\[|]|'|&apos;/g, "").split(',');
  352. serviceConfigObj.set('value', value);
  353. }
  354. }
  355. configs.push(serviceConfigObj);
  356. } else {
  357. mappingConfigs.push(serviceConfigObj);
  358. }
  359. }
  360. }, this);
  361. return {
  362. configs: configs,
  363. mappingConfigs: mappingConfigs
  364. }
  365. },
  366. /**
  367. * @param serviceConfigObj : Object
  368. * @param configsPropertyDef : Object
  369. */
  370. setServiceConfigUiAttributes: function (serviceConfigObj, configsPropertyDef) {
  371. serviceConfigObj.displayType = configsPropertyDef.displayType;
  372. serviceConfigObj.isRequired = (configsPropertyDef.isRequired !== undefined) ? configsPropertyDef.isRequired : true;
  373. serviceConfigObj.isRequiredByAgent = (configsPropertyDef.isRequiredByAgent !== undefined) ? configsPropertyDef.isRequiredByAgent : true;
  374. serviceConfigObj.isReconfigurable = (configsPropertyDef.isReconfigurable !== undefined) ? configsPropertyDef.isReconfigurable : true;
  375. serviceConfigObj.isVisible = (configsPropertyDef.isVisible !== undefined) ? configsPropertyDef.isVisible : true;
  376. serviceConfigObj.unit = (configsPropertyDef.unit !== undefined) ? configsPropertyDef.unit : undefined;
  377. serviceConfigObj.description = (configsPropertyDef.description !== undefined) ? configsPropertyDef.description : undefined;
  378. serviceConfigObj.isOverridable = configsPropertyDef.isOverridable === undefined ? true : configsPropertyDef.isOverridable;
  379. serviceConfigObj.serviceName = configsPropertyDef ? configsPropertyDef.serviceName : null;
  380. serviceConfigObj.index = configsPropertyDef.index;
  381. serviceConfigObj.isSecureConfig = configsPropertyDef.isSecureConfig === undefined ? false : configsPropertyDef.isSecureConfig;
  382. serviceConfigObj.belongsToService = configsPropertyDef.belongsToService;
  383. serviceConfigObj.category = configsPropertyDef.category;
  384. serviceConfigObj.showLabel = configsPropertyDef.showLabel !== false;
  385. },
  386. /**
  387. * synchronize order of config properties with order, that on UI side
  388. *
  389. * @method syncOrderWithPredefined
  390. * @param configSet {object}
  391. * @return {Object}
  392. */
  393. syncOrderWithPredefined: function (configSet) {
  394. var siteConfigs = configSet.configs,
  395. siteStart = [];
  396. var preDefinedSiteProperties = this.get('preDefinedSiteProperties').mapProperty('name');
  397. var contentProperties = this.createContentProperties().mapProperty('name');
  398. var siteProperties = preDefinedSiteProperties.concat(contentProperties);
  399. siteProperties.forEach(function (name) {
  400. var _site = siteConfigs.filterProperty('name', name);
  401. if (_site.length == 1) {
  402. siteStart.push(_site[0]);
  403. siteConfigs = siteConfigs.without(_site[0]);
  404. } else if (_site.length > 1) {
  405. _site.forEach(function (site) {
  406. siteStart.push(site);
  407. siteConfigs = siteConfigs.without(site);
  408. }, this);
  409. }
  410. }, this);
  411. return {
  412. configs: siteStart.concat(siteConfigs.sortProperty('name')),
  413. mappingConfigs: configSet.mappingConfigs
  414. }
  415. },
  416. /**
  417. * merge stored configs with pre-defined
  418. * @param storedConfigs
  419. * @param advancedConfigs
  420. * @param selectedServiceNames
  421. * @return {array}
  422. */
  423. mergePreDefinedWithStored: function (storedConfigs, advancedConfigs, selectedServiceNames) {
  424. var mergedConfigs = [];
  425. var contentProperties = this.createContentProperties();
  426. var preDefinedConfigs = this.get('preDefinedSiteProperties').concat(contentProperties);
  427. storedConfigs = (storedConfigs) ? storedConfigs : [];
  428. var preDefinedNames = preDefinedConfigs.mapProperty('name');
  429. var storedNames = storedConfigs.mapProperty('name');
  430. var names = preDefinedNames.concat(storedNames).uniq();
  431. names.forEach(function (name) {
  432. var storedCfgs = storedConfigs.filterProperty('name', name);
  433. var preDefinedCfgs = [];
  434. var preDefinedConfig = preDefinedConfigs.filterProperty('name', name);
  435. preDefinedConfig.forEach(function (_preDefinedConfig) {
  436. if (selectedServiceNames.contains(_preDefinedConfig.serviceName) || _preDefinedConfig.serviceName === 'MISC') {
  437. preDefinedCfgs.push(_preDefinedConfig);
  438. }
  439. }, this);
  440. var configData = {};
  441. var isAdvanced = advancedConfigs.someProperty('name', name);
  442. if (storedCfgs.length <= 1 && preDefinedCfgs.length <= 1) {
  443. var stored = storedCfgs[0];
  444. var preDefined = preDefinedCfgs[0];
  445. if (preDefined && stored) {
  446. configData = preDefined;
  447. configData.value = stored.value;
  448. configData.defaultValue = stored.defaultValue;
  449. configData.overrides = stored.overrides;
  450. configData.filename = stored.filename;
  451. configData.description = stored.description;
  452. configData.isVisible = stored.isVisible;
  453. configData.isFinal = stored.isFinal;
  454. configData.supportsFinal = stored.supportsFinal;
  455. configData.isRequired = (configData.isRequired !== undefined) ? configData.isRequired : true;
  456. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  457. configData.showLabel = stored.showLabel !== false;
  458. }
  459. else if (!preDefined && stored) {
  460. configData = this.addUserProperty(stored, isAdvanced, advancedConfigs);
  461. }
  462. else if (preDefined && !stored) {
  463. configData = preDefined;
  464. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  465. if (isAdvanced) {
  466. var advanced = advancedConfigs.findProperty('name', configData.name);
  467. this.setPropertyFromStack(configData, advanced);
  468. }
  469. }
  470. if (configData.displayType === 'checkbox') {
  471. configData.value = configData.value === 'true'; // convert {String} value to {Boolean}
  472. configData.defaultValue = configData.value;
  473. }
  474. mergedConfigs.push(configData);
  475. } else {
  476. preDefinedCfgs.forEach(function (cfg) {
  477. configData = cfg;
  478. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  479. var storedCfg = storedCfgs.findProperty('filename', cfg.filename);
  480. if (storedCfg) {
  481. configData.value = storedCfg.value;
  482. configData.defaultValue = storedCfg.defaultValue;
  483. configData.overrides = storedCfg.overrides;
  484. configData.filename = storedCfg.filename;
  485. configData.description = storedCfg.description;
  486. configData.description = storedCfg.showLabel !== false;
  487. configData.isFinal = storedCfg.isFinal;
  488. configData.supportsFinal = storedCfg.supportsFinal;
  489. } else if (isAdvanced) {
  490. advanced = advancedConfigs.filterProperty('filename', configData.filename).findProperty('name', configData.name);
  491. this.setPropertyFromStack(configData, advanced);
  492. }
  493. mergedConfigs.push(configData);
  494. }, this);
  495. }
  496. }, this);
  497. return mergedConfigs;
  498. },
  499. /**
  500. *
  501. * @param configData {Object} Configs that will be binded to the view on step-7 of installer wizard
  502. * @param advanced {Object} Config property loaded from Server side stack definition
  503. */
  504. setPropertyFromStack: function (configData, advanced) {
  505. // Password fields should be made blank by default in installer wizard
  506. // irrespective of whatever value is sent from stack definition.
  507. // This forces the user to fill the password field.
  508. configData.value = configData.displayType == "password" ? '' : advanced ? advanced.value : configData.value;
  509. configData.defaultValue = configData.value;
  510. configData.filename = advanced ? advanced.filename : configData.filename;
  511. configData.description = advanced ? advanced.description : configData.description;
  512. configData.isFinal = !!(advanced && (advanced.isFinal === "true"));
  513. configData.supportsFinal = !!(advanced && advanced.supportsFinal);
  514. },
  515. /**
  516. * look over advanced configs and add missing configs to serviceConfigs
  517. * filter fetched configs by service if passed
  518. * @param serviceConfigs
  519. * @param advancedConfigs
  520. * @param serviceName
  521. */
  522. addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
  523. var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs.slice();
  524. advancedConfigs.forEach(function (_config) {
  525. var configCategory = 'Advanced';
  526. var categoryMetaData = null;
  527. if (_config) {
  528. if (this.get('configMapping').computed().someProperty('name', _config.name)) {
  529. } else if (!(configsToVerifying.someProperty('name', _config.name))) {
  530. if (this.get('customFileNames').contains(_config.filename)) {
  531. categoryMetaData = this.identifyCategory(_config);
  532. if (categoryMetaData != null) {
  533. configCategory = categoryMetaData.get('name');
  534. }
  535. }
  536. _config.id = "site property";
  537. _config.category = configCategory;
  538. _config.displayName = _config.name;
  539. _config.defaultValue = _config.value;
  540. // make all advanced configs optional and populated by default
  541. /*
  542. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  543. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  544. * false; _config.value = ''; } else if
  545. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  546. */
  547. _config.isRequired = true;
  548. _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
  549. serviceConfigs.push(_config);
  550. }
  551. }
  552. }, this);
  553. },
  554. /**
  555. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  556. */
  557. addCustomConfigs: function (configs) {
  558. var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
  559. var stored = configs.filter(function (_config) {
  560. return this.get('categoriesWithCustom').contains(_config.category);
  561. }, this);
  562. if (App.supports.capacitySchedulerUi) {
  563. var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
  564. if (queueProperties.length) {
  565. queueProperties.setEach('isQueue', true);
  566. }
  567. }
  568. },
  569. miscConfigVisibleProperty: function (configs, serviceToShow) {
  570. configs.forEach(function (item) {
  571. item.set("isVisible", item.belongsToService.some(function (cur) {
  572. return serviceToShow.contains(cur)
  573. }));
  574. });
  575. return configs;
  576. },
  577. /**
  578. * render configs, distribute them by service
  579. * and wrap each in ServiceConfigProperty object
  580. * @param configs
  581. * @param storedConfigs
  582. * @param allSelectedServiceNames
  583. * @param installedServiceNames
  584. * @param localDB
  585. * @return {Array}
  586. */
  587. renderConfigs: function (configs, storedConfigs, allSelectedServiceNames, installedServiceNames, localDB, recommended) {
  588. var renderedServiceConfigs = [];
  589. var services = [];
  590. this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  591. var serviceName = serviceConfig.get('serviceName');
  592. if (allSelectedServiceNames.contains(serviceName) || serviceName === 'MISC') {
  593. console.log('pushing ' + serviceName, serviceConfig);
  594. if (!installedServiceNames.contains(serviceName) || serviceName === 'MISC') {
  595. serviceConfig.set('showConfig', true);
  596. }
  597. services.push(serviceConfig);
  598. }
  599. });
  600. services.forEach(function (service) {
  601. var configsByService = [];
  602. var serviceConfigs = configs.filterProperty('serviceName', service.get('serviceName'));
  603. serviceConfigs.forEach(function (_config) {
  604. _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
  605. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  606. this.updateHostOverrides(serviceConfigProperty, _config);
  607. if (!storedConfigs && !serviceConfigProperty.get('hasInitialValue')) {
  608. serviceConfigProperty.initialValue(localDB);
  609. }
  610. if (storedConfigs && storedConfigs.filterProperty('name', _config.name).length && !!_config.filename) {
  611. var storedConfig = storedConfigs.filterProperty('name', _config.name).findProperty('filename', _config.filename);
  612. if (storedConfig) {
  613. serviceConfigProperty.set('defaultValue', storedConfig.defaultValue);
  614. serviceConfigProperty.set('value', storedConfig.value);
  615. }
  616. }
  617. this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
  618. serviceConfigProperty.validate();
  619. configsByService.pushObject(serviceConfigProperty);
  620. }, this);
  621. var serviceConfig = this.createServiceConfig(service.get('serviceName'));
  622. serviceConfig.set('showConfig', service.get('showConfig'));
  623. // Use calculated default values for some configs
  624. var recommendedDefaults = {};
  625. if (App.supports.serverRecommendValidate) {
  626. if (!storedConfigs && service.get('configTypes')) {
  627. Object.keys(service.get('configTypes')).forEach(function (type) {
  628. if (!recommended || !recommended[type]) {
  629. return;
  630. }
  631. var defaults = recommended[type].properties;
  632. for (var name in defaults) {
  633. var config = configsByService.findProperty('name', name);
  634. if (!config) {
  635. continue;
  636. }
  637. recommendedDefaults[name] = defaults[name];
  638. config.set('value', defaults[name]);
  639. config.set('defaultValue', defaults[name]);
  640. }
  641. });
  642. }
  643. } else {
  644. if (!storedConfigs && service.get('defaultsProviders')) {
  645. service.get('defaultsProviders').forEach(function (defaultsProvider) {
  646. var defaults = defaultsProvider.getDefaults(localDB);
  647. for (var name in defaults) {
  648. var config = configsByService.findProperty('name', name);
  649. if (!config) {
  650. continue;
  651. }
  652. if (!!defaults[name]) {
  653. recommendedDefaults[name] = defaults[name];
  654. config.set('value', defaults[name]);
  655. config.set('defaultValue', defaults[name]);
  656. } else {
  657. recommendedDefaults[name] = config.get('defaultValue');
  658. }
  659. }
  660. });
  661. }
  662. }
  663. if (service.get('configsValidator')) {
  664. service.get('configsValidator').set('recommendedDefaults', recommendedDefaults);
  665. var validators = service.get('configsValidator').get('configValidators');
  666. for (var validatorName in validators) {
  667. var c = configsByService.findProperty('name', validatorName);
  668. if (c) {
  669. c.set('serviceValidator', service.get('configsValidator'));
  670. }
  671. }
  672. }
  673. serviceConfig.set('configs', configsByService);
  674. renderedServiceConfigs.push(serviceConfig);
  675. }, this);
  676. return renderedServiceConfigs;
  677. },
  678. /**
  679. Takes care of the "dynamic defaults" for the GLUSTERFS configs. Sets
  680. some of the config defaults to previously user-entered data.
  681. **/
  682. tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
  683. var firstHost = null;
  684. for (var host in localDB.hosts) {
  685. firstHost = host;
  686. break;
  687. }
  688. try {
  689. if (typeof(config.defaultValue) == "string" && config.defaultValue.indexOf("{firstHost}") >= 0) {
  690. serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
  691. serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
  692. }
  693. } catch (err) {
  694. // Nothing to worry about here, most likely trying indexOf on a non-string
  695. }
  696. },
  697. /**
  698. * create new child configs from overrides, attach them to parent config
  699. * override - value of config, related to particular host(s)
  700. * @param configProperty
  701. * @param storedConfigProperty
  702. */
  703. updateHostOverrides: function (configProperty, storedConfigProperty) {
  704. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  705. var overrides = [];
  706. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  707. // create new override with new value
  708. var newSCP = App.ServiceConfigProperty.create(configProperty);
  709. newSCP.set('value', overrideEntry.value);
  710. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  711. newSCP.set('parentSCP', configProperty);
  712. var hostsArray = Ember.A([]);
  713. overrideEntry.hosts.forEach(function (host) {
  714. hostsArray.push(host);
  715. });
  716. newSCP.set('selectedHostOptions', hostsArray);
  717. overrides.pushObject(newSCP);
  718. });
  719. configProperty.set('overrides', overrides);
  720. }
  721. },
  722. /**
  723. * create new ServiceConfig object by service name
  724. * @param serviceName
  725. */
  726. createServiceConfig: function (serviceName) {
  727. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  728. var serviceConfig = App.ServiceConfig.create({
  729. serviceName: preDefinedServiceConfig.get('serviceName'),
  730. displayName: preDefinedServiceConfig.get('displayName'),
  731. configCategories: preDefinedServiceConfig.get('configCategories'),
  732. configs: [],
  733. configGroups: []
  734. });
  735. serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
  736. switch (category.name) {
  737. case 'CapacityScheduler':
  738. if (App.supports.capacitySchedulerUi) {
  739. category.set('customView', App.ServiceConfigCapacityScheduler);
  740. } else {
  741. category.set('isCustomView', false);
  742. }
  743. break;
  744. }
  745. }, this);
  746. return serviceConfig;
  747. },
  748. /**
  749. * GETs all cluster level sites in one call.
  750. *
  751. * @return {object}
  752. */
  753. loadConfigsByTags: function (tags) {
  754. var urlParams = [];
  755. tags.forEach(function (_tag) {
  756. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  757. });
  758. var params = urlParams.join('|');
  759. return App.ajax.send({
  760. name: 'config.on_site',
  761. sender: this,
  762. data: {
  763. params: params
  764. }
  765. });
  766. },
  767. /**
  768. * Generate serviceProperties save it to localDB
  769. * called form stepController step6WizardController
  770. *
  771. * @param serviceName
  772. * @param callback
  773. * @return {object|null}
  774. */
  775. loadAdvancedConfig: function (serviceName, callback) {
  776. return App.ajax.send({
  777. name: 'config.advanced',
  778. sender: this,
  779. data: {
  780. serviceName: serviceName,
  781. stackVersionUrl: App.get('stackVersionURL'),
  782. stackVersion: App.get('currentStackVersionNumber'),
  783. callback: callback
  784. },
  785. success: 'loadAdvancedConfigSuccess',
  786. error: 'loadAdvancedConfigError'
  787. });
  788. },
  789. loadAdvancedConfigSuccess: function (data, opt, params) {
  790. console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
  791. var properties = [];
  792. if (data.items.length) {
  793. data.items.forEach(function (item) {
  794. item = item.StackConfigurations;
  795. item.isVisible = true;
  796. var serviceName = item.service_name;
  797. var fileName = item.type;
  798. var isHDP2 = App.get('isHadoop2Stack');
  799. /**
  800. * Properties from mapred-queue-acls.xml are ignored unless App.supports.capacitySchedulerUi is true
  801. * Properties from capacity-scheduler.xml are ignored unless HDP stack version is 2.x or
  802. * HDP stack version is 1.x and App.supports.capacitySchedulerUi is true.
  803. */
  804. if ((fileName !== 'mapred-queue-acls.xml' || App.supports.capacitySchedulerUi) &&
  805. (fileName !== 'capacity-scheduler.xml' || isHDP2 || App.supports.capacitySchedulerUi)) {
  806. properties.push({
  807. serviceName: serviceName,
  808. name: item.property_name,
  809. value: item.property_value,
  810. description: item.property_description,
  811. isVisible: item.isVisible,
  812. isFinal: item.final === "true",
  813. defaultIsFinal: item.final === "true",
  814. filename: item.filename || fileName
  815. });
  816. }
  817. }, this);
  818. }
  819. params.callback(properties);
  820. },
  821. loadAdvancedConfigError: function (request, ajaxOptions, error, opt, params) {
  822. console.log('ERROR: failed to load stack configs for', params.serviceName);
  823. params.callback([]);
  824. },
  825. /**
  826. * Get config types and config type attributes from stack service
  827. *
  828. * @param service
  829. * @return {object}
  830. */
  831. getConfigTypesInfoFromService: function (service) {
  832. var configTypes = service.get('configTypes');
  833. var configTypesInfo = {
  834. items: [],
  835. supportsFinal: []
  836. };
  837. if (configTypes) {
  838. for (var key in configTypes) {
  839. if (configTypes.hasOwnProperty(key)) {
  840. configTypesInfo.items.push(key);
  841. if (configTypes[key].supports && configTypes[key].supports.final === "true") {
  842. configTypesInfo.supportsFinal.push(key);
  843. }
  844. }
  845. }
  846. }
  847. return configTypesInfo;
  848. },
  849. /**
  850. * Get properties from server by type and tag with properties, that belong to group
  851. * push them to common {serviceConfigs} and call callback function
  852. */
  853. loadServiceConfigGroupOverrides: function (serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups, callback, sender) {
  854. var configKeyToConfigMap = {};
  855. serviceConfigs.forEach(function (item) {
  856. if (!configKeyToConfigMap[item.filename]) {
  857. configKeyToConfigMap[item.filename] = {};
  858. }
  859. configKeyToConfigMap[item.filename][item.name] = item;
  860. });
  861. var typeTagToGroupMap = {};
  862. var urlParams = [];
  863. for (var group in loadedGroupToOverrideSiteToTagMap) {
  864. var overrideTypeTags = loadedGroupToOverrideSiteToTagMap[group];
  865. for (var type in overrideTypeTags) {
  866. var tag = overrideTypeTags[type];
  867. typeTagToGroupMap[type + "///" + tag] = configGroups.findProperty('name', group);
  868. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  869. }
  870. }
  871. var params = urlParams.join('|');
  872. if (urlParams.length) {
  873. App.ajax.send({
  874. name: 'config.host_overrides',
  875. sender: this,
  876. data: {
  877. params: params,
  878. configKeyToConfigMap: configKeyToConfigMap,
  879. typeTagToGroupMap: typeTagToGroupMap,
  880. callback: callback,
  881. sender: sender,
  882. serviceConfigs: serviceConfigs
  883. },
  884. success: 'loadServiceConfigGroupOverridesSuccess'
  885. });
  886. } else {
  887. callback.call(sender, serviceConfigs);
  888. }
  889. },
  890. loadServiceConfigGroupOverridesSuccess: function (data, opt, params) {
  891. data.items.forEach(function (config) {
  892. App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
  893. var group = params.typeTagToGroupMap[config.type + "///" + config.tag];
  894. var properties = config.properties;
  895. for (var prop in properties) {
  896. var fileName = this.getOriginalFileName(config.type);
  897. var serviceConfig = !!params.configKeyToConfigMap[fileName] ? params.configKeyToConfigMap[fileName][prop] : false;
  898. var hostOverrideValue = this.formatOverrideValue(serviceConfig, properties[prop]);
  899. var hostOverrideIsFinal = !!(config.properties_attributes && config.properties_attributes.final && config.properties_attributes.final[prop]);
  900. if (serviceConfig) {
  901. // Value of this property is different for this host.
  902. if (!Em.get(serviceConfig, 'overrides')) Em.set(serviceConfig, 'overrides', []);
  903. console.log("loadServiceConfigGroupOverridesSuccess(): [" + group + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
  904. serviceConfig.overrides.pushObject({value: hostOverrideValue, group: group, isFinal: hostOverrideIsFinal});
  905. } else {
  906. params.serviceConfigs.push(this.createCustomGroupConfig(prop, config, group));
  907. }
  908. }
  909. }, this);
  910. params.callback.call(params.sender, params.serviceConfigs);
  911. },
  912. /**
  913. * Create config with non default config group. Some custom config properties
  914. * can be created and assigned to non-default config group.
  915. *
  916. * @param {String} propertyName - name of the property
  917. * @param {Object} config - config info
  918. * @param {Em.Object} group - config group to set
  919. * @return {Object}
  920. **/
  921. createCustomGroupConfig: function(propertyName, config, group) {
  922. var propertyValue = config.properties[propertyName];
  923. var propertyObject = {
  924. name: propertyName,
  925. displayName: propertyName,
  926. defaultValue: propertyValue,
  927. value: propertyValue,
  928. displayType: stringUtils.isSingleLine(propertyValue) ? 'advanced' : 'multiLine',
  929. isSecureConfig: false,
  930. group: group,
  931. id: 'site property',
  932. serviceName: group.get('service.serviceName'),
  933. filename: this.getOriginalFileName(config.type),
  934. isUserProperty: true,
  935. isVisible: true,
  936. isOverridable: false
  937. };
  938. propertyObject.category = this.identifyCategory(propertyObject).name;
  939. group.set('switchGroupTextShort', Em.I18n.t('services.service.config_groups.switchGroupTextShort').format(group.get('name')));
  940. group.set('switchGroupTextFull', Em.I18n.t('services.service.config_groups.switchGroupTextFull').format(group.get('name')));
  941. return App.ServiceConfigProperty.create(propertyObject);
  942. },
  943. /**
  944. * format value of override of config
  945. * @param serviceConfig
  946. * @param hostOverrideValue
  947. */
  948. formatOverrideValue: function (serviceConfig, hostOverrideValue) {
  949. if (serviceConfig && serviceConfig.displayType === 'int') {
  950. if (/\d+m$/.test(hostOverrideValue)) {
  951. return hostOverrideValue.slice(0, hostOverrideValue.length - 1);
  952. }
  953. } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
  954. switch (hostOverrideValue) {
  955. case 'true':
  956. return true;
  957. case 'false':
  958. return false;
  959. }
  960. }
  961. return hostOverrideValue;
  962. },
  963. /**
  964. * Set all site property that are derived from other site-properties
  965. */
  966. setConfigValue: function (mappedConfigs, allConfigs, config) {
  967. var globalValue;
  968. if (config.value == null) {
  969. return;
  970. }
  971. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  972. var fkName = config.name.match(/<(foreignKey.*?)>/g);
  973. var templateValue = config.value.match(/<(templateName.*?)>/g);
  974. if (fkValue) {
  975. fkValue.forEach(function (_fkValue) {
  976. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  977. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  978. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  979. config.value = config.value.replace(_fkValue, globalValue);
  980. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  981. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  982. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  983. } else {
  984. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  985. }
  986. config.value = config.value.replace(_fkValue, globalValue);
  987. }
  988. }, this);
  989. }
  990. // config._name - formatted name from original config name
  991. if (fkName) {
  992. fkName.forEach(function (_fkName) {
  993. var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
  994. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  995. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  996. config._name = config.name.replace(_fkName, globalValue);
  997. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  998. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  999. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  1000. } else {
  1001. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  1002. }
  1003. config._name = config.name.replace(_fkName, globalValue);
  1004. }
  1005. }, this);
  1006. }
  1007. //For properties in the configMapping file having foreignKey and templateName properties.
  1008. if (templateValue) {
  1009. templateValue.forEach(function (_value) {
  1010. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  1011. if (allConfigs.someProperty('name', config.templateName[index])) {
  1012. var globalValue = allConfigs.findProperty('name', config.templateName[index]).value;
  1013. config.value = config.value.replace(_value, globalValue);
  1014. } else {
  1015. config.value = null;
  1016. }
  1017. }, this);
  1018. }
  1019. },
  1020. /**
  1021. * identify service name of config by its config's type
  1022. * @param type
  1023. * @return {string|null}
  1024. */
  1025. getServiceNameByConfigType: function (type) {
  1026. var preDefinedServiceConfigs = this.get('preDefinedServiceConfigs');
  1027. var service = preDefinedServiceConfigs.find(function (serviceConfig) {
  1028. return !!serviceConfig.get('configTypes')[type];
  1029. }, this);
  1030. return service && service.get('serviceName');
  1031. },
  1032. /**
  1033. * add user property
  1034. * @param stored
  1035. * @param isAdvanced
  1036. * @param advancedConfigs
  1037. * @return {Object}
  1038. */
  1039. addUserProperty: function (stored, isAdvanced, advancedConfigs) {
  1040. var configData = {
  1041. id: stored.id,
  1042. name: stored.name,
  1043. displayName: stored.name,
  1044. serviceName: stored.serviceName,
  1045. value: stored.value,
  1046. defaultValue: stored.defaultValue,
  1047. displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
  1048. filename: stored.filename,
  1049. category: 'Advanced',
  1050. isUserProperty: stored.isUserProperty === true,
  1051. hasInitialValue: !!stored.hasInitialValue,
  1052. isOverridable: true,
  1053. overrides: stored.overrides,
  1054. isRequired: true,
  1055. isVisible: stored.isVisible,
  1056. isFinal: stored.isFinal,
  1057. defaultIsFinal: stored.defaultIsFinal,
  1058. supportsFinal: stored.supportsFinal,
  1059. showLabel: stored.showLabel !== false
  1060. };
  1061. App.get('config').calculateConfigProperties(configData, isAdvanced, advancedConfigs);
  1062. return configData;
  1063. },
  1064. complexConfigs: [
  1065. {
  1066. "id": "site property",
  1067. "name": "capacity-scheduler",
  1068. "displayName": "Capacity Scheduler",
  1069. "value": "",
  1070. "defaultValue": "",
  1071. "description": "Capacity Scheduler properties",
  1072. "displayType": "custom",
  1073. "isOverridable": true,
  1074. "isRequired": true,
  1075. "isVisible": true,
  1076. "supportsFinal": true,
  1077. "serviceName": "YARN",
  1078. "filename": "capacity-scheduler.xml",
  1079. "category": "CapacityScheduler"
  1080. }
  1081. ],
  1082. /**
  1083. * transform set of configs from file
  1084. * into one config with textarea content:
  1085. * name=value
  1086. * @param configs
  1087. * @param filename
  1088. * @return {*}
  1089. */
  1090. fileConfigsIntoTextarea: function (configs, filename) {
  1091. var fileConfigs = configs.filterProperty('filename', filename);
  1092. var value = '';
  1093. var defaultValue = '';
  1094. var complexConfig = this.get('complexConfigs').findProperty('filename', filename);
  1095. if (complexConfig) {
  1096. fileConfigs.forEach(function (_config) {
  1097. value += _config.name + '=' + _config.value + '\n';
  1098. defaultValue += _config.name + '=' + _config.defaultValue + '\n';
  1099. }, this);
  1100. var isFinal = fileConfigs.someProperty('isFinal', true);
  1101. complexConfig.value = value;
  1102. complexConfig.defaultValue = defaultValue;
  1103. complexConfig.isFinal = isFinal;
  1104. complexConfig.defaultIsFinal = isFinal;
  1105. configs = configs.filter(function (_config) {
  1106. return _config.filename !== filename;
  1107. });
  1108. configs.push(complexConfig);
  1109. }
  1110. return configs;
  1111. },
  1112. /**
  1113. * transform one config with textarea content
  1114. * into set of configs of file
  1115. * @param configs
  1116. * @param filename
  1117. * @return {*}
  1118. */
  1119. textareaIntoFileConfigs: function (configs, filename) {
  1120. var complexConfigName = this.get('complexConfigs').findProperty('filename', filename).name;
  1121. var configsTextarea = configs.findProperty('name', complexConfigName);
  1122. if (configsTextarea) {
  1123. var properties = configsTextarea.get('value').split('\n');
  1124. properties.forEach(function (_property) {
  1125. var name, value;
  1126. if (_property) {
  1127. _property = _property.split('=');
  1128. name = _property[0];
  1129. value = (_property[1]) ? _property[1] : "";
  1130. configs.push(Em.Object.create({
  1131. id: configsTextarea.get('id'),
  1132. name: name,
  1133. value: value,
  1134. defaultValue: value,
  1135. serviceName: configsTextarea.get('serviceName'),
  1136. filename: filename,
  1137. isFinal: configsTextarea.get('isFinal'),
  1138. isNotDefaultValue: configsTextarea.get('isNotDefaultValue'),
  1139. group: null
  1140. }));
  1141. }
  1142. });
  1143. return configs.without(configsTextarea);
  1144. }
  1145. console.log('ERROR: textarea config - ' + complexConfigName + ' is missing');
  1146. return configs;
  1147. },
  1148. /**
  1149. * trim trailing spaces for all properties.
  1150. * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
  1151. * for directory or directories displayType format string for further using.
  1152. * for password and values with spaces only do nothing.
  1153. * @param {Object} property
  1154. * @param {Boolean} isEmberObject
  1155. * @returns {*}
  1156. */
  1157. trimProperty: function (property, isEmberObject) {
  1158. var displayType = (isEmberObject) ? property.get('displayType') : property.displayType;
  1159. var value = (isEmberObject) ? property.get('value') : property.value;
  1160. var name = (isEmberObject) ? property.get('name') : property.name;
  1161. var rez;
  1162. switch (displayType) {
  1163. case 'directories':
  1164. case 'directory':
  1165. rez = value.trim().split(/\s+/g).join(',');
  1166. break;
  1167. case 'host':
  1168. rez = value.trim();
  1169. break;
  1170. case 'password':
  1171. break;
  1172. case 'advanced':
  1173. if (name == 'javax.jdo.option.ConnectionURL' || name == 'oozie.service.JPAService.jdbc.url') {
  1174. rez = value.trim();
  1175. }
  1176. default:
  1177. rez = (typeof value == 'string') ? value.replace(/(\s+$)/g, '') : value;
  1178. }
  1179. return ((rez == '') || (rez == undefined)) ? value : rez;
  1180. },
  1181. OnNnHAHideSnn: function (ServiceConfig) {
  1182. var configCategories = ServiceConfig.get('configCategories');
  1183. var snCategory = configCategories.findProperty('name', 'SNameNode');
  1184. var isSnnPresent = !!App.HDFSService.find('HDFS').get('snameNode');
  1185. if (snCategory && !isSnnPresent) {
  1186. configCategories.removeObject(snCategory);
  1187. }
  1188. },
  1189. /**
  1190. * Launches a dialog where an existing config-group can be selected, or a new
  1191. * one can be created. This is different than the config-group management
  1192. * dialog where host membership can be managed.
  1193. *
  1194. * The callback will be passed the created/selected config-group in the form
  1195. * of {id:2, name:'New hardware group'}. In the case of dialog being cancelled,
  1196. * the callback is provided <code>null</code>
  1197. *
  1198. * @param {String} groupName
  1199. * is closed, cancelled or OK is pressed.
  1200. */
  1201. saveGroupConfirmationPopup: function (groupName) {
  1202. App.ModalPopup.show({
  1203. header: Em.I18n.t('config.group.save.confirmation.header'),
  1204. secondary: Em.I18n.t('config.group.save.confirmation.manage.button'),
  1205. groupName: groupName,
  1206. bodyClass: Ember.View.extend({
  1207. templateName: require('templates/common/configs/saveConfigGroup')
  1208. }),
  1209. onSecondary: function () {
  1210. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups();
  1211. this.hide();
  1212. }
  1213. });
  1214. },
  1215. //Persist config groups created in step7 wizard controller
  1216. persistWizardStep7ConfigGroups: function () {
  1217. var installerController = App.router.get('installerController');
  1218. var step7Controller = App.router.get('wizardStep7Controller');
  1219. if (App.supports.hostOverridesInstaller) {
  1220. installerController.saveServiceConfigGroups(step7Controller, step7Controller.get('content.controllerName') == 'addServiceController');
  1221. App.clusterStatus.setClusterStatus({
  1222. localdb: App.db.data
  1223. });
  1224. }
  1225. },
  1226. /**
  1227. * exclude configs that depends on services which are uninstalled
  1228. * if config doesn't have serviceName or dependent service is installed then
  1229. * config not excluded
  1230. */
  1231. excludeUnsupportedConfigs: function (configs, installedServices) {
  1232. return configs.filter(function (config) {
  1233. return !(config.serviceName && !installedServices.contains(config.serviceName));
  1234. });
  1235. },
  1236. launchConfigGroupSelectionCreationDialog: function (serviceId, configGroups, configProperty, callback, isInstaller) {
  1237. var self = this;
  1238. var availableConfigGroups = configGroups.slice();
  1239. // delete Config Groups, that already have selected property overridden
  1240. var alreadyOverriddenGroups = [];
  1241. if (configProperty.get('overrides')) {
  1242. alreadyOverriddenGroups = configProperty.get('overrides').mapProperty('group.name');
  1243. }
  1244. var result = [];
  1245. availableConfigGroups.forEach(function (group) {
  1246. if (!group.get('isDefault') && (!alreadyOverriddenGroups.length || !alreadyOverriddenGroups.contains(group.name))) {
  1247. result.push(group);
  1248. }
  1249. }, this);
  1250. availableConfigGroups = result;
  1251. var selectedConfigGroup = availableConfigGroups && availableConfigGroups.length > 0 ?
  1252. availableConfigGroups[0] : null;
  1253. var serviceName = App.format.role(serviceId);
  1254. App.ModalPopup.show({
  1255. classNames: [ 'sixty-percent-width-modal' ],
  1256. header: Em.I18n.t('config.group.selection.dialog.title').format(serviceName),
  1257. subTitle: Em.I18n.t('config.group.selection.dialog.subtitle').format(serviceName),
  1258. selectExistingGroupLabel: Em.I18n.t('config.group.selection.dialog.option.select').format(serviceName),
  1259. noGroups: Em.I18n.t('config.group.selection.dialog.no.groups').format(serviceName),
  1260. createNewGroupLabel: Em.I18n.t('config.group.selection.dialog.option.create').format(serviceName),
  1261. createNewGroupDescription: Em.I18n.t('config.group.selection.dialog.option.create.msg').format(serviceName),
  1262. warningMessage: '&nbsp;',
  1263. isWarning: false,
  1264. optionSelectConfigGroup: true,
  1265. optionCreateConfigGroup: function () {
  1266. return !this.get('optionSelectConfigGroup');
  1267. }.property('optionSelectConfigGroup'),
  1268. hasExistedGroups: function () {
  1269. return !!this.get('availableConfigGroups').length;
  1270. }.property('availableConfigGroups'),
  1271. availableConfigGroups: availableConfigGroups,
  1272. selectedConfigGroup: selectedConfigGroup,
  1273. newConfigGroupName: '',
  1274. disablePrimary: function () {
  1275. return !(this.get('optionSelectConfigGroup') || (this.get('newConfigGroupName').trim().length > 0 && !this.get('isWarning')));
  1276. }.property('newConfigGroupName', 'optionSelectConfigGroup', 'warningMessage'),
  1277. onPrimary: function () {
  1278. if (this.get('optionSelectConfigGroup')) {
  1279. var selectedConfigGroup = this.get('selectedConfigGroup');
  1280. this.hide();
  1281. callback(selectedConfigGroup);
  1282. } else {
  1283. var newConfigGroupName = this.get('newConfigGroupName').trim();
  1284. var newConfigGroup = App.ConfigGroup.create({
  1285. id: null,
  1286. name: newConfigGroupName,
  1287. description: Em.I18n.t('config.group.description.default').format(new Date().toDateString()),
  1288. isDefault: false,
  1289. parentConfigGroup: null,
  1290. service: (isInstaller) ? Em.Object.create({id: serviceId}) : App.Service.find().findProperty('serviceName', serviceId),
  1291. hosts: [],
  1292. configSiteTags: [],
  1293. properties: []
  1294. });
  1295. if (!isInstaller) {
  1296. self.postNewConfigurationGroup(newConfigGroup);
  1297. }
  1298. if (newConfigGroup) {
  1299. newConfigGroup.set('parentConfigGroup', configGroups.findProperty('isDefault'));
  1300. configGroups.pushObject(newConfigGroup);
  1301. if (isInstaller) {
  1302. self.persistWizardStep7ConfigGroups();
  1303. } else {
  1304. self.saveGroupConfirmationPopup(newConfigGroupName);
  1305. }
  1306. this.hide();
  1307. callback(newConfigGroup);
  1308. }
  1309. }
  1310. },
  1311. onSecondary: function () {
  1312. this.hide();
  1313. callback(null);
  1314. },
  1315. doSelectConfigGroup: function (event) {
  1316. var configGroup = event.context;
  1317. console.log(configGroup);
  1318. this.set('selectedConfigGroup', configGroup);
  1319. },
  1320. validate: function () {
  1321. var msg = '&nbsp;';
  1322. var isWarning = false;
  1323. var optionSelect = this.get('optionSelectConfigGroup');
  1324. if (!optionSelect) {
  1325. var nn = this.get('newConfigGroupName');
  1326. if (nn && configGroups.mapProperty('name').contains(nn.trim())) {
  1327. msg = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  1328. isWarning = true;
  1329. }
  1330. }
  1331. this.set('warningMessage', msg);
  1332. this.set('isWarning', isWarning);
  1333. }.observes('newConfigGroupName', 'optionSelectConfigGroup'),
  1334. bodyClass: Ember.View.extend({
  1335. templateName: require('templates/common/configs/selectCreateConfigGroup'),
  1336. controllerBinding: 'App.router.mainServiceInfoConfigsController',
  1337. selectConfigGroupRadioButton: Ember.Checkbox.extend({
  1338. tagName: 'input',
  1339. attributeBindings: ['type', 'checked', 'disabled'],
  1340. checked: function () {
  1341. return this.get('parentView.parentView.optionSelectConfigGroup');
  1342. }.property('parentView.parentView.optionSelectConfigGroup'),
  1343. type: 'radio',
  1344. disabled: false,
  1345. click: function () {
  1346. this.set('parentView.parentView.optionSelectConfigGroup', true);
  1347. },
  1348. didInsertElement: function () {
  1349. if (!this.get('parentView.parentView.hasExistedGroups')) {
  1350. this.set('disabled', true);
  1351. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1352. }
  1353. }
  1354. }),
  1355. createConfigGroupRadioButton: Ember.Checkbox.extend({
  1356. tagName: 'input',
  1357. attributeBindings: ['type', 'checked'],
  1358. checked: function () {
  1359. return !this.get('parentView.parentView.optionSelectConfigGroup');
  1360. }.property('parentView.parentView.optionSelectConfigGroup'),
  1361. type: 'radio',
  1362. click: function () {
  1363. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1364. }
  1365. })
  1366. })
  1367. });
  1368. },
  1369. /**
  1370. * launch dialog where can be assigned another group to host
  1371. * @param selectedGroup
  1372. * @param configGroups
  1373. * @param hostName
  1374. * @param callback
  1375. */
  1376. launchSwitchConfigGroupOfHostDialog: function (selectedGroup, configGroups, hostName, callback) {
  1377. var self = this;
  1378. App.ModalPopup.show({
  1379. header: Em.I18n.t('config.group.host.switch.dialog.title'),
  1380. configGroups: configGroups,
  1381. selectedConfigGroup: selectedGroup,
  1382. disablePrimary: function () {
  1383. return !(this.get('selectedConfigGroup.name') !== selectedGroup.get('name'));
  1384. }.property('selectedConfigGroup'),
  1385. onPrimary: function () {
  1386. var newGroup = this.get('selectedConfigGroup');
  1387. if (selectedGroup.get('isDefault')) {
  1388. selectedGroup.set('hosts.length', selectedGroup.get('hosts.length') - 1)
  1389. } else {
  1390. selectedGroup.get('hosts').removeObject(hostName);
  1391. }
  1392. if (!selectedGroup.get('isDefault')) {
  1393. self.updateConfigurationGroup(selectedGroup, function () {
  1394. }, Em.K);
  1395. }
  1396. if (newGroup.get('isDefault')) {
  1397. newGroup.set('hosts.length', newGroup.get('hosts.length') + 1)
  1398. } else {
  1399. newGroup.get('hosts').pushObject(hostName);
  1400. }
  1401. callback(newGroup);
  1402. if (!newGroup.get('isDefault')) {
  1403. self.updateConfigurationGroup(newGroup, function () {
  1404. }, Em.K);
  1405. }
  1406. this.hide();
  1407. },
  1408. bodyClass: Ember.View.extend({
  1409. templateName: require('templates/utils/config_launch_switch_config_group_of_host')
  1410. })
  1411. });
  1412. },
  1413. /**
  1414. * Create a new config-group for a service.
  1415. *
  1416. * @param newConfigGroupData config group to post to server
  1417. * @param callback Callback function for Success or Error handling
  1418. * @return Returns the created config-group
  1419. */
  1420. postNewConfigurationGroup: function (newConfigGroupData, callback) {
  1421. var dataHosts = [];
  1422. newConfigGroupData.get('hosts').forEach(function (_host) {
  1423. dataHosts.push({
  1424. host_name: _host
  1425. });
  1426. }, this);
  1427. var sendData = {
  1428. name: 'config_groups.create',
  1429. data: {
  1430. 'group_name': newConfigGroupData.get('name'),
  1431. 'service_id': newConfigGroupData.get('service.id'),
  1432. 'description': newConfigGroupData.get('description'),
  1433. 'hosts': dataHosts
  1434. },
  1435. success: 'successFunction',
  1436. error: 'errorFunction',
  1437. successFunction: function (response) {
  1438. newConfigGroupData.set('id', response.resources[0].ConfigGroup.id);
  1439. if (callback) {
  1440. callback();
  1441. }
  1442. },
  1443. errorFunction: function (xhr, text, errorThrown) {
  1444. if (callback) {
  1445. callback(xhr, text, errorThrown);
  1446. }
  1447. console.error('Error in creating new Config Group');
  1448. }
  1449. };
  1450. sendData.sender = sendData;
  1451. App.ajax.send(sendData);
  1452. return newConfigGroupData;
  1453. },
  1454. /**
  1455. * PUTs the new configuration-group on the server.
  1456. * Changes possible here are the name, description and
  1457. * host memberships of the configuration-group.
  1458. *
  1459. * @param {App.ConfigGroup} configGroup Configuration group to update
  1460. * @param {Function} successCallback
  1461. * @param {Function} errorCallback
  1462. */
  1463. updateConfigurationGroup: function (configGroup, successCallback, errorCallback) {
  1464. var putConfigGroup = {
  1465. ConfigGroup: {
  1466. group_name: configGroup.get('name'),
  1467. description: configGroup.get('description'),
  1468. tag: configGroup.get('service.id'),
  1469. hosts: [],
  1470. desired_configs: []
  1471. }
  1472. };
  1473. configGroup.get('hosts').forEach(function (h) {
  1474. putConfigGroup.ConfigGroup.hosts.push({
  1475. host_name: h
  1476. });
  1477. });
  1478. configGroup.get('configSiteTags').forEach(function (cst) {
  1479. putConfigGroup.ConfigGroup.desired_configs.push({
  1480. type: cst.get('site'),
  1481. tag: cst.get('tag')
  1482. });
  1483. });
  1484. var sendData = {
  1485. name: 'config_groups.update',
  1486. data: {
  1487. id: configGroup.get('id'),
  1488. data: putConfigGroup
  1489. },
  1490. success: 'successFunction',
  1491. error: 'errorFunction',
  1492. successFunction: function () {
  1493. if (successCallback) {
  1494. successCallback();
  1495. }
  1496. },
  1497. errorFunction: function (xhr, text, errorThrown) {
  1498. if (errorCallback) {
  1499. errorCallback(xhr, text, errorThrown);
  1500. }
  1501. }
  1502. };
  1503. sendData.sender = sendData;
  1504. App.ajax.send(sendData);
  1505. },
  1506. clearConfigurationGroupHosts: function (configGroup, successCallback, errorCallback) {
  1507. configGroup = jQuery.extend({}, configGroup);
  1508. configGroup.set('hosts', []);
  1509. this.updateConfigurationGroup(configGroup, successCallback, errorCallback);
  1510. },
  1511. deleteConfigGroup: function (configGroup, successCallback, errorCallback) {
  1512. var sendData = {
  1513. name: 'common.delete.config_group',
  1514. sender: this,
  1515. data: {
  1516. id: configGroup.get('id')
  1517. },
  1518. success: 'successFunction',
  1519. error: 'errorFunction',
  1520. successFunction: function () {
  1521. if (successCallback) {
  1522. successCallback();
  1523. }
  1524. },
  1525. errorFunction: function (xhr, text, errorThrown) {
  1526. if (errorCallback) {
  1527. errorCallback(xhr, text, errorThrown);
  1528. }
  1529. }
  1530. };
  1531. sendData.sender = sendData;
  1532. App.ajax.send(sendData);
  1533. },
  1534. /**
  1535. * Gets all the configuration-groups for the given service.
  1536. *
  1537. * @param serviceId
  1538. * (string) ID of the service. Ex: HDFS
  1539. */
  1540. getConfigGroupsForService: function (serviceId) {
  1541. },
  1542. /**
  1543. * Gets all the configuration-groups for a host.
  1544. *
  1545. * @param hostName
  1546. * (string) host name used to register
  1547. */
  1548. getConfigGroupsForHost: function (hostName) {
  1549. }
  1550. });