step9_test.js 55 KB

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