step3_controller_test.js 12 KB

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