config.js 59 KB

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