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