config.js 57 KB

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