step9_test.js 56 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923
  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. if (test.e.b) {
  933. expect(test.host.message).to.be.equal(test.e.message);
  934. }
  935. else {
  936. expect(test.host.message).to.be.not.equal(test.e.message);
  937. }
  938. });
  939. });
  940. });
  941. describe('#progressPerHost', function () {
  942. var tests = Em.A([
  943. {
  944. cluster: {status: 'PENDING'},
  945. host: Em.Object.create({progress: 0}),
  946. actions: {
  947. 'COMPLETED': 2,
  948. 'QUEUED': 2,
  949. 'IN_PROGRESS': 1
  950. },
  951. e: {progress: 17},
  952. s: false,
  953. m: 'All types of status available. cluster status PENDING'
  954. },
  955. {
  956. cluster: {status: 'PENDING'},
  957. host: Em.Object.create({progress: 0}),
  958. actions: {},
  959. e: {progress: 33},
  960. s: false,
  961. m: 'No tasks available. cluster status PENDING'
  962. },
  963. {
  964. cluster: {status: 'PENDING'},
  965. host: Em.Object.create({progress: 0}),
  966. actions: {},
  967. e: {progress: 100},
  968. s: true,
  969. m: 'No tasks available. cluster status PENDING. skipComponentStartAfterInstall is true.'
  970. },
  971. {
  972. cluster: {status: 'INSTALLED'},
  973. host: Em.Object.create({progress: 0}),
  974. actions: {},
  975. e: {progress: 100},
  976. m: 'No tasks available. cluster status INSTALLED'
  977. },
  978. {
  979. cluster: {status: 'INSTALLED'},
  980. host: Em.Object.create({progress: 0}),
  981. actions: {
  982. 'COMPLETED': 2,
  983. 'QUEUED': 2,
  984. 'IN_PROGRESS': 1
  985. },
  986. e: {progress: 66},
  987. s: false,
  988. m: 'All types of status available. cluster status INSTALLED'
  989. },
  990. {
  991. cluster: {status: 'FAILED'},
  992. host: Em.Object.create({progress: 0}),
  993. actions: {},
  994. e: {progress: 100},
  995. s: false,
  996. m: 'Cluster status is not PENDING or INSTALLED'
  997. },
  998. {
  999. cluster: {status: 'INSTALLED'},
  1000. host: Em.Object.create({progress: 0}),
  1001. actions: {
  1002. 'COMPLETED': 150,
  1003. 'QUEUED': 0,
  1004. 'IN_PROGRESS': 1
  1005. },
  1006. e: {progress: 99},
  1007. s: false,
  1008. m: '150 tasks on host'
  1009. },
  1010. {
  1011. cluster: {status: 'INSTALLED'},
  1012. host: Em.Object.create({progress: 0}),
  1013. actions: {
  1014. 'COMPLETED': 498,
  1015. 'QUEUED': 1,
  1016. 'IN_PROGRESS': 1
  1017. },
  1018. e: {progress: 99},
  1019. s: false,
  1020. m: '500 tasks on host'
  1021. },
  1022. {
  1023. cluster: {status: 'INSTALLED'},
  1024. host: Em.Object.create({progress: 0}),
  1025. actions: {
  1026. 'COMPLETED': 150,
  1027. 'QUEUED': 0,
  1028. 'IN_PROGRESS': 0
  1029. },
  1030. e: {progress: 100},
  1031. s: false,
  1032. m: '100 tasks, 100 completed'
  1033. },
  1034. {
  1035. cluster: {status: 'INSTALLED'},
  1036. host: Em.Object.create({progress: 0}),
  1037. actions: {
  1038. 'COMPLETED': 1,
  1039. 'QUEUED': 0,
  1040. 'IN_PROGRESS': 0
  1041. },
  1042. e: {progress: 100},
  1043. s: false,
  1044. m: '1 task, 1 completed'
  1045. }
  1046. ]);
  1047. tests.forEach(function (test) {
  1048. describe(test.m, function () {
  1049. beforeEach(function () {
  1050. var actions = [];
  1051. for (var prop in test.actions) {
  1052. if (test.actions.hasOwnProperty(prop) && test.actions[prop]) {
  1053. for (var i = 0; i < test.actions[prop]; i++) {
  1054. actions.push({Tasks: {status: prop}});
  1055. }
  1056. }
  1057. }
  1058. c.reopen({content: {cluster: {status: test.cluster.status}}});
  1059. App.set('supports.skipComponentStartAfterInstall', test.s);
  1060. this.progress = c.progressPerHost(actions, test.host);
  1061. });
  1062. it('progress is ' + test.e.progress, function () {
  1063. expect(this.progress).to.equal(test.e.progress);
  1064. });
  1065. it('host progress is ' + test.e.progress.toString(), function () {
  1066. expect(test.host.progress).to.equal(test.e.progress.toString());
  1067. });
  1068. });
  1069. });
  1070. });
  1071. describe('#clearStep', function () {
  1072. beforeEach(function () {
  1073. c.reopen({hosts: [{},{},{}]});
  1074. c.clearStep();
  1075. });
  1076. it('hosts are empty', function () {
  1077. expect(c.get('hosts.length')).to.equal(0);
  1078. });
  1079. it('status is `info`', function () {
  1080. expect(c.get('status')).to.equal('info');
  1081. });
  1082. it('progress is 0', function () {
  1083. expect(c.get('progress')).to.equal('0');
  1084. });
  1085. it('numPolls is 1', function () {
  1086. expect(c.get('numPolls')).to.equal(1);
  1087. });
  1088. });
  1089. describe('#replacePolledData', function () {
  1090. it('replacing polled data', function () {
  1091. c.reopen({polledData: [{},{},{}]});
  1092. var newPolledData = [{}];
  1093. c.replacePolledData(newPolledData);
  1094. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  1095. });
  1096. });
  1097. describe('#isSuccess', function () {
  1098. var tests = Em.A([
  1099. {
  1100. polledData: [
  1101. {Tasks: {status: 'COMPLETED'}},
  1102. {Tasks: {status: 'COMPLETED'}}
  1103. ],
  1104. e: true,
  1105. m: 'All tasks are COMPLETED'
  1106. },
  1107. {
  1108. polledData: [
  1109. {Tasks: {status: 'COMPLETED'}},
  1110. {Tasks: {status: 'FAILED'}}
  1111. ],
  1112. e: false,
  1113. m: 'Not all tasks are COMPLETED'
  1114. }
  1115. ]);
  1116. tests.forEach(function (test) {
  1117. it(test.m, function () {
  1118. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  1119. });
  1120. });
  1121. });
  1122. describe('#isStepFailed', function () {
  1123. beforeEach(function() {
  1124. sinon.stub(App, 'get', function(k) {
  1125. if (k === 'components.slaves') {
  1126. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  1127. }
  1128. return Em.get(App, k);
  1129. });
  1130. });
  1131. afterEach(function() {
  1132. App.get.restore();
  1133. });
  1134. var tests = Em.A([
  1135. {
  1136. polledData: [
  1137. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1138. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  1139. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1140. ],
  1141. e: true,
  1142. m: 'GANGLIA_MONITOR 2/3 failed'
  1143. },
  1144. {
  1145. polledData: [
  1146. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1147. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  1148. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1149. ],
  1150. e: false,
  1151. m: 'GANGLIA_MONITOR 1/3 failed'
  1152. },
  1153. {
  1154. polledData: [
  1155. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1156. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  1157. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1158. ],
  1159. e: true,
  1160. m: 'HBASE_REGIONSERVER 2/3 failed'
  1161. },
  1162. {
  1163. polledData: [
  1164. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1165. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  1166. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1167. ],
  1168. e: false,
  1169. m: 'HBASE_REGIONSERVER 1/3 failed'
  1170. },
  1171. {
  1172. polledData: [
  1173. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1174. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  1175. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1176. ],
  1177. e: true,
  1178. m: 'TASKTRACKER 2/3 failed'
  1179. },
  1180. {
  1181. polledData: [
  1182. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1183. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  1184. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1185. ],
  1186. e: false,
  1187. m: 'TASKTRACKER 1/3 failed'
  1188. },
  1189. {
  1190. polledData: [
  1191. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1192. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  1193. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1194. ],
  1195. e: true,
  1196. m: 'DATANODE 2/3 failed'
  1197. },
  1198. {
  1199. polledData: [
  1200. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1201. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1202. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1203. ],
  1204. e: false,
  1205. m: 'DATANODE 1/3 failed'
  1206. },
  1207. {
  1208. polledData: [
  1209. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  1210. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1211. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1212. ],
  1213. e: true,
  1214. m: 'NAMENODE failed'
  1215. },
  1216. {
  1217. polledData: [
  1218. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  1219. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1220. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1221. ],
  1222. e: false,
  1223. m: 'Nothing failed failed'
  1224. }
  1225. ]);
  1226. tests.forEach(function (test) {
  1227. it(test.m, function () {
  1228. c.reopen({polledData: test.polledData});
  1229. expect(c.isStepFailed()).to.equal(test.e);
  1230. });
  1231. });
  1232. });
  1233. describe('#setLogTasksStatePerHost', function () {
  1234. var tests = Em.A([
  1235. {
  1236. tasksPerHost: [
  1237. {Tasks: {id: 1, status: 'COMPLETED'}},
  1238. {Tasks: {id: 2, status: 'COMPLETED'}}
  1239. ],
  1240. tasks: [],
  1241. e: {m: 'COMPLETED', l: 2},
  1242. m: 'host didn\'t have tasks and got 2 new'
  1243. },
  1244. {
  1245. tasksPerHost: [
  1246. {Tasks: {id: 1, status: 'COMPLETED'}},
  1247. {Tasks: {id: 2, status: 'COMPLETED'}}
  1248. ],
  1249. tasks: [
  1250. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1251. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1252. ],
  1253. e: {m: 'COMPLETED', l: 2},
  1254. m: 'host had 2 tasks and got both updated'
  1255. },
  1256. {
  1257. tasksPerHost: [],
  1258. tasks: [
  1259. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1260. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1261. ],
  1262. e: {m: 'IN_PROGRESS', l: 2},
  1263. m: 'host had 2 tasks and didn\'t get updates'
  1264. },
  1265. {
  1266. tasksPerHost: [
  1267. {Tasks: {id: 1, status: 'COMPLETED'}},
  1268. {Tasks: {id: 2, status: 'COMPLETED'}},
  1269. {Tasks: {id: 3, status: 'COMPLETED'}}
  1270. ],
  1271. tasks: [
  1272. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1273. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1274. ],
  1275. e: {m: 'COMPLETED', l: 3},
  1276. m: 'host had 2 tasks and got both updated and 1 new'
  1277. }
  1278. ]);
  1279. tests.forEach(function (test) {
  1280. it(test.m, function () {
  1281. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  1282. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  1283. var host = c.get('hosts')[0];
  1284. expect(host.get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  1285. expect(host.get('logTasks.length')).to.equal(test.e.l);
  1286. });
  1287. });
  1288. });
  1289. // On completion of Start all services error callback function,
  1290. // Cluster Status should be INSTALL FAILED
  1291. // All progress bar on the screen should be finished (100%) with blue color.
  1292. // Retry button should be enabled, next button should be disabled
  1293. describe('#launchStartServicesErrorCallback', function () {
  1294. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1295. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1296. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1297. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1298. expect(c.get('progress')).to.equal('100');
  1299. expect(c.get('status')).to.equal('failed');
  1300. });
  1301. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1302. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1303. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1304. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1305. expect(c.get('hosts').everyProperty('progress', '100')).to.be.true;
  1306. expect(c.get('hosts').everyProperty('status', 'info')).to.be.true;
  1307. });
  1308. it('Next button should be disabled', function () {
  1309. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1310. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1311. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1312. expect(c.get('isSubmitDisabled')).to.equal(true);
  1313. });
  1314. });
  1315. describe('#submit', function () {
  1316. beforeEach(function () {
  1317. sinon.stub(App.router, 'send', Em.K);
  1318. });
  1319. afterEach(function () {
  1320. App.router.send.restore();
  1321. });
  1322. it('should call App.router.send', function () {
  1323. c.submit();
  1324. expect(App.router.send.calledWith('next')).to.equal(true);
  1325. });
  1326. });
  1327. describe('#back', function () {
  1328. beforeEach(function () {
  1329. sinon.stub(App.router, 'send', Em.K);
  1330. });
  1331. afterEach(function () {
  1332. App.router.send.restore();
  1333. });
  1334. it('should call App.router.send', function () {
  1335. c.reopen({isSubmitDisabled: false});
  1336. c.back();
  1337. expect(App.router.send.calledWith('back')).to.equal(true);
  1338. });
  1339. it('shouldn\'t call App.router.send', function () {
  1340. c.reopen({isSubmitDisabled: true});
  1341. c.back();
  1342. expect(App.router.send.called).to.equal(false);
  1343. });
  1344. });
  1345. describe('#loadStep', function () {
  1346. beforeEach(function () {
  1347. sinon.stub(c, 'clearStep', Em.K);
  1348. sinon.stub(c, 'loadHosts', Em.K);
  1349. });
  1350. afterEach(function () {
  1351. c.clearStep.restore();
  1352. c.loadHosts.restore();
  1353. });
  1354. it('should call clearStep', function () {
  1355. c.loadStep();
  1356. expect(c.clearStep.calledOnce).to.equal(true);
  1357. });
  1358. it('should call loadHosts', function () {
  1359. c.loadStep();
  1360. expect(c.loadHosts.calledOnce).to.equal(true);
  1361. });
  1362. });
  1363. describe('#startPolling', function () {
  1364. beforeEach(function () {
  1365. sinon.stub(c, 'reloadErrorCallback', Em.K);
  1366. sinon.stub(c, 'doPolling', Em.K);
  1367. });
  1368. afterEach(function () {
  1369. c.reloadErrorCallback.restore();
  1370. c.doPolling.restore();
  1371. });
  1372. it('should set isSubmitDisabled to true', function () {
  1373. c.set('isSubmitDisabled', false);
  1374. c.startPolling();
  1375. expect(c.get('isSubmitDisabled')).to.equal(true);
  1376. });
  1377. it('should call doPolling', function () {
  1378. c.startPolling();
  1379. expect(c.doPolling.calledOnce).to.equal(true);
  1380. });
  1381. });
  1382. describe('#loadLogData', function () {
  1383. beforeEach(function () {
  1384. obj.reopen({
  1385. cluster: {oldRequestsId: [1,2,3]},
  1386. getDBProperty: function (name) {
  1387. return this.get(name);
  1388. }
  1389. });
  1390. c.reopen({wizardController: obj});
  1391. sinon.stub(c, 'getLogsByRequest', Em.K);
  1392. });
  1393. afterEach(function () {
  1394. c.getLogsByRequest.restore();
  1395. });
  1396. it('should call getLogsByRequest 1 time with 3', function () {
  1397. c.loadLogData(true);
  1398. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  1399. });
  1400. });
  1401. describe('#loadCurrentTaskLog', function () {
  1402. beforeEach(function () {
  1403. sinon.stub(c, 'loadLogData', Em.K);
  1404. c.set('wizardController', Em.Object.create({
  1405. getDBProperty: Em.K
  1406. }));
  1407. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1408. });
  1409. afterEach(function () {
  1410. c.loadLogData.restore();
  1411. c.togglePreviousSteps.restore();
  1412. });
  1413. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1414. c.set('currentOpenTaskId', null);
  1415. c.loadCurrentTaskLog();
  1416. var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
  1417. expect(args).not.exists;
  1418. });
  1419. it('should call App.ajax.send with provided data', function () {
  1420. c.set('currentOpenTaskId', 1);
  1421. c.set('currentOpenTaskRequestId', 2);
  1422. c.set('content', {cluster: {name: 3}});
  1423. c.loadCurrentTaskLog();
  1424. var args = testHelpers.findAjaxRequest('name', 'background_operations.get_by_task');
  1425. expect(args[0]).exists;
  1426. expect(args[0].data).to.be.eql({taskId: 1, requestId: 2, clusterName: 3});
  1427. });
  1428. });
  1429. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1430. beforeEach(function() {
  1431. sinon.stub(c, 'getLogsByRequest', Em.K);
  1432. sinon.stub(c, 'loadLogData', Em.K);
  1433. });
  1434. afterEach(function() {
  1435. c.getLogsByRequest.restore();
  1436. c.loadLogData.restore();
  1437. });
  1438. it('should increment logTasksChangesCounter', function () {
  1439. c.set('logTasksChangesCounter', 0);
  1440. c.loadCurrentTaskLogSuccessCallback();
  1441. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1442. });
  1443. it('should update stdout, stderr', function () {
  1444. c.set('currentOpenTaskId', 1);
  1445. c.reopen({
  1446. hosts: [
  1447. Em.Object.create({
  1448. name: 'h1',
  1449. logTasks: [
  1450. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1451. ]
  1452. })
  1453. ]
  1454. });
  1455. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1456. c.loadCurrentTaskLogSuccessCallback(data);
  1457. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1458. expect(t.stdout).to.equal('stdout');
  1459. expect(t.stderr).to.equal('stderr');
  1460. });
  1461. it('shouldn\'t update stdout, stderr', function () {
  1462. c.set('currentOpenTaskId', 1);
  1463. c.reopen({
  1464. hosts: [
  1465. Em.Object.create({
  1466. name: 'h1',
  1467. logTasks: [
  1468. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1469. ]
  1470. })
  1471. ]
  1472. });
  1473. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1474. c.loadCurrentTaskLogSuccessCallback(data);
  1475. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1476. expect(t.stdout).to.equal('');
  1477. expect(t.stderr).to.equal('');
  1478. });
  1479. it('shouldn\'t update stdout, stderr (2)', function () {
  1480. c.set('currentOpenTaskId', 1);
  1481. c.reopen({
  1482. hosts: [
  1483. Em.Object.create({
  1484. name: 'h2',
  1485. logTasks: [
  1486. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1487. ]
  1488. })
  1489. ]
  1490. });
  1491. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1492. c.loadCurrentTaskLogSuccessCallback(data);
  1493. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1494. expect(t.stdout).to.equal('');
  1495. expect(t.stderr).to.equal('');
  1496. });
  1497. });
  1498. describe('#loadCurrentTaskLogErrorCallback', function () {
  1499. it('should set currentOpenTaskId to 0', function () {
  1500. c.set('currentOpenTaskId', 123);
  1501. c.loadCurrentTaskLogErrorCallback();
  1502. expect(c.get('currentOpenTaskId')).to.equal(0);
  1503. });
  1504. });
  1505. describe('#doPolling', function () {
  1506. beforeEach(function () {
  1507. sinon.stub(c, 'getLogsByRequest', Em.K);
  1508. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1509. });
  1510. afterEach(function () {
  1511. c.getLogsByRequest.restore();
  1512. c.togglePreviousSteps.restore();
  1513. });
  1514. it('should call getLogsByRequest', function () {
  1515. c.set('content', {cluster: {requestId: 1}});
  1516. c.doPolling();
  1517. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1518. });
  1519. });
  1520. describe('#isAllComponentsInstalledErrorCallback', function () {
  1521. beforeEach(function () {
  1522. sinon.stub(c, 'saveClusterStatus', Em.K);
  1523. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1524. });
  1525. afterEach(function () {
  1526. c.saveClusterStatus.restore();
  1527. c.togglePreviousSteps.restore();
  1528. });
  1529. it('should call saveClusterStatus', function () {
  1530. c.isAllComponentsInstalledErrorCallback({});
  1531. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1532. });
  1533. });
  1534. describe('#navigateStep', function () {
  1535. beforeEach(function () {
  1536. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1537. sinon.stub(c, 'loadStep', Em.K);
  1538. sinon.stub(c, 'loadLogData', Em.K);
  1539. sinon.stub(c, 'startPolling', Em.K);
  1540. });
  1541. afterEach(function () {
  1542. c.togglePreviousSteps.restore();
  1543. c.loadStep.restore();
  1544. c.loadLogData.restore();
  1545. c.startPolling.restore();
  1546. });
  1547. it('isCompleted = true, requestId = 1', function () {
  1548. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1549. c.navigateStep();
  1550. expect(c.loadStep.calledOnce).to.equal(true);
  1551. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1552. expect(c.get('progress')).to.equal('100');
  1553. });
  1554. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1555. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1556. c.navigateStep();
  1557. expect(c.loadStep.calledOnce).to.equal(true);
  1558. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1559. });
  1560. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1561. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1562. c.navigateStep();
  1563. expect(c.loadStep.calledOnce).to.equal(true);
  1564. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1565. });
  1566. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1567. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1568. c.navigateStep();
  1569. expect(c.loadStep.calledOnce).to.equal(true);
  1570. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1571. });
  1572. });
  1573. describe('#launchStartServicesSuccessCallback', function () {
  1574. beforeEach(function () {
  1575. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1576. return $.ajax();
  1577. });
  1578. sinon.stub(c, 'saveClusterStatus', Em.K);
  1579. sinon.stub(c, 'doPolling', Em.K);
  1580. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1581. });
  1582. afterEach(function () {
  1583. c.saveClusterStatus.restore();
  1584. c.doPolling.restore();
  1585. c.hostHasClientsOnly.restore();
  1586. App.clusterStatus.setClusterStatus.restore();
  1587. });
  1588. it('should call doPolling if some data were received', function () {
  1589. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1590. expect(c.doPolling.calledOnce).to.equal(true);
  1591. });
  1592. Em.A([
  1593. {
  1594. jsonData: {Requests: {id: 2}},
  1595. e: {
  1596. hostHasClientsOnly: false,
  1597. clusterStatus: {
  1598. status: 'INSTALLED',
  1599. requestId: 2,
  1600. isStartError: false,
  1601. isCompleted: false
  1602. }
  1603. }
  1604. },
  1605. {
  1606. jsonData: null,
  1607. e: {
  1608. hostHasClientsOnly: true,
  1609. clusterStatus: {
  1610. status: 'STARTED',
  1611. isStartError: false,
  1612. isCompleted: true
  1613. },
  1614. status: 'success',
  1615. progress: '100'
  1616. }
  1617. }
  1618. ]).forEach(function (test) {
  1619. describe(test.m, function () {
  1620. beforeEach(function () {
  1621. c.launchStartServicesSuccessCallback(test.jsonData);
  1622. });
  1623. it('hostHasClientsOnly is called with valid arguments', function () {
  1624. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1625. });
  1626. it('saveClusterStatus is called with valid arguments', function () {
  1627. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1628. });
  1629. if (test.e.status) {
  1630. it('status is valid', function () {
  1631. expect(c.get('status')).to.equal(test.e.status);
  1632. });
  1633. }
  1634. if (test.e.progress) {
  1635. it('progress is valid', function () {
  1636. expect(c.get('progress')).to.equal(test.e.progress);
  1637. });
  1638. }
  1639. });
  1640. });
  1641. });
  1642. describe('#isAllComponentsInstalledSuccessCallback', function () {
  1643. var hosts = [
  1644. Em.Object.create({name: 'h1', status: '', message: '', progress: ''}),
  1645. Em.Object.create({name: 'h2', status: '', message: '', progress: ''})
  1646. ];
  1647. var jsonData = {
  1648. items: [
  1649. {
  1650. Hosts: {
  1651. host_state: 'HEARTBEAT_LOST',
  1652. host_name: 'h1'
  1653. },
  1654. host_components: [
  1655. {
  1656. HostRoles: {
  1657. component_name: 'c1'
  1658. }
  1659. },
  1660. {
  1661. HostRoles: {
  1662. component_name: 'c2'
  1663. }
  1664. }
  1665. ]
  1666. },
  1667. {
  1668. Hosts: {
  1669. host_state: 'HEARTBEAT_LOST',
  1670. host_name: 'h2'
  1671. },
  1672. host_components: [
  1673. {
  1674. HostRoles: {
  1675. component_name: 'c3'
  1676. }
  1677. },
  1678. {
  1679. HostRoles: {
  1680. component_name: 'c4'
  1681. }
  1682. }
  1683. ]
  1684. }
  1685. ]
  1686. };
  1687. beforeEach(function () {
  1688. sinon.stub(c, 'changeParseHostInfo', Em.K);
  1689. sinon.stub(c, 'launchStartServices', Em.K);
  1690. sinon.stub(c, 'saveClusterStatus', Em.K);
  1691. c.set('hosts', hosts);
  1692. c.set('content', Em.Object.create({
  1693. slaveComponentHosts: [
  1694. {hosts: [{isInstalled: true, hostName: 'h1'}]},
  1695. {hosts: [{isInstalled: false, hostName: 'h2'}]}
  1696. ],
  1697. masterComponentHosts: []
  1698. }));
  1699. c.isAllComponentsInstalledSuccessCallback(jsonData);
  1700. this.clusterStatus = c.saveClusterStatus.args[0][0];
  1701. });
  1702. afterEach(function () {
  1703. c.changeParseHostInfo.restore();
  1704. c.launchStartServices.restore();
  1705. c.saveClusterStatus.restore();
  1706. });
  1707. it('cluster status / status', function () {
  1708. expect(this.clusterStatus.status).to.be.equal('INSTALL FAILED');
  1709. });
  1710. it('cluster status / isStartError', function () {
  1711. expect(this.clusterStatus.isStartError).to.be.true;
  1712. });
  1713. it('cluster status / isCompleted', function () {
  1714. expect(this.clusterStatus.isCompleted).to.be.false;
  1715. });
  1716. it('each host progress is 100', function () {
  1717. expect(c.get('hosts').everyProperty('progress', '100')).to.be.true;
  1718. });
  1719. it('each host status is `heartbeat_lost`', function () {
  1720. expect(c.get('hosts').everyProperty('status', 'heartbeat_lost')).to.be.true;
  1721. });
  1722. it('overall progress is 100', function () {
  1723. expect(c.get('progress')).to.be.equal('100');
  1724. });
  1725. });
  1726. describe('#loadDoServiceChecksFlagSuccessCallback', function () {
  1727. var data = {
  1728. RootServiceComponents: {
  1729. properties: {
  1730. 'skip.service.checks': 'true'
  1731. }
  1732. }
  1733. };
  1734. it('skipServiceChecks should be true', function () {
  1735. c.loadDoServiceChecksFlagSuccessCallback(data);
  1736. expect(c.get('skipServiceChecks')).to.be.true;
  1737. });
  1738. it('skipServiceChecks should be false', function () {
  1739. data.RootServiceComponents.properties['skip.service.checks'] = 'false';
  1740. c.loadDoServiceChecksFlagSuccessCallback(data);
  1741. expect(c.get('skipServiceChecks')).to.be.false;
  1742. });
  1743. });
  1744. describe('#isNextButtonDisabled', function () {
  1745. var cases = [
  1746. {
  1747. nextBtnClickInProgress: true,
  1748. isSubmitDisabled: true,
  1749. isNextButtonDisabled: true,
  1750. description: 'button clicked, submit disabled',
  1751. title: 'next button disabled'
  1752. },
  1753. {
  1754. nextBtnClickInProgress: true,
  1755. isSubmitDisabled: false,
  1756. isNextButtonDisabled: true,
  1757. description: 'button clicked, submit not disabled',
  1758. title: 'next button disabled'
  1759. },
  1760. {
  1761. nextBtnClickInProgress: false,
  1762. isSubmitDisabled: true,
  1763. isNextButtonDisabled: true,
  1764. description: 'no button clicked, submit disabled',
  1765. title: 'next button disabled'
  1766. },
  1767. {
  1768. nextBtnClickInProgress: false,
  1769. isSubmitDisabled: false,
  1770. isNextButtonDisabled: false,
  1771. description: 'no button clicked, submit not disabled',
  1772. title: 'next button enabled'
  1773. }
  1774. ];
  1775. cases.forEach(function (item) {
  1776. describe(item.description, function () {
  1777. beforeEach(function () {
  1778. c.reopen({
  1779. isSubmitDisabled: item.isSubmitDisabled
  1780. });
  1781. sinon.stub(App, 'get').withArgs('router.nextBtnClickInProgress').returns(item.nextBtnClickInProgress);
  1782. c.propertyDidChange('isSubmitDisabled');
  1783. c.propertyDidChange('App.router.nextBtnClickInProgress');
  1784. });
  1785. afterEach(function () {
  1786. App.get.restore();
  1787. });
  1788. it(item.title, function () {
  1789. expect(c.get('isNextButtonDisabled')).to.equal(item.isNextButtonDisabled);
  1790. });
  1791. });
  1792. });
  1793. });
  1794. });