step10_test.js 15 KB

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