step9_test.js 55 KB

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