step10_test.js 14 KB

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