step8_test.js 68 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763
  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_database', 'hive_existing_oracle_database', 'hive_existing_postgresql_database', 'hive_master_hosts']),
  273. m: 'hive_database: New MySQL Database',
  274. host: 'h1'
  275. },
  276. {
  277. globals: [
  278. {name: 'hive_database', value: 'Existing MySQL Database'},
  279. {name: 'hive_database_type', value: 'mysql'},
  280. {name: 'hive_existing_mysql_host', value: 'h1'},
  281. {name: 'hive_hostname', value: 'h2'}
  282. ],
  283. removed: Em.A(['hive_ambari_database', 'hive_existing_oracle_database', 'hive_existing_postgresql_database', 'hive_master_hosts']),
  284. m: 'hive_database: Existing MySQL Database',
  285. host: 'h1'
  286. },
  287. {
  288. globals: [
  289. {name: 'hive_database', value: 'Existing PostgreSQL Database'},
  290. {name: 'hive_database_type', value: 'postgresql'},
  291. {name: 'hive_existing_postgresql_host', value: 'h1'},
  292. {name: 'hive_hostname', value: 'h2'}
  293. ],
  294. removed: Em.A(['hive_ambari_database', 'hive_existing_oracle_database', 'hive_existing_mysql_database', 'hive_master_hosts']),
  295. m: 'hive_database: Existing PostgreSQL Database',
  296. host: 'h1'
  297. },
  298. {
  299. globals: [
  300. {name: 'hive_database', value: 'Existing Oracle Database'},
  301. {name: 'hive_database_type', value: 'oracle'},
  302. {name: 'hive_existing_oracle_host', value: 'h1'},
  303. {name: 'hive_hostname', value: 'h2'}
  304. ],
  305. removed: Em.A(['hive_ambari_database', 'hive_existing_mysql_database', 'hive_existing_postgresql_database', 'hive_master_hosts']),
  306. m: 'hive_database: Existing Oracle Database',
  307. host: 'h1'
  308. }
  309. ]).forEach(function (test) {
  310. it(test.m, function () {
  311. test.removed.forEach(function (c) {
  312. test.globals.pushObject({name: c})
  313. });
  314. var configs = installerStep8Controller.removeHiveConfigs(test.globals);
  315. test.removed.forEach(function(name) {
  316. expect(Em.isNone(configs.findProperty('name', name))).to.equal(true);
  317. });
  318. expect(configs.findProperty('name', 'hive_hostname').value).to.equal(test.host);
  319. });
  320. });
  321. });
  322. describe('#removeOozieConfigs', function () {
  323. Em.A([
  324. {
  325. globals: [
  326. {name: 'oozie_database', value: 'New Derby Database'},
  327. {name: 'oozie_ambari_host', value: 'h1'},
  328. {name: 'oozie_hostname', value: 'h2'}
  329. ],
  330. removed: Em.A(['oozie_ambari_database', 'oozie_existing_mysql_database', 'oozie_existing_oracle_database',
  331. 'oozie_existing_postgresql_database']),
  332. m: 'oozie_database: New Derby Database',
  333. host: 'h1'
  334. },
  335. {
  336. globals: [
  337. {name: 'oozie_database', value: 'Existing MySQL Database'},
  338. {name: 'oozie_existing_mysql_host', value: 'h1'},
  339. {name: 'oozie_hostname', value: 'h2'}
  340. ],
  341. removed: Em.A(['oozie_ambari_database', 'oozie_existing_oracle_database', 'oozie_derby_database',
  342. 'oozie_existing_postgresql_database']),
  343. m: 'oozie_database: Existing MySQL Database',
  344. host: 'h1'
  345. },
  346. {
  347. globals: [
  348. {name: 'oozie_database', value: 'Existing PostgreSQL Database'},
  349. {name: 'oozie_existing_postgresql_host', value: 'h1'},
  350. {name: 'oozie_hostname', value: 'h2'}
  351. ],
  352. removed: Em.A(['oozie_ambari_database', 'oozie_existing_oracle_database', 'oozie_existing_mysql_database']),
  353. m: 'oozie_database: Existing PostgreSQL Database',
  354. host: 'h1'
  355. },
  356. {
  357. globals: [
  358. {name: 'oozie_database', value: 'Existing Oracle Database'},
  359. {name: 'oozie_existing_oracle_host', value: 'h1'},
  360. {name: 'oozie_hostname', value: 'h2'}
  361. ],
  362. removed: Em.A(['oozie_ambari_database', 'oozie_existing_mysql_database', 'oozie_derby_database',
  363. 'oozie_existing_postgresql_database']),
  364. m: 'oozie_database: Existing Oracle Database',
  365. host: 'h1'
  366. }
  367. ]).forEach(function (test) {
  368. it(test.m, function () {
  369. test.removed.forEach(function (c) {
  370. if (!test.globals.findProperty('name', c)) {
  371. test.globals.pushObject({name: c})
  372. }
  373. });
  374. var configs = installerStep8Controller.removeOozieConfigs(test.globals);
  375. test.removed.forEach(function(name) {
  376. expect(Em.isNone(configs.findProperty('name', name))).to.equal(true);
  377. });
  378. expect(configs.findProperty('name', 'oozie_hostname').value).to.equal(test.host);
  379. });
  380. });
  381. });
  382. describe('#getRegisteredHosts', function() {
  383. Em.A([
  384. {
  385. hosts: {},
  386. m: 'no content.hosts',
  387. e: []
  388. },
  389. {
  390. hosts: {
  391. h1:{bootStatus: ''},
  392. h2:{bootStatus: ''}
  393. },
  394. m: 'no registered hosts',
  395. e: []
  396. },
  397. {
  398. hosts: {
  399. h1:{bootStatus: 'REGISTERED', hostName: '', name: 'n1'},
  400. h2:{bootStatus: 'REGISTERED', hostName: '', name: 'n2'}
  401. },
  402. m: 'registered hosts available',
  403. e: ['n1', 'n2']
  404. }
  405. ]).forEach(function(test) {
  406. it(test.m, function() {
  407. installerStep8Controller.set('content', {hosts: test.hosts});
  408. var hosts = installerStep8Controller.getRegisteredHosts();
  409. expect(hosts.mapProperty('hostName')).to.eql(test.e);
  410. });
  411. });
  412. });
  413. describe('#loadRepoInfo', function() {
  414. it('should use App.currentStackVersion', function() {
  415. var version = 'HDP-1.1.1';
  416. sinon.stub(App, 'get', function() {return version;});
  417. sinon.stub(App.ajax, 'send', Em.K);
  418. installerStep8Controller.loadRepoInfo();
  419. var data = App.ajax.send.args[0][0].data;
  420. expect(data).to.eql({stackName: 'HDP', stackVersion: '1.1.1'});
  421. App.ajax.send.restore();
  422. App.get.restore();
  423. });
  424. });
  425. describe('#loadRepoInfoSuccessCallback', function () {
  426. beforeEach(function () {
  427. installerStep8Controller.set('clusterInfo', Em.Object.create({}));
  428. });
  429. Em.A([
  430. {
  431. items: [],
  432. m: 'no data',
  433. e: {
  434. base_url: [],
  435. os_type: []
  436. }
  437. },
  438. {
  439. items: [
  440. {
  441. repositories: [
  442. {
  443. Repositories: {
  444. os_type: 'redhat5',
  445. base_url: 'url1'
  446. }
  447. }
  448. ],
  449. OperatingSystems: {
  450. is_type: ''
  451. }
  452. }
  453. ],
  454. m: 'only redhat5',
  455. e: {
  456. base_url: ['url1'],
  457. os_type: ['redhat5']
  458. }
  459. },
  460. {
  461. items: [
  462. {
  463. repositories: [
  464. {
  465. Repositories: {
  466. os_type: 'redhat5',
  467. base_url: 'url1'
  468. }
  469. }
  470. ],
  471. OperatingSystems: {
  472. is_type: ''
  473. }
  474. },
  475. {
  476. repositories: [
  477. {
  478. Repositories: {
  479. os_type: 'redhat6',
  480. base_url: 'url2'
  481. }
  482. }
  483. ],
  484. OperatingSystems: {
  485. is_type: ''
  486. }
  487. }
  488. ],
  489. m: 'redhat5, redhat6',
  490. e: {
  491. base_url: ['url1', 'url2'],
  492. os_type: ['redhat5', 'redhat6']
  493. }
  494. },
  495. {
  496. items: [
  497. {
  498. repositories: [
  499. {
  500. Repositories: {
  501. os_type: 'redhat5',
  502. base_url: 'url1'
  503. }
  504. }
  505. ],
  506. OperatingSystems: {
  507. is_type: ''
  508. }
  509. },
  510. {
  511. repositories: [
  512. {
  513. Repositories: {
  514. os_type: 'redhat6',
  515. base_url: 'url2'
  516. }
  517. }
  518. ],
  519. OperatingSystems: {
  520. is_type: ''
  521. }
  522. },
  523. {
  524. repositories: [
  525. {
  526. Repositories: {
  527. os_type: 'sles11',
  528. base_url: 'url3'
  529. }
  530. }
  531. ],
  532. OperatingSystems: {
  533. is_type: ''
  534. }
  535. }
  536. ],
  537. m: 'redhat5, redhat6, sles11',
  538. e: {
  539. base_url: ['url1', 'url2', 'url3'],
  540. os_type: ['redhat5', 'redhat6', 'sles11']
  541. }
  542. }
  543. ]).forEach(function (test) {
  544. it(test.m, function () {
  545. installerStep8Controller.loadRepoInfoSuccessCallback({items: test.items});
  546. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('base_url')).to.eql(test.e.base_url);
  547. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('os_type')).to.eql(test.e.os_type);
  548. });
  549. });
  550. });
  551. describe('#loadRepoInfoErrorCallback', function() {
  552. it('should set [] to repoInfo', function() {
  553. installerStep8Controller.set('clusterInfo', Em.Object.create({repoInfo: [{}, {}]}));
  554. installerStep8Controller.loadRepoInfoErrorCallback({});
  555. expect(installerStep8Controller.get('clusterInfo.repoInfo.length')).to.eql(0);
  556. });
  557. });
  558. describe('#loadHiveDbValue', function() {
  559. beforeEach(function() {
  560. installerStep8Controller.set('wizardController', Em.Object.create({
  561. getDBProperty: Em.K
  562. }));
  563. });
  564. Em.A([
  565. {
  566. serviceConfigProperties: [
  567. {name: 'hive_database', value: 'New MySQL Database'}
  568. ],
  569. m: 'New MySQL Database',
  570. e: 'MySQL (New Database)'
  571. },
  572. {
  573. serviceConfigProperties: [
  574. {name: 'hive_database', value: 'New PostgreSQL Database'}
  575. ],
  576. m: 'New PostgreSQL Database',
  577. e: 'Postgres (New Database)'
  578. },
  579. {
  580. serviceConfigProperties: [
  581. {name: 'hive_database', value: 'Existing MySQL Database'},
  582. {name: 'hive_existing_mysql_database', value: 'dbname'}
  583. ],
  584. m: 'Existing MySQL Database',
  585. e: 'dbname (Existing MySQL Database)'
  586. },
  587. {
  588. serviceConfigProperties: [
  589. {name: 'hive_database', value: 'Existing PostgreSQL Database'},
  590. {name: 'hive_existing_postgresql_database', value: 'dbname'}
  591. ],
  592. m: 'Existing PostgreSQL Database',
  593. e: 'dbname (Existing PostgreSQL Database)'
  594. },
  595. {
  596. serviceConfigProperties: [
  597. {name: 'hive_database', value: 'Existing Oracle Database'},
  598. {name: 'hive_existing_oracle_database', value: 'dbname'}
  599. ],
  600. m: 'Existing Oracle Database',
  601. e: 'dbname (Existing Oracle Database)'
  602. }
  603. ]).forEach(function(test) {
  604. it(test.m, function() {
  605. sinon.stub(installerStep8Controller.get('wizardController'), 'getDBProperty', function() {
  606. return test.serviceConfigProperties;
  607. });
  608. var dbComponent = installerStep8Controller.loadHiveDbValue();
  609. expect(dbComponent).to.equal(test.e);
  610. installerStep8Controller.get('wizardController').getDBProperty.restore();
  611. });
  612. });
  613. });
  614. describe('#loadHbaseMasterValue', function () {
  615. Em.A([
  616. {
  617. masterComponentHosts: [{component: 'HBASE_MASTER', hostName: 'h1'}],
  618. component: Em.Object.create({component_name: 'HBASE_MASTER'}),
  619. m: 'one host',
  620. e: 'h1'
  621. },
  622. {
  623. masterComponentHosts: [{component: 'HBASE_MASTER', hostName: 'h1'}, {component: 'HBASE_MASTER', hostName: 'h2'}, {component: 'HBASE_MASTER', hostName: 'h3'}],
  624. component: Em.Object.create({component_name: 'HBASE_MASTER'}),
  625. m: 'many hosts',
  626. e: 'h1 ' + Em.I18n.t('installer.step8.other').format(2)
  627. }
  628. ]).forEach(function (test) {
  629. it(test.m, function() {
  630. installerStep8Controller.set('content', {masterComponentHosts: test.masterComponentHosts});
  631. installerStep8Controller.loadHbaseMasterValue(test.component);
  632. expect(test.component.component_value).to.equal(test.e);
  633. });
  634. });
  635. });
  636. describe('#loadZkServerValue', function() {
  637. Em.A([
  638. {
  639. masterComponentHosts: [{component: 'ZOOKEEPER_SERVER'}],
  640. component: Em.Object.create({component_name: 'ZOOKEEPER_SERVER'}),
  641. m: '1 host',
  642. e: '1 host'
  643. },
  644. {
  645. masterComponentHosts: [{component: 'ZOOKEEPER_SERVER'},{component: 'ZOOKEEPER_SERVER'},{component: 'ZOOKEEPER_SERVER'}],
  646. component: Em.Object.create({component_name: 'ZOOKEEPER_SERVER'}),
  647. m: 'many hosts',
  648. e: '3 hosts'
  649. }
  650. ]).forEach(function (test) {
  651. it(test.m, function () {
  652. installerStep8Controller.set('content', {masterComponentHosts: test.masterComponentHosts});
  653. installerStep8Controller.loadZkServerValue(test.component);
  654. expect(test.component.component_value).to.equal(test.e);
  655. });
  656. });
  657. });
  658. describe('#loadOozieDbValue', function() {
  659. beforeEach(function() {
  660. installerStep8Controller.set('wizardController', Em.Object.create({
  661. getDBProperty: Em.K
  662. }));
  663. });
  664. Em.A([
  665. {
  666. serviceConfigProperties: [
  667. {name: 'oozie_database', value: 'New Derby Database'},
  668. {name: 'oozie_derby_database', value: 'dbname'}
  669. ],
  670. m: 'New Derby Database',
  671. e: 'dbname (New Derby Database)'
  672. },
  673. {
  674. serviceConfigProperties: [
  675. {name: 'oozie_database', value: 'Existing MySQL Database'},
  676. {name: 'oozie_existing_mysql_database', value: 'dbname'}
  677. ],
  678. m: 'Existing MySQL Database',
  679. e: 'dbname (Existing MySQL Database)'
  680. },
  681. {
  682. serviceConfigProperties: [
  683. {name: 'oozie_database', value: 'Existing PostgreSQL Database'},
  684. {name: 'oozie_existing_postgresql_database', value: 'dbname'}
  685. ],
  686. m: 'Existing PostgreSQL Database',
  687. e: 'dbname (Existing PostgreSQL Database)'
  688. },
  689. {
  690. serviceConfigProperties: [
  691. {name: 'oozie_database', value: 'Existing Oracle Database'},
  692. {name: 'oozie_existing_oracle_database', value: 'dbname'}
  693. ],
  694. m: 'Existing Oracle Database',
  695. e: 'dbname (Existing Oracle Database)'
  696. }
  697. ]).forEach(function(test) {
  698. it(test.m, function() {
  699. sinon.stub(installerStep8Controller.get('wizardController'), 'getDBProperty', function() {
  700. return test.serviceConfigProperties;
  701. });
  702. var dbComponent = installerStep8Controller.loadOozieDbValue();
  703. expect(dbComponent).to.equal(test.e);
  704. installerStep8Controller.get('wizardController').getDBProperty.restore();
  705. });
  706. });
  707. });
  708. describe('#loadNagiosAdminValue', function() {
  709. it('should use serviceConfigProperties nagios_web_login and nagios_contact', function() {
  710. installerStep8Controller.set('content', {
  711. serviceConfigProperties: [
  712. {name: 'nagios_web_login', value: 'admin'},
  713. {name: 'nagios_contact', value: 'admin@admin.com'}
  714. ]
  715. });
  716. var nagiosAdmin = installerStep8Controller.loadNagiosAdminValue();
  717. expect(nagiosAdmin).to.equal('admin / (admin@admin.com)');
  718. });
  719. });
  720. describe('#submit', function() {
  721. beforeEach(function() {
  722. sinon.stub(installerStep8Controller, 'submitProceed', Em.K);
  723. sinon.spy(App, 'showConfirmationPopup');
  724. });
  725. afterEach(function() {
  726. installerStep8Controller.submitProceed.restore();
  727. App.showConfirmationPopup.restore();
  728. });
  729. Em.A([
  730. {
  731. controllerName: 'addHostController',
  732. securityEnabled: true,
  733. e: true
  734. },
  735. {
  736. controllerName: 'addHostController',
  737. securityEnabled: false,
  738. e: false
  739. },
  740. {
  741. controllerName: 'addServiceController',
  742. securityEnabled: true,
  743. e: false
  744. },
  745. {
  746. controllerName: 'addServiceController',
  747. securityEnabled: false,
  748. e: false
  749. }
  750. ]).forEach(function (test) {
  751. it(test.controllerName + ' ' + test.securityEnabled.toString(), function () {
  752. installerStep8Controller.reopen({isSubmitDisabled: false, securityEnabled: test.securityEnabled, content: {controllerName: test.controllerName}});
  753. installerStep8Controller.submit();
  754. if (test.e) {
  755. expect(App.showConfirmationPopup.calledOnce).to.equal(true);
  756. expect(installerStep8Controller.submitProceed.called).to.equal(false);
  757. }
  758. else {
  759. expect(App.showConfirmationPopup.called).to.equal(false);
  760. expect(installerStep8Controller.submitProceed.calledOnce).to.equal(true);
  761. }
  762. });
  763. });
  764. it('should call submitProceed when Ok clicked', function() {
  765. installerStep8Controller.reopen({isSubmitDisabled: false, securityEnabled: true, content: {controllerName: 'addHostController'}});
  766. installerStep8Controller.submit().onPrimary();
  767. expect(installerStep8Controller.submitProceed.calledOnce).to.equal(true);
  768. });
  769. it('shouldn\'t do nothing if isSubmitDisabled is true', function() {
  770. installerStep8Controller.reopen({isSubmitDisabled: true});
  771. installerStep8Controller.submit();
  772. expect(App.showConfirmationPopup.called).to.equal(false);
  773. expect(installerStep8Controller.submitProceed.called).to.equal(false);
  774. });
  775. });
  776. describe('#getExistingClusterNamesSuccessCallBack', function() {
  777. it('should set clusterNames received from server', function() {
  778. var data = {
  779. items:[
  780. {Clusters: {cluster_name: 'c1'}},
  781. {Clusters: {cluster_name: 'c2'}},
  782. {Clusters: {cluster_name: 'c3'}}
  783. ]
  784. },
  785. clasterNames = ['c1','c2','c3'];
  786. installerStep8Controller.getExistingClusterNamesSuccessCallBack(data);
  787. expect(installerStep8Controller.get('clusterNames')).to.eql(clasterNames);
  788. });
  789. });
  790. describe('#getExistingClusterNamesErrorCallback', function() {
  791. it('should set [] to clusterNames', function() {
  792. installerStep8Controller.set('clusterNames', ['c1', 'c2']);
  793. installerStep8Controller.getExistingClusterNamesErrorCallback();
  794. expect(installerStep8Controller.get('clusterNames')).to.eql([]);
  795. });
  796. });
  797. describe('#deleteClusters', function() {
  798. beforeEach(function () {
  799. sinon.stub(App.ajax, 'send', Em.K);
  800. });
  801. afterEach(function () {
  802. App.ajax.send.restore();
  803. });
  804. it('should call App.ajax.send for each provided clusterName', function() {
  805. var clusterNames = ['h1', 'h2', 'h3'];
  806. installerStep8Controller.deleteClusters(clusterNames);
  807. expect(App.ajax.send.callCount).to.equal(clusterNames.length);
  808. clusterNames.forEach(function(n, i) {
  809. expect(App.ajax.send.getCall(i).args[0].data).to.eql({name: n, isLast: i == clusterNames.length - 1});
  810. });
  811. });
  812. it('should clear cluster delete error popup body views', function () {
  813. installerStep8Controller.deleteClusters([]);
  814. expect(installerStep8Controller.get('clusterDeleteErrorViews')).to.eql([]);
  815. });
  816. });
  817. describe('#createSelectedServicesData', function() {
  818. it('should reformat provided data', function() {
  819. var selectedServices = [
  820. Em.Object.create({serviceName: 's1'}),
  821. Em.Object.create({serviceName: 's2'}),
  822. Em.Object.create({serviceName: 's3'})
  823. ];
  824. var expected = [
  825. {"ServiceInfo": { "service_name": 's1' }},
  826. {"ServiceInfo": { "service_name": 's2' }},
  827. {"ServiceInfo": { "service_name": 's3' }}
  828. ];
  829. installerStep8Controller.reopen({selectedServices: selectedServices});
  830. var createdData = installerStep8Controller.createSelectedServicesData();
  831. expect(createdData).to.eql(expected);
  832. });
  833. });
  834. describe('#createRegisterHostData', function() {
  835. it('should return empty data if no hosts', function() {
  836. sinon.stub(installerStep8Controller, 'getRegisteredHosts', function() {return [];});
  837. expect(installerStep8Controller.createRegisterHostData()).to.eql([]);
  838. installerStep8Controller.getRegisteredHosts.restore();
  839. });
  840. it('should return computed data', function() {
  841. var data = [
  842. {isInstalled: false, hostName: 'h1'},
  843. {isInstalled: true, hostName: 'h2'},
  844. {isInstalled: false, hostName: 'h3'}
  845. ];
  846. var expected = [
  847. {"Hosts": { "host_name": 'h1'}},
  848. {"Hosts": { "host_name": 'h3'}}
  849. ];
  850. sinon.stub(installerStep8Controller, 'getRegisteredHosts', function() {return data;});
  851. expect(installerStep8Controller.createRegisterHostData()).to.eql(expected);
  852. installerStep8Controller.getRegisteredHosts.restore();
  853. });
  854. });
  855. describe('#createStormSiteObj', function() {
  856. it('should replace quote \'"\' to "\'" for some properties', function() {
  857. var configs = [
  858. {filename: 'storm-site.xml', value: ["a", "b"], name: 'storm.zookeeper.servers'}
  859. ],
  860. expected = {
  861. type: 'storm-site',
  862. tag: 'version1',
  863. properties: {
  864. 'storm.zookeeper.servers': '[\'a\',\'b\']'
  865. }
  866. };
  867. installerStep8Controller.reopen({configs: configs});
  868. expect(installerStep8Controller.createStormSiteObj('version1')).to.eql(expected);
  869. });
  870. it('should not escape special characters', function() {
  871. var configs = [
  872. {filename: 'storm-site.xml', value: "abc\n\t", name: 'nimbus.childopts'},
  873. {filename: 'storm-site.xml', value: "a\nb", name: 'supervisor.childopts'},
  874. {filename: 'storm-site.xml', value: "a\t\tb", name: 'worker.childopts'}
  875. ],
  876. expected = {
  877. type: 'storm-site',
  878. tag: 'version1',
  879. properties: {
  880. 'nimbus.childopts': 'abc\n\t',
  881. 'supervisor.childopts': 'a\nb',
  882. 'worker.childopts': 'a\t\tb'
  883. }
  884. };
  885. installerStep8Controller.reopen({configs: configs});
  886. expect(installerStep8Controller.createStormSiteObj('version1')).to.eql(expected);
  887. });
  888. });
  889. describe('#ajaxQueueFinished', function() {
  890. it('should call App.router.next', function() {
  891. sinon.stub(App.router, 'send', Em.K);
  892. installerStep8Controller.ajaxQueueFinished();
  893. expect(App.router.send.calledWith('next')).to.equal(true);
  894. App.router.send.restore();
  895. });
  896. });
  897. describe('#addRequestToAjaxQueue', function() {
  898. describe('testMode = true', function() {
  899. before(function() {
  900. App.set('testMode', true);
  901. });
  902. after(function() {
  903. App.set('testMode', false);
  904. });
  905. it('shouldn\'t do nothing', function() {
  906. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  907. installerStep8Controller.get('ajaxRequestsQueue').clear();
  908. installerStep8Controller.addRequestToAjaxQueue({});
  909. expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(0);
  910. });
  911. });
  912. describe('testMode = true', function() {
  913. before(function() {
  914. App.set('testMode', false);
  915. });
  916. it('should add request', function() {
  917. var clusterName = 'c1';
  918. installerStep8Controller.reopen({clusterName: clusterName});
  919. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  920. installerStep8Controller.get('ajaxRequestsQueue').clear();
  921. installerStep8Controller.addRequestToAjaxQueue({name:'name', data:{}});
  922. var request = installerStep8Controller.get('ajaxRequestsQueue.queue.firstObject');
  923. expect(request.error).to.equal('ajaxQueueRequestErrorCallback');
  924. expect(request.data.cluster).to.equal(clusterName);
  925. });
  926. });
  927. });
  928. describe('#ajaxQueueRequestErrorCallback', function() {
  929. var obj = Em.Object.create({
  930. registerErrPopup: Em.K,
  931. setStepsEnable: Em.K
  932. });
  933. beforeEach(function() {
  934. sinon.stub(App.router, 'get', function() {
  935. return obj;
  936. });
  937. sinon.spy(obj, 'registerErrPopup');
  938. sinon.spy(obj, 'setStepsEnable');
  939. });
  940. afterEach(function() {
  941. App.router.get.restore();
  942. obj.registerErrPopup.restore();
  943. obj.setStepsEnable.restore();
  944. });
  945. it('should set hasErrorOccurred true', function () {
  946. installerStep8Controller.set('hasErrorOccurred', false);
  947. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  948. expect(installerStep8Controller.get('hasErrorOccurred')).to.equal(true);
  949. });
  950. it('should set isSubmitDisabled false', function () {
  951. installerStep8Controller.set('isSubmitDisabled', true);
  952. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  953. expect(installerStep8Controller.get('isSubmitDisabled')).to.equal(false);
  954. });
  955. it('should set isBackBtnDisabled false', function () {
  956. installerStep8Controller.set('isBackBtnDisabled', true);
  957. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  958. expect(installerStep8Controller.get('isBackBtnDisabled')).to.equal(false);
  959. });
  960. it('should call setStepsEnable', function () {
  961. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  962. expect(obj.setStepsEnable.calledOnce).to.equal(true);
  963. });
  964. it('should call registerErrPopup', function () {
  965. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  966. expect(obj.registerErrPopup.calledOnce).to.equal(true);
  967. });
  968. });
  969. describe('#removeInstalledServicesConfigurationGroups', function() {
  970. beforeEach(function() {
  971. sinon.stub(App.config, 'deleteConfigGroup', Em.K);
  972. });
  973. afterEach(function() {
  974. App.config.deleteConfigGroup.restore();
  975. });
  976. it('should call App.config.deleteConfigGroup for each received group', function() {
  977. var groups = [{}, {}, {}];
  978. installerStep8Controller.removeInstalledServicesConfigurationGroups(groups);
  979. expect(App.config.deleteConfigGroup.callCount).to.equal(groups.length);
  980. });
  981. });
  982. describe('#addDynamicProperties', function() {
  983. it('shouldn\'t add property', function() {
  984. var serviceConfigProperties = [
  985. {name: 'templeton.hive.properties'}
  986. ],
  987. configs = [];
  988. installerStep8Controller.reopen({content: {serviceConfigProperties: serviceConfigProperties}});
  989. installerStep8Controller.addDynamicProperties(configs);
  990. expect(configs.length).to.equal(0);
  991. });
  992. it('should add property', function() {
  993. var serviceConfigProperties = [],
  994. configs = [];
  995. installerStep8Controller.reopen({content: {serviceConfigProperties: serviceConfigProperties}});
  996. installerStep8Controller.addDynamicProperties(configs);
  997. expect(configs.length).to.equal(1);
  998. });
  999. });
  1000. describe('#applyInstalledServicesConfigurationGroup', function() {
  1001. beforeEach(function() {
  1002. sinon.stub($, 'ajax', Em.K);
  1003. sinon.stub(App.router, 'get', function() {
  1004. return configurationController;
  1005. });
  1006. });
  1007. afterEach(function() {
  1008. $.ajax.restore();
  1009. App.router.get.restore();
  1010. });
  1011. it('should do ajax request for each config group', function() {
  1012. var configGroups = [{ConfigGroup: {id:''}}, {ConfigGroup: {id:''}}];
  1013. installerStep8Controller.applyInstalledServicesConfigurationGroup(configGroups);
  1014. expect($.ajax.callCount).to.equal(configGroups.length);
  1015. });
  1016. });
  1017. describe('#getExistingClusterNames', function() {
  1018. beforeEach(function() {
  1019. sinon.stub(App.ajax, 'send', Em.K);
  1020. });
  1021. afterEach(function() {
  1022. App.ajax.send.restore();
  1023. });
  1024. it('should do ajax request', function() {
  1025. installerStep8Controller.getExistingClusterNames();
  1026. expect(App.ajax.send.calledOnce).to.be.true;
  1027. });
  1028. });
  1029. describe('#loadUiSideConfigs', function() {
  1030. beforeEach(function() {
  1031. sinon.stub(installerStep8Controller, 'addDynamicProperties', Em.K);
  1032. sinon.stub(installerStep8Controller, 'getGlobConfigValueWithOverrides', function(t, v, n) {
  1033. return {
  1034. value: v,
  1035. overrides: []
  1036. }
  1037. });
  1038. sinon.stub(App.config, 'setConfigValue', Em.K);
  1039. });
  1040. afterEach(function() {
  1041. installerStep8Controller.addDynamicProperties.restore();
  1042. installerStep8Controller.getGlobConfigValueWithOverrides.restore();
  1043. App.config.setConfigValue.restore();
  1044. });
  1045. it('all configs witohut foreignKey', function() {
  1046. var configMapping = [
  1047. {foreignKey: null, templateName: 't1', value: 'v1', name: 'c1', filename: 'f1'},
  1048. {foreignKey: null, templateName: 't2', value: 'v2', name: 'c2', filename: 'f2'},
  1049. {foreignKey: null, templateName: 't3', value: 'v3', name: 'c3', filename: 'f2'},
  1050. {foreignKey: null, templateName: 't4', value: 'v4', name: 'c4', filename: 'f1'}
  1051. ];
  1052. var uiConfigs = installerStep8Controller.loadUiSideConfigs(configMapping);
  1053. expect(uiConfigs.length).to.equal(configMapping.length);
  1054. expect(uiConfigs.everyProperty('id', 'site property')).to.be.true;
  1055. uiConfigs.forEach(function(c, index) {
  1056. expect(c.overrides).to.be.an.array;
  1057. expect(c.value).to.equal(configMapping[index].value);
  1058. expect(c.name).to.equal(configMapping[index].name);
  1059. expect(c.filename).to.equal(configMapping[index].filename);
  1060. });
  1061. });
  1062. it('some configs witohut foreignKey', function() {
  1063. var configMapping = [
  1064. {foreignKey: null, templateName: 't1', value: 'v1', name: 'c1', filename: 'f1'},
  1065. {foreignKey: null, templateName: 't2', value: 'v2', name: 'c2', filename: 'f2'},
  1066. {foreignKey: null, templateName: 't3', value: 'v3', name: 'c3', filename: 'f2'},
  1067. {foreignKey: null, templateName: 't4', value: 'v4', name: 'c4', filename: 'f1'},
  1068. {foreignKey: 'fk1', templateName: 't5', value: 'v5', name: 'c5', filename: 'f1'},
  1069. {foreignKey: 'fk2', templateName: 't6', value: 'v6', name: 'c6', filename: 'f1'},
  1070. {foreignKey: 'fk3', templateName: 't7', value: 'v7', name: 'c7', filename: 'f2'},
  1071. {foreignKey: 'fk4', templateName: 't8', value: 'v8', name: 'c8', filename: 'f2'}
  1072. ];
  1073. var uiConfigs = installerStep8Controller.loadUiSideConfigs(configMapping);
  1074. expect(uiConfigs.length).to.equal(configMapping.length);
  1075. expect(uiConfigs.everyProperty('id', 'site property')).to.be.true;
  1076. uiConfigs.forEach(function(c, index) {
  1077. if (Em.isNone(configMapping[index].foreignKey))
  1078. expect(c.overrides).to.be.an.array;
  1079. expect(c.value).to.equal(configMapping[index].value);
  1080. expect(c.name).to.equal(configMapping[index].name);
  1081. expect(c.filename).to.equal(configMapping[index].filename);
  1082. });
  1083. });
  1084. });
  1085. describe('Queued requests', function() {
  1086. beforeEach(function() {
  1087. installerStep8Controller.clearStep();
  1088. sinon.spy(installerStep8Controller, 'addRequestToAjaxQueue');
  1089. });
  1090. afterEach(function() {
  1091. installerStep8Controller.addRequestToAjaxQueue.restore();
  1092. });
  1093. describe('#createCluster', function() {
  1094. it('shouldn\'t add request to queue if not installerController used', function() {
  1095. installerStep8Controller.reopen({content: {controllerName: 'addServiceController'}});
  1096. installerStep8Controller.createCluster();
  1097. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1098. });
  1099. it('App.currentStackVersion should be changed if localRepo selected', function() {
  1100. App.set('currentStackVersion', 'HDP-1.1.1');
  1101. installerStep8Controller.reopen({content: {controllerName: 'installerController', installOptions: {localRepo: true}}});
  1102. var data = {
  1103. data: JSON.stringify({ "Clusters": {"version": 'HDPLocal-1.1.1' }})
  1104. };
  1105. installerStep8Controller.createCluster();
  1106. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(data.data);
  1107. });
  1108. it('App.currentStackVersion shouldn\'t be changed if localRepo ins\'t selected', function() {
  1109. App.set('currentStackVersion', 'HDP-1.1.1');
  1110. installerStep8Controller.reopen({content: {controllerName: 'installerController', installOptions: {localRepo: false}}});
  1111. var data = {
  1112. data: JSON.stringify({ "Clusters": {"version": 'HDP-1.1.1' }})
  1113. };
  1114. installerStep8Controller.createCluster();
  1115. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.eql(data.data);
  1116. });
  1117. });
  1118. describe('#createSelectedServices', function() {
  1119. it('shouldn\'t do nothing if no data', function() {
  1120. sinon.stub(installerStep8Controller, 'createSelectedServicesData', function() {return [];});
  1121. installerStep8Controller.createSelectedServices();
  1122. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1123. installerStep8Controller.createSelectedServicesData.restore();
  1124. });
  1125. it('should call addRequestToAjaxQueue with computed data', function() {
  1126. var data = [
  1127. {"ServiceInfo": { "service_name": 's1' }},
  1128. {"ServiceInfo": { "service_name": 's2' }},
  1129. {"ServiceInfo": { "service_name": 's3' }}
  1130. ];
  1131. sinon.stub(installerStep8Controller, 'createSelectedServicesData', function() {return data;});
  1132. installerStep8Controller.createSelectedServices();
  1133. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(JSON.stringify(data));
  1134. installerStep8Controller.createSelectedServicesData.restore();
  1135. });
  1136. });
  1137. describe('#registerHostsToCluster', function() {
  1138. it('shouldn\'t do nothing if no data', function() {
  1139. sinon.stub(installerStep8Controller, 'createRegisterHostData', function() {return [];});
  1140. installerStep8Controller.registerHostsToCluster();
  1141. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1142. installerStep8Controller.createRegisterHostData.restore();
  1143. });
  1144. it('should call addRequestToAjaxQueue with computed data', function() {
  1145. var data = [
  1146. {"Hosts": { "host_name": 'h1'}},
  1147. {"Hosts": { "host_name": 'h3'}}
  1148. ];
  1149. sinon.stub(installerStep8Controller, 'createRegisterHostData', function() {return data;});
  1150. installerStep8Controller.registerHostsToCluster();
  1151. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(JSON.stringify(data));
  1152. installerStep8Controller.createRegisterHostData.restore();
  1153. });
  1154. });
  1155. describe('#registerHostsToComponent', function() {
  1156. it('shouldn\'t do request if no hosts provided', function() {
  1157. installerStep8Controller.registerHostsToComponent([]);
  1158. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1159. });
  1160. it('should do request if hostNames are provided', function() {
  1161. var hostNames = ['h1', 'h2'],
  1162. componentName = 'c1';
  1163. installerStep8Controller.registerHostsToComponent(hostNames, componentName);
  1164. var data = JSON.parse(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data);
  1165. expect(data.RequestInfo.query).to.equal('Hosts/host_name=h1|Hosts/host_name=h2');
  1166. expect(data.Body.host_components[0].HostRoles.component_name).to.equal('c1');
  1167. });
  1168. });
  1169. describe('#applyConfigurationsToCluster', function() {
  1170. it('should call addRequestToAjaxQueue', function() {
  1171. var serviceConfigTags = [
  1172. {
  1173. type: 'hdfs',
  1174. tag: 'tag1',
  1175. properties: [
  1176. {},
  1177. {}
  1178. ]
  1179. }
  1180. ],
  1181. data = '['+JSON.stringify({
  1182. Clusters: {
  1183. desired_config: [serviceConfigTags[0]]
  1184. }
  1185. })+']';
  1186. installerStep8Controller.reopen({
  1187. installedServices: [
  1188. Em.Object.create({
  1189. isSelected: true,
  1190. isInstalled: false,
  1191. configTypesRendered: {hdfs:'tag1'}
  1192. })
  1193. ], selectedServices: []
  1194. });
  1195. installerStep8Controller.applyConfigurationsToCluster(serviceConfigTags);
  1196. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(data);
  1197. });
  1198. });
  1199. describe('#applyConfigurationGroups', function() {
  1200. it('should call addRequestToAjaxQueue', function() {
  1201. var data = [{}, {}];
  1202. installerStep8Controller.applyConfigurationGroups(data);
  1203. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(JSON.stringify(data));
  1204. });
  1205. });
  1206. describe('#newServiceComponentErrorCallback', function() {
  1207. it('should add request for new component', function() {
  1208. var serviceName = 's1',
  1209. componentName = 'c1';
  1210. installerStep8Controller.newServiceComponentErrorCallback({}, {}, '', {}, {serviceName: serviceName, componentName: componentName});
  1211. var data = JSON.parse(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data);
  1212. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.serviceName).to.equal(serviceName);
  1213. expect(data.components[0].ServiceComponentInfo.component_name).to.equal(componentName);
  1214. });
  1215. });
  1216. describe('#createAdditionalHostComponents', function() {
  1217. beforeEach(function() {
  1218. sinon.stub(installerStep8Controller, 'registerHostsToComponent', Em.K);
  1219. });
  1220. afterEach(function() {
  1221. installerStep8Controller.registerHostsToComponent.restore();
  1222. });
  1223. it('should add components with isRequiredOnAllHosts == true (1)', function() {
  1224. installerStep8Controller.reopen({
  1225. getRegisteredHosts: function() {
  1226. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1227. },
  1228. content: {
  1229. services: [
  1230. Em.Object.create({
  1231. serviceName: 'GANGLIA', isSelected: true, isInstalled: false, serviceComponents: [
  1232. Em.Object.create({
  1233. componentName: 'GANGLIA_MONITOR',
  1234. isRequiredOnAllHosts: true
  1235. }),
  1236. Em.Object.create({
  1237. componentName: 'GANGLIA_SERVER',
  1238. isRequiredOnAllHosts: false
  1239. })
  1240. ]
  1241. })
  1242. ]
  1243. }
  1244. });
  1245. installerStep8Controller.createAdditionalHostComponents();
  1246. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1247. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1248. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('GANGLIA_MONITOR');
  1249. });
  1250. it('should add components with isRequiredOnAllHosts == true (2)', function() {
  1251. installerStep8Controller.reopen({
  1252. getRegisteredHosts: function() {
  1253. return [{hostName: 'h1', isInstalled: true}, {hostName: 'h2', isInstalled: false}];
  1254. },
  1255. content: {
  1256. services: [
  1257. Em.Object.create({
  1258. serviceName: 'GANGLIA', isSelected: true, isInstalled: true, serviceComponents: [
  1259. Em.Object.create({
  1260. componentName: 'GANGLIA_MONITOR',
  1261. isRequiredOnAllHosts: true
  1262. }),
  1263. Em.Object.create({
  1264. componentName: 'GANGLIA_SERVER',
  1265. isRequiredOnAllHosts: false
  1266. })
  1267. ]
  1268. })
  1269. ]
  1270. }
  1271. });
  1272. installerStep8Controller.createAdditionalHostComponents();
  1273. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1274. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h2']);
  1275. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('GANGLIA_MONITOR');
  1276. });
  1277. var newDatabases = [
  1278. {name: 'New MySQL Database',
  1279. component: 'MYSQL_SERVER'
  1280. },
  1281. {name: 'New PostgreSQL Database',
  1282. component: 'POSTGRESQL_SERVER'
  1283. }
  1284. ];
  1285. newDatabases.forEach(function (db) {
  1286. it('should add {0}'.format(db.component), function() {
  1287. installerStep8Controller.reopen({
  1288. getRegisteredHosts: function() {
  1289. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1290. },
  1291. content: {
  1292. masterComponentHosts: [
  1293. {component: 'HIVE_SERVER', hostName: 'h1'},
  1294. {component: 'HIVE_SERVER', hostName: 'h2'}
  1295. ],
  1296. services: [
  1297. Em.Object.create({serviceName: 'HIVE', isSelected: true, isInstalled: false, serviceComponents: []})
  1298. ],
  1299. serviceConfigProperties: [
  1300. {name: 'hive_database', value: db.name}
  1301. ]
  1302. }
  1303. });
  1304. installerStep8Controller.createAdditionalHostComponents();
  1305. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1306. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1307. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal(db.component);
  1308. });
  1309. });
  1310. });
  1311. describe('#createNotification', function () {
  1312. beforeEach(function () {
  1313. sinon.stub(App, 'get', function (k) {
  1314. if ('testMode' === k) return false;
  1315. return Em.get(App, k);
  1316. });
  1317. installerStep8Controller.clearStep();
  1318. installerStep8Controller.set('content', {controllerName: 'installerController'});
  1319. installerStep8Controller.set('configs', [
  1320. {name: 'create_notification', value: 'yes', serviceName: 'MISC', filename: 'alert_notification'},
  1321. {name: 'ambari.dispatch.recipients', value: 'to@f.c', serviceName: 'MISC', filename: 'alert_notification'},
  1322. {name: 'mail.smtp.host', value: 'h', serviceName: 'MISC', filename: 'alert_notification'},
  1323. {name: 'mail.smtp.port', value: '25', serviceName: 'MISC', filename: 'alert_notification'},
  1324. {name: 'mail.smtp.from', value: 'from@f.c', serviceName: 'MISC', filename: 'alert_notification'},
  1325. {name: 'mail.smtp.starttls.enable', value: true, serviceName: 'MISC', filename: 'alert_notification'},
  1326. {name: 'mail.smtp.startssl.enable', value: false, serviceName: 'MISC', filename: 'alert_notification'},
  1327. {name: 'smtp_use_auth', value: 'true', serviceName: 'MISC', filename: 'alert_notification'},
  1328. {name: 'ambari.dispatch.credential.username', value: 'usr', serviceName: 'MISC', filename: 'alert_notification'},
  1329. {name: 'ambari.dispatch.credential.password', value: 'pwd', serviceName: 'MISC', filename: 'alert_notification'},
  1330. {name: 'some_p', value: 'some_v', serviceName: 'MISC', filename: 'alert_notification'}
  1331. ]);
  1332. installerStep8Controller.get('ajaxRequestsQueue').clear();
  1333. });
  1334. afterEach(function () {
  1335. App.get.restore();
  1336. });
  1337. it('should add request to queue', function () {
  1338. installerStep8Controller.createNotification();
  1339. expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(1);
  1340. });
  1341. it('sent data should be valid', function () {
  1342. installerStep8Controller.createNotification();
  1343. var data = installerStep8Controller.get('ajaxRequestsQueue.queue')[0].data.data.AlertTarget;
  1344. expect(data.global).to.be.true;
  1345. expect(data.notification_type).to.equal('EMAIL');
  1346. expect(data.alert_states).to.eql(['OK', 'WARNING', 'CRITICAL', 'UNKNOWN']);
  1347. expect(data.properties['ambari.dispatch.recipients']).to.eql(['to@f.c']);
  1348. expect(data.properties['mail.smtp.host']).to.equal('h');
  1349. expect(data.properties['mail.smtp.port']).to.equal('25');
  1350. expect(data.properties['mail.smtp.from']).to.equal('from@f.c');
  1351. expect(data.properties['mail.smtp.starttls.enable']).to.equal(true);
  1352. expect(data.properties['mail.smtp.startssl.enable']).to.equal(false);
  1353. expect(data.properties['ambari.dispatch.credential.username']).to.equal('usr');
  1354. expect(data.properties['ambari.dispatch.credential.password']).to.equal('pwd');
  1355. expect(data.properties['some_p']).to.equal('some_v');
  1356. });
  1357. });
  1358. });
  1359. describe("#resolveProxyuserDependecies()", function() {
  1360. it("No core-site configs", function() {
  1361. expect(installerStep8Controller.resolveProxyuserDependecies([], [])).to.be.empty;
  1362. });
  1363. it("Only proxyuser group config", function() {
  1364. var configs = [{
  1365. name: 'proxyuser_group'
  1366. }];
  1367. installerStep8Controller.set('configs', [{
  1368. name: 'proxyuser_group',
  1369. value: 'val1'
  1370. }]);
  1371. expect(installerStep8Controller.resolveProxyuserDependecies(configs, [])).to.be.empty;
  1372. });
  1373. it("Property should be added", function() {
  1374. var configs = [
  1375. {
  1376. name: 'proxyuser_group'
  1377. },
  1378. {
  1379. name: 'hadoop.proxyuser.user.hosts',
  1380. value: 'val2'
  1381. }
  1382. ];
  1383. installerStep8Controller.set('configs', [{
  1384. name: 'proxyuser_group',
  1385. value: 'val1'
  1386. }]);
  1387. expect(installerStep8Controller.resolveProxyuserDependecies(configs, [])).to.be.eql({
  1388. 'hadoop.proxyuser.user.hosts': 'val2',
  1389. 'proxyuser_group': 'val1'
  1390. });
  1391. });
  1392. it("Property should be skipped", function() {
  1393. var configs = [
  1394. {
  1395. name: 'proxyuser_group'
  1396. },
  1397. {
  1398. name: 'hadoop.proxyuser.user.hosts',
  1399. value: 'val2'
  1400. }
  1401. ];
  1402. installerStep8Controller.set('configs', [
  1403. {
  1404. name: 'proxyuser_group',
  1405. value: 'val1'
  1406. },
  1407. {
  1408. name: 'user1',
  1409. value: 'user'
  1410. }
  1411. ]);
  1412. installerStep8Controller.set('optionalCoreSiteConfigs', [
  1413. {
  1414. serviceName: 'S1',
  1415. user: 'user1'
  1416. }
  1417. ]);
  1418. expect(installerStep8Controller.resolveProxyuserDependecies(configs, [])).to.be.empty;
  1419. });
  1420. });
  1421. describe("#addDynamicProperties", function() {
  1422. var tests = [
  1423. {
  1424. content: Em.Object.create({
  1425. serviceConfigProperties: [
  1426. Em.Object.create({
  1427. configs: []
  1428. })
  1429. ]
  1430. }),
  1431. m: 'add dynamic property',
  1432. addDynamic: true
  1433. },
  1434. {
  1435. content: Em.Object.create({
  1436. serviceConfigProperties: [
  1437. Em.Object.create({
  1438. name: 'templeton.hive.properties'
  1439. })
  1440. ]
  1441. }),
  1442. m: 'don\'t add dynamic property (already included)',
  1443. addDynamic: false
  1444. }
  1445. ],
  1446. dynamicProperty = {
  1447. name: 'templeton.hive.properties',
  1448. templateName: ['hive.metastore.uris'],
  1449. foreignKey: null,
  1450. value: 'hive.metastore.local=false,hive.metastore.uris=<templateName[0]>,hive.metastore.sasl.enabled=yes,hive.metastore.execute.setugi=true,hive.metastore.warehouse.dir=/apps/hive/warehouse',
  1451. filename: 'webhcat-site.xml'
  1452. };
  1453. tests.forEach(function(t) {
  1454. it(t.m, function() {
  1455. installerStep8Controller.set('content', t.content);
  1456. var configs = [];
  1457. installerStep8Controller.addDynamicProperties(configs);
  1458. if (t.addDynamic){
  1459. expect(configs.findProperty('name', 'templeton.hive.properties')).to.deep.eql(dynamicProperty);
  1460. }
  1461. });
  1462. });
  1463. });
  1464. describe('#isAllClusterDeleteRequestsCompleted', function () {
  1465. it('should depend on completed cluster delete requests number', function () {
  1466. installerStep8Controller.setProperties({
  1467. clusterDeleteRequestsCompleted: 0,
  1468. clusterNames: ['c0']
  1469. });
  1470. expect(installerStep8Controller.get('isAllClusterDeleteRequestsCompleted')).to.be.false;
  1471. installerStep8Controller.incrementProperty('clusterDeleteRequestsCompleted');
  1472. expect(installerStep8Controller.get('isAllClusterDeleteRequestsCompleted')).to.be.true;
  1473. });
  1474. });
  1475. describe('#deleteClusterSuccessCallback', function () {
  1476. beforeEach(function () {
  1477. sinon.stub(installerStep8Controller, 'showDeleteClustersErrorPopup', Em.K);
  1478. sinon.stub(installerStep8Controller, 'startDeploy', Em.K);
  1479. installerStep8Controller.setProperties({
  1480. clusterDeleteRequestsCompleted: 0,
  1481. clusterNames: ['c0', 'c1'],
  1482. clusterDeleteErrorViews: []
  1483. });
  1484. installerStep8Controller.deleteClusterSuccessCallback();
  1485. });
  1486. afterEach(function () {
  1487. installerStep8Controller.showDeleteClustersErrorPopup.restore();
  1488. installerStep8Controller.startDeploy.restore();
  1489. });
  1490. it('no failed requests', function () {
  1491. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(1);
  1492. expect(installerStep8Controller.showDeleteClustersErrorPopup.called).to.be.false;
  1493. expect(installerStep8Controller.startDeploy.called).to.be.false;
  1494. installerStep8Controller.deleteClusterSuccessCallback();
  1495. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(2);
  1496. expect(installerStep8Controller.showDeleteClustersErrorPopup.called).to.be.false;
  1497. expect(installerStep8Controller.startDeploy.calledOnce).to.be.true;
  1498. });
  1499. it('one request failed', function () {
  1500. installerStep8Controller.deleteClusterErrorCallback({}, null, null, {});
  1501. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(2);
  1502. expect(installerStep8Controller.showDeleteClustersErrorPopup.calledOnce).to.be.true;
  1503. expect(installerStep8Controller.startDeploy.called).to.be.false;
  1504. });
  1505. });
  1506. describe('#deleteClusterErrorCallback', function () {
  1507. var request = {
  1508. status: 500,
  1509. responseText: '{"message":"Internal Server Error"}'
  1510. },
  1511. ajaxOptions = 'error',
  1512. error = 'Internal Server Error',
  1513. opt = {
  1514. url: 'api/v1/clusters/c0',
  1515. type: 'DELETE'
  1516. };
  1517. beforeEach(function () {
  1518. installerStep8Controller.setProperties({
  1519. clusterDeleteRequestsCompleted: 0,
  1520. clusterNames: ['c0', 'c1'],
  1521. clusterDeleteErrorViews: []
  1522. });
  1523. sinon.stub(installerStep8Controller, 'showDeleteClustersErrorPopup', Em.K);
  1524. installerStep8Controller.deleteClusterErrorCallback(request, ajaxOptions, error, opt);
  1525. });
  1526. afterEach(function () {
  1527. installerStep8Controller.showDeleteClustersErrorPopup.restore();
  1528. });
  1529. it('should show error popup only if all requests are completed', function () {
  1530. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(1);
  1531. expect(installerStep8Controller.showDeleteClustersErrorPopup.called).to.be.false;
  1532. installerStep8Controller.deleteClusterErrorCallback(request, ajaxOptions, error, opt);
  1533. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(2);
  1534. expect(installerStep8Controller.showDeleteClustersErrorPopup.calledOnce).to.be.true;
  1535. });
  1536. it('should create error popup body view', function () {
  1537. expect(installerStep8Controller.get('clusterDeleteErrorViews')).to.have.length(1);
  1538. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.url')).to.equal('api/v1/clusters/c0');
  1539. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.type')).to.equal('DELETE');
  1540. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.status')).to.equal(500);
  1541. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.message')).to.equal('Internal Server Error');
  1542. });
  1543. });
  1544. describe('#showDeleteClustersErrorPopup', function () {
  1545. beforeEach(function () {
  1546. installerStep8Controller.setProperties({
  1547. isSubmitDisabled: true,
  1548. isBackBtnDisabled: true
  1549. });
  1550. sinon.stub(App.ModalPopup, 'show', Em.K);
  1551. installerStep8Controller.showDeleteClustersErrorPopup();
  1552. });
  1553. afterEach(function () {
  1554. App.ModalPopup.show.restore();
  1555. });
  1556. it('should show error popup and unlock navigation', function () {
  1557. expect(installerStep8Controller.get('isSubmitDisabled')).to.be.false;
  1558. expect(installerStep8Controller.get('isBackBtnDisabled')).to.be.false;
  1559. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1560. });
  1561. });
  1562. describe('#startDeploy', function () {
  1563. var stubbedNames = ['createCluster', 'createSelectedServices', 'updateConfigurations', 'createConfigurations',
  1564. 'applyConfigurationsToCluster', 'createComponents', 'registerHostsToCluster', 'createConfigurationGroups',
  1565. 'createMasterHostComponents', 'createSlaveAndClientsHostComponents', 'createAdditionalClientComponents',
  1566. 'createAdditionalHostComponents'],
  1567. cases = [
  1568. {
  1569. controllerName: 'installerController',
  1570. notExecuted: ['createAdditionalClientComponents', 'updateConfigurations'],
  1571. fileNamesToUpdate: [],
  1572. title: 'Installer, no configs to update'
  1573. },
  1574. {
  1575. controllerName: 'installerController',
  1576. notExecuted: ['createAdditionalClientComponents'],
  1577. fileNamesToUpdate: [''],
  1578. title: 'Installer, some configs to be updated'
  1579. },
  1580. {
  1581. controllerName: 'addHostController',
  1582. notExecuted: ['updateConfigurations', 'createConfigurations', 'applyConfigurationsToCluster', 'createAdditionalClientComponents'],
  1583. title: 'Add Host Wizard'
  1584. },
  1585. {
  1586. controllerName: 'addServiceController',
  1587. notExecuted: ['updateConfigurations'],
  1588. fileNamesToUpdate: [],
  1589. title: 'Add Service Wizard, no configs to update'
  1590. },
  1591. {
  1592. controllerName: 'addServiceController',
  1593. notExecuted: [],
  1594. fileNamesToUpdate: [''],
  1595. title: 'Add Service Wizard, some configs to be updated'
  1596. }
  1597. ];
  1598. beforeEach(function () {
  1599. stubbedNames.forEach(function (name) {
  1600. sinon.stub(installerStep8Controller, name, Em.K);
  1601. });
  1602. installerStep8Controller.setProperties({
  1603. serviceConfigTags: [],
  1604. content: {
  1605. controllerName: null
  1606. }
  1607. });
  1608. });
  1609. afterEach(function () {
  1610. stubbedNames.forEach(function (name) {
  1611. installerStep8Controller[name].restore();
  1612. });
  1613. installerStep8Controller.get.restore();
  1614. });
  1615. cases.forEach(function (item) {
  1616. it(item.title, function () {
  1617. sinon.stub(installerStep8Controller, 'get')
  1618. .withArgs('ajaxRequestsQueue').returns({
  1619. start: Em.K
  1620. })
  1621. .withArgs('ajaxRequestsQueue.queue.length').returns(1)
  1622. .withArgs('wizardController').returns({
  1623. getDBProperty: function () {
  1624. return item.fileNamesToUpdate;
  1625. }
  1626. })
  1627. .withArgs('content.controllerName').returns(item.controllerName);
  1628. installerStep8Controller.startDeploy();
  1629. stubbedNames.forEach(function (name) {
  1630. expect(installerStep8Controller[name].called).to.equal(!item.notExecuted.contains(name));
  1631. });
  1632. });
  1633. });
  1634. });
  1635. });