config_test.js 26 KB

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