config.js 70 KB

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