step9_test.js 50 KB

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