step3_controller_test.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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. var testHelpers = require('test/helpers');
  20. var controller;
  21. describe('App.HighAvailabilityWizardStep3Controller', function() {
  22. var serverConfigData = {
  23. items: [
  24. {
  25. type: 'hdfs-site',
  26. properties: {
  27. 'dfs.namenode.http-address': 'h1:1234',
  28. 'dfs.namenode.https-address': 'h1:4321',
  29. 'dfs.namenode.rpc-address': 'h1:1111',
  30. 'dfs.journalnode.edits.dir': '/hadoop/hdfs/journalnode123'
  31. }
  32. },
  33. {
  34. type: 'zoo.cfg',
  35. properties: {
  36. clientPort: '4444'
  37. }
  38. },
  39. {
  40. type: 'hbase-site',
  41. properties: {
  42. 'hbase.rootdir': 'hdfs://h34:8020/apps/hbase/data'
  43. }
  44. },
  45. {
  46. type: 'ams-hbase-site',
  47. properties: {
  48. 'hbase.rootdir': 'file:///var/lib/ambari-metrics-collector/hbase'
  49. }
  50. },
  51. {
  52. type: 'accumulo-site',
  53. properties: {
  54. 'instance.volumes': 'hdfs://localhost:8020/apps/accumulo/data'
  55. }
  56. },
  57. {
  58. type: 'hawq-site',
  59. properties: {
  60. 'hawq_dfs_url': 'localhost:8020/hawq_data'
  61. }
  62. },
  63. {
  64. type: 'ranger-env',
  65. properties: {
  66. 'xasecure.audit.destination.hdfs.dir': 'hdfs://c6401.ambari.apache.org/ranger/audit'
  67. }
  68. }
  69. ]
  70. };
  71. beforeEach(function () {
  72. controller = App.HighAvailabilityWizardStep3Controller.create();
  73. controller.set('serverConfigData', serverConfigData);
  74. });
  75. afterEach(function () {
  76. controller.destroy();
  77. });
  78. describe('#removeConfigs', function() {
  79. var tests = [
  80. {
  81. m: 'should not delete properties if configsToRemove is empty',
  82. configs: {
  83. items: [
  84. {
  85. type: 'site1',
  86. properties: {
  87. property1: 'value1',
  88. property2: 'value2',
  89. property3: 'value3',
  90. property4: 'value4'
  91. }
  92. }
  93. ]
  94. },
  95. toRemove: {},
  96. expected: {
  97. items: [
  98. {
  99. type: 'site1',
  100. properties: {
  101. property1: 'value1',
  102. property2: 'value2',
  103. property3: 'value3',
  104. property4: 'value4'
  105. }
  106. }
  107. ]
  108. }
  109. },
  110. {
  111. m: 'should delete properties from configsToRemove',
  112. configs: {
  113. items: [
  114. {
  115. type: 'site1',
  116. properties: {
  117. property1: 'value1',
  118. property2: 'value2',
  119. property3: 'value3',
  120. property4: 'value4'
  121. }
  122. }
  123. ]
  124. },
  125. toRemove: {
  126. 'site1': ['property1', 'property3']
  127. },
  128. expected: {
  129. items: [
  130. {
  131. type: 'site1',
  132. properties: {
  133. property2: 'value2',
  134. property4: 'value4'
  135. }
  136. }
  137. ]
  138. }
  139. },
  140. {
  141. m: 'should delete properties from configsToRemove from different sites',
  142. configs: {
  143. items: [
  144. {
  145. type: 'site1',
  146. properties: {
  147. property1: 'value1',
  148. property2: 'value2',
  149. property3: 'value3',
  150. property4: 'value4'
  151. }
  152. },
  153. {
  154. type: 'site2',
  155. properties: {
  156. property1: 'value1',
  157. property2: 'value2',
  158. property3: 'value3',
  159. property4: 'value4'
  160. }
  161. }
  162. ]
  163. },
  164. toRemove: {
  165. 'site1': ['property1', 'property3'],
  166. 'site2': ['property2', 'property4']
  167. },
  168. expected: {
  169. items: [
  170. {
  171. type: 'site1',
  172. properties: {
  173. property2: 'value2',
  174. property4: 'value4'
  175. }
  176. },
  177. {
  178. type: 'site2',
  179. properties: {
  180. property1: 'value1',
  181. property3: 'value3'
  182. }
  183. }
  184. ]
  185. }
  186. }
  187. ];
  188. tests.forEach(function(test) {
  189. it(test.m, function() {
  190. var _controller = App.HighAvailabilityWizardStep3Controller.create({
  191. configsToRemove: test.toRemove,
  192. serverConfigData: test.configs
  193. });
  194. var result = _controller.removeConfigs(test.toRemove, _controller.get('serverConfigData'));
  195. expect(JSON.stringify(_controller.get('serverConfigData'))).to.equal(JSON.stringify(test.expected));
  196. expect(JSON.stringify(result)).to.equal(JSON.stringify(test.expected));
  197. });
  198. });
  199. });
  200. describe('#tweakServiceConfigs', function () {
  201. var nameServiceId = 'tdk';
  202. var masterComponentHosts = [
  203. {component: 'NAMENODE', isInstalled: true, hostName: 'h1'},
  204. {component: 'NAMENODE', isInstalled: false, hostName: 'h2'},
  205. {component: 'RANGER_ADMIN', isInstalled: true, hostName: 'h1'},
  206. {component: 'JOURNALNODE', hostName: 'h1'},
  207. {component: 'JOURNALNODE', hostName: 'h2'},
  208. {component: 'JOURNALNODE', hostName: 'h3'},
  209. {component: 'ZOOKEEPER_SERVER', hostName: 'h1'},
  210. {component: 'ZOOKEEPER_SERVER', hostName: 'h2'},
  211. {component: 'ZOOKEEPER_SERVER', hostName: 'h3'}
  212. ];
  213. beforeEach(function () {
  214. controller.set('content', Em.Object.create({
  215. masterComponentHosts: masterComponentHosts,
  216. slaveComponentHosts: [],
  217. hosts: {},
  218. nameServiceId: nameServiceId
  219. }));
  220. var get = sinon.stub(App, 'get');
  221. get.withArgs('isHadoopWindowsStack').returns(true);
  222. sinon.stub(App.Service, 'find', function () {
  223. return [{serviceName: 'HDFS'}, {serviceName: 'HBASE'}, {serviceName: 'AMBARI_METRICS'}, {serviceName: 'ACCUMULO'}, {serviceName: 'HAWQ'}, {serviceName: 'RANGER'}]
  224. });
  225. });
  226. afterEach(function () {
  227. App.Service.find.restore();
  228. App.get.restore();
  229. });
  230. Em.A([
  231. {
  232. config: {
  233. name: 'dfs.namenode.rpc-address.${dfs.nameservices}.nn1',
  234. filename: 'hdfs-site'
  235. },
  236. value: 'h1:1111',
  237. name: 'dfs.namenode.rpc-address.' + nameServiceId + '.nn1'
  238. },
  239. {
  240. config: {
  241. name: 'dfs.namenode.rpc-address.${dfs.nameservices}.nn2',
  242. filename: 'hdfs-site'
  243. },
  244. value: 'h2:8020',
  245. name: 'dfs.namenode.rpc-address.' + nameServiceId + '.nn2'
  246. },
  247. {
  248. config: {
  249. name: 'dfs.namenode.http-address.${dfs.nameservices}.nn1',
  250. filename: 'hdfs-site'
  251. },
  252. value: 'h1:1234',
  253. name: 'dfs.namenode.http-address.' + nameServiceId + '.nn1'
  254. },
  255. {
  256. config: {
  257. name: 'dfs.namenode.http-address.${dfs.nameservices}.nn2',
  258. filename: 'hdfs-site'
  259. },
  260. value: 'h2:50070',
  261. name: 'dfs.namenode.http-address.' + nameServiceId + '.nn2'
  262. },{
  263. config: {
  264. name: 'dfs.namenode.rpc-address.${dfs.nameservices}.nn1',
  265. filename: 'hdfs-client'
  266. },
  267. value: 'h1:1111',
  268. name: 'dfs.namenode.rpc-address.' + nameServiceId + '.nn1'
  269. },
  270. {
  271. config: {
  272. name: 'dfs.namenode.rpc-address.${dfs.nameservices}.nn2',
  273. filename: 'hdfs-client'
  274. },
  275. value: 'h2:8020',
  276. name: 'dfs.namenode.rpc-address.' + nameServiceId + '.nn2'
  277. },
  278. {
  279. config: {
  280. name: 'dfs.namenode.http-address.${dfs.nameservices}.nn1',
  281. filename: 'hdfs-client'
  282. },
  283. value: 'h1:1234',
  284. name: 'dfs.namenode.http-address.' + nameServiceId + '.nn1'
  285. },
  286. {
  287. config: {
  288. name: 'dfs.namenode.http-address.${dfs.nameservices}.nn2',
  289. filename: 'hdfs-client'
  290. },
  291. value: 'h2:50070',
  292. name: 'dfs.namenode.http-address.' + nameServiceId + '.nn2'
  293. },
  294. {
  295. config: {
  296. name: 'dfs.namenode.https-address.${dfs.nameservices}.nn1',
  297. filename: 'hdfs-site'
  298. },
  299. value: 'h1:4321',
  300. name: 'dfs.namenode.https-address.' + nameServiceId + '.nn1'
  301. },
  302. {
  303. config: {
  304. name: 'dfs.namenode.https-address.${dfs.nameservices}.nn2',
  305. filename: 'hdfs-site'
  306. },
  307. value: 'h2:50470',
  308. name: 'dfs.namenode.https-address.' + nameServiceId + '.nn2'
  309. },
  310. {
  311. config: {
  312. name: 'dfs.namenode.shared.edits.dir'
  313. },
  314. value: 'qjournal://h1:8485;h2:8485;h3:8485/' + nameServiceId
  315. },
  316. {
  317. config: {
  318. name: 'ha.zookeeper.quorum'
  319. },
  320. value: 'h1:4444,h2:4444,h3:4444'
  321. },
  322. {
  323. config: {
  324. name: 'hbase.rootdir',
  325. filename: 'hbase-site'
  326. },
  327. value: 'hdfs://' + nameServiceId + '/apps/hbase/data'
  328. },
  329. {
  330. config: {
  331. name: 'hbase.rootdir',
  332. filename: 'ams-hbase-site'
  333. },
  334. value: 'file:///var/lib/ambari-metrics-collector/hbase'
  335. },
  336. {
  337. config: {
  338. name: 'instance.volumes'
  339. },
  340. value: 'hdfs://' + nameServiceId + '/apps/accumulo/data'
  341. },
  342. {
  343. config: {
  344. name: 'instance.volumes.replacements'
  345. },
  346. value: 'hdfs://localhost:8020/apps/accumulo/data hdfs://' + nameServiceId + '/apps/accumulo/data'
  347. },
  348. {
  349. config: {
  350. name: 'dfs.journalnode.edits.dir'
  351. },
  352. value: '/hadoop/hdfs/journalnode123'
  353. },
  354. {
  355. config: {
  356. name: 'hawq_dfs_url',
  357. filename: 'hawq-site'
  358. },
  359. value: nameServiceId + '/hawq_data'
  360. },
  361. {
  362. config: {
  363. name: 'xasecure.audit.destination.hdfs.dir',
  364. filename: 'ranger-env'
  365. },
  366. value: 'hdfs://' + nameServiceId + '/ranger/audit'
  367. }
  368. ]).forEach(function (test) {
  369. describe(test.config.name, function () {
  370. var configs;
  371. beforeEach(function () {
  372. test.config.displayName = test.config.name;
  373. configs = controller.tweakServiceConfigs([test.config]);
  374. });
  375. it('value is ' + test.value, function () {
  376. expect(configs[0].value).to.equal(test.value);
  377. });
  378. it('recommendedValue is ' + test.value, function () {
  379. expect(configs[0].recommendedValue).to.equal(test.value);
  380. });
  381. if(test.name) {
  382. it('name is ' + test.name, function () {
  383. expect(configs[0].name).to.equal(test.name);
  384. });
  385. it('displayName is' + test.name, function () {
  386. expect(configs[0].displayName).to.equal(test.name);
  387. });
  388. }
  389. });
  390. });
  391. it('should set isOverridable=false for each config', function () {
  392. var configs = [
  393. {name: 'prop1'}, {name: 'prop2'}
  394. ];
  395. configs = controller.tweakServiceConfigs(configs);
  396. expect(configs.everyProperty('isOverridable', false)).to.be.true;
  397. });
  398. });
  399. describe('#onLoadConfigsTags', function () {
  400. var data = {Clusters: {desired_configs: {
  401. 'hdfs-site': {tag: 'v1'},
  402. 'core-site': {tag: 'v2'},
  403. 'zoo.cfg': {tag: 'v3'},
  404. 'hbase-site': {tag: 'v4'},
  405. 'accumulo-site': {tag: 'v5'},
  406. 'ams-hbase-site': {tag: 'v6'},
  407. 'hawq-site': {tag: 'v7'},
  408. 'hdfs-client': {tag: 'v8'},
  409. 'ranger-env': {tag: 'v9'}
  410. }}};
  411. beforeEach(function () {
  412. sinon.stub(App.Service, 'find', function () {
  413. return [
  414. Em.Object.create({serviceName: 'HBASE'}),
  415. Em.Object.create({serviceName: 'ACCUMULO'}),
  416. Em.Object.create({serviceName: 'AMBARI_METRICS'}),
  417. Em.Object.create({serviceName: 'HAWQ'}),
  418. Em.Object.create({serviceName: 'RANGER'})
  419. ];
  420. });
  421. controller.onLoadConfigsTags(data);
  422. this.args = testHelpers.findAjaxRequest('name', 'admin.get.all_configurations');
  423. });
  424. afterEach(function () {
  425. App.Service.find.restore();
  426. });
  427. it('urlParams are valid', function () {
  428. expect(this.args[0].data.urlParams).to.be.equal('(type=hdfs-site&tag=v1)|(type=core-site&tag=v2)|(type=zoo.cfg&tag=v3)|(type=hbase-site&tag=v4)|(type=accumulo-site&tag=v5)|(type=ams-hbase-site&tag=v6)|(type=hawq-site&tag=v7)|(type=hdfs-client&tag=v8)|(type=ranger-env&tag=v9)');
  429. });
  430. });
  431. });