step9_test.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916
  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. text: '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. text: '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. jsonData: {Requests: {id: 2}},
  1595. e: {
  1596. hostHasClientsOnly: false,
  1597. clusterStatus: {
  1598. status: 'INSTALLED',
  1599. requestId: 2,
  1600. isStartError: false,
  1601. isCompleted: false
  1602. }
  1603. }
  1604. },
  1605. {
  1606. jsonData: null,
  1607. e: {
  1608. hostHasClientsOnly: true,
  1609. clusterStatus: {
  1610. status: 'STARTED',
  1611. isStartError: false,
  1612. isCompleted: true
  1613. },
  1614. status: 'success',
  1615. progress: '100'
  1616. }
  1617. }
  1618. ]).forEach(function (test) {
  1619. describe(test.m, function () {
  1620. beforeEach(function () {
  1621. c.launchStartServicesSuccessCallback(test.jsonData);
  1622. });
  1623. it('hostHasClientsOnly is called with valid arguments', function () {
  1624. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1625. });
  1626. it('saveClusterStatus is called with valid arguments', function () {
  1627. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1628. });
  1629. if (test.e.status) {
  1630. it('status is valid', function () {
  1631. expect(c.get('status')).to.equal(test.e.status);
  1632. });
  1633. }
  1634. if (test.e.progress) {
  1635. it('progress is valid', function () {
  1636. expect(c.get('progress')).to.equal(test.e.progress);
  1637. });
  1638. }
  1639. });
  1640. });
  1641. });
  1642. describe('#isAllComponentsInstalledSuccessCallback', function () {
  1643. var hosts = [
  1644. Em.Object.create({name: 'h1', status: '', message: '', progress: ''}),
  1645. Em.Object.create({name: 'h2', status: '', message: '', progress: ''})
  1646. ];
  1647. var jsonData = {
  1648. items: [
  1649. {
  1650. Hosts: {
  1651. host_state: 'HEARTBEAT_LOST',
  1652. host_name: 'h1'
  1653. },
  1654. host_components: [
  1655. {
  1656. HostRoles: {
  1657. component_name: 'c1'
  1658. }
  1659. },
  1660. {
  1661. HostRoles: {
  1662. component_name: 'c2'
  1663. }
  1664. }
  1665. ]
  1666. },
  1667. {
  1668. Hosts: {
  1669. host_state: 'HEARTBEAT_LOST',
  1670. host_name: 'h2'
  1671. },
  1672. host_components: [
  1673. {
  1674. HostRoles: {
  1675. component_name: 'c3'
  1676. }
  1677. },
  1678. {
  1679. HostRoles: {
  1680. component_name: 'c4'
  1681. }
  1682. }
  1683. ]
  1684. }
  1685. ]
  1686. };
  1687. beforeEach(function () {
  1688. sinon.stub(c, 'changeParseHostInfo', Em.K);
  1689. sinon.stub(c, 'launchStartServices', Em.K);
  1690. sinon.stub(c, 'saveClusterStatus', Em.K);
  1691. c.set('hosts', hosts);
  1692. c.isAllComponentsInstalledSuccessCallback(jsonData);
  1693. this.clusterStatus = c.saveClusterStatus.args[0][0];
  1694. });
  1695. afterEach(function () {
  1696. c.changeParseHostInfo.restore();
  1697. c.launchStartServices.restore();
  1698. c.saveClusterStatus.restore();
  1699. });
  1700. it('cluster status / status', function () {
  1701. expect(this.clusterStatus.status).to.be.equal('INSTALL FAILED');
  1702. });
  1703. it('cluster status / isStartError', function () {
  1704. expect(this.clusterStatus.isStartError).to.be.true;
  1705. });
  1706. it('cluster status / isCompleted', function () {
  1707. expect(this.clusterStatus.isCompleted).to.be.false;
  1708. });
  1709. it('each host progress is 100', function () {
  1710. expect(c.get('hosts').everyProperty('progress', '100')).to.be.true;
  1711. });
  1712. it('each host status is `heartbeat_lost`', function () {
  1713. expect(c.get('hosts').everyProperty('status', 'heartbeat_lost')).to.be.true;
  1714. });
  1715. it('overall progress is 100', function () {
  1716. expect(c.get('progress')).to.be.equal('100');
  1717. });
  1718. });
  1719. describe('#loadDoServiceChecksFlagSuccessCallback', function () {
  1720. var data = {
  1721. RootServiceComponents: {
  1722. properties: {
  1723. 'skip.service.checks': 'true'
  1724. }
  1725. }
  1726. };
  1727. it('skipServiceChecks should be true', function () {
  1728. c.loadDoServiceChecksFlagSuccessCallback(data);
  1729. expect(c.get('skipServiceChecks')).to.be.true;
  1730. });
  1731. it('skipServiceChecks should be false', function () {
  1732. data.RootServiceComponents.properties['skip.service.checks'] = 'false';
  1733. c.loadDoServiceChecksFlagSuccessCallback(data);
  1734. expect(c.get('skipServiceChecks')).to.be.false;
  1735. });
  1736. });
  1737. describe('#isNextButtonDisabled', function () {
  1738. var cases = [
  1739. {
  1740. nextBtnClickInProgress: true,
  1741. isSubmitDisabled: true,
  1742. isNextButtonDisabled: true,
  1743. description: 'button clicked, submit disabled',
  1744. title: 'next button disabled'
  1745. },
  1746. {
  1747. nextBtnClickInProgress: true,
  1748. isSubmitDisabled: false,
  1749. isNextButtonDisabled: true,
  1750. description: 'button clicked, submit not disabled',
  1751. title: 'next button disabled'
  1752. },
  1753. {
  1754. nextBtnClickInProgress: false,
  1755. isSubmitDisabled: true,
  1756. isNextButtonDisabled: true,
  1757. description: 'no button clicked, submit disabled',
  1758. title: 'next button disabled'
  1759. },
  1760. {
  1761. nextBtnClickInProgress: false,
  1762. isSubmitDisabled: false,
  1763. isNextButtonDisabled: false,
  1764. description: 'no button clicked, submit not disabled',
  1765. title: 'next button enabled'
  1766. }
  1767. ];
  1768. cases.forEach(function (item) {
  1769. describe(item.description, function () {
  1770. beforeEach(function () {
  1771. c.reopen({
  1772. isSubmitDisabled: item.isSubmitDisabled
  1773. });
  1774. sinon.stub(App, 'get').withArgs('router.nextBtnClickInProgress').returns(item.nextBtnClickInProgress);
  1775. c.propertyDidChange('isSubmitDisabled');
  1776. c.propertyDidChange('App.router.nextBtnClickInProgress');
  1777. });
  1778. afterEach(function () {
  1779. App.get.restore();
  1780. });
  1781. it(item.title, function () {
  1782. expect(c.get('isNextButtonDisabled')).to.equal(item.isNextButtonDisabled);
  1783. });
  1784. });
  1785. });
  1786. });
  1787. });