config_test.js 33 KB

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