config_test.js 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007
  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('config');
  20. require('utils/configs_collection');
  21. require('utils/config');
  22. require('models/service/hdfs');
  23. var setups = require('test/init_model_test');
  24. describe('App.config', function () {
  25. describe('#trimProperty',function() {
  26. var testMessage = 'displayType `{0}`, value `{1}`{3} should return `{2}`';
  27. var tests = [
  28. {
  29. config: {
  30. displayType: 'directory',
  31. value: ' /a /b /c'
  32. },
  33. e: '/a,/b,/c'
  34. },
  35. {
  36. config: {
  37. displayType: 'directories',
  38. value: ' /a /b '
  39. },
  40. e: '/a,/b'
  41. },
  42. {
  43. config: {
  44. displayType: 'directories',
  45. name: 'dfs.datanode.data.dir',
  46. value: ' [DISK]/a [SSD]/b '
  47. },
  48. e: '[DISK]/a,[SSD]/b'
  49. },
  50. {
  51. config: {
  52. displayType: 'directories',
  53. name: 'dfs.datanode.data.dir',
  54. value: '/a,/b, /c\n/d,\n/e /f'
  55. },
  56. e: '/a,/b,/c,/d,/e,/f'
  57. },
  58. {
  59. config: {
  60. displayType: 'host',
  61. value: ' localhost '
  62. },
  63. e: 'localhost'
  64. },
  65. {
  66. config: {
  67. displayType: 'password',
  68. value: ' passw ord '
  69. },
  70. e: ' passw ord '
  71. },
  72. {
  73. config: {
  74. displayType: 'string',
  75. value: ' value'
  76. },
  77. e: ' value'
  78. },
  79. {
  80. config: {
  81. displayType: 'string',
  82. value: ' value'
  83. },
  84. e: ' value'
  85. },
  86. {
  87. config: {
  88. displayType: 'string',
  89. value: 'http://localhost ',
  90. name: 'javax.jdo.option.ConnectionURL'
  91. },
  92. e: 'http://localhost'
  93. },
  94. {
  95. config: {
  96. displayType: 'string',
  97. value: 'http://localhost ',
  98. name: 'oozie.service.JPAService.jdbc.url'
  99. },
  100. e: 'http://localhost'
  101. },
  102. {
  103. config: {
  104. displayType: 'custom',
  105. value: ' custom value '
  106. },
  107. e: ' custom value'
  108. },
  109. {
  110. config: {
  111. displayType: 'componentHosts',
  112. value: ['host1.com', 'host2.com']
  113. },
  114. e: ['host1.com', 'host2.com']
  115. }
  116. ];
  117. tests.forEach(function(test) {
  118. it(testMessage.format(test.config.displayType, test.config.value, test.e, !!test.config.name ? ', name `' + test.config.name + '`' : ''), function() {
  119. expect(App.config.trimProperty(test.config)).to.eql(test.e);
  120. expect(App.config.trimProperty(Em.Object.create(test.config), true)).to.eql(test.e);
  121. });
  122. });
  123. });
  124. describe('#mapCustomStack', function() {
  125. before(function() {
  126. setups.setupStackVersion(this, 'HDF-2.2');
  127. });
  128. it('versions of HDF > 2.0 should map with HDP 2.3 stack based property definitions', function() {
  129. var baseStackFolder = App.config.mapCustomStack();
  130. expect(baseStackFolder).to.equal("HDP2.3");
  131. });
  132. it('versions of HDF = 2.0 should map with HDP 2.3 stack based property definitions', function() {
  133. App.set('currentStackVersion', 'HDF-2.0');
  134. var baseStackFolder = App.config.mapCustomStack();
  135. expect(baseStackFolder).to.equal("HDP2.3");
  136. });
  137. after(function() {
  138. setups.restoreStackVersion(this);
  139. });
  140. });
  141. describe('#preDefinedConfigFile', function() {
  142. before(function() {
  143. setups.setupStackVersion(this, 'BIGTOP-0.8');
  144. });
  145. it('bigtop site properties should be ok.', function() {
  146. var bigtopSiteProperties = App.config.preDefinedConfigFile('BIGTOP', 'site_properties');
  147. expect(bigtopSiteProperties).to.be.ok;
  148. });
  149. it('a non-existing file should not be ok.', function () {
  150. var notExistingSiteProperty = App.config.preDefinedConfigFile('notExisting');
  151. expect(notExistingSiteProperty).to.not.be.ok;
  152. });
  153. after(function() {
  154. setups.restoreStackVersion(this);
  155. });
  156. });
  157. describe('#preDefinedSiteProperties-bigtop', function () {
  158. before(function() {
  159. setups.setupStackVersion(this, 'BIGTOP-0.8');
  160. });
  161. it('bigtop should use New PostgreSQL Database as its default hive metastore database', function () {
  162. App.StackService.createRecord({serviceName: 'HIVE'});
  163. expect(App.config.get('preDefinedSiteProperties').findProperty('recommendedValue', 'New PostgreSQL Database')).to.be.ok;
  164. });
  165. after(function() {
  166. setups.restoreStackVersion(this);
  167. });
  168. });
  169. describe('#generateConfigPropertiesByName', function() {
  170. var tests = [
  171. {
  172. names: ['property_1', 'property_2'],
  173. properties: undefined,
  174. e: {
  175. keys: ['name']
  176. },
  177. m: 'Should generate base property object without additional fields'
  178. },
  179. {
  180. names: ['property_1', 'property_2'],
  181. properties: { category: 'SomeCat', serviceName: 'SERVICE_NAME' },
  182. e: {
  183. keys: ['name', 'category', 'serviceName']
  184. },
  185. m: 'Should generate base property object without additional fields'
  186. }
  187. ];
  188. tests.forEach(function(test) {
  189. it(test.m, function() {
  190. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).length).to.eql(test.names.length);
  191. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).map(function(property) {
  192. return Em.keys(property);
  193. }).reduce(function(p, c) {
  194. return p.concat(c);
  195. }).uniq()).to.eql(test.e.keys);
  196. });
  197. });
  198. });
  199. describe('#setPreDefinedServiceConfigs', function() {
  200. beforeEach(function() {
  201. sinon.stub(App.StackService, 'find', function() {
  202. return [
  203. Em.Object.create({
  204. id: 'HDFS',
  205. serviceName: 'HDFS',
  206. configTypes: {
  207. 'hadoop-env': {},
  208. 'hdfs-site': {}
  209. }
  210. }),
  211. Em.Object.create({
  212. id: 'OOZIE',
  213. serviceName: 'OOZIE',
  214. configTypes: {
  215. 'oozie-env': {},
  216. 'oozie-site': {}
  217. }
  218. })
  219. ];
  220. });
  221. App.config.setPreDefinedServiceConfigs(true);
  222. });
  223. afterEach(function() {
  224. App.StackService.find.restore();
  225. });
  226. it('should include service MISC', function() {
  227. expect(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC')).to.be.ok;
  228. });
  229. it('should include -env config types according to stack services', function() {
  230. var miscCategory = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC');
  231. expect(Em.keys(miscCategory.get('configTypes'))).to.eql(['cluster-env', 'hadoop-env', 'oozie-env']);
  232. });
  233. });
  234. describe('#isManagedMySQLForHiveAllowed', function () {
  235. var cases = [
  236. {
  237. osFamily: 'redhat5',
  238. expected: false
  239. },
  240. {
  241. osFamily: 'redhat6',
  242. expected: true
  243. },
  244. {
  245. osFamily: 'suse11',
  246. expected: false
  247. }
  248. ],
  249. title = 'should be {0} for {1}';
  250. cases.forEach(function (item) {
  251. it(title.format(item.expected, item.osFamily), function () {
  252. expect(App.config.isManagedMySQLForHiveAllowed(item.osFamily)).to.equal(item.expected);
  253. });
  254. });
  255. });
  256. describe('#shouldSupportFinal', function () {
  257. var cases = [
  258. {
  259. shouldSupportFinal: false,
  260. title: 'no service name specified'
  261. },
  262. {
  263. serviceName: 's0',
  264. shouldSupportFinal: false,
  265. title: 'no filename specified'
  266. },
  267. {
  268. serviceName: 'MISC',
  269. shouldSupportFinal: false,
  270. title: 'MISC'
  271. },
  272. {
  273. serviceName: 's0',
  274. filename: 's0-site',
  275. shouldSupportFinal: true,
  276. title: 'final attribute supported'
  277. },
  278. {
  279. serviceName: 's0',
  280. filename: 's0-env',
  281. shouldSupportFinal: false,
  282. title: 'final attribute not supported'
  283. },
  284. {
  285. serviceName: 'Cluster',
  286. filename: 'krb5-conf.xml',
  287. shouldSupportFinal: false,
  288. title: 'kerberos descriptor identities don\'t support final'
  289. }
  290. ];
  291. beforeEach(function () {
  292. sinon.stub(App.StackService, 'find').returns([
  293. {
  294. serviceName: 's0'
  295. }
  296. ]);
  297. sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({
  298. supportsFinal: ['s0-site']
  299. });
  300. });
  301. afterEach(function () {
  302. App.StackService.find.restore();
  303. App.config.getConfigTypesInfoFromService.restore();
  304. });
  305. cases.forEach(function (item) {
  306. it(item.title, function () {
  307. expect(App.config.shouldSupportFinal(item.serviceName, item.filename)).to.equal(item.shouldSupportFinal);
  308. });
  309. });
  310. });
  311. describe('#shouldSupportAddingForbidden', function () {
  312. var cases = [
  313. {
  314. shouldSupportAddingForbidden: false,
  315. title: 'no service name specified'
  316. },
  317. {
  318. serviceName: 's0',
  319. shouldSupportAddingForbidden: false,
  320. title: 'no filename specified'
  321. },
  322. {
  323. serviceName: 'MISC',
  324. shouldSupportAddingForbidden: false,
  325. title: 'MISC'
  326. },
  327. {
  328. serviceName: 's0',
  329. filename: 's0-site',
  330. shouldSupportAddingForbidden: true,
  331. title: 'adding forbidden supported'
  332. },
  333. {
  334. serviceName: 's0',
  335. filename: 's0-properties',
  336. shouldSupportAddingForbidden: false,
  337. title: 'adding forbidden not supported'
  338. }
  339. ];
  340. beforeEach(function () {
  341. sinon.stub(App.StackService, 'find').returns([
  342. Em.Object.create({
  343. serviceName: 's0',
  344. configTypes: {
  345. 's0-size': {},
  346. 's0-properties': {}
  347. }
  348. })
  349. ]);
  350. sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({
  351. supportsAddingForbidden: ['s0-site']
  352. });
  353. });
  354. afterEach(function () {
  355. App.StackService.find.restore();
  356. App.config.getConfigTypesInfoFromService.restore();
  357. });
  358. cases.forEach(function (item) {
  359. it(item.title, function () {
  360. expect(App.config.shouldSupportAddingForbidden(item.serviceName, item.filename)).to.equal(item.shouldSupportAddingForbidden);
  361. });
  362. });
  363. });
  364. describe('#removeRangerConfigs', function () {
  365. it('should remove ranger configs and categories', function () {
  366. var configs = [
  367. Em.Object.create({
  368. configs: [
  369. Em.Object.create({filename: 'filename'}),
  370. Em.Object.create({filename: 'ranger-filename'})
  371. ],
  372. configCategories: [
  373. Em.Object.create({name: 'ranger-name'}),
  374. Em.Object.create({name: 'name'}),
  375. Em.Object.create({name: 'also-ranger-name'})
  376. ]
  377. })
  378. ];
  379. App.config.removeRangerConfigs(configs);
  380. expect(configs).eql(
  381. [
  382. Em.Object.create({
  383. configs: [
  384. Em.Object.create({filename: 'filename'})
  385. ],
  386. configCategories: [
  387. Em.Object.create({name: 'name'})
  388. ]
  389. })
  390. ]
  391. );
  392. });
  393. });
  394. describe("#createOverride", function() {
  395. var template = {
  396. name: "p1",
  397. filename: "f1",
  398. value: "v1",
  399. recommendedValue: "rv1",
  400. savedValue: "sv1",
  401. isFinal: true,
  402. recommendedIsFinal: false,
  403. savedIsFinal: true
  404. };
  405. var configProperty = App.ServiceConfigProperty.create(template);
  406. var group = Em.Object.create({name: "group1", properties: []});
  407. Object.keys(template).forEach(function (key) {
  408. it(key, function () {
  409. var override = App.config.createOverride(configProperty, {}, group);
  410. if (['savedValue', 'savedIsFinal'].contains(key)) {
  411. expect(override.get(key)).to.equal(null);
  412. } else {
  413. expect(override.get(key)).to.equal(template[key]);
  414. }
  415. });
  416. });
  417. describe('overrides some values that should be different for override', function() {
  418. var override;
  419. beforeEach(function () {
  420. override = App.config.createOverride(configProperty, {}, group);
  421. });
  422. it('isOriginalSCP is false', function () {
  423. expect(override.get('isOriginalSCP')).to.be.false;
  424. });
  425. it('overrides is null', function () {
  426. expect(override.get('overrides')).to.be.null;
  427. });
  428. it('group is valid', function () {
  429. expect(override.get('group')).to.eql(group);
  430. });
  431. it('parentSCP is valid', function () {
  432. expect(override.get('parentSCP')).to.eql(configProperty);
  433. });
  434. });
  435. var overriddenTemplate = {
  436. value: "v2",
  437. recommendedValue: "rv2",
  438. savedValue: "sv2",
  439. isFinal: true,
  440. recommendedIsFinal: false,
  441. savedIsFinal: true
  442. };
  443. Object.keys(overriddenTemplate).forEach(function (key) {
  444. it('overrides some specific values `' + key + '`', function () {
  445. var override = App.config.createOverride(configProperty, overriddenTemplate, group);
  446. expect(override.get(key)).to.equal(overriddenTemplate[key]);
  447. });
  448. });
  449. it('throws error due to undefined configGroup', function() {
  450. expect(App.config.createOverride.bind(App.config, configProperty, {}, null)).to.throw(App.EmberObjectTypeError);
  451. });
  452. it('throws error due to undefined originalSCP', function() {
  453. expect(App.config.createOverride.bind(App.config, null, {}, group)).to.throw(App.ObjectTypeError);
  454. });
  455. describe('updates originalSCP object ', function() {
  456. var overridenTemplate2;
  457. var override;
  458. beforeEach(function () {
  459. configProperty.set('overrides', null);
  460. configProperty.set('overrideValues', []);
  461. configProperty.set('overrideIsFinalValues', []);
  462. overridenTemplate2 = {
  463. value: "v12",
  464. recommendedValue: "rv12",
  465. savedValue: "sv12",
  466. isFinal: true,
  467. recommendedIsFinal: false,
  468. savedIsFinal: false
  469. };
  470. override = App.config.createOverride(configProperty, overridenTemplate2, group);
  471. });
  472. it('overrides.0 is valid', function () {
  473. expect(configProperty.get('overrides')[0]).to.be.eql(override);
  474. });
  475. it('overrideValues is valid', function () {
  476. expect(configProperty.get('overrideValues')).to.be.eql([overridenTemplate2.savedValue]);
  477. });
  478. it('overrideIsFinalValues is valid', function () {
  479. expect(configProperty.get('overrideIsFinalValues')).to.be.eql([overridenTemplate2.savedIsFinal]);
  480. });
  481. });
  482. });
  483. describe('#getIsSecure', function() {
  484. var secureConfigs = App.config.get('secureConfigs');
  485. before(function() {
  486. App.config.set('secureConfigs', [{name: 'secureConfig'}]);
  487. });
  488. after(function() {
  489. App.config.set('secureConfigs', secureConfigs);
  490. });
  491. it('config is secure', function() {
  492. expect(App.config.getIsSecure('secureConfig')).to.equal(true);
  493. });
  494. it('config is not secure', function() {
  495. expect(App.config.getIsSecure('NotSecureConfig')).to.equal(false);
  496. });
  497. });
  498. describe('#getDefaultCategory', function() {
  499. it('returns custom category', function() {
  500. expect(App.config.getDefaultCategory(null, 'filename.xml')).to.equal('Custom filename');
  501. });
  502. it('returns advanced category', function() {
  503. expect(App.config.getDefaultCategory(Em.Object.create, 'filename.xml')).to.equal('Advanced filename');
  504. });
  505. });
  506. describe('#getDefaultDisplayType', function() {
  507. it('returns singleLine displayType', function() {
  508. expect(App.config.getDefaultDisplayType('v1')).to.equal('string');
  509. });
  510. it('returns multiLine displayType', function() {
  511. expect(App.config.getDefaultDisplayType('v1\nv2')).to.equal('multiLine');
  512. });
  513. });
  514. describe('#formatValue', function() {
  515. it('formatValue for componentHosts', function () {
  516. var serviceConfigProperty = Em.Object.create({'displayType': 'componentHosts', value: "['h1','h2']"});
  517. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.eql(['h1','h2']);
  518. });
  519. it('formatValue for int', function () {
  520. var serviceConfigProperty = Em.Object.create({'displayType': 'int', value: '4.0'});
  521. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('4');
  522. });
  523. it('formatValue for int with m', function () {
  524. var serviceConfigProperty = Em.Object.create({'displayType': 'int', value: '4m'});
  525. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('4');
  526. });
  527. it('formatValue for float', function () {
  528. var serviceConfigProperty = Em.Object.create({'displayType': 'float', value: '0.40'});
  529. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('0.4');
  530. });
  531. it('formatValue for kdc_type', function () {
  532. var serviceConfigProperty = Em.Object.create({'name': 'kdc_type', value: 'mit-kdc'});
  533. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal(Em.I18n.t('admin.kerberos.wizard.step1.option.kdc'));
  534. });
  535. it('don\'t format value', function () {
  536. var serviceConfigProperty = Em.Object.create({'name': 'any', displayType: 'any', value: 'any'});
  537. expect(App.config.formatPropertyValue(serviceConfigProperty)).to.equal('any');
  538. });
  539. });
  540. describe('#getPropertyIfExists', function() {
  541. [
  542. {
  543. propertyName: 'someProperty',
  544. defaultValue: 'default',
  545. firstObject: { someProperty: '1' },
  546. secondObject: { someProperty: '2' },
  547. res: '1',
  548. m: 'use value from first object'
  549. },
  550. {
  551. propertyName: 'someProperty',
  552. defaultValue: 'default',
  553. firstObject: { someOtherProperty: '1' },
  554. secondObject: { someProperty: '2' },
  555. res: '2',
  556. m: 'use value from second object'
  557. },
  558. {
  559. propertyName: 'someProperty',
  560. defaultValue: 'default',
  561. firstObject: { someOtherProperty: '1' },
  562. secondObject: { someOtherProperty: '2' },
  563. res: 'default',
  564. m: 'use default value'
  565. },
  566. {
  567. propertyName: 'someProperty',
  568. defaultValue: 'default',
  569. res: 'default',
  570. m: 'use default value'
  571. },
  572. {
  573. propertyName: 'someProperty',
  574. defaultValue: true,
  575. firstObject: { someProperty: false },
  576. secondObject: { someProperty: true },
  577. res: false,
  578. m: 'use value from first object, check booleans'
  579. },
  580. {
  581. propertyName: 'someProperty',
  582. defaultValue: true,
  583. firstObject: { someProperty: 0 },
  584. secondObject: { someProperty: 1 },
  585. res: 0,
  586. m: 'use value from first object, check 0'
  587. },
  588. {
  589. propertyName: 'someProperty',
  590. defaultValue: true,
  591. firstObject: { someProperty: '' },
  592. secondObject: { someProperty: '1' },
  593. res: '',
  594. m: 'use value from first object, check empty string'
  595. }
  596. ].forEach(function (t) {
  597. it(t.m, function () {
  598. expect(App.config.getPropertyIfExists(t.propertyName, t.defaultValue, t.firstObject, t.secondObject)).to.equal(t.res);
  599. })
  600. });
  601. });
  602. describe('#createDefaultConfig', function() {
  603. before(function() {
  604. sinon.stub(App.config, 'getDefaultDisplayType', function() {
  605. return 'pDisplayType';
  606. });
  607. sinon.stub(App.config, 'getDefaultCategory', function() {
  608. return 'pCategory';
  609. });
  610. sinon.stub(App.config, 'getIsSecure', function() {
  611. return false;
  612. });
  613. sinon.stub(App.config, 'shouldSupportFinal', function() {
  614. return true;
  615. });
  616. sinon.stub(App.config, 'get', function(param) {
  617. if (param === 'serviceByConfigTypeMap') {
  618. return { 'pFileName': Em.Object.create({serviceName: 'pServiceName' }) };
  619. }
  620. return Em.get(App.config, param);
  621. });
  622. });
  623. after(function() {
  624. App.config.getDefaultDisplayType.restore();
  625. App.config.getDefaultCategory.restore();
  626. App.config.getIsSecure.restore();
  627. App.config.shouldSupportFinal.restore();
  628. App.config.get.restore();
  629. });
  630. var res = {
  631. /** core properties **/
  632. id: 'pName__pFileName',
  633. name: 'pName',
  634. filename: 'pFileName.xml',
  635. value: '',
  636. savedValue: null,
  637. isFinal: false,
  638. savedIsFinal: null,
  639. /** UI and Stack properties **/
  640. recommendedValue: null,
  641. recommendedIsFinal: null,
  642. supportsFinal: true,
  643. supportsAddingForbidden: false,
  644. serviceName: 'pServiceName',
  645. displayName: 'pName',
  646. displayType: 'pDisplayType',
  647. description: '',
  648. category: 'pCategory',
  649. isSecureConfig: false,
  650. showLabel: true,
  651. isVisible: true,
  652. isUserProperty: false,
  653. isRequired: true,
  654. group: null,
  655. isRequiredByAgent: true,
  656. isReconfigurable: true,
  657. unit: null,
  658. hasInitialValue: false,
  659. isOverridable: true,
  660. index: Infinity,
  661. dependentConfigPattern: null,
  662. options: null,
  663. radioName: null,
  664. widgetType: null,
  665. errorMessage: '',
  666. warnMessage: ''
  667. };
  668. it('create default config object', function () {
  669. expect(App.config.createDefaultConfig('pName', 'pFileName', true)).to.eql(res);
  670. });
  671. it('getDefaultDisplayType is called', function() {
  672. expect(App.config.getDefaultDisplayType.called).to.be.true;
  673. });
  674. it('getDefaultCategory is called with correct arguments', function() {
  675. expect(App.config.getDefaultCategory.calledWith(true, 'pFileName')).to.be.true;
  676. });
  677. it('getIsSecure is called with correct arguments', function() {
  678. expect(App.config.getIsSecure.calledWith('pName')).to.be.true;
  679. });
  680. it('shouldSupportFinal is called with correct arguments', function() {
  681. expect(App.config.shouldSupportFinal.calledWith('pServiceName', 'pFileName')).to.be.true;
  682. });
  683. });
  684. describe('#mergeStackConfigsWithUI', function() {
  685. beforeEach(function() {
  686. sinon.stub(App.config, 'getPropertyIfExists', function(key, value) {return 'res_' + value});
  687. });
  688. afterEach(function() {
  689. App.config.getPropertyIfExists.restore();
  690. });
  691. var template = {
  692. name: 'pName',
  693. filename: 'pFileName',
  694. value: 'pValue',
  695. savedValue: 'pValue',
  696. isFinal: true,
  697. savedIsFinal: true,
  698. serviceName: 'pServiceName',
  699. displayName: 'pDisplayName',
  700. displayType: 'pDisplayType',
  701. category: 'pCategory'
  702. };
  703. var result = {
  704. name: 'pName',
  705. filename: 'pFileName',
  706. value: 'pValue',
  707. savedValue: 'pValue',
  708. isFinal: true,
  709. savedIsFinal: true,
  710. serviceName: 'res_pServiceName',
  711. displayName: 'res_pDisplayName',
  712. displayType: 'res_pDisplayType',
  713. category: 'res_pCategory'
  714. };
  715. it('called generate property object', function () {
  716. expect(App.config.mergeStaticProperties(template, {}, {})).to.eql(result);
  717. });
  718. });
  719. describe('#updateHostsListValue', function() {
  720. var tests = [
  721. {
  722. siteConfigs: {
  723. 'hadoop.registry.zk.quorum': 'host1,host2'
  724. },
  725. propertyName: 'hadoop.registry.zk.quorum',
  726. hostsList: 'host1',
  727. e: 'host1'
  728. },
  729. {
  730. siteConfigs: {
  731. 'hadoop.registry.zk.quorum': 'host1:10,host2:10'
  732. },
  733. propertyName: 'hadoop.registry.zk.quorum',
  734. hostsList: 'host2:10,host1:10',
  735. e: 'host1:10,host2:10'
  736. },
  737. {
  738. siteConfigs: {
  739. 'hadoop.registry.zk.quorum': 'host1:10,host2:10,host3:10'
  740. },
  741. propertyName: 'hadoop.registry.zk.quorum',
  742. hostsList: 'host2:10,host1:10',
  743. e: 'host2:10,host1:10'
  744. },
  745. {
  746. siteConfigs: {
  747. 'hadoop.registry.zk.quorum': 'host1:10,host2:10,host3:10'
  748. },
  749. propertyName: 'hadoop.registry.zk.quorum',
  750. hostsList: 'host2:10,host1:10,host3:10,host4:11',
  751. e: 'host2:10,host1:10,host3:10,host4:11'
  752. },
  753. {
  754. siteConfigs: {
  755. 'hive.zookeeper.quorum': 'host1'
  756. },
  757. propertyName: 'some.new.property',
  758. hostsList: 'host2,host1:10',
  759. e: 'host2,host1:10'
  760. }
  761. ];
  762. tests.forEach(function(test) {
  763. it('ZK located on {0}, current prop value is "{1}" "{2}" value should be "{3}"'.format(test.hostsList, ''+test.siteConfigs[test.propertyName], test.propertyName, test.e), function() {
  764. var result = App.config.updateHostsListValue(test.siteConfigs, test.propertyName, test.hostsList);
  765. expect(result).to.be.eql(test.e);
  766. expect(test.siteConfigs[test.propertyName]).to.be.eql(test.e);
  767. });
  768. });
  769. });
  770. describe('#createHostNameProperty', function () {
  771. it('create host property', function () {
  772. expect(App.config.createHostNameProperty('service1', 'component1', ['host1'], Em.Object.create({
  773. isMultipleAllowed: false,
  774. displayName: 'display name'
  775. }))).to.eql({
  776. "id": 'component1_host__service1-site',
  777. "name": 'component1_host',
  778. "displayName": 'display name host',
  779. "value": ['host1'],
  780. "recommendedValue": ['host1'],
  781. "description": "The host that has been assigned to run display name",
  782. "displayType": "componentHost",
  783. "isOverridable": false,
  784. "isRequiredByAgent": false,
  785. "serviceName": 'service1',
  786. "filename": "service1-site.xml",
  787. "category": 'component1',
  788. "index": 0
  789. })
  790. });
  791. it('create hosts property', function () {
  792. expect(App.config.createHostNameProperty('service1', 'component1', ['host1'], Em.Object.create({
  793. isMultipleAllowed: true,
  794. displayName: 'display name'
  795. }))).to.eql({
  796. "id": 'component1_hosts__service1-site',
  797. "name": 'component1_hosts',
  798. "displayName": 'display name host',
  799. "value": ['host1'],
  800. "recommendedValue": ['host1'],
  801. "description": "The hosts that has been assigned to run display name",
  802. "displayType": "componentHosts",
  803. "isOverridable": false,
  804. "isRequiredByAgent": false,
  805. "serviceName": 'service1',
  806. "filename": "service1-site.xml",
  807. "category": 'component1',
  808. "index": 0
  809. })
  810. });
  811. });
  812. describe("#truncateGroupName()", function() {
  813. it("name is empty", function() {
  814. expect(App.config.truncateGroupName('')).to.be.empty;
  815. });
  816. it("name has less than max chars", function() {
  817. expect(App.config.truncateGroupName('group1')).to.equal('group1');
  818. });
  819. it("name has more than max chars", function() {
  820. expect(App.config.truncateGroupName('group_has_more_than_max_characters')).to.equal('group_has...haracters');
  821. });
  822. });
  823. describe('#getComponentName', function () {
  824. [
  825. { configName: 'somename_host', componentName: 'SOMENAME' },
  826. { configName: 'somename_hosts', componentName: 'SOMENAME' },
  827. { configName: 'somenamehost', componentName: '' },
  828. { configName: 'somenamehosts', componentName: '' }
  829. ].forEach(function (t) {
  830. it('format config name ' + t.configName + ' to component ', function() {
  831. expect(App.config.getComponentName(t.configName)).to.equal(t.componentName);
  832. });
  833. });
  834. });
  835. describe('#getDescription', function () {
  836. it('should add extra-message to the description for `password`-configs', function () {
  837. var extraMessage = Em.I18n.t('services.service.config.password.additionalDescription');
  838. expect(App.config.getDescription('', 'password')).to.contain(extraMessage);
  839. });
  840. it('should not add extra-message to the description if it already contains it', function () {
  841. var extraMessage = Em.I18n.t('services.service.config.password.additionalDescription');
  842. var res = App.config.getDescription(extraMessage, 'password');
  843. expect(res).to.contain(extraMessage);
  844. expect(res).to.contain(extraMessage);
  845. var subd = res.replace(extraMessage, '');
  846. expect(subd).to.not.contain(extraMessage);
  847. });
  848. it('should add extra-message to the description if description is not defined', function () {
  849. var extraMessage = Em.I18n.t('services.service.config.password.additionalDescription');
  850. expect(App.config.getDescription(undefined, 'password')).to.contain(extraMessage);
  851. });
  852. });
  853. describe('#parseIdentities', function() {
  854. var testObject = {
  855. identities: [
  856. {
  857. name: "/spnego"
  858. },
  859. {
  860. principal: {
  861. configuration: "hbase-env/hbase_principal_name",
  862. type: "user",
  863. local_username: "${hbase-env/hbase_user}",
  864. value: "${hbase-env/hbase_user}-${cluster_name|toLower()}@${realm}"
  865. },
  866. name: "hbase",
  867. keytab: {
  868. owner: {
  869. access: "r",
  870. name: "${hbase-env/hbase_user}"
  871. },
  872. file: "${keytab_dir}/hbase.headless.keytab",
  873. configuration: "hbase-env/hbase_user_keytab",
  874. group: {
  875. access: "r",
  876. name: "${cluster-env/user_group}"
  877. }
  878. }
  879. },
  880. {
  881. name: "/smokeuser"
  882. }
  883. ]
  884. };
  885. var result = {
  886. "hbase_principal_name__hbase-env": true,
  887. "hbase_user_keytab__hbase-env": true
  888. };
  889. it('generates map with identities', function() {
  890. expect(App.config.parseIdentities(testObject, {})).to.eql(result);
  891. });
  892. });
  893. describe('#kerberosIdentitiesDescription', function () {
  894. it('update empty description', function() {
  895. expect(App.config.kerberosIdentitiesDescription()).to.eql(Em.I18n.t('services.service.config.secure.additionalDescription'));
  896. });
  897. it('update description for identities (without dot)', function() {
  898. expect(App.config.kerberosIdentitiesDescription('some text')).to.eql('some text. '
  899. + Em.I18n.t('services.service.config.secure.additionalDescription'));
  900. });
  901. it('update description for identities (with dot)', function() {
  902. expect(App.config.kerberosIdentitiesDescription('some text.')).to.eql('some text. '
  903. + Em.I18n.t('services.service.config.secure.additionalDescription'));
  904. });
  905. it('update description for identities (with dot and spaces at the end)', function() {
  906. expect(App.config.kerberosIdentitiesDescription('some text. ')).to.eql('some text. '
  907. + Em.I18n.t('services.service.config.secure.additionalDescription'));
  908. });
  909. });
  910. });