blueprint_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  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 blueprintUtils = require('utils/blueprint');
  19. describe('utils/blueprint', function() {
  20. var masterBlueprint = {
  21. blueprint: {
  22. host_groups: [
  23. {
  24. name: "host-group-1",
  25. components: [
  26. { name: "ZOOKEEPER_SERVER" },
  27. { name: "NAMENODE" },
  28. { name: "HBASE_MASTER" }
  29. ]
  30. },
  31. {
  32. name: "host-group-2",
  33. components: [
  34. { name: "SECONDARY_NAMENODE" }
  35. ]
  36. }
  37. ]
  38. },
  39. blueprint_cluster_binding: {
  40. host_groups: [
  41. {
  42. name: "host-group-1",
  43. hosts: [
  44. { fqdn: "host1" },
  45. { fqdn: "host2" }
  46. ]
  47. },
  48. {
  49. name: "host-group-2",
  50. hosts: [
  51. { fqdn: "host3" }
  52. ]
  53. }
  54. ]
  55. }
  56. };
  57. var slaveBlueprint = {
  58. blueprint: {
  59. host_groups: [
  60. {
  61. name: "host-group-1",
  62. components: [
  63. { name: "DATANODE" }
  64. ]
  65. },
  66. {
  67. name: "host-group-2",
  68. components: [
  69. { name: "DATANODE" },
  70. { name: "HDFS_CLIENT" },
  71. { name: "ZOOKEEPER_CLIENT" }
  72. ]
  73. }
  74. ]
  75. },
  76. blueprint_cluster_binding: {
  77. host_groups: [
  78. {
  79. name: "host-group-1",
  80. hosts: [
  81. { fqdn: "host3" }
  82. ]
  83. },
  84. {
  85. name: "host-group-2",
  86. hosts: [
  87. { fqdn: "host4" },
  88. { fqdn: "host5" }
  89. ]
  90. }
  91. ]
  92. }
  93. };
  94. describe('#getHostsFromBlueprint', function() {
  95. it('should extract all hosts from blueprint', function() {
  96. expect(blueprintUtils.getHostsFromBlueprint(masterBlueprint)).to.deep.equal(["host1", "host2", "host3"]);
  97. });
  98. });
  99. describe('#getHostsFromBlueprintByGroupName', function() {
  100. it('should extract hosts from blueprint by given group name', function() {
  101. expect(blueprintUtils.getHostsFromBlueprintByGroupName(masterBlueprint, "host-group-1")).to.deep.equal([
  102. { fqdn: "host1" },
  103. { fqdn: "host2" }
  104. ]);
  105. });
  106. it('should return empty array if group with given name doesn\'t exist', function() {
  107. expect(blueprintUtils.getHostsFromBlueprintByGroupName(masterBlueprint, "not an existing group")).to.deep.equal([]);
  108. });
  109. });
  110. describe('#getComponentsFromBlueprintByGroupName', function() {
  111. it('should extract all components from blueprint for given host', function() {
  112. expect(blueprintUtils.getComponentsFromBlueprintByGroupName(masterBlueprint, "host-group-1")).to.deep.equal([
  113. { name: "ZOOKEEPER_SERVER" },
  114. { name: "NAMENODE" },
  115. { name: "HBASE_MASTER" }
  116. ]);
  117. });
  118. it('should return empty array if group doesn\'t exists', function() {
  119. expect(blueprintUtils.getComponentsFromBlueprintByGroupName(masterBlueprint, "not an existing group")).to.deep.equal([]);
  120. });
  121. it('should return empty array if group name isn\'t valid', function() {
  122. expect(blueprintUtils.getComponentsFromBlueprintByGroupName(masterBlueprint, undefined)).to.deep.equal([]);
  123. });
  124. });
  125. describe('#matchGroups', function() {
  126. it('should compose same host group into pairs', function() {
  127. expect(blueprintUtils.matchGroups(masterBlueprint, slaveBlueprint)).to.deep.equal([
  128. { g1: "host-group-1" },
  129. { g1: "host-group-2", g2: "host-group-1" },
  130. { g2: "host-group-2" }
  131. ]);
  132. });
  133. });
  134. describe('#filterByComponents', function() {
  135. it('should remove all components except', function() {
  136. expect(blueprintUtils.filterByComponents(masterBlueprint, ["NAMENODE"])).to.deep.equal({
  137. blueprint: {
  138. host_groups: [
  139. {
  140. name: "host-group-1",
  141. components: [
  142. { name: "NAMENODE" }
  143. ]
  144. }
  145. ]
  146. },
  147. blueprint_cluster_binding: {
  148. host_groups: [
  149. {
  150. name: "host-group-1",
  151. hosts: [
  152. { fqdn: "host1" },
  153. { fqdn: "host2" }
  154. ]
  155. }
  156. ]
  157. }
  158. });
  159. });
  160. });
  161. describe('#addComponentsToBlueprint', function() {
  162. it('should add components to blueprint', function() {
  163. var components = ["FLUME_HANDLER", "HCAT"];
  164. expect(blueprintUtils.addComponentsToBlueprint(masterBlueprint, components)).to.deep.equal({
  165. blueprint: {
  166. host_groups: [
  167. {
  168. name: "host-group-1",
  169. components: [
  170. { name: "ZOOKEEPER_SERVER" },
  171. { name: "NAMENODE" },
  172. { name: "HBASE_MASTER" },
  173. { name: "FLUME_HANDLER" },
  174. { name: "HCAT" }
  175. ]
  176. },
  177. {
  178. name: "host-group-2",
  179. components: [
  180. { name: "SECONDARY_NAMENODE" },
  181. { name: "FLUME_HANDLER" },
  182. { name: "HCAT" }
  183. ]
  184. }
  185. ]
  186. },
  187. blueprint_cluster_binding: {
  188. host_groups: [
  189. {
  190. name: "host-group-1",
  191. hosts: [
  192. { fqdn: "host1" },
  193. { fqdn: "host2" }
  194. ]
  195. },
  196. {
  197. name: "host-group-2",
  198. hosts: [
  199. { fqdn: "host3" }
  200. ]
  201. }
  202. ]
  203. }
  204. });
  205. });
  206. });
  207. describe('#mergeBlueprints', function() {
  208. it('should merge components', function() {
  209. expect(blueprintUtils.mergeBlueprints(masterBlueprint, slaveBlueprint)).to.deep.equal(
  210. {
  211. blueprint: {
  212. host_groups: [
  213. {
  214. name: "host-group-1",
  215. components: [
  216. { name: "ZOOKEEPER_SERVER" },
  217. { name: "NAMENODE" },
  218. { name: "HBASE_MASTER" }
  219. ]
  220. },
  221. {
  222. name: "host-group-2",
  223. components: [
  224. { name: "SECONDARY_NAMENODE" },
  225. { name: "DATANODE" }
  226. ]
  227. },
  228. {
  229. name: "host-group-3",
  230. components: [
  231. { name: "DATANODE" },
  232. { name: "HDFS_CLIENT" },
  233. { name: "ZOOKEEPER_CLIENT" }
  234. ]
  235. }
  236. ]
  237. },
  238. blueprint_cluster_binding: {
  239. host_groups: [
  240. {
  241. name: "host-group-1",
  242. hosts: [
  243. { fqdn: "host1" },
  244. { fqdn: "host2" }
  245. ]
  246. },
  247. {
  248. name: "host-group-2",
  249. hosts: [
  250. { fqdn: "host3" }
  251. ]
  252. },
  253. {
  254. name: "host-group-3",
  255. hosts: [
  256. { fqdn: "host4" },
  257. { fqdn: "host5" }
  258. ]
  259. }
  260. ]
  261. }
  262. }
  263. );
  264. });
  265. });
  266. describe('#buildConfisJSON', function () {
  267. var tests = [
  268. {
  269. "services": [
  270. Em.Object.create({
  271. serviceName: "YARN",
  272. configTypes: {
  273. "yarn-site": {},
  274. "yarn-env": {}
  275. },
  276. isInstalled: true
  277. })
  278. ],
  279. "stepConfigs": [
  280. Em.Object.create({
  281. serviceName: "YARN",
  282. configs: [
  283. Em.Object.create({
  284. name: "p1",
  285. value: "v1",
  286. filename: "yarn-site.xml"
  287. }),
  288. Em.Object.create({
  289. name: "p2",
  290. value: "v2",
  291. filename: "yarn-site.xml"
  292. }),
  293. Em.Object.create({
  294. name: "p3",
  295. value: "v3",
  296. filename: "yarn-env.xml"
  297. })
  298. ]
  299. })
  300. ],
  301. "configurations": {
  302. "yarn-site": {
  303. "properties": {
  304. "p1": "v1",
  305. "p2": "v2"
  306. }
  307. },
  308. "yarn-env": {
  309. "properties": {
  310. "p3": "v3"
  311. }
  312. }
  313. }
  314. }
  315. ];
  316. tests.forEach(function (test) {
  317. it("generate configs for request (use in validation)", function () {
  318. expect(blueprintUtils.buildConfisJSON(test.services, test.stepConfigs)).to.eql(test.configurations);
  319. });
  320. });
  321. });
  322. describe('#generateHostGroups', function () {
  323. var tests = [
  324. {
  325. "hostNames": ["host1", "host2"],
  326. "hostComponents": [
  327. Em.Object.create({
  328. componentName: "C1",
  329. hostName: "host1"
  330. }),
  331. Em.Object.create({
  332. componentName: "C2",
  333. hostName: "host1"
  334. }),
  335. Em.Object.create({
  336. componentName: "C1",
  337. hostName: "host2"
  338. }),
  339. Em.Object.create({
  340. componentName: "C3",
  341. hostName: "host2"
  342. })
  343. ],
  344. result: {
  345. blueprint: {
  346. host_groups: [
  347. {
  348. name: "host-group-1",
  349. "components": [
  350. {
  351. "name": "C1"
  352. },
  353. {
  354. "name": "C2"
  355. }
  356. ]
  357. },
  358. {
  359. name: "host-group-2",
  360. "components": [
  361. {
  362. "name": "C1"
  363. },
  364. {
  365. "name": "C3"
  366. }
  367. ]
  368. }
  369. ]
  370. },
  371. blueprint_cluster_binding: {
  372. host_groups: [
  373. {
  374. "name": "host-group-1",
  375. "hosts": [
  376. {
  377. "fqdn": "host1"
  378. }
  379. ]
  380. },
  381. {
  382. "name": "host-group-2",
  383. "hosts": [
  384. {
  385. "fqdn": "host2"
  386. }
  387. ]
  388. }
  389. ]
  390. }
  391. }
  392. }
  393. ];
  394. tests.forEach(function (test) {
  395. it("generate host groups", function () {
  396. expect(blueprintUtils.generateHostGroups(test.hostNames, test.hostComponents)).to.eql(test.result);
  397. });
  398. });
  399. });
  400. });