config.js 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551
  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. createContentProperties: 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') || type.endsWith('-env')) {
  125. var property = {
  126. "id": "site property",
  127. "name": "content",
  128. "displayName": "content",
  129. "value": "",
  130. "defaultValue": "",
  131. "description": type + " 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. if (App.get('isHadoop2Stack')) {
  242. return function (_config) {
  243. return (yarnRegex.test(_config.name));
  244. }
  245. } else {
  246. return function (_config) {
  247. return (_config.name.indexOf('mapred.capacity-scheduler.queue.') !== -1) ||
  248. (/^mapred\.queue\.[a-z]([\_\-a-z0-9]{0,50})\.(acl-administer-jobs|acl-submit-job)$/i.test(_config.name));
  249. }
  250. }
  251. }.property('App.isHadoop2Stack'),
  252. /**
  253. * return:
  254. * configs,
  255. * mappingConfigs
  256. *
  257. * @param configGroups
  258. * @param advancedConfigs
  259. * @param tags
  260. * @param serviceName
  261. * @return {object}
  262. */
  263. mergePreDefinedWithLoaded: function (configGroups, advancedConfigs, tags, serviceName) {
  264. var configs = [];
  265. var contentProperties = this.createContentProperties();
  266. var preDefinedConfigs = this.get('preDefinedSiteProperties').concat(contentProperties);
  267. var mappingConfigs = [];
  268. var filenameExceptions = this.get('filenameExceptions');
  269. var selectedServiceNames = App.Service.find().mapProperty('serviceName');
  270. tags.forEach(function (_tag) {
  271. var isAdvanced = null;
  272. var filename = (filenameExceptions.contains(_tag.siteName)) ? _tag.siteName : _tag.siteName + ".xml";
  273. var siteConfig = configGroups.filter(function (serviceConfigProperties) {
  274. return _tag.tagName === serviceConfigProperties.tag && _tag.siteName === serviceConfigProperties.type;
  275. });
  276. siteConfig = siteConfig[0] || {};
  277. var attributes = siteConfig['properties_attributes'] || {};
  278. var finalAttributes = attributes.final || {};
  279. var properties = siteConfig.properties || {};
  280. for (var index in properties) {
  281. var configsPropertyDef = preDefinedConfigs.filterProperty('name', index).findProperty('filename', filename);
  282. if (!configsPropertyDef) {
  283. preDefinedConfigs.filterProperty('name', index).forEach(function (_preDefinedConfig) {
  284. var isServiceInstalled = selectedServiceNames.contains(_preDefinedConfig.serviceName);
  285. if (isServiceInstalled || _preDefinedConfig.serviceName === 'MISC') {
  286. configsPropertyDef = _preDefinedConfig;
  287. }
  288. }, this);
  289. }
  290. var serviceConfigObj = App.ServiceConfig.create({
  291. name: index,
  292. value: properties[index],
  293. defaultValue: properties[index],
  294. filename: filename,
  295. isUserProperty: false,
  296. isOverridable: true,
  297. isRequired: true,
  298. isFinal: finalAttributes[index] === "true",
  299. showLabel: true,
  300. serviceName: serviceName,
  301. belongsToService: []
  302. });
  303. if (configsPropertyDef) {
  304. this.setServiceConfigUiAttributes(serviceConfigObj, configsPropertyDef);
  305. }
  306. if (!this.getBySitename(serviceConfigObj.get('filename')).someProperty('name', index)) {
  307. isAdvanced = advancedConfigs.someProperty('name', index);
  308. serviceConfigObj.id = 'site property';
  309. if (configsPropertyDef) {
  310. if (configsPropertyDef.isRequiredByAgent === false) {
  311. continue;
  312. }
  313. this.handleSpecialProperties(serviceConfigObj);
  314. } else {
  315. serviceConfigObj.displayType = stringUtils.isSingleLine(serviceConfigObj.value) ? 'advanced' : 'multiLine';
  316. }
  317. serviceConfigObj.displayName = configsPropertyDef ? configsPropertyDef.displayName : index;
  318. serviceConfigObj.options = configsPropertyDef ? configsPropertyDef.options : null;
  319. this.calculateConfigProperties(serviceConfigObj, isAdvanced, advancedConfigs);
  320. if (serviceConfigObj.get('displayType') == 'directories'
  321. && (serviceConfigObj.get('category') == 'DataNode'
  322. || serviceConfigObj.get('category') == 'NameNode')) {
  323. var dirs = serviceConfigObj.get('value').split(',').sort();
  324. serviceConfigObj.set('value', dirs.join(','));
  325. serviceConfigObj.set('defaultValue', dirs.join(','));
  326. }
  327. if (serviceConfigObj.get('displayType') == 'directory'
  328. && serviceConfigObj.get('category') == 'SNameNode') {
  329. var dirs = serviceConfigObj.get('value').split(',').sort();
  330. serviceConfigObj.set('value', dirs[0]);
  331. serviceConfigObj.set('defaultValue', dirs[0]);
  332. }
  333. if (serviceConfigObj.get('displayType') == 'masterHosts') {
  334. if (typeof(serviceConfigObj.get('value')) == 'string') {
  335. var value = serviceConfigObj.get('value').replace(/\[|]|'|&apos;/g, "").split(',');
  336. serviceConfigObj.set('value', value);
  337. }
  338. }
  339. configs.push(serviceConfigObj);
  340. } else {
  341. mappingConfigs.push(serviceConfigObj);
  342. }
  343. }
  344. }, this);
  345. return {
  346. configs: configs,
  347. mappingConfigs: mappingConfigs
  348. }
  349. },
  350. /**
  351. * @param serviceConfigObj : Object
  352. * @param configsPropertyDef : Object
  353. */
  354. setServiceConfigUiAttributes: function (serviceConfigObj, configsPropertyDef) {
  355. serviceConfigObj.displayType = configsPropertyDef.displayType;
  356. serviceConfigObj.isRequired = (configsPropertyDef.isRequired !== undefined) ? configsPropertyDef.isRequired : true;
  357. serviceConfigObj.isRequiredByAgent = (configsPropertyDef.isRequiredByAgent !== undefined) ? configsPropertyDef.isRequiredByAgent : true;
  358. serviceConfigObj.isReconfigurable = (configsPropertyDef.isReconfigurable !== undefined) ? configsPropertyDef.isReconfigurable : true;
  359. serviceConfigObj.isVisible = (configsPropertyDef.isVisible !== undefined) ? configsPropertyDef.isVisible : true;
  360. serviceConfigObj.unit = (configsPropertyDef.unit !== undefined) ? configsPropertyDef.unit : undefined;
  361. serviceConfigObj.description = (configsPropertyDef.description !== undefined) ? configsPropertyDef.description : undefined;
  362. serviceConfigObj.isOverridable = configsPropertyDef.isOverridable === undefined ? true : configsPropertyDef.isOverridable;
  363. serviceConfigObj.serviceName = configsPropertyDef ? configsPropertyDef.serviceName : null;
  364. serviceConfigObj.index = configsPropertyDef.index;
  365. serviceConfigObj.isSecureConfig = configsPropertyDef.isSecureConfig === undefined ? false : configsPropertyDef.isSecureConfig;
  366. serviceConfigObj.belongsToService = configsPropertyDef.belongsToService;
  367. serviceConfigObj.category = configsPropertyDef.category;
  368. serviceConfigObj.showLabel = configsPropertyDef.showLabel !== false;
  369. },
  370. /**
  371. * synchronize order of config properties with order, that on UI side
  372. *
  373. * @method syncOrderWithPredefined
  374. * @param configSet {object}
  375. * @return {Object}
  376. */
  377. syncOrderWithPredefined: function (configSet) {
  378. var siteConfigs = configSet.configs,
  379. siteStart = [];
  380. var preDefinedSiteProperties = this.get('preDefinedSiteProperties').mapProperty('name');
  381. var contentProperties = this.createContentProperties().mapProperty('name');
  382. var siteProperties = preDefinedSiteProperties.concat(contentProperties);
  383. siteProperties.forEach(function (name) {
  384. var _site = siteConfigs.filterProperty('name', name);
  385. if (_site.length == 1) {
  386. siteStart.push(_site[0]);
  387. siteConfigs = siteConfigs.without(_site[0]);
  388. } else if (_site.length > 1) {
  389. _site.forEach(function (site) {
  390. siteStart.push(site);
  391. siteConfigs = siteConfigs.without(site);
  392. }, this);
  393. }
  394. }, this);
  395. return {
  396. configs: siteStart.concat(siteConfigs.sortProperty('name')),
  397. mappingConfigs: configSet.mappingConfigs
  398. }
  399. },
  400. /**
  401. * merge stored configs with pre-defined
  402. * @param storedConfigs
  403. * @param advancedConfigs
  404. * @param selectedServiceNames
  405. * @return {array}
  406. */
  407. mergePreDefinedWithStored: function (storedConfigs, advancedConfigs, selectedServiceNames) {
  408. var mergedConfigs = [];
  409. var contentProperties = this.createContentProperties();
  410. var preDefinedConfigs = this.get('preDefinedSiteProperties').concat(contentProperties);
  411. storedConfigs = (storedConfigs) ? storedConfigs : [];
  412. var preDefinedNames = preDefinedConfigs.mapProperty('name');
  413. var storedNames = storedConfigs.mapProperty('name');
  414. var names = preDefinedNames.concat(storedNames).uniq();
  415. names.forEach(function (name) {
  416. var storedCfgs = storedConfigs.filterProperty('name', name);
  417. var preDefinedCfgs = [];
  418. var preDefinedConfig = preDefinedConfigs.filterProperty('name', name);
  419. preDefinedConfig.forEach(function (_preDefinedConfig) {
  420. if (selectedServiceNames.contains(_preDefinedConfig.serviceName) || _preDefinedConfig.serviceName === 'MISC') {
  421. preDefinedCfgs.push(_preDefinedConfig);
  422. }
  423. }, this);
  424. var configData = {};
  425. var isAdvanced = advancedConfigs.someProperty('name', name);
  426. if (storedCfgs.length <= 1 && preDefinedCfgs.length <= 1) {
  427. var stored = storedCfgs[0];
  428. var preDefined = preDefinedCfgs[0];
  429. if (preDefined && stored) {
  430. configData = preDefined;
  431. configData.value = stored.value;
  432. configData.defaultValue = stored.defaultValue;
  433. configData.overrides = stored.overrides;
  434. configData.filename = stored.filename;
  435. configData.description = stored.description;
  436. configData.isVisible = stored.isVisible;
  437. configData.isFinal = stored.isFinal;
  438. configData.supportsFinal = stored.supportsFinal;
  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. configData.isFinal = storedCfg.isFinal;
  472. configData.supportsFinal = storedCfg.supportsFinal;
  473. } else if (isAdvanced) {
  474. advanced = advancedConfigs.filterProperty('filename', configData.filename).findProperty('name', configData.name);
  475. this.setPropertyFromStack(configData, advanced);
  476. }
  477. mergedConfigs.push(configData);
  478. }, this);
  479. }
  480. }, this);
  481. return mergedConfigs;
  482. },
  483. /**
  484. *
  485. * @param configData {Object} Configs that will be binded to the view on step-7 of installer wizard
  486. * @param advanced {Object} Config property loaded from Server side stack definition
  487. */
  488. setPropertyFromStack: function (configData, advanced) {
  489. // Password fields should be made blank by default in installer wizard
  490. // irrespective of whatever value is sent from stack definition.
  491. // This forces the user to fill the password field.
  492. configData.value = configData.displayType == "password" ? '' : advanced ? advanced.value : configData.value;
  493. configData.defaultValue = configData.value;
  494. configData.filename = advanced ? advanced.filename : configData.filename;
  495. configData.description = advanced ? advanced.description : configData.description;
  496. configData.isFinal = !!(advanced && (advanced.isFinal === "true"));
  497. configData.supportsFinal = !!(advanced && advanced.supportsFinal);
  498. },
  499. /**
  500. * look over advanced configs and add missing configs to serviceConfigs
  501. * filter fetched configs by service if passed
  502. * @param serviceConfigs
  503. * @param advancedConfigs
  504. * @param serviceName
  505. */
  506. addAdvancedConfigs: function (serviceConfigs, advancedConfigs, serviceName) {
  507. var configsToVerifying = (serviceName) ? serviceConfigs.filterProperty('serviceName', serviceName) : serviceConfigs.slice();
  508. advancedConfigs.forEach(function (_config) {
  509. var configCategory = 'Advanced';
  510. var categoryMetaData = null;
  511. if (_config) {
  512. if (this.get('configMapping').computed().someProperty('name', _config.name)) {
  513. } else if (!(configsToVerifying.someProperty('name', _config.name))) {
  514. if (this.get('customFileNames').contains(_config.filename)) {
  515. categoryMetaData = this.identifyCategory(_config);
  516. if (categoryMetaData != null) {
  517. configCategory = categoryMetaData.get('name');
  518. }
  519. }
  520. _config.id = "site property";
  521. _config.category = configCategory;
  522. _config.displayName = _config.name;
  523. _config.defaultValue = _config.value;
  524. // make all advanced configs optional and populated by default
  525. /*
  526. * if (/\${.*}/.test(_config.value) || (service.serviceName !==
  527. * 'OOZIE' && service.serviceName !== 'HBASE')) { _config.isRequired =
  528. * false; _config.value = ''; } else if
  529. * (/^\s+$/.test(_config.value)) { _config.isRequired = false; }
  530. */
  531. _config.isRequired = true;
  532. _config.displayType = stringUtils.isSingleLine(_config.value) ? 'advanced' : 'multiLine';
  533. serviceConfigs.push(_config);
  534. }
  535. }
  536. }, this);
  537. },
  538. /**
  539. * Render a custom conf-site box for entering properties that will be written in *-site.xml files of the services
  540. */
  541. addCustomConfigs: function (configs) {
  542. var preDefinedCustomConfigs = $.extend(true, [], this.get('preDefinedCustomConfigs'));
  543. var stored = configs.filter(function (_config) {
  544. return this.get('categoriesWithCustom').contains(_config.category);
  545. }, this);
  546. if (App.supports.capacitySchedulerUi) {
  547. var queueProperties = stored.filter(this.get('capacitySchedulerFilter'));
  548. if (queueProperties.length) {
  549. queueProperties.setEach('isQueue', true);
  550. }
  551. }
  552. },
  553. miscConfigVisibleProperty: function (configs, serviceToShow) {
  554. configs.forEach(function (item) {
  555. item.set("isVisible", item.belongsToService.some(function (cur) {
  556. return serviceToShow.contains(cur)
  557. }));
  558. });
  559. return configs;
  560. },
  561. /**
  562. * render configs, distribute them by service
  563. * and wrap each in ServiceConfigProperty object
  564. * @param configs
  565. * @param storedConfigs
  566. * @param allSelectedServiceNames
  567. * @param installedServiceNames
  568. * @param localDB
  569. * @return {Array}
  570. */
  571. renderConfigs: function (configs, storedConfigs, allSelectedServiceNames, installedServiceNames, localDB) {
  572. var renderedServiceConfigs = [];
  573. var services = [];
  574. this.get('preDefinedServiceConfigs').forEach(function (serviceConfig) {
  575. var serviceName = serviceConfig.get('serviceName');
  576. if (allSelectedServiceNames.contains(serviceName) || serviceName === 'MISC') {
  577. console.log('pushing ' + serviceName, serviceConfig);
  578. if (!installedServiceNames.contains(serviceName) || serviceName === 'MISC') {
  579. serviceConfig.set('showConfig', true);
  580. }
  581. services.push(serviceConfig);
  582. }
  583. });
  584. services.forEach(function (service) {
  585. var configsByService = [];
  586. var serviceConfigs = configs.filterProperty('serviceName', service.get('serviceName'));
  587. serviceConfigs.forEach(function (_config) {
  588. _config.isOverridable = (_config.isOverridable === undefined) ? true : _config.isOverridable;
  589. var serviceConfigProperty = App.ServiceConfigProperty.create(_config);
  590. this.updateHostOverrides(serviceConfigProperty, _config);
  591. if (!storedConfigs && !serviceConfigProperty.get('hasInitialValue')) {
  592. serviceConfigProperty.initialValue(localDB);
  593. }
  594. if (storedConfigs && storedConfigs.filterProperty('name', _config.name).length && !!_config.filename) {
  595. var storedConfig = storedConfigs.filterProperty('name', _config.name).findProperty('filename', _config.filename);
  596. if (storedConfig) {
  597. serviceConfigProperty.set('defaultValue', storedConfig.defaultValue);
  598. serviceConfigProperty.set('value', storedConfig.value);
  599. }
  600. }
  601. this.tweakDynamicDefaults(localDB, serviceConfigProperty, _config);
  602. serviceConfigProperty.validate();
  603. configsByService.pushObject(serviceConfigProperty);
  604. }, this);
  605. var serviceConfig = this.createServiceConfig(service.get('serviceName'));
  606. serviceConfig.set('showConfig', service.get('showConfig'));
  607. // Use calculated default values for some configs
  608. var recommendedDefaults = {};
  609. if (!storedConfigs && service.get('defaultsProviders')) {
  610. service.get('defaultsProviders').forEach(function (defaultsProvider) {
  611. var defaults = defaultsProvider.getDefaults(localDB);
  612. for (var name in defaults) {
  613. var config = configsByService.findProperty('name', name);
  614. if (!config) {
  615. continue;
  616. }
  617. if (!!defaults[name]) {
  618. recommendedDefaults[name] = defaults[name];
  619. config.set('value', defaults[name]);
  620. config.set('defaultValue', defaults[name]);
  621. } else {
  622. recommendedDefaults[name] = config.get('defaultValue');
  623. }
  624. }
  625. });
  626. }
  627. if (service.get('configsValidator')) {
  628. service.get('configsValidator').set('recommendedDefaults', recommendedDefaults);
  629. var validators = service.get('configsValidator').get('configValidators');
  630. for (var validatorName in validators) {
  631. var c = configsByService.findProperty('name', validatorName);
  632. if (c) {
  633. c.set('serviceValidator', service.get('configsValidator'));
  634. }
  635. }
  636. }
  637. serviceConfig.set('configs', configsByService);
  638. renderedServiceConfigs.push(serviceConfig);
  639. }, this);
  640. return renderedServiceConfigs;
  641. },
  642. /**
  643. Takes care of the "dynamic defaults" for the GLUSTERFS configs. Sets
  644. some of the config defaults to previously user-entered data.
  645. **/
  646. tweakDynamicDefaults: function (localDB, serviceConfigProperty, config) {
  647. var firstHost = null;
  648. for (var host in localDB.hosts) {
  649. firstHost = host;
  650. break;
  651. }
  652. try {
  653. if (typeof(config.defaultValue) == "string" && config.defaultValue.indexOf("{firstHost}") >= 0) {
  654. serviceConfigProperty.set('value', serviceConfigProperty.value.replace(new RegExp("{firstHost}"), firstHost));
  655. serviceConfigProperty.set('defaultValue', serviceConfigProperty.defaultValue.replace(new RegExp("{firstHost}"), firstHost));
  656. }
  657. } catch (err) {
  658. // Nothing to worry about here, most likely trying indexOf on a non-string
  659. }
  660. },
  661. /**
  662. * create new child configs from overrides, attach them to parent config
  663. * override - value of config, related to particular host(s)
  664. * @param configProperty
  665. * @param storedConfigProperty
  666. */
  667. updateHostOverrides: function (configProperty, storedConfigProperty) {
  668. if (storedConfigProperty.overrides != null && storedConfigProperty.overrides.length > 0) {
  669. var overrides = [];
  670. storedConfigProperty.overrides.forEach(function (overrideEntry) {
  671. // create new override with new value
  672. var newSCP = App.ServiceConfigProperty.create(configProperty);
  673. newSCP.set('value', overrideEntry.value);
  674. newSCP.set('isOriginalSCP', false); // indicated this is overridden value,
  675. newSCP.set('parentSCP', configProperty);
  676. var hostsArray = Ember.A([]);
  677. overrideEntry.hosts.forEach(function (host) {
  678. hostsArray.push(host);
  679. });
  680. newSCP.set('selectedHostOptions', hostsArray);
  681. overrides.pushObject(newSCP);
  682. });
  683. configProperty.set('overrides', overrides);
  684. }
  685. },
  686. /**
  687. * create new ServiceConfig object by service name
  688. * @param serviceName
  689. */
  690. createServiceConfig: function (serviceName) {
  691. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  692. var serviceConfig = App.ServiceConfig.create({
  693. serviceName: preDefinedServiceConfig.get('serviceName'),
  694. displayName: preDefinedServiceConfig.get('displayName'),
  695. configCategories: preDefinedServiceConfig.get('configCategories'),
  696. configs: [],
  697. configGroups: []
  698. });
  699. serviceConfig.configCategories.filterProperty('isCustomView', true).forEach(function (category) {
  700. switch (category.name) {
  701. case 'CapacityScheduler':
  702. if (App.supports.capacitySchedulerUi) {
  703. category.set('customView', App.ServiceConfigCapacityScheduler);
  704. } else {
  705. category.set('isCustomView', false);
  706. }
  707. break;
  708. }
  709. }, this);
  710. return serviceConfig;
  711. },
  712. /**
  713. * GETs all cluster level sites in one call.
  714. *
  715. * @return {object}
  716. */
  717. loadConfigsByTags: function (tags) {
  718. var urlParams = [];
  719. tags.forEach(function (_tag) {
  720. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  721. });
  722. var params = urlParams.join('|');
  723. return App.ajax.send({
  724. name: 'config.on_site',
  725. sender: this,
  726. data: {
  727. params: params
  728. }
  729. });
  730. },
  731. /**
  732. * Generate serviceProperties save it to localDB
  733. * called form stepController step6WizardController
  734. *
  735. * @param serviceName
  736. * @param callback
  737. * @return {object|null}
  738. */
  739. loadAdvancedConfig: function (serviceName, callback) {
  740. return App.ajax.send({
  741. name: 'config.advanced',
  742. sender: this,
  743. data: {
  744. serviceName: serviceName,
  745. stackVersionUrl: App.get('stackVersionURL'),
  746. stackVersion: App.get('currentStackVersionNumber'),
  747. callback: callback
  748. },
  749. success: 'loadAdvancedConfigSuccess',
  750. error: 'loadAdvancedConfigError'
  751. });
  752. },
  753. loadAdvancedConfigSuccess: function (data, opt, params) {
  754. console.log("TRACE: In success function for the loadAdvancedConfig; url is ", opt.url);
  755. var properties = [];
  756. if (data.items.length) {
  757. data.items.forEach(function (item) {
  758. item = item.StackConfigurations;
  759. item.isVisible = true;
  760. var serviceName = item.service_name;
  761. var fileName = item.type;
  762. var isHDP2 = App.get('isHadoop2Stack');
  763. /**
  764. * Properties from mapred-queue-acls.xml are ignored unless App.supports.capacitySchedulerUi is true
  765. * Properties from capacity-scheduler.xml are ignored unless HDP stack version is 2.x or
  766. * HDP stack version is 1.x and App.supports.capacitySchedulerUi is true.
  767. */
  768. if ((fileName !== 'mapred-queue-acls.xml' || App.supports.capacitySchedulerUi) &&
  769. (fileName !== 'capacity-scheduler.xml' || isHDP2 || App.supports.capacitySchedulerUi)) {
  770. properties.push({
  771. serviceName: serviceName,
  772. name: item.property_name,
  773. value: item.property_value,
  774. description: item.property_description,
  775. isVisible: item.isVisible,
  776. isFinal: item.final === "true",
  777. filename: item.filename || fileName
  778. });
  779. }
  780. }, this);
  781. }
  782. params.callback(properties);
  783. },
  784. loadAdvancedConfigError: function (request, ajaxOptions, error, opt, params) {
  785. console.log('ERROR: failed to load stack configs for', params.serviceName);
  786. params.callback([]);
  787. },
  788. /**
  789. * Get config types and config type attributes from stack service
  790. *
  791. * @param service
  792. * @return {object}
  793. */
  794. getConfigTypesInfoFromService: function (service) {
  795. var configTypes = service.get('configTypes');
  796. var configTypesInfo = {
  797. items: [],
  798. supportsFinal: []
  799. };
  800. if (configTypes) {
  801. for (var key in configTypes) {
  802. if (configTypes.hasOwnProperty(key)) {
  803. configTypesInfo.items.push(key);
  804. if (configTypes[key].supports && configTypes[key].supports.final === "true") {
  805. configTypesInfo.supportsFinal.push(key);
  806. }
  807. }
  808. }
  809. }
  810. return configTypesInfo;
  811. },
  812. /**
  813. * Get properties from server by type and tag with properties, that belong to group
  814. * push them to common {serviceConfigs} and call callback function
  815. */
  816. loadServiceConfigGroupOverrides: function (serviceConfigs, loadedGroupToOverrideSiteToTagMap, configGroups, callback, sender) {
  817. var configKeyToConfigMap = {};
  818. serviceConfigs.forEach(function (item) {
  819. if (!configKeyToConfigMap[item.filename]) {
  820. configKeyToConfigMap[item.filename] = {};
  821. }
  822. configKeyToConfigMap[item.filename][item.name] = item;
  823. });
  824. var typeTagToGroupMap = {};
  825. var urlParams = [];
  826. for (var group in loadedGroupToOverrideSiteToTagMap) {
  827. var overrideTypeTags = loadedGroupToOverrideSiteToTagMap[group];
  828. for (var type in overrideTypeTags) {
  829. var tag = overrideTypeTags[type];
  830. typeTagToGroupMap[type + "///" + tag] = configGroups.findProperty('name', group);
  831. urlParams.push('(type=' + type + '&tag=' + tag + ')');
  832. }
  833. }
  834. var params = urlParams.join('|');
  835. if (urlParams.length) {
  836. App.ajax.send({
  837. name: 'config.host_overrides',
  838. sender: this,
  839. data: {
  840. params: params,
  841. configKeyToConfigMap: configKeyToConfigMap,
  842. typeTagToGroupMap: typeTagToGroupMap,
  843. callback: callback,
  844. sender: sender,
  845. serviceConfigs: serviceConfigs
  846. },
  847. success: 'loadServiceConfigGroupOverridesSuccess'
  848. });
  849. } else {
  850. callback.call(sender, serviceConfigs);
  851. }
  852. },
  853. loadServiceConfigGroupOverridesSuccess: function (data, opt, params) {
  854. data.items.forEach(function (config) {
  855. App.config.loadedConfigurationsCache[config.type + "_" + config.tag] = config.properties;
  856. var group = params.typeTagToGroupMap[config.type + "///" + config.tag];
  857. var properties = config.properties;
  858. for (var prop in properties) {
  859. var serviceConfig = params.configKeyToConfigMap[config.type + ".xml"][prop];
  860. var hostOverrideValue = properties[prop];
  861. if (serviceConfig && serviceConfig.displayType === 'int') {
  862. if (/\d+m$/.test(hostOverrideValue)) {
  863. hostOverrideValue = hostOverrideValue.slice(0, hostOverrideValue.length - 1);
  864. }
  865. } else if (serviceConfig && serviceConfig.displayType === 'checkbox') {
  866. switch (hostOverrideValue) {
  867. case 'true':
  868. hostOverrideValue = true;
  869. break;
  870. case 'false':
  871. hostOverrideValue = false;
  872. break;
  873. }
  874. }
  875. if (serviceConfig) {
  876. // Value of this property is different for this host.
  877. var overrides = 'overrides';
  878. if (!(overrides in serviceConfig)) {
  879. serviceConfig.overrides = [];
  880. }
  881. if (!serviceConfig.overrides) {
  882. serviceConfig.set('overrides', []);
  883. }
  884. console.log("loadServiceConfigGroupOverridesSuccess(): [" + group + "] OVERRODE(" + serviceConfig.name + "): " + serviceConfig.value + " -> " + hostOverrideValue);
  885. serviceConfig.overrides.push({value: hostOverrideValue, group: group});
  886. }
  887. }
  888. });
  889. params.callback.call(params.sender, params.serviceConfigs);
  890. },
  891. /**
  892. * Set all site property that are derived from other site-properties
  893. */
  894. setConfigValue: function (mappedConfigs, allConfigs, config) {
  895. var globalValue;
  896. if (config.value == null) {
  897. return;
  898. }
  899. var fkValue = config.value.match(/<(foreignKey.*?)>/g);
  900. var fkName = config.name.match(/<(foreignKey.*?)>/g);
  901. var templateValue = config.value.match(/<(templateName.*?)>/g);
  902. if (fkValue) {
  903. fkValue.forEach(function (_fkValue) {
  904. var index = parseInt(_fkValue.match(/\[([\d]*)(?=\])/)[1]);
  905. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  906. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  907. config.value = config.value.replace(_fkValue, globalValue);
  908. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  909. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  910. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  911. } else {
  912. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  913. }
  914. config.value = config.value.replace(_fkValue, globalValue);
  915. }
  916. }, this);
  917. }
  918. // config._name - formatted name from original config name
  919. if (fkName) {
  920. fkName.forEach(function (_fkName) {
  921. var index = parseInt(_fkName.match(/\[([\d]*)(?=\])/)[1]);
  922. if (mappedConfigs.someProperty('name', config.foreignKey[index])) {
  923. globalValue = mappedConfigs.findProperty('name', config.foreignKey[index]).value;
  924. config._name = config.name.replace(_fkName, globalValue);
  925. } else if (allConfigs.someProperty('name', config.foreignKey[index])) {
  926. if (allConfigs.findProperty('name', config.foreignKey[index]).value === '') {
  927. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).defaultValue;
  928. } else {
  929. globalValue = allConfigs.findProperty('name', config.foreignKey[index]).value;
  930. }
  931. config._name = config.name.replace(_fkName, globalValue);
  932. }
  933. }, this);
  934. }
  935. //For properties in the configMapping file having foreignKey and templateName properties.
  936. if (templateValue) {
  937. templateValue.forEach(function (_value) {
  938. var index = parseInt(_value.match(/\[([\d]*)(?=\])/)[1]);
  939. if (allConfigs.someProperty('name', config.templateName[index])) {
  940. var globalValue = allConfigs.findProperty('name', config.templateName[index]).value;
  941. config.value = config.value.replace(_value, globalValue);
  942. } else {
  943. config.value = null;
  944. }
  945. }, this);
  946. }
  947. },
  948. /**
  949. * identify service name of config by its config's type
  950. * @param type
  951. * @return {string|null}
  952. */
  953. getServiceNameByConfigType: function (type) {
  954. var preDefinedServiceConfigs = this.get('preDefinedServiceConfigs');
  955. var service = preDefinedServiceConfigs.find(function (serviceConfig) {
  956. return !!serviceConfig.get('configTypes')[type];
  957. }, this);
  958. return service && service.get('serviceName');
  959. },
  960. /**
  961. * add user property
  962. * @param stored
  963. * @param isAdvanced
  964. * @param advancedConfigs
  965. * @return {Object}
  966. */
  967. addUserProperty: function (stored, isAdvanced, advancedConfigs) {
  968. var configData = {
  969. id: stored.id,
  970. name: stored.name,
  971. displayName: stored.name,
  972. serviceName: stored.serviceName,
  973. value: stored.value,
  974. defaultValue: stored.defaultValue,
  975. displayType: stringUtils.isSingleLine(stored.value) ? 'advanced' : 'multiLine',
  976. filename: stored.filename,
  977. category: 'Advanced',
  978. isUserProperty: stored.isUserProperty === true,
  979. hasInitialValue: !!stored.hasInitialValue,
  980. isOverridable: true,
  981. overrides: stored.overrides,
  982. isRequired: true,
  983. isVisible: stored.isVisible,
  984. isFinal: stored.isFinal,
  985. defaultIsFinal: stored.defaultIsFinal,
  986. supportsFinal: stored.supportsFinal,
  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. });