step9_test.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  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 = Em.A([
  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 = Em.A([
  58. {
  59. hosts: [
  60. {status: 'failed'},
  61. {status: 'success'}
  62. ],
  63. isStepFailed: false,
  64. progress: '100',
  65. m: 'One host is failed',
  66. e: 'failed'
  67. },
  68. {
  69. hosts: [
  70. {status: 'warning'},
  71. {status: 'success'}
  72. ],
  73. m: 'One host is failed and step is not failed',
  74. isStepFailed: false,
  75. progress: '100',
  76. e: 'warning'
  77. },
  78. {
  79. hosts: [
  80. {status: 'warning'},
  81. {status: 'success'}
  82. ],
  83. m: 'One host is failed and step is failed',
  84. isStepFailed: true,
  85. progress: '100',
  86. e: 'failed'
  87. },
  88. {
  89. hosts: [
  90. {status: 'success'},
  91. {status: 'success'}
  92. ],
  93. m: 'All hosts are success and progress is 100',
  94. isStepFailed: false,
  95. progress: '100',
  96. e: 'success'
  97. },
  98. {
  99. hosts: [
  100. {status: 'success'},
  101. {status: 'success'}
  102. ],
  103. m: 'All hosts are success and progress is 50',
  104. isStepFailed: false,
  105. progress: '50',
  106. e: 'info'
  107. }
  108. ]);
  109. tests.forEach(function (test) {
  110. var controller = App.WizardStep9Controller.create({hosts: test.hosts, isStepFailed: function () {
  111. return test.isStepFailed
  112. }, progress: test.progress});
  113. controller.updateStatus();
  114. it(test.m, function () {
  115. expect(controller.get('status')).to.equal(test.e);
  116. });
  117. });
  118. });
  119. describe('#visibleHosts', function () {
  120. var hosts = [
  121. Em.Object.create({status: 'failed'}),
  122. Em.Object.create({status: 'heartbeat_lost'}),
  123. Em.Object.create({status: 'success'}),
  124. Em.Object.create({status: 'success'}),
  125. Em.Object.create({status: 'warning'}),
  126. Em.Object.create({status: 'info'}),
  127. Em.Object.create({status: 'info'})
  128. ];
  129. var tests = Em.A([
  130. {category: {hostStatus: 'all'}, e: hosts.length},
  131. {category: {hostStatus: 'inProgress'}, e: 2},
  132. {category: {hostStatus: 'warning'}, e: 1},
  133. {category: {hostStatus: 'failed'}, e: 2},
  134. {category: {hostStatus: 'success'}, e: 2}
  135. ]);
  136. tests.forEach(function (test) {
  137. it('selected category with hostStatus "' + test.category.hostStatus + '"', function () {
  138. var controller = App.WizardStep9Controller.create({
  139. hosts: hosts
  140. });
  141. controller.selectCategory({context: test.category});
  142. expect(controller.get('visibleHosts.length')).to.equal(test.e);
  143. });
  144. });
  145. });
  146. describe('#showRetry', function () {
  147. it('cluster status is not INSTALL FAILED', function () {
  148. var controller = App.WizardStep9Controller.create({content: {cluster: {status: 'INSTALLED'}}});
  149. expect(controller.get('showRetry')).to.equal(false);
  150. });
  151. it('cluster status is INSTALL FAILED', function () {
  152. var controller = App.WizardStep9Controller.create({content: {cluster: {status: 'INSTALL FAILED'}}});
  153. expect(controller.get('showRetry')).to.equal(true);
  154. });
  155. });
  156. describe('#resetHostsForRetry', function () {
  157. var hosts = {'host1': Em.Object.create({status: 'failed', message: 'Failed'}), 'host2': Em.Object.create({status: 'success', message: 'Success'})};
  158. var controller = App.WizardStep9Controller.create({content: {hosts: hosts}});
  159. it('All should have status "pending" and message "Waiting"', function () {
  160. controller.resetHostsForRetry();
  161. for (var name in hosts) {
  162. if (hosts.hasOwnProperty(name)) {
  163. expect(controller.get('content.hosts')[name].get('status', 'pending')).to.equal('pending');
  164. expect(controller.get('content.hosts')[name].get('message', 'Waiting')).to.equal('Waiting');
  165. }
  166. }
  167. });
  168. });
  169. var hosts_for_load_and_render = {
  170. 'host1': {
  171. message: 'message1',
  172. status: 'unknown',
  173. progress: '1',
  174. logTasks: [
  175. {},
  176. {}
  177. ],
  178. bootStatus: 'REGISTERED'
  179. },
  180. 'host2': {
  181. message: '',
  182. status: 'failed',
  183. progress: '1',
  184. logTasks: [
  185. {},
  186. {}
  187. ],
  188. bootStatus: ''
  189. },
  190. 'host3': {
  191. message: '',
  192. status: 'waiting',
  193. progress: null,
  194. logTasks: [
  195. {},
  196. {}
  197. ],
  198. bootStatus: ''
  199. },
  200. 'host4': {
  201. message: 'message4',
  202. status: null,
  203. progress: '10',
  204. logTasks: [
  205. {}
  206. ],
  207. bootStatus: 'REGISTERED'
  208. }
  209. };
  210. describe('#loadHosts', function () {
  211. var controller = App.WizardStep9Controller.create({content: {hosts: hosts_for_load_and_render}});
  212. controller.loadHosts();
  213. var loaded_hosts = controller.get('hosts');
  214. it('Only REGISTERED hosts', function () {
  215. expect(loaded_hosts.length).to.equal(2);
  216. });
  217. it('All hosts have progress 0', function () {
  218. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  219. });
  220. it('All hosts have progress 0', function () {
  221. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  222. });
  223. it('All host don\'t have logTasks', function () {
  224. expect(loaded_hosts.everyProperty('logTasks.length', 0)).to.equal(true);
  225. });
  226. });
  227. describe('#hostHasClientsOnly', function () {
  228. var tests = Em.A([
  229. {
  230. hosts: [
  231. Em.Object.create({
  232. hostName: 'host1',
  233. logTasks: [
  234. {Tasks: {role: 'HDFS_CLIENT'}},
  235. {Tasks: {role: 'DATANODE'}}
  236. ],
  237. status: 'old_status',
  238. progress: '10',
  239. e: {status: 'old_status', progress: '10'}
  240. }),
  241. Em.Object.create({
  242. hostName: 'host2',
  243. logTasks: [
  244. {Tasks: {role: 'HDFS_CLIENT'}}
  245. ],
  246. status: 'old_status',
  247. progress: '10',
  248. e: {status: 'success', progress: '100'}
  249. })
  250. ],
  251. jsonError: false
  252. },
  253. {
  254. hosts: [
  255. Em.Object.create({
  256. hostName: 'host1',
  257. logTasks: [
  258. {Tasks: {role: 'HDFS_CLIENT'}},
  259. {Tasks: {role: 'DATANODE'}}
  260. ],
  261. status: 'old_status',
  262. progress: '10',
  263. e: {status: 'success', progress: '100'}
  264. }),
  265. Em.Object.create({
  266. hostName: 'host2',
  267. logTasks: [
  268. {Tasks: {role: 'HDFS_CLIENT'}}
  269. ],
  270. status: 'old_status',
  271. progress: '10',
  272. e: {status: 'success', progress: '100'}
  273. })
  274. ],
  275. jsonError: true
  276. }
  277. ]);
  278. tests.forEach(function (test) {
  279. it('', function () {
  280. var controller = App.WizardStep9Controller.create({hosts: test.hosts});
  281. controller.hostHasClientsOnly(test.jsonError);
  282. test.hosts.forEach(function (host) {
  283. expect(controller.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  284. expect(controller.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  285. });
  286. });
  287. });
  288. });
  289. describe('#onSuccessPerHost', function () {
  290. var tests = Em.A([
  291. {
  292. cluster: {status: 'INSTALLED'},
  293. host: Em.Object.create({status: 'pending'}),
  294. actions: [],
  295. e: {status: 'success'},
  296. m: 'No tasks for host'
  297. },
  298. {
  299. cluster: {status: 'INSTALLED'},
  300. host: Em.Object.create({status: 'info'}),
  301. actions: [
  302. {Tasks: {status: 'COMPLETED'}},
  303. {Tasks: {status: 'COMPLETED'}}
  304. ],
  305. e: {status: 'success'},
  306. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  307. },
  308. {
  309. cluster: {status: 'FAILED'},
  310. host: Em.Object.create({status: 'info'}),
  311. actions: [
  312. {Tasks: {status: 'COMPLETED'}},
  313. {Tasks: {status: 'COMPLETED'}}
  314. ],
  315. e: {status: 'info'},
  316. m: 'All Tasks COMPLETED and cluster status FAILED'
  317. },
  318. {
  319. cluster: {status: 'INSTALLED'},
  320. host: Em.Object.create({status: 'info'}),
  321. actions: [
  322. {Tasks: {status: 'FAILED'}},
  323. {Tasks: {status: 'COMPLETED'}}
  324. ],
  325. e: {status: 'info'},
  326. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  327. },
  328. {
  329. cluster: {status: 'FAILED'},
  330. host: Em.Object.create({status: 'info'}),
  331. actions: [
  332. {Tasks: {status: 'FAILED'}},
  333. {Tasks: {status: 'COMPLETED'}}
  334. ],
  335. e: {status: 'info'},
  336. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  337. }
  338. ]);
  339. tests.forEach(function (test) {
  340. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}});
  341. controller.onSuccessPerHost(test.actions, test.host);
  342. it(test.m, function () {
  343. expect(test.host.status).to.equal(test.e.status);
  344. });
  345. });
  346. });
  347. describe('#onErrorPerHost', function () {
  348. var tests = Em.A([
  349. {
  350. cluster: {status: 'INSTALLED'},
  351. host: Em.Object.create({status: 'pending'}),
  352. actions: [],
  353. e: {status: 'pending'},
  354. isMasterFailed: false,
  355. m: 'No tasks for host'
  356. },
  357. {
  358. cluster: {status: 'INSTALLED'},
  359. host: Em.Object.create({status: 'info'}),
  360. actions: [
  361. {Tasks: {status: 'FAILED'}},
  362. {Tasks: {status: 'COMPLETED'}}
  363. ],
  364. e: {status: 'warning'},
  365. isMasterFailed: false,
  366. m: 'One Task FAILED and cluster status INSTALLED'
  367. },
  368. {
  369. cluster: {status: 'INSTALLED'},
  370. host: Em.Object.create({status: 'info'}),
  371. actions: [
  372. {Tasks: {status: 'ABORTED'}},
  373. {Tasks: {status: 'COMPLETED'}}
  374. ],
  375. e: {status: 'warning'},
  376. isMasterFailed: false,
  377. m: 'One Task ABORTED and cluster status INSTALLED'
  378. },
  379. {
  380. cluster: {status: 'INSTALLED'},
  381. host: Em.Object.create({status: 'info'}),
  382. actions: [
  383. {Tasks: {status: 'TIMEDOUT'}},
  384. {Tasks: {status: 'COMPLETED'}}
  385. ],
  386. e: {status: 'warning'},
  387. isMasterFailed: false,
  388. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  389. },
  390. {
  391. cluster: {status: 'PENDING'},
  392. host: Em.Object.create({status: 'info'}),
  393. actions: [
  394. {Tasks: {status: 'FAILED'}},
  395. {Tasks: {status: 'COMPLETED'}}
  396. ],
  397. e: {status: 'failed'},
  398. isMasterFailed: true,
  399. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  400. },
  401. {
  402. cluster: {status: 'PENDING'},
  403. host: Em.Object.create({status: 'info'}),
  404. actions: [
  405. {Tasks: {status: 'COMPLETED'}},
  406. {Tasks: {status: 'COMPLETED'}}
  407. ],
  408. e: {status: 'info'},
  409. isMasterFailed: false,
  410. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  411. }
  412. ]);
  413. tests.forEach(function (test) {
  414. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  415. return test.isMasterFailed;
  416. }});
  417. controller.onErrorPerHost(test.actions, test.host);
  418. it(test.m, function () {
  419. expect(test.host.status).to.equal(test.e.status);
  420. });
  421. });
  422. });
  423. describe('#isMasterFailed', function () {
  424. var tests = Em.A([
  425. {
  426. actions: [
  427. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  428. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  429. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  430. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  431. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  432. ],
  433. e: false,
  434. m: 'No one Master is failed'
  435. },
  436. {
  437. actions: [
  438. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  439. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  440. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  441. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  442. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  443. ],
  444. e: true,
  445. m: 'One Master is failed'
  446. },
  447. {
  448. actions: [
  449. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  450. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  451. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  452. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  453. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  454. ],
  455. e: false,
  456. m: 'one Master is failed but command is not install'
  457. }
  458. ]);
  459. tests.forEach(function (test) {
  460. it(test.m, function () {
  461. var controller = App.WizardStep9Controller.create();
  462. expect(controller.isMasterFailed(test.actions)).to.equal(test.e);
  463. });
  464. });
  465. });
  466. describe('#onInProgressPerHost', function () {
  467. var tests = Em.A([
  468. {
  469. host: Em.Object.create({message: 'default_message'}),
  470. actions: [
  471. {Tasks: {status: 'COMPLETED'}},
  472. {Tasks: {status: 'COMPLETED'}}
  473. ],
  474. e: {message: 'default_message', b: true},
  475. m: 'All Tasks COMPLETED'
  476. },
  477. {
  478. host: Em.Object.create({message: 'default_message'}),
  479. actions: [
  480. {Tasks: {status: 'IN_PROGRESS'}},
  481. {Tasks: {status: 'COMPLETED'}}
  482. ],
  483. e: {message: 'default_message', b: false},
  484. m: 'One Task IN_PROGRESS'
  485. },
  486. {
  487. host: Em.Object.create({message: 'default_message'}),
  488. actions: [
  489. {Tasks: {status: 'QUEUED'}},
  490. {Tasks: {status: 'COMPLETED'}}
  491. ],
  492. e: {message: 'default_message', b: false},
  493. m: 'One Task QUEUED'
  494. },
  495. {
  496. host: Em.Object.create({message: 'default_message'}),
  497. actions: [
  498. {Tasks: {status: 'PENDING'}},
  499. {Tasks: {status: 'COMPLETED'}}
  500. ],
  501. e: {message: 'default_message', b: false},
  502. m: 'One Task PENDING'
  503. }
  504. ]);
  505. tests.forEach(function (test) {
  506. it(test.m, function () {
  507. var controller = App.WizardStep9Controller.create();
  508. controller.onInProgressPerHost(test.actions, test.host);
  509. expect(test.host.message == test.e.message).to.equal(test.e.b);
  510. });
  511. });
  512. });
  513. describe('#progressPerHost', function () {
  514. var tests = Em.A([
  515. {
  516. cluster: {status: 'PENDING'},
  517. host: Em.Object.create({progress: 0}),
  518. actions: [
  519. {Tasks: {status: 'COMPLETED'}},
  520. {Tasks: {status: 'COMPLETED'}},
  521. {Tasks: {status: 'QUEUED'}},
  522. {Tasks: {status: 'QUEUED'}},
  523. {Tasks: {status: 'IN_PROGRESS'}}
  524. ],
  525. e: {ret: 17, host: '17'},
  526. m: 'All types of status available. cluster status PENDING'
  527. },
  528. {
  529. cluster: {status: 'PENDING'},
  530. host: Em.Object.create({progress: 0}),
  531. actions: [],
  532. e: {ret: 33, host: '33'},
  533. m: 'No tasks available. cluster status PENDING'
  534. },
  535. {
  536. cluster: {status: 'INSTALLED'},
  537. host: Em.Object.create({progress: 0}),
  538. actions: [],
  539. e: {ret: 100, host: '100'},
  540. m: 'No tasks available. cluster status INSTALLED'
  541. },
  542. {
  543. cluster: {status: 'INSTALLED'},
  544. host: Em.Object.create({progress: 0}),
  545. actions: [
  546. {Tasks: {status: 'COMPLETED'}},
  547. {Tasks: {status: 'COMPLETED'}},
  548. {Tasks: {status: 'QUEUED'}},
  549. {Tasks: {status: 'QUEUED'}},
  550. {Tasks: {status: 'IN_PROGRESS'}}
  551. ],
  552. e: {ret: 68, host: '68'},
  553. m: 'All types of status available. cluster status INSTALLED'
  554. },
  555. {
  556. cluster: {status: 'FAILED'},
  557. host: Em.Object.create({progress: 0}),
  558. actions: [],
  559. e: {ret: 100, host: '100'},
  560. m: 'Cluster status is not PENDING or INSTALLED'
  561. }
  562. ]);
  563. tests.forEach(function (test) {
  564. it(test.m, function () {
  565. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}});
  566. var progress = controller.progressPerHost(test.actions, test.host);
  567. expect(progress).to.equal(test.e.ret);
  568. expect(test.host.progress).to.equal(test.e.host);
  569. });
  570. });
  571. });
  572. describe('#clearStep', function () {
  573. var controller = App.WizardStep9Controller.create({hosts: [
  574. {},
  575. {},
  576. {}
  577. ]});
  578. it('All to default values', function () {
  579. controller.clearStep();
  580. expect(controller.get('hosts.length')).to.equal(0);
  581. expect(controller.get('status')).to.equal('info');
  582. expect(controller.get('progress')).to.equal('0');
  583. expect(controller.get('numPolls')).to.equal(1);
  584. });
  585. });
  586. describe('#replacePolledData', function () {
  587. var controller = App.WizardStep9Controller.create({polledData: [
  588. {},
  589. {},
  590. {}
  591. ]});
  592. var newPolledData = [
  593. {}
  594. ];
  595. controller.replacePolledData(newPolledData);
  596. it('replacing polled data', function () {
  597. expect(controller.get('polledData.length')).to.equal(newPolledData.length);
  598. });
  599. });
  600. describe('#isSuccess', function () {
  601. var tests = Em.A([
  602. {
  603. polledData: [
  604. {Tasks: {status: 'COMPLETED'}},
  605. {Tasks: {status: 'COMPLETED'}}
  606. ],
  607. e: true,
  608. m: 'All tasks are COMPLETED'
  609. },
  610. {
  611. polledData: [
  612. {Tasks: {status: 'COMPLETED'}},
  613. {Tasks: {status: 'FAILED'}}
  614. ],
  615. e: false,
  616. m: 'Not all tasks are COMPLETED'
  617. }
  618. ]);
  619. tests.forEach(function (test) {
  620. it(test.m, function () {
  621. var controller = App.WizardStep9Controller.create();
  622. expect(controller.isSuccess(test.polledData)).to.equal(test.e);
  623. });
  624. });
  625. });
  626. describe('#isStepFailed', function () {
  627. var tests = Em.A([
  628. {
  629. polledData: [
  630. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  631. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  632. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  633. ],
  634. e: true,
  635. m: 'GANGLIA_MONITOR 2/3 failed'
  636. },
  637. {
  638. polledData: [
  639. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  640. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  641. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  642. ],
  643. e: false,
  644. m: 'GANGLIA_MONITOR 1/3 failed'
  645. },
  646. {
  647. polledData: [
  648. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  649. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  650. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  651. ],
  652. e: true,
  653. m: 'HBASE_REGIONSERVER 2/3 failed'
  654. },
  655. {
  656. polledData: [
  657. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  658. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  659. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  660. ],
  661. e: false,
  662. m: 'HBASE_REGIONSERVER 1/3 failed'
  663. },
  664. {
  665. polledData: [
  666. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  667. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  668. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  669. ],
  670. e: true,
  671. m: 'TASKTRACKER 2/3 failed'
  672. },
  673. {
  674. polledData: [
  675. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  676. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  677. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  678. ],
  679. e: false,
  680. m: 'TASKTRACKER 1/3 failed'
  681. },
  682. {
  683. polledData: [
  684. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  685. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  686. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  687. ],
  688. e: true,
  689. m: 'DATANODE 2/3 failed'
  690. },
  691. {
  692. polledData: [
  693. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  694. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  695. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  696. ],
  697. e: false,
  698. m: 'DATANODE 1/3 failed'
  699. },
  700. {
  701. polledData: [
  702. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  703. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  704. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  705. ],
  706. e: true,
  707. m: 'NAMENODE failed'
  708. },
  709. {
  710. polledData: [
  711. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  712. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  713. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  714. ],
  715. e: false,
  716. m: 'Nothing failed failed'
  717. }
  718. ]);
  719. tests.forEach(function (test) {
  720. var controller = App.WizardStep9Controller.create({polledData: test.polledData});
  721. it(test.m, function () {
  722. expect(controller.isStepFailed()).to.equal(test.e);
  723. });
  724. });
  725. });
  726. describe('#getUrl', function () {
  727. var clusterName = 'tdk';
  728. var cluster = App.WizardStep9Controller.create({content: {cluster: {name: clusterName, requestId: null}}});
  729. it('check requestId priority', function () {
  730. cluster.set('content.cluster.requestId', 123);
  731. var url = cluster.getUrl(321);
  732. expect(url).to.equal(App.apiPrefix + '/clusters/' + clusterName + '/requests/' + '321' + '?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true');
  733. url = cluster.getUrl();
  734. expect(url).to.equal(App.apiPrefix + '/clusters/' + clusterName + '/requests/' + '123' + '?fields=tasks/Tasks/command,tasks/Tasks/exit_code,tasks/Tasks/start_time,tasks/Tasks/end_time,tasks/Tasks/host_name,tasks/Tasks/id,tasks/Tasks/role,tasks/Tasks/status&minimal_response=true');
  735. });
  736. });
  737. describe('#finishState', function () {
  738. var statuses = Em.A(['INSTALL FAILED', 'START FAILED', 'STARTED']);
  739. it('Installer is finished', function () {
  740. statuses.forEach(function (status) {
  741. var controller = App.WizardStep9Controller.create({content: {cluster: {status: status}}});
  742. var result = controller.finishState();
  743. expect(result).to.equal(true);
  744. });
  745. });
  746. it('Unknown cluster status ', function () {
  747. var controller = App.WizardStep9Controller.create({content: {cluster: {status: 'FAKE_STATUS'}}});
  748. var result = controller.finishState();
  749. expect(result).to.equal(false);
  750. });
  751. });
  752. describe('#setLogTasksStatePerHost', function () {
  753. var tests = Em.A([
  754. {
  755. tasksPerHost: [
  756. {Tasks: {id: 1, status: 'COMPLETED'}},
  757. {Tasks: {id: 2, status: 'COMPLETED'}}
  758. ],
  759. tasks: [],
  760. e: {m: 'COMPLETED', l: 2},
  761. m: 'host didn\'t have tasks and got 2 new'
  762. },
  763. {
  764. tasksPerHost: [
  765. {Tasks: {id: 1, status: 'COMPLETED'}},
  766. {Tasks: {id: 2, status: 'COMPLETED'}}
  767. ],
  768. tasks: [
  769. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  770. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  771. ],
  772. e: {m: 'COMPLETED', l: 2},
  773. m: 'host had 2 tasks and got both updated'
  774. },
  775. {
  776. tasksPerHost: [],
  777. tasks: [
  778. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  779. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  780. ],
  781. e: {m: 'IN_PROGRESS', l: 2},
  782. m: 'host had 2 tasks and didn\'t get updates'
  783. },
  784. {
  785. tasksPerHost: [
  786. {Tasks: {id: 1, status: 'COMPLETED'}},
  787. {Tasks: {id: 2, status: 'COMPLETED'}},
  788. {Tasks: {id: 3, status: 'COMPLETED'}}
  789. ],
  790. tasks: [
  791. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  792. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  793. ],
  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 = Em.A([
  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 () {
  933. return false;
  934. }});
  935. var logTasksChangesCounter = controller.get('logTasksChangesCounter');
  936. controller.parseHostInfo(test.polledData);
  937. expect(controller.get('logTasksChangesCounter')).to.equal(logTasksChangesCounter + 1);
  938. for (var name in test.e.hosts) {
  939. if (test.e.hosts.hasOwnProperty(name)) {
  940. expect(controller.get('hosts').findProperty('name', name).get('progress')).to.equal(test.e.hosts[name].progress);
  941. }
  942. }
  943. expect(controller.get('progress')).to.equal(test.e.progress);
  944. });
  945. });
  946. });
  947. describe('#isAllComponentsInstalledSuccessCallback', function () {
  948. describe('', function() {
  949. var hosts = Em.A([
  950. Em.Object.create({name: 'host1', status: 'failed', expectedStatus: 'heartbeat_lost'}),
  951. Em.Object.create({name: 'host2', status: 'info', expectedStatus: 'heartbeat_lost'}),
  952. Em.Object.create({name: 'host3', status: 'warning', expectedStatus: 'warning'}),
  953. Em.Object.create({name: 'host4', status: 'info', expectedStatus: 'info'})
  954. ]);
  955. var heartbeatLostData = {
  956. "items": [
  957. {
  958. "Hosts": {
  959. "cluster_name": "c1",
  960. "host_name": "host1",
  961. "host_state": "HEARTBEAT_LOST"
  962. },
  963. "host_components": [
  964. {
  965. "HostRoles": {
  966. "cluster_name": "c1",
  967. "component_name": "NAMENODE",
  968. "host_name": "host1",
  969. "state": "INSTALL_FAILED"
  970. }
  971. }
  972. ]
  973. },
  974. {
  975. "Hosts": {
  976. "cluster_name": "c1",
  977. "host_name": "host2",
  978. "host_state": "HEARTBEAT_LOST"
  979. },
  980. "host_components": [
  981. {
  982. "HostRoles": {
  983. "cluster_name": "c1",
  984. "component_name": "ZOOKEEPER_SERVER",
  985. "host_name": "host2",
  986. "state": "UNKNOWN"
  987. }
  988. }
  989. ]
  990. },
  991. {
  992. "Hosts": {
  993. "cluster_name": "c1",
  994. "host_name": "host3",
  995. "host_state": "HEALTHY"
  996. },
  997. "host_components": [
  998. {
  999. "HostRoles": {
  1000. "cluster_name": "c1",
  1001. "component_name": "DATANODE",
  1002. "host_name": "host3",
  1003. "state": "INSTALL_FAILED"
  1004. }
  1005. }
  1006. ]
  1007. },
  1008. {
  1009. "Hosts": {
  1010. "cluster_name": "c1",
  1011. "host_name": "host4",
  1012. "host_state": "HEALTHY"
  1013. },
  1014. "host_components": [
  1015. {
  1016. "HostRoles": {
  1017. "cluster_name": "c1",
  1018. "component_name": "PIG",
  1019. "host_name": "host4",
  1020. "state": "INSTALLED"
  1021. }
  1022. },
  1023. {
  1024. "HostRoles": {
  1025. "cluster_name": "c1",
  1026. "component_name": "DATANODE",
  1027. "host_name": "host3",
  1028. "state": "INSTALLED"
  1029. }
  1030. }
  1031. ]
  1032. }
  1033. ]
  1034. };
  1035. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController'}});
  1036. App.testMode = true;
  1037. // Action
  1038. controller.isAllComponentsInstalledSuccessCallback(heartbeatLostData);
  1039. // Validation for the status of all hosts.
  1040. controller.get('hosts').forEach(function (test) {
  1041. var status = heartbeatLostData.items.findProperty('Hosts.host_name', test.get('name')).Hosts.host_state;
  1042. it('Host "' + test.get('name') + '"' + ' with status "' + status + '" ', function () {
  1043. expect(test.get('status')).to.equal(test.get('expectedStatus'));
  1044. });
  1045. });
  1046. });
  1047. describe('', function() {
  1048. var noHeartbeatLostData = {
  1049. "items": [
  1050. {
  1051. "Hosts": {
  1052. "cluster_name": "c1",
  1053. "host_name": "host1",
  1054. "host_state": "HEALTHY"
  1055. },
  1056. "host_components": [
  1057. {
  1058. "HostRoles": {
  1059. "cluster_name": "c1",
  1060. "component_name": "NAMENODE",
  1061. "host_name": "host1",
  1062. "state": "INSTALL_FAILED"
  1063. }
  1064. }
  1065. ]
  1066. }
  1067. ]
  1068. };
  1069. var hosts = Em.A([Em.Object.create({name: 'host1', status: 'failed'})]);
  1070. // When there is no heartbeat lost for any host and cluster failed install task, Refreshing the page should not launch start all services request.
  1071. // Below transitions are possibilities in this function
  1072. // PENDING -> INSTALL or PENDING. This transition happens when install all services request is completed successfully.
  1073. // INSTALL FAILED -> INSTALL FAILED. No transition should happen when install all services request fails and then user hits refresh
  1074. // Cluster is not expected to enter this function in other states: INSTALLED, START FAILED, STARTED
  1075. var statuses = Em.A(['INSTALL FAILED', 'INSTALLED','START FAILED', 'STARTED']); // Cluster in any of this states should have no effect on the state from this function
  1076. statuses.forEach(function (priorStatus) {
  1077. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: priorStatus}},togglePreviousSteps: function(){}});
  1078. // Action
  1079. controller.isAllComponentsInstalledSuccessCallback(noHeartbeatLostData);
  1080. // Validation for the cluster state.
  1081. var actualStatus = controller.get('content.cluster.status');
  1082. it('Cluster state before entering the function "' + priorStatus + '"', function () {
  1083. expect(actualStatus).to.equal(priorStatus);
  1084. });
  1085. });
  1086. });
  1087. })
  1088. // On completion of Start all services error callback function,
  1089. // Cluster Status should be INSTALL FAILED
  1090. // All progress bar on the screen should be finished (100%) with blue color.
  1091. // Retry button should be enabled, next button should be disabled
  1092. describe('#launchStartServicesErrorCallback', function () {
  1093. App.testMode = true;
  1094. // override the actual function
  1095. App.popup = {
  1096. setErrorPopup: function() {
  1097. return true;
  1098. }
  1099. };
  1100. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}),Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1101. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING',name: 'c1'}},togglePreviousSteps: function(){}});
  1102. //Action
  1103. controller.launchStartServicesErrorCallback({status:500, statusTesxt: 'Server Error'});
  1104. it('Cluster Status should be INSTALL FAILED', function () {
  1105. expect(controller.get('content.cluster.status')).to.equal('INSTALL FAILED');
  1106. });
  1107. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1108. expect(controller.get('progress')).to.equal('100');
  1109. expect(controller.get('status')).to.equal('failed');
  1110. });
  1111. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1112. controller.get('hosts').forEach(function(host){
  1113. expect(host.get('progress')).to.equal('100');
  1114. expect(host.get('status')).to.equal('info');
  1115. });
  1116. });
  1117. it('Next button should be disabled', function () {
  1118. expect(controller.get('isSubmitDisabled')).to.equal(true);
  1119. });
  1120. it('Retry button should be visible', function () {
  1121. expect(controller.get('showRetry')).to.equal(true);
  1122. })
  1123. });
  1124. });