step9_test.js 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585
  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. {Tasks: {status: 'COMPLETED'}},
  882. {Tasks: {status: 'COMPLETED'}},
  883. {Tasks: {status: 'QUEUED'}},
  884. {Tasks: {status: 'QUEUED'}},
  885. {Tasks: {status: 'IN_PROGRESS'}}
  886. ],
  887. e: {ret: 17, host: '17'},
  888. m: 'All types of status available. cluster status PENDING'
  889. },
  890. {
  891. cluster: {status: 'PENDING'},
  892. host: Em.Object.create({progress: 0}),
  893. actions: [],
  894. e: {ret: 33, host: '33'},
  895. m: 'No tasks available. cluster status PENDING'
  896. },
  897. {
  898. cluster: {status: 'INSTALLED'},
  899. host: Em.Object.create({progress: 0}),
  900. actions: [],
  901. e: {ret: 100, host: '100'},
  902. m: 'No tasks available. cluster status INSTALLED'
  903. },
  904. {
  905. cluster: {status: 'INSTALLED'},
  906. host: Em.Object.create({progress: 0}),
  907. actions: [
  908. {Tasks: {status: 'COMPLETED'}},
  909. {Tasks: {status: 'COMPLETED'}},
  910. {Tasks: {status: 'QUEUED'}},
  911. {Tasks: {status: 'QUEUED'}},
  912. {Tasks: {status: 'IN_PROGRESS'}}
  913. ],
  914. e: {ret: 68, host: '68'},
  915. m: 'All types of status available. cluster status INSTALLED'
  916. },
  917. {
  918. cluster: {status: 'FAILED'},
  919. host: Em.Object.create({progress: 0}),
  920. actions: [],
  921. e: {ret: 100, host: '100'},
  922. m: 'Cluster status is not PENDING or INSTALLED'
  923. }
  924. ]);
  925. tests.forEach(function (test) {
  926. it(test.m, function () {
  927. c.reopen({content: {cluster: {status: test.cluster.status}}});
  928. var progress = c.progressPerHost(test.actions, test.host);
  929. expect(progress).to.equal(test.e.ret);
  930. expect(test.host.progress).to.equal(test.e.host);
  931. });
  932. });
  933. });
  934. describe('#clearStep', function () {
  935. it('All to default values', function () {
  936. c.reopen({hosts: [{},{},{}]});
  937. c.clearStep();
  938. expect(c.get('hosts.length')).to.equal(0);
  939. expect(c.get('status')).to.equal('info');
  940. expect(c.get('progress')).to.equal('0');
  941. expect(c.get('numPolls')).to.equal(1);
  942. });
  943. });
  944. describe('#replacePolledData', function () {
  945. it('replacing polled data', function () {
  946. c.reopen({polledData: [{},{},{}]});
  947. var newPolledData = [{}];
  948. c.replacePolledData(newPolledData);
  949. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  950. });
  951. });
  952. describe('#isSuccess', function () {
  953. var tests = Em.A([
  954. {
  955. polledData: [
  956. {Tasks: {status: 'COMPLETED'}},
  957. {Tasks: {status: 'COMPLETED'}}
  958. ],
  959. e: true,
  960. m: 'All tasks are COMPLETED'
  961. },
  962. {
  963. polledData: [
  964. {Tasks: {status: 'COMPLETED'}},
  965. {Tasks: {status: 'FAILED'}}
  966. ],
  967. e: false,
  968. m: 'Not all tasks are COMPLETED'
  969. }
  970. ]);
  971. tests.forEach(function (test) {
  972. it(test.m, function () {
  973. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  974. });
  975. });
  976. });
  977. describe('#isStepFailed', function () {
  978. beforeEach(function() {
  979. sinon.stub(App, 'get', function(k) {
  980. if (k === 'components.slaves')
  981. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  982. return Em.get(App, k);
  983. });
  984. });
  985. afterEach(function() {
  986. App.get.restore();
  987. });
  988. var tests = Em.A([
  989. {
  990. polledData: [
  991. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  992. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  993. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  994. ],
  995. e: true,
  996. m: 'GANGLIA_MONITOR 2/3 failed'
  997. },
  998. {
  999. polledData: [
  1000. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1001. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  1002. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1003. ],
  1004. e: false,
  1005. m: 'GANGLIA_MONITOR 1/3 failed'
  1006. },
  1007. {
  1008. polledData: [
  1009. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1010. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  1011. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1012. ],
  1013. e: true,
  1014. m: 'HBASE_REGIONSERVER 2/3 failed'
  1015. },
  1016. {
  1017. polledData: [
  1018. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1019. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  1020. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1021. ],
  1022. e: false,
  1023. m: 'HBASE_REGIONSERVER 1/3 failed'
  1024. },
  1025. {
  1026. polledData: [
  1027. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1028. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  1029. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1030. ],
  1031. e: true,
  1032. m: 'TASKTRACKER 2/3 failed'
  1033. },
  1034. {
  1035. polledData: [
  1036. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1037. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  1038. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1039. ],
  1040. e: false,
  1041. m: 'TASKTRACKER 1/3 failed'
  1042. },
  1043. {
  1044. polledData: [
  1045. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1046. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  1047. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1048. ],
  1049. e: true,
  1050. m: 'DATANODE 2/3 failed'
  1051. },
  1052. {
  1053. polledData: [
  1054. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1055. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1056. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1057. ],
  1058. e: false,
  1059. m: 'DATANODE 1/3 failed'
  1060. },
  1061. {
  1062. polledData: [
  1063. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  1064. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1065. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1066. ],
  1067. e: true,
  1068. m: 'NAMENODE failed'
  1069. },
  1070. {
  1071. polledData: [
  1072. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  1073. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1074. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1075. ],
  1076. e: false,
  1077. m: 'Nothing failed failed'
  1078. }
  1079. ]);
  1080. tests.forEach(function (test) {
  1081. it(test.m, function () {
  1082. c.reopen({polledData: test.polledData});
  1083. expect(c.isStepFailed()).to.equal(test.e);
  1084. });
  1085. });
  1086. });
  1087. describe('#setLogTasksStatePerHost', function () {
  1088. var tests = Em.A([
  1089. {
  1090. tasksPerHost: [
  1091. {Tasks: {id: 1, status: 'COMPLETED'}},
  1092. {Tasks: {id: 2, status: 'COMPLETED'}}
  1093. ],
  1094. tasks: [],
  1095. e: {m: 'COMPLETED', l: 2},
  1096. m: 'host didn\'t have tasks and got 2 new'
  1097. },
  1098. {
  1099. tasksPerHost: [
  1100. {Tasks: {id: 1, status: 'COMPLETED'}},
  1101. {Tasks: {id: 2, status: 'COMPLETED'}}
  1102. ],
  1103. tasks: [
  1104. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1105. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1106. ],
  1107. e: {m: 'COMPLETED', l: 2},
  1108. m: 'host had 2 tasks and got both updated'
  1109. },
  1110. {
  1111. tasksPerHost: [],
  1112. tasks: [
  1113. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1114. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1115. ],
  1116. e: {m: 'IN_PROGRESS', l: 2},
  1117. m: 'host had 2 tasks and didn\'t get updates'
  1118. },
  1119. {
  1120. tasksPerHost: [
  1121. {Tasks: {id: 1, status: 'COMPLETED'}},
  1122. {Tasks: {id: 2, status: 'COMPLETED'}},
  1123. {Tasks: {id: 3, status: 'COMPLETED'}}
  1124. ],
  1125. tasks: [
  1126. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1127. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1128. ],
  1129. e: {m: 'COMPLETED', l: 3},
  1130. m: 'host had 2 tasks and got both updated and 1 new'
  1131. }
  1132. ]);
  1133. tests.forEach(function (test) {
  1134. it(test.m, function () {
  1135. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  1136. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  1137. expect(c.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  1138. expect(c.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  1139. });
  1140. });
  1141. });
  1142. // On completion of Start all services error callback function,
  1143. // Cluster Status should be INSTALL FAILED
  1144. // All progress bar on the screen should be finished (100%) with blue color.
  1145. // Retry button should be enabled, next button should be disabled
  1146. describe('#launchStartServicesErrorCallback', function () {
  1147. beforeEach(function() {
  1148. sinon.stub(App, 'get', function(k) {
  1149. if ('testMode' === k) return true;
  1150. return Em.get(App, k);
  1151. });
  1152. });
  1153. afterEach(function() {
  1154. App.get.restore();
  1155. });
  1156. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1157. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1158. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1159. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1160. expect(c.get('progress')).to.equal('100');
  1161. expect(c.get('status')).to.equal('failed');
  1162. });
  1163. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1164. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1165. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1166. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1167. c.get('hosts').forEach(function (host) {
  1168. expect(host.get('progress')).to.equal('100');
  1169. expect(host.get('status')).to.equal('info');
  1170. });
  1171. });
  1172. it('Next button should be disabled', function () {
  1173. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1174. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1175. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1176. expect(c.get('isSubmitDisabled')).to.equal(true);
  1177. });
  1178. });
  1179. describe('#submit', function () {
  1180. it('should call App.router.send', function () {
  1181. sinon.stub(App.router, 'send', Em.K);
  1182. c.submit();
  1183. expect(App.router.send.calledWith('next')).to.equal(true);
  1184. App.router.send.restore();
  1185. });
  1186. });
  1187. describe('#back', function () {
  1188. beforeEach(function () {
  1189. sinon.stub(App.router, 'send', Em.K);
  1190. });
  1191. afterEach(function () {
  1192. App.router.send.restore();
  1193. });
  1194. it('should call App.router.send', function () {
  1195. c.reopen({isSubmitDisabled: false});
  1196. c.back();
  1197. expect(App.router.send.calledWith('back')).to.equal(true);
  1198. });
  1199. it('shouldn\'t call App.router.send', function () {
  1200. c.reopen({isSubmitDisabled: true});
  1201. c.back();
  1202. expect(App.router.send.called).to.equal(false);
  1203. });
  1204. });
  1205. describe('#loadStep', function () {
  1206. beforeEach(function () {
  1207. sinon.stub(c, 'clearStep', Em.K);
  1208. sinon.stub(c, 'loadHosts', Em.K);
  1209. });
  1210. afterEach(function () {
  1211. c.clearStep.restore();
  1212. c.loadHosts.restore();
  1213. });
  1214. it('should call clearStep', function () {
  1215. c.loadStep();
  1216. expect(c.clearStep.calledOnce).to.equal(true);
  1217. });
  1218. it('should call loadHosts', function () {
  1219. c.loadStep();
  1220. expect(c.loadHosts.calledOnce).to.equal(true);
  1221. });
  1222. });
  1223. describe('#startPolling', function () {
  1224. beforeEach(function () {
  1225. sinon.stub(c, 'getLogsByRequestErrorCallback', Em.K);
  1226. });
  1227. afterEach(function () {
  1228. c.getLogsByRequestErrorCallback.restore();
  1229. });
  1230. it('should set isSubmitDisabled to true', function () {
  1231. c.set('isSubmitDisabled', false);
  1232. c.startPolling();
  1233. expect(c.get('isSubmitDisabled')).to.equal(true);
  1234. });
  1235. it('should call doPolling', function () {
  1236. sinon.stub(c, 'doPolling', Em.K);
  1237. c.startPolling();
  1238. expect(c.doPolling.calledOnce).to.equal(true);
  1239. c.doPolling.restore();
  1240. });
  1241. });
  1242. describe('#loadLogData', function () {
  1243. beforeEach(function () {
  1244. obj.reopen({
  1245. cluster: {oldRequestsId: [1,2,3]},
  1246. getDBProperty: function (name) {
  1247. return this.get(name);
  1248. }
  1249. });
  1250. c.reopen({wizardController: obj});
  1251. sinon.stub(c, 'getLogsByRequest', Em.K);
  1252. });
  1253. afterEach(function () {
  1254. c.getLogsByRequest.restore();
  1255. });
  1256. it('should call getLogsByRequest 1 time with 3', function () {
  1257. c.loadLogData(true);
  1258. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  1259. });
  1260. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  1261. sinon.stub(App, 'get', function(k) { if ('testMode' === k) return true; return Em.get(App, k);});
  1262. c.loadLogData();
  1263. expect(c.get('POLL_INTERVAL')).to.equal(1);
  1264. App.get.restore();
  1265. });
  1266. });
  1267. describe('#loadCurrentTaskLog', function () {
  1268. beforeEach(function () {
  1269. sinon.stub(c, 'loadLogData', Em.K);
  1270. c.set('wizardController', Em.Object.create({
  1271. getDBProperty: Em.K
  1272. }));
  1273. });
  1274. afterEach(function () {
  1275. c.loadLogData.restore();
  1276. });
  1277. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1278. c.set('currentOpenTaskId', null);
  1279. c.loadCurrentTaskLog();
  1280. expect(App.ajax.send.called).to.equal(false);
  1281. });
  1282. it('should call App.ajax.send with provided data', function () {
  1283. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1284. c.set('currentOpenTaskId', 1);
  1285. c.set('currentOpenTaskRequestId', 2);
  1286. c.set('content', {cluster: {name: 3}});
  1287. c.loadCurrentTaskLog();
  1288. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3});
  1289. c.togglePreviousSteps.restore();
  1290. });
  1291. });
  1292. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1293. beforeEach(function() {
  1294. sinon.stub(c, 'getLogsByRequest', Em.K);
  1295. sinon.stub(c, 'loadLogData', Em.K);
  1296. });
  1297. afterEach(function() {
  1298. c.getLogsByRequest.restore();
  1299. c.loadLogData.restore();
  1300. });
  1301. it('should increment logTasksChangesCounter', function () {
  1302. c.set('logTasksChangesCounter', 0);
  1303. c.loadCurrentTaskLogSuccessCallback();
  1304. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1305. });
  1306. it('should update stdout, stderr', function () {
  1307. c.set('currentOpenTaskId', 1);
  1308. c.reopen({
  1309. hosts: [
  1310. Em.Object.create({
  1311. name: 'h1',
  1312. logTasks: [
  1313. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1314. ]
  1315. })
  1316. ]
  1317. });
  1318. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1319. c.loadCurrentTaskLogSuccessCallback(data);
  1320. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1321. expect(t.stdout).to.equal('stdout');
  1322. expect(t.stderr).to.equal('stderr');
  1323. });
  1324. it('shouldn\'t update stdout, stderr', function () {
  1325. c.set('currentOpenTaskId', 1);
  1326. c.reopen({
  1327. hosts: [
  1328. Em.Object.create({
  1329. name: 'h1',
  1330. logTasks: [
  1331. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1332. ]
  1333. })
  1334. ]
  1335. });
  1336. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1337. c.loadCurrentTaskLogSuccessCallback(data);
  1338. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1339. expect(t.stdout).to.equal('');
  1340. expect(t.stderr).to.equal('');
  1341. });
  1342. it('shouldn\'t update stdout, stderr (2)', function () {
  1343. c.set('currentOpenTaskId', 1);
  1344. c.reopen({
  1345. hosts: [
  1346. Em.Object.create({
  1347. name: 'h2',
  1348. logTasks: [
  1349. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1350. ]
  1351. })
  1352. ]
  1353. });
  1354. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1355. c.loadCurrentTaskLogSuccessCallback(data);
  1356. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1357. expect(t.stdout).to.equal('');
  1358. expect(t.stderr).to.equal('');
  1359. });
  1360. });
  1361. describe('#loadCurrentTaskLogErrorCallback', function () {
  1362. it('should set currentOpenTaskId to 0', function () {
  1363. c.set('currentOpenTaskId', 123);
  1364. c.loadCurrentTaskLogErrorCallback();
  1365. expect(c.get('currentOpenTaskId')).to.equal(0);
  1366. });
  1367. });
  1368. describe('#doPolling', function () {
  1369. beforeEach(function () {
  1370. sinon.stub(c, 'getLogsByRequest', Em.K);
  1371. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1372. });
  1373. afterEach(function () {
  1374. c.getLogsByRequest.restore();
  1375. c.togglePreviousSteps.restore();
  1376. });
  1377. it('should increment numPolls if testMode', function () {
  1378. App.set('testMode', true);
  1379. c.set('numPolls', 0);
  1380. c.doPolling();
  1381. expect(c.get('numPolls')).to.equal(1);
  1382. App.set('testMode', false);
  1383. });
  1384. it('should call getLogsByRequest', function () {
  1385. c.set('content', {cluster: {requestId: 1}});
  1386. c.doPolling();
  1387. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1388. });
  1389. });
  1390. describe('#isAllComponentsInstalledErrorCallback', function () {
  1391. beforeEach(function () {
  1392. sinon.stub(c, 'saveClusterStatus', Em.K);
  1393. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1394. });
  1395. afterEach(function () {
  1396. c.saveClusterStatus.restore();
  1397. c.togglePreviousSteps.restore();
  1398. });
  1399. it('should call saveClusterStatus', function () {
  1400. c.isAllComponentsInstalledErrorCallback({});
  1401. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1402. });
  1403. });
  1404. describe('#navigateStep', function () {
  1405. beforeEach(function () {
  1406. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1407. sinon.stub(c, 'loadStep', Em.K);
  1408. sinon.stub(c, 'loadLogData', Em.K);
  1409. sinon.stub(c, 'startPolling', Em.K);
  1410. });
  1411. afterEach(function () {
  1412. c.togglePreviousSteps.restore();
  1413. c.loadStep.restore();
  1414. c.loadLogData.restore();
  1415. c.startPolling.restore();
  1416. App.get.restore();
  1417. });
  1418. it('should set custom data in testMode', function () {
  1419. sinon.stub(App, 'get', function(k) {if('testMode' === k) return true; return Em.get(App, k);});
  1420. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1421. c.navigateStep();
  1422. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1423. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1424. expect(c.get('content.cluster.requestId')).to.equal(1);
  1425. });
  1426. it('isCompleted = true, requestId = 1', function () {
  1427. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1428. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1429. c.navigateStep();
  1430. expect(c.loadStep.calledOnce).to.equal(true);
  1431. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1432. expect(c.get('progress')).to.equal('100');
  1433. });
  1434. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1435. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1436. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1437. c.navigateStep();
  1438. expect(c.loadStep.calledOnce).to.equal(true);
  1439. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1440. });
  1441. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1442. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1443. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1444. c.navigateStep();
  1445. expect(c.loadStep.calledOnce).to.equal(true);
  1446. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1447. });
  1448. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1449. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1450. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1451. c.navigateStep();
  1452. expect(c.loadStep.calledOnce).to.equal(true);
  1453. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1454. });
  1455. });
  1456. describe('#launchStartServicesSuccessCallback', function () {
  1457. beforeEach(function () {
  1458. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1459. return $.ajax();
  1460. });
  1461. sinon.stub(c, 'saveClusterStatus', Em.K);
  1462. sinon.stub(c, 'doPolling', Em.K);
  1463. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1464. });
  1465. afterEach(function () {
  1466. c.saveClusterStatus.restore();
  1467. c.doPolling.restore();
  1468. c.hostHasClientsOnly.restore();
  1469. App.clusterStatus.setClusterStatus.restore();
  1470. });
  1471. it('should call doPolling if some data were received', function () {
  1472. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1473. expect(c.doPolling.calledOnce).to.equal(true);
  1474. });
  1475. Em.A([
  1476. {
  1477. jsonData: {Requests: {id: 2}},
  1478. e: {
  1479. hostHasClientsOnly: false,
  1480. clusterStatus: {
  1481. status: 'INSTALLED',
  1482. requestId: 2,
  1483. isStartError: false,
  1484. isCompleted: false
  1485. }
  1486. }
  1487. },
  1488. {
  1489. jsonData: null,
  1490. e: {
  1491. hostHasClientsOnly: true,
  1492. clusterStatus: {
  1493. status: 'STARTED',
  1494. isStartError: false,
  1495. isCompleted: true
  1496. },
  1497. status: 'success',
  1498. progress: '100'
  1499. }
  1500. }
  1501. ]).forEach(function (test) {
  1502. it(test.m, function () {
  1503. c.launchStartServicesSuccessCallback(test.jsonData);
  1504. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1505. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1506. if (test.e.status) {
  1507. expect(c.get('status')).to.equal(test.e.status);
  1508. }
  1509. if (test.e.progress) {
  1510. expect(c.get('progress')).to.equal(test.e.progress);
  1511. }
  1512. });
  1513. });
  1514. });
  1515. });