config.js 57 KB

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