step10_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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. describe('loadMasterComponents: ' + test.loadMasterComponents.toString() + ' loadStartedServices: ' + test.loadStartedServices.toString(), function() {
  91. beforeEach(function () {
  92. controller.set('content.controllerName', 'installerController');
  93. sinon.stub(controller, 'loadMasterComponents', function() {return test.loadMasterComponents;});
  94. sinon.stub(controller, 'loadStartedServices', function() {return test.loadStartedServices;});
  95. controller.loadStep();
  96. });
  97. afterEach(function () {
  98. controller.loadMasterComponents.restore();
  99. controller.loadStartedServices.restore();
  100. });
  101. it('loadInstallTime was ' + (test.e ? '' : 'not') + ' called', function () {
  102. expect(controller.loadInstallTime.called).to.equal(test.e);
  103. });
  104. });
  105. });
  106. });
  107. describe('#loadInstalledHosts', function() {
  108. var tests = Em.A([
  109. {
  110. hosts: {
  111. 'h1': Em.Object.create({status: 'success', tasks: []}),
  112. 'h2': Em.Object.create({status: 'success', tasks: []}),
  113. 'h3': Em.Object.create({status: 'success', tasks: []})
  114. },
  115. m: 'all success',
  116. e: Em.A([
  117. {id: 1, l: 3}
  118. ])
  119. },
  120. {
  121. hosts: {
  122. 'h1': Em.Object.create({status: 'warning', tasks: []}),
  123. 'h2': Em.Object.create({status: 'failed', tasks: []}),
  124. 'h3': Em.Object.create({status: 'failed', tasks: []})
  125. },
  126. m: 'some failed, some warning',
  127. e: Em.A([
  128. {id: 2, l: 3}
  129. ])
  130. },
  131. {
  132. hosts: {
  133. 'h1': Em.Object.create({status: 'failed', tasks: []}),
  134. 'h2': Em.Object.create({status: 'success', tasks: []}),
  135. 'h3': Em.Object.create({status: 'warning', tasks: []})
  136. },
  137. m: 'sone failed, some success, some warning',
  138. e: Em.A([
  139. {id: 1, l: 1},
  140. {id: 2, l: 2}
  141. ])
  142. }
  143. ]);
  144. tests.forEach(function(test) {
  145. it(test.m, function() {
  146. controller.set('content.hosts', test.hosts);
  147. controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
  148. controller.loadInstalledHosts();
  149. test.e.forEach(function(ex) {
  150. expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', ex.id).get('displayStatement').contains(ex.l)).to.equal(true);
  151. });
  152. })
  153. });
  154. var testsForFailedTasks = Em.A([
  155. {
  156. hosts: {
  157. 'h1': Em.Object.create({
  158. status: 'failed',
  159. tasks: [
  160. {Tasks: {status: 'FAILED'}},
  161. {Tasks: {status: 'FAILED'}}
  162. ]
  163. }),
  164. 'h2': Em.Object.create({
  165. status: 'failed',
  166. tasks: [
  167. {Tasks: {status: 'FAILED'}}
  168. ]
  169. }),
  170. 'h3': Em.Object.create({status: 'failed', tasks: []})
  171. },
  172. m: 'only failed tasks',
  173. e: Em.A([
  174. {st: 'failed', l: 3}
  175. ])
  176. },
  177. {
  178. hosts: {
  179. 'h1': Em.Object.create({
  180. status: 'failed',
  181. tasks: [
  182. {Tasks: {status: 'TIMEDOUT'}}
  183. ]
  184. }),
  185. 'h2': Em.Object.create({
  186. status: 'failed',
  187. tasks: [
  188. {Tasks: {status: 'TIMEDOUT'}}
  189. ]
  190. }),
  191. 'h3': Em.Object.create({
  192. status: 'failed',
  193. tasks: [
  194. {Tasks: {status: 'TIMEDOUT'}}
  195. ]
  196. })
  197. },
  198. m: 'only timedout tasks',
  199. e: Em.A([
  200. {st: 'timedout', l: 3}
  201. ])
  202. },
  203. {
  204. hosts: {
  205. 'h1': Em.Object.create({
  206. status: 'failed',
  207. tasks: []
  208. }),
  209. 'h2': Em.Object.create({
  210. status: 'failed',
  211. tasks: []
  212. }),
  213. 'h3': Em.Object.create({
  214. status: 'failed',
  215. tasks: [
  216. {Tasks: {status: 'ABORTED'}},
  217. {Tasks: {status: 'ABORTED'}},
  218. {Tasks: {status: 'ABORTED'}}
  219. ]
  220. })
  221. },
  222. m: 'only aborted tasks',
  223. e: Em.A([
  224. {st: 'aborted', l: 3}
  225. ])
  226. },
  227. {
  228. hosts: {
  229. 'h1': Em.Object.create({
  230. status: 'warning',
  231. tasks: [
  232. {Tasks: {status: 'FAILED'}},
  233. {Tasks: {status: 'FAILED'}}
  234. ]
  235. }),
  236. 'h2': Em.Object.create({
  237. status: 'warning',
  238. tasks: [
  239. {Tasks: {status: 'FAILED'}}
  240. ]
  241. }),
  242. 'h3': Em.Object.create({status: 'warning', tasks: []})
  243. },
  244. m: 'only failed tasks, warning hosts',
  245. e: Em.A([
  246. {st: 'failed', l: 3}
  247. ])
  248. },
  249. {
  250. hosts: {
  251. 'h1': Em.Object.create({
  252. status: 'warning',
  253. tasks: [
  254. {Tasks: {status: 'TIMEDOUT'}}
  255. ]
  256. }),
  257. 'h2': Em.Object.create({
  258. status: 'warning',
  259. tasks: [
  260. {Tasks: {status: 'TIMEDOUT'}}
  261. ]
  262. }),
  263. 'h3': Em.Object.create({
  264. status: 'warning',
  265. tasks: [
  266. {Tasks: {status: 'TIMEDOUT'}}
  267. ]
  268. })
  269. },
  270. m: 'only timedout tasks, warning hosts',
  271. e: Em.A([
  272. {st: 'timedout', l: 3}
  273. ])
  274. },
  275. {
  276. hosts: {
  277. 'h1': Em.Object.create({
  278. status: 'warning',
  279. tasks: []
  280. }),
  281. 'h2': Em.Object.create({
  282. status: 'warning',
  283. tasks: []
  284. }),
  285. 'h3': Em.Object.create({
  286. status: 'warning',
  287. tasks: [
  288. {Tasks: {status: 'ABORTED'}},
  289. {Tasks: {status: 'ABORTED'}},
  290. {Tasks: {status: 'ABORTED'}}
  291. ]
  292. })
  293. },
  294. m: 'only aborted tasks, warning hosts',
  295. e: Em.A([
  296. {st: 'aborted', l: 3}
  297. ])
  298. }
  299. ]);
  300. testsForFailedTasks.forEach(function(test) {
  301. it(test.m, function() {
  302. controller.set('content.hosts', test.hosts);
  303. controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
  304. controller.loadInstalledHosts();
  305. test.e.forEach(function(ex) {
  306. expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').mapProperty('status', ex.st).length).to.equal(ex.l);
  307. });
  308. })
  309. });
  310. });
  311. describe('#loadMasterComponent', function() {
  312. var tests = Em.A([
  313. {
  314. component: Em.Object.create({hostName: 'h1'}),
  315. e: 1
  316. },
  317. {
  318. component: Em.Object.create({}),
  319. e: 0
  320. }
  321. ]);
  322. tests.forEach(function(test) {
  323. it(test.component.get('hostName') ? 'Has hosNBame' : 'Doesn\'t have hostName', function() {
  324. controller.clearStep();
  325. controller.get('clusterInfo').pushObject(Em.Object.create({id: 2, status: []}));
  326. controller.loadMasterComponent(test.component);
  327. expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(test.e);
  328. })
  329. });
  330. });
  331. describe('#loadStartedServices', function() {
  332. var tests = Em.A([
  333. {
  334. status: 'STARTED',
  335. e: {
  336. ids: [3, 4],
  337. r: true
  338. }
  339. },
  340. {
  341. status: 'FAILED',
  342. e: {
  343. ids: [3],
  344. r: false
  345. }
  346. },
  347. {
  348. status: 'START_SKIPPED',
  349. e: {
  350. ids: [3],
  351. r: false
  352. }
  353. }
  354. ]);
  355. tests.forEach(function(test) {
  356. it(test.status, function() {
  357. controller.set('content', {cluster: {status: test.status}});
  358. var r = controller.loadStartedServices();
  359. expect(r).to.equal(test.e.r);
  360. expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e.ids);
  361. });
  362. });
  363. });
  364. describe('#loadInstallTime', function() {
  365. var tests = Em.A([
  366. {
  367. installTime: 123,
  368. e: [5]
  369. },
  370. {
  371. installTime: null,
  372. e: []
  373. }
  374. ]);
  375. tests.forEach(function(test) {
  376. it('Install time' + test.installTime ? ' available' : ' not available', function() {
  377. controller.set('content', {cluster: {installTime: test.installTime}});
  378. var r = controller.loadInstallTime();
  379. expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e);
  380. });
  381. });
  382. });
  383. describe('#calculateInstallTime', function () {
  384. it('from "9.21" to 9 minutes 12 seconds', function () {
  385. expect(controller.calculateInstallTime('9.21')).to.eql({minutes: 9, seconds: 12});
  386. });
  387. it('from "0" to 0 minutes 0 seconds', function () {
  388. expect(controller.calculateInstallTime('0')).to.eql({minutes: 0, seconds: 0});
  389. });
  390. it('from "10" to 10 minutes 0 seconds', function () {
  391. expect(controller.calculateInstallTime('10')).to.eql({minutes: 10, seconds: 0});
  392. });
  393. it('from "0.5" to 0 minutes 30 seconds', function () {
  394. expect(controller.calculateInstallTime('0.5')).to.eql({minutes: 0, seconds: 30});
  395. });
  396. });
  397. describe('#loadMasterComponents', function() {
  398. var components = Em.A(['NAMENODE','SECONDARY_NAMENODE','JOBTRACKER','HISTORYSERVER','RESOURCEMANAGER','HBASE_MASTER','HIVE_SERVER','OOZIE_SERVER','GANGLIA_SERVER']);
  399. d3.range(1, components.length).forEach(function(i) {
  400. d3.range(1, i).forEach(function(j) {
  401. var c = components.slice(0, j);
  402. it(c.join(', '), function() {
  403. var m = c.map(function(component){return {component: component, displayName: component, hostName: 'h1'};});
  404. controller.set('content.masterComponentHosts', m);
  405. controller.loadMasterComponents();
  406. expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(m.length);
  407. });
  408. });
  409. });
  410. });
  411. describe('#loadRegisteredHosts', function() {
  412. var masterComponentHosts = [{hostName: 'h1'}, {hostName: 'h2'}, {hostName: 'h3'}],
  413. slaveComponentHosts = [{hosts: [{hostName: 'h1'}, {hostName: 'h4'}]}, {hosts: [{hostName: 'h2'}, {hostName: 'h5'}]}],
  414. hosts = [{hostName: 'h6'}, {hostName: 'h3'}, {hostName: 'h7'}];
  415. var obj;
  416. beforeEach(function () {
  417. controller.set('content.masterComponentHosts', masterComponentHosts);
  418. controller.set('content.slaveComponentHosts', slaveComponentHosts);
  419. controller.set('clusterInfo', []);
  420. sinon.stub(App.Host, 'find', function() {
  421. return hosts;
  422. });
  423. obj = controller.loadRegisteredHosts();
  424. });
  425. afterEach(function () {
  426. App.Host.find.restore();
  427. });
  428. it('id = 1', function() {
  429. expect(obj.id).to.equal(1);
  430. });
  431. it('color = text-info', function () {
  432. expect(obj.color).to.equal('text-info');
  433. });
  434. it('displayStatement is valid', function () {
  435. expect(obj.displayStatement).to.equal(Em.I18n.t('installer.step10.hostsSummary').format(7));
  436. });
  437. it('status is []', function () {
  438. expect(obj.status).to.eql([]);
  439. });
  440. it('clusterInfo.firstObject is valid', function () {
  441. expect(controller.get('clusterInfo.firstObject')).to.eql(obj);
  442. });
  443. });
  444. });