config.js 63 KB

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