step9_test.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var Ember = require('ember');
  19. var App = require('app');
  20. require('models/stack_service_component');
  21. require('models/hosts');
  22. require('controllers/wizard');
  23. require('controllers/installer');
  24. require('controllers/wizard/step9_controller');
  25. require('utils/helper');
  26. require('utils/ajax/ajax');
  27. var modelSetup = require('test/init_model_test');
  28. var c, obj;
  29. describe('App.InstallerStep9Controller', function () {
  30. beforeEach(function () {
  31. modelSetup.setupStackServiceComponent();
  32. c = App.WizardStep9Controller.create({
  33. content: {controllerName: ''},
  34. saveClusterStatus: Em.K,
  35. saveInstalledHosts: Em.K,
  36. togglePreviousSteps: Em.K,
  37. setFinishState: Em.K,
  38. changeParseHostInfo: Em.K,
  39. parseHostInfoPolling: Em.K,
  40. wizardController: Em.Object.create({
  41. requestsId: [],
  42. cluster: {oldRequestsId: []},
  43. getDBProperty: function(name) {
  44. return this.get(name);
  45. }
  46. })
  47. });
  48. obj = App.InstallerController.create();
  49. sinon.stub(App.ajax, 'send', function() {
  50. return {
  51. then: function() {
  52. return true;
  53. },
  54. retry: function() {
  55. return {
  56. then: Em.K,
  57. complete: Em.K
  58. };
  59. },
  60. complete: Em.K
  61. };
  62. });
  63. });
  64. afterEach(function () {
  65. modelSetup.cleanStackServiceComponent();
  66. App.ajax.send.restore();
  67. });
  68. describe('#isSubmitDisabled', function () {
  69. var tests = Em.A([
  70. {controllerName: 'addHostController', state: 'STARTED', e: false},
  71. {controllerName: 'addHostController', state: 'START FAILED', e: false},
  72. {controllerName: 'addHostController', state: 'INSTALL FAILED', e: false},
  73. {controllerName: 'addHostController', state: 'PENDING', e: true},
  74. {controllerName: 'addHostController', state: 'INSTALLED', e: true},
  75. {controllerName: 'addServiceController', state: 'STARTED', e: false},
  76. {controllerName: 'addServiceController', state: 'START FAILED', e: false},
  77. {controllerName: 'addServiceController', state: 'INSTALL FAILED', e: false},
  78. {controllerName: 'addServiceController', state: 'PENDING', e: true},
  79. {controllerName: 'addServiceController', state: 'INSTALLED', e: true},
  80. {controllerName: 'installerController', state: 'STARTED', e: false},
  81. {controllerName: 'installerController', state: 'START FAILED', e: false},
  82. {controllerName: 'installerController', state: 'INSTALL FAILED', e: true},
  83. {controllerName: 'installerController', state: 'INSTALLED', e: true},
  84. {controllerName: 'installerController', state: 'PENDING', e: true}
  85. ]);
  86. tests.forEach(function (test) {
  87. var controller = App.WizardStep9Controller.create({
  88. saveClusterStatus: Em.K,
  89. saveInstalledHosts: Em.K,
  90. content: {
  91. controllerName: test.controllerName,
  92. cluster: {
  93. status: test.state
  94. }
  95. }
  96. });
  97. it('controllerName is ' + test.controllerName + '; cluster status is ' + test.state + '; isSubmitDisabled should be ' + test.e, function () {
  98. expect(controller.get('isSubmitDisabled')).to.equal(test.e);
  99. });
  100. });
  101. });
  102. describe('#status', function () {
  103. var tests = Em.A([
  104. {
  105. hosts: [
  106. {status: 'failed'},
  107. {status: 'success'}
  108. ],
  109. isStepFailed: false,
  110. progress: '100',
  111. m: 'One host is failed',
  112. e: 'failed'
  113. },
  114. {
  115. hosts: [
  116. {status: 'warning'},
  117. {status: 'success'}
  118. ],
  119. m: 'One host is failed and step is not failed',
  120. isStepFailed: false,
  121. progress: '100',
  122. e: 'warning'
  123. },
  124. {
  125. hosts: [
  126. {status: 'warning'},
  127. {status: 'success'}
  128. ],
  129. m: 'One host is failed and step is failed',
  130. isStepFailed: true,
  131. progress: '100',
  132. e: 'failed'
  133. },
  134. {
  135. hosts: [
  136. {status: 'success'},
  137. {status: 'success'}
  138. ],
  139. m: 'All hosts are success and progress is 100',
  140. isStepFailed: false,
  141. progress: '100',
  142. e: 'success'
  143. },
  144. {
  145. hosts: [
  146. {status: 'success'},
  147. {status: 'success'}
  148. ],
  149. m: 'All hosts are success and progress is 50',
  150. isStepFailed: false,
  151. progress: '50',
  152. e: 'info'
  153. }
  154. ]);
  155. tests.forEach(function (test) {
  156. var controller = App.WizardStep9Controller.create({
  157. saveClusterStatus: Em.K,
  158. saveInstalledHosts: Em.K,
  159. hosts: test.hosts,
  160. isStepFailed: function () {
  161. return test.isStepFailed
  162. },
  163. progress: test.progress
  164. });
  165. controller.updateStatus();
  166. it(test.m, function () {
  167. expect(controller.get('status')).to.equal(test.e);
  168. });
  169. });
  170. });
  171. describe('#showRetry', function () {
  172. it('cluster status is not INSTALL FAILED', function () {
  173. c.reopen({content: {cluster: {status: 'INSTALLED'}}});
  174. expect(c.get('showRetry')).to.equal(false);
  175. });
  176. it('cluster status is INSTALL FAILED', function () {
  177. c.reopen({content: {cluster: {status: 'INSTALL FAILED'}}});
  178. expect(c.get('showRetry')).to.equal(true);
  179. });
  180. });
  181. describe('#resetHostsForRetry', function () {
  182. it('All should have status "pending" and message "Waiting"', function () {
  183. var hosts = {'host1': Em.Object.create({status: 'failed', message: 'Failed'}), 'host2': Em.Object.create({status: 'success', message: 'Success'})};
  184. c.reopen({content: {hosts: hosts}});
  185. c.resetHostsForRetry();
  186. for (var name in hosts) {
  187. if (hosts.hasOwnProperty(name)) {
  188. expect(c.get('content.hosts')[name].get('status', 'pending')).to.equal('pending');
  189. expect(c.get('content.hosts')[name].get('message', 'Waiting')).to.equal('Waiting');
  190. }
  191. }
  192. });
  193. });
  194. describe('#setParseHostInfo', function () {
  195. var tasks = Em.A([
  196. Em.Object.create({
  197. Tasks: Em.Object.create({
  198. host_name: 'host1',
  199. status: 'PENDING'
  200. })
  201. }),
  202. Em.Object.create({
  203. Tasks: Em.Object.create({
  204. host_name: 'host1',
  205. status: 'PENDING'
  206. })
  207. })
  208. ]);
  209. var content = Em.Object.create({
  210. cluster: Em.Object.create({
  211. requestId: '11',
  212. status: 'PENDING'
  213. })
  214. });
  215. beforeEach(function(){
  216. c.set('content', content)
  217. });
  218. it('Should make parseHostInfo false"', function () {
  219. var polledData = Em.Object.create({
  220. tasks: tasks,
  221. Requests: Em.Object.create({
  222. id: '222'
  223. })
  224. });
  225. c.setParseHostInfo(polledData);
  226. expect(c.get('parseHostInfo')).to.be.false;
  227. });
  228. it('Should set polledData"', function () {
  229. var polledData = Em.Object.create({
  230. tasks: tasks,
  231. Requests: Em.Object.create({
  232. id: '11'
  233. })
  234. });
  235. c.setParseHostInfo(polledData);
  236. var expected = [
  237. {
  238. "Tasks": {
  239. "status": "PENDING",
  240. "host_name": "host1",
  241. "request_id": "11"
  242. }
  243. },
  244. {
  245. "Tasks": {
  246. "status": "PENDING",
  247. "host_name": "host1",
  248. "request_id": "11"
  249. }
  250. }
  251. ];
  252. var result = JSON.parse(JSON.stringify(c.get('polledData')));
  253. expect(result).to.eql(expected);
  254. });
  255. it('Should set progress for hosts"', function () {
  256. var polledData = Em.Object.create({
  257. tasks: tasks,
  258. Requests: Em.Object.create({
  259. id: '11'
  260. })
  261. });
  262. var hosts = Em.A([
  263. Em.Object.create({
  264. name: 'host1',
  265. logTasks: [
  266. {Tasks: {role: 'HDFS_CLIENT'}},
  267. {Tasks: {role: 'DATANODE'}}
  268. ],
  269. status: 'old_status',
  270. progress: '10',
  271. isNoTasksForInstall: true,
  272. e: {status: 'old_status', progress: '10'}
  273. }),
  274. Em.Object.create({
  275. name: 'host2',
  276. logTasks: [
  277. {Tasks: {role: 'HDFS_CLIENT'}}
  278. ],
  279. status: 'old_status',
  280. progress: '10',
  281. e: {status: 'success', progress: '100'}
  282. })
  283. ]);
  284. c.set('hosts', hosts);
  285. c.setParseHostInfo(polledData);
  286. var expected = [
  287. {
  288. "name": "host1",
  289. "logTasks": [
  290. {
  291. "Tasks": {
  292. "role": "HDFS_CLIENT",
  293. "status": "PENDING"
  294. }
  295. },
  296. {
  297. "Tasks": {
  298. "role": "DATANODE"
  299. }
  300. }
  301. ],
  302. "progress": "0",
  303. "isNoTasksForInstall": false,
  304. "e": {
  305. "status": "old_status",
  306. "progress": "10"
  307. },
  308. "status": "in_progress",
  309. "message": ""
  310. },
  311. {
  312. "name": "host2",
  313. "logTasks": [
  314. {
  315. "Tasks": {
  316. "role": "HDFS_CLIENT"
  317. }
  318. }
  319. ],
  320. "progress": "33",
  321. "e": {
  322. "status": "success",
  323. "progress": "100"
  324. },
  325. "status": "pending",
  326. "isNoTasksForInstall": true,
  327. "message": "Install complete (Waiting to start)"
  328. }
  329. ];
  330. var result = JSON.parse(JSON.stringify(c.get('hosts')));
  331. expect(result).to.eql(expected);
  332. });
  333. });
  334. var hosts_for_load_and_render = {
  335. 'host1': {
  336. message: 'message1',
  337. status: 'unknown',
  338. progress: '1',
  339. logTasks: [
  340. {},
  341. {}
  342. ],
  343. bootStatus: 'REGISTERED'
  344. },
  345. 'host2': {
  346. message: '',
  347. status: 'failed',
  348. progress: '1',
  349. logTasks: [
  350. {},
  351. {}
  352. ],
  353. bootStatus: ''
  354. },
  355. 'host3': {
  356. message: '',
  357. status: 'waiting',
  358. progress: null,
  359. logTasks: [
  360. {},
  361. {}
  362. ],
  363. bootStatus: ''
  364. },
  365. 'host4': {
  366. message: 'message4',
  367. status: null,
  368. progress: '10',
  369. logTasks: [
  370. {}
  371. ],
  372. bootStatus: 'REGISTERED'
  373. }
  374. };
  375. describe('#loadHosts', function () {
  376. beforeEach(function() {
  377. c.reopen({content: {hosts: hosts_for_load_and_render}});
  378. c.loadHosts();
  379. });
  380. it('Only REGISTERED hosts', function () {
  381. var loaded_hosts = c.get('hosts');
  382. expect(loaded_hosts.length).to.equal(2);
  383. });
  384. it('All hosts have progress 0', function () {
  385. var loaded_hosts = c.get('hosts');
  386. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  387. });
  388. it('All hosts have progress 0', function () {
  389. var loaded_hosts = c.get('hosts');
  390. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  391. });
  392. it('All host don\'t have logTasks', function () {
  393. var loaded_hosts = c.get('hosts');
  394. expect(loaded_hosts.everyProperty('logTasks.length', 0)).to.equal(true);
  395. });
  396. });
  397. describe('#isServicesStarted', function () {
  398. it('Should return false when server not started', function () {
  399. var polledData = Em.A([
  400. Em.Object.create({
  401. Tasks: Em.Object.create({
  402. status: 'PENDING'
  403. })
  404. }),
  405. Em.Object.create({
  406. Tasks: Em.Object.create({
  407. status: 'PENDING'
  408. })
  409. })
  410. ]);
  411. expect(c.isServicesStarted(polledData)).to.be.false;
  412. });
  413. it('Should return true when server started', function () {
  414. var polledData = Em.A([
  415. Em.Object.create({
  416. Tasks: Em.Object.create({
  417. status: 'NONE'
  418. })
  419. }),
  420. Em.Object.create({
  421. Tasks: Em.Object.create({
  422. status: 'NONE'
  423. })
  424. })
  425. ]);
  426. expect(c.isServicesStarted(polledData)).to.be.true;
  427. });
  428. it('Should return true when tasks completed', function () {
  429. var polledData = Em.A([
  430. Em.Object.create({
  431. Tasks: Em.Object.create({
  432. status: 'COMPLETED'
  433. })
  434. }),
  435. Em.Object.create({
  436. Tasks: Em.Object.create({
  437. status: 'COMPLETED'
  438. })
  439. })
  440. ]);
  441. expect(c.isServicesStarted(polledData)).to.be.true;
  442. });
  443. });
  444. describe('#setIsServicesInstalled', function () {
  445. it('Should return 100% completed', function () {
  446. var polledData = Em.A([
  447. Em.Object.create({
  448. Tasks: Em.Object.create({
  449. status: 'NONE'
  450. })
  451. }),
  452. Em.Object.create({
  453. Tasks: Em.Object.create({
  454. status: 'NONE'
  455. })
  456. })
  457. ]);
  458. c.set('status', 'failed');
  459. c.set('hosts', Em.A([
  460. Em.Object.create({
  461. progress: 0
  462. })
  463. ]));
  464. c.setIsServicesInstalled(polledData);
  465. expect(c.get('progress')).to.equal('100');
  466. });
  467. it('Should return 34% completed', function () {
  468. var polledData = Em.A([
  469. Em.Object.create({
  470. Tasks: Em.Object.create({
  471. status: 'NONE'
  472. })
  473. }),
  474. Em.Object.create({
  475. Tasks: Em.Object.create({
  476. status: 'NONE'
  477. })
  478. })
  479. ]);
  480. c.set('status', '');
  481. c.set('hosts', Em.A([
  482. Em.Object.create({
  483. progress: 0
  484. })
  485. ]));
  486. c.set('content', Em.Object.create({
  487. controllerName: 'installerController'
  488. }));
  489. c.setIsServicesInstalled(polledData);
  490. expect(c.get('progress')).to.equal('34');
  491. });
  492. });
  493. describe('#launchStartServices', function () {
  494. beforeEach(function() {
  495. sinon.stub(App, 'get', function(k) {
  496. if (k === 'components.slaves')
  497. return ["TASKTRACKER", "DATANODE",
  498. "JOURNALNODE", "ZKFC",
  499. "APP_TIMELINE_SERVER",
  500. "NODEMANAGER",
  501. "GANGLIA_MONITOR",
  502. "HBASE_REGIONSERVER",
  503. "SUPERVISOR",
  504. "FLUME_HANDLER"];
  505. return true;
  506. });
  507. });
  508. afterEach(function() {
  509. App.get.restore();
  510. });
  511. var tests = [
  512. {
  513. expected: [],
  514. message: 'should return query',
  515. controllerName: 'addHostController',
  516. hosts: Em.A([
  517. Em.Object.create({
  518. name: 'h1'
  519. }),
  520. Em.Object.create({
  521. name: 'h2'
  522. })
  523. ])
  524. },
  525. {
  526. expected: [],
  527. text: 'should return server info',
  528. controllerName: 'addServiceController',
  529. services: Em.A([
  530. Em.Object.create({
  531. serviceName: 'OOZIE',
  532. isSelected: true,
  533. isInstalled: false
  534. }),
  535. Em.Object.create({
  536. serviceName: 'h2',
  537. isSelected: false,
  538. isInstalled: true
  539. })
  540. ])
  541. },
  542. {
  543. expected: [],
  544. text: 'should return default data',
  545. controllerName: 'addHostContro',
  546. hosts: Em.A([
  547. Em.Object.create({
  548. name: 'h1'
  549. }),
  550. Em.Object.create({
  551. name: 'h2'
  552. })
  553. ])
  554. }
  555. ];
  556. tests.forEach(function(test) {
  557. it(test.message, function () {
  558. var content = Em.Object.create({
  559. controllerName: test.controllerName,
  560. services: test.services
  561. });
  562. var wizardController = Em.Object.create({
  563. getDBProperty: function() {
  564. return test.hosts
  565. }
  566. });
  567. c.set('content', content);
  568. c.set('wizardController', wizardController);
  569. expect(c.launchStartServices(function(){})).to.be.true;
  570. });
  571. })
  572. });
  573. describe('#hostHasClientsOnly', function () {
  574. var tests = Em.A([
  575. {
  576. hosts: [
  577. Em.Object.create({
  578. hostName: 'host1',
  579. logTasks: [
  580. {Tasks: {role: 'HDFS_CLIENT'}},
  581. {Tasks: {role: 'DATANODE'}}
  582. ],
  583. status: 'old_status',
  584. progress: '10',
  585. e: {status: 'old_status', progress: '10'}
  586. }),
  587. Em.Object.create({
  588. hostName: 'host2',
  589. logTasks: [
  590. {Tasks: {role: 'HDFS_CLIENT'}}
  591. ],
  592. status: 'old_status',
  593. progress: '10',
  594. e: {status: 'success', progress: '100'}
  595. })
  596. ],
  597. jsonError: false
  598. },
  599. {
  600. hosts: [
  601. Em.Object.create({
  602. hostName: 'host1',
  603. logTasks: [
  604. {Tasks: {role: 'HDFS_CLIENT'}},
  605. {Tasks: {role: 'DATANODE'}}
  606. ],
  607. status: 'old_status',
  608. progress: '10',
  609. e: {status: 'success', progress: '100'}
  610. }),
  611. Em.Object.create({
  612. hostName: 'host2',
  613. logTasks: [
  614. {Tasks: {role: 'HDFS_CLIENT'}}
  615. ],
  616. status: 'old_status',
  617. progress: '10',
  618. e: {status: 'success', progress: '100'}
  619. })
  620. ],
  621. jsonError: true
  622. }
  623. ]);
  624. tests.forEach(function (test) {
  625. it('', function () {
  626. c.reopen({hosts: test.hosts});
  627. c.hostHasClientsOnly(test.jsonError);
  628. test.hosts.forEach(function (host) {
  629. expect(c.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  630. expect(c.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  631. });
  632. });
  633. });
  634. });
  635. describe('#onSuccessPerHost', function () {
  636. var tests = Em.A([
  637. {
  638. cluster: {status: 'INSTALLED'},
  639. host: Em.Object.create({status: 'pending'}),
  640. actions: [],
  641. e: {status: 'success'},
  642. m: 'No tasks for host'
  643. },
  644. {
  645. cluster: {status: 'INSTALLED'},
  646. host: Em.Object.create({status: 'info'}),
  647. actions: [
  648. {Tasks: {status: 'COMPLETED'}},
  649. {Tasks: {status: 'COMPLETED'}}
  650. ],
  651. e: {status: 'success'},
  652. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  653. },
  654. {
  655. cluster: {status: 'FAILED'},
  656. host: Em.Object.create({status: 'info'}),
  657. actions: [
  658. {Tasks: {status: 'COMPLETED'}},
  659. {Tasks: {status: 'COMPLETED'}}
  660. ],
  661. e: {status: 'info'},
  662. m: 'All Tasks COMPLETED and cluster status FAILED'
  663. },
  664. {
  665. cluster: {status: 'INSTALLED'},
  666. host: Em.Object.create({status: 'info'}),
  667. actions: [
  668. {Tasks: {status: 'FAILED'}},
  669. {Tasks: {status: 'COMPLETED'}}
  670. ],
  671. e: {status: 'info'},
  672. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  673. },
  674. {
  675. cluster: {status: 'FAILED'},
  676. host: Em.Object.create({status: 'info'}),
  677. actions: [
  678. {Tasks: {status: 'FAILED'}},
  679. {Tasks: {status: 'COMPLETED'}}
  680. ],
  681. e: {status: 'info'},
  682. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  683. }
  684. ]);
  685. tests.forEach(function (test) {
  686. it(test.m, function () {
  687. c.reopen({content: {cluster: {status: test.cluster.status}}});
  688. c.onSuccessPerHost(test.actions, test.host);
  689. expect(test.host.status).to.equal(test.e.status);
  690. });
  691. });
  692. });
  693. describe('#onErrorPerHost', function () {
  694. var tests = Em.A([
  695. {
  696. cluster: {status: 'INSTALLED'},
  697. host: Em.Object.create({status: 'pending'}),
  698. actions: [],
  699. e: {status: 'pending'},
  700. isMasterFailed: false,
  701. m: 'No tasks for host'
  702. },
  703. {
  704. cluster: {status: 'INSTALLED'},
  705. host: Em.Object.create({status: 'info'}),
  706. actions: [
  707. {Tasks: {status: 'FAILED'}},
  708. {Tasks: {status: 'COMPLETED'}}
  709. ],
  710. e: {status: 'warning'},
  711. isMasterFailed: false,
  712. m: 'One Task FAILED and cluster status INSTALLED'
  713. },
  714. {
  715. cluster: {status: 'INSTALLED'},
  716. host: Em.Object.create({status: 'info'}),
  717. actions: [
  718. {Tasks: {status: 'ABORTED'}},
  719. {Tasks: {status: 'COMPLETED'}}
  720. ],
  721. e: {status: 'warning'},
  722. isMasterFailed: false,
  723. m: 'One Task ABORTED and cluster status INSTALLED'
  724. },
  725. {
  726. cluster: {status: 'INSTALLED'},
  727. host: Em.Object.create({status: 'info'}),
  728. actions: [
  729. {Tasks: {status: 'TIMEDOUT'}},
  730. {Tasks: {status: 'COMPLETED'}}
  731. ],
  732. e: {status: 'warning'},
  733. isMasterFailed: false,
  734. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  735. },
  736. {
  737. cluster: {status: 'PENDING'},
  738. host: Em.Object.create({status: 'info'}),
  739. actions: [
  740. {Tasks: {status: 'FAILED'}},
  741. {Tasks: {status: 'COMPLETED'}}
  742. ],
  743. e: {status: 'failed'},
  744. isMasterFailed: true,
  745. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  746. },
  747. {
  748. cluster: {status: 'PENDING'},
  749. host: Em.Object.create({status: 'info'}),
  750. actions: [
  751. {Tasks: {status: 'COMPLETED'}},
  752. {Tasks: {status: 'COMPLETED'}}
  753. ],
  754. e: {status: 'info'},
  755. isMasterFailed: false,
  756. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  757. }
  758. ]);
  759. tests.forEach(function (test) {
  760. it(test.m, function () {
  761. c.reopen({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  762. return test.isMasterFailed;
  763. }});
  764. c.onErrorPerHost(test.actions, test.host);
  765. expect(test.host.status).to.equal(test.e.status);
  766. });
  767. });
  768. });
  769. describe('#isMasterFailed', function () {
  770. beforeEach(function() {
  771. sinon.stub(App, 'get', function(k) {
  772. if (k === 'components.slaves')
  773. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  774. return Em.get(App, k);
  775. });
  776. });
  777. afterEach(function() {
  778. App.get.restore();
  779. });
  780. var tests = Em.A([
  781. {
  782. actions: [
  783. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  784. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  785. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  786. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  787. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  788. ],
  789. e: false,
  790. m: 'No one Master is failed'
  791. },
  792. {
  793. actions: [
  794. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  795. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  796. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  797. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  798. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  799. ],
  800. e: true,
  801. m: 'One Master is failed'
  802. },
  803. {
  804. actions: [
  805. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  806. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  807. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  808. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  809. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  810. ],
  811. e: false,
  812. m: 'one Master is failed but command is not install'
  813. }
  814. ]);
  815. tests.forEach(function (test) {
  816. it(test.m, function () {
  817. expect(c.isMasterFailed(test.actions)).to.equal(test.e);
  818. });
  819. });
  820. });
  821. describe('#onInProgressPerHost', function () {
  822. var tests = Em.A([
  823. {
  824. host: Em.Object.create({message: 'default_message'}),
  825. actions: [
  826. {Tasks: {status: 'COMPLETED'}},
  827. {Tasks: {status: 'COMPLETED'}}
  828. ],
  829. e: {message: 'default_message', b: true},
  830. m: 'All Tasks COMPLETED'
  831. },
  832. {
  833. host: Em.Object.create({message: 'default_message'}),
  834. actions: [
  835. {Tasks: {status: 'IN_PROGRESS'}},
  836. {Tasks: {status: 'COMPLETED'}}
  837. ],
  838. e: {message: 'default_message', b: false},
  839. m: 'One Task IN_PROGRESS'
  840. },
  841. {
  842. host: Em.Object.create({message: 'default_message'}),
  843. actions: [
  844. {Tasks: {status: 'QUEUED'}},
  845. {Tasks: {status: 'COMPLETED'}}
  846. ],
  847. e: {message: 'default_message', b: false},
  848. m: 'One Task QUEUED'
  849. },
  850. {
  851. host: Em.Object.create({message: 'default_message'}),
  852. actions: [
  853. {Tasks: {status: 'PENDING'}},
  854. {Tasks: {status: 'COMPLETED'}}
  855. ],
  856. e: {message: 'default_message', b: false},
  857. m: 'One Task PENDING'
  858. }
  859. ]);
  860. tests.forEach(function (test) {
  861. it(test.m, function () {
  862. c.onInProgressPerHost(test.actions, test.host);
  863. expect(test.host.message == test.e.message).to.equal(test.e.b);
  864. });
  865. });
  866. });
  867. describe('#progressPerHost', function () {
  868. var tests = Em.A([
  869. {
  870. cluster: {status: 'PENDING'},
  871. host: Em.Object.create({progress: 0}),
  872. actions: [
  873. {Tasks: {status: 'COMPLETED'}},
  874. {Tasks: {status: 'COMPLETED'}},
  875. {Tasks: {status: 'QUEUED'}},
  876. {Tasks: {status: 'QUEUED'}},
  877. {Tasks: {status: 'IN_PROGRESS'}}
  878. ],
  879. e: {ret: 17, host: '17'},
  880. m: 'All types of status available. cluster status PENDING'
  881. },
  882. {
  883. cluster: {status: 'PENDING'},
  884. host: Em.Object.create({progress: 0}),
  885. actions: [],
  886. e: {ret: 33, host: '33'},
  887. m: 'No tasks available. cluster status PENDING'
  888. },
  889. {
  890. cluster: {status: 'INSTALLED'},
  891. host: Em.Object.create({progress: 0}),
  892. actions: [],
  893. e: {ret: 100, host: '100'},
  894. m: 'No tasks available. cluster status INSTALLED'
  895. },
  896. {
  897. cluster: {status: 'INSTALLED'},
  898. host: Em.Object.create({progress: 0}),
  899. actions: [
  900. {Tasks: {status: 'COMPLETED'}},
  901. {Tasks: {status: 'COMPLETED'}},
  902. {Tasks: {status: 'QUEUED'}},
  903. {Tasks: {status: 'QUEUED'}},
  904. {Tasks: {status: 'IN_PROGRESS'}}
  905. ],
  906. e: {ret: 68, host: '68'},
  907. m: 'All types of status available. cluster status INSTALLED'
  908. },
  909. {
  910. cluster: {status: 'FAILED'},
  911. host: Em.Object.create({progress: 0}),
  912. actions: [],
  913. e: {ret: 100, host: '100'},
  914. m: 'Cluster status is not PENDING or INSTALLED'
  915. }
  916. ]);
  917. tests.forEach(function (test) {
  918. it(test.m, function () {
  919. c.reopen({content: {cluster: {status: test.cluster.status}}});
  920. var progress = c.progressPerHost(test.actions, test.host);
  921. expect(progress).to.equal(test.e.ret);
  922. expect(test.host.progress).to.equal(test.e.host);
  923. });
  924. });
  925. });
  926. describe('#clearStep', function () {
  927. it('All to default values', function () {
  928. c.reopen({hosts: [{},{},{}]});
  929. c.clearStep();
  930. expect(c.get('hosts.length')).to.equal(0);
  931. expect(c.get('status')).to.equal('info');
  932. expect(c.get('progress')).to.equal('0');
  933. expect(c.get('numPolls')).to.equal(1);
  934. });
  935. });
  936. describe('#replacePolledData', function () {
  937. it('replacing polled data', function () {
  938. c.reopen({polledData: [{},{},{}]});
  939. var newPolledData = [{}];
  940. c.replacePolledData(newPolledData);
  941. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  942. });
  943. });
  944. describe('#isSuccess', function () {
  945. var tests = Em.A([
  946. {
  947. polledData: [
  948. {Tasks: {status: 'COMPLETED'}},
  949. {Tasks: {status: 'COMPLETED'}}
  950. ],
  951. e: true,
  952. m: 'All tasks are COMPLETED'
  953. },
  954. {
  955. polledData: [
  956. {Tasks: {status: 'COMPLETED'}},
  957. {Tasks: {status: 'FAILED'}}
  958. ],
  959. e: false,
  960. m: 'Not all tasks are COMPLETED'
  961. }
  962. ]);
  963. tests.forEach(function (test) {
  964. it(test.m, function () {
  965. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  966. });
  967. });
  968. });
  969. describe('#isStepFailed', function () {
  970. beforeEach(function() {
  971. sinon.stub(App, 'get', function(k) {
  972. if (k === 'components.slaves')
  973. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  974. return Em.get(App, k);
  975. });
  976. });
  977. afterEach(function() {
  978. App.get.restore();
  979. });
  980. var tests = Em.A([
  981. {
  982. polledData: [
  983. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  984. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  985. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  986. ],
  987. e: true,
  988. m: 'GANGLIA_MONITOR 2/3 failed'
  989. },
  990. {
  991. polledData: [
  992. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  993. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  994. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  995. ],
  996. e: false,
  997. m: 'GANGLIA_MONITOR 1/3 failed'
  998. },
  999. {
  1000. polledData: [
  1001. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1002. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  1003. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1004. ],
  1005. e: true,
  1006. m: 'HBASE_REGIONSERVER 2/3 failed'
  1007. },
  1008. {
  1009. polledData: [
  1010. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1011. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  1012. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1013. ],
  1014. e: false,
  1015. m: 'HBASE_REGIONSERVER 1/3 failed'
  1016. },
  1017. {
  1018. polledData: [
  1019. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1020. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  1021. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1022. ],
  1023. e: true,
  1024. m: 'TASKTRACKER 2/3 failed'
  1025. },
  1026. {
  1027. polledData: [
  1028. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1029. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  1030. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1031. ],
  1032. e: false,
  1033. m: 'TASKTRACKER 1/3 failed'
  1034. },
  1035. {
  1036. polledData: [
  1037. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1038. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  1039. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1040. ],
  1041. e: true,
  1042. m: 'DATANODE 2/3 failed'
  1043. },
  1044. {
  1045. polledData: [
  1046. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1047. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1048. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1049. ],
  1050. e: false,
  1051. m: 'DATANODE 1/3 failed'
  1052. },
  1053. {
  1054. polledData: [
  1055. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  1056. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1057. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1058. ],
  1059. e: true,
  1060. m: 'NAMENODE failed'
  1061. },
  1062. {
  1063. polledData: [
  1064. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  1065. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1066. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1067. ],
  1068. e: false,
  1069. m: 'Nothing failed failed'
  1070. }
  1071. ]);
  1072. tests.forEach(function (test) {
  1073. it(test.m, function () {
  1074. c.reopen({polledData: test.polledData});
  1075. expect(c.isStepFailed()).to.equal(test.e);
  1076. });
  1077. });
  1078. });
  1079. describe('#setLogTasksStatePerHost', function () {
  1080. var tests = Em.A([
  1081. {
  1082. tasksPerHost: [
  1083. {Tasks: {id: 1, status: 'COMPLETED'}},
  1084. {Tasks: {id: 2, status: 'COMPLETED'}}
  1085. ],
  1086. tasks: [],
  1087. e: {m: 'COMPLETED', l: 2},
  1088. m: 'host didn\'t have tasks and got 2 new'
  1089. },
  1090. {
  1091. tasksPerHost: [
  1092. {Tasks: {id: 1, status: 'COMPLETED'}},
  1093. {Tasks: {id: 2, status: 'COMPLETED'}}
  1094. ],
  1095. tasks: [
  1096. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1097. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1098. ],
  1099. e: {m: 'COMPLETED', l: 2},
  1100. m: 'host had 2 tasks and got both updated'
  1101. },
  1102. {
  1103. tasksPerHost: [],
  1104. tasks: [
  1105. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1106. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1107. ],
  1108. e: {m: 'IN_PROGRESS', l: 2},
  1109. m: 'host had 2 tasks and didn\'t get updates'
  1110. },
  1111. {
  1112. tasksPerHost: [
  1113. {Tasks: {id: 1, status: 'COMPLETED'}},
  1114. {Tasks: {id: 2, status: 'COMPLETED'}},
  1115. {Tasks: {id: 3, status: 'COMPLETED'}}
  1116. ],
  1117. tasks: [
  1118. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1119. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1120. ],
  1121. e: {m: 'COMPLETED', l: 3},
  1122. m: 'host had 2 tasks and got both updated and 1 new'
  1123. }
  1124. ]);
  1125. tests.forEach(function (test) {
  1126. it(test.m, function () {
  1127. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  1128. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  1129. expect(c.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  1130. expect(c.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  1131. });
  1132. });
  1133. });
  1134. // On completion of Start all services error callback function,
  1135. // Cluster Status should be INSTALL FAILED
  1136. // All progress bar on the screen should be finished (100%) with blue color.
  1137. // Retry button should be enabled, next button should be disabled
  1138. describe('#launchStartServicesErrorCallback', function () {
  1139. beforeEach(function() {
  1140. sinon.stub(App, 'get', function(k) {
  1141. if ('testMode' === k) return true;
  1142. return Em.get(App, k);
  1143. });
  1144. });
  1145. afterEach(function() {
  1146. App.get.restore();
  1147. });
  1148. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1149. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1150. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1151. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1152. expect(c.get('progress')).to.equal('100');
  1153. expect(c.get('status')).to.equal('failed');
  1154. });
  1155. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1156. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1157. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1158. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1159. c.get('hosts').forEach(function (host) {
  1160. expect(host.get('progress')).to.equal('100');
  1161. expect(host.get('status')).to.equal('info');
  1162. });
  1163. });
  1164. it('Next button should be disabled', function () {
  1165. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1166. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1167. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1168. expect(c.get('isSubmitDisabled')).to.equal(true);
  1169. });
  1170. });
  1171. describe('#submit', function () {
  1172. it('should call App.router.send', function () {
  1173. sinon.stub(App.router, 'send', Em.K);
  1174. c.submit();
  1175. expect(App.router.send.calledWith('next')).to.equal(true);
  1176. App.router.send.restore();
  1177. });
  1178. });
  1179. describe('#back', function () {
  1180. beforeEach(function () {
  1181. sinon.stub(App.router, 'send', Em.K);
  1182. });
  1183. afterEach(function () {
  1184. App.router.send.restore();
  1185. });
  1186. it('should call App.router.send', function () {
  1187. c.reopen({isSubmitDisabled: false});
  1188. c.back();
  1189. expect(App.router.send.calledWith('back')).to.equal(true);
  1190. });
  1191. it('shouldn\'t call App.router.send', function () {
  1192. c.reopen({isSubmitDisabled: true});
  1193. c.back();
  1194. expect(App.router.send.called).to.equal(false);
  1195. });
  1196. });
  1197. describe('#loadStep', function () {
  1198. beforeEach(function () {
  1199. sinon.stub(c, 'clearStep', Em.K);
  1200. sinon.stub(c, 'loadHosts', Em.K);
  1201. });
  1202. afterEach(function () {
  1203. c.clearStep.restore();
  1204. c.loadHosts.restore();
  1205. });
  1206. it('should call clearStep', function () {
  1207. c.loadStep();
  1208. expect(c.clearStep.calledOnce).to.equal(true);
  1209. });
  1210. it('should call loadHosts', function () {
  1211. c.loadStep();
  1212. expect(c.loadHosts.calledOnce).to.equal(true);
  1213. });
  1214. });
  1215. describe('#startPolling', function () {
  1216. beforeEach(function () {
  1217. sinon.stub(c, 'getLogsByRequestErrorCallback', Em.K);
  1218. });
  1219. afterEach(function () {
  1220. c.getLogsByRequestErrorCallback.restore();
  1221. });
  1222. it('should set isSubmitDisabled to true', function () {
  1223. c.set('isSubmitDisabled', false);
  1224. c.startPolling();
  1225. expect(c.get('isSubmitDisabled')).to.equal(true);
  1226. });
  1227. it('should call doPolling', function () {
  1228. sinon.stub(c, 'doPolling', Em.K);
  1229. c.startPolling();
  1230. expect(c.doPolling.calledOnce).to.equal(true);
  1231. c.doPolling.restore();
  1232. });
  1233. });
  1234. describe('#loadLogData', function () {
  1235. beforeEach(function () {
  1236. obj.reopen({
  1237. cluster: {oldRequestsId: [1,2,3]},
  1238. getDBProperty: function (name) {
  1239. return this.get(name);
  1240. }
  1241. });
  1242. c.reopen({wizardController: obj});
  1243. sinon.stub(c, 'getLogsByRequest', Em.K);
  1244. });
  1245. afterEach(function () {
  1246. c.getLogsByRequest.restore();
  1247. });
  1248. it('should call getLogsByRequest 1 time with 3', function () {
  1249. c.loadLogData(true);
  1250. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  1251. });
  1252. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  1253. sinon.stub(App, 'get', function(k) { if ('testMode' === k) return true; return Em.get(App, k);});
  1254. c.loadLogData();
  1255. expect(c.get('POLL_INTERVAL')).to.equal(1);
  1256. App.get.restore();
  1257. });
  1258. });
  1259. describe('#loadCurrentTaskLog', function () {
  1260. beforeEach(function () {
  1261. sinon.stub(c, 'loadLogData', Em.K);
  1262. c.set('wizardController', Em.Object.create({
  1263. getDBProperty: Em.K
  1264. }));
  1265. });
  1266. afterEach(function () {
  1267. c.loadLogData.restore();
  1268. });
  1269. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1270. c.set('currentOpenTaskId', null);
  1271. c.loadCurrentTaskLog();
  1272. expect(App.ajax.send.called).to.equal(false);
  1273. });
  1274. it('should call App.ajax.send with provided data', function () {
  1275. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1276. c.set('currentOpenTaskId', 1);
  1277. c.set('currentOpenTaskRequestId', 2);
  1278. c.set('content', {cluster: {name: 3}});
  1279. c.loadCurrentTaskLog();
  1280. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3});
  1281. c.togglePreviousSteps.restore();
  1282. });
  1283. });
  1284. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1285. beforeEach(function() {
  1286. sinon.stub(c, 'getLogsByRequest', Em.K);
  1287. sinon.stub(c, 'loadLogData', Em.K);
  1288. });
  1289. afterEach(function() {
  1290. c.getLogsByRequest.restore();
  1291. c.loadLogData.restore();
  1292. });
  1293. it('should increment logTasksChangesCounter', function () {
  1294. c.set('logTasksChangesCounter', 0);
  1295. c.loadCurrentTaskLogSuccessCallback();
  1296. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1297. });
  1298. it('should update stdout, stderr', function () {
  1299. c.set('currentOpenTaskId', 1);
  1300. c.reopen({
  1301. hosts: [
  1302. Em.Object.create({
  1303. name: 'h1',
  1304. logTasks: [
  1305. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1306. ]
  1307. })
  1308. ]
  1309. });
  1310. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1311. c.loadCurrentTaskLogSuccessCallback(data);
  1312. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1313. expect(t.stdout).to.equal('stdout');
  1314. expect(t.stderr).to.equal('stderr');
  1315. });
  1316. it('shouldn\'t update stdout, stderr', function () {
  1317. c.set('currentOpenTaskId', 1);
  1318. c.reopen({
  1319. hosts: [
  1320. Em.Object.create({
  1321. name: 'h1',
  1322. logTasks: [
  1323. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1324. ]
  1325. })
  1326. ]
  1327. });
  1328. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1329. c.loadCurrentTaskLogSuccessCallback(data);
  1330. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1331. expect(t.stdout).to.equal('');
  1332. expect(t.stderr).to.equal('');
  1333. });
  1334. it('shouldn\'t update stdout, stderr (2)', function () {
  1335. c.set('currentOpenTaskId', 1);
  1336. c.reopen({
  1337. hosts: [
  1338. Em.Object.create({
  1339. name: 'h2',
  1340. logTasks: [
  1341. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1342. ]
  1343. })
  1344. ]
  1345. });
  1346. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1347. c.loadCurrentTaskLogSuccessCallback(data);
  1348. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1349. expect(t.stdout).to.equal('');
  1350. expect(t.stderr).to.equal('');
  1351. });
  1352. });
  1353. describe('#loadCurrentTaskLogErrorCallback', function () {
  1354. it('should set currentOpenTaskId to 0', function () {
  1355. c.set('currentOpenTaskId', 123);
  1356. c.loadCurrentTaskLogErrorCallback();
  1357. expect(c.get('currentOpenTaskId')).to.equal(0);
  1358. });
  1359. });
  1360. describe('#doPolling', function () {
  1361. beforeEach(function () {
  1362. sinon.stub(c, 'getLogsByRequest', Em.K);
  1363. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1364. });
  1365. afterEach(function () {
  1366. c.getLogsByRequest.restore();
  1367. c.togglePreviousSteps.restore();
  1368. });
  1369. it('should increment numPolls if testMode', function () {
  1370. App.set('testMode', true);
  1371. c.set('numPolls', 0);
  1372. c.doPolling();
  1373. expect(c.get('numPolls')).to.equal(1);
  1374. App.set('testMode', false);
  1375. });
  1376. it('should call getLogsByRequest', function () {
  1377. c.set('content', {cluster: {requestId: 1}});
  1378. c.doPolling();
  1379. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1380. });
  1381. });
  1382. describe('#isAllComponentsInstalledErrorCallback', function () {
  1383. beforeEach(function () {
  1384. sinon.stub(c, 'saveClusterStatus', Em.K);
  1385. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1386. });
  1387. afterEach(function () {
  1388. c.saveClusterStatus.restore();
  1389. c.togglePreviousSteps.restore();
  1390. });
  1391. it('should call saveClusterStatus', function () {
  1392. c.isAllComponentsInstalledErrorCallback({});
  1393. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1394. });
  1395. });
  1396. describe('#navigateStep', function () {
  1397. beforeEach(function () {
  1398. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1399. sinon.stub(c, 'loadStep', Em.K);
  1400. sinon.stub(c, 'loadLogData', Em.K);
  1401. sinon.stub(c, 'startPolling', Em.K);
  1402. });
  1403. afterEach(function () {
  1404. c.togglePreviousSteps.restore();
  1405. c.loadStep.restore();
  1406. c.loadLogData.restore();
  1407. c.startPolling.restore();
  1408. App.get.restore();
  1409. });
  1410. it('should set custom data in testMode', function () {
  1411. sinon.stub(App, 'get', function(k) {if('testMode' === k) return true; return Em.get(App, k);});
  1412. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1413. c.navigateStep();
  1414. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1415. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1416. expect(c.get('content.cluster.requestId')).to.equal(1);
  1417. });
  1418. it('isCompleted = true, requestId = 1', function () {
  1419. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1420. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1421. c.navigateStep();
  1422. expect(c.loadStep.calledOnce).to.equal(true);
  1423. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1424. expect(c.get('progress')).to.equal('100');
  1425. });
  1426. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1427. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1428. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1429. c.navigateStep();
  1430. expect(c.loadStep.calledOnce).to.equal(true);
  1431. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1432. });
  1433. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1434. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1435. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1436. c.navigateStep();
  1437. expect(c.loadStep.calledOnce).to.equal(true);
  1438. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1439. });
  1440. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1441. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1442. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1443. c.navigateStep();
  1444. expect(c.loadStep.calledOnce).to.equal(true);
  1445. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1446. });
  1447. });
  1448. describe('#launchStartServicesSuccessCallback', function () {
  1449. beforeEach(function () {
  1450. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1451. return $.ajax();
  1452. });
  1453. sinon.stub(c, 'saveClusterStatus', Em.K);
  1454. sinon.stub(c, 'doPolling', Em.K);
  1455. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1456. });
  1457. afterEach(function () {
  1458. c.saveClusterStatus.restore();
  1459. c.doPolling.restore();
  1460. c.hostHasClientsOnly.restore();
  1461. App.clusterStatus.setClusterStatus.restore();
  1462. });
  1463. it('should call doPolling if some data were received', function () {
  1464. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1465. expect(c.doPolling.calledOnce).to.equal(true);
  1466. });
  1467. Em.A([
  1468. {
  1469. jsonData: {Requests: {id: 2}},
  1470. e: {
  1471. hostHasClientsOnly: false,
  1472. clusterStatus: {
  1473. status: 'INSTALLED',
  1474. requestId: 2,
  1475. isStartError: false,
  1476. isCompleted: false
  1477. }
  1478. }
  1479. },
  1480. {
  1481. jsonData: null,
  1482. e: {
  1483. hostHasClientsOnly: true,
  1484. clusterStatus: {
  1485. status: 'STARTED',
  1486. isStartError: false,
  1487. isCompleted: true
  1488. },
  1489. status: 'success',
  1490. progress: '100'
  1491. }
  1492. }
  1493. ]).forEach(function (test) {
  1494. it(test.m, function () {
  1495. c.launchStartServicesSuccessCallback(test.jsonData);
  1496. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1497. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1498. if (test.e.status) {
  1499. expect(c.get('status')).to.equal(test.e.status);
  1500. }
  1501. if (test.e.progress) {
  1502. expect(c.get('progress')).to.equal(test.e.progress);
  1503. }
  1504. });
  1505. });
  1506. });
  1507. });