step9_test.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  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. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'SUPERVISOR'}}
  369. ],
  370. e: false,
  371. m: 'No one Master is failed'
  372. },
  373. {
  374. actions: [
  375. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'NAMENODE'}},
  376. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'TASKTRACKER'}},
  377. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'HBASE_REGIONSERVER'}},
  378. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'GANGLIA_MONITOR'}},
  379. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'SUPERVISOR'}}
  380. ],
  381. e: true,
  382. m: 'One Master is failed'
  383. },
  384. {
  385. actions: [
  386. {Tasks: {command: 'PENDING',status: 'FAILED',role: 'NAMENODE'}},
  387. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'TASKTRACKER'}},
  388. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'HBASE_REGIONSERVER'}},
  389. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'GANGLIA_MONITOR'}},
  390. {Tasks: {command: 'INSTALL',status: 'FAILED',role: 'SUPERVISOR'}}
  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/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true');
  649. url = cluster.getUrl();
  650. 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');
  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: Em.A([
  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. if (test.e.hosts.hasOwnProperty(name)) {
  765. expect(controller.get('hosts').findProperty('name', name).get('tasks.length')).to.equal(test.e[name].count);
  766. }
  767. }
  768. });
  769. });
  770. });
  771. describe('#setLogTasksStatePerHost', function() {
  772. var tests = [
  773. {
  774. tasksPerHost: [{Tasks: {id: 1,status: 'COMPLETED'}},{Tasks: {id: 2,status: 'COMPLETED'}}],
  775. tasks: [],
  776. e: {m: 'COMPLETED',l: 2},
  777. m: 'host didn\'t have tasks and got 2 new'
  778. },
  779. {
  780. tasksPerHost: [{Tasks: {id: 1,status: 'COMPLETED'}},{Tasks: {id: 2,status: 'COMPLETED'}}],
  781. tasks: [{Tasks: {id: 1,status: 'IN_PROGRESS'}},{Tasks: {id: 2,status: 'IN_PROGRESS'}}],
  782. e: {m: 'COMPLETED',l: 2},
  783. m: 'host had 2 tasks and got both updated'
  784. },
  785. {
  786. tasksPerHost: [],
  787. tasks: [{Tasks: {id: 1,status: 'IN_PROGRESS'}},{Tasks: {id: 2,status: 'IN_PROGRESS'}}],
  788. e: {m: 'IN_PROGRESS',l: 2},
  789. m: 'host had 2 tasks and didn\'t get updates'
  790. },
  791. {
  792. tasksPerHost: [{Tasks: {id: 1,status: 'COMPLETED'}},{Tasks: {id: 2,status: 'COMPLETED'}},{Tasks: {id: 3,status: 'COMPLETED'}}],
  793. tasks: [{Tasks: {id: 1,status: 'IN_PROGRESS'}},{Tasks: {id: 2,status: 'IN_PROGRESS'}}],
  794. e: {m: 'COMPLETED',l: 3},
  795. m: 'host had 2 tasks and got both updated and 1 new'
  796. }
  797. ];
  798. tests.forEach(function(test) {
  799. it(test.m, function() {
  800. var controller = App.WizardStep9Controller.create({hosts: [Em.Object.create({logTasks: test.tasks})]});
  801. controller.setLogTasksStatePerHost(test.tasksPerHost, controller.get('hosts')[0]);
  802. expect(controller.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  803. expect(controller.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  804. });
  805. });
  806. });
  807. describe('#parseHostInfo', function() {
  808. var tests = [
  809. {
  810. cluster: {status: 'PENDING'},
  811. hosts: Em.A([
  812. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  813. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  814. ]),
  815. polledData: {
  816. tasks:[
  817. {Tasks: {host_name: 'host2',status: 'COMPLETED'}},
  818. {Tasks: {host_name: 'host2',status: 'COMPLETED'}}
  819. ]
  820. },
  821. e: {
  822. hosts:{
  823. host1: {progress: '33'},
  824. host2: {progress: '33'}
  825. },
  826. progress: '33'
  827. },
  828. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is PENDING'
  829. },
  830. {
  831. cluster: {status: 'PENDING'},
  832. hosts: Em.A([
  833. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  834. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  835. ]),
  836. polledData: {
  837. tasks:[
  838. {Tasks: {host_name: 'host1',status: 'IN_PROGRESS'}},
  839. {Tasks: {host_name: 'host2',status: 'IN_PROGRESS'}}
  840. ]
  841. },
  842. e: {hosts:{host1: {progress: '12'},host2: {progress: '12'}},progress: '12'},
  843. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is PENDING'
  844. },
  845. {
  846. cluster: {status: 'PENDING'},
  847. hosts: Em.A([
  848. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  849. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  850. ]),
  851. polledData: {
  852. tasks:[
  853. {Tasks: {host_name: 'host1',status: 'QUEUED'}},
  854. {Tasks: {host_name: 'host2',status: 'QUEUED'}}
  855. ]
  856. },
  857. e: {
  858. hosts:{
  859. host1: {progress: '3'},
  860. host2: {progress: '3'}
  861. },
  862. progress: '3'
  863. },
  864. m: 'Two hosts. Each host has one task QUEUED. Cluster status is PENDING'
  865. },
  866. {
  867. cluster: {status: 'INSTALLED'},
  868. hosts: Em.A([
  869. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  870. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  871. ]),
  872. polledData: {
  873. tasks:[
  874. {Tasks: {host_name: 'host2',status: 'COMPLETED'}},
  875. {Tasks: {host_name: 'host2',status: 'COMPLETED'}}
  876. ]
  877. },
  878. e: {
  879. hosts:{
  880. host1: {progress: '100'},
  881. host2: {progress: '100'}
  882. },
  883. progress: '100'
  884. },
  885. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is INSTALLED'
  886. },
  887. {
  888. cluster: {status: 'INSTALLED'},
  889. hosts: Em.A([
  890. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  891. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  892. ]),
  893. polledData: {
  894. tasks:[
  895. {Tasks: {host_name: 'host1',status: 'IN_PROGRESS'}},
  896. {Tasks: {host_name: 'host2',status: 'IN_PROGRESS'}}
  897. ]
  898. },
  899. e: {
  900. hosts:{
  901. host1: {progress: '58'},
  902. host2: {progress: '58'}
  903. },
  904. progress: '58'
  905. },
  906. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is INSTALLED'
  907. },
  908. {
  909. cluster: {status: 'INSTALLED'},
  910. hosts: Em.A([
  911. Em.Object.create({name: 'host1',status: '',message: '',progress: '',logTasks: []}),
  912. Em.Object.create({name: 'host2',status: '',message: '',progress: '',logTasks: []})
  913. ]),
  914. polledData: {
  915. tasks:[
  916. {Tasks: {host_name: 'host1',status: 'QUEUED'}},
  917. {Tasks: {host_name: 'host2',status: 'QUEUED'}}
  918. ]
  919. },
  920. e: {
  921. hosts:{
  922. host1: {progress: '40'},
  923. host2: {progress: '40'}
  924. },
  925. progress: '40'
  926. },
  927. m: 'Two hosts. Each host has one task QUEUED. Cluster status is INSTALLED'
  928. }
  929. ];
  930. tests.forEach(function(test) {
  931. it(test.m, function() {
  932. var controller = App.WizardStep9Controller.create({hosts: test.hosts, content: {cluster:{status: test.cluster.status}}, finishState: function(){return false;}});
  933. var logTasksChangesCounter = controller.get('logTasksChangesCounter');
  934. controller.parseHostInfo(test.polledData);
  935. expect(controller.get('logTasksChangesCounter')).to.equal(logTasksChangesCounter + 1);
  936. for (var name in test.e.hosts) {
  937. if (test.e.hosts.hasOwnProperty(name)) {
  938. expect(controller.get('hosts').findProperty('name', name).get('progress')).to.equal(test.e.hosts[name].progress);
  939. }
  940. }
  941. expect(controller.get('progress')).to.equal(test.e.progress);
  942. });
  943. });
  944. });
  945. });