config.js 63 KB

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