host_progress_popup_test.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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 bgController = App.BackgroundOperationsController.create();
  94. bgController.set('services', services);
  95. describe('#initPopup', function() {
  96. App.HostPopup.initPopup("", bgController, true);
  97. it('services loaded', function() {
  98. expect(App.HostPopup.get('inputData').length).to.equal(services.length);
  99. });
  100. });
  101. var test_tasks = [
  102. {
  103. t: [
  104. {
  105. Tasks: {
  106. status: 'COMPLETED',
  107. id: 2
  108. }
  109. },
  110. {
  111. Tasks: {
  112. status: 'COMPLETED',
  113. id: 3
  114. }
  115. },
  116. {
  117. Tasks: {
  118. status: 'COMPLETED',
  119. id: 1
  120. }
  121. }
  122. ],
  123. m: 'All COMPLETED',
  124. r: 'SUCCESS',
  125. p: 100,
  126. ids: [1,2,3]
  127. },
  128. {
  129. t: [
  130. {
  131. Tasks: {
  132. status: 'FAILED',
  133. id: 2
  134. }
  135. },
  136. {
  137. Tasks: {
  138. status: 'COMPLETED',
  139. id: 1
  140. }
  141. }
  142. ,
  143. {
  144. Tasks: {
  145. status: 'COMPLETED',
  146. id: 3
  147. }
  148. }
  149. ],
  150. m: 'One FAILED',
  151. r: 'FAILED',
  152. p: 100,
  153. ids: [1,2,3]
  154. },
  155. {
  156. t: [
  157. {
  158. Tasks: {
  159. status: 'ABORTED',
  160. id: 1
  161. }
  162. },
  163. {
  164. Tasks: {
  165. status: 'COMPLETED',
  166. id: 2
  167. }
  168. }
  169. ],
  170. m: 'One ABORTED',
  171. r: 'CANCELLED',
  172. p: 100,
  173. ids: [1,2]
  174. },
  175. {
  176. t: [
  177. {
  178. Tasks: {
  179. status: 'TIMEDOUT',
  180. id: 3
  181. }
  182. },
  183. {
  184. Tasks: {
  185. status: 'COMPLETED',
  186. id: 1
  187. }
  188. }
  189. ],
  190. m: 'One TIMEDOUT',
  191. r: 'TIMEDOUT',
  192. p: 100,
  193. ids: [1,3]
  194. },
  195. {
  196. t: [
  197. {
  198. Tasks: {
  199. status: 'IN_PROGRESS',
  200. id: 1
  201. }
  202. },
  203. {
  204. Tasks: {
  205. status: 'COMPLETED',
  206. id: 2
  207. }
  208. }
  209. ],
  210. m: 'One IN_PROGRESS',
  211. r: 'IN_PROGRESS',
  212. p: 68,
  213. ids: [1,2]
  214. },
  215. {
  216. t: [
  217. {
  218. Tasks: {
  219. status: 'QUEUED',
  220. id: 2
  221. }
  222. },
  223. {
  224. Tasks: {
  225. status: 'COMPLETED',
  226. id: 3
  227. }
  228. }
  229. ],
  230. m: 'Something else',
  231. r: 'PENDING',
  232. p: 55,
  233. ids: [2,3]
  234. }
  235. ];
  236. describe('#setSelectCount', function () {
  237. var itemsForStatusTest = [
  238. {
  239. title: 'Empty',
  240. data: [],
  241. result: [0, 0, 0, 0, 0, 0, 0]
  242. },
  243. {
  244. title: 'All Pending',
  245. data: [
  246. {status: 'pending'},
  247. {status: 'queued'}
  248. ],
  249. result: [2, 2, 0, 0, 0, 0, 0]
  250. },
  251. {
  252. title: 'All Completed',
  253. data: [
  254. {status: 'success'},
  255. {status: 'completed'}
  256. ],
  257. result: [2, 0, 0, 0, 2, 0, 0]
  258. },
  259. {
  260. title: 'All Failed',
  261. data: [
  262. {status: 'failed'},
  263. {status: 'failed'}
  264. ],
  265. result: [2, 0, 0, 2, 0, 0, 0]
  266. },
  267. {
  268. title: 'All InProgress',
  269. data: [
  270. {status: 'in_progress'},
  271. {status: 'in_progress'}
  272. ],
  273. result: [2, 0, 2, 0, 0, 0, 0]
  274. },
  275. {
  276. title: 'All Aborted',
  277. data: [
  278. {status: 'aborted'},
  279. {status: 'aborted'}
  280. ],
  281. result: [2, 0, 0, 0, 0, 2, 0]
  282. },
  283. {
  284. title: 'All Timedout',
  285. data: [
  286. {status: 'timedout'},
  287. {status: 'timedout'}
  288. ],
  289. result: [2, 0, 0, 0, 0, 0, 2]
  290. },
  291. {
  292. title: 'Every Category',
  293. data: [
  294. {status: 'pending'},
  295. {status: 'queued'},
  296. {status: 'success'},
  297. {status: 'completed'},
  298. {status: 'failed'},
  299. {status: 'in_progress'},
  300. {status: 'aborted'},
  301. {status: 'timedout'}
  302. ],
  303. result: [8, 2, 1, 1, 2, 1, 1]
  304. }
  305. ];
  306. var categories = [
  307. Ember.Object.create({value: 'all'}),
  308. Ember.Object.create({value: 'pending'}),
  309. Ember.Object.create({value: 'in_progress'}),
  310. Ember.Object.create({value: 'failed'}),
  311. Ember.Object.create({value: 'completed'}),
  312. Ember.Object.create({value: 'aborted'}),
  313. Ember.Object.create({value: 'timedout'})
  314. ];
  315. itemsForStatusTest.forEach(function(statusTest) {
  316. it(statusTest.title, function() {
  317. App.HostPopup.setSelectCount(statusTest.data, categories);
  318. expect(categories.mapProperty('count')).to.deep.equal(statusTest.result);
  319. });
  320. });
  321. });
  322. describe('#getStatus', function() {
  323. test_tasks.forEach(function(test_task) {
  324. it(test_task.m, function() {
  325. expect(App.HostPopup.getStatus(test_task.t)[0]).to.equal(test_task.r);
  326. });
  327. });
  328. });
  329. describe('#getProgress', function() {
  330. test_tasks.forEach(function(test_task) {
  331. it(test_task.m, function() {
  332. expect(App.HostPopup.getProgress(test_task.t)).to.equal(test_task.p);
  333. });
  334. });
  335. });
  336. });