step8_test.js 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  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 modelSetup = require('test/init_model_test');
  20. require('utils/ajax/ajax_queue');
  21. require('controllers/main/admin/security');
  22. require('controllers/main/service/info/configs');
  23. require('controllers/wizard/step8_controller');
  24. var installerStep8Controller, configurationController;
  25. describe('App.WizardStep8Controller', function () {
  26. var configs = Em.A([
  27. Em.Object.create({filename: 'hdfs-site.xml', name: 'p1', value: 'v1'}),
  28. Em.Object.create({filename: 'hdfs-site.xml', name: 'p2', value: 'v2'}),
  29. Em.Object.create({filename: 'hue-site.xml', name: 'p1', value: 'v1'}),
  30. Em.Object.create({filename: 'hue-site.xml', name: 'p2', value: 'v2'}),
  31. Em.Object.create({filename: 'mapred-site.xml', name: 'p1', value: 'v1'}),
  32. Em.Object.create({filename: 'mapred-site.xml', name: 'p2', value: 'v2'}),
  33. Em.Object.create({filename: 'yarn-site.xml', name: 'p1', value: 'v1'}),
  34. Em.Object.create({filename: 'yarn-site.xml', name: 'p2', value: 'v2'}),
  35. Em.Object.create({filename: 'capacity-scheduler.xml', name: 'p1', value: 'v1'}),
  36. Em.Object.create({filename: 'capacity-scheduler.xml', name: 'p2', value: 'v2'}),
  37. Em.Object.create({filename: 'mapred-queue-acls.xml', name: 'p1', value: 'v1'}),
  38. Em.Object.create({filename: 'mapred-queue-acls.xml', name: 'p2', value: 'v2'}),
  39. Em.Object.create({filename: 'hbase-site.xml', name: 'p1', value: 'v1'}),
  40. Em.Object.create({filename: 'hbase-site.xml', name: 'p2', value: 'v2'}),
  41. Em.Object.create({filename: 'oozie-site.xml', name: 'p1', value: 'v1'}),
  42. Em.Object.create({filename: 'oozie-site.xml', name: 'p2', value: 'v2'}),
  43. Em.Object.create({filename: 'hive-site.xml', name: 'p1', value: 'v1'}),
  44. Em.Object.create({filename: 'hive-site.xml', name: 'p2', value: 'v2'}),
  45. Em.Object.create({filename: 'pig-properties.xml', name: 'p1', value: 'v1'}),
  46. Em.Object.create({filename: 'webhcat-site.xml', name: 'p1', value: 'v1'}),
  47. Em.Object.create({filename: 'webhcat-site.xml', name: 'p2', value: 'v2'}),
  48. Em.Object.create({filename: 'tez-site.xml', name: 'p1', value: 'v1'}),
  49. Em.Object.create({filename: 'tez-site.xml', name: 'p2', value: 'v2'}),
  50. Em.Object.create({filename: 'falcon-startup.properties.xml', name: 'p1', value: 'v1'}),
  51. Em.Object.create({filename: 'falcon-startup.properties.xml', name: 'p2', value: 'v2'}),
  52. Em.Object.create({filename: 'falcon-runtime.properties.xml', name: 'p1', value: 'v1'}),
  53. Em.Object.create({filename: 'falcon-runtime.properties.xml', name: 'p2', value: 'v2'})
  54. ]);
  55. beforeEach(function () {
  56. installerStep8Controller = App.WizardStep8Controller.create({
  57. configs: configs
  58. });
  59. configurationController = App.MainServiceInfoConfigsController.create({});
  60. });
  61. var siteObjTests = Em.A([
  62. {name: 'createHdfsSiteObj', e: {type: 'hdfs-site', tag: 'version1', l: 2}},
  63. {name: 'createHueSiteObj', e: {type: 'hue-site', tag: 'version1', l: 2}},
  64. {name: 'createMrSiteObj', e: {type: 'mapred-site', tag: 'version1', l: 2}},
  65. {name: 'createYarnSiteObj', e: {type: 'yarn-site', tag: 'version1', l: 2}},
  66. {name: 'createCapacityScheduler', e: {type: 'capacity-scheduler', tag: 'version1', l: 2}},
  67. {name: 'createMapredQueueAcls', e: {type: 'mapred-queue-acls', tag: 'version1', l: 2}},
  68. {name: 'createHbaseSiteObj', e: {type: 'hbase-site', tag: 'version1', l: 2}},
  69. {name: 'createOozieSiteObj', e: {type: 'oozie-site', tag: 'version1', l: 2}},
  70. {name: 'createHiveSiteObj', e: {type: 'hive-site', tag: 'version1', l: 2}},
  71. {name: 'createWebHCatSiteObj', e: {type: 'webhcat-site', tag: 'version1', l: 2}},
  72. {name: 'createTezSiteObj', e: {type: 'tez-site', tag: 'version1', l: 2}},
  73. {name: 'createPigPropertiesSiteObj', e: {type: 'pig-properties', tag: 'version1', l: 1}},
  74. {name: 'createFalconStartupSiteObj', e: {type: 'falcon-startup.properties', tag: 'version1', l: 2}},
  75. {name: 'createFalconRuntimeSiteObj', e: {type: 'falcon-runtime.properties', tag: 'version1', l: 2}}
  76. ]);
  77. siteObjTests.forEach(function (test) {
  78. describe('#' + test.name, function () {
  79. it(test.name, function () {
  80. var siteObj = installerStep8Controller.createSiteObj(test.e.type, test.e.tag);
  81. expect(siteObj.tag).to.equal(test.e.tag);
  82. expect(Em.keys(siteObj.properties).length).to.equal(test.e.l);
  83. });
  84. });
  85. });
  86. describe('#createSelectedServicesData', function () {
  87. var tests = Em.A([
  88. {selectedServices: Em.A(['MAPREDUCE2']), e: 2},
  89. {selectedServices: Em.A(['MAPREDUCE2', 'YARN']), e: 5},
  90. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE']), e: 7},
  91. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE']), e: 9},
  92. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE']), e: 12},
  93. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE']), e: 13},
  94. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE']), e: 14},
  95. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG']), e: 15},
  96. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON']), e: 17},
  97. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON', 'STORM']), e: 18},
  98. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON', 'STORM', 'TEZ']), e: 19},
  99. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON', 'STORM', 'TEZ', 'ZOOKEEPER']), e: 21}
  100. ]);
  101. tests.forEach(function (test) {
  102. it(test.selectedServices.join(','), function () {
  103. var services = test.selectedServices.map(function (serviceName) {
  104. return Em.Object.create({isSelected: true, isInstalled: false, serviceName: serviceName});
  105. });
  106. installerStep8Controller = App.WizardStep8Controller.create({
  107. content: {controllerName: 'addServiceController', services: services},
  108. configs: configs
  109. });
  110. var serviceData = installerStep8Controller.createSelectedServicesData();
  111. expect(serviceData.mapProperty('ServiceInfo.service_name')).to.eql(test.selectedServices.toArray());
  112. installerStep8Controller.clearStep();
  113. });
  114. });
  115. });
  116. describe('#getRegisteredHosts', function () {
  117. var tests = Em.A([
  118. {
  119. hosts: {
  120. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1'}),
  121. h2: Em.Object.create({bootStatus: 'OTHER', name: 'h2'})
  122. },
  123. e: ['h1'],
  124. m: 'Two hosts, one registered'
  125. },
  126. {
  127. hosts: {
  128. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1'}),
  129. h2: Em.Object.create({bootStatus: 'OTHER', name: 'h2'})
  130. },
  131. e: [],
  132. m: 'Two hosts, zero registered'
  133. },
  134. {
  135. hosts: {
  136. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1'}),
  137. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2'})
  138. },
  139. e: ['h1', 'h2'],
  140. m: 'Two hosts, two registered'
  141. }
  142. ]);
  143. tests.forEach(function (test) {
  144. it(test.m, function () {
  145. installerStep8Controller.set('content', Em.Object.create({hosts: test.hosts}));
  146. var registeredHosts = installerStep8Controller.getRegisteredHosts();
  147. expect(registeredHosts.mapProperty('hostName').toArray()).to.eql(test.e);
  148. });
  149. });
  150. });
  151. describe('#createRegisterHostData', function () {
  152. var tests = Em.A([
  153. {
  154. hosts: {
  155. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1', isInstalled: false}),
  156. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  157. },
  158. e: ['h1', 'h2'],
  159. m: 'two registered, two isInstalled false'
  160. },
  161. {
  162. hosts: {
  163. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1', isInstalled: false}),
  164. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  165. },
  166. e: ['h2'],
  167. m: 'one registered, two isInstalled false'
  168. },
  169. {
  170. hosts: {
  171. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1', isInstalled: true}),
  172. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  173. },
  174. e: ['h2'],
  175. m: 'one registered, one isInstalled false'
  176. },
  177. {
  178. hosts: {
  179. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1', isInstalled: true}),
  180. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  181. },
  182. e: ['h2'],
  183. m: 'two registered, one isInstalled false'
  184. },
  185. {
  186. hosts: {
  187. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1', isInstalled: false}),
  188. h2: Em.Object.create({bootStatus: 'OTHER', name: 'h2', isInstalled: false})
  189. },
  190. e: [],
  191. m: 'zero registered, two isInstalled false'
  192. },
  193. {
  194. hosts: {
  195. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1', isInstalled: true}),
  196. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: true})
  197. },
  198. e: [],
  199. m: 'two registered, zeto insInstalled false'
  200. }
  201. ]);
  202. tests.forEach(function (test) {
  203. it(test.m, function () {
  204. installerStep8Controller.set('content', Em.Object.create({hosts: test.hosts}));
  205. var registeredHostData = installerStep8Controller.createRegisterHostData();
  206. expect(registeredHostData.mapProperty('Hosts.host_name').toArray()).to.eql(test.e);
  207. });
  208. });
  209. });
  210. describe('#clusterName', function () {
  211. it('should be equal to content.cluster.name', function () {
  212. installerStep8Controller.set('content', {cluster: {name: 'new_name'}});
  213. expect(installerStep8Controller.get('clusterName')).to.equal('new_name');
  214. });
  215. });
  216. describe('#loadStep', function () {
  217. beforeEach(function () {
  218. sinon.stub(installerStep8Controller, 'clearStep', Em.K);
  219. sinon.stub(installerStep8Controller, 'formatProperties', Em.K);
  220. sinon.stub(installerStep8Controller, 'loadConfigs', Em.K);
  221. sinon.stub(installerStep8Controller, 'loadClusterInfo', Em.K);
  222. sinon.stub(installerStep8Controller, 'loadServices', Em.K);
  223. installerStep8Controller.set('content', {controllerName: 'installerController'});
  224. });
  225. afterEach(function () {
  226. installerStep8Controller.clearStep.restore();
  227. installerStep8Controller.formatProperties.restore();
  228. installerStep8Controller.loadConfigs.restore();
  229. installerStep8Controller.loadClusterInfo.restore();
  230. installerStep8Controller.loadServices.restore();
  231. });
  232. it('should call clearStep', function () {
  233. installerStep8Controller.loadStep();
  234. expect(installerStep8Controller.clearStep.calledOnce).to.equal(true);
  235. });
  236. it('should call loadClusterInfo', function () {
  237. installerStep8Controller.loadStep();
  238. expect(installerStep8Controller.loadClusterInfo.calledOnce).to.equal(true);
  239. });
  240. it('should call loadServices', function () {
  241. installerStep8Controller.loadStep();
  242. expect(installerStep8Controller.loadServices.calledOnce).to.equal(true);
  243. });
  244. it('should call formatProperties if content.serviceConfigProperties is true', function () {
  245. installerStep8Controller.set('content.serviceConfigProperties', true);
  246. installerStep8Controller.loadStep();
  247. expect(installerStep8Controller.loadServices.calledOnce).to.equal(true);
  248. });
  249. it('should call loadConfigs if content.serviceConfigProperties is true', function () {
  250. installerStep8Controller.set('content.serviceConfigProperties', true);
  251. installerStep8Controller.loadStep();
  252. expect(installerStep8Controller.loadConfigs.calledOnce).to.equal(true);
  253. });
  254. it('should set isSubmitDisabled to false', function () {
  255. installerStep8Controller.loadStep();
  256. expect(installerStep8Controller.get('isSubmitDisabled')).to.equal(false);
  257. });
  258. it('should set isBackBtnDisabled to false', function () {
  259. installerStep8Controller.loadStep();
  260. expect(installerStep8Controller.get('isBackBtnDisabled')).to.equal(false);
  261. });
  262. });
  263. describe('#removeHiveConfigs', function () {
  264. Em.A([
  265. {
  266. globals: [
  267. {name: 'hive_database', value: 'New MySQL Database'},
  268. {name: 'hive_database_type', value: 'mysql'},
  269. {name: 'hive_ambari_host', value: 'h1'},
  270. {name: 'hive_hostname', value: 'h2'}
  271. ],
  272. removed: Em.A(['hive_existing_mysql_host', 'hive_existing_mysql_database', 'hive_existing_oracle_host',
  273. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']),
  274. m: 'hive_database: New MySQL Database',
  275. host: 'h1'
  276. },
  277. {
  278. globals: [
  279. {name: 'hive_database', value: 'Existing MySQL Database'},
  280. {name: 'hive_database_type', value: 'mysql'},
  281. {name: 'hive_existing_mysql_host', value: 'h1'},
  282. {name: 'hive_hostname', value: 'h2'}
  283. ],
  284. removed: Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  285. 'hive_existing_oracle_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']),
  286. m: 'hive_database: Existing MySQL Database',
  287. host: 'h1'
  288. },
  289. {
  290. globals: [
  291. {name: 'hive_database', value: 'Existing PostgreSQL Database'},
  292. {name: 'hive_database_type', value: 'postgresql'},
  293. {name: 'hive_existing_postgresql_host', value: 'h1'},
  294. {name: 'hive_hostname', value: 'h2'}
  295. ],
  296. removed: Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_oracle_host',
  297. 'hive_existing_oracle_database', 'hive_existing_mysql_host', 'hive_existing_mysql_database']),
  298. m: 'hive_database: Existing PostgreSQL Database',
  299. host: 'h1'
  300. },
  301. {
  302. globals: [
  303. {name: 'hive_database', value: 'Existing Oracle Database'},
  304. {name: 'hive_database_type', value: 'oracle'},
  305. {name: 'hive_existing_oracle_host', value: 'h1'},
  306. {name: 'hive_hostname', value: 'h2'}
  307. ],
  308. removed: Em.A(['hive_ambari_host', 'hive_ambari_database', 'hive_existing_mysql_host',
  309. 'hive_existing_mysql_database', 'hive_existing_postgresql_host', 'hive_existing_postgresql_database']),
  310. m: 'hive_database: Existing Oracle Database',
  311. host: 'h1'
  312. }
  313. ]).forEach(function (test) {
  314. it(test.m, function () {
  315. test.removed.forEach(function (c) {
  316. test.globals.pushObject({name: c})
  317. });
  318. var configs = installerStep8Controller.removeHiveConfigs(test.globals);
  319. test.removed.forEach(function(name) {
  320. expect(Em.isNone(configs.findProperty('name', name))).to.equal(true);
  321. });
  322. expect(configs.findProperty('name', 'hive_hostname').value).to.equal(test.host);
  323. });
  324. });
  325. });
  326. describe('#removeOozieConfigs', function () {
  327. Em.A([
  328. {
  329. globals: [
  330. {name: 'oozie_database', value: 'New Derby Database'},
  331. {name: 'oozie_database_type', value: 'derby'},
  332. {name: 'oozie_ambari_host', value: 'h1'},
  333. {name: 'oozie_hostname', value: 'h2'}
  334. ],
  335. removed: Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_mysql_host',
  336. 'oozie_existing_mysql_database', 'oozie_existing_oracle_host', 'oozie_existing_oracle_database',
  337. 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database']),
  338. oozie_database_type: 'derby',
  339. m: 'oozie_database: New Derby Database',
  340. host: 'h1'
  341. },
  342. {
  343. globals: [
  344. {name: 'oozie_database', value: 'Existing MySQL Database'},
  345. {name: 'oozie_database_type', value: 'mysql'},
  346. {name: 'oozie_existing_mysql_host', value: 'h1'},
  347. {name: 'oozie_hostname', value: 'h2'}
  348. ],
  349. removed: Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_oracle_host',
  350. 'oozie_existing_oracle_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database']),
  351. oozie_database_type: 'mysql',
  352. m: 'oozie_database: Existing MySQL Database',
  353. host: 'h1'
  354. },
  355. {
  356. globals: [
  357. {name: 'oozie_database', value: 'Existing PostgreSQL Database'},
  358. {name: 'oozie_database_type', value: 'postgresql'},
  359. {name: 'oozie_existing_postgresql_host', value: 'h1'},
  360. {name: 'oozie_hostname', value: 'h2'}
  361. ],
  362. removed: Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_oracle_host',
  363. 'oozie_existing_oracle_database', 'oozie_existing_mysql_host', 'oozie_existing_mysql_database']),
  364. oozie_database_type: 'postgresql',
  365. m: 'oozie_database: Existing PostgreSQL Database',
  366. host: 'h1'
  367. },
  368. {
  369. globals: [
  370. {name: 'oozie_database', value: 'Existing Oracle Database'},
  371. {name: 'oozie_database_type', value: 'oracle'},
  372. {name: 'oozie_existing_oracle_host', value: 'h1'},
  373. {name: 'oozie_hostname', value: 'h2'}
  374. ],
  375. removed: Em.A(['oozie_ambari_host', 'oozie_ambari_database', 'oozie_existing_mysql_host',
  376. 'oozie_existing_mysql_database', 'oozie_derby_database', 'oozie_existing_postgresql_host', 'oozie_existing_postgresql_database']),
  377. oozie_database_type: 'oracle',
  378. m: 'oozie_database: Existing Oracle Database',
  379. host: 'h1'
  380. }
  381. ]).forEach(function (test) {
  382. it(test.m, function () {
  383. test.removed.forEach(function (c) {
  384. if (!test.globals.findProperty('name', c)) {
  385. test.globals.pushObject({name: c})
  386. }
  387. });
  388. var configs = installerStep8Controller.removeOozieConfigs(test.globals);
  389. test.removed.forEach(function(name) {
  390. expect(Em.isNone(configs.findProperty('name', name))).to.equal(true);
  391. });
  392. expect(configs.findProperty('name', 'oozie_database_type').value).to.equal(test.oozie_database_type);
  393. expect(configs.findProperty('name', 'oozie_hostname').value).to.equal(test.host);
  394. });
  395. });
  396. });
  397. describe('#getRegisteredHosts', function() {
  398. Em.A([
  399. {
  400. hosts: {},
  401. m: 'no content.hosts',
  402. e: []
  403. },
  404. {
  405. hosts: {
  406. h1:{bootStatus: ''},
  407. h2:{bootStatus: ''}
  408. },
  409. m: 'no registered hosts',
  410. e: []
  411. },
  412. {
  413. hosts: {
  414. h1:{bootStatus: 'REGISTERED', hostName: '', name: 'n1'},
  415. h2:{bootStatus: 'REGISTERED', hostName: '', name: 'n2'}
  416. },
  417. m: 'registered hosts available',
  418. e: ['n1', 'n2']
  419. }
  420. ]).forEach(function(test) {
  421. it(test.m, function() {
  422. installerStep8Controller.set('content', {hosts: test.hosts});
  423. var hosts = installerStep8Controller.getRegisteredHosts();
  424. expect(hosts.mapProperty('hostName')).to.eql(test.e);
  425. });
  426. });
  427. });
  428. describe('#loadRepoInfo', function() {
  429. it('should use App.currentStackVersion', function() {
  430. var version = 'HDP-1.1.1';
  431. sinon.stub(App, 'get', function() {return version;});
  432. sinon.stub(App.ajax, 'send', Em.K);
  433. installerStep8Controller.loadRepoInfo();
  434. var data = App.ajax.send.args[0][0].data;
  435. expect(data).to.eql({stackName: 'HDP', stackVersion: '1.1.1'});
  436. App.ajax.send.restore();
  437. App.get.restore();
  438. });
  439. });
  440. describe('#loadRepoInfoSuccessCallback', function () {
  441. beforeEach(function () {
  442. installerStep8Controller.set('clusterInfo', Em.Object.create({}));
  443. });
  444. Em.A([
  445. {
  446. items: [],
  447. m: 'no data',
  448. e: {
  449. base_url: [],
  450. os_type: []
  451. }
  452. },
  453. {
  454. items: [
  455. {
  456. repositories: [
  457. {
  458. Repositories: {
  459. os_type: 'redhat5',
  460. base_url: 'url1'
  461. }
  462. }
  463. ],
  464. OperatingSystems: {
  465. is_type: ''
  466. }
  467. }
  468. ],
  469. m: 'only redhat5',
  470. e: {
  471. base_url: ['url1'],
  472. os_type: ['redhat5']
  473. }
  474. },
  475. {
  476. items: [
  477. {
  478. repositories: [
  479. {
  480. Repositories: {
  481. os_type: 'redhat5',
  482. base_url: 'url1'
  483. }
  484. }
  485. ],
  486. OperatingSystems: {
  487. is_type: ''
  488. }
  489. },
  490. {
  491. repositories: [
  492. {
  493. Repositories: {
  494. os_type: 'redhat6',
  495. base_url: 'url2'
  496. }
  497. }
  498. ],
  499. OperatingSystems: {
  500. is_type: ''
  501. }
  502. }
  503. ],
  504. m: 'redhat5, redhat6',
  505. e: {
  506. base_url: ['url1', 'url2'],
  507. os_type: ['redhat5', 'redhat6']
  508. }
  509. },
  510. {
  511. items: [
  512. {
  513. repositories: [
  514. {
  515. Repositories: {
  516. os_type: 'redhat5',
  517. base_url: 'url1'
  518. }
  519. }
  520. ],
  521. OperatingSystems: {
  522. is_type: ''
  523. }
  524. },
  525. {
  526. repositories: [
  527. {
  528. Repositories: {
  529. os_type: 'redhat6',
  530. base_url: 'url2'
  531. }
  532. }
  533. ],
  534. OperatingSystems: {
  535. is_type: ''
  536. }
  537. },
  538. {
  539. repositories: [
  540. {
  541. Repositories: {
  542. os_type: 'sles11',
  543. base_url: 'url3'
  544. }
  545. }
  546. ],
  547. OperatingSystems: {
  548. is_type: ''
  549. }
  550. }
  551. ],
  552. m: 'redhat5, redhat6, sles11',
  553. e: {
  554. base_url: ['url1', 'url2', 'url3'],
  555. os_type: ['redhat5', 'redhat6', 'sles11']
  556. }
  557. }
  558. ]).forEach(function (test) {
  559. it(test.m, function () {
  560. installerStep8Controller.loadRepoInfoSuccessCallback({items: test.items});
  561. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('base_url')).to.eql(test.e.base_url);
  562. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('os_type')).to.eql(test.e.os_type);
  563. });
  564. });
  565. });
  566. describe('#loadRepoInfoErrorCallback', function() {
  567. it('should set [] to repoInfo', function() {
  568. installerStep8Controller.set('clusterInfo', Em.Object.create({repoInfo: [{}, {}]}));
  569. installerStep8Controller.loadRepoInfoErrorCallback({});
  570. expect(installerStep8Controller.get('clusterInfo.repoInfo.length')).to.eql(0);
  571. });
  572. });
  573. describe('#loadHiveDbValue', function() {
  574. beforeEach(function() {
  575. installerStep8Controller.set('wizardController', Em.Object.create({
  576. getDBProperty: Em.K
  577. }));
  578. });
  579. Em.A([
  580. {
  581. serviceConfigProperties: [
  582. {name: 'hive_database', value: 'New MySQL Database'}
  583. ],
  584. m: 'New MySQL Database',
  585. e: 'MySQL (New Database)'
  586. },
  587. {
  588. serviceConfigProperties: [
  589. {name: 'hive_database', value: 'New PostgreSQL Database'}
  590. ],
  591. m: 'New PostgreSQL Database',
  592. e: 'Postgres (New Database)'
  593. },
  594. {
  595. serviceConfigProperties: [
  596. {name: 'hive_database', value: 'Existing MySQL Database'},
  597. {name: 'hive_existing_mysql_database', value: 'dbname'}
  598. ],
  599. m: 'Existing MySQL Database',
  600. e: 'dbname (Existing MySQL Database)'
  601. },
  602. {
  603. serviceConfigProperties: [
  604. {name: 'hive_database', value: 'Existing PostgreSQL Database'},
  605. {name: 'hive_existing_postgresql_database', value: 'dbname'}
  606. ],
  607. m: 'Existing PostgreSQL Database',
  608. e: 'dbname (Existing PostgreSQL Database)'
  609. },
  610. {
  611. serviceConfigProperties: [
  612. {name: 'hive_database', value: 'Existing Oracle Database'},
  613. {name: 'hive_existing_oracle_database', value: 'dbname'}
  614. ],
  615. m: 'Existing Oracle Database',
  616. e: 'dbname (Existing Oracle Database)'
  617. }
  618. ]).forEach(function(test) {
  619. it(test.m, function() {
  620. sinon.stub(installerStep8Controller.get('wizardController'), 'getDBProperty', function() {
  621. return test.serviceConfigProperties;
  622. });
  623. var dbComponent = installerStep8Controller.loadHiveDbValue();
  624. expect(dbComponent).to.equal(test.e);
  625. installerStep8Controller.get('wizardController').getDBProperty.restore();
  626. });
  627. });
  628. });
  629. describe('#loadHbaseMasterValue', function () {
  630. Em.A([
  631. {
  632. masterComponentHosts: [{component: 'HBASE_MASTER', hostName: 'h1'}],
  633. component: Em.Object.create({component_name: 'HBASE_MASTER'}),
  634. m: 'one host',
  635. e: 'h1'
  636. },
  637. {
  638. masterComponentHosts: [{component: 'HBASE_MASTER', hostName: 'h1'}, {component: 'HBASE_MASTER', hostName: 'h2'}, {component: 'HBASE_MASTER', hostName: 'h3'}],
  639. component: Em.Object.create({component_name: 'HBASE_MASTER'}),
  640. m: 'many hosts',
  641. e: 'h1 ' + Em.I18n.t('installer.step8.other').format(2)
  642. }
  643. ]).forEach(function (test) {
  644. it(test.m, function() {
  645. installerStep8Controller.set('content', {masterComponentHosts: test.masterComponentHosts});
  646. installerStep8Controller.loadHbaseMasterValue(test.component);
  647. expect(test.component.component_value).to.equal(test.e);
  648. });
  649. });
  650. });
  651. describe('#loadZkServerValue', function() {
  652. Em.A([
  653. {
  654. masterComponentHosts: [{component: 'ZOOKEEPER_SERVER'}],
  655. component: Em.Object.create({component_name: 'ZOOKEEPER_SERVER'}),
  656. m: '1 host',
  657. e: '1 host'
  658. },
  659. {
  660. masterComponentHosts: [{component: 'ZOOKEEPER_SERVER'},{component: 'ZOOKEEPER_SERVER'},{component: 'ZOOKEEPER_SERVER'}],
  661. component: Em.Object.create({component_name: 'ZOOKEEPER_SERVER'}),
  662. m: 'many hosts',
  663. e: '3 hosts'
  664. }
  665. ]).forEach(function (test) {
  666. it(test.m, function () {
  667. installerStep8Controller.set('content', {masterComponentHosts: test.masterComponentHosts});
  668. installerStep8Controller.loadZkServerValue(test.component);
  669. expect(test.component.component_value).to.equal(test.e);
  670. });
  671. });
  672. });
  673. describe('#loadOozieDbValue', function() {
  674. beforeEach(function() {
  675. installerStep8Controller.set('wizardController', Em.Object.create({
  676. getDBProperty: Em.K
  677. }));
  678. });
  679. Em.A([
  680. {
  681. serviceConfigProperties: [
  682. {name: 'oozie_database', value: 'New Derby Database'},
  683. {name: 'oozie_derby_database', value: 'dbname'}
  684. ],
  685. m: 'New Derby Database',
  686. e: 'dbname (New Derby Database)'
  687. },
  688. {
  689. serviceConfigProperties: [
  690. {name: 'oozie_database', value: 'Existing MySQL Database'},
  691. {name: 'oozie_existing_mysql_database', value: 'dbname'}
  692. ],
  693. m: 'Existing MySQL Database',
  694. e: 'dbname (Existing MySQL Database)'
  695. },
  696. {
  697. serviceConfigProperties: [
  698. {name: 'oozie_database', value: 'Existing PostgreSQL Database'},
  699. {name: 'oozie_existing_postgresql_database', value: 'dbname'}
  700. ],
  701. m: 'Existing PostgreSQL Database',
  702. e: 'dbname (Existing PostgreSQL Database)'
  703. },
  704. {
  705. serviceConfigProperties: [
  706. {name: 'oozie_database', value: 'Existing Oracle Database'},
  707. {name: 'oozie_existing_oracle_database', value: 'dbname'}
  708. ],
  709. m: 'Existing Oracle Database',
  710. e: 'dbname (Existing Oracle Database)'
  711. }
  712. ]).forEach(function(test) {
  713. it(test.m, function() {
  714. sinon.stub(installerStep8Controller.get('wizardController'), 'getDBProperty', function() {
  715. return test.serviceConfigProperties;
  716. });
  717. var dbComponent = installerStep8Controller.loadOozieDbValue();
  718. expect(dbComponent).to.equal(test.e);
  719. installerStep8Controller.get('wizardController').getDBProperty.restore();
  720. });
  721. });
  722. });
  723. describe('#loadNagiosAdminValue', function() {
  724. it('should use serviceConfigProperties nagios_web_login and nagios_contact', function() {
  725. installerStep8Controller.set('content', {
  726. serviceConfigProperties: [
  727. {name: 'nagios_web_login', value: 'admin'},
  728. {name: 'nagios_contact', value: 'admin@admin.com'}
  729. ]
  730. });
  731. var nagiosAdmin = installerStep8Controller.loadNagiosAdminValue();
  732. expect(nagiosAdmin).to.equal('admin / (admin@admin.com)');
  733. });
  734. });
  735. describe('#submit', function() {
  736. beforeEach(function() {
  737. sinon.stub(installerStep8Controller, 'submitProceed', Em.K);
  738. sinon.spy(App, 'showConfirmationPopup');
  739. });
  740. afterEach(function() {
  741. installerStep8Controller.submitProceed.restore();
  742. App.showConfirmationPopup.restore();
  743. });
  744. Em.A([
  745. {
  746. controllerName: 'addHostController',
  747. securityEnabled: true,
  748. e: true
  749. },
  750. {
  751. controllerName: 'addHostController',
  752. securityEnabled: false,
  753. e: false
  754. },
  755. {
  756. controllerName: 'addServiceController',
  757. securityEnabled: true,
  758. e: false
  759. },
  760. {
  761. controllerName: 'addServiceController',
  762. securityEnabled: false,
  763. e: false
  764. }
  765. ]).forEach(function (test) {
  766. it(test.controllerName + ' ' + test.securityEnabled.toString(), function () {
  767. installerStep8Controller.reopen({isSubmitDisabled: false, securityEnabled: test.securityEnabled, content: {controllerName: test.controllerName}});
  768. installerStep8Controller.submit();
  769. if (test.e) {
  770. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  771. expect(installerStep8Controller.submitProceed.called).to.equal(false);
  772. }
  773. else {
  774. expect(App.showConfirmationPopup.called).to.equal(false);
  775. expect(installerStep8Controller.submitProceed.calledOnce).to.equal(true);
  776. }
  777. });
  778. });
  779. it('should call submitProceed when Ok clicked', function() {
  780. installerStep8Controller.reopen({isSubmitDisabled: false, securityEnabled: true, content: {controllerName: 'addHostController'}});
  781. installerStep8Controller.submit().onPrimary();
  782. expect(installerStep8Controller.submitProceed.calledOnce).to.equal(true);
  783. });
  784. it('shouldn\'t do nothing if isSubmitDisabled is true', function() {
  785. installerStep8Controller.reopen({isSubmitDisabled: true});
  786. installerStep8Controller.submit();
  787. expect(App.showConfirmationPopup.called).to.equal(false);
  788. expect(installerStep8Controller.submitProceed.called).to.equal(false);
  789. });
  790. });
  791. describe('#getExistingClusterNamesSuccessCallBack', function() {
  792. it('should set clusterNames received from server', function() {
  793. var data = {
  794. items:[
  795. {Clusters: {cluster_name: 'c1'}},
  796. {Clusters: {cluster_name: 'c2'}},
  797. {Clusters: {cluster_name: 'c3'}}
  798. ]
  799. },
  800. clasterNames = ['c1','c2','c3'];
  801. installerStep8Controller.getExistingClusterNamesSuccessCallBack(data);
  802. expect(installerStep8Controller.get('clusterNames')).to.eql(clasterNames);
  803. });
  804. });
  805. describe('#getExistingClusterNamesErrorCallback', function() {
  806. it('should set [] to clusterNames', function() {
  807. installerStep8Controller.set('clusterNames', ['c1', 'c2']);
  808. installerStep8Controller.getExistingClusterNamesErrorCallback();
  809. expect(installerStep8Controller.get('clusterNames')).to.eql([]);
  810. });
  811. });
  812. describe('#deleteClusters', function() {
  813. it('should call App.ajax.send for each provided clusterName', function() {
  814. sinon.stub(App.ajax, 'send', Em.K);
  815. var clusterNames = ['h1', 'h2', 'h3'];
  816. installerStep8Controller.deleteClusters(clusterNames);
  817. expect(App.ajax.send.callCount).to.equal(clusterNames.length);
  818. clusterNames.forEach(function(n, i) {
  819. expect(App.ajax.send.getCall(i).args[0].data).to.eql({name: n, isLast: i == clusterNames.length - 1});
  820. });
  821. App.ajax.send.restore();
  822. });
  823. });
  824. describe('#createSelectedServicesData', function() {
  825. it('should reformat provided data', function() {
  826. var selectedServices = [
  827. Em.Object.create({serviceName: 's1'}),
  828. Em.Object.create({serviceName: 's2'}),
  829. Em.Object.create({serviceName: 's3'})
  830. ];
  831. var expected = [
  832. {"ServiceInfo": { "service_name": 's1' }},
  833. {"ServiceInfo": { "service_name": 's2' }},
  834. {"ServiceInfo": { "service_name": 's3' }}
  835. ];
  836. installerStep8Controller.reopen({selectedServices: selectedServices});
  837. var createdData = installerStep8Controller.createSelectedServicesData();
  838. expect(createdData).to.eql(expected);
  839. });
  840. });
  841. describe('#createRegisterHostData', function() {
  842. it('should return empty data if no hosts', function() {
  843. sinon.stub(installerStep8Controller, 'getRegisteredHosts', function() {return [];});
  844. expect(installerStep8Controller.createRegisterHostData()).to.eql([]);
  845. installerStep8Controller.getRegisteredHosts.restore();
  846. });
  847. it('should return computed data', function() {
  848. var data = [
  849. {isInstalled: false, hostName: 'h1'},
  850. {isInstalled: true, hostName: 'h2'},
  851. {isInstalled: false, hostName: 'h3'}
  852. ];
  853. var expected = [
  854. {"Hosts": { "host_name": 'h1'}},
  855. {"Hosts": { "host_name": 'h3'}}
  856. ];
  857. sinon.stub(installerStep8Controller, 'getRegisteredHosts', function() {return data;});
  858. expect(installerStep8Controller.createRegisterHostData()).to.eql(expected);
  859. installerStep8Controller.getRegisteredHosts.restore();
  860. });
  861. });
  862. describe('#createStormSiteObj', function() {
  863. it('should replace quote \'"\' to "\'" for some properties', function() {
  864. var configs = [
  865. {filename: 'storm-site.xml', value: ["a", "b"], name: 'storm.zookeeper.servers'}
  866. ],
  867. expected = {
  868. type: 'storm-site',
  869. tag: 'version1',
  870. properties: {
  871. 'storm.zookeeper.servers': '[\'a\',\'b\']'
  872. }
  873. };
  874. installerStep8Controller.reopen({configs: configs});
  875. expect(installerStep8Controller.createStormSiteObj('version1')).to.eql(expected);
  876. });
  877. it('should not escape special characters', function() {
  878. var configs = [
  879. {filename: 'storm-site.xml', value: "abc\n\t", name: 'nimbus.childopts'},
  880. {filename: 'storm-site.xml', value: "a\nb", name: 'supervisor.childopts'},
  881. {filename: 'storm-site.xml', value: "a\t\tb", name: 'worker.childopts'}
  882. ],
  883. expected = {
  884. type: 'storm-site',
  885. tag: 'version1',
  886. properties: {
  887. 'nimbus.childopts': 'abc\n\t',
  888. 'supervisor.childopts': 'a\nb',
  889. 'worker.childopts': 'a\t\tb'
  890. }
  891. };
  892. installerStep8Controller.reopen({configs: configs});
  893. expect(installerStep8Controller.createStormSiteObj('version1')).to.eql(expected);
  894. });
  895. });
  896. describe('#ajaxQueueFinished', function() {
  897. it('should call App.router.next', function() {
  898. sinon.stub(App.router, 'send', Em.K);
  899. installerStep8Controller.ajaxQueueFinished();
  900. expect(App.router.send.calledWith('next')).to.equal(true);
  901. App.router.send.restore();
  902. });
  903. });
  904. describe('#addRequestToAjaxQueue', function() {
  905. describe('testMode = true', function() {
  906. before(function() {
  907. App.set('testMode', true);
  908. });
  909. after(function() {
  910. App.set('testMode', false);
  911. });
  912. it('shouldn\'t do nothing', function() {
  913. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  914. installerStep8Controller.get('ajaxRequestsQueue').clear();
  915. installerStep8Controller.addRequestToAjaxQueue({});
  916. expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(0);
  917. });
  918. });
  919. describe('testMode = true', function() {
  920. before(function() {
  921. App.set('testMode', false);
  922. });
  923. it('should add request', function() {
  924. var clusterName = 'c1';
  925. installerStep8Controller.reopen({clusterName: clusterName});
  926. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  927. installerStep8Controller.get('ajaxRequestsQueue').clear();
  928. installerStep8Controller.addRequestToAjaxQueue({name:'name', data:{}});
  929. var request = installerStep8Controller.get('ajaxRequestsQueue.queue.firstObject');
  930. expect(request.error).to.equal('ajaxQueueRequestErrorCallback');
  931. expect(request.data.cluster).to.equal(clusterName);
  932. });
  933. });
  934. });
  935. describe('#ajaxQueueRequestErrorCallback', function() {
  936. var obj = Em.Object.create({
  937. registerErrPopup: Em.K,
  938. setStepsEnable: Em.K
  939. });
  940. beforeEach(function() {
  941. sinon.stub(App.router, 'get', function() {
  942. return obj;
  943. });
  944. sinon.spy(obj, 'registerErrPopup');
  945. sinon.spy(obj, 'setStepsEnable');
  946. });
  947. afterEach(function() {
  948. App.router.get.restore();
  949. obj.registerErrPopup.restore();
  950. obj.setStepsEnable.restore();
  951. });
  952. it('should set hasErrorOccurred true', function () {
  953. installerStep8Controller.set('hasErrorOccurred', false);
  954. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  955. expect(installerStep8Controller.get('hasErrorOccurred')).to.equal(true);
  956. });
  957. it('should set isSubmitDisabled false', function () {
  958. installerStep8Controller.set('isSubmitDisabled', true);
  959. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  960. expect(installerStep8Controller.get('isSubmitDisabled')).to.equal(false);
  961. });
  962. it('should set isBackBtnDisabled false', function () {
  963. installerStep8Controller.set('isBackBtnDisabled', true);
  964. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  965. expect(installerStep8Controller.get('isBackBtnDisabled')).to.equal(false);
  966. });
  967. it('should call setStepsEnable', function () {
  968. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  969. expect(obj.setStepsEnable.calledOnce).to.equal(true);
  970. });
  971. it('should call registerErrPopup', function () {
  972. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  973. expect(obj.registerErrPopup.calledOnce).to.equal(true);
  974. });
  975. });
  976. describe('#removeInstalledServicesConfigurationGroups', function() {
  977. beforeEach(function() {
  978. sinon.stub(App.config, 'deleteConfigGroup', Em.K);
  979. });
  980. afterEach(function() {
  981. App.config.deleteConfigGroup.restore();
  982. });
  983. it('should call App.config.deleteConfigGroup for each received group', function() {
  984. var groups = [{}, {}, {}];
  985. installerStep8Controller.removeInstalledServicesConfigurationGroups(groups);
  986. expect(App.config.deleteConfigGroup.callCount).to.equal(groups.length);
  987. });
  988. });
  989. describe('#addDynamicProperties', function() {
  990. it('shouldn\'t add property', function() {
  991. var serviceConfigProperties = [
  992. {name: 'templeton.hive.properties'}
  993. ],
  994. configs = [];
  995. installerStep8Controller.reopen({content: {serviceConfigProperties: serviceConfigProperties}});
  996. installerStep8Controller.addDynamicProperties(configs);
  997. expect(configs.length).to.equal(0);
  998. });
  999. it('should add property', function() {
  1000. var serviceConfigProperties = [],
  1001. configs = [];
  1002. installerStep8Controller.reopen({content: {serviceConfigProperties: serviceConfigProperties}});
  1003. installerStep8Controller.addDynamicProperties(configs);
  1004. expect(configs.length).to.equal(1);
  1005. });
  1006. });
  1007. describe('#applyInstalledServicesConfigurationGroup', function() {
  1008. beforeEach(function() {
  1009. sinon.stub($, 'ajax', Em.K);
  1010. sinon.stub(App.router, 'get', function() {
  1011. return configurationController;
  1012. });
  1013. });
  1014. afterEach(function() {
  1015. $.ajax.restore();
  1016. App.router.get.restore();
  1017. });
  1018. it('should do ajax request for each config group', function() {
  1019. var configGroups = [{ConfigGroup: {id:''}}, {ConfigGroup: {id:''}}];
  1020. installerStep8Controller.applyInstalledServicesConfigurationGroup(configGroups);
  1021. expect($.ajax.callCount).to.equal(configGroups.length);
  1022. });
  1023. });
  1024. describe('#getExistingClusterNames', function() {
  1025. beforeEach(function() {
  1026. sinon.stub(App.ajax, 'send', Em.K);
  1027. });
  1028. afterEach(function() {
  1029. App.ajax.send.restore();
  1030. });
  1031. it('should do ajax request', function() {
  1032. installerStep8Controller.getExistingClusterNames();
  1033. expect(App.ajax.send.calledOnce).to.be.true;
  1034. });
  1035. });
  1036. describe('#loadUiSideConfigs', function() {
  1037. beforeEach(function() {
  1038. sinon.stub(installerStep8Controller, 'addDynamicProperties', Em.K);
  1039. sinon.stub(installerStep8Controller, 'getGlobConfigValueWithOverrides', function(t, v, n) {
  1040. return {
  1041. value: v,
  1042. overrides: []
  1043. }
  1044. });
  1045. sinon.stub(App.config, 'setConfigValue', Em.K);
  1046. });
  1047. afterEach(function() {
  1048. installerStep8Controller.addDynamicProperties.restore();
  1049. installerStep8Controller.getGlobConfigValueWithOverrides.restore();
  1050. App.config.setConfigValue.restore();
  1051. });
  1052. it('all configs witohut foreignKey', function() {
  1053. var configMapping = [
  1054. {foreignKey: null, templateName: 't1', value: 'v1', name: 'c1', filename: 'f1'},
  1055. {foreignKey: null, templateName: 't2', value: 'v2', name: 'c2', filename: 'f2'},
  1056. {foreignKey: null, templateName: 't3', value: 'v3', name: 'c3', filename: 'f2'},
  1057. {foreignKey: null, templateName: 't4', value: 'v4', name: 'c4', filename: 'f1'}
  1058. ];
  1059. var uiConfigs = installerStep8Controller.loadUiSideConfigs(configMapping);
  1060. expect(uiConfigs.length).to.equal(configMapping.length);
  1061. expect(uiConfigs.everyProperty('id', 'site property')).to.be.true;
  1062. uiConfigs.forEach(function(c, index) {
  1063. expect(c.overrides).to.be.an.array;
  1064. expect(c.value).to.equal(configMapping[index].value);
  1065. expect(c.name).to.equal(configMapping[index].name);
  1066. expect(c.filename).to.equal(configMapping[index].filename);
  1067. });
  1068. });
  1069. it('some configs witohut foreignKey', function() {
  1070. var configMapping = [
  1071. {foreignKey: null, templateName: 't1', value: 'v1', name: 'c1', filename: 'f1'},
  1072. {foreignKey: null, templateName: 't2', value: 'v2', name: 'c2', filename: 'f2'},
  1073. {foreignKey: null, templateName: 't3', value: 'v3', name: 'c3', filename: 'f2'},
  1074. {foreignKey: null, templateName: 't4', value: 'v4', name: 'c4', filename: 'f1'},
  1075. {foreignKey: 'fk1', templateName: 't5', value: 'v5', name: 'c5', filename: 'f1'},
  1076. {foreignKey: 'fk2', templateName: 't6', value: 'v6', name: 'c6', filename: 'f1'},
  1077. {foreignKey: 'fk3', templateName: 't7', value: 'v7', name: 'c7', filename: 'f2'},
  1078. {foreignKey: 'fk4', templateName: 't8', value: 'v8', name: 'c8', filename: 'f2'}
  1079. ];
  1080. var uiConfigs = installerStep8Controller.loadUiSideConfigs(configMapping);
  1081. expect(uiConfigs.length).to.equal(configMapping.length);
  1082. expect(uiConfigs.everyProperty('id', 'site property')).to.be.true;
  1083. uiConfigs.forEach(function(c, index) {
  1084. if (Em.isNone(configMapping[index].foreignKey))
  1085. expect(c.overrides).to.be.an.array;
  1086. expect(c.value).to.equal(configMapping[index].value);
  1087. expect(c.name).to.equal(configMapping[index].name);
  1088. expect(c.filename).to.equal(configMapping[index].filename);
  1089. });
  1090. });
  1091. });
  1092. describe('Queued requests', function() {
  1093. beforeEach(function() {
  1094. sinon.stub(installerStep8Controller, 'addRequestToAjaxQueue', Em.K);
  1095. });
  1096. afterEach(function() {
  1097. installerStep8Controller.addRequestToAjaxQueue.restore();
  1098. });
  1099. describe('#createCluster', function() {
  1100. it('shouldn\'t add request to queue if not installerController used', function() {
  1101. installerStep8Controller.reopen({content: {controllerName: 'addServiceController'}});
  1102. installerStep8Controller.createCluster();
  1103. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1104. });
  1105. it('App.currentStackVersion should be changed if localRepo selected', function() {
  1106. App.set('currentStackVersion', 'HDP-1.1.1');
  1107. installerStep8Controller.reopen({content: {controllerName: 'installerController', installOptions: {localRepo: true}}});
  1108. var data = {
  1109. data: JSON.stringify({ "Clusters": {"version": 'HDPLocal-1.1.1' }})
  1110. };
  1111. installerStep8Controller.createCluster();
  1112. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.eql(data);
  1113. });
  1114. it('App.currentStackVersion shouldn\'t be changed if localRepo ins\'t selected', function() {
  1115. App.set('currentStackVersion', 'HDP-1.1.1');
  1116. installerStep8Controller.reopen({content: {controllerName: 'installerController', installOptions: {localRepo: false}}});
  1117. var data = {
  1118. data: JSON.stringify({ "Clusters": {"version": 'HDP-1.1.1' }})
  1119. };
  1120. installerStep8Controller.createCluster();
  1121. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.eql(data);
  1122. });
  1123. });
  1124. describe('#createSelectedServices', function() {
  1125. it('shouldn\'t do nothing if no data', function() {
  1126. sinon.stub(installerStep8Controller, 'createSelectedServicesData', function() {return [];});
  1127. installerStep8Controller.createSelectedServices();
  1128. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1129. installerStep8Controller.createSelectedServicesData.restore();
  1130. });
  1131. it('should call addRequestToAjaxQueue with computed data', function() {
  1132. var data = [
  1133. {"ServiceInfo": { "service_name": 's1' }},
  1134. {"ServiceInfo": { "service_name": 's2' }},
  1135. {"ServiceInfo": { "service_name": 's3' }}
  1136. ];
  1137. sinon.stub(installerStep8Controller, 'createSelectedServicesData', function() {return data;});
  1138. installerStep8Controller.createSelectedServices();
  1139. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.eql({data: JSON.stringify(data)});
  1140. installerStep8Controller.createSelectedServicesData.restore();
  1141. });
  1142. });
  1143. describe('#registerHostsToCluster', function() {
  1144. it('shouldn\'t do nothing if no data', function() {
  1145. sinon.stub(installerStep8Controller, 'createRegisterHostData', function() {return [];});
  1146. installerStep8Controller.registerHostsToCluster();
  1147. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1148. installerStep8Controller.createRegisterHostData.restore();
  1149. });
  1150. it('should call addRequestToAjaxQueue with computed data', function() {
  1151. var data = [
  1152. {"Hosts": { "host_name": 'h1'}},
  1153. {"Hosts": { "host_name": 'h3'}}
  1154. ];
  1155. sinon.stub(installerStep8Controller, 'createRegisterHostData', function() {return data;});
  1156. installerStep8Controller.registerHostsToCluster();
  1157. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.eql({data: JSON.stringify(data)});
  1158. installerStep8Controller.createRegisterHostData.restore();
  1159. });
  1160. });
  1161. describe('#registerHostsToComponent', function() {
  1162. it('shouldn\'t do request if no hosts provided', function() {
  1163. installerStep8Controller.registerHostsToComponent([]);
  1164. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1165. });
  1166. it('should do request if hostNames are provided', function() {
  1167. var hostNames = ['h1', 'h2'],
  1168. componentName = 'c1';
  1169. installerStep8Controller.registerHostsToComponent(hostNames, componentName);
  1170. var data = JSON.parse(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data);
  1171. expect(data.RequestInfo.query).to.equal('Hosts/host_name=h1|Hosts/host_name=h2');
  1172. expect(data.Body.host_components[0].HostRoles.component_name).to.equal('c1');
  1173. });
  1174. });
  1175. describe('#applyConfigurationsToCluster', function() {
  1176. it('should call addRequestToAjaxQueue', function() {
  1177. var serviceConfigTags = [
  1178. {
  1179. type: 'hdfs',
  1180. tag: 'tag1',
  1181. properties: [
  1182. {},
  1183. {}
  1184. ]
  1185. }
  1186. ],
  1187. data = '['+JSON.stringify({
  1188. Clusters: {
  1189. desired_config: [serviceConfigTags[0]]
  1190. }
  1191. })+']';
  1192. installerStep8Controller.reopen({
  1193. installedServices: [
  1194. Em.Object.create({
  1195. isSelected: true,
  1196. isInstalled: false,
  1197. configTypesRendered: {hdfs:'tag1'}
  1198. })
  1199. ], selectedServices: []
  1200. });
  1201. installerStep8Controller.applyConfigurationsToCluster(serviceConfigTags);
  1202. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.eql({data: data});
  1203. });
  1204. });
  1205. describe('#applyConfigurationGroups', function() {
  1206. it('should call addRequestToAjaxQueue', function() {
  1207. var data = [{}, {}];
  1208. installerStep8Controller.applyConfigurationGroups(data);
  1209. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.eql({data: JSON.stringify(data)});
  1210. });
  1211. });
  1212. describe('#newServiceComponentErrorCallback', function() {
  1213. it('should add request for new component', function() {
  1214. var serviceName = 's1',
  1215. componentName = 'c1';
  1216. installerStep8Controller.newServiceComponentErrorCallback({}, {}, '', {}, {serviceName: serviceName, componentName: componentName});
  1217. var data = JSON.parse(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data);
  1218. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.serviceName).to.equal(serviceName);
  1219. expect(data.components[0].ServiceComponentInfo.component_name).to.equal(componentName);
  1220. });
  1221. });
  1222. describe('#createAdditionalHostComponents', function() {
  1223. beforeEach(function() {
  1224. sinon.stub(installerStep8Controller, 'registerHostsToComponent', Em.K);
  1225. });
  1226. afterEach(function() {
  1227. installerStep8Controller.registerHostsToComponent.restore();
  1228. });
  1229. it('should add components with isRequiredOnAllHosts == true (1)', function() {
  1230. installerStep8Controller.reopen({
  1231. getRegisteredHosts: function() {
  1232. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1233. },
  1234. content: {
  1235. services: [
  1236. Em.Object.create({
  1237. serviceName: 'GANGLIA', isSelected: true, isInstalled: false, serviceComponents: [
  1238. Em.Object.create({
  1239. componentName: 'GANGLIA_MONITOR',
  1240. isRequiredOnAllHosts: true
  1241. }),
  1242. Em.Object.create({
  1243. componentName: 'GANGLIA_SERVER',
  1244. isRequiredOnAllHosts: false
  1245. })
  1246. ]
  1247. })
  1248. ]
  1249. }
  1250. });
  1251. installerStep8Controller.createAdditionalHostComponents();
  1252. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1253. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1254. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('GANGLIA_MONITOR');
  1255. });
  1256. it('should add components with isRequiredOnAllHosts == true (2)', function() {
  1257. installerStep8Controller.reopen({
  1258. getRegisteredHosts: function() {
  1259. return [{hostName: 'h1', isInstalled: true}, {hostName: 'h2', isInstalled: false}];
  1260. },
  1261. content: {
  1262. services: [
  1263. Em.Object.create({
  1264. serviceName: 'GANGLIA', isSelected: true, isInstalled: true, serviceComponents: [
  1265. Em.Object.create({
  1266. componentName: 'GANGLIA_MONITOR',
  1267. isRequiredOnAllHosts: true
  1268. }),
  1269. Em.Object.create({
  1270. componentName: 'GANGLIA_SERVER',
  1271. isRequiredOnAllHosts: false
  1272. })
  1273. ]
  1274. })
  1275. ]
  1276. }
  1277. });
  1278. installerStep8Controller.createAdditionalHostComponents();
  1279. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1280. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h2']);
  1281. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('GANGLIA_MONITOR');
  1282. });
  1283. var newDatabases = [
  1284. {name: 'New MySQL Database',
  1285. component: 'MYSQL_SERVER'
  1286. },
  1287. {name: 'New PostgreSQL Database',
  1288. component: 'POSTGRESQL_SERVER'
  1289. }
  1290. ];
  1291. newDatabases.forEach(function (db) {
  1292. it('should add {0}'.format(db.component), function() {
  1293. installerStep8Controller.reopen({
  1294. getRegisteredHosts: function() {
  1295. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1296. },
  1297. content: {
  1298. masterComponentHosts: [
  1299. {component: 'HIVE_SERVER', hostName: 'h1'},
  1300. {component: 'HIVE_SERVER', hostName: 'h2'}
  1301. ],
  1302. services: [
  1303. Em.Object.create({serviceName: 'HIVE', isSelected: true, isInstalled: false, serviceComponents: []})
  1304. ],
  1305. serviceConfigProperties: [
  1306. {name: 'hive_database', value: db.name}
  1307. ]
  1308. }
  1309. });
  1310. installerStep8Controller.createAdditionalHostComponents();
  1311. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1312. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1313. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal(db.component);
  1314. });
  1315. });
  1316. });
  1317. describe('#createNotification', function () {
  1318. beforeEach(function () {
  1319. installerStep8Controller.set('content', {controllerName: 'installerController'});
  1320. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  1321. installerStep8Controller.set('configs', [
  1322. {name: 'create_notification', value: 'yes', serviceName: 'MISC'},
  1323. {name: 'ambari.dispatch.recipients', value: 'to@f.c', serviceName: 'MISC'},
  1324. {name: 'mail.smtp.host', value: 'h', serviceName: 'MISC'},
  1325. {name: 'mail.smtp.port', value: '25', serviceName: 'MISC'},
  1326. {name: 'mail.smtp.from', value: 'from@f.c', serviceName: 'MISC'},
  1327. {name: 'mail.smtp.starttls.enable', value: true, serviceName: 'MISC'},
  1328. {name: 'mail.smtp.startssl.enable', value: false, serviceName: 'MISC'},
  1329. {name: 'smtp_use_auth', value: 'false', serviceName: 'MISC'},
  1330. ]);
  1331. sinon.stub(App, 'get', function (k) {
  1332. if ('isHadoop2Stack' === k) return true;
  1333. return Em.get(App, k);
  1334. });
  1335. });
  1336. afterEach(function () {
  1337. App.get.restore();
  1338. });
  1339. it('should add request to queue', function () {
  1340. installerStep8Controller.createNotification();
  1341. expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(1);
  1342. });
  1343. });
  1344. });
  1345. describe("#resolveProxyuserDependecies()", function() {
  1346. it("No core-site configs", function() {
  1347. expect(installerStep8Controller.resolveProxyuserDependecies([], [])).to.be.empty;
  1348. });
  1349. it("Only proxyuser group config", function() {
  1350. var configs = [{
  1351. name: 'proxyuser_group'
  1352. }];
  1353. installerStep8Controller.set('configs', [{
  1354. name: 'proxyuser_group',
  1355. value: 'val1'
  1356. }]);
  1357. expect(installerStep8Controller.resolveProxyuserDependecies(configs, [])).to.be.empty;
  1358. });
  1359. it("Property should be added", function() {
  1360. var configs = [
  1361. {
  1362. name: 'proxyuser_group'
  1363. },
  1364. {
  1365. name: 'hadoop.proxyuser.user.hosts',
  1366. value: 'val2'
  1367. }
  1368. ];
  1369. installerStep8Controller.set('configs', [{
  1370. name: 'proxyuser_group',
  1371. value: 'val1'
  1372. }]);
  1373. expect(installerStep8Controller.resolveProxyuserDependecies(configs, [])).to.be.eql({
  1374. 'hadoop.proxyuser.user.hosts': 'val2',
  1375. 'proxyuser_group': 'val1'
  1376. });
  1377. });
  1378. it("Property should be skipped", function() {
  1379. var configs = [
  1380. {
  1381. name: 'proxyuser_group'
  1382. },
  1383. {
  1384. name: 'hadoop.proxyuser.user.hosts',
  1385. value: 'val2'
  1386. }
  1387. ];
  1388. installerStep8Controller.set('configs', [
  1389. {
  1390. name: 'proxyuser_group',
  1391. value: 'val1'
  1392. },
  1393. {
  1394. name: 'user1',
  1395. value: 'user'
  1396. }
  1397. ]);
  1398. installerStep8Controller.set('optionalCoreSiteConfigs', [
  1399. {
  1400. serviceName: 'S1',
  1401. user: 'user1'
  1402. }
  1403. ]);
  1404. expect(installerStep8Controller.resolveProxyuserDependecies(configs, [])).to.be.empty;
  1405. });
  1406. });
  1407. });