config.js 48 KB

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