config.js 58 KB

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