config_test.js 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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('#setPreDefinedServiceConfigs', function() {
  434. beforeEach(function() {
  435. sinon.stub(App.StackService, 'find', function() {
  436. return [
  437. Em.Object.create({
  438. id: 'HDFS',
  439. serviceName: 'HDFS',
  440. configTypes: {
  441. 'hadoop-env': {},
  442. 'hdfs-site': {}
  443. }
  444. }),
  445. Em.Object.create({
  446. id: 'OOZIE',
  447. serviceName: 'OOZIE',
  448. configTypes: {
  449. 'oozie-env': {},
  450. 'oozie-site': {}
  451. }
  452. })
  453. ];
  454. });
  455. App.config.setPreDefinedServiceConfigs(true);
  456. });
  457. afterEach(function() {
  458. App.StackService.find.restore();
  459. });
  460. it('should include service MISC', function() {
  461. expect(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC')).to.be.ok;
  462. });
  463. it('should include -env config types according to stack services', function() {
  464. var miscCategory = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC');
  465. expect(Em.keys(miscCategory.get('configTypes'))).to.eql(['cluster-env', 'hadoop-env', 'oozie-env']);
  466. });
  467. });
  468. describe('#isManagedMySQLForHiveAllowed', function () {
  469. var cases = [
  470. {
  471. osFamily: 'redhat5',
  472. expected: false
  473. },
  474. {
  475. osFamily: 'redhat6',
  476. expected: true
  477. },
  478. {
  479. osFamily: 'suse11',
  480. expected: false
  481. }
  482. ],
  483. title = 'should be {0} for {1}';
  484. cases.forEach(function (item) {
  485. it(title.format(item.expected, item.osFamily), function () {
  486. expect(App.config.isManagedMySQLForHiveAllowed(item.osFamily)).to.equal(item.expected);
  487. });
  488. });
  489. });
  490. describe('#createAdvancedPropertyObject', function() {
  491. var tests = [
  492. {
  493. name: 'proxyuser_group',
  494. cases: [
  495. {
  496. key: 'displayType',
  497. e: 'user'
  498. },
  499. {
  500. key: 'serviceName',
  501. e: 'MISC'
  502. },
  503. {
  504. key: 'belongsToService',
  505. e: ['HIVE', 'OOZIE', 'FALCON']
  506. }
  507. ]
  508. },
  509. {
  510. name: 'oozie.service.JPAService.jdbc.password',
  511. cases: [
  512. {
  513. key: 'displayType',
  514. e: 'password'
  515. },
  516. {
  517. key: 'isVisible',
  518. e: true
  519. }
  520. ]
  521. },
  522. {
  523. name: 'ignore_groupsusers_create',
  524. cases: [
  525. {
  526. key: 'isVisible',
  527. e: false
  528. }
  529. ]
  530. },
  531. {
  532. name: 'user_group',
  533. cases: [
  534. {
  535. key: 'isVisible',
  536. e: true
  537. },
  538. {
  539. key: 'index',
  540. e: 30
  541. },
  542. {
  543. key: 'displayName',
  544. e: 'Hadoop Group'
  545. }
  546. ]
  547. },
  548. {
  549. name: 'zk_user',
  550. cases: [
  551. {
  552. key: 'displayName',
  553. e: 'ZooKeeper User'
  554. }
  555. ]
  556. },
  557. {
  558. name: 'mapred_user',
  559. cases: [
  560. {
  561. key: 'displayName',
  562. e: 'MapReduce User'
  563. }
  564. ]
  565. },
  566. {
  567. name: 'smokeuser',
  568. cases: [
  569. {
  570. key: 'displayName',
  571. e: 'Smoke Test User'
  572. }
  573. ]
  574. }
  575. ];
  576. var properties = [];
  577. modelSetup.advancedConfigs.items.forEach(function(item) {
  578. properties.push(App.config.createAdvancedPropertyObject(item.StackConfigurations));
  579. });
  580. App.config.loadClusterConfigSuccess(modelSetup.advancedClusterConfigs, {url: '/cluster/configurations'}, {callback: function (items) {properties = properties.concat(items)}});
  581. beforeEach(function () {
  582. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
  583. });
  584. afterEach(function () {
  585. App.get.restore();
  586. });
  587. tests.forEach(function(test) {
  588. test.cases.forEach(function(testCase) {
  589. it('config property `{0}` `{1}` key should be`{2}`'.format(test.name, testCase.key, testCase.e), function() {
  590. var property = properties.findProperty('name', test.name);
  591. expect(Em.get(property, testCase.key)).to.eql(testCase.e);
  592. });
  593. });
  594. });
  595. });
  596. describe('#mergePreDefinedWithLoaded', function() {
  597. var result;
  598. before(function() {
  599. setups.setupStackVersion(this, 'HDP-2.2');
  600. loadServiceModelsData(['HDFS', 'STORM']);
  601. App.config.loadAdvancedConfigSuccess(modelSetup.advancedConfigs, { url: '/serviceName/configurations'}, {
  602. callback: function(advancedConfigs) {
  603. App.config.loadClusterConfigSuccess(modelSetup.advancedClusterConfigs, { url: '/cluster/configurations'}, {
  604. callback: function(clusterConfigs) {
  605. var configCategories = modelSetup.setupConfigGroupsObject();
  606. var tags = [
  607. {newTagName: null, tagName: 'version1', siteName: 'hadoop-env'},
  608. {newTagName: null, tagName: 'version1', siteName: 'hdfs-site'},
  609. {newTagName: null, tagName: 'version1', siteName: 'cluster-env'},
  610. {newTagName: null, tagName: 'version1', siteName: 'storm-env'}
  611. ];
  612. var serviceName = 'STORM';
  613. result = App.config.mergePreDefinedWithLoaded(configCategories, advancedConfigs.concat(clusterConfigs), tags, serviceName);
  614. }
  615. });
  616. }
  617. });
  618. });
  619. after(function() {
  620. setups.restoreStackVersion(this);
  621. removeServiceModelData(['HDFS', 'STORM']);
  622. });
  623. var propertyTests = [
  624. {
  625. name: 'hdfs_user',
  626. cases: [
  627. {
  628. key: 'displayType',
  629. e: 'user'
  630. },
  631. {
  632. key: 'isVisible',
  633. e: true
  634. },
  635. {
  636. key: 'serviceName',
  637. e: 'MISC'
  638. },
  639. {
  640. key: 'category',
  641. e: 'Users and Groups'
  642. }
  643. ]
  644. }
  645. ];
  646. propertyTests.forEach(function(test) {
  647. test.cases.forEach(function(testCase) {
  648. it('config property `{0}` `{1}` key should be`{2}`'.format(test.name, testCase.key, testCase.e), function() {
  649. var property = result.configs.findProperty('name', test.name);
  650. expect(Em.get(property, testCase.key)).to.equal(testCase.e);
  651. });
  652. });
  653. });
  654. });
  655. describe('#replaceConfigValues', function () {
  656. var cases = [
  657. {
  658. name: 'name',
  659. express: '<templateName[0]>',
  660. value: '<templateName[0]>',
  661. globValue: 'v',
  662. expected: 'v',
  663. title: 'default case'
  664. },
  665. {
  666. name: 'templeton.hive.properties',
  667. express: '<templateName[0]>',
  668. value: 'hive.matestore.uris=<templateName[0]>',
  669. globValue: 'thrift://h0:9933,thrift://h1:9933,thrift://h2:9933',
  670. expected: 'hive.matestore.uris=thrift://h0:9933\\,thrift://h1:9933\\,thrift://h2:9933',
  671. title: 'should escape commas for templeton.hive.properties'
  672. }
  673. ];
  674. cases.forEach(function (item) {
  675. it(item.title, function () {
  676. expect(App.config.replaceConfigValues(item.name, item.express, item.value, item.globValue)).to.equal(item.expected);
  677. });
  678. });
  679. });
  680. describe('#advancedConfigIdentityData', function () {
  681. var configs = [
  682. {
  683. input: {
  684. property_type: ['USER'],
  685. property_name: 'hdfs_user'
  686. },
  687. output: {
  688. id: 'puppet var',
  689. category: 'Users and Groups',
  690. isVisible: true,
  691. serviceName: 'MISC',
  692. isOverridable: false,
  693. isReconfigurable: false,
  694. displayName: 'HDFS User',
  695. displayType: 'user',
  696. index: 30
  697. },
  698. title: 'user, no service name specified, default display name behaviour'
  699. },
  700. {
  701. input: {
  702. property_type: ['GROUP'],
  703. property_name: 'knox_group',
  704. service_name: 'KNOX'
  705. },
  706. output: {
  707. id: 'puppet var',
  708. category: 'Users and Groups',
  709. isVisible: true,
  710. serviceName: 'MISC',
  711. isOverridable: false,
  712. isReconfigurable: false,
  713. displayName: 'Knox Group',
  714. displayType: 'user',
  715. index: 0
  716. },
  717. title: 'group, service_name = KNOX, default display name behaviour'
  718. },
  719. {
  720. input: {
  721. property_type: ['USER']
  722. },
  723. output: {
  724. isVisible: false
  725. },
  726. isHDPWIN: true,
  727. title: 'HDPWIN stack'
  728. },
  729. {
  730. input: {
  731. property_type: ['USER'],
  732. property_name: 'smokeuser',
  733. service_name: 'MISC'
  734. },
  735. output: {
  736. displayName: 'Smoke Test User',
  737. serviceName: 'MISC',
  738. belongsToService: ['MISC'],
  739. index: 30
  740. },
  741. title: 'smokeuser, service_name = MISC'
  742. },
  743. {
  744. input: {
  745. property_type: ['GROUP'],
  746. property_name: 'user_group'
  747. },
  748. output: {
  749. displayName: 'Hadoop Group'
  750. },
  751. title: 'user_group'
  752. },
  753. {
  754. input: {
  755. property_type: ['USER'],
  756. property_name: 'mapred_user'
  757. },
  758. output: {
  759. displayName: 'MapReduce User'
  760. },
  761. title: 'mapred_user'
  762. },
  763. {
  764. input: {
  765. property_type: ['USER'],
  766. property_name: 'zk_user'
  767. },
  768. output: {
  769. displayName: 'ZooKeeper User'
  770. },
  771. title: 'zk_user'
  772. },
  773. {
  774. input: {
  775. property_type: ['USER'],
  776. property_name: 'ignore_groupsusers_create'
  777. },
  778. output: {
  779. displayName: 'Skip group modifications during install',
  780. displayType: 'checkbox'
  781. },
  782. title: 'ignore_groupsusers_create'
  783. },
  784. {
  785. input: {
  786. property_type: ['GROUP'],
  787. property_name: 'proxyuser_group'
  788. },
  789. output: {
  790. belongsToService: ['HIVE', 'OOZIE', 'FALCON']
  791. },
  792. title: 'proxyuser_group'
  793. },
  794. {
  795. input: {
  796. property_type: ['PASSWORD'],
  797. property_name: 'javax.jdo.option.ConnectionPassword'
  798. },
  799. output: {
  800. displayType: 'password'
  801. },
  802. title: 'password'
  803. }
  804. ];
  805. before(function () {
  806. sinon.stub(App.StackService, 'find').returns([
  807. {
  808. serviceName: 'KNOX'
  809. }
  810. ]);
  811. });
  812. afterEach(function () {
  813. App.get.restore();
  814. });
  815. after(function () {
  816. App.StackService.find.restore();
  817. });
  818. configs.forEach(function (item) {
  819. it(item.title, function () {
  820. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(Boolean(item.isHDPWIN));
  821. var propertyData = App.config.advancedConfigIdentityData(item.input);
  822. Em.keys(item.output).forEach(function (key) {
  823. expect(propertyData[key]).to.eql(item.output[key]);
  824. });
  825. });
  826. });
  827. });
  828. describe('#addUserProperty', function () {
  829. var cases = [
  830. {
  831. stored: {
  832. id: 0,
  833. name: 'prop_name0',
  834. serviceName: 's0',
  835. value: 'v0',
  836. defaultValue: 'dv0',
  837. filename: 'fn0.xml',
  838. overrides: null,
  839. isVisible: false,
  840. isFinal: true,
  841. defaultIsFinal: false,
  842. supportsFinal: true,
  843. category: 'c0'
  844. },
  845. expected: {
  846. id: 0,
  847. name: 'prop_name0',
  848. displayName: 'Prop Name0',
  849. serviceName: 's0',
  850. value: 'v0',
  851. defaultValue: 'dv0',
  852. displayType: 'advanced',
  853. filename: 'fn0.xml',
  854. isUserProperty: false,
  855. hasInitialValue: false,
  856. isOverridable: true,
  857. overrides: null,
  858. isRequired: false,
  859. isVisible: false,
  860. isFinal: true,
  861. defaultIsFinal: false,
  862. supportsFinal: true,
  863. showLabel: true,
  864. category: 'c0'
  865. },
  866. title: 'default case'
  867. },
  868. {
  869. stored: {
  870. name: 'n1',
  871. value: 'multi\nline',
  872. filename: 'fn1.xml',
  873. isUserProperty: true,
  874. hasInitialValue: true,
  875. showLabel: false
  876. },
  877. expected: {
  878. displayType: 'multiLine',
  879. isUserProperty: true,
  880. hasInitialValue: true,
  881. showLabel: false
  882. },
  883. title: 'multiline user property with initial value, label not to be shown'
  884. },
  885. {
  886. stored: {
  887. name: 'n2',
  888. filename: 'fn2.xml'
  889. },
  890. expected: {
  891. isUserProperty: false,
  892. showLabel: true
  893. },
  894. title: 'isUserProperty and showLabel not set'
  895. },
  896. {
  897. stored: {
  898. name: 'ignore_groupsusers_create',
  899. category: 'Users and Groups',
  900. filename: 'fn3.xml'
  901. },
  902. expected: {
  903. displayName: 'dn0',
  904. displayType: 'checkbox',
  905. index: 0
  906. }
  907. },
  908. {
  909. stored: {
  910. name: 'smokeuser',
  911. category: 'Users and Groups',
  912. filename: 'fn4.xml'
  913. },
  914. expected: {
  915. displayName: 'dn1',
  916. index: 1
  917. }
  918. },
  919. {
  920. stored: {
  921. name: 'user_group',
  922. category: 'Users and Groups',
  923. filename: 'fn5.xml'
  924. },
  925. expected: {
  926. displayName: 'dn1',
  927. index: 2
  928. }
  929. },
  930. {
  931. stored: {
  932. name: 'mapred_user',
  933. category: 'Users and Groups',
  934. filename: 'fn6.xml'
  935. },
  936. expected: {
  937. displayName: 'dn1',
  938. index: 3
  939. }
  940. },
  941. {
  942. stored: {
  943. name: 'zk_user',
  944. category: 'Users and Groups',
  945. filename: 'fn7.xml'
  946. },
  947. expected: {
  948. displayName: 'dn1',
  949. index: 4
  950. }
  951. }
  952. ],
  953. advancedConfigs = [
  954. {
  955. name: 'ignore_groupsusers_create',
  956. displayName: 'dn0',
  957. displayType: 'checkbox',
  958. index: 0
  959. },
  960. {
  961. name: 'smokeuser',
  962. displayName: 'dn1',
  963. index: 1
  964. },
  965. {
  966. name: 'user_group',
  967. displayName: 'dn1',
  968. index: 2
  969. },
  970. {
  971. name: 'mapred_user',
  972. displayName: 'dn1',
  973. index: 3
  974. },
  975. {
  976. name: 'zk_user',
  977. displayName: 'dn1',
  978. index: 4
  979. }
  980. ];
  981. cases.forEach(function (item) {
  982. it(item.title || item.stored.name, function () {
  983. var configData = App.config.addUserProperty(item.stored, true, advancedConfigs);
  984. Em.keys(item.expected).forEach(function (key) {
  985. expect(configData[key]).to.equal(item.expected[key]);
  986. });
  987. });
  988. });
  989. });
  990. describe('#getOriginalConfigAttribute', function () {
  991. var stored = {
  992. name: 'p',
  993. displayName: 'dn'
  994. },
  995. cases = [
  996. {
  997. advancedConfigs: [
  998. {
  999. name: 'p',
  1000. displayName: 'dn0'
  1001. }
  1002. ],
  1003. expected: 'dn0',
  1004. title: 'should take attribute from advancedConfigs'
  1005. },
  1006. {
  1007. advancedConfigs: [],
  1008. expected: 'dn',
  1009. title: 'property is absent in advancedConfigs'
  1010. }
  1011. ];
  1012. cases.forEach(function (item) {
  1013. it(item.title, function () {
  1014. expect(App.config.getOriginalConfigAttribute(stored, 'displayName', item.advancedConfigs)).to.equal(item.expected);
  1015. });
  1016. });
  1017. });
  1018. describe('#setConfigValue', function () {
  1019. Em.A([
  1020. {
  1021. mappedConfigs: [
  1022. {
  1023. name: 'falcon_user',
  1024. value: 'fu'
  1025. }
  1026. ],
  1027. allConfigs: [],
  1028. m: 'in mapped, value used',
  1029. e: {
  1030. _name: 'hadoop.proxyuser.fu.groups',
  1031. value: 'fu',
  1032. noMatchSoSkipThisConfig: false
  1033. }
  1034. },
  1035. {
  1036. mappedConfigs: [],
  1037. allConfigs: [
  1038. {
  1039. name: 'falcon_user',
  1040. value: 'fu'
  1041. }
  1042. ],
  1043. m: 'in all, value used',
  1044. e: {
  1045. _name: 'hadoop.proxyuser.fu.groups',
  1046. value: 'fu',
  1047. noMatchSoSkipThisConfig: false
  1048. }
  1049. },
  1050. {
  1051. mappedConfigs: [],
  1052. allConfigs: [
  1053. {
  1054. name: 'falcon_user',
  1055. value: '',
  1056. defaultValue: 'fu'
  1057. }
  1058. ],
  1059. m: 'in all, default value used',
  1060. e: {
  1061. _name: 'hadoop.proxyuser.fu.groups',
  1062. value: 'fu',
  1063. noMatchSoSkipThisConfig: false
  1064. }
  1065. },
  1066. {
  1067. mappedConfigs: [],
  1068. allConfigs: [],
  1069. m: 'not found',
  1070. e: {
  1071. _name: 'hadoop.proxyuser.<foreignKey[0]>.groups',
  1072. value: '<foreignKey[0]>',
  1073. noMatchSoSkipThisConfig: true
  1074. }
  1075. }
  1076. ]).forEach(function (test) {
  1077. it(test.m, function () {
  1078. var config = {
  1079. name: "hadoop.proxyuser.<foreignKey[0]>.groups",
  1080. templateName: ["proxyuser_group"],
  1081. foreignKey: ["falcon_user"],
  1082. noMatchSoSkipThisConfig: false,
  1083. value: "<foreignKey[0]>"
  1084. };
  1085. App.config.setConfigValue(test.mappedConfigs, test.allConfigs, config);
  1086. expect(config.value).to.equal(test.e.value);
  1087. if(test.e.noMatchSoSkipThisConfig) {
  1088. expect(Em.isNone(config._name)).to.be.true;
  1089. }
  1090. else {
  1091. expect(config._name).to.equal(test.e._name);
  1092. }
  1093. expect(config.noMatchSoSkipThisConfig).to.equal(test.e.noMatchSoSkipThisConfig);
  1094. });
  1095. Em.A([
  1096. {
  1097. mappedConfigs: [],
  1098. allConfigs: [
  1099. {
  1100. name: 'falcon_user',
  1101. value: 'fu'
  1102. },
  1103. {
  1104. name: 'proxyuser_group',
  1105. value: 'pg'
  1106. }
  1107. ],
  1108. m: 'in all, template in all',
  1109. e: {
  1110. _name: 'hadoop.proxyuser.fu.groups',
  1111. value: 'fupg'
  1112. }
  1113. },
  1114. {
  1115. mappedConfigs: [
  1116. {
  1117. name: 'falcon_user',
  1118. value: 'fu'
  1119. },
  1120. {
  1121. name: 'proxyuser_group',
  1122. value: 'pg'
  1123. }
  1124. ],
  1125. allConfigs: [],
  1126. m: 'in mapped, template in mapped',
  1127. e: {
  1128. _name: 'hadoop.proxyuser.fu.groups',
  1129. value: 'fupg'
  1130. }
  1131. },
  1132. {
  1133. mappedConfigs: [],
  1134. allConfigs: [],
  1135. m: 'not found (template not found too)',
  1136. e: {
  1137. _name: 'hadoop.proxyuser.<foreignKey[0]>.groups',
  1138. value: null
  1139. }
  1140. }
  1141. ]).forEach(function (test) {
  1142. it(test.m, function () {
  1143. var config = {
  1144. name: "hadoop.proxyuser.<foreignKey[0]>.groups",
  1145. templateName: ["proxyuser_group"],
  1146. foreignKey: ["falcon_user"],
  1147. noMatchSoSkipThisConfig: false,
  1148. value: "<foreignKey[0]><templateName[0]>"
  1149. };
  1150. App.config.setConfigValue(test.mappedConfigs, test.allConfigs, config);
  1151. });
  1152. });
  1153. });
  1154. });
  1155. });