step9_test.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275
  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. describe('App.InstallerStep9Controller', function () {
  30. beforeEach(function () {
  31. modelSetup.setupStackServiceComponent();
  32. c = App.WizardStep9Controller.create({
  33. content: {controllerName: ''},
  34. saveClusterStatus: Em.K,
  35. saveInstalledHosts: Em.K,
  36. togglePreviousSteps: Em.K,
  37. wizardController: Em.Object.create({
  38. requestsId: [],
  39. cluster: {oldRequestsId: []},
  40. getDBProperty: function(name) {
  41. return this.get(name);
  42. }
  43. })
  44. });
  45. obj = App.InstallerController.create();
  46. sinon.stub(App.ajax, 'send', function() {
  47. return {
  48. retry: function() {
  49. return {
  50. then: Em.K,
  51. complete: Em.K
  52. };
  53. },
  54. complete: Em.K
  55. };
  56. });
  57. });
  58. afterEach(function () {
  59. modelSetup.cleanStackServiceComponent();
  60. App.ajax.send.restore();
  61. });
  62. describe('#isSubmitDisabled', function () {
  63. var tests = Em.A([
  64. {controllerName: 'addHostController', state: 'STARTED', e: false},
  65. {controllerName: 'addHostController', state: 'START FAILED', e: false},
  66. {controllerName: 'addHostController', state: 'INSTALL FAILED', e: false},
  67. {controllerName: 'addHostController', state: 'PENDING', e: true},
  68. {controllerName: 'addHostController', state: 'INSTALLED', e: true},
  69. {controllerName: 'addServiceController', state: 'STARTED', e: false},
  70. {controllerName: 'addServiceController', state: 'START FAILED', e: false},
  71. {controllerName: 'addServiceController', state: 'INSTALL FAILED', e: false},
  72. {controllerName: 'addServiceController', state: 'PENDING', e: true},
  73. {controllerName: 'addServiceController', state: 'INSTALLED', e: true},
  74. {controllerName: 'installerController', state: 'STARTED', e: false},
  75. {controllerName: 'installerController', state: 'START FAILED', e: false},
  76. {controllerName: 'installerController', state: 'INSTALL FAILED', e: true},
  77. {controllerName: 'installerController', state: 'INSTALLED', e: true},
  78. {controllerName: 'installerController', state: 'PENDING', e: true}
  79. ]);
  80. tests.forEach(function (test) {
  81. var controller = App.WizardStep9Controller.create({
  82. saveClusterStatus: Em.K,
  83. saveInstalledHosts: Em.K,
  84. content: {
  85. controllerName: test.controllerName,
  86. cluster: {
  87. status: test.state
  88. }
  89. }
  90. });
  91. it('controllerName is ' + test.controllerName + '; cluster status is ' + test.state + '; isSubmitDisabled should be ' + test.e, function () {
  92. expect(controller.get('isSubmitDisabled')).to.equal(test.e);
  93. });
  94. });
  95. });
  96. describe('#status', function () {
  97. var tests = Em.A([
  98. {
  99. hosts: [
  100. {status: 'failed'},
  101. {status: 'success'}
  102. ],
  103. isStepFailed: false,
  104. progress: '100',
  105. m: 'One host is failed',
  106. e: 'failed'
  107. },
  108. {
  109. hosts: [
  110. {status: 'warning'},
  111. {status: 'success'}
  112. ],
  113. m: 'One host is failed and step is not failed',
  114. isStepFailed: false,
  115. progress: '100',
  116. e: 'warning'
  117. },
  118. {
  119. hosts: [
  120. {status: 'warning'},
  121. {status: 'success'}
  122. ],
  123. m: 'One host is failed and step is failed',
  124. isStepFailed: true,
  125. progress: '100',
  126. e: 'failed'
  127. },
  128. {
  129. hosts: [
  130. {status: 'success'},
  131. {status: 'success'}
  132. ],
  133. m: 'All hosts are success and progress is 100',
  134. isStepFailed: false,
  135. progress: '100',
  136. e: 'success'
  137. },
  138. {
  139. hosts: [
  140. {status: 'success'},
  141. {status: 'success'}
  142. ],
  143. m: 'All hosts are success and progress is 50',
  144. isStepFailed: false,
  145. progress: '50',
  146. e: 'info'
  147. }
  148. ]);
  149. tests.forEach(function (test) {
  150. var controller = App.WizardStep9Controller.create({
  151. saveClusterStatus: Em.K,
  152. saveInstalledHosts: Em.K,
  153. hosts: test.hosts,
  154. isStepFailed: function () {
  155. return test.isStepFailed
  156. },
  157. progress: test.progress
  158. });
  159. controller.updateStatus();
  160. it(test.m, function () {
  161. expect(controller.get('status')).to.equal(test.e);
  162. });
  163. });
  164. });
  165. describe('#showRetry', function () {
  166. it('cluster status is not INSTALL FAILED', function () {
  167. c.reopen({content: {cluster: {status: 'INSTALLED'}}});
  168. expect(c.get('showRetry')).to.equal(false);
  169. });
  170. it('cluster status is INSTALL FAILED', function () {
  171. c.reopen({content: {cluster: {status: 'INSTALL FAILED'}}});
  172. expect(c.get('showRetry')).to.equal(true);
  173. });
  174. });
  175. describe('#resetHostsForRetry', function () {
  176. it('All should have status "pending" and message "Waiting"', function () {
  177. var hosts = {'host1': Em.Object.create({status: 'failed', message: 'Failed'}), 'host2': Em.Object.create({status: 'success', message: 'Success'})};
  178. c.reopen({content: {hosts: hosts}});
  179. c.resetHostsForRetry();
  180. for (var name in hosts) {
  181. if (hosts.hasOwnProperty(name)) {
  182. expect(c.get('content.hosts')[name].get('status', 'pending')).to.equal('pending');
  183. expect(c.get('content.hosts')[name].get('message', 'Waiting')).to.equal('Waiting');
  184. }
  185. }
  186. });
  187. });
  188. var hosts_for_load_and_render = {
  189. 'host1': {
  190. message: 'message1',
  191. status: 'unknown',
  192. progress: '1',
  193. logTasks: [
  194. {},
  195. {}
  196. ],
  197. bootStatus: 'REGISTERED'
  198. },
  199. 'host2': {
  200. message: '',
  201. status: 'failed',
  202. progress: '1',
  203. logTasks: [
  204. {},
  205. {}
  206. ],
  207. bootStatus: ''
  208. },
  209. 'host3': {
  210. message: '',
  211. status: 'waiting',
  212. progress: null,
  213. logTasks: [
  214. {},
  215. {}
  216. ],
  217. bootStatus: ''
  218. },
  219. 'host4': {
  220. message: 'message4',
  221. status: null,
  222. progress: '10',
  223. logTasks: [
  224. {}
  225. ],
  226. bootStatus: 'REGISTERED'
  227. }
  228. };
  229. describe('#loadHosts', function () {
  230. beforeEach(function() {
  231. c.reopen({content: {hosts: hosts_for_load_and_render}});
  232. c.loadHosts();
  233. });
  234. it('Only REGISTERED hosts', function () {
  235. var loaded_hosts = c.get('hosts');
  236. expect(loaded_hosts.length).to.equal(2);
  237. });
  238. it('All hosts have progress 0', function () {
  239. var loaded_hosts = c.get('hosts');
  240. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  241. });
  242. it('All hosts have progress 0', function () {
  243. var loaded_hosts = c.get('hosts');
  244. expect(loaded_hosts.everyProperty('progress', 0)).to.equal(true);
  245. });
  246. it('All host don\'t have logTasks', function () {
  247. var loaded_hosts = c.get('hosts');
  248. expect(loaded_hosts.everyProperty('logTasks.length', 0)).to.equal(true);
  249. });
  250. });
  251. describe('#hostHasClientsOnly', function () {
  252. var tests = Em.A([
  253. {
  254. hosts: [
  255. Em.Object.create({
  256. hostName: 'host1',
  257. logTasks: [
  258. {Tasks: {role: 'HDFS_CLIENT'}},
  259. {Tasks: {role: 'DATANODE'}}
  260. ],
  261. status: 'old_status',
  262. progress: '10',
  263. e: {status: 'old_status', progress: '10'}
  264. }),
  265. Em.Object.create({
  266. hostName: 'host2',
  267. logTasks: [
  268. {Tasks: {role: 'HDFS_CLIENT'}}
  269. ],
  270. status: 'old_status',
  271. progress: '10',
  272. e: {status: 'success', progress: '100'}
  273. })
  274. ],
  275. jsonError: false
  276. },
  277. {
  278. hosts: [
  279. Em.Object.create({
  280. hostName: 'host1',
  281. logTasks: [
  282. {Tasks: {role: 'HDFS_CLIENT'}},
  283. {Tasks: {role: 'DATANODE'}}
  284. ],
  285. status: 'old_status',
  286. progress: '10',
  287. e: {status: 'success', progress: '100'}
  288. }),
  289. Em.Object.create({
  290. hostName: 'host2',
  291. logTasks: [
  292. {Tasks: {role: 'HDFS_CLIENT'}}
  293. ],
  294. status: 'old_status',
  295. progress: '10',
  296. e: {status: 'success', progress: '100'}
  297. })
  298. ],
  299. jsonError: true
  300. }
  301. ]);
  302. tests.forEach(function (test) {
  303. it('', function () {
  304. c.reopen({hosts: test.hosts});
  305. c.hostHasClientsOnly(test.jsonError);
  306. test.hosts.forEach(function (host) {
  307. expect(c.get('hosts').findProperty('hostName', host.hostName).get('status')).to.equal(host.e.status);
  308. expect(c.get('hosts').findProperty('hostName', host.hostName).get('progress')).to.equal(host.e.progress);
  309. });
  310. });
  311. });
  312. });
  313. describe('#onSuccessPerHost', function () {
  314. var tests = Em.A([
  315. {
  316. cluster: {status: 'INSTALLED'},
  317. host: Em.Object.create({status: 'pending'}),
  318. actions: [],
  319. e: {status: 'success'},
  320. m: 'No tasks for host'
  321. },
  322. {
  323. cluster: {status: 'INSTALLED'},
  324. host: Em.Object.create({status: 'info'}),
  325. actions: [
  326. {Tasks: {status: 'COMPLETED'}},
  327. {Tasks: {status: 'COMPLETED'}}
  328. ],
  329. e: {status: 'success'},
  330. m: 'All Tasks COMPLETED and cluster status INSTALLED'
  331. },
  332. {
  333. cluster: {status: 'FAILED'},
  334. host: Em.Object.create({status: 'info'}),
  335. actions: [
  336. {Tasks: {status: 'COMPLETED'}},
  337. {Tasks: {status: 'COMPLETED'}}
  338. ],
  339. e: {status: 'info'},
  340. m: 'All Tasks COMPLETED and cluster status FAILED'
  341. },
  342. {
  343. cluster: {status: 'INSTALLED'},
  344. host: Em.Object.create({status: 'info'}),
  345. actions: [
  346. {Tasks: {status: 'FAILED'}},
  347. {Tasks: {status: 'COMPLETED'}}
  348. ],
  349. e: {status: 'info'},
  350. m: 'Not all Tasks COMPLETED and cluster status INSTALLED'
  351. },
  352. {
  353. cluster: {status: 'FAILED'},
  354. host: Em.Object.create({status: 'info'}),
  355. actions: [
  356. {Tasks: {status: 'FAILED'}},
  357. {Tasks: {status: 'COMPLETED'}}
  358. ],
  359. e: {status: 'info'},
  360. m: 'Not all Tasks COMPLETED and cluster status FAILED'
  361. }
  362. ]);
  363. tests.forEach(function (test) {
  364. it(test.m, function () {
  365. c.reopen({content: {cluster: {status: test.cluster.status}}});
  366. c.onSuccessPerHost(test.actions, test.host);
  367. expect(test.host.status).to.equal(test.e.status);
  368. });
  369. });
  370. });
  371. describe('#onErrorPerHost', function () {
  372. var tests = Em.A([
  373. {
  374. cluster: {status: 'INSTALLED'},
  375. host: Em.Object.create({status: 'pending'}),
  376. actions: [],
  377. e: {status: 'pending'},
  378. isMasterFailed: false,
  379. m: 'No tasks for host'
  380. },
  381. {
  382. cluster: {status: 'INSTALLED'},
  383. host: Em.Object.create({status: 'info'}),
  384. actions: [
  385. {Tasks: {status: 'FAILED'}},
  386. {Tasks: {status: 'COMPLETED'}}
  387. ],
  388. e: {status: 'warning'},
  389. isMasterFailed: false,
  390. m: 'One Task FAILED and cluster status INSTALLED'
  391. },
  392. {
  393. cluster: {status: 'INSTALLED'},
  394. host: Em.Object.create({status: 'info'}),
  395. actions: [
  396. {Tasks: {status: 'ABORTED'}},
  397. {Tasks: {status: 'COMPLETED'}}
  398. ],
  399. e: {status: 'warning'},
  400. isMasterFailed: false,
  401. m: 'One Task ABORTED and cluster status INSTALLED'
  402. },
  403. {
  404. cluster: {status: 'INSTALLED'},
  405. host: Em.Object.create({status: 'info'}),
  406. actions: [
  407. {Tasks: {status: 'TIMEDOUT'}},
  408. {Tasks: {status: 'COMPLETED'}}
  409. ],
  410. e: {status: 'warning'},
  411. isMasterFailed: false,
  412. m: 'One Task TIMEDOUT and cluster status INSTALLED'
  413. },
  414. {
  415. cluster: {status: 'PENDING'},
  416. host: Em.Object.create({status: 'info'}),
  417. actions: [
  418. {Tasks: {status: 'FAILED'}},
  419. {Tasks: {status: 'COMPLETED'}}
  420. ],
  421. e: {status: 'failed'},
  422. isMasterFailed: true,
  423. m: 'One Task FAILED and cluster status PENDING isMasterFailed true'
  424. },
  425. {
  426. cluster: {status: 'PENDING'},
  427. host: Em.Object.create({status: 'info'}),
  428. actions: [
  429. {Tasks: {status: 'COMPLETED'}},
  430. {Tasks: {status: 'COMPLETED'}}
  431. ],
  432. e: {status: 'info'},
  433. isMasterFailed: false,
  434. m: 'One Task FAILED and cluster status PENDING isMasterFailed false'
  435. }
  436. ]);
  437. tests.forEach(function (test) {
  438. it(test.m, function () {
  439. c.reopen({content: {cluster: {status: test.cluster.status}}, isMasterFailed: function () {
  440. return test.isMasterFailed;
  441. }});
  442. c.onErrorPerHost(test.actions, test.host);
  443. expect(test.host.status).to.equal(test.e.status);
  444. });
  445. });
  446. });
  447. describe('#isMasterFailed', function () {
  448. beforeEach(function() {
  449. sinon.stub(App, 'get', function(k) {
  450. if (k === 'components.slaves')
  451. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  452. return Em.get(App, k);
  453. });
  454. });
  455. afterEach(function() {
  456. App.get.restore();
  457. });
  458. var tests = Em.A([
  459. {
  460. actions: [
  461. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'DATANODE'}},
  462. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  463. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  464. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  465. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  466. ],
  467. e: false,
  468. m: 'No one Master is failed'
  469. },
  470. {
  471. actions: [
  472. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'NAMENODE'}},
  473. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  474. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  475. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  476. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  477. ],
  478. e: true,
  479. m: 'One Master is failed'
  480. },
  481. {
  482. actions: [
  483. {Tasks: {command: 'PENDING', status: 'FAILED', role: 'NAMENODE'}},
  484. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'TASKTRACKER'}},
  485. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'HBASE_REGIONSERVER'}},
  486. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'GANGLIA_MONITOR'}},
  487. {Tasks: {command: 'INSTALL', status: 'FAILED', role: 'SUPERVISOR'}}
  488. ],
  489. e: false,
  490. m: 'one Master is failed but command is not install'
  491. }
  492. ]);
  493. tests.forEach(function (test) {
  494. it(test.m, function () {
  495. expect(c.isMasterFailed(test.actions)).to.equal(test.e);
  496. });
  497. });
  498. });
  499. describe('#onInProgressPerHost', function () {
  500. var tests = Em.A([
  501. {
  502. host: Em.Object.create({message: 'default_message'}),
  503. actions: [
  504. {Tasks: {status: 'COMPLETED'}},
  505. {Tasks: {status: 'COMPLETED'}}
  506. ],
  507. e: {message: 'default_message', b: true},
  508. m: 'All Tasks COMPLETED'
  509. },
  510. {
  511. host: Em.Object.create({message: 'default_message'}),
  512. actions: [
  513. {Tasks: {status: 'IN_PROGRESS'}},
  514. {Tasks: {status: 'COMPLETED'}}
  515. ],
  516. e: {message: 'default_message', b: false},
  517. m: 'One Task IN_PROGRESS'
  518. },
  519. {
  520. host: Em.Object.create({message: 'default_message'}),
  521. actions: [
  522. {Tasks: {status: 'QUEUED'}},
  523. {Tasks: {status: 'COMPLETED'}}
  524. ],
  525. e: {message: 'default_message', b: false},
  526. m: 'One Task QUEUED'
  527. },
  528. {
  529. host: Em.Object.create({message: 'default_message'}),
  530. actions: [
  531. {Tasks: {status: 'PENDING'}},
  532. {Tasks: {status: 'COMPLETED'}}
  533. ],
  534. e: {message: 'default_message', b: false},
  535. m: 'One Task PENDING'
  536. }
  537. ]);
  538. tests.forEach(function (test) {
  539. it(test.m, function () {
  540. c.onInProgressPerHost(test.actions, test.host);
  541. expect(test.host.message == test.e.message).to.equal(test.e.b);
  542. });
  543. });
  544. });
  545. describe('#progressPerHost', function () {
  546. var tests = Em.A([
  547. {
  548. cluster: {status: 'PENDING'},
  549. host: Em.Object.create({progress: 0}),
  550. actions: [
  551. {Tasks: {status: 'COMPLETED'}},
  552. {Tasks: {status: 'COMPLETED'}},
  553. {Tasks: {status: 'QUEUED'}},
  554. {Tasks: {status: 'QUEUED'}},
  555. {Tasks: {status: 'IN_PROGRESS'}}
  556. ],
  557. e: {ret: 17, host: '17'},
  558. m: 'All types of status available. cluster status PENDING'
  559. },
  560. {
  561. cluster: {status: 'PENDING'},
  562. host: Em.Object.create({progress: 0}),
  563. actions: [],
  564. e: {ret: 33, host: '33'},
  565. m: 'No tasks available. cluster status PENDING'
  566. },
  567. {
  568. cluster: {status: 'INSTALLED'},
  569. host: Em.Object.create({progress: 0}),
  570. actions: [],
  571. e: {ret: 100, host: '100'},
  572. m: 'No tasks available. cluster status INSTALLED'
  573. },
  574. {
  575. cluster: {status: 'INSTALLED'},
  576. host: Em.Object.create({progress: 0}),
  577. actions: [
  578. {Tasks: {status: 'COMPLETED'}},
  579. {Tasks: {status: 'COMPLETED'}},
  580. {Tasks: {status: 'QUEUED'}},
  581. {Tasks: {status: 'QUEUED'}},
  582. {Tasks: {status: 'IN_PROGRESS'}}
  583. ],
  584. e: {ret: 68, host: '68'},
  585. m: 'All types of status available. cluster status INSTALLED'
  586. },
  587. {
  588. cluster: {status: 'FAILED'},
  589. host: Em.Object.create({progress: 0}),
  590. actions: [],
  591. e: {ret: 100, host: '100'},
  592. m: 'Cluster status is not PENDING or INSTALLED'
  593. }
  594. ]);
  595. tests.forEach(function (test) {
  596. it(test.m, function () {
  597. c.reopen({content: {cluster: {status: test.cluster.status}}});
  598. var progress = c.progressPerHost(test.actions, test.host);
  599. expect(progress).to.equal(test.e.ret);
  600. expect(test.host.progress).to.equal(test.e.host);
  601. });
  602. });
  603. });
  604. describe('#clearStep', function () {
  605. it('All to default values', function () {
  606. c.reopen({hosts: [{},{},{}]});
  607. c.clearStep();
  608. expect(c.get('hosts.length')).to.equal(0);
  609. expect(c.get('status')).to.equal('info');
  610. expect(c.get('progress')).to.equal('0');
  611. expect(c.get('numPolls')).to.equal(1);
  612. });
  613. });
  614. describe('#replacePolledData', function () {
  615. it('replacing polled data', function () {
  616. c.reopen({polledData: [{},{},{}]});
  617. var newPolledData = [{}];
  618. c.replacePolledData(newPolledData);
  619. expect(c.get('polledData.length')).to.equal(newPolledData.length);
  620. });
  621. });
  622. describe('#isSuccess', function () {
  623. var tests = Em.A([
  624. {
  625. polledData: [
  626. {Tasks: {status: 'COMPLETED'}},
  627. {Tasks: {status: 'COMPLETED'}}
  628. ],
  629. e: true,
  630. m: 'All tasks are COMPLETED'
  631. },
  632. {
  633. polledData: [
  634. {Tasks: {status: 'COMPLETED'}},
  635. {Tasks: {status: 'FAILED'}}
  636. ],
  637. e: false,
  638. m: 'Not all tasks are COMPLETED'
  639. }
  640. ]);
  641. tests.forEach(function (test) {
  642. it(test.m, function () {
  643. expect(c.isSuccess(test.polledData)).to.equal(test.e);
  644. });
  645. });
  646. });
  647. describe('#isStepFailed', function () {
  648. beforeEach(function() {
  649. sinon.stub(App, 'get', function(k) {
  650. if (k === 'components.slaves')
  651. return ["TASKTRACKER", "DATANODE", "JOURNALNODE", "ZKFC", "APP_TIMELINE_SERVER", "NODEMANAGER", "GANGLIA_MONITOR", "HBASE_REGIONSERVER", "SUPERVISOR", "FLUME_HANDLER"];
  652. return Em.get(App, k);
  653. });
  654. });
  655. afterEach(function() {
  656. App.get.restore();
  657. });
  658. var tests = Em.A([
  659. {
  660. polledData: [
  661. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  662. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'FAILED'}},
  663. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  664. ],
  665. e: true,
  666. m: 'GANGLIA_MONITOR 2/3 failed'
  667. },
  668. {
  669. polledData: [
  670. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'TIMEDOUT'}},
  671. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}},
  672. {Tasks: {command: 'INSTALL', role: 'GANGLIA_MONITOR', status: 'PENDING'}}
  673. ],
  674. e: false,
  675. m: 'GANGLIA_MONITOR 1/3 failed'
  676. },
  677. {
  678. polledData: [
  679. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  680. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'FAILED'}},
  681. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  682. ],
  683. e: true,
  684. m: 'HBASE_REGIONSERVER 2/3 failed'
  685. },
  686. {
  687. polledData: [
  688. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'TIMEDOUT'}},
  689. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}},
  690. {Tasks: {command: 'INSTALL', role: 'HBASE_REGIONSERVER', status: 'PENDING'}}
  691. ],
  692. e: false,
  693. m: 'HBASE_REGIONSERVER 1/3 failed'
  694. },
  695. {
  696. polledData: [
  697. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  698. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'FAILED'}},
  699. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  700. ],
  701. e: true,
  702. m: 'TASKTRACKER 2/3 failed'
  703. },
  704. {
  705. polledData: [
  706. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'TIMEDOUT'}},
  707. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}},
  708. {Tasks: {command: 'INSTALL', role: 'TASKTRACKER', status: 'PENDING'}}
  709. ],
  710. e: false,
  711. m: 'TASKTRACKER 1/3 failed'
  712. },
  713. {
  714. polledData: [
  715. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  716. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'FAILED'}},
  717. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  718. ],
  719. e: true,
  720. m: 'DATANODE 2/3 failed'
  721. },
  722. {
  723. polledData: [
  724. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'TIMEDOUT'}},
  725. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  726. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  727. ],
  728. e: false,
  729. m: 'DATANODE 1/3 failed'
  730. },
  731. {
  732. polledData: [
  733. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'TIMEDOUT'}},
  734. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  735. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  736. ],
  737. e: true,
  738. m: 'NAMENODE failed'
  739. },
  740. {
  741. polledData: [
  742. {Tasks: {command: 'INSTALL', role: 'NAMENODE', status: 'PENDING'}},
  743. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}},
  744. {Tasks: {command: 'INSTALL', role: 'DATANODE', status: 'PENDING'}}
  745. ],
  746. e: false,
  747. m: 'Nothing failed failed'
  748. }
  749. ]);
  750. tests.forEach(function (test) {
  751. it(test.m, function () {
  752. c.reopen({polledData: test.polledData});
  753. expect(c.isStepFailed()).to.equal(test.e);
  754. });
  755. });
  756. });
  757. describe('#setLogTasksStatePerHost', function () {
  758. var tests = Em.A([
  759. {
  760. tasksPerHost: [
  761. {Tasks: {id: 1, status: 'COMPLETED'}},
  762. {Tasks: {id: 2, status: 'COMPLETED'}}
  763. ],
  764. tasks: [],
  765. e: {m: 'COMPLETED', l: 2},
  766. m: 'host didn\'t have tasks and got 2 new'
  767. },
  768. {
  769. tasksPerHost: [
  770. {Tasks: {id: 1, status: 'COMPLETED'}},
  771. {Tasks: {id: 2, status: 'COMPLETED'}}
  772. ],
  773. tasks: [
  774. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  775. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  776. ],
  777. e: {m: 'COMPLETED', l: 2},
  778. m: 'host had 2 tasks and got both updated'
  779. },
  780. {
  781. tasksPerHost: [],
  782. tasks: [
  783. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  784. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  785. ],
  786. e: {m: 'IN_PROGRESS', l: 2},
  787. m: 'host had 2 tasks and didn\'t get updates'
  788. },
  789. {
  790. tasksPerHost: [
  791. {Tasks: {id: 1, status: 'COMPLETED'}},
  792. {Tasks: {id: 2, status: 'COMPLETED'}},
  793. {Tasks: {id: 3, status: 'COMPLETED'}}
  794. ],
  795. tasks: [
  796. {Tasks: {id: 1, status: 'IN_PROGRESS'}},
  797. {Tasks: {id: 2, status: 'IN_PROGRESS'}}
  798. ],
  799. e: {m: 'COMPLETED', l: 3},
  800. m: 'host had 2 tasks and got both updated and 1 new'
  801. }
  802. ]);
  803. tests.forEach(function (test) {
  804. it(test.m, function () {
  805. c.reopen({hosts: [Em.Object.create({logTasks: test.tasks})]});
  806. c.setLogTasksStatePerHost(test.tasksPerHost, c.get('hosts')[0]);
  807. expect(c.get('hosts')[0].get('logTasks').everyProperty('Tasks.status', test.e.m)).to.equal(true);
  808. expect(c.get('hosts')[0].get('logTasks.length')).to.equal(test.e.l);
  809. });
  810. });
  811. });
  812. // On completion of Start all services error callback function,
  813. // Cluster Status should be INSTALL FAILED
  814. // All progress bar on the screen should be finished (100%) with blue color.
  815. // Retry button should be enabled, next button should be disabled
  816. describe('#launchStartServicesErrorCallback', function () {
  817. beforeEach(function() {
  818. sinon.stub(App, 'get', function(k) {
  819. if ('testMode' === k) return true;
  820. return Em.get(App, k);
  821. });
  822. });
  823. afterEach(function() {
  824. App.get.restore();
  825. });
  826. it('Main progress bar on the screen should be finished (100%) with red color', function () {
  827. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  828. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  829. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  830. expect(c.get('progress')).to.equal('100');
  831. expect(c.get('status')).to.equal('failed');
  832. });
  833. it('All Host progress bars on the screen should be finished (100%) with blue color', function () {
  834. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  835. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  836. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  837. c.get('hosts').forEach(function (host) {
  838. expect(host.get('progress')).to.equal('100');
  839. expect(host.get('status')).to.equal('info');
  840. });
  841. });
  842. it('Next button should be disabled', function () {
  843. var hosts = Em.A([Em.Object.create({name: 'host1', progress: '33', status: 'info'}), Em.Object.create({name: 'host2', progress: '33', status: 'info'})]);
  844. c.reopen({hosts: hosts, content: {controllerName: 'installerController', cluster: {status: 'PENDING', name: 'c1'}}});
  845. c.launchStartServicesErrorCallback({status: 500, statusTesxt: 'Server Error'}, {}, '', {});
  846. expect(c.get('isSubmitDisabled')).to.equal(true);
  847. });
  848. });
  849. describe('#submit', function () {
  850. it('should call App.router.send', function () {
  851. sinon.stub(App.router, 'send', Em.K);
  852. c.submit();
  853. expect(App.router.send.calledWith('next')).to.equal(true);
  854. App.router.send.restore();
  855. });
  856. });
  857. describe('#back', function () {
  858. beforeEach(function () {
  859. sinon.stub(App.router, 'send', Em.K);
  860. });
  861. afterEach(function () {
  862. App.router.send.restore();
  863. });
  864. it('should call App.router.send', function () {
  865. c.reopen({isSubmitDisabled: false});
  866. c.back();
  867. expect(App.router.send.calledWith('back')).to.equal(true);
  868. });
  869. it('shouldn\'t call App.router.send', function () {
  870. c.reopen({isSubmitDisabled: true});
  871. c.back();
  872. expect(App.router.send.called).to.equal(false);
  873. });
  874. });
  875. describe('#loadStep', function () {
  876. beforeEach(function () {
  877. sinon.stub(c, 'clearStep', Em.K);
  878. sinon.stub(c, 'loadHosts', Em.K);
  879. });
  880. afterEach(function () {
  881. c.clearStep.restore();
  882. c.loadHosts.restore();
  883. });
  884. it('should call clearStep', function () {
  885. c.loadStep();
  886. expect(c.clearStep.calledOnce).to.equal(true);
  887. });
  888. it('should call loadHosts', function () {
  889. c.loadStep();
  890. expect(c.loadHosts.calledOnce).to.equal(true);
  891. });
  892. });
  893. describe('#startPolling', function () {
  894. beforeEach(function () {
  895. sinon.stub(c, 'getLogsByRequestErrorCallback', Em.K);
  896. });
  897. afterEach(function () {
  898. c.getLogsByRequestErrorCallback.restore();
  899. });
  900. it('should set isSubmitDisabled to true', function () {
  901. c.set('isSubmitDisabled', false);
  902. c.startPolling();
  903. expect(c.get('isSubmitDisabled')).to.equal(true);
  904. });
  905. it('should call doPolling', function () {
  906. sinon.stub(c, 'doPolling', Em.K);
  907. c.startPolling();
  908. expect(c.doPolling.calledOnce).to.equal(true);
  909. c.doPolling.restore();
  910. });
  911. });
  912. describe('#loadLogData', function () {
  913. beforeEach(function () {
  914. obj.reopen({
  915. cluster: {oldRequestsId: [1,2,3]},
  916. getDBProperty: function (name) {
  917. return this.get(name);
  918. }
  919. });
  920. c.reopen({wizardController: obj});
  921. sinon.stub(c, 'getLogsByRequest', Em.K);
  922. });
  923. afterEach(function () {
  924. c.getLogsByRequest.restore();
  925. });
  926. it('should call getLogsByRequest 1 time with 3', function () {
  927. c.loadLogData(true);
  928. expect(c.getLogsByRequest.calledWith(true, 3)).to.equal(true);
  929. });
  930. it('should set POLL_INTERVAL to 1 if testMode enabled', function () {
  931. sinon.stub(App, 'get', function(k) { if ('testMode' === k) return true; return Em.get(App, k);});
  932. c.loadLogData();
  933. expect(c.get('POLL_INTERVAL')).to.equal(1);
  934. App.get.restore();
  935. });
  936. });
  937. describe('#loadCurrentTaskLog', function () {
  938. beforeEach(function () {
  939. sinon.stub(c, 'loadLogData', Em.K);
  940. c.set('wizardController', Em.Object.create({
  941. getDBProperty: Em.K
  942. }));
  943. });
  944. afterEach(function () {
  945. c.loadLogData.restore();
  946. });
  947. it('shouldn\'t call App.ajax.send if no currentOpenTaskId', function () {
  948. c.set('currentOpenTaskId', null);
  949. c.loadCurrentTaskLog();
  950. expect(App.ajax.send.called).to.equal(false);
  951. });
  952. it('should call App.ajax.send with provided data', function () {
  953. sinon.stub(c, 'togglePreviousSteps', Em.K);
  954. c.set('currentOpenTaskId', 1);
  955. c.set('currentOpenTaskRequestId', 2);
  956. c.set('content', {cluster: {name: 3}});
  957. c.loadCurrentTaskLog();
  958. expect(App.ajax.send.args[0][0].data).to.eql({taskId: 1, requestId: 2, clusterName: 3});
  959. c.togglePreviousSteps.restore();
  960. });
  961. });
  962. describe('#loadCurrentTaskLogSuccessCallback', function () {
  963. beforeEach(function() {
  964. sinon.stub(c, 'getLogsByRequest', Em.K);
  965. sinon.stub(c, 'loadLogData', Em.K);
  966. });
  967. afterEach(function() {
  968. c.getLogsByRequest.restore();
  969. c.loadLogData.restore();
  970. });
  971. it('should increment logTasksChangesCounter', function () {
  972. c.set('logTasksChangesCounter', 0);
  973. c.loadCurrentTaskLogSuccessCallback();
  974. expect(c.get('logTasksChangesCounter')).to.equal(1);
  975. });
  976. it('should update stdout, stderr', function () {
  977. c.set('currentOpenTaskId', 1);
  978. c.reopen({
  979. hosts: [
  980. Em.Object.create({
  981. name: 'h1',
  982. logTasks: [
  983. {Tasks: {id: 1, stdout: '', stderr: ''}}
  984. ]
  985. })
  986. ]
  987. });
  988. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  989. c.loadCurrentTaskLogSuccessCallback(data);
  990. var t = c.get('hosts')[0].logTasks[0].Tasks;
  991. expect(t.stdout).to.equal('stdout');
  992. expect(t.stderr).to.equal('stderr');
  993. });
  994. it('shouldn\'t update stdout, stderr', function () {
  995. c.set('currentOpenTaskId', 1);
  996. c.reopen({
  997. hosts: [
  998. Em.Object.create({
  999. name: 'h1',
  1000. logTasks: [
  1001. {Tasks: {id: 2, stdout: '', stderr: ''}}
  1002. ]
  1003. })
  1004. ]
  1005. });
  1006. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1007. c.loadCurrentTaskLogSuccessCallback(data);
  1008. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1009. expect(t.stdout).to.equal('');
  1010. expect(t.stderr).to.equal('');
  1011. });
  1012. it('shouldn\'t update stdout, stderr (2)', function () {
  1013. c.set('currentOpenTaskId', 1);
  1014. c.reopen({
  1015. hosts: [
  1016. Em.Object.create({
  1017. name: 'h2',
  1018. logTasks: [
  1019. {Tasks: {id: 1, stdout: '', stderr: ''}}
  1020. ]
  1021. })
  1022. ]
  1023. });
  1024. var data = {Tasks: {host_name: 'h1', id: 1, stderr: 'stderr', stdout: 'stdout'}};
  1025. c.loadCurrentTaskLogSuccessCallback(data);
  1026. var t = c.get('hosts')[0].logTasks[0].Tasks;
  1027. expect(t.stdout).to.equal('');
  1028. expect(t.stderr).to.equal('');
  1029. });
  1030. });
  1031. describe('#loadCurrentTaskLogErrorCallback', function () {
  1032. it('should set currentOpenTaskId to 0', function () {
  1033. c.set('currentOpenTaskId', 123);
  1034. c.loadCurrentTaskLogErrorCallback();
  1035. expect(c.get('currentOpenTaskId')).to.equal(0);
  1036. });
  1037. });
  1038. describe('#getLogsByRequest', function () {
  1039. beforeEach(function () {
  1040. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1041. sinon.stub(c, 'loadLogData', Em.K);
  1042. });
  1043. afterEach(function () {
  1044. c.togglePreviousSteps.restore();
  1045. c.loadLogData.restore();
  1046. });
  1047. it('should call App.ajax.send with provided data', function () {
  1048. var polling = 1;
  1049. var requestId = 2;
  1050. c.set('content', {cluster: {name: 3}});
  1051. c.set('numPolls', 4);
  1052. c.getLogsByRequest(polling, requestId);
  1053. expect(App.ajax.send.args[0][0].data).to.eql({polling: polling, requestId: requestId, cluster: 3, numPolls: 4});
  1054. });
  1055. });
  1056. describe('#doPolling', function () {
  1057. beforeEach(function () {
  1058. sinon.stub(c, 'getLogsByRequest', Em.K);
  1059. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1060. });
  1061. afterEach(function () {
  1062. c.getLogsByRequest.restore();
  1063. c.togglePreviousSteps.restore();
  1064. });
  1065. it('should increment numPolls if testMode', function () {
  1066. App.set('testMode', true);
  1067. c.set('numPolls', 0);
  1068. c.doPolling();
  1069. expect(c.get('numPolls')).to.equal(1);
  1070. App.set('testMode', false);
  1071. });
  1072. it('should call getLogsByRequest', function () {
  1073. c.set('content', {cluster: {requestId: 1}});
  1074. c.doPolling();
  1075. expect(c.getLogsByRequest.calledWith(true, 1)).to.equal(true);
  1076. });
  1077. });
  1078. describe('#isAllComponentsInstalled', function () {
  1079. it('shouldn\'t call App.ajax.send', function () {
  1080. c.set('content', {controllerName: 'addServiceController'});
  1081. c.isAllComponentsInstalled();
  1082. expect(App.ajax.send.called).to.equal(false);
  1083. });
  1084. it('should call App.ajax.send', function () {
  1085. c.set('content', Ember.Object.create({cluster: {name: 'n'}, controllerName: 'installerController'}));
  1086. c.isAllComponentsInstalled();
  1087. expect(App.ajax.send.args[0][0].data).to.eql({cluster: 'n'});
  1088. });
  1089. });
  1090. describe('#isAllComponentsInstalledErrorCallback', function () {
  1091. beforeEach(function () {
  1092. sinon.stub(c, 'saveClusterStatus', Em.K);
  1093. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1094. });
  1095. afterEach(function () {
  1096. c.saveClusterStatus.restore();
  1097. c.togglePreviousSteps.restore();
  1098. });
  1099. it('should call saveClusterStatus', function () {
  1100. c.isAllComponentsInstalledErrorCallback({});
  1101. expect(c.saveClusterStatus.calledOnce).to.equal(true);
  1102. });
  1103. });
  1104. describe('#navigateStep', function () {
  1105. beforeEach(function () {
  1106. sinon.stub(c, 'togglePreviousSteps', Em.K);
  1107. sinon.stub(c, 'loadStep', Em.K);
  1108. sinon.stub(c, 'loadLogData', Em.K);
  1109. sinon.stub(c, 'startPolling', Em.K);
  1110. });
  1111. afterEach(function () {
  1112. c.togglePreviousSteps.restore();
  1113. c.loadStep.restore();
  1114. c.loadLogData.restore();
  1115. c.startPolling.restore();
  1116. App.get.restore();
  1117. });
  1118. it('should set custom data in testMode', function () {
  1119. sinon.stub(App, 'get', function(k) {if('testMode' === k) return true; return Em.get(App, k);});
  1120. c.reopen({content: {cluster: {status: 'st', isCompleted: true, requestId: 0}}});
  1121. c.navigateStep();
  1122. expect(c.get('content.cluster.status')).to.equal('PENDING');
  1123. expect(c.get('content.cluster.isCompleted')).to.equal(false);
  1124. expect(c.get('content.cluster.requestId')).to.equal(1);
  1125. });
  1126. it('isCompleted = true, requestId = 1', function () {
  1127. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1128. c.reopen({content: {cluster: {isCompleted: true, requestId: 1}}});
  1129. c.navigateStep();
  1130. expect(c.loadStep.calledOnce).to.equal(true);
  1131. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1132. expect(c.get('progress')).to.equal('100');
  1133. });
  1134. it('isCompleted = false, requestId = 1, status = INSTALL FAILED', function () {
  1135. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1136. c.reopen({content: {cluster: {status: 'INSTALL FAILED', isCompleted: false, requestId: 1}}});
  1137. c.navigateStep();
  1138. expect(c.loadStep.calledOnce).to.equal(true);
  1139. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1140. });
  1141. it('isCompleted = false, requestId = 1, status = START FAILED', function () {
  1142. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1143. c.reopen({content: {cluster: {status: 'START FAILED', isCompleted: false, requestId: 1}}});
  1144. c.navigateStep();
  1145. expect(c.loadStep.calledOnce).to.equal(true);
  1146. expect(c.loadLogData.calledWith(false)).to.equal(true);
  1147. });
  1148. it('isCompleted = false, requestId = 1, status = OTHER', function () {
  1149. sinon.stub(App, 'get', function(k) {if('testMode' === k) return false; return Em.get(App, k);});
  1150. c.reopen({content: {cluster: {status: 'STARTED', isCompleted: false, requestId: 1}}});
  1151. c.navigateStep();
  1152. expect(c.loadStep.calledOnce).to.equal(true);
  1153. expect(c.loadLogData.calledWith(true)).to.equal(true);
  1154. });
  1155. });
  1156. describe('#launchStartServicesSuccessCallback', function () {
  1157. beforeEach(function () {
  1158. sinon.stub(App.clusterStatus, 'setClusterStatus', function() {
  1159. return $.ajax();
  1160. });
  1161. sinon.stub(c, 'saveClusterStatus', Em.K);
  1162. sinon.stub(c, 'doPolling', Em.K);
  1163. sinon.stub(c, 'hostHasClientsOnly', Em.K);
  1164. });
  1165. afterEach(function () {
  1166. c.saveClusterStatus.restore();
  1167. c.doPolling.restore();
  1168. c.hostHasClientsOnly.restore();
  1169. App.clusterStatus.setClusterStatus.restore();
  1170. });
  1171. it('should call doPolling if some data were received', function () {
  1172. c.launchStartServicesSuccessCallback({Requests: {id: 2}});
  1173. expect(c.doPolling.calledOnce).to.equal(true);
  1174. });
  1175. Em.A([
  1176. {
  1177. jsonData: {Requests: {id: 2}},
  1178. e: {
  1179. hostHasClientsOnly: false,
  1180. clusterStatus: {
  1181. status: 'INSTALLED',
  1182. requestId: 2,
  1183. isStartError: false,
  1184. isCompleted: false
  1185. }
  1186. }
  1187. },
  1188. {
  1189. jsonData: null,
  1190. e: {
  1191. hostHasClientsOnly: true,
  1192. clusterStatus: {
  1193. status: 'STARTED',
  1194. isStartError: false,
  1195. isCompleted: true
  1196. },
  1197. status: 'success',
  1198. progress: '100'
  1199. }
  1200. }
  1201. ]).forEach(function (test) {
  1202. it(test.m, function () {
  1203. c.launchStartServicesSuccessCallback(test.jsonData);
  1204. expect(c.hostHasClientsOnly.calledWith(test.e.hostHasClientsOnly)).to.equal(true);
  1205. expect(c.saveClusterStatus.calledWith(test.e.clusterStatus)).to.equal(true);
  1206. if (test.e.status) {
  1207. expect(c.get('status')).to.equal(test.e.status);
  1208. }
  1209. if (test.e.progress) {
  1210. expect(c.get('progress')).to.equal(test.e.progress);
  1211. }
  1212. });
  1213. });
  1214. });
  1215. });