config.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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.isRequiredByAgent === false) {
  246. continue;
  247. }
  248. if (configsPropertyDef) {
  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. configs.push(serviceConfigObj);
  266. } else {
  267. mappingConfigs.push(serviceConfigObj);
  268. }
  269. }
  270. }, this);
  271. return {
  272. configs: configs,
  273. globalConfigs: globalConfigs,
  274. mappingConfigs: mappingConfigs
  275. }
  276. },
  277. /**
  278. * @param serviceConfigObj : Object
  279. * @param configsPropertyDef : Object
  280. */
  281. setServiceConfigUiAttributes: function (serviceConfigObj, configsPropertyDef) {
  282. serviceConfigObj.displayType = configsPropertyDef.displayType;
  283. serviceConfigObj.isRequired = (configsPropertyDef.isRequired !== undefined) ? configsPropertyDef.isRequired : true;
  284. serviceConfigObj.isRequiredByAgent = (configsPropertyDef.isRequiredByAgent !== undefined) ? configsPropertyDef.isRequiredByAgent : true;
  285. serviceConfigObj.isReconfigurable = (configsPropertyDef.isReconfigurable !== undefined) ? configsPropertyDef.isReconfigurable : true;
  286. serviceConfigObj.isVisible = (configsPropertyDef.isVisible !== undefined) ? configsPropertyDef.isVisible : true;
  287. serviceConfigObj.unit = (configsPropertyDef.unit !== undefined) ? configsPropertyDef.unit : undefined;
  288. serviceConfigObj.description = (configsPropertyDef.description !== undefined) ? configsPropertyDef.description : undefined;
  289. serviceConfigObj.isOverridable = configsPropertyDef.isOverridable === undefined ? true : configsPropertyDef.isOverridable;
  290. serviceConfigObj.serviceName = configsPropertyDef ? configsPropertyDef.serviceName : null;
  291. serviceConfigObj.index = configsPropertyDef.index;
  292. serviceConfigObj.isSecureConfig = configsPropertyDef.isSecureConfig === undefined ? false : configsPropertyDef.isSecureConfig;
  293. serviceConfigObj.belongsToService = configsPropertyDef.belongsToService;
  294. serviceConfigObj.category = configsPropertyDef.category;
  295. },
  296. /**
  297. * synchronize order of config properties with order, that on UI side
  298. * @param configSet
  299. * @return {Object}
  300. */
  301. syncOrderWithPredefined: function (configSet) {
  302. var globalConfigs = configSet.globalConfigs,
  303. siteConfigs = configSet.configs,
  304. globalStart = [],
  305. siteStart = [];
  306. this.get('preDefinedGlobalProperties').mapProperty('name').forEach(function (name) {
  307. var _global = globalConfigs.findProperty('name', name);
  308. if (_global) {
  309. globalStart.push(_global);
  310. globalConfigs = globalConfigs.without(_global);
  311. }
  312. }, this);
  313. this.get('preDefinedSiteProperties').mapProperty('name').forEach(function (name) {
  314. var _site = siteConfigs.findProperty('name', name);
  315. if (_site) {
  316. siteStart.push(_site);
  317. siteConfigs = siteConfigs.without(_site);
  318. }
  319. }, this);
  320. var alphabeticalSort = function (a, b) {
  321. if (a.name < b.name) return -1;
  322. if (a.name > b.name) return 1;
  323. return 0;
  324. }
  325. return {
  326. globalConfigs: globalStart.concat(globalConfigs.sort(alphabeticalSort)),
  327. configs: siteStart.concat(siteConfigs.sort(alphabeticalSort)),
  328. mappingConfigs: configSet.mappingConfigs
  329. }
  330. },
  331. /**
  332. * merge stored configs with pre-defined
  333. * @param storedConfigs
  334. * @param advancedConfigs
  335. * @return {*}
  336. */
  337. mergePreDefinedWithStored: function (storedConfigs, advancedConfigs) {
  338. var mergedConfigs = [];
  339. var preDefinedConfigs = $.extend(true, [], this.get('preDefinedGlobalProperties').concat(this.get('preDefinedSiteProperties')));
  340. var preDefinedNames = [];
  341. var storedNames = [];
  342. var names = [];
  343. var categoryMetaData = null;
  344. storedConfigs = (storedConfigs) ? storedConfigs : [];
  345. preDefinedNames = preDefinedConfigs.mapProperty('name');
  346. storedNames = storedConfigs.mapProperty('name');
  347. names = preDefinedNames.concat(storedNames).uniq();
  348. names.forEach(function (name) {
  349. var stored = storedConfigs.findProperty('name', name);
  350. var preDefined = preDefinedConfigs.findProperty('name', name);
  351. var configData = {};
  352. var isAdvanced = advancedConfigs.someProperty('name', name);
  353. if (preDefined && stored) {
  354. configData = preDefined;
  355. configData.value = stored.value;
  356. configData.defaultValue = stored.defaultValue;
  357. configData.overrides = stored.overrides;
  358. configData.filename = stored.filename;
  359. configData.description = stored.description;
  360. } else if (!preDefined && stored) {
  361. configData = {
  362. id: stored.id,
  363. name: stored.name,
  364. displayName: stored.name,
  365. serviceName: stored.serviceName,
  366. value: stored.value,
  367. defaultValue: stored.defaultValue,
  368. displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
  369. filename: stored.filename,
  370. category: 'Advanced',
  371. isUserProperty: stored.isUserProperty === true,
  372. isOverridable: true,
  373. overrides: stored.overrides,
  374. isRequired: true
  375. };
  376. this.calculateConfigProperties(configData, isAdvanced, advancedConfigs);
  377. } else if (preDefined && !stored) {
  378. configData = preDefined;
  379. if (isAdvanced) {
  380. var advanced = advancedConfigs.findProperty('name', configData.name);
  381. configData.value = configData.displayType == "password" ? '' : advanced.value;
  382. configData.defaultValue = advanced.value;
  383. configData.filename = advanced.filename;
  384. configData.description = advanced.description;
  385. }
  386. }
  387. mergedConfigs.push(configData);
  388. }, this);
  389. return mergedConfigs;
  390. },
  391. /**
  392. * look over advanced configs and add missing configs to serviceConfigs
  393. * filter fetched configs by service if passed
  394. * @param serviceConfigs
  395. * @param advancedConfigs
  396. * @param serviceName
  397. */
  398. addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
  399. var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs;
  400. advancedConfigs.forEach(function (_config) {
  401. var configCategory = 'Advanced';
  402. var categoryMetaData = null;
  403. if (_config) {
  404. if (this.get('configMapping').computed().someProperty('name', _config.name)) {
  405. } else if (!(configsToVerifying.someProperty('name', _config.name))) {
  406. if (this.get('customFileNames').contains(_config.filename)) {
  407. categoryMetaData = this.identifyCategory(_config);
  408. if (categoryMetaData != null) {
  409. configCategory = categoryMetaData.get('name');
  410. }
  411. }
  412. _config.id = "site property";
  413. _config.category = configCategory;
  414. _config.displayName = _config.name;
  415. _config.defaultValue = _config.value;
  416. // make all advanced configs optional and populated by default
  417. /*
  418. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  419. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  420. * false; _config.value = ''; } else if
  421. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  422. */
  423. _config.isRequired = true;
  424. _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
  425. serviceConfigs.push(_config);
  426. }
  427. }
  428. }, this);
  429. },
  430. /**
  431. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  432. */
  433. addCustomConfigs: function (configs) {
  434. var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
  435. var stored = configs.filter(function (_config) {
  436. return this.get('categoriesWithCustom').contains(_config.category);
  437. }, this);
  438. if (App.supports.capacitySchedulerUi) {
  439. var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
  440. if (queueProperties.length) {
  441. queueProperties.setEach('isQueue', true);
  442. }
  443. }
  444. },
  445. miscConfigVisibleProperty: function (configs, serviceToShow) {
  446. configs.forEach(function (item) {
  447. item.set("isVisible", item.belongsToService.some(function (cur) {
  448. return serviceToShow.contains(cur)
  449. }));
  450. });
  451. return configs;
  452. },
  453. /**
  454. * render configs, distribute them by service
  455. * and wrap each in ServiceConfigProperty object
  456. * @param configs
  457. * @param storedConfigs
  458. * @param allInstalledServiceNames
  459. * @param selectedServiceNames
  460. * @param localDB
  461. * @return {Array}
  462. */
  463. renderConfigs: function (configs, storedConfigs, allInstalledServiceNames, selectedServiceNames, localDB) {
  464. var renderedServiceConfigs = [];
  465. var services = [];
  466. this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  467. if (allInstalledServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  468. console.log('pushing ' + serviceConfig.serviceName, serviceConfig);
  469. if (selectedServiceNames.contains(serviceConfig.serviceName) || serviceConfig.serviceName === 'MISC') {
  470. serviceConfig.showConfig = true;
  471. }
  472. services.push(serviceConfig);
  473. }
  474. });
  475. services.forEach(function (service) {
  476. var serviceConfig = {};
  477. var configsByService = [];
  478. var serviceConfigs = configs.filterProperty('serviceName', service.serviceName);
  479. serviceConfigs.forEach(function (_config) {
  480. var serviceConfigProperty = {};
  481. _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
  482. serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  483. this.updateHostOverrides(serviceConfigProperty, _config);
  484. if (!storedConfigs) {
  485. serviceConfigProperty.initialValue(localDB);
  486. }
  487. this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
  488. serviceConfigProperty.validate();
  489. configsByService.pushObject(serviceConfigProperty);
  490. }, this);
  491. serviceConfig = this.createServiceConfig(service.serviceName);
  492. serviceConfig.set('showConfig', service.showConfig);
  493. // Use calculated default values for some configs
  494. var recommendedDefaults = {};
  495. if (!storedConfigs && service.defaultsProviders) {
  496. service.defaultsProviders.forEach(function (defaultsProvider) {
  497. var defaults = defaultsProvider.getDefaults(localDB);
  498. for (var name in defaults) {
  499. recommendedDefaults[name] = defaults[name];
  500. var config = configsByService.findProperty('name', name);
  501. if (config) {
  502. config.set('value', defaults[name]);
  503. config.set('defaultValue', defaults[name]);
  504. }
  505. }
  506. });
  507. }
  508. if (service.configsValidator) {
  509. service.configsValidator.set('recommendedDefaults', recommendedDefaults);
  510. var validators = service.configsValidator.get('configValidators');
  511. for (var validatorName in validators) {
  512. var c = configsByService.findProperty('name', validatorName);
  513. if (c) {
  514. c.set('serviceValidator', service.configsValidator);
  515. }
  516. }
  517. }
  518. serviceConfig.set('configs', configsByService);
  519. renderedServiceConfigs.push(serviceConfig);
  520. }, this);
  521. return renderedServiceConfigs;
  522. },
  523. /**
  524. Takes care of the "dynamic defaults" for the HCFS configs. Sets
  525. some of the config defaults to previously user-entered data.
  526. **/
  527. tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
  528. console.log("Step7: Tweaking Dynamic defaults");
  529. var firstHost = null;
  530. for (var host in localDB.hosts) {
  531. firstHost = host;
  532. break;
  533. }
  534. try {
  535. if (typeof(config == "string") && config.defaultValue.indexOf("{firstHost}") >= 0) {
  536. serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
  537. serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
  538. }
  539. } catch (err) {
  540. // Nothing to worry about here, most likely trying indexOf on a non-string
  541. }
  542. },
  543. /**
  544. * create new child configs from overrides, attach them to parent config
  545. * override - value of config, related to particular host(s)
  546. * @param configProperty
  547. * @param storedConfigProperty
  548. */
  549. updateHostOverrides: function (configProperty, storedConfigProperty) {
  550. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  551. var overrides = [];
  552. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  553. // create new override with new value
  554. var newSCP = App.ServiceConfigProperty.create(configProperty);
  555. newSCP.set('value', overrideEntry.value);
  556. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  557. newSCP.set('parentSCP', configProperty);
  558. var hostsArray = Ember.A([]);
  559. overrideEntry.hosts.forEach(function (host) {
  560. hostsArray.push(host);
  561. });
  562. newSCP.set('selectedHostOptions', hostsArray);
  563. overrides.pushObject(newSCP);
  564. });
  565. configProperty.set('overrides', overrides);
  566. }
  567. },
  568. /**
  569. * create new ServiceConfig object by service name
  570. * @param serviceName
  571. */
  572. createServiceConfig: function (serviceName) {
  573. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  574. var serviceConfig = App.ServiceConfig.create({
  575. filename: preDefinedServiceConfig.filename,
  576. serviceName: preDefinedServiceConfig.serviceName,
  577. displayName: preDefinedServiceConfig.displayName,
  578. configCategories: preDefinedServiceConfig.configCategories,
  579. configs: [],
  580. configGroups: []
  581. });
  582. serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
  583. switch (category.name) {
  584. case 'CapacityScheduler':
  585. if (App.supports.capacitySchedulerUi) {
  586. category.set('customView', App.ServiceConfigCapacityScheduler);
  587. } else {
  588. category.set('isCustomView', false);
  589. }
  590. break;
  591. }
  592. }, this);
  593. return serviceConfig;
  594. },
  595. /**
  596. * GETs all cluster level sites in one call.
  597. *
  598. * @return Array of all site configs
  599. */
  600. loadConfigsByTags: function (tags) {
  601. var urlParams = [];
  602. tags.forEach(function (_tag) {
  603. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  604. });
  605. var params = urlParams.join('|');
  606. App.ajax.send({
  607. name: 'config.on_site',
  608. sender: this,
  609. data: {
  610. params: params
  611. },
  612. success: 'loadConfigsByTagsSuccess'
  613. });
  614. return configGroupsByTag;
  615. },
  616. loadConfigsByTagsSuccess: function (data) {
  617. if (data.items) {
  618. configGroupsByTag = [];
  619. data.items.forEach(function (item) {
  620. this.loadedConfigurationsCache[item.type + "_" + item.tag] = item.properties;
  621. configGroupsByTag.push(item);
  622. }, this);
  623. }
  624. },
  625. /**
  626. * Generate serviceProperties save it to localDB
  627. * called form stepController step6WizardController
  628. *
  629. * @param serviceName
  630. * @return {*}
  631. */
  632. loadAdvancedConfig: function (serviceName) {
  633. App.ajax.send({
  634. name: 'config.advanced',
  635. sender: this,
  636. data: {
  637. serviceName: serviceName,
  638. stack2VersionUrl: App.get('stack2VersionURL'),
  639. stackVersion: App.get('currentStackVersionNumber')
  640. },
  641. success: 'loadAdvancedConfigSuccess'
  642. });
  643. return serviceComponents[serviceName];
  644. //TODO clean serviceComponents
  645. },
  646. loadAdvancedConfigSuccess: function (data, opt, params) {
  647. console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
  648. var properties = [];
  649. if (data.items.length) {
  650. data.items.forEach(function (item) {
  651. item = item.StackConfigurations;
  652. item.isVisible = item.type !== 'global.xml';
  653. properties.push({
  654. serviceName: item.service_name,
  655. name: item.property_name,
  656. value: item.property_value,
  657. description: item.property_description,
  658. isVisible: item.isVisible,
  659. filename: item.filename || item.type
  660. });
  661. }, this);
  662. serviceComponents[data.items[0].StackConfigurations.service_name] = properties;
  663. }
  664. },
  665. /**
  666. * Determine the map which shows which services
  667. * each global property effects.
  668. *
  669. * @return {*}
  670. * Example:
  671. * {
  672. * 'hive_pid_dir': ['HIVE'],
  673. * ...
  674. * }
  675. */
  676. loadGlobalPropertyToServicesMap: function () {
  677. if (globalPropertyToServicesMap == null) {
  678. App.ajax.send({
  679. name: 'config.advanced.global',
  680. sender: this,
  681. data: {
  682. stack2VersionUrl: App.get('stack2VersionURL')
  683. },
  684. success: 'loadGlobalPropertyToServicesMapSuccess'
  685. });
  686. }
  687. return globalPropertyToServicesMap;
  688. },
  689. loadGlobalPropertyToServicesMapSuccess: function (data) {
  690. globalPropertyToServicesMap = {};
  691. if (data.items != null) {
  692. data.items.forEach(function (service) {
  693. service.configurations.forEach(function (config) {
  694. if ("global.xml" === config.StackConfigurations.type) {
  695. if (!(config.StackConfigurations.property_name in globalPropertyToServicesMap)) {
  696. globalPropertyToServicesMap[config.StackConfigurations.property_name] = [];
  697. }
  698. globalPropertyToServicesMap[config.StackConfigurations.property_name].push(service.StackServices.service_name);
  699. }
  700. });
  701. });
  702. }
  703. },
  704. /**
  705. * Hosts can override service configurations per property. This method GETs
  706. * the overriden configurations and sets only the changed properties into
  707. * the 'overrides' of serviceConfig.
  708. *
  709. *
  710. */
  711. loadServiceConfigHostsOverrides: function (serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups) {
  712. var configKeyToConfigMap = {};
  713. serviceConfigs.forEach(function (item) {
  714. configKeyToConfigMap[item.name] = item;
  715. });
  716. var typeTagToGroupMap = {};
  717. var urlParams = [];
  718. for (var group in loadedGroupToOverrideSiteToTagMap) {
  719. var overrideTypeTags = loadedGroupToOverrideSiteToTagMap[group];
  720. for (var type in overrideTypeTags) {
  721. var tag = overrideTypeTags[type];
  722. typeTagToGroupMap[type + "///" + tag] = configGroups.findProperty('name', group);
  723. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  724. }
  725. }
  726. var params = urlParams.join('|');
  727. if (urlParams.length) {
  728. App.ajax.send({
  729. name: 'config.host_overrides',
  730. sender: this,
  731. data: {
  732. params: params,
  733. configKeyToConfigMap: configKeyToConfigMap,
  734. typeTagToGroupMap: typeTagToGroupMap
  735. },
  736. success: 'loadServiceConfigHostsOverridesSuccess'
  737. });
  738. }
  739. },
  740. loadServiceConfigHostsOverridesSuccess: function (data, opt, params) {
  741. console.debug("loadServiceConfigHostsOverrides: Data=", data);
  742. data.items.forEach(function (config) {
  743. App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
  744. var group = params.typeTagToGroupMap[config.type + "///" + config.tag];
  745. var properties = config.properties;
  746. for (var prop in properties) {
  747. var serviceConfig = params.configKeyToConfigMap[prop];
  748. var hostOverrideValue = properties[prop];
  749. if (serviceConfig && serviceConfig.displayType === 'int') {
  750. if (/\d+m$/.test(hostOverrideValue)) {
  751. hostOverrideValue = hostOverrideValue.slice(0, hostOverrideValue.length - 1);
  752. }
  753. } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
  754. switch (hostOverrideValue) {
  755. case 'true':
  756. hostOverrideValue = true;
  757. break;
  758. case 'false':
  759. hostOverrideValue = false;
  760. break;
  761. }
  762. }
  763. if (serviceConfig) {
  764. // Value of this property is different for this host.
  765. var overrides = 'overrides';
  766. if (!(overrides in serviceConfig)) {
  767. serviceConfig.overrides = [];
  768. }
  769. console.log("loadServiceConfigHostsOverrides(): [" + group + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
  770. serviceConfig.overrides.push({value: hostOverrideValue, group: group});
  771. }
  772. }
  773. });
  774. console.log("loadServiceConfigHostsOverrides(): Finished loading.");
  775. },
  776. /**
  777. * Set all site property that are derived from other site-properties
  778. */
  779. setConfigValue: function (mappedConfigs, allConfigs, config, globalConfigs) {
  780. var globalValue;
  781. if (config.value == null) {
  782. return;
  783. }
  784. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  785. var fkName = config.name.match(/<(foreignKey.*?)>/g);
  786. var templateValue = config.value.match(/<(templateName.*?)>/g);
  787. if (fkValue) {
  788. fkValue.forEach(function (_fkValue) {
  789. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  790. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  791. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  792. config.value = config.value.replace(_fkValue, globalValue);
  793. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  794. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  795. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  796. } else {
  797. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  798. }
  799. config.value = config.value.replace(_fkValue, globalValue);
  800. }
  801. }, this);
  802. }
  803. // config._name - formatted name from original config name
  804. if (fkName) {
  805. fkName.forEach(function (_fkName) {
  806. var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
  807. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  808. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  809. config._name = config.name.replace(_fkName, 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._name = config.name.replace(_fkName, globalValue);
  817. }
  818. }, this);
  819. }
  820. //For properties in the configMapping file having foreignKey and templateName properties.
  821. if (templateValue) {
  822. templateValue.forEach(function (_value) {
  823. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  824. if (globalConfigs.someProperty('name', config.templateName[index])) {
  825. var globalValue = globalConfigs.findProperty('name', config.templateName[index]).value;
  826. config.value = config.value.replace(_value, globalValue);
  827. } else {
  828. config.value = null;
  829. }
  830. }, this);
  831. }
  832. },
  833. complexConfigs: [
  834. {
  835. "id": "site property",
  836. "name": "capacity-scheduler",
  837. "displayName": "Capacity Scheduler",
  838. "value": "",
  839. "defaultValue": "",
  840. "description": "Capacity Scheduler properties",
  841. "displayType": "custom",
  842. "isOverridable": true,
  843. "isRequired": true,
  844. "isVisible": true,
  845. "serviceName": "YARN",
  846. "filename": "capacity-scheduler.xml",
  847. "category": "CapacityScheduler"
  848. }
  849. ],
  850. /**
  851. * transform set of configs from file
  852. * into one config with textarea content:
  853. * name=value
  854. * @param configs
  855. * @param filename
  856. * @return {*}
  857. */
  858. fileConfigsIntoTextarea: function (configs, filename) {
  859. var fileConfigs = configs.filterProperty('filename', filename);
  860. var value = '';
  861. var defaultValue = '';
  862. var complexConfig = this.get('complexConfigs').findProperty('filename', filename);
  863. if (complexConfig) {
  864. fileConfigs.forEach(function (_config) {
  865. value += _config.name + '=' + _config.value + '\n';
  866. defaultValue += _config.name + '=' + _config.defaultValue + '\n';
  867. }, this);
  868. complexConfig.value = value;
  869. complexConfig.defaultValue = defaultValue;
  870. configs = configs.filter(function (_config) {
  871. return _config.filename !== filename;
  872. });
  873. configs.push(complexConfig);
  874. }
  875. return configs;
  876. },
  877. /**
  878. * transform one config with textarea content
  879. * into set of configs of file
  880. * @param configs
  881. * @param filename
  882. * @return {*}
  883. */
  884. textareaIntoFileConfigs: function (configs, filename) {
  885. var complexConfigName = this.get('complexConfigs').findProperty('filename', filename).name;
  886. var configsTextarea = configs.findProperty('name', complexConfigName);
  887. if (configsTextarea) {
  888. var properties = configsTextarea.get('value').replace(/( |\n)+/g, '\n').split('\n');
  889. properties.forEach(function (_property) {
  890. var name, value;
  891. if (_property) {
  892. _property = _property.split('=');
  893. name = _property[0];
  894. value = (_property[1]) ? _property[1] : "";
  895. configs.push(Em.Object.create({
  896. id: configsTextarea.get('id'),
  897. name: name,
  898. value: value,
  899. defaultValue: value,
  900. serviceName: configsTextarea.get('serviceName'),
  901. filename: filename
  902. }));
  903. }
  904. });
  905. return configs.without(configsTextarea);
  906. }
  907. console.log('ERROR: textarea config - ' + complexConfigName + ' is missing');
  908. return configs;
  909. },
  910. /**
  911. * trim trailing spaces for all properties.
  912. * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
  913. * for directory or directories displayType format string for further using.
  914. * for password and values with spaces only do nothing.
  915. * @param property
  916. * @returns {*}
  917. */
  918. trimProperty: function (property, isEmberObject) {
  919. var displayType = (isEmberObject) ? property.get('displayType') : property.displayType;
  920. var value = (isEmberObject) ? property.get('value') : property.value;
  921. var name = (isEmberObject) ? property.get('name') : property.name;
  922. var rez;
  923. switch (displayType) {
  924. case 'directories':
  925. case 'directory':
  926. rez = value.trim().split(/\s+/g).join(',');
  927. break;
  928. case 'host':
  929. rez = value.trim();
  930. break;
  931. case 'password':
  932. break;
  933. case 'advanced':
  934. if (name == 'javax.jdo.option.ConnectionURL' || name == 'oozie.service.JPAService.jdbc.url') {
  935. rez = value.trim();
  936. }
  937. default:
  938. rez = (typeof value == 'string') ? value.replace(/(\s+$)/g, '') : value;
  939. }
  940. return ((rez == '') || (rez == undefined)) ? value : rez;
  941. },
  942. OnNnHAHideSnn: function (ServiceConfig) {
  943. var configCategories = ServiceConfig.get('configCategories');
  944. var snCategory = configCategories.findProperty('name', 'SNameNode');
  945. var activeNn = App.HDFSService.find('HDFS').get('activeNameNode.hostName');
  946. if (snCategory && activeNn) {
  947. configCategories.removeObject(snCategory);
  948. }
  949. },
  950. /**
  951. * Launches a dialog where an existing config-group can be selected, or a new
  952. * one can be created. This is different than the config-group management
  953. * dialog where host membership can be managed.
  954. *
  955. * The callback will be passed the created/selected config-group in the form
  956. * of {id:2, name:'New hardware group'}. In the case of dialog being cancelled,
  957. * the callback is provided <code>null</code>
  958. *
  959. * @param callback Callback function which is invoked when dialog
  960. * is closed, cancelled or OK is pressed.
  961. */
  962. saveGroupConfirmationPopup: function(groupName,isInstaller) {
  963. App.ModalPopup.show({
  964. header: Em.I18n.t('config.group.save.confirmation.header'),
  965. secondary: Em.I18n.t('config.group.save.confirmation.manage.button'),
  966. groupName: groupName,
  967. bodyClass: Ember.View.extend({
  968. templateName: require('templates/common/configs/saveConfigGroup')
  969. }),
  970. onSecondary: function() {
  971. var controller = isInstaller ? App.router.get('wizardStep7Controller') : undefined;
  972. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(controller);
  973. this.hide();
  974. }
  975. });
  976. },
  977. //Persist config groups created in step7 wizard controller
  978. persistWizardStep7ConfigGroups: function () {
  979. var installerController = App.router.get('installerController');
  980. var step7Controller = App.router.get('wizardStep7Controller');
  981. if (App.supports.hostOverridesInstaller) {
  982. installerController.saveServiceConfigGroups(step7Controller);
  983. App.clusterStatus.setClusterStatus({
  984. localdb: App.db.data
  985. });
  986. }
  987. },
  988. launchConfigGroupSelectionCreationDialog : function(serviceId, configGroups, configProperty, callback, isInstaller) {
  989. var self = this;
  990. var availableConfigGroups = configGroups.slice();
  991. // delete Config Groups, that already have selected property overridden
  992. var alreadyOverriddenGroups = [];
  993. if (configProperty.get('overrides')) {
  994. alreadyOverriddenGroups = configProperty.get('overrides').mapProperty('group.name');
  995. }
  996. var result = [];
  997. availableConfigGroups.forEach(function (group) {
  998. if (!group.get('isDefault') && (!alreadyOverriddenGroups.length || !alreadyOverriddenGroups.contains(group.name))) {
  999. result.push(group);
  1000. }
  1001. }, this);
  1002. availableConfigGroups = result;
  1003. var selectedConfigGroup = availableConfigGroups && availableConfigGroups.length > 0 ?
  1004. availableConfigGroups[0] : null;
  1005. App.ModalPopup.show({
  1006. classNames: [ 'sixty-percent-width-modal' ],
  1007. header: Em.I18n.t('config.group.selection.dialog.title').format(App.Service.DisplayNames[serviceId]),
  1008. primary: Em.I18n.t('ok'),
  1009. secondary: Em.I18n.t('common.cancel'),
  1010. warningMessage: null,
  1011. optionSelectConfigGroup: true,
  1012. optionCreateConfigGroup: function(){
  1013. return !this.get('optionSelectConfigGroup');
  1014. }.property('optionSelectConfigGroup'),
  1015. availableConfigGroups: availableConfigGroups,
  1016. selectedConfigGroup: selectedConfigGroup,
  1017. newConfigGroupName: '',
  1018. enablePrimary: function () {
  1019. return this.get('optionSelectConfigGroup') || (this.get('newConfigGroupName').trim().length > 0 && !this.get('warningMessage'));
  1020. }.property('newConfigGroupName', 'optionSelectConfigGroup', 'warningMessage'),
  1021. onPrimary: function () {
  1022. if (!this.get('enablePrimary')) {
  1023. return false;
  1024. }
  1025. if (this.get('optionSelectConfigGroup')) {
  1026. var selectedConfigGroup = this.get('selectedConfigGroup');
  1027. this.hide();
  1028. callback(selectedConfigGroup);
  1029. } else {
  1030. var newConfigGroupName = this.get('newConfigGroupName').trim();
  1031. var newConfigGroup = self.createNewConfigurationGroup(serviceId, newConfigGroupName, isInstaller);
  1032. if (newConfigGroup) {
  1033. newConfigGroup.set('parentConfigGroup', configGroups.findProperty('isDefault'));
  1034. configGroups.pushObject(newConfigGroup);
  1035. if (isInstaller) {
  1036. self.persistWizardStep7ConfigGroups();
  1037. }
  1038. this.hide();
  1039. self.saveGroupConfirmationPopup(newConfigGroupName,isInstaller);
  1040. callback(newConfigGroup);
  1041. }
  1042. }
  1043. },
  1044. onSecondary: function () {
  1045. this.hide();
  1046. callback(null);
  1047. },
  1048. doSelectConfigGroup: function (event) {
  1049. var configGroup = event.context;
  1050. console.log(configGroup);
  1051. this.set('selectedConfigGroup', configGroup);
  1052. },
  1053. validate: function () {
  1054. var msg = null;
  1055. var optionSelect = this.get('optionSelectConfigGroup');
  1056. if (!optionSelect) {
  1057. var nn = this.get('newConfigGroupName');
  1058. if (nn && configGroups.mapProperty('name').contains(nn)) {
  1059. msg = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  1060. }
  1061. }
  1062. this.set('warningMessage', msg);
  1063. }.observes('newConfigGroupName', 'optionSelectConfigGroup'),
  1064. bodyClass: Ember.View.extend({
  1065. templateName: require('templates/common/configs/selectCreateConfigGroup'),
  1066. controllerBinding: 'App.router.mainServiceInfoConfigsController',
  1067. selectConfigGroupRadioButton: Ember.Checkbox.extend({
  1068. tagName: 'input',
  1069. attributeBindings: ['type', 'checked', 'disabled'],
  1070. checked: function () {
  1071. return this.get('parentView.parentView.optionSelectConfigGroup');
  1072. }.property('parentView.parentView.optionSelectConfigGroup'),
  1073. type: 'radio',
  1074. disabled: false,
  1075. click: function () {
  1076. this.set('parentView.parentView.optionSelectConfigGroup', true);
  1077. },
  1078. didInsertElement: function () {
  1079. if (!this.get('parentView.parentView.availableConfigGroups').length) {
  1080. this.set('disabled', true);
  1081. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1082. }
  1083. }
  1084. }),
  1085. createConfigGroupRadioButton: Ember.Checkbox.extend({
  1086. tagName: 'input',
  1087. attributeBindings: ['type', 'checked'],
  1088. checked: function () {
  1089. return !this.get('parentView.parentView.optionSelectConfigGroup');
  1090. }.property('parentView.parentView.optionSelectConfigGroup'),
  1091. type: 'radio',
  1092. click: function () {
  1093. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1094. }
  1095. })
  1096. })
  1097. });
  1098. },
  1099. /**
  1100. * launch dialog where can be assigned another group to host
  1101. * @param selectedGroup
  1102. * @param configGroups
  1103. * @param hostName
  1104. * @param callback
  1105. */
  1106. launchSwitchConfigGroupOfHostDialog: function (selectedGroup, configGroups, hostName, callback) {
  1107. var self = this;
  1108. App.ModalPopup.show({
  1109. header: Em.I18n.t('config.group.host.switch.dialog.title'),
  1110. primary: Em.I18n.t('ok'),
  1111. secondary: Em.I18n.t('common.cancel'),
  1112. configGroups: configGroups,
  1113. selectedConfigGroup: selectedGroup,
  1114. enablePrimary: function () {
  1115. return this.get('selectedConfigGroup.name') !== selectedGroup.get('name');
  1116. }.property('selectedConfigGroup'),
  1117. onPrimary: function () {
  1118. if (this.get('enablePrimary')) {
  1119. var newGroup = this.get('selectedConfigGroup');
  1120. selectedGroup.get('hosts').removeObject(hostName);
  1121. if (!selectedGroup.get('isDefault')) {
  1122. self.updateConfigurationGroup(selectedGroup, function(){}, function(){});
  1123. }
  1124. newGroup.get('hosts').pushObject(hostName);
  1125. callback(newGroup);
  1126. if (!newGroup.get('isDefault')) {
  1127. self.updateConfigurationGroup(newGroup, function(){}, function(){});
  1128. }
  1129. this.hide();
  1130. }
  1131. },
  1132. bodyClass: Ember.View.extend({
  1133. template: Em.Handlebars.compile('{{t installer.controls.slaveComponentGroups}}&#58;&nbsp;' +
  1134. '{{view Em.Select contentBinding="view.parentView.configGroups" optionLabelPath="content.displayName" selectionBinding="view.parentView.selectedConfigGroup"}}')
  1135. })
  1136. });
  1137. },
  1138. /**
  1139. * Creates a new config-group for a service.
  1140. *
  1141. * @param serviceId Service for which this group has to be created
  1142. * @param configGroupName Name of the new config-group
  1143. * @return Returns the created config-group or error as
  1144. * { configGroup: {id:4}, error: {...}}
  1145. */
  1146. createNewConfigurationGroup: function (serviceId, configGroupName, isInstaller) {
  1147. var newConfigGroupData = App.ConfigGroup.create({
  1148. id: null,
  1149. name: configGroupName,
  1150. description: "New configuration group created on " + new Date().toDateString(),
  1151. isDefault: false,
  1152. parentConfigGroup: null,
  1153. service: App.Service.find().findProperty('serviceName', serviceId),
  1154. hosts: [],
  1155. configSiteTags: [],
  1156. properties: []
  1157. });
  1158. if (isInstaller) {
  1159. newConfigGroupData.set('service', Em.Object.create({id: serviceId}));
  1160. return newConfigGroupData;
  1161. }
  1162. var sendData = {
  1163. name: 'config_groups.create',
  1164. data: {
  1165. 'group_name': configGroupName,
  1166. 'service_id': serviceId,
  1167. 'description': newConfigGroupData.description
  1168. },
  1169. success: 'successFunction',
  1170. error: 'errorFunction',
  1171. successFunction: function (response) {
  1172. newConfigGroupData.id = response.resources[0].ConfigGroup.id;
  1173. },
  1174. errorFunction: function () {
  1175. newConfigGroupData = null;
  1176. console.error('Error in creating new Config Group');
  1177. }
  1178. };
  1179. sendData.sender = sendData;
  1180. App.ajax.send(sendData);
  1181. return newConfigGroupData;
  1182. },
  1183. /**
  1184. * PUTs the new configuration-group on the server.
  1185. * Changes possible here are the name, description and
  1186. * host memberships of the configuration-group.
  1187. *
  1188. * @param configGroup (App.ConfigGroup) Configuration group to update
  1189. */
  1190. updateConfigurationGroup: function (configGroup, successCallback, errorCallback) {
  1191. var putConfigGroup = {
  1192. ConfigGroup: {
  1193. group_name: configGroup.get('name'),
  1194. description: configGroup.get('description'),
  1195. tag: configGroup.get('service.serviceName'),
  1196. hosts: [],
  1197. desired_configs: []
  1198. }
  1199. };
  1200. configGroup.get('hosts').forEach(function(h){
  1201. putConfigGroup.ConfigGroup.hosts.push({
  1202. host_name: h
  1203. });
  1204. });
  1205. configGroup.get('configSiteTags').forEach(function(cst){
  1206. putConfigGroup.ConfigGroup.desired_configs.push({
  1207. type: cst.get('site'),
  1208. tag: cst.get('tag')
  1209. });
  1210. });
  1211. var sendData = {
  1212. name: 'config_groups.update',
  1213. data: {
  1214. id: configGroup.get('id'),
  1215. data: putConfigGroup
  1216. },
  1217. success: 'successFunction',
  1218. error: 'errorFunction',
  1219. successFunction: function () {
  1220. if(successCallback) {
  1221. successCallback();
  1222. }
  1223. },
  1224. errorFunction: function (xhr, text, errorThrown) {
  1225. error = xhr.status + "(" + errorThrown + ") ";
  1226. try {
  1227. var json = $.parseJSON(xhr.responseText);
  1228. error += json.message;
  1229. } catch (err) {
  1230. }
  1231. console.error('Error updating Config Group:', error, configGroup);
  1232. if(errorCallback) {
  1233. errorCallback(error);
  1234. }
  1235. }
  1236. };
  1237. sendData.sender = sendData;
  1238. App.ajax.send(sendData);
  1239. },
  1240. clearConfigurationGroupHosts: function (configGroup, successCallback, errorCallback) {
  1241. configGroup = jQuery.extend({}, configGroup);
  1242. configGroup.set('hosts', []);
  1243. this.updateConfigurationGroup(configGroup, successCallback, errorCallback);
  1244. },
  1245. /**
  1246. * Gets all the configuration-groups for the given service.
  1247. *
  1248. * @param serviceId
  1249. * (string) ID of the service. Ex: HDFS
  1250. * @return Array of App.ConfigGroups
  1251. */
  1252. getConfigGroupsForService: function (serviceId) {
  1253. },
  1254. /**
  1255. * Gets all the configuration-groups for a host.
  1256. *
  1257. * @param hostName
  1258. * (string) host name used to register
  1259. * @return Array of App.ConfigGroups
  1260. */
  1261. getConfigGroupsForHost: function (hostName) {
  1262. }
  1263. });