config.js 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  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. require('utils/configs_collection');
  20. var stringUtils = require('utils/string_utils');
  21. var validator = require('utils/validator');
  22. var configTagFromFileNameMap = {};
  23. App.config = Em.Object.create({
  24. CONFIG_GROUP_NAME_MAX_LENGTH: 18,
  25. /**
  26. * filename exceptions used to support substandard sitenames which don't have "xml" extension
  27. * @type {string[]}
  28. */
  29. filenameExceptions: ['alert_notification'],
  30. preDefinedServiceConfigs: [],
  31. /**
  32. *
  33. * Returns file name version that stored on server.
  34. *
  35. * Example:
  36. * App.config.getOriginalFileName('core-site') // returns core-site.xml
  37. * App.config.getOriginalFileName('zoo.cfg') // returns zoo.cfg
  38. *
  39. * @param {String} fileName
  40. * @method getOriginalFileName
  41. **/
  42. getOriginalFileName: function (fileName) {
  43. if (/\.xml$/.test(fileName)) return fileName;
  44. return this.get('filenameExceptions').contains(fileName) ? fileName : fileName + '.xml';
  45. },
  46. /**
  47. * truncate Config Group name to <CONFIG_GROUP_NAME_MAX_LENGTH> length and paste "..." in the middle
  48. */
  49. truncateGroupName: function (name) {
  50. if (name && name.length > App.config.CONFIG_GROUP_NAME_MAX_LENGTH) {
  51. var middle = Math.floor(App.config.CONFIG_GROUP_NAME_MAX_LENGTH / 2);
  52. name = name.substring(0, middle) + "..." + name.substring(name.length - middle);
  53. }
  54. return name;
  55. },
  56. /**
  57. * Check if Hive installation with new MySQL database created via Ambari is allowed
  58. * @param osFamily
  59. * @returns {boolean}
  60. */
  61. isManagedMySQLForHiveAllowed: function (osFamily) {
  62. var osList = ['redhat5', 'suse11'];
  63. return !osList.contains(osFamily);
  64. },
  65. /**
  66. *
  67. * Returns the configuration tagName from supplied filename
  68. *
  69. * Example:
  70. * App.config.getConfigTagFromFileName('core-site.xml') // returns core-site
  71. * App.config.getConfigTagFromFileName('zoo.cfg') // returns zoo.cfg
  72. *
  73. * @param {String} fileName
  74. * @method getConfigTagFromFileName
  75. **/
  76. getConfigTagFromFileName: function (fileName) {
  77. if (configTagFromFileNameMap[fileName]) {
  78. return configTagFromFileNameMap[fileName];
  79. }
  80. var ret = fileName.endsWith('.xml') ? fileName.slice(0, -4) : fileName;
  81. configTagFromFileNameMap[fileName] = ret;
  82. return ret;
  83. },
  84. /**
  85. *
  86. * @param name
  87. * @param fileName
  88. * @returns {string}
  89. */
  90. configId: function(name, fileName) {
  91. return name + "__" + App.config.getConfigTagFromFileName(fileName);
  92. },
  93. setPreDefinedServiceConfigs: function (isMiscTabToBeAdded) {
  94. var stackServices = App.StackService.find().filterProperty('id');
  95. // Only include services that has configTypes related to them for service configuration page
  96. var servicesWithConfigTypes = stackServices.filter(function (service) {
  97. var configtypes = service.get('configTypes');
  98. return configtypes && !!Object.keys(configtypes).length;
  99. }, this);
  100. var allTabs;
  101. if (isMiscTabToBeAdded) {
  102. var nonServiceTab = require('data/service_configs');
  103. var miscService = nonServiceTab.findProperty('serviceName', 'MISC');
  104. var tagTypes = {};
  105. servicesWithConfigTypes.mapProperty('configTypes').forEach(function (configTypes) {
  106. for (var fileName in configTypes) {
  107. if (fileName.endsWith('-env') && !miscService.get('configTypes')[fileName]) {
  108. tagTypes[fileName] = configTypes[fileName];
  109. }
  110. }
  111. });
  112. miscService.set('configTypes', $.extend(miscService.get('configTypes'), tagTypes));
  113. allTabs = servicesWithConfigTypes.concat(nonServiceTab);
  114. } else {
  115. allTabs = servicesWithConfigTypes;
  116. }
  117. this.set('preDefinedServiceConfigs', allTabs);
  118. },
  119. secureConfigs: require('data/HDP2/secure_mapping'),
  120. secureConfigsMap: function () {
  121. var ret = {};
  122. this.get('secureConfigs').forEach(function (sc) {
  123. ret[sc.name] = true;
  124. });
  125. return ret;
  126. }.property('secureConfigs.[]'),
  127. kerberosIdentities: require('data/HDP2/kerberos_identities').configProperties,
  128. kerberosIdentitiesMap: function() {
  129. var map = {};
  130. this.get('kerberosIdentities').forEach(function (c) {
  131. map[this.configId(c.name, c.filename)] = c;
  132. }, this);
  133. return map;
  134. }.property('kerberosIdentities'),
  135. customStackMapping: require('data/custom_stack_map'),
  136. mapCustomStack: function () {
  137. var
  138. baseStackFolder = App.get('currentStackName'),
  139. singMap = {
  140. "1": ">",
  141. "-1": "<",
  142. "0": "="
  143. };
  144. this.get('customStackMapping').every(function (stack) {
  145. if(stack.stackName == App.get('currentStackName')){
  146. var versionCompare = Em.compare(App.get('currentStackVersionNumber'), stack.stackVersionNumber);
  147. if(singMap[versionCompare+""] === stack.sign){
  148. baseStackFolder = stack.baseStackFolder;
  149. return false;
  150. }
  151. }
  152. return true;
  153. });
  154. return baseStackFolder;
  155. },
  156. allPreDefinedSiteProperties: function() {
  157. var sitePropertiesForCurrentStack = this.preDefinedConfigFile(this.mapCustomStack(), 'site_properties');
  158. if (sitePropertiesForCurrentStack) {
  159. return sitePropertiesForCurrentStack.configProperties;
  160. } else if (App.get('isHadoop23Stack')) {
  161. return require('data/HDP2.3/site_properties').configProperties;
  162. } else {
  163. return require('data/HDP2.2/site_properties').configProperties;
  164. }
  165. }.property('App.isHadoop23Stack'),
  166. preDefinedSiteProperties: function () {
  167. var serviceNames = App.StackService.find().mapProperty('serviceName').concat('MISC');
  168. return this.get('allPreDefinedSiteProperties').filter(function(p) {
  169. return serviceNames.contains(p.serviceName);
  170. });
  171. }.property('allPreDefinedSiteProperties'),
  172. /**
  173. * map of <code>preDefinedSiteProperties</code> provide search by index
  174. * @type {object}
  175. */
  176. preDefinedSitePropertiesMap: function () {
  177. var map = {};
  178. this.get('preDefinedSiteProperties').forEach(function (c) {
  179. map[this.configId(c.name, c.filename)] = c;
  180. }, this);
  181. return map;
  182. }.property('preDefinedSiteProperties'),
  183. preDefinedConfigFile: function(folder, file) {
  184. try {
  185. return require('data/{0}/{1}'.format(folder, file));
  186. } catch (err) {
  187. // the file doesn't exist, which might be expected.
  188. }
  189. },
  190. serviceByConfigTypeMap: function () {
  191. var ret = {};
  192. App.StackService.find().forEach(function(s) {
  193. s.get('configTypeList').forEach(function (ct) {
  194. ret[ct] = s;
  195. });
  196. });
  197. return ret;
  198. }.property(),
  199. /**
  200. * Generate configs collection with Ember or plain config objects
  201. * from config JSON
  202. *
  203. * @param configJSON
  204. * @param useEmberObject
  205. * @returns {Array}
  206. */
  207. getConfigsFromJSON: function(configJSON, useEmberObject) {
  208. var configs = [],
  209. filename = App.config.getOriginalFileName(configJSON.type),
  210. properties = configJSON.properties,
  211. finalAttributes = Em.get(configJSON, 'properties_attributes.final') || {};
  212. for (var index in properties) {
  213. var serviceConfigObj = this.getDefaultConfig(index, filename);
  214. if (serviceConfigObj.isRequiredByAgent !== false) {
  215. serviceConfigObj.value = serviceConfigObj.savedValue = this.formatPropertyValue(serviceConfigObj, properties[index]);
  216. serviceConfigObj.isFinal = serviceConfigObj.savedIsFinal = finalAttributes[index] === "true";
  217. serviceConfigObj.isEditable = serviceConfigObj.isReconfigurable;
  218. }
  219. if (useEmberObject) {
  220. configs.push(App.ServiceConfigProperty.create(serviceConfigObj));
  221. } else {
  222. configs.push(serviceConfigObj);
  223. }
  224. }
  225. return configs;
  226. },
  227. /**
  228. * Get config from configsCollections or
  229. * generate new default config in collection does not contain
  230. * such config
  231. *
  232. * @param name
  233. * @param fileName
  234. * @param coreObject
  235. * @returns {*|Object}
  236. */
  237. getDefaultConfig: function(name, fileName, coreObject) {
  238. var cfg = App.configsCollection.getConfigByName(name, fileName) ||
  239. App.config.createDefaultConfig(name, fileName, false);
  240. if (Em.typeOf(coreObject) === 'object') {
  241. Em.setProperties(cfg, coreObject);
  242. }
  243. return cfg;
  244. },
  245. /**
  246. * This method sets default values for config property
  247. * These property values has the lowest priority and can be overridden be stack/UI
  248. * config property but is used when such properties are absent in stack/UI configs
  249. * @param {string} name
  250. * @param {string} fileName
  251. * @param {boolean} definedInStack
  252. * @param {Object} [coreObject]
  253. * @returns {Object}
  254. */
  255. createDefaultConfig: function(name, fileName, definedInStack, coreObject) {
  256. var service = this.get('serviceByConfigTypeMap')[App.config.getConfigTagFromFileName(fileName)];
  257. var serviceName = service ? service.get('serviceName') : 'MISC';
  258. var tpl = {
  259. /** core properties **/
  260. id: this.configId(name, fileName),
  261. name: name,
  262. filename: this.getOriginalFileName(fileName),
  263. value: '',
  264. savedValue: null,
  265. isFinal: false,
  266. savedIsFinal: null,
  267. /** UI and Stack properties **/
  268. recommendedValue: null,
  269. recommendedIsFinal: null,
  270. supportsFinal: this.shouldSupportFinal(serviceName, fileName),
  271. supportsAddingForbidden: this.shouldSupportAddingForbidden(serviceName, fileName),
  272. serviceName: serviceName,
  273. displayName: name,
  274. displayType: this.getDefaultDisplayType(coreObject ? coreObject.value : ''),
  275. description: '',
  276. category: this.getDefaultCategory(definedInStack, fileName),
  277. isSecureConfig: this.getIsSecure(name),
  278. showLabel: true,
  279. isVisible: true,
  280. isUserProperty: !definedInStack,
  281. isRequired: definedInStack,
  282. group: null,
  283. isRequiredByAgent: true,
  284. isReconfigurable: true,
  285. unit: null,
  286. hasInitialValue: false,
  287. isOverridable: true,
  288. index: Infinity,
  289. dependentConfigPattern: null,
  290. options: null,
  291. radioName: null,
  292. widgetType: null,
  293. errorMessage: '',
  294. warnMessage: ''
  295. };
  296. return Object.keys(coreObject|| {}).length ?
  297. $.extend(tpl, coreObject) : tpl;
  298. },
  299. /**
  300. * This method creates host name properties
  301. * @param serviceName
  302. * @param componentName
  303. * @param value
  304. * @param stackComponent
  305. * @returns Object
  306. */
  307. createHostNameProperty: function(serviceName, componentName, value, stackComponent) {
  308. var hostOrHosts = stackComponent.get('isMultipleAllowed') ? 'hosts' : 'host';
  309. var name = componentName.toLowerCase() + '_' + hostOrHosts;
  310. var filename = serviceName.toLowerCase() + "-site.xml";
  311. return {
  312. "id": App.config.configId(name, filename),
  313. "name": name,
  314. "displayName": stackComponent.get('displayName') + ' ' + (value.length > 1 ? 'hosts' : 'host'),
  315. "value": value,
  316. "recommendedValue": value,
  317. "description": "The " + hostOrHosts + " that has been assigned to run " + stackComponent.get('displayName'),
  318. "displayType": "component" + hostOrHosts.capitalize(),
  319. "isOverridable": false,
  320. "isRequiredByAgent": false,
  321. "serviceName": serviceName,
  322. "filename": filename,
  323. "category": componentName,
  324. "index": 0
  325. }
  326. },
  327. /**
  328. * Get component name from config name string
  329. *
  330. * @param configName
  331. * @returns {string}
  332. */
  333. getComponentName: function(configName) {
  334. var match = configName.match(/^(.*)_host[s]?$/) || [],
  335. component = match[1];
  336. return component ? component.toUpperCase() : "";
  337. },
  338. /**
  339. * This method merge properties form <code>stackConfigProperty<code> which are taken from stack
  340. * with <code>UIConfigProperty<code> which are hardcoded on UI
  341. * @param coreObject
  342. * @param stackProperty
  343. * @param preDefined
  344. * @param [propertiesToSkip]
  345. */
  346. mergeStaticProperties: function(coreObject, stackProperty, preDefined, propertiesToSkip) {
  347. propertiesToSkip = propertiesToSkip || ['name', 'filename', 'value', 'savedValue', 'isFinal', 'savedIsFinal'];
  348. for (var k in coreObject) {
  349. if (coreObject.hasOwnProperty(k)) {
  350. if (!propertiesToSkip.contains(k)) {
  351. coreObject[k] = this.getPropertyIfExists(k, coreObject[k], stackProperty, preDefined);
  352. }
  353. }
  354. }
  355. return coreObject;
  356. },
  357. /**
  358. * This method using for merging some properties from two objects
  359. * if property exists in <code>firstPriority<code> result will be it's property
  360. * else if property exists in <code>secondPriority<code> result will be it's property
  361. * otherwise <code>defaultValue<code> will be returned
  362. * @param {String} propertyName
  363. * @param {*} defaultValue=null
  364. * @param {Em.Object|Object} firstPriority
  365. * @param {Em.Object|Object} [secondPriority=null]
  366. * @returns {*}
  367. */
  368. getPropertyIfExists: function(propertyName, defaultValue, firstPriority, secondPriority) {
  369. firstPriority = firstPriority || {};
  370. secondPriority = secondPriority || {};
  371. var fp = Em.get(firstPriority, propertyName);
  372. if (firstPriority && !Em.isNone(fp)) {
  373. return fp;
  374. }
  375. else {
  376. var sp = Em.get(secondPriority, propertyName);
  377. if (secondPriority && !Em.isNone(sp)) {
  378. return sp;
  379. } else {
  380. return defaultValue;
  381. }
  382. }
  383. },
  384. /**
  385. * Get displayType for properties that has not defined value
  386. * @param value
  387. * @returns {string}
  388. */
  389. getDefaultDisplayType: function(value) {
  390. return value && !stringUtils.isSingleLine(value) ? 'multiLine' : 'string';
  391. },
  392. /**
  393. * Get category for properties that has not defined value
  394. * @param stackConfigProperty
  395. * @param fileName
  396. * @returns {string}
  397. */
  398. getDefaultCategory: function(stackConfigProperty, fileName) {
  399. return (stackConfigProperty ? 'Advanced ' : 'Custom ') + this.getConfigTagFromFileName(fileName);
  400. },
  401. /**
  402. * Get isSecureConfig for properties that has not defined value
  403. * @param propertyName
  404. * @returns {boolean}
  405. */
  406. getIsSecure: function(propertyName) {
  407. return !!this.get('secureConfigsMap')[propertyName];
  408. },
  409. /**
  410. * Returns description, formatted if needed
  411. *
  412. * @param {String} description
  413. * @param {String} displayType
  414. * @returns {String}
  415. */
  416. getDescription: function(description, displayType) {
  417. var additionalDescription = Em.I18n.t('services.service.config.password.additionalDescription');
  418. if ('password' === displayType) {
  419. if (description && !description.contains(additionalDescription)) {
  420. return description + '<br />' + additionalDescription;
  421. } else {
  422. return additionalDescription;
  423. }
  424. }
  425. return description
  426. },
  427. /**
  428. * parse Kerberos descriptor
  429. *
  430. * @param kerberosDescriptor
  431. * @returns {{}}
  432. */
  433. parseDescriptor: function(kerberosDescriptor) {
  434. var identitiesMap = {};
  435. Em.get(kerberosDescriptor, 'KerberosDescriptor.kerberos_descriptor.services').forEach(function (service) {
  436. this.parseIdentities(service, identitiesMap);
  437. if (Array.isArray(service.components)) {
  438. service.components.forEach(function (component) {
  439. this.parseIdentities(component, identitiesMap);
  440. }, this);
  441. }
  442. }, this);
  443. return identitiesMap;
  444. },
  445. /**
  446. * Looking for configs identities and add them to <code>identitiesMap<code>
  447. *
  448. * @param item
  449. * @param identitiesMap
  450. */
  451. parseIdentities: function (item, identitiesMap) {
  452. if (item.identities) {
  453. item.identities.forEach(function (identity) {
  454. Em.keys(identity).without('name').forEach(function (item) {
  455. if (identity[item].configuration) {
  456. var cfg = identity[item].configuration.split('/'), name = cfg[1], fileName = cfg[0];
  457. identitiesMap[App.config.configId(name, fileName)] = true;
  458. }
  459. });
  460. });
  461. }
  462. return identitiesMap;
  463. },
  464. /**
  465. * Update description for disabled kerberos configs which are identities
  466. *
  467. * @param description
  468. * @returns {*}
  469. */
  470. kerberosIdentitiesDescription: function(description) {
  471. if (!description) return Em.I18n.t('services.service.config.secure.additionalDescription');
  472. description = description.trim();
  473. return (description.endsWith('.') ? description + ' ' : description + '. ') +
  474. Em.I18n.t('services.service.config.secure.additionalDescription');
  475. },
  476. /**
  477. * Get view class based on display type of config
  478. *
  479. * @param displayType
  480. * @param dependentConfigPattern
  481. * @param unit
  482. * @returns {*}
  483. */
  484. getViewClass: function (displayType, dependentConfigPattern, unit) {
  485. switch (displayType) {
  486. case 'checkbox':
  487. case 'boolean':
  488. return dependentConfigPattern ? App.ServiceConfigCheckboxWithDependencies : App.ServiceConfigCheckbox;
  489. case 'password':
  490. return App.ServiceConfigPasswordField;
  491. case 'combobox':
  492. return App.ServiceConfigComboBox;
  493. case 'radio button':
  494. return App.ServiceConfigRadioButtons;
  495. case 'directories':
  496. return App.ServiceConfigTextArea;
  497. case 'directory':
  498. return App.ServiceConfigTextField;
  499. case 'content':
  500. return App.ServiceConfigTextAreaContent;
  501. case 'multiLine':
  502. return App.ServiceConfigTextArea;
  503. case 'custom':
  504. return App.ServiceConfigBigTextArea;
  505. case 'componentHost':
  506. return App.ServiceConfigMasterHostView;
  507. case 'label':
  508. return App.ServiceConfigLabelView;
  509. case 'componentHosts':
  510. return App.ServiceConfigComponentHostsView;
  511. case 'supportTextConnection':
  512. return App.checkConnectionView;
  513. case 'capacityScheduler':
  514. return App.CapacitySceduler;
  515. default:
  516. return unit ? App.ServiceConfigTextFieldWithUnit : App.ServiceConfigTextField;
  517. }
  518. },
  519. /**
  520. * Returns error validator function based on config type
  521. *
  522. * @param displayType
  523. * @returns {Function}
  524. */
  525. getErrorValidator: function (displayType) {
  526. switch (displayType) {
  527. case 'checkbox':
  528. case 'custom':
  529. return function () {
  530. return ''
  531. };
  532. case 'int':
  533. return function (value) {
  534. return !validator.isValidInt(value) && !validator.isConfigValueLink(value)
  535. ? Em.I18n.t('errorMessage.config.number.integer') : '';
  536. };
  537. case 'float':
  538. return function (value) {
  539. return !validator.isValidFloat(value) && !validator.isConfigValueLink(value)
  540. ? Em.I18n.t('errorMessage.config.number.float') : '';
  541. };
  542. case 'directories':
  543. case 'directory':
  544. return function (value, name) {
  545. if (App.config.isDirHeterogeneous(name)) {
  546. if (!validator.isValidDataNodeDir(value)) return Em.I18n.t('errorMessage.config.directory.heterogeneous');
  547. } else {
  548. if (!validator.isValidDir(value)) return Em.I18n.t('errorMessage.config.directory.default');
  549. }
  550. if (!validator.isAllowedDir(value)) {
  551. return Em.I18n.t('errorMessage.config.directory.allowed');
  552. }
  553. return validator.isNotTrimmedRight(value) ? Em.I18n.t('errorMessage.config.spaces.trailing') : '';
  554. };
  555. case 'email':
  556. return function (value) {
  557. return !validator.isValidEmail(value) ? Em.I18n.t('errorMessage.config.mail') : '';
  558. };
  559. case 'supportTextConnection':
  560. case 'host':
  561. return function (value) {
  562. return validator.isNotTrimmed(value) ? Em.I18n.t('errorMessage.config.spaces.trim') : '';
  563. };
  564. case 'password':
  565. return function (value, name, retypedPassword) {
  566. return value !== retypedPassword ? Em.I18n.t('errorMessage.config.password') : '';
  567. };
  568. case 'user':
  569. case 'database':
  570. case 'db_user':
  571. return function (value) {
  572. return !validator.isValidDbName(value) ? Em.I18n.t('errorMessage.config.user') : '';
  573. };
  574. case 'ldap_url':
  575. return function (value) {
  576. return !validator.isValidLdapsURL(value) ? Em.I18n.t('errorMessage.config.ldapUrl') : '';
  577. };
  578. default:
  579. return function (value, name) {
  580. if (['javax.jdo.option.ConnectionURL', 'oozie.service.JPAService.jdbc.url'].contains(name)
  581. && !validator.isConfigValueLink(value) && validator.isConfigValueLink(value)) {
  582. return Em.I18n.t('errorMessage.config.spaces.trim');
  583. } else {
  584. return validator.isNotTrimmedRight(value) ? Em.I18n.t('errorMessage.config.spaces.trailing') : '';
  585. }
  586. };
  587. }
  588. },
  589. /**
  590. * Returns warning validator function based on config type
  591. *
  592. * @param displayType
  593. * @returns {Function}
  594. */
  595. getWarningValidator: function(displayType) {
  596. switch (displayType) {
  597. case 'int':
  598. case 'float':
  599. return function (value, name, filename, stackConfigProperty, unitLabel) {
  600. stackConfigProperty = stackConfigProperty || App.configsCollection.getConfigByName(name, filename);
  601. var maximum = Em.get(stackConfigProperty || {}, 'valueAttributes.maximum'),
  602. minimum = Em.get(stackConfigProperty || {}, 'valueAttributes.minimum'),
  603. min = validator.isValidFloat(minimum) ? parseFloat(minimum) : NaN,
  604. max = validator.isValidFloat(maximum) ? parseFloat(maximum) : NaN,
  605. val = validator.isValidFloat(value) ? parseFloat(value) : NaN;
  606. if (!isNaN(val) && !isNaN(max) && val > max) {
  607. return Em.I18n.t('config.warnMessage.outOfBoundaries.greater').format(max + unitLabel);
  608. }
  609. if (!isNaN(val) && !isNaN(min) && val < min) {
  610. return Em.I18n.t('config.warnMessage.outOfBoundaries.less').format(min + unitLabel);
  611. }
  612. return '';
  613. };
  614. default:
  615. return function () { return ''; }
  616. }
  617. },
  618. /**
  619. * Defines if config support heterogeneous devices
  620. *
  621. * @param {string} name
  622. * @returns {boolean}
  623. */
  624. isDirHeterogeneous: function(name) {
  625. return ['dfs.datanode.data.dir'].contains(name);
  626. },
  627. /**
  628. * format property value depending on displayType
  629. * and one exception for 'kdc_type'
  630. * @param serviceConfigProperty
  631. * @param [originalValue]
  632. * @returns {*}
  633. */
  634. formatPropertyValue: function(serviceConfigProperty, originalValue) {
  635. var value = Em.isNone(originalValue) ? Em.get(serviceConfigProperty, 'value') : originalValue,
  636. displayType = Em.get(serviceConfigProperty, 'displayType') || Em.get(serviceConfigProperty, 'valueAttributes.type');
  637. if (Em.get(serviceConfigProperty, 'name') === 'kdc_type') {
  638. return App.router.get('mainAdminKerberosController.kdcTypesValues')[value];
  639. }
  640. if ( /^\s+$/.test("" + value)) {
  641. return " ";
  642. }
  643. switch (displayType) {
  644. case 'int':
  645. if (/\d+m$/.test(value) ) {
  646. return value.slice(0, value.length - 1);
  647. } else {
  648. var int = parseInt(value);
  649. return isNaN(int) ? "" : int.toString();
  650. }
  651. case 'float':
  652. var float = parseFloat(value);
  653. return isNaN(float) ? "" : float.toString();
  654. case 'componentHosts':
  655. if (typeof(value) == 'string') {
  656. return value.replace(/\[|]|'|&apos;/g, "").split(',');
  657. }
  658. return value;
  659. case 'content':
  660. case 'string':
  661. case 'multiLine':
  662. case 'directories':
  663. case 'directory':
  664. return this.trimProperty({ displayType: displayType, value: value });
  665. default:
  666. return value;
  667. }
  668. },
  669. /**
  670. * Format float value
  671. *
  672. * @param {*} value
  673. * @returns {string|*}
  674. */
  675. formatValue: function(value) {
  676. return validator.isValidFloat(value) ? parseFloat(value).toString() : value;
  677. },
  678. /**
  679. * Get step config by file name
  680. *
  681. * @param stepConfigs
  682. * @param fileName
  683. * @returns {Object|null}
  684. */
  685. getStepConfigForProperty: function (stepConfigs, fileName) {
  686. return stepConfigs.find(function (s) {
  687. return s.get('configTypes').contains(App.config.getConfigTagFromFileName(fileName));
  688. });
  689. },
  690. /**
  691. *
  692. * @param configs
  693. * @returns {Object[]}
  694. */
  695. sortConfigs: function(configs) {
  696. return configs.sort(function(a, b) {
  697. if (Em.get(a, 'index') > Em.get(b, 'index')) return 1;
  698. if (Em.get(a, 'index') < Em.get(b, 'index')) return -1;
  699. if (Em.get(a, 'name') > Em.get(b, 'name')) return 1;
  700. if (Em.get(a, 'name') < Em.get(b, 'name')) return -1;
  701. return 0;
  702. });
  703. },
  704. /**
  705. * create new ServiceConfig object by service name
  706. * @param {string} serviceName
  707. * @param {App.ServiceConfigGroup[]} [configGroups]
  708. * @param {App.ServiceConfigProperty[]} [configs]
  709. * @param {Number} [initConfigsLength]
  710. * @return {App.ServiceConfig}
  711. * @method createServiceConfig
  712. */
  713. createServiceConfig: function (serviceName, configGroups, configs, initConfigsLength) {
  714. var preDefinedServiceConfig = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', serviceName);
  715. return App.ServiceConfig.create({
  716. serviceName: preDefinedServiceConfig.get('serviceName'),
  717. displayName: preDefinedServiceConfig.get('displayName'),
  718. configCategories: preDefinedServiceConfig.get('configCategories'),
  719. configs: configs || [],
  720. configGroups: configGroups || [],
  721. initConfigsLength: initConfigsLength || 0
  722. });
  723. },
  724. /**
  725. * GETs all cluster level sites in one call.
  726. *
  727. * @return {$.ajax}
  728. */
  729. loadConfigsByTags: function (tags) {
  730. var urlParams = [];
  731. tags.forEach(function (_tag) {
  732. urlParams.push('(type=' + _tag.siteName + '&tag=' + _tag.tagName + ')');
  733. });
  734. var params = urlParams.join('|');
  735. return App.ajax.send({
  736. name: 'config.on_site',
  737. sender: this,
  738. data: {
  739. params: params
  740. }
  741. });
  742. },
  743. configTypesInfoMap: {},
  744. /**
  745. * Get config types and config type attributes from stack service
  746. *
  747. * @param service
  748. * @return {object}
  749. */
  750. getConfigTypesInfoFromService: function (service) {
  751. var configTypesInfoMap = this.get('configTypesInfoMap');
  752. if (configTypesInfoMap[service]) {
  753. // don't recalculate
  754. return configTypesInfoMap[service];
  755. }
  756. var configTypes = service.get('configTypes');
  757. var configTypesInfo = {
  758. items: [],
  759. supportsFinal: [],
  760. supportsAddingForbidden: []
  761. };
  762. if (configTypes) {
  763. for (var key in configTypes) {
  764. if (configTypes.hasOwnProperty(key)) {
  765. configTypesInfo.items.push(key);
  766. if (configTypes[key].supports && configTypes[key].supports.final === "true") {
  767. configTypesInfo.supportsFinal.push(key);
  768. }
  769. if (configTypes[key].supports && configTypes[key].supports.adding_forbidden === "true"){
  770. configTypesInfo.supportsAddingForbidden.push(key);
  771. }
  772. }
  773. }
  774. }
  775. configTypesInfoMap[service] = configTypesInfo;
  776. this.set('configTypesInfoMap', configTypesInfoMap);
  777. return configTypesInfo;
  778. },
  779. /**
  780. *
  781. * @param configs
  782. */
  783. addYarnCapacityScheduler: function(configs) {
  784. var value = '', savedValue = '', recommendedValue = '',
  785. excludedConfigs = App.config.getPropertiesFromTheme('YARN');
  786. var connectedConfigs = configs.filter(function(config) {
  787. return !excludedConfigs.contains(App.config.configId(config.get('name'), config.get('filename'))) && (config.get('filename') === 'capacity-scheduler.xml');
  788. });
  789. var names = connectedConfigs.mapProperty('name');
  790. connectedConfigs.forEach(function (config) {
  791. value += config.get('name') + '=' + config.get('value') + '\n';
  792. if (!Em.isNone(config.get('savedValue'))) {
  793. savedValue += config.get('name') + '=' + config.get('savedValue') + '\n';
  794. }
  795. if (!Em.isNone(config.get('recommendedValue'))) {
  796. recommendedValue += config.get('name') + '=' + config.get('recommendedValue') + '\n';
  797. }
  798. }, this);
  799. var isFinal = connectedConfigs.someProperty('isFinal', true);
  800. var savedIsFinal = connectedConfigs.someProperty('savedIsFinal', true);
  801. var recommendedIsFinal = connectedConfigs.someProperty('recommendedIsFinal', true);
  802. var cs = App.config.createDefaultConfig('capacity-scheduler', 'capacity-scheduler.xml', true, {
  803. 'value': value,
  804. 'serviceName': 'YARN',
  805. 'savedValue': savedValue || null,
  806. 'recommendedValue': recommendedValue || null,
  807. 'isFinal': isFinal,
  808. 'savedIsFinal': savedIsFinal,
  809. 'recommendedIsFinal': recommendedIsFinal,
  810. 'category': 'CapacityScheduler',
  811. 'displayName': 'Capacity Scheduler',
  812. 'description': 'Capacity Scheduler properties',
  813. 'displayType': 'capacityScheduler'
  814. });
  815. configs = configs.filter(function(c) {
  816. return !(names.contains(c.get('name')) && (c.get('filename') === 'capacity-scheduler.xml'));
  817. });
  818. configs.push(App.ServiceConfigProperty.create(cs));
  819. return configs;
  820. },
  821. /**
  822. *
  823. * @param serviceName
  824. * @returns {Array}
  825. */
  826. getPropertiesFromTheme: function (serviceName) {
  827. var properties = [];
  828. App.Tab.find().forEach(function (t) {
  829. if (!t.get('isAdvanced') && t.get('serviceName') === serviceName) {
  830. t.get('sections').forEach(function (s) {
  831. s.get('subSections').forEach(function (ss) {
  832. properties = properties.concat(ss.get('configProperties'));
  833. });
  834. });
  835. }
  836. }, this);
  837. return properties;
  838. },
  839. /**
  840. * transform one config with textarea content
  841. * into set of configs of file
  842. * @param configs
  843. * @param filename
  844. * @return {*}
  845. */
  846. textareaIntoFileConfigs: function (configs, filename) {
  847. var configsTextarea = configs.findProperty('name', 'capacity-scheduler');
  848. if (configsTextarea && !App.get('testMode')) {
  849. var properties = configsTextarea.get('value').split('\n');
  850. properties.forEach(function (_property) {
  851. var name, value;
  852. if (_property) {
  853. _property = _property.split('=');
  854. name = _property[0];
  855. value = (_property[1]) ? _property[1] : "";
  856. configs.push(Em.Object.create({
  857. name: name,
  858. value: value,
  859. savedValue: value,
  860. serviceName: configsTextarea.get('serviceName'),
  861. filename: filename,
  862. isFinal: configsTextarea.get('isFinal'),
  863. isNotDefaultValue: configsTextarea.get('isNotDefaultValue'),
  864. isRequiredByAgent: configsTextarea.get('isRequiredByAgent'),
  865. group: null
  866. }));
  867. }
  868. });
  869. return configs.without(configsTextarea);
  870. }
  871. return configs;
  872. },
  873. /**
  874. * trim trailing spaces for all properties.
  875. * trim both trailing and leading spaces for host displayType and hive/oozie datebases url.
  876. * for directory or directories displayType format string for further using.
  877. * for password and values with spaces only do nothing.
  878. * @param {Object} property
  879. * @returns {*}
  880. */
  881. trimProperty: function (property) {
  882. var displayType = Em.get(property, 'displayType');
  883. var value = Em.get(property, 'value');
  884. var name = Em.get(property, 'name');
  885. var rez;
  886. switch (displayType) {
  887. case 'directories':
  888. case 'directory':
  889. rez = value.replace(/,/g, ' ').trim().split(/\s+/g).join(',');
  890. break;
  891. case 'host':
  892. rez = value.trim();
  893. break;
  894. case 'password':
  895. break;
  896. default:
  897. if (name == 'javax.jdo.option.ConnectionURL' || name == 'oozie.service.JPAService.jdbc.url') {
  898. rez = value.trim();
  899. }
  900. rez = (typeof value == 'string') ? value.replace(/(\s+$)/g, '') : value;
  901. }
  902. return ((rez == '') || (rez == undefined)) ? value : rez;
  903. },
  904. /**
  905. * Generate minimal config property object used in *_properties.js files.
  906. * Example:
  907. * <code>
  908. * var someProperties = App.config.generateConfigPropertiesByName([
  909. * 'property_1', 'property_2', 'property_3'], { category: 'General', filename: 'myFileName'});
  910. * // someProperties contains Object[]
  911. * [
  912. * {
  913. * name: 'property_1',
  914. * displayName: 'property_1',
  915. * isVisible: true,
  916. * isReconfigurable: true,
  917. * category: 'General',
  918. * filename: 'myFileName'
  919. * },
  920. * .......
  921. * ]
  922. * </code>
  923. * @param {string[]} names
  924. * @param {Object} properties - additional properties which will merge with base object definition
  925. * @returns {object[]}
  926. * @method generateConfigPropertiesByName
  927. */
  928. generateConfigPropertiesByName: function (names, properties) {
  929. return names.map(function (item) {
  930. var baseObj = {
  931. name: item
  932. };
  933. if (properties) return $.extend(baseObj, properties);
  934. else return baseObj;
  935. });
  936. },
  937. /**
  938. * load cluster stack configs from server and run mapper
  939. * @returns {$.ajax}
  940. * @method loadConfigsFromStack
  941. */
  942. loadClusterConfigsFromStack: function () {
  943. return App.ajax.send({
  944. name: 'configs.stack_configs.load.cluster_configs',
  945. sender: this,
  946. data: {
  947. stackVersionUrl: App.get('stackVersionURL')
  948. },
  949. success: 'saveConfigsToModel'
  950. });
  951. },
  952. /**
  953. * load stack configs from server and run mapper
  954. * @param {String[]} [serviceNames=null]
  955. * @returns {$.ajax}
  956. * @method loadConfigsFromStack
  957. */
  958. loadConfigsFromStack: function (serviceNames) {
  959. serviceNames = serviceNames || [];
  960. var name = serviceNames.length > 0 ? 'configs.stack_configs.load.services' : 'configs.stack_configs.load.all';
  961. return App.ajax.send({
  962. name: name,
  963. sender: this,
  964. data: {
  965. stackVersionUrl: App.get('stackVersionURL'),
  966. serviceList: serviceNames.join(',')
  967. },
  968. success: 'saveConfigsToModel'
  969. });
  970. },
  971. /**
  972. * Runs <code>stackConfigPropertiesMapper<code>
  973. * @param {object} data
  974. * @method saveConfigsToModel
  975. */
  976. saveConfigsToModel: function (data) {
  977. App.stackConfigPropertiesMapper.map(data);
  978. },
  979. /**
  980. * Check if config filename supports final attribute
  981. * @param serviceName
  982. * @param filename
  983. * @returns {boolean}
  984. */
  985. shouldSupportFinal: function (serviceName, filename) {
  986. var unsupportedServiceNames = ['MISC', 'Cluster'];
  987. if (!serviceName || unsupportedServiceNames.contains(serviceName) || !filename) {
  988. return false;
  989. } else {
  990. var stackService = App.StackService.find(serviceName);
  991. if (!stackService) {
  992. return false;
  993. }
  994. return !!this.getConfigTypesInfoFromService(stackService).supportsFinal.find(function (configType) {
  995. return filename.startsWith(configType);
  996. });
  997. }
  998. },
  999. shouldSupportAddingForbidden: function(serviceName, filename) {
  1000. var unsupportedServiceNames = ['MISC', 'Cluster'];
  1001. if (!serviceName || unsupportedServiceNames.contains(serviceName) || !filename) {
  1002. return false;
  1003. } else {
  1004. var stackServiceName = App.StackService.find().findProperty('serviceName', serviceName);
  1005. if (!stackServiceName) {
  1006. return false;
  1007. }
  1008. var stackService = App.StackService.find(serviceName);
  1009. return !!this.getConfigTypesInfoFromService(stackService).supportsAddingForbidden.find(function (configType) {
  1010. return filename.startsWith(configType);
  1011. });
  1012. }
  1013. },
  1014. /**
  1015. * Remove all ranger-related configs, that should be available only if Ranger is installed
  1016. * @param configs - stepConfigs object
  1017. */
  1018. removeRangerConfigs: function (configs) {
  1019. configs.forEach(function (service) {
  1020. var filteredConfigs = [];
  1021. service.get('configs').forEach(function (config) {
  1022. if (!/^ranger-/.test(config.get('filename'))) {
  1023. filteredConfigs.push(config);
  1024. }
  1025. });
  1026. service.set('configs', filteredConfigs);
  1027. var filteredCategories = [];
  1028. service.get('configCategories').forEach(function (category) {
  1029. if (!/ranger-/.test(category.get('name'))) {
  1030. filteredCategories.push(category);
  1031. }
  1032. });
  1033. service.set('configCategories', filteredCategories);
  1034. });
  1035. },
  1036. /**
  1037. * Create config with non default config group. Some custom config properties
  1038. * can be created and assigned to non-default config group.
  1039. *
  1040. * @param {Em.Object} override - config value
  1041. * @param {Em.Object} configGroup - config group to set
  1042. * @return {Object}
  1043. **/
  1044. createCustomGroupConfig: function (override, configGroup) {
  1045. App.assertObject(override);
  1046. App.assertEmberObject(configGroup);
  1047. var newOverride = App.ServiceConfigProperty.create(this.createDefaultConfig(override.propertyName, override.filename, false, override));
  1048. newOverride.setProperties({
  1049. 'isOriginalSCP': false,
  1050. 'overrides': null,
  1051. 'group': configGroup,
  1052. 'parentSCP': null
  1053. });
  1054. if (!configGroup.get('properties.length')) {
  1055. configGroup.set('properties', Em.A([]));
  1056. }
  1057. configGroup.set('properties', configGroup.get('properties').concat(newOverride));
  1058. return newOverride;
  1059. },
  1060. /**
  1061. * @param {App.ServiceConfigProperty} serviceConfigProperty
  1062. * @param {Object} override - plain object with properties that is different from parent SCP
  1063. * @param {App.ServiceConfigGroup} configGroup
  1064. * @returns {App.ServiceConfigProperty}
  1065. */
  1066. createOverride: function(serviceConfigProperty, override, configGroup) {
  1067. App.assertObject(serviceConfigProperty);
  1068. App.assertEmberObject(configGroup);
  1069. if (Em.isNone(serviceConfigProperty.get('overrides'))) serviceConfigProperty.set('overrides', []);
  1070. var newOverride = App.ServiceConfigProperty.create(serviceConfigProperty);
  1071. newOverride.setProperties({ 'savedValue': null, 'savedIsFinal': null });
  1072. if (!Em.isNone(override)) {
  1073. for (var key in override) {
  1074. newOverride.set(key, override[key]);
  1075. }
  1076. }
  1077. newOverride.setProperties({
  1078. 'isOriginalSCP': false,
  1079. 'overrides': null,
  1080. 'group': configGroup,
  1081. 'parentSCP': serviceConfigProperty
  1082. });
  1083. if (!configGroup.get('properties.length')) {
  1084. configGroup.set('properties', Em.A([]));
  1085. }
  1086. configGroup.set('properties', configGroup.get('properties').concat(newOverride));
  1087. serviceConfigProperty.get('overrides').pushObject(newOverride);
  1088. var savedOverrides = serviceConfigProperty.get('overrides').filterProperty('savedValue');
  1089. serviceConfigProperty.set('overrideValues', savedOverrides.mapProperty('savedValue'));
  1090. serviceConfigProperty.set('overrideIsFinalValues', savedOverrides.mapProperty('savedIsFinal'));
  1091. return newOverride;
  1092. },
  1093. /**
  1094. * Merge values in "stored" to "base" if name matches, it's a value only merge.
  1095. * @param base {Array} Em.Object
  1096. * @param stored {Array} Object
  1097. */
  1098. mergeStoredValue: function(base, stored) {
  1099. if (stored) {
  1100. base.forEach(function (p) {
  1101. var sp = stored.filterProperty("filename", p.filename).findProperty("name", p.name);
  1102. if (sp) {
  1103. p.set("value", sp.value);
  1104. }
  1105. });
  1106. }
  1107. },
  1108. /**
  1109. * Helper method to get property from the <code>stepConfigs</code>
  1110. *
  1111. * @param {String} name - config property name
  1112. * @param {String} fileName - config property filename
  1113. * @param {Object[]} stepConfigs
  1114. * @return {App.ServiceConfigProperty|Boolean} - App.ServiceConfigProperty instance or <code>false</code> when property not found
  1115. */
  1116. findConfigProperty: function(stepConfigs, name, fileName) {
  1117. if (!name && !fileName) return false;
  1118. if (stepConfigs && stepConfigs.length) {
  1119. return stepConfigs.mapProperty('configs').filter(function(item) {
  1120. return item.length;
  1121. }).reduce(function(p, c) {
  1122. if (p) {
  1123. return p.concat(c);
  1124. }
  1125. }).filterProperty('filename', fileName).findProperty('name', name);
  1126. }
  1127. return false;
  1128. },
  1129. /**
  1130. * creates config object with non static properties like
  1131. * 'value', 'isFinal', 'errorMessage' and
  1132. * 'id', 'name', 'filename',
  1133. * @param configProperty
  1134. * @returns {Object}
  1135. */
  1136. createMinifiedConfig: function (configProperty) {
  1137. if (configProperty instanceof Ember.Object) {
  1138. return configProperty.getProperties('name', 'filename', 'serviceName', 'value', 'isFinal');
  1139. }
  1140. return {
  1141. name: configProperty.name,
  1142. filename: configProperty.filename,
  1143. serviceName: configProperty.serviceName,
  1144. value: configProperty.value,
  1145. isFinal: configProperty.isFinal
  1146. }
  1147. },
  1148. /**
  1149. * Update config property value based on its current value and list of zookeeper server hosts.
  1150. * Used to prevent sort order issues.
  1151. * <code>siteConfigs</code> object formatted according server's persist format e.g.
  1152. *
  1153. * <code>
  1154. * {
  1155. * 'yarn-site': {
  1156. * 'property_name1': 'property_value1'
  1157. * 'property_name2': 'property_value2'
  1158. * .....
  1159. * }
  1160. * }
  1161. * </code>
  1162. *
  1163. * @method updateHostsListValue
  1164. * @param {Object} siteConfigs - prepared site config object to store
  1165. * @param {String} propertyName - name of the property to update
  1166. * @param {String} hostsList - list of ZooKeeper Server names to set as config property value
  1167. * @return {String} - result value
  1168. */
  1169. updateHostsListValue: function(siteConfigs, propertyName, hostsList) {
  1170. var value = hostsList;
  1171. var propertyHosts = (siteConfigs[propertyName] || '').split(',');
  1172. var hostsToSet = hostsList.split(',');
  1173. if (!Em.isEmpty(siteConfigs[propertyName])) {
  1174. var diffLength = propertyHosts.filter(function(hostName) {
  1175. return !hostsToSet.contains(hostName);
  1176. }).length;
  1177. if (diffLength == 0 && propertyHosts.length == hostsToSet.length) {
  1178. value = siteConfigs[propertyName];
  1179. }
  1180. }
  1181. siteConfigs[propertyName] = value;
  1182. return value;
  1183. },
  1184. /**
  1185. * Load cluster-env configs mapped to array
  1186. * @return {*|{then}}
  1187. */
  1188. getClusterEnvConfigs: function () {
  1189. var dfd = $.Deferred();
  1190. App.ajax.send({
  1191. name: 'config.cluster_env_site',
  1192. sender: this
  1193. }).done(function (data) {
  1194. App.router.get('configurationController').getConfigsByTags([{
  1195. siteName: data.items[data.items.length - 1].type,
  1196. tagName: data.items[data.items.length - 1].tag
  1197. }]).done(function (clusterEnvConfigs) {
  1198. var configsObject = clusterEnvConfigs[0].properties;
  1199. var configsArray = [];
  1200. for (var property in configsObject) {
  1201. if (configsObject.hasOwnProperty(property)) {
  1202. configsArray.push(Em.Object.create({
  1203. name: property,
  1204. value: configsObject[property],
  1205. filename: 'cluster-env.xml'
  1206. }));
  1207. }
  1208. }
  1209. dfd.resolve(configsArray);
  1210. });
  1211. });
  1212. return dfd.promise();
  1213. }
  1214. });