step9_test.js 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973
  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. c.set('content', {cluster: {status: 'INSTALLED'}});
  726. var polledData = {'{}': {}};
  727. sinon.stub(c, 'isServicesStarted', Em.K);
  728. c.finishState(polledData);
  729. expect(c.isServicesStarted.calledWith(polledData)).to.equal(true);
  730. c.isServicesStarted.restore();
  731. });
  732. it('for PENDING status should call isServicesInstalled', function () {
  733. c.set('content', {cluster: {status: 'PENDING'}});
  734. var polledData = {'{}': {}};
  735. sinon.stub(c, 'isServicesInstalled', Em.K);
  736. c.finishState(polledData);
  737. expect(c.isServicesInstalled.calledWith(polledData)).to.equal(true);
  738. c.isServicesInstalled.restore();
  739. });
  740. });
  741. describe('#setLogTasksStatePerHost', function () {
  742. var tests = Em.A([
  743. {
  744. tasksPerHost: [
  745. {Tasks: {id: 1, status: 'COMPLETED'}},
  746. {Tasks: {id: 2, status: 'COMPLETED'}}
  747. ],
  748. tasks: [],
  749. e: {m: 'COMPLETED', l: 2},
  750. m: 'host didn\'t have tasks and got 2 new'
  751. },
  752. {
  753. tasksPerHost: [
  754. {Tasks: {id: 1, status: 'COMPLETED'}},
  755. {Tasks: {id: 2, status: 'COMPLETED'}}
  756. ],
  757. tasks: [
  758. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  759. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  760. ],
  761. e: {m: 'COMPLETED', l: 2},
  762. m: 'host had 2 tasks and got both updated'
  763. },
  764. {
  765. tasksPerHost: [],
  766. tasks: [
  767. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  768. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  769. ],
  770. e: {m: 'IN_PROGRESS', l: 2},
  771. m: 'host had 2 tasks and didn\'t get updates'
  772. },
  773. {
  774. tasksPerHost: [
  775. {Tasks: {id: 1, status: 'COMPLETED'}},
  776. {Tasks: {id: 2, status: 'COMPLETED'}},
  777. {Tasks: {id: 3, status: 'COMPLETED'}}
  778. ],
  779. tasks: [
  780. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  781. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  782. ],
  783. e: {m: 'COMPLETED', l: 3},
  784. m: 'host had 2 tasks and got both updated and 1 new'
  785. }
  786. ]);
  787. tests.forEach(function (test) {
  788. it(test.m, function () {
  789. var controller = App.WizardStep9Controller.create({hosts: [Em.Object.create({logTasks: test.tasks})]});
  790. controller.setLogTasksStatePerHost(test.tasksPerHost, controller.get('hosts')[0]);
  791. expect(controller.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  792. expect(controller.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  793. });
  794. });
  795. });
  796. describe('#parseHostInfo', function () {
  797. var tests = Em.A([
  798. {
  799. cluster: {status: 'PENDING'},
  800. hosts: Em.A([
  801. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  802. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  803. ]),
  804. polledData: {
  805. tasks: [
  806. {Tasks: {host_name: 'host2', status: 'COMPLETED'}},
  807. {Tasks: {host_name: 'host2', status: 'COMPLETED'}}
  808. ]
  809. },
  810. e: {
  811. hosts: {
  812. host1: {progress: '33'},
  813. host2: {progress: '33'}
  814. },
  815. progress: '33'
  816. },
  817. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is PENDING'
  818. },
  819. {
  820. cluster: {status: 'PENDING'},
  821. hosts: Em.A([
  822. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  823. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  824. ]),
  825. polledData: {
  826. tasks: [
  827. {Tasks: {host_name: 'host1', status: 'IN_PROGRESS'}},
  828. {Tasks: {host_name: 'host2', status: 'IN_PROGRESS'}}
  829. ]
  830. },
  831. e: {hosts: {host1: {progress: '12'}, host2: {progress: '12'}}, progress: '12'},
  832. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is PENDING'
  833. },
  834. {
  835. cluster: {status: 'PENDING'},
  836. hosts: Em.A([
  837. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  838. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  839. ]),
  840. polledData: {
  841. tasks: [
  842. {Tasks: {host_name: 'host1', status: 'QUEUED'}},
  843. {Tasks: {host_name: 'host2', status: 'QUEUED'}}
  844. ]
  845. },
  846. e: {
  847. hosts: {
  848. host1: {progress: '3'},
  849. host2: {progress: '3'}
  850. },
  851. progress: '3'
  852. },
  853. m: 'Two hosts. Each host has one task QUEUED. Cluster status is PENDING'
  854. },
  855. {
  856. cluster: {status: 'INSTALLED'},
  857. hosts: Em.A([
  858. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  859. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  860. ]),
  861. polledData: {
  862. tasks: [
  863. {Tasks: {host_name: 'host2', status: 'COMPLETED'}},
  864. {Tasks: {host_name: 'host2', status: 'COMPLETED'}}
  865. ]
  866. },
  867. e: {
  868. hosts: {
  869. host1: {progress: '100'},
  870. host2: {progress: '100'}
  871. },
  872. progress: '100'
  873. },
  874. m: 'Two hosts. One host without tasks. Second host has all tasks COMPLETED. Cluster status is INSTALLED'
  875. },
  876. {
  877. cluster: {status: 'INSTALLED'},
  878. hosts: Em.A([
  879. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  880. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  881. ]),
  882. polledData: {
  883. tasks: [
  884. {Tasks: {host_name: 'host1', status: 'IN_PROGRESS'}},
  885. {Tasks: {host_name: 'host2', status: 'IN_PROGRESS'}}
  886. ]
  887. },
  888. e: {
  889. hosts: {
  890. host1: {progress: '58'},
  891. host2: {progress: '58'}
  892. },
  893. progress: '58'
  894. },
  895. m: 'Two hosts. Each host has one task IN_PROGRESS. Cluster status is INSTALLED'
  896. },
  897. {
  898. cluster: {status: 'INSTALLED'},
  899. hosts: Em.A([
  900. Em.Object.create({name: 'host1', status: '', message: '', progress: '', logTasks: []}),
  901. Em.Object.create({name: 'host2', status: '', message: '', progress: '', logTasks: []})
  902. ]),
  903. polledData: {
  904. tasks: [
  905. {Tasks: {host_name: 'host1', status: 'QUEUED'}},
  906. {Tasks: {host_name: 'host2', status: 'QUEUED'}}
  907. ]
  908. },
  909. e: {
  910. hosts: {
  911. host1: {progress: '40'},
  912. host2: {progress: '40'}
  913. },
  914. progress: '40'
  915. },
  916. m: 'Two hosts. Each host has one task QUEUED. Cluster status is INSTALLED'
  917. }
  918. ]);
  919. tests.forEach(function (test) {
  920. it(test.m, function () {
  921. var controller = App.WizardStep9Controller.create({hosts: test.hosts, content: {cluster: {status: test.cluster.status}}, finishState: function () {
  922. return false;
  923. }});
  924. var logTasksChangesCounter = controller.get('logTasksChangesCounter');
  925. controller.parseHostInfo(test.polledData);
  926. expect(controller.get('logTasksChangesCounter')).to.equal(logTasksChangesCounter + 1);
  927. for (var name in test.e.hosts) {
  928. if (test.e.hosts.hasOwnProperty(name)) {
  929. expect(controller.get('hosts').findProperty('name', name).get('progress')).to.equal(test.e.hosts[name].progress);
  930. }
  931. }
  932. expect(controller.get('progress')).to.equal(test.e.progress);
  933. });
  934. });
  935. it('shouldn\'t do nothing if polledData.Requests.id != requestId', function () {
  936. c.set('content', {cluster: {requestId: 1}});
  937. var polledData = {Requests: {id: 2}, tasks: []};
  938. sinon.spy(c, 'finishState');
  939. expect(c.parseHostInfo(polledData)).to.equal(false);
  940. expect(c.finishState.called).to.equal(false);
  941. c.finishState.restore();
  942. });
  943. });
  944. describe('#isAllComponentsInstalledSuccessCallback', function () {
  945. describe('', function () {
  946. var hosts = Em.A([
  947. Em.Object.create({name: 'host1', status: 'failed', expectedStatus: 'heartbeat_lost'}),
  948. Em.Object.create({name: 'host2', status: 'info', expectedStatus: 'heartbeat_lost'}),
  949. Em.Object.create({name: 'host3', status: 'warning', expectedStatus: 'warning'}),
  950. Em.Object.create({name: 'host4', status: 'info', expectedStatus: 'info'})
  951. ]);
  952. var heartbeatLostData = {
  953. "items": [
  954. {
  955. "Hosts": {
  956. "cluster_name": "c1",
  957. "host_name": "host1",
  958. "host_state": "HEARTBEAT_LOST"
  959. },
  960. "host_components": [
  961. {
  962. "HostRoles": {
  963. "cluster_name": "c1",
  964. "component_name": "NAMENODE",
  965. "host_name": "host1",
  966. "state": "INSTALL_FAILED"
  967. }
  968. }
  969. ]
  970. },
  971. {
  972. "Hosts": {
  973. "cluster_name": "c1",
  974. "host_name": "host2",
  975. "host_state": "HEARTBEAT_LOST"
  976. },
  977. "host_components": [
  978. {
  979. "HostRoles": {
  980. "cluster_name": "c1",
  981. "component_name": "ZOOKEEPER_SERVER",
  982. "host_name": "host2",
  983. "state": "UNKNOWN"
  984. }
  985. }
  986. ]
  987. },
  988. {
  989. "Hosts": {
  990. "cluster_name": "c1",
  991. "host_name": "host3",
  992. "host_state": "HEALTHY"
  993. },
  994. "host_components": [
  995. {
  996. "HostRoles": {
  997. "cluster_name": "c1",
  998. "component_name": "DATANODE",
  999. "host_name": "host3",
  1000. "state": "INSTALL_FAILED"
  1001. }
  1002. }
  1003. ]
  1004. },
  1005. {
  1006. "Hosts": {
  1007. "cluster_name": "c1",
  1008. "host_name": "host4",
  1009. "host_state": "HEALTHY"
  1010. },
  1011. "host_components": [
  1012. {
  1013. "HostRoles": {
  1014. "cluster_name": "c1",
  1015. "component_name": "PIG",
  1016. "host_name": "host4",
  1017. "state": "INSTALLED"
  1018. }
  1019. },
  1020. {
  1021. "HostRoles": {
  1022. "cluster_name": "c1",
  1023. "component_name": "DATANODE",
  1024. "host_name": "host3",
  1025. "state": "INSTALLED"
  1026. }
  1027. }
  1028. ]
  1029. }
  1030. ]
  1031. };
  1032. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController'}});
  1033. App.testMode = true;
  1034. // Action
  1035. controller.isAllComponentsInstalledSuccessCallback(heartbeatLostData);
  1036. // Validation for the status of all hosts.
  1037. controller.get('hosts').forEach(function (test) {
  1038. var status = heartbeatLostData.items.findProperty('Hosts.host_name', test.get('name')).Hosts.host_state;
  1039. it('Host "' + test.get('name') + '"' + ' with status "' + status + '" ', function () {
  1040. expect(test.get('status')).to.equal(test.get('expectedStatus'));
  1041. });
  1042. });
  1043. });
  1044. describe('', function () {
  1045. var noHeartbeatLostData = {
  1046. "items": [
  1047. {
  1048. "Hosts": {
  1049. "cluster_name": "c1",
  1050. "host_name": "host1",
  1051. "host_state": "HEALTHY"
  1052. },
  1053. "host_components": [
  1054. {
  1055. "HostRoles": {
  1056. "cluster_name": "c1",
  1057. "component_name": "NAMENODE",
  1058. "host_name": "host1",
  1059. "state": "INSTALL_FAILED"
  1060. }
  1061. }
  1062. ]
  1063. }
  1064. ]
  1065. };
  1066. var hosts = Em.A([Em.Object.create({name: 'host1', status: 'failed'})]);
  1067. // When there is no heartbeat lost for any host and cluster failed install task, Refreshing the page should not launch start all services request.
  1068. // Below transitions are possibilities in this function
  1069. // PENDING -> INSTALL or PENDING. This transition happens when install all services request is completed successfully.
  1070. // INSTALL FAILED -> INSTALL FAILED. No transition should happen when install all services request fails and then user hits refresh
  1071. // Cluster is not expected to enter this function in other states: INSTALLED, START FAILED, STARTED
  1072. 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
  1073. statuses.forEach(function (priorStatus) {
  1074. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: priorStatus}}, togglePreviousSteps: function () {
  1075. }});
  1076. // Action
  1077. controller.isAllComponentsInstalledSuccessCallback(noHeartbeatLostData);
  1078. // Validation for the cluster state.
  1079. var actualStatus = controller.get('content.cluster.status');
  1080. it('Cluster state before entering the function "' + priorStatus + '"', function () {
  1081. expect(actualStatus).to.equal(priorStatus);
  1082. });
  1083. });
  1084. });
  1085. });
  1086. // isServicesInstalled is called after every poll for "Install All Services" request.
  1087. // This function should result into a call to "Start All Services" request only if install request completed successfully.
  1088. describe('#isServicesInstalled', function () {
  1089. var hostStateJsonData = {
  1090. "items": [
  1091. {
  1092. "Hosts": {
  1093. "cluster_name": "c1",
  1094. "host_name": "ambari-1.c.apache.internal",
  1095. "host_state": "HEALTHY"
  1096. },
  1097. "host_components": [
  1098. {
  1099. "HostRoles": {
  1100. "cluster_name": "c1",
  1101. "component_name": "GANGLIA_MONITOR",
  1102. "host_name": "ambari-1.c.apache.internal",
  1103. "state": "STARTED"
  1104. }
  1105. }
  1106. ]
  1107. }
  1108. ]
  1109. };
  1110. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}),
  1111. Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1112. // polledData has all hosts with status completed to trigger transition from install->start request.
  1113. var polledData = Em.A([Em.Object.create({Tasks: {name: 'host1', status: 'COMPLETED'}}),
  1114. Em.Object.create({Tasks: {name: 'host2', status: 'COMPLETED'}})]);
  1115. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController',
  1116. cluster: {status: 'PENDING', name: 'c1'}}, launchStartServices: function () {
  1117. return true;
  1118. }});
  1119. var tests = Em.A([
  1120. // controller has "status" value as "info" initially. If no errors are encountered then wizard stages
  1121. // transition info->success, on error info->error, on warning info->warning
  1122. {status: 'info', e: {startServicesCalled: true}, m: 'If no failed tasks then start services request should be called'},
  1123. {status: 'failed', e: {startServicesCalled: false}, m: 'If install request has failed tasks then start services call should not be called'}
  1124. ]);
  1125. beforeEach(function () {
  1126. App.testMode = true;
  1127. sinon.spy(controller, 'launchStartServices');
  1128. sinon.stub($, 'ajax').yieldsTo('success', hostStateJsonData);
  1129. });
  1130. afterEach(function () {
  1131. App.testMode = false;
  1132. controller.launchStartServices.restore();
  1133. $.ajax.restore();
  1134. });
  1135. tests.forEach(function (test) {
  1136. it(test.m, function () {
  1137. controller.set('status', test.status);
  1138. //Action
  1139. controller.isServicesInstalled(polledData);
  1140. //Validation
  1141. expect(controller.launchStartServices.called).to.equal(test.e.startServicesCalled);
  1142. });
  1143. });
  1144. });
  1145. // On completion of Start all services error callback function,
  1146. // Cluster Status should be INSTALL FAILED
  1147. // All progress bar on the screen should be finished (100%) with blue color.
  1148. // Retry button should be enabled, next button should be disabled
  1149. describe('#launchStartServicesErrorCallback', function () {
  1150. App.testMode = true;
  1151. // override the actual function
  1152. App.popup = {
  1153. setErrorPopup: function () {
  1154. return true;
  1155. }
  1156. };
  1157. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1158. var controller = App.WizardStep9Controller.create({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}, togglePreviousSteps: function () {
  1159. }});
  1160. //Action
  1161. controller.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1162. it('Cluster Status should be INSTALL FAILED', function () {
  1163. expect(controller.get('content.cluster.status')).to.equal('INSTALL FAILED');
  1164. });
  1165. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1166. expect(controller.get('progress')).to.equal('100');
  1167. expect(controller.get('status')).to.equal('failed');
  1168. });
  1169. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1170. controller.get('hosts').forEach(function (host) {
  1171. expect(host.get('progress')).to.equal('100');
  1172. expect(host.get('status')).to.equal('info');
  1173. });
  1174. });
  1175. it('Next button should be disabled', function () {
  1176. expect(controller.get('isSubmitDisabled')).to.equal(true);
  1177. });
  1178. it('Retry button should be visible', function () {
  1179. expect(controller.get('showRetry')).to.equal(true);
  1180. })
  1181. });
  1182. describe('#submit', function () {
  1183. it('should call App.router.send', function () {
  1184. sinon.stub(App.router, 'send', Em.K);
  1185. c.submit();
  1186. expect(App.router.send.calledWith('next')).to.equal(true);
  1187. App.router.send.restore();
  1188. });
  1189. });
  1190. describe('#back', function () {
  1191. beforeEach(function () {
  1192. sinon.stub(App.router, 'send', Em.K);
  1193. });
  1194. afterEach(function () {
  1195. App.router.send.restore();
  1196. });
  1197. it('should call App.router.send', function () {
  1198. c.reopen({isSubmitDisabled: false});
  1199. c.back();
  1200. expect(App.router.send.calledWith('back')).to.equal(true);
  1201. });
  1202. it('shouldn\'t call App.router.send', function () {
  1203. c.reopen({isSubmitDisabled: true});
  1204. c.back();
  1205. expect(App.router.send.called).to.equal(false);
  1206. });
  1207. });
  1208. describe('#loadStep', function () {
  1209. beforeEach(function () {
  1210. sinon.stub(c, 'clearStep', Em.K);
  1211. sinon.stub(c, 'loadHosts', Em.K);
  1212. });
  1213. afterEach(function () {
  1214. c.clearStep.restore();
  1215. c.loadHosts.restore();
  1216. });
  1217. it('should call clearStep', function () {
  1218. c.loadStep();
  1219. expect(c.clearStep.calledOnce).to.equal(true);
  1220. });
  1221. it('should call loadHosts', function () {
  1222. c.loadStep();
  1223. expect(c.loadHosts.calledOnce).to.equal(true);
  1224. });
  1225. });
  1226. describe('#startPolling', function () {
  1227. beforeEach(function () {
  1228. sinon.stub(c, 'getLogsByRequestErrorCallback', Em.K);
  1229. });
  1230. afterEach(function () {
  1231. c.getLogsByRequestErrorCallback.restore();
  1232. });
  1233. it('should set isSubmitDisabled to true', function () {
  1234. c.set('isSubmitDisabled', false);
  1235. c.startPolling();
  1236. expect(c.get('isSubmitDisabled')).to.equal(true);
  1237. });
  1238. it('should call doPolling', function () {
  1239. sinon.stub(c, 'doPolling', Em.K);
  1240. c.startPolling();
  1241. expect(c.doPolling.calledOnce).to.equal(true);
  1242. c.doPolling.restore();
  1243. });
  1244. });
  1245. describe('#loadLogData', function () {
  1246. beforeEach(function () {
  1247. sinon.stub(c, 'getLogsByRequest', Em.K);
  1248. c.set('wizardController', Em.Object.create({
  1249. cluster: {oldRequestsId: []},
  1250. getDBProperty: function (name) {
  1251. return this.get(name);
  1252. }
  1253. }));
  1254. });
  1255. afterEach(function () {
  1256. c.getLogsByRequest.restore();
  1257. });
  1258. it('shouldn\'t call getLogsByRequest if no requestIds', function () {
  1259. c.set('wizardController.cluster.oldRequestsId', []);
  1260. c.loadLogData();
  1261. expect(c.getLogsByRequest.called).to.equal(false);
  1262. });
  1263. it('should call getLogsByRequest 3 times', function () {
  1264. c.set('wizardController.cluster.oldRequestsId', [1, 2, 3]);
  1265. c.loadLogData();
  1266. expect(c.getLogsByRequest.calledThrice).to.equal(true);
  1267. });
  1268. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  1269. App.set('testMode', true);
  1270. c.set('wizardController.cluster.oldRequestsId', [1, 2, 3]);
  1271. c.loadLogData();
  1272. expect(c.get('POLL_INTERVAL')).to.equal(1);
  1273. App.set('testMode', false);
  1274. });
  1275. });
  1276. describe('#loadCurrentTaskLog', function () {
  1277. beforeEach(function () {
  1278. sinon.spy(App.ajax, 'send');
  1279. });
  1280. afterEach(function () {
  1281. App.ajax.send.restore();
  1282. });
  1283. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1284. c.set('currentOpenTaskId', null);
  1285. c.loadCurrentTaskLog();
  1286. expect(App.ajax.send.called).to.equal(false);
  1287. });
  1288. it('should call App.ajax.send with provided data', function () {
  1289. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1290. c.set('currentOpenTaskId', 1);
  1291. c.set('currentOpenTaskRequestId', 2);
  1292. c.set('content', {cluster: {name: 3}});
  1293. c.loadCurrentTaskLog();
  1294. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3, sync: true});
  1295. c.togglePreviousSteps.restore();
  1296. });
  1297. });
  1298. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1299. it('should increment logTasksChangesCounter', function () {
  1300. c.set('logTasksChangesCounter', 0);
  1301. c.loadCurrentTaskLogSuccessCallback();
  1302. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1303. });
  1304. it('should update stdout, stderr', function () {
  1305. c.set('currentOpenTaskId', 1);
  1306. c.reopen({
  1307. hosts: [
  1308. Em.Object.create({
  1309. name: 'h1',
  1310. logTasks: [
  1311. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1312. ]
  1313. })
  1314. ]
  1315. });
  1316. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1317. c.loadCurrentTaskLogSuccessCallback(data);
  1318. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1319. expect(t.stdout).to.equal('stdout');
  1320. expect(t.stderr).to.equal('stderr');
  1321. });
  1322. it('shouldn\'t update stdout, stderr', function () {
  1323. c.set('currentOpenTaskId', 1);
  1324. c.reopen({
  1325. hosts: [
  1326. Em.Object.create({
  1327. name: 'h1',
  1328. logTasks: [
  1329. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1330. ]
  1331. })
  1332. ]
  1333. });
  1334. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1335. c.loadCurrentTaskLogSuccessCallback(data);
  1336. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1337. expect(t.stdout).to.equal('');
  1338. expect(t.stderr).to.equal('');
  1339. });
  1340. it('shouldn\'t update stdout, stderr (2)', function () {
  1341. c.set('currentOpenTaskId', 1);
  1342. c.reopen({
  1343. hosts: [
  1344. Em.Object.create({
  1345. name: 'h2',
  1346. logTasks: [
  1347. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1348. ]
  1349. })
  1350. ]
  1351. });
  1352. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1353. c.loadCurrentTaskLogSuccessCallback(data);
  1354. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1355. expect(t.stdout).to.equal('');
  1356. expect(t.stderr).to.equal('');
  1357. });
  1358. });
  1359. describe('#loadCurrentTaskLogErrorCallback', function () {
  1360. it('should set currentOpenTaskId to 0', function () {
  1361. c.set('currentOpenTaskId', 123);
  1362. c.loadCurrentTaskLogErrorCallback();
  1363. expect(c.get('currentOpenTaskId')).to.equal(0);
  1364. });
  1365. });
  1366. describe('#getLogsByRequest', function () {
  1367. beforeEach(function () {
  1368. sinon.spy(App.ajax, 'send');
  1369. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1370. });
  1371. afterEach(function () {
  1372. App.ajax.send.restore();
  1373. c.togglePreviousSteps.restore();
  1374. });
  1375. it('should call App.ajax.send with provided data', function () {
  1376. var polling = 1;
  1377. var requestId = 2;
  1378. c.set('content', {cluster: {name: 3}});
  1379. c.set('numPolls', 4);
  1380. c.getLogsByRequest(polling, requestId);
  1381. expect(App.ajax.send.args[0][0].data).to.eql({polling: polling, requestId: requestId, cluster: 3, numPolls: 4});
  1382. });
  1383. });
  1384. describe('#doPolling', function () {
  1385. beforeEach(function () {
  1386. sinon.stub(c, 'getLogsByRequest', Em.K);
  1387. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1388. });
  1389. afterEach(function () {
  1390. c.getLogsByRequest.restore();
  1391. c.togglePreviousSteps.restore();
  1392. });
  1393. it('should increment numPolls if testMode', function () {
  1394. App.set('testMode', true);
  1395. c.set('numPolls', 0);
  1396. c.doPolling();
  1397. expect(c.get('numPolls')).to.equal(1);
  1398. App.set('testMode', false);
  1399. });
  1400. it('should call getLogsByRequest', function () {
  1401. c.set('content', {cluster: {requestId: 1}});
  1402. c.doPolling();
  1403. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1404. });
  1405. });
  1406. describe('#isAllComponentsInstalled', function () {
  1407. beforeEach(function () {
  1408. sinon.spy(App.ajax, 'send');
  1409. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1410. sinon.stub(c, 'saveClusterStatus', Em.K);
  1411. });
  1412. afterEach(function () {
  1413. App.ajax.send.restore();
  1414. c.togglePreviousSteps.restore();
  1415. c.saveClusterStatus.restore();
  1416. });
  1417. it('shouldn\'t call App.ajax.send', function () {
  1418. c.set('content', {controllerName: 'addServiceController'});
  1419. c.isAllComponentsInstalled();
  1420. expect(App.ajax.send.called).to.equal(false);
  1421. });
  1422. it('shouldn\'t call App.ajax.send (2)', function () {
  1423. c.set('content', {controllerName: 'addHostController'});
  1424. c.isAllComponentsInstalled();
  1425. expect(App.ajax.send.called).to.equal(false);
  1426. });
  1427. it('should call App.ajax.send', function () {
  1428. c.set('content', {cluster: {name: 'n'}, controllerName: 'installerController'});
  1429. c.isAllComponentsInstalled();
  1430. expect(App.ajax.send.args[0][0].data).to.eql({cluster: 'n'});
  1431. });
  1432. });
  1433. describe('#isAllComponentsInstalledErrorCallback', function () {
  1434. beforeEach(function () {
  1435. sinon.stub(c, 'saveClusterStatus', Em.K);
  1436. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1437. });
  1438. afterEach(function () {
  1439. c.saveClusterStatus.restore();
  1440. c.togglePreviousSteps.restore();
  1441. });
  1442. it('should call saveClusterStatus', function () {
  1443. c.isAllComponentsInstalledErrorCallback({});
  1444. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1445. });
  1446. });
  1447. describe('#saveClusterStatus', function () {
  1448. beforeEach(function () {
  1449. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1450. });
  1451. afterEach(function () {
  1452. c.togglePreviousSteps.restore();
  1453. });
  1454. it('in testMode should set content.cluster', function () {
  1455. var d = {n: 'n'};
  1456. c.set('content', {cluster: ''});
  1457. App.set('testMode', true);
  1458. c.saveClusterStatus(d);
  1459. expect(c.get('content.cluster')).to.eql(d);
  1460. App.set('testMode', false);
  1461. });
  1462. it('if testMode is false should use content.controller', function () {
  1463. var d = {n: 'n'},
  1464. obj = Em.Object.create({
  1465. saveClusterStatus: Em.K
  1466. });
  1467. sinon.stub(App.router, 'get', function () {
  1468. return obj;
  1469. });
  1470. sinon.spy(obj, 'saveClusterStatus');
  1471. c.set('content', {cluster: ''});
  1472. App.set('testMode', false);
  1473. c.saveClusterStatus(d);
  1474. expect(obj.saveClusterStatus.calledWith(d)).to.eql(true);
  1475. App.set('testMode', true);
  1476. obj.saveClusterStatus.restore();
  1477. App.router.get.restore();
  1478. });
  1479. });
  1480. describe('#saveInstalledHosts', function () {
  1481. beforeEach(function () {
  1482. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1483. });
  1484. afterEach(function () {
  1485. c.togglePreviousSteps.restore();
  1486. });
  1487. it('if testMode is false should use content.controller', function () {
  1488. var d = {n: 'n'},
  1489. obj = Em.Object.create({
  1490. saveInstalledHosts: Em.K
  1491. });
  1492. sinon.stub(App.router, 'get', function () {
  1493. return obj;
  1494. });
  1495. sinon.spy(obj, 'saveInstalledHosts');
  1496. c.set('content', {cluster: ''});
  1497. App.set('testMode', false);
  1498. c.saveInstalledHosts(d);
  1499. expect(obj.saveInstalledHosts.calledWith(d)).to.eql(true);
  1500. App.set('testMode', true);
  1501. obj.saveInstalledHosts.restore();
  1502. App.router.get.restore();
  1503. });
  1504. });
  1505. describe('#getComponentMessage', function () {
  1506. var tests = Em.A([
  1507. {
  1508. clients: ['c1'],
  1509. m: 'One client',
  1510. e: 'c1'
  1511. },
  1512. {
  1513. clients: ['c1', 'c2'],
  1514. m: 'Two clients',
  1515. e: 'c1 and c2'
  1516. },
  1517. {
  1518. clients: ['c1', 'c2', 'c3'],
  1519. m: 'Three clients',
  1520. e: 'c1, c2 and c3'
  1521. },
  1522. {
  1523. clients: ['c1', 'c2', 'c3', 'c4'],
  1524. m: 'Four clients',
  1525. e: 'c1, c2, c3 and c4'
  1526. },
  1527. {
  1528. clients: ['c1', 'c2', 'c3', 'c4', 'c5'],
  1529. m: 'Five clients',
  1530. e: 'c1, c2, c3, c4 and c5'
  1531. }
  1532. ]);
  1533. tests.forEach(function (test) {
  1534. it(test.m, function () {
  1535. var label = c.getComponentMessage(test.clients);
  1536. expect(label).to.equal(test.e);
  1537. });
  1538. });
  1539. });
  1540. describe('#togglePreviousSteps', function () {
  1541. beforeEach(function () {
  1542. sinon.stub(obj, 'setStepsEnable', Em.K);
  1543. sinon.stub(obj, 'setLowerStepsDisable', Em.K);
  1544. sinon.stub(App.router, 'get', function () {
  1545. return obj;
  1546. });
  1547. });
  1548. afterEach(function () {
  1549. App.router.get.restore();
  1550. obj.setStepsEnable.restore();
  1551. obj.setLowerStepsDisable.restore();
  1552. });
  1553. it('shouldn\'t do nothing on testMode', function () {
  1554. App.set('testMode', true);
  1555. c.togglePreviousSteps();
  1556. expect(App.router.get.called).to.equal(false);
  1557. App.set('testMode', false);
  1558. });
  1559. Em.A([
  1560. {
  1561. status: 'INSTALL FAILED',
  1562. controllerName: 'installerController',
  1563. e: {
  1564. setStepsEnable: true,
  1565. setLowerStepsDisable: false
  1566. }
  1567. },
  1568. {
  1569. status: 'STARTED',
  1570. controllerName: 'installerController',
  1571. e: {
  1572. setStepsEnable: false,
  1573. setLowerStepsDisable: true
  1574. }
  1575. },
  1576. {
  1577. status: 'INSTALL FAILED',
  1578. controllerName: 'addServiceController',
  1579. e: {
  1580. setStepsEnable: false,
  1581. setLowerStepsDisable: true
  1582. }
  1583. },
  1584. {
  1585. status: 'STARTED',
  1586. controllerName: 'addServiceController',
  1587. e: {
  1588. setStepsEnable: false,
  1589. setLowerStepsDisable: true
  1590. }
  1591. }
  1592. ]).forEach(function (test) {
  1593. it(test.status + ' ' + test.controllerName, function () {
  1594. App.set('testMode', false);
  1595. c.reopen({content: {cluster: {status: test.status}, controllerName: test.controllerName}});
  1596. c.togglePreviousSteps();
  1597. expect(App.router.get.calledWith('installerController')).to.equal(true);
  1598. if (test.e.setStepsEnable) {
  1599. expect(obj.setStepsEnable.calledOnce).to.equal(true);
  1600. }
  1601. else {
  1602. expect(obj.setStepsEnable.called).to.equal(false);
  1603. }
  1604. if (test.e.setLowerStepsDisable) {
  1605. expect(obj.setLowerStepsDisable.calledWith(9)).to.equal(true);
  1606. }
  1607. else {
  1608. expect(obj.setLowerStepsDisable.called).to.equal(false);
  1609. }
  1610. });
  1611. });
  1612. });
  1613. describe('#navigateStep', function () {
  1614. beforeEach(function () {
  1615. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1616. sinon.stub(c, 'loadStep', Em.K);
  1617. sinon.stub(c, 'loadLogData', Em.K);
  1618. sinon.stub(c, 'startPolling', Em.K);
  1619. });
  1620. afterEach(function () {
  1621. c.togglePreviousSteps.restore();
  1622. c.loadStep.restore();
  1623. c.loadLogData.restore();
  1624. c.startPolling.restore();
  1625. });
  1626. it('should set custom data in testMode', function () {
  1627. App.set('testMode', true);
  1628. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1629. c.navigateStep();
  1630. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1631. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1632. expect(c.get('content.cluster.requestId')).to.equal(1);
  1633. App.set('testMode', false);
  1634. });
  1635. it('isCompleted = true, requestId = 1', function () {
  1636. App.set('testMode', false);
  1637. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1638. c.navigateStep();
  1639. expect(c.loadStep.calledOnce).to.equal(true);
  1640. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1641. expect(c.get('progress')).to.equal('100');
  1642. });
  1643. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1644. App.set('testMode', false);
  1645. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1646. c.navigateStep();
  1647. expect(c.loadStep.calledOnce).to.equal(true);
  1648. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1649. });
  1650. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1651. App.set('testMode', false);
  1652. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1653. c.navigateStep();
  1654. expect(c.loadStep.calledOnce).to.equal(true);
  1655. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1656. });
  1657. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1658. App.set('testMode', false);
  1659. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1660. c.navigateStep();
  1661. expect(c.loadStep.calledOnce).to.equal(true);
  1662. expect(c.loadLogData.calledWith(1)).to.equal(true);
  1663. expect(c.startPolling.calledOnce).to.equal(true);
  1664. });
  1665. });
  1666. describe('#launchStartServices', function () {
  1667. beforeEach(function () {
  1668. sinon.spy(App.ajax, 'send');
  1669. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1670. sinon.stub(c, 'saveClusterStatus', Em.K);
  1671. c.reopen({content: {}});
  1672. });
  1673. afterEach(function () {
  1674. App.ajax.send.restore();
  1675. c.togglePreviousSteps.restore();
  1676. c.saveClusterStatus.restore();
  1677. });
  1678. it('should set numPolls to 6 in testMode', function () {
  1679. App.set('testMode', true);
  1680. c.set('numPolls', 0);
  1681. c.launchStartServices();
  1682. expect(c.get('numPolls')).to.equal(6);
  1683. App.set('testMode', false);
  1684. });
  1685. Em.A([
  1686. {
  1687. controllerName: 'installerController',
  1688. clusterName: 'c1',
  1689. e: {
  1690. name: 'wizard.step9.installer.launch_start_services'
  1691. }
  1692. },
  1693. {
  1694. controllerName: 'addHostController',
  1695. clusterName: 'c1',
  1696. wizardController: Em.Object.create({
  1697. getDBProperty: function () {
  1698. return {h1: '', h2: ''};
  1699. }
  1700. }),
  1701. e: {
  1702. name: 'wizard.step9.add_host.launch_start_services',
  1703. data: 'host_name.in(h1,h2)'
  1704. }
  1705. }
  1706. ]).forEach(function (test) {
  1707. it(test.controllerName, function () {
  1708. c.reopen({content: {controllerName: test.controllerName, cluster: {name: test.clusterName}}});
  1709. if (test.wizardController) {
  1710. c.reopen({wizardController: test.wizardController});
  1711. }
  1712. c.launchStartServices();
  1713. var r = App.ajax.send.args[0][0];
  1714. expect(r.data.cluster).to.equal(test.clusterName);
  1715. expect(r.name).to.equal(test.e.name);
  1716. if (test.e.data) {
  1717. expect(r.data.data.contains(test.e.data)).to.equal(true);
  1718. }
  1719. });
  1720. });
  1721. });
  1722. describe('#isServicesStarted', function () {
  1723. beforeEach(function () {
  1724. sinon.stub(c, 'saveClusterStatus', Em.K);
  1725. sinon.stub(c, 'saveInstalledHosts', Em.K);
  1726. });
  1727. afterEach(function () {
  1728. c.saveClusterStatus.restore();
  1729. c.saveInstalledHosts.restore();
  1730. });
  1731. Em.A([
  1732. {
  1733. polledData: [
  1734. {Tasks: {status: 'PENDING'}}
  1735. ],
  1736. m: 'PENDING',
  1737. e: false
  1738. },
  1739. {
  1740. polledData: [
  1741. {Tasks: {status: 'QUEUED'}}
  1742. ],
  1743. m: 'QUEUED',
  1744. e: false
  1745. },
  1746. {
  1747. polledData: [
  1748. {Tasks: {status: 'IN_PROGRESS'}}
  1749. ],
  1750. m: 'IN_PROGRESS',
  1751. e: false
  1752. }
  1753. ]).forEach(function (test) {
  1754. it(test.m, function () {
  1755. var r = c.isServicesStarted(test.polledData);
  1756. expect(r).to.equal(test.e);
  1757. });
  1758. });
  1759. Em.A([
  1760. {
  1761. polledData: [
  1762. {Tasks: {status: 'SUCCESS'}}
  1763. ],
  1764. m: 'tasks ok, isSuccess true',
  1765. isSuccess: true,
  1766. e: {
  1767. status: 'STARTED',
  1768. hasInstallTime: true
  1769. }
  1770. },
  1771. {
  1772. polledData: [
  1773. {Tasks: {status: 'SUCCESS'}}
  1774. ],
  1775. m: 'tasks ok, isSuccess false',
  1776. isSuccess: false,
  1777. e: {
  1778. status: 'START FAILED',
  1779. hasInstallTime: false
  1780. }
  1781. }
  1782. ]).forEach(function (test) {
  1783. it(test.m, function () {
  1784. sinon.stub(c, 'isSuccess', function () {
  1785. return test.isSuccess;
  1786. });
  1787. c.reopen({content: {cluster: {requestId: 2}}});
  1788. var r = c.isServicesStarted(test.polledData);
  1789. var args = c.saveClusterStatus.args[0][0];
  1790. expect(r).to.equal(true);
  1791. expect(c.get('progress')).to.equal('100');
  1792. expect(args.status).to.equal(test.e.status);
  1793. expect(args.requestId).to.equal(2);
  1794. expect(args.hasOwnProperty('installTime')).to.equal(test.e.hasInstallTime);
  1795. expect(args.isCompleted).to.equal(true);
  1796. expect(c.saveInstalledHosts.calledOnce).to.equal(true);
  1797. c.isSuccess.restore();
  1798. });
  1799. });
  1800. });
  1801. describe('#launchStartServicesSuccessCallback', function () {
  1802. beforeEach(function () {
  1803. sinon.stub(c, 'saveClusterStatus', Em.K);
  1804. sinon.stub(c, 'doPolling', Em.K);
  1805. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1806. });
  1807. afterEach(function () {
  1808. c.saveClusterStatus.restore();
  1809. c.doPolling.restore();
  1810. c.hostHasClientsOnly.restore();
  1811. });
  1812. it('should call doPolling if some data were received', function () {
  1813. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1814. expect(c.doPolling.calledOnce).to.equal(true);
  1815. });
  1816. Em.A([
  1817. {
  1818. jsonData: {Requests: {id: 2}},
  1819. e: {
  1820. hostHasClientsOnly: false,
  1821. clusterStatus: {
  1822. status: 'INSTALLED',
  1823. requestId: 2,
  1824. isStartError: false,
  1825. isCompleted: false
  1826. }
  1827. }
  1828. },
  1829. {
  1830. jsonData: null,
  1831. e: {
  1832. hostHasClientsOnly: true,
  1833. clusterStatus: {
  1834. status: 'STARTED',
  1835. isStartError: false,
  1836. isCompleted: true
  1837. },
  1838. status: 'success',
  1839. progress: '100'
  1840. }
  1841. }
  1842. ]).forEach(function (test) {
  1843. it(test.m, function () {
  1844. c.launchStartServicesSuccessCallback(test.jsonData);
  1845. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1846. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1847. if (test.e.status) {
  1848. expect(c.get('status')).to.equal(test.e.status);
  1849. }
  1850. if (test.e.progress) {
  1851. expect(c.get('progress')).to.equal(test.e.progress);
  1852. }
  1853. });
  1854. });
  1855. });
  1856. describe('#getLogsByRequestSuccessCallback', function () {
  1857. beforeEach(function () {
  1858. sinon.stub(c, 'isAllComponentsInstalled', Em.K);
  1859. sinon.stub(window, 'setTimeout', Em.K);
  1860. });
  1861. afterEach(function () {
  1862. c.isAllComponentsInstalled.restore();
  1863. window.setTimeout.restore();
  1864. });
  1865. Em.A([
  1866. {
  1867. polling: false,
  1868. status: 'INSTALL FAILED',
  1869. m: 'should call isAllComponentsInstalled',
  1870. e: true
  1871. },
  1872. {
  1873. polling: false,
  1874. status: 'INSTALLED',
  1875. m: 'shouldn\'t call isAllComponentsInstalled',
  1876. e: false
  1877. },
  1878. {
  1879. polling: true,
  1880. status: 'INSTALL FAILED',
  1881. m: 'shouldn\'t call isAllComponentsInstalled (2)',
  1882. e: false
  1883. },
  1884. {
  1885. polling: true,
  1886. status: 'INSTALLED',
  1887. m: 'shouldn\'t call isAllComponentsInstalled (3)',
  1888. e: false
  1889. }
  1890. ]).forEach(function (test) {
  1891. it(test.m, function () {
  1892. sinon.stub(c, 'parseHostInfo', Em.K);
  1893. c.reopen({content: {cluster: {status: test.status}}});
  1894. c.getLogsByRequestSuccessCallback({}, {}, {polling: test.polling});
  1895. if (test.e) {
  1896. expect(c.isAllComponentsInstalled.calledOnce).to.equal(true);
  1897. }
  1898. else {
  1899. expect(c.isAllComponentsInstalled.called).to.equal(false);
  1900. }
  1901. c.parseHostInfo.restore();
  1902. });
  1903. });
  1904. });
  1905. });