step9_test.js 34 KB

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