step9_test.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979
  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/step9_controller');
  23. require('utils/helper');
  24. var modelSetup = require('test/init_model_test');
  25. var c, obj;
  26. describe('App.InstallerStep9Controller', function () {
  27. beforeEach(function () {
  28. modelSetup.setupStackServiceComponent();
  29. c = App.WizardStep9Controller.create();
  30. obj = App.InstallerController.create();
  31. });
  32. afterEach(function () {
  33. modelSetup.cleanStackServiceComponent();
  34. });
  35. describe('#isSubmitDisabled', function () {
  36. var tests = Em.A([
  37. {controllerName: 'addHostController', state: 'STARTED', e: false},
  38. {controllerName: 'addHostController', state: 'START FAILED', e: false},
  39. {controllerName: 'addHostController', state: 'INSTALL FAILED', e: false},
  40. {controllerName: 'addHostController', state: 'PENDING', e: true},
  41. {controllerName: 'addHostController', state: 'INSTALLED', e: true},
  42. {controllerName: 'addServiceController', state: 'STARTED', e: false},
  43. {controllerName: 'addServiceController', state: 'START FAILED', e: false},
  44. {controllerName: 'addServiceController', state: 'INSTALL FAILED', e: false},
  45. {controllerName: 'addServiceController', state: 'PENDING', e: true},
  46. {controllerName: 'addServiceController', state: 'INSTALLED', e: true},
  47. {controllerName: 'installerController', state: 'STARTED', e: false},
  48. {controllerName: 'installerController', state: 'START FAILED', e: false},
  49. {controllerName: 'installerController', state: 'INSTALL FAILED', e: true},
  50. {controllerName: 'installerController', state: 'INSTALLED', e: true},
  51. {controllerName: 'installerController', state: 'PENDING', e: true}
  52. ]);
  53. tests.forEach(function (test) {
  54. var controller = App.WizardStep9Controller.create({
  55. content: {
  56. controllerName: test.controllerName,
  57. cluster: {
  58. status: test.state
  59. }
  60. }
  61. });
  62. it('controllerName is ' + test.controllerName + '; cluster status is ' + test.state + '; isSubmitDisabled should be ' + test.e, function () {
  63. expect(controller.get('isSubmitDisabled')).to.equal(test.e);
  64. });
  65. });
  66. });
  67. describe('#status', function () {
  68. var tests = Em.A([
  69. {
  70. hosts: [
  71. {status: 'failed'},
  72. {status: 'success'}
  73. ],
  74. isStepFailed: false,
  75. progress: '100',
  76. m: 'One host is failed',
  77. e: 'failed'
  78. },
  79. {
  80. hosts: [
  81. {status: 'warning'},
  82. {status: 'success'}
  83. ],
  84. m: 'One host is failed and step is not failed',
  85. isStepFailed: false,
  86. progress: '100',
  87. e: 'warning'
  88. },
  89. {
  90. hosts: [
  91. {status: 'warning'},
  92. {status: 'success'}
  93. ],
  94. m: 'One host is failed and step is failed',
  95. isStepFailed: true,
  96. progress: '100',
  97. e: 'failed'
  98. },
  99. {
  100. hosts: [
  101. {status: 'success'},
  102. {status: 'success'}
  103. ],
  104. m: 'All hosts are success and progress is 100',
  105. isStepFailed: false,
  106. progress: '100',
  107. e: 'success'
  108. },
  109. {
  110. hosts: [
  111. {status: 'success'},
  112. {status: 'success'}
  113. ],
  114. m: 'All hosts are success and progress is 50',
  115. isStepFailed: false,
  116. progress: '50',
  117. e: 'info'
  118. }
  119. ]);
  120. tests.forEach(function (test) {
  121. var controller = App.WizardStep9Controller.create({hosts: test.hosts, isStepFailed: function () {
  122. return test.isStepFailed
  123. }, progress: test.progress});
  124. controller.updateStatus();
  125. it(test.m, function () {
  126. expect(controller.get('status')).to.equal(test.e);
  127. });
  128. });
  129. });
  130. describe('#showRetry', function () {
  131. it('cluster status is not INSTALL FAILED', function () {
  132. var controller = App.WizardStep9Controller.create({content: {cluster: {status: 'INSTALLED'}}});
  133. expect(controller.get('showRetry')).to.equal(false);
  134. });
  135. it('cluster status is INSTALL FAILED', function () {
  136. var controller = App.WizardStep9Controller.create({content: {cluster: {status: 'INSTALL FAILED'}}});
  137. expect(controller.get('showRetry')).to.equal(true);
  138. });
  139. });
  140. describe('#resetHostsForRetry', function () {
  141. var hosts = {'host1': Em.Object.create({status: 'failed', message: 'Failed'}), 'host2': Em.Object.create({status: 'success', message: 'Success'})};
  142. var controller = App.WizardStep9Controller.create({content: {hosts: hosts}});
  143. it('All should have status "pending" and message "Waiting"', function () {
  144. controller.resetHostsForRetry();
  145. for (var name in hosts) {
  146. if (hosts.hasOwnProperty(name)) {
  147. expect(controller.get('content.hosts')[name].get('status', 'pending')).to.equal('pending');
  148. expect(controller.get('content.hosts')[name].get('message', 'Waiting')).to.equal('Waiting');
  149. }
  150. }
  151. });
  152. });
  153. var hosts_for_load_and_render = {
  154. 'host1': {
  155. message: 'message1',
  156. status: 'unknown',
  157. progress: '1',
  158. logTasks: [
  159. {},
  160. {}
  161. ],
  162. bootStatus: 'REGISTERED'
  163. },
  164. 'host2': {
  165. message: '',
  166. status: 'failed',
  167. progress: '1',
  168. logTasks: [
  169. {},
  170. {}
  171. ],
  172. bootStatus: ''
  173. },
  174. 'host3': {
  175. message: '',
  176. status: 'waiting',
  177. progress: null,
  178. logTasks: [
  179. {},
  180. {}
  181. ],
  182. bootStatus: ''
  183. },
  184. 'host4': {
  185. message: 'message4',
  186. status: null,
  187. progress: '10',
  188. logTasks: [
  189. {}
  190. ],
  191. bootStatus: 'REGISTERED'
  192. }
  193. };
  194. describe('#loadHosts', function () {
  195. var controller = App.WizardStep9Controller.create({content: {hosts: hosts_for_load_and_render}});
  196. controller.loadHosts();
  197. var loaded_hosts = controller.get('hosts');
  198. it('Only REGISTERED hosts', function () {
  199. expect(loaded_hosts.length).to.equal(2);
  200. });
  201. it('All hosts have progress 0', function () {
  202. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  203. });
  204. it('All hosts have progress 0', function () {
  205. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  206. });
  207. it('All host don\'t have logTasks', function () {
  208. expect(loaded_hosts.everyProperty('logTasks.length', 0)).to.equal(true);
  209. });
  210. });
  211. describe('#hostHasClientsOnly', function () {
  212. var tests = Em.A([
  213. {
  214. hosts: [
  215. Em.Object.create({
  216. hostName: 'host1',
  217. logTasks: [
  218. {Tasks: {role: 'HDFS_CLIENT'}},
  219. {Tasks: {role: 'DATANODE'}}
  220. ],
  221. status: 'old_status',
  222. progress: '10',
  223. e: {status: 'old_status', progress: '10'}
  224. }),
  225. Em.Object.create({
  226. hostName: 'host2',
  227. logTasks: [
  228. {Tasks: {role: 'HDFS_CLIENT'}}
  229. ],
  230. status: 'old_status',
  231. progress: '10',
  232. e: {status: 'success', progress: '100'}
  233. })
  234. ],
  235. jsonError: false
  236. },
  237. {
  238. hosts: [
  239. Em.Object.create({
  240. hostName: 'host1',
  241. logTasks: [
  242. {Tasks: {role: 'HDFS_CLIENT'}},
  243. {Tasks: {role: 'DATANODE'}}
  244. ],
  245. status: 'old_status',
  246. progress: '10',
  247. e: {status: 'success', progress: '100'}
  248. }),
  249. Em.Object.create({
  250. hostName: 'host2',
  251. logTasks: [
  252. {Tasks: {role: 'HDFS_CLIENT'}}
  253. ],
  254. status: 'old_status',
  255. progress: '10',
  256. e: {status: 'success', progress: '100'}
  257. })
  258. ],
  259. jsonError: true
  260. }
  261. ]);
  262. tests.forEach(function (test) {
  263. it('', function () {
  264. var controller = App.WizardStep9Controller.create({hosts: test.hosts});
  265. controller.hostHasClientsOnly(test.jsonError);
  266. test.hosts.forEach(function (host) {
  267. expect(controller.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  268. expect(controller.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  269. });
  270. });
  271. });
  272. });
  273. describe('#onSuccessPerHost', function () {
  274. var tests = Em.A([
  275. {
  276. cluster: {status: 'INSTALLED'},
  277. host: Em.Object.create({status: 'pending'}),
  278. actions: [],
  279. e: {status: 'success'},
  280. m: 'No tasks for host'
  281. },
  282. {
  283. cluster: {status: 'INSTALLED'},
  284. host: Em.Object.create({status: 'info'}),
  285. actions: [
  286. {Tasks: {status: 'COMPLETED'}},
  287. {Tasks: {status: 'COMPLETED'}}
  288. ],
  289. e: {status: 'success'},
  290. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  291. },
  292. {
  293. cluster: {status: 'FAILED'},
  294. host: Em.Object.create({status: 'info'}),
  295. actions: [
  296. {Tasks: {status: 'COMPLETED'}},
  297. {Tasks: {status: 'COMPLETED'}}
  298. ],
  299. e: {status: 'info'},
  300. m: 'All Tasks COMPLETED and cluster status FAILED'
  301. },
  302. {
  303. cluster: {status: 'INSTALLED'},
  304. host: Em.Object.create({status: 'info'}),
  305. actions: [
  306. {Tasks: {status: 'FAILED'}},
  307. {Tasks: {status: 'COMPLETED'}}
  308. ],
  309. e: {status: 'info'},
  310. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  311. },
  312. {
  313. cluster: {status: 'FAILED'},
  314. host: Em.Object.create({status: 'info'}),
  315. actions: [
  316. {Tasks: {status: 'FAILED'}},
  317. {Tasks: {status: 'COMPLETED'}}
  318. ],
  319. e: {status: 'info'},
  320. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  321. }
  322. ]);
  323. tests.forEach(function (test) {
  324. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}});
  325. controller.onSuccessPerHost(test.actions, test.host);
  326. it(test.m, function () {
  327. expect(test.host.status).to.equal(test.e.status);
  328. });
  329. });
  330. });
  331. describe('#onErrorPerHost', function () {
  332. var tests = Em.A([
  333. {
  334. cluster: {status: 'INSTALLED'},
  335. host: Em.Object.create({status: 'pending'}),
  336. actions: [],
  337. e: {status: 'pending'},
  338. isMasterFailed: false,
  339. m: 'No tasks for host'
  340. },
  341. {
  342. cluster: {status: 'INSTALLED'},
  343. host: Em.Object.create({status: 'info'}),
  344. actions: [
  345. {Tasks: {status: 'FAILED'}},
  346. {Tasks: {status: 'COMPLETED'}}
  347. ],
  348. e: {status: 'warning'},
  349. isMasterFailed: false,
  350. m: 'One Task FAILED and cluster status INSTALLED'
  351. },
  352. {
  353. cluster: {status: 'INSTALLED'},
  354. host: Em.Object.create({status: 'info'}),
  355. actions: [
  356. {Tasks: {status: 'ABORTED'}},
  357. {Tasks: {status: 'COMPLETED'}}
  358. ],
  359. e: {status: 'warning'},
  360. isMasterFailed: false,
  361. m: 'One Task ABORTED and cluster status INSTALLED'
  362. },
  363. {
  364. cluster: {status: 'INSTALLED'},
  365. host: Em.Object.create({status: 'info'}),
  366. actions: [
  367. {Tasks: {status: 'TIMEDOUT'}},
  368. {Tasks: {status: 'COMPLETED'}}
  369. ],
  370. e: {status: 'warning'},
  371. isMasterFailed: false,
  372. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  373. },
  374. {
  375. cluster: {status: 'PENDING'},
  376. host: Em.Object.create({status: 'info'}),
  377. actions: [
  378. {Tasks: {status: 'FAILED'}},
  379. {Tasks: {status: 'COMPLETED'}}
  380. ],
  381. e: {status: 'failed'},
  382. isMasterFailed: true,
  383. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  384. },
  385. {
  386. cluster: {status: 'PENDING'},
  387. host: Em.Object.create({status: 'info'}),
  388. actions: [
  389. {Tasks: {status: 'COMPLETED'}},
  390. {Tasks: {status: 'COMPLETED'}}
  391. ],
  392. e: {status: 'info'},
  393. isMasterFailed: false,
  394. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  395. }
  396. ]);
  397. tests.forEach(function (test) {
  398. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  399. return test.isMasterFailed;
  400. }});
  401. controller.onErrorPerHost(test.actions, test.host);
  402. it(test.m, function () {
  403. expect(test.host.status).to.equal(test.e.status);
  404. });
  405. });
  406. });
  407. describe('#isMasterFailed', function () {
  408. var tests = Em.A([
  409. {
  410. actions: [
  411. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  412. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  413. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  414. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  415. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  416. ],
  417. e: false,
  418. m: 'No one Master is failed'
  419. },
  420. {
  421. actions: [
  422. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  423. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  424. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  425. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  426. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  427. ],
  428. e: true,
  429. m: 'One Master is failed'
  430. },
  431. {
  432. actions: [
  433. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  434. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  435. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  436. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  437. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  438. ],
  439. e: false,
  440. m: 'one Master is failed but command is not install'
  441. }
  442. ]);
  443. tests.forEach(function (test) {
  444. it(test.m, function () {
  445. var controller = App.WizardStep9Controller.create();
  446. expect(controller.isMasterFailed(test.actions)).to.equal(test.e);
  447. });
  448. });
  449. });
  450. describe('#onInProgressPerHost', function () {
  451. var tests = Em.A([
  452. {
  453. host: Em.Object.create({message: 'default_message'}),
  454. actions: [
  455. {Tasks: {status: 'COMPLETED'}},
  456. {Tasks: {status: 'COMPLETED'}}
  457. ],
  458. e: {message: 'default_message', b: true},
  459. m: 'All Tasks COMPLETED'
  460. },
  461. {
  462. host: Em.Object.create({message: 'default_message'}),
  463. actions: [
  464. {Tasks: {status: 'IN_PROGRESS'}},
  465. {Tasks: {status: 'COMPLETED'}}
  466. ],
  467. e: {message: 'default_message', b: false},
  468. m: 'One Task IN_PROGRESS'
  469. },
  470. {
  471. host: Em.Object.create({message: 'default_message'}),
  472. actions: [
  473. {Tasks: {status: 'QUEUED'}},
  474. {Tasks: {status: 'COMPLETED'}}
  475. ],
  476. e: {message: 'default_message', b: false},
  477. m: 'One Task QUEUED'
  478. },
  479. {
  480. host: Em.Object.create({message: 'default_message'}),
  481. actions: [
  482. {Tasks: {status: 'PENDING'}},
  483. {Tasks: {status: 'COMPLETED'}}
  484. ],
  485. e: {message: 'default_message', b: false},
  486. m: 'One Task PENDING'
  487. }
  488. ]);
  489. tests.forEach(function (test) {
  490. it(test.m, function () {
  491. var controller = App.WizardStep9Controller.create();
  492. controller.onInProgressPerHost(test.actions, test.host);
  493. expect(test.host.message == test.e.message).to.equal(test.e.b);
  494. });
  495. });
  496. });
  497. describe('#progressPerHost', function () {
  498. var tests = Em.A([
  499. {
  500. cluster: {status: 'PENDING'},
  501. host: Em.Object.create({progress: 0}),
  502. actions: [
  503. {Tasks: {status: 'COMPLETED'}},
  504. {Tasks: {status: 'COMPLETED'}},
  505. {Tasks: {status: 'QUEUED'}},
  506. {Tasks: {status: 'QUEUED'}},
  507. {Tasks: {status: 'IN_PROGRESS'}}
  508. ],
  509. e: {ret: 17, host: '17'},
  510. m: 'All types of status available. cluster status PENDING'
  511. },
  512. {
  513. cluster: {status: 'PENDING'},
  514. host: Em.Object.create({progress: 0}),
  515. actions: [],
  516. e: {ret: 33, host: '33'},
  517. m: 'No tasks available. cluster status PENDING'
  518. },
  519. {
  520. cluster: {status: 'INSTALLED'},
  521. host: Em.Object.create({progress: 0}),
  522. actions: [],
  523. e: {ret: 100, host: '100'},
  524. m: 'No tasks available. cluster status INSTALLED'
  525. },
  526. {
  527. cluster: {status: 'INSTALLED'},
  528. host: Em.Object.create({progress: 0}),
  529. actions: [
  530. {Tasks: {status: 'COMPLETED'}},
  531. {Tasks: {status: 'COMPLETED'}},
  532. {Tasks: {status: 'QUEUED'}},
  533. {Tasks: {status: 'QUEUED'}},
  534. {Tasks: {status: 'IN_PROGRESS'}}
  535. ],
  536. e: {ret: 68, host: '68'},
  537. m: 'All types of status available. cluster status INSTALLED'
  538. },
  539. {
  540. cluster: {status: 'FAILED'},
  541. host: Em.Object.create({progress: 0}),
  542. actions: [],
  543. e: {ret: 100, host: '100'},
  544. m: 'Cluster status is not PENDING or INSTALLED'
  545. }
  546. ]);
  547. tests.forEach(function (test) {
  548. it(test.m, function () {
  549. var controller = App.WizardStep9Controller.create({content: {cluster: {status: test.cluster.status}}});
  550. var progress = controller.progressPerHost(test.actions, test.host);
  551. expect(progress).to.equal(test.e.ret);
  552. expect(test.host.progress).to.equal(test.e.host);
  553. });
  554. });
  555. });
  556. describe('#clearStep', function () {
  557. var controller = App.WizardStep9Controller.create({hosts: [
  558. {},
  559. {},
  560. {}
  561. ]});
  562. it('All to default values', function () {
  563. controller.clearStep();
  564. expect(controller.get('hosts.length')).to.equal(0);
  565. expect(controller.get('status')).to.equal('info');
  566. expect(controller.get('progress')).to.equal('0');
  567. expect(controller.get('numPolls')).to.equal(1);
  568. });
  569. });
  570. describe('#replacePolledData', function () {
  571. var controller = App.WizardStep9Controller.create({polledData: [
  572. {},
  573. {},
  574. {}
  575. ]});
  576. var newPolledData = [
  577. {}
  578. ];
  579. controller.replacePolledData(newPolledData);
  580. it('replacing polled data', function () {
  581. expect(controller.get('polledData.length')).to.equal(newPolledData.length);
  582. });
  583. });
  584. describe('#isSuccess', function () {
  585. var tests = Em.A([
  586. {
  587. polledData: [
  588. {Tasks: {status: 'COMPLETED'}},
  589. {Tasks: {status: 'COMPLETED'}}
  590. ],
  591. e: true,
  592. m: 'All tasks are COMPLETED'
  593. },
  594. {
  595. polledData: [
  596. {Tasks: {status: 'COMPLETED'}},
  597. {Tasks: {status: 'FAILED'}}
  598. ],
  599. e: false,
  600. m: 'Not all tasks are COMPLETED'
  601. }
  602. ]);
  603. tests.forEach(function (test) {
  604. it(test.m, function () {
  605. var controller = App.WizardStep9Controller.create();
  606. expect(controller.isSuccess(test.polledData)).to.equal(test.e);
  607. });
  608. });
  609. });
  610. describe('#isStepFailed', function () {
  611. var tests = Em.A([
  612. {
  613. polledData: [
  614. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  615. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  616. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  617. ],
  618. e: true,
  619. m: 'GANGLIA_MONITOR 2/3 failed'
  620. },
  621. {
  622. polledData: [
  623. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  624. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  625. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  626. ],
  627. e: false,
  628. m: 'GANGLIA_MONITOR 1/3 failed'
  629. },
  630. {
  631. polledData: [
  632. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  633. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  634. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  635. ],
  636. e: true,
  637. m: 'HBASE_REGIONSERVER 2/3 failed'
  638. },
  639. {
  640. polledData: [
  641. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  642. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  643. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  644. ],
  645. e: false,
  646. m: 'HBASE_REGIONSERVER 1/3 failed'
  647. },
  648. {
  649. polledData: [
  650. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  651. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  652. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  653. ],
  654. e: true,
  655. m: 'TASKTRACKER 2/3 failed'
  656. },
  657. {
  658. polledData: [
  659. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  660. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  661. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  662. ],
  663. e: false,
  664. m: 'TASKTRACKER 1/3 failed'
  665. },
  666. {
  667. polledData: [
  668. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  669. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  670. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  671. ],
  672. e: true,
  673. m: 'DATANODE 2/3 failed'
  674. },
  675. {
  676. polledData: [
  677. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  678. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  679. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  680. ],
  681. e: false,
  682. m: 'DATANODE 1/3 failed'
  683. },
  684. {
  685. polledData: [
  686. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  687. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  688. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  689. ],
  690. e: true,
  691. m: 'NAMENODE failed'
  692. },
  693. {
  694. polledData: [
  695. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  696. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  697. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  698. ],
  699. e: false,
  700. m: 'Nothing failed failed'
  701. }
  702. ]);
  703. tests.forEach(function (test) {
  704. var controller = App.WizardStep9Controller.create({polledData: test.polledData});
  705. it(test.m, function () {
  706. expect(controller.isStepFailed()).to.equal(test.e);
  707. });
  708. });
  709. });
  710. describe('#finishState', function () {
  711. var statuses = Em.A(['INSTALL FAILED', 'START FAILED', 'STARTED']);
  712. it('Installer is finished', function () {
  713. statuses.forEach(function (status) {
  714. var controller = App.WizardStep9Controller.create({content: {cluster: {status: status}}});
  715. var result = controller.finishState();
  716. expect(result).to.equal(true);
  717. });
  718. });
  719. it('Unknown cluster status ', function () {
  720. var controller = App.WizardStep9Controller.create({content: {cluster: {status: 'FAKE_STATUS'}}});
  721. var result = controller.finishState();
  722. expect(result).to.equal(false);
  723. });
  724. it('for INSTALLED status should call isServicesStarted', function () {
  725. sinon.stub(c, 'togglePreviousSteps', Em.K);
  726. c.set('content', {cluster: {status: 'INSTALLED'}});
  727. var polledData = {'{}': {}};
  728. sinon.stub(c, 'isServicesStarted', Em.K);
  729. c.finishState(polledData);
  730. expect(c.isServicesStarted.calledWith(polledData)).to.equal(true);
  731. c.isServicesStarted.restore();
  732. c.togglePreviousSteps.restore();
  733. });
  734. it('for PENDING status should call isServicesInstalled', function () {
  735. sinon.stub(c, 'togglePreviousSteps', Em.K);
  736. c.set('content', {cluster: {status: 'PENDING'}});
  737. var polledData = {'{}': {}};
  738. sinon.stub(c, 'isServicesInstalled', Em.K);
  739. c.finishState(polledData);
  740. expect(c.isServicesInstalled.calledWith(polledData)).to.equal(true);
  741. c.isServicesInstalled.restore();
  742. c.togglePreviousSteps.restore();
  743. });
  744. });
  745. describe('#setLogTasksStatePerHost', function () {
  746. var tests = Em.A([
  747. {
  748. tasksPerHost: [
  749. {Tasks: {id: 1, status: 'COMPLETED'}},
  750. {Tasks: {id: 2, status: 'COMPLETED'}}
  751. ],
  752. tasks: [],
  753. e: {m: 'COMPLETED', l: 2},
  754. m: 'host didn\'t have tasks and got 2 new'
  755. },
  756. {
  757. tasksPerHost: [
  758. {Tasks: {id: 1, status: 'COMPLETED'}},
  759. {Tasks: {id: 2, status: 'COMPLETED'}}
  760. ],
  761. tasks: [
  762. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  763. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  764. ],
  765. e: {m: 'COMPLETED', l: 2},
  766. m: 'host had 2 tasks and got both updated'
  767. },
  768. {
  769. tasksPerHost: [],
  770. tasks: [
  771. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  772. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  773. ],
  774. e: {m: 'IN_PROGRESS', l: 2},
  775. m: 'host had 2 tasks and didn\'t get updates'
  776. },
  777. {
  778. tasksPerHost: [
  779. {Tasks: {id: 1, status: 'COMPLETED'}},
  780. {Tasks: {id: 2, status: 'COMPLETED'}},
  781. {Tasks: {id: 3, status: 'COMPLETED'}}
  782. ],
  783. tasks: [
  784. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  785. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  786. ],
  787. e: {m: 'COMPLETED', l: 3},
  788. m: 'host had 2 tasks and got both updated and 1 new'
  789. }
  790. ]);
  791. tests.forEach(function (test) {
  792. it(test.m, function () {
  793. var controller = App.WizardStep9Controller.create({hosts: [Em.Object.create({logTasks: test.tasks})]});
  794. controller.setLogTasksStatePerHost(test.tasksPerHost, controller.get('hosts')[0]);
  795. expect(controller.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  796. expect(controller.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  797. });
  798. });
  799. });
  800. describe('#parseHostInfo', function () {
  801. var tests = Em.A([
  802. {
  803. cluster: {status: 'PENDING'},
  804. hosts: Em.A([
  805. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  806. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  807. ]),
  808. polledData: {
  809. tasks: [
  810. {Tasks: {host_name: 'host2', status: 'COMPLETED'}},
  811. {Tasks: {host_name: 'host2', status: 'COMPLETED'}}
  812. ]
  813. },
  814. e: {
  815. hosts: {
  816. host1: {progress: '33'},
  817. host2: {progress: '33'}
  818. },
  819. progress: '33'
  820. },
  821. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is PENDING'
  822. },
  823. {
  824. cluster: {status: 'PENDING'},
  825. hosts: Em.A([
  826. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  827. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  828. ]),
  829. polledData: {
  830. tasks: [
  831. {Tasks: {host_name: 'host1', status: 'IN_PROGRESS'}},
  832. {Tasks: {host_name: 'host2', status: 'IN_PROGRESS'}}
  833. ]
  834. },
  835. e: {hosts: {host1: {progress: '12'}, host2: {progress: '12'}}, progress: '12'},
  836. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is PENDING'
  837. },
  838. {
  839. cluster: {status: 'PENDING'},
  840. hosts: Em.A([
  841. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  842. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  843. ]),
  844. polledData: {
  845. tasks: [
  846. {Tasks: {host_name: 'host1', status: 'QUEUED'}},
  847. {Tasks: {host_name: 'host2', status: 'QUEUED'}}
  848. ]
  849. },
  850. e: {
  851. hosts: {
  852. host1: {progress: '3'},
  853. host2: {progress: '3'}
  854. },
  855. progress: '3'
  856. },
  857. m: 'Two hosts. Each host has one task QUEUED. Cluster status is PENDING'
  858. },
  859. {
  860. cluster: {status: 'INSTALLED'},
  861. hosts: Em.A([
  862. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  863. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  864. ]),
  865. polledData: {
  866. tasks: [
  867. {Tasks: {host_name: 'host2', status: 'COMPLETED'}},
  868. {Tasks: {host_name: 'host2', status: 'COMPLETED'}}
  869. ]
  870. },
  871. e: {
  872. hosts: {
  873. host1: {progress: '100'},
  874. host2: {progress: '100'}
  875. },
  876. progress: '100'
  877. },
  878. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is INSTALLED'
  879. },
  880. {
  881. cluster: {status: 'INSTALLED'},
  882. hosts: Em.A([
  883. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  884. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  885. ]),
  886. polledData: {
  887. tasks: [
  888. {Tasks: {host_name: 'host1', status: 'IN_PROGRESS'}},
  889. {Tasks: {host_name: 'host2', status: 'IN_PROGRESS'}}
  890. ]
  891. },
  892. e: {
  893. hosts: {
  894. host1: {progress: '58'},
  895. host2: {progress: '58'}
  896. },
  897. progress: '58'
  898. },
  899. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is INSTALLED'
  900. },
  901. {
  902. cluster: {status: 'INSTALLED'},
  903. hosts: Em.A([
  904. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  905. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  906. ]),
  907. polledData: {
  908. tasks: [
  909. {Tasks: {host_name: 'host1', status: 'QUEUED'}},
  910. {Tasks: {host_name: 'host2', status: 'QUEUED'}}
  911. ]
  912. },
  913. e: {
  914. hosts: {
  915. host1: {progress: '40'},
  916. host2: {progress: '40'}
  917. },
  918. progress: '40'
  919. },
  920. m: 'Two hosts. Each host has one task QUEUED. Cluster status is INSTALLED'
  921. }
  922. ]);
  923. tests.forEach(function (test) {
  924. it(test.m, function () {
  925. var controller = App.WizardStep9Controller.create({hosts: test.hosts, content: {cluster: {status: test.cluster.status}}, finishState: function () {
  926. return false;
  927. }});
  928. var logTasksChangesCounter = controller.get('logTasksChangesCounter');
  929. controller.parseHostInfo(test.polledData);
  930. expect(controller.get('logTasksChangesCounter')).to.equal(logTasksChangesCounter + 1);
  931. for (var name in test.e.hosts) {
  932. if (test.e.hosts.hasOwnProperty(name)) {
  933. expect(controller.get('hosts').findProperty('name', name).get('progress')).to.equal(test.e.hosts[name].progress);
  934. }
  935. }
  936. expect(controller.get('progress')).to.equal(test.e.progress);
  937. });
  938. });
  939. it('shouldn\'t do nothing if polledData.Requests.id != requestId', function () {
  940. sinon.stub(c, 'togglePreviousSteps', Em.K);
  941. c.set('content', {cluster: {requestId: 1}});
  942. var polledData = {Requests: {id: 2}, tasks: []};
  943. sinon.spy(c, 'finishState');
  944. expect(c.parseHostInfo(polledData)).to.equal(false);
  945. expect(c.finishState.called).to.equal(false);
  946. c.finishState.restore();
  947. c.togglePreviousSteps.restore();
  948. });
  949. });
  950. describe('#isAllComponentsInstalledSuccessCallback', function () {
  951. describe('', function () {
  952. var hosts = Em.A([
  953. Em.Object.create({name: 'host1', status: 'failed', expectedStatus: 'heartbeat_lost'}),
  954. Em.Object.create({name: 'host2', status: 'info', expectedStatus: 'heartbeat_lost'}),
  955. Em.Object.create({name: 'host3', status: 'warning', expectedStatus: 'warning'}),
  956. Em.Object.create({name: 'host4', status: 'info', expectedStatus: 'info'})
  957. ]);
  958. var heartbeatLostData = {
  959. "items": [
  960. {
  961. "Hosts": {
  962. "cluster_name": "c1",
  963. "host_name": "host1",
  964. "host_state": "HEARTBEAT_LOST"
  965. },
  966. "host_components": [
  967. {
  968. "HostRoles": {
  969. "cluster_name": "c1",
  970. "component_name": "NAMENODE",
  971. "host_name": "host1",
  972. "state": "INSTALL_FAILED"
  973. }
  974. }
  975. ]
  976. },
  977. {
  978. "Hosts": {
  979. "cluster_name": "c1",
  980. "host_name": "host2",
  981. "host_state": "HEARTBEAT_LOST"
  982. },
  983. "host_components": [
  984. {
  985. "HostRoles": {
  986. "cluster_name": "c1",
  987. "component_name": "ZOOKEEPER_SERVER",
  988. "host_name": "host2",
  989. "state": "UNKNOWN"
  990. }
  991. }
  992. ]
  993. },
  994. {
  995. "Hosts": {
  996. "cluster_name": "c1",
  997. "host_name": "host3",
  998. "host_state": "HEALTHY"
  999. },
  1000. "host_components": [
  1001. {
  1002. "HostRoles": {
  1003. "cluster_name": "c1",
  1004. "component_name": "DATANODE",
  1005. "host_name": "host3",
  1006. "state": "INSTALL_FAILED"
  1007. }
  1008. }
  1009. ]
  1010. },
  1011. {
  1012. "Hosts": {
  1013. "cluster_name": "c1",
  1014. "host_name": "host4",
  1015. "host_state": "HEALTHY"
  1016. },
  1017. "host_components": [
  1018. {
  1019. "HostRoles": {
  1020. "cluster_name": "c1",
  1021. "component_name": "PIG",
  1022. "host_name": "host4",
  1023. "state": "INSTALLED"
  1024. }
  1025. },
  1026. {
  1027. "HostRoles": {
  1028. "cluster_name": "c1",
  1029. "component_name": "DATANODE",
  1030. "host_name": "host3",
  1031. "state": "INSTALLED"
  1032. }
  1033. }
  1034. ]
  1035. }
  1036. ]
  1037. };
  1038. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController'}});
  1039. App.testMode = true;
  1040. // Action
  1041. controller.isAllComponentsInstalledSuccessCallback(heartbeatLostData);
  1042. // Validation for the status of all hosts.
  1043. controller.get('hosts').forEach(function (test) {
  1044. var status = heartbeatLostData.items.findProperty('Hosts.host_name', test.get('name')).Hosts.host_state;
  1045. it('Host "' + test.get('name') + '"' + ' with status "' + status + '" ', function () {
  1046. expect(test.get('status')).to.equal(test.get('expectedStatus'));
  1047. });
  1048. });
  1049. });
  1050. describe('', function () {
  1051. var noHeartbeatLostData = {
  1052. "items": [
  1053. {
  1054. "Hosts": {
  1055. "cluster_name": "c1",
  1056. "host_name": "host1",
  1057. "host_state": "HEALTHY"
  1058. },
  1059. "host_components": [
  1060. {
  1061. "HostRoles": {
  1062. "cluster_name": "c1",
  1063. "component_name": "NAMENODE",
  1064. "host_name": "host1",
  1065. "state": "INSTALL_FAILED"
  1066. }
  1067. }
  1068. ]
  1069. }
  1070. ]
  1071. };
  1072. var hosts = Em.A([Em.Object.create({name: 'host1', status: 'failed'})]);
  1073. // When there is no heartbeat lost for any host and cluster failed install task, Refreshing the page should not launch start all services request.
  1074. // Below transitions are possibilities in this function
  1075. // PENDING -> INSTALL or PENDING. This transition happens when install all services request is completed successfully.
  1076. // INSTALL FAILED -> INSTALL FAILED. No transition should happen when install all services request fails and then user hits refresh
  1077. // Cluster is not expected to enter this function in other states: INSTALLED, START FAILED, STARTED
  1078. var statuses = Em.A(['INSTALL FAILED', 'INSTALLED', 'START FAILED', 'STARTED']); // Cluster in any of this states should have no effect on the state from this function
  1079. statuses.forEach(function (priorStatus) {
  1080. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: priorStatus}}, togglePreviousSteps: function () {
  1081. }});
  1082. // Action
  1083. controller.isAllComponentsInstalledSuccessCallback(noHeartbeatLostData);
  1084. // Validation for the cluster state.
  1085. var actualStatus = controller.get('content.cluster.status');
  1086. it('Cluster state before entering the function "' + priorStatus + '"', function () {
  1087. expect(actualStatus).to.equal(priorStatus);
  1088. });
  1089. });
  1090. });
  1091. });
  1092. // isServicesInstalled is called after every poll for "Install All Services" request.
  1093. // This function should result into a call to "Start All Services" request only if install request completed successfully.
  1094. describe('#isServicesInstalled', function () {
  1095. var hostStateJsonData = {
  1096. "items": [
  1097. {
  1098. "Hosts": {
  1099. "cluster_name": "c1",
  1100. "host_name": "ambari-1.c.apache.internal",
  1101. "host_state": "HEALTHY"
  1102. },
  1103. "host_components": [
  1104. {
  1105. "HostRoles": {
  1106. "cluster_name": "c1",
  1107. "component_name": "GANGLIA_MONITOR",
  1108. "host_name": "ambari-1.c.apache.internal",
  1109. "state": "STARTED"
  1110. }
  1111. }
  1112. ]
  1113. }
  1114. ]
  1115. };
  1116. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}),
  1117. Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1118. // polledData has all hosts with status completed to trigger transition from install->start request.
  1119. var polledData = Em.A([Em.Object.create({Tasks: {name: 'host1', status: 'COMPLETED'}}),
  1120. Em.Object.create({Tasks: {name: 'host2', status: 'COMPLETED'}})]);
  1121. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController',
  1122. cluster: {status: 'PENDING', name: 'c1'}}, launchStartServices: function () {
  1123. return true;
  1124. }});
  1125. var tests = Em.A([
  1126. // controller has "status" value as "info" initially. If no errors are encountered then wizard stages
  1127. // transition info->success, on error info->error, on warning info->warning
  1128. {status: 'info', e: {startServicesCalled: true}, m: 'If no failed tasks then start services request should be called'},
  1129. {status: 'failed', e: {startServicesCalled: false}, m: 'If install request has failed tasks then start services call should not be called'}
  1130. ]);
  1131. beforeEach(function () {
  1132. App.testMode = true;
  1133. sinon.spy(controller, 'launchStartServices');
  1134. sinon.stub($, 'ajax').yieldsTo('success', hostStateJsonData);
  1135. });
  1136. afterEach(function () {
  1137. App.testMode = false;
  1138. controller.launchStartServices.restore();
  1139. $.ajax.restore();
  1140. });
  1141. tests.forEach(function (test) {
  1142. it(test.m, function () {
  1143. controller.set('status', test.status);
  1144. //Action
  1145. controller.isServicesInstalled(polledData);
  1146. //Validation
  1147. expect(controller.launchStartServices.called).to.equal(test.e.startServicesCalled);
  1148. });
  1149. });
  1150. });
  1151. // On completion of Start all services error callback function,
  1152. // Cluster Status should be INSTALL FAILED
  1153. // All progress bar on the screen should be finished (100%) with blue color.
  1154. // Retry button should be enabled, next button should be disabled
  1155. describe('#launchStartServicesErrorCallback', function () {
  1156. App.testMode = true;
  1157. // override the actual function
  1158. App.popup = {
  1159. setErrorPopup: function () {
  1160. return true;
  1161. }
  1162. };
  1163. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1164. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}, togglePreviousSteps: function () {
  1165. }});
  1166. //Action
  1167. controller.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1168. it('Cluster Status should be INSTALL FAILED', function () {
  1169. expect(controller.get('content.cluster.status')).to.equal('INSTALL FAILED');
  1170. });
  1171. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1172. expect(controller.get('progress')).to.equal('100');
  1173. expect(controller.get('status')).to.equal('failed');
  1174. });
  1175. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1176. controller.get('hosts').forEach(function (host) {
  1177. expect(host.get('progress')).to.equal('100');
  1178. expect(host.get('status')).to.equal('info');
  1179. });
  1180. });
  1181. it('Next button should be disabled', function () {
  1182. expect(controller.get('isSubmitDisabled')).to.equal(true);
  1183. });
  1184. it('Retry button should be visible', function () {
  1185. expect(controller.get('showRetry')).to.equal(true);
  1186. })
  1187. });
  1188. describe('#submit', function () {
  1189. it('should call App.router.send', function () {
  1190. sinon.stub(App.router, 'send', Em.K);
  1191. c.submit();
  1192. expect(App.router.send.calledWith('next')).to.equal(true);
  1193. App.router.send.restore();
  1194. });
  1195. });
  1196. describe('#back', function () {
  1197. beforeEach(function () {
  1198. sinon.stub(App.router, 'send', Em.K);
  1199. });
  1200. afterEach(function () {
  1201. App.router.send.restore();
  1202. });
  1203. it('should call App.router.send', function () {
  1204. c.reopen({isSubmitDisabled: false});
  1205. c.back();
  1206. expect(App.router.send.calledWith('back')).to.equal(true);
  1207. });
  1208. it('shouldn\'t call App.router.send', function () {
  1209. c.reopen({isSubmitDisabled: true});
  1210. c.back();
  1211. expect(App.router.send.called).to.equal(false);
  1212. });
  1213. });
  1214. describe('#loadStep', function () {
  1215. beforeEach(function () {
  1216. sinon.stub(c, 'clearStep', Em.K);
  1217. sinon.stub(c, 'loadHosts', Em.K);
  1218. });
  1219. afterEach(function () {
  1220. c.clearStep.restore();
  1221. c.loadHosts.restore();
  1222. });
  1223. it('should call clearStep', function () {
  1224. c.loadStep();
  1225. expect(c.clearStep.calledOnce).to.equal(true);
  1226. });
  1227. it('should call loadHosts', function () {
  1228. c.loadStep();
  1229. expect(c.loadHosts.calledOnce).to.equal(true);
  1230. });
  1231. });
  1232. describe('#startPolling', function () {
  1233. beforeEach(function () {
  1234. sinon.stub(c, 'getLogsByRequestErrorCallback', Em.K);
  1235. });
  1236. afterEach(function () {
  1237. c.getLogsByRequestErrorCallback.restore();
  1238. });
  1239. it('should set isSubmitDisabled to true', function () {
  1240. c.set('isSubmitDisabled', false);
  1241. c.startPolling();
  1242. expect(c.get('isSubmitDisabled')).to.equal(true);
  1243. });
  1244. it('should call doPolling', function () {
  1245. sinon.stub(c, 'doPolling', Em.K);
  1246. c.startPolling();
  1247. expect(c.doPolling.calledOnce).to.equal(true);
  1248. c.doPolling.restore();
  1249. });
  1250. });
  1251. describe('#loadLogData', function () {
  1252. beforeEach(function () {
  1253. sinon.stub(c, 'getLogsByRequest', Em.K);
  1254. c.set('wizardController', Em.Object.create({
  1255. cluster: {oldRequestsId: []},
  1256. getDBProperty: function (name) {
  1257. return this.get(name);
  1258. }
  1259. }));
  1260. });
  1261. afterEach(function () {
  1262. c.getLogsByRequest.restore();
  1263. });
  1264. it('shouldn\'t call getLogsByRequest if no requestIds', function () {
  1265. c.set('wizardController.cluster.oldRequestsId', []);
  1266. c.loadLogData();
  1267. expect(c.getLogsByRequest.called).to.equal(false);
  1268. });
  1269. it('should call getLogsByRequest 3 times', function () {
  1270. c.set('wizardController.cluster.oldRequestsId', [1, 2, 3]);
  1271. c.loadLogData();
  1272. expect(c.getLogsByRequest.calledThrice).to.equal(true);
  1273. });
  1274. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  1275. App.set('testMode', true);
  1276. c.set('wizardController.cluster.oldRequestsId', [1, 2, 3]);
  1277. c.loadLogData();
  1278. expect(c.get('POLL_INTERVAL')).to.equal(1);
  1279. App.set('testMode', false);
  1280. });
  1281. });
  1282. describe('#loadCurrentTaskLog', function () {
  1283. beforeEach(function () {
  1284. sinon.spy(App.ajax, 'send');
  1285. });
  1286. afterEach(function () {
  1287. App.ajax.send.restore();
  1288. });
  1289. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1290. c.set('currentOpenTaskId', null);
  1291. c.loadCurrentTaskLog();
  1292. expect(App.ajax.send.called).to.equal(false);
  1293. });
  1294. it('should call App.ajax.send with provided data', function () {
  1295. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1296. c.set('currentOpenTaskId', 1);
  1297. c.set('currentOpenTaskRequestId', 2);
  1298. c.set('content', {cluster: {name: 3}});
  1299. c.loadCurrentTaskLog();
  1300. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3, sync: true});
  1301. c.togglePreviousSteps.restore();
  1302. });
  1303. });
  1304. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1305. it('should increment logTasksChangesCounter', function () {
  1306. c.set('logTasksChangesCounter', 0);
  1307. c.loadCurrentTaskLogSuccessCallback();
  1308. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1309. });
  1310. it('should update stdout, stderr', function () {
  1311. c.set('currentOpenTaskId', 1);
  1312. c.reopen({
  1313. hosts: [
  1314. Em.Object.create({
  1315. name: 'h1',
  1316. logTasks: [
  1317. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1318. ]
  1319. })
  1320. ]
  1321. });
  1322. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1323. c.loadCurrentTaskLogSuccessCallback(data);
  1324. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1325. expect(t.stdout).to.equal('stdout');
  1326. expect(t.stderr).to.equal('stderr');
  1327. });
  1328. it('shouldn\'t update stdout, stderr', function () {
  1329. c.set('currentOpenTaskId', 1);
  1330. c.reopen({
  1331. hosts: [
  1332. Em.Object.create({
  1333. name: 'h1',
  1334. logTasks: [
  1335. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1336. ]
  1337. })
  1338. ]
  1339. });
  1340. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1341. c.loadCurrentTaskLogSuccessCallback(data);
  1342. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1343. expect(t.stdout).to.equal('');
  1344. expect(t.stderr).to.equal('');
  1345. });
  1346. it('shouldn\'t update stdout, stderr (2)', function () {
  1347. c.set('currentOpenTaskId', 1);
  1348. c.reopen({
  1349. hosts: [
  1350. Em.Object.create({
  1351. name: 'h2',
  1352. logTasks: [
  1353. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1354. ]
  1355. })
  1356. ]
  1357. });
  1358. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1359. c.loadCurrentTaskLogSuccessCallback(data);
  1360. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1361. expect(t.stdout).to.equal('');
  1362. expect(t.stderr).to.equal('');
  1363. });
  1364. });
  1365. describe('#loadCurrentTaskLogErrorCallback', function () {
  1366. it('should set currentOpenTaskId to 0', function () {
  1367. c.set('currentOpenTaskId', 123);
  1368. c.loadCurrentTaskLogErrorCallback();
  1369. expect(c.get('currentOpenTaskId')).to.equal(0);
  1370. });
  1371. });
  1372. describe('#getLogsByRequest', function () {
  1373. beforeEach(function () {
  1374. sinon.spy(App.ajax, 'send');
  1375. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1376. });
  1377. afterEach(function () {
  1378. App.ajax.send.restore();
  1379. c.togglePreviousSteps.restore();
  1380. });
  1381. it('should call App.ajax.send with provided data', function () {
  1382. var polling = 1;
  1383. var requestId = 2;
  1384. c.set('content', {cluster: {name: 3}});
  1385. c.set('numPolls', 4);
  1386. c.getLogsByRequest(polling, requestId);
  1387. expect(App.ajax.send.args[0][0].data).to.eql({polling: polling, requestId: requestId, cluster: 3, numPolls: 4});
  1388. });
  1389. });
  1390. describe('#doPolling', function () {
  1391. beforeEach(function () {
  1392. sinon.stub(c, 'getLogsByRequest', Em.K);
  1393. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1394. });
  1395. afterEach(function () {
  1396. c.getLogsByRequest.restore();
  1397. c.togglePreviousSteps.restore();
  1398. });
  1399. it('should increment numPolls if testMode', function () {
  1400. App.set('testMode', true);
  1401. c.set('numPolls', 0);
  1402. c.doPolling();
  1403. expect(c.get('numPolls')).to.equal(1);
  1404. App.set('testMode', false);
  1405. });
  1406. it('should call getLogsByRequest', function () {
  1407. c.set('content', {cluster: {requestId: 1}});
  1408. c.doPolling();
  1409. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1410. });
  1411. });
  1412. describe('#isAllComponentsInstalled', function () {
  1413. beforeEach(function () {
  1414. sinon.spy(App.ajax, 'send');
  1415. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1416. sinon.stub(c, 'saveClusterStatus', Em.K);
  1417. });
  1418. afterEach(function () {
  1419. App.ajax.send.restore();
  1420. c.togglePreviousSteps.restore();
  1421. c.saveClusterStatus.restore();
  1422. });
  1423. it('shouldn\'t call App.ajax.send', function () {
  1424. c.set('content', {controllerName: 'addServiceController'});
  1425. c.isAllComponentsInstalled();
  1426. expect(App.ajax.send.called).to.equal(false);
  1427. });
  1428. it('shouldn\'t call App.ajax.send (2)', function () {
  1429. c.set('content', {controllerName: 'addHostController'});
  1430. c.isAllComponentsInstalled();
  1431. expect(App.ajax.send.called).to.equal(false);
  1432. });
  1433. it('should call App.ajax.send', function () {
  1434. c.set('content', {cluster: {name: 'n'}, controllerName: 'installerController'});
  1435. c.isAllComponentsInstalled();
  1436. expect(App.ajax.send.args[0][0].data).to.eql({cluster: 'n'});
  1437. });
  1438. });
  1439. describe('#isAllComponentsInstalledErrorCallback', function () {
  1440. beforeEach(function () {
  1441. sinon.stub(c, 'saveClusterStatus', Em.K);
  1442. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1443. });
  1444. afterEach(function () {
  1445. c.saveClusterStatus.restore();
  1446. c.togglePreviousSteps.restore();
  1447. });
  1448. it('should call saveClusterStatus', function () {
  1449. c.isAllComponentsInstalledErrorCallback({});
  1450. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1451. });
  1452. });
  1453. describe('#saveClusterStatus', function () {
  1454. beforeEach(function () {
  1455. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1456. });
  1457. afterEach(function () {
  1458. c.togglePreviousSteps.restore();
  1459. });
  1460. it('in testMode should set content.cluster', function () {
  1461. var d = {n: 'n'};
  1462. c.set('content', {cluster: ''});
  1463. App.set('testMode', true);
  1464. c.saveClusterStatus(d);
  1465. expect(c.get('content.cluster')).to.eql(d);
  1466. App.set('testMode', false);
  1467. });
  1468. it('if testMode is false should use content.controller', function () {
  1469. var d = {n: 'n'},
  1470. obj = Em.Object.create({
  1471. saveClusterStatus: Em.K
  1472. });
  1473. sinon.stub(App.router, 'get', function () {
  1474. return obj;
  1475. });
  1476. sinon.spy(obj, 'saveClusterStatus');
  1477. c.set('content', {cluster: ''});
  1478. App.set('testMode', false);
  1479. c.saveClusterStatus(d);
  1480. expect(obj.saveClusterStatus.calledWith(d)).to.eql(true);
  1481. App.set('testMode', true);
  1482. obj.saveClusterStatus.restore();
  1483. App.router.get.restore();
  1484. });
  1485. });
  1486. describe('#saveInstalledHosts', function () {
  1487. beforeEach(function () {
  1488. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1489. });
  1490. afterEach(function () {
  1491. c.togglePreviousSteps.restore();
  1492. });
  1493. it('if testMode is false should use content.controller', function () {
  1494. var d = {n: 'n'},
  1495. obj = Em.Object.create({
  1496. saveInstalledHosts: Em.K
  1497. });
  1498. sinon.stub(App.router, 'get', function () {
  1499. return obj;
  1500. });
  1501. sinon.spy(obj, 'saveInstalledHosts');
  1502. c.set('content', {cluster: ''});
  1503. App.set('testMode', false);
  1504. c.saveInstalledHosts(d);
  1505. expect(obj.saveInstalledHosts.calledWith(d)).to.eql(true);
  1506. App.set('testMode', true);
  1507. obj.saveInstalledHosts.restore();
  1508. App.router.get.restore();
  1509. });
  1510. });
  1511. describe('#getComponentMessage', function () {
  1512. var tests = Em.A([
  1513. {
  1514. clients: ['c1'],
  1515. m: 'One client',
  1516. e: 'c1'
  1517. },
  1518. {
  1519. clients: ['c1', 'c2'],
  1520. m: 'Two clients',
  1521. e: 'c1 and c2'
  1522. },
  1523. {
  1524. clients: ['c1', 'c2', 'c3'],
  1525. m: 'Three clients',
  1526. e: 'c1, c2 and c3'
  1527. },
  1528. {
  1529. clients: ['c1', 'c2', 'c3', 'c4'],
  1530. m: 'Four clients',
  1531. e: 'c1, c2, c3 and c4'
  1532. },
  1533. {
  1534. clients: ['c1', 'c2', 'c3', 'c4', 'c5'],
  1535. m: 'Five clients',
  1536. e: 'c1, c2, c3, c4 and c5'
  1537. }
  1538. ]);
  1539. tests.forEach(function (test) {
  1540. it(test.m, function () {
  1541. var label = c.getComponentMessage(test.clients);
  1542. expect(label).to.equal(test.e);
  1543. });
  1544. });
  1545. });
  1546. describe('#togglePreviousSteps', function () {
  1547. beforeEach(function () {
  1548. sinon.stub(obj, 'setStepsEnable', Em.K);
  1549. sinon.stub(obj, 'setLowerStepsDisable', Em.K);
  1550. sinon.stub(App.router, 'get', function () {
  1551. return obj;
  1552. });
  1553. });
  1554. afterEach(function () {
  1555. App.router.get.restore();
  1556. obj.setStepsEnable.restore();
  1557. obj.setLowerStepsDisable.restore();
  1558. });
  1559. it('shouldn\'t do nothing on testMode', function () {
  1560. App.set('testMode', true);
  1561. c.togglePreviousSteps();
  1562. expect(App.router.get.called).to.equal(false);
  1563. App.set('testMode', false);
  1564. });
  1565. Em.A([
  1566. {
  1567. status: 'INSTALL FAILED',
  1568. controllerName: 'installerController',
  1569. e: {
  1570. setStepsEnable: true,
  1571. setLowerStepsDisable: false
  1572. }
  1573. },
  1574. {
  1575. status: 'STARTED',
  1576. controllerName: 'installerController',
  1577. e: {
  1578. setStepsEnable: false,
  1579. setLowerStepsDisable: true
  1580. }
  1581. },
  1582. {
  1583. status: 'INSTALL FAILED',
  1584. controllerName: 'addServiceController',
  1585. e: {
  1586. setStepsEnable: false,
  1587. setLowerStepsDisable: true
  1588. }
  1589. },
  1590. {
  1591. status: 'STARTED',
  1592. controllerName: 'addServiceController',
  1593. e: {
  1594. setStepsEnable: false,
  1595. setLowerStepsDisable: true
  1596. }
  1597. }
  1598. ]).forEach(function (test) {
  1599. it(test.status + ' ' + test.controllerName, function () {
  1600. App.set('testMode', false);
  1601. c.reopen({content: {cluster: {status: test.status}, controllerName: test.controllerName}});
  1602. c.togglePreviousSteps();
  1603. expect(App.router.get.calledWith('installerController')).to.equal(true);
  1604. if (test.e.setStepsEnable) {
  1605. expect(obj.setStepsEnable.calledOnce).to.equal(true);
  1606. }
  1607. else {
  1608. expect(obj.setStepsEnable.called).to.equal(false);
  1609. }
  1610. if (test.e.setLowerStepsDisable) {
  1611. expect(obj.setLowerStepsDisable.calledWith(9)).to.equal(true);
  1612. }
  1613. else {
  1614. expect(obj.setLowerStepsDisable.called).to.equal(false);
  1615. }
  1616. });
  1617. });
  1618. });
  1619. describe('#navigateStep', function () {
  1620. beforeEach(function () {
  1621. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1622. sinon.stub(c, 'loadStep', Em.K);
  1623. sinon.stub(c, 'loadLogData', Em.K);
  1624. sinon.stub(c, 'startPolling', Em.K);
  1625. });
  1626. afterEach(function () {
  1627. c.togglePreviousSteps.restore();
  1628. c.loadStep.restore();
  1629. c.loadLogData.restore();
  1630. c.startPolling.restore();
  1631. });
  1632. it('should set custom data in testMode', function () {
  1633. App.set('testMode', true);
  1634. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1635. c.navigateStep();
  1636. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1637. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1638. expect(c.get('content.cluster.requestId')).to.equal(1);
  1639. App.set('testMode', false);
  1640. });
  1641. it('isCompleted = true, requestId = 1', function () {
  1642. App.set('testMode', false);
  1643. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1644. c.navigateStep();
  1645. expect(c.loadStep.calledOnce).to.equal(true);
  1646. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1647. expect(c.get('progress')).to.equal('100');
  1648. });
  1649. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1650. App.set('testMode', false);
  1651. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1652. c.navigateStep();
  1653. expect(c.loadStep.calledOnce).to.equal(true);
  1654. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1655. });
  1656. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1657. App.set('testMode', false);
  1658. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1659. c.navigateStep();
  1660. expect(c.loadStep.calledOnce).to.equal(true);
  1661. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1662. });
  1663. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1664. App.set('testMode', false);
  1665. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1666. c.navigateStep();
  1667. expect(c.loadStep.calledOnce).to.equal(true);
  1668. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1669. expect(c.startPolling.calledOnce).to.equal(true);
  1670. });
  1671. });
  1672. describe('#launchStartServices', function () {
  1673. beforeEach(function () {
  1674. sinon.spy(App.ajax, 'send');
  1675. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1676. sinon.stub(c, 'saveClusterStatus', Em.K);
  1677. c.reopen({content: {}});
  1678. });
  1679. afterEach(function () {
  1680. App.ajax.send.restore();
  1681. c.togglePreviousSteps.restore();
  1682. c.saveClusterStatus.restore();
  1683. });
  1684. it('should set numPolls to 6 in testMode', function () {
  1685. App.set('testMode', true);
  1686. c.set('numPolls', 0);
  1687. c.launchStartServices();
  1688. expect(c.get('numPolls')).to.equal(6);
  1689. App.set('testMode', false);
  1690. });
  1691. Em.A([
  1692. {
  1693. controllerName: 'installerController',
  1694. clusterName: 'c1',
  1695. e: {
  1696. name: 'wizard.step9.installer.launch_start_services'
  1697. }
  1698. },
  1699. {
  1700. controllerName: 'addHostController',
  1701. clusterName: 'c1',
  1702. wizardController: Em.Object.create({
  1703. getDBProperty: function () {
  1704. return {h1: '', h2: ''};
  1705. }
  1706. }),
  1707. e: {
  1708. name: 'wizard.step9.add_host.launch_start_services',
  1709. data: 'host_name.in(h1,h2)'
  1710. }
  1711. }
  1712. ]).forEach(function (test) {
  1713. it(test.controllerName, function () {
  1714. c.reopen({content: {controllerName: test.controllerName, cluster: {name: test.clusterName}}});
  1715. if (test.wizardController) {
  1716. c.reopen({wizardController: test.wizardController});
  1717. }
  1718. c.launchStartServices();
  1719. var r = App.ajax.send.args[0][0];
  1720. expect(r.data.cluster).to.equal(test.clusterName);
  1721. expect(r.name).to.equal(test.e.name);
  1722. if (test.e.data) {
  1723. expect(r.data.data.contains(test.e.data)).to.equal(true);
  1724. }
  1725. });
  1726. });
  1727. });
  1728. describe('#isServicesStarted', function () {
  1729. beforeEach(function () {
  1730. sinon.stub(c, 'saveClusterStatus', Em.K);
  1731. sinon.stub(c, 'saveInstalledHosts', Em.K);
  1732. });
  1733. afterEach(function () {
  1734. c.saveClusterStatus.restore();
  1735. c.saveInstalledHosts.restore();
  1736. });
  1737. Em.A([
  1738. {
  1739. polledData: [
  1740. {Tasks: {status: 'PENDING'}}
  1741. ],
  1742. m: 'PENDING',
  1743. e: false
  1744. },
  1745. {
  1746. polledData: [
  1747. {Tasks: {status: 'QUEUED'}}
  1748. ],
  1749. m: 'QUEUED',
  1750. e: false
  1751. },
  1752. {
  1753. polledData: [
  1754. {Tasks: {status: 'IN_PROGRESS'}}
  1755. ],
  1756. m: 'IN_PROGRESS',
  1757. e: false
  1758. }
  1759. ]).forEach(function (test) {
  1760. it(test.m, function () {
  1761. var r = c.isServicesStarted(test.polledData);
  1762. expect(r).to.equal(test.e);
  1763. });
  1764. });
  1765. Em.A([
  1766. {
  1767. polledData: [
  1768. {Tasks: {status: 'SUCCESS'}}
  1769. ],
  1770. m: 'tasks ok, isSuccess true',
  1771. isSuccess: true,
  1772. e: {
  1773. status: 'STARTED',
  1774. hasInstallTime: true
  1775. }
  1776. },
  1777. {
  1778. polledData: [
  1779. {Tasks: {status: 'SUCCESS'}}
  1780. ],
  1781. m: 'tasks ok, isSuccess false',
  1782. isSuccess: false,
  1783. e: {
  1784. status: 'START FAILED',
  1785. hasInstallTime: false
  1786. }
  1787. }
  1788. ]).forEach(function (test) {
  1789. it(test.m, function () {
  1790. sinon.stub(c, 'isSuccess', function () {
  1791. return test.isSuccess;
  1792. });
  1793. c.reopen({content: {cluster: {requestId: 2}}});
  1794. var r = c.isServicesStarted(test.polledData);
  1795. var args = c.saveClusterStatus.args[0][0];
  1796. expect(r).to.equal(true);
  1797. expect(c.get('progress')).to.equal('100');
  1798. expect(args.status).to.equal(test.e.status);
  1799. expect(args.requestId).to.equal(2);
  1800. expect(args.hasOwnProperty('installTime')).to.equal(test.e.hasInstallTime);
  1801. expect(args.isCompleted).to.equal(true);
  1802. expect(c.saveInstalledHosts.calledOnce).to.equal(true);
  1803. c.isSuccess.restore();
  1804. });
  1805. });
  1806. });
  1807. describe('#launchStartServicesSuccessCallback', function () {
  1808. beforeEach(function () {
  1809. sinon.stub(c, 'saveClusterStatus', Em.K);
  1810. sinon.stub(c, 'doPolling', Em.K);
  1811. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1812. });
  1813. afterEach(function () {
  1814. c.saveClusterStatus.restore();
  1815. c.doPolling.restore();
  1816. c.hostHasClientsOnly.restore();
  1817. });
  1818. it('should call doPolling if some data were received', function () {
  1819. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1820. expect(c.doPolling.calledOnce).to.equal(true);
  1821. });
  1822. Em.A([
  1823. {
  1824. jsonData: {Requests: {id: 2}},
  1825. e: {
  1826. hostHasClientsOnly: false,
  1827. clusterStatus: {
  1828. status: 'INSTALLED',
  1829. requestId: 2,
  1830. isStartError: false,
  1831. isCompleted: false
  1832. }
  1833. }
  1834. },
  1835. {
  1836. jsonData: null,
  1837. e: {
  1838. hostHasClientsOnly: true,
  1839. clusterStatus: {
  1840. status: 'STARTED',
  1841. isStartError: false,
  1842. isCompleted: true
  1843. },
  1844. status: 'success',
  1845. progress: '100'
  1846. }
  1847. }
  1848. ]).forEach(function (test) {
  1849. it(test.m, function () {
  1850. c.launchStartServicesSuccessCallback(test.jsonData);
  1851. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1852. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1853. if (test.e.status) {
  1854. expect(c.get('status')).to.equal(test.e.status);
  1855. }
  1856. if (test.e.progress) {
  1857. expect(c.get('progress')).to.equal(test.e.progress);
  1858. }
  1859. });
  1860. });
  1861. });
  1862. describe('#getLogsByRequestSuccessCallback', function () {
  1863. beforeEach(function () {
  1864. sinon.stub(c, 'isAllComponentsInstalled', Em.K);
  1865. sinon.stub(window, 'setTimeout', Em.K);
  1866. });
  1867. afterEach(function () {
  1868. c.isAllComponentsInstalled.restore();
  1869. window.setTimeout.restore();
  1870. });
  1871. Em.A([
  1872. {
  1873. polling: false,
  1874. status: 'INSTALL FAILED',
  1875. m: 'should call isAllComponentsInstalled',
  1876. e: true
  1877. },
  1878. {
  1879. polling: false,
  1880. status: 'INSTALLED',
  1881. m: 'shouldn\'t call isAllComponentsInstalled',
  1882. e: false
  1883. },
  1884. {
  1885. polling: true,
  1886. status: 'INSTALL FAILED',
  1887. m: 'shouldn\'t call isAllComponentsInstalled (2)',
  1888. e: false
  1889. },
  1890. {
  1891. polling: true,
  1892. status: 'INSTALLED',
  1893. m: 'shouldn\'t call isAllComponentsInstalled (3)',
  1894. e: false
  1895. }
  1896. ]).forEach(function (test) {
  1897. it(test.m, function () {
  1898. sinon.stub(c, 'parseHostInfo', Em.K);
  1899. c.reopen({content: {cluster: {status: test.status}}});
  1900. c.getLogsByRequestSuccessCallback({}, {}, {polling: test.polling});
  1901. if (test.e) {
  1902. expect(c.isAllComponentsInstalled.calledOnce).to.equal(true);
  1903. }
  1904. else {
  1905. expect(c.isAllComponentsInstalled.called).to.equal(false);
  1906. }
  1907. c.parseHostInfo.restore();
  1908. });
  1909. });
  1910. });
  1911. });