config_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('config');
  20. require('utils/config');
  21. require('models/service/hdfs');
  22. var setups = require('test/init_model_test');
  23. var modelSetup = setups.configs;
  24. describe('App.config', function () {
  25. 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('#identifyCategory', function () {
  57. var data = {};
  58. it('should return null if config doesn\'t have category', function () {
  59. expect(App.config.identifyCategory(data)).to.equal(null);
  60. });
  61. it('should return "AdvancedCoreSite" if filename "core-site.xml" and serviceName "HDFS"', function () {
  62. data = {
  63. serviceName: 'HDFS',
  64. filename: 'core-site.xml'
  65. };
  66. expect(App.config.identifyCategory(data).name).to.equal('AdvancedCoreSite');
  67. });
  68. it('should return "CapacityScheduler" if filename "capacity-scheduler.xml" and serviceName "YARN"', function () {
  69. data = {
  70. serviceName: 'YARN',
  71. filename: 'capacity-scheduler.xml'
  72. };
  73. expect(App.config.identifyCategory(data).name).to.equal('CapacityScheduler');
  74. });
  75. });
  76. describe('#handleSpecialProperties', function () {
  77. var config = {};
  78. it('value should be transformed to "1024" from "1024m"', function () {
  79. config = {
  80. displayType: 'int',
  81. value: '1024m',
  82. defaultValue: '1024m'
  83. };
  84. App.config.handleSpecialProperties(config);
  85. expect(config.value).to.equal('1024');
  86. expect(config.defaultValue).to.equal('1024');
  87. });
  88. it('value should be transformed to true from "true"', function () {
  89. config = {
  90. displayType: 'checkbox',
  91. value: 'true',
  92. defaultValue: 'true'
  93. };
  94. App.config.handleSpecialProperties(config);
  95. expect(config.value).to.equal(true);
  96. expect(config.defaultValue).to.equal(true);
  97. });
  98. it('value should be transformed to false from "false"', function () {
  99. config = {
  100. displayType: 'checkbox',
  101. value: 'false',
  102. defaultValue: 'false'
  103. };
  104. App.config.handleSpecialProperties(config);
  105. expect(config.value).to.equal(false);
  106. expect(config.defaultValue).to.equal(false);
  107. });
  108. });
  109. describe('#calculateConfigProperties', function () {
  110. var config = {};
  111. var isAdvanced = false;
  112. var advancedConfigs = [];
  113. it('isUserProperty should be true if config is custom(site.xml) and not advanced', function () {
  114. config = {
  115. serviceName: 'HDFS',
  116. filename: 'core-site.xml'
  117. };
  118. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  119. expect(config.isUserProperty).to.equal(true);
  120. });
  121. it('isUserProperty should be false if config from "capacity-scheduler.xml" or "mapred-queue-acls.xml" ', function () {
  122. config = {
  123. name: 'test',
  124. serviceName: 'MAPREDUCE',
  125. filename: 'capacity-scheduler.xml',
  126. isUserProperty: false
  127. };
  128. isAdvanced = true;
  129. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  130. expect(config.isUserProperty).to.equal(false);
  131. });
  132. it('isRequired should be false if config is advanced"', function () {
  133. config = {
  134. name: 'test',
  135. serviceName: 'HDFS',
  136. filename: 'core-site.xml'
  137. };
  138. isAdvanced = true;
  139. advancedConfigs = [{name:'test', filename: 'core-site.xml'}];
  140. App.config.calculateConfigProperties(config, isAdvanced, advancedConfigs);
  141. expect(config.category).to.equal('Advanced');
  142. expect(config.isRequired).to.equal(true);
  143. expect(config.filename).to.equal('core-site.xml');
  144. });
  145. });
  146. describe('#capacitySchedulerFilter', function() {
  147. var testMessage = 'filter should {0} detect `{1}` property';
  148. describe('Stack version >= 2.0', function() {
  149. before(function() {
  150. setups.setupStackVersion(this, 'HDP-2.1');
  151. });
  152. var tests = [
  153. {
  154. config: {
  155. name: 'yarn.scheduler.capacity.maximum-am-resource-percent'
  156. },
  157. e: false
  158. },
  159. {
  160. config: {
  161. name: 'yarn.scheduler.capacity.root.capacity'
  162. },
  163. e: false
  164. },
  165. {
  166. config: {
  167. name: 'yarn.scheduler.capacity.root.default.capacity'
  168. },
  169. e: true
  170. }
  171. ];
  172. tests.forEach(function(test){
  173. it(testMessage.format( !!test.e ? '' : 'not', test.config.name), function() {
  174. expect(App.config.get('capacitySchedulerFilter')(test.config)).to.eql(test.e);
  175. });
  176. });
  177. after(function() {
  178. setups.restoreStackVersion(this);
  179. })
  180. });
  181. describe('Stack version < 2.0', function() {
  182. before(function() {
  183. setups.setupStackVersion(this, 'HDP-1.3');
  184. });
  185. var tests = [
  186. {
  187. config: {
  188. name: 'mapred.capacity-scheduler.maximum-system-jobs'
  189. },
  190. e: false
  191. },
  192. {
  193. config: {
  194. name: 'yarn.scheduler.capacity.root.capacity'
  195. },
  196. e: false
  197. },
  198. {
  199. config: {
  200. name: 'mapred.capacity-scheduler.queue.default.capacity'
  201. },
  202. e: true
  203. },
  204. {
  205. config: {
  206. name: 'mapred.queue.default.acl-administer-jobs'
  207. },
  208. e: true
  209. }
  210. ];
  211. tests.forEach(function(test){
  212. it(testMessage.format( !!test.e ? '' : 'not', test.config.name), function() {
  213. expect(App.config.get('capacitySchedulerFilter')(test.config)).to.eql(test.e);
  214. });
  215. });
  216. after(function() {
  217. setups.restoreStackVersion(this);
  218. });
  219. });
  220. });
  221. describe('#fileConfigsIntoTextarea', function () {
  222. var filename = 'capacity-scheduler.xml';
  223. var configs = [
  224. {
  225. name: 'config1',
  226. value: 'value1',
  227. defaultValue: 'value1',
  228. filename: 'capacity-scheduler.xml'
  229. },
  230. {
  231. name: 'config2',
  232. value: 'value2',
  233. defaultValue: 'value2',
  234. filename: 'capacity-scheduler.xml'
  235. }
  236. ];
  237. it('two configs into textarea', function () {
  238. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  239. expect(result.length).to.equal(1);
  240. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\n');
  241. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\n');
  242. });
  243. it('three config into textarea', function () {
  244. configs.push({
  245. name: 'config3',
  246. value: 'value3',
  247. defaultValue: 'value3',
  248. filename: 'capacity-scheduler.xml'
  249. });
  250. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  251. expect(result.length).to.equal(1);
  252. expect(result[0].value).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  253. expect(result[0].defaultValue).to.equal('config1=value1\nconfig2=value2\nconfig3=value3\n');
  254. });
  255. it('one of three configs has different filename', function () {
  256. configs[1].filename = 'another filename';
  257. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  258. //result contains two configs: one with different filename and one textarea config
  259. expect(result.length).to.equal(2);
  260. expect(result[1].value).to.equal('config1=value1\nconfig3=value3\n');
  261. expect(result[1].defaultValue).to.equal('config1=value1\nconfig3=value3\n');
  262. });
  263. it('none configs into empty textarea', function () {
  264. filename = 'capacity-scheduler.xml';
  265. configs.clear();
  266. var result = App.config.fileConfigsIntoTextarea.call(App.config, configs, filename);
  267. expect(result.length).to.equal(1);
  268. expect(result[0].value).to.equal('');
  269. expect(result[0].defaultValue).to.equal('');
  270. });
  271. });
  272. describe('#textareaIntoFileConfigs', function () {
  273. var filename = 'capacity-scheduler.xml';
  274. var testData = [
  275. {
  276. configs: [Em.Object.create({
  277. "name": "capacity-scheduler",
  278. "value": "config1=value1",
  279. "filename": "capacity-scheduler.xml"
  280. })]
  281. },
  282. {
  283. configs: [Em.Object.create({
  284. "name": "capacity-scheduler",
  285. "value": "config1=value1\nconfig2=value2\n",
  286. "filename": "capacity-scheduler.xml"
  287. })]
  288. },
  289. {
  290. configs: [Em.Object.create({
  291. "name": "capacity-scheduler",
  292. "value": "config1=value1,value2\n",
  293. "filename": "capacity-scheduler.xml"
  294. })]
  295. },
  296. {
  297. configs: [Em.Object.create({
  298. "name": "capacity-scheduler",
  299. "value": "config1=value1 config2=value2\n",
  300. "filename": "capacity-scheduler.xml"
  301. })]
  302. }
  303. ];
  304. it('config1=value1 to one config', function () {
  305. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[0].configs, filename);
  306. expect(result.length).to.equal(1);
  307. expect(result[0].value).to.equal('value1');
  308. expect(result[0].name).to.equal('config1');
  309. });
  310. it('config1=value1\\nconfig2=value2\\n to two configs', function () {
  311. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[1].configs, filename);
  312. expect(result.length).to.equal(2);
  313. expect(result[0].value).to.equal('value1');
  314. expect(result[0].name).to.equal('config1');
  315. expect(result[1].value).to.equal('value2');
  316. expect(result[1].name).to.equal('config2');
  317. });
  318. it('config1=value1,value2\n to one config', function () {
  319. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[2].configs, filename);
  320. expect(result.length).to.equal(1);
  321. expect(result[0].value).to.equal('value1,value2');
  322. expect(result[0].name).to.equal('config1');
  323. });
  324. it('config1=value1 config2=value2 to two configs', function () {
  325. var result = App.config.textareaIntoFileConfigs.call(App.config, testData[3].configs, filename);
  326. expect(result.length).to.equal(1);
  327. });
  328. });
  329. describe('#escapeXMLCharacters', function () {
  330. var testConfigs = [
  331. {
  332. html: '&>"',
  333. json: '&>"'
  334. },
  335. {
  336. html: '&amp;&gt;&quot;&apos;',
  337. json: '&>"\''
  338. },
  339. {
  340. html: '&&gt;',
  341. json: '&>'
  342. },
  343. {
  344. html: '&&&amp;',
  345. json: '&&&'
  346. },
  347. {
  348. html: 'LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lib/native/`$JAVA_HOME/bin/java -d32 -version &amp;&gt; /dev/null;if [ $? -eq 0 ]; then echo Linux-i386-32; else echo Linux-amd64-64;fi`',
  349. json: 'LD_LIBRARY_PATH=/usr/lib/hadoop/lib/native:/usr/lib/hadoop/lib/native/`$JAVA_HOME/bin/java -d32 -version &> /dev/null;if [ $? -eq 0 ]; then echo Linux-i386-32; else echo Linux-amd64-64;fi`'
  350. },
  351. {
  352. html: '&&&amp;',
  353. json: '&amp;&amp;&amp;',
  354. toXml: true
  355. }
  356. ];
  357. testConfigs.forEach(function(t){
  358. it('parsing html ' + t.html + ' `toXml` param passed ' + !!t.toXml, function () {
  359. expect(t.json).to.equal(App.config.escapeXMLCharacters(t.html, t.toXml));
  360. });
  361. });
  362. });
  363. describe('#mergePreDefinedWithLoaded()', function() {
  364. before(function() {
  365. loadServiceModelsData(['HDFS','STORM','ZOOKEEPER']);
  366. setups.setupStackVersion(this, 'HDP-2.1');
  367. });
  368. describe('Load STORM configs: global, storm-site', function() {
  369. before(function() {
  370. loadServiceSpecificConfigs(this, "STORM");
  371. });
  372. it('site property with `masterHosts` display type should pass value validation', function() {
  373. var property = this.result.configs.findProperty('name', 'storm.zookeeper.servers');
  374. expect(property).to.be.ok;
  375. expect(property.displayType).to.eql('masterHosts');
  376. expect(property.value).to.eql(["c6401.ambari.apache.org", "c6402.ambari.apache.org"]);
  377. expect(property.category).to.eql('General')
  378. });
  379. it('non-predefined global properties should not be displayed on UI', function() {
  380. var property = this.result.globalConfigs.findProperty('name', 'nonexistent_property');
  381. expect(property).to.be.a('object');
  382. expect(property.isVisible).to.be.false;
  383. });
  384. it('non-predefined site properties should have displayType advanced/multiLine', function() {
  385. var tests = [
  386. {
  387. property: 'single_line_property',
  388. e: 'advanced'
  389. },
  390. {
  391. property: 'multi_line_property',
  392. e: 'multiLine'
  393. }
  394. ];
  395. tests.forEach(function(test) {
  396. var property = this.result.configs.findProperty('name', test.property);
  397. expect(property).to.be.ok;
  398. expect(property.displayType).to.eql(test.e);
  399. }, this);
  400. });
  401. });
  402. describe('Load HDFS configs: global, hdfs-site, core-site', function() {
  403. before(function() {
  404. loadServiceSpecificConfigs(this, "HDFS");
  405. });
  406. it('Data Node, Name Node, SName Node directory properties should have sorted values', function() {
  407. var tests = [
  408. {
  409. property: "dfs.datanode.data.dir",
  410. e: '/a,/b'
  411. },
  412. {
  413. property: "dfs.namenode.name.dir",
  414. e: '/a,/b,/c'
  415. },
  416. {
  417. property: "dfs.namenode.checkpoint.dir",
  418. e: '/a'
  419. }
  420. ];
  421. tests.forEach(function(test) {
  422. var property = this.result.configs.findProperty('name', test.property);
  423. expect(property).to.be.ok;
  424. expect(property.value).to.eql(test.e);
  425. }, this);
  426. });
  427. });
  428. describe('Load ZOOKEEPER configs: global, zoo.cfg', function() {
  429. before(function() {
  430. loadServiceSpecificConfigs(this, "ZOOKEEPER");
  431. });
  432. it('zoo.cfg configs should have non xml filename', function() {
  433. expect(this.result.configs.findProperty('name', 'custom.zoo.cfg').filename).to.eql('zoo.cfg');
  434. });
  435. });
  436. after(function() {
  437. removeServiceModelData(['HDFS','STORM','ZOOKEEPER']);
  438. setups.restoreStackVersion(this);
  439. });
  440. });
  441. describe('#syncOrderWithPredefined()', function() {
  442. before(function() {
  443. setups.setupStackVersion(this, 'HDP-2.1');
  444. loadServiceModelsData(['HDFS','STORM','ZOOKEEPER']);
  445. loadServiceSpecificConfigs(this, 'HDFS');
  446. });
  447. it('properties should be ordered according to position in predefined data', function() {
  448. var result = App.config.syncOrderWithPredefined(this.result);
  449. expect(result).to.be.a('object');
  450. expect(result.configs.filterProperty('category','DataNode').mapProperty('name')).to.eql(['dfs.datanode.failed.volumes.tolerated', 'dfs.datanode.data.dir']);
  451. });
  452. after(function() {
  453. removeServiceModelData(['HDFS','STORM','ZOOKEEPER']);
  454. });
  455. });
  456. describe('#mergePreDefinedWithStored()', function() {
  457. describe('without `storedConfigs` parameter', function() {
  458. before(function() {
  459. this.installedServiceNames = ['HDFS','STORM', 'ZOOKEEPER'];
  460. setupContentForMergeWithStored(this);
  461. });
  462. var tests = [
  463. {
  464. property: 'dfs.datanode.data.dir',
  465. e: '/hadoop/hdfs/data'
  466. },
  467. {
  468. property: 'dfs.datanode.failed.volumes.tolerated',
  469. e: '2'
  470. }
  471. ];
  472. tests.forEach(function(test) {
  473. it('should set value and defaultValue to ' + test.e + ' for `' + test.property + '`', function() {
  474. expect(this.result.findProperty('name', test.property).value).to.eql(test.e);
  475. expect(this.result.findProperty('name', test.property).defaultValue).to.eql(test.e);
  476. });
  477. });
  478. after(function() {
  479. removeServiceModelData(this.installedServiceNames);
  480. setups.restoreStackVersion(this);
  481. });
  482. });
  483. describe('with `storedConfigs` parameter', function() {
  484. before(function() {
  485. this.installedServiceNames = ['HDFS','STORM','ZOOKEEPER'];
  486. this.storedConfigs = modelSetup.setupStoredConfigsObject();
  487. setupContentForMergeWithStored(this);
  488. });
  489. var tests = [
  490. {
  491. property: 'nonexistent_property',
  492. stored: true,
  493. e: {
  494. value: 'some value',
  495. isVisible: false,
  496. category: 'Advanced',
  497. displayType: 'advanced',
  498. isRequired: true,
  499. isOverridable: true
  500. }
  501. },
  502. {
  503. property: 'content',
  504. filename: 'hdfs-log4j.xml',
  505. stored: true,
  506. predefined: true,
  507. e: {
  508. value: 'hdfs log4j content',
  509. defaultValue: 'hdfs log4j content',
  510. displayType: 'content'
  511. }
  512. },
  513. {
  514. property: 'content',
  515. filename: 'zookeeper-log4j.xml',
  516. stored: false,
  517. predefined: true,
  518. e: {
  519. value: 'zookeeper log4j.xml content',
  520. defaultValue: 'zookeeper log4j.xml content',
  521. displayType: 'content'
  522. }
  523. }
  524. ];
  525. tests.forEach(function(test) {
  526. it('`{0}` should pass validation. stored/predefined: {1}/{2}'.format(test.property, !!test.stored, !!test.predefined), function() {
  527. var property = test.property == 'content' ? this.result.filterProperty('name', 'content').findProperty('filename', test.filename) : this.result.findProperty('name', test.property);
  528. for (var key in test.e) {
  529. expect(property[key]).to.be.eql(test.e[key]);
  530. }
  531. });
  532. });
  533. after(function(){
  534. removeServiceModelData(this.installedServiceNames);
  535. setups.restoreStackVersion(this);
  536. });
  537. });
  538. });
  539. describe('#addAvancedConfigs()', function() {
  540. before(function() {
  541. this.storedConfigs = modelSetup.setupStoredConfigsObject();
  542. });
  543. it('`custom.zoo.cfg` absent in stored configs', function() {
  544. expect(this.storedConfigs.findProperty('name', 'custom.zoo.cfg')).to.be.undefined;
  545. });
  546. it('`custom.zoo.cfg.` from advanced configs should be added to stored configs', function() {
  547. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'ZOOKEEPER');
  548. var property = this.storedConfigs.findProperty('name', 'custom.zoo.cfg');
  549. expect(property).to.be.ok;
  550. expect(property.category).to.eql('Advanced');
  551. });
  552. it('`capacity-scheduler.xml` configs related to `YARN` service should have category `CapacityScheduler`', function() {
  553. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'YARN');
  554. expect(this.storedConfigs.filterProperty('filename', 'capacity-scheduler.xml').mapProperty('category').uniq()).to.eql(['CapacityScheduler']);
  555. });
  556. it('`capacity-scheduler.xml` property with name `content` should have `displayType` `multiLine`', function() {
  557. expect(this.storedConfigs.filterProperty('filename', 'capacity-scheduler.xml').findProperty('name','content').displayType).to.eql('multiLine');
  558. });
  559. });
  560. describe('#addCustomConfigs()', function() {
  561. before(function() {
  562. setups.setupStackVersion(this, 'HDP-2.1');
  563. this.storedConfigs = modelSetup.setupStoredConfigsObject();
  564. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'ZOOKEEPER');
  565. App.config.addAdvancedConfigs(this.storedConfigs, modelSetup.setupAdvancedConfigsObject(), 'YARN');
  566. });
  567. it('`yarn.scheduler.capacity.root.default.capacity` should have `isQueue` flag on', function() {
  568. App.config.addCustomConfigs(this.storedConfigs);
  569. expect(this.storedConfigs.findProperty('name','yarn.scheduler.capacity.root.default.capacity').isQueue).to.be.ok;
  570. });
  571. after(function() {
  572. setups.restoreStackVersion(this);
  573. });
  574. });
  575. describe('#createServiceConfig()', function() {
  576. it('should create valid object for `HDFS`', function() {
  577. var ServiceConfig = App.config.createServiceConfig('HDFS');
  578. expect(ServiceConfig.configCategories.mapProperty('name')).to.include.members(["NameNode","SNameNode","DataNode"]);
  579. });
  580. it('should create valid object for `YARN` with capacity scheduler flag `on`', function() {
  581. var ServiceConfig = App.config.createServiceConfig('YARN');
  582. expect(ServiceConfig.configCategories.mapProperty('name')).to.include.members(["ResourceManager","NodeManager"]);
  583. expect(ServiceConfig.configCategories.findProperty('name', 'CapacityScheduler').customView).to.be.a('Function');
  584. expect(ServiceConfig.configCategories.findProperty('name', 'CapacityScheduler').isCustomView).to.true;
  585. });
  586. it('should create valid object for `YARN` with capacity scheduler flag `off`', function() {
  587. App.supports.capacitySchedulerUi = false;
  588. var ServiceConfig = App.config.createServiceConfig('YARN');
  589. expect(ServiceConfig.configCategories.mapProperty('name')).to.include.members(["ResourceManager","NodeManager"]);
  590. expect(ServiceConfig.configCategories.findProperty('name', 'CapacityScheduler').isCustomView).to.false;
  591. App.supports.capacitySchedulerUi = true;
  592. });
  593. });
  594. describe('#trimProperty',function() {
  595. var testMessage = 'displayType `{0}`, value `{1}`{3} should return `{2}`';
  596. var tests = [
  597. {
  598. config: {
  599. displayType: 'directory',
  600. value: ' /a /b /c'
  601. },
  602. e: '/a,/b,/c'
  603. },
  604. {
  605. config: {
  606. displayType: 'directories',
  607. value: ' /a /b '
  608. },
  609. e: '/a,/b'
  610. },
  611. {
  612. config: {
  613. displayType: 'host',
  614. value: ' localhost '
  615. },
  616. e: 'localhost'
  617. },
  618. {
  619. config: {
  620. displayType: 'password',
  621. value: ' passw ord '
  622. },
  623. e: ' passw ord '
  624. },
  625. {
  626. config: {
  627. displayType: 'advanced',
  628. value: ' value'
  629. },
  630. e: ' value'
  631. },
  632. {
  633. config: {
  634. displayType: 'advanced',
  635. value: ' value'
  636. },
  637. e: ' value'
  638. },
  639. {
  640. config: {
  641. displayType: 'advanced',
  642. value: 'http://localhost ',
  643. name: 'javax.jdo.option.ConnectionURL'
  644. },
  645. e: 'http://localhost'
  646. },
  647. {
  648. config: {
  649. displayType: 'advanced',
  650. value: 'http://localhost ',
  651. name: 'oozie.service.JPAService.jdbc.url'
  652. },
  653. e: 'http://localhost'
  654. },
  655. {
  656. config: {
  657. displayType: 'custom',
  658. value: ' custom value '
  659. },
  660. e: ' custom value'
  661. },
  662. {
  663. config: {
  664. displayType: 'masterHosts',
  665. value: ['host1.com', 'host2.com']
  666. },
  667. e: ['host1.com', 'host2.com']
  668. }
  669. ];
  670. tests.forEach(function(test) {
  671. it(testMessage.format(test.config.displayType, test.config.value, test.e, !!test.config.name ? ', name `' + test.config.name + '`' : ''), function() {
  672. expect(App.config.trimProperty(test.config)).to.eql(test.e);
  673. expect(App.config.trimProperty(Em.Object.create(test.config), true)).to.eql(test.e);
  674. });
  675. });
  676. });
  677. describe('#OnNnHAHideSnn()', function() {
  678. it('`SNameNode` category present in `ServiceConfig`. It should be removed.', function() {
  679. App.store.load(App.HDFSService, {
  680. 'id': 'HDFS'
  681. });
  682. var ServiceConfig = Em.Object.create({
  683. configCategories: [ { name: 'SNameNode' } ]
  684. });
  685. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.ok;
  686. App.config.OnNnHAHideSnn(ServiceConfig);
  687. expect(ServiceConfig.get('configCategories').findProperty('name','SNameNode')).to.undefined;
  688. var record = App.HDFSService.find('HDFS');
  689. record.deleteRecord();
  690. record.get('stateManager').transitionTo('loading');
  691. });
  692. it('`SNameNode` category absent in `ServiceConfig`. Nothing to do.', function() {
  693. App.store.load(App.HDFSService, {
  694. 'id': 'HDFS'
  695. });
  696. var ServiceConfig = Em.Object.create({
  697. configCategories: [ { name: 'DataNode' } ]
  698. });
  699. App.config.OnNnHAHideSnn(ServiceConfig);
  700. expect(ServiceConfig.get('configCategories').findProperty('name','DataNode')).to.ok;
  701. expect(ServiceConfig.get('configCategories.length')).to.eql(1);
  702. });
  703. });
  704. });