step7_test.js 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460
  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. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  542. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(1);
  543. var group = installerStep7Controller.get('stepConfigs.firstObject.configGroups.firstObject');
  544. expect(group.get('name')).to.equal(serviceName + ' Default');
  545. expect(group.get('description').contains(serviceName)).to.equal(true);
  546. expect(group.get('isDefault')).to.equal(true);
  547. expect(group.get('hosts')).to.eql(['h1', 'h2', 'h3']);
  548. expect(group.get('service.id')).to.equal(serviceName);
  549. expect(group.get('serviceName')).to.equal(serviceName);
  550. });
  551. it('should update configGroups for service (only default group)', function () {
  552. var configGroups = [],
  553. serviceName = 'HDFS',
  554. serviceConfigGroups = [
  555. {service: {id: 'HDFS'}, isDefault: true, n: 'n1'}
  556. ];
  557. installerStep7Controller.reopen({
  558. stepConfigs: [Em.Object.create({serviceName: serviceName, displayName: serviceName, configGroups: configGroups})]
  559. });
  560. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  561. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  562. });
  563. it('should update configGroups for service', function () {
  564. var configGroups = [],
  565. serviceName = 'HDFS',
  566. properties = [
  567. { name: "p1", filename: "file.xml" },
  568. { name: "p2", filename: "file.xml" }
  569. ],
  570. serviceConfigGroups = [
  571. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: true, n: 'n1'},
  572. {service: {id: 'HDFS'}, properties: properties.slice(), isDefault: false, n: 'n2'}
  573. ];
  574. installerStep7Controller.reopen({
  575. stepConfigs: [Em.Object.create({serviceName: serviceName, configGroups: configGroups, configs: properties})]
  576. });
  577. installerStep7Controller.loadConfigGroups(serviceConfigGroups);
  578. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups.length')).to.equal(2);
  579. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault').get('n')).to.equal('n1');
  580. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('properties').everyProperty('group.n', 'n2')).to.equal(true);
  581. expect(installerStep7Controller.get('stepConfigs.firstObject.configGroups').findProperty('isDefault', false).get('parentConfigGroup.n')).to.equal('n1');
  582. });
  583. });
  584. describe('#_getDisplayedConfigGroups', function () {
  585. it('should return [] if no selected group', function () {
  586. installerStep7Controller.reopen({
  587. content: {services: []},
  588. selectedConfigGroup: null
  589. });
  590. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([]);
  591. });
  592. it('should return default config group if another selected', function () {
  593. var defaultGroup = Em.Object.create({isDefault: false});
  594. installerStep7Controller.reopen({
  595. content: {services: []},
  596. selectedConfigGroup: defaultGroup
  597. });
  598. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql([defaultGroup]);
  599. });
  600. it('should return other groups if default selected', function () {
  601. var defaultGroup = Em.Object.create({isDefault: true}),
  602. cfgG = Em.Object.create({isDefault: true}),
  603. configGroups = Em.A([
  604. Em.Object.create({isDefault: false}),
  605. Em.Object.create({isDefault: false}),
  606. cfgG,
  607. Em.Object.create({isDefault: false})
  608. ]);
  609. installerStep7Controller.reopen({
  610. content: {services: []},
  611. selectedConfigGroup: defaultGroup,
  612. selectedService: {configGroups: configGroups}
  613. });
  614. expect(installerStep7Controller._getDisplayedConfigGroups()).to.eql(configGroups.without(cfgG));
  615. });
  616. });
  617. describe('#_setEditableValue', function () {
  618. it('shouldn\'t update config if no selectedConfigGroup', function () {
  619. installerStep7Controller.reopen({
  620. selectedConfigGroup: null
  621. });
  622. var config = Em.Object.create({isEditable: null});
  623. var updatedConfig = installerStep7Controller._setEditableValue(config);
  624. expect(updatedConfig.get('isEditable')).to.be.null;
  625. });
  626. it('should set isEditable equal to selectedGroup.isDefault if service not installed', function () {
  627. var isDefault = true;
  628. installerStep7Controller.reopen({
  629. installedServiceNames: [],
  630. selectedService: {serviceName: 'abc'},
  631. selectedConfigGroup: Em.Object.create({isDefault: isDefault})
  632. });
  633. var config = Em.Object.create({isEditable: null});
  634. var updatedConfig = installerStep7Controller._setEditableValue(config);
  635. expect(updatedConfig.get('isEditable')).to.equal(isDefault);
  636. installerStep7Controller.toggleProperty('selectedConfigGroup.isDefault');
  637. updatedConfig = installerStep7Controller._setEditableValue(config);
  638. expect(updatedConfig.get('isEditable')).to.equal(!isDefault);
  639. });
  640. Em.A([
  641. {
  642. isEditable: false,
  643. isReconfigurable: false,
  644. isDefault: true,
  645. e: false
  646. },
  647. {
  648. isEditable: true,
  649. isReconfigurable: true,
  650. isDefault: true,
  651. e: true
  652. },
  653. {
  654. isEditable: false,
  655. isReconfigurable: true,
  656. isDefault: false,
  657. e: false
  658. },
  659. {
  660. isEditable: true,
  661. isReconfigurable: false,
  662. isDefault: false,
  663. e: false
  664. }
  665. ]).forEach(function (test) {
  666. it('service installed, isEditable = ' + test.isEditable.toString() + ', isReconfigurable = ' + test.isReconfigurable.toString(), function () {
  667. var config = Em.Object.create({
  668. isReconfigurable: test.isReconfigurable,
  669. isEditable: test.isEditable
  670. });
  671. installerStep7Controller.reopen({
  672. installedServiceNames: Em.A(['a']),
  673. selectedService: Em.Object.create({serviceName: 'a'}),
  674. selectedConfigGroup: Em.Object.create({isDefault: test.isDefault})
  675. });
  676. var updateConfig = installerStep7Controller._setEditableValue(config);
  677. expect(updateConfig.get('isEditable')).to.equal(test.e);
  678. });
  679. });
  680. });
  681. describe('#_setOverrides', function () {
  682. it('shouldn\'t update config if no selectedConfigGroup', function () {
  683. installerStep7Controller.reopen({
  684. selectedConfigGroup: null
  685. });
  686. var config = Em.Object.create({overrides: null});
  687. var updatedConfig = installerStep7Controller._setOverrides(config, []);
  688. expect(updatedConfig.get('overrides')).to.be.null;
  689. });
  690. it('no overrideToAdd', function () {
  691. var isDefault = true,
  692. name = 'n1',
  693. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  694. overrides = Em.A([
  695. Em.Object.create({name: name, value: 'v1'}),
  696. Em.Object.create({name: name, value: 'v2'}),
  697. Em.Object.create({name: 'n2', value: 'v3'})
  698. ]);
  699. installerStep7Controller.reopen({
  700. overrideToAdd: null,
  701. selectedConfigGroup: Em.Object.create({
  702. isDefault: isDefault
  703. })
  704. });
  705. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  706. expect(updatedConfig.get('overrides.length')).to.equal(2);
  707. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  708. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  709. });
  710. it('overrideToAdd exists', function () {
  711. var isDefault = true,
  712. name = 'n1',
  713. config = Em.Object.create({overrides: null, name: name, flag: 'flag'}),
  714. overrides = Em.A([
  715. Em.Object.create({name: name, value: 'v1'}),
  716. Em.Object.create({name: name, value: 'v2'}),
  717. Em.Object.create({name: 'n2', value: 'v3'})
  718. ]);
  719. installerStep7Controller.reopen({
  720. overrideToAdd: Em.Object.create({name: name}),
  721. selectedService: {configGroups: [Em.Object.create({name: 'n', properties: []})]},
  722. selectedConfigGroup: Em.Object.create({
  723. isDefault: isDefault,
  724. name: 'n'
  725. })
  726. });
  727. var updatedConfig = installerStep7Controller._setOverrides(config, overrides);
  728. expect(updatedConfig.get('overrides.length')).to.equal(3);
  729. expect(updatedConfig.get('overrides').everyProperty('isEditable', !isDefault)).to.equal(true);
  730. expect(updatedConfig.get('overrides').everyProperty('parentSCP.flag', 'flag')).to.equal(true);
  731. });
  732. });
  733. describe('#switchConfigGroupConfigs', function () {
  734. it('if selectedConfigGroup is null, serviceConfigs shouldn\'t be changed', function () {
  735. installerStep7Controller.reopen({
  736. selectedConfigGroup: null,
  737. content: {services: []},
  738. serviceConfigs: {configs: [
  739. {overrides: []},
  740. {overrides: []}
  741. ]}
  742. });
  743. installerStep7Controller.switchConfigGroupConfigs();
  744. expect(installerStep7Controller.get('serviceConfigs.configs').everyProperty('overrides.length', 0)).to.equal(true);
  745. });
  746. it('should set configs for serviceConfigs', function () {
  747. var configGroups = [
  748. Em.Object.create({
  749. properties: [
  750. {name: 'g1', value: 'v1'},
  751. {name: 'g2', value: 'v2'}
  752. ]
  753. })
  754. ];
  755. sinon.stub(installerStep7Controller, '_getDisplayedConfigGroups', function () {
  756. return configGroups;
  757. });
  758. sinon.stub(installerStep7Controller, '_setEditableValue', function (config) {
  759. config.set('isEditable', true);
  760. return config;
  761. });
  762. installerStep7Controller.reopen({
  763. selectedConfigGroup: Em.Object.create({isDefault: true, name: 'g1'}),
  764. content: {services: []},
  765. selectedService: {configs: Em.A([Em.Object.create({name: 'g1', overrides: [], properties: []}), Em.Object.create({name: 'g2', overrides: []})])},
  766. serviceConfigs: {configs: [Em.Object.create({name: 'g1'})]}
  767. });
  768. installerStep7Controller.switchConfigGroupConfigs();
  769. var configs = installerStep7Controller.get('selectedService.configs');
  770. expect(configs.findProperty('name', 'g1').get('overrides').length).to.equal(1);
  771. expect(configs.findProperty('name', 'g2').get('overrides').length).to.equal(1);
  772. expect(configs.everyProperty('isEditable', true)).to.equal(true);
  773. installerStep7Controller._getDisplayedConfigGroups.restore();
  774. installerStep7Controller._setEditableValue.restore();
  775. });
  776. });
  777. describe('#selectProperService', function () {
  778. Em.A([
  779. {
  780. name: 'addServiceController',
  781. stepConfigs: [
  782. {selected: false, name: 'n1'},
  783. {selected: true, name: 'n2'},
  784. {selected: true, name: 'n3'}
  785. ],
  786. e: 'n2'
  787. },
  788. {
  789. name: 'installerController',
  790. stepConfigs: [
  791. {showConfig: false, name: 'n1'},
  792. {showConfig: false, name: 'n2'},
  793. {showConfig: true, name: 'n3'}
  794. ],
  795. e: 'n3'
  796. }
  797. ]).forEach(function (test) {
  798. it(test.name, function () {
  799. sinon.stub(installerStep7Controller, 'selectedServiceObserver', Em.K);
  800. installerStep7Controller.reopen({
  801. wizardController: Em.Object.create({
  802. name: test.name
  803. }),
  804. stepConfigs: test.stepConfigs
  805. });
  806. installerStep7Controller.selectProperService();
  807. expect(installerStep7Controller.get('selectedService.name')).to.equal(test.e);
  808. installerStep7Controller.selectedServiceObserver.restore();
  809. });
  810. });
  811. });
  812. describe('#setStepConfigs', function () {
  813. beforeEach(function () {
  814. installerStep7Controller.reopen({
  815. content: {services: []},
  816. wizardController: Em.Object.create({
  817. getDBProperty: function (key) {
  818. return this.get(key);
  819. }
  820. })
  821. });
  822. });
  823. afterEach(function () {
  824. App.config.renderConfigs.restore();
  825. });
  826. it('if wizard isn\'t addService, should set output of App.config.renderConfigs', function () {
  827. var serviceConfigs = Em.A([
  828. {serviceName:'HDFS', configs: []},
  829. {}
  830. ]);
  831. sinon.stub(App.config, 'renderConfigs', function () {
  832. return serviceConfigs;
  833. });
  834. installerStep7Controller.set('wizardController.name', 'installerController');
  835. installerStep7Controller.setStepConfigs([], []);
  836. expect(installerStep7Controller.get('stepConfigs')).to.eql(serviceConfigs);
  837. });
  838. it('addServiceWizard used', function () {
  839. var serviceConfigs = Em.A([Em.Object.create({serviceName: 'HDFS', configs: []}), Em.Object.create({serviceName: 's2'})]);
  840. installerStep7Controller.set('wizardController.name', 'addServiceController');
  841. installerStep7Controller.reopen({selectedServiceNames: ['s2']});
  842. sinon.stub(App.config, 'renderConfigs', function () {
  843. return serviceConfigs;
  844. });
  845. installerStep7Controller.setStepConfigs([], []);
  846. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  847. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 's2').get('selected')).to.equal(true);
  848. });
  849. it('addServiceWizard used, HA enabled', function () {
  850. sinon.stub(App, 'get', function (k) {
  851. if (k === 'isHaEnabled') {
  852. return true;
  853. }
  854. return Em.get(App, k);
  855. });
  856. var serviceConfigs = Em.A([
  857. Em.Object.create({
  858. serviceName: 'HDFS',
  859. configs: [
  860. {category: 'SECONDARY_NAMENODE'},
  861. {category: 'SECONDARY_NAMENODE'},
  862. {category: 'NameNode'},
  863. {category: 'NameNode'},
  864. {category: 'SECONDARY_NAMENODE'}
  865. ]
  866. }),
  867. Em.Object.create({serviceName: 's2'})]
  868. );
  869. installerStep7Controller.set('wizardController.name', 'addServiceController');
  870. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  871. sinon.stub(App.config, 'renderConfigs', function () {
  872. return serviceConfigs;
  873. });
  874. installerStep7Controller.setStepConfigs([], []);
  875. expect(installerStep7Controller.get('stepConfigs').everyProperty('showConfig', true)).to.equal(true);
  876. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('selected')).to.equal(true);
  877. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  878. App.get.restore();
  879. });
  880. it('not windows stack', function () {
  881. var s = sinon.stub(App, 'get');
  882. s.withArgs('isHadoopWindowsStack').returns(false);
  883. s.withArgs('isHaEnabled').returns(false);
  884. var serviceConfigs = Em.A([
  885. Em.Object.create({
  886. serviceName: 'HDFS',
  887. configs: [
  888. {category: 'NameNode'},
  889. {category: 'NameNode'}
  890. ]
  891. }),
  892. Em.Object.create({serviceName: 's2'})]
  893. );
  894. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  895. sinon.stub(App.config, 'renderConfigs', function () {
  896. return serviceConfigs;
  897. });
  898. installerStep7Controller.setStepConfigs([], []);
  899. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  900. s.restore();
  901. });
  902. it('windows stack', function () {
  903. var s = sinon.stub(App, 'get');
  904. s.withArgs('isHadoopWindowsStack').returns(true);
  905. s.withArgs('isHaEnabled').returns(false);
  906. var serviceConfigs = Em.A([
  907. Em.Object.create({
  908. serviceName: 'HDFS',
  909. configs: [
  910. {category: 'NameNode'},
  911. {category: 'NameNode'}
  912. ]
  913. }),
  914. Em.Object.create({serviceName: 's2'})]
  915. );
  916. installerStep7Controller.reopen({selectedServiceNames: ['HDFS', 's2']});
  917. sinon.stub(App.config, 'renderConfigs', function () {
  918. return serviceConfigs;
  919. });
  920. installerStep7Controller.setStepConfigs([], []);
  921. expect(installerStep7Controller.get('stepConfigs').findProperty('serviceName', 'HDFS').get('configs').length).to.equal(2);
  922. s.restore();
  923. });
  924. });
  925. describe('#checkHostOverrideInstaller', function () {
  926. beforeEach(function () {
  927. sinon.stub(installerStep7Controller, 'loadConfigGroups', Em.K);
  928. sinon.stub(installerStep7Controller, 'loadInstalledServicesConfigGroups', Em.K);
  929. });
  930. afterEach(function () {
  931. installerStep7Controller.loadConfigGroups.restore();
  932. installerStep7Controller.loadInstalledServicesConfigGroups.restore();
  933. App.get.restore();
  934. });
  935. Em.A([
  936. {
  937. installedServiceNames: [],
  938. m: 'installedServiceNames is empty',
  939. e: {
  940. loadConfigGroups: true,
  941. loadInstalledServicesConfigGroups: false
  942. }
  943. },
  944. {
  945. installedServiceNames: ['s1', 's2', 's3'],
  946. m: 'installedServiceNames isn\'t empty',
  947. e: {
  948. loadConfigGroups: true,
  949. loadInstalledServicesConfigGroups: true
  950. }
  951. }
  952. ]).forEach(function (test) {
  953. it(test.m, function () {
  954. sinon.stub(App, 'get', function (k) {
  955. if (k === 'supports.hostOverridesInstaller') return test.hostOverridesInstaller;
  956. return Em.get(App, k);
  957. });
  958. installerStep7Controller.reopen({installedServiceNames: test.installedServiceNames});
  959. installerStep7Controller.checkHostOverrideInstaller();
  960. if (test.e.loadConfigGroups) {
  961. expect(installerStep7Controller.loadConfigGroups.calledOnce).to.equal(true);
  962. }
  963. else {
  964. expect(installerStep7Controller.loadConfigGroups.called).to.equal(false);
  965. }
  966. if (test.e.loadInstalledServicesConfigGroups) {
  967. expect(installerStep7Controller.loadInstalledServicesConfigGroups.calledOnce).to.equal(true);
  968. }
  969. else {
  970. expect(installerStep7Controller.loadInstalledServicesConfigGroups.called).to.equal(false);
  971. }
  972. });
  973. });
  974. });
  975. describe('#loadStep', function () {
  976. beforeEach(function () {
  977. installerStep7Controller.reopen({
  978. content: {services: []},
  979. wizardController: Em.Object.create({
  980. getDBProperty: function (k) {
  981. return this.get(k);
  982. }
  983. })
  984. });
  985. sinon.stub(App.config, 'mergePreDefinedWithStored', Em.K);
  986. sinon.stub(App.config, 'addAdvancedConfigs', Em.K);
  987. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  988. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  989. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  990. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  991. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  992. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  993. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  994. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  995. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  996. sinon.stub(installerStep7Controller, 'applyServicesConfigs', Em.K);
  997. sinon.stub(App.router, 'send', Em.K);
  998. });
  999. afterEach(function () {
  1000. App.config.mergePreDefinedWithStored.restore();
  1001. App.config.addAdvancedConfigs.restore();
  1002. App.config.fileConfigsIntoTextarea.restore();
  1003. installerStep7Controller.clearStep.restore();
  1004. installerStep7Controller.getConfigTags.restore();
  1005. installerStep7Controller.setInstalledServiceConfigs.restore();
  1006. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  1007. installerStep7Controller.setStepConfigs.restore();
  1008. installerStep7Controller.checkHostOverrideInstaller.restore();
  1009. installerStep7Controller.activateSpecialConfigs.restore();
  1010. installerStep7Controller.selectProperService.restore();
  1011. installerStep7Controller.applyServicesConfigs.restore();
  1012. App.router.send.restore();
  1013. });
  1014. it('should call clearStep', function () {
  1015. installerStep7Controller.loadStep();
  1016. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  1017. });
  1018. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  1019. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  1020. installerStep7Controller.loadStep();
  1021. expect(installerStep7Controller.clearStep.called).to.equal(false);
  1022. });
  1023. it('should use App.config to map configs', function () {
  1024. installerStep7Controller.loadStep();
  1025. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  1026. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  1027. });
  1028. it('should call setInstalledServiceConfigs for addServiceController', function () {
  1029. installerStep7Controller.set('wizardController.name', 'addServiceController');
  1030. installerStep7Controller.loadStep();
  1031. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  1032. });
  1033. });
  1034. describe('#applyServicesConfigs', function() {
  1035. beforeEach(function() {
  1036. installerStep7Controller.reopen({
  1037. allSelectedServiceNames: []
  1038. });
  1039. sinon.stub(App.config, 'fileConfigsIntoTextarea', function(configs) {
  1040. return configs;
  1041. });
  1042. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  1043. sinon.stub(installerStep7Controller, 'loadServerSideConfigsRecommendations', function() {
  1044. return $.Deferred().resolve();
  1045. });
  1046. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  1047. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  1048. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  1049. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  1050. sinon.stub(App.router, 'send', Em.K);
  1051. });
  1052. afterEach(function () {
  1053. App.config.fileConfigsIntoTextarea.restore();
  1054. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  1055. installerStep7Controller.loadServerSideConfigsRecommendations.restore();
  1056. installerStep7Controller.checkHostOverrideInstaller.restore();
  1057. installerStep7Controller.activateSpecialConfigs.restore();
  1058. installerStep7Controller.selectProperService.restore();
  1059. installerStep7Controller.setStepConfigs.restore();
  1060. App.router.send.restore();
  1061. });
  1062. it('should run some methods' , function () {
  1063. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1064. expect(installerStep7Controller.loadServerSideConfigsRecommendations.calledOnce).to.equal(true);
  1065. expect(installerStep7Controller.get('isRecommendedLoaded')).to.equal(true);
  1066. expect(installerStep7Controller.setStepConfigs.calledWith({name: 'configs'}, {name: 'storedConfigs'})).to.equal(true);
  1067. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1068. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1069. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1070. });
  1071. Em.A([
  1072. {
  1073. allSelectedServiceNames: ['YARN'],
  1074. fileConfigsIntoTextarea: true,
  1075. m: 'should run fileConfigsIntoTextarea and resolveServiceDependencyConfigs',
  1076. resolveServiceDependencyConfigs: true
  1077. },
  1078. {
  1079. allSelectedServiceNames: ['STORM'],
  1080. resolveServiceDependencyConfigs: true,
  1081. m: 'should run resolveServiceDependencyConfigs'
  1082. }
  1083. ]).forEach(function(t) {
  1084. it(t.m, function () {
  1085. installerStep7Controller.reopen({
  1086. allSelectedServiceNames: t.allSelectedServiceNames
  1087. });
  1088. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1089. if (t.fileConfigsIntoTextarea) {
  1090. expect(App.config.fileConfigsIntoTextarea.calledWith({name: 'configs'}, 'capacity-scheduler.xml')).to.equal(true);
  1091. } else {
  1092. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(false);
  1093. }
  1094. if (t.resolveServiceDependencyConfigs) {
  1095. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledWith(t.allSelectedServiceNames[0], {name: 'configs'})).to.equal(true);
  1096. } else {
  1097. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(false);
  1098. }
  1099. });
  1100. });
  1101. });
  1102. describe('#_updateIsEditableFlagForConfig', function () {
  1103. beforeEach(function(){
  1104. this.mock = sinon.stub(App, 'isAccessible');
  1105. });
  1106. afterEach(function () {
  1107. this.mock.restore();
  1108. });
  1109. Em.A([
  1110. {
  1111. isAdmin: false,
  1112. isReconfigurable: false,
  1113. isHostsConfigsPage: true,
  1114. defaultGroupSelected: false,
  1115. m: 'false for non-admin users',
  1116. e: false
  1117. },
  1118. {
  1119. isAdmin: true,
  1120. isReconfigurable: false,
  1121. isHostsConfigsPage: true,
  1122. defaultGroupSelected: false,
  1123. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1124. e: false
  1125. },
  1126. {
  1127. isAdmin: true,
  1128. isReconfigurable: false,
  1129. isHostsConfigsPage: true,
  1130. defaultGroupSelected: true,
  1131. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1132. e: false
  1133. },
  1134. {
  1135. isAdmin: true,
  1136. isReconfigurable: false,
  1137. isHostsConfigsPage: false,
  1138. defaultGroupSelected: false,
  1139. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1140. e: false
  1141. },
  1142. {
  1143. isAdmin: true,
  1144. isReconfigurable: true,
  1145. isHostsConfigsPage: false,
  1146. defaultGroupSelected: true,
  1147. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1148. e: true
  1149. }
  1150. ]).forEach(function (test) {
  1151. it(test.m, function () {
  1152. this.mock.returns(test.isAdmin);
  1153. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1154. var serviceConfigProperty = Em.Object.create({
  1155. isReconfigurable: test.isReconfigurable
  1156. });
  1157. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1158. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1159. });
  1160. });
  1161. });
  1162. describe('#_updateOverridesForConfig', function () {
  1163. it('should set empty array', function () {
  1164. var serviceConfigProperty = Em.Object.create({
  1165. overrides: null
  1166. }), component = Em.Object.create();
  1167. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1168. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1169. });
  1170. it('host overrides not supported', function () {
  1171. var serviceConfigProperty = Em.Object.create({
  1172. overrides: [
  1173. {value: 'new value'}
  1174. ]
  1175. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1176. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1177. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1178. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1179. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1180. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1181. });
  1182. it('host overrides supported', function () {
  1183. sinon.stub(App, 'get', function (k) {
  1184. if (k === 'supports.hostOverrides') return true;
  1185. return Em.get(App, k);
  1186. });
  1187. var serviceConfigProperty = Em.Object.create({
  1188. overrides: [
  1189. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1190. ]
  1191. }),
  1192. component = Em.Object.create({
  1193. selectedConfigGroup: {isDefault: true},
  1194. configGroups: Em.A([
  1195. Em.Object.create({name: 'n1', properties: []})
  1196. ])
  1197. });
  1198. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1199. App.get.restore();
  1200. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1201. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1202. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1203. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1204. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1205. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1206. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1207. });
  1208. });
  1209. describe('#setInstalledServiceConfigs', function () {
  1210. var controller = App.WizardStep7Controller.create({
  1211. installedServiceNames: ['HBASE', 'AMBARI_METRICS']
  1212. }),
  1213. serviceConfigTags = [
  1214. {
  1215. siteName: 'hbase-site',
  1216. tagName: 'version1'
  1217. },
  1218. {
  1219. siteName: 'ams-hbase-site',
  1220. tagName: 'version1'
  1221. },
  1222. {
  1223. siteName: 'site-without-properties',
  1224. tagName: 'version1'
  1225. }
  1226. ],
  1227. configs = [
  1228. {
  1229. name: 'hbase.client.scanner.caching',
  1230. value: '1000',
  1231. serviceName: 'HBASE',
  1232. filename: 'hbase-site.xml'
  1233. },
  1234. {
  1235. name: 'hbase.client.scanner.caching',
  1236. value: '2000',
  1237. serviceName: 'AMBARI_METRICS',
  1238. filename: 'ams-hbase-site.xml'
  1239. }
  1240. ],
  1241. configsByTags = [
  1242. {
  1243. type: 'hbase-site',
  1244. tag: 'version2',
  1245. properties: {
  1246. 'hbase.client.scanner.caching': '1500'
  1247. }
  1248. },
  1249. {
  1250. type: 'ams-hbase-site',
  1251. tag: 'version2',
  1252. properties: {
  1253. 'hbase.client.scanner.caching': '2500'
  1254. }
  1255. },
  1256. {
  1257. type: 'site-without-properties',
  1258. tag: 'version1'
  1259. }
  1260. ],
  1261. installedServiceNames = ['HBASE', 'AMBARI_METRICS'];
  1262. it('should handle properties with the same name', function () {
  1263. controller.setInstalledServiceConfigs(serviceConfigTags, configs, configsByTags, installedServiceNames);
  1264. var properties = configs.filterProperty('name', 'hbase.client.scanner.caching');
  1265. expect(properties).to.have.length(2);
  1266. expect(properties.findProperty('filename', 'hbase-site.xml').value).to.equal('1500');
  1267. expect(properties.findProperty('filename', 'hbase-site.xml').defaultValue).to.equal('1500');
  1268. expect(properties.findProperty('filename', 'ams-hbase-site.xml').value).to.equal('2500');
  1269. expect(properties.findProperty('filename', 'ams-hbase-site.xml').defaultValue).to.equal('2500');
  1270. });
  1271. });
  1272. describe('#getAmbariDatabaseSuccess', function () {
  1273. var controller = App.WizardStep7Controller.create({
  1274. stepConfigs: [
  1275. {
  1276. serviceName: 'HIVE',
  1277. configs: [
  1278. {
  1279. name: 'hive_ambari_host',
  1280. value: 'h0'
  1281. }
  1282. ]
  1283. }
  1284. ]
  1285. }),
  1286. cases = [
  1287. {
  1288. data: {
  1289. hostComponents: []
  1290. },
  1291. mySQLServerConflict: false,
  1292. title: 'no Ambari Server host components'
  1293. },
  1294. {
  1295. data: {
  1296. hostComponents: [
  1297. {
  1298. RootServiceHostComponents: {
  1299. properties: {
  1300. 'server.jdbc.url': 'jdbc:mysql://h0/db0?createDatabaseIfNotExist=true'
  1301. }
  1302. }
  1303. }
  1304. ]
  1305. },
  1306. mySQLServerConflict: true,
  1307. title: 'Ambari MySQL Server and Hive Server are on the same host'
  1308. },
  1309. {
  1310. data: {
  1311. hostComponents: [
  1312. {
  1313. RootServiceHostComponents: {
  1314. properties: {
  1315. 'server.jdbc.url': 'jdbc:mysql://h1/db1?createDatabaseIfNotExist=true'
  1316. }
  1317. }
  1318. }
  1319. ]
  1320. },
  1321. mySQLServerConflict: false,
  1322. title: 'Ambari MySQL Server and Hive Server are on different hosts'
  1323. }
  1324. ];
  1325. cases.forEach(function (item) {
  1326. it(item.title, function () {
  1327. controller.getAmbariDatabaseSuccess(item.data);
  1328. expect(controller.get('mySQLServerConflict')).to.equal(item.mySQLServerConflict);
  1329. });
  1330. });
  1331. });
  1332. describe('#showDatabaseConnectionWarningPopup', function () {
  1333. var cases = [
  1334. {
  1335. method: 'onSecondary',
  1336. submitButtonClicked: false,
  1337. isRejected: true,
  1338. title: 'Cancel button clicked'
  1339. },
  1340. {
  1341. method: 'onPrimary',
  1342. submitButtonClicked: true,
  1343. isResolved: true,
  1344. title: 'Proceed Anyway button clicked'
  1345. }
  1346. ],
  1347. dfd,
  1348. testObject,
  1349. serviceNames = ['HIVE', 'OOZIE'],
  1350. bodyMessage = 'HIVE, OOZIE';
  1351. beforeEach(function () {
  1352. installerStep7Controller.set('submitButtonClicked', true);
  1353. dfd = $.Deferred(function (d) {
  1354. d.done(function () {
  1355. testObject.isResolved = true;
  1356. });
  1357. d.fail(function () {
  1358. testObject.isRejected = true;
  1359. })
  1360. });
  1361. testObject = {};
  1362. });
  1363. cases.forEach(function (item) {
  1364. it(item.title, function () {
  1365. var popup = installerStep7Controller.showDatabaseConnectionWarningPopup(serviceNames, dfd);
  1366. expect(popup.get('body')).to.equal(Em.I18n.t('installer.step7.popup.database.connection.body').format(bodyMessage));
  1367. popup[item.method]();
  1368. expect(testObject.isResolved).to.equal(item.isResolved);
  1369. expect(testObject.isRejected).to.equal(item.isRejected);
  1370. expect(installerStep7Controller.get('submitButtonClicked')).to.equal(item.submitButtonClicked);
  1371. });
  1372. });
  1373. });
  1374. });