config_test.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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/config');
  21. require('models/service/hdfs');
  22. var setups = require('test/init_model_test');
  23. var modelSetup = setups.configs;
  24. describe('App.config', function () {
  25. var loadServiceSpecificConfigs = function(context, serviceName) {
  26. context.configGroups = modelSetup.setupConfigGroupsObject(serviceName);
  27. context.advancedConfigs = modelSetup.setupAdvancedConfigsObject();
  28. context.tags = modelSetup.setupServiceConfigTagsObject(serviceName);
  29. context.result = App.config.mergePreDefinedWithLoaded(context.configGroups, context.advancedConfigs, context.tags, App.Service.find().findProperty('id', serviceName).get('serviceName'));
  30. };
  31. var loadAllServicesConfigs = function(context, serviceNames) {
  32. context.configGroups = modelSetup.setupConfigGroupsObject();
  33. }
  34. var loadServiceModelsData = function(serviceNames) {
  35. serviceNames.forEach(function(serviceName) {
  36. App.store.load(App.Service, {
  37. id: serviceName,
  38. service_name: serviceName
  39. });
  40. });
  41. };
  42. var setupContentForMergeWithStored = function(context) {
  43. loadServiceModelsData(context.installedServiceNames);
  44. loadAllServicesConfigs(context);
  45. setups.setupStackVersion(this, 'HDP-2.1');
  46. context.result = App.config.mergePreDefinedWithStored(context.storedConfigs, modelSetup.setupAdvancedConfigsObject(), context.installedServiceNames);
  47. };
  48. var removeServiceModelData = function(serviceIds) {
  49. serviceIds.forEach(function(serviceId) {
  50. var record = App.Service.find(serviceId);
  51. record.deleteRecord();
  52. record.get('stateManager').transitionTo('loading');
  53. });
  54. };
  55. describe('#handleSpecialProperties', function () {
  56. var config = {};
  57. it('value should be transformed to "1024" from "1024m"', function () {
  58. config = {
  59. displayType: 'int',
  60. value: '1024m',
  61. defaultValue: '1024m'
  62. };
  63. App.config.handleSpecialProperties(config);
  64. expect(config.value).to.equal('1024');
  65. expect(config.defaultValue).to.equal('1024');
  66. });
  67. it('value should be transformed to true from "true"', function () {
  68. config = {
  69. displayType: 'checkbox',
  70. value: 'true',
  71. defaultValue: 'true'
  72. };
  73. App.config.handleSpecialProperties(config);
  74. expect(config.value).to.equal(true);
  75. expect(config.defaultValue).to.equal(true);
  76. });
  77. it('value should be transformed to false from "false"', function () {
  78. config = {
  79. displayType: 'checkbox',
  80. value: 'false',
  81. defaultValue: 'false'
  82. };
  83. App.config.handleSpecialProperties(config);
  84. expect(config.value).to.equal(false);
  85. expect(config.defaultValue).to.equal(false);
  86. });
  87. });
  88. describe('#capacitySchedulerFilter', function() {
  89. var testMessage = 'filter should {0} detect `{1}` property';
  90. describe('Stack version >= 2.0', function() {
  91. before(function() {
  92. setups.setupStackVersion(this, 'HDP-2.1');
  93. });
  94. var tests = [
  95. {
  96. config: {
  97. name: 'yarn.scheduler.capacity.maximum-am-resource-percent'
  98. },
  99. e: false
  100. },
  101. {
  102. config: {
  103. name: 'yarn.scheduler.capacity.root.capacity'
  104. },
  105. e: false
  106. },
  107. {
  108. config: {
  109. name: 'yarn.scheduler.capacity.root.default.capacity'
  110. },
  111. e: true
  112. }
  113. ];
  114. tests.forEach(function(test){
  115. it(testMessage.format( !!test.e ? '' : 'not', test.config.name), function() {
  116. expect(App.config.get('capacitySchedulerFilter')(test.config)).to.eql(test.e);
  117. });
  118. });
  119. after(function() {
  120. setups.restoreStackVersion(this);
  121. })
  122. });
  123. });
  124. describe('#fileConfigsIntoTextarea', function () {
  125. var filename = 'capacity-scheduler.xml';
  126. var configs = [
  127. {
  128. name: 'config1',
  129. value: 'value1',
  130. defaultValue: 'value1',
  131. filename: 'capacity-scheduler.xml'
  132. },
  133. {
  134. name: 'config2',
  135. value: 'value2',
  136. defaultValue: 'value2',
  137. filename: 'capacity-scheduler.xml'
  138. }
  139. ];
  140. it('two configs into textarea', function () {
  141. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  142. expect(result.length).to.equal(1);
  143. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
  144. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\n');
  145. });
  146. it('three config into textarea', function () {
  147. configs.push({
  148. name: 'config3',
  149. value: 'value3',
  150. defaultValue: 'value3',
  151. filename: 'capacity-scheduler.xml'
  152. });
  153. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  154. expect(result.length).to.equal(1);
  155. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  156. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  157. });
  158. it('one of three configs has different filename', function () {
  159. configs[1].filename = 'another filename';
  160. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  161. //result contains two configs: one with different filename and one textarea config
  162. expect(result.length).to.equal(2);
  163. expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
  164. expect(result[1].defaultValue).to.equal('config1=value1\nconfig3=value3\n');
  165. });
  166. it('none configs into empty textarea', function () {
  167. filename = 'capacity-scheduler.xml';
  168. configs.clear();
  169. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  170. expect(result.length).to.equal(1);
  171. expect(result[0].value).to.equal('');
  172. expect(result[0].defaultValue).to.equal('');
  173. });
  174. });
  175. describe('#textareaIntoFileConfigs', function () {
  176. var filename = 'capacity-scheduler.xml';
  177. var testData = [
  178. {
  179. configs: [Em.Object.create({
  180. "name": "capacity-scheduler",
  181. "value": "config1=value1",
  182. "filename": "capacity-scheduler.xml"
  183. })]
  184. },
  185. {
  186. configs: [Em.Object.create({
  187. "name": "capacity-scheduler",
  188. "value": "config1=value1\nconfig2=value2\n",
  189. "filename": "capacity-scheduler.xml"
  190. })]
  191. },
  192. {
  193. configs: [Em.Object.create({
  194. "name": "capacity-scheduler",
  195. "value": "config1=value1,value2\n",
  196. "filename": "capacity-scheduler.xml"
  197. })]
  198. },
  199. {
  200. configs: [Em.Object.create({
  201. "name": "capacity-scheduler",
  202. "value": "config1=value1 config2=value2\n",
  203. "filename": "capacity-scheduler.xml"
  204. })]
  205. }
  206. ];
  207. it('config1=value1 to one config', function () {
  208. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
  209. expect(result.length).to.equal(1);
  210. expect(result[0].value).to.equal('value1');
  211. expect(result[0].name).to.equal('config1');
  212. });
  213. it('config1=value1\\nconfig2=value2\\n to two configs', function () {
  214. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
  215. expect(result.length).to.equal(2);
  216. expect(result[0].value).to.equal('value1');
  217. expect(result[0].name).to.equal('config1');
  218. expect(result[1].value).to.equal('value2');
  219. expect(result[1].name).to.equal('config2');
  220. });
  221. it('config1=value1,value2\n to one config', function () {
  222. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
  223. expect(result.length).to.equal(1);
  224. expect(result[0].value).to.equal('value1,value2');
  225. expect(result[0].name).to.equal('config1');
  226. });
  227. it('config1=value1 config2=value2 to two configs', function () {
  228. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[3].configs, filename);
  229. expect(result.length).to.equal(1);
  230. });
  231. });
  232. describe('#addAvancedConfigs()', function() {
  233. beforeEach(function() {
  234. this.storedConfigs = modelSetup.setupStoredConfigsObject();
  235. });
  236. it('`custom.zoo.cfg` absent in stored configs', function() {
  237. expect(this.storedConfigs.findProperty('name', 'custom.zoo.cfg')).to.be.undefined;
  238. });
  239. it('`custom.zoo.cfg.` from advanced configs should be added to stored configs', function() {
  240. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'ZOOKEEPER');
  241. var property = this.storedConfigs.findProperty('name', 'custom.zoo.cfg');
  242. expect(property).to.be.ok;
  243. expect(property.category).to.eql('Advanced zoo.cfg');
  244. });
  245. it('`capacity-scheduler.xml` property with name `content` should have `displayType` `multiLine`', function() {
  246. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'YARN');
  247. expect(this.storedConfigs.filterProperty('filename', 'capacity-scheduler.xml').findProperty('name','content').displayType).to.eql('multiLine');
  248. });
  249. it('storing different configs with the same name', function () {
  250. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'HBASE');
  251. var properties = this.storedConfigs.filterProperty('name', 'hbase_log_dir');
  252. var hbaseProperty = properties.findProperty('filename', 'hbase-env.xml');
  253. var amsProperty = properties.findProperty('filename', 'ams-hbase-env.xml');
  254. expect(properties).to.have.length(2);
  255. expect(hbaseProperty.serviceName).to.equal('HBASE');
  256. expect(hbaseProperty.value).to.equal('/hadoop/hbase');
  257. expect(amsProperty.serviceName).to.equal('AMS');
  258. expect(amsProperty.value).to.equal('/hadoop/ams-hbase');
  259. });
  260. });
  261. describe('#trimProperty',function() {
  262. var testMessage = 'displayType `{0}`, value `{1}`{3} should return `{2}`';
  263. var tests = [
  264. {
  265. config: {
  266. displayType: 'directory',
  267. value: ' /a /b /c'
  268. },
  269. e: '/a,/b,/c'
  270. },
  271. {
  272. config: {
  273. displayType: 'directories',
  274. value: ' /a /b '
  275. },
  276. e: '/a,/b'
  277. },
  278. {
  279. config: {
  280. displayType: 'datanodedirs',
  281. value: ' [DISK]/a [SSD]/b '
  282. },
  283. e: '[DISK]/a,[SSD]/b'
  284. },
  285. {
  286. config: {
  287. displayType: 'datanodedirs',
  288. value: '/a,/b, /c\n/d,\n/e /f'
  289. },
  290. e: '/a,/b,/c,/d,/e,/f'
  291. },
  292. {
  293. config: {
  294. displayType: 'host',
  295. value: ' localhost '
  296. },
  297. e: 'localhost'
  298. },
  299. {
  300. config: {
  301. displayType: 'password',
  302. value: ' passw ord '
  303. },
  304. e: ' passw ord '
  305. },
  306. {
  307. config: {
  308. displayType: 'advanced',
  309. value: ' value'
  310. },
  311. e: ' value'
  312. },
  313. {
  314. config: {
  315. displayType: 'advanced',
  316. value: ' value'
  317. },
  318. e: ' value'
  319. },
  320. {
  321. config: {
  322. displayType: 'advanced',
  323. value: 'http://localhost ',
  324. name: 'javax.jdo.option.ConnectionURL'
  325. },
  326. e: 'http://localhost'
  327. },
  328. {
  329. config: {
  330. displayType: 'advanced',
  331. value: 'http://localhost ',
  332. name: 'oozie.service.JPAService.jdbc.url'
  333. },
  334. e: 'http://localhost'
  335. },
  336. {
  337. config: {
  338. displayType: 'custom',
  339. value: ' custom value '
  340. },
  341. e: ' custom value'
  342. },
  343. {
  344. config: {
  345. displayType: 'masterHosts',
  346. value: ['host1.com', 'host2.com']
  347. },
  348. e: ['host1.com', 'host2.com']
  349. }
  350. ];
  351. tests.forEach(function(test) {
  352. it(testMessage.format(test.config.displayType, test.config.value, test.e, !!test.config.name ? ', name `' + test.config.name + '`' : ''), function() {
  353. expect(App.config.trimProperty(test.config)).to.eql(test.e);
  354. expect(App.config.trimProperty(Em.Object.create(test.config), true)).to.eql(test.e);
  355. });
  356. });
  357. });
  358. describe('#OnNnHAHideSnn()', function() {
  359. it('`SNameNode` category present in `ServiceConfig`. It should be removed.', function() {
  360. App.store.load(App.HDFSService, {
  361. 'id': 'HDFS'
  362. });
  363. var ServiceConfig = Em.Object.create({
  364. configCategories: [ { name: 'SNameNode' } ]
  365. });
  366. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.ok;
  367. App.config.OnNnHAHideSnn(ServiceConfig);
  368. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.undefined;
  369. var record = App.HDFSService.find('HDFS');
  370. record.deleteRecord();
  371. record.get('stateManager').transitionTo('loading');
  372. });
  373. it('`SNameNode` category absent in `ServiceConfig`. Nothing to do.', function() {
  374. App.store.load(App.HDFSService, {
  375. 'id': 'HDFS'
  376. });
  377. var ServiceConfig = Em.Object.create({
  378. configCategories: [ { name: 'DataNode' } ]
  379. });
  380. App.config.OnNnHAHideSnn(ServiceConfig);
  381. expect(ServiceConfig.get('configCategories').findProperty('name','DataNode')).to.ok;
  382. expect(ServiceConfig.get('configCategories.length')).to.eql(1);
  383. });
  384. });
  385. describe('#preDefinedConfigFile', function() {
  386. before(function() {
  387. setups.setupStackVersion(this, 'BIGTOP-0.8');
  388. });
  389. it('bigtop site properties should be ok.', function() {
  390. var bigtopSiteProperties = App.config.preDefinedConfigFile('site_properties');
  391. expect(bigtopSiteProperties).to.be.ok;
  392. });
  393. it('a non-existing file should not be ok.', function () {
  394. var notExistingSiteProperty = App.config.preDefinedConfigFile('notExisting');
  395. expect(notExistingSiteProperty).to.not.be.ok;
  396. });
  397. after(function() {
  398. setups.restoreStackVersion(this);
  399. });
  400. });
  401. describe('#preDefinedSiteProperties-bigtop', function () {
  402. before(function() {
  403. setups.setupStackVersion(this, 'BIGTOP-0.8');
  404. });
  405. it('bigtop should use New PostgreSQL Database as its default hive metastore database', function () {
  406. expect(App.config.get('preDefinedSiteProperties').findProperty('defaultValue', 'New PostgreSQL Database')).to.be.ok;
  407. });
  408. after(function() {
  409. setups.restoreStackVersion(this);
  410. });
  411. });
  412. describe('#preDefinedSiteProperties-hdp2', function () {
  413. before(function() {
  414. setups.setupStackVersion(this, 'HDP-2.0');
  415. });
  416. it('HDP2 should use New MySQL Database as its default hive metastore database', function () {
  417. expect(App.config.get('preDefinedSiteProperties').findProperty('defaultValue', 'New MySQL Database')).to.be.ok;
  418. });
  419. after(function() {
  420. setups.restoreStackVersion(this);
  421. });
  422. });
  423. describe('#generateConfigPropertiesByName', function() {
  424. var tests = [
  425. {
  426. names: ['property_1', 'property_2'],
  427. properties: undefined,
  428. e: {
  429. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable']
  430. },
  431. m: 'Should generate base property object without additional fields'
  432. },
  433. {
  434. names: ['property_1', 'property_2'],
  435. properties: { category: 'SomeCat', serviceName: 'SERVICE_NAME' },
  436. e: {
  437. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable', 'category', 'serviceName']
  438. },
  439. m: 'Should generate base property object without additional fields'
  440. }
  441. ];
  442. tests.forEach(function(test) {
  443. it(test.m, function() {
  444. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).length).to.eql(test.names.length);
  445. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).map(function(property) {
  446. return Em.keys(property);
  447. }).reduce(function(p, c) {
  448. return p.concat(c);
  449. }).uniq()).to.eql(test.e.keys);
  450. });
  451. });
  452. });
  453. describe('#generateConfigPropertiesByName', function() {
  454. var tests = [
  455. {
  456. names: ['property_1', 'property_2'],
  457. properties: undefined,
  458. e: {
  459. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable']
  460. },
  461. m: 'Should generate base property object without additional fields'
  462. },
  463. {
  464. names: ['property_1', 'property_2'],
  465. properties: { category: 'SomeCat', serviceName: 'SERVICE_NAME' },
  466. e: {
  467. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable', 'category', 'serviceName']
  468. },
  469. m: 'Should generate base property object without additional fields'
  470. }
  471. ];
  472. tests.forEach(function(test) {
  473. it(test.m, function() {
  474. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).length).to.eql(test.names.length);
  475. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).map(function(property) {
  476. return Em.keys(property);
  477. }).reduce(function(p, c) {
  478. return p.concat(c);
  479. }).uniq()).to.eql(test.e.keys);
  480. });
  481. });
  482. });
  483. describe('#generateConfigPropertiesByName', function() {
  484. var tests = [
  485. {
  486. names: ['property_1', 'property_2'],
  487. properties: undefined,
  488. e: {
  489. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable']
  490. },
  491. m: 'Should generate base property object without additional fields'
  492. },
  493. {
  494. names: ['property_1', 'property_2'],
  495. properties: { category: 'SomeCat', serviceName: 'SERVICE_NAME' },
  496. e: {
  497. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable', 'category', 'serviceName']
  498. },
  499. m: 'Should generate base property object without additional fields'
  500. }
  501. ];
  502. tests.forEach(function(test) {
  503. it(test.m, function() {
  504. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).length).to.eql(test.names.length);
  505. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).map(function(property) {
  506. return Em.keys(property);
  507. }).reduce(function(p, c) {
  508. return p.concat(c);
  509. }).uniq()).to.eql(test.e.keys);
  510. });
  511. });
  512. });
  513. describe('#setPreDefinedServiceConfigs', function() {
  514. beforeEach(function() {
  515. sinon.stub(App.StackService, 'find', function() {
  516. return [
  517. Em.Object.create({
  518. id: 'HDFS',
  519. serviceName: 'HDFS',
  520. configTypes: {
  521. 'hadoop-env': {},
  522. 'hdfs-site': {}
  523. }
  524. }),
  525. Em.Object.create({
  526. id: 'OOZIE',
  527. serviceName: 'OOZIE',
  528. configTypes: {
  529. 'oozie-env': {},
  530. 'oozie-site': {}
  531. }
  532. })
  533. ];
  534. });
  535. App.config.setPreDefinedServiceConfigs(true);
  536. });
  537. afterEach(function() {
  538. App.StackService.find.restore();
  539. });
  540. it('should include service MISC', function() {
  541. expect(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC')).to.be.ok;
  542. });
  543. it('should include -env config types according to stack services', function() {
  544. var miscCategory = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC');
  545. expect(Em.keys(miscCategory.get('configTypes'))).to.eql(['cluster-env', 'hadoop-env', 'oozie-env']);
  546. });
  547. });
  548. describe('#isManagedMySQLForHiveAllowed', function () {
  549. var cases = [
  550. {
  551. osType: 'redhat5',
  552. expected: false
  553. },
  554. {
  555. osType: 'redhat6',
  556. expected: true
  557. },
  558. {
  559. osType: 'suse11',
  560. expected: false
  561. }
  562. ],
  563. title = 'should be {0} for {1}';
  564. cases.forEach(function (item) {
  565. it(title.format(item.expected, item.osType), function () {
  566. expect(App.config.isManagedMySQLForHiveAllowed(item.osType)).to.equal(item.expected);
  567. });
  568. });
  569. });
  570. describe('#createAdvancedPropertyObject', function() {
  571. var tests = [
  572. {
  573. name: 'proxyuser_group',
  574. cases: [
  575. {
  576. key: 'displayType',
  577. e: 'user'
  578. },
  579. {
  580. key: 'serviceName',
  581. e: 'MISC'
  582. },
  583. {
  584. key: 'belongsToService',
  585. e: ['HIVE', 'OOZIE', 'FALCON']
  586. }
  587. ]
  588. },
  589. {
  590. name: 'oozie.service.JPAService.jdbc.password',
  591. cases: [
  592. {
  593. key: 'displayType',
  594. e: 'password'
  595. }
  596. ]
  597. }
  598. ];
  599. var properties = [];
  600. modelSetup.advancedConfigs.items.forEach(function(item) {
  601. properties.push(App.config.createAdvancedPropertyObject(item.StackConfigurations));
  602. });
  603. tests.forEach(function(test) {
  604. test.cases.forEach(function(testCase) {
  605. it('config property `{0}` `{1}` key should be`{2}`'.format(test.name, testCase.key, testCase.e), function() {
  606. var property = properties.findProperty('name', test.name);
  607. expect(Em.get(property, testCase.key)).to.eql(testCase.e);
  608. });
  609. });
  610. });
  611. });
  612. describe('#mergePreDefinedWithLoaded', function() {
  613. var result;
  614. before(function() {
  615. setups.setupStackVersion(this, 'HDP-2.2');
  616. loadServiceModelsData(['HDFS', 'STORM']);
  617. App.config.loadAdvancedConfigSuccess(modelSetup.advancedConfigs, { url: '/serviceName/configurations'}, {
  618. callback: function(advancedConfigs) {
  619. App.config.loadClusterConfigSuccess(modelSetup.advancedClusterConfigs, { url: '/cluster/configurations'}, {
  620. callback: function(clusterConfigs) {
  621. var configCategories = modelSetup.setupConfigGroupsObject();
  622. var tags = [
  623. {newTagName: null, tagName: 'version1', siteName: 'hadoop-env'},
  624. {newTagName: null, tagName: 'version1', siteName: 'hdfs-site'},
  625. {newTagName: null, tagName: 'version1', siteName: 'cluster-env'},
  626. {newTagName: null, tagName: 'version1', siteName: 'storm-env'}
  627. ];
  628. var serviceName = 'STORM';
  629. result = App.config.mergePreDefinedWithLoaded(configCategories, advancedConfigs.concat(clusterConfigs), tags, serviceName);
  630. }
  631. });
  632. }
  633. });
  634. });
  635. after(function() {
  636. setups.restoreStackVersion(this);
  637. removeServiceModelData(['HDFS', 'STORM']);
  638. });
  639. var propertyTests = [
  640. {
  641. name: 'hdfs_user',
  642. cases: [
  643. {
  644. key: 'displayType',
  645. e: 'user'
  646. },
  647. {
  648. key: 'isVisible',
  649. e: true
  650. },
  651. {
  652. key: 'serviceName',
  653. e: 'MISC'
  654. },
  655. {
  656. key: 'category',
  657. e: 'Users and Groups'
  658. }
  659. ]
  660. }
  661. ];
  662. propertyTests.forEach(function(test) {
  663. test.cases.forEach(function(testCase) {
  664. it('config property `{0}` `{1}` key should be`{2}`'.format(test.name, testCase.key, testCase.e), function() {
  665. var property = result.configs.findProperty('name', test.name);
  666. expect(Em.get(property, testCase.key)).to.equal(testCase.e);
  667. });
  668. });
  669. });
  670. });
  671. describe('#replaceConfigValues', function () {
  672. var cases = [
  673. {
  674. name: 'name',
  675. express: '<templateName[0]>',
  676. value: '<templateName[0]>',
  677. globValue: 'v',
  678. expected: 'v',
  679. title: 'default case'
  680. },
  681. {
  682. name: 'templeton.hive.properties',
  683. express: '<templateName[0]>',
  684. value: 'hive.matestore.uris=<templateName[0]>',
  685. globValue: 'thrift://h0:9933,thrift://h1:9933,thrift://h2:9933',
  686. expected: 'hive.matestore.uris=thrift://h0:9933\\,thrift://h1:9933\\,thrift://h2:9933',
  687. title: 'should escape commas for templeton.hive.properties'
  688. }
  689. ];
  690. cases.forEach(function (item) {
  691. it(item.title, function () {
  692. expect(App.config.replaceConfigValues(item.name, item.express, item.value, item.globValue)).to.equal(item.expected);
  693. });
  694. });
  695. });
  696. });