step9_test.js 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924
  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 App = require('app');
  19. require('models/stack_service_component');
  20. require('models/hosts');
  21. require('controllers/wizard');
  22. require('controllers/installer');
  23. require('controllers/wizard/step9_controller');
  24. require('utils/helper');
  25. require('utils/ajax/ajax');
  26. var testHelpers = require('test/helpers');
  27. var modelSetup = require('test/init_model_test');
  28. var c, obj;
  29. function getController() {
  30. return App.WizardStep9Controller.create({
  31. content: {controllerName: '', cluster: {status: ''}},
  32. saveClusterStatus: Em.K,
  33. saveInstalledHosts: Em.K,
  34. togglePreviousSteps: Em.K,
  35. setFinishState: Em.K,
  36. changeParseHostInfo: Em.K,
  37. parseHostInfoPolling: Em.K,
  38. wizardController: Em.Object.create({
  39. requestsId: [],
  40. cluster: {oldRequestsId: []},
  41. getDBProperty: function(name) {
  42. return this.get(name);
  43. }
  44. })
  45. });
  46. }
  47. describe('App.InstallerStep9Controller', function () {
  48. beforeEach(function () {
  49. App.set('supports.skipComponentStartAfterInstall', false);
  50. modelSetup.setupStackServiceComponent();
  51. c = getController();
  52. obj = App.InstallerController.create();
  53. App.ajax.send.restore();
  54. sinon.stub(App.ajax, 'send', function() {
  55. return {
  56. then: function() {
  57. return true;
  58. },
  59. retry: function() {
  60. return {
  61. then: Em.K,
  62. complete: Em.K
  63. };
  64. },
  65. complete: Em.K
  66. };
  67. });
  68. });
  69. afterEach(function () {
  70. modelSetup.cleanStackServiceComponent();
  71. });
  72. App.TestAliases.testAsComputedEqual(getController(), 'showRetry', 'content.cluster.status', 'INSTALL FAILED');
  73. describe('#isSubmitDisabled', function () {
  74. var tests = Em.A([
  75. {controllerName: 'addHostController', state: 'STARTED', e: false},
  76. {controllerName: 'addHostController', state: 'START_SKIPPED', e: false},
  77. {controllerName: 'addHostController', state: 'START FAILED', e: false},
  78. {controllerName: 'addHostController', state: 'INSTALL FAILED', e: false},
  79. {controllerName: 'addHostController', state: 'PENDING', e: true},
  80. {controllerName: 'addHostController', state: 'INSTALLED', e: true},
  81. {controllerName: 'addServiceController', state: 'STARTED', e: false},
  82. {controllerName: 'addServiceController', state: 'START_SKIPPED', e: false},
  83. {controllerName: 'addServiceController', state: 'START FAILED', e: false},
  84. {controllerName: 'addServiceController', state: 'INSTALL FAILED', e: false},
  85. {controllerName: 'addServiceController', state: 'PENDING', e: true},
  86. {controllerName: 'addServiceController', state: 'INSTALLED', e: true},
  87. {controllerName: 'installerController', state: 'STARTED', e: false},
  88. {controllerName: 'installerController', state: 'START_SKIPPED', e: false},
  89. {controllerName: 'installerController', state: 'START FAILED', e: false},
  90. {controllerName: 'installerController', state: 'INSTALL FAILED', e: true},
  91. {controllerName: 'installerController', state: 'INSTALLED', e: true},
  92. {controllerName: 'installerController', state: 'PENDING', e: true}
  93. ]);
  94. tests.forEach(function (test) {
  95. var controller = App.WizardStep9Controller.create({
  96. saveClusterStatus: Em.K,
  97. saveInstalledHosts: Em.K,
  98. content: {
  99. controllerName: test.controllerName,
  100. cluster: {
  101. status: test.state
  102. }
  103. }
  104. });
  105. it('controllerName is ' + test.controllerName + '; cluster status is ' + test.state + '; isSubmitDisabled should be ' + test.e, function () {
  106. expect(controller.get('isSubmitDisabled')).to.equal(test.e);
  107. });
  108. });
  109. });
  110. describe('#status', function () {
  111. var tests = Em.A([
  112. {
  113. hosts: [
  114. {status: 'failed'},
  115. {status: 'success'}
  116. ],
  117. isStepFailed: false,
  118. progress: '100',
  119. m: 'One host is failed',
  120. e: 'failed'
  121. },
  122. {
  123. hosts: [
  124. {status: 'warning'},
  125. {status: 'success'}
  126. ],
  127. m: 'One host is failed and step is not failed',
  128. isStepFailed: false,
  129. progress: '100',
  130. e: 'warning'
  131. },
  132. {
  133. hosts: [
  134. {status: 'warning'},
  135. {status: 'success'}
  136. ],
  137. m: 'One host is failed and step is failed',
  138. isStepFailed: true,
  139. progress: '100',
  140. e: 'failed'
  141. },
  142. {
  143. hosts: [
  144. {status: 'success'},
  145. {status: 'success'}
  146. ],
  147. m: 'All hosts are success and progress is 100',
  148. isStepFailed: false,
  149. progress: '100',
  150. e: 'success'
  151. },
  152. {
  153. hosts: [
  154. {status: 'success'},
  155. {status: 'success'}
  156. ],
  157. m: 'All hosts are success and progress is 50',
  158. isStepFailed: false,
  159. progress: '50',
  160. e: 'info'
  161. }
  162. ]);
  163. tests.forEach(function (test) {
  164. var controller = App.WizardStep9Controller.create({
  165. saveClusterStatus: Em.K,
  166. saveInstalledHosts: Em.K,
  167. hosts: test.hosts,
  168. isStepFailed: function () {
  169. return test.isStepFailed
  170. },
  171. progress: test.progress
  172. });
  173. controller.updateStatus();
  174. it(test.m, function () {
  175. expect(controller.get('status')).to.equal(test.e);
  176. });
  177. });
  178. });
  179. describe('#resetHostsForRetry', function () {
  180. var hosts = {'host1': Em.Object.create({status: 'failed', message: 'Failed'}), 'host2': Em.Object.create({status: 'success', message: 'Success'})};
  181. beforeEach(function () {
  182. c.reopen({content: {hosts: hosts}});
  183. c.resetHostsForRetry();
  184. });
  185. Object.keys(hosts).forEach(function (name) {
  186. if (hosts.hasOwnProperty(name)) {
  187. it(name + '.status', function () {
  188. expect(c.get('content.hosts')[name].get('status', 'pending')).to.equal('pending');
  189. });
  190. it(name + '.message', function () {
  191. expect(c.get('content.hosts')[name].get('message', 'Waiting')).to.equal('Waiting');
  192. });
  193. }
  194. });
  195. });
  196. describe('#setParseHostInfo', function () {
  197. var tasks = Em.A([
  198. Em.Object.create({
  199. Tasks: Em.Object.create({
  200. host_name: 'host1',
  201. status: 'PENDING'
  202. })
  203. }),
  204. Em.Object.create({
  205. Tasks: Em.Object.create({
  206. host_name: 'host1',
  207. status: 'PENDING'
  208. })
  209. })
  210. ]);
  211. var content = Em.Object.create({
  212. cluster: Em.Object.create({
  213. requestId: '11',
  214. status: 'PENDING'
  215. })
  216. });
  217. beforeEach(function(){
  218. c.set('content', content)
  219. });
  220. it('Should make parseHostInfo false"', function () {
  221. var polledData = Em.Object.create({
  222. tasks: tasks,
  223. Requests: Em.Object.create({
  224. id: '222'
  225. })
  226. });
  227. c.setParseHostInfo(polledData);
  228. expect(c.get('parseHostInfo')).to.be.false;
  229. });
  230. it('Should set polledData"', function () {
  231. var polledData = Em.Object.create({
  232. tasks: tasks,
  233. Requests: Em.Object.create({
  234. id: '11'
  235. })
  236. });
  237. c.setParseHostInfo(polledData);
  238. var expected = [
  239. {
  240. "Tasks": {
  241. "status": "PENDING",
  242. "host_name": "host1",
  243. "request_id": "11"
  244. }
  245. },
  246. {
  247. "Tasks": {
  248. "status": "PENDING",
  249. "host_name": "host1",
  250. "request_id": "11"
  251. }
  252. }
  253. ];
  254. var result = JSON.parse(JSON.stringify(c.get('polledData')));
  255. expect(result).to.eql(expected);
  256. });
  257. it('Should set progress for hosts"', function () {
  258. var polledData = Em.Object.create({
  259. tasks: tasks,
  260. Requests: Em.Object.create({
  261. id: '11'
  262. })
  263. });
  264. var hosts = Em.A([
  265. Em.Object.create({
  266. name: 'host1',
  267. logTasks: [
  268. {Tasks: {role: 'HDFS_CLIENT'}},
  269. {Tasks: {role: 'DATANODE'}}
  270. ],
  271. status: 'old_status',
  272. progress: '10',
  273. isNoTasksForInstall: true,
  274. e: {status: 'old_status', progress: '10'}
  275. }),
  276. Em.Object.create({
  277. name: 'host2',
  278. logTasks: [
  279. {Tasks: {role: 'HDFS_CLIENT'}}
  280. ],
  281. status: 'old_status',
  282. progress: '10',
  283. e: {status: 'success', progress: '100'}
  284. })
  285. ]);
  286. c.set('hosts', hosts);
  287. c.setParseHostInfo(polledData);
  288. var expected = [
  289. {
  290. "name": "host1",
  291. "logTasks": [
  292. {
  293. "Tasks": {
  294. "role": "HDFS_CLIENT",
  295. "status": "PENDING"
  296. }
  297. },
  298. {
  299. "Tasks": {
  300. "role": "DATANODE"
  301. }
  302. }
  303. ],
  304. "progress": "0",
  305. "isNoTasksForInstall": false,
  306. "e": {
  307. "status": "old_status",
  308. "progress": "10"
  309. },
  310. "status": "in_progress",
  311. "message": ""
  312. },
  313. {
  314. "name": "host2",
  315. "logTasks": [
  316. {
  317. "Tasks": {
  318. "role": "HDFS_CLIENT"
  319. }
  320. }
  321. ],
  322. "progress": "33",
  323. "e": {
  324. "status": "success",
  325. "progress": "100"
  326. },
  327. "status": "pending",
  328. "isNoTasksForInstall": true,
  329. "message": "Install complete (Waiting to start)"
  330. }
  331. ];
  332. var result = JSON.parse(JSON.stringify(c.get('hosts')));
  333. expect(result).to.eql(expected);
  334. });
  335. });
  336. var hostsForLoadAndRender = {
  337. 'host1': {
  338. message: 'message1',
  339. status: 'unknown',
  340. progress: '1',
  341. logTasks: [
  342. {},
  343. {}
  344. ],
  345. bootStatus: 'REGISTERED'
  346. },
  347. 'host2': {
  348. message: '',
  349. status: 'failed',
  350. progress: '1',
  351. logTasks: [
  352. {},
  353. {}
  354. ],
  355. bootStatus: ''
  356. },
  357. 'host3': {
  358. message: '',
  359. status: 'waiting',
  360. progress: null,
  361. logTasks: [
  362. {},
  363. {}
  364. ],
  365. bootStatus: ''
  366. },
  367. 'host4': {
  368. message: 'message4',
  369. status: null,
  370. progress: '10',
  371. logTasks: [
  372. {}
  373. ],
  374. bootStatus: 'REGISTERED'
  375. }
  376. };
  377. describe('#loadHosts', function () {
  378. beforeEach(function() {
  379. c.reopen({content: {hosts: hostsForLoadAndRender}});
  380. c.loadHosts();
  381. });
  382. it('Only REGISTERED hosts', function () {
  383. var loadedHosts = c.get('hosts');
  384. expect(loadedHosts.length).to.equal(2);
  385. });
  386. it('All hosts have progress 0', function () {
  387. var loadedHosts = c.get('hosts');
  388. expect(loadedHosts.everyProperty('progress', 0)).to.equal(true);
  389. });
  390. it('All host don\'t have logTasks', function () {
  391. var loadedHosts = c.get('hosts');
  392. expect(loadedHosts.everyProperty('logTasks.length', 0)).to.equal(true);
  393. });
  394. });
  395. describe('#isServicesStarted', function () {
  396. it('Should return false when server not started', function () {
  397. var polledData = Em.A([
  398. Em.Object.create({
  399. Tasks: Em.Object.create({
  400. status: 'PENDING'
  401. })
  402. }),
  403. Em.Object.create({
  404. Tasks: Em.Object.create({
  405. status: 'PENDING'
  406. })
  407. })
  408. ]);
  409. expect(c.isServicesStarted(polledData)).to.be.false;
  410. });
  411. it('Should return true when server started', function () {
  412. var polledData = Em.A([
  413. Em.Object.create({
  414. Tasks: Em.Object.create({
  415. status: 'NONE'
  416. })
  417. }),
  418. Em.Object.create({
  419. Tasks: Em.Object.create({
  420. status: 'NONE'
  421. })
  422. })
  423. ]);
  424. expect(c.isServicesStarted(polledData)).to.be.true;
  425. });
  426. it('Should return true when tasks completed', function () {
  427. var polledData = Em.A([
  428. Em.Object.create({
  429. Tasks: Em.Object.create({
  430. status: 'COMPLETED'
  431. })
  432. }),
  433. Em.Object.create({
  434. Tasks: Em.Object.create({
  435. status: 'COMPLETED'
  436. })
  437. })
  438. ]);
  439. expect(c.isServicesStarted(polledData)).to.be.true;
  440. });
  441. });
  442. describe('#setIsServicesInstalled', function () {
  443. Em.A([
  444. {
  445. m: 'Should return 100% completed',
  446. c: {
  447. status: 'failed',
  448. isPolling: true,
  449. hosts: Em.A([
  450. Em.Object.create({
  451. progress: 0
  452. })
  453. ])
  454. },
  455. polledData: Em.A([
  456. Em.Object.create({
  457. Tasks: Em.Object.create({
  458. status: 'NONE'
  459. })
  460. }),
  461. Em.Object.create({
  462. Tasks: Em.Object.create({
  463. status: 'NONE'
  464. })
  465. })
  466. ]),
  467. e: {
  468. progress: '100',
  469. isPolling: false
  470. }
  471. },
  472. {
  473. m: 'Should return 34% completed',
  474. c: {
  475. status: '',
  476. isPolling: true,
  477. hosts: Em.A([
  478. Em.Object.create({
  479. progress: 0
  480. })
  481. ]),
  482. content: Em.Object.create({
  483. controllerName: 'installerController'
  484. })
  485. },
  486. polledData: Em.A([
  487. Em.Object.create({
  488. Tasks: Em.Object.create({
  489. status: 'NONE'
  490. })
  491. }),
  492. Em.Object.create({
  493. Tasks: Em.Object.create({
  494. status: 'NONE'
  495. })
  496. })
  497. ]),
  498. e: {
  499. progress: '34',
  500. isPolling: true
  501. }
  502. }
  503. ]).forEach(function (test) {
  504. it(test.m, function () {
  505. c.setProperties(test.c);
  506. c.setIsServicesInstalled(test.polledData);
  507. expect(c.get('progress')).to.equal(test.e.progress);
  508. expect(c.get('isPolling')).to.be.equal(test.e.isPolling);
  509. });
  510. });
  511. describe('`skipComponentStartAfterInstall` is true', function () {
  512. var polledData = Em.A([
  513. Em.Object.create({
  514. Tasks: Em.Object.create({
  515. status: 'NONE'
  516. })
  517. }),
  518. Em.Object.create({
  519. Tasks: Em.Object.create({
  520. status: 'NONE'
  521. })
  522. })
  523. ]);
  524. var hosts = [
  525. Em.Object.create({status: '', message: '', progress: 0}),
  526. Em.Object.create({status: '', message: '', progress: 0}),
  527. Em.Object.create({status: '', message: '', progress: 0}),
  528. Em.Object.create({status: '', message: '', progress: 0})
  529. ];
  530. beforeEach(function () {
  531. sinon.stub(App, 'get').withArgs('supports.skipComponentStartAfterInstall').returns(true);
  532. sinon.stub(c, 'saveClusterStatus', Em.K);
  533. sinon.stub(c, 'saveInstalledHosts', Em.K);
  534. sinon.stub(c, 'changeParseHostInfo', Em.K);
  535. c.set('hosts', hosts);
  536. c.setIsServicesInstalled(polledData);
  537. });
  538. afterEach(function () {
  539. App.get.restore();
  540. c.saveClusterStatus.restore();
  541. c.saveInstalledHosts.restore();
  542. c.changeParseHostInfo.restore();
  543. });
  544. it('cluster status is valid', function () {
  545. var clusterStatus = c.saveClusterStatus.args[0][0];
  546. expect(clusterStatus.status).to.be.equal('START_SKIPPED');
  547. expect(clusterStatus.isCompleted).to.be.true;
  548. });
  549. it('each host status is `success`', function () {
  550. expect(c.get('hosts').everyProperty('status', 'success')).to.be.true;
  551. });
  552. it('each host progress is `100`', function () {
  553. expect(c.get('hosts').everyProperty('progress', '100')).to.be.true;
  554. });
  555. it('each host message is valid', function () {
  556. expect(c.get('hosts').everyProperty('message', Em.I18n.t('installer.step9.host.status.success'))).to.be.true;
  557. });
  558. });
  559. });
  560. describe('#launchStartServices', function () {
  561. beforeEach(function() {
  562. sinon.stub(App, 'get', function(k) {
  563. if (k === 'components.slaves') {
  564. return ["TASKTRACKER", "DATANODE",
  565. "JOURNALNODE", "ZKFC",
  566. "APP_TIMELINE_SERVER",
  567. "NODEMANAGER",
  568. "GANGLIA_MONITOR",
  569. "HBASE_REGIONSERVER",
  570. "SUPERVISOR",
  571. "FLUME_HANDLER"];
  572. }
  573. return true;
  574. });
  575. });
  576. afterEach(function() {
  577. App.get.restore();
  578. });
  579. var tests = [
  580. {
  581. expected: [],
  582. message: 'should return query',
  583. controllerName: 'addHostController',
  584. hosts: Em.A([
  585. Em.Object.create({
  586. name: 'h1'
  587. }),
  588. Em.Object.create({
  589. name: 'h2'
  590. })
  591. ])
  592. },
  593. {
  594. expected: [],
  595. message: 'should return server info',
  596. controllerName: 'addServiceController',
  597. services: Em.A([
  598. Em.Object.create({
  599. serviceName: 'OOZIE',
  600. isSelected: true,
  601. isInstalled: false
  602. }),
  603. Em.Object.create({
  604. serviceName: 'h2',
  605. isSelected: false,
  606. isInstalled: true
  607. })
  608. ])
  609. },
  610. {
  611. expected: [],
  612. message: 'should return default data',
  613. controllerName: 'addHostContro',
  614. hosts: Em.A([
  615. Em.Object.create({
  616. name: 'h1'
  617. }),
  618. Em.Object.create({
  619. name: 'h2'
  620. })
  621. ])
  622. }
  623. ];
  624. tests.forEach(function(test) {
  625. it(test.message, function () {
  626. var content = Em.Object.create({
  627. controllerName: test.controllerName,
  628. services: test.services
  629. });
  630. var wizardController = Em.Object.create({
  631. getDBProperty: function() {
  632. return test.hosts
  633. }
  634. });
  635. c.set('content', content);
  636. c.set('wizardController', wizardController);
  637. expect(c.launchStartServices(function(){})).to.be.true;
  638. });
  639. })
  640. });
  641. describe('#hostHasClientsOnly', function () {
  642. var tests = Em.A([
  643. {
  644. hosts: [
  645. Em.Object.create({
  646. hostName: 'host1',
  647. logTasks: [
  648. {Tasks: {role: 'HDFS_CLIENT'}},
  649. {Tasks: {role: 'DATANODE'}}
  650. ],
  651. status: 'old_status',
  652. progress: '10',
  653. e: {status: 'old_status', progress: '10'}
  654. }),
  655. Em.Object.create({
  656. hostName: 'host2',
  657. logTasks: [
  658. {Tasks: {role: 'HDFS_CLIENT'}}
  659. ],
  660. status: 'old_status',
  661. progress: '10',
  662. e: {status: 'success', progress: '100'}
  663. })
  664. ],
  665. jsonError: false
  666. },
  667. {
  668. hosts: [
  669. Em.Object.create({
  670. hostName: 'host1',
  671. logTasks: [
  672. {Tasks: {role: 'HDFS_CLIENT'}},
  673. {Tasks: {role: 'DATANODE'}}
  674. ],
  675. status: 'old_status',
  676. progress: '10',
  677. e: {status: 'success', progress: '100'}
  678. }),
  679. Em.Object.create({
  680. hostName: 'host2',
  681. logTasks: [
  682. {Tasks: {role: 'HDFS_CLIENT'}}
  683. ],
  684. status: 'old_status',
  685. progress: '10',
  686. e: {status: 'success', progress: '100'}
  687. })
  688. ],
  689. jsonError: true
  690. }
  691. ]);
  692. tests.forEach(function (test, index1) {
  693. test.hosts.forEach(function (host, index2) {
  694. it('#test ' + index1 + ' #host ' + index2, function () {
  695. c.reopen({hosts: test.hosts});
  696. c.hostHasClientsOnly(test.jsonError);
  697. expect(c.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  698. expect(c.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  699. });
  700. });
  701. });
  702. });
  703. describe('#onSuccessPerHost', function () {
  704. var tests = Em.A([
  705. {
  706. cluster: {status: 'INSTALLED'},
  707. host: Em.Object.create({status: 'pending'}),
  708. actions: [],
  709. e: {status: 'success'},
  710. m: 'No tasks for host'
  711. },
  712. {
  713. cluster: {status: 'INSTALLED'},
  714. host: Em.Object.create({status: 'info'}),
  715. actions: [
  716. {Tasks: {status: 'COMPLETED'}},
  717. {Tasks: {status: 'COMPLETED'}}
  718. ],
  719. e: {status: 'success'},
  720. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  721. },
  722. {
  723. cluster: {status: 'FAILED'},
  724. host: Em.Object.create({status: 'info'}),
  725. actions: [
  726. {Tasks: {status: 'COMPLETED'}},
  727. {Tasks: {status: 'COMPLETED'}}
  728. ],
  729. e: {status: 'info'},
  730. m: 'All Tasks COMPLETED and cluster status FAILED'
  731. },
  732. {
  733. cluster: {status: 'INSTALLED'},
  734. host: Em.Object.create({status: 'info'}),
  735. actions: [
  736. {Tasks: {status: 'FAILED'}},
  737. {Tasks: {status: 'COMPLETED'}}
  738. ],
  739. e: {status: 'info'},
  740. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  741. },
  742. {
  743. cluster: {status: 'FAILED'},
  744. host: Em.Object.create({status: 'info'}),
  745. actions: [
  746. {Tasks: {status: 'FAILED'}},
  747. {Tasks: {status: 'COMPLETED'}}
  748. ],
  749. e: {status: 'info'},
  750. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  751. }
  752. ]);
  753. tests.forEach(function (test) {
  754. it(test.m, function () {
  755. c.reopen({content: {cluster: {status: test.cluster.status}}});
  756. c.onSuccessPerHost(test.actions, test.host);
  757. expect(test.host.status).to.equal(test.e.status);
  758. });
  759. });
  760. });
  761. describe('#onErrorPerHost', function () {
  762. var tests = Em.A([
  763. {
  764. cluster: {status: 'INSTALLED'},
  765. host: Em.Object.create({status: 'pending'}),
  766. actions: [],
  767. e: {status: 'pending'},
  768. isMasterFailed: false,
  769. m: 'No tasks for host'
  770. },
  771. {
  772. cluster: {status: 'INSTALLED'},
  773. host: Em.Object.create({status: 'info'}),
  774. actions: [
  775. {Tasks: {status: 'FAILED'}},
  776. {Tasks: {status: 'COMPLETED'}}
  777. ],
  778. e: {status: 'warning'},
  779. isMasterFailed: false,
  780. m: 'One Task FAILED and cluster status INSTALLED'
  781. },
  782. {
  783. cluster: {status: 'INSTALLED'},
  784. host: Em.Object.create({status: 'info'}),
  785. actions: [
  786. {Tasks: {status: 'ABORTED'}},
  787. {Tasks: {status: 'COMPLETED'}}
  788. ],
  789. e: {status: 'warning'},
  790. isMasterFailed: false,
  791. m: 'One Task ABORTED and cluster status INSTALLED'
  792. },
  793. {
  794. cluster: {status: 'INSTALLED'},
  795. host: Em.Object.create({status: 'info'}),
  796. actions: [
  797. {Tasks: {status: 'TIMEDOUT'}},
  798. {Tasks: {status: 'COMPLETED'}}
  799. ],
  800. e: {status: 'warning'},
  801. isMasterFailed: false,
  802. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  803. },
  804. {
  805. cluster: {status: 'PENDING'},
  806. host: Em.Object.create({status: 'info'}),
  807. actions: [
  808. {Tasks: {status: 'FAILED'}},
  809. {Tasks: {status: 'COMPLETED'}}
  810. ],
  811. e: {status: 'failed'},
  812. isMasterFailed: true,
  813. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  814. },
  815. {
  816. cluster: {status: 'PENDING'},
  817. host: Em.Object.create({status: 'info'}),
  818. actions: [
  819. {Tasks: {status: 'COMPLETED'}},
  820. {Tasks: {status: 'COMPLETED'}}
  821. ],
  822. e: {status: 'info'},
  823. isMasterFailed: false,
  824. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  825. }
  826. ]);
  827. tests.forEach(function (test) {
  828. it(test.m, function () {
  829. c.reopen({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  830. return test.isMasterFailed;
  831. }});
  832. c.onErrorPerHost(test.actions, test.host);
  833. expect(test.host.status).to.equal(test.e.status);
  834. });
  835. });
  836. });
  837. describe('#isMasterFailed', function () {
  838. beforeEach(function() {
  839. sinon.stub(App, 'get', function(k) {
  840. if (k === 'components.slaves') {
  841. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  842. }
  843. return Em.get(App, k);
  844. });
  845. });
  846. afterEach(function() {
  847. App.get.restore();
  848. });
  849. var tests = Em.A([
  850. {
  851. actions: [
  852. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  853. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  854. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  855. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  856. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  857. ],
  858. e: false,
  859. m: 'No one Master is failed'
  860. },
  861. {
  862. actions: [
  863. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  864. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  865. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  866. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  867. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  868. ],
  869. e: true,
  870. m: 'One Master is failed'
  871. },
  872. {
  873. actions: [
  874. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  875. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  876. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  877. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  878. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  879. ],
  880. e: false,
  881. m: 'one Master is failed but command is not install'
  882. }
  883. ]);
  884. tests.forEach(function (test) {
  885. it(test.m, function () {
  886. expect(c.isMasterFailed(test.actions)).to.equal(test.e);
  887. });
  888. });
  889. });
  890. describe('#onInProgressPerHost', function () {
  891. var tests = Em.A([
  892. {
  893. host: Em.Object.create({message: 'default_message'}),
  894. actions: [
  895. {Tasks: {status: 'COMPLETED'}},
  896. {Tasks: {status: 'COMPLETED'}}
  897. ],
  898. e: {message: 'default_message', b: true},
  899. m: 'All Tasks COMPLETED'
  900. },
  901. {
  902. host: Em.Object.create({message: 'default_message'}),
  903. actions: [
  904. {Tasks: {status: 'IN_PROGRESS'}},
  905. {Tasks: {status: 'COMPLETED'}}
  906. ],
  907. e: {message: 'default_message', b: false},
  908. m: 'One Task IN_PROGRESS'
  909. },
  910. {
  911. host: Em.Object.create({message: 'default_message'}),
  912. actions: [
  913. {Tasks: {status: 'QUEUED'}},
  914. {Tasks: {status: 'COMPLETED'}}
  915. ],
  916. e: {message: 'default_message', b: false},
  917. m: 'One Task QUEUED'
  918. },
  919. {
  920. host: Em.Object.create({message: 'default_message'}),
  921. actions: [
  922. {Tasks: {status: 'PENDING'}},
  923. {Tasks: {status: 'COMPLETED'}}
  924. ],
  925. e: {message: 'default_message', b: false},
  926. m: 'One Task PENDING'
  927. }
  928. ]);
  929. tests.forEach(function (test) {
  930. it(test.m, function () {
  931. c.onInProgressPerHost(test.actions, test.host);
  932. if (test.e.b) {
  933. expect(test.host.message).to.be.equal(test.e.message);
  934. }
  935. else {
  936. expect(test.host.message).to.be.not.equal(test.e.message);
  937. }
  938. });
  939. });
  940. });
  941. describe('#progressPerHost', function () {
  942. var tests = Em.A([
  943. {
  944. cluster: {status: 'PENDING'},
  945. host: Em.Object.create({progress: 0}),
  946. actions: {
  947. 'COMPLETED': 2,
  948. 'QUEUED': 2,
  949. 'IN_PROGRESS': 1
  950. },
  951. e: {progress: 17},
  952. s: false,
  953. m: 'All types of status available. cluster status PENDING'
  954. },
  955. {
  956. cluster: {status: 'PENDING'},
  957. host: Em.Object.create({progress: 0}),
  958. actions: {},
  959. e: {progress: 33},
  960. s: false,
  961. m: 'No tasks available. cluster status PENDING'
  962. },
  963. {
  964. cluster: {status: 'PENDING'},
  965. host: Em.Object.create({progress: 0}),
  966. actions: {},
  967. e: {progress: 100},
  968. s: true,
  969. m: 'No tasks available. cluster status PENDING. skipComponentStartAfterInstall is true.'
  970. },
  971. {
  972. cluster: {status: 'INSTALLED'},
  973. host: Em.Object.create({progress: 0}),
  974. actions: {},
  975. e: {progress: 100},
  976. m: 'No tasks available. cluster status INSTALLED'
  977. },
  978. {
  979. cluster: {status: 'INSTALLED'},
  980. host: Em.Object.create({progress: 0}),
  981. actions: {
  982. 'COMPLETED': 2,
  983. 'QUEUED': 2,
  984. 'IN_PROGRESS': 1
  985. },
  986. e: {progress: 66},
  987. s: false,
  988. m: 'All types of status available. cluster status INSTALLED'
  989. },
  990. {
  991. cluster: {status: 'FAILED'},
  992. host: Em.Object.create({progress: 0}),
  993. actions: {},
  994. e: {progress: 100},
  995. s: false,
  996. m: 'Cluster status is not PENDING or INSTALLED'
  997. },
  998. {
  999. cluster: {status: 'INSTALLED'},
  1000. host: Em.Object.create({progress: 0}),
  1001. actions: {
  1002. 'COMPLETED': 150,
  1003. 'QUEUED': 0,
  1004. 'IN_PROGRESS': 1
  1005. },
  1006. e: {progress: 99},
  1007. s: false,
  1008. m: '150 tasks on host'
  1009. },
  1010. {
  1011. cluster: {status: 'INSTALLED'},
  1012. host: Em.Object.create({progress: 0}),
  1013. actions: {
  1014. 'COMPLETED': 498,
  1015. 'QUEUED': 1,
  1016. 'IN_PROGRESS': 1
  1017. },
  1018. e: {progress: 99},
  1019. s: false,
  1020. m: '500 tasks on host'
  1021. },
  1022. {
  1023. cluster: {status: 'INSTALLED'},
  1024. host: Em.Object.create({progress: 0}),
  1025. actions: {
  1026. 'COMPLETED': 150,
  1027. 'QUEUED': 0,
  1028. 'IN_PROGRESS': 0
  1029. },
  1030. e: {progress: 100},
  1031. s: false,
  1032. m: '100 tasks, 100 completed'
  1033. },
  1034. {
  1035. cluster: {status: 'INSTALLED'},
  1036. host: Em.Object.create({progress: 0}),
  1037. actions: {
  1038. 'COMPLETED': 1,
  1039. 'QUEUED': 0,
  1040. 'IN_PROGRESS': 0
  1041. },
  1042. e: {progress: 100},
  1043. s: false,
  1044. m: '1 task, 1 completed'
  1045. }
  1046. ]);
  1047. tests.forEach(function (test) {
  1048. describe(test.m, function () {
  1049. beforeEach(function () {
  1050. var actions = [];
  1051. for (var prop in test.actions) {
  1052. if (test.actions.hasOwnProperty(prop) && test.actions[prop]) {
  1053. for (var i = 0; i < test.actions[prop]; i++) {
  1054. actions.push({Tasks: {status: prop}});
  1055. }
  1056. }
  1057. }
  1058. c.reopen({content: {cluster: {status: test.cluster.status}}});
  1059. App.set('supports.skipComponentStartAfterInstall', test.s);
  1060. this.progress = c.progressPerHost(actions, test.host);
  1061. });
  1062. it('progress is ' + test.e.progress, function () {
  1063. expect(this.progress).to.equal(test.e.progress);
  1064. });
  1065. it('host progress is ' + test.e.progress.toString(), function () {
  1066. expect(test.host.progress).to.equal(test.e.progress.toString());
  1067. });
  1068. });
  1069. });
  1070. });
  1071. describe('#clearStep', function () {
  1072. beforeEach(function () {
  1073. c.reopen({hosts: [{},{},{}]});
  1074. c.clearStep();
  1075. });
  1076. it('hosts are empty', function () {
  1077. expect(c.get('hosts.length')).to.equal(0);
  1078. });
  1079. it('status is `info`', function () {
  1080. expect(c.get('status')).to.equal('info');
  1081. });
  1082. it('progress is 0', function () {
  1083. expect(c.get('progress')).to.equal('0');
  1084. });
  1085. it('numPolls is 1', function () {
  1086. expect(c.get('numPolls')).to.equal(1);
  1087. });
  1088. });
  1089. describe('#replacePolledData', function () {
  1090. it('replacing polled data', function () {
  1091. c.reopen({polledData: [{},{},{}]});
  1092. var newPolledData = [{}];
  1093. c.replacePolledData(newPolledData);
  1094. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  1095. });
  1096. });
  1097. describe('#isSuccess', function () {
  1098. var tests = Em.A([
  1099. {
  1100. polledData: [
  1101. {Tasks: {status: 'COMPLETED'}},
  1102. {Tasks: {status: 'COMPLETED'}}
  1103. ],
  1104. e: true,
  1105. m: 'All tasks are COMPLETED'
  1106. },
  1107. {
  1108. polledData: [
  1109. {Tasks: {status: 'COMPLETED'}},
  1110. {Tasks: {status: 'FAILED'}}
  1111. ],
  1112. e: false,
  1113. m: 'Not all tasks are COMPLETED'
  1114. }
  1115. ]);
  1116. tests.forEach(function (test) {
  1117. it(test.m, function () {
  1118. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  1119. });
  1120. });
  1121. });
  1122. describe('#isStepFailed', function () {
  1123. beforeEach(function() {
  1124. sinon.stub(App, 'get', function(k) {
  1125. if (k === 'components.slaves') {
  1126. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  1127. }
  1128. return Em.get(App, k);
  1129. });
  1130. });
  1131. afterEach(function() {
  1132. App.get.restore();
  1133. });
  1134. var tests = Em.A([
  1135. {
  1136. polledData: [
  1137. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1138. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  1139. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1140. ],
  1141. e: true,
  1142. m: 'GANGLIA_MONITOR 2/3 failed'
  1143. },
  1144. {
  1145. polledData: [
  1146. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1147. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  1148. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1149. ],
  1150. e: false,
  1151. m: 'GANGLIA_MONITOR 1/3 failed'
  1152. },
  1153. {
  1154. polledData: [
  1155. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1156. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  1157. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1158. ],
  1159. e: true,
  1160. m: 'HBASE_REGIONSERVER 2/3 failed'
  1161. },
  1162. {
  1163. polledData: [
  1164. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1165. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  1166. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1167. ],
  1168. e: false,
  1169. m: 'HBASE_REGIONSERVER 1/3 failed'
  1170. },
  1171. {
  1172. polledData: [
  1173. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1174. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  1175. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1176. ],
  1177. e: true,
  1178. m: 'TASKTRACKER 2/3 failed'
  1179. },
  1180. {
  1181. polledData: [
  1182. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1183. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  1184. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1185. ],
  1186. e: false,
  1187. m: 'TASKTRACKER 1/3 failed'
  1188. },
  1189. {
  1190. polledData: [
  1191. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1192. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  1193. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1194. ],
  1195. e: true,
  1196. m: 'DATANODE 2/3 failed'
  1197. },
  1198. {
  1199. polledData: [
  1200. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1201. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1202. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1203. ],
  1204. e: false,
  1205. m: 'DATANODE 1/3 failed'
  1206. },
  1207. {
  1208. polledData: [
  1209. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  1210. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1211. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1212. ],
  1213. e: true,
  1214. m: 'NAMENODE failed'
  1215. },
  1216. {
  1217. polledData: [
  1218. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  1219. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1220. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1221. ],
  1222. e: false,
  1223. m: 'Nothing failed failed'
  1224. }
  1225. ]);
  1226. tests.forEach(function (test) {
  1227. it(test.m, function () {
  1228. c.reopen({polledData: test.polledData});
  1229. expect(c.isStepFailed()).to.equal(test.e);
  1230. });
  1231. });
  1232. });
  1233. describe('#setLogTasksStatePerHost', function () {
  1234. var tests = Em.A([
  1235. {
  1236. tasksPerHost: [
  1237. {Tasks: {id: 1, status: 'COMPLETED'}},
  1238. {Tasks: {id: 2, status: 'COMPLETED'}}
  1239. ],
  1240. tasks: [],
  1241. e: {m: 'COMPLETED', l: 2},
  1242. m: 'host didn\'t have tasks and got 2 new'
  1243. },
  1244. {
  1245. tasksPerHost: [
  1246. {Tasks: {id: 1, status: 'COMPLETED'}},
  1247. {Tasks: {id: 2, status: 'COMPLETED'}}
  1248. ],
  1249. tasks: [
  1250. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1251. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1252. ],
  1253. e: {m: 'COMPLETED', l: 2},
  1254. m: 'host had 2 tasks and got both updated'
  1255. },
  1256. {
  1257. tasksPerHost: [],
  1258. tasks: [
  1259. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1260. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1261. ],
  1262. e: {m: 'IN_PROGRESS', l: 2},
  1263. m: 'host had 2 tasks and didn\'t get updates'
  1264. },
  1265. {
  1266. tasksPerHost: [
  1267. {Tasks: {id: 1, status: 'COMPLETED'}},
  1268. {Tasks: {id: 2, status: 'COMPLETED'}},
  1269. {Tasks: {id: 3, status: 'COMPLETED'}}
  1270. ],
  1271. tasks: [
  1272. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1273. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1274. ],
  1275. e: {m: 'COMPLETED', l: 3},
  1276. m: 'host had 2 tasks and got both updated and 1 new'
  1277. }
  1278. ]);
  1279. tests.forEach(function (test) {
  1280. it(test.m, function () {
  1281. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  1282. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  1283. var host = c.get('hosts')[0];
  1284. expect(host.get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  1285. expect(host.get('logTasks.length')).to.equal(test.e.l);
  1286. });
  1287. });
  1288. });
  1289. // On completion of Start all services error callback function,
  1290. // Cluster Status should be INSTALL FAILED
  1291. // All progress bar on the screen should be finished (100%) with blue color.
  1292. // Retry button should be enabled, next button should be disabled
  1293. describe('#launchStartServicesErrorCallback', function () {
  1294. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1295. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1296. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1297. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1298. expect(c.get('progress')).to.equal('100');
  1299. expect(c.get('status')).to.equal('failed');
  1300. });
  1301. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1302. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1303. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1304. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1305. expect(c.get('hosts').everyProperty('progress', '100')).to.be.true;
  1306. expect(c.get('hosts').everyProperty('status', 'info')).to.be.true;
  1307. });
  1308. it('Next button should be disabled', function () {
  1309. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1310. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1311. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1312. expect(c.get('isSubmitDisabled')).to.equal(true);
  1313. });
  1314. });
  1315. describe('#submit', function () {
  1316. beforeEach(function () {
  1317. sinon.stub(App.router, 'send', Em.K);
  1318. });
  1319. afterEach(function () {
  1320. App.router.send.restore();
  1321. });
  1322. it('should call App.router.send', function () {
  1323. c.submit();
  1324. expect(App.router.send.calledWith('next')).to.equal(true);
  1325. });
  1326. });
  1327. describe('#back', function () {
  1328. beforeEach(function () {
  1329. sinon.stub(App.router, 'send', Em.K);
  1330. });
  1331. afterEach(function () {
  1332. App.router.send.restore();
  1333. });
  1334. it('should call App.router.send', function () {
  1335. c.reopen({isSubmitDisabled: false});
  1336. c.back();
  1337. expect(App.router.send.calledWith('back')).to.equal(true);
  1338. });
  1339. it('shouldn\'t call App.router.send', function () {
  1340. c.reopen({isSubmitDisabled: true});
  1341. c.back();
  1342. expect(App.router.send.called).to.equal(false);
  1343. });
  1344. });
  1345. describe('#loadStep', function () {
  1346. beforeEach(function () {
  1347. sinon.stub(c, 'clearStep', Em.K);
  1348. sinon.stub(c, 'loadHosts', Em.K);
  1349. });
  1350. afterEach(function () {
  1351. c.clearStep.restore();
  1352. c.loadHosts.restore();
  1353. });
  1354. it('should call clearStep', function () {
  1355. c.loadStep();
  1356. expect(c.clearStep.calledOnce).to.equal(true);
  1357. });
  1358. it('should call loadHosts', function () {
  1359. c.loadStep();
  1360. expect(c.loadHosts.calledOnce).to.equal(true);
  1361. });
  1362. });
  1363. describe('#startPolling', function () {
  1364. beforeEach(function () {
  1365. sinon.stub(c, 'reloadErrorCallback', Em.K);
  1366. sinon.stub(c, 'doPolling', Em.K);
  1367. });
  1368. afterEach(function () {
  1369. c.reloadErrorCallback.restore();
  1370. c.doPolling.restore();
  1371. });
  1372. it('should set isSubmitDisabled to true', function () {
  1373. c.set('isSubmitDisabled', false);
  1374. c.startPolling();
  1375. expect(c.get('isSubmitDisabled')).to.equal(true);
  1376. });
  1377. it('should call doPolling', function () {
  1378. c.startPolling();
  1379. expect(c.doPolling.calledOnce).to.equal(true);
  1380. });
  1381. });
  1382. describe('#loadLogData', function () {
  1383. beforeEach(function () {
  1384. obj.reopen({
  1385. cluster: {oldRequestsId: [1,2,3]},
  1386. getDBProperty: function (name) {
  1387. return this.get(name);
  1388. }
  1389. });
  1390. c.reopen({wizardController: obj});
  1391. sinon.stub(c, 'getLogsByRequest', Em.K);
  1392. });
  1393. afterEach(function () {
  1394. c.getLogsByRequest.restore();
  1395. });
  1396. it('should call getLogsByRequest 1 time with 3', function () {
  1397. c.loadLogData(true);
  1398. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  1399. });
  1400. });
  1401. describe('#loadCurrentTaskLog', function () {
  1402. beforeEach(function () {
  1403. sinon.stub(c, 'loadLogData', Em.K);
  1404. c.set('wizardController', Em.Object.create({
  1405. getDBProperty: Em.K
  1406. }));
  1407. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1408. });
  1409. afterEach(function () {
  1410. c.loadLogData.restore();
  1411. c.togglePreviousSteps.restore();
  1412. });
  1413. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1414. c.set('currentOpenTaskId', null);
  1415. c.loadCurrentTaskLog();
  1416. var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
  1417. expect(args).not.exists;
  1418. });
  1419. it('should call App.ajax.send with provided data', function () {
  1420. c.set('currentOpenTaskId', 1);
  1421. c.set('currentOpenTaskRequestId', 2);
  1422. c.set('content', {cluster: {name: 3}});
  1423. c.loadCurrentTaskLog();
  1424. var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
  1425. expect(args[0]).exists;
  1426. expect(args[0].data).to.be.eql({taskId: 1, requestId: 2, clusterName: 3});
  1427. });
  1428. });
  1429. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1430. beforeEach(function() {
  1431. sinon.stub(c, 'getLogsByRequest', Em.K);
  1432. sinon.stub(c, 'loadLogData', Em.K);
  1433. });
  1434. afterEach(function() {
  1435. c.getLogsByRequest.restore();
  1436. c.loadLogData.restore();
  1437. });
  1438. it('should increment logTasksChangesCounter', function () {
  1439. c.set('logTasksChangesCounter', 0);
  1440. c.loadCurrentTaskLogSuccessCallback();
  1441. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1442. });
  1443. it('should update stdout, stderr', function () {
  1444. c.set('currentOpenTaskId', 1);
  1445. c.reopen({
  1446. hosts: [
  1447. Em.Object.create({
  1448. name: 'h1',
  1449. logTasks: [
  1450. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1451. ]
  1452. })
  1453. ]
  1454. });
  1455. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1456. c.loadCurrentTaskLogSuccessCallback(data);
  1457. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1458. expect(t.stdout).to.equal('stdout');
  1459. expect(t.stderr).to.equal('stderr');
  1460. });
  1461. it('shouldn\'t update stdout, stderr', function () {
  1462. c.set('currentOpenTaskId', 1);
  1463. c.reopen({
  1464. hosts: [
  1465. Em.Object.create({
  1466. name: 'h1',
  1467. logTasks: [
  1468. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1469. ]
  1470. })
  1471. ]
  1472. });
  1473. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1474. c.loadCurrentTaskLogSuccessCallback(data);
  1475. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1476. expect(t.stdout).to.equal('');
  1477. expect(t.stderr).to.equal('');
  1478. });
  1479. it('shouldn\'t update stdout, stderr (2)', function () {
  1480. c.set('currentOpenTaskId', 1);
  1481. c.reopen({
  1482. hosts: [
  1483. Em.Object.create({
  1484. name: 'h2',
  1485. logTasks: [
  1486. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1487. ]
  1488. })
  1489. ]
  1490. });
  1491. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1492. c.loadCurrentTaskLogSuccessCallback(data);
  1493. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1494. expect(t.stdout).to.equal('');
  1495. expect(t.stderr).to.equal('');
  1496. });
  1497. });
  1498. describe('#loadCurrentTaskLogErrorCallback', function () {
  1499. it('should set currentOpenTaskId to 0', function () {
  1500. c.set('currentOpenTaskId', 123);
  1501. c.loadCurrentTaskLogErrorCallback();
  1502. expect(c.get('currentOpenTaskId')).to.equal(0);
  1503. });
  1504. });
  1505. describe('#doPolling', function () {
  1506. beforeEach(function () {
  1507. sinon.stub(c, 'getLogsByRequest', Em.K);
  1508. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1509. });
  1510. afterEach(function () {
  1511. c.getLogsByRequest.restore();
  1512. c.togglePreviousSteps.restore();
  1513. });
  1514. it('should call getLogsByRequest', function () {
  1515. c.set('content', {cluster: {requestId: 1}});
  1516. c.doPolling();
  1517. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1518. });
  1519. });
  1520. describe('#isAllComponentsInstalledErrorCallback', function () {
  1521. beforeEach(function () {
  1522. sinon.stub(c, 'saveClusterStatus', Em.K);
  1523. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1524. });
  1525. afterEach(function () {
  1526. c.saveClusterStatus.restore();
  1527. c.togglePreviousSteps.restore();
  1528. });
  1529. it('should call saveClusterStatus', function () {
  1530. c.isAllComponentsInstalledErrorCallback({});
  1531. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1532. });
  1533. });
  1534. describe('#navigateStep', function () {
  1535. beforeEach(function () {
  1536. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1537. sinon.stub(c, 'loadStep', Em.K);
  1538. sinon.stub(c, 'loadLogData', Em.K);
  1539. sinon.stub(c, 'startPolling', Em.K);
  1540. });
  1541. afterEach(function () {
  1542. c.togglePreviousSteps.restore();
  1543. c.loadStep.restore();
  1544. c.loadLogData.restore();
  1545. c.startPolling.restore();
  1546. });
  1547. it('isCompleted = true, requestId = 1', function () {
  1548. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1549. c.navigateStep();
  1550. expect(c.loadStep.calledOnce).to.equal(true);
  1551. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1552. expect(c.get('progress')).to.equal('100');
  1553. });
  1554. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1555. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1556. c.navigateStep();
  1557. expect(c.loadStep.calledOnce).to.equal(true);
  1558. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1559. });
  1560. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1561. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1562. c.navigateStep();
  1563. expect(c.loadStep.calledOnce).to.equal(true);
  1564. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1565. });
  1566. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1567. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1568. c.navigateStep();
  1569. expect(c.loadStep.calledOnce).to.equal(true);
  1570. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1571. });
  1572. });
  1573. describe('#launchStartServicesSuccessCallback', function () {
  1574. beforeEach(function () {
  1575. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1576. return $.ajax();
  1577. });
  1578. sinon.stub(c, 'saveClusterStatus', Em.K);
  1579. sinon.stub(c, 'doPolling', Em.K);
  1580. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1581. });
  1582. afterEach(function () {
  1583. c.saveClusterStatus.restore();
  1584. c.doPolling.restore();
  1585. c.hostHasClientsOnly.restore();
  1586. App.clusterStatus.setClusterStatus.restore();
  1587. });
  1588. it('should call doPolling if some data were received', function () {
  1589. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1590. expect(c.doPolling.calledOnce).to.equal(true);
  1591. });
  1592. Em.A([
  1593. {
  1594. m: 'Launch start service after install services completed',
  1595. jsonData: {Requests: {id: 2}},
  1596. e: {
  1597. hostHasClientsOnly: false,
  1598. clusterStatus: {
  1599. status: 'INSTALLED',
  1600. requestId: 2,
  1601. isStartError: false,
  1602. isCompleted: false
  1603. }
  1604. }
  1605. },
  1606. {
  1607. jsonData: null,
  1608. e: {
  1609. hostHasClientsOnly: true,
  1610. clusterStatus: {
  1611. status: 'STARTED',
  1612. isStartError: false,
  1613. isCompleted: true
  1614. },
  1615. status: 'success',
  1616. progress: '100'
  1617. }
  1618. }
  1619. ]).forEach(function (test) {
  1620. describe(test.m, function () {
  1621. beforeEach(function () {
  1622. c.launchStartServicesSuccessCallback(test.jsonData);
  1623. });
  1624. it('hostHasClientsOnly is called with valid arguments', function () {
  1625. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1626. });
  1627. it('saveClusterStatus is called with valid arguments', function () {
  1628. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1629. });
  1630. if (test.e.status) {
  1631. it('status is valid', function () {
  1632. expect(c.get('status')).to.equal(test.e.status);
  1633. });
  1634. }
  1635. if (test.e.progress) {
  1636. it('progress is valid', function () {
  1637. expect(c.get('progress')).to.equal(test.e.progress);
  1638. });
  1639. }
  1640. });
  1641. });
  1642. });
  1643. describe('#isAllComponentsInstalledSuccessCallback', function () {
  1644. var hosts = [
  1645. Em.Object.create({name: 'h1', status: '', message: '', progress: ''}),
  1646. Em.Object.create({name: 'h2', status: '', message: '', progress: ''})
  1647. ];
  1648. var jsonData = {
  1649. items: [
  1650. {
  1651. Hosts: {
  1652. host_state: 'HEARTBEAT_LOST',
  1653. host_name: 'h1'
  1654. },
  1655. host_components: [
  1656. {
  1657. HostRoles: {
  1658. component_name: 'c1'
  1659. }
  1660. },
  1661. {
  1662. HostRoles: {
  1663. component_name: 'c2'
  1664. }
  1665. }
  1666. ]
  1667. },
  1668. {
  1669. Hosts: {
  1670. host_state: 'HEARTBEAT_LOST',
  1671. host_name: 'h2'
  1672. },
  1673. host_components: [
  1674. {
  1675. HostRoles: {
  1676. component_name: 'c3'
  1677. }
  1678. },
  1679. {
  1680. HostRoles: {
  1681. component_name: 'c4'
  1682. }
  1683. }
  1684. ]
  1685. }
  1686. ]
  1687. };
  1688. beforeEach(function () {
  1689. sinon.stub(c, 'changeParseHostInfo', Em.K);
  1690. sinon.stub(c, 'launchStartServices', Em.K);
  1691. sinon.stub(c, 'saveClusterStatus', Em.K);
  1692. c.set('hosts', hosts);
  1693. c.set('content', Em.Object.create({
  1694. slaveComponentHosts: [
  1695. {hosts: [{isInstalled: true, hostName: 'h1'}]},
  1696. {hosts: [{isInstalled: false, hostName: 'h2'}]}
  1697. ],
  1698. masterComponentHosts: []
  1699. }));
  1700. c.isAllComponentsInstalledSuccessCallback(jsonData);
  1701. this.clusterStatus = c.saveClusterStatus.args[0][0];
  1702. });
  1703. afterEach(function () {
  1704. c.changeParseHostInfo.restore();
  1705. c.launchStartServices.restore();
  1706. c.saveClusterStatus.restore();
  1707. });
  1708. it('cluster status / status', function () {
  1709. expect(this.clusterStatus.status).to.be.equal('INSTALL FAILED');
  1710. });
  1711. it('cluster status / isStartError', function () {
  1712. expect(this.clusterStatus.isStartError).to.be.true;
  1713. });
  1714. it('cluster status / isCompleted', function () {
  1715. expect(this.clusterStatus.isCompleted).to.be.false;
  1716. });
  1717. it('each host progress is 100', function () {
  1718. expect(c.get('hosts').everyProperty('progress', '100')).to.be.true;
  1719. });
  1720. it('each host status is `heartbeat_lost`', function () {
  1721. expect(c.get('hosts').everyProperty('status', 'heartbeat_lost')).to.be.true;
  1722. });
  1723. it('overall progress is 100', function () {
  1724. expect(c.get('progress')).to.be.equal('100');
  1725. });
  1726. });
  1727. describe('#loadDoServiceChecksFlagSuccessCallback', function () {
  1728. var data = {
  1729. RootServiceComponents: {
  1730. properties: {
  1731. 'skip.service.checks': 'true'
  1732. }
  1733. }
  1734. };
  1735. it('skipServiceChecks should be true', function () {
  1736. c.loadDoServiceChecksFlagSuccessCallback(data);
  1737. expect(c.get('skipServiceChecks')).to.be.true;
  1738. });
  1739. it('skipServiceChecks should be false', function () {
  1740. data.RootServiceComponents.properties['skip.service.checks'] = 'false';
  1741. c.loadDoServiceChecksFlagSuccessCallback(data);
  1742. expect(c.get('skipServiceChecks')).to.be.false;
  1743. });
  1744. });
  1745. describe('#isNextButtonDisabled', function () {
  1746. var cases = [
  1747. {
  1748. nextBtnClickInProgress: true,
  1749. isSubmitDisabled: true,
  1750. isNextButtonDisabled: true,
  1751. description: 'button clicked, submit disabled',
  1752. title: 'next button disabled'
  1753. },
  1754. {
  1755. nextBtnClickInProgress: true,
  1756. isSubmitDisabled: false,
  1757. isNextButtonDisabled: true,
  1758. description: 'button clicked, submit not disabled',
  1759. title: 'next button disabled'
  1760. },
  1761. {
  1762. nextBtnClickInProgress: false,
  1763. isSubmitDisabled: true,
  1764. isNextButtonDisabled: true,
  1765. description: 'no button clicked, submit disabled',
  1766. title: 'next button disabled'
  1767. },
  1768. {
  1769. nextBtnClickInProgress: false,
  1770. isSubmitDisabled: false,
  1771. isNextButtonDisabled: false,
  1772. description: 'no button clicked, submit not disabled',
  1773. title: 'next button enabled'
  1774. }
  1775. ];
  1776. cases.forEach(function (item) {
  1777. describe(item.description, function () {
  1778. beforeEach(function () {
  1779. c.reopen({
  1780. isSubmitDisabled: item.isSubmitDisabled
  1781. });
  1782. sinon.stub(App, 'get').withArgs('router.nextBtnClickInProgress').returns(item.nextBtnClickInProgress);
  1783. c.propertyDidChange('isSubmitDisabled');
  1784. c.propertyDidChange('App.router.nextBtnClickInProgress');
  1785. });
  1786. afterEach(function () {
  1787. App.get.restore();
  1788. });
  1789. it(item.title, function () {
  1790. expect(c.get('isNextButtonDisabled')).to.equal(item.isNextButtonDisabled);
  1791. });
  1792. });
  1793. });
  1794. });
  1795. });