step3_controller_test.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 controller;
  20. describe('App.HighAvailabilityWizardStep3Controller', function() {
  21. var serverConfigData = {
  22. items: [
  23. {
  24. type: 'hdfs-site',
  25. properties: {
  26. 'dfs.namenode.http-address': 'h1:1234',
  27. 'dfs.namenode.https-address': 'h1:4321',
  28. 'dfs.namenode.rpc-address': 'h1:1111',
  29. 'dfs.journalnode.edits.dir': '/hadoop/hdfs/journalnode123'
  30. }
  31. },
  32. {
  33. type: 'zoo.cfg',
  34. properties: {
  35. clientPort: '4444'
  36. }
  37. },
  38. {
  39. type: 'hbase-site',
  40. properties: {
  41. 'hbase.rootdir': 'hdfs://h34:8020/apps/hbase/data'
  42. }
  43. },
  44. {
  45. type: 'ams-hbase-site',
  46. properties: {
  47. 'hbase.rootdir': 'file:///var/lib/ambari-metrics-collector/hbase'
  48. }
  49. },
  50. {
  51. type: 'accumulo-site',
  52. properties: {
  53. 'instance.volumes': 'hdfs://localhost:8020/apps/accumulo/data'
  54. }
  55. },
  56. {
  57. type: 'hawq-site',
  58. properties: {
  59. 'hawq_dfs_url': 'localhost:8020/hawq_default'
  60. }
  61. }
  62. ]
  63. };
  64. beforeEach(function () {
  65. controller = App.HighAvailabilityWizardStep3Controller.create();
  66. controller.set('serverConfigData', serverConfigData);
  67. });
  68. afterEach(function () {
  69. controller.destroy();
  70. });
  71. describe('#removeConfigs', function() {
  72. var tests = [
  73. {
  74. m: 'should not delete properties if configsToRemove is empty',
  75. configs: {
  76. items: [
  77. {
  78. type: 'site1',
  79. properties: {
  80. property1: 'value1',
  81. property2: 'value2',
  82. property3: 'value3',
  83. property4: 'value4'
  84. }
  85. }
  86. ]
  87. },
  88. toRemove: {},
  89. expected: {
  90. items: [
  91. {
  92. type: 'site1',
  93. properties: {
  94. property1: 'value1',
  95. property2: 'value2',
  96. property3: 'value3',
  97. property4: 'value4'
  98. }
  99. }
  100. ]
  101. }
  102. },
  103. {
  104. m: 'should delete properties from configsToRemove',
  105. configs: {
  106. items: [
  107. {
  108. type: 'site1',
  109. properties: {
  110. property1: 'value1',
  111. property2: 'value2',
  112. property3: 'value3',
  113. property4: 'value4'
  114. }
  115. }
  116. ]
  117. },
  118. toRemove: {
  119. 'site1': ['property1', 'property3']
  120. },
  121. expected: {
  122. items: [
  123. {
  124. type: 'site1',
  125. properties: {
  126. property2: 'value2',
  127. property4: 'value4'
  128. }
  129. }
  130. ]
  131. }
  132. },
  133. {
  134. m: 'should delete properties from configsToRemove from different sites',
  135. configs: {
  136. items: [
  137. {
  138. type: 'site1',
  139. properties: {
  140. property1: 'value1',
  141. property2: 'value2',
  142. property3: 'value3',
  143. property4: 'value4'
  144. }
  145. },
  146. {
  147. type: 'site2',
  148. properties: {
  149. property1: 'value1',
  150. property2: 'value2',
  151. property3: 'value3',
  152. property4: 'value4'
  153. }
  154. }
  155. ]
  156. },
  157. toRemove: {
  158. 'site1': ['property1', 'property3'],
  159. 'site2': ['property2', 'property4']
  160. },
  161. expected: {
  162. items: [
  163. {
  164. type: 'site1',
  165. properties: {
  166. property2: 'value2',
  167. property4: 'value4'
  168. }
  169. },
  170. {
  171. type: 'site2',
  172. properties: {
  173. property1: 'value1',
  174. property3: 'value3'
  175. }
  176. }
  177. ]
  178. }
  179. }
  180. ];
  181. tests.forEach(function(test) {
  182. it(test.m, function() {
  183. var _controller = App.HighAvailabilityWizardStep3Controller.create({
  184. configsToRemove: test.toRemove,
  185. serverConfigData: test.configs
  186. });
  187. var result = _controller.removeConfigs(test.toRemove, _controller.get('serverConfigData'));
  188. expect(JSON.stringify(_controller.get('serverConfigData'))).to.equal(JSON.stringify(test.expected));
  189. expect(JSON.stringify(result)).to.equal(JSON.stringify(test.expected));
  190. });
  191. });
  192. });
  193. describe('#tweakServiceConfigs', function () {
  194. var nameServiceId = 'tdk';
  195. var masterComponentHosts = [
  196. {component: 'NAMENODE', isInstalled: true, hostName: 'h1'},
  197. {component: 'NAMENODE', isInstalled: false, hostName: 'h2'},
  198. {component: 'JOURNALNODE', hostName: 'h1'},
  199. {component: 'JOURNALNODE', hostName: 'h2'},
  200. {component: 'JOURNALNODE', hostName: 'h3'},
  201. {component: 'ZOOKEEPER_SERVER', hostName: 'h1'},
  202. {component: 'ZOOKEEPER_SERVER', hostName: 'h2'},
  203. {component: 'ZOOKEEPER_SERVER', hostName: 'h3'}
  204. ];
  205. beforeEach(function () {
  206. controller.set('content', Em.Object.create({
  207. masterComponentHosts: masterComponentHosts,
  208. slaveComponentHosts: [],
  209. hosts: {},
  210. nameServiceId: nameServiceId
  211. }));
  212. var get = sinon.stub(App, 'get');
  213. get.withArgs('isHadoopWindowsStack').returns(true);
  214. sinon.stub(App.Service, 'find', function () {
  215. return [{serviceName: 'HDFS'}, {serviceName: 'HBASE'}, {serviceName: 'AMBARI_METRICS'}, {serviceName: 'ACCUMULO'}, {serviceName: 'HAWQ'}]
  216. });
  217. });
  218. afterEach(function () {
  219. App.Service.find.restore();
  220. App.get.restore();
  221. });
  222. Em.A([
  223. {
  224. config: {
  225. name: 'dfs.namenode.rpc-address.${dfs.nameservices}.nn1'
  226. },
  227. value: 'h1:1111',
  228. name: 'dfs.namenode.rpc-address.' + nameServiceId + '.nn1'
  229. },
  230. {
  231. config: {
  232. name: 'dfs.namenode.rpc-address.${dfs.nameservices}.nn2'
  233. },
  234. value: 'h2:8020',
  235. name: 'dfs.namenode.rpc-address.' + nameServiceId + '.nn2'
  236. },
  237. {
  238. config: {
  239. name: 'dfs.namenode.http-address.${dfs.nameservices}.nn1'
  240. },
  241. value: 'h1:1234',
  242. name: 'dfs.namenode.http-address.' + nameServiceId + '.nn1'
  243. },
  244. {
  245. config: {
  246. name: 'dfs.namenode.http-address.${dfs.nameservices}.nn2'
  247. },
  248. value: 'h2:50070',
  249. name: 'dfs.namenode.http-address.' + nameServiceId + '.nn2'
  250. },
  251. {
  252. config: {
  253. name: 'dfs.namenode.https-address.${dfs.nameservices}.nn1'
  254. },
  255. value: 'h1:4321',
  256. name: 'dfs.namenode.https-address.' + nameServiceId + '.nn1'
  257. },
  258. {
  259. config: {
  260. name: 'dfs.namenode.https-address.${dfs.nameservices}.nn2'
  261. },
  262. value: 'h2:50470',
  263. name: 'dfs.namenode.https-address.' + nameServiceId + '.nn2'
  264. },
  265. {
  266. config: {
  267. name: 'dfs.namenode.shared.edits.dir'
  268. },
  269. value: 'qjournal://h1:8485;h2:8485;h3:8485/' + nameServiceId
  270. },
  271. {
  272. config: {
  273. name: 'ha.zookeeper.quorum'
  274. },
  275. value: 'h1:4444,h2:4444,h3:4444'
  276. },
  277. {
  278. config: {
  279. name: 'hbase.rootdir',
  280. filename: 'hbase-site'
  281. },
  282. value: 'hdfs://' + nameServiceId + '/apps/hbase/data'
  283. },
  284. {
  285. config: {
  286. name: 'hbase.rootdir',
  287. filename: 'ams-hbase-site'
  288. },
  289. value: 'file:///var/lib/ambari-metrics-collector/hbase'
  290. },
  291. {
  292. config: {
  293. name: 'instance.volumes'
  294. },
  295. value: 'hdfs://' + nameServiceId + '/apps/accumulo/data'
  296. },
  297. {
  298. config: {
  299. name: 'instance.volumes.replacements'
  300. },
  301. value: 'hdfs://localhost:8020/apps/accumulo/data hdfs://' + nameServiceId + '/apps/accumulo/data'
  302. },
  303. {
  304. config: {
  305. name: 'dfs.journalnode.edits.dir'
  306. },
  307. value: '/hadoop/hdfs/journalnode123'
  308. },
  309. {
  310. config: {
  311. name: 'hawq_dfs_url',
  312. filename: 'hawq-site'
  313. },
  314. value: nameServiceId + '/hawq_default'
  315. }
  316. ]).forEach(function (test) {
  317. describe(test.config.name, function () {
  318. var configs;
  319. beforeEach(function () {
  320. test.config.displayName = test.config.name;
  321. configs = controller.tweakServiceConfigs([test.config]);
  322. });
  323. it('value is ' + test.value, function () {
  324. expect(configs[0].value).to.equal(test.value);
  325. });
  326. it('recommendedValue is ' + test.value, function () {
  327. expect(configs[0].recommendedValue).to.equal(test.value);
  328. });
  329. if(test.name) {
  330. it('name is ' + test.name, function () {
  331. expect(configs[0].name).to.equal(test.name);
  332. });
  333. it('displayNamr is' + test.name, function () {
  334. expect(configs[0].displayName).to.equal(test.name);
  335. });
  336. }
  337. });
  338. });
  339. });
  340. });