step7_test.js 60 KB

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