config.js 57 KB

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