step4_test.js 30 KB

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