quick_link_view_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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('views/common/quick_view_link_view');
  20. describe('App.QuickViewLinks', function () {
  21. var quickViewLinks = App.QuickViewLinks.create({});
  22. describe('#setProtocol', function() {
  23. var tests = [
  24. { serviceName: "GANGLIA", ambariProperties: { 'ganglia.https': true }, m: "https for ganglia", result: "https" },
  25. { serviceName: "GANGLIA", ambariProperties: { 'ganglia.https': false }, m: "http for ganglia 1", result: "http" },
  26. { serviceName: "GANGLIA", m: "http for ganglia 2", result: "http" },
  27. { serviceName: "YARN", configProperties: [
  28. { type: 'yarn-site', properties: { 'yarn.http.policy': 'HTTPS_ONLY' }}
  29. ], m: "https for yarn", result: "https" },
  30. { serviceName: "YARN", configProperties: [
  31. { type: 'yarn-site', properties: { 'yarn.http.policy': 'HTTP_ONLY' }}
  32. ], m: "http for yarn", result: "http" },
  33. { serviceName: "YARN", configProperties: [
  34. { type: 'yarn-site', properties: { 'yarn.http.policy': 'HTTP_ONLY' }}
  35. ], m: "http for yarn (overrides hadoop.ssl.enabled)", result: "http" },
  36. { serviceName: "YARN", configProperties: [
  37. { type: 'yarn-site', properties: { 'yarn.http.policy': 'HTTPS_ONLY' }}
  38. ], m: "https for yarn (overrides hadoop.ssl.enabled)", result: "https" },
  39. { serviceName: "MAPREDUCE2", configProperties: [
  40. { type: 'mapred-site', properties: { 'mapreduce.jobhistory.http.policy': 'HTTPS_ONLY' }}
  41. ], m: "https for mapreduce2", result: "https" },
  42. { serviceName: "MAPREDUCE2", configProperties: [
  43. { type: 'mapred-site', properties: { 'mapreduce.jobhistory.http.policy': 'HTTP_ONLY' }}
  44. ], m: "http for mapreduce2", result: "http" },
  45. { serviceName: "ANYSERVICE", configProperties: [
  46. { type: 'hdfs-site', properties: { 'dfs.http.policy': 'HTTPS_ONLY' }}
  47. ], m: "https for anyservice", servicesSupportsHttps: ["ANYSERVICE"], result: "https" }
  48. ];
  49. tests.forEach(function(t) {
  50. it(t.m, function() {
  51. quickViewLinks.set('servicesSupportsHttps', t.servicesSupportsHttps);
  52. expect(quickViewLinks.setProtocol(t.serviceName, t.configProperties, t.ambariProperties)).to.equal(t.result);
  53. });
  54. });
  55. });
  56. describe('#setPort', function () {
  57. var testData = [
  58. Em.Object.create({
  59. 'service_id': 'YARN',
  60. 'protocol': 'http',
  61. 'result': '8088',
  62. 'default_http_port': '8088',
  63. 'default_https_port': '8090',
  64. 'regex': '\\w*:(\\d+)'
  65. }),
  66. Em.Object.create({
  67. 'service_id': 'YARN',
  68. 'protocol': 'https',
  69. 'https_config': 'https_config',
  70. 'result': '8090',
  71. 'default_http_port': '8088',
  72. 'default_https_port': '8090',
  73. 'regex': '\\w*:(\\d+)'
  74. }),
  75. Em.Object.create({
  76. 'service_id': 'YARN',
  77. 'protocol': 'https',
  78. 'https_config': 'https_config',
  79. 'result': '8090',
  80. 'default_http_port': '8088',
  81. 'default_https_port': '8090',
  82. 'regex': '\\w*:(\\d+)'
  83. })
  84. ];
  85. testData.forEach(function(item) {
  86. it(item.service_id + ' ' + item.protocol, function () {
  87. expect(quickViewLinks.setPort(item, item.protocol, item.version)).to.equal(item.result);
  88. })
  89. },this);
  90. });
  91. describe('#setHost', function () {
  92. var quickViewLinks = App.QuickViewLinks.create({
  93. content: Em.Object.create()
  94. }),
  95. cases = [
  96. {
  97. singleNodeInstall: true,
  98. hosts: ['host0'],
  99. title: 'single node install'
  100. },
  101. {
  102. response: {
  103. items: [
  104. {
  105. host_components: [
  106. {
  107. HostRoles: {
  108. component_name: 'STORM_UI_SERVER'
  109. }
  110. }
  111. ],
  112. Hosts: {
  113. public_host_name: 'host3'
  114. }
  115. }
  116. ]
  117. },
  118. serviceName: 'STORM',
  119. hosts: ['host3']
  120. },
  121. {
  122. serviceName: 'PIG',
  123. hosts: [],
  124. title: 'client only service'
  125. },
  126. {
  127. response: {
  128. items: [
  129. {
  130. host_components: [
  131. {
  132. HostRoles: {
  133. component_name: 'ZOOKEEPER_SERVER'
  134. }
  135. }
  136. ],
  137. Hosts: {
  138. public_host_name: 'host4'
  139. }
  140. }
  141. ]
  142. },
  143. serviceName: 'ZOOKEEPER',
  144. hosts: ['host4'],
  145. setup: function () {
  146. quickViewLinks.set('content', {
  147. hostComponents: [
  148. Em.Object.create({
  149. componentName: 'ZOOKEEPER_SERVER',
  150. isMaster: true
  151. })
  152. ]
  153. });
  154. },
  155. title: 'service with master component, except HDFS, HBase, YARN and Storm'
  156. },
  157. {
  158. response: {
  159. items: [
  160. {
  161. host_components: [
  162. {
  163. HostRoles: {
  164. component_name: 'NAMENODE'
  165. }
  166. }
  167. ],
  168. Hosts: {
  169. public_host_name: 'host5'
  170. }
  171. }
  172. ]
  173. },
  174. serviceName: 'HDFS',
  175. hosts: ['host5'],
  176. setup: function () {
  177. quickViewLinks.set('content', {
  178. snameNode: true
  179. });
  180. },
  181. title: 'HDFS, HA disabled'
  182. },
  183. {
  184. response: {
  185. items: [
  186. {
  187. host_components: [
  188. {
  189. HostRoles: {
  190. component_name: 'NAMENODE'
  191. }
  192. }
  193. ],
  194. Hosts: {
  195. host_name: 'host6',
  196. public_host_name: 'host6'
  197. }
  198. },
  199. {
  200. host_components: [
  201. {
  202. HostRoles: {
  203. component_name: 'NAMENODE'
  204. }
  205. }
  206. ],
  207. Hosts: {
  208. host_name: 'host7',
  209. public_host_name: 'host7'
  210. }
  211. },
  212. {
  213. host_components: [
  214. {
  215. HostRoles: {
  216. component_name: 'NAMENODE'
  217. }
  218. }
  219. ],
  220. Hosts: {
  221. host_name: 'host8',
  222. public_host_name: 'host8'
  223. }
  224. }
  225. ]
  226. },
  227. serviceName: 'HDFS',
  228. multipleMasters: true,
  229. hosts: ['host6', 'host7', 'host8'],
  230. setup: function () {
  231. quickViewLinks.set('content', {
  232. hostComponents: [
  233. Em.Object.create({
  234. componentName: 'NAMENODE',
  235. hostName: 'host6'
  236. }),
  237. Em.Object.create({
  238. componentName: 'NAMENODE',
  239. hostName: 'host7'
  240. }),
  241. Em.Object.create({
  242. componentName: 'NAMENODE',
  243. hostName: 'host8'
  244. })
  245. ],
  246. activeNameNode: {
  247. hostName: 'host6'
  248. },
  249. standbyNameNode: {
  250. hostName: 'host7'
  251. },
  252. standbyNameNode2: {
  253. hostName: 'host8'
  254. }
  255. });
  256. },
  257. title: 'HDFS, HA enabled'
  258. },
  259. {
  260. response: {
  261. items: [
  262. {
  263. host_components: [
  264. {
  265. HostRoles: {
  266. component_name: 'RESOURCEMANAGER'
  267. }
  268. }
  269. ],
  270. Hosts: {
  271. public_host_name: 'host9'
  272. }
  273. }
  274. ]
  275. },
  276. serviceName: 'YARN',
  277. hosts: ['host9'],
  278. title: 'YARN, HA disabled'
  279. },
  280. {
  281. response: {
  282. items: [
  283. {
  284. host_components: [
  285. {
  286. HostRoles: {
  287. component_name: 'RESOURCEMANAGER'
  288. }
  289. }
  290. ],
  291. Hosts: {
  292. host_name: 'host10',
  293. public_host_name: 'host10'
  294. }
  295. },
  296. {
  297. host_components: [
  298. {
  299. HostRoles: {
  300. component_name: 'RESOURCEMANAGER'
  301. }
  302. }
  303. ],
  304. Hosts: {
  305. host_name: 'host11',
  306. public_host_name: 'host11'
  307. }
  308. },
  309. {
  310. host_components: [
  311. {
  312. HostRoles: {
  313. component_name: 'RESOURCEMANAGER'
  314. }
  315. }
  316. ],
  317. Hosts: {
  318. host_name: 'host12',
  319. public_host_name: 'host12'
  320. }
  321. }
  322. ]
  323. },
  324. serviceName: 'YARN',
  325. multipleMasters: true,
  326. hosts: ['host10', 'host11', 'host12'],
  327. setup: function () {
  328. quickViewLinks.set('content', {
  329. hostComponents: [
  330. Em.Object.create({
  331. componentName: 'RESOURCEMANAGER',
  332. hostName: 'host10'
  333. }),
  334. Em.Object.create({
  335. componentName: 'RESOURCEMANAGER',
  336. hostName: 'host11'
  337. }),
  338. Em.Object.create({
  339. componentName: 'RESOURCEMANAGER',
  340. hostName: 'host12'
  341. })
  342. ]
  343. });
  344. },
  345. title: 'YARN, HA enabled'
  346. },
  347. {
  348. response: {
  349. items: [
  350. {
  351. host_components: [
  352. {
  353. HostRoles: {
  354. component_name: 'HBASE_MASTER'
  355. },
  356. metrics: {
  357. hbase: {
  358. master: {
  359. IsActiveMaster: true
  360. }
  361. }
  362. }
  363. }
  364. ],
  365. Hosts: {
  366. host_name: 'host13',
  367. public_host_name: 'host13'
  368. }
  369. },
  370. {
  371. host_components: [
  372. {
  373. HostRoles: {
  374. component_name: 'HBASE_MASTER'
  375. },
  376. metrics: {
  377. hbase: {
  378. master: {
  379. IsActiveMaster: false
  380. }
  381. }
  382. }
  383. }
  384. ],
  385. Hosts: {
  386. host_name: 'host14',
  387. public_host_name: 'host14'
  388. }
  389. },
  390. {
  391. host_components: [
  392. {
  393. HostRoles: {
  394. component_name: 'HBASE_MASTER'
  395. }
  396. }
  397. ],
  398. Hosts: {
  399. host_name: 'host15',
  400. public_host_name: 'host15'
  401. }
  402. }
  403. ]
  404. },
  405. serviceName: 'HBASE',
  406. multipleMasters: true,
  407. hosts: ['host13', 'host14', 'host15']
  408. }
  409. ];
  410. before(function () {
  411. sinon.stub(App.StackService, 'find', function () {
  412. return [
  413. Em.Object.create({
  414. serviceName: 'ZOOKEEPER',
  415. hasMaster: true
  416. }),
  417. Em.Object.create({
  418. serviceName: 'PIG',
  419. hasMaster: false
  420. })
  421. ];
  422. })
  423. });
  424. after(function () {
  425. App.StackService.find.restore();
  426. });
  427. afterEach(function () {
  428. App.get.restore();
  429. });
  430. cases.forEach(function (item) {
  431. it(item.title || item.serviceName, function () {
  432. if (item.setup) {
  433. item.setup();
  434. }
  435. sinon.stub(App, 'get').withArgs('singleNodeInstall').returns(item.singleNodeInstall).
  436. withArgs('singleNodeAlias').returns('host0').
  437. withArgs('isRMHaEnabled').returns(item.multipleMasters);
  438. if (item.multipleMasters) {
  439. expect(quickViewLinks.setHost(item.response, item.serviceName).mapProperty('publicHostName')).to.eql(item.hosts);
  440. } else {
  441. expect(quickViewLinks.setHost(item.response, item.serviceName)).to.eql(item.hosts);
  442. }
  443. });
  444. });
  445. });
  446. });