config.js 60 KB

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