step4_test.js 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954
  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. var modelSetup = require('test/init_model_test');
  21. require('controllers/wizard/step4_controller');
  22. describe('App.WizardStep4Controller', function () {
  23. var services = [
  24. 'HDFS', 'GANGLIA', 'OOZIE', 'HIVE', 'HBASE', 'PIG', 'SCOOP', 'ZOOKEEPER',
  25. 'YARN', 'MAPREDUCE2', 'FALCON', 'TEZ', 'STORM', 'AMBARI_METRICS', 'RANGER', 'SPARK'
  26. ];
  27. var controller = App.WizardStep4Controller.create();
  28. var generateSelectedServicesContent = function(selectedServiceNames) {
  29. var allServices = services.slice(0);
  30. modelSetup.setupStackServiceComponent();
  31. if (selectedServiceNames.contains('GLUSTERFS')) allServices.push('GLUSTERFS');
  32. allServices = allServices.map(function(serviceName) {
  33. return [Ember.Object.create({
  34. 'serviceName': serviceName,
  35. 'isSelected': false,
  36. 'canBeSelected': true,
  37. 'isInstalled': false,
  38. isPrimaryDFS: serviceName === 'HDFS',
  39. isDFS: ['HDFS','GLUSTERFS'].contains(serviceName),
  40. isMonitoringService: ['GANGLIA'].contains(serviceName),
  41. requiredServices: App.StackService.find(serviceName).get('requiredServices'),
  42. displayNameOnSelectServicePage: App.format.role(serviceName),
  43. coSelectedServices: function() {
  44. return App.StackService.coSelected[this.get('serviceName')] || [];
  45. }.property('serviceName')
  46. })];
  47. }).reduce(function(current, prev) { return current.concat(prev); });
  48. selectedServiceNames.forEach(function(serviceName) {
  49. allServices.findProperty('serviceName', serviceName).set('isSelected', true);
  50. });
  51. return allServices;
  52. };
  53. services.forEach(function(serviceName) {
  54. controller.pushObject(Ember.Object.create({
  55. 'serviceName':serviceName, 'isSelected': true, 'isHiddenOnSelectServicePage': false, 'isInstalled': false, 'isDisabled': 'HDFS' === serviceName, isDFS: 'HDFS' === serviceName
  56. }));
  57. });
  58. describe('#isSubmitDisabled', function () {
  59. it('should return false if at least one selected service is not installed', function () {
  60. expect(controller.get('isSubmitDisabled')).to.equal(false);
  61. });
  62. it('should return true if all selected services are already installed', function () {
  63. controller.setEach('isInstalled', true);
  64. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  65. expect(controller.get('isSubmitDisabled')).to.equal(true);
  66. });
  67. });
  68. describe('#isAllChecked', function () {
  69. it('should return true if all services are selected', function () {
  70. controller.setEach('isInstalled', false);
  71. controller.findProperty('serviceName', 'HDFS').set('isSelected', true);
  72. expect(controller.get('isAllChecked')).to.equal(true);
  73. });
  74. it('should return false if at least one service is not selected', function () {
  75. controller.findProperty('serviceName', 'HDFS').set('isSelected', false);
  76. expect(controller.get('isAllChecked')).to.equal(false);
  77. });
  78. });
  79. describe('#multipleDFSs()', function () {
  80. it('should return true if HDFS is selected and GLUSTERFS is selected', function () {
  81. controller.set('content', generateSelectedServicesContent(['HDFS', 'GLUSTERFS']));
  82. expect(controller.multipleDFSs()).to.equal(true);
  83. });
  84. it('should return false if HDFS is not selected and GLUSTERFS is selected', function () {
  85. controller.set('content', generateSelectedServicesContent(['GLUSTERFS']));
  86. expect(controller.multipleDFSs()).to.equal(false);
  87. });
  88. it('should return false if HDFS is selected and GLUSTERFS is not selected', function () {
  89. controller.set('content', generateSelectedServicesContent(['HDFS']));
  90. expect(controller.multipleDFSs()).to.equal(false);
  91. });
  92. });
  93. describe('#setGroupedServices()', function () {
  94. var testCases = [
  95. {
  96. title: 'should set MapReduce2 isSelected to true when YARN is selected',
  97. condition: {
  98. 'YARN': true,
  99. 'HBASE': true,
  100. 'ZOOKEEPER': true,
  101. 'HIVE': true,
  102. 'MAPREDUCE2': true
  103. },
  104. result: {
  105. 'MAPREDUCE2': true
  106. }
  107. },
  108. {
  109. title: 'should set MapReduce2 isSelected to false when YARN is not selected',
  110. condition: {
  111. 'YARN': false,
  112. 'HBASE': true,
  113. 'ZOOKEEPER': true,
  114. 'HIVE': false,
  115. 'MAPREDUCE2': true
  116. },
  117. result: {
  118. 'MAPREDUCE2': false
  119. }
  120. },
  121. {
  122. title: 'should set MAPREDUCE2 isSelected to true when YARN is selected',
  123. condition: {
  124. 'HBASE': true,
  125. 'ZOOKEEPER': true,
  126. 'HIVE': false,
  127. 'YARN': true,
  128. 'MAPREDUCE2': true
  129. },
  130. result: {
  131. 'MAPREDUCE2': true
  132. }
  133. },
  134. {
  135. title: 'should set MAPREDUCE2 isSelected to false when YARN is not selected',
  136. condition: {
  137. 'HBASE': true,
  138. 'ZOOKEEPER': true,
  139. 'HIVE': true,
  140. 'YARN': false,
  141. 'MAPREDUCE2': true
  142. },
  143. result: {
  144. 'MAPREDUCE2': false
  145. }
  146. }
  147. ];
  148. testCases.forEach(function(testCase){
  149. describe(testCase.title, function () {
  150. beforeEach(function () {
  151. controller.clear();
  152. Object.keys(testCase.condition).forEach(function (id) {
  153. controller.pushObject(Ember.Object.create({
  154. serviceName: id,
  155. isSelected: testCase.condition[id],
  156. canBeSelected: true,
  157. isInstalled: false,
  158. coSelectedServices: function() {
  159. return App.StackService.coSelected[this.get('serviceName')] || [];
  160. }.property('serviceName')
  161. }));
  162. });
  163. controller.setGroupedServices();
  164. });
  165. Object.keys(testCase.result).forEach(function (service) {
  166. it(service, function () {
  167. expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
  168. });
  169. });
  170. });
  171. }, this);
  172. });
  173. describe('#addValidationError()', function() {
  174. var tests = [
  175. {
  176. errorObjects: [
  177. {
  178. id: 'serviceCheck_ZOOKEEPER',
  179. shouldBeAdded: true
  180. },
  181. {
  182. id: 'serviceCheck_YARN',
  183. shouldBeAdded: true
  184. }
  185. ],
  186. expectedIds: ['serviceCheck_ZOOKEEPER', 'serviceCheck_YARN']
  187. },
  188. {
  189. errorObjects: [
  190. {
  191. id: 'fsCheck',
  192. shouldBeAdded: true
  193. },
  194. {
  195. id: 'fsCheck',
  196. shouldBeAdded: false
  197. }
  198. ],
  199. expectedIds: ['fsCheck']
  200. }
  201. ];
  202. beforeEach(function() {
  203. controller.clear();
  204. controller.set('errorStack', []);
  205. });
  206. tests.forEach(function(test) {
  207. var message = 'Erorrs {0} thrown. errorStack property should contains ids: {1}'
  208. .format(test.errorObjects.mapProperty('id').join(', '), test.expectedIds.join(', '));
  209. describe(message, function() {
  210. beforeEach(function () {
  211. this.added = [];
  212. test.errorObjects.forEach(function(errorObject) {
  213. this.added.push(controller.addValidationError(errorObject));
  214. }, this);
  215. });
  216. it('shouldBeAdded', function() {
  217. expect(this.added).to.be.eql(test.errorObjects.mapProperty('shouldBeAdded'));
  218. });
  219. it('expectedIds', function() {
  220. expect(controller.get('errorStack').mapProperty('id')).to.eql(test.expectedIds);
  221. });
  222. });
  223. })
  224. });
  225. describe('#validate()', function() {
  226. var tests = [
  227. {
  228. services: ['HDFS','ZOOKEEPER'],
  229. errorsExpected: ['ambariMetricsCheck']
  230. },
  231. {
  232. services: ['ZOOKEEPER'],
  233. errorsExpected: ['ambariMetricsCheck']
  234. },
  235. {
  236. services: ['HDFS'],
  237. errorsExpected: ['serviceCheck_ZOOKEEPER', 'ambariMetricsCheck']
  238. },
  239. {
  240. services: ['HDFS', 'TEZ', 'ZOOKEEPER'],
  241. errorsExpected: ['serviceCheck_YARN', 'ambariMetricsCheck']
  242. },
  243. {
  244. services: ['HDFS', 'ZOOKEEPER', 'FALCON'],
  245. errorsExpected: ['serviceCheck_OOZIE', 'ambariMetricsCheck']
  246. },
  247. {
  248. services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'HIVE'],
  249. errorsExpected: ['serviceCheck_YARN', 'ambariMetricsCheck']
  250. },
  251. {
  252. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  253. errorsExpected: ['serviceCheck_YARN', 'multipleDFS', 'ambariMetricsCheck']
  254. },
  255. {
  256. services: ['HDFS','ZOOKEEPER', 'GANGLIA'],
  257. errorsExpected: ['ambariMetricsCheck']
  258. },
  259. {
  260. services: ['HDFS','ZOOKEEPER', 'AMBARI_METRICS'],
  261. errorsExpected: []
  262. },
  263. {
  264. services: ['ZOOKEEPER', 'AMBARI_METRICS'],
  265. errorsExpected: []
  266. },
  267. {
  268. services: ['HDFS', 'AMBARI_METRICS'],
  269. errorsExpected: ['serviceCheck_ZOOKEEPER']
  270. },
  271. {
  272. services: ['HDFS', 'TEZ', 'ZOOKEEPER', 'AMBARI_METRICS'],
  273. errorsExpected: ['serviceCheck_YARN']
  274. },
  275. {
  276. services: ['HDFS', 'ZOOKEEPER', 'FALCON', 'AMBARI_METRICS'],
  277. errorsExpected: ['serviceCheck_OOZIE']
  278. },
  279. {
  280. services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'HIVE', 'AMBARI_METRICS'],
  281. errorsExpected: ['serviceCheck_YARN']
  282. },
  283. {
  284. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE', 'AMBARI_METRICS'],
  285. errorsExpected: ['serviceCheck_YARN', 'multipleDFS']
  286. },
  287. {
  288. services: ['HDFS','ZOOKEEPER', 'GANGLIA', 'AMBARI_METRICS'],
  289. errorsExpected: []
  290. },
  291. {
  292. services: ['RANGER'],
  293. errorsExpected: ['ambariMetricsCheck', 'rangerRequirements']
  294. }
  295. ],
  296. controllerNames = ['installerController', 'addServiceController'],
  297. wizardNames = {
  298. installerController: 'Install Wizard',
  299. addServiceController: 'Add Service Wizard'
  300. },
  301. sparkCases = [
  302. {
  303. currentStackName: 'HDP',
  304. currentStackVersionNumber: '2.2',
  305. sparkWarningExpected: true,
  306. title: 'HDP 2.2'
  307. },
  308. {
  309. currentStackName: 'HDP',
  310. currentStackVersionNumber: '2.3',
  311. sparkWarningExpected: false,
  312. title: 'HDP 2.3'
  313. },
  314. {
  315. currentStackName: 'BIGTOP',
  316. currentStackVersionNumber: '0.8',
  317. sparkWarningExpected: false,
  318. title: 'Non-HDP stack'
  319. }
  320. ];
  321. beforeEach(function () {
  322. controller.clear();
  323. });
  324. controllerNames.forEach(function (name) {
  325. tests.forEach(function(test) {
  326. var errorsExpected = test.errorsExpected;
  327. if (name !== 'installerController') {
  328. errorsExpected = test.errorsExpected.without('ambariMetricsCheck');
  329. }
  330. var message = '{0}, {1} selected validation should be {2}, errors: {3}'
  331. .format(wizardNames[name], test.services.join(','), errorsExpected.length ? 'passed' : 'failed',
  332. errorsExpected.length ? errorsExpected.join(',') : 'absent');
  333. it(message, function() {
  334. controller.setProperties({
  335. content: generateSelectedServicesContent(test.services),
  336. errorStack: [],
  337. wizardController: Em.Object.create({
  338. name: name
  339. })
  340. });
  341. controller.validate();
  342. expect(controller.get('errorStack').mapProperty('id')).to.eql(errorsExpected.toArray());
  343. });
  344. })
  345. });
  346. sparkCases.forEach(function (item) {
  347. describe(item.title, function () {
  348. beforeEach(function () {
  349. sinon.stub(App, 'get').withArgs('currentStackName').returns(item.currentStackName).
  350. withArgs('currentStackVersionNumber').returns(item.currentStackVersionNumber);
  351. controller.set('errorStack', []);
  352. controller.set('content', generateSelectedServicesContent(['SPARK']));
  353. controller.validate();
  354. });
  355. afterEach(function () {
  356. App.get.restore();
  357. });
  358. it('sparkWarning ' + (item.sparkWarningExpected ? 'exists' : 'not exists'), function () {
  359. expect(controller.get('errorStack').someProperty('id', 'sparkWarning')).to.equal(item.sparkWarningExpected);
  360. });
  361. });
  362. });
  363. });
  364. describe('#onPrimaryPopupCallback()', function() {
  365. var c;
  366. var tests = [
  367. {
  368. services: ['HDFS','ZOOKEEPER'],
  369. confirmPopupCount: 0,
  370. errorsExpected: []
  371. },
  372. {
  373. services: ['ZOOKEEPER'],
  374. confirmPopupCount: 0,
  375. errorsExpected: []
  376. },
  377. {
  378. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  379. confirmPopupCount: 2,
  380. errorsExpected: ['serviceCheck_YARN', 'serviceCheck_TEZ', 'multipleDFS']
  381. },
  382. {
  383. services: ['HDFS','ZOOKEEPER', 'GANGLIA'],
  384. confirmPopupCount: 0,
  385. errorsExpected: []
  386. }
  387. ];
  388. beforeEach(function() {
  389. c = App.WizardStep4Controller.create({});
  390. sinon.stub(App.router, 'send', Em.K);
  391. sinon.stub(c, 'submit', Em.K);
  392. sinon.spy(c, 'onPrimaryPopupCallback');
  393. });
  394. afterEach(function() {
  395. App.router.send.restore();
  396. c.submit.restore();
  397. c.onPrimaryPopupCallback.restore();
  398. });
  399. tests.forEach(function(test) {
  400. var message = 'Selected services: {0}. {1} errors should be confirmed'
  401. .format(test.services.join(', '), test.confirmPopupCount);
  402. describe(message, function() {
  403. var runValidations = function() {
  404. c.serviceDependencyValidation();
  405. c.fileSystemServiceValidation();
  406. };
  407. beforeEach(function () {
  408. c.set('content', generateSelectedServicesContent(test.services));
  409. runValidations();
  410. });
  411. it('errors count validation', function () {
  412. expect(c.get('errorStack.length')).to.equal(test.confirmPopupCount);
  413. });
  414. if (test.errorsExpected) {
  415. describe('if errors detected than it should be shown', function () {
  416. var currentErrorObject;
  417. beforeEach(function () {
  418. currentErrorObject = c.get('errorStack').findProperty('isShown', false);
  419. });
  420. test.errorsExpected.forEach(function(error) {
  421. it(error, function () {
  422. // validate current error
  423. if (currentErrorObject) {
  424. expect(test.errorsExpected).to.contain(currentErrorObject.id);
  425. // show current error
  426. var popup = c.showError(currentErrorObject);
  427. // submit popup
  428. popup.onPrimary();
  429. // onPrimaryPopupCallback should be called
  430. expect(c.onPrimaryPopupCallback.called).to.equal(true);
  431. // submit called
  432. expect(c.submit.called).to.equal(true);
  433. if (c.get('errorStack').length) {
  434. // current error isShown flag changed to true
  435. expect(currentErrorObject.isShown).to.equal(true);
  436. }
  437. runValidations();
  438. }
  439. });
  440. });
  441. });
  442. }
  443. });
  444. });
  445. });
  446. describe('#needToAddServicePopup', function() {
  447. beforeEach(function () {
  448. sinon.stub(controller, 'submit', Em.K);
  449. });
  450. afterEach(function () {
  451. controller.submit.restore();
  452. });
  453. Em.A([
  454. {
  455. m: 'one service',
  456. services: {selected: true, serviceName: 's1'},
  457. content: [Em.Object.create({serviceName: 's1', isSelected: false})],
  458. e: [true]
  459. },
  460. {
  461. m: 'many services',
  462. services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
  463. content: [Em.Object.create({serviceName: 's1', isSelected: false}),
  464. Em.Object.create({serviceName: 's2', isSelected: true})],
  465. e: [true, false]
  466. }
  467. ]).forEach(function (test) {
  468. it(test.m, function () {
  469. controller.set('content', test.content);
  470. controller.needToAddServicePopup(test.services, '').onPrimary();
  471. expect(controller.submit.calledOnce).to.equal(true);
  472. expect(controller.mapProperty('isSelected')).to.eql(test.e);
  473. });
  474. });
  475. });
  476. describe('#submit', function() {
  477. var c;
  478. var tests = [
  479. {
  480. isSubmitDisabled: true,
  481. validate: false,
  482. userCanProceed: false
  483. },
  484. {
  485. isSubmitDisabled: false,
  486. validate: false,
  487. userCanProceed: false
  488. },
  489. {
  490. isSubmitDisabled: false,
  491. validate: true,
  492. userCanProceed: true
  493. }
  494. ];
  495. beforeEach(function() {
  496. c = App.WizardStep4Controller.create();
  497. sinon.stub(App.router, 'send', Em.K);
  498. });
  499. afterEach(function() {
  500. App.router.send.restore();
  501. });
  502. tests.forEach(function(test) {
  503. var messageFormat = [
  504. test.isSubmitDisabled ? 'disabled' : 'enabled',
  505. test.validate ? 'success' : 'failed',
  506. test.userCanProceed ? '' : 'not'
  507. ];
  508. var message = String.prototype.format.apply('Submit btn: {0}. Validation: {1}. Can{2} move to the next step.', messageFormat);
  509. it(message, function() {
  510. c.reopen({
  511. isSubmitDisabled: test.isSubmitDisabled,
  512. validate: function() { return test.validate; }
  513. });
  514. c.clear();
  515. c.submit();
  516. expect(App.router.send.calledOnce).to.equal(test.userCanProceed);
  517. });
  518. })
  519. });
  520. describe('#submit for Next click', function() {
  521. var c;
  522. beforeEach(function(){
  523. c = App.WizardStep4Controller.create();
  524. sinon.stub(App.router, 'send', Em.K);
  525. App.router.nextBtnClickInProgress = false;
  526. });
  527. afterEach(function(){
  528. App.router.nextBtnClickInProgress = false;
  529. App.router.send.restore();
  530. });
  531. it('if Next button is clicked multiple times before the next step renders, it must not be processed',function(){
  532. c.reopen({isSubmitDisabled:false});
  533. c.submit();
  534. expect(App.router.send.calledWith('next')).to.equal(true);
  535. App.router.send.reset();
  536. c.submit();
  537. expect(App.router.send.calledWith('next')).to.equal(false);
  538. });
  539. });
  540. describe('#dependencies', function() {
  541. var tests = [
  542. {
  543. services: ['HDFS'],
  544. dependencies: ['ZOOKEEPER']
  545. },
  546. {
  547. services: ['STORM'],
  548. dependencies: ['ZOOKEEPER']
  549. }
  550. ];
  551. tests.forEach(function(test) {
  552. var message = '{0} dependency should be {1}'.format(test.services.join(','), test.dependencies.join(','));
  553. it(message, function() {
  554. controller.clear();
  555. controller.set('content', generateSelectedServicesContent(test.services));
  556. var dependentServicesTest = [];
  557. test.services.forEach(function(serviceName) {
  558. var service = controller.filterProperty('serviceName', serviceName);
  559. service.forEach(function(item) {
  560. var dependencies = item.get('requiredServices');
  561. if(!!dependencies) {
  562. dependentServicesTest = dependentServicesTest.concat(dependencies);
  563. }
  564. });
  565. });
  566. expect(dependentServicesTest).to.be.eql(test.dependencies);
  567. });
  568. })
  569. });
  570. describe('#ambariMetricsValidation', function () {
  571. var cases = [
  572. {
  573. services: ['HDFS'],
  574. isAmbariMetricsWarning: false,
  575. title: 'Ambari Metrics not available'
  576. },
  577. {
  578. services: ['AMBARI_METRICS'],
  579. isAmbariMetricsSelected: false,
  580. isAmbariMetricsWarning: true,
  581. title: 'Ambari Metrics not selected'
  582. },
  583. {
  584. services: ['AMBARI_METRICS'],
  585. isAmbariMetricsSelected: true,
  586. isAmbariMetricsWarning: false,
  587. title: 'Ambari Metrics selected'
  588. }
  589. ];
  590. beforeEach(function() {
  591. controller.clear();
  592. controller.set('errorStack', []);
  593. });
  594. cases.forEach(function (item) {
  595. it(item.title, function () {
  596. controller.set('content', generateSelectedServicesContent(item.services));
  597. var ams = controller.findProperty('serviceName', 'AMBARI_METRICS');
  598. if (item.services.contains('AMBARI_METRICS')) {
  599. ams.set('isSelected', item.isAmbariMetricsSelected);
  600. } else {
  601. controller.removeObject(ams);
  602. }
  603. controller.ambariMetricsValidation();
  604. expect(controller.get('errorStack').mapProperty('id').contains('ambariMetricsCheck')).to.equal(item.isAmbariMetricsWarning);
  605. });
  606. });
  607. });
  608. describe('#rangerValidation', function () {
  609. var cases = [
  610. {
  611. services: ['HDFS'],
  612. isRangerWarning: false,
  613. title: 'Ranger not available'
  614. },
  615. {
  616. services: ['RANGER'],
  617. isRangerSelected: false,
  618. isRangerInstalled: false,
  619. isRangerWarning: false,
  620. title: 'Ranger not selected'
  621. },
  622. {
  623. services: ['RANGER'],
  624. isRangerSelected: true,
  625. isRangerInstalled: false,
  626. isRangerWarning: true,
  627. title: 'Ranger selected'
  628. },
  629. {
  630. services: ['RANGER'],
  631. isRangerSelected: true,
  632. isRangerInstalled: true,
  633. isRangerWarning: false,
  634. title: 'Ranger installed'
  635. }
  636. ];
  637. beforeEach(function() {
  638. controller.clear();
  639. controller.set('errorStack', []);
  640. });
  641. cases.forEach(function (item) {
  642. it(item.title, function () {
  643. controller.set('content', generateSelectedServicesContent(item.services));
  644. var ranger = controller.findProperty('serviceName', 'RANGER');
  645. if (item.services.contains('RANGER')) {
  646. ranger.setProperties({
  647. isSelected: item.isRangerSelected,
  648. isInstalled: item.isRangerInstalled
  649. });
  650. } else {
  651. controller.removeObject(ranger);
  652. }
  653. controller.rangerValidation();
  654. expect(controller.get('errorStack').mapProperty('id').contains('rangerRequirements')).to.equal(item.isRangerWarning);
  655. });
  656. });
  657. });
  658. describe('#sparkValidation', function () {
  659. var cases = [
  660. {
  661. services: ['HDFS'],
  662. isSparkWarning: false,
  663. currentStackName: 'HDP',
  664. currentStackVersionNumber: '2.2',
  665. title: 'HDP 2.2, Spark not available'
  666. },
  667. {
  668. services: ['HDFS'],
  669. isSparkWarning: false,
  670. currentStackName: 'HDP',
  671. currentStackVersionNumber: '2.3',
  672. title: 'HDP 2.3, Spark not available'
  673. },
  674. {
  675. services: ['HDFS'],
  676. isSparkWarning: false,
  677. currentStackName: 'BIGTOP',
  678. currentStackVersionNumber: '0.8',
  679. title: 'Non-HDP stack, Spark not available'
  680. },
  681. {
  682. services: ['SPARK'],
  683. isSparkSelected: false,
  684. isSparkInstalled: false,
  685. isSparkWarning: false,
  686. currentStackName: 'HDP',
  687. currentStackVersionNumber: '2.2',
  688. title: 'HDP 2.2, Spark not selected'
  689. },
  690. {
  691. services: ['SPARK'],
  692. isSparkSelected: true,
  693. isSparkInstalled: false,
  694. isSparkWarning: true,
  695. currentStackName: 'HDP',
  696. currentStackVersionNumber: '2.2',
  697. title: 'HDP 2.2, Spark selected'
  698. },
  699. {
  700. services: ['SPARK'],
  701. isSparkSelected: true,
  702. isSparkInstalled: true,
  703. isSparkWarning: false,
  704. currentStackName: 'HDP',
  705. currentStackVersionNumber: '2.2',
  706. title: 'HDP 2.2, Spark installed'
  707. },
  708. {
  709. services: ['SPARK'],
  710. isSparkSelected: false,
  711. isSparkInstalled: false,
  712. isSparkWarning: false,
  713. currentStackName: 'HDP',
  714. currentStackVersionNumber: '2.3',
  715. title: 'HDP 2.3, Spark not selected'
  716. },
  717. {
  718. services: ['SPARK'],
  719. isSparkSelected: true,
  720. isSparkInstalled: false,
  721. isSparkWarning: false,
  722. currentStackName: 'HDP',
  723. currentStackVersionNumber: '2.3',
  724. title: 'HDP 2.3, Spark selected'
  725. },
  726. {
  727. services: ['SPARK'],
  728. isSparkSelected: true,
  729. isSparkInstalled: true,
  730. isSparkWarning: false,
  731. currentStackName: 'HDP',
  732. currentStackVersionNumber: '2.3',
  733. title: 'HDP 2.3, Spark installed'
  734. },
  735. {
  736. services: ['SPARK'],
  737. isSparkSelected: false,
  738. isSparkInstalled: false,
  739. isSparkWarning: false,
  740. currentStackName: 'BIGTOP',
  741. currentStackVersionNumber: '0.8',
  742. title: 'Non-HDP stack, Spark not selected'
  743. },
  744. {
  745. services: ['SPARK'],
  746. isSparkSelected: true,
  747. isSparkInstalled: false,
  748. isSparkWarning: false,
  749. currentStackName: 'BIGTOP',
  750. currentStackVersionNumber: '0.8',
  751. title: 'Non-HDP stack, Spark selected'
  752. },
  753. {
  754. services: ['SPARK'],
  755. isSparkSelected: true,
  756. isSparkInstalled: true,
  757. isSparkWarning: false,
  758. currentStackName: 'BIGTOP',
  759. currentStackVersionNumber: '0.8',
  760. title: 'Non-HDP stack, Spark installed'
  761. }
  762. ];
  763. beforeEach(function() {
  764. controller.clear();
  765. controller.set('errorStack', []);
  766. this.stub = sinon.stub(App, 'get');
  767. });
  768. afterEach(function () {
  769. App.get.restore();
  770. });
  771. cases.forEach(function (item) {
  772. describe(item.title, function () {
  773. beforeEach(function () {
  774. this.stub.withArgs('currentStackName').returns(item.currentStackName).
  775. withArgs('currentStackVersionNumber').returns(item.currentStackVersionNumber);
  776. controller.set('content', generateSelectedServicesContent(item.services));
  777. var spark = controller.findProperty('serviceName', 'SPARK');
  778. if (item.services.contains('SPARK')) {
  779. spark.setProperties({
  780. isSelected: item.isSparkSelected,
  781. isInstalled: item.isSparkInstalled
  782. });
  783. } else {
  784. controller.removeObject(spark);
  785. }
  786. controller.sparkValidation();
  787. });
  788. it('sparkWarning is ' + item.sparkWarning, function () {
  789. expect(controller.get('errorStack').mapProperty('id').contains('sparkWarning')).to.equal(item.isSparkWarning);
  790. });
  791. });
  792. });
  793. });
  794. describe('#clearErrors', function () {
  795. var cases = [
  796. {
  797. errorStack: [{
  798. isAccepted: false
  799. }],
  800. resultingErrorStack: [{
  801. isAccepted: false
  802. }],
  803. title: 'error stack shouldn\'t be cleared during validation'
  804. },
  805. {
  806. errorStack: [{
  807. isAccepted: true
  808. }],
  809. resultingErrorStack: [],
  810. title: 'error stack should be cleared'
  811. }
  812. ];
  813. beforeEach(function () {
  814. controller.set('errorStack', [{}]);
  815. });
  816. cases.forEach(function (item) {
  817. it(item.title, function () {
  818. controller.set('errorStack', item.errorStack);
  819. controller.propertyDidChange('@each.isSelected');
  820. expect(controller.get('errorStack')).to.eql(item.resultingErrorStack);
  821. });
  822. });
  823. });
  824. describe('Service warnings popup', function () {
  825. var target = {
  826. clb: Em.K
  827. };
  828. var id = 1;
  829. beforeEach(function () {
  830. sinon.spy(target, 'clb');
  831. sinon.stub(controller, 'onPrimaryPopupCallback', Em.K);
  832. });
  833. afterEach(function () {
  834. target.clb.restore();
  835. controller.onPrimaryPopupCallback.restore();
  836. });
  837. Em.A([
  838. 'ambariMetricsCheckPopup',
  839. 'rangerRequirementsPopup',
  840. 'sparkWarningPopup'
  841. ]).forEach(function (methodName) {
  842. describe('#' + methodName, function () {
  843. beforeEach(function () {
  844. this.popup = controller[methodName](target.clb, id);
  845. });
  846. it('#onPrimary', function () {
  847. this.popup.onPrimary();
  848. expect(controller.onPrimaryPopupCallback.calledWith(target.clb)).to.be.true;
  849. });
  850. it('#onSecondary', function () {
  851. this.popup.onSecondary();
  852. expect(target.clb.calledWith(id)).to.be.true;
  853. });
  854. it('#onClose', function () {
  855. this.popup.onClose();
  856. expect(target.clb.calledWith(id)).to.be.true;
  857. });
  858. });
  859. });
  860. });
  861. });