config.js 52 KB

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