config.js 52 KB

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