step10_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/wizard/step10_controller');
  20. var controller;
  21. function getController() {
  22. return App.WizardStep10Controller.create({
  23. content: {cluster: {controllerName: '', status: 'INSTALL COMPLETE'}}
  24. });
  25. }
  26. describe('App.WizardStep10Controller', function () {
  27. beforeEach(function() {
  28. controller = getController();
  29. });
  30. afterEach(function() {
  31. controller.clearStep();
  32. });
  33. App.TestAliases.testAsComputedEqual(getController(), 'isAddServiceWizard', 'content.controllerName', 'addServiceController');
  34. describe('#clearStep', function() {
  35. it('should clear clusterInfo', function() {
  36. controller.get('clusterInfo').pushObject({});
  37. controller.clearStep();
  38. expect(controller.get('clusterInfo.length')).to.equal(0);
  39. });
  40. });
  41. describe('#loadStep', function() {
  42. beforeEach(function() {
  43. sinon.spy(controller, 'clearStep');
  44. sinon.stub(controller, 'loadRegisteredHosts', Em.K);
  45. sinon.stub(controller, 'loadInstalledHosts', Em.K);
  46. sinon.stub(controller, 'loadInstallTime', Em.K);
  47. });
  48. afterEach(function() {
  49. controller.clearStep.restore();
  50. controller.loadRegisteredHosts.restore();
  51. controller.loadInstalledHosts.restore();
  52. controller.loadInstallTime.restore();
  53. });
  54. it('should call clearStep', function() {
  55. controller.loadStep();
  56. expect(controller.clearStep.calledOnce).to.equal(true);
  57. });
  58. it('should call loadInstalledHosts', function() {
  59. controller.loadStep();
  60. expect(controller.loadInstalledHosts.calledOnce).to.equal(true);
  61. });
  62. it('should loadInstallTime if not installerController', function() {
  63. controller.set('content.controllerName', 'addServiceController');
  64. controller.loadStep();
  65. expect(controller.loadInstallTime.calledOnce).to.equal(true);
  66. });
  67. var testsForLoadInstallTime = Em.A([
  68. {
  69. loadMasterComponents: true,
  70. loadStartedServices: true,
  71. e: true
  72. },
  73. {
  74. loadMasterComponents: true,
  75. loadStartedServices: false,
  76. e: false
  77. },
  78. {
  79. loadMasterComponents: false,
  80. loadStartedServices: false,
  81. e: false
  82. },
  83. {
  84. loadMasterComponents: false,
  85. loadStartedServices: false,
  86. e: false
  87. }
  88. ]);
  89. testsForLoadInstallTime.forEach(function(test) {
  90. it('loadMasterComponents: ' + test.loadMasterComponents.toString() + ' loadStartedServices: ' + test.loadStartedServices.toString(), function() {
  91. controller.set('content.controllerName', 'installerController');
  92. sinon.stub(controller, 'loadMasterComponents', function() {return test.loadMasterComponents;});
  93. sinon.stub(controller, 'loadStartedServices', function() {return test.loadStartedServices;});
  94. controller.loadStep();
  95. expect(controller.loadInstallTime.called).to.equal(test.e);
  96. controller.loadMasterComponents.restore();
  97. controller.loadStartedServices.restore();
  98. });
  99. });
  100. });
  101. describe('#loadInstalledHosts', function() {
  102. var tests = Em.A([
  103. {
  104. hosts: {
  105. 'h1': Em.Object.create({status: 'success', tasks: []}),
  106. 'h2': Em.Object.create({status: 'success', tasks: []}),
  107. 'h3': Em.Object.create({status: 'success', tasks: []})
  108. },
  109. m: 'all success',
  110. e: Em.A([
  111. {id: 1, l: 3}
  112. ])
  113. },
  114. {
  115. hosts: {
  116. 'h1': Em.Object.create({status: 'warning', tasks: []}),
  117. 'h2': Em.Object.create({status: 'failed', tasks: []}),
  118. 'h3': Em.Object.create({status: 'failed', tasks: []})
  119. },
  120. m: 'some failed, some warning',
  121. e: Em.A([
  122. {id: 2, l: 3}
  123. ])
  124. },
  125. {
  126. hosts: {
  127. 'h1': Em.Object.create({status: 'failed', tasks: []}),
  128. 'h2': Em.Object.create({status: 'success', tasks: []}),
  129. 'h3': Em.Object.create({status: 'warning', tasks: []})
  130. },
  131. m: 'sone failed, some success, some warning',
  132. e: Em.A([
  133. {id: 1, l: 1},
  134. {id: 2, l: 2}
  135. ])
  136. }
  137. ]);
  138. tests.forEach(function(test) {
  139. it(test.m, function() {
  140. controller.set('content.hosts', test.hosts);
  141. controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
  142. controller.loadInstalledHosts();
  143. test.e.forEach(function(ex) {
  144. expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', ex.id).get('displayStatement').contains(ex.l)).to.equal(true);
  145. });
  146. })
  147. });
  148. var testsForFailedTasks = Em.A([
  149. {
  150. hosts: {
  151. 'h1': Em.Object.create({
  152. status: 'failed',
  153. tasks: [
  154. {Tasks: {status: 'FAILED'}},
  155. {Tasks: {status: 'FAILED'}}
  156. ]
  157. }),
  158. 'h2': Em.Object.create({
  159. status: 'failed',
  160. tasks: [
  161. {Tasks: {status: 'FAILED'}}
  162. ]
  163. }),
  164. 'h3': Em.Object.create({status: 'failed', tasks: []})
  165. },
  166. m: 'only failed tasks',
  167. e: Em.A([
  168. {st: 'failed', l: 3}
  169. ])
  170. },
  171. {
  172. hosts: {
  173. 'h1': Em.Object.create({
  174. status: 'failed',
  175. tasks: [
  176. {Tasks: {status: 'TIMEDOUT'}}
  177. ]
  178. }),
  179. 'h2': Em.Object.create({
  180. status: 'failed',
  181. tasks: [
  182. {Tasks: {status: 'TIMEDOUT'}}
  183. ]
  184. }),
  185. 'h3': Em.Object.create({
  186. status: 'failed',
  187. tasks: [
  188. {Tasks: {status: 'TIMEDOUT'}}
  189. ]
  190. })
  191. },
  192. m: 'only timedout tasks',
  193. e: Em.A([
  194. {st: 'timedout', l: 3}
  195. ])
  196. },
  197. {
  198. hosts: {
  199. 'h1': Em.Object.create({
  200. status: 'failed',
  201. tasks: []
  202. }),
  203. 'h2': Em.Object.create({
  204. status: 'failed',
  205. tasks: []
  206. }),
  207. 'h3': Em.Object.create({
  208. status: 'failed',
  209. tasks: [
  210. {Tasks: {status: 'ABORTED'}},
  211. {Tasks: {status: 'ABORTED'}},
  212. {Tasks: {status: 'ABORTED'}}
  213. ]
  214. })
  215. },
  216. m: 'only aborted tasks',
  217. e: Em.A([
  218. {st: 'aborted', l: 3}
  219. ])
  220. },
  221. {
  222. hosts: {
  223. 'h1': Em.Object.create({
  224. status: 'warning',
  225. tasks: [
  226. {Tasks: {status: 'FAILED'}},
  227. {Tasks: {status: 'FAILED'}}
  228. ]
  229. }),
  230. 'h2': Em.Object.create({
  231. status: 'warning',
  232. tasks: [
  233. {Tasks: {status: 'FAILED'}}
  234. ]
  235. }),
  236. 'h3': Em.Object.create({status: 'warning', tasks: []})
  237. },
  238. m: 'only failed tasks, warning hosts',
  239. e: Em.A([
  240. {st: 'failed', l: 3}
  241. ])
  242. },
  243. {
  244. hosts: {
  245. 'h1': Em.Object.create({
  246. status: 'warning',
  247. tasks: [
  248. {Tasks: {status: 'TIMEDOUT'}}
  249. ]
  250. }),
  251. 'h2': Em.Object.create({
  252. status: 'warning',
  253. tasks: [
  254. {Tasks: {status: 'TIMEDOUT'}}
  255. ]
  256. }),
  257. 'h3': Em.Object.create({
  258. status: 'warning',
  259. tasks: [
  260. {Tasks: {status: 'TIMEDOUT'}}
  261. ]
  262. })
  263. },
  264. m: 'only timedout tasks, warning hosts',
  265. e: Em.A([
  266. {st: 'timedout', l: 3}
  267. ])
  268. },
  269. {
  270. hosts: {
  271. 'h1': Em.Object.create({
  272. status: 'warning',
  273. tasks: []
  274. }),
  275. 'h2': Em.Object.create({
  276. status: 'warning',
  277. tasks: []
  278. }),
  279. 'h3': Em.Object.create({
  280. status: 'warning',
  281. tasks: [
  282. {Tasks: {status: 'ABORTED'}},
  283. {Tasks: {status: 'ABORTED'}},
  284. {Tasks: {status: 'ABORTED'}}
  285. ]
  286. })
  287. },
  288. m: 'only aborted tasks, warning hosts',
  289. e: Em.A([
  290. {st: 'aborted', l: 3}
  291. ])
  292. }
  293. ]);
  294. testsForFailedTasks.forEach(function(test) {
  295. it(test.m, function() {
  296. controller.set('content.hosts', test.hosts);
  297. controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
  298. controller.loadInstalledHosts();
  299. test.e.forEach(function(ex) {
  300. expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').mapProperty('status', ex.st).length).to.equal(ex.l);
  301. });
  302. })
  303. });
  304. });
  305. describe('#loadMasterComponent', function() {
  306. var tests = Em.A([
  307. {
  308. component: Em.Object.create({hostName: 'h1'}),
  309. e: 1
  310. },
  311. {
  312. component: Em.Object.create({}),
  313. e: 0
  314. }
  315. ]);
  316. tests.forEach(function(test) {
  317. it(test.component.get('hostName') ? 'Has hosNBame' : 'Doesn\'t have hostName', function() {
  318. controller.clearStep();
  319. controller.get('clusterInfo').pushObject(Em.Object.create({id: 2, status: []}));
  320. controller.loadMasterComponent(test.component);
  321. expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(test.e);
  322. })
  323. });
  324. });
  325. describe('#loadStartedServices', function() {
  326. var tests = Em.A([
  327. {
  328. status: 'STARTED',
  329. e: {
  330. ids: [3, 4],
  331. r: true
  332. }
  333. },
  334. {
  335. status: 'FAILED',
  336. e: {
  337. ids: [3],
  338. r: false
  339. }
  340. },
  341. {
  342. status: 'START_SKIPPED',
  343. e: {
  344. ids: [3],
  345. r: false
  346. }
  347. }
  348. ]);
  349. tests.forEach(function(test) {
  350. it(test.status, function() {
  351. controller.set('content', {cluster: {status: test.status}});
  352. var r = controller.loadStartedServices();
  353. expect(r).to.equal(test.e.r);
  354. expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e.ids);
  355. });
  356. });
  357. });
  358. describe('#loadInstallTime', function() {
  359. var tests = Em.A([
  360. {
  361. installTime: 123,
  362. e: [5]
  363. },
  364. {
  365. installTime: null,
  366. e: []
  367. }
  368. ]);
  369. tests.forEach(function(test) {
  370. it('Install time' + test.installTime ? ' available' : ' not available', function() {
  371. controller.set('content', {cluster: {installTime: test.installTime}});
  372. var r = controller.loadInstallTime();
  373. expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e);
  374. });
  375. });
  376. });
  377. describe('#calculateInstallTime', function () {
  378. it('from "9.21" to 9 minutes 12 seconds', function () {
  379. expect(controller.calculateInstallTime('9.21')).to.eql({minutes: 9, seconds: 12});
  380. });
  381. it('from "0" to 0 minutes 0 seconds', function () {
  382. expect(controller.calculateInstallTime('0')).to.eql({minutes: 0, seconds: 0});
  383. });
  384. it('from "10" to 10 minutes 0 seconds', function () {
  385. expect(controller.calculateInstallTime('10')).to.eql({minutes: 10, seconds: 0});
  386. });
  387. it('from "0.5" to 0 minutes 30 seconds', function () {
  388. expect(controller.calculateInstallTime('0.5')).to.eql({minutes: 0, seconds: 30});
  389. });
  390. });
  391. describe('#loadMasterComponents', function() {
  392. var components = Em.A(['NAMENODE','SECONDARY_NAMENODE','JOBTRACKER','HISTORYSERVER','RESOURCEMANAGER','HBASE_MASTER','HIVE_SERVER','OOZIE_SERVER','GANGLIA_SERVER']);
  393. d3.range(1, components.length).forEach(function(i) {
  394. d3.range(1, i).forEach(function(j) {
  395. var c = components.slice(0, j);
  396. it(c.join(', '), function() {
  397. var m = c.map(function(component){return {component: component, displayName: component, hostName: 'h1'};});
  398. controller.set('content.masterComponentHosts', m);
  399. controller.loadMasterComponents();
  400. expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(m.length);
  401. });
  402. });
  403. });
  404. });
  405. describe('#loadRegisteredHosts', function() {
  406. it('should add object to clusterInfo', function() {
  407. var masterComponentHosts = [{hostName: 'h1'}, {hostName: 'h2'}, {hostName: 'h3'}],
  408. slaveComponentHosts = [{hosts: [{hostName: 'h1'}, {hostName: 'h4'}]}, {hosts: [{hostName: 'h2'}, {hostName: 'h5'}]}],
  409. hosts = [{hostName: 'h6'}, {hostName: 'h3'}, {hostName: 'h7'}];
  410. controller.set('content.masterComponentHosts', masterComponentHosts);
  411. controller.set('content.slaveComponentHosts', slaveComponentHosts);
  412. controller.set('clusterInfo', []);
  413. sinon.stub(App.Host, 'find', function() {
  414. return hosts;
  415. });
  416. var obj = controller.loadRegisteredHosts();
  417. App.Host.find.restore();
  418. expect(obj.id).to.equal(1);
  419. expect(obj.color).to.equal('text-info');
  420. expect(obj.displayStatement).to.equal(Em.I18n.t('installer.step10.hostsSummary').format(7));
  421. expect(obj.status).to.eql([]);
  422. expect(controller.get('clusterInfo.firstObject')).to.eql(obj);
  423. });
  424. });
  425. });