config_test.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  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. App.supports.capacitySchedulerUi = true;
  26. var loadServiceSpecificConfigs = function(context, serviceName) {
  27. context.configGroups = modelSetup.setupConfigGroupsObject(serviceName);
  28. context.advancedConfigs = modelSetup.setupAdvancedConfigsObject();
  29. context.tags = modelSetup.setupServiceConfigTagsObject(serviceName);
  30. context.result = App.config.mergePreDefinedWithLoaded(context.configGroups, context.advancedConfigs, context.tags, App.Service.find().findProperty('id', serviceName).get('serviceName'));
  31. };
  32. var loadAllServicesConfigs = function(context, serviceNames) {
  33. context.configGroups = modelSetup.setupConfigGroupsObject();
  34. }
  35. var loadServiceModelsData = function(serviceNames) {
  36. serviceNames.forEach(function(serviceName) {
  37. App.store.load(App.Service, {
  38. id: serviceName,
  39. service_name: serviceName
  40. });
  41. });
  42. };
  43. var setupContentForMergeWithStored = function(context) {
  44. loadServiceModelsData(context.installedServiceNames);
  45. loadAllServicesConfigs(context);
  46. setups.setupStackVersion(this, 'HDP-2.1');
  47. context.result = App.config.mergePreDefinedWithStored(context.storedConfigs, modelSetup.setupAdvancedConfigsObject(), context.installedServiceNames);
  48. };
  49. var removeServiceModelData = function(serviceIds) {
  50. serviceIds.forEach(function(serviceId) {
  51. var record = App.Service.find(serviceId);
  52. record.deleteRecord();
  53. record.get('stateManager').transitionTo('loading');
  54. });
  55. };
  56. describe('#handleSpecialProperties', function () {
  57. var config = {};
  58. it('value should be transformed to "1024" from "1024m"', function () {
  59. config = {
  60. displayType: 'int',
  61. value: '1024m',
  62. defaultValue: '1024m'
  63. };
  64. App.config.handleSpecialProperties(config);
  65. expect(config.value).to.equal('1024');
  66. expect(config.defaultValue).to.equal('1024');
  67. });
  68. it('value should be transformed to true from "true"', function () {
  69. config = {
  70. displayType: 'checkbox',
  71. value: 'true',
  72. defaultValue: 'true'
  73. };
  74. App.config.handleSpecialProperties(config);
  75. expect(config.value).to.equal(true);
  76. expect(config.defaultValue).to.equal(true);
  77. });
  78. it('value should be transformed to false from "false"', function () {
  79. config = {
  80. displayType: 'checkbox',
  81. value: 'false',
  82. defaultValue: 'false'
  83. };
  84. App.config.handleSpecialProperties(config);
  85. expect(config.value).to.equal(false);
  86. expect(config.defaultValue).to.equal(false);
  87. });
  88. });
  89. describe('#capacitySchedulerFilter', function() {
  90. var testMessage = 'filter should {0} detect `{1}` property';
  91. describe('Stack version >= 2.0', function() {
  92. before(function() {
  93. setups.setupStackVersion(this, 'HDP-2.1');
  94. });
  95. var tests = [
  96. {
  97. config: {
  98. name: 'yarn.scheduler.capacity.maximum-am-resource-percent'
  99. },
  100. e: false
  101. },
  102. {
  103. config: {
  104. name: 'yarn.scheduler.capacity.root.capacity'
  105. },
  106. e: false
  107. },
  108. {
  109. config: {
  110. name: 'yarn.scheduler.capacity.root.default.capacity'
  111. },
  112. e: true
  113. }
  114. ];
  115. tests.forEach(function(test){
  116. it(testMessage.format( !!test.e ? '' : 'not', test.config.name), function() {
  117. expect(App.config.get('capacitySchedulerFilter')(test.config)).to.eql(test.e);
  118. });
  119. });
  120. after(function() {
  121. setups.restoreStackVersion(this);
  122. })
  123. });
  124. describe('Stack version < 2.0', function() {
  125. before(function() {
  126. setups.setupStackVersion(this, 'HDP-1.3');
  127. });
  128. var tests = [
  129. {
  130. config: {
  131. name: 'mapred.capacity-scheduler.maximum-system-jobs'
  132. },
  133. e: false
  134. },
  135. {
  136. config: {
  137. name: 'yarn.scheduler.capacity.root.capacity'
  138. },
  139. e: false
  140. },
  141. {
  142. config: {
  143. name: 'mapred.capacity-scheduler.queue.default.capacity'
  144. },
  145. e: true
  146. },
  147. {
  148. config: {
  149. name: 'mapred.queue.default.acl-administer-jobs'
  150. },
  151. e: true
  152. }
  153. ];
  154. tests.forEach(function(test){
  155. it(testMessage.format( !!test.e ? '' : 'not', test.config.name), function() {
  156. expect(App.config.get('capacitySchedulerFilter')(test.config)).to.eql(test.e);
  157. });
  158. });
  159. after(function() {
  160. setups.restoreStackVersion(this);
  161. });
  162. });
  163. });
  164. describe('#fileConfigsIntoTextarea', function () {
  165. var filename = 'capacity-scheduler.xml';
  166. var configs = [
  167. {
  168. name: 'config1',
  169. value: 'value1',
  170. defaultValue: 'value1',
  171. filename: 'capacity-scheduler.xml'
  172. },
  173. {
  174. name: 'config2',
  175. value: 'value2',
  176. defaultValue: 'value2',
  177. filename: 'capacity-scheduler.xml'
  178. }
  179. ];
  180. it('two configs into textarea', function () {
  181. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  182. expect(result.length).to.equal(1);
  183. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
  184. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\n');
  185. });
  186. it('three config into textarea', function () {
  187. configs.push({
  188. name: 'config3',
  189. value: 'value3',
  190. defaultValue: 'value3',
  191. filename: 'capacity-scheduler.xml'
  192. });
  193. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  194. expect(result.length).to.equal(1);
  195. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  196. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  197. });
  198. it('one of three configs has different filename', function () {
  199. configs[1].filename = 'another filename';
  200. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  201. //result contains two configs: one with different filename and one textarea config
  202. expect(result.length).to.equal(2);
  203. expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
  204. expect(result[1].defaultValue).to.equal('config1=value1\nconfig3=value3\n');
  205. });
  206. it('none configs into empty textarea', function () {
  207. filename = 'capacity-scheduler.xml';
  208. configs.clear();
  209. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  210. expect(result.length).to.equal(1);
  211. expect(result[0].value).to.equal('');
  212. expect(result[0].defaultValue).to.equal('');
  213. });
  214. });
  215. describe('#textareaIntoFileConfigs', function () {
  216. var filename = 'capacity-scheduler.xml';
  217. var testData = [
  218. {
  219. configs: [Em.Object.create({
  220. "name": "capacity-scheduler",
  221. "value": "config1=value1",
  222. "filename": "capacity-scheduler.xml"
  223. })]
  224. },
  225. {
  226. configs: [Em.Object.create({
  227. "name": "capacity-scheduler",
  228. "value": "config1=value1\nconfig2=value2\n",
  229. "filename": "capacity-scheduler.xml"
  230. })]
  231. },
  232. {
  233. configs: [Em.Object.create({
  234. "name": "capacity-scheduler",
  235. "value": "config1=value1,value2\n",
  236. "filename": "capacity-scheduler.xml"
  237. })]
  238. },
  239. {
  240. configs: [Em.Object.create({
  241. "name": "capacity-scheduler",
  242. "value": "config1=value1 config2=value2\n",
  243. "filename": "capacity-scheduler.xml"
  244. })]
  245. }
  246. ];
  247. it('config1=value1 to one config', function () {
  248. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
  249. expect(result.length).to.equal(1);
  250. expect(result[0].value).to.equal('value1');
  251. expect(result[0].name).to.equal('config1');
  252. });
  253. it('config1=value1\\nconfig2=value2\\n to two configs', function () {
  254. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
  255. expect(result.length).to.equal(2);
  256. expect(result[0].value).to.equal('value1');
  257. expect(result[0].name).to.equal('config1');
  258. expect(result[1].value).to.equal('value2');
  259. expect(result[1].name).to.equal('config2');
  260. });
  261. it('config1=value1,value2\n to one config', function () {
  262. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
  263. expect(result.length).to.equal(1);
  264. expect(result[0].value).to.equal('value1,value2');
  265. expect(result[0].name).to.equal('config1');
  266. });
  267. it('config1=value1 config2=value2 to two configs', function () {
  268. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[3].configs, filename);
  269. expect(result.length).to.equal(1);
  270. });
  271. });
  272. describe('#addAvancedConfigs()', function() {
  273. before(function() {
  274. this.storedConfigs = modelSetup.setupStoredConfigsObject();
  275. });
  276. it('`custom.zoo.cfg` absent in stored configs', function() {
  277. expect(this.storedConfigs.findProperty('name', 'custom.zoo.cfg')).to.be.undefined;
  278. });
  279. it('`custom.zoo.cfg.` from advanced configs should be added to stored configs', function() {
  280. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'ZOOKEEPER');
  281. var property = this.storedConfigs.findProperty('name', 'custom.zoo.cfg');
  282. expect(property).to.be.ok;
  283. expect(property.category).to.eql('Advanced zoo.cfg');
  284. });
  285. it('`capacity-scheduler.xml` property with name `content` should have `displayType` `multiLine`', function() {
  286. expect(this.storedConfigs.filterProperty('filename', 'capacity-scheduler.xml').findProperty('name','content').displayType).to.eql('multiLine');
  287. });
  288. });
  289. describe('#trimProperty',function() {
  290. var testMessage = 'displayType `{0}`, value `{1}`{3} should return `{2}`';
  291. var tests = [
  292. {
  293. config: {
  294. displayType: 'directory',
  295. value: ' /a /b /c'
  296. },
  297. e: '/a,/b,/c'
  298. },
  299. {
  300. config: {
  301. displayType: 'directories',
  302. value: ' /a /b '
  303. },
  304. e: '/a,/b'
  305. },
  306. {
  307. config: {
  308. displayType: 'datanodedirs',
  309. value: ' [DISK]/a [SSD]/b '
  310. },
  311. e: '[DISK]/a,[SSD]/b'
  312. },
  313. {
  314. config: {
  315. displayType: 'host',
  316. value: ' localhost '
  317. },
  318. e: 'localhost'
  319. },
  320. {
  321. config: {
  322. displayType: 'password',
  323. value: ' passw ord '
  324. },
  325. e: ' passw ord '
  326. },
  327. {
  328. config: {
  329. displayType: 'advanced',
  330. value: ' value'
  331. },
  332. e: ' value'
  333. },
  334. {
  335. config: {
  336. displayType: 'advanced',
  337. value: ' value'
  338. },
  339. e: ' value'
  340. },
  341. {
  342. config: {
  343. displayType: 'advanced',
  344. value: 'http://localhost ',
  345. name: 'javax.jdo.option.ConnectionURL'
  346. },
  347. e: 'http://localhost'
  348. },
  349. {
  350. config: {
  351. displayType: 'advanced',
  352. value: 'http://localhost ',
  353. name: 'oozie.service.JPAService.jdbc.url'
  354. },
  355. e: 'http://localhost'
  356. },
  357. {
  358. config: {
  359. displayType: 'custom',
  360. value: ' custom value '
  361. },
  362. e: ' custom value'
  363. },
  364. {
  365. config: {
  366. displayType: 'masterHosts',
  367. value: ['host1.com', 'host2.com']
  368. },
  369. e: ['host1.com', 'host2.com']
  370. }
  371. ];
  372. tests.forEach(function(test) {
  373. it(testMessage.format(test.config.displayType, test.config.value, test.e, !!test.config.name ? ', name `' + test.config.name + '`' : ''), function() {
  374. expect(App.config.trimProperty(test.config)).to.eql(test.e);
  375. expect(App.config.trimProperty(Em.Object.create(test.config), true)).to.eql(test.e);
  376. });
  377. });
  378. });
  379. describe('#OnNnHAHideSnn()', function() {
  380. it('`SNameNode` category present in `ServiceConfig`. It should be removed.', function() {
  381. App.store.load(App.HDFSService, {
  382. 'id': 'HDFS'
  383. });
  384. var ServiceConfig = Em.Object.create({
  385. configCategories: [ { name: 'SNameNode' } ]
  386. });
  387. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.ok;
  388. App.config.OnNnHAHideSnn(ServiceConfig);
  389. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.undefined;
  390. var record = App.HDFSService.find('HDFS');
  391. record.deleteRecord();
  392. record.get('stateManager').transitionTo('loading');
  393. });
  394. it('`SNameNode` category absent in `ServiceConfig`. Nothing to do.', function() {
  395. App.store.load(App.HDFSService, {
  396. 'id': 'HDFS'
  397. });
  398. var ServiceConfig = Em.Object.create({
  399. configCategories: [ { name: 'DataNode' } ]
  400. });
  401. App.config.OnNnHAHideSnn(ServiceConfig);
  402. expect(ServiceConfig.get('configCategories').findProperty('name','DataNode')).to.ok;
  403. expect(ServiceConfig.get('configCategories.length')).to.eql(1);
  404. });
  405. });
  406. describe('#preDefinedConfigFile', function() {
  407. before(function() {
  408. setups.setupStackVersion(this, 'BIGTOP-0.8');
  409. });
  410. it('bigtop site properties should be ok.', function() {
  411. var bigtopSiteProperties = App.config.preDefinedConfigFile('site_properties');
  412. expect(bigtopSiteProperties).to.be.ok;
  413. });
  414. it('a non-existing file should not be ok.', function () {
  415. var notExistingSiteProperty = App.config.preDefinedConfigFile('notExisting');
  416. expect(notExistingSiteProperty).to.not.be.ok;
  417. });
  418. after(function() {
  419. setups.restoreStackVersion(this);
  420. });
  421. });
  422. describe('#preDefinedSiteProperties-bigtop', function () {
  423. before(function() {
  424. setups.setupStackVersion(this, 'BIGTOP-0.8');
  425. });
  426. it('bigtop should use New PostgreSQL Database as its default hive metastore database', function () {
  427. expect(App.config.get('preDefinedSiteProperties').findProperty('defaultValue', 'New PostgreSQL Database')).to.be.ok;
  428. });
  429. after(function() {
  430. setups.restoreStackVersion(this);
  431. });
  432. });
  433. describe('#preDefinedSiteProperties-hdp2', function () {
  434. before(function() {
  435. setups.setupStackVersion(this, 'HDP-2.0');
  436. });
  437. it('HDP2 should use New MySQL Database as its default hive metastore database', function () {
  438. expect(App.config.get('preDefinedSiteProperties').findProperty('defaultValue', 'New MySQL Database')).to.be.ok;
  439. });
  440. after(function() {
  441. setups.restoreStackVersion(this);
  442. });
  443. });
  444. });