host_progress_popup_test.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('controllers/global/background_operations_controller');
  21. require('views/common/modal_popup');
  22. require('utils/helper');
  23. require('utils/host_progress_popup');
  24. describe('App.HostPopup', function () {
  25. var services = [
  26. {
  27. displayName: "Start service WebHCat",
  28. hosts: [
  29. {
  30. logTasks: [
  31. {
  32. Tasks: {
  33. command: "START",
  34. host_name: "ip-10-12-123-90.ec2.internal",
  35. role: "WEBHCAT_SERVER",
  36. status: "QUEUED"
  37. },
  38. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/23/tasks/94"
  39. }
  40. ],
  41. name: "ip-10-12-123-90.ec2.internal",
  42. publicName: "ip-10-12-123-90.ec2.internal",
  43. serviceName: "Start service WebHCat"
  44. }
  45. ],
  46. isRunning: false
  47. },
  48. {
  49. displayName: "Start service Hive/HCat",
  50. hosts: [
  51. {
  52. logTasks: [
  53. {
  54. Tasks: {
  55. command: "INSTALL",
  56. host_name: "ip-10-12-123-90.ec2.internal",
  57. status: "COMPLETED"
  58. },
  59. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/76"
  60. }
  61. ],
  62. name: "ip-10-12-123-90.ec2.internal",
  63. publicName: "ip-10-12-123-90.ec2.internal",
  64. serviceName: "Start service Hive/HCat"
  65. },
  66. {
  67. logTasks: [
  68. {
  69. Tasks: {
  70. command: "START",
  71. host_name: "ip-10-33-7-23.ec2.internal",
  72. status: "COMPLETED"
  73. },
  74. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/78"
  75. },
  76. {
  77. Tasks: {
  78. command: "START",
  79. host_name: "ip-10-33-7-23.ec2.internal",
  80. status: "COMPLETED"
  81. },
  82. href: "http://ec2-54-224-233-43.compute-1.amazonaws.com:8080/api/v1/clusters/mycluster/requests/15/tasks/79"
  83. }
  84. ],
  85. name: "ip-10-33-7-23.ec2.internal",
  86. publicName: "ip-10-33-7-23.ec2.internal",
  87. serviceName: "Start service Hive/HCat"
  88. }
  89. ],
  90. isRunning: false
  91. }
  92. ];
  93. var test_tasks = [
  94. {
  95. t: [
  96. {
  97. Tasks: {
  98. status: 'COMPLETED',
  99. id: 2
  100. }
  101. },
  102. {
  103. Tasks: {
  104. status: 'COMPLETED',
  105. id: 3
  106. }
  107. },
  108. {
  109. Tasks: {
  110. status: 'COMPLETED',
  111. id: 1
  112. }
  113. }
  114. ],
  115. m: 'All COMPLETED',
  116. r: 'SUCCESS',
  117. p: 100,
  118. ids: [1,2,3]
  119. },
  120. {
  121. t: [
  122. {
  123. Tasks: {
  124. status: 'FAILED',
  125. id: 2
  126. }
  127. },
  128. {
  129. Tasks: {
  130. status: 'COMPLETED',
  131. id: 1
  132. }
  133. }
  134. ,
  135. {
  136. Tasks: {
  137. status: 'COMPLETED',
  138. id: 3
  139. }
  140. }
  141. ],
  142. m: 'One FAILED',
  143. r: 'FAILED',
  144. p: 100,
  145. ids: [1,2,3]
  146. },
  147. {
  148. t: [
  149. {
  150. Tasks: {
  151. status: 'ABORTED',
  152. id: 1
  153. }
  154. },
  155. {
  156. Tasks: {
  157. status: 'COMPLETED',
  158. id: 2
  159. }
  160. }
  161. ],
  162. m: 'One ABORTED',
  163. r: 'ABORTED',
  164. p: 100,
  165. ids: [1,2]
  166. },
  167. {
  168. t: [
  169. {
  170. Tasks: {
  171. status: 'TIMEDOUT',
  172. id: 3
  173. }
  174. },
  175. {
  176. Tasks: {
  177. status: 'COMPLETED',
  178. id: 1
  179. }
  180. }
  181. ],
  182. m: 'One TIMEDOUT',
  183. r: 'TIMEDOUT',
  184. p: 100,
  185. ids: [1,3]
  186. },
  187. {
  188. t: [
  189. {
  190. Tasks: {
  191. status: 'IN_PROGRESS',
  192. id: 1
  193. }
  194. },
  195. {
  196. Tasks: {
  197. status: 'COMPLETED',
  198. id: 2
  199. }
  200. }
  201. ],
  202. m: 'One IN_PROGRESS',
  203. r: 'IN_PROGRESS',
  204. p: 68,
  205. ids: [1,2]
  206. },
  207. {
  208. t: [
  209. {
  210. Tasks: {
  211. status: 'QUEUED',
  212. id: 2
  213. }
  214. },
  215. {
  216. Tasks: {
  217. status: 'COMPLETED',
  218. id: 3
  219. }
  220. }
  221. ],
  222. m: 'Something else',
  223. r: 'PENDING',
  224. p: 55,
  225. ids: [2,3]
  226. }
  227. ];
  228. describe('#setSelectCount', function () {
  229. var itemsForStatusTest = [
  230. {
  231. title: 'Empty',
  232. data: [],
  233. result: [0, 0, 0, 0, 0, 0, 0]
  234. },
  235. {
  236. title: 'All Pending',
  237. data: [
  238. {status: 'pending'},
  239. {status: 'queued'}
  240. ],
  241. result: [2, 2, 0, 0, 0, 0, 0]
  242. },
  243. {
  244. title: 'All Completed',
  245. data: [
  246. {status: 'success'},
  247. {status: 'completed'}
  248. ],
  249. result: [2, 0, 0, 0, 2, 0, 0]
  250. },
  251. {
  252. title: 'All Failed',
  253. data: [
  254. {status: 'failed'},
  255. {status: 'failed'}
  256. ],
  257. result: [2, 0, 0, 2, 0, 0, 0]
  258. },
  259. {
  260. title: 'All InProgress',
  261. data: [
  262. {status: 'in_progress'},
  263. {status: 'in_progress'}
  264. ],
  265. result: [2, 0, 2, 0, 0, 0, 0]
  266. },
  267. {
  268. title: 'All Aborted',
  269. data: [
  270. {status: 'aborted'},
  271. {status: 'aborted'}
  272. ],
  273. result: [2, 0, 0, 0, 0, 2, 0]
  274. },
  275. {
  276. title: 'All Timedout',
  277. data: [
  278. {status: 'timedout'},
  279. {status: 'timedout'}
  280. ],
  281. result: [2, 0, 0, 0, 0, 0, 2]
  282. },
  283. {
  284. title: 'Every Category',
  285. data: [
  286. {status: 'pending'},
  287. {status: 'queued'},
  288. {status: 'success'},
  289. {status: 'completed'},
  290. {status: 'failed'},
  291. {status: 'in_progress'},
  292. {status: 'aborted'},
  293. {status: 'timedout'}
  294. ],
  295. result: [8, 2, 1, 1, 2, 1, 1]
  296. }
  297. ];
  298. var categories = [
  299. Ember.Object.create({value: 'all'}),
  300. Ember.Object.create({value: 'pending'}),
  301. Ember.Object.create({value: 'in_progress'}),
  302. Ember.Object.create({value: 'failed'}),
  303. Ember.Object.create({value: 'completed'}),
  304. Ember.Object.create({value: 'aborted'}),
  305. Ember.Object.create({value: 'timedout'})
  306. ];
  307. itemsForStatusTest.forEach(function(statusTest) {
  308. it(statusTest.title, function() {
  309. App.HostPopup.setSelectCount(statusTest.data, categories);
  310. expect(categories.mapProperty('count')).to.deep.equal(statusTest.result);
  311. });
  312. });
  313. });
  314. describe('#getStatus', function() {
  315. test_tasks.forEach(function(test_task) {
  316. it(test_task.m, function() {
  317. expect(App.HostPopup.getStatus(test_task.t)[0]).to.equal(test_task.r);
  318. });
  319. });
  320. });
  321. describe('#getProgress', function() {
  322. test_tasks.forEach(function(test_task) {
  323. it(test_task.m, function() {
  324. expect(App.HostPopup.getProgress(test_task.t)).to.equal(test_task.p);
  325. });
  326. });
  327. });
  328. describe('#abortRequest', function () {
  329. beforeEach(function () {
  330. sinon.stub(App.ajax, 'send', Em.K);
  331. sinon.spy(App, 'showConfirmationPopup');
  332. App.HostPopup.createPopup();
  333. });
  334. afterEach(function () {
  335. App.HostPopup.get('isPopup').hide();
  336. App.ajax.send.restore();
  337. App.showConfirmationPopup.restore();
  338. });
  339. it('should show confirmation popup', function () {
  340. App.HostPopup.get('isPopup.bodyClass').create().abortRequest({
  341. context: Em.Object.create({
  342. name: 'name'
  343. })
  344. });
  345. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  346. });
  347. });
  348. describe('#abortRequestSuccessCallback', function () {
  349. beforeEach(function () {
  350. App.HostPopup.createPopup();
  351. sinon.spy(App.ModalPopup, 'show');
  352. });
  353. afterEach(function () {
  354. App.HostPopup.get('isPopup').hide();
  355. App.ModalPopup.show.restore();
  356. });
  357. it('should open popup', function () {
  358. App.HostPopup.get('isPopup.bodyClass').create().abortRequestSuccessCallback(null, null, {
  359. requestName: 'name'
  360. });
  361. expect(App.ModalPopup.show.calledOnce).to.be.true;
  362. });
  363. });
  364. describe('#abortRequestErrorCallback', function () {
  365. var popup = App.HostPopup.createPopup();
  366. beforeEach(function () {
  367. sinon.stub(App.ajax, 'get', function(k) {
  368. if (k === 'modalPopup') return null;
  369. return Em.get(App, k);
  370. });
  371. sinon.spy(App.ModalPopup, 'show');
  372. sinon.stub(popup, 'get', function(k) {
  373. if (k === 'abortedRequests') return [0];
  374. return Em.get(popup, k);
  375. });
  376. popup.get('bodyClass').create().abortRequestErrorCallback({
  377. responseText: {
  378. message: 'message'
  379. },
  380. status: 404
  381. }, 'status', 'error', {
  382. url: 'url'
  383. }, {
  384. requestId: 0
  385. });
  386. });
  387. afterEach(function () {
  388. App.HostPopup.get('isPopup').hide();
  389. App.ModalPopup.show.restore();
  390. popup.get.restore();
  391. App.ajax.get.restore();
  392. });
  393. it('should open popup', function () {
  394. expect(App.ModalPopup.show.calledOnce).to.be.true;
  395. });
  396. it('should remove current request id from abortedRequests', function () {
  397. expect(App.HostPopup.get('abortedRequests')).to.be.empty;
  398. });
  399. });
  400. });