config_test.js 30 KB

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