step9_test.js 33 KB

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