step4_test.js 28 KB

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