config.js 48 KB

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