config.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. * @return {*}
  394. */
  395. mergePreDefinedWithStored: function (storedConfigs, advancedConfigs, selectedServiceNames) {
  396. var mergedConfigs = [];
  397. var preDefinedConfigs = $.extend(true, [], this.get('preDefinedGlobalProperties').concat(this.get('preDefinedSiteProperties')));
  398. storedConfigs = (storedConfigs) ? storedConfigs : [];
  399. var preDefinedNames = preDefinedConfigs.mapProperty('name');
  400. var storedNames = storedConfigs.mapProperty('name');
  401. var names = preDefinedNames.concat(storedNames).uniq();
  402. names.forEach(function (name) {
  403. var storedCfgs = storedConfigs.filterProperty('name', name);
  404. var preDefinedCfgs = [];
  405. var preDefinedConfig = preDefinedConfigs.filterProperty('name', name);
  406. preDefinedConfig.forEach(function (_preDefinedConfig) {
  407. if (selectedServiceNames.contains(_preDefinedConfig.serviceName) || _preDefinedConfig.serviceName === 'MISC') {
  408. preDefinedCfgs.push(_preDefinedConfig);
  409. }
  410. }, this);
  411. var configData = {};
  412. var isAdvanced = advancedConfigs.someProperty('name', name);
  413. if (storedCfgs.length <= 1 && preDefinedCfgs.length <= 1) {
  414. var stored = storedCfgs[0];
  415. var preDefined = preDefinedCfgs[0];
  416. if (preDefined && stored) {
  417. configData = preDefined;
  418. configData.value = stored.value;
  419. configData.defaultValue = stored.defaultValue;
  420. configData.overrides = stored.overrides;
  421. configData.filename = stored.filename;
  422. configData.description = stored.description;
  423. configData.isVisible = stored.isVisible;
  424. configData.isRequired = (configData.isRequired !== undefined) ? configData.isRequired : true;
  425. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  426. configData.showLabel = stored.showLabel !== false;
  427. } else if (!preDefined && stored) {
  428. configData = {
  429. id: stored.id,
  430. name: stored.name,
  431. displayName: stored.name,
  432. serviceName: stored.serviceName,
  433. value: stored.value,
  434. defaultValue: stored.defaultValue,
  435. displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
  436. filename: stored.filename,
  437. category: 'Advanced',
  438. isUserProperty: stored.isUserProperty === true,
  439. isOverridable: true,
  440. overrides: stored.overrides,
  441. isRequired: true,
  442. isVisible: stored.isVisible,
  443. showLabel: stored.showLabel !== false
  444. };
  445. this.calculateConfigProperties(configData, isAdvanced, advancedConfigs);
  446. } else if (preDefined && !stored) {
  447. configData = preDefined;
  448. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  449. if (isAdvanced) {
  450. var advanced = advancedConfigs.findProperty('name', configData.name);
  451. this.setPropertyFromStack(configData,advanced);
  452. }
  453. }
  454. if (configData.displayType === 'checkbox') {
  455. configData.value = configData.value === 'true'; // convert {String} value to {Boolean}
  456. configData.defaultValue = configData.value;
  457. }
  458. mergedConfigs.push(configData);
  459. } else {
  460. preDefinedCfgs.forEach(function (cfg) {
  461. configData = cfg;
  462. configData.isRequiredByAgent = (configData.isRequiredByAgent !== undefined) ? configData.isRequiredByAgent : true;
  463. var storedCfg = storedCfgs.findProperty('filename', cfg.filename);
  464. if (storedCfg) {
  465. configData.value = storedCfg.value;
  466. configData.defaultValue = storedCfg.defaultValue;
  467. configData.overrides = storedCfg.overrides;
  468. configData.filename = storedCfg.filename;
  469. configData.description = storedCfg.description;
  470. configData.description = storedCfg.showLabel !== false;
  471. } else if (isAdvanced){
  472. advanced = advancedConfigs.filterProperty('filename', configData.filename).findProperty('name', configData.name);
  473. this.setPropertyFromStack(configData,advanced);
  474. }
  475. mergedConfigs.push(configData);
  476. }, this);
  477. }
  478. }, this);
  479. return mergedConfigs;
  480. },
  481. /**
  482. *
  483. * @param configData {Object} Configs that will be binded to the view on step-7 of installer wizard
  484. * @param advanced {Object} Config property loaded from Server side stack definition
  485. */
  486. setPropertyFromStack: function(configData,advanced) {
  487. // Password fields should be made blank by default in installer wizard
  488. // irrespective of whatever value is sent from stack definition.
  489. // This forces the user to fill the password field.
  490. configData.value = configData.displayType == "password" ? '' : advanced ? advanced.value : configData.value;
  491. configData.defaultValue = configData.value;
  492. configData.filename = advanced ? advanced.filename : configData.filename;
  493. configData.description = advanced ? advanced.description : configData.description;
  494. },
  495. /**
  496. * look over advanced configs and add missing configs to serviceConfigs
  497. * filter fetched configs by service if passed
  498. * @param serviceConfigs
  499. * @param advancedConfigs
  500. * @param serviceName
  501. */
  502. addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
  503. var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs.slice();
  504. advancedConfigs.forEach(function (_config) {
  505. var configCategory = 'Advanced';
  506. var categoryMetaData = null;
  507. if (_config) {
  508. if (this.get('configMapping').computed().someProperty('name', _config.name)) {
  509. } else if (!(configsToVerifying.someProperty('name', _config.name))) {
  510. if (this.get('customFileNames').contains(_config.filename)) {
  511. categoryMetaData = this.identifyCategory(_config);
  512. if (categoryMetaData != null) {
  513. configCategory = categoryMetaData.get('name');
  514. }
  515. }
  516. _config.id = "site property";
  517. _config.category = configCategory;
  518. _config.displayName = _config.name;
  519. _config.defaultValue = _config.value;
  520. // make all advanced configs optional and populated by default
  521. /*
  522. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  523. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  524. * false; _config.value = ''; } else if
  525. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  526. */
  527. _config.isRequired = true;
  528. _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
  529. serviceConfigs.push(_config);
  530. }
  531. }
  532. }, this);
  533. },
  534. /**
  535. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  536. */
  537. addCustomConfigs: function (configs) {
  538. var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
  539. var stored = configs.filter(function (_config) {
  540. return this.get('categoriesWithCustom').contains(_config.category);
  541. }, this);
  542. if (App.supports.capacitySchedulerUi) {
  543. var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
  544. if (queueProperties.length) {
  545. queueProperties.setEach('isQueue', true);
  546. }
  547. }
  548. },
  549. miscConfigVisibleProperty: function (configs, serviceToShow) {
  550. configs.forEach(function (item) {
  551. item.set("isVisible", item.belongsToService.some(function (cur) {
  552. return serviceToShow.contains(cur)
  553. }));
  554. });
  555. return configs;
  556. },
  557. /**
  558. * render configs, distribute them by service
  559. * and wrap each in ServiceConfigProperty object
  560. * @param configs
  561. * @param storedConfigs
  562. * @param allSelectedServiceNames
  563. * @param installedServiceNames
  564. * @param localDB
  565. * @return {Array}
  566. */
  567. renderConfigs: function (configs, storedConfigs, allSelectedServiceNames, installedServiceNames, localDB) {
  568. var renderedServiceConfigs = [];
  569. var services = [];
  570. this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  571. if (allSelectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  572. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  573. if (!installedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  574. serviceConfig.showConfig = true;
  575. }
  576. services.push(serviceConfig);
  577. }
  578. });
  579. services.forEach(function (service) {
  580. var configsByService = [];
  581. var serviceConfigs = configs.filterProperty('serviceName', service.serviceName);
  582. serviceConfigs.forEach(function (_config) {
  583. _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
  584. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  585. this.updateHostOverrides(serviceConfigProperty, _config);
  586. if (!storedConfigs) {
  587. serviceConfigProperty.initialValue(localDB);
  588. }
  589. this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
  590. serviceConfigProperty.validate();
  591. configsByService.pushObject(serviceConfigProperty);
  592. }, this);
  593. var serviceConfig = this.createServiceConfig(service.serviceName);
  594. serviceConfig.set('showConfig', service.showConfig);
  595. // Use calculated default values for some configs
  596. var recommendedDefaults = {};
  597. if (!storedConfigs && service.defaultsProviders) {
  598. service.defaultsProviders.forEach(function (defaultsProvider) {
  599. var defaults = defaultsProvider.getDefaults(localDB);
  600. for (var name in defaults) {
  601. var config = configsByService.findProperty('name', name);
  602. if (!config) {
  603. continue;
  604. }
  605. if (!!defaults[name]) {
  606. recommendedDefaults[name] = defaults[name];
  607. config.set('value', defaults[name]);
  608. config.set('defaultValue', defaults[name]);
  609. } else {
  610. recommendedDefaults[name] = config.get('defaultValue');
  611. }
  612. }
  613. });
  614. }
  615. if (service.configsValidator) {
  616. service.configsValidator.set('recommendedDefaults', recommendedDefaults);
  617. var validators = service.configsValidator.get('configValidators');
  618. for (var validatorName in validators) {
  619. var c = configsByService.findProperty('name', validatorName);
  620. if (c) {
  621. c.set('serviceValidator', service.configsValidator);
  622. }
  623. }
  624. }
  625. serviceConfig.set('configs', configsByService);
  626. renderedServiceConfigs.push(serviceConfig);
  627. }, this);
  628. return renderedServiceConfigs;
  629. },
  630. /**
  631. Takes care of the "dynamic defaults" for the GLUSTERFS configs. Sets
  632. some of the config defaults to previously user-entered data.
  633. **/
  634. tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
  635. var firstHost = null;
  636. for (var host in localDB.hosts) {
  637. firstHost = host;
  638. break;
  639. }
  640. try {
  641. if (typeof(config.defaultValue) == "string" && config.defaultValue.indexOf("{firstHost}") >= 0) {
  642. serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
  643. serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
  644. }
  645. } catch (err) {
  646. // Nothing to worry about here, most likely trying indexOf on a non-string
  647. }
  648. },
  649. /**
  650. * create new child configs from overrides, attach them to parent config
  651. * override - value of config, related to particular host(s)
  652. * @param configProperty
  653. * @param storedConfigProperty
  654. */
  655. updateHostOverrides: function (configProperty, storedConfigProperty) {
  656. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  657. var overrides = [];
  658. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  659. // create new override with new value
  660. var newSCP = App.ServiceConfigProperty.create(configProperty);
  661. newSCP.set('value', overrideEntry.value);
  662. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  663. newSCP.set('parentSCP', configProperty);
  664. var hostsArray = Ember.A([]);
  665. overrideEntry.hosts.forEach(function (host) {
  666. hostsArray.push(host);
  667. });
  668. newSCP.set('selectedHostOptions', hostsArray);
  669. overrides.pushObject(newSCP);
  670. });
  671. configProperty.set('overrides', overrides);
  672. }
  673. },
  674. /**
  675. * create new ServiceConfig object by service name
  676. * @param serviceName
  677. */
  678. createServiceConfig: function (serviceName) {
  679. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  680. var serviceConfig = App.ServiceConfig.create({
  681. filename: preDefinedServiceConfig.filename,
  682. serviceName: preDefinedServiceConfig.serviceName,
  683. displayName: preDefinedServiceConfig.displayName,
  684. configCategories: preDefinedServiceConfig.configCategories,
  685. configs: [],
  686. configGroups: []
  687. });
  688. serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
  689. switch (category.name) {
  690. case 'CapacityScheduler':
  691. if (App.supports.capacitySchedulerUi) {
  692. category.set('customView', App.ServiceConfigCapacityScheduler);
  693. } else {
  694. category.set('isCustomView', false);
  695. }
  696. break;
  697. }
  698. }, this);
  699. return serviceConfig;
  700. },
  701. /**
  702. * GETs all cluster level sites in one call.
  703. *
  704. * @return Array of all site configs
  705. */
  706. loadConfigsByTags: function (tags) {
  707. var urlParams = [];
  708. tags.forEach(function (_tag) {
  709. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  710. });
  711. var params = urlParams.join('|');
  712. App.ajax.send({
  713. name: 'config.on_site',
  714. sender: this,
  715. data: {
  716. params: params
  717. },
  718. success: 'loadConfigsByTagsSuccess'
  719. });
  720. return configGroupsByTag;
  721. },
  722. loadConfigsByTagsSuccess: function (data) {
  723. if (data.items) {
  724. configGroupsByTag = [];
  725. data.items.forEach(function (item) {
  726. this.loadedConfigurationsCache[item.type + "_" + item.tag] = item.properties;
  727. configGroupsByTag.push(item);
  728. }, this);
  729. }
  730. },
  731. /**
  732. * Generate serviceProperties save it to localDB
  733. * called form stepController step6WizardController
  734. *
  735. * @param serviceName
  736. * @return {*}
  737. */
  738. loadAdvancedConfig: function (serviceName, callback, sync) {
  739. App.ajax.send({
  740. name: 'config.advanced',
  741. sender: this,
  742. data: {
  743. serviceName: serviceName,
  744. stackVersionUrl: App.get('stackVersionURL'),
  745. stackVersion: App.get('currentStackVersionNumber'),
  746. callback: callback,
  747. sync: sync
  748. },
  749. success: 'loadAdvancedConfigSuccess',
  750. error: 'loadAdvancedConfigError'
  751. });
  752. },
  753. loadAdvancedConfigSuccess: function (data, opt, params) {
  754. console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
  755. var properties = [];
  756. if (data.items.length) {
  757. data.items.forEach(function (item) {
  758. item = item.StackConfigurations;
  759. item.isVisible = item.type !== 'global.xml';
  760. var serviceName = item.service_name;
  761. var fileName = item.type;
  762. var isHDP2 = App.get('isHadoop2Stack');
  763. /**
  764. * Properties from mapred-queue-acls.xml are ignored unless App.supports.capacitySchedulerUi is true
  765. * Properties from capacity-scheduler.xml are ignored unless HDP stack version is 2.x or
  766. * HDP stack version is 1.x and App.supports.capacitySchedulerUi is true.
  767. */
  768. if ((fileName !== 'mapred-queue-acls.xml' || App.supports.capacitySchedulerUi) &&
  769. (fileName !== 'capacity-scheduler.xml' || isHDP2 || App.supports.capacitySchedulerUi)) {
  770. properties.push({
  771. serviceName: serviceName,
  772. name: item.property_name,
  773. value: item.property_value,
  774. description: item.property_description,
  775. isVisible: item.isVisible,
  776. filename: item.filename || fileName
  777. });
  778. }
  779. }, this);
  780. }
  781. params.callback(properties);
  782. },
  783. loadAdvancedConfigError: function (request, ajaxOptions, error, opt, params) {
  784. console.log('ERROR: failed to load stack configs for', params.serviceName);
  785. params.callback([]);
  786. },
  787. /**
  788. * Get properties from server by type and tag with properties, that belong to group
  789. * push them to common {serviceConfigs}
  790. */
  791. loadServiceConfigGroupOverrides: function (serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups) {
  792. var configKeyToConfigMap = {};
  793. serviceConfigs.forEach(function (item) {
  794. configKeyToConfigMap[item.name] = item;
  795. });
  796. var typeTagToGroupMap = {};
  797. var urlParams = [];
  798. for (var group in loadedGroupToOverrideSiteToTagMap) {
  799. var overrideTypeTags = loadedGroupToOverrideSiteToTagMap[group];
  800. for (var type in overrideTypeTags) {
  801. var tag = overrideTypeTags[type];
  802. typeTagToGroupMap[type + "///" + tag] = configGroups.findProperty('name', group);
  803. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  804. }
  805. }
  806. var params = urlParams.join('|');
  807. if (urlParams.length) {
  808. App.ajax.send({
  809. name: 'config.host_overrides',
  810. sender: this,
  811. data: {
  812. params: params,
  813. configKeyToConfigMap: configKeyToConfigMap,
  814. typeTagToGroupMap: typeTagToGroupMap
  815. },
  816. success: 'loadServiceConfigGroupOverridesSuccess'
  817. });
  818. }
  819. },
  820. loadServiceConfigGroupOverridesSuccess: function (data, opt, params) {
  821. data.items.forEach(function (config) {
  822. App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
  823. var group = params.typeTagToGroupMap[config.type + "///" + config.tag];
  824. var properties = config.properties;
  825. for (var prop in properties) {
  826. var serviceConfig = params.configKeyToConfigMap[prop];
  827. var hostOverrideValue = properties[prop];
  828. if (serviceConfig && serviceConfig.displayType === 'int') {
  829. if (/\d+m$/.test(hostOverrideValue)) {
  830. hostOverrideValue = hostOverrideValue.slice(0, hostOverrideValue.length - 1);
  831. }
  832. } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
  833. switch (hostOverrideValue) {
  834. case 'true':
  835. hostOverrideValue = true;
  836. break;
  837. case 'false':
  838. hostOverrideValue = false;
  839. break;
  840. }
  841. }
  842. if (serviceConfig) {
  843. // Value of this property is different for this host.
  844. var overrides = 'overrides';
  845. if (!(overrides in serviceConfig)) {
  846. serviceConfig.overrides = [];
  847. }
  848. if (!serviceConfig.overrides) {
  849. serviceConfig.set('overrides', []);
  850. }
  851. console.log("loadServiceConfigGroupOverridesSuccess(): [" + group + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
  852. serviceConfig.overrides.push({value: hostOverrideValue, group: group});
  853. }
  854. }
  855. });
  856. },
  857. /**
  858. * Set all site property that are derived from other site-properties
  859. */
  860. setConfigValue: function (mappedConfigs, allConfigs, config, globalConfigs) {
  861. var globalValue;
  862. if (config.value == null) {
  863. return;
  864. }
  865. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  866. var fkName = config.name.match(/<(foreignKey.*?)>/g);
  867. var templateValue = config.value.match(/<(templateName.*?)>/g);
  868. if (fkValue) {
  869. fkValue.forEach(function (_fkValue) {
  870. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  871. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  872. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  873. config.value = config.value.replace(_fkValue, globalValue);
  874. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  875. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  876. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  877. } else {
  878. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  879. }
  880. config.value = config.value.replace(_fkValue, globalValue);
  881. }
  882. }, this);
  883. }
  884. // config._name - formatted name from original config name
  885. if (fkName) {
  886. fkName.forEach(function (_fkName) {
  887. var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
  888. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  889. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  890. config._name = config.name.replace(_fkName, globalValue);
  891. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  892. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  893. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  894. } else {
  895. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  896. }
  897. config._name = config.name.replace(_fkName, globalValue);
  898. }
  899. }, this);
  900. }
  901. //For properties in the configMapping file having foreignKey and templateName properties.
  902. if (templateValue) {
  903. templateValue.forEach(function (_value) {
  904. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  905. if (globalConfigs.someProperty('name', config.templateName[index])) {
  906. var globalValue = globalConfigs.findProperty('name', config.templateName[index]).value;
  907. config.value = config.value.replace(_value, globalValue);
  908. } else {
  909. config.value = null;
  910. }
  911. }, this);
  912. }
  913. },
  914. complexConfigs: [
  915. {
  916. "id": "site property",
  917. "name": "capacity-scheduler",
  918. "displayName": "Capacity Scheduler",
  919. "value": "",
  920. "defaultValue": "",
  921. "description": "Capacity Scheduler properties",
  922. "displayType": "custom",
  923. "isOverridable": true,
  924. "isRequired": true,
  925. "isVisible": true,
  926. "serviceName": "YARN",
  927. "filename": "capacity-scheduler.xml",
  928. "category": "CapacityScheduler"
  929. }
  930. ],
  931. /**
  932. * transform set of configs from file
  933. * into one config with textarea content:
  934. * name=value
  935. * @param configs
  936. * @param filename
  937. * @return {*}
  938. */
  939. fileConfigsIntoTextarea: function (configs, filename) {
  940. var fileConfigs = configs.filterProperty('filename', filename);
  941. var value = '';
  942. var defaultValue = '';
  943. var complexConfig = this.get('complexConfigs').findProperty('filename', filename);
  944. if (complexConfig) {
  945. fileConfigs.forEach(function (_config) {
  946. value += _config.name + '=' + _config.value + '\n';
  947. defaultValue += _config.name + '=' + _config.defaultValue + '\n';
  948. }, this);
  949. complexConfig.value = value;
  950. complexConfig.defaultValue = defaultValue;
  951. configs = configs.filter(function (_config) {
  952. return _config.filename !== filename;
  953. });
  954. configs.push(complexConfig);
  955. }
  956. return configs;
  957. },
  958. /**
  959. * transform one config with textarea content
  960. * into set of configs of file
  961. * @param configs
  962. * @param filename
  963. * @return {*}
  964. */
  965. textareaIntoFileConfigs: function (configs, filename) {
  966. var complexConfigName = this.get('complexConfigs').findProperty('filename', filename).name;
  967. var configsTextarea = configs.findProperty('name', complexConfigName);
  968. if (configsTextarea) {
  969. var properties = configsTextarea.get('value').split('\n');
  970. properties.forEach(function (_property) {
  971. var name, value;
  972. if (_property) {
  973. _property = _property.split('=');
  974. name = _property[0];
  975. value = (_property[1]) ? _property[1] : "";
  976. configs.push(Em.Object.create({
  977. id: configsTextarea.get('id'),
  978. name: name,
  979. value: value,
  980. defaultValue: value,
  981. serviceName: configsTextarea.get('serviceName'),
  982. filename: filename
  983. }));
  984. }
  985. });
  986. return configs.without(configsTextarea);
  987. }
  988. console.log('ERROR: textarea config - ' + complexConfigName + ' is missing');
  989. return configs;
  990. },
  991. /**
  992. * trim trailing spaces for all properties.
  993. * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
  994. * for directory or directories displayType format string for further using.
  995. * for password and values with spaces only do nothing.
  996. * @param {Object} property
  997. * @param {Boolean} isEmberObject
  998. * @returns {*}
  999. */
  1000. trimProperty: function (property, isEmberObject) {
  1001. var displayType = (isEmberObject) ? property.get('displayType') : property.displayType;
  1002. var value = (isEmberObject) ? property.get('value') : property.value;
  1003. var name = (isEmberObject) ? property.get('name') : property.name;
  1004. var rez;
  1005. switch (displayType) {
  1006. case 'directories':
  1007. case 'directory':
  1008. rez = value.trim().split(/\s+/g).join(',');
  1009. break;
  1010. case 'host':
  1011. rez = value.trim();
  1012. break;
  1013. case 'password':
  1014. break;
  1015. case 'advanced':
  1016. if (name == 'javax.jdo.option.ConnectionURL' || name == 'oozie.service.JPAService.jdbc.url') {
  1017. rez = value.trim();
  1018. }
  1019. default:
  1020. rez = (typeof value == 'string') ? value.replace(/(\s+$)/g, '') : value;
  1021. }
  1022. return ((rez == '') || (rez == undefined)) ? value : rez;
  1023. },
  1024. OnNnHAHideSnn: function (ServiceConfig) {
  1025. var configCategories = ServiceConfig.get('configCategories');
  1026. var snCategory = configCategories.findProperty('name', 'SNameNode');
  1027. var isSnnPresent = !!App.HDFSService.find('HDFS').get('snameNode');
  1028. if (snCategory && !isSnnPresent) {
  1029. configCategories.removeObject(snCategory);
  1030. }
  1031. },
  1032. /**
  1033. * Launches a dialog where an existing config-group can be selected, or a new
  1034. * one can be created. This is different than the config-group management
  1035. * dialog where host membership can be managed.
  1036. *
  1037. * The callback will be passed the created/selected config-group in the form
  1038. * of {id:2, name:'New hardware group'}. In the case of dialog being cancelled,
  1039. * the callback is provided <code>null</code>
  1040. *
  1041. * @param {String} groupName
  1042. * is closed, cancelled or OK is pressed.
  1043. */
  1044. saveGroupConfirmationPopup: function(groupName) {
  1045. App.ModalPopup.show({
  1046. header: Em.I18n.t('config.group.save.confirmation.header'),
  1047. secondary: Em.I18n.t('config.group.save.confirmation.manage.button'),
  1048. groupName: groupName,
  1049. bodyClass: Ember.View.extend({
  1050. templateName: require('templates/common/configs/saveConfigGroup')
  1051. }),
  1052. onSecondary: function() {
  1053. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups();
  1054. this.hide();
  1055. }
  1056. });
  1057. },
  1058. //Persist config groups created in step7 wizard controller
  1059. persistWizardStep7ConfigGroups: function () {
  1060. var installerController = App.router.get('installerController');
  1061. var step7Controller = App.router.get('wizardStep7Controller');
  1062. if (App.supports.hostOverridesInstaller) {
  1063. installerController.saveServiceConfigGroups(step7Controller);
  1064. App.clusterStatus.setClusterStatus({
  1065. localdb: App.db.data
  1066. });
  1067. }
  1068. },
  1069. /**
  1070. * exclude configs that depends on services which are uninstalled
  1071. * if config doesn't have serviceName or dependent service is installed then
  1072. * config not excluded
  1073. */
  1074. excludeUnsupportedConfigs: function (configs, installedServices) {
  1075. return configs.filter(function (config) {
  1076. return !(config.serviceName && !installedServices.contains(config.serviceName));
  1077. });
  1078. },
  1079. launchConfigGroupSelectionCreationDialog : function(serviceId, configGroups, configProperty, callback, isInstaller) {
  1080. var self = this;
  1081. var availableConfigGroups = configGroups.slice();
  1082. // delete Config Groups, that already have selected property overridden
  1083. var alreadyOverriddenGroups = [];
  1084. if (configProperty.get('overrides')) {
  1085. alreadyOverriddenGroups = configProperty.get('overrides').mapProperty('group.name');
  1086. }
  1087. var result = [];
  1088. availableConfigGroups.forEach(function (group) {
  1089. if (!group.get('isDefault') && (!alreadyOverriddenGroups.length || !alreadyOverriddenGroups.contains(group.name))) {
  1090. result.push(group);
  1091. }
  1092. }, this);
  1093. availableConfigGroups = result;
  1094. var selectedConfigGroup = availableConfigGroups && availableConfigGroups.length > 0 ?
  1095. availableConfigGroups[0] : null;
  1096. var serviceName = App.Service.DisplayNames[serviceId];
  1097. App.ModalPopup.show({
  1098. classNames: [ 'sixty-percent-width-modal' ],
  1099. header: Em.I18n.t('config.group.selection.dialog.title').format(serviceName),
  1100. subTitle: Em.I18n.t('config.group.selection.dialog.subtitle').format(serviceName),
  1101. selectExistingGroupLabel: Em.I18n.t('config.group.selection.dialog.option.select').format(serviceName),
  1102. noGroups: Em.I18n.t('config.group.selection.dialog.no.groups').format(serviceName),
  1103. createNewGroupLabel: Em.I18n.t('config.group.selection.dialog.option.create').format(serviceName),
  1104. createNewGroupDescription: Em.I18n.t('config.group.selection.dialog.option.create.msg').format(serviceName),
  1105. warningMessage: '&nbsp;',
  1106. isWarning: false,
  1107. optionSelectConfigGroup: true,
  1108. optionCreateConfigGroup: function(){
  1109. return !this.get('optionSelectConfigGroup');
  1110. }.property('optionSelectConfigGroup'),
  1111. hasExistedGroups: function() {
  1112. return !!this.get('availableConfigGroups').length;
  1113. }.property('availableConfigGroups'),
  1114. availableConfigGroups: availableConfigGroups,
  1115. selectedConfigGroup: selectedConfigGroup,
  1116. newConfigGroupName: '',
  1117. disablePrimary: function () {
  1118. return !(this.get('optionSelectConfigGroup') || (this.get('newConfigGroupName').trim().length > 0 && !this.get('isWarning')));
  1119. }.property('newConfigGroupName', 'optionSelectConfigGroup', 'warningMessage'),
  1120. onPrimary: function () {
  1121. if (this.get('optionSelectConfigGroup')) {
  1122. var selectedConfigGroup = this.get('selectedConfigGroup');
  1123. this.hide();
  1124. callback(selectedConfigGroup);
  1125. } else {
  1126. var newConfigGroupName = this.get('newConfigGroupName').trim();
  1127. var newConfigGroup = App.ConfigGroup.create({
  1128. id: null,
  1129. name: newConfigGroupName,
  1130. description: Em.I18n.t('config.group.description.default').format(new Date().toDateString()),
  1131. isDefault: false,
  1132. parentConfigGroup: null,
  1133. service: (isInstaller) ? Em.Object.create({id: serviceId}) : App.Service.find().findProperty('serviceName', serviceId),
  1134. hosts: [],
  1135. configSiteTags: [],
  1136. properties: []
  1137. });
  1138. self.postNewConfigurationGroup(newConfigGroup);
  1139. if (newConfigGroup) {
  1140. newConfigGroup.set('parentConfigGroup', configGroups.findProperty('isDefault'));
  1141. configGroups.pushObject(newConfigGroup);
  1142. if (isInstaller) {
  1143. self.persistWizardStep7ConfigGroups();
  1144. } else {
  1145. self.saveGroupConfirmationPopup(newConfigGroupName);
  1146. }
  1147. this.hide();
  1148. callback(newConfigGroup);
  1149. }
  1150. }
  1151. },
  1152. onSecondary: function () {
  1153. this.hide();
  1154. callback(null);
  1155. },
  1156. doSelectConfigGroup: function (event) {
  1157. var configGroup = event.context;
  1158. console.log(configGroup);
  1159. this.set('selectedConfigGroup', configGroup);
  1160. },
  1161. validate: function () {
  1162. var msg = '&nbsp;';
  1163. var isWarning = false;
  1164. var optionSelect = this.get('optionSelectConfigGroup');
  1165. if (!optionSelect) {
  1166. var nn = this.get('newConfigGroupName');
  1167. if (nn && configGroups.mapProperty('name').contains(nn.trim())) {
  1168. msg = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  1169. isWarning = true;
  1170. }
  1171. }
  1172. this.set('warningMessage', msg);
  1173. this.set('isWarning', isWarning);
  1174. }.observes('newConfigGroupName', 'optionSelectConfigGroup'),
  1175. bodyClass: Ember.View.extend({
  1176. templateName: require('templates/common/configs/selectCreateConfigGroup'),
  1177. controllerBinding: 'App.router.mainServiceInfoConfigsController',
  1178. selectConfigGroupRadioButton: Ember.Checkbox.extend({
  1179. tagName: 'input',
  1180. attributeBindings: ['type', 'checked', 'disabled'],
  1181. checked: function () {
  1182. return this.get('parentView.parentView.optionSelectConfigGroup');
  1183. }.property('parentView.parentView.optionSelectConfigGroup'),
  1184. type: 'radio',
  1185. disabled: false,
  1186. click: function () {
  1187. this.set('parentView.parentView.optionSelectConfigGroup', true);
  1188. },
  1189. didInsertElement: function () {
  1190. if (!this.get('parentView.parentView.hasExistedGroups')) {
  1191. this.set('disabled', true);
  1192. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1193. }
  1194. }
  1195. }),
  1196. createConfigGroupRadioButton: Ember.Checkbox.extend({
  1197. tagName: 'input',
  1198. attributeBindings: ['type', 'checked'],
  1199. checked: function () {
  1200. return !this.get('parentView.parentView.optionSelectConfigGroup');
  1201. }.property('parentView.parentView.optionSelectConfigGroup'),
  1202. type: 'radio',
  1203. click: function () {
  1204. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1205. }
  1206. })
  1207. })
  1208. });
  1209. },
  1210. /**
  1211. * launch dialog where can be assigned another group to host
  1212. * @param selectedGroup
  1213. * @param configGroups
  1214. * @param hostName
  1215. * @param callback
  1216. */
  1217. launchSwitchConfigGroupOfHostDialog: function (selectedGroup, configGroups, hostName, callback) {
  1218. var self = this;
  1219. App.ModalPopup.show({
  1220. header: Em.I18n.t('config.group.host.switch.dialog.title'),
  1221. configGroups: configGroups,
  1222. selectedConfigGroup: selectedGroup,
  1223. disablePrimary: function () {
  1224. return !(this.get('selectedConfigGroup.name') !== selectedGroup.get('name'));
  1225. }.property('selectedConfigGroup'),
  1226. onPrimary: function () {
  1227. var newGroup = this.get('selectedConfigGroup');
  1228. selectedGroup.get('hosts').removeObject(hostName);
  1229. if (!selectedGroup.get('isDefault')) {
  1230. self.updateConfigurationGroup(selectedGroup, function () {
  1231. }, function () {});
  1232. }
  1233. newGroup.get('hosts').pushObject(hostName);
  1234. callback(newGroup);
  1235. if (!newGroup.get('isDefault')) {
  1236. self.updateConfigurationGroup(newGroup, function () {
  1237. }, function () {});
  1238. }
  1239. this.hide();
  1240. },
  1241. bodyClass: Ember.View.extend({
  1242. templateName: require('templates/utils/config_launch_switch_config_group_of_host')
  1243. })
  1244. });
  1245. },
  1246. /**
  1247. * Create a new config-group for a service.
  1248. *
  1249. * @param newConfigGroupData config group to post to server
  1250. * @param callback Callback function for Success or Error handling
  1251. * @return Returns the created config-group
  1252. */
  1253. postNewConfigurationGroup: function (newConfigGroupData, callback) {
  1254. var dataHosts = [];
  1255. newConfigGroupData.get('hosts').forEach(function (_host) {
  1256. dataHosts.push({
  1257. host_name: _host
  1258. });
  1259. }, this);
  1260. var sendData = {
  1261. name: 'config_groups.create',
  1262. data: {
  1263. 'group_name': newConfigGroupData.get('name'),
  1264. 'service_id': newConfigGroupData.get('service.id'),
  1265. 'description': newConfigGroupData.get('description'),
  1266. 'hosts': dataHosts
  1267. },
  1268. success: 'successFunction',
  1269. error: 'errorFunction',
  1270. successFunction: function (response) {
  1271. newConfigGroupData.set('id', response.resources[0].ConfigGroup.id);
  1272. if (callback) {
  1273. callback();
  1274. }
  1275. },
  1276. errorFunction: function (xhr, text, errorThrown) {
  1277. if (callback) {
  1278. callback(xhr, text, errorThrown);
  1279. }
  1280. console.error('Error in creating new Config Group');
  1281. }
  1282. };
  1283. sendData.sender = sendData;
  1284. App.ajax.send(sendData);
  1285. return newConfigGroupData;
  1286. },
  1287. /**
  1288. * PUTs the new configuration-group on the server.
  1289. * Changes possible here are the name, description and
  1290. * host memberships of the configuration-group.
  1291. *
  1292. * @param {App.ConfigGroup} configGroup Configuration group to update
  1293. * @param {Function} successCallback
  1294. * @param {Function} errorCallback
  1295. */
  1296. updateConfigurationGroup: function (configGroup, successCallback, errorCallback) {
  1297. var putConfigGroup = {
  1298. ConfigGroup: {
  1299. group_name: configGroup.get('name'),
  1300. description: configGroup.get('description'),
  1301. tag: configGroup.get('service.id'),
  1302. hosts: [],
  1303. desired_configs: []
  1304. }
  1305. };
  1306. configGroup.get('hosts').forEach(function(h){
  1307. putConfigGroup.ConfigGroup.hosts.push({
  1308. host_name: h
  1309. });
  1310. });
  1311. configGroup.get('configSiteTags').forEach(function(cst){
  1312. putConfigGroup.ConfigGroup.desired_configs.push({
  1313. type: cst.get('site'),
  1314. tag: cst.get('tag')
  1315. });
  1316. });
  1317. var sendData = {
  1318. name: 'config_groups.update',
  1319. data: {
  1320. id: configGroup.get('id'),
  1321. data: putConfigGroup
  1322. },
  1323. success: 'successFunction',
  1324. error: 'errorFunction',
  1325. successFunction: function () {
  1326. if(successCallback) {
  1327. successCallback();
  1328. }
  1329. },
  1330. errorFunction: function (xhr, text, errorThrown) {
  1331. if(errorCallback) {
  1332. errorCallback(xhr, text, errorThrown);
  1333. }
  1334. }
  1335. };
  1336. sendData.sender = sendData;
  1337. App.ajax.send(sendData);
  1338. },
  1339. clearConfigurationGroupHosts: function (configGroup, successCallback, errorCallback) {
  1340. configGroup = jQuery.extend({}, configGroup);
  1341. configGroup.set('hosts', []);
  1342. this.updateConfigurationGroup(configGroup, successCallback, errorCallback);
  1343. },
  1344. deleteConfigGroup: function (configGroup, successCallback, errorCallback) {
  1345. var sendData = {
  1346. name: 'config_groups.delete_config_group',
  1347. sender: this,
  1348. data: {
  1349. id: configGroup.get('id')
  1350. },
  1351. success: 'successFunction',
  1352. error: 'errorFunction',
  1353. successFunction: function () {
  1354. if(successCallback) {
  1355. successCallback();
  1356. }
  1357. },
  1358. errorFunction: function (xhr, text, errorThrown) {
  1359. if(errorCallback) {
  1360. errorCallback(xhr, text, errorThrown);
  1361. }
  1362. }
  1363. };
  1364. sendData.sender = sendData;
  1365. App.ajax.send(sendData);
  1366. },
  1367. /**
  1368. * Gets all the configuration-groups for the given service.
  1369. *
  1370. * @param serviceId
  1371. * (string) ID of the service. Ex: HDFS
  1372. */
  1373. getConfigGroupsForService: function (serviceId) {
  1374. },
  1375. /**
  1376. * Gets all the configuration-groups for a host.
  1377. *
  1378. * @param hostName
  1379. * (string) host name used to register
  1380. */
  1381. getConfigGroupsForHost: function (hostName) {
  1382. }
  1383. });