config.js 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302
  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. saveGroupConfirmationPopup: function(groupName,isInstaller) {
  950. App.ModalPopup.show({
  951. header: Em.I18n.t('config.group.save.confirmation.header'),
  952. secondary: Em.I18n.t('config.group.save.confirmation.manage.button'),
  953. groupName: groupName,
  954. bodyClass: Ember.View.extend({
  955. templateName: require('templates/common/configs/saveConfigGroup')
  956. }),
  957. onSecondary: function() {
  958. var controller = isInstaller ? App.router.get('wizardStep7Controller') : undefined;
  959. App.router.get('mainServiceInfoConfigsController').manageConfigurationGroups(controller);
  960. this.hide();
  961. }
  962. });
  963. },
  964. //Persist config groups created in step7 wizard controller
  965. persistWizardStep7ConfigGroups: function () {
  966. var installerController = App.router.get('installerController');
  967. var step7Controller = App.router.get('wizardStep7Controller');
  968. if (App.supports.hostOverridesInstaller) {
  969. installerController.saveServiceConfigGroups(step7Controller);
  970. App.clusterStatus.setClusterStatus({
  971. localdb: App.db.data
  972. });
  973. }
  974. },
  975. launchConfigGroupSelectionCreationDialog : function(serviceId, configGroups, usedConfigGroupNames, configProperty, callback, isInstaller) {
  976. var self = this;
  977. var availableConfigGroups = configGroups.slice();
  978. // delete Config Groups, that already have selected property overridden
  979. var alreadyOverriddenGroups = [];
  980. if (configProperty.get('overrides')) {
  981. alreadyOverriddenGroups = configProperty.get('overrides').mapProperty('group.name');
  982. }
  983. var result = [];
  984. availableConfigGroups.forEach(function (group) {
  985. if (!group.get('isDefault') && (!alreadyOverriddenGroups.length || !alreadyOverriddenGroups.contains(group.name))) {
  986. result.push(group);
  987. }
  988. }, this);
  989. availableConfigGroups = result;
  990. var selectedConfigGroup = availableConfigGroups && availableConfigGroups.length > 0 ?
  991. availableConfigGroups[0] : null;
  992. App.ModalPopup.show({
  993. classNames: [ 'sixty-percent-width-modal' ],
  994. header: Em.I18n.t('config.group.selection.dialog.title').format(App.Service.DisplayNames[serviceId]),
  995. primary: Em.I18n.t('ok'),
  996. secondary: Em.I18n.t('common.cancel'),
  997. warningMessage: null,
  998. optionSelectConfigGroup: true,
  999. optionCreateConfigGroup: function(){
  1000. return !this.get('optionSelectConfigGroup');
  1001. }.property('optionSelectConfigGroup'),
  1002. availableConfigGroups: availableConfigGroups,
  1003. selectedConfigGroup: selectedConfigGroup,
  1004. newConfigGroupName: '',
  1005. enablePrimary: function () {
  1006. return this.get('optionSelectConfigGroup') || (this.get('newConfigGroupName').trim().length > 0 && !this.get('warningMessage'));
  1007. }.property('newConfigGroupName', 'optionSelectConfigGroup', 'warningMessage'),
  1008. onPrimary: function () {
  1009. if (!this.get('enablePrimary')) {
  1010. return false;
  1011. }
  1012. if (this.get('optionSelectConfigGroup')) {
  1013. var selectedConfigGroup = this.get('selectedConfigGroup');
  1014. this.hide();
  1015. self.saveGroupConfirmationPopup(selectedConfigGroup,isInstaller);
  1016. callback(selectedConfigGroup);
  1017. } else {
  1018. var newConfigGroupName = this.get('newConfigGroupName').trim();
  1019. var newConfigGroup = self.createNewConfigurationGroup(serviceId, newConfigGroupName, isInstaller);
  1020. if (newConfigGroup) {
  1021. newConfigGroup.set('parentConfigGroup', configGroups.findProperty('isDefault'));
  1022. configGroups.pushObject(newConfigGroup);
  1023. if (isInstaller) {
  1024. self.persistWizardStep7ConfigGroups();
  1025. }
  1026. this.hide();
  1027. self.saveGroupConfirmationPopup(newConfigGroupName,isInstaller);
  1028. callback(newConfigGroup);
  1029. }
  1030. }
  1031. },
  1032. onSecondary: function () {
  1033. this.hide();
  1034. callback(null);
  1035. },
  1036. doSelectConfigGroup: function (event) {
  1037. var configGroup = event.context;
  1038. console.log(configGroup);
  1039. this.set('selectedConfigGroup', configGroup);
  1040. },
  1041. validate: function () {
  1042. var msg = null;
  1043. var optionSelect = this.get('optionSelectConfigGroup');
  1044. if (!optionSelect) {
  1045. var nn = this.get('newConfigGroupName');
  1046. if (nn && usedConfigGroupNames.concat(configGroups.mapProperty('name')).contains(nn)) {
  1047. msg = Em.I18n.t("config.group.selection.dialog.err.name.exists");
  1048. }
  1049. }
  1050. this.set('warningMessage', msg);
  1051. }.observes('newConfigGroupName', 'optionSelectConfigGroup'),
  1052. bodyClass: Ember.View.extend({
  1053. templateName: require('templates/common/configs/selectCreateConfigGroup'),
  1054. controllerBinding: 'App.router.mainServiceInfoConfigsController',
  1055. selectConfigGroupRadioButton: Ember.Checkbox.extend({
  1056. tagName: 'input',
  1057. attributeBindings: ['type', 'checked', 'disabled'],
  1058. checked: function () {
  1059. return this.get('parentView.parentView.optionSelectConfigGroup');
  1060. }.property('parentView.parentView.optionSelectConfigGroup'),
  1061. type: 'radio',
  1062. disabled: false,
  1063. click: function () {
  1064. this.set('parentView.parentView.optionSelectConfigGroup', true);
  1065. },
  1066. didInsertElement: function () {
  1067. if (!this.get('parentView.parentView.availableConfigGroups').length) {
  1068. this.set('disabled', true);
  1069. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1070. }
  1071. }
  1072. }),
  1073. createConfigGroupRadioButton: Ember.Checkbox.extend({
  1074. tagName: 'input',
  1075. attributeBindings: ['type', 'checked'],
  1076. checked: function () {
  1077. return !this.get('parentView.parentView.optionSelectConfigGroup');
  1078. }.property('parentView.parentView.optionSelectConfigGroup'),
  1079. type: 'radio',
  1080. click: function () {
  1081. this.set('parentView.parentView.optionSelectConfigGroup', false);
  1082. }
  1083. })
  1084. })
  1085. });
  1086. },
  1087. /**
  1088. * launch dialog where can be assigned another group to host
  1089. * @param selectedGroup
  1090. * @param configGroups
  1091. * @param hostName
  1092. * @param callback
  1093. */
  1094. launchSwitchConfigGroupOfHostDialog: function (selectedGroup, configGroups, hostName, callback) {
  1095. var self = this;
  1096. App.ModalPopup.show({
  1097. header: Em.I18n.t('config.group.host.switch.dialog.title'),
  1098. primary: Em.I18n.t('ok'),
  1099. secondary: Em.I18n.t('common.cancel'),
  1100. configGroups: configGroups,
  1101. selectedConfigGroup: selectedGroup,
  1102. enablePrimary: function () {
  1103. return this.get('selectedConfigGroup.name') !== selectedGroup.get('name');
  1104. }.property('selectedConfigGroup'),
  1105. onPrimary: function () {
  1106. if (this.get('enablePrimary')) {
  1107. var newGroup = this.get('selectedConfigGroup');
  1108. selectedGroup.get('hosts').removeObject(hostName);
  1109. if (!selectedGroup.get('isDefault')) {
  1110. self.updateConfigurationGroup(selectedGroup, function(){}, function(){});
  1111. }
  1112. newGroup.get('hosts').pushObject(hostName);
  1113. callback(newGroup);
  1114. if (!newGroup.get('isDefault')) {
  1115. self.updateConfigurationGroup(newGroup, function(){}, function(){});
  1116. }
  1117. this.hide();
  1118. }
  1119. },
  1120. bodyClass: Ember.View.extend({
  1121. template: Em.Handlebars.compile('{{t installer.controls.slaveComponentGroups}}&#58;&nbsp;' +
  1122. '{{view Em.Select contentBinding="view.parentView.configGroups" optionLabelPath="content.displayName" selectionBinding="view.parentView.selectedConfigGroup"}}')
  1123. })
  1124. });
  1125. },
  1126. /**
  1127. * Creates a new config-group for a service.
  1128. *
  1129. * @param serviceId Service for which this group has to be created
  1130. * @param configGroupName Name of the new config-group
  1131. * @return Returns the created config-group or error as
  1132. * { configGroup: {id:4}, error: {...}}
  1133. */
  1134. createNewConfigurationGroup: function (serviceId, configGroupName, isInstaller) {
  1135. var newConfigGroupData = App.ConfigGroup.create({
  1136. id: null,
  1137. name: configGroupName,
  1138. description: "New configuration group created on " + new Date().toDateString(),
  1139. isDefault: false,
  1140. parentConfigGroup: null,
  1141. service: App.Service.find().findProperty('serviceName', serviceId),
  1142. hosts: [],
  1143. configSiteTags: [],
  1144. properties: []
  1145. });
  1146. if (isInstaller) {
  1147. newConfigGroupData.set('service', Em.Object.create({id: serviceId}));
  1148. return newConfigGroupData;
  1149. }
  1150. var sendData = {
  1151. name: 'config_groups.create',
  1152. data: {
  1153. 'group_name': configGroupName,
  1154. 'service_id': serviceId,
  1155. 'description': newConfigGroupData.description
  1156. },
  1157. success: 'successFunction',
  1158. error: 'errorFunction',
  1159. successFunction: function (response) {
  1160. newConfigGroupData.id = response.resources[0].ConfigGroup.id;
  1161. },
  1162. errorFunction: function () {
  1163. newConfigGroupData = null;
  1164. console.error('Error in creating new Config Group');
  1165. }
  1166. };
  1167. sendData.sender = sendData;
  1168. App.ajax.send(sendData);
  1169. return newConfigGroupData;
  1170. },
  1171. /**
  1172. * PUTs the new configuration-group on the server.
  1173. * Changes possible here are the name, description and
  1174. * host memberships of the configuration-group.
  1175. *
  1176. * @param configGroup (App.ConfigGroup) Configuration group to update
  1177. */
  1178. updateConfigurationGroup: function (configGroup, successCallback, errorCallback) {
  1179. var putConfigGroup = {
  1180. ConfigGroup: {
  1181. group_name: configGroup.get('name'),
  1182. description: configGroup.get('description'),
  1183. tag: configGroup.get('service.serviceName'),
  1184. hosts: [],
  1185. desired_configs: []
  1186. }
  1187. };
  1188. configGroup.get('hosts').forEach(function(h){
  1189. putConfigGroup.ConfigGroup.hosts.push({
  1190. host_name: h
  1191. });
  1192. });
  1193. configGroup.get('configSiteTags').forEach(function(cst){
  1194. putConfigGroup.ConfigGroup.desired_configs.push({
  1195. type: cst.get('site'),
  1196. tag: cst.get('tag')
  1197. });
  1198. });
  1199. var sendData = {
  1200. name: 'config_groups.update',
  1201. data: {
  1202. id: configGroup.get('id'),
  1203. data: putConfigGroup
  1204. },
  1205. success: 'successFunction',
  1206. error: 'errorFunction',
  1207. successFunction: function () {
  1208. if(successCallback) {
  1209. successCallback();
  1210. }
  1211. },
  1212. errorFunction: function (xhr, text, errorThrown) {
  1213. error = xhr.status + "(" + errorThrown + ") ";
  1214. try {
  1215. var json = $.parseJSON(xhr.responseText);
  1216. error += json.message;
  1217. } catch (err) {
  1218. }
  1219. console.error('Error updating Config Group:', error, configGroup);
  1220. if(errorCallback) {
  1221. errorCallback(error);
  1222. }
  1223. }
  1224. };
  1225. sendData.sender = sendData;
  1226. App.ajax.send(sendData);
  1227. },
  1228. clearConfigurationGroupHosts: function (configGroup, successCallback, errorCallback) {
  1229. configGroup = jQuery.extend({}, configGroup);
  1230. configGroup.set('hosts', []);
  1231. this.updateConfigurationGroup(configGroup, successCallback, errorCallback);
  1232. },
  1233. /**
  1234. * Gets all the configuration-groups for the given service.
  1235. *
  1236. * @param serviceId
  1237. * (string) ID of the service. Ex: HDFS
  1238. * @return Array of App.ConfigGroups
  1239. */
  1240. getConfigGroupsForService: function (serviceId) {
  1241. },
  1242. /**
  1243. * Gets all the configuration-groups for a host.
  1244. *
  1245. * @param hostName
  1246. * (string) host name used to register
  1247. * @return Array of App.ConfigGroups
  1248. */
  1249. getConfigGroupsForHost: function (hostName) {
  1250. }
  1251. });