step9_test.js 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var Ember = require('ember');
  19. var App = require('app');
  20. require('models/stack_service_component');
  21. require('models/hosts');
  22. require('controllers/wizard');
  23. require('controllers/installer');
  24. require('controllers/wizard/step9_controller');
  25. require('utils/helper');
  26. require('utils/ajax/ajax');
  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. sinon.stub(App.ajax, 'send', function() {
  54. return {
  55. then: function() {
  56. return true;
  57. },
  58. retry: function() {
  59. return {
  60. then: Em.K,
  61. complete: Em.K
  62. };
  63. },
  64. complete: Em.K
  65. };
  66. });
  67. });
  68. afterEach(function () {
  69. modelSetup.cleanStackServiceComponent();
  70. App.ajax.send.restore();
  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. it('All should have status "pending" and message "Waiting"', function () {
  181. var hosts = {'host1': Em.Object.create({status: 'failed', message: 'Failed'}), 'host2': Em.Object.create({status: 'success', message: 'Success'})};
  182. c.reopen({content: {hosts: hosts}});
  183. c.resetHostsForRetry();
  184. for (var name in hosts) {
  185. if (hosts.hasOwnProperty(name)) {
  186. expect(c.get('content.hosts')[name].get('status', 'pending')).to.equal('pending');
  187. expect(c.get('content.hosts')[name].get('message', 'Waiting')).to.equal('Waiting');
  188. }
  189. }
  190. });
  191. });
  192. describe('#setParseHostInfo', function () {
  193. var tasks = Em.A([
  194. Em.Object.create({
  195. Tasks: Em.Object.create({
  196. host_name: 'host1',
  197. status: 'PENDING'
  198. })
  199. }),
  200. Em.Object.create({
  201. Tasks: Em.Object.create({
  202. host_name: 'host1',
  203. status: 'PENDING'
  204. })
  205. })
  206. ]);
  207. var content = Em.Object.create({
  208. cluster: Em.Object.create({
  209. requestId: '11',
  210. status: 'PENDING'
  211. })
  212. });
  213. beforeEach(function(){
  214. c.set('content', content)
  215. });
  216. it('Should make parseHostInfo false"', function () {
  217. var polledData = Em.Object.create({
  218. tasks: tasks,
  219. Requests: Em.Object.create({
  220. id: '222'
  221. })
  222. });
  223. c.setParseHostInfo(polledData);
  224. expect(c.get('parseHostInfo')).to.be.false;
  225. });
  226. it('Should set polledData"', function () {
  227. var polledData = Em.Object.create({
  228. tasks: tasks,
  229. Requests: Em.Object.create({
  230. id: '11'
  231. })
  232. });
  233. c.setParseHostInfo(polledData);
  234. var expected = [
  235. {
  236. "Tasks": {
  237. "status": "PENDING",
  238. "host_name": "host1",
  239. "request_id": "11"
  240. }
  241. },
  242. {
  243. "Tasks": {
  244. "status": "PENDING",
  245. "host_name": "host1",
  246. "request_id": "11"
  247. }
  248. }
  249. ];
  250. var result = JSON.parse(JSON.stringify(c.get('polledData')));
  251. expect(result).to.eql(expected);
  252. });
  253. it('Should set progress for hosts"', function () {
  254. var polledData = Em.Object.create({
  255. tasks: tasks,
  256. Requests: Em.Object.create({
  257. id: '11'
  258. })
  259. });
  260. var hosts = Em.A([
  261. Em.Object.create({
  262. name: 'host1',
  263. logTasks: [
  264. {Tasks: {role: 'HDFS_CLIENT'}},
  265. {Tasks: {role: 'DATANODE'}}
  266. ],
  267. status: 'old_status',
  268. progress: '10',
  269. isNoTasksForInstall: true,
  270. e: {status: 'old_status', progress: '10'}
  271. }),
  272. Em.Object.create({
  273. name: 'host2',
  274. logTasks: [
  275. {Tasks: {role: 'HDFS_CLIENT'}}
  276. ],
  277. status: 'old_status',
  278. progress: '10',
  279. e: {status: 'success', progress: '100'}
  280. })
  281. ]);
  282. c.set('hosts', hosts);
  283. c.setParseHostInfo(polledData);
  284. var expected = [
  285. {
  286. "name": "host1",
  287. "logTasks": [
  288. {
  289. "Tasks": {
  290. "role": "HDFS_CLIENT",
  291. "status": "PENDING"
  292. }
  293. },
  294. {
  295. "Tasks": {
  296. "role": "DATANODE"
  297. }
  298. }
  299. ],
  300. "progress": "0",
  301. "isNoTasksForInstall": false,
  302. "e": {
  303. "status": "old_status",
  304. "progress": "10"
  305. },
  306. "status": "in_progress",
  307. "message": ""
  308. },
  309. {
  310. "name": "host2",
  311. "logTasks": [
  312. {
  313. "Tasks": {
  314. "role": "HDFS_CLIENT"
  315. }
  316. }
  317. ],
  318. "progress": "33",
  319. "e": {
  320. "status": "success",
  321. "progress": "100"
  322. },
  323. "status": "pending",
  324. "isNoTasksForInstall": true,
  325. "message": "Install complete (Waiting to start)"
  326. }
  327. ];
  328. var result = JSON.parse(JSON.stringify(c.get('hosts')));
  329. expect(result).to.eql(expected);
  330. });
  331. });
  332. var hosts_for_load_and_render = {
  333. 'host1': {
  334. message: 'message1',
  335. status: 'unknown',
  336. progress: '1',
  337. logTasks: [
  338. {},
  339. {}
  340. ],
  341. bootStatus: 'REGISTERED'
  342. },
  343. 'host2': {
  344. message: '',
  345. status: 'failed',
  346. progress: '1',
  347. logTasks: [
  348. {},
  349. {}
  350. ],
  351. bootStatus: ''
  352. },
  353. 'host3': {
  354. message: '',
  355. status: 'waiting',
  356. progress: null,
  357. logTasks: [
  358. {},
  359. {}
  360. ],
  361. bootStatus: ''
  362. },
  363. 'host4': {
  364. message: 'message4',
  365. status: null,
  366. progress: '10',
  367. logTasks: [
  368. {}
  369. ],
  370. bootStatus: 'REGISTERED'
  371. }
  372. };
  373. describe('#loadHosts', function () {
  374. beforeEach(function() {
  375. c.reopen({content: {hosts: hosts_for_load_and_render}});
  376. c.loadHosts();
  377. });
  378. it('Only REGISTERED hosts', function () {
  379. var loaded_hosts = c.get('hosts');
  380. expect(loaded_hosts.length).to.equal(2);
  381. });
  382. it('All hosts have progress 0', function () {
  383. var loaded_hosts = c.get('hosts');
  384. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  385. });
  386. it('All hosts have progress 0', function () {
  387. var loaded_hosts = c.get('hosts');
  388. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  389. });
  390. it('All host don\'t have logTasks', function () {
  391. var loaded_hosts = c.get('hosts');
  392. expect(loaded_hosts.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. it('Should return 100% completed', function () {
  444. var polledData = Em.A([
  445. Em.Object.create({
  446. Tasks: Em.Object.create({
  447. status: 'NONE'
  448. })
  449. }),
  450. Em.Object.create({
  451. Tasks: Em.Object.create({
  452. status: 'NONE'
  453. })
  454. })
  455. ]);
  456. c.setProperties({
  457. status: 'failed',
  458. isPolling: true,
  459. hosts: Em.A([
  460. Em.Object.create({
  461. progress: 0
  462. })
  463. ])
  464. });
  465. c.setIsServicesInstalled(polledData);
  466. expect(c.get('progress')).to.equal('100');
  467. expect(c.get('isPolling')).to.be.false;
  468. });
  469. it('Should return 34% completed', function () {
  470. var polledData = Em.A([
  471. Em.Object.create({
  472. Tasks: Em.Object.create({
  473. status: 'NONE'
  474. })
  475. }),
  476. Em.Object.create({
  477. Tasks: Em.Object.create({
  478. status: 'NONE'
  479. })
  480. })
  481. ]);
  482. c.setProperties({
  483. status: '',
  484. isPolling: true,
  485. hosts: Em.A([
  486. Em.Object.create({
  487. progress: 0
  488. })
  489. ]),
  490. content: Em.Object.create({
  491. controllerName: 'installerController'
  492. })
  493. });
  494. c.setIsServicesInstalled(polledData);
  495. expect(c.get('progress')).to.equal('34');
  496. expect(c.get('isPolling')).to.be.true;
  497. });
  498. });
  499. describe('#launchStartServices', function () {
  500. beforeEach(function() {
  501. sinon.stub(App, 'get', function(k) {
  502. if (k === 'components.slaves')
  503. return ["TASKTRACKER", "DATANODE",
  504. "JOURNALNODE", "ZKFC",
  505. "APP_TIMELINE_SERVER",
  506. "NODEMANAGER",
  507. "GANGLIA_MONITOR",
  508. "HBASE_REGIONSERVER",
  509. "SUPERVISOR",
  510. "FLUME_HANDLER"];
  511. return true;
  512. });
  513. });
  514. afterEach(function() {
  515. App.get.restore();
  516. });
  517. var tests = [
  518. {
  519. expected: [],
  520. message: 'should return query',
  521. controllerName: 'addHostController',
  522. hosts: Em.A([
  523. Em.Object.create({
  524. name: 'h1'
  525. }),
  526. Em.Object.create({
  527. name: 'h2'
  528. })
  529. ])
  530. },
  531. {
  532. expected: [],
  533. text: 'should return server info',
  534. controllerName: 'addServiceController',
  535. services: Em.A([
  536. Em.Object.create({
  537. serviceName: 'OOZIE',
  538. isSelected: true,
  539. isInstalled: false
  540. }),
  541. Em.Object.create({
  542. serviceName: 'h2',
  543. isSelected: false,
  544. isInstalled: true
  545. })
  546. ])
  547. },
  548. {
  549. expected: [],
  550. text: 'should return default data',
  551. controllerName: 'addHostContro',
  552. hosts: Em.A([
  553. Em.Object.create({
  554. name: 'h1'
  555. }),
  556. Em.Object.create({
  557. name: 'h2'
  558. })
  559. ])
  560. }
  561. ];
  562. tests.forEach(function(test) {
  563. it(test.message, function () {
  564. var content = Em.Object.create({
  565. controllerName: test.controllerName,
  566. services: test.services
  567. });
  568. var wizardController = Em.Object.create({
  569. getDBProperty: function() {
  570. return test.hosts
  571. }
  572. });
  573. c.set('content', content);
  574. c.set('wizardController', wizardController);
  575. expect(c.launchStartServices(function(){})).to.be.true;
  576. });
  577. })
  578. });
  579. describe('#hostHasClientsOnly', function () {
  580. var tests = Em.A([
  581. {
  582. hosts: [
  583. Em.Object.create({
  584. hostName: 'host1',
  585. logTasks: [
  586. {Tasks: {role: 'HDFS_CLIENT'}},
  587. {Tasks: {role: 'DATANODE'}}
  588. ],
  589. status: 'old_status',
  590. progress: '10',
  591. e: {status: 'old_status', progress: '10'}
  592. }),
  593. Em.Object.create({
  594. hostName: 'host2',
  595. logTasks: [
  596. {Tasks: {role: 'HDFS_CLIENT'}}
  597. ],
  598. status: 'old_status',
  599. progress: '10',
  600. e: {status: 'success', progress: '100'}
  601. })
  602. ],
  603. jsonError: false
  604. },
  605. {
  606. hosts: [
  607. Em.Object.create({
  608. hostName: 'host1',
  609. logTasks: [
  610. {Tasks: {role: 'HDFS_CLIENT'}},
  611. {Tasks: {role: 'DATANODE'}}
  612. ],
  613. status: 'old_status',
  614. progress: '10',
  615. e: {status: 'success', progress: '100'}
  616. }),
  617. Em.Object.create({
  618. hostName: 'host2',
  619. logTasks: [
  620. {Tasks: {role: 'HDFS_CLIENT'}}
  621. ],
  622. status: 'old_status',
  623. progress: '10',
  624. e: {status: 'success', progress: '100'}
  625. })
  626. ],
  627. jsonError: true
  628. }
  629. ]);
  630. tests.forEach(function (test) {
  631. it('', function () {
  632. c.reopen({hosts: test.hosts});
  633. c.hostHasClientsOnly(test.jsonError);
  634. test.hosts.forEach(function (host) {
  635. expect(c.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  636. expect(c.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  637. });
  638. });
  639. });
  640. });
  641. describe('#onSuccessPerHost', function () {
  642. var tests = Em.A([
  643. {
  644. cluster: {status: 'INSTALLED'},
  645. host: Em.Object.create({status: 'pending'}),
  646. actions: [],
  647. e: {status: 'success'},
  648. m: 'No tasks for host'
  649. },
  650. {
  651. cluster: {status: 'INSTALLED'},
  652. host: Em.Object.create({status: 'info'}),
  653. actions: [
  654. {Tasks: {status: 'COMPLETED'}},
  655. {Tasks: {status: 'COMPLETED'}}
  656. ],
  657. e: {status: 'success'},
  658. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  659. },
  660. {
  661. cluster: {status: 'FAILED'},
  662. host: Em.Object.create({status: 'info'}),
  663. actions: [
  664. {Tasks: {status: 'COMPLETED'}},
  665. {Tasks: {status: 'COMPLETED'}}
  666. ],
  667. e: {status: 'info'},
  668. m: 'All Tasks COMPLETED and cluster status FAILED'
  669. },
  670. {
  671. cluster: {status: 'INSTALLED'},
  672. host: Em.Object.create({status: 'info'}),
  673. actions: [
  674. {Tasks: {status: 'FAILED'}},
  675. {Tasks: {status: 'COMPLETED'}}
  676. ],
  677. e: {status: 'info'},
  678. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  679. },
  680. {
  681. cluster: {status: 'FAILED'},
  682. host: Em.Object.create({status: 'info'}),
  683. actions: [
  684. {Tasks: {status: 'FAILED'}},
  685. {Tasks: {status: 'COMPLETED'}}
  686. ],
  687. e: {status: 'info'},
  688. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  689. }
  690. ]);
  691. tests.forEach(function (test) {
  692. it(test.m, function () {
  693. c.reopen({content: {cluster: {status: test.cluster.status}}});
  694. c.onSuccessPerHost(test.actions, test.host);
  695. expect(test.host.status).to.equal(test.e.status);
  696. });
  697. });
  698. });
  699. describe('#onErrorPerHost', function () {
  700. var tests = Em.A([
  701. {
  702. cluster: {status: 'INSTALLED'},
  703. host: Em.Object.create({status: 'pending'}),
  704. actions: [],
  705. e: {status: 'pending'},
  706. isMasterFailed: false,
  707. m: 'No tasks for host'
  708. },
  709. {
  710. cluster: {status: 'INSTALLED'},
  711. host: Em.Object.create({status: 'info'}),
  712. actions: [
  713. {Tasks: {status: 'FAILED'}},
  714. {Tasks: {status: 'COMPLETED'}}
  715. ],
  716. e: {status: 'warning'},
  717. isMasterFailed: false,
  718. m: 'One Task FAILED and cluster status INSTALLED'
  719. },
  720. {
  721. cluster: {status: 'INSTALLED'},
  722. host: Em.Object.create({status: 'info'}),
  723. actions: [
  724. {Tasks: {status: 'ABORTED'}},
  725. {Tasks: {status: 'COMPLETED'}}
  726. ],
  727. e: {status: 'warning'},
  728. isMasterFailed: false,
  729. m: 'One Task ABORTED and cluster status INSTALLED'
  730. },
  731. {
  732. cluster: {status: 'INSTALLED'},
  733. host: Em.Object.create({status: 'info'}),
  734. actions: [
  735. {Tasks: {status: 'TIMEDOUT'}},
  736. {Tasks: {status: 'COMPLETED'}}
  737. ],
  738. e: {status: 'warning'},
  739. isMasterFailed: false,
  740. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  741. },
  742. {
  743. cluster: {status: 'PENDING'},
  744. host: Em.Object.create({status: 'info'}),
  745. actions: [
  746. {Tasks: {status: 'FAILED'}},
  747. {Tasks: {status: 'COMPLETED'}}
  748. ],
  749. e: {status: 'failed'},
  750. isMasterFailed: true,
  751. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  752. },
  753. {
  754. cluster: {status: 'PENDING'},
  755. host: Em.Object.create({status: 'info'}),
  756. actions: [
  757. {Tasks: {status: 'COMPLETED'}},
  758. {Tasks: {status: 'COMPLETED'}}
  759. ],
  760. e: {status: 'info'},
  761. isMasterFailed: false,
  762. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  763. }
  764. ]);
  765. tests.forEach(function (test) {
  766. it(test.m, function () {
  767. c.reopen({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  768. return test.isMasterFailed;
  769. }});
  770. c.onErrorPerHost(test.actions, test.host);
  771. expect(test.host.status).to.equal(test.e.status);
  772. });
  773. });
  774. });
  775. describe('#isMasterFailed', function () {
  776. beforeEach(function() {
  777. sinon.stub(App, 'get', function(k) {
  778. if (k === 'components.slaves')
  779. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  780. return Em.get(App, k);
  781. });
  782. });
  783. afterEach(function() {
  784. App.get.restore();
  785. });
  786. var tests = Em.A([
  787. {
  788. actions: [
  789. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  790. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  791. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  792. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  793. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  794. ],
  795. e: false,
  796. m: 'No one Master is failed'
  797. },
  798. {
  799. actions: [
  800. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  801. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  802. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  803. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  804. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  805. ],
  806. e: true,
  807. m: 'One Master is failed'
  808. },
  809. {
  810. actions: [
  811. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  812. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  813. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  814. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  815. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  816. ],
  817. e: false,
  818. m: 'one Master is failed but command is not install'
  819. }
  820. ]);
  821. tests.forEach(function (test) {
  822. it(test.m, function () {
  823. expect(c.isMasterFailed(test.actions)).to.equal(test.e);
  824. });
  825. });
  826. });
  827. describe('#onInProgressPerHost', function () {
  828. var tests = Em.A([
  829. {
  830. host: Em.Object.create({message: 'default_message'}),
  831. actions: [
  832. {Tasks: {status: 'COMPLETED'}},
  833. {Tasks: {status: 'COMPLETED'}}
  834. ],
  835. e: {message: 'default_message', b: true},
  836. m: 'All Tasks COMPLETED'
  837. },
  838. {
  839. host: Em.Object.create({message: 'default_message'}),
  840. actions: [
  841. {Tasks: {status: 'IN_PROGRESS'}},
  842. {Tasks: {status: 'COMPLETED'}}
  843. ],
  844. e: {message: 'default_message', b: false},
  845. m: 'One Task IN_PROGRESS'
  846. },
  847. {
  848. host: Em.Object.create({message: 'default_message'}),
  849. actions: [
  850. {Tasks: {status: 'QUEUED'}},
  851. {Tasks: {status: 'COMPLETED'}}
  852. ],
  853. e: {message: 'default_message', b: false},
  854. m: 'One Task QUEUED'
  855. },
  856. {
  857. host: Em.Object.create({message: 'default_message'}),
  858. actions: [
  859. {Tasks: {status: 'PENDING'}},
  860. {Tasks: {status: 'COMPLETED'}}
  861. ],
  862. e: {message: 'default_message', b: false},
  863. m: 'One Task PENDING'
  864. }
  865. ]);
  866. tests.forEach(function (test) {
  867. it(test.m, function () {
  868. c.onInProgressPerHost(test.actions, test.host);
  869. expect(test.host.message == test.e.message).to.equal(test.e.b);
  870. });
  871. });
  872. });
  873. describe('#progressPerHost', function () {
  874. var tests = Em.A([
  875. {
  876. cluster: {status: 'PENDING'},
  877. host: Em.Object.create({progress: 0}),
  878. actions: {
  879. 'COMPLETED': 2,
  880. 'QUEUED': 2,
  881. 'IN_PROGRESS': 1
  882. },
  883. e: {progress: 17},
  884. s: false,
  885. m: 'All types of status available. cluster status PENDING'
  886. },
  887. {
  888. cluster: {status: 'PENDING'},
  889. host: Em.Object.create({progress: 0}),
  890. actions: {},
  891. e: {progress: 33},
  892. s: false,
  893. m: 'No tasks available. cluster status PENDING'
  894. },
  895. {
  896. cluster: {status: 'PENDING'},
  897. host: Em.Object.create({progress: 0}),
  898. actions: {},
  899. e: {progress: 100},
  900. s: true,
  901. m: 'No tasks available. cluster status PENDING. skipComponentStartAfterInstall is true.'
  902. },
  903. {
  904. cluster: {status: 'INSTALLED'},
  905. host: Em.Object.create({progress: 0}),
  906. actions: {},
  907. e: {progress: 100},
  908. m: 'No tasks available. cluster status INSTALLED'
  909. },
  910. {
  911. cluster: {status: 'INSTALLED'},
  912. host: Em.Object.create({progress: 0}),
  913. actions: {
  914. 'COMPLETED': 2,
  915. 'QUEUED': 2,
  916. 'IN_PROGRESS': 1
  917. },
  918. e: {progress: 66},
  919. s: false,
  920. m: 'All types of status available. cluster status INSTALLED'
  921. },
  922. {
  923. cluster: {status: 'FAILED'},
  924. host: Em.Object.create({progress: 0}),
  925. actions: {},
  926. e: {progress: 100},
  927. s: false,
  928. m: 'Cluster status is not PENDING or INSTALLED'
  929. },
  930. {
  931. cluster: {status: 'INSTALLED'},
  932. host: Em.Object.create({progress: 0}),
  933. actions: {
  934. 'COMPLETED': 150,
  935. 'QUEUED': 0,
  936. 'IN_PROGRESS': 1
  937. },
  938. e: {progress: 99},
  939. s: false,
  940. m: '150 tasks on host'
  941. },
  942. {
  943. cluster: {status: 'INSTALLED'},
  944. host: Em.Object.create({progress: 0}),
  945. actions: {
  946. 'COMPLETED': 498,
  947. 'QUEUED': 1,
  948. 'IN_PROGRESS': 1
  949. },
  950. e: {progress: 99},
  951. s: false,
  952. m: '500 tasks on host'
  953. },
  954. {
  955. cluster: {status: 'INSTALLED'},
  956. host: Em.Object.create({progress: 0}),
  957. actions: {
  958. 'COMPLETED': 150,
  959. 'QUEUED': 0,
  960. 'IN_PROGRESS': 0
  961. },
  962. e: {progress: 100},
  963. s: false,
  964. m: '100 tasks, 100 completed'
  965. },
  966. {
  967. cluster: {status: 'INSTALLED'},
  968. host: Em.Object.create({progress: 0}),
  969. actions: {
  970. 'COMPLETED': 1,
  971. 'QUEUED': 0,
  972. 'IN_PROGRESS': 0
  973. },
  974. e: {progress: 100},
  975. s: false,
  976. m: '1 task, 1 completed'
  977. }
  978. ]);
  979. tests.forEach(function (test) {
  980. it(test.m, function () {
  981. var actions = [];
  982. for (var prop in test.actions) {
  983. if (test.actions.hasOwnProperty(prop) && test.actions[prop]) {
  984. for (var i = 0; i < test.actions[prop]; i++) {
  985. actions.push({Tasks: {status: prop}});
  986. }
  987. }
  988. }
  989. c.reopen({content: {cluster: {status: test.cluster.status}}});
  990. App.set('supports.skipComponentStartAfterInstall', test.s);
  991. var progress = c.progressPerHost(actions, test.host);
  992. expect(progress).to.equal(test.e.progress);
  993. expect(test.host.progress).to.equal(test.e.progress.toString());
  994. });
  995. });
  996. });
  997. describe('#clearStep', function () {
  998. it('All to default values', function () {
  999. c.reopen({hosts: [{},{},{}]});
  1000. c.clearStep();
  1001. expect(c.get('hosts.length')).to.equal(0);
  1002. expect(c.get('status')).to.equal('info');
  1003. expect(c.get('progress')).to.equal('0');
  1004. expect(c.get('numPolls')).to.equal(1);
  1005. });
  1006. });
  1007. describe('#replacePolledData', function () {
  1008. it('replacing polled data', function () {
  1009. c.reopen({polledData: [{},{},{}]});
  1010. var newPolledData = [{}];
  1011. c.replacePolledData(newPolledData);
  1012. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  1013. });
  1014. });
  1015. describe('#isSuccess', function () {
  1016. var tests = Em.A([
  1017. {
  1018. polledData: [
  1019. {Tasks: {status: 'COMPLETED'}},
  1020. {Tasks: {status: 'COMPLETED'}}
  1021. ],
  1022. e: true,
  1023. m: 'All tasks are COMPLETED'
  1024. },
  1025. {
  1026. polledData: [
  1027. {Tasks: {status: 'COMPLETED'}},
  1028. {Tasks: {status: 'FAILED'}}
  1029. ],
  1030. e: false,
  1031. m: 'Not all tasks are COMPLETED'
  1032. }
  1033. ]);
  1034. tests.forEach(function (test) {
  1035. it(test.m, function () {
  1036. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  1037. });
  1038. });
  1039. });
  1040. describe('#isStepFailed', function () {
  1041. beforeEach(function() {
  1042. sinon.stub(App, 'get', function(k) {
  1043. if (k === 'components.slaves')
  1044. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  1045. return Em.get(App, k);
  1046. });
  1047. });
  1048. afterEach(function() {
  1049. App.get.restore();
  1050. });
  1051. var tests = Em.A([
  1052. {
  1053. polledData: [
  1054. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1055. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  1056. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1057. ],
  1058. e: true,
  1059. m: 'GANGLIA_MONITOR 2/3 failed'
  1060. },
  1061. {
  1062. polledData: [
  1063. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  1064. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  1065. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  1066. ],
  1067. e: false,
  1068. m: 'GANGLIA_MONITOR 1/3 failed'
  1069. },
  1070. {
  1071. polledData: [
  1072. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1073. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  1074. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1075. ],
  1076. e: true,
  1077. m: 'HBASE_REGIONSERVER 2/3 failed'
  1078. },
  1079. {
  1080. polledData: [
  1081. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  1082. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  1083. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  1084. ],
  1085. e: false,
  1086. m: 'HBASE_REGIONSERVER 1/3 failed'
  1087. },
  1088. {
  1089. polledData: [
  1090. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1091. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  1092. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1093. ],
  1094. e: true,
  1095. m: 'TASKTRACKER 2/3 failed'
  1096. },
  1097. {
  1098. polledData: [
  1099. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  1100. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  1101. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  1102. ],
  1103. e: false,
  1104. m: 'TASKTRACKER 1/3 failed'
  1105. },
  1106. {
  1107. polledData: [
  1108. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1109. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  1110. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1111. ],
  1112. e: true,
  1113. m: 'DATANODE 2/3 failed'
  1114. },
  1115. {
  1116. polledData: [
  1117. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  1118. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1119. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1120. ],
  1121. e: false,
  1122. m: 'DATANODE 1/3 failed'
  1123. },
  1124. {
  1125. polledData: [
  1126. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  1127. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1128. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1129. ],
  1130. e: true,
  1131. m: 'NAMENODE failed'
  1132. },
  1133. {
  1134. polledData: [
  1135. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  1136. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  1137. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  1138. ],
  1139. e: false,
  1140. m: 'Nothing failed failed'
  1141. }
  1142. ]);
  1143. tests.forEach(function (test) {
  1144. it(test.m, function () {
  1145. c.reopen({polledData: test.polledData});
  1146. expect(c.isStepFailed()).to.equal(test.e);
  1147. });
  1148. });
  1149. });
  1150. describe('#setLogTasksStatePerHost', function () {
  1151. var tests = Em.A([
  1152. {
  1153. tasksPerHost: [
  1154. {Tasks: {id: 1, status: 'COMPLETED'}},
  1155. {Tasks: {id: 2, status: 'COMPLETED'}}
  1156. ],
  1157. tasks: [],
  1158. e: {m: 'COMPLETED', l: 2},
  1159. m: 'host didn\'t have tasks and got 2 new'
  1160. },
  1161. {
  1162. tasksPerHost: [
  1163. {Tasks: {id: 1, status: 'COMPLETED'}},
  1164. {Tasks: {id: 2, status: 'COMPLETED'}}
  1165. ],
  1166. tasks: [
  1167. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1168. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1169. ],
  1170. e: {m: 'COMPLETED', l: 2},
  1171. m: 'host had 2 tasks and got both updated'
  1172. },
  1173. {
  1174. tasksPerHost: [],
  1175. tasks: [
  1176. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1177. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1178. ],
  1179. e: {m: 'IN_PROGRESS', l: 2},
  1180. m: 'host had 2 tasks and didn\'t get updates'
  1181. },
  1182. {
  1183. tasksPerHost: [
  1184. {Tasks: {id: 1, status: 'COMPLETED'}},
  1185. {Tasks: {id: 2, status: 'COMPLETED'}},
  1186. {Tasks: {id: 3, status: 'COMPLETED'}}
  1187. ],
  1188. tasks: [
  1189. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  1190. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  1191. ],
  1192. e: {m: 'COMPLETED', l: 3},
  1193. m: 'host had 2 tasks and got both updated and 1 new'
  1194. }
  1195. ]);
  1196. tests.forEach(function (test) {
  1197. it(test.m, function () {
  1198. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  1199. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  1200. expect(c.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  1201. expect(c.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  1202. });
  1203. });
  1204. });
  1205. // On completion of Start all services error callback function,
  1206. // Cluster Status should be INSTALL FAILED
  1207. // All progress bar on the screen should be finished (100%) with blue color.
  1208. // Retry button should be enabled, next button should be disabled
  1209. describe('#launchStartServicesErrorCallback', function () {
  1210. beforeEach(function() {
  1211. sinon.stub(App, 'get', function(k) {
  1212. if ('testMode' === k) return true;
  1213. return Em.get(App, k);
  1214. });
  1215. });
  1216. afterEach(function() {
  1217. App.get.restore();
  1218. });
  1219. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  1220. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1221. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1222. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1223. expect(c.get('progress')).to.equal('100');
  1224. expect(c.get('status')).to.equal('failed');
  1225. });
  1226. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  1227. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1228. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1229. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1230. c.get('hosts').forEach(function (host) {
  1231. expect(host.get('progress')).to.equal('100');
  1232. expect(host.get('status')).to.equal('info');
  1233. });
  1234. });
  1235. it('Next button should be disabled', function () {
  1236. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  1237. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  1238. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  1239. expect(c.get('isSubmitDisabled')).to.equal(true);
  1240. });
  1241. });
  1242. describe('#submit', function () {
  1243. it('should call App.router.send', function () {
  1244. sinon.stub(App.router, 'send', Em.K);
  1245. c.submit();
  1246. expect(App.router.send.calledWith('next')).to.equal(true);
  1247. App.router.send.restore();
  1248. });
  1249. });
  1250. describe('#back', function () {
  1251. beforeEach(function () {
  1252. sinon.stub(App.router, 'send', Em.K);
  1253. });
  1254. afterEach(function () {
  1255. App.router.send.restore();
  1256. });
  1257. it('should call App.router.send', function () {
  1258. c.reopen({isSubmitDisabled: false});
  1259. c.back();
  1260. expect(App.router.send.calledWith('back')).to.equal(true);
  1261. });
  1262. it('shouldn\'t call App.router.send', function () {
  1263. c.reopen({isSubmitDisabled: true});
  1264. c.back();
  1265. expect(App.router.send.called).to.equal(false);
  1266. });
  1267. });
  1268. describe('#loadStep', function () {
  1269. beforeEach(function () {
  1270. sinon.stub(c, 'clearStep', Em.K);
  1271. sinon.stub(c, 'loadHosts', Em.K);
  1272. });
  1273. afterEach(function () {
  1274. c.clearStep.restore();
  1275. c.loadHosts.restore();
  1276. });
  1277. it('should call clearStep', function () {
  1278. c.loadStep();
  1279. expect(c.clearStep.calledOnce).to.equal(true);
  1280. });
  1281. it('should call loadHosts', function () {
  1282. c.loadStep();
  1283. expect(c.loadHosts.calledOnce).to.equal(true);
  1284. });
  1285. });
  1286. describe('#startPolling', function () {
  1287. beforeEach(function () {
  1288. sinon.stub(c, 'reloadErrorCallback', Em.K);
  1289. });
  1290. afterEach(function () {
  1291. c.reloadErrorCallback.restore();
  1292. });
  1293. it('should set isSubmitDisabled to true', function () {
  1294. c.set('isSubmitDisabled', false);
  1295. c.startPolling();
  1296. expect(c.get('isSubmitDisabled')).to.equal(true);
  1297. });
  1298. it('should call doPolling', function () {
  1299. sinon.stub(c, 'doPolling', Em.K);
  1300. c.startPolling();
  1301. expect(c.doPolling.calledOnce).to.equal(true);
  1302. c.doPolling.restore();
  1303. });
  1304. });
  1305. describe('#loadLogData', function () {
  1306. beforeEach(function () {
  1307. obj.reopen({
  1308. cluster: {oldRequestsId: [1,2,3]},
  1309. getDBProperty: function (name) {
  1310. return this.get(name);
  1311. }
  1312. });
  1313. c.reopen({wizardController: obj});
  1314. sinon.stub(c, 'getLogsByRequest', Em.K);
  1315. });
  1316. afterEach(function () {
  1317. c.getLogsByRequest.restore();
  1318. });
  1319. it('should call getLogsByRequest 1 time with 3', function () {
  1320. c.loadLogData(true);
  1321. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  1322. });
  1323. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  1324. sinon.stub(App, 'get', function(k) { if ('testMode' === k) return true; return Em.get(App, k);});
  1325. c.loadLogData();
  1326. expect(c.get('POLL_INTERVAL')).to.equal(1);
  1327. App.get.restore();
  1328. });
  1329. });
  1330. describe('#loadCurrentTaskLog', function () {
  1331. beforeEach(function () {
  1332. sinon.stub(c, 'loadLogData', Em.K);
  1333. c.set('wizardController', Em.Object.create({
  1334. getDBProperty: Em.K
  1335. }));
  1336. });
  1337. afterEach(function () {
  1338. c.loadLogData.restore();
  1339. });
  1340. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  1341. c.set('currentOpenTaskId', null);
  1342. c.loadCurrentTaskLog();
  1343. expect(App.ajax.send.called).to.equal(false);
  1344. });
  1345. it('should call App.ajax.send with provided data', function () {
  1346. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1347. c.set('currentOpenTaskId', 1);
  1348. c.set('currentOpenTaskRequestId', 2);
  1349. c.set('content', {cluster: {name: 3}});
  1350. c.loadCurrentTaskLog();
  1351. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3});
  1352. c.togglePreviousSteps.restore();
  1353. });
  1354. });
  1355. describe('#loadCurrentTaskLogSuccessCallback', function () {
  1356. beforeEach(function() {
  1357. sinon.stub(c, 'getLogsByRequest', Em.K);
  1358. sinon.stub(c, 'loadLogData', Em.K);
  1359. });
  1360. afterEach(function() {
  1361. c.getLogsByRequest.restore();
  1362. c.loadLogData.restore();
  1363. });
  1364. it('should increment logTasksChangesCounter', function () {
  1365. c.set('logTasksChangesCounter', 0);
  1366. c.loadCurrentTaskLogSuccessCallback();
  1367. expect(c.get('logTasksChangesCounter')).to.equal(1);
  1368. });
  1369. it('should update stdout, stderr', function () {
  1370. c.set('currentOpenTaskId', 1);
  1371. c.reopen({
  1372. hosts: [
  1373. Em.Object.create({
  1374. name: 'h1',
  1375. logTasks: [
  1376. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1377. ]
  1378. })
  1379. ]
  1380. });
  1381. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1382. c.loadCurrentTaskLogSuccessCallback(data);
  1383. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1384. expect(t.stdout).to.equal('stdout');
  1385. expect(t.stderr).to.equal('stderr');
  1386. });
  1387. it('shouldn\'t update stdout, stderr', function () {
  1388. c.set('currentOpenTaskId', 1);
  1389. c.reopen({
  1390. hosts: [
  1391. Em.Object.create({
  1392. name: 'h1',
  1393. logTasks: [
  1394. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1395. ]
  1396. })
  1397. ]
  1398. });
  1399. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1400. c.loadCurrentTaskLogSuccessCallback(data);
  1401. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1402. expect(t.stdout).to.equal('');
  1403. expect(t.stderr).to.equal('');
  1404. });
  1405. it('shouldn\'t update stdout, stderr (2)', function () {
  1406. c.set('currentOpenTaskId', 1);
  1407. c.reopen({
  1408. hosts: [
  1409. Em.Object.create({
  1410. name: 'h2',
  1411. logTasks: [
  1412. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1413. ]
  1414. })
  1415. ]
  1416. });
  1417. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1418. c.loadCurrentTaskLogSuccessCallback(data);
  1419. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1420. expect(t.stdout).to.equal('');
  1421. expect(t.stderr).to.equal('');
  1422. });
  1423. });
  1424. describe('#loadCurrentTaskLogErrorCallback', function () {
  1425. it('should set currentOpenTaskId to 0', function () {
  1426. c.set('currentOpenTaskId', 123);
  1427. c.loadCurrentTaskLogErrorCallback();
  1428. expect(c.get('currentOpenTaskId')).to.equal(0);
  1429. });
  1430. });
  1431. describe('#doPolling', function () {
  1432. beforeEach(function () {
  1433. sinon.stub(c, 'getLogsByRequest', Em.K);
  1434. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1435. });
  1436. afterEach(function () {
  1437. c.getLogsByRequest.restore();
  1438. c.togglePreviousSteps.restore();
  1439. });
  1440. it('should increment numPolls if testMode', function () {
  1441. App.set('testMode', true);
  1442. c.set('numPolls', 0);
  1443. c.doPolling();
  1444. expect(c.get('numPolls')).to.equal(1);
  1445. App.set('testMode', false);
  1446. });
  1447. it('should call getLogsByRequest', function () {
  1448. c.set('content', {cluster: {requestId: 1}});
  1449. c.doPolling();
  1450. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1451. });
  1452. });
  1453. describe('#isAllComponentsInstalledErrorCallback', function () {
  1454. beforeEach(function () {
  1455. sinon.stub(c, 'saveClusterStatus', Em.K);
  1456. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1457. });
  1458. afterEach(function () {
  1459. c.saveClusterStatus.restore();
  1460. c.togglePreviousSteps.restore();
  1461. });
  1462. it('should call saveClusterStatus', function () {
  1463. c.isAllComponentsInstalledErrorCallback({});
  1464. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1465. });
  1466. });
  1467. describe('#navigateStep', function () {
  1468. beforeEach(function () {
  1469. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1470. sinon.stub(c, 'loadStep', Em.K);
  1471. sinon.stub(c, 'loadLogData', Em.K);
  1472. sinon.stub(c, 'startPolling', Em.K);
  1473. });
  1474. afterEach(function () {
  1475. c.togglePreviousSteps.restore();
  1476. c.loadStep.restore();
  1477. c.loadLogData.restore();
  1478. c.startPolling.restore();
  1479. App.get.restore();
  1480. });
  1481. it('should set custom data in testMode', function () {
  1482. sinon.stub(App, 'get', function(k) {if('testMode' === k) return true; return Em.get(App, k);});
  1483. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1484. c.navigateStep();
  1485. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1486. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1487. expect(c.get('content.cluster.requestId')).to.equal(1);
  1488. });
  1489. it('isCompleted = true, requestId = 1', function () {
  1490. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1491. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1492. c.navigateStep();
  1493. expect(c.loadStep.calledOnce).to.equal(true);
  1494. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1495. expect(c.get('progress')).to.equal('100');
  1496. });
  1497. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1498. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1499. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1500. c.navigateStep();
  1501. expect(c.loadStep.calledOnce).to.equal(true);
  1502. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1503. });
  1504. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1505. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1506. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1507. c.navigateStep();
  1508. expect(c.loadStep.calledOnce).to.equal(true);
  1509. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1510. });
  1511. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1512. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1513. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1514. c.navigateStep();
  1515. expect(c.loadStep.calledOnce).to.equal(true);
  1516. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1517. });
  1518. });
  1519. describe('#launchStartServicesSuccessCallback', function () {
  1520. beforeEach(function () {
  1521. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1522. return $.ajax();
  1523. });
  1524. sinon.stub(c, 'saveClusterStatus', Em.K);
  1525. sinon.stub(c, 'doPolling', Em.K);
  1526. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1527. });
  1528. afterEach(function () {
  1529. c.saveClusterStatus.restore();
  1530. c.doPolling.restore();
  1531. c.hostHasClientsOnly.restore();
  1532. App.clusterStatus.setClusterStatus.restore();
  1533. });
  1534. it('should call doPolling if some data were received', function () {
  1535. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1536. expect(c.doPolling.calledOnce).to.equal(true);
  1537. });
  1538. Em.A([
  1539. {
  1540. jsonData: {Requests: {id: 2}},
  1541. e: {
  1542. hostHasClientsOnly: false,
  1543. clusterStatus: {
  1544. status: 'INSTALLED',
  1545. requestId: 2,
  1546. isStartError: false,
  1547. isCompleted: false
  1548. }
  1549. }
  1550. },
  1551. {
  1552. jsonData: null,
  1553. e: {
  1554. hostHasClientsOnly: true,
  1555. clusterStatus: {
  1556. status: 'STARTED',
  1557. isStartError: false,
  1558. isCompleted: true
  1559. },
  1560. status: 'success',
  1561. progress: '100'
  1562. }
  1563. }
  1564. ]).forEach(function (test) {
  1565. it(test.m, function () {
  1566. c.launchStartServicesSuccessCallback(test.jsonData);
  1567. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1568. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1569. if (test.e.status) {
  1570. expect(c.get('status')).to.equal(test.e.status);
  1571. }
  1572. if (test.e.progress) {
  1573. expect(c.get('progress')).to.equal(test.e.progress);
  1574. }
  1575. });
  1576. });
  1577. });
  1578. });