config.js 69 KB

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