config.js 65 KB

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