step4_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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, index){
  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. it(testCase.title, function () {
  150. controller.clear();
  151. for(var id in testCase.condition) {
  152. controller.pushObject(Ember.Object.create({
  153. 'serviceName':id, 'isSelected': testCase.condition[id], 'canBeSelected': true, 'isInstalled': false,
  154. coSelectedServices: function() {
  155. return App.StackService.coSelected[this.get('serviceName')] || [];
  156. }.property('serviceName')
  157. }));
  158. }
  159. controller.setGroupedServices();
  160. for(var service in testCase.result) {
  161. expect(controller.findProperty('serviceName', service).get('isSelected')).to.equal(testCase.result[service]);
  162. }
  163. });
  164. }, this);
  165. });
  166. describe('#addValidationError()', function() {
  167. var tests = [
  168. {
  169. errorObjects: [
  170. {
  171. id: 'serviceCheck_ZOOKEEPER',
  172. shouldBeAdded: true
  173. },
  174. {
  175. id: 'serviceCheck_YARN',
  176. shouldBeAdded: true
  177. }
  178. ],
  179. expectedIds: ['serviceCheck_ZOOKEEPER', 'serviceCheck_YARN']
  180. },
  181. {
  182. errorObjects: [
  183. {
  184. id: 'fsCheck',
  185. shouldBeAdded: true
  186. },
  187. {
  188. id: 'fsCheck',
  189. shouldBeAdded: false
  190. }
  191. ],
  192. expectedIds: ['fsCheck']
  193. }
  194. ];
  195. beforeEach(function() {
  196. controller.clear();
  197. controller.set('errorStack', []);
  198. });
  199. tests.forEach(function(test) {
  200. var message = 'Erorrs {0} thrown. errorStack property should contains ids: {1}'
  201. .format(test.errorObjects.mapProperty('id').join(', '), test.expectedIds.join(', '));
  202. it(message, function() {
  203. test.errorObjects.forEach(function(errorObject) {
  204. expect(controller.addValidationError(errorObject)).to.equal(errorObject.shouldBeAdded);
  205. });
  206. expect(controller.get('errorStack').mapProperty('id')).to.eql(test.expectedIds);
  207. });
  208. })
  209. });
  210. describe('#validate()', function() {
  211. var tests = [
  212. {
  213. services: ['HDFS','ZOOKEEPER'],
  214. errorsExpected: ['ambariMetricsCheck']
  215. },
  216. {
  217. services: ['ZOOKEEPER'],
  218. errorsExpected: ['ambariMetricsCheck']
  219. },
  220. {
  221. services: ['HDFS'],
  222. errorsExpected: ['serviceCheck_ZOOKEEPER', 'ambariMetricsCheck']
  223. },
  224. {
  225. services: ['HDFS', 'TEZ', 'ZOOKEEPER'],
  226. errorsExpected: ['serviceCheck_YARN', 'ambariMetricsCheck']
  227. },
  228. {
  229. services: ['HDFS', 'ZOOKEEPER', 'FALCON'],
  230. errorsExpected: ['serviceCheck_OOZIE', 'ambariMetricsCheck']
  231. },
  232. {
  233. services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'HIVE'],
  234. errorsExpected: ['serviceCheck_YARN', 'ambariMetricsCheck']
  235. },
  236. {
  237. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  238. errorsExpected: ['serviceCheck_YARN', 'multipleDFS', 'ambariMetricsCheck']
  239. },
  240. {
  241. services: ['HDFS','ZOOKEEPER', 'GANGLIA'],
  242. errorsExpected: ['ambariMetricsCheck']
  243. },
  244. {
  245. services: ['HDFS','ZOOKEEPER', 'AMBARI_METRICS'],
  246. errorsExpected: []
  247. },
  248. {
  249. services: ['ZOOKEEPER', 'AMBARI_METRICS'],
  250. errorsExpected: []
  251. },
  252. {
  253. services: ['HDFS', 'AMBARI_METRICS'],
  254. errorsExpected: ['serviceCheck_ZOOKEEPER']
  255. },
  256. {
  257. services: ['HDFS', 'TEZ', 'ZOOKEEPER', 'AMBARI_METRICS'],
  258. errorsExpected: ['serviceCheck_YARN']
  259. },
  260. {
  261. services: ['HDFS', 'ZOOKEEPER', 'FALCON', 'AMBARI_METRICS'],
  262. errorsExpected: ['serviceCheck_OOZIE']
  263. },
  264. {
  265. services: ['HDFS', 'ZOOKEEPER', 'GANGLIA', 'HIVE', 'AMBARI_METRICS'],
  266. errorsExpected: ['serviceCheck_YARN']
  267. },
  268. {
  269. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE', 'AMBARI_METRICS'],
  270. errorsExpected: ['serviceCheck_YARN', 'multipleDFS']
  271. },
  272. {
  273. services: ['HDFS','ZOOKEEPER', 'GANGLIA', 'AMBARI_METRICS'],
  274. errorsExpected: []
  275. },
  276. {
  277. services: ['RANGER'],
  278. errorsExpected: ['ambariMetricsCheck', 'rangerRequirements']
  279. }
  280. ],
  281. controllerNames = ['installerController', 'addServiceController'],
  282. wizardNames = {
  283. installerController: 'Install Wizard',
  284. addServiceController: 'Add Service Wizard'
  285. },
  286. sparkCases = [
  287. {
  288. currentStackName: 'HDP',
  289. currentStackVersionNumber: '2.2',
  290. sparkWarningExpected: true,
  291. title: 'HDP 2.2'
  292. },
  293. {
  294. currentStackName: 'HDP',
  295. currentStackVersionNumber: '2.3',
  296. sparkWarningExpected: false,
  297. title: 'HDP 2.3'
  298. },
  299. {
  300. currentStackName: 'BIGTOP',
  301. currentStackVersionNumber: '0.8',
  302. sparkWarningExpected: false,
  303. title: 'Non-HDP stack'
  304. }
  305. ];
  306. beforeEach(function () {
  307. controller.clear();
  308. });
  309. controllerNames.forEach(function (name) {
  310. tests.forEach(function(test) {
  311. var errorsExpected = test.errorsExpected;
  312. if (name != 'installerController') {
  313. errorsExpected = test.errorsExpected.without('ambariMetricsCheck');
  314. }
  315. var message = '{0}, {1} selected validation should be {2}, errors: {3}'
  316. .format(wizardNames[name], test.services.join(','), errorsExpected.length ? 'passed' : 'failed',
  317. errorsExpected.length ? errorsExpected.join(',') : 'absent');
  318. it(message, function() {
  319. controller.setProperties({
  320. content: generateSelectedServicesContent(test.services),
  321. errorStack: [],
  322. wizardController: Em.Object.create({
  323. name: name
  324. })
  325. });
  326. controller.validate();
  327. expect(controller.get('errorStack').mapProperty('id')).to.eql(errorsExpected.toArray());
  328. });
  329. })
  330. });
  331. sparkCases.forEach(function (item) {
  332. describe(item.title, function () {
  333. beforeEach(function () {
  334. sinon.stub(App, 'get').withArgs('currentStackName').returns(item.currentStackName).
  335. withArgs('currentStackVersionNumber').returns(item.currentStackVersionNumber);
  336. controller.set('errorStack', []);
  337. controller.set('content', generateSelectedServicesContent(['SPARK']));
  338. controller.validate();
  339. });
  340. afterEach(function () {
  341. App.get.restore();
  342. });
  343. it('sparkWarning ' + (item.sparkWarningExpected ? 'exists' : 'not exists'), function () {
  344. expect(controller.get('errorStack').someProperty('id', 'sparkWarning')).to.equal(item.sparkWarningExpected);
  345. });
  346. });
  347. });
  348. });
  349. describe('#onPrimaryPopupCallback()', function() {
  350. var c;
  351. var tests = [
  352. {
  353. services: ['HDFS','ZOOKEEPER'],
  354. confirmPopupCount: 0,
  355. errorsExpected: []
  356. },
  357. {
  358. services: ['ZOOKEEPER'],
  359. confirmPopupCount: 0,
  360. errorsExpected: []
  361. },
  362. {
  363. services: ['HDFS', 'GLUSTERFS', 'ZOOKEEPER', 'HIVE'],
  364. confirmPopupCount: 2,
  365. errorsExpected: ['serviceCheck_YARN', 'serviceCheck_TEZ', 'multipleDFS']
  366. },
  367. {
  368. services: ['HDFS','ZOOKEEPER', 'GANGLIA'],
  369. confirmPopupCount: 0,
  370. errorsExpected: []
  371. }
  372. ];
  373. beforeEach(function() {
  374. c = App.WizardStep4Controller.create({});
  375. sinon.stub(App.router, 'send', Em.K);
  376. sinon.stub(c, 'submit', Em.K);
  377. sinon.spy(c, 'onPrimaryPopupCallback');
  378. });
  379. afterEach(function() {
  380. App.router.send.restore();
  381. c.submit.restore();
  382. c.onPrimaryPopupCallback.restore();
  383. });
  384. tests.forEach(function(test) {
  385. var message = 'Selected services: {0}. {1} errors should be confirmed'
  386. .format(test.services.join(', '), test.confirmPopupCount);
  387. describe(message, function() {
  388. var runValidations = function() {
  389. c.serviceDependencyValidation();
  390. c.fileSystemServiceValidation();
  391. };
  392. beforeEach(function () {
  393. c.set('content', generateSelectedServicesContent(test.services));
  394. runValidations();
  395. });
  396. it('errors count validation', function () {
  397. expect(c.get('errorStack.length')).to.equal(test.confirmPopupCount);
  398. });
  399. if (test.errorsExpected) {
  400. it('if errors detected than it should be shown', function () {
  401. test.errorsExpected.forEach(function(error, index, errors) {
  402. // validate current error
  403. var currentErrorObject = c.get('errorStack').findProperty('isShown', false);
  404. if (currentErrorObject) {
  405. expect(test.errorsExpected).to.contain(currentErrorObject.id);
  406. // show current error
  407. var popup = c.showError(currentErrorObject);
  408. // submit popup
  409. popup.onPrimary();
  410. // onPrimaryPopupCallback should be called
  411. expect(c.onPrimaryPopupCallback.called).to.equal(true);
  412. // submit called
  413. expect(c.submit.called).to.equal(true);
  414. if (c.get('errorStack').length) {
  415. // current error isShown flag changed to true
  416. expect(currentErrorObject.isShown).to.equal(true);
  417. }
  418. runValidations();
  419. }
  420. });
  421. });
  422. }
  423. });
  424. });
  425. });
  426. describe('#needToAddServicePopup', function() {
  427. beforeEach(function () {
  428. sinon.stub(controller, 'submit', Em.K);
  429. });
  430. afterEach(function () {
  431. controller.submit.restore();
  432. });
  433. Em.A([
  434. {
  435. m: 'one service',
  436. services: {selected: true, serviceName: 's1'},
  437. content: [Em.Object.create({serviceName: 's1', isSelected: false})],
  438. e: [true]
  439. },
  440. {
  441. m: 'many services',
  442. services: [{selected: true, serviceName: 's1'}, {selected: false, serviceName: 's2'}],
  443. content: [Em.Object.create({serviceName: 's1', isSelected: false}),
  444. Em.Object.create({serviceName: 's2', isSelected: true})],
  445. e: [true, false]
  446. }
  447. ]).forEach(function (test) {
  448. it(test.m, function () {
  449. controller.set('content', test.content);
  450. controller.needToAddServicePopup(test.services, '').onPrimary();
  451. expect(controller.submit.calledOnce).to.equal(true);
  452. expect(controller.mapProperty('isSelected')).to.eql(test.e);
  453. });
  454. });
  455. });
  456. describe('#submit', function() {
  457. var c;
  458. var tests = [
  459. {
  460. isSubmitDisabled: true,
  461. validate: false,
  462. userCanProceed: false
  463. },
  464. {
  465. isSubmitDisabled: false,
  466. validate: false,
  467. userCanProceed: false
  468. },
  469. {
  470. isSubmitDisabled: false,
  471. validate: true,
  472. userCanProceed: true
  473. }
  474. ];
  475. beforeEach(function() {
  476. c = App.WizardStep4Controller.create();
  477. sinon.stub(App.router, 'send', Em.K);
  478. });
  479. afterEach(function() {
  480. App.router.send.restore();
  481. });
  482. tests.forEach(function(test) {
  483. var messageFormat = [
  484. test.isSubmitDisabled ? 'disabled' : 'enabled',
  485. test.validate ? 'success' : 'failed',
  486. test.userCanProceed ? '' : 'not'
  487. ];
  488. var message = String.prototype.format.apply('Submit btn: {0}. Validation: {1}. Can{2} move to the next step.', messageFormat);
  489. it(message, function() {
  490. c.reopen({
  491. isSubmitDisabled: test.isSubmitDisabled,
  492. validate: function() { return test.validate; }
  493. });
  494. c.clear();
  495. c.submit();
  496. expect(App.router.send.calledOnce).to.equal(test.userCanProceed);
  497. });
  498. })
  499. });
  500. describe('#dependencies', function() {
  501. var tests = [
  502. {
  503. services: ['HDFS'],
  504. dependencies: ['ZOOKEEPER']
  505. },
  506. {
  507. services: ['STORM'],
  508. dependencies: ['ZOOKEEPER']
  509. }
  510. ];
  511. tests.forEach(function(test) {
  512. var message = '{0} dependency should be {1}'.format(test.services.join(','), test.dependencies.join(','));
  513. it(message, function() {
  514. controller.clear();
  515. controller.set('content', generateSelectedServicesContent(test.services));
  516. var dependentServicesTest = [];
  517. test.services.forEach(function(serviceName) {
  518. var service = controller.filterProperty('serviceName', serviceName);
  519. service.forEach(function(item) {
  520. var dependencies = item.get('requiredServices');
  521. if(!!dependencies) {
  522. dependentServicesTest = dependentServicesTest.concat(dependencies);
  523. }
  524. });
  525. });
  526. expect(dependentServicesTest).to.be.eql(test.dependencies);
  527. });
  528. })
  529. });
  530. describe('#ambariMetricsValidation', function () {
  531. var cases = [
  532. {
  533. services: ['HDFS'],
  534. isAmbariMetricsWarning: false,
  535. title: 'Ambari Metrics not available'
  536. },
  537. {
  538. services: ['AMBARI_METRICS'],
  539. isAmbariMetricsSelected: false,
  540. isAmbariMetricsWarning: true,
  541. title: 'Ambari Metrics not selected'
  542. },
  543. {
  544. services: ['AMBARI_METRICS'],
  545. isAmbariMetricsSelected: true,
  546. isAmbariMetricsWarning: false,
  547. title: 'Ambari Metrics selected'
  548. }
  549. ];
  550. beforeEach(function() {
  551. controller.clear();
  552. controller.set('errorStack', []);
  553. });
  554. cases.forEach(function (item) {
  555. it(item.title, function () {
  556. controller.set('content', generateSelectedServicesContent(item.services));
  557. var ams = controller.findProperty('serviceName', 'AMBARI_METRICS');
  558. if (item.services.contains('AMBARI_METRICS')) {
  559. ams.set('isSelected', item.isAmbariMetricsSelected);
  560. } else {
  561. controller.removeObject(ams);
  562. }
  563. controller.ambariMetricsValidation();
  564. expect(controller.get('errorStack').mapProperty('id').contains('ambariMetricsCheck')).to.equal(item.isAmbariMetricsWarning);
  565. });
  566. });
  567. });
  568. describe('#rangerValidation', function () {
  569. var cases = [
  570. {
  571. services: ['HDFS'],
  572. isRangerWarning: false,
  573. title: 'Ranger not available'
  574. },
  575. {
  576. services: ['RANGER'],
  577. isRangerSelected: false,
  578. isRangerInstalled: false,
  579. isRangerWarning: false,
  580. title: 'Ranger not selected'
  581. },
  582. {
  583. services: ['RANGER'],
  584. isRangerSelected: true,
  585. isRangerInstalled: false,
  586. isRangerWarning: true,
  587. title: 'Ranger selected'
  588. },
  589. {
  590. services: ['RANGER'],
  591. isRangerSelected: true,
  592. isRangerInstalled: true,
  593. isRangerWarning: false,
  594. title: 'Ranger installed'
  595. }
  596. ];
  597. beforeEach(function() {
  598. controller.clear();
  599. controller.set('errorStack', []);
  600. });
  601. cases.forEach(function (item) {
  602. it(item.title, function () {
  603. controller.set('content', generateSelectedServicesContent(item.services));
  604. var ranger = controller.findProperty('serviceName', 'RANGER');
  605. if (item.services.contains('RANGER')) {
  606. ranger.setProperties({
  607. isSelected: item.isRangerSelected,
  608. isInstalled: item.isRangerInstalled
  609. });
  610. } else {
  611. controller.removeObject(ranger);
  612. }
  613. controller.rangerValidation();
  614. expect(controller.get('errorStack').mapProperty('id').contains('rangerRequirements')).to.equal(item.isRangerWarning);
  615. });
  616. });
  617. });
  618. describe('#sparkValidation', function () {
  619. var cases = [
  620. {
  621. services: ['HDFS'],
  622. isSparkWarning: false,
  623. currentStackName: 'HDP',
  624. currentStackVersionNumber: '2.2',
  625. title: 'HDP 2.2, Spark not available'
  626. },
  627. {
  628. services: ['HDFS'],
  629. isSparkWarning: false,
  630. currentStackName: 'HDP',
  631. currentStackVersionNumber: '2.3',
  632. title: 'HDP 2.3, Spark not available'
  633. },
  634. {
  635. services: ['HDFS'],
  636. isSparkWarning: false,
  637. currentStackName: 'BIGTOP',
  638. currentStackVersionNumber: '0.8',
  639. title: 'Non-HDP stack, Spark not available'
  640. },
  641. {
  642. services: ['SPARK'],
  643. isSparkSelected: false,
  644. isSparkInstalled: false,
  645. isSparkWarning: false,
  646. currentStackName: 'HDP',
  647. currentStackVersionNumber: '2.2',
  648. title: 'HDP 2.2, Spark not selected'
  649. },
  650. {
  651. services: ['SPARK'],
  652. isSparkSelected: true,
  653. isSparkInstalled: false,
  654. isSparkWarning: true,
  655. currentStackName: 'HDP',
  656. currentStackVersionNumber: '2.2',
  657. title: 'HDP 2.2, Spark selected'
  658. },
  659. {
  660. services: ['SPARK'],
  661. isSparkSelected: true,
  662. isSparkInstalled: true,
  663. isSparkWarning: false,
  664. currentStackName: 'HDP',
  665. currentStackVersionNumber: '2.2',
  666. title: 'HDP 2.2, Spark installed'
  667. },
  668. {
  669. services: ['SPARK'],
  670. isSparkSelected: false,
  671. isSparkInstalled: false,
  672. isSparkWarning: false,
  673. currentStackName: 'HDP',
  674. currentStackVersionNumber: '2.3',
  675. title: 'HDP 2.3, Spark not selected'
  676. },
  677. {
  678. services: ['SPARK'],
  679. isSparkSelected: true,
  680. isSparkInstalled: false,
  681. isSparkWarning: false,
  682. currentStackName: 'HDP',
  683. currentStackVersionNumber: '2.3',
  684. title: 'HDP 2.3, Spark selected'
  685. },
  686. {
  687. services: ['SPARK'],
  688. isSparkSelected: true,
  689. isSparkInstalled: true,
  690. isSparkWarning: false,
  691. currentStackName: 'HDP',
  692. currentStackVersionNumber: '2.3',
  693. title: 'HDP 2.3, Spark installed'
  694. },
  695. {
  696. services: ['SPARK'],
  697. isSparkSelected: false,
  698. isSparkInstalled: false,
  699. isSparkWarning: false,
  700. currentStackName: 'BIGTOP',
  701. currentStackVersionNumber: '0.8',
  702. title: 'Non-HDP stack, Spark not selected'
  703. },
  704. {
  705. services: ['SPARK'],
  706. isSparkSelected: true,
  707. isSparkInstalled: false,
  708. isSparkWarning: false,
  709. currentStackName: 'BIGTOP',
  710. currentStackVersionNumber: '0.8',
  711. title: 'Non-HDP stack, Spark selected'
  712. },
  713. {
  714. services: ['SPARK'],
  715. isSparkSelected: true,
  716. isSparkInstalled: true,
  717. isSparkWarning: false,
  718. currentStackName: 'BIGTOP',
  719. currentStackVersionNumber: '0.8',
  720. title: 'Non-HDP stack, Spark installed'
  721. }
  722. ];
  723. beforeEach(function() {
  724. controller.clear();
  725. controller.set('errorStack', []);
  726. this.stub = sinon.stub(App, 'get');
  727. });
  728. afterEach(function () {
  729. App.get.restore();
  730. });
  731. cases.forEach(function (item) {
  732. it(item.title, function () {
  733. this.stub.withArgs('currentStackName').returns(item.currentStackName).
  734. withArgs('currentStackVersionNumber').returns(item.currentStackVersionNumber);
  735. controller.set('content', generateSelectedServicesContent(item.services));
  736. var spark = controller.findProperty('serviceName', 'SPARK');
  737. if (item.services.contains('SPARK')) {
  738. spark.setProperties({
  739. isSelected: item.isSparkSelected,
  740. isInstalled: item.isSparkInstalled
  741. });
  742. } else {
  743. controller.removeObject(spark);
  744. }
  745. controller.sparkValidation();
  746. expect(controller.get('errorStack').mapProperty('id').contains('sparkWarning')).to.equal(item.isSparkWarning);
  747. });
  748. });
  749. });
  750. describe('#clearErrors', function () {
  751. var cases = [
  752. {
  753. errorStack: [{
  754. isAccepted: false
  755. }],
  756. resultingErrorStack: [{
  757. isAccepted: false
  758. }],
  759. title: 'error stack shouldn\'t be cleared during validation'
  760. },
  761. {
  762. errorStack: [{
  763. isAccepted: true
  764. }],
  765. resultingErrorStack: [],
  766. title: 'error stack should be cleared'
  767. }
  768. ];
  769. beforeEach(function () {
  770. controller.set('errorStack', [{}]);
  771. });
  772. cases.forEach(function (item) {
  773. it(item.title, function () {
  774. controller.set('errorStack', item.errorStack);
  775. controller.propertyDidChange('@each.isSelected');
  776. expect(controller.get('errorStack')).to.eql(item.resultingErrorStack);
  777. });
  778. });
  779. });
  780. });