step7_test.js 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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, 'addCustomConfigs', Em.K);
  988. sinon.stub(App.config, 'fileConfigsIntoTextarea', Em.K);
  989. sinon.stub(installerStep7Controller, 'clearStep', Em.K);
  990. sinon.stub(installerStep7Controller, 'getConfigTags', Em.K);
  991. sinon.stub(installerStep7Controller, 'setInstalledServiceConfigs', Em.K);
  992. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  993. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  994. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  995. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  996. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  997. sinon.stub(installerStep7Controller, 'applyServicesConfigs', Em.K);
  998. sinon.stub(App.router, 'send', Em.K);
  999. });
  1000. afterEach(function () {
  1001. App.config.mergePreDefinedWithStored.restore();
  1002. App.config.addAdvancedConfigs.restore();
  1003. App.config.addCustomConfigs.restore();
  1004. App.config.fileConfigsIntoTextarea.restore();
  1005. installerStep7Controller.clearStep.restore();
  1006. installerStep7Controller.getConfigTags.restore();
  1007. installerStep7Controller.setInstalledServiceConfigs.restore();
  1008. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  1009. installerStep7Controller.setStepConfigs.restore();
  1010. installerStep7Controller.checkHostOverrideInstaller.restore();
  1011. installerStep7Controller.activateSpecialConfigs.restore();
  1012. installerStep7Controller.selectProperService.restore();
  1013. installerStep7Controller.applyServicesConfigs.restore();
  1014. App.router.send.restore();
  1015. });
  1016. it('should call clearStep', function () {
  1017. installerStep7Controller.loadStep();
  1018. expect(installerStep7Controller.clearStep.calledOnce).to.equal(true);
  1019. });
  1020. it('shouldn\'t do nothing if isAdvancedConfigLoaded is false', function () {
  1021. installerStep7Controller.set('isAdvancedConfigLoaded', false);
  1022. installerStep7Controller.loadStep();
  1023. expect(installerStep7Controller.clearStep.called).to.equal(false);
  1024. });
  1025. it('should use App.config to map configs', function () {
  1026. installerStep7Controller.loadStep();
  1027. expect(App.config.mergePreDefinedWithStored.calledOnce).to.equal(true);
  1028. expect(App.config.addAdvancedConfigs.calledOnce).to.equal(true);
  1029. expect(App.config.addCustomConfigs.calledOnce).to.equal(true);
  1030. });
  1031. it('should call setInstalledServiceConfigs for addServiceController', function () {
  1032. installerStep7Controller.set('wizardController.name', 'addServiceController');
  1033. installerStep7Controller.loadStep();
  1034. expect(installerStep7Controller.setInstalledServiceConfigs.calledOnce).to.equal(true);
  1035. });
  1036. });
  1037. describe('#applyServicesConfigs', function() {
  1038. beforeEach(function() {
  1039. installerStep7Controller.reopen({
  1040. allSelectedServiceNames: []
  1041. });
  1042. sinon.stub(App.config, 'fileConfigsIntoTextarea', function(configs) {
  1043. return configs;
  1044. });
  1045. sinon.stub(installerStep7Controller, 'resolveServiceDependencyConfigs', Em.K);
  1046. sinon.stub(installerStep7Controller, 'loadServerSideConfigsRecommendations', function() {
  1047. return $.Deferred().resolve();
  1048. });
  1049. sinon.stub(installerStep7Controller, 'checkHostOverrideInstaller', Em.K);
  1050. sinon.stub(installerStep7Controller, 'activateSpecialConfigs', Em.K);
  1051. sinon.stub(installerStep7Controller, 'selectProperService', Em.K);
  1052. sinon.stub(installerStep7Controller, 'setStepConfigs', Em.K);
  1053. sinon.stub(App.router, 'send', Em.K);
  1054. });
  1055. afterEach(function () {
  1056. App.config.fileConfigsIntoTextarea.restore();
  1057. installerStep7Controller.resolveServiceDependencyConfigs.restore();
  1058. installerStep7Controller.loadServerSideConfigsRecommendations.restore();
  1059. installerStep7Controller.checkHostOverrideInstaller.restore();
  1060. installerStep7Controller.activateSpecialConfigs.restore();
  1061. installerStep7Controller.selectProperService.restore();
  1062. installerStep7Controller.setStepConfigs.restore();
  1063. App.router.send.restore();
  1064. });
  1065. it('should run some methods' , function () {
  1066. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1067. expect(installerStep7Controller.loadServerSideConfigsRecommendations.calledOnce).to.equal(true);
  1068. expect(installerStep7Controller.get('isRecommendedLoaded')).to.equal(true);
  1069. expect(installerStep7Controller.setStepConfigs.calledWith({name: 'configs'}, {name: 'storedConfigs'})).to.equal(true);
  1070. expect(installerStep7Controller.checkHostOverrideInstaller.calledOnce).to.equal(true);
  1071. expect(installerStep7Controller.activateSpecialConfigs.calledOnce).to.equal(true);
  1072. expect(installerStep7Controller.selectProperService.calledOnce).to.equal(true);
  1073. });
  1074. Em.A([
  1075. {
  1076. allSelectedServiceNames: ['YARN'],
  1077. fileConfigsIntoTextarea: true,
  1078. m: 'should run fileConfigsIntoTextarea and resolveServiceDependencyConfigs',
  1079. resolveServiceDependencyConfigs: true
  1080. },
  1081. {
  1082. allSelectedServiceNames: ['STORM'],
  1083. resolveServiceDependencyConfigs: true,
  1084. m: 'should run resolveServiceDependencyConfigs'
  1085. }
  1086. ]).forEach(function(t) {
  1087. it(t.m, function () {
  1088. installerStep7Controller.reopen({
  1089. allSelectedServiceNames: t.allSelectedServiceNames
  1090. });
  1091. installerStep7Controller.applyServicesConfigs({name: 'configs'}, {name: 'storedConfigs'});
  1092. if (t.fileConfigsIntoTextarea) {
  1093. expect(App.config.fileConfigsIntoTextarea.calledWith({name: 'configs'}, 'capacity-scheduler.xml')).to.equal(true);
  1094. } else {
  1095. expect(App.config.fileConfigsIntoTextarea.calledOnce).to.equal(false);
  1096. }
  1097. if (t.resolveServiceDependencyConfigs) {
  1098. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledWith(t.allSelectedServiceNames[0], {name: 'configs'})).to.equal(true);
  1099. } else {
  1100. expect(installerStep7Controller.resolveServiceDependencyConfigs.calledOnce).to.equal(false);
  1101. }
  1102. });
  1103. });
  1104. });
  1105. describe('#_updateIsEditableFlagForConfig', function () {
  1106. beforeEach(function(){
  1107. this.mock = sinon.stub(App, 'isAccessible');
  1108. });
  1109. afterEach(function () {
  1110. this.mock.restore();
  1111. });
  1112. Em.A([
  1113. {
  1114. isAdmin: false,
  1115. isReconfigurable: false,
  1116. isHostsConfigsPage: true,
  1117. defaultGroupSelected: false,
  1118. m: 'false for non-admin users',
  1119. e: false
  1120. },
  1121. {
  1122. isAdmin: true,
  1123. isReconfigurable: false,
  1124. isHostsConfigsPage: true,
  1125. defaultGroupSelected: false,
  1126. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is true',
  1127. e: false
  1128. },
  1129. {
  1130. isAdmin: true,
  1131. isReconfigurable: false,
  1132. isHostsConfigsPage: true,
  1133. defaultGroupSelected: true,
  1134. m: 'false if defaultGroupSelected is true and isHostsConfigsPage is true',
  1135. e: false
  1136. },
  1137. {
  1138. isAdmin: true,
  1139. isReconfigurable: false,
  1140. isHostsConfigsPage: false,
  1141. defaultGroupSelected: false,
  1142. m: 'false if defaultGroupSelected is false and isHostsConfigsPage is false',
  1143. e: false
  1144. },
  1145. {
  1146. isAdmin: true,
  1147. isReconfigurable: true,
  1148. isHostsConfigsPage: false,
  1149. defaultGroupSelected: true,
  1150. m: 'equal to isReconfigurable if defaultGroupSelected is true and isHostsConfigsPage is false',
  1151. e: true
  1152. }
  1153. ]).forEach(function (test) {
  1154. it(test.m, function () {
  1155. this.mock.returns(test.isAdmin);
  1156. installerStep7Controller.reopen({isHostsConfigsPage: test.isHostsConfigsPage});
  1157. var serviceConfigProperty = Em.Object.create({
  1158. isReconfigurable: test.isReconfigurable
  1159. });
  1160. installerStep7Controller._updateIsEditableFlagForConfig(serviceConfigProperty, test.defaultGroupSelected);
  1161. expect(serviceConfigProperty.get('isEditable')).to.equal(test.e);
  1162. });
  1163. });
  1164. });
  1165. describe('#_updateOverridesForConfig', function () {
  1166. it('should set empty array', function () {
  1167. var serviceConfigProperty = Em.Object.create({
  1168. overrides: null
  1169. }), component = Em.Object.create();
  1170. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1171. expect(serviceConfigProperty.get('overrides')).to.eql(Em.A([]));
  1172. });
  1173. it('host overrides not supported', function () {
  1174. var serviceConfigProperty = Em.Object.create({
  1175. overrides: [
  1176. {value: 'new value'}
  1177. ]
  1178. }), component = Em.Object.create({selectedConfigGroup: {isDefault: false}});
  1179. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1180. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1181. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1182. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1183. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1184. });
  1185. it('host overrides supported', function () {
  1186. sinon.stub(App, 'get', function (k) {
  1187. if (k === 'supports.hostOverrides') return true;
  1188. return Em.get(App, k);
  1189. });
  1190. var serviceConfigProperty = Em.Object.create({
  1191. overrides: [
  1192. {value: 'new value', group: Em.Object.create({name: 'n1'})}
  1193. ]
  1194. }),
  1195. component = Em.Object.create({
  1196. selectedConfigGroup: {isDefault: true},
  1197. configGroups: Em.A([
  1198. Em.Object.create({name: 'n1', properties: []})
  1199. ])
  1200. });
  1201. installerStep7Controller._updateOverridesForConfig(serviceConfigProperty, component);
  1202. App.get.restore();
  1203. expect(serviceConfigProperty.get('overrides').length).to.equal(1);
  1204. expect(serviceConfigProperty.get('overrides.firstObject.value')).to.equal('new value');
  1205. expect(serviceConfigProperty.get('overrides.firstObject.isOriginalSCP')).to.equal(false);
  1206. expect(serviceConfigProperty.get('overrides.firstObject.parentSCP')).to.eql(serviceConfigProperty);
  1207. expect(component.get('configGroups.firstObject.properties').length).to.equal(1);
  1208. expect(component.get('configGroups.firstObject.properties.firstObject.isEditable')).to.equal(false);
  1209. expect(component.get('configGroups.firstObject.properties.firstObject.group')).to.be.object;
  1210. });
  1211. });
  1212. describe('#setSecureConfigs', function() {
  1213. var serviceConfigObj = Em.Object.create({
  1214. serviceName: 'HDFS',
  1215. configs: [
  1216. Em.Object.create({ name: 'hadoop.http.authentication.signature.secret.file' }),
  1217. Em.Object.create({ name: 'hadoop.security.authentication' })
  1218. ]
  1219. });
  1220. var tests = [
  1221. { name: 'hadoop.http.authentication.signature.secret.file', e: false },
  1222. { name: 'hadoop.security.authentication', e: true }
  1223. ];
  1224. sinon.stub(App, 'get', function(key) {
  1225. if (['isHadoop22Stack'].contains(key)) return true;
  1226. else App.get(key);
  1227. });
  1228. var controller = App.WizardStep7Controller.create({});
  1229. controller.get('secureConfigs').pushObjects([
  1230. {
  1231. name: 'hadoop.http.authentication.signature.secret.file',
  1232. serviceName: 'HDFS',
  1233. value: ''
  1234. }
  1235. ]);
  1236. controller.setSecureConfigs(serviceConfigObj, 'HDFS');
  1237. App.get.restore();
  1238. tests.forEach(function(test) {
  1239. it('{0} is {1}required'.format(test.name, !!test.e ? '' : 'non ' ), function() {
  1240. expect(serviceConfigObj.get('configs').findProperty('name', test.name).get('isRequired')).to.eql(test.e);
  1241. });
  1242. });
  1243. });
  1244. describe('#setInstalledServiceConfigs', function () {
  1245. var controller = App.WizardStep7Controller.create({
  1246. installedServiceNames: ['HBASE', 'AMBARI_METRICS']
  1247. }),
  1248. serviceConfigTags = [
  1249. {
  1250. siteName: 'hbase-site',
  1251. tagName: 'version1'
  1252. },
  1253. {
  1254. siteName: 'ams-hbase-site',
  1255. tagName: 'version1'
  1256. },
  1257. {
  1258. siteName: 'site-without-properties',
  1259. tagName: 'version1'
  1260. }
  1261. ],
  1262. configs = [
  1263. {
  1264. name: 'hbase.client.scanner.caching',
  1265. value: '1000',
  1266. serviceName: 'HBASE',
  1267. filename: 'hbase-site.xml'
  1268. },
  1269. {
  1270. name: 'hbase.client.scanner.caching',
  1271. value: '2000',
  1272. serviceName: 'AMBARI_METRICS',
  1273. filename: 'ams-hbase-site.xml'
  1274. }
  1275. ],
  1276. configsByTags = [
  1277. {
  1278. type: 'hbase-site',
  1279. tag: 'version2',
  1280. properties: {
  1281. 'hbase.client.scanner.caching': '1500'
  1282. }
  1283. },
  1284. {
  1285. type: 'ams-hbase-site',
  1286. tag: 'version2',
  1287. properties: {
  1288. 'hbase.client.scanner.caching': '2500'
  1289. }
  1290. },
  1291. {
  1292. type: 'site-without-properties',
  1293. tag: 'version1'
  1294. }
  1295. ],
  1296. installedServiceNames = ['HBASE', 'AMBARI_METRICS'];
  1297. it('should handle properties with the same name', function () {
  1298. controller.setInstalledServiceConfigs(serviceConfigTags, configs, configsByTags, installedServiceNames);
  1299. var properties = configs.filterProperty('name', 'hbase.client.scanner.caching');
  1300. expect(properties).to.have.length(2);
  1301. expect(properties.findProperty('filename', 'hbase-site.xml').value).to.equal('1500');
  1302. expect(properties.findProperty('filename', 'hbase-site.xml').defaultValue).to.equal('1500');
  1303. expect(properties.findProperty('filename', 'ams-hbase-site.xml').value).to.equal('2500');
  1304. expect(properties.findProperty('filename', 'ams-hbase-site.xml').defaultValue).to.equal('2500');
  1305. });
  1306. });
  1307. describe('#getAmbariDatabaseSuccess', function () {
  1308. var controller = App.WizardStep7Controller.create({
  1309. stepConfigs: [
  1310. {
  1311. serviceName: 'HIVE',
  1312. configs: [
  1313. {
  1314. name: 'hive_ambari_host',
  1315. value: 'h0'
  1316. }
  1317. ]
  1318. }
  1319. ]
  1320. }),
  1321. cases = [
  1322. {
  1323. data: {
  1324. hostComponents: []
  1325. },
  1326. mySQLServerConflict: false,
  1327. title: 'no Ambari Server host components'
  1328. },
  1329. {
  1330. data: {
  1331. hostComponents: [
  1332. {
  1333. RootServiceHostComponents: {
  1334. properties: {
  1335. 'server.jdbc.url': 'jdbc:mysql://h0/db0?createDatabaseIfNotExist=true'
  1336. }
  1337. }
  1338. }
  1339. ]
  1340. },
  1341. mySQLServerConflict: true,
  1342. title: 'Ambari MySQL Server and Hive Server are on the same host'
  1343. },
  1344. {
  1345. data: {
  1346. hostComponents: [
  1347. {
  1348. RootServiceHostComponents: {
  1349. properties: {
  1350. 'server.jdbc.url': 'jdbc:mysql://h1/db1?createDatabaseIfNotExist=true'
  1351. }
  1352. }
  1353. }
  1354. ]
  1355. },
  1356. mySQLServerConflict: false,
  1357. title: 'Ambari MySQL Server and Hive Server are on different hosts'
  1358. }
  1359. ];
  1360. cases.forEach(function (item) {
  1361. it(item.title, function () {
  1362. controller.getAmbariDatabaseSuccess(item.data);
  1363. expect(controller.get('mySQLServerConflict')).to.equal(item.mySQLServerConflict);
  1364. });
  1365. });
  1366. });
  1367. });