config_test.js 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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('#fileConfigsIntoTextarea', function () {
  69. var filename = 'capacity-scheduler.xml';
  70. var configs = [
  71. {
  72. name: 'config1',
  73. value: 'value1',
  74. defaultValue: 'value1',
  75. filename: 'capacity-scheduler.xml'
  76. },
  77. {
  78. name: 'config2',
  79. value: 'value2',
  80. defaultValue: 'value2',
  81. filename: 'capacity-scheduler.xml'
  82. }
  83. ];
  84. it('two configs into textarea', function () {
  85. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  86. expect(result.length).to.equal(1);
  87. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
  88. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\n');
  89. });
  90. it('three config into textarea', function () {
  91. configs.push({
  92. name: 'config3',
  93. value: 'value3',
  94. defaultValue: 'value3',
  95. filename: 'capacity-scheduler.xml'
  96. });
  97. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  98. expect(result.length).to.equal(1);
  99. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  100. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  101. });
  102. it('one of three configs has different filename', function () {
  103. configs[1].filename = 'another filename';
  104. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  105. //result contains two configs: one with different filename and one textarea config
  106. expect(result.length).to.equal(2);
  107. expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
  108. expect(result[1].defaultValue).to.equal('config1=value1\nconfig3=value3\n');
  109. });
  110. it('none configs into empty textarea', function () {
  111. filename = 'capacity-scheduler.xml';
  112. configs.clear();
  113. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  114. expect(result.length).to.equal(1);
  115. expect(result[0].value).to.equal('');
  116. expect(result[0].defaultValue).to.equal('');
  117. });
  118. it("filename has configs that shouldn't be included in textarea", function () {
  119. var configs = [
  120. {
  121. name: 'config1',
  122. value: 'value1',
  123. defaultValue: 'value1',
  124. filename: filename
  125. },
  126. {
  127. name: 'config2',
  128. value: 'value2',
  129. defaultValue: 'value2',
  130. filename: filename
  131. }
  132. ];
  133. var cfg = {
  134. name: 'config3',
  135. value: 'value3',
  136. defaultValue: 'value3',
  137. filename: filename
  138. };
  139. configs.push(cfg);
  140. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename, [cfg]);
  141. expect(result.length).to.equal(2);
  142. expect(result[1].value).to.equal('config1=value1\nconfig2=value2\n');
  143. expect(result[1].defaultValue).to.equal('config1=value1\nconfig2=value2\n');
  144. expect(configs.findProperty('name', 'config3')).to.eql(cfg);
  145. });
  146. });
  147. describe('#textareaIntoFileConfigs', function () {
  148. var filename = 'capacity-scheduler.xml';
  149. var testData = [
  150. {
  151. configs: [Em.Object.create({
  152. "name": "capacity-scheduler",
  153. "value": "config1=value1",
  154. "filename": "capacity-scheduler.xml",
  155. "isRequiredByAgent": true
  156. })]
  157. },
  158. {
  159. configs: [Em.Object.create({
  160. "name": "capacity-scheduler",
  161. "value": "config1=value1\nconfig2=value2\n",
  162. "filename": "capacity-scheduler.xml",
  163. "isRequiredByAgent": false
  164. })]
  165. },
  166. {
  167. configs: [Em.Object.create({
  168. "name": "capacity-scheduler",
  169. "value": "config1=value1,value2\n",
  170. "filename": "capacity-scheduler.xml",
  171. "isRequiredByAgent": true
  172. })]
  173. },
  174. {
  175. configs: [Em.Object.create({
  176. "name": "capacity-scheduler",
  177. "value": "config1=value1 config2=value2\n",
  178. "filename": "capacity-scheduler.xml",
  179. "isRequiredByAgent": false
  180. })]
  181. }
  182. ];
  183. it('config1=value1 to one config', function () {
  184. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
  185. expect(result.length).to.equal(1);
  186. expect(result[0].value).to.equal('value1');
  187. expect(result[0].name).to.equal('config1');
  188. expect(result[0].isRequiredByAgent).to.be.true;
  189. });
  190. it('config1=value1\\nconfig2=value2\\n to two configs', function () {
  191. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
  192. expect(result.length).to.equal(2);
  193. expect(result[0].value).to.equal('value1');
  194. expect(result[0].name).to.equal('config1');
  195. expect(result[1].value).to.equal('value2');
  196. expect(result[1].name).to.equal('config2');
  197. expect(result[0].isRequiredByAgent).to.be.false;
  198. expect(result[1].isRequiredByAgent).to.be.false;
  199. });
  200. it('config1=value1,value2\n to one config', function () {
  201. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
  202. expect(result.length).to.equal(1);
  203. expect(result[0].value).to.equal('value1,value2');
  204. expect(result[0].name).to.equal('config1');
  205. expect(result[0].isRequiredByAgent).to.be.true;
  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. expect(result[0].isRequiredByAgent).to.be.false;
  211. });
  212. });
  213. describe('#addAvancedConfigs()', function() {
  214. beforeEach(function() {
  215. this.storedConfigs = modelSetup.setupStoredConfigsObject();
  216. });
  217. it('`custom.zoo.cfg` absent in stored configs', function() {
  218. expect(this.storedConfigs.findProperty('name', 'custom.zoo.cfg')).to.be.undefined;
  219. });
  220. it('`custom.zoo.cfg.` from advanced configs should be added to stored configs', function() {
  221. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'ZOOKEEPER');
  222. var property = this.storedConfigs.findProperty('name', 'custom.zoo.cfg');
  223. expect(property).to.be.ok;
  224. expect(property.category).to.eql('Advanced zoo.cfg');
  225. });
  226. it('`capacity-scheduler.xml` property with name `content` should have `displayType` `multiLine`', function() {
  227. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'YARN');
  228. expect(this.storedConfigs.filterProperty('filename', 'capacity-scheduler.xml').findProperty('name','content').displayType).to.eql('multiLine');
  229. });
  230. it('storing different configs with the same name', function () {
  231. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'HBASE');
  232. var properties = this.storedConfigs.filterProperty('name', 'hbase_log_dir');
  233. var hbaseProperty = properties.findProperty('filename', 'hbase-env.xml');
  234. var amsProperty = properties.findProperty('filename', 'ams-hbase-env.xml');
  235. expect(properties).to.have.length(2);
  236. expect(hbaseProperty.serviceName).to.equal('HBASE');
  237. expect(hbaseProperty.value).to.equal('/hadoop/hbase');
  238. expect(amsProperty.serviceName).to.equal('AMBARI_METRICS');
  239. expect(amsProperty.value).to.equal('/hadoop/ams-hbase');
  240. });
  241. });
  242. describe('#trimProperty',function() {
  243. var testMessage = 'displayType `{0}`, value `{1}`{3} should return `{2}`';
  244. var tests = [
  245. {
  246. config: {
  247. displayType: 'directory',
  248. value: ' /a /b /c'
  249. },
  250. e: '/a,/b,/c'
  251. },
  252. {
  253. config: {
  254. displayType: 'directories',
  255. value: ' /a /b '
  256. },
  257. e: '/a,/b'
  258. },
  259. {
  260. config: {
  261. displayType: 'datanodedirs',
  262. value: ' [DISK]/a [SSD]/b '
  263. },
  264. e: '[DISK]/a,[SSD]/b'
  265. },
  266. {
  267. config: {
  268. displayType: 'datanodedirs',
  269. value: '/a,/b, /c\n/d,\n/e /f'
  270. },
  271. e: '/a,/b,/c,/d,/e,/f'
  272. },
  273. {
  274. config: {
  275. displayType: 'host',
  276. value: ' localhost '
  277. },
  278. e: 'localhost'
  279. },
  280. {
  281. config: {
  282. displayType: 'password',
  283. value: ' passw ord '
  284. },
  285. e: ' passw ord '
  286. },
  287. {
  288. config: {
  289. displayType: 'advanced',
  290. value: ' value'
  291. },
  292. e: ' value'
  293. },
  294. {
  295. config: {
  296. displayType: 'advanced',
  297. value: ' value'
  298. },
  299. e: ' value'
  300. },
  301. {
  302. config: {
  303. displayType: 'advanced',
  304. value: 'http://localhost ',
  305. name: 'javax.jdo.option.ConnectionURL'
  306. },
  307. e: 'http://localhost'
  308. },
  309. {
  310. config: {
  311. displayType: 'advanced',
  312. value: 'http://localhost ',
  313. name: 'oozie.service.JPAService.jdbc.url'
  314. },
  315. e: 'http://localhost'
  316. },
  317. {
  318. config: {
  319. displayType: 'custom',
  320. value: ' custom value '
  321. },
  322. e: ' custom value'
  323. },
  324. {
  325. config: {
  326. displayType: 'masterHosts',
  327. value: ['host1.com', 'host2.com']
  328. },
  329. e: ['host1.com', 'host2.com']
  330. }
  331. ];
  332. tests.forEach(function(test) {
  333. it(testMessage.format(test.config.displayType, test.config.value, test.e, !!test.config.name ? ', name `' + test.config.name + '`' : ''), function() {
  334. expect(App.config.trimProperty(test.config)).to.eql(test.e);
  335. expect(App.config.trimProperty(Em.Object.create(test.config), true)).to.eql(test.e);
  336. });
  337. });
  338. });
  339. describe('#OnNnHAHideSnn()', function() {
  340. it('`SNameNode` category present in `ServiceConfig`. It should be removed.', function() {
  341. App.store.load(App.HDFSService, {
  342. 'id': 'HDFS'
  343. });
  344. var ServiceConfig = Em.Object.create({
  345. configCategories: [ { name: 'SNameNode' } ]
  346. });
  347. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.ok;
  348. App.config.OnNnHAHideSnn(ServiceConfig);
  349. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.undefined;
  350. var record = App.HDFSService.find('HDFS');
  351. record.deleteRecord();
  352. record.get('stateManager').transitionTo('loading');
  353. });
  354. it('`SNameNode` category absent in `ServiceConfig`. Nothing to do.', function() {
  355. App.store.load(App.HDFSService, {
  356. 'id': 'HDFS'
  357. });
  358. var ServiceConfig = Em.Object.create({
  359. configCategories: [ { name: 'DataNode' } ]
  360. });
  361. App.config.OnNnHAHideSnn(ServiceConfig);
  362. expect(ServiceConfig.get('configCategories').findProperty('name','DataNode')).to.ok;
  363. expect(ServiceConfig.get('configCategories.length')).to.eql(1);
  364. });
  365. });
  366. describe('#preDefinedConfigFile', function() {
  367. before(function() {
  368. setups.setupStackVersion(this, 'BIGTOP-0.8');
  369. });
  370. it('bigtop site properties should be ok.', function() {
  371. var bigtopSiteProperties = App.config.preDefinedConfigFile('site_properties');
  372. expect(bigtopSiteProperties).to.be.ok;
  373. });
  374. it('a non-existing file should not be ok.', function () {
  375. var notExistingSiteProperty = App.config.preDefinedConfigFile('notExisting');
  376. expect(notExistingSiteProperty).to.not.be.ok;
  377. });
  378. after(function() {
  379. setups.restoreStackVersion(this);
  380. });
  381. });
  382. describe('#preDefinedSiteProperties-bigtop', function () {
  383. before(function() {
  384. setups.setupStackVersion(this, 'BIGTOP-0.8');
  385. });
  386. it('bigtop should use New PostgreSQL Database as its default hive metastore database', function () {
  387. expect(App.config.get('preDefinedSiteProperties').findProperty('defaultValue', 'New PostgreSQL Database')).to.be.ok;
  388. });
  389. after(function() {
  390. setups.restoreStackVersion(this);
  391. });
  392. });
  393. describe('#preDefinedSiteProperties-hdp2', function () {
  394. before(function() {
  395. setups.setupStackVersion(this, 'HDP-2.0');
  396. });
  397. it('HDP2 should use New MySQL Database as its default hive metastore database', function () {
  398. expect(App.config.get('preDefinedSiteProperties').findProperty('defaultValue', 'New MySQL Database')).to.be.ok;
  399. });
  400. after(function() {
  401. setups.restoreStackVersion(this);
  402. });
  403. });
  404. describe('#generateConfigPropertiesByName', function() {
  405. var tests = [
  406. {
  407. names: ['property_1', 'property_2'],
  408. properties: undefined,
  409. e: {
  410. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable']
  411. },
  412. m: 'Should generate base property object without additional fields'
  413. },
  414. {
  415. names: ['property_1', 'property_2'],
  416. properties: { category: 'SomeCat', serviceName: 'SERVICE_NAME' },
  417. e: {
  418. keys: ['name', 'displayName', 'isVisible', 'isReconfigurable', 'category', 'serviceName']
  419. },
  420. m: 'Should generate base property object without additional fields'
  421. }
  422. ];
  423. tests.forEach(function(test) {
  424. it(test.m, function() {
  425. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).length).to.eql(test.names.length);
  426. expect(App.config.generateConfigPropertiesByName(test.names, test.properties).map(function(property) {
  427. return Em.keys(property);
  428. }).reduce(function(p, c) {
  429. return p.concat(c);
  430. }).uniq()).to.eql(test.e.keys);
  431. });
  432. });
  433. });
  434. describe('#setPreDefinedServiceConfigs', function() {
  435. beforeEach(function() {
  436. sinon.stub(App.StackService, 'find', function() {
  437. return [
  438. Em.Object.create({
  439. id: 'HDFS',
  440. serviceName: 'HDFS',
  441. configTypes: {
  442. 'hadoop-env': {},
  443. 'hdfs-site': {}
  444. }
  445. }),
  446. Em.Object.create({
  447. id: 'OOZIE',
  448. serviceName: 'OOZIE',
  449. configTypes: {
  450. 'oozie-env': {},
  451. 'oozie-site': {}
  452. }
  453. })
  454. ];
  455. });
  456. App.config.setPreDefinedServiceConfigs(true);
  457. });
  458. afterEach(function() {
  459. App.StackService.find.restore();
  460. });
  461. it('should include service MISC', function() {
  462. expect(App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC')).to.be.ok;
  463. });
  464. it('should include -env config types according to stack services', function() {
  465. var miscCategory = App.config.get('preDefinedServiceConfigs').findProperty('serviceName', 'MISC');
  466. expect(Em.keys(miscCategory.get('configTypes'))).to.eql(['cluster-env', 'hadoop-env', 'oozie-env']);
  467. });
  468. });
  469. describe('#isManagedMySQLForHiveAllowed', function () {
  470. var cases = [
  471. {
  472. osFamily: 'redhat5',
  473. expected: false
  474. },
  475. {
  476. osFamily: 'redhat6',
  477. expected: true
  478. },
  479. {
  480. osFamily: 'suse11',
  481. expected: false
  482. }
  483. ],
  484. title = 'should be {0} for {1}';
  485. cases.forEach(function (item) {
  486. it(title.format(item.expected, item.osFamily), function () {
  487. expect(App.config.isManagedMySQLForHiveAllowed(item.osFamily)).to.equal(item.expected);
  488. });
  489. });
  490. });
  491. describe('#createAdvancedPropertyObject', function() {
  492. var tests = [
  493. {
  494. name: 'proxyuser_group',
  495. cases: [
  496. {
  497. key: 'displayType',
  498. e: 'user'
  499. },
  500. {
  501. key: 'serviceName',
  502. e: 'MISC'
  503. },
  504. {
  505. key: 'belongsToService',
  506. e: ['HIVE', 'OOZIE', 'FALCON']
  507. }
  508. ]
  509. },
  510. {
  511. name: 'oozie.service.JPAService.jdbc.password',
  512. cases: [
  513. {
  514. key: 'displayType',
  515. e: 'password'
  516. },
  517. {
  518. key: 'isVisible',
  519. e: true
  520. }
  521. ]
  522. },
  523. {
  524. name: 'ignore_groupsusers_create',
  525. cases: [
  526. {
  527. key: 'isVisible',
  528. e: false
  529. }
  530. ]
  531. },
  532. {
  533. name: 'user_group',
  534. cases: [
  535. {
  536. key: 'isVisible',
  537. e: true
  538. },
  539. {
  540. key: 'index',
  541. e: 30
  542. },
  543. {
  544. key: 'displayName',
  545. e: 'Hadoop Group'
  546. }
  547. ]
  548. },
  549. {
  550. name: 'zk_user',
  551. cases: [
  552. {
  553. key: 'displayName',
  554. e: 'ZooKeeper User'
  555. }
  556. ]
  557. },
  558. {
  559. name: 'mapred_user',
  560. cases: [
  561. {
  562. key: 'displayName',
  563. e: 'MapReduce User'
  564. }
  565. ]
  566. },
  567. {
  568. name: 'smokeuser',
  569. cases: [
  570. {
  571. key: 'displayName',
  572. e: 'Smoke Test User'
  573. }
  574. ]
  575. }
  576. ];
  577. var properties = [];
  578. modelSetup.advancedConfigs.items.forEach(function(item) {
  579. properties.push(App.config.createAdvancedPropertyObject(item.StackConfigurations));
  580. });
  581. App.config.loadClusterConfigSuccess(modelSetup.advancedClusterConfigs, {url: '/cluster/configurations'}, {callback: function (items) {properties = properties.concat(items)}});
  582. beforeEach(function () {
  583. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(false);
  584. });
  585. afterEach(function () {
  586. App.get.restore();
  587. });
  588. tests.forEach(function(test) {
  589. test.cases.forEach(function(testCase) {
  590. it('config property `{0}` `{1}` key should be`{2}`'.format(test.name, testCase.key, testCase.e), function() {
  591. var property = properties.findProperty('name', test.name);
  592. expect(Em.get(property, testCase.key)).to.eql(testCase.e);
  593. });
  594. });
  595. });
  596. });
  597. describe('#mergePreDefinedWithLoaded', function() {
  598. var result;
  599. before(function() {
  600. sinon.stub(App.config, 'parseValue', function(value) {return value});
  601. sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({
  602. supportsFinal: ['hdfs-site']
  603. });
  604. setups.setupStackVersion(this, 'HDP-2.2');
  605. loadServiceModelsData(['HDFS', 'STORM']);
  606. App.config.loadAdvancedConfigSuccess(modelSetup.advancedConfigs, { url: '/serviceName/configurations'}, {
  607. callback: function(advancedConfigs) {
  608. App.config.loadClusterConfigSuccess(modelSetup.advancedClusterConfigs, { url: '/cluster/configurations'}, {
  609. callback: function(clusterConfigs) {
  610. var configCategories = modelSetup.setupConfigGroupsObject();
  611. var tags = [
  612. {newTagName: null, tagName: 'version1', siteName: 'hadoop-env'},
  613. {newTagName: null, tagName: 'version1', siteName: 'hdfs-site'},
  614. {newTagName: null, tagName: 'version1', siteName: 'cluster-env'},
  615. {newTagName: null, tagName: 'version1', siteName: 'storm-env'}
  616. ];
  617. var serviceName = 'STORM';
  618. result = App.config.mergePreDefinedWithLoaded(configCategories, advancedConfigs.concat(clusterConfigs), tags, serviceName);
  619. }
  620. });
  621. }
  622. });
  623. });
  624. after(function() {
  625. App.config.parseValue.restore();
  626. App.config.getConfigTypesInfoFromService.restore();
  627. setups.restoreStackVersion(this);
  628. removeServiceModelData(['HDFS', 'STORM']);
  629. });
  630. var propertyTests = [
  631. {
  632. name: 'hdfs_user',
  633. cases: [
  634. {
  635. key: 'displayType',
  636. e: 'user'
  637. },
  638. {
  639. key: 'isVisible',
  640. e: true
  641. },
  642. {
  643. key: 'serviceName',
  644. e: 'MISC'
  645. },
  646. {
  647. key: 'category',
  648. e: 'Users and Groups'
  649. }
  650. ]
  651. }
  652. ];
  653. propertyTests.forEach(function(test) {
  654. test.cases.forEach(function(testCase) {
  655. it('config property `{0}` `{1}` key should be`{2}`'.format(test.name, testCase.key, testCase.e), function() {
  656. var property = result.configs.findProperty('name', test.name);
  657. expect(Em.get(property, testCase.key)).to.equal(testCase.e);
  658. });
  659. });
  660. });
  661. });
  662. describe('#replaceConfigValues', function () {
  663. var cases = [
  664. {
  665. name: 'name',
  666. express: '<templateName[0]>',
  667. value: '<templateName[0]>',
  668. globValue: 'v',
  669. expected: 'v',
  670. title: 'default case'
  671. },
  672. {
  673. name: 'templeton.hive.properties',
  674. express: '<templateName[0]>',
  675. value: 'hive.matestore.uris=<templateName[0]>',
  676. globValue: 'thrift://h0:9933,thrift://h1:9933,thrift://h2:9933',
  677. expected: 'hive.matestore.uris=thrift://h0:9933\\,thrift://h1:9933\\,thrift://h2:9933',
  678. title: 'should escape commas for templeton.hive.properties'
  679. }
  680. ];
  681. cases.forEach(function (item) {
  682. it(item.title, function () {
  683. expect(App.config.replaceConfigValues(item.name, item.express, item.value, item.globValue)).to.equal(item.expected);
  684. });
  685. });
  686. });
  687. describe('#advancedConfigIdentityData', function () {
  688. var configs = [
  689. {
  690. input: {
  691. property_type: ['USER'],
  692. property_name: 'hdfs_user'
  693. },
  694. output: {
  695. id: 'puppet var',
  696. category: 'Users and Groups',
  697. isVisible: true,
  698. serviceName: 'MISC',
  699. isOverridable: false,
  700. isReconfigurable: false,
  701. displayName: 'HDFS User',
  702. displayType: 'user',
  703. index: 30
  704. },
  705. title: 'user, no service name specified, default display name behaviour'
  706. },
  707. {
  708. input: {
  709. property_type: ['GROUP'],
  710. property_name: 'knox_group',
  711. service_name: 'KNOX'
  712. },
  713. output: {
  714. id: 'puppet var',
  715. category: 'Users and Groups',
  716. isVisible: true,
  717. serviceName: 'MISC',
  718. isOverridable: false,
  719. isReconfigurable: false,
  720. displayName: 'Knox Group',
  721. displayType: 'user',
  722. index: 0
  723. },
  724. title: 'group, service_name = KNOX, default display name behaviour'
  725. },
  726. {
  727. input: {
  728. property_type: ['USER']
  729. },
  730. output: {
  731. isVisible: false
  732. },
  733. isHDPWIN: true,
  734. title: 'HDPWIN stack'
  735. },
  736. {
  737. input: {
  738. property_type: ['USER'],
  739. property_name: 'smokeuser',
  740. service_name: 'MISC'
  741. },
  742. output: {
  743. displayName: 'Smoke Test User',
  744. serviceName: 'MISC',
  745. belongsToService: ['MISC'],
  746. index: 30
  747. },
  748. title: 'smokeuser, service_name = MISC'
  749. },
  750. {
  751. input: {
  752. property_type: ['GROUP'],
  753. property_name: 'user_group'
  754. },
  755. output: {
  756. displayName: 'Hadoop Group'
  757. },
  758. title: 'user_group'
  759. },
  760. {
  761. input: {
  762. property_type: ['USER'],
  763. property_name: 'mapred_user'
  764. },
  765. output: {
  766. displayName: 'MapReduce User'
  767. },
  768. title: 'mapred_user'
  769. },
  770. {
  771. input: {
  772. property_type: ['USER'],
  773. property_name: 'zk_user'
  774. },
  775. output: {
  776. displayName: 'ZooKeeper User'
  777. },
  778. title: 'zk_user'
  779. },
  780. {
  781. input: {
  782. property_type: ['USER'],
  783. property_name: 'ignore_groupsusers_create'
  784. },
  785. output: {
  786. displayName: 'Skip group modifications during install',
  787. displayType: 'checkbox'
  788. },
  789. title: 'ignore_groupsusers_create'
  790. },
  791. {
  792. input: {
  793. property_type: ['GROUP'],
  794. property_name: 'proxyuser_group'
  795. },
  796. output: {
  797. belongsToService: ['HIVE', 'OOZIE', 'FALCON']
  798. },
  799. title: 'proxyuser_group'
  800. },
  801. {
  802. input: {
  803. property_type: ['PASSWORD'],
  804. property_name: 'javax.jdo.option.ConnectionPassword'
  805. },
  806. output: {
  807. displayType: 'password'
  808. },
  809. title: 'password'
  810. }
  811. ];
  812. before(function () {
  813. sinon.stub(App.StackService, 'find').returns([
  814. {
  815. serviceName: 'KNOX'
  816. }
  817. ]);
  818. });
  819. afterEach(function () {
  820. App.get.restore();
  821. });
  822. after(function () {
  823. App.StackService.find.restore();
  824. });
  825. configs.forEach(function (item) {
  826. it(item.title, function () {
  827. sinon.stub(App, 'get').withArgs('isHadoopWindowsStack').returns(Boolean(item.isHDPWIN));
  828. var propertyData = App.config.advancedConfigIdentityData(item.input);
  829. Em.keys(item.output).forEach(function (key) {
  830. expect(propertyData[key]).to.eql(item.output[key]);
  831. });
  832. });
  833. });
  834. });
  835. describe('#addUserProperty', function () {
  836. var cases = [
  837. {
  838. stored: {
  839. id: 0,
  840. name: 'prop_name0',
  841. serviceName: 's0',
  842. value: 'v0',
  843. defaultValue: 'dv0',
  844. filename: 'fn0.xml',
  845. overrides: null,
  846. isVisible: false,
  847. isFinal: true,
  848. defaultIsFinal: false,
  849. supportsFinal: true,
  850. category: 'c0'
  851. },
  852. expected: {
  853. id: 0,
  854. name: 'prop_name0',
  855. displayName: 'Prop Name0',
  856. serviceName: 's0',
  857. value: 'v0',
  858. defaultValue: 'dv0',
  859. displayType: 'advanced',
  860. filename: 'fn0.xml',
  861. isUserProperty: false,
  862. hasInitialValue: false,
  863. isOverridable: true,
  864. overrides: null,
  865. isRequired: false,
  866. isVisible: false,
  867. isFinal: true,
  868. defaultIsFinal: false,
  869. supportsFinal: true,
  870. showLabel: true,
  871. category: 'c0'
  872. },
  873. title: 'default case'
  874. },
  875. {
  876. stored: {
  877. name: 'n1',
  878. value: 'multi\nline',
  879. filename: 'fn1.xml',
  880. isUserProperty: true,
  881. hasInitialValue: true,
  882. showLabel: false
  883. },
  884. expected: {
  885. displayType: 'multiLine',
  886. isUserProperty: true,
  887. hasInitialValue: true,
  888. showLabel: false
  889. },
  890. title: 'multiline user property with initial value, label not to be shown'
  891. },
  892. {
  893. stored: {
  894. name: 'n2',
  895. filename: 'fn2.xml'
  896. },
  897. expected: {
  898. isUserProperty: false,
  899. showLabel: true
  900. },
  901. title: 'isUserProperty and showLabel not set'
  902. },
  903. {
  904. stored: {
  905. name: 'ignore_groupsusers_create',
  906. category: 'Users and Groups',
  907. filename: 'fn3.xml'
  908. },
  909. expected: {
  910. displayName: 'dn0',
  911. displayType: 'checkbox',
  912. index: 0
  913. }
  914. },
  915. {
  916. stored: {
  917. name: 'smokeuser',
  918. category: 'Users and Groups',
  919. filename: 'fn4.xml'
  920. },
  921. expected: {
  922. displayName: 'dn1',
  923. index: 1
  924. }
  925. },
  926. {
  927. stored: {
  928. name: 'user_group',
  929. category: 'Users and Groups',
  930. filename: 'fn5.xml'
  931. },
  932. expected: {
  933. displayName: 'dn1',
  934. index: 2
  935. }
  936. },
  937. {
  938. stored: {
  939. name: 'mapred_user',
  940. category: 'Users and Groups',
  941. filename: 'fn6.xml'
  942. },
  943. expected: {
  944. displayName: 'dn1',
  945. index: 3
  946. }
  947. },
  948. {
  949. stored: {
  950. name: 'zk_user',
  951. category: 'Users and Groups',
  952. filename: 'fn7.xml'
  953. },
  954. expected: {
  955. displayName: 'dn1',
  956. index: 4
  957. }
  958. }
  959. ],
  960. advancedConfigs = [
  961. {
  962. name: 'ignore_groupsusers_create',
  963. displayName: 'dn0',
  964. displayType: 'checkbox',
  965. index: 0
  966. },
  967. {
  968. name: 'smokeuser',
  969. displayName: 'dn1',
  970. index: 1
  971. },
  972. {
  973. name: 'user_group',
  974. displayName: 'dn1',
  975. index: 2
  976. },
  977. {
  978. name: 'mapred_user',
  979. displayName: 'dn1',
  980. index: 3
  981. },
  982. {
  983. name: 'zk_user',
  984. displayName: 'dn1',
  985. index: 4
  986. }
  987. ];
  988. cases.forEach(function (item) {
  989. it(item.title || item.stored.name, function () {
  990. var configData = App.config.addUserProperty(item.stored, true, advancedConfigs);
  991. Em.keys(item.expected).forEach(function (key) {
  992. expect(configData[key]).to.equal(item.expected[key]);
  993. });
  994. });
  995. });
  996. });
  997. describe('#getOriginalConfigAttribute', function () {
  998. var stored = {
  999. name: 'p',
  1000. displayName: 'dn'
  1001. },
  1002. cases = [
  1003. {
  1004. advancedConfigs: [
  1005. {
  1006. name: 'p',
  1007. displayName: 'dn0'
  1008. }
  1009. ],
  1010. expected: 'dn0',
  1011. title: 'should take attribute from advancedConfigs'
  1012. },
  1013. {
  1014. advancedConfigs: [],
  1015. expected: 'dn',
  1016. title: 'property is absent in advancedConfigs'
  1017. }
  1018. ];
  1019. cases.forEach(function (item) {
  1020. it(item.title, function () {
  1021. expect(App.config.getOriginalConfigAttribute(stored, 'displayName', item.advancedConfigs)).to.equal(item.expected);
  1022. });
  1023. });
  1024. });
  1025. describe('#setConfigValue', function () {
  1026. Em.A([
  1027. {
  1028. mappedConfigs: [
  1029. {
  1030. name: 'falcon_user',
  1031. value: 'fu'
  1032. }
  1033. ],
  1034. allConfigs: [],
  1035. m: 'in mapped, value used',
  1036. e: {
  1037. _name: 'hadoop.proxyuser.fu.groups',
  1038. value: 'fu',
  1039. noMatchSoSkipThisConfig: false
  1040. }
  1041. },
  1042. {
  1043. mappedConfigs: [],
  1044. allConfigs: [
  1045. {
  1046. name: 'falcon_user',
  1047. value: 'fu'
  1048. }
  1049. ],
  1050. m: 'in all, value used',
  1051. e: {
  1052. _name: 'hadoop.proxyuser.fu.groups',
  1053. value: 'fu',
  1054. noMatchSoSkipThisConfig: false
  1055. }
  1056. },
  1057. {
  1058. mappedConfigs: [],
  1059. allConfigs: [
  1060. {
  1061. name: 'falcon_user',
  1062. value: '',
  1063. defaultValue: 'fu'
  1064. }
  1065. ],
  1066. m: 'in all, default value used',
  1067. e: {
  1068. _name: 'hadoop.proxyuser.fu.groups',
  1069. value: 'fu',
  1070. noMatchSoSkipThisConfig: false
  1071. }
  1072. },
  1073. {
  1074. mappedConfigs: [],
  1075. allConfigs: [],
  1076. m: 'not found',
  1077. e: {
  1078. _name: 'hadoop.proxyuser.<foreignKey[0]>.groups',
  1079. value: '<foreignKey[0]>',
  1080. noMatchSoSkipThisConfig: true
  1081. }
  1082. }
  1083. ]).forEach(function (test) {
  1084. it(test.m, function () {
  1085. var config = {
  1086. name: "hadoop.proxyuser.<foreignKey[0]>.groups",
  1087. templateName: ["proxyuser_group"],
  1088. foreignKey: ["falcon_user"],
  1089. noMatchSoSkipThisConfig: false,
  1090. value: "<foreignKey[0]>"
  1091. };
  1092. App.config.setConfigValue(test.mappedConfigs, test.allConfigs, config);
  1093. expect(config.value).to.equal(test.e.value);
  1094. if(test.e.noMatchSoSkipThisConfig) {
  1095. expect(Em.isNone(config._name)).to.be.true;
  1096. }
  1097. else {
  1098. expect(config._name).to.equal(test.e._name);
  1099. }
  1100. expect(config.noMatchSoSkipThisConfig).to.equal(test.e.noMatchSoSkipThisConfig);
  1101. });
  1102. Em.A([
  1103. {
  1104. mappedConfigs: [],
  1105. allConfigs: [
  1106. {
  1107. name: 'falcon_user',
  1108. value: 'fu'
  1109. },
  1110. {
  1111. name: 'proxyuser_group',
  1112. value: 'pg'
  1113. }
  1114. ],
  1115. m: 'in all, template in all',
  1116. e: {
  1117. _name: 'hadoop.proxyuser.fu.groups',
  1118. value: 'fupg'
  1119. }
  1120. },
  1121. {
  1122. mappedConfigs: [
  1123. {
  1124. name: 'falcon_user',
  1125. value: 'fu'
  1126. },
  1127. {
  1128. name: 'proxyuser_group',
  1129. value: 'pg'
  1130. }
  1131. ],
  1132. allConfigs: [],
  1133. m: 'in mapped, template in mapped',
  1134. e: {
  1135. _name: 'hadoop.proxyuser.fu.groups',
  1136. value: 'fupg'
  1137. }
  1138. },
  1139. {
  1140. mappedConfigs: [],
  1141. allConfigs: [],
  1142. m: 'not found (template not found too)',
  1143. e: {
  1144. _name: 'hadoop.proxyuser.<foreignKey[0]>.groups',
  1145. value: null
  1146. }
  1147. }
  1148. ]).forEach(function (test) {
  1149. it(test.m, function () {
  1150. var config = {
  1151. name: "hadoop.proxyuser.<foreignKey[0]>.groups",
  1152. templateName: ["proxyuser_group"],
  1153. foreignKey: ["falcon_user"],
  1154. noMatchSoSkipThisConfig: false,
  1155. value: "<foreignKey[0]><templateName[0]>"
  1156. };
  1157. App.config.setConfigValue(test.mappedConfigs, test.allConfigs, config);
  1158. });
  1159. });
  1160. });
  1161. });
  1162. describe('#shouldSupportFinal', function () {
  1163. var cases = [
  1164. {
  1165. shouldSupportFinal: false,
  1166. title: 'no service name specified'
  1167. },
  1168. {
  1169. serviceName: 's0',
  1170. shouldSupportFinal: false,
  1171. title: 'no filename specified'
  1172. },
  1173. {
  1174. serviceName: 'MISC',
  1175. shouldSupportFinal: false,
  1176. title: 'MISC'
  1177. },
  1178. {
  1179. serviceName: 's0',
  1180. filename: 's0-site',
  1181. shouldSupportFinal: true,
  1182. title: 'final attribute supported'
  1183. },
  1184. {
  1185. serviceName: 's0',
  1186. filename: 's0-env',
  1187. shouldSupportFinal: false,
  1188. title: 'final attribute not supported'
  1189. }
  1190. ];
  1191. beforeEach(function () {
  1192. sinon.stub(App.StackService, 'find').returns([
  1193. {
  1194. serviceName: 's0'
  1195. }
  1196. ]);
  1197. sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({
  1198. supportsFinal: ['s0-site']
  1199. });
  1200. });
  1201. afterEach(function () {
  1202. App.StackService.find.restore();
  1203. App.config.getConfigTypesInfoFromService.restore();
  1204. });
  1205. cases.forEach(function (item) {
  1206. it(item.title, function () {
  1207. expect(App.config.shouldSupportFinal(item.serviceName, item.filename)).to.equal(item.shouldSupportFinal);
  1208. });
  1209. });
  1210. });
  1211. });