config.js 55 KB

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