step9_test.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  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.setProperties({
  459. status: 'failed',
  460. isPolling: true,
  461. hosts: Em.A([
  462. Em.Object.create({
  463. progress: 0
  464. })
  465. ])
  466. });
  467. c.setIsServicesInstalled(polledData);
  468. expect(c.get('progress')).to.equal('100');
  469. expect(c.get('isPolling')).to.be.false;
  470. });
  471. it('Should return 34% completed', function () {
  472. var polledData = Em.A([
  473. Em.Object.create({
  474. Tasks: Em.Object.create({
  475. status: 'NONE'
  476. })
  477. }),
  478. Em.Object.create({
  479. Tasks: Em.Object.create({
  480. status: 'NONE'
  481. })
  482. })
  483. ]);
  484. c.setProperties({
  485. status: '',
  486. isPolling: true,
  487. hosts: Em.A([
  488. Em.Object.create({
  489. progress: 0
  490. })
  491. ]),
  492. content: Em.Object.create({
  493. controllerName: 'installerController'
  494. })
  495. });
  496. c.setIsServicesInstalled(polledData);
  497. expect(c.get('progress')).to.equal('34');
  498. expect(c.get('isPolling')).to.be.true;
  499. });
  500. });
  501. describe('#launchStartServices', function () {
  502. beforeEach(function() {
  503. sinon.stub(App, 'get', function(k) {
  504. if (k === 'components.slaves')
  505. return ["TASKTRACKER", "DATANODE",
  506. "JOURNALNODE", "ZKFC",
  507. "APP_TIMELINE_SERVER",
  508. "NODEMANAGER",
  509. "GANGLIA_MONITOR",
  510. "HBASE_REGIONSERVER",
  511. "SUPERVISOR",
  512. "FLUME_HANDLER"];
  513. return true;
  514. });
  515. });
  516. afterEach(function() {
  517. App.get.restore();
  518. });
  519. var tests = [
  520. {
  521. expected: [],
  522. message: 'should return query',
  523. controllerName: 'addHostController',
  524. hosts: Em.A([
  525. Em.Object.create({
  526. name: 'h1'
  527. }),
  528. Em.Object.create({
  529. name: 'h2'
  530. })
  531. ])
  532. },
  533. {
  534. expected: [],
  535. text: 'should return server info',
  536. controllerName: 'addServiceController',
  537. services: Em.A([
  538. Em.Object.create({
  539. serviceName: 'OOZIE',
  540. isSelected: true,
  541. isInstalled: false
  542. }),
  543. Em.Object.create({
  544. serviceName: 'h2',
  545. isSelected: false,
  546. isInstalled: true
  547. })
  548. ])
  549. },
  550. {
  551. expected: [],
  552. text: 'should return default data',
  553. controllerName: 'addHostContro',
  554. hosts: Em.A([
  555. Em.Object.create({
  556. name: 'h1'
  557. }),
  558. Em.Object.create({
  559. name: 'h2'
  560. })
  561. ])
  562. }
  563. ];
  564. tests.forEach(function(test) {
  565. it(test.message, function () {
  566. var content = Em.Object.create({
  567. controllerName: test.controllerName,
  568. services: test.services
  569. });
  570. var wizardController = Em.Object.create({
  571. getDBProperty: function() {
  572. return test.hosts
  573. }
  574. });
  575. c.set('content', content);
  576. c.set('wizardController', wizardController);
  577. expect(c.launchStartServices(function(){})).to.be.true;
  578. });
  579. })
  580. });
  581. describe('#hostHasClientsOnly', function () {
  582. var tests = Em.A([
  583. {
  584. hosts: [
  585. Em.Object.create({
  586. hostName: 'host1',
  587. logTasks: [
  588. {Tasks: {role: 'HDFS_CLIENT'}},
  589. {Tasks: {role: 'DATANODE'}}
  590. ],
  591. status: 'old_status',
  592. progress: '10',
  593. e: {status: 'old_status', progress: '10'}
  594. }),
  595. Em.Object.create({
  596. hostName: 'host2',
  597. logTasks: [
  598. {Tasks: {role: 'HDFS_CLIENT'}}
  599. ],
  600. status: 'old_status',
  601. progress: '10',
  602. e: {status: 'success', progress: '100'}
  603. })
  604. ],
  605. jsonError: false
  606. },
  607. {
  608. hosts: [
  609. Em.Object.create({
  610. hostName: 'host1',
  611. logTasks: [
  612. {Tasks: {role: 'HDFS_CLIENT'}},
  613. {Tasks: {role: 'DATANODE'}}
  614. ],
  615. status: 'old_status',
  616. progress: '10',
  617. e: {status: 'success', progress: '100'}
  618. }),
  619. Em.Object.create({
  620. hostName: 'host2',
  621. logTasks: [
  622. {Tasks: {role: 'HDFS_CLIENT'}}
  623. ],
  624. status: 'old_status',
  625. progress: '10',
  626. e: {status: 'success', progress: '100'}
  627. })
  628. ],
  629. jsonError: true
  630. }
  631. ]);
  632. tests.forEach(function (test) {
  633. it('', function () {
  634. c.reopen({hosts: test.hosts});
  635. c.hostHasClientsOnly(test.jsonError);
  636. test.hosts.forEach(function (host) {
  637. expect(c.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  638. expect(c.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  639. });
  640. });
  641. });
  642. });
  643. describe('#onSuccessPerHost', function () {
  644. var tests = Em.A([
  645. {
  646. cluster: {status: 'INSTALLED'},
  647. host: Em.Object.create({status: 'pending'}),
  648. actions: [],
  649. e: {status: 'success'},
  650. m: 'No tasks for host'
  651. },
  652. {
  653. cluster: {status: 'INSTALLED'},
  654. host: Em.Object.create({status: 'info'}),
  655. actions: [
  656. {Tasks: {status: 'COMPLETED'}},
  657. {Tasks: {status: 'COMPLETED'}}
  658. ],
  659. e: {status: 'success'},
  660. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  661. },
  662. {
  663. cluster: {status: 'FAILED'},
  664. host: Em.Object.create({status: 'info'}),
  665. actions: [
  666. {Tasks: {status: 'COMPLETED'}},
  667. {Tasks: {status: 'COMPLETED'}}
  668. ],
  669. e: {status: 'info'},
  670. m: 'All Tasks COMPLETED and cluster status FAILED'
  671. },
  672. {
  673. cluster: {status: 'INSTALLED'},
  674. host: Em.Object.create({status: 'info'}),
  675. actions: [
  676. {Tasks: {status: 'FAILED'}},
  677. {Tasks: {status: 'COMPLETED'}}
  678. ],
  679. e: {status: 'info'},
  680. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  681. },
  682. {
  683. cluster: {status: 'FAILED'},
  684. host: Em.Object.create({status: 'info'}),
  685. actions: [
  686. {Tasks: {status: 'FAILED'}},
  687. {Tasks: {status: 'COMPLETED'}}
  688. ],
  689. e: {status: 'info'},
  690. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  691. }
  692. ]);
  693. tests.forEach(function (test) {
  694. it(test.m, function () {
  695. c.reopen({content: {cluster: {status: test.cluster.status}}});
  696. c.onSuccessPerHost(test.actions, test.host);
  697. expect(test.host.status).to.equal(test.e.status);
  698. });
  699. });
  700. });
  701. describe('#onErrorPerHost', function () {
  702. var tests = Em.A([
  703. {
  704. cluster: {status: 'INSTALLED'},
  705. host: Em.Object.create({status: 'pending'}),
  706. actions: [],
  707. e: {status: 'pending'},
  708. isMasterFailed: false,
  709. m: 'No tasks for host'
  710. },
  711. {
  712. cluster: {status: 'INSTALLED'},
  713. host: Em.Object.create({status: 'info'}),
  714. actions: [
  715. {Tasks: {status: 'FAILED'}},
  716. {Tasks: {status: 'COMPLETED'}}
  717. ],
  718. e: {status: 'warning'},
  719. isMasterFailed: false,
  720. m: 'One Task FAILED and cluster status INSTALLED'
  721. },
  722. {
  723. cluster: {status: 'INSTALLED'},
  724. host: Em.Object.create({status: 'info'}),
  725. actions: [
  726. {Tasks: {status: 'ABORTED'}},
  727. {Tasks: {status: 'COMPLETED'}}
  728. ],
  729. e: {status: 'warning'},
  730. isMasterFailed: false,
  731. m: 'One Task ABORTED and cluster status INSTALLED'
  732. },
  733. {
  734. cluster: {status: 'INSTALLED'},
  735. host: Em.Object.create({status: 'info'}),
  736. actions: [
  737. {Tasks: {status: 'TIMEDOUT'}},
  738. {Tasks: {status: 'COMPLETED'}}
  739. ],
  740. e: {status: 'warning'},
  741. isMasterFailed: false,
  742. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  743. },
  744. {
  745. cluster: {status: 'PENDING'},
  746. host: Em.Object.create({status: 'info'}),
  747. actions: [
  748. {Tasks: {status: 'FAILED'}},
  749. {Tasks: {status: 'COMPLETED'}}
  750. ],
  751. e: {status: 'failed'},
  752. isMasterFailed: true,
  753. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  754. },
  755. {
  756. cluster: {status: 'PENDING'},
  757. host: Em.Object.create({status: 'info'}),
  758. actions: [
  759. {Tasks: {status: 'COMPLETED'}},
  760. {Tasks: {status: 'COMPLETED'}}
  761. ],
  762. e: {status: 'info'},
  763. isMasterFailed: false,
  764. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  765. }
  766. ]);
  767. tests.forEach(function (test) {
  768. it(test.m, function () {
  769. c.reopen({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  770. return test.isMasterFailed;
  771. }});
  772. c.onErrorPerHost(test.actions, test.host);
  773. expect(test.host.status).to.equal(test.e.status);
  774. });
  775. });
  776. });
  777. describe('#isMasterFailed', function () {
  778. beforeEach(function() {
  779. sinon.stub(App, 'get', function(k) {
  780. if (k === 'components.slaves')
  781. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  782. return Em.get(App, k);
  783. });
  784. });
  785. afterEach(function() {
  786. App.get.restore();
  787. });
  788. var tests = Em.A([
  789. {
  790. actions: [
  791. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  792. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  793. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  794. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  795. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  796. ],
  797. e: false,
  798. m: 'No one Master is failed'
  799. },
  800. {
  801. actions: [
  802. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  803. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  804. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  805. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  806. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  807. ],
  808. e: true,
  809. m: 'One Master is failed'
  810. },
  811. {
  812. actions: [
  813. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  814. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  815. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  816. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  817. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  818. ],
  819. e: false,
  820. m: 'one Master is failed but command is not install'
  821. }
  822. ]);
  823. tests.forEach(function (test) {
  824. it(test.m, function () {
  825. expect(c.isMasterFailed(test.actions)).to.equal(test.e);
  826. });
  827. });
  828. });
  829. describe('#onInProgressPerHost', function () {
  830. var tests = Em.A([
  831. {
  832. host: Em.Object.create({message: 'default_message'}),
  833. actions: [
  834. {Tasks: {status: 'COMPLETED'}},
  835. {Tasks: {status: 'COMPLETED'}}
  836. ],
  837. e: {message: 'default_message', b: true},
  838. m: 'All Tasks COMPLETED'
  839. },
  840. {
  841. host: Em.Object.create({message: 'default_message'}),
  842. actions: [
  843. {Tasks: {status: 'IN_PROGRESS'}},
  844. {Tasks: {status: 'COMPLETED'}}
  845. ],
  846. e: {message: 'default_message', b: false},
  847. m: 'One Task IN_PROGRESS'
  848. },
  849. {
  850. host: Em.Object.create({message: 'default_message'}),
  851. actions: [
  852. {Tasks: {status: 'QUEUED'}},
  853. {Tasks: {status: 'COMPLETED'}}
  854. ],
  855. e: {message: 'default_message', b: false},
  856. m: 'One Task QUEUED'
  857. },
  858. {
  859. host: Em.Object.create({message: 'default_message'}),
  860. actions: [
  861. {Tasks: {status: 'PENDING'}},
  862. {Tasks: {status: 'COMPLETED'}}
  863. ],
  864. e: {message: 'default_message', b: false},
  865. m: 'One Task PENDING'
  866. }
  867. ]);
  868. tests.forEach(function (test) {
  869. it(test.m, function () {
  870. c.onInProgressPerHost(test.actions, test.host);
  871. expect(test.host.message == test.e.message).to.equal(test.e.b);
  872. });
  873. });
  874. });
  875. describe('#progressPerHost', function () {
  876. var tests = Em.A([
  877. {
  878. cluster: {status: 'PENDING'},
  879. host: Em.Object.create({progress: 0}),
  880. actions: {
  881. 'COMPLETED': 2,
  882. 'QUEUED': 2,
  883. 'IN_PROGRESS': 1
  884. },
  885. e: {progress: 17},
  886. m: 'All types of status available. cluster status PENDING'
  887. },
  888. {
  889. cluster: {status: 'PENDING'},
  890. host: Em.Object.create({progress: 0}),
  891. actions: {},
  892. e: {progress: 33},
  893. m: 'No tasks available. cluster status PENDING'
  894. },
  895. {
  896. cluster: {status: 'INSTALLED'},
  897. host: Em.Object.create({progress: 0}),
  898. actions: {},
  899. e: {progress: 100},
  900. m: 'No tasks available. cluster status INSTALLED'
  901. },
  902. {
  903. cluster: {status: 'INSTALLED'},
  904. host: Em.Object.create({progress: 0}),
  905. actions: {
  906. 'COMPLETED': 2,
  907. 'QUEUED': 2,
  908. 'IN_PROGRESS': 1
  909. },
  910. e: {progress: 66},
  911. m: 'All types of status available. cluster status INSTALLED'
  912. },
  913. {
  914. cluster: {status: 'FAILED'},
  915. host: Em.Object.create({progress: 0}),
  916. actions: {},
  917. e: {progress: 100},
  918. m: 'Cluster status is not PENDING or INSTALLED'
  919. },
  920. {
  921. cluster: {status: 'INSTALLED'},
  922. host: Em.Object.create({progress: 0}),
  923. actions: {
  924. 'COMPLETED': 150,
  925. 'QUEUED': 0,
  926. 'IN_PROGRESS': 1
  927. },
  928. e: {progress: 99},
  929. m: '150 tasks on host'
  930. },
  931. {
  932. cluster: {status: 'INSTALLED'},
  933. host: Em.Object.create({progress: 0}),
  934. actions: {
  935. 'COMPLETED': 498,
  936. 'QUEUED': 1,
  937. 'IN_PROGRESS': 1
  938. },
  939. e: {progress: 99},
  940. m: '500 tasks on host'
  941. },
  942. {
  943. cluster: {status: 'INSTALLED'},
  944. host: Em.Object.create({progress: 0}),
  945. actions: {
  946. 'COMPLETED': 150,
  947. 'QUEUED': 0,
  948. 'IN_PROGRESS': 0
  949. },
  950. e: {progress: 100},
  951. m: '100 tasks, 100 completed'
  952. },
  953. {
  954. cluster: {status: 'INSTALLED'},
  955. host: Em.Object.create({progress: 0}),
  956. actions: {
  957. 'COMPLETED': 1,
  958. 'QUEUED': 0,
  959. 'IN_PROGRESS': 0
  960. },
  961. e: {progress: 100},
  962. m: '1 task, 1 completed'
  963. }
  964. ]);
  965. tests.forEach(function (test) {
  966. it(test.m, function () {
  967. var actions = [];
  968. for (var prop in test.actions) {
  969. if (test.actions.hasOwnProperty(prop) && test.actions[prop]) {
  970. for (var i = 0; i < test.actions[prop]; i++) {
  971. actions.push({Tasks: {status: prop}});
  972. }
  973. }
  974. }
  975. c.reopen({content: {cluster: {status: test.cluster.status}}});
  976. var progress = c.progressPerHost(actions, test.host);
  977. expect(progress).to.equal(test.e.progress);
  978. expect(test.host.progress).to.equal(test.e.progress.toString());
  979. });
  980. });
  981. });
  982. describe('#clearStep', function () {
  983. it('All to default values', function () {
  984. c.reopen({hosts: [{},{},{}]});
  985. c.clearStep();
  986. expect(c.get('hosts.length')).to.equal(0);
  987. expect(c.get('status')).to.equal('info');
  988. expect(c.get('progress')).to.equal('0');
  989. expect(c.get('numPolls')).to.equal(1);
  990. });
  991. });
  992. describe('#replacePolledData', function () {
  993. it('replacing polled data', function () {
  994. c.reopen({polledData: [{},{},{}]});
  995. var newPolledData = [{}];
  996. c.replacePolledData(newPolledData);
  997. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  998. });
  999. });
  1000. describe('#isSuccess', function () {
  1001. var tests = Em.A([
  1002. {
  1003. polledData: [
  1004. {Tasks: {status: 'COMPLETED'}},
  1005. {Tasks: {status: 'COMPLETED'}}
  1006. ],
  1007. e: true,
  1008. m: 'All tasks are COMPLETED'
  1009. },
  1010. {
  1011. polledData: [
  1012. {Tasks: {status: 'COMPLETED'}},
  1013. {Tasks: {status: 'FAILED'}}
  1014. ],
  1015. e: false,
  1016. m: 'Not all tasks are COMPLETED'
  1017. }
  1018. ]);
  1019. tests.forEach(function (test) {
  1020. it(test.m, function () {
  1021. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  1022. });
  1023. });
  1024. });
  1025. describe('#isStepFailed', function () {
  1026. beforeEach(function() {
  1027. sinon.stub(App, 'get', function(k) {
  1028. if (k === 'components.slaves')
  1029. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  1030. return Em.get(App, k);
  1031. });
  1032. });
  1033. afterEach(function() {
  1034. App.get.restore();
  1035. });
  1036. var tests = Em.A([
  1037. {
  1038. polledData: [
  1039. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1040. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  1041. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1042. ],
  1043. e: true,
  1044. m: 'GANGLIA_MONITOR 2/3 failed'
  1045. },
  1046. {
  1047. polledData: [
  1048. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1049. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  1050. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1051. ],
  1052. e: false,
  1053. m: 'GANGLIA_MONITOR 1/3 failed'
  1054. },
  1055. {
  1056. polledData: [
  1057. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1058. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  1059. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1060. ],
  1061. e: true,
  1062. m: 'HBASE_REGIONSERVER 2/3 failed'
  1063. },
  1064. {
  1065. polledData: [
  1066. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1067. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  1068. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1069. ],
  1070. e: false,
  1071. m: 'HBASE_REGIONSERVER 1/3 failed'
  1072. },
  1073. {
  1074. polledData: [
  1075. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1076. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  1077. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1078. ],
  1079. e: true,
  1080. m: 'TASKTRACKER 2/3 failed'
  1081. },
  1082. {
  1083. polledData: [
  1084. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1085. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  1086. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1087. ],
  1088. e: false,
  1089. m: 'TASKTRACKER 1/3 failed'
  1090. },
  1091. {
  1092. polledData: [
  1093. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1094. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  1095. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1096. ],
  1097. e: true,
  1098. m: 'DATANODE 2/3 failed'
  1099. },
  1100. {
  1101. polledData: [
  1102. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1103. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1104. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1105. ],
  1106. e: false,
  1107. m: 'DATANODE 1/3 failed'
  1108. },
  1109. {
  1110. polledData: [
  1111. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  1112. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1113. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1114. ],
  1115. e: true,
  1116. m: 'NAMENODE failed'
  1117. },
  1118. {
  1119. polledData: [
  1120. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  1121. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1122. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1123. ],
  1124. e: false,
  1125. m: 'Nothing failed failed'
  1126. }
  1127. ]);
  1128. tests.forEach(function (test) {
  1129. it(test.m, function () {
  1130. c.reopen({polledData: test.polledData});
  1131. expect(c.isStepFailed()).to.equal(test.e);
  1132. });
  1133. });
  1134. });
  1135. describe('#setLogTasksStatePerHost', function () {
  1136. var tests = Em.A([
  1137. {
  1138. tasksPerHost: [
  1139. {Tasks: {id: 1, status: 'COMPLETED'}},
  1140. {Tasks: {id: 2, status: 'COMPLETED'}}
  1141. ],
  1142. tasks: [],
  1143. e: {m: 'COMPLETED', l: 2},
  1144. m: 'host didn\'t have tasks and got 2 new'
  1145. },
  1146. {
  1147. tasksPerHost: [
  1148. {Tasks: {id: 1, status: 'COMPLETED'}},
  1149. {Tasks: {id: 2, status: 'COMPLETED'}}
  1150. ],
  1151. tasks: [
  1152. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1153. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1154. ],
  1155. e: {m: 'COMPLETED', l: 2},
  1156. m: 'host had 2 tasks and got both updated'
  1157. },
  1158. {
  1159. tasksPerHost: [],
  1160. tasks: [
  1161. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1162. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1163. ],
  1164. e: {m: 'IN_PROGRESS', l: 2},
  1165. m: 'host had 2 tasks and didn\'t get updates'
  1166. },
  1167. {
  1168. tasksPerHost: [
  1169. {Tasks: {id: 1, status: 'COMPLETED'}},
  1170. {Tasks: {id: 2, status: 'COMPLETED'}},
  1171. {Tasks: {id: 3, status: 'COMPLETED'}}
  1172. ],
  1173. tasks: [
  1174. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1175. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1176. ],
  1177. e: {m: 'COMPLETED', l: 3},
  1178. m: 'host had 2 tasks and got both updated and 1 new'
  1179. }
  1180. ]);
  1181. tests.forEach(function (test) {
  1182. it(test.m, function () {
  1183. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  1184. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  1185. expect(c.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  1186. expect(c.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  1187. });
  1188. });
  1189. });
  1190. // On completion of Start all services error callback function,
  1191. // Cluster Status should be INSTALL FAILED
  1192. // All progress bar on the screen should be finished (100%) with blue color.
  1193. // Retry button should be enabled, next button should be disabled
  1194. describe('#launchStartServicesErrorCallback', function () {
  1195. beforeEach(function() {
  1196. sinon.stub(App, 'get', function(k) {
  1197. if ('testMode' === k) return true;
  1198. return Em.get(App, k);
  1199. });
  1200. });
  1201. afterEach(function() {
  1202. App.get.restore();
  1203. });
  1204. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1205. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1206. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1207. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1208. expect(c.get('progress')).to.equal('100');
  1209. expect(c.get('status')).to.equal('failed');
  1210. });
  1211. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1212. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1213. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1214. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1215. c.get('hosts').forEach(function (host) {
  1216. expect(host.get('progress')).to.equal('100');
  1217. expect(host.get('status')).to.equal('info');
  1218. });
  1219. });
  1220. it('Next button should be disabled', function () {
  1221. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1222. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1223. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1224. expect(c.get('isSubmitDisabled')).to.equal(true);
  1225. });
  1226. });
  1227. describe('#submit', function () {
  1228. it('should call App.router.send', function () {
  1229. sinon.stub(App.router, 'send', Em.K);
  1230. c.submit();
  1231. expect(App.router.send.calledWith('next')).to.equal(true);
  1232. App.router.send.restore();
  1233. });
  1234. });
  1235. describe('#back', function () {
  1236. beforeEach(function () {
  1237. sinon.stub(App.router, 'send', Em.K);
  1238. });
  1239. afterEach(function () {
  1240. App.router.send.restore();
  1241. });
  1242. it('should call App.router.send', function () {
  1243. c.reopen({isSubmitDisabled: false});
  1244. c.back();
  1245. expect(App.router.send.calledWith('back')).to.equal(true);
  1246. });
  1247. it('shouldn\'t call App.router.send', function () {
  1248. c.reopen({isSubmitDisabled: true});
  1249. c.back();
  1250. expect(App.router.send.called).to.equal(false);
  1251. });
  1252. });
  1253. describe('#loadStep', function () {
  1254. beforeEach(function () {
  1255. sinon.stub(c, 'clearStep', Em.K);
  1256. sinon.stub(c, 'loadHosts', Em.K);
  1257. });
  1258. afterEach(function () {
  1259. c.clearStep.restore();
  1260. c.loadHosts.restore();
  1261. });
  1262. it('should call clearStep', function () {
  1263. c.loadStep();
  1264. expect(c.clearStep.calledOnce).to.equal(true);
  1265. });
  1266. it('should call loadHosts', function () {
  1267. c.loadStep();
  1268. expect(c.loadHosts.calledOnce).to.equal(true);
  1269. });
  1270. });
  1271. describe('#startPolling', function () {
  1272. beforeEach(function () {
  1273. sinon.stub(c, 'reloadErrorCallback', Em.K);
  1274. });
  1275. afterEach(function () {
  1276. c.reloadErrorCallback.restore();
  1277. });
  1278. it('should set isSubmitDisabled to true', function () {
  1279. c.set('isSubmitDisabled', false);
  1280. c.startPolling();
  1281. expect(c.get('isSubmitDisabled')).to.equal(true);
  1282. });
  1283. it('should call doPolling', function () {
  1284. sinon.stub(c, 'doPolling', Em.K);
  1285. c.startPolling();
  1286. expect(c.doPolling.calledOnce).to.equal(true);
  1287. c.doPolling.restore();
  1288. });
  1289. });
  1290. describe('#loadLogData', function () {
  1291. beforeEach(function () {
  1292. obj.reopen({
  1293. cluster: {oldRequestsId: [1,2,3]},
  1294. getDBProperty: function (name) {
  1295. return this.get(name);
  1296. }
  1297. });
  1298. c.reopen({wizardController: obj});
  1299. sinon.stub(c, 'getLogsByRequest', Em.K);
  1300. });
  1301. afterEach(function () {
  1302. c.getLogsByRequest.restore();
  1303. });
  1304. it('should call getLogsByRequest 1 time with 3', function () {
  1305. c.loadLogData(true);
  1306. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  1307. });
  1308. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  1309. sinon.stub(App, 'get', function(k) { if ('testMode' === k) return true; return Em.get(App, k);});
  1310. c.loadLogData();
  1311. expect(c.get('POLL_INTERVAL')).to.equal(1);
  1312. App.get.restore();
  1313. });
  1314. });
  1315. describe('#loadCurrentTaskLog', function () {
  1316. beforeEach(function () {
  1317. sinon.stub(c, 'loadLogData', Em.K);
  1318. c.set('wizardController', Em.Object.create({
  1319. getDBProperty: Em.K
  1320. }));
  1321. });
  1322. afterEach(function () {
  1323. c.loadLogData.restore();
  1324. });
  1325. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1326. c.set('currentOpenTaskId', null);
  1327. c.loadCurrentTaskLog();
  1328. expect(App.ajax.send.called).to.equal(false);
  1329. });
  1330. it('should call App.ajax.send with provided data', function () {
  1331. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1332. c.set('currentOpenTaskId', 1);
  1333. c.set('currentOpenTaskRequestId', 2);
  1334. c.set('content', {cluster: {name: 3}});
  1335. c.loadCurrentTaskLog();
  1336. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3});
  1337. c.togglePreviousSteps.restore();
  1338. });
  1339. });
  1340. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1341. beforeEach(function() {
  1342. sinon.stub(c, 'getLogsByRequest', Em.K);
  1343. sinon.stub(c, 'loadLogData', Em.K);
  1344. });
  1345. afterEach(function() {
  1346. c.getLogsByRequest.restore();
  1347. c.loadLogData.restore();
  1348. });
  1349. it('should increment logTasksChangesCounter', function () {
  1350. c.set('logTasksChangesCounter', 0);
  1351. c.loadCurrentTaskLogSuccessCallback();
  1352. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1353. });
  1354. it('should update stdout, stderr', function () {
  1355. c.set('currentOpenTaskId', 1);
  1356. c.reopen({
  1357. hosts: [
  1358. Em.Object.create({
  1359. name: 'h1',
  1360. logTasks: [
  1361. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1362. ]
  1363. })
  1364. ]
  1365. });
  1366. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1367. c.loadCurrentTaskLogSuccessCallback(data);
  1368. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1369. expect(t.stdout).to.equal('stdout');
  1370. expect(t.stderr).to.equal('stderr');
  1371. });
  1372. it('shouldn\'t update stdout, stderr', function () {
  1373. c.set('currentOpenTaskId', 1);
  1374. c.reopen({
  1375. hosts: [
  1376. Em.Object.create({
  1377. name: 'h1',
  1378. logTasks: [
  1379. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1380. ]
  1381. })
  1382. ]
  1383. });
  1384. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1385. c.loadCurrentTaskLogSuccessCallback(data);
  1386. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1387. expect(t.stdout).to.equal('');
  1388. expect(t.stderr).to.equal('');
  1389. });
  1390. it('shouldn\'t update stdout, stderr (2)', function () {
  1391. c.set('currentOpenTaskId', 1);
  1392. c.reopen({
  1393. hosts: [
  1394. Em.Object.create({
  1395. name: 'h2',
  1396. logTasks: [
  1397. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1398. ]
  1399. })
  1400. ]
  1401. });
  1402. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1403. c.loadCurrentTaskLogSuccessCallback(data);
  1404. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1405. expect(t.stdout).to.equal('');
  1406. expect(t.stderr).to.equal('');
  1407. });
  1408. });
  1409. describe('#loadCurrentTaskLogErrorCallback', function () {
  1410. it('should set currentOpenTaskId to 0', function () {
  1411. c.set('currentOpenTaskId', 123);
  1412. c.loadCurrentTaskLogErrorCallback();
  1413. expect(c.get('currentOpenTaskId')).to.equal(0);
  1414. });
  1415. });
  1416. describe('#doPolling', function () {
  1417. beforeEach(function () {
  1418. sinon.stub(c, 'getLogsByRequest', Em.K);
  1419. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1420. });
  1421. afterEach(function () {
  1422. c.getLogsByRequest.restore();
  1423. c.togglePreviousSteps.restore();
  1424. });
  1425. it('should increment numPolls if testMode', function () {
  1426. App.set('testMode', true);
  1427. c.set('numPolls', 0);
  1428. c.doPolling();
  1429. expect(c.get('numPolls')).to.equal(1);
  1430. App.set('testMode', false);
  1431. });
  1432. it('should call getLogsByRequest', function () {
  1433. c.set('content', {cluster: {requestId: 1}});
  1434. c.doPolling();
  1435. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1436. });
  1437. });
  1438. describe('#isAllComponentsInstalledErrorCallback', function () {
  1439. beforeEach(function () {
  1440. sinon.stub(c, 'saveClusterStatus', Em.K);
  1441. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1442. });
  1443. afterEach(function () {
  1444. c.saveClusterStatus.restore();
  1445. c.togglePreviousSteps.restore();
  1446. });
  1447. it('should call saveClusterStatus', function () {
  1448. c.isAllComponentsInstalledErrorCallback({});
  1449. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1450. });
  1451. });
  1452. describe('#navigateStep', function () {
  1453. beforeEach(function () {
  1454. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1455. sinon.stub(c, 'loadStep', Em.K);
  1456. sinon.stub(c, 'loadLogData', Em.K);
  1457. sinon.stub(c, 'startPolling', Em.K);
  1458. });
  1459. afterEach(function () {
  1460. c.togglePreviousSteps.restore();
  1461. c.loadStep.restore();
  1462. c.loadLogData.restore();
  1463. c.startPolling.restore();
  1464. App.get.restore();
  1465. });
  1466. it('should set custom data in testMode', function () {
  1467. sinon.stub(App, 'get', function(k) {if('testMode' === k) return true; return Em.get(App, k);});
  1468. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1469. c.navigateStep();
  1470. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1471. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1472. expect(c.get('content.cluster.requestId')).to.equal(1);
  1473. });
  1474. it('isCompleted = true, requestId = 1', function () {
  1475. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1476. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1477. c.navigateStep();
  1478. expect(c.loadStep.calledOnce).to.equal(true);
  1479. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1480. expect(c.get('progress')).to.equal('100');
  1481. });
  1482. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1483. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1484. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1485. c.navigateStep();
  1486. expect(c.loadStep.calledOnce).to.equal(true);
  1487. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1488. });
  1489. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1490. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1491. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1492. c.navigateStep();
  1493. expect(c.loadStep.calledOnce).to.equal(true);
  1494. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1495. });
  1496. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1497. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1498. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1499. c.navigateStep();
  1500. expect(c.loadStep.calledOnce).to.equal(true);
  1501. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1502. });
  1503. });
  1504. describe('#launchStartServicesSuccessCallback', function () {
  1505. beforeEach(function () {
  1506. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1507. return $.ajax();
  1508. });
  1509. sinon.stub(c, 'saveClusterStatus', Em.K);
  1510. sinon.stub(c, 'doPolling', Em.K);
  1511. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1512. });
  1513. afterEach(function () {
  1514. c.saveClusterStatus.restore();
  1515. c.doPolling.restore();
  1516. c.hostHasClientsOnly.restore();
  1517. App.clusterStatus.setClusterStatus.restore();
  1518. });
  1519. it('should call doPolling if some data were received', function () {
  1520. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1521. expect(c.doPolling.calledOnce).to.equal(true);
  1522. });
  1523. Em.A([
  1524. {
  1525. jsonData: {Requests: {id: 2}},
  1526. e: {
  1527. hostHasClientsOnly: false,
  1528. clusterStatus: {
  1529. status: 'INSTALLED',
  1530. requestId: 2,
  1531. isStartError: false,
  1532. isCompleted: false
  1533. }
  1534. }
  1535. },
  1536. {
  1537. jsonData: null,
  1538. e: {
  1539. hostHasClientsOnly: true,
  1540. clusterStatus: {
  1541. status: 'STARTED',
  1542. isStartError: false,
  1543. isCompleted: true
  1544. },
  1545. status: 'success',
  1546. progress: '100'
  1547. }
  1548. }
  1549. ]).forEach(function (test) {
  1550. it(test.m, function () {
  1551. c.launchStartServicesSuccessCallback(test.jsonData);
  1552. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1553. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1554. if (test.e.status) {
  1555. expect(c.get('status')).to.equal(test.e.status);
  1556. }
  1557. if (test.e.progress) {
  1558. expect(c.get('progress')).to.equal(test.e.progress);
  1559. }
  1560. });
  1561. });
  1562. });
  1563. });