step7_test.js 57 KB

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