step9_test.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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('models/hosts');
  21. require('controllers/wizard/step9_controller');
  22. describe('App.InstallerStep9Controller', function () {
  23. describe('#isSubmitDisabled', function () {
  24. var tests = [
  25. {controllerName: 'addHostController',state: 'STARTED',e: false},
  26. {controllerName: 'addHostController',state: 'START FAILED',e: false},
  27. {controllerName: 'addHostController',state: 'INSTALL FAILED',e: false},
  28. {controllerName: 'addHostController',state: 'PENDING',e: true},
  29. {controllerName: 'addHostController',state: 'INSTALLED',e: true},
  30. {controllerName: 'addServiceController',state: 'STARTED',e: false},
  31. {controllerName: 'addServiceController',state: 'START FAILED',e: false},
  32. {controllerName: 'addServiceController',state: 'INSTALL FAILED',e: false},
  33. {controllerName: 'addServiceController',state: 'PENDING',e: true},
  34. {controllerName: 'addServiceController',state: 'INSTALLED',e: true},
  35. {controllerName: 'installerController',state: 'STARTED',e: false},
  36. {controllerName: 'installerController',state: 'START FAILED',e: false},
  37. {controllerName: 'installerController',state: 'INSTALL FAILED',e: true},
  38. {controllerName: 'installerController',state: 'INSTALLED',e: true},
  39. {controllerName: 'installerController',state: 'PENDING',e: true}
  40. ];
  41. tests.forEach(function(test) {
  42. var controller = App.WizardStep9Controller.create({
  43. content: {
  44. controllerName: test.controllerName,
  45. cluster: {
  46. status: test.state
  47. }
  48. }
  49. });
  50. it('controllerName is ' + test.controllerName + '; cluster status is ' + test.state + '; isSubmitDisabled should be ' + test.e, function() {
  51. expect(controller.get('isSubmitDisabled')).to.equal(test.e);
  52. });
  53. });
  54. });
  55. describe('#status', function() {
  56. var tests = [
  57. {
  58. hosts: [{status: 'failed'},{status: 'success'}],
  59. isStepFailed: false,
  60. progress: '100',
  61. m:'One host is failed',
  62. e:'failed'
  63. },
  64. {
  65. hosts: [{status: 'warning'},{status: 'success'}],
  66. m:'One host is failed and step is not failed',
  67. isStepFailed: false,
  68. progress: '100',
  69. e:'warning'
  70. },
  71. {
  72. hosts: [{status: 'warning'},{status: 'success'}],
  73. m:'One host is failed and step is failed',
  74. isStepFailed: true,
  75. progress: '100',
  76. e:'failed'
  77. },
  78. {
  79. hosts: [{status: 'success'},{status: 'success'}],
  80. m:'All hosts are success and progress is 100',
  81. isStepFailed: false,
  82. progress: '100',
  83. e:'success'
  84. },
  85. {
  86. hosts: [{status: 'success'},{status: 'success'}],
  87. m:'All hosts are success and progress is 50',
  88. isStepFailed: false,
  89. progress: '50',
  90. e:'info'
  91. }
  92. ];
  93. tests.forEach(function(test) {
  94. var controller = App.WizardStep9Controller.create({hosts: test.hosts, isStepFailed: function(){return test.isStepFailed}, progress: test.progress});
  95. it(test.m, function() {
  96. expect(controller.get('status')).to.equal(test.e);
  97. });
  98. });
  99. });
  100. describe('#visibleHosts', function() {
  101. var hosts = [
  102. Em.Object.create({status: 'failed'}),
  103. Em.Object.create({status: 'success'}),
  104. Em.Object.create({status: 'success'}),
  105. Em.Object.create({status: 'warning'}),
  106. Em.Object.create({status: 'info'}),
  107. Em.Object.create({status: 'info'})
  108. ];
  109. var tests = [
  110. {category: {hostStatus: 'all'},e: hosts.length},
  111. {category:{hostStatus: 'inProgress'},e: 2},
  112. {category: {hostStatus: 'warning'},e: 1},
  113. {category: {hostStatus: 'failed'},e: 1},
  114. {category: {hostStatus: 'success'},e: 2}
  115. ];
  116. var controller = App.WizardStep9Controller.create({
  117. hosts: hosts
  118. });
  119. tests.forEach(function(test) {
  120. it('selected category with hostStatus "' + test.category.hostStatus + '"', function() {
  121. controller.selectCategory({context: test.category});
  122. expect(controller.get('visibleHosts.length')).to.equal(test.e);
  123. });
  124. });
  125. });
  126. describe('#showRetry', function() {
  127. it('cluster status is not INSTALL FAILED', function() {
  128. var controller = App.WizardStep9Controller.create({content: {cluster:{status:'INSTALLED'}}});
  129. expect(controller.get('showRetry')).to.equal(false);
  130. });
  131. it('cluster status is INSTALL FAILED', function() {
  132. var controller = App.WizardStep9Controller.create({content: {cluster:{status:'INSTALL FAILED'}}});
  133. expect(controller.get('showRetry')).to.equal(true);
  134. });
  135. });
  136. describe('#resetHostsForRetry', function() {
  137. var hosts = {'host1':Em.Object.create({status:'failed', message:'Failed'}), 'host2':Em.Object.create({status:'success', message:'Success'})};
  138. var controller = App.WizardStep9Controller.create({content:{hosts: hosts}});
  139. it('All should have status "pending" and message "Waiting"', function() {
  140. controller.resetHostsForRetry();
  141. for (var name in hosts) {
  142. expect(controller.get('content.hosts')[name].get('status','pending')).to.equal('pending');
  143. expect(controller.get('content.hosts')[name].get('message','Waiting')).to.equal('Waiting');
  144. }
  145. });
  146. });
  147. var hosts_for_load_and_render = {
  148. 'host1': {
  149. message: 'message1',
  150. status: 'unknown',
  151. progress: '1',
  152. tasks: [{},{}],
  153. logTasks: [{},{}],
  154. bootStatus: 'REGISTERED'
  155. },
  156. 'host2': {
  157. message: '',
  158. status: 'failed',
  159. progress: '1',
  160. tasks: [{},{}],
  161. logTasks: [{},{}],
  162. bootStatus: ''
  163. },
  164. 'host3': {
  165. message: '',
  166. status: 'waiting',
  167. progress: null,
  168. tasks: [{},{}],
  169. logTasks: [{},{}],
  170. bootStatus: ''
  171. },
  172. 'host4': {
  173. message: 'message4',
  174. status: null,
  175. progress: '10',
  176. tasks: [],
  177. logTasks: [{}],
  178. bootStatus: 'REGISTERED'
  179. }
  180. };
  181. describe('#loadHosts', function() {
  182. var controller = App.WizardStep9Controller.create({content: {hosts: hosts_for_load_and_render}});
  183. var loaded_hosts = controller.loadHosts();
  184. it('Only REGISTERED hosts', function() {
  185. expect(loaded_hosts.length).to.equal(2);
  186. });
  187. it('All hosts have progress 0', function() {
  188. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  189. });
  190. it('All hosts have progress 0', function() {
  191. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  192. });
  193. it('All host don\'t have tasks and logTasks', function() {
  194. expect(loaded_hosts.everyProperty('tasks.length', 0)).to.equal(true);
  195. expect(loaded_hosts.everyProperty('logTasks.length', 0)).to.equal(true);
  196. });
  197. });
  198. describe('#renderHosts', function() {
  199. var controller = App.WizardStep9Controller.create({content: {hosts: hosts_for_load_and_render}});
  200. var loaded_hosts = controller.loadHosts();
  201. controller.renderHosts(loaded_hosts);
  202. it('All host should be rendered', function() {
  203. expect(controller.get('hosts.length')).to.equal(loaded_hosts.length);
  204. });
  205. });
  206. describe('#hostHasClientsOnly', function() {
  207. var tests = [
  208. {
  209. hosts: [
  210. Em.Object.create({
  211. hostName: 'host1',
  212. logTasks: [{Tasks: {role: 'HDFS_CLIENT'}},{Tasks: {role: 'DATANODE'}}],
  213. status: 'old_status',
  214. progress: '10',
  215. e: {status: 'old_status',progress: '10'}
  216. }),
  217. Em.Object.create({
  218. hostName: 'host2',
  219. logTasks: [{Tasks: {role: 'HDFS_CLIENT'}}],
  220. status: 'old_status',
  221. progress: '10',
  222. e: {status: 'success',progress: '100'}
  223. })
  224. ],
  225. jsonError: false
  226. },
  227. {
  228. hosts: [
  229. Em.Object.create({
  230. hostName: 'host1',
  231. logTasks: [{Tasks: {role: 'HDFS_CLIENT'}},{Tasks: {role: 'DATANODE'}}],
  232. status: 'old_status',
  233. progress: '10',
  234. e: {status: 'success',progress: '100'}
  235. }),
  236. Em.Object.create({
  237. hostName: 'host2',
  238. logTasks: [{Tasks: {role: 'HDFS_CLIENT'}}],
  239. status: 'old_status',
  240. progress: '10',
  241. e: {status: 'success',progress: '100'}
  242. })
  243. ],
  244. jsonError: true
  245. }
  246. ];
  247. tests.forEach(function(test) {
  248. it('', function() {
  249. var controller = App.WizardStep9Controller.create({hosts: test.hosts});
  250. controller.hostHasClientsOnly(test.jsonError);
  251. test.hosts.forEach(function(host) {
  252. expect(controller.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  253. expect(controller.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  254. });
  255. });
  256. });
  257. });
  258. describe('#onSuccessPerHost', function() {
  259. var tests = [
  260. {
  261. cluster: {status: 'INSTALLED'},
  262. host: Em.Object.create({status: 'pending'}),
  263. actions: [],
  264. e: {status: 'success'},
  265. m: 'No tasks for host'
  266. },
  267. {
  268. cluster: {status: 'INSTALLED'},
  269. host: Em.Object.create({status: 'info'}),
  270. actions: [{Tasks: {status: 'COMPLETED'}},{Tasks: {status: 'COMPLETED'}}],
  271. e: {status: 'success'},
  272. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  273. },
  274. {
  275. cluster: {status: 'FAILED'},
  276. host: Em.Object.create({status: 'info'}),
  277. actions: [{Tasks: {status: 'COMPLETED'}},{Tasks: {status: 'COMPLETED'}}],
  278. e: {status: 'info'},
  279. m: 'All Tasks COMPLETED and cluster status FAILED'
  280. },
  281. {
  282. cluster: {status: 'INSTALLED'},
  283. host: Em.Object.create({status: 'info'}),
  284. actions: [{Tasks: {status: 'FAILED'}},{Tasks: {status: 'COMPLETED'}}],
  285. e: {status: 'info'},
  286. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  287. },
  288. {
  289. cluster: {status: 'FAILED'},
  290. host: Em.Object.create({status: 'info'}),
  291. actions: [{Tasks: {status: 'FAILED'}},{Tasks: {status: 'COMPLETED'}}],
  292. e: {status: 'info'},
  293. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  294. }
  295. ];
  296. tests.forEach(function(test) {
  297. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}});
  298. controller.onSuccessPerHost(test.actions, test.host);
  299. it(test.m, function() {
  300. expect(test.host.status).to.equal(test.e.status);
  301. });
  302. });
  303. });
  304. describe('#onErrorPerHost', function() {
  305. var tests = [
  306. {
  307. cluster: {status: 'INSTALLED'},
  308. host: Em.Object.create({status: 'pending'}),
  309. actions: [],
  310. e: {status: 'pending'},
  311. isMasterFailed: false,
  312. m: 'No tasks for host'
  313. },
  314. {
  315. cluster: {status: 'INSTALLED'},
  316. host: Em.Object.create({status: 'info'}),
  317. actions: [{Tasks: {status: 'FAILED'}},{Tasks: {status: 'COMPLETED'}}],
  318. e: {status: 'warning'},
  319. isMasterFailed: false,
  320. m: 'One Task FAILED and cluster status INSTALLED'
  321. },
  322. {
  323. cluster: {status: 'INSTALLED'},
  324. host: Em.Object.create({status: 'info'}),
  325. actions: [{Tasks: {status: 'ABORTED'}},{Tasks: {status: 'COMPLETED'}}],
  326. e: {status: 'warning'},
  327. isMasterFailed: false,
  328. m: 'One Task ABORTED and cluster status INSTALLED'
  329. },
  330. {
  331. cluster: {status: 'INSTALLED'},
  332. host: Em.Object.create({status: 'info'}),
  333. actions: [{Tasks: {status: 'TIMEDOUT'}},{Tasks: {status: 'COMPLETED'}}],
  334. e: {status: 'warning'},
  335. isMasterFailed: false,
  336. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  337. },
  338. {
  339. cluster: {status: 'PENDING'},
  340. host: Em.Object.create({status: 'info'}),
  341. actions: [{Tasks: {status: 'FAILED'}},{Tasks: {status: 'COMPLETED'}}],
  342. e: {status: 'failed'},
  343. isMasterFailed: true,
  344. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  345. },
  346. {
  347. cluster: {status: 'PENDING'},
  348. host: Em.Object.create({status: 'info'}),
  349. actions: [{Tasks: {status: 'COMPLETED'}},{Tasks: {status: 'COMPLETED'}}],
  350. e: {status: 'info'},
  351. isMasterFailed: false,
  352. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  353. }
  354. ];
  355. tests.forEach(function(test) {
  356. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function(){return test.isMasterFailed;}});
  357. controller.onErrorPerHost(test.actions, test.host);
  358. it(test.m, function() {
  359. expect(test.host.status).to.equal(test.e.status);
  360. });
  361. });
  362. });
  363. describe('#isMasterFailed', function() {
  364. var tests = [
  365. {
  366. actions: [
  367. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'DATANODE'}},
  368. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'TASKTRACKER'}},
  369. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'HBASE_REGIONSERVER'}},
  370. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'GANGLIA_MONITOR'}}
  371. ],
  372. e: false,
  373. m: 'No one Master is failed'
  374. },
  375. {
  376. actions: [
  377. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'NAMENODE'}},
  378. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'TASKTRACKER'}},
  379. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'HBASE_REGIONSERVER'}},
  380. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'GANGLIA_MONITOR'}}
  381. ],
  382. e: true,
  383. m: 'One Master is failed'
  384. },
  385. {
  386. actions: [
  387. {Tasks: {command: 'PENDING',status: 'FAILED',role: 'NAMENODE'}},
  388. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'TASKTRACKER'}},
  389. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'HBASE_REGIONSERVER'}},
  390. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'GANGLIA_MONITOR'}}
  391. ],
  392. e: false,
  393. m: 'one Master is failed but command is not install'
  394. }
  395. ];
  396. tests.forEach(function(test) {
  397. it(test.m, function() {
  398. var controller = App.WizardStep9Controller.create();
  399. expect(controller.isMasterFailed(test.actions)).to.equal(test.e);
  400. });
  401. });
  402. });
  403. describe('#onInProgressPerHost', function() {
  404. var tests = [
  405. {
  406. host: Em.Object.create({message: 'default_message'}),
  407. actions: [{Tasks: {status: 'COMPLETED'}},{Tasks: {status: 'COMPLETED'}}],
  408. e: {message: 'default_message',b: true},
  409. m: 'All Tasks COMPLETED'
  410. },
  411. {
  412. host: Em.Object.create({message: 'default_message'}),
  413. actions: [{Tasks: {status: 'IN_PROGRESS'}},{Tasks: {status: 'COMPLETED'}}],
  414. e: {message: 'default_message',b: false},
  415. m: 'One Task IN_PROGRESS'
  416. },
  417. {
  418. host: Em.Object.create({message: 'default_message'}),
  419. actions: [{Tasks: {status: 'QUEUED'}},{Tasks: {status: 'COMPLETED'}}],
  420. e: {message: 'default_message',b: false},
  421. m: 'One Task QUEUED'
  422. },
  423. {
  424. host: Em.Object.create({message: 'default_message'}),
  425. actions: [{Tasks: {status: 'PENDING'}},{Tasks: {status: 'COMPLETED'}}],
  426. e: {message: 'default_message',b: false},
  427. m: 'One Task PENDING'
  428. }
  429. ];
  430. tests.forEach(function(test) {
  431. it(test.m, function() {
  432. var controller = App.WizardStep9Controller.create();
  433. controller.onInProgressPerHost(test.actions, test.host);
  434. expect(test.host.message == test.e.message).to.equal(test.e.b);
  435. });
  436. });
  437. });
  438. describe('#progressPerHost', function() {
  439. var tests = [
  440. {
  441. cluster: {status: 'PENDING'},
  442. host: Em.Object.create({progress: 0}),
  443. actions: [
  444. {Tasks: {status: 'COMPLETED'}},
  445. {Tasks: {status: 'COMPLETED'}},
  446. {Tasks: {status: 'QUEUED'}},
  447. {Tasks: {status: 'QUEUED'}},
  448. {Tasks: {status: 'IN_PROGRESS'}}
  449. ],
  450. e: {ret: 17,host: '17'},
  451. m: 'All types of status available. cluster status PENDING'
  452. },
  453. {
  454. cluster: {status: 'PENDING'},
  455. host: Em.Object.create({progress: 0}),
  456. actions: [],
  457. e: {ret: 33,host: '33'},
  458. m: 'No tasks available. cluster status PENDING'
  459. },
  460. {
  461. cluster: {status: 'INSTALLED'},
  462. host: Em.Object.create({progress: 0}),
  463. actions: [],
  464. e: {ret: 100,host: '100'},
  465. m: 'No tasks available. cluster status INSTALLED'
  466. },
  467. {
  468. cluster: {status: 'INSTALLED'},
  469. host: Em.Object.create({progress: 0}),
  470. actions: [
  471. {Tasks: {status: 'COMPLETED'}},
  472. {Tasks: {status: 'COMPLETED'}},
  473. {Tasks: {status: 'QUEUED'}},
  474. {Tasks: {status: 'QUEUED'}},
  475. {Tasks: {status: 'IN_PROGRESS'}}
  476. ],
  477. e: {ret: 68,host: '68'},
  478. m: 'All types of status available. cluster status INSTALLED'
  479. },
  480. {
  481. cluster: {status: 'FAILED'},
  482. host: Em.Object.create({progress: 0}),
  483. actions: [],
  484. e: {ret: 100,host: '100'},
  485. m: 'Cluster status is not PENDING or INSTALLED'
  486. }
  487. ];
  488. tests.forEach(function(test) {
  489. it(test.m, function() {
  490. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}});
  491. var progress = controller.progressPerHost(test.actions, test.host);
  492. expect(progress).to.equal(test.e.ret);
  493. expect(test.host.progress).to.equal(test.e.host);
  494. });
  495. });
  496. });
  497. describe('#clearStep', function() {
  498. var controller = App.WizardStep9Controller.create({hosts: [{},{},{}]});
  499. it('All to default values', function() {
  500. controller.clearStep();
  501. expect(controller.get('hosts.length')).to.equal(0);
  502. expect(controller.get('status')).to.equal('info');
  503. expect(controller.get('progress')).to.equal('0');
  504. expect(controller.get('isStepCompleted')).to.equal(false);
  505. expect(controller.get('numPolls')).to.equal(1);
  506. });
  507. });
  508. describe('#replacePolledData', function() {
  509. var controller = App.WizardStep9Controller.create({polledData: [{},{},{}]});
  510. var newPolledData = [{}];
  511. controller.replacePolledData(newPolledData);
  512. it('replacing polled data', function() {
  513. expect(controller.get('polledData.length')).to.equal(newPolledData.length);
  514. });
  515. });
  516. describe('#isSuccess', function() {
  517. var tests = [
  518. {
  519. polledData: [
  520. {Tasks: {status: 'COMPLETED'}},
  521. {Tasks: {status: 'COMPLETED'}}
  522. ],
  523. e: true,
  524. m: 'All tasks are COMPLETED'
  525. },
  526. {
  527. polledData: [
  528. {Tasks: {status: 'COMPLETED'}},
  529. {Tasks: {status: 'FAILED'}}
  530. ],
  531. e: false,
  532. m: 'Not all tasks are COMPLETED'
  533. }
  534. ];
  535. tests.forEach(function(test) {
  536. it(test.m, function() {
  537. var controller = App.WizardStep9Controller.create();
  538. expect(controller.isSuccess(test.polledData)).to.equal(test.e);
  539. });
  540. });
  541. });
  542. describe('#isStepFailed', function() {
  543. var tests = [
  544. {
  545. polledData: [
  546. {Tasks: {command: 'INSTALL',role: 'GANGLIA_MONITOR',status: 'TIMEDOUT'}},
  547. {Tasks: {command: 'INSTALL',role: 'GANGLIA_MONITOR',status: 'FAILED'}},
  548. {Tasks: {command: 'INSTALL',role: 'GANGLIA_MONITOR',status: 'PENDING'}}
  549. ],
  550. e: true,
  551. m: 'GANGLIA_MONITOR 2/3 failed'
  552. },
  553. {
  554. polledData: [
  555. {Tasks: {command: 'INSTALL',role: 'GANGLIA_MONITOR',status: 'TIMEDOUT'}},
  556. {Tasks: {command: 'INSTALL',role: 'GANGLIA_MONITOR',status: 'PENDING'}},
  557. {Tasks: {command: 'INSTALL',role: 'GANGLIA_MONITOR',status: 'PENDING'}}
  558. ],
  559. e: false,
  560. m: 'GANGLIA_MONITOR 1/3 failed'
  561. },
  562. {
  563. polledData: [
  564. {Tasks: {command: 'INSTALL',role: 'HBASE_REGIONSERVER',status: 'TIMEDOUT'}},
  565. {Tasks: {command: 'INSTALL',role: 'HBASE_REGIONSERVER',status: 'FAILED'}},
  566. {Tasks: {command: 'INSTALL',role: 'HBASE_REGIONSERVER',status: 'PENDING'}}
  567. ],
  568. e: true,
  569. m: 'HBASE_REGIONSERVER 2/3 failed'
  570. },
  571. {
  572. polledData: [
  573. {Tasks: {command: 'INSTALL',role: 'HBASE_REGIONSERVER',status: 'TIMEDOUT'}},
  574. {Tasks: {command: 'INSTALL',role: 'HBASE_REGIONSERVER',status: 'PENDING'}},
  575. {Tasks: {command: 'INSTALL',role: 'HBASE_REGIONSERVER',status: 'PENDING'}}
  576. ],
  577. e: false,
  578. m: 'HBASE_REGIONSERVER 1/3 failed'
  579. },
  580. {
  581. polledData: [
  582. {Tasks: {command: 'INSTALL',role: 'TASKTRACKER',status: 'TIMEDOUT'}},
  583. {Tasks: {command: 'INSTALL',role: 'TASKTRACKER',status: 'FAILED'}},
  584. {Tasks: {command: 'INSTALL',role: 'TASKTRACKER',status: 'PENDING'}}
  585. ],
  586. e: true,
  587. m: 'TASKTRACKER 2/3 failed'
  588. },
  589. {
  590. polledData: [
  591. {Tasks: {command: 'INSTALL',role: 'TASKTRACKER',status: 'TIMEDOUT'}},
  592. {Tasks: {command: 'INSTALL',role: 'TASKTRACKER',status: 'PENDING'}},
  593. {Tasks: {command: 'INSTALL',role: 'TASKTRACKER',status: 'PENDING'}}
  594. ],
  595. e: false,
  596. m: 'TASKTRACKER 1/3 failed'
  597. },
  598. {
  599. polledData: [
  600. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'TIMEDOUT'}},
  601. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'FAILED'}},
  602. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}}
  603. ],
  604. e: true,
  605. m: 'DATANODE 2/3 failed'
  606. },
  607. {
  608. polledData: [
  609. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'TIMEDOUT'}},
  610. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}},
  611. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}}
  612. ],
  613. e: false,
  614. m: 'DATANODE 1/3 failed'
  615. },
  616. {
  617. polledData: [
  618. {Tasks: {command: 'INSTALL',role: 'NAMENODE',status: 'TIMEDOUT'}},
  619. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}},
  620. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}}
  621. ],
  622. e: true,
  623. m: 'NAMENODE failed'
  624. },
  625. {
  626. polledData: [
  627. {Tasks: {command: 'INSTALL',role: 'NAMENODE',status: 'PENDING'}},
  628. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}},
  629. {Tasks: {command: 'INSTALL',role: 'DATANODE',status: 'PENDING'}}
  630. ],
  631. e: false,
  632. m: 'Nothing failed failed'
  633. }
  634. ];
  635. tests.forEach(function(test) {
  636. var controller = App.WizardStep9Controller.create({polledData: test.polledData});
  637. it(test.m, function() {
  638. expect(controller.isStepFailed()).to.equal(test.e);
  639. });
  640. });
  641. });
  642. describe('#getUrl', function() {
  643. var clusterName = 'tdk';
  644. var cluster = App.WizardStep9Controller.create({content:{cluster:{name: clusterName, requestId: null}}});
  645. it('check requestId priority', function() {
  646. cluster.set('content.cluster.requestId', 123);
  647. var url = cluster.getUrl(321);
  648. expect(url).to.equal(App.apiPrefix + '/clusters/' + clusterName + '/requests/' + '321' + '?fields=tasks/*');
  649. url = cluster.getUrl();
  650. expect(url).to.equal(App.apiPrefix + '/clusters/' + clusterName + '/requests/' + '123' + '?fields=tasks/*');
  651. });
  652. });
  653. describe('#finishState', function() {
  654. var statuses = ['INSTALL FAILED', 'START FAILED', 'STARTED'];
  655. it('Installer is finished', function() {
  656. statuses.forEach(function(status) {
  657. var controller = App.WizardStep9Controller.create({content:{cluster:{status:status}}});
  658. var result = controller.finishState();
  659. expect(result).to.equal(true);
  660. });
  661. });
  662. it('Unknown cluster status ', function() {
  663. var controller = App.WizardStep9Controller.create({content:{cluster:{status:'FAKE_STATUS'}}});
  664. var result = controller.finishState();
  665. expect(result).to.equal(false);
  666. });
  667. });
  668. describe('#setTasksPerHost', function() {
  669. var tests = [
  670. {
  671. hosts: [
  672. Em.Object.create({
  673. name: 'host1',
  674. tasks: [],
  675. bootStatus: 'REGISTERED'
  676. }),
  677. Em.Object.create({
  678. name: 'host2',
  679. tasks: [],
  680. bootStatus: 'REGISTERED'
  681. }),
  682. Em.Object.create({
  683. name: 'host3',
  684. tasks: [],
  685. bootStatus: 'REGISTERED'
  686. })
  687. ],
  688. polledData: [
  689. {Tasks: {host_name: 'host1'}},
  690. {Tasks: {host_name: 'host1'}},
  691. {Tasks: {host_name: 'host1'}},
  692. {Tasks: {host_name: 'host2'}},
  693. {Tasks: {host_name: 'host2'}},
  694. {Tasks: {host_name: 'host3'}}
  695. ],
  696. e: {
  697. host1: {count: 3},
  698. host2: {count: 2},
  699. host3: {count: 1}
  700. },
  701. m: 'Several tasks for each host'
  702. },
  703. {
  704. hosts: [
  705. Em.Object.create({
  706. name: 'host1',
  707. tasks: [],
  708. bootStatus: 'REGISTERED'
  709. }),
  710. Em.Object.create({
  711. name: 'host2',
  712. tasks: [],
  713. bootStatus: 'REGISTERED'
  714. }),
  715. Em.Object.create({
  716. name: 'host3',
  717. tasks: [],
  718. bootStatus: 'REGISTERED'
  719. })
  720. ],
  721. polledData: [
  722. {Tasks: {host_name: 'host1'}},
  723. {Tasks: {host_name: 'host2'}}
  724. ],
  725. e: {
  726. host1: {count: 1},
  727. host2: {count: 1},
  728. host3: {count: 0}
  729. },
  730. m: 'Some hosts without tasks'
  731. },
  732. {
  733. hosts: [
  734. Em.Object.create({
  735. name: 'host1',
  736. tasks: [],
  737. bootStatus: 'REGISTERED'
  738. }),
  739. Em.Object.create({
  740. name: 'host2',
  741. tasks: [],
  742. bootStatus: 'REGISTERED'
  743. }),
  744. Em.Object.create({
  745. name: 'host3',
  746. tasks: [],
  747. bootStatus: 'REGISTERED'
  748. })
  749. ],
  750. polledData: [],
  751. e: {
  752. host1: {count: 0},
  753. host2: {count: 0},
  754. host3: {count: 0}
  755. },
  756. m: 'No tasks'
  757. }
  758. ];
  759. tests.forEach(function(test) {
  760. it(test.m, function() {
  761. var controller = App.WizardStep9Controller.create({polledData: test.polledData, hosts: test.hosts});
  762. controller.setTasksPerHost();
  763. for(var name in test.e.hosts) {
  764. expect(controller.get('hosts').findProperty('name', name).get('tasks.length')).to.equal(test.e[name].count);
  765. }
  766. });
  767. });
  768. });
  769. describe('#setLogTasksStatePerHost', function() {
  770. var tests = [
  771. {
  772. tasksPerHost: [{Tasks: {id: 1,message: '2'}},{Tasks: {id: 2,message: '2'}}],
  773. tasks: [],
  774. e: {m: '2',l: 2},
  775. m: 'host didn\'t have tasks and got 2 new'
  776. },
  777. {
  778. tasksPerHost: [{Tasks: {id: 1,message: '2'}},{Tasks: {id: 2,message: '2'}}],
  779. tasks: [{Tasks: {id: 1,message: '1'}},{Tasks: {id: 2,message: '1'}}],
  780. e: {m: '2',l: 2},
  781. m: 'host had 2 tasks and got both updated'
  782. },
  783. {
  784. tasksPerHost: [],
  785. tasks: [{Tasks: {id: 1,message: '1'}},{Tasks: {id: 2,message: '1'}}],
  786. e: {m: '1',l: 2},
  787. m: 'host had 2 tasks and didn\'t get updates'
  788. },
  789. {
  790. tasksPerHost: [{Tasks: {id: 1,message: '2'}},{Tasks: {id: 2,message: '2'}},{Tasks: {id: 3,message: '2'}}],
  791. tasks: [{Tasks: {id: 1,message: '1'}},{Tasks: {id: 2,message: '1'}}],
  792. e: {m: '2',l: 3},
  793. m: 'host had 2 tasks and got both updated and 1 new'
  794. }
  795. ];
  796. tests.forEach(function(test) {
  797. it(test.m, function() {
  798. var controller = App.WizardStep9Controller.create({hosts: [Em.Object.create({logTasks: test.tasks})]});
  799. var logTasksChangesCounter = controller.get('logTasksChangesCounter');
  800. controller.setLogTasksStatePerHost(test.tasksPerHost, controller.get('hosts')[0]);
  801. expect(controller.get('hosts')[0].get('logTasks').everyProperty('Tasks.message', test.e.m)).to.equal(true);
  802. expect(controller.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  803. expect(controller.get('logTasksChangesCounter')).to.equal(logTasksChangesCounter + 1);
  804. });
  805. });
  806. });
  807. describe('#parseHostInfo', function() {
  808. var requestId = 1;
  809. var polledData = {Requests:{id:2}};
  810. it('Invalid requestId. Should return false', function() {
  811. var controller = App.WizardStep9Controller.create({content: {cluster:{requestId: requestId}}});
  812. var res = controller.parseHostInfo(polledData);
  813. expect(res).to.equal(false);
  814. });
  815. var tests = [
  816. {
  817. cluster: {status: 'PENDING'},
  818. hosts: [
  819. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  820. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  821. ],
  822. polledData: {
  823. tasks:[
  824. {Tasks: {host_name: 'host2',status: 'COMPLETED'}},
  825. {Tasks: {host_name: 'host2',status: 'COMPLETED'}}
  826. ]
  827. },
  828. e: {
  829. hosts:{
  830. host1: {progress: '33'},
  831. host2: {progress: '33'}
  832. },
  833. progress: '33'
  834. },
  835. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is PENDING'
  836. },
  837. {
  838. cluster: {status: 'PENDING'},
  839. hosts: [
  840. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  841. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  842. ],
  843. polledData: {
  844. tasks:[
  845. {Tasks: {host_name: 'host1',status: 'IN_PROGRESS'}},
  846. {Tasks: {host_name: 'host2',status: 'IN_PROGRESS'}}
  847. ]
  848. },
  849. e: {hosts:{host1: {progress: '12'},host2: {progress: '12'}},progress: '12'},
  850. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is PENDING'
  851. },
  852. {
  853. cluster: {status: 'PENDING'},
  854. hosts: [
  855. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  856. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  857. ],
  858. polledData: {
  859. tasks:[
  860. {Tasks: {host_name: 'host1',status: 'QUEUED'}},
  861. {Tasks: {host_name: 'host2',status: 'QUEUED'}}
  862. ]
  863. },
  864. e: {
  865. hosts:{
  866. host1: {progress: '3'},
  867. host2: {progress: '3'}
  868. },
  869. progress: '3'
  870. },
  871. m: 'Two hosts. Each host has one task QUEUED. Cluster status is PENDING'
  872. },
  873. {
  874. cluster: {status: 'INSTALLED'},
  875. hosts: [
  876. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  877. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  878. ],
  879. polledData: {
  880. tasks:[
  881. {Tasks: {host_name: 'host2',status: 'COMPLETED'}},
  882. {Tasks: {host_name: 'host2',status: 'COMPLETED'}}
  883. ]
  884. },
  885. e: {
  886. hosts:{
  887. host1: {progress: '100'},
  888. host2: {progress: '100'}
  889. },
  890. progress: '100'
  891. },
  892. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is INSTALLED'
  893. },
  894. {
  895. cluster: {status: 'INSTALLED'},
  896. hosts: [
  897. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  898. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  899. ],
  900. polledData: {
  901. tasks:[
  902. {Tasks: {host_name: 'host1',status: 'IN_PROGRESS'}},
  903. {Tasks: {host_name: 'host2',status: 'IN_PROGRESS'}}
  904. ]
  905. },
  906. e: {
  907. hosts:{
  908. host1: {progress: '58'},
  909. host2: {progress: '58'}
  910. },
  911. progress: '58'
  912. },
  913. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is INSTALLED'
  914. },
  915. {
  916. cluster: {status: 'INSTALLED'},
  917. hosts: [
  918. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  919. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  920. ],
  921. polledData: {
  922. tasks:[
  923. {Tasks: {host_name: 'host1',status: 'QUEUED'}},
  924. {Tasks: {host_name: 'host2',status: 'QUEUED'}}
  925. ]
  926. },
  927. e: {
  928. hosts:{
  929. host1: {progress: '40'},
  930. host2: {progress: '40'}
  931. },
  932. progress: '40'
  933. },
  934. m: 'Two hosts. Each host has one task QUEUED. Cluster status is INSTALLED'
  935. }
  936. ];
  937. tests.forEach(function(test) {
  938. it(test.m, function() {
  939. var controller = App.WizardStep9Controller.create({hosts: test.hosts, content: {cluster:{status: test.cluster.status}}, finishState: function(){return false;}});
  940. controller.parseHostInfo(test.polledData);
  941. for (var name in test.e.hosts) {
  942. expect(controller.get('hosts').findProperty('name', name).get('progress')).to.equal(test.e.hosts[name].progress);
  943. }
  944. expect(controller.get('progress')).to.equal(test.e.progress);
  945. });
  946. });
  947. });
  948. });