config.js 56 KB

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