config.js 63 KB

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