step7_test.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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('#resolveYarnConfigs', function () {
  299. it('should set property to true', function () {
  300. var allSelectedServiceNames = ['SLIDER', 'YARN'],
  301. configs = [
  302. {name: 'hadoop.registry.rm.enabled', value: false, defaultValue: false}
  303. ],
  304. expected = [
  305. {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true, forceUpdate: true}
  306. ];
  307. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  308. installerStep7Controller.resolveYarnConfigs(configs);
  309. expect(configs[0]).to.eql(expected[0]);
  310. });
  311. it('should set property to false', function () {
  312. var allSelectedServiceNames = ['YARN'],
  313. configs = [
  314. {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true},
  315. ],
  316. expected = [
  317. {name: 'hadoop.registry.rm.enabled', value: false, defaultValue: false, forceUpdate: true}
  318. ];
  319. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  320. installerStep7Controller.resolveYarnConfigs(configs);
  321. expect(configs[0]).to.eql(expected[0]);
  322. });
  323. it('should skip setting property', function () {
  324. var allSelectedServiceNames = ['YARN', 'SLIDER'],
  325. configs = [
  326. {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true},
  327. ],
  328. expected = [
  329. {name: 'hadoop.registry.rm.enabled', value: true, defaultValue: true}
  330. ];
  331. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  332. installerStep7Controller.resolveYarnConfigs(configs);
  333. expect(configs[0]).to.eql(expected[0]);
  334. });
  335. });
  336. describe('#resolveStormConfigs', function () {
  337. beforeEach(function () {
  338. installerStep7Controller.reopen({
  339. content: {services: []},
  340. wizardController: Em.Object.create({
  341. hosts: {'h1': {name: 'host1', id: 'h1'}},
  342. masterComponentHosts: [{component: 'GANGLIA_SERVER', host_id: 'h1'}],
  343. getDBProperty: function (k) {
  344. return this.get(k);
  345. }
  346. })
  347. });
  348. });
  349. it('shouldn\'t do nothing if Ganglia and Storm are installed', function () {
  350. var installedServiceNames = ['GANGLIA', 'STORM'],
  351. configs = [
  352. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  353. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  354. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  355. ],
  356. expected = [
  357. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  358. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  359. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  360. ];
  361. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  362. installerStep7Controller.resolveStormConfigs(configs);
  363. expect(configs).to.eql(expected);
  364. });
  365. it('shouldn\'t do nothing if Ganglia is in allSelectedServiceNames', function () {
  366. var allSelectedServiceNames = ['GANGLIA'],
  367. configs = [
  368. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  369. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  370. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  371. ],
  372. expected = [
  373. {name: 'nimbus.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  374. {name: 'supervisor.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  375. {name: 'worker.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true}
  376. ];
  377. installerStep7Controller.reopen({allSelectedServiceNames: allSelectedServiceNames});
  378. installerStep7Controller.resolveStormConfigs(configs);
  379. Em.keys(expected[0]).forEach(function (k) {
  380. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  381. });
  382. });
  383. it('shouldn\'t do nothing if Ganglia is in installedServiceNames (2)', function () {
  384. var installedServiceNames = ['GANGLIA'],
  385. configs = [
  386. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  387. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  388. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  389. ],
  390. expected = [
  391. {name: 'nimbus.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  392. {name: 'supervisor.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true},
  393. {name: 'worker.childopts', value: '.jar=host=host1', defaultValue: '.jar=host=host1', forceUpdate: true}
  394. ];
  395. installerStep7Controller.reopen({installedServiceNames: installedServiceNames});
  396. installerStep7Controller.resolveStormConfigs(configs);
  397. Em.keys(expected[0]).forEach(function (k) {
  398. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  399. });
  400. });
  401. it('should replace host name for *.childopts properties if Ganglia is in installedServiceNames for Add Service Wizard', function () {
  402. var installedServiceNames = ['GANGLIA'],
  403. configs = [
  404. {name: 'nimbus.childopts', value: '.jar=host=host2', defaultValue: ''},
  405. {name: 'supervisor.childopts', value: '.jar=host=host2', defaultValue: ''},
  406. {name: 'worker.childopts', value: '.jar=host=host2', defaultValue: ''}
  407. ],
  408. expected = [
  409. {name: 'nimbus.childopts', value: '.jar=host=realhost1', defaultValue: '.jar=host=realhost1', forceUpdate: true},
  410. {name: 'supervisor.childopts', value: '.jar=host=realhost1', defaultValue: '.jar=host=realhost1', forceUpdate: true},
  411. {name: 'worker.childopts', value: '.jar=host=realhost1', defaultValue: '.jar=host=realhost1', forceUpdate: true}
  412. ];
  413. installerStep7Controller.reopen({
  414. installedServiceNames: installedServiceNames,
  415. wizardController: Em.Object.create({
  416. name: 'addServiceController',
  417. masterComponentHosts: [{component: 'GANGLIA_SERVER', hostName: 'realhost1'}],
  418. getDBProperty: function (k) {
  419. return this.get(k);
  420. }
  421. })
  422. });
  423. installerStep7Controller.resolveStormConfigs(configs);
  424. Em.keys(expected[0]).forEach(function (k) {
  425. expect(configs.mapProperty(k)).to.eql(expected.mapProperty(k));
  426. });
  427. });
  428. });
  429. describe('#resolveServiceDependencyConfigs', function () {
  430. beforeEach(function () {
  431. sinon.stub(installerStep7Controller, 'resolveStormConfigs', Em.K);
  432. sinon.stub(installerStep7Controller, 'resolveYarnConfigs', Em.K);
  433. });
  434. afterEach(function () {
  435. installerStep7Controller.resolveStormConfigs.restore();
  436. installerStep7Controller.resolveYarnConfigs.restore();
  437. });
  438. var serviceNames = [
  439. {serviceName: 'STORM', method: "resolveStormConfigs"},
  440. {serviceName: 'YARN', method: "resolveYarnConfigs"}].forEach(function(t) {
  441. it("should call " + t.method + " if serviceName is " + t.serviceName, function () {
  442. var configs = [
  443. {},
  444. {}
  445. ];
  446. installerStep7Controller.resolveServiceDependencyConfigs(t.serviceName, configs);
  447. expect(installerStep7Controller[t.method].calledWith(configs)).to.equal(true);
  448. });
  449. });
  450. });
  451. describe('#selectedServiceObserver', function () {
  452. beforeEach(function () {
  453. installerStep7Controller.reopen({content: {services: []}});
  454. sinon.stub(installerStep7Controller, 'switchConfigGroupConfigs', Em.K);
  455. });
  456. afterEach(function () {
  457. installerStep7Controller.switchConfigGroupConfigs.restore();
  458. });
  459. it('shouldn\'t do nothing if App.supports.hostOverridesInstaller is false', function () {
  460. App.set('supports.hostOverridesInstaller', false);
  461. var configGroups = [
  462. {},
  463. {}
  464. ],
  465. selectedConfigGroup = {};
  466. installerStep7Controller.reopen({configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  467. installerStep7Controller.selectedServiceObserver();
  468. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  469. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  470. });
  471. it('shouldn\'t do nothing if selectedService is null', function () {
  472. App.set('supports.hostOverridesInstaller', true);
  473. var configGroups = [
  474. {},
  475. {}
  476. ],
  477. selectedConfigGroup = {};
  478. installerStep7Controller.reopen({selectedService: null, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  479. installerStep7Controller.selectedServiceObserver();
  480. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  481. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  482. });
  483. it('shouldn\'t do nothing if selectedService.serviceName is MISC', function () {
  484. App.set('supports.hostOverridesInstaller', true);
  485. var configGroups = [
  486. {},
  487. {}
  488. ],
  489. selectedConfigGroup = {};
  490. installerStep7Controller.reopen({selectedService: {serviceName: 'MISC'}, configGroups: configGroups, selectedConfigGroup: selectedConfigGroup});
  491. installerStep7Controller.selectedServiceObserver();
  492. expect(installerStep7Controller.get('configGroups')).to.eql(configGroups);
  493. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(selectedConfigGroup);
  494. });
  495. it('should update configGroups and selectedConfigGroup', function () {
  496. App.set('supports.hostOverridesInstaller', true);
  497. var defaultGroup = {isDefault: true, n: 'n2'},
  498. configGroups = [
  499. {isDefault: false, n: 'n1'},
  500. defaultGroup,
  501. {n: 'n3'}
  502. ],
  503. selectedConfigGroup = {};
  504. installerStep7Controller.reopen({selectedService: {serviceName: 's1', configGroups: configGroups}});
  505. installerStep7Controller.selectedServiceObserver();
  506. expect(installerStep7Controller.get('configGroups').mapProperty('n')).to.eql(['n2', 'n1', 'n3']);
  507. expect(installerStep7Controller.get('selectedConfigGroup')).to.eql(defaultGroup);
  508. });
  509. });
  510. describe('#loadConfigGroups', function () {
  511. beforeEach(function () {
  512. installerStep7Controller.reopen({
  513. wizardController: Em.Object.create({
  514. allHosts: [
  515. {hostName: 'h1'},
  516. {hostName: 'h2'},
  517. {hostName: 'h3'}
  518. ]
  519. })
  520. });
  521. });
  522. it('shouldn\'t do nothing if only MISC available', function () {
  523. var configGroups = [
  524. {}
  525. ];
  526. installerStep7Controller.reopen({
  527. stepConfigs: [Em.Object.create({serviceName: 'MISC', configGroups: configGroups})]
  528. });
  529. installerStep7Controller.loadConfigGroups([]);
  530. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups')).to.eql(configGroups);
  531. });
  532. it('should set configGroups for service if they don\'t exist', function () {
  533. var configGroups = [],
  534. serviceName = 'HDFS',
  535. serviceConfigGroups = [
  536. {service: {id: 's1'}}
  537. ];
  538. installerStep7Controller.reopen({
  539. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  540. });
  541. var manageCGController = App.router.get('manageConfigGroupsController');
  542. sinon.stub(manageCGController, 'hostsToPublic', function(data){return ['c6401','c6402','c6403']});
  543. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  544. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(1);
  545. var group = installerStep7Controller.get('stepConfigs.firstObject.configGroups.firstObject');
  546. expect(group.get('name')).to.equal(serviceName + ' Default');
  547. expect(group.get('description').contains(serviceName)).to.equal(true);
  548. expect(group.get('isDefault')).to.equal(true);
  549. expect(group.get('hosts')).to.eql(['h1', 'h2', 'h3']);
  550. expect(group.get('service.id')).to.equal(serviceName);
  551. expect(group.get('serviceName')).to.equal(serviceName);
  552. manageCGController.hostsToPublic.restore();
  553. });
  554. it('should update configGroups for service (only default group)', function () {
  555. var configGroups = [],
  556. serviceName = 'HDFS',
  557. serviceConfigGroups = [
  558. {service: {id: 'HDFS'}, isDefault: true, n: 'n1'}
  559. ];
  560. installerStep7Controller.reopen({
  561. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  562. });
  563. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  564. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  565. });
  566. it('should update configGroups for service', function () {
  567. var configGroups = [],
  568. serviceName = 'HDFS',
  569. properties = [
  570. { name: "p1", filename: "file.xml" },
  571. { name: "p2", filename: "file.xml" }
  572. ],
  573. serviceConfigGroups = [
  574. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: true, n: 'n1'},
  575. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: false, n: 'n2'}
  576. ];
  577. installerStep7Controller.reopen({
  578. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups, configs: properties})]
  579. });
  580. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  581. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(2);
  582. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  583. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('properties').everyProperty('group.n', 'n2')).to.equal(true);
  584. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('parentConfigGroup.n')).to.equal('n1');
  585. });
  586. });
  587. describe('#_getDisplayedConfigGroups', function () {
  588. it('should return [] if no selected group', function () {
  589. installerStep7Controller.reopen({
  590. content: {services: []},
  591. selectedConfigGroup: null
  592. });
  593. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([]);
  594. });
  595. it('should return default config group if another selected', function () {
  596. var defaultGroup = Em.Object.create({isDefault: false});
  597. installerStep7Controller.reopen({
  598. content: {services: []},
  599. selectedConfigGroup: defaultGroup
  600. });
  601. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([defaultGroup]);
  602. });
  603. it('should return other groups if default selected', function () {
  604. var defaultGroup = Em.Object.create({isDefault: true}),
  605. cfgG = Em.Object.create({isDefault: true}),
  606. configGroups = Em.A([
  607. Em.Object.create({isDefault: false}),
  608. Em.Object.create({isDefault: false}),
  609. cfgG,
  610. Em.Object.create({isDefault: false})
  611. ]);
  612. installerStep7Controller.reopen({
  613. content: {services: []},
  614. selectedConfigGroup: defaultGroup,
  615. selectedService: {configGroups: configGroups}
  616. });
  617. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql(configGroups.without(cfgG));
  618. });
  619. });
  620. describe('#_setEditableValue', function () {
  621. it('shouldn\'t update config if no selectedConfigGroup', function () {
  622. installerStep7Controller.reopen({
  623. selectedConfigGroup: null
  624. });
  625. var config = Em.Object.create({isEditable: null});
  626. var updatedConfig = installerStep7Controller._setEditableValue(config);
  627. expect(updatedConfig.get('isEditable')).to.be.null;
  628. });
  629. it('should set isEditable equal to selectedGroup.isDefault if service not installed', function () {
  630. var isDefault = true;
  631. installerStep7Controller.reopen({
  632. installedServiceNames: [],
  633. selectedService: {serviceName: 'abc'},
  634. selectedConfigGroup: Em.Object.create({isDefault: isDefault})
  635. });
  636. var config = Em.Object.create({isEditable: null});
  637. var updatedConfig = installerStep7Controller._setEditableValue(config);
  638. expect(updatedConfig.get('isEditable')).to.equal(isDefault);
  639. installerStep7Controller.toggleProperty('selectedConfigGroup.isDefault');
  640. updatedConfig = installerStep7Controller._setEditableValue(config);
  641. expect(updatedConfig.get('isEditable')).to.equal(!isDefault);
  642. });
  643. Em.A([
  644. {
  645. isEditable: false,
  646. isReconfigurable: false,
  647. isDefault: true,
  648. e: false
  649. },
  650. {
  651. isEditable: true,
  652. isReconfigurable: true,
  653. isDefault: true,
  654. e: true
  655. },
  656. {
  657. isEditable: false,
  658. isReconfigurable: true,
  659. isDefault: false,
  660. e: false
  661. },
  662. {
  663. isEditable: true,
  664. isReconfigurable: false,
  665. isDefault: false,
  666. e: false
  667. }
  668. ]).forEach(function (test) {
  669. it('service installed, isEditable = ' + test.isEditable.toString() + ', isReconfigurable = ' + test.isReconfigurable.toString(), function () {
  670. var config = Em.Object.create({
  671. isReconfigurable: test.isReconfigurable,
  672. isEditable: test.isEditable
  673. });
  674. installerStep7Controller.reopen({
  675. installedServiceNames: Em.A(['a']),
  676. selectedService: Em.Object.create({serviceName: 'a'}),
  677. selectedConfigGroup: Em.Object.create({isDefault: test.isDefault})
  678. });
  679. var updateConfig = installerStep7Controller._setEditableValue(config);
  680. expect(updateConfig.get('isEditable')).to.equal(test.e);
  681. });
  682. });
  683. });
  684. describe('#_setOverrides', function () {
  685. it('shouldn\'t update config if no selectedConfigGroup', function () {
  686. installerStep7Controller.reopen({
  687. selectedConfigGroup: null
  688. });
  689. var config = Em.Object.create({overrides: null});
  690. var updatedConfig = installerStep7Controller._setOverrides(config, []);
  691. expect(updatedConfig.get('overrides')).to.be.null;
  692. });
  693. it('no overrideToAdd', function () {
  694. var isDefault = true,
  695. name = 'n1',
  696. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  697. overrides = Em.A([
  698. Em.Object.create({name: name, value: 'v1'}),
  699. Em.Object.create({name: name, value: 'v2'}),
  700. Em.Object.create({name: 'n2', value: 'v3'})
  701. ]);
  702. installerStep7Controller.reopen({
  703. overrideToAdd: null,
  704. selectedConfigGroup: Em.Object.create({
  705. isDefault: isDefault
  706. })
  707. });
  708. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  709. expect(updatedConfig.get('overrides.length')).to.equal(2);
  710. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  711. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  712. });
  713. it('overrideToAdd exists', function () {
  714. var isDefault = true,
  715. name = 'n1',
  716. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  717. overrides = Em.A([
  718. Em.Object.create({name: name, value: 'v1'}),
  719. Em.Object.create({name: name, value: 'v2'}),
  720. Em.Object.create({name: 'n2', value: 'v3'})
  721. ]);
  722. installerStep7Controller.reopen({
  723. overrideToAdd: Em.Object.create({name: name}),
  724. selectedService: {configGroups: [Em.Object.create({name: 'n', properties: []})]},
  725. selectedConfigGroup: Em.Object.create({
  726. isDefault: isDefault,
  727. name: 'n'
  728. })
  729. });
  730. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  731. expect(updatedConfig.get('overrides.length')).to.equal(3);
  732. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  733. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  734. });
  735. });
  736. describe('#switchConfigGroupConfigs', function () {
  737. it('if selectedConfigGroup is null, serviceConfigs shouldn\'t be changed', function () {
  738. installerStep7Controller.reopen({
  739. selectedConfigGroup: null,
  740. content: {services: []},
  741. serviceConfigs: {configs: [
  742. {overrides: []},
  743. {overrides: []}
  744. ]}
  745. });
  746. installerStep7Controller.switchConfigGroupConfigs();
  747. expect(installerStep7Controller.get('serviceConfigs.configs').everyProperty('overrides.length', 0)).to.equal(true);
  748. });
  749. it('should set configs for serviceConfigs', function () {
  750. var configGroups = [
  751. Em.Object.create({
  752. properties: [
  753. {name: 'g1', value: 'v1'},
  754. {name: 'g2', value: 'v2'}
  755. ]
  756. })
  757. ];
  758. sinon.stub(installerStep7Controller, '_getDisplayedConfigGroups', function () {
  759. return configGroups;
  760. });
  761. sinon.stub(installerStep7Controller, '_setEditableValue', function (config) {
  762. config.set('isEditable', true);
  763. return config;
  764. });
  765. installerStep7Controller.reopen({
  766. selectedConfigGroup: Em.Object.create({isDefault: true, name: 'g1'}),
  767. content: {services: []},
  768. selectedService: {configs: Em.A([Em.Object.create({name: 'g1', overrides: [], properties: []}), Em.Object.create({name: 'g2', overrides: []})])},
  769. serviceConfigs: {configs: [Em.Object.create({name: 'g1'})]}
  770. });
  771. installerStep7Controller.switchConfigGroupConfigs();
  772. var configs = installerStep7Controller.get('selectedService.configs');
  773. expect(configs.findProperty('name', 'g1').get('overrides').length).to.equal(1);
  774. expect(configs.findProperty('name', 'g2').get('overrides').length).to.equal(1);
  775. expect(configs.everyProperty('isEditable', true)).to.equal(true);
  776. installerStep7Controller._getDisplayedConfigGroups.restore();
  777. installerStep7Controller._setEditableValue.restore();
  778. });
  779. });
  780. describe('#selectProperService', function () {
  781. Em.A([
  782. {
  783. name: 'addServiceController',
  784. stepConfigs: [
  785. {selected: false, name: 'n1'},
  786. {selected: true, name: 'n2'},
  787. {selected: true, name: 'n3'}
  788. ],
  789. e: 'n2'
  790. },
  791. {
  792. name: 'installerController',
  793. stepConfigs: [
  794. {showConfig: false, name: 'n1'},
  795. {showConfig: false, name: 'n2'},
  796. {showConfig: true, name: 'n3'}
  797. ],
  798. e: 'n3'
  799. }
  800. ]).forEach(function (test) {
  801. it(test.name, function () {
  802. sinon.stub(installerStep7Controller, 'selectedServiceObserver', Em.K);
  803. installerStep7Controller.reopen({
  804. wizardController: Em.Object.create({
  805. name: test.name
  806. }),
  807. stepConfigs: test.stepConfigs
  808. });
  809. installerStep7Controller.selectProperService();
  810. expect(installerStep7Controller.get('selectedService.name')).to.equal(test.e);
  811. installerStep7Controller.selectedServiceObserver.restore();
  812. });
  813. });
  814. });
  815. describe('#setStepConfigs', function () {
  816. beforeEach(function () {
  817. installerStep7Controller.reopen({
  818. content: {services: []},
  819. wizardController: Em.Object.create({
  820. getDBProperty: function (key) {
  821. return this.get(key);
  822. }
  823. })
  824. });
  825. });
  826. afterEach(function () {
  827. App.config.renderConfigs.restore();
  828. });
  829. it('if wizard isn\'t addService, should set output of App.config.renderConfigs', function () {
  830. var serviceConfigs = Em.A([
  831. {},
  832. {}
  833. ]);
  834. sinon.stub(App.config, 'renderConfigs', function () {
  835. return serviceConfigs;
  836. });
  837. installerStep7Controller.set('wizardController.name', 'installerController');
  838. installerStep7Controller.setStepConfigs([], []);
  839. expect(installerStep7Controller.get('stepConfigs')).to.eql(serviceConfigs);
  840. });
  841. it('addServiceWizard used', function () {
  842. var serviceConfigs = Em.A([Em.Object.create({serviceName: 's1'}), Em.Object.create({serviceName: 's2'})]);
  843. installerStep7Controller.set('wizardController.name', 'addServiceController');
  844. installerStep7Controller.reopen({selectedServiceNames: ['s2']});
  845. sinon.stub(App.config, 'renderConfigs', function () {
  846. return serviceConfigs;
  847. });
  848. installerStep7Controller.setStepConfigs([], []);
  849. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  850. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 's2').get('selected')).to.equal(true);
  851. });
  852. it('addServiceWizard used, HA enabled', function () {
  853. sinon.stub(App, 'get', function (k) {
  854. if (k === 'isHaEnabled') {
  855. return true;
  856. }
  857. return Em.get(App, k);
  858. });
  859. var serviceConfigs = Em.A([
  860. Em.Object.create({
  861. serviceName: 'HDFS',
  862. configs: [
  863. {category: 'SECONDARY_NAMENODE'},
  864. {category: 'SECONDARY_NAMENODE'},
  865. {category: 'NameNode'},
  866. {category: 'NameNode'},
  867. {category: 'SECONDARY_NAMENODE'}
  868. ]
  869. }),
  870. Em.Object.create({serviceName: 's2'})]
  871. );
  872. installerStep7Controller.set('wizardController.name', 'addServiceController');
  873. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  874. sinon.stub(App.config, 'renderConfigs', function () {
  875. return serviceConfigs;
  876. });
  877. installerStep7Controller.setStepConfigs([], []);
  878. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  879. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('selected')).to.equal(true);
  880. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  881. App.get.restore();
  882. });
  883. });
  884. describe('#checkHostOverrideInstaller', function () {
  885. beforeEach(function () {
  886. sinon.stub(installerStep7Controller, 'loadConfigGroups', Em.K);
  887. sinon.stub(installerStep7Controller, 'loadInstalledServicesConfigGroups', Em.K);
  888. });
  889. afterEach(function () {
  890. installerStep7Controller.loadConfigGroups.restore();
  891. installerStep7Controller.loadInstalledServicesConfigGroups.restore();
  892. App.get.restore();
  893. });
  894. Em.A([
  895. {
  896. installedServiceNames: [],
  897. m: 'installedServiceNames is empty',
  898. e: {
  899. loadConfigGroups: true,
  900. loadInstalledServicesConfigGroups: false
  901. }
  902. },
  903. {
  904. installedServiceNames: ['s1', 's2', 's3'],
  905. m: 'installedServiceNames isn\'t empty',
  906. e: {
  907. loadConfigGroups: true,
  908. loadInstalledServicesConfigGroups: true
  909. }
  910. }
  911. ]).forEach(function (test) {
  912. it(test.m, function () {
  913. sinon.stub(App, 'get', function (k) {
  914. if (k === 'supports.hostOverridesInstaller') return test.hostOverridesInstaller;
  915. return Em.get(App, k);
  916. });
  917. installerStep7Controller.reopen({installedServiceNames: test.installedServiceNames});
  918. installerStep7Controller.checkHostOverrideInstaller();
  919. if (test.e.loadConfigGroups) {
  920. expect(installerStep7Controller.loadConfigGroups.calledOnce).to.equal(true);
  921. }
  922. else {
  923. expect(installerStep7Controller.loadConfigGroups.called).to.equal(false);
  924. }
  925. if (test.e.loadInstalledServicesConfigGroups) {
  926. expect(installerStep7Controller.loadInstalledServicesConfigGroups.calledOnce).to.equal(true);
  927. }
  928. else {
  929. expect(installerStep7Controller.loadInstalledServicesConfigGroups.called).to.equal(false);
  930. }
  931. });
  932. });
  933. });
  934. describe('#loadStep', function () {
  935. beforeEach(function () {
  936. installerStep7Controller.reopen({
  937. content: {services: []},
  938. wizardController: Em.Object.create({
  939. getDBProperty: function (k) {
  940. return this.get(k);
  941. }
  942. })
  943. });
  944. sinon.stub(App.config, 'mergePreDefinedWithStored', Em.K);
  945. sinon.stub(App.config, 'addAdvancedConfigs', Em.K);
  946. sinon.stub(App.config, 'addCustomConfigs', Em.K);
  947. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  948. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  949. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  950. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  951. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  952. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  953. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  954. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  955. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  956. sinon.stub(installerStep7Controller, 'applyServicesConfigs', Em.K);
  957. sinon.stub(App.router, 'send', Em.K);
  958. });
  959. afterEach(function () {
  960. App.config.mergePreDefinedWithStored.restore();
  961. App.config.addAdvancedConfigs.restore();
  962. App.config.addCustomConfigs.restore();
  963. App.config.fileConfigsIntoTextarea.restore();
  964. installerStep7Controller.clearStep.restore();
  965. installerStep7Controller.getConfigTags.restore();
  966. installerStep7Controller.setInstalledServiceConfigs.restore();
  967. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  968. installerStep7Controller.setStepConfigs.restore();
  969. installerStep7Controller.checkHostOverrideInstaller.restore();
  970. installerStep7Controller.activateSpecialConfigs.restore();
  971. installerStep7Controller.selectProperService.restore();
  972. installerStep7Controller.applyServicesConfigs.restore();
  973. App.router.send.restore();
  974. });
  975. it('should call clearStep', function () {
  976. installerStep7Controller.loadStep();
  977. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  978. });
  979. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  980. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  981. installerStep7Controller.loadStep();
  982. expect(installerStep7Controller.clearStep.called).to.equal(false);
  983. });
  984. it('should use App.config to map configs', function () {
  985. installerStep7Controller.loadStep();
  986. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  987. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  988. expect(App.config.addCustomConfigs.calledOnce).to.equal(true);
  989. });
  990. it('should call setInstalledServiceConfigs for addServiceController', function () {
  991. installerStep7Controller.set('wizardController.name', 'addServiceController');
  992. installerStep7Controller.loadStep();
  993. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  994. });
  995. });
  996. describe('#applyServicesConfigs', function() {
  997. beforeEach(function() {
  998. installerStep7Controller.reopen({
  999. allSelectedServiceNames: []
  1000. });
  1001. sinon.stub(App.config, 'fileConfigsIntoTextarea', function(configs) {
  1002. return configs;
  1003. });
  1004. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  1005. sinon.stub(installerStep7Controller, 'loadServerSideConfigsRecommendations', function() {
  1006. return $.Deferred().resolve();
  1007. });
  1008. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  1009. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  1010. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  1011. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  1012. sinon.stub(App.router, 'send', Em.K);
  1013. });
  1014. afterEach(function () {
  1015. App.config.fileConfigsIntoTextarea.restore();
  1016. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  1017. installerStep7Controller.loadServerSideConfigsRecommendations.restore();
  1018. installerStep7Controller.checkHostOverrideInstaller.restore();
  1019. installerStep7Controller.activateSpecialConfigs.restore();
  1020. installerStep7Controller.selectProperService.restore();
  1021. installerStep7Controller.setStepConfigs.restore();
  1022. App.router.send.restore();
  1023. });
  1024. it('should run some methods' , function () {
  1025. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1026. expect(installerStep7Controller.loadServerSideConfigsRecommendations.calledOnce).to.equal(true);
  1027. expect(installerStep7Controller.get('isRecommendedLoaded')).to.equal(true);
  1028. expect(installerStep7Controller.setStepConfigs.calledWith({name: 'configs'}, {name: 'storedConfigs'})).to.equal(true);
  1029. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1030. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1031. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1032. });
  1033. Em.A([
  1034. {
  1035. allSelectedServiceNames: ['YARN'],
  1036. fileConfigsIntoTextarea: true,
  1037. m: 'should run fileConfigsIntoTextarea and resolveServiceDependencyConfigs',
  1038. resolveServiceDependencyConfigs: true
  1039. },
  1040. {
  1041. allSelectedServiceNames: ['STORM'],
  1042. resolveServiceDependencyConfigs: true,
  1043. m: 'should run resolveServiceDependencyConfigs'
  1044. }
  1045. ]).forEach(function(t) {
  1046. it(t.m, function () {
  1047. installerStep7Controller.reopen({
  1048. allSelectedServiceNames: t.allSelectedServiceNames
  1049. });
  1050. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1051. if (t.fileConfigsIntoTextarea) {
  1052. expect(App.config.fileConfigsIntoTextarea.calledWith({name: 'configs'}, 'capacity-scheduler.xml')).to.equal(true);
  1053. } else {
  1054. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(false);
  1055. }
  1056. if (t.resolveServiceDependencyConfigs) {
  1057. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledWith(t.allSelectedServiceNames[0], {name: 'configs'})).to.equal(true);
  1058. } else {
  1059. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(false);
  1060. }
  1061. });
  1062. });
  1063. });
  1064. describe('#_updateValueForCheckBoxConfig', function () {
  1065. Em.A([
  1066. {
  1067. v: 'true',
  1068. e: true
  1069. },
  1070. {
  1071. v: 'false',
  1072. e: false
  1073. }
  1074. ]).forEach(function (test) {
  1075. it(test.v, function () {
  1076. var serviceConfigProperty = Em.Object.create({value: test.v});
  1077. installerStep7Controller._updateValueForCheckBoxConfig(serviceConfigProperty);
  1078. expect(serviceConfigProperty.get('value')).to.equal(test.e);
  1079. expect(serviceConfigProperty.get('defaultValue')).to.equal(test.e);
  1080. });
  1081. });
  1082. });
  1083. describe('#_updateIsEditableFlagForConfig', function () {
  1084. Em.A([
  1085. {
  1086. isAdmin: false,
  1087. isReconfigurable: false,
  1088. isHostsConfigsPage: true,
  1089. defaultGroupSelected: false,
  1090. m: 'false for non-admin users',
  1091. e: false
  1092. },
  1093. {
  1094. isAdmin: true,
  1095. isReconfigurable: false,
  1096. isHostsConfigsPage: true,
  1097. defaultGroupSelected: false,
  1098. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1099. e: false
  1100. },
  1101. {
  1102. isAdmin: true,
  1103. isReconfigurable: false,
  1104. isHostsConfigsPage: true,
  1105. defaultGroupSelected: true,
  1106. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1107. e: false
  1108. },
  1109. {
  1110. isAdmin: true,
  1111. isReconfigurable: false,
  1112. isHostsConfigsPage: false,
  1113. defaultGroupSelected: false,
  1114. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1115. e: false
  1116. },
  1117. {
  1118. isAdmin: true,
  1119. isReconfigurable: true,
  1120. isHostsConfigsPage: false,
  1121. defaultGroupSelected: true,
  1122. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1123. e: true
  1124. }
  1125. ]).forEach(function (test) {
  1126. it(test.m, function () {
  1127. sinon.stub(App, 'get', function (k) {
  1128. if (k === 'isAdmin') return test.isAdmin;
  1129. return Em.get(App, k);
  1130. });
  1131. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1132. var serviceConfigProperty = Em.Object.create({
  1133. isReconfigurable: test.isReconfigurable
  1134. });
  1135. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1136. App.get.restore();
  1137. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1138. });
  1139. });
  1140. });
  1141. describe('#_updateOverridesForConfig', function () {
  1142. it('should set empty array', function () {
  1143. var serviceConfigProperty = Em.Object.create({
  1144. overrides: null
  1145. }), component = Em.Object.create();
  1146. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1147. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1148. });
  1149. it('host overrides not supported', function () {
  1150. var serviceConfigProperty = Em.Object.create({
  1151. overrides: [
  1152. {value: 'new value'}
  1153. ]
  1154. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1155. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1156. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1157. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1158. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1159. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1160. });
  1161. it('host overrides supported', function () {
  1162. sinon.stub(App, 'get', function (k) {
  1163. if (k === 'supports.hostOverrides') return true;
  1164. return Em.get(App, k);
  1165. });
  1166. var serviceConfigProperty = Em.Object.create({
  1167. overrides: [
  1168. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1169. ]
  1170. }),
  1171. component = Em.Object.create({
  1172. selectedConfigGroup: {isDefault: true},
  1173. configGroups: Em.A([
  1174. Em.Object.create({name: 'n1', properties: []})
  1175. ])
  1176. });
  1177. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1178. App.get.restore();
  1179. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1180. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1181. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1182. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1183. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1184. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1185. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1186. });
  1187. });
  1188. });