step7_test.js 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  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('#setInstalledServiceConfigs', function () {
  1213. var controller = App.WizardStep7Controller.create({
  1214. installedServiceNames: ['HBASE', 'AMBARI_METRICS']
  1215. }),
  1216. serviceConfigTags = [
  1217. {
  1218. siteName: 'hbase-site',
  1219. tagName: 'version1'
  1220. },
  1221. {
  1222. siteName: 'ams-hbase-site',
  1223. tagName: 'version1'
  1224. },
  1225. {
  1226. siteName: 'site-without-properties',
  1227. tagName: 'version1'
  1228. }
  1229. ],
  1230. configs = [
  1231. {
  1232. name: 'hbase.client.scanner.caching',
  1233. value: '1000',
  1234. serviceName: 'HBASE',
  1235. filename: 'hbase-site.xml'
  1236. },
  1237. {
  1238. name: 'hbase.client.scanner.caching',
  1239. value: '2000',
  1240. serviceName: 'AMBARI_METRICS',
  1241. filename: 'ams-hbase-site.xml'
  1242. }
  1243. ],
  1244. configsByTags = [
  1245. {
  1246. type: 'hbase-site',
  1247. tag: 'version2',
  1248. properties: {
  1249. 'hbase.client.scanner.caching': '1500'
  1250. }
  1251. },
  1252. {
  1253. type: 'ams-hbase-site',
  1254. tag: 'version2',
  1255. properties: {
  1256. 'hbase.client.scanner.caching': '2500'
  1257. }
  1258. },
  1259. {
  1260. type: 'site-without-properties',
  1261. tag: 'version1'
  1262. }
  1263. ],
  1264. installedServiceNames = ['HBASE', 'AMBARI_METRICS'];
  1265. it('should handle properties with the same name', function () {
  1266. controller.setInstalledServiceConfigs(serviceConfigTags, configs, configsByTags, installedServiceNames);
  1267. var properties = configs.filterProperty('name', 'hbase.client.scanner.caching');
  1268. expect(properties).to.have.length(2);
  1269. expect(properties.findProperty('filename', 'hbase-site.xml').value).to.equal('1500');
  1270. expect(properties.findProperty('filename', 'hbase-site.xml').defaultValue).to.equal('1500');
  1271. expect(properties.findProperty('filename', 'ams-hbase-site.xml').value).to.equal('2500');
  1272. expect(properties.findProperty('filename', 'ams-hbase-site.xml').defaultValue).to.equal('2500');
  1273. });
  1274. });
  1275. describe('#getAmbariDatabaseSuccess', function () {
  1276. var controller = App.WizardStep7Controller.create({
  1277. stepConfigs: [
  1278. {
  1279. serviceName: 'HIVE',
  1280. configs: [
  1281. {
  1282. name: 'hive_ambari_host',
  1283. value: 'h0'
  1284. }
  1285. ]
  1286. }
  1287. ]
  1288. }),
  1289. cases = [
  1290. {
  1291. data: {
  1292. hostComponents: []
  1293. },
  1294. mySQLServerConflict: false,
  1295. title: 'no Ambari Server host components'
  1296. },
  1297. {
  1298. data: {
  1299. hostComponents: [
  1300. {
  1301. RootServiceHostComponents: {
  1302. properties: {
  1303. 'server.jdbc.url': 'jdbc:mysql://h0/db0?createDatabaseIfNotExist=true'
  1304. }
  1305. }
  1306. }
  1307. ]
  1308. },
  1309. mySQLServerConflict: true,
  1310. title: 'Ambari MySQL Server and Hive Server are on the same host'
  1311. },
  1312. {
  1313. data: {
  1314. hostComponents: [
  1315. {
  1316. RootServiceHostComponents: {
  1317. properties: {
  1318. 'server.jdbc.url': 'jdbc:mysql://h1/db1?createDatabaseIfNotExist=true'
  1319. }
  1320. }
  1321. }
  1322. ]
  1323. },
  1324. mySQLServerConflict: false,
  1325. title: 'Ambari MySQL Server and Hive Server are on different hosts'
  1326. }
  1327. ];
  1328. cases.forEach(function (item) {
  1329. it(item.title, function () {
  1330. controller.getAmbariDatabaseSuccess(item.data);
  1331. expect(controller.get('mySQLServerConflict')).to.equal(item.mySQLServerConflict);
  1332. });
  1333. });
  1334. });
  1335. });