step7_test.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. var numberUtils = require('utils/number_utils');
  20. require('mixins/common/localStorage');
  21. require('models/config_group');
  22. require('controllers/wizard/step7_controller');
  23. var installerStep7Controller;
  24. describe('App.InstallerStep7Controller', function () {
  25. beforeEach(function () {
  26. sinon.stub(App.config, 'setPreDefinedServiceConfigs', Em.K);
  27. installerStep7Controller = App.WizardStep7Controller.create({
  28. content: {
  29. advancedServiceConfig: [],
  30. serviceConfigProperties: []
  31. }
  32. });
  33. });
  34. afterEach(function() {
  35. App.config.setPreDefinedServiceConfigs.restore();
  36. });
  37. describe('#installedServiceNames', function () {
  38. var tests = Em.A([
  39. {
  40. content: Em.Object.create({
  41. controllerName: 'installerController',
  42. services: Em.A([
  43. Em.Object.create({
  44. isInstalled: true,
  45. serviceName: 'SQOOP'
  46. }),
  47. Em.Object.create({
  48. isInstalled: true,
  49. serviceName: 'HDFS'
  50. })
  51. ])
  52. }),
  53. e: ['SQOOP', 'HDFS'],
  54. m: 'installerController with SQOOP'
  55. },
  56. {
  57. content: Em.Object.create({
  58. controllerName: 'installerController',
  59. services: Em.A([
  60. Em.Object.create({
  61. isInstalled: true,
  62. serviceName: 'HIVE'
  63. }),
  64. Em.Object.create({
  65. isInstalled: true,
  66. serviceName: 'HDFS'
  67. })
  68. ])
  69. }),
  70. e: ['HIVE', 'HDFS'],
  71. m: 'installerController without SQOOP'
  72. },
  73. {
  74. content: Em.Object.create({
  75. controllerName: 'addServiceController',
  76. services: Em.A([
  77. Em.Object.create({
  78. isInstalled: true,
  79. serviceName: 'HIVE'
  80. }),
  81. Em.Object.create({
  82. isInstalled: true,
  83. serviceName: 'HDFS'
  84. })
  85. ])
  86. }),
  87. e: ['HIVE', 'HDFS'],
  88. m: 'addServiceController without SQOOP'
  89. }
  90. ]);
  91. tests.forEach(function (test) {
  92. it(test.m, function () {
  93. installerStep7Controller.set('content', test.content);
  94. expect(installerStep7Controller.get('installedServiceNames')).to.include.members(test.e);
  95. expect(test.e).to.include.members(installerStep7Controller.get('installedServiceNames'));
  96. });
  97. });
  98. });
  99. describe('#isSubmitDisabled', function () {
  100. it('should be true if miscModalVisible', function () {
  101. installerStep7Controller.reopen({miscModalVisible: true});
  102. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(true);
  103. });
  104. it('should be true if some of stepConfigs has errors', function () {
  105. installerStep7Controller.reopen({
  106. miscModalVisible: false,
  107. stepConfigs: [
  108. {
  109. showConfig: true,
  110. errorCount: 1
  111. }
  112. ]
  113. });
  114. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(true);
  115. });
  116. it('should be false if all of stepConfigs don\'t have errors and miscModalVisible is false', function () {
  117. installerStep7Controller.reopen({
  118. miscModalVisible: false,
  119. stepConfigs: [
  120. {
  121. showConfig: true,
  122. errorCount: 0
  123. }
  124. ]
  125. });
  126. expect(installerStep7Controller.get('isSubmitDisabled')).to.equal(false);
  127. });
  128. });
  129. describe('#selectedServiceNames', function () {
  130. it('should use content.services as source of data', function () {
  131. installerStep7Controller.set('content', {
  132. services: [
  133. {isSelected: true, isInstalled: false, serviceName: 's1'},
  134. {isSelected: false, isInstalled: false, serviceName: 's2'},
  135. {isSelected: true, isInstalled: true, serviceName: 's3'},
  136. {isSelected: false, isInstalled: false, serviceName: 's4'},
  137. {isSelected: true, isInstalled: false, serviceName: 's5'},
  138. {isSelected: false, isInstalled: false, serviceName: 's6'},
  139. {isSelected: true, isInstalled: true, serviceName: 's7'},
  140. {isSelected: false, isInstalled: false, serviceName: 's8'}
  141. ]
  142. });
  143. var expected = ['s1', 's5'];
  144. expect(installerStep7Controller.get('selectedServiceNames')).to.eql(expected);
  145. });
  146. });
  147. describe('#allSelectedServiceNames', function () {
  148. it('should use content.services as source of data', function () {
  149. installerStep7Controller.set('content', {
  150. services: [
  151. Em.Object.create({isSelected: true, isInstalled: false, serviceName: 's1'}),
  152. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's2'}),
  153. Em.Object.create({isSelected: true, isInstalled: true, serviceName: 's3'}),
  154. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's4'}),
  155. Em.Object.create({isSelected: true, isInstalled: false, serviceName: 's5'}),
  156. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's6'}),
  157. Em.Object.create({isSelected: true, isInstalled: true, serviceName: 's7'}),
  158. Em.Object.create({isSelected: false, isInstalled: false, serviceName: 's8'})
  159. ]
  160. });
  161. var expected = ['s1', 's3', 's5', 's7'];
  162. expect(installerStep7Controller.get('allSelectedServiceNames')).to.eql(expected);
  163. });
  164. });
  165. describe('#masterComponentHosts', function () {
  166. it('should be equal to content.masterComponentHosts', function () {
  167. var masterComponentHosts = [
  168. {},
  169. {},
  170. {}
  171. ];
  172. installerStep7Controller.reopen({content: {masterComponentHosts: masterComponentHosts}});
  173. expect(installerStep7Controller.get('masterComponentHosts')).to.eql(masterComponentHosts);
  174. });
  175. });
  176. describe('#slaveComponentHosts', function () {
  177. it('should be equal to content.slaveGroupProperties', function () {
  178. var slaveGroupProperties = [
  179. {},
  180. {},
  181. {}
  182. ];
  183. installerStep7Controller.reopen({content: {slaveGroupProperties: slaveGroupProperties}});
  184. expect(installerStep7Controller.get('slaveComponentHosts')).to.eql(slaveGroupProperties);
  185. });
  186. });
  187. describe('#clearStep', function () {
  188. it('should clear stepConfigs', function () {
  189. installerStep7Controller.set('stepConfigs', [
  190. {},
  191. {}
  192. ]);
  193. installerStep7Controller.clearStep();
  194. expect(installerStep7Controller.get('stepConfigs.length')).to.equal(0);
  195. });
  196. it('should clear filter', function () {
  197. installerStep7Controller.set('filter', 'filter');
  198. installerStep7Controller.clearStep();
  199. expect(installerStep7Controller.get('filter')).to.equal('');
  200. });
  201. it('should set for each filterColumns "selected" false', function () {
  202. installerStep7Controller.set('filterColumns', [
  203. {selected: true},
  204. {selected: false},
  205. {selected: true}
  206. ]);
  207. installerStep7Controller.clearStep();
  208. expect(installerStep7Controller.get('filterColumns').everyProperty('selected', false)).to.equal(true);
  209. });
  210. });
  211. describe('#loadInstalledServicesConfigGroups', function () {
  212. before(function () {
  213. sinon.stub(App.ajax, 'send', Em.K);
  214. });
  215. after(function () {
  216. App.ajax.send.restore();
  217. });
  218. it('should do ajax request for each received service name', function () {
  219. var serviceNames = ['s1', 's2', 's3'];
  220. installerStep7Controller.loadInstalledServicesConfigGroups(serviceNames);
  221. expect(App.ajax.send.callCount).to.equal(serviceNames.length);
  222. });
  223. });
  224. describe('#getConfigTags', function () {
  225. before(function () {
  226. sinon.stub(App.ajax, 'send', Em.K);
  227. });
  228. after(function () {
  229. App.ajax.send.restore();
  230. });
  231. it('should do ajax-request', function () {
  232. installerStep7Controller.getConfigTags();
  233. expect(App.ajax.send.calledOnce).to.equal(true);
  234. });
  235. });
  236. describe('#setGroupsToDelete', function () {
  237. beforeEach(function () {
  238. installerStep7Controller.set('wizardController', Em.Object.create(App.LocalStorage, {name: 'tdk'}));
  239. });
  240. it('should add new groups to groupsToDelete', function () {
  241. var groupsToDelete = [
  242. {id: '1'},
  243. {id: '2'}
  244. ],
  245. groups = [
  246. Em.Object.create({id: '3'}),
  247. Em.Object.create(),
  248. Em.Object.create({id: '5'})
  249. ],
  250. expected = [
  251. {id: "1"},
  252. {id: "2"},
  253. {id: "3"},
  254. {id: "5"}
  255. ];
  256. installerStep7Controller.set('groupsToDelete', groupsToDelete);
  257. installerStep7Controller.setGroupsToDelete(groups);
  258. expect(installerStep7Controller.get('groupsToDelete')).to.eql(expected);
  259. expect(installerStep7Controller.get('wizardController').getDBProperty('groupsToDelete')).to.eql(expected);
  260. });
  261. });
  262. describe('#selectConfigGroup', function () {
  263. beforeEach(function () {
  264. installerStep7Controller.reopen({content: {services: []}});
  265. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  266. });
  267. afterEach(function () {
  268. installerStep7Controller.switchConfigGroupConfigs.restore();
  269. });
  270. it('should set selectedConfigGroup', function () {
  271. var group = {':': []};
  272. installerStep7Controller.selectConfigGroup({context: group});
  273. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(group);
  274. });
  275. });
  276. describe('#addOverrideProperty', function () {
  277. it('should add override property', function () {
  278. var groupName = 'groupName',
  279. selectedService = {configGroups: [Em.Object.create({name: groupName, properties: []})]},
  280. selectedConfigGroup = {name: groupName},
  281. serviceConfigProperty = Em.Object.create({overrides: []}),
  282. expected = Em.Object.create({
  283. value: '',
  284. isOriginalSCP: false,
  285. isEditable: true
  286. });
  287. installerStep7Controller.reopen({selectedService: selectedService, selectedConfigGroup: selectedConfigGroup});
  288. var newSCP = installerStep7Controller.addOverrideProperty(serviceConfigProperty);
  289. Em.keys(expected).forEach(function (k) {
  290. expect(newSCP.get(k)).to.equal(expected.get(k));
  291. });
  292. var group = installerStep7Controller.get('selectedService.configGroups').findProperty('name', groupName);
  293. expect(newSCP.get('group')).to.eql(group);
  294. expect(newSCP.get('parentSCP')).to.eql(serviceConfigProperty);
  295. expect(group.get('properties.length')).to.equal(1);
  296. });
  297. });
  298. describe('#resolveStormConfigs', function () {
  299. beforeEach(function () {
  300. installerStep7Controller.reopen({
  301. content: {services: []},
  302. wizardController: Em.Object.create({
  303. hosts: {'h1': {name: 'host1', id: 'h1'}},
  304. masterComponentHosts: [{component: 'GANGLIA_SERVER', host_id: 'h1'}],
  305. getDBProperty: function (k) {
  306. return this.get(k);
  307. }
  308. })
  309. });
  310. });
  311. it('shouldn\'t do nothing if Ganglia and Storm are installed', function () {
  312. var installedServiceNames = ['GANGLIA', 'STORM'],
  313. configs = [
  314. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  315. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  316. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  317. ],
  318. expected = [
  319. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  320. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  321. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  322. ];
  323. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  324. installerStep7Controller.resolveStormConfigs(configs);
  325. expect(configs).to.eql(expected);
  326. });
  327. it('shouldn\'t do nothing if Ganglia is in allSelectedServiceNames', function () {
  328. var allSelectedServiceNames = ['GANGLIA'],
  329. configs = [
  330. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  331. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  332. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  333. ],
  334. expected = [
  335. {name: 'nimbus.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  336. {name: 'supervisor.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  337. {name: 'worker.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true}
  338. ];
  339. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  340. installerStep7Controller.resolveStormConfigs(configs);
  341. Em.keys(expected[0]).forEach(function (k) {
  342. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  343. });
  344. });
  345. it('shouldn\'t do nothing if Ganglia is in installedServiceNames (2)', function () {
  346. var installedServiceNames = ['GANGLIA'],
  347. configs = [
  348. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  349. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  350. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  351. ],
  352. expected = [
  353. {name: 'nimbus.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  354. {name: 'supervisor.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  355. {name: 'worker.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true}
  356. ];
  357. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  358. installerStep7Controller.resolveStormConfigs(configs);
  359. Em.keys(expected[0]).forEach(function (k) {
  360. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  361. });
  362. });
  363. it('should replace host name for *.childopts properties if Ganglia is in installedServiceNames for Add Service Wizard', function () {
  364. var installedServiceNames = ['GANGLIA'],
  365. configs = [
  366. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  367. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  368. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  369. ],
  370. expected = [
  371. {name: 'nimbus.childopts', value: '.jar=host=realhost1', defaultValue: '.jar=host=realhost1', forceUpdate: true},
  372. {name: 'supervisor.childopts', value: '.jar=host=realhost1', defaultValue: '.jar=host=realhost1', forceUpdate: true},
  373. {name: 'worker.childopts', value: '.jar=host=realhost1', defaultValue: '.jar=host=realhost1', forceUpdate: true}
  374. ];
  375. installerStep7Controller.reopen({
  376. installedServiceNames: installedServiceNames,
  377. wizardController: Em.Object.create({
  378. name: 'addServiceController',
  379. masterComponentHosts: [{component: 'GANGLIA_SERVER', hostName: 'realhost1'}],
  380. getDBProperty: function (k) {
  381. return this.get(k);
  382. }
  383. })
  384. });
  385. installerStep7Controller.resolveStormConfigs(configs);
  386. Em.keys(expected[0]).forEach(function (k) {
  387. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  388. });
  389. });
  390. });
  391. describe('#resolveServiceDependencyConfigs', function () {
  392. beforeEach(function () {
  393. sinon.stub(installerStep7Controller, 'resolveStormConfigs', Em.K);
  394. });
  395. afterEach(function () {
  396. installerStep7Controller.resolveStormConfigs.restore();
  397. });
  398. it('should call resolveStormConfigs if serviceName is STORM', function () {
  399. var serviceName = 'STORM', configs = [
  400. {},
  401. {},
  402. {}
  403. ];
  404. installerStep7Controller.resolveServiceDependencyConfigs(serviceName, configs);
  405. expect(installerStep7Controller.resolveStormConfigs.calledWith(configs)).to.equal(true);
  406. });
  407. });
  408. describe('#selectedServiceObserver', function () {
  409. beforeEach(function () {
  410. installerStep7Controller.reopen({content: {services: []}});
  411. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  412. });
  413. afterEach(function () {
  414. installerStep7Controller.switchConfigGroupConfigs.restore();
  415. });
  416. it('shouldn\'t do nothing if App.supports.hostOverridesInstaller is false', function () {
  417. App.set('supports.hostOverridesInstaller', false);
  418. var configGroups = [
  419. {},
  420. {}
  421. ],
  422. selectedConfigGroup = {};
  423. installerStep7Controller.reopen({configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  424. installerStep7Controller.selectedServiceObserver();
  425. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  426. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  427. });
  428. it('shouldn\'t do nothing if selectedService is null', function () {
  429. App.set('supports.hostOverridesInstaller', true);
  430. var configGroups = [
  431. {},
  432. {}
  433. ],
  434. selectedConfigGroup = {};
  435. installerStep7Controller.reopen({selectedService: null, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  436. installerStep7Controller.selectedServiceObserver();
  437. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  438. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  439. });
  440. it('shouldn\'t do nothing if selectedService.serviceName is MISC', function () {
  441. App.set('supports.hostOverridesInstaller', true);
  442. var configGroups = [
  443. {},
  444. {}
  445. ],
  446. selectedConfigGroup = {};
  447. installerStep7Controller.reopen({selectedService: {serviceName: 'MISC'}, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  448. installerStep7Controller.selectedServiceObserver();
  449. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  450. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  451. });
  452. it('should update configGroups and selectedConfigGroup', function () {
  453. App.set('supports.hostOverridesInstaller', true);
  454. var defaultGroup = {isDefault: true, n: 'n2'},
  455. configGroups = [
  456. {isDefault: false, n: 'n1'},
  457. defaultGroup,
  458. {n: 'n3'}
  459. ],
  460. selectedConfigGroup = {};
  461. installerStep7Controller.reopen({selectedService: {serviceName: 's1', configGroups: configGroups}});
  462. installerStep7Controller.selectedServiceObserver();
  463. expect(installerStep7Controller.get('configGroups').mapProperty('n')).to.eql(['n2', 'n1', 'n3']);
  464. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(defaultGroup);
  465. });
  466. });
  467. describe('#loadConfigGroups', function () {
  468. beforeEach(function () {
  469. installerStep7Controller.reopen({
  470. wizardController: Em.Object.create({
  471. allHosts: [
  472. {hostName: 'h1'},
  473. {hostName: 'h2'},
  474. {hostName: 'h3'}
  475. ]
  476. })
  477. });
  478. });
  479. it('shouldn\'t do nothing if only MISC available', function () {
  480. var configGroups = [
  481. {}
  482. ];
  483. installerStep7Controller.reopen({
  484. stepConfigs: [Em.Object.create({serviceName: 'MISC', configGroups: configGroups})]
  485. });
  486. installerStep7Controller.loadConfigGroups([]);
  487. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups')).to.eql(configGroups);
  488. });
  489. it('should set configGroups for service if they don\'t exist', function () {
  490. var configGroups = [],
  491. serviceName = 'HDFS',
  492. serviceConfigGroups = [
  493. {service: {id: 's1'}}
  494. ];
  495. installerStep7Controller.reopen({
  496. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  497. });
  498. var manageCGController = App.router.get('manageConfigGroupsController');
  499. sinon.stub(manageCGController, 'hostsToPublic', function(data){return ['c6401','c6402','c6403']});
  500. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  501. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(1);
  502. var group = installerStep7Controller.get('stepConfigs.firstObject.configGroups.firstObject');
  503. expect(group.get('name')).to.equal(serviceName + ' Default');
  504. expect(group.get('description').contains(serviceName)).to.equal(true);
  505. expect(group.get('isDefault')).to.equal(true);
  506. expect(group.get('hosts')).to.eql(['h1', 'h2', 'h3']);
  507. expect(group.get('service.id')).to.equal(serviceName);
  508. expect(group.get('serviceName')).to.equal(serviceName);
  509. manageCGController.hostsToPublic.restore();
  510. });
  511. it('should update configGroups for service (only default group)', function () {
  512. var configGroups = [],
  513. serviceName = 'HDFS',
  514. serviceConfigGroups = [
  515. {service: {id: 'HDFS'}, isDefault: true, n: 'n1'}
  516. ];
  517. installerStep7Controller.reopen({
  518. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  519. });
  520. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  521. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  522. });
  523. it('should update configGroups for service', function () {
  524. var configGroups = [],
  525. serviceName = 'HDFS',
  526. properties = [
  527. { name: "p1", filename: "file.xml" },
  528. { name: "p2", filename: "file.xml" }
  529. ],
  530. serviceConfigGroups = [
  531. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: true, n: 'n1'},
  532. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: false, n: 'n2'}
  533. ];
  534. installerStep7Controller.reopen({
  535. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups, configs: properties})]
  536. });
  537. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  538. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(2);
  539. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  540. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('properties').everyProperty('group.n', 'n2')).to.equal(true);
  541. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('parentConfigGroup.n')).to.equal('n1');
  542. });
  543. });
  544. describe('#_getDisplayedConfigGroups', function () {
  545. it('should return [] if no selected group', function () {
  546. installerStep7Controller.reopen({
  547. content: {services: []},
  548. selectedConfigGroup: null
  549. });
  550. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([]);
  551. });
  552. it('should return default config group if another selected', function () {
  553. var defaultGroup = Em.Object.create({isDefault: false});
  554. installerStep7Controller.reopen({
  555. content: {services: []},
  556. selectedConfigGroup: defaultGroup
  557. });
  558. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([defaultGroup]);
  559. });
  560. it('should return other groups if default selected', function () {
  561. var defaultGroup = Em.Object.create({isDefault: true}),
  562. cfgG = Em.Object.create({isDefault: true}),
  563. configGroups = Em.A([
  564. Em.Object.create({isDefault: false}),
  565. Em.Object.create({isDefault: false}),
  566. cfgG,
  567. Em.Object.create({isDefault: false})
  568. ]);
  569. installerStep7Controller.reopen({
  570. content: {services: []},
  571. selectedConfigGroup: defaultGroup,
  572. selectedService: {configGroups: configGroups}
  573. });
  574. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql(configGroups.without(cfgG));
  575. });
  576. });
  577. describe('#_setEditableValue', function () {
  578. it('shouldn\'t update config if no selectedConfigGroup', function () {
  579. installerStep7Controller.reopen({
  580. selectedConfigGroup: null
  581. });
  582. var config = Em.Object.create({isEditable: null});
  583. var updatedConfig = installerStep7Controller._setEditableValue(config);
  584. expect(updatedConfig.get('isEditable')).to.be.null;
  585. });
  586. it('should set isEditable equal to selectedGroup.isDefault if service not installed', function () {
  587. var isDefault = true;
  588. installerStep7Controller.reopen({
  589. installedServiceNames: [],
  590. selectedService: {serviceName: 'abc'},
  591. selectedConfigGroup: Em.Object.create({isDefault: isDefault})
  592. });
  593. var config = Em.Object.create({isEditable: null});
  594. var updatedConfig = installerStep7Controller._setEditableValue(config);
  595. expect(updatedConfig.get('isEditable')).to.equal(isDefault);
  596. installerStep7Controller.toggleProperty('selectedConfigGroup.isDefault');
  597. updatedConfig = installerStep7Controller._setEditableValue(config);
  598. expect(updatedConfig.get('isEditable')).to.equal(!isDefault);
  599. });
  600. Em.A([
  601. {
  602. isEditable: false,
  603. isReconfigurable: false,
  604. isDefault: true,
  605. e: false
  606. },
  607. {
  608. isEditable: true,
  609. isReconfigurable: true,
  610. isDefault: true,
  611. e: true
  612. },
  613. {
  614. isEditable: false,
  615. isReconfigurable: true,
  616. isDefault: false,
  617. e: false
  618. },
  619. {
  620. isEditable: true,
  621. isReconfigurable: false,
  622. isDefault: false,
  623. e: false
  624. }
  625. ]).forEach(function (test) {
  626. it('service installed, isEditable = ' + test.isEditable.toString() + ', isReconfigurable = ' + test.isReconfigurable.toString(), function () {
  627. var config = Em.Object.create({
  628. isReconfigurable: test.isReconfigurable,
  629. isEditable: test.isEditable
  630. });
  631. installerStep7Controller.reopen({
  632. installedServiceNames: Em.A(['a']),
  633. selectedService: Em.Object.create({serviceName: 'a'}),
  634. selectedConfigGroup: Em.Object.create({isDefault: test.isDefault})
  635. });
  636. var updateConfig = installerStep7Controller._setEditableValue(config);
  637. expect(updateConfig.get('isEditable')).to.equal(test.e);
  638. });
  639. });
  640. });
  641. describe('#_setOverrides', function () {
  642. it('shouldn\'t update config if no selectedConfigGroup', function () {
  643. installerStep7Controller.reopen({
  644. selectedConfigGroup: null
  645. });
  646. var config = Em.Object.create({overrides: null});
  647. var updatedConfig = installerStep7Controller._setOverrides(config, []);
  648. expect(updatedConfig.get('overrides')).to.be.null;
  649. });
  650. it('no overrideToAdd', function () {
  651. var isDefault = true,
  652. name = 'n1',
  653. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  654. overrides = Em.A([
  655. Em.Object.create({name: name, value: 'v1'}),
  656. Em.Object.create({name: name, value: 'v2'}),
  657. Em.Object.create({name: 'n2', value: 'v3'})
  658. ]);
  659. installerStep7Controller.reopen({
  660. overrideToAdd: null,
  661. selectedConfigGroup: Em.Object.create({
  662. isDefault: isDefault
  663. })
  664. });
  665. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  666. expect(updatedConfig.get('overrides.length')).to.equal(2);
  667. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  668. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  669. });
  670. it('overrideToAdd exists', function () {
  671. var isDefault = true,
  672. name = 'n1',
  673. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  674. overrides = Em.A([
  675. Em.Object.create({name: name, value: 'v1'}),
  676. Em.Object.create({name: name, value: 'v2'}),
  677. Em.Object.create({name: 'n2', value: 'v3'})
  678. ]);
  679. installerStep7Controller.reopen({
  680. overrideToAdd: Em.Object.create({name: name}),
  681. selectedService: {configGroups: [Em.Object.create({name: 'n', properties: []})]},
  682. selectedConfigGroup: Em.Object.create({
  683. isDefault: isDefault,
  684. name: 'n'
  685. })
  686. });
  687. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  688. expect(updatedConfig.get('overrides.length')).to.equal(3);
  689. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  690. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  691. });
  692. });
  693. describe('#switchConfigGroupConfigs', function () {
  694. it('if selectedConfigGroup is null, serviceConfigs shouldn\'t be changed', function () {
  695. installerStep7Controller.reopen({
  696. selectedConfigGroup: null,
  697. content: {services: []},
  698. serviceConfigs: {configs: [
  699. {overrides: []},
  700. {overrides: []}
  701. ]}
  702. });
  703. installerStep7Controller.switchConfigGroupConfigs();
  704. expect(installerStep7Controller.get('serviceConfigs.configs').everyProperty('overrides.length', 0)).to.equal(true);
  705. });
  706. it('should set configs for serviceConfigs', function () {
  707. var configGroups = [
  708. Em.Object.create({
  709. properties: [
  710. {name: 'g1', value: 'v1'},
  711. {name: 'g2', value: 'v2'}
  712. ]
  713. })
  714. ];
  715. sinon.stub(installerStep7Controller, '_getDisplayedConfigGroups', function () {
  716. return configGroups;
  717. });
  718. sinon.stub(installerStep7Controller, '_setEditableValue', function (config) {
  719. config.set('isEditable', true);
  720. return config;
  721. });
  722. installerStep7Controller.reopen({
  723. selectedConfigGroup: Em.Object.create({isDefault: true, name: 'g1'}),
  724. content: {services: []},
  725. selectedService: {configs: Em.A([Em.Object.create({name: 'g1', overrides: [], properties: []}), Em.Object.create({name: 'g2', overrides: []})])},
  726. serviceConfigs: {configs: [Em.Object.create({name: 'g1'})]}
  727. });
  728. installerStep7Controller.switchConfigGroupConfigs();
  729. var configs = installerStep7Controller.get('selectedService.configs');
  730. expect(configs.findProperty('name', 'g1').get('overrides').length).to.equal(1);
  731. expect(configs.findProperty('name', 'g2').get('overrides').length).to.equal(1);
  732. expect(configs.everyProperty('isEditable', true)).to.equal(true);
  733. installerStep7Controller._getDisplayedConfigGroups.restore();
  734. installerStep7Controller._setEditableValue.restore();
  735. });
  736. });
  737. describe('#selectProperService', function () {
  738. Em.A([
  739. {
  740. name: 'addServiceController',
  741. stepConfigs: [
  742. {selected: false, name: 'n1'},
  743. {selected: true, name: 'n2'},
  744. {selected: true, name: 'n3'}
  745. ],
  746. e: 'n2'
  747. },
  748. {
  749. name: 'installerController',
  750. stepConfigs: [
  751. {showConfig: false, name: 'n1'},
  752. {showConfig: false, name: 'n2'},
  753. {showConfig: true, name: 'n3'}
  754. ],
  755. e: 'n3'
  756. }
  757. ]).forEach(function (test) {
  758. it(test.name, function () {
  759. sinon.stub(installerStep7Controller, 'selectedServiceObserver', Em.K);
  760. installerStep7Controller.reopen({
  761. wizardController: Em.Object.create({
  762. name: test.name
  763. }),
  764. stepConfigs: test.stepConfigs
  765. });
  766. installerStep7Controller.selectProperService();
  767. expect(installerStep7Controller.get('selectedService.name')).to.equal(test.e);
  768. installerStep7Controller.selectedServiceObserver.restore();
  769. });
  770. });
  771. });
  772. describe('#setStepConfigs', function () {
  773. beforeEach(function () {
  774. installerStep7Controller.reopen({
  775. content: {services: []},
  776. wizardController: Em.Object.create({
  777. getDBProperty: function (key) {
  778. return this.get(key);
  779. }
  780. })
  781. });
  782. });
  783. afterEach(function () {
  784. App.config.renderConfigs.restore();
  785. });
  786. it('if wizard isn\'t addService, should set output of App.config.renderConfigs', function () {
  787. var serviceConfigs = Em.A([
  788. {},
  789. {}
  790. ]);
  791. sinon.stub(App.config, 'renderConfigs', function () {
  792. return serviceConfigs;
  793. });
  794. installerStep7Controller.set('wizardController.name', 'installerController');
  795. installerStep7Controller.setStepConfigs([], []);
  796. expect(installerStep7Controller.get('stepConfigs')).to.eql(serviceConfigs);
  797. });
  798. it('addServiceWizard used', function () {
  799. var serviceConfigs = Em.A([Em.Object.create({serviceName: 's1'}), Em.Object.create({serviceName: 's2'})]);
  800. installerStep7Controller.set('wizardController.name', 'addServiceController');
  801. installerStep7Controller.reopen({selectedServiceNames: ['s2']});
  802. sinon.stub(App.config, 'renderConfigs', function () {
  803. return serviceConfigs;
  804. });
  805. installerStep7Controller.setStepConfigs([], []);
  806. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  807. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 's2').get('selected')).to.equal(true);
  808. });
  809. it('addServiceWizard used, HA enabled', function () {
  810. sinon.stub(App, 'get', function (k) {
  811. if (k === 'isHaEnabled') {
  812. return true;
  813. }
  814. return Em.get(App, k);
  815. });
  816. var serviceConfigs = Em.A([
  817. Em.Object.create({
  818. serviceName: 'HDFS',
  819. configs: [
  820. {category: 'SECONDARY_NAMENODE'},
  821. {category: 'SECONDARY_NAMENODE'},
  822. {category: 'NameNode'},
  823. {category: 'NameNode'},
  824. {category: 'SECONDARY_NAMENODE'}
  825. ]
  826. }),
  827. Em.Object.create({serviceName: 's2'})]
  828. );
  829. installerStep7Controller.set('wizardController.name', 'addServiceController');
  830. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  831. sinon.stub(App.config, 'renderConfigs', function () {
  832. return serviceConfigs;
  833. });
  834. installerStep7Controller.setStepConfigs([], []);
  835. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  836. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('selected')).to.equal(true);
  837. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  838. App.get.restore();
  839. });
  840. });
  841. describe('#checkHostOverrideInstaller', function () {
  842. beforeEach(function () {
  843. sinon.stub(installerStep7Controller, 'loadConfigGroups', Em.K);
  844. sinon.stub(installerStep7Controller, 'loadInstalledServicesConfigGroups', Em.K);
  845. });
  846. afterEach(function () {
  847. installerStep7Controller.loadConfigGroups.restore();
  848. installerStep7Controller.loadInstalledServicesConfigGroups.restore();
  849. App.get.restore();
  850. });
  851. Em.A([
  852. {
  853. hostOverridesInstaller: false,
  854. installedServiceNames: [],
  855. m: 'hostOverridesInstaller is false, installedServiceNames is empty',
  856. e: {
  857. loadConfigGroups: false,
  858. loadInstalledServicesConfigGroups: false
  859. }
  860. },
  861. {
  862. hostOverridesInstaller: false,
  863. installedServiceNames: ['s1', 's2'],
  864. m: 'hostOverridesInstaller is false, installedServiceNames is n\'t empty',
  865. e: {
  866. loadConfigGroups: false,
  867. loadInstalledServicesConfigGroups: false
  868. }
  869. },
  870. {
  871. hostOverridesInstaller: true,
  872. installedServiceNames: [],
  873. m: 'hostOverridesInstaller is true, installedServiceNames is empty',
  874. e: {
  875. loadConfigGroups: true,
  876. loadInstalledServicesConfigGroups: false
  877. }
  878. },
  879. {
  880. hostOverridesInstaller: true,
  881. installedServiceNames: ['s1', 's2', 's3'],
  882. m: 'hostOverridesInstaller is true, installedServiceNames isn\'t empty',
  883. e: {
  884. loadConfigGroups: true,
  885. loadInstalledServicesConfigGroups: true
  886. }
  887. }
  888. ]).forEach(function (test) {
  889. it(test.m, function () {
  890. sinon.stub(App, 'get', function (k) {
  891. if (k === 'supports.hostOverridesInstaller') return test.hostOverridesInstaller;
  892. return Em.get(App, k);
  893. });
  894. installerStep7Controller.reopen({installedServiceNames: test.installedServiceNames});
  895. installerStep7Controller.checkHostOverrideInstaller();
  896. if (test.e.loadConfigGroups) {
  897. expect(installerStep7Controller.loadConfigGroups.calledOnce).to.equal(true);
  898. }
  899. else {
  900. expect(installerStep7Controller.loadConfigGroups.called).to.equal(false);
  901. }
  902. if (test.e.loadInstalledServicesConfigGroups) {
  903. expect(installerStep7Controller.loadInstalledServicesConfigGroups.calledOnce).to.equal(true);
  904. }
  905. else {
  906. expect(installerStep7Controller.loadInstalledServicesConfigGroups.called).to.equal(false);
  907. }
  908. });
  909. });
  910. });
  911. describe('#loadStep', function () {
  912. beforeEach(function () {
  913. installerStep7Controller.reopen({
  914. content: {services: []},
  915. wizardController: Em.Object.create({
  916. getDBProperty: function (k) {
  917. return this.get(k);
  918. }
  919. })
  920. });
  921. sinon.stub(App.config, 'mergePreDefinedWithStored', Em.K);
  922. sinon.stub(App.config, 'addAdvancedConfigs', Em.K);
  923. sinon.stub(App.config, 'addCustomConfigs', Em.K);
  924. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  925. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  926. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  927. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  928. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  929. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  930. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  931. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  932. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  933. sinon.stub(installerStep7Controller, 'applyServicesConfigs', Em.K);
  934. sinon.stub(App.router, 'send', Em.K);
  935. });
  936. afterEach(function () {
  937. App.config.mergePreDefinedWithStored.restore();
  938. App.config.addAdvancedConfigs.restore();
  939. App.config.addCustomConfigs.restore();
  940. App.config.fileConfigsIntoTextarea.restore();
  941. installerStep7Controller.clearStep.restore();
  942. installerStep7Controller.getConfigTags.restore();
  943. installerStep7Controller.setInstalledServiceConfigs.restore();
  944. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  945. installerStep7Controller.setStepConfigs.restore();
  946. installerStep7Controller.checkHostOverrideInstaller.restore();
  947. installerStep7Controller.activateSpecialConfigs.restore();
  948. installerStep7Controller.selectProperService.restore();
  949. installerStep7Controller.applyServicesConfigs.restore();
  950. App.router.send.restore();
  951. });
  952. it('should call clearStep', function () {
  953. installerStep7Controller.loadStep();
  954. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  955. });
  956. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  957. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  958. installerStep7Controller.loadStep();
  959. expect(installerStep7Controller.clearStep.called).to.equal(false);
  960. });
  961. it('should use App.config to map configs', function () {
  962. installerStep7Controller.loadStep();
  963. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  964. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  965. expect(App.config.addCustomConfigs.calledOnce).to.equal(true);
  966. });
  967. it('should call setInstalledServiceConfigs for addServiceController', function () {
  968. installerStep7Controller.set('wizardController.name', 'addServiceController');
  969. installerStep7Controller.loadStep();
  970. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  971. });
  972. });
  973. describe('#applyServicesConfigs', function() {
  974. beforeEach(function() {
  975. installerStep7Controller.reopen({
  976. allSelectedServiceNames: [],
  977. });
  978. sinon.stub(App.config, 'fileConfigsIntoTextarea', function(configs) {
  979. return configs;
  980. });
  981. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  982. sinon.stub(installerStep7Controller, 'loadServerSideConfigsRecommendations', function() {
  983. return $.Deferred().resolve();
  984. });
  985. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  986. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  987. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  988. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  989. sinon.stub(App.router, 'send', Em.K);
  990. });
  991. afterEach(function () {
  992. App.config.fileConfigsIntoTextarea.restore();
  993. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  994. installerStep7Controller.loadServerSideConfigsRecommendations.restore();
  995. installerStep7Controller.checkHostOverrideInstaller.restore();
  996. installerStep7Controller.activateSpecialConfigs.restore();
  997. installerStep7Controller.selectProperService.restore();
  998. installerStep7Controller.setStepConfigs.restore();
  999. App.router.send.restore();
  1000. });
  1001. it('should run some methods' , function () {
  1002. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1003. expect(installerStep7Controller.loadServerSideConfigsRecommendations.calledOnce).to.equal(true);
  1004. expect(installerStep7Controller.get('isRecommendedLoaded')).to.equal(true);
  1005. expect(installerStep7Controller.setStepConfigs.calledWith({name: 'configs'}, {name: 'storedConfigs'})).to.equal(true);
  1006. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1007. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1008. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1009. });
  1010. Em.A([
  1011. {
  1012. allSelectedServiceNames: ['YARN'],
  1013. fileConfigsIntoTextarea: true,
  1014. m: 'should run fileConfigsIntoTextarea',
  1015. capacitySchedulerUi: false
  1016. },
  1017. {
  1018. allSelectedServiceNames: ['YARN'],
  1019. m: 'shouldn\'t run fileConfigsIntoTextarea',
  1020. capacitySchedulerUi: true
  1021. },
  1022. {
  1023. allSelectedServiceNames: ['STORM'],
  1024. resolveServiceDependencyConfigs: true,
  1025. m: 'should run resolveServiceDependencyConfigs'
  1026. }
  1027. ]).forEach(function(t) {
  1028. it(t.m, function () {
  1029. sinon.stub(App, 'get', function (k) {
  1030. if (k === 'supports.capacitySchedulerUi') return t.capacitySchedulerUi;
  1031. return Em.get(App, k);
  1032. });
  1033. installerStep7Controller.reopen({
  1034. allSelectedServiceNames: t.allSelectedServiceNames
  1035. });
  1036. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1037. if (t.fileConfigsIntoTextarea) {
  1038. expect(App.config.fileConfigsIntoTextarea.calledWith({name: 'configs'}, 'capacity-scheduler.xml')).to.equal(true);
  1039. } else {
  1040. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(false);
  1041. }
  1042. if (t.resolveServiceDependencyConfigs) {
  1043. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledWith('STORM', {name: 'configs'})).to.equal(true);
  1044. } else {
  1045. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(false);
  1046. }
  1047. App.get.restore();
  1048. });
  1049. });
  1050. });
  1051. describe('#_updateValueForCheckBoxConfig', function () {
  1052. Em.A([
  1053. {
  1054. v: 'true',
  1055. e: true
  1056. },
  1057. {
  1058. v: 'false',
  1059. e: false
  1060. }
  1061. ]).forEach(function (test) {
  1062. it(test.v, function () {
  1063. var serviceConfigProperty = Em.Object.create({value: test.v});
  1064. installerStep7Controller._updateValueForCheckBoxConfig(serviceConfigProperty);
  1065. expect(serviceConfigProperty.get('value')).to.equal(test.e);
  1066. expect(serviceConfigProperty.get('defaultValue')).to.equal(test.e);
  1067. });
  1068. });
  1069. });
  1070. describe('#_updateIsEditableFlagForConfig', function () {
  1071. Em.A([
  1072. {
  1073. isAdmin: false,
  1074. isReconfigurable: false,
  1075. isHostsConfigsPage: true,
  1076. defaultGroupSelected: false,
  1077. m: 'false for non-admin users',
  1078. e: false
  1079. },
  1080. {
  1081. isAdmin: true,
  1082. isReconfigurable: false,
  1083. isHostsConfigsPage: true,
  1084. defaultGroupSelected: false,
  1085. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1086. e: false
  1087. },
  1088. {
  1089. isAdmin: true,
  1090. isReconfigurable: false,
  1091. isHostsConfigsPage: true,
  1092. defaultGroupSelected: true,
  1093. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1094. e: false
  1095. },
  1096. {
  1097. isAdmin: true,
  1098. isReconfigurable: false,
  1099. isHostsConfigsPage: false,
  1100. defaultGroupSelected: false,
  1101. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1102. e: false
  1103. },
  1104. {
  1105. isAdmin: true,
  1106. isReconfigurable: true,
  1107. isHostsConfigsPage: false,
  1108. defaultGroupSelected: true,
  1109. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1110. e: true
  1111. }
  1112. ]).forEach(function (test) {
  1113. it(test.m, function () {
  1114. sinon.stub(App, 'get', function (k) {
  1115. if (k === 'isAdmin') return test.isAdmin;
  1116. return Em.get(App, k);
  1117. });
  1118. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1119. var serviceConfigProperty = Em.Object.create({
  1120. isReconfigurable: test.isReconfigurable
  1121. });
  1122. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1123. App.get.restore();
  1124. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1125. });
  1126. });
  1127. });
  1128. describe('#_updateOverridesForConfig', function () {
  1129. it('should set empty array', function () {
  1130. var serviceConfigProperty = Em.Object.create({
  1131. overrides: null
  1132. }), component = Em.Object.create();
  1133. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1134. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1135. });
  1136. it('host overrides not supported', function () {
  1137. var serviceConfigProperty = Em.Object.create({
  1138. overrides: [
  1139. {value: 'new value'}
  1140. ]
  1141. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1142. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1143. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1144. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1145. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1146. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1147. });
  1148. it('host overrides supported', function () {
  1149. sinon.stub(App, 'get', function (k) {
  1150. if (k === 'supports.hostOverrides') return true;
  1151. return Em.get(App, k);
  1152. });
  1153. var serviceConfigProperty = Em.Object.create({
  1154. overrides: [
  1155. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1156. ]
  1157. }),
  1158. component = Em.Object.create({
  1159. selectedConfigGroup: {isDefault: true},
  1160. configGroups: Em.A([
  1161. Em.Object.create({name: 'n1', properties: []})
  1162. ])
  1163. });
  1164. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1165. App.get.restore();
  1166. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1167. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1168. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1169. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1170. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1171. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1172. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1173. });
  1174. });
  1175. });