step8_test.js 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150
  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. require('utils/ajax/ajax_queue');
  20. require('controllers/main/service/info/configs');
  21. require('controllers/wizard/step8_controller');
  22. var installerStep8Controller, configurationController;
  23. var testHelpers = require('test/helpers');
  24. var configs = Em.A([
  25. Em.Object.create({filename: 'hdfs-site.xml', name: 'p1', value: 'v1'}),
  26. Em.Object.create({filename: 'hdfs-site.xml', name: 'p2', value: 'v2'}),
  27. Em.Object.create({filename: 'hue-site.xml', name: 'p1', value: 'v1'}),
  28. Em.Object.create({filename: 'hue-site.xml', name: 'p2', value: 'v2'}),
  29. Em.Object.create({filename: 'mapred-site.xml', name: 'p1', value: 'v1'}),
  30. Em.Object.create({filename: 'mapred-site.xml', name: 'p2', value: 'v2'}),
  31. Em.Object.create({filename: 'yarn-site.xml', name: 'p1', value: 'v1'}),
  32. Em.Object.create({filename: 'yarn-site.xml', name: 'p2', value: 'v2'}),
  33. Em.Object.create({filename: 'capacity-scheduler.xml', name: 'p1', value: 'v1'}),
  34. Em.Object.create({filename: 'capacity-scheduler.xml', name: 'p2', value: 'v2'}),
  35. Em.Object.create({filename: 'mapred-queue-acls.xml', name: 'p1', value: 'v1'}),
  36. Em.Object.create({filename: 'mapred-queue-acls.xml', name: 'p2', value: 'v2'}),
  37. Em.Object.create({filename: 'hbase-site.xml', name: 'p1', value: 'v1'}),
  38. Em.Object.create({filename: 'hbase-site.xml', name: 'p2', value: 'v2'}),
  39. Em.Object.create({filename: 'oozie-site.xml', name: 'p1', value: 'v1'}),
  40. Em.Object.create({filename: 'oozie-site.xml', name: 'p2', value: 'v2'}),
  41. Em.Object.create({filename: 'hive-site.xml', name: 'p1', value: 'v1'}),
  42. Em.Object.create({filename: 'hive-site.xml', name: 'p2', value: 'v2'}),
  43. Em.Object.create({filename: 'pig-properties.xml', name: 'p1', value: 'v1'}),
  44. Em.Object.create({filename: 'webhcat-site.xml', name: 'p1', value: 'v1'}),
  45. Em.Object.create({filename: 'webhcat-site.xml', name: 'p2', value: 'v2'}),
  46. Em.Object.create({filename: 'tez-site.xml', name: 'p1', value: 'v1'}),
  47. Em.Object.create({filename: 'tez-site.xml', name: 'p2', value: 'v2'}),
  48. Em.Object.create({filename: 'falcon-startup.properties.xml', name: 'p1', value: 'v1'}),
  49. Em.Object.create({filename: 'falcon-startup.properties.xml', name: 'p2', value: 'v2'}),
  50. Em.Object.create({filename: 'falcon-runtime.properties.xml', name: 'p1', value: 'v1'}),
  51. Em.Object.create({filename: 'falcon-runtime.properties.xml', name: 'p2', value: 'v2'})
  52. ]);
  53. function getController() {
  54. return App.WizardStep8Controller.create({
  55. configs: configs,
  56. content: {controllerName: ''}
  57. });
  58. }
  59. describe('App.WizardStep8Controller', function () {
  60. beforeEach(function () {
  61. installerStep8Controller = getController();
  62. configurationController = App.MainServiceInfoConfigsController.create({});
  63. });
  64. App.TestAliases.testAsComputedFilterBy(getController(), 'installedServices', 'content.services', 'isInstalled', true);
  65. App.TestAliases.testAsComputedEqual(getController(), 'isManualKerberos', 'App.router.mainAdminKerberosController.kdc_type', 'none');
  66. App.TestAliases.testAsComputedAlias(getController(), 'clusterName', 'content.cluster.name', 'string');
  67. describe('#createSelectedServicesData', function () {
  68. var tests = Em.A([
  69. {selectedServices: Em.A(['MAPREDUCE2']), e: 2},
  70. {selectedServices: Em.A(['MAPREDUCE2', 'YARN']), e: 5},
  71. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE']), e: 7},
  72. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE']), e: 9},
  73. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE']), e: 12},
  74. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE']), e: 13},
  75. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE']), e: 14},
  76. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG']), e: 15},
  77. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON']), e: 17},
  78. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON', 'STORM']), e: 18},
  79. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON', 'STORM', 'TEZ']), e: 19},
  80. {selectedServices: Em.A(['MAPREDUCE2', 'YARN', 'HBASE', 'OOZIE', 'HIVE', 'HUE', 'PIG', 'FALCON', 'STORM', 'TEZ', 'ZOOKEEPER']), e: 21}
  81. ]);
  82. tests.forEach(function (test) {
  83. it(test.selectedServices.join(','), function () {
  84. var services = test.selectedServices.map(function (serviceName) {
  85. return Em.Object.create({isSelected: true, isInstalled: false, serviceName: serviceName});
  86. });
  87. installerStep8Controller = App.WizardStep8Controller.create({
  88. content: {controllerName: 'addServiceController', services: services},
  89. configs: configs
  90. });
  91. var serviceData = installerStep8Controller.createSelectedServicesData();
  92. expect(serviceData.mapProperty('ServiceInfo.service_name')).to.eql(test.selectedServices.toArray());
  93. installerStep8Controller.clearStep();
  94. });
  95. });
  96. });
  97. describe('#getRegisteredHosts', function () {
  98. var tests = Em.A([
  99. {
  100. hosts: {
  101. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1'}),
  102. h2: Em.Object.create({bootStatus: 'OTHER', name: 'h2'})
  103. },
  104. e: ['h1'],
  105. m: 'Two hosts, one registered'
  106. },
  107. {
  108. hosts: {
  109. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1'}),
  110. h2: Em.Object.create({bootStatus: 'OTHER', name: 'h2'})
  111. },
  112. e: [],
  113. m: 'Two hosts, zero registered'
  114. },
  115. {
  116. hosts: {
  117. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1'}),
  118. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2'})
  119. },
  120. e: ['h1', 'h2'],
  121. m: 'Two hosts, two registered'
  122. }
  123. ]);
  124. tests.forEach(function (test) {
  125. it(test.m, function () {
  126. installerStep8Controller.set('content', Em.Object.create({hosts: test.hosts}));
  127. var registeredHosts = installerStep8Controller.getRegisteredHosts();
  128. expect(registeredHosts.mapProperty('hostName').toArray()).to.eql(test.e);
  129. });
  130. });
  131. });
  132. describe('#createRegisterHostData', function () {
  133. var tests = Em.A([
  134. {
  135. hosts: {
  136. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1', isInstalled: false}),
  137. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  138. },
  139. e: ['h1', 'h2'],
  140. m: 'two registered, two isInstalled false'
  141. },
  142. {
  143. hosts: {
  144. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1', isInstalled: false}),
  145. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  146. },
  147. e: ['h2'],
  148. m: 'one registered, two isInstalled false'
  149. },
  150. {
  151. hosts: {
  152. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1', isInstalled: true}),
  153. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  154. },
  155. e: ['h2'],
  156. m: 'one registered, one isInstalled false'
  157. },
  158. {
  159. hosts: {
  160. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1', isInstalled: true}),
  161. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: false})
  162. },
  163. e: ['h2'],
  164. m: 'two registered, one isInstalled false'
  165. },
  166. {
  167. hosts: {
  168. h1: Em.Object.create({bootStatus: 'OTHER', name: 'h1', isInstalled: false}),
  169. h2: Em.Object.create({bootStatus: 'OTHER', name: 'h2', isInstalled: false})
  170. },
  171. e: [],
  172. m: 'zero registered, two isInstalled false'
  173. },
  174. {
  175. hosts: {
  176. h1: Em.Object.create({bootStatus: 'REGISTERED', name: 'h1', isInstalled: true}),
  177. h2: Em.Object.create({bootStatus: 'REGISTERED', name: 'h2', isInstalled: true})
  178. },
  179. e: [],
  180. m: 'two registered, zeto insInstalled false'
  181. }
  182. ]);
  183. tests.forEach(function (test) {
  184. it(test.m, function () {
  185. installerStep8Controller.set('content', Em.Object.create({hosts: test.hosts}));
  186. var registeredHostData = installerStep8Controller.createRegisterHostData();
  187. expect(registeredHostData.mapProperty('Hosts.host_name').toArray()).to.eql(test.e);
  188. });
  189. });
  190. });
  191. describe('#loadServices', function () {
  192. beforeEach(function () {
  193. var services = Em.A([
  194. Em.Object.create({
  195. serviceName: 's1',
  196. isSelected: true,
  197. displayNameOnSelectServicePage: 's01',
  198. isClientOnlyService: false,
  199. serviceComponents: Em.A([
  200. Em.Object.create({
  201. isClient: true
  202. })
  203. ]),
  204. isHiddenOnSelectServicePage: false
  205. }),
  206. Em.Object.create({
  207. serviceName: 's2',
  208. isSelected: true,
  209. displayNameOnSelectServicePage: 's02',
  210. serviceComponents: Em.A([
  211. Em.Object.create({
  212. isMaster: true
  213. })
  214. ]),
  215. isHiddenOnSelectServicePage: false
  216. }),
  217. Em.Object.create({
  218. serviceName: 's3',
  219. isSelected: true,
  220. displayNameOnSelectServicePage: 's03',
  221. serviceComponents: Em.A([
  222. Em.Object.create({
  223. isHAComponentOnly: true
  224. })
  225. ]),
  226. isHiddenOnSelectServicePage: false
  227. }),
  228. Em.Object.create({
  229. serviceName: 's4',
  230. isSelected: true,
  231. displayNameOnSelectServicePage: 's03',
  232. isClientOnlyService: true,
  233. serviceComponents: Em.A([
  234. Em.Object.create({
  235. isClient: true
  236. })
  237. ]),
  238. isHiddenOnSelectServicePage: false
  239. })
  240. ]);
  241. var selectedServices = services.filterProperty('isSelected');
  242. var slaveComponentHosts = Em.A([
  243. Em.Object.create({
  244. componentName: 'CLIENT',
  245. hostName: 'h1',
  246. hosts: Em.A([
  247. Em.Object.create({hostName: 'h1', isInstalled: true}),
  248. Em.Object.create({hostName: 'h2', isInstalled: false})
  249. ])
  250. })
  251. ]);
  252. var content = Em.Object.create({
  253. services: services,
  254. selectedServices: selectedServices,
  255. slaveComponentHosts: slaveComponentHosts,
  256. hosts: Em.A([
  257. Em.Object.create({hostName: 'h1', isInstalled: true}),
  258. Em.Object.create({hostName: 'h2', isInstalled: false})
  259. ]),
  260. masterComponentHosts: []
  261. });
  262. installerStep8Controller.set('content', content);
  263. installerStep8Controller.set('services', Em.A([]));
  264. installerStep8Controller.reopen({selectedServices: selectedServices});
  265. installerStep8Controller.loadServices();
  266. });
  267. it('should load services', function () {
  268. var expected = [
  269. {
  270. "service_name": "s1",
  271. "display_name": "s01",
  272. "service_components": []
  273. },
  274. {
  275. "service_name": "s2",
  276. "display_name": "s02",
  277. "service_components": []
  278. },
  279. {
  280. "service_name": "s3",
  281. "display_name": "s03",
  282. "service_components": []
  283. },
  284. {
  285. "service_name": "s4",
  286. "display_name": "s03",
  287. "service_components": [
  288. {
  289. "component_name": "CLIENT",
  290. "display_name": "Clients",
  291. "component_value": "2 hosts"
  292. }
  293. ]
  294. }
  295. ];
  296. var result = JSON.parse(JSON.stringify(installerStep8Controller.get('services')));
  297. expect(result).to.be.eql(expected);
  298. });
  299. });
  300. describe('#removeClientsFromList', function () {
  301. beforeEach(function () {
  302. installerStep8Controller.set('content', Em.Object.create({
  303. hosts: Em.Object.create({
  304. h1: Em.Object.create({
  305. hostName: 'h1',
  306. isInstalled: true,
  307. hostComponents: Em.A([Em.Object.create({HostRoles: Em.Object.create({component_name: "h1"})})])
  308. }),
  309. h2: Em.Object.create({
  310. hostName: 'h2',
  311. isInstalled: true,
  312. hostComponents: Em.A([Em.Object.create({HostRoles: Em.Object.create({component_name: "h2"})})])
  313. })
  314. })
  315. }));
  316. });
  317. it('should remove h1', function () {
  318. var hostList = Em.A(['h1','h2']);
  319. installerStep8Controller.removeClientsFromList('h1', hostList);
  320. expect(JSON.parse(JSON.stringify(hostList))).to.eql(["h2"]);
  321. });
  322. });
  323. describe('#createSlaveAndClientsHostComponents', function () {
  324. beforeEach(function () {
  325. installerStep8Controller.set('content', Em.Object.create({
  326. masterComponentHosts: Em.A([
  327. Em.Object.create({
  328. componentName: 'CLIENT',
  329. component: 'HBASE_MASTER',
  330. hostName: 'h1'
  331. })
  332. ]),
  333. slaveComponentHosts: Em.A([
  334. Em.Object.create({
  335. componentName: 'CLIENT',
  336. hostName: 'h1',
  337. hosts: Em.A([
  338. Em.Object.create({hostName: 'h1', isInstalled: true}),
  339. Em.Object.create({hostName: 'h2', isInstalled: false})
  340. ])
  341. }),
  342. Em.Object.create({
  343. componentName: 'CLIENT1',
  344. hostName: 'h1',
  345. hosts: Em.A([
  346. Em.Object.create({hostName: 'h1', isInstalled: true}),
  347. Em.Object.create({hostName: 'h2', isInstalled: false})
  348. ])
  349. })
  350. ]),
  351. clients: Em.A([
  352. Em.Object.create({
  353. isInstalled: false
  354. })
  355. ]),
  356. services: Em.A([
  357. Em.Object.create({
  358. isInstalled: true,
  359. serviceName: "name",
  360. isClient: true
  361. })
  362. ]),
  363. hosts: Em.Object.create({
  364. h1: Em.Object.create({
  365. hostName: 'h1',
  366. isInstalled: true,
  367. hostComponents: Em.A([Em.Object.create({})])
  368. }),
  369. h2: Em.Object.create({
  370. hostName: 'h2',
  371. isInstalled: false,
  372. hostComponents: Em.A([Em.Object.create({})])
  373. })
  374. }),
  375. additionalClients: Em.A([{hostNames: "name", componentName: "client"}])
  376. }));
  377. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  378. installerStep8Controller.get('ajaxRequestsQueue').clear();
  379. });
  380. it('should return non install object', function () {
  381. installerStep8Controller.createSlaveAndClientsHostComponents();
  382. expect(installerStep8Controller.get('content.clients')[0].isInstalled).to.be.false;
  383. });
  384. });
  385. describe('#createAdditionalClientComponents', function () {
  386. beforeEach(function () {
  387. installerStep8Controller.set('content', Em.Object.create({
  388. masterComponentHosts: Em.A([
  389. Em.Object.create({
  390. componentName: 'CLIENT',
  391. component: 'HBASE_MASTER',
  392. hostName: 'h1'
  393. })
  394. ]),
  395. slaveComponentHosts: Em.A([
  396. Em.Object.create({
  397. componentName: 'CLIENT',
  398. hostName: 'h1',
  399. hosts: Em.A([
  400. Em.Object.create({hostName: 'h1', isInstalled: true}),
  401. Em.Object.create({hostName: 'h2', isInstalled: false})
  402. ])
  403. })
  404. ]),
  405. clients: Em.A([
  406. Em.Object.create({
  407. isInstalled: false
  408. })
  409. ]),
  410. services: Em.A([
  411. Em.Object.create({
  412. isInstalled: true,
  413. serviceName: "name",
  414. isClient: true
  415. })
  416. ]),
  417. hosts: Em.Object.create({
  418. h1: Em.Object.create({
  419. hostName: 'h1',
  420. isInstalled: true,
  421. hostComponents: Em.A([Em.Object.create({})])
  422. }),
  423. h2: Em.Object.create({
  424. hostName: 'h2',
  425. isInstalled: false,
  426. hostComponents: Em.A([Em.Object.create({})])
  427. })
  428. }),
  429. additionalClients: Em.A([{hostNames: "name", componentName: "client"}])
  430. }));
  431. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  432. installerStep8Controller.get('ajaxRequestsQueue').clear();
  433. installerStep8Controller.createAdditionalClientComponents();
  434. });
  435. it('should bes equal to content.cluster.name', function () {
  436. var result = [
  437. {
  438. "hostNames": "name",
  439. "componentName": "client"
  440. }
  441. ];
  442. var expected = installerStep8Controller.get('content.additionalClients');
  443. expect(JSON.parse(JSON.stringify(expected))).to.eql(result);
  444. });
  445. });
  446. describe('#assignComponentHosts', function () {
  447. it('should return host name', function () {
  448. var component = Em.Object.create({
  449. isMaster: true,
  450. componentName: 'HBASE_MASTER',
  451. hostName: 'h1'
  452. });
  453. installerStep8Controller.set('content', Em.Object.create({
  454. masterComponentHosts:Em.A([
  455. Em.Object.create({component: 'HBASE_MASTER', hostName: 'h1'})
  456. ])}));
  457. var res = installerStep8Controller.assignComponentHosts(component);
  458. expect(res).to.equal("h1");
  459. });
  460. it('should return number of hosts', function () {
  461. var component = Em.Object.create({
  462. componentName: 'HBASE_MASTER',
  463. isClient: false,
  464. hostName: 'h1'
  465. });
  466. installerStep8Controller.set('content', Em.Object.create({
  467. slaveComponentHosts:Em.A([
  468. Em.Object.create({
  469. componentName: 'HBASE_MASTER',
  470. hostName: 'h1',
  471. hosts: [
  472. {hostName: 'h1'},
  473. {hostName: 'h2'}
  474. ]
  475. })
  476. ])}));
  477. var res = installerStep8Controller.assignComponentHosts(component);
  478. expect(res).to.equal("2 hosts");
  479. });
  480. });
  481. describe('#loadClusterInfo', function () {
  482. beforeEach(function () {
  483. sinon.stub(App.Stack, 'find', function(){
  484. return Em.A([
  485. Em.Object.create({isSelected: false, hostName: 'h1'}),
  486. Em.Object.create({
  487. isSelected: true,
  488. hostName: 'h2',
  489. operatingSystems: Em.A([Em.Object.create({
  490. name:'windows',
  491. isSelected: true,
  492. repositories: Em.A([Em.Object.create({
  493. baseUrl: "url",
  494. osType: "2",
  495. repoId: "3"
  496. })])
  497. })])
  498. }),
  499. Em.Object.create({isSelected: false, hostName: 'h3'})
  500. ]);
  501. });
  502. });
  503. afterEach(function () {
  504. App.Stack.find.restore();
  505. });
  506. it('should return config with display_name', function () {
  507. installerStep8Controller.set('clusterInfo', Em.A([]));
  508. installerStep8Controller.loadClusterInfo();
  509. var res = [{
  510. "config_name":"cluster",
  511. "display_name":"Cluster Name"
  512. },{
  513. "config_name":"hosts",
  514. "display_name":"Total Hosts",
  515. "config_value":"0 (0 new)"
  516. }];
  517. var calcRes = JSON.parse(JSON.stringify(installerStep8Controller.get('clusterInfo')));
  518. expect(calcRes).to.eql(res);
  519. });
  520. });
  521. describe('#loadStep', function () {
  522. beforeEach(function () {
  523. sinon.stub(installerStep8Controller, 'clearStep', Em.K);
  524. sinon.stub(installerStep8Controller, 'formatProperties', Em.K);
  525. sinon.stub(installerStep8Controller, 'loadConfigs', Em.K);
  526. sinon.stub(installerStep8Controller, 'loadClusterInfo', Em.K);
  527. sinon.stub(installerStep8Controller, 'loadServices', Em.K);
  528. installerStep8Controller.set('content', {controllerName: 'installerController'});
  529. });
  530. afterEach(function () {
  531. installerStep8Controller.clearStep.restore();
  532. installerStep8Controller.formatProperties.restore();
  533. installerStep8Controller.loadConfigs.restore();
  534. installerStep8Controller.loadClusterInfo.restore();
  535. installerStep8Controller.loadServices.restore();
  536. });
  537. it('should call clearStep', function () {
  538. installerStep8Controller.loadStep();
  539. expect(installerStep8Controller.clearStep.calledOnce).to.equal(true);
  540. });
  541. it('should call loadClusterInfo', function () {
  542. installerStep8Controller.loadStep();
  543. expect(installerStep8Controller.loadClusterInfo.calledOnce).to.equal(true);
  544. });
  545. it('should call loadServices', function () {
  546. installerStep8Controller.loadStep();
  547. expect(installerStep8Controller.loadServices.calledOnce).to.equal(true);
  548. });
  549. it('should call formatProperties if content.serviceConfigProperties is true', function () {
  550. installerStep8Controller.set('content.serviceConfigProperties', true);
  551. installerStep8Controller.loadStep();
  552. expect(installerStep8Controller.loadServices.calledOnce).to.equal(true);
  553. });
  554. it('should call loadConfigs if content.serviceConfigProperties is true', function () {
  555. installerStep8Controller.set('content.serviceConfigProperties', true);
  556. installerStep8Controller.loadStep();
  557. expect(installerStep8Controller.loadConfigs.calledOnce).to.equal(true);
  558. });
  559. it('should set isSubmitDisabled to false', function () {
  560. installerStep8Controller.loadStep();
  561. expect(installerStep8Controller.get('isSubmitDisabled')).to.equal(false);
  562. });
  563. it('should set isBackBtnDisabled to false', function () {
  564. installerStep8Controller.loadStep();
  565. expect(installerStep8Controller.get('isBackBtnDisabled')).to.equal(false);
  566. });
  567. });
  568. describe('#getRegisteredHosts', function() {
  569. Em.A([
  570. {
  571. hosts: {},
  572. m: 'no content.hosts',
  573. e: []
  574. },
  575. {
  576. hosts: {
  577. h1:{bootStatus: ''},
  578. h2:{bootStatus: ''}
  579. },
  580. m: 'no registered hosts',
  581. e: []
  582. },
  583. {
  584. hosts: {
  585. h1:{bootStatus: 'REGISTERED', hostName: '', name: 'n1'},
  586. h2:{bootStatus: 'REGISTERED', hostName: '', name: 'n2'}
  587. },
  588. m: 'registered hosts available',
  589. e: ['n1', 'n2']
  590. }
  591. ]).forEach(function(test) {
  592. it(test.m, function() {
  593. installerStep8Controller.set('content', {hosts: test.hosts});
  594. var hosts = installerStep8Controller.getRegisteredHosts();
  595. expect(hosts.mapProperty('hostName')).to.eql(test.e);
  596. });
  597. });
  598. });
  599. describe('#loadRepoInfo', function() {
  600. beforeEach(function () {
  601. sinon.stub(App, 'get').withArgs('currentStackName').returns('HDP');
  602. sinon.stub(App.StackVersion, 'find', function() {
  603. return [
  604. Em.Object.create({state: 'CURRENT', repositoryVersion: {repositoryVersion: '2.3.0.0-2208'}})
  605. ];
  606. });
  607. });
  608. afterEach(function () {
  609. App.get.restore();
  610. App.StackVersion.find.restore();
  611. });
  612. it('should use current StackVersion', function() {
  613. installerStep8Controller.loadRepoInfo();
  614. var args = testHelpers.findAjaxRequest('name', 'cluster.load_repo_version');
  615. expect(args[0].data).to.eql({stackName: 'HDP', repositoryVersion: '2.3.0.0-2208'});
  616. });
  617. });
  618. describe('#loadRepoInfoSuccessCallback', function () {
  619. beforeEach(function () {
  620. installerStep8Controller.set('clusterInfo', Em.Object.create({}));
  621. });
  622. it('should assert error if no data returned from server', function () {
  623. expect(function () {
  624. installerStep8Controller.loadRepoInfoSuccessCallback({items: []});
  625. }).to.throw(Error);
  626. });
  627. Em.A([
  628. {
  629. m: 'Normal JSON',
  630. e: {
  631. base_url: ['baseurl1', 'baseurl2'],
  632. os_type: ['redhat6', 'suse11'],
  633. repo_id: ['HDP-2.3', 'HDP-UTILS-1.1.0.20']
  634. },
  635. items: [
  636. {
  637. repository_versions: [
  638. {
  639. operating_systems: [
  640. {
  641. repositories: [
  642. {
  643. Repositories: {
  644. base_url: 'baseurl1',
  645. os_type: 'redhat6',
  646. repo_id: 'HDP-2.3'
  647. }
  648. }
  649. ]
  650. },
  651. {
  652. repositories: [
  653. {
  654. Repositories: {
  655. base_url: 'baseurl2',
  656. os_type: 'suse11',
  657. repo_id: 'HDP-UTILS-1.1.0.20'
  658. }
  659. }
  660. ]
  661. }
  662. ]
  663. }
  664. ]
  665. }
  666. ]
  667. }
  668. ]).forEach(function (test) {
  669. it(test.m, function () {
  670. installerStep8Controller.loadRepoInfoSuccessCallback({items: test.items});
  671. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('base_url')).to.eql(test.e.base_url);
  672. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('os_type')).to.eql(test.e.os_type);
  673. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('repo_id')).to.eql(test.e.repo_id);
  674. });
  675. });
  676. /*Em.A([
  677. {
  678. items: [
  679. {
  680. repositories: [
  681. {
  682. Repositories: {
  683. os_type: 'redhat5',
  684. base_url: 'url1'
  685. }
  686. }
  687. ],
  688. OperatingSystems: {
  689. is_type: ''
  690. }
  691. }
  692. ],
  693. m: 'only redhat5',
  694. e: {
  695. base_url: ['url1'],
  696. os_type: ['redhat5']
  697. }
  698. },
  699. {
  700. items: [
  701. {
  702. repositories: [
  703. {
  704. Repositories: {
  705. os_type: 'redhat5',
  706. base_url: 'url1'
  707. }
  708. }
  709. ],
  710. OperatingSystems: {
  711. is_type: ''
  712. }
  713. },
  714. {
  715. repositories: [
  716. {
  717. Repositories: {
  718. os_type: 'redhat6',
  719. base_url: 'url2'
  720. }
  721. }
  722. ],
  723. OperatingSystems: {
  724. is_type: ''
  725. }
  726. }
  727. ],
  728. m: 'redhat5, redhat6',
  729. e: {
  730. base_url: ['url1', 'url2'],
  731. os_type: ['redhat5', 'redhat6']
  732. }
  733. },
  734. {
  735. items: [
  736. {
  737. repositories: [
  738. {
  739. Repositories: {
  740. os_type: 'redhat5',
  741. base_url: 'url1'
  742. }
  743. }
  744. ],
  745. OperatingSystems: {
  746. is_type: ''
  747. }
  748. },
  749. {
  750. repositories: [
  751. {
  752. Repositories: {
  753. os_type: 'redhat6',
  754. base_url: 'url2'
  755. }
  756. }
  757. ],
  758. OperatingSystems: {
  759. is_type: ''
  760. }
  761. },
  762. {
  763. repositories: [
  764. {
  765. Repositories: {
  766. os_type: 'sles11',
  767. base_url: 'url3'
  768. }
  769. }
  770. ],
  771. OperatingSystems: {
  772. is_type: ''
  773. }
  774. }
  775. ],
  776. m: 'redhat5, redhat6, sles11',
  777. e: {
  778. base_url: ['url1', 'url2', 'url3'],
  779. os_type: ['redhat5', 'redhat6', 'sles11']
  780. }
  781. }
  782. ]).forEach(function (test) {
  783. it(test.m, function () {
  784. installerStep8Controller.loadRepoInfoSuccessCallback({items: test.items});
  785. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('base_url')).to.eql(test.e.base_url);
  786. expect(installerStep8Controller.get('clusterInfo.repoInfo').mapProperty('os_type')).to.eql(test.e.os_type);
  787. });
  788. });*/
  789. });
  790. describe('#loadRepoInfoErrorCallback', function() {
  791. it('should set [] to repoInfo', function() {
  792. installerStep8Controller.set('clusterInfo', Em.Object.create({repoInfo: [{}, {}]}));
  793. installerStep8Controller.loadRepoInfoErrorCallback({});
  794. expect(installerStep8Controller.get('clusterInfo.repoInfo.length')).to.be.equal(0);
  795. });
  796. });
  797. describe('#loadHbaseMasterValue', function () {
  798. Em.A([
  799. {
  800. masterComponentHosts: [{component: 'HBASE_MASTER', hostName: 'h1'}],
  801. component: Em.Object.create({component_name: 'HBASE_MASTER'}),
  802. m: 'one host',
  803. e: 'h1'
  804. },
  805. {
  806. masterComponentHosts: [{component: 'HBASE_MASTER', hostName: 'h1'}, {component: 'HBASE_MASTER', hostName: 'h2'}, {component: 'HBASE_MASTER', hostName: 'h3'}],
  807. component: Em.Object.create({component_name: 'HBASE_MASTER'}),
  808. m: 'many hosts',
  809. e: 'h1 ' + Em.I18n.t('installer.step8.other').format(2)
  810. }
  811. ]).forEach(function (test) {
  812. it(test.m, function() {
  813. installerStep8Controller.set('content', {masterComponentHosts: test.masterComponentHosts});
  814. installerStep8Controller.loadHbaseMasterValue(test.component);
  815. expect(test.component.component_value).to.equal(test.e);
  816. });
  817. });
  818. });
  819. describe('#loadZkServerValue', function() {
  820. Em.A([
  821. {
  822. masterComponentHosts: [{component: 'ZOOKEEPER_SERVER'}],
  823. component: Em.Object.create({component_name: 'ZOOKEEPER_SERVER'}),
  824. m: '1 host',
  825. e: '1 host'
  826. },
  827. {
  828. masterComponentHosts: [{component: 'ZOOKEEPER_SERVER'},{component: 'ZOOKEEPER_SERVER'},{component: 'ZOOKEEPER_SERVER'}],
  829. component: Em.Object.create({component_name: 'ZOOKEEPER_SERVER'}),
  830. m: 'many hosts',
  831. e: '3 hosts'
  832. }
  833. ]).forEach(function (test) {
  834. it(test.m, function () {
  835. installerStep8Controller.set('content', {masterComponentHosts: test.masterComponentHosts});
  836. installerStep8Controller.loadZkServerValue(test.component);
  837. expect(test.component.component_value).to.equal(test.e);
  838. });
  839. });
  840. });
  841. describe('#submit', function() {
  842. beforeEach(function() {
  843. sinon.stub(installerStep8Controller, 'submitProceed', Em.K);
  844. sinon.stub(installerStep8Controller, 'showRestartWarnings').returns($.Deferred().resolve().promise());
  845. sinon.stub(App.get('router.mainAdminKerberosController'), 'getKDCSessionState', Em.K);
  846. });
  847. afterEach(function() {
  848. installerStep8Controller.submitProceed.restore();
  849. installerStep8Controller.showRestartWarnings.restore();
  850. App.set('isKerberosEnabled', false);
  851. App.get('router.mainAdminKerberosController').getKDCSessionState.restore();
  852. });
  853. it('AddServiceController Kerberos enabled', function () {
  854. installerStep8Controller.reopen({
  855. isSubmitDisabled: false,
  856. content: {controllerName: 'addServiceController'}
  857. });
  858. installerStep8Controller.submit();
  859. expect(App.get('router.mainAdminKerberosController').getKDCSessionState.called).to.equal(true);
  860. });
  861. it('shouldn\'t do nothing if isSubmitDisabled is true', function() {
  862. installerStep8Controller.reopen({isSubmitDisabled: true});
  863. installerStep8Controller.submit();
  864. expect(App.get('router.mainAdminKerberosController').getKDCSessionState.called).to.equal(false);
  865. expect(installerStep8Controller.submitProceed.called).to.equal(false);
  866. });
  867. });
  868. describe('#getExistingClusterNamesSuccessCallBack', function() {
  869. it('should set clusterNames received from server', function() {
  870. var data = {
  871. items:[
  872. {Clusters: {cluster_name: 'c1'}},
  873. {Clusters: {cluster_name: 'c2'}},
  874. {Clusters: {cluster_name: 'c3'}}
  875. ]
  876. },
  877. clasterNames = ['c1','c2','c3'];
  878. installerStep8Controller.getExistingClusterNamesSuccessCallBack(data);
  879. expect(installerStep8Controller.get('clusterNames')).to.eql(clasterNames);
  880. });
  881. });
  882. describe('#getExistingClusterNamesErrorCallback', function() {
  883. it('should set [] to clusterNames', function() {
  884. installerStep8Controller.set('clusterNames', ['c1', 'c2']);
  885. installerStep8Controller.getExistingClusterNamesErrorCallback();
  886. expect(installerStep8Controller.get('clusterNames')).to.eql([]);
  887. });
  888. });
  889. describe('#deleteClusters', function() {
  890. describe('should call App.ajax.send for each provided clusterName', function() {
  891. var clusterNames = ['h1', 'h2', 'h3'];
  892. var args;
  893. beforeEach(function () {
  894. installerStep8Controller.deleteClusters(clusterNames);
  895. args = testHelpers.filterAjaxRequests('name', 'common.delete.cluster');
  896. });
  897. it('args', function () {
  898. expect(args).to.have.property('length').equal(clusterNames.length);
  899. });
  900. clusterNames.forEach(function(n, i) {
  901. it(n, function () {
  902. expect(args[i][0].data).to.eql({name: n, isLast: i === clusterNames.length - 1});
  903. });
  904. });
  905. });
  906. it('should clear cluster delete error popup body views', function () {
  907. installerStep8Controller.deleteClusters([]);
  908. expect(installerStep8Controller.get('clusterDeleteErrorViews')).to.eql([]);
  909. });
  910. });
  911. describe('#ajaxQueueFinished', function() {
  912. beforeEach(function () {
  913. sinon.stub(App.router, 'send', Em.K);
  914. });
  915. afterEach(function () {
  916. App.router.send.restore();
  917. });
  918. it('should call App.router.next', function() {
  919. installerStep8Controller.ajaxQueueFinished();
  920. expect(App.router.send.calledWith('next')).to.equal(true);
  921. });
  922. });
  923. describe('#addRequestToAjaxQueue', function() {
  924. describe('testMode = false', function() {
  925. it('should add request', function() {
  926. var clusterName = 'c1';
  927. installerStep8Controller.reopen({clusterName: clusterName});
  928. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  929. installerStep8Controller.get('ajaxRequestsQueue').clear();
  930. installerStep8Controller.addRequestToAjaxQueue({name:'name', data:{}});
  931. var request = installerStep8Controller.get('ajaxRequestsQueue.queue.firstObject');
  932. expect(request.error).to.equal('ajaxQueueRequestErrorCallback');
  933. expect(request.data.cluster).to.equal(clusterName);
  934. });
  935. });
  936. });
  937. describe('#ajaxQueueRequestErrorCallback', function() {
  938. var obj = Em.Object.create({
  939. registerErrPopup: Em.K,
  940. setStepsEnable: Em.K
  941. });
  942. beforeEach(function() {
  943. sinon.stub(App.router, 'get', function() {
  944. return obj;
  945. });
  946. sinon.spy(obj, 'registerErrPopup');
  947. sinon.spy(obj, 'setStepsEnable');
  948. });
  949. afterEach(function() {
  950. App.router.get.restore();
  951. obj.registerErrPopup.restore();
  952. obj.setStepsEnable.restore();
  953. });
  954. it('should set hasErrorOccurred true', function () {
  955. installerStep8Controller.set('hasErrorOccurred', false);
  956. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  957. expect(installerStep8Controller.get('hasErrorOccurred')).to.equal(true);
  958. });
  959. it('should set isSubmitDisabled false', function () {
  960. installerStep8Controller.set('isSubmitDisabled', true);
  961. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  962. expect(installerStep8Controller.get('isSubmitDisabled')).to.equal(false);
  963. });
  964. it('should set isBackBtnDisabled false', function () {
  965. installerStep8Controller.set('isBackBtnDisabled', true);
  966. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  967. expect(installerStep8Controller.get('isBackBtnDisabled')).to.equal(false);
  968. });
  969. it('should call setStepsEnable', function () {
  970. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  971. expect(obj.setStepsEnable.calledOnce).to.equal(true);
  972. });
  973. it('should call registerErrPopup', function () {
  974. installerStep8Controller.ajaxQueueRequestErrorCallback({responseText: '{"message": ""}'});
  975. expect(obj.registerErrPopup.calledOnce).to.equal(true);
  976. });
  977. });
  978. describe('#removeInstalledServicesConfigurationGroups', function() {
  979. beforeEach(function() {
  980. sinon.stub(installerStep8Controller, 'deleteConfigurationGroup', Em.K);
  981. });
  982. afterEach(function() {
  983. installerStep8Controller.deleteConfigurationGroup.restore();
  984. });
  985. it('should call App.config.deleteConfigGroup for each received group', function() {
  986. var groups = [{}, {}, {}];
  987. installerStep8Controller.removeInstalledServicesConfigurationGroups(groups);
  988. expect(installerStep8Controller.deleteConfigurationGroup.callCount).to.equal(groups.length);
  989. });
  990. });
  991. describe('#getExistingClusterNames', function() {
  992. it('should do ajax request', function() {
  993. installerStep8Controller.getExistingClusterNames();
  994. var args = testHelpers.findAjaxRequest('name', 'wizard.step8.existing_cluster_names');
  995. expect(args).exists;
  996. });
  997. });
  998. describe('Queued requests', function() {
  999. beforeEach(function() {
  1000. installerStep8Controller.clearStep();
  1001. sinon.spy(installerStep8Controller, 'addRequestToAjaxQueue');
  1002. });
  1003. afterEach(function() {
  1004. installerStep8Controller.addRequestToAjaxQueue.restore();
  1005. });
  1006. describe('#createCluster', function() {
  1007. it('shouldn\'t add request to queue if not installerController used', function() {
  1008. installerStep8Controller.reopen({content: {controllerName: 'addServiceController'}});
  1009. installerStep8Controller.createCluster();
  1010. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1011. });
  1012. it('App.currentStackVersion should be changed if localRepo selected', function() {
  1013. App.set('currentStackVersion', 'HDP-1.1.1');
  1014. installerStep8Controller.reopen({content: {controllerName: 'installerController', installOptions: {localRepo: true}}});
  1015. var data = {
  1016. data: JSON.stringify({ "Clusters": {"version": 'HDPLocal-1.1.1' }})
  1017. };
  1018. installerStep8Controller.createCluster();
  1019. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(data.data);
  1020. });
  1021. it('App.currentStackVersion shouldn\'t be changed if localRepo ins\'t selected', function() {
  1022. App.set('currentStackVersion', 'HDP-1.1.1');
  1023. installerStep8Controller.reopen({content: {controllerName: 'installerController', installOptions: {localRepo: false}}});
  1024. var data = {
  1025. data: JSON.stringify({ "Clusters": {"version": 'HDP-1.1.1' }})
  1026. };
  1027. installerStep8Controller.createCluster();
  1028. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.eql(data.data);
  1029. });
  1030. });
  1031. describe('#createSelectedServices', function() {
  1032. var data;
  1033. beforeEach(function () {
  1034. sinon.stub(installerStep8Controller, 'createSelectedServicesData', function () {
  1035. return data;
  1036. });
  1037. });
  1038. afterEach(function () {
  1039. installerStep8Controller.createSelectedServicesData.restore();
  1040. });
  1041. it('shouldn\'t do nothing if no data', function() {
  1042. data = [];
  1043. installerStep8Controller.createSelectedServices();
  1044. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1045. });
  1046. it('should call addRequestToAjaxQueue with computed data', function() {
  1047. data = [
  1048. {"ServiceInfo": { "service_name": 's1' }},
  1049. {"ServiceInfo": { "service_name": 's2' }},
  1050. {"ServiceInfo": { "service_name": 's3' }}
  1051. ];
  1052. installerStep8Controller.createSelectedServices();
  1053. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(JSON.stringify(data));
  1054. });
  1055. });
  1056. describe('#registerHostsToCluster', function() {
  1057. var data;
  1058. beforeEach(function () {
  1059. sinon.stub(installerStep8Controller, 'createRegisterHostData', function () {
  1060. return data;
  1061. });
  1062. });
  1063. afterEach(function () {
  1064. installerStep8Controller.createRegisterHostData.restore();
  1065. });
  1066. it('shouldn\'t do nothing if no data', function() {
  1067. data = [];
  1068. installerStep8Controller.registerHostsToCluster();
  1069. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1070. });
  1071. it('should call addRequestToAjaxQueue with computed data', function() {
  1072. data = [
  1073. {"Hosts": { "host_name": 'h1'}},
  1074. {"Hosts": { "host_name": 'h3'}}
  1075. ];
  1076. installerStep8Controller.registerHostsToCluster();
  1077. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(JSON.stringify(data));
  1078. });
  1079. });
  1080. describe('#registerHostsToComponent', function() {
  1081. it('shouldn\'t do request if no hosts provided', function() {
  1082. installerStep8Controller.registerHostsToComponent([]);
  1083. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.equal(false);
  1084. });
  1085. it('should do request if hostNames are provided', function() {
  1086. var hostNames = ['h1', 'h2'],
  1087. componentName = 'c1';
  1088. installerStep8Controller.registerHostsToComponent(hostNames, componentName);
  1089. var data = JSON.parse(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data);
  1090. expect(data.RequestInfo.query).to.equal('Hosts/host_name=h1|Hosts/host_name=h2');
  1091. expect(data.Body.host_components[0].HostRoles.component_name).to.equal('c1');
  1092. });
  1093. });
  1094. describe('#applyConfigurationsToCluster', function() {
  1095. it('should call addRequestToAjaxQueue', function() {
  1096. var serviceConfigTags = [
  1097. {
  1098. type: 'hdfs',
  1099. tag: 'tag1',
  1100. properties: {
  1101. 'prop1': 'value1'
  1102. }
  1103. }
  1104. ],
  1105. data = '['+JSON.stringify({
  1106. Clusters: {
  1107. desired_config: [serviceConfigTags[0]]
  1108. }
  1109. })+']';
  1110. installerStep8Controller.reopen({
  1111. installedServices: [
  1112. Em.Object.create({
  1113. isSelected: true,
  1114. isInstalled: false,
  1115. configTypesRendered: {hdfs:'tag1'}
  1116. })
  1117. ], selectedServices: []
  1118. });
  1119. installerStep8Controller.applyConfigurationsToCluster(serviceConfigTags);
  1120. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data).to.equal(data);
  1121. });
  1122. });
  1123. describe('#newServiceComponentErrorCallback', function() {
  1124. it('should add request for new component', function() {
  1125. var serviceName = 's1',
  1126. componentName = 'c1';
  1127. installerStep8Controller.newServiceComponentErrorCallback({}, {}, '', {}, {serviceName: serviceName, componentName: componentName});
  1128. var data = JSON.parse(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.data);
  1129. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data.serviceName).to.equal(serviceName);
  1130. expect(data.components[0].ServiceComponentInfo.component_name).to.equal(componentName);
  1131. });
  1132. });
  1133. describe('#createAdditionalHostComponents', function() {
  1134. beforeEach(function() {
  1135. sinon.stub(installerStep8Controller, 'registerHostsToComponent', Em.K);
  1136. });
  1137. afterEach(function() {
  1138. installerStep8Controller.registerHostsToComponent.restore();
  1139. });
  1140. describe('should add components with isRequiredOnAllHosts == true (1)', function() {
  1141. beforeEach(function () {
  1142. installerStep8Controller.reopen({
  1143. getRegisteredHosts: function() {
  1144. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1145. },
  1146. content: {
  1147. services: [
  1148. Em.Object.create({
  1149. serviceName: 'GANGLIA', isSelected: true, isInstalled: false, serviceComponents: [
  1150. Em.Object.create({
  1151. componentName: 'GANGLIA_MONITOR',
  1152. isRequiredOnAllHosts: true
  1153. }),
  1154. Em.Object.create({
  1155. componentName: 'GANGLIA_SERVER',
  1156. isRequiredOnAllHosts: false
  1157. })
  1158. ]
  1159. })
  1160. ]
  1161. }
  1162. });
  1163. installerStep8Controller.createAdditionalHostComponents();
  1164. });
  1165. it('registerHostsToComponent is called once', function () {
  1166. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1167. });
  1168. it('hosts are ["h1", "h2"]', function () {
  1169. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1170. });
  1171. it('component is GANGLIA_MONITOR', function () {
  1172. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('GANGLIA_MONITOR');
  1173. });
  1174. });
  1175. describe('should add components with isRequiredOnAllHosts == true (2)', function() {
  1176. beforeEach(function () {
  1177. installerStep8Controller.reopen({
  1178. getRegisteredHosts: function() {
  1179. return [{hostName: 'h1', isInstalled: true}, {hostName: 'h2', isInstalled: false}];
  1180. },
  1181. content: {
  1182. services: [
  1183. Em.Object.create({
  1184. serviceName: 'GANGLIA', isSelected: true, isInstalled: true, serviceComponents: [
  1185. Em.Object.create({
  1186. componentName: 'GANGLIA_MONITOR',
  1187. isRequiredOnAllHosts: true
  1188. }),
  1189. Em.Object.create({
  1190. componentName: 'GANGLIA_SERVER',
  1191. isRequiredOnAllHosts: false
  1192. })
  1193. ]
  1194. })
  1195. ]
  1196. }
  1197. });
  1198. installerStep8Controller.createAdditionalHostComponents();
  1199. });
  1200. it('registerHostsToComponent is called once', function () {
  1201. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1202. });
  1203. it('hosts are ["h2"]', function () {
  1204. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h2']);
  1205. });
  1206. it('component is GANGLIA_MONITOR', function () {
  1207. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('GANGLIA_MONITOR');
  1208. });
  1209. });
  1210. var newDatabases = [
  1211. {name: 'New MySQL Database',
  1212. component: 'MYSQL_SERVER'
  1213. },
  1214. {name: 'New PostgreSQL Database',
  1215. component: 'POSTGRESQL_SERVER'
  1216. }
  1217. ];
  1218. newDatabases.forEach(function (db) {
  1219. describe('should add {0}'.format(db.component), function() {
  1220. beforeEach(function () {
  1221. installerStep8Controller.reopen({
  1222. getRegisteredHosts: function() {
  1223. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1224. },
  1225. content: {
  1226. masterComponentHosts: [
  1227. {component: 'HIVE_SERVER', hostName: 'h1'},
  1228. {component: 'HIVE_SERVER', hostName: 'h2'}
  1229. ],
  1230. services: [
  1231. Em.Object.create({serviceName: 'HIVE', isSelected: true, isInstalled: false, serviceComponents: []})
  1232. ],
  1233. serviceConfigProperties: [
  1234. {name: 'hive_database', value: db.name}
  1235. ]
  1236. }
  1237. });
  1238. installerStep8Controller.createAdditionalHostComponents();
  1239. });
  1240. it('registerHostsToComponent is called once', function () {
  1241. expect(installerStep8Controller.registerHostsToComponent.calledOnce).to.equal(true);
  1242. });
  1243. it('hosts are ["h1", "h2"]', function () {
  1244. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1245. });
  1246. it('component is ' + db.component, function () {
  1247. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal(db.component);
  1248. });
  1249. });
  1250. });
  1251. });
  1252. describe('#createAdditionalHostComponentsOnAllHosts', function () {
  1253. beforeEach(function() {
  1254. sinon.stub(installerStep8Controller, 'registerHostsToComponent', Em.K);
  1255. });
  1256. afterEach(function() {
  1257. installerStep8Controller.registerHostsToComponent.restore();
  1258. });
  1259. describe('should add components with isRequiredOnAllHosts == true (1)', function() {
  1260. beforeEach(function () {
  1261. installerStep8Controller.reopen({
  1262. getRegisteredHosts: function() {
  1263. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1264. },
  1265. content: {
  1266. services: Em.A([
  1267. Em.Object.create({
  1268. serviceName: 'ANYSERVICE', isSelected: true, isInstalled: false, serviceComponents: [
  1269. // set isRequiredOnAllHosts = true for slave and client
  1270. Em.Object.create({
  1271. componentName: 'ANYSERVICE_MASTER',
  1272. isMaster: true,
  1273. isRequiredOnAllHosts: false
  1274. }),
  1275. Em.Object.create({
  1276. componentName: 'ANYSERVICE_SLAVE',
  1277. isSlave: true,
  1278. isRequiredOnAllHosts: true
  1279. }),
  1280. Em.Object.create({
  1281. componentName: 'ANYSERVICE_SLAVE2',
  1282. isSlave: true,
  1283. isRequiredOnAllHosts: true
  1284. }),
  1285. Em.Object.create({
  1286. componentName: 'ANYSERVICE_CLIENT',
  1287. isClient: true,
  1288. isRequiredOnAllHosts: true
  1289. })
  1290. ]
  1291. })
  1292. ]),
  1293. masterComponentHosts: Em.A([
  1294. Em.Object.create({
  1295. componentName: 'ANYSERVICE_MASTER',
  1296. component: 'ANYSERVICE_MASTER',
  1297. hosts: Em.A([
  1298. Em.Object.create({hostName: 'h1', isInstalled: true})
  1299. ])
  1300. })
  1301. ]),
  1302. slaveComponentHosts: Em.A([
  1303. Em.Object.create({
  1304. componentName: 'ANYSERVICE_SLAVE',
  1305. hosts: Em.A([
  1306. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1307. Em.Object.create({hostName: 'h2', isInstalled: false})
  1308. ])
  1309. }),
  1310. Em.Object.create({
  1311. componentName: 'ANYSERVICE_SLAVE2',
  1312. hosts: Em.A([
  1313. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1314. Em.Object.create({hostName: 'h2', isInstalled: false})
  1315. ])
  1316. }),
  1317. Em.Object.create({
  1318. componentName: 'CLIENT',
  1319. hosts: Em.A([
  1320. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1321. Em.Object.create({hostName: 'h2', isInstalled: false})
  1322. ])
  1323. })
  1324. ]),
  1325. clients: Em.A([
  1326. Em.Object.create({
  1327. component_name: 'ANYSERVICE_CLIENT',
  1328. isInstalled: false,
  1329. hosts: Em.A([
  1330. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1331. Em.Object.create({hostName: 'h2', isInstalled: false})
  1332. ])
  1333. })
  1334. ])
  1335. }
  1336. });
  1337. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  1338. installerStep8Controller.get('ajaxRequestsQueue').clear();
  1339. installerStep8Controller.createAdditionalHostComponents();
  1340. });
  1341. // Any component with isRequiredOnAllHosts = true implies that
  1342. // registerHostsToComponent would be done via
  1343. // createAdditionalHostComponents() BUT NOT
  1344. // createMasterHostComponents() or createSlaveAndClientsHostComponents()
  1345. // or createAdditionalClientComponents()
  1346. it('registerHostsToComponent 1st call', function () {
  1347. expect(installerStep8Controller.registerHostsToComponent.args[0][0]).to.eql(['h1', 'h2']);
  1348. expect(installerStep8Controller.registerHostsToComponent.args[0][1]).to.equal('ANYSERVICE_SLAVE');
  1349. });
  1350. it('registerHostsToComponent 2nd call', function () {
  1351. expect(installerStep8Controller.registerHostsToComponent.args[1][0]).to.eql(['h1', 'h2']);
  1352. expect(installerStep8Controller.registerHostsToComponent.args[1][1]).to.equal('ANYSERVICE_SLAVE2');
  1353. });
  1354. it('registerHostsToComponent 3rd call', function () {
  1355. expect(installerStep8Controller.registerHostsToComponent.args[2][0]).to.eql(['h1', 'h2']);
  1356. expect(installerStep8Controller.registerHostsToComponent.args[2][1]).to.equal('ANYSERVICE_CLIENT');
  1357. });
  1358. });
  1359. describe('should not add components with isRequiredOnAllHosts == false (2)', function() {
  1360. beforeEach(function () {
  1361. installerStep8Controller.reopen({
  1362. getRegisteredHosts: function() {
  1363. return [{hostName: 'h1'}, {hostName: 'h2'}];
  1364. },
  1365. content: {
  1366. services: Em.A([
  1367. Em.Object.create({
  1368. serviceName: 'ANYSERVICE', isSelected: true, isInstalled: false, serviceComponents: [
  1369. // set isRequiredOnAllHosts = false for all components
  1370. Em.Object.create({
  1371. componentName: 'ANYSERVICE_MASTER',
  1372. isMaster: true,
  1373. isRequiredOnAllHosts: false
  1374. }),
  1375. Em.Object.create({
  1376. componentName: 'ANYSERVICE_SLAVE',
  1377. isSlave: true,
  1378. isRequiredOnAllHosts: false
  1379. }),
  1380. Em.Object.create({
  1381. componentName: 'ANYSERVICE_SLAVE2',
  1382. isSlave: true,
  1383. isRequiredOnAllHosts: false
  1384. }),
  1385. Em.Object.create({
  1386. componentName: 'ANYSERVICE_CLIENT',
  1387. isClient: true,
  1388. isRequiredOnAllHosts: false
  1389. })
  1390. ]
  1391. })
  1392. ]),
  1393. masterComponentHosts: Em.A([
  1394. Em.Object.create({
  1395. componentName: 'ANYSERVICE_MASTER',
  1396. component: 'ANYSERVICE_MASTER',
  1397. hosts: Em.A([
  1398. Em.Object.create({hostName: 'h1', isInstalled: true})
  1399. ])
  1400. })
  1401. ]),
  1402. slaveComponentHosts: Em.A([
  1403. Em.Object.create({
  1404. componentName: 'ANYSERVICE_SLAVE',
  1405. hosts: Em.A([
  1406. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1407. Em.Object.create({hostName: 'h2', isInstalled: false})
  1408. ])
  1409. }),
  1410. Em.Object.create({
  1411. componentName: 'ANYSERVICE_SLAVE2',
  1412. hosts: Em.A([
  1413. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1414. Em.Object.create({hostName: 'h2', isInstalled: false})
  1415. ])
  1416. }),
  1417. Em.Object.create({
  1418. componentName: 'CLIENT',
  1419. hosts: Em.A([
  1420. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1421. Em.Object.create({hostName: 'h2', isInstalled: false})
  1422. ])
  1423. })
  1424. ]),
  1425. clients: Em.A([
  1426. Em.Object.create({
  1427. component_name: 'ANYSERVICE_CLIENT',
  1428. isInstalled: false,
  1429. hosts: Em.A([
  1430. Em.Object.create({hostName: 'h1', isInstalled: false}),
  1431. Em.Object.create({hostName: 'h2', isInstalled: false})
  1432. ])
  1433. })
  1434. ])
  1435. }
  1436. });
  1437. installerStep8Controller.set('ajaxRequestsQueue', App.ajaxQueue.create());
  1438. installerStep8Controller.get('ajaxRequestsQueue').clear();
  1439. installerStep8Controller.createAdditionalHostComponents();
  1440. });
  1441. it('registerHostsToComponent is not called', function () {
  1442. // isRequiredOnAllHosts = false for all components, implies that
  1443. // registerHostsToComponent would be done via
  1444. // createMasterHostComponents() or createSlaveAndClientsHostComponents()
  1445. // or createAdditionalClientComponents()
  1446. // BUT NOT createAdditionalHostComponents()
  1447. expect(installerStep8Controller.registerHostsToComponent.callCount).to.equal(0);
  1448. });
  1449. });
  1450. });
  1451. describe('#createNotification', function () {
  1452. beforeEach(function () {
  1453. installerStep8Controller.clearStep();
  1454. installerStep8Controller.set('content', {controllerName: 'installerController'});
  1455. installerStep8Controller.set('configs', [
  1456. {name: 'create_notification', value: 'yes', serviceName: 'MISC', filename: 'alert_notification'},
  1457. {name: 'ambari.dispatch.recipients', value: 'to@f.c', serviceName: 'MISC', filename: 'alert_notification'},
  1458. {name: 'mail.smtp.host', value: 'h', serviceName: 'MISC', filename: 'alert_notification'},
  1459. {name: 'mail.smtp.port', value: '25', serviceName: 'MISC', filename: 'alert_notification'},
  1460. {name: 'mail.smtp.from', value: 'from@f.c', serviceName: 'MISC', filename: 'alert_notification'},
  1461. {name: 'mail.smtp.starttls.enable', value: true, serviceName: 'MISC', filename: 'alert_notification'},
  1462. {name: 'mail.smtp.startssl.enable', value: false, serviceName: 'MISC', filename: 'alert_notification'},
  1463. {name: 'smtp_use_auth', value: 'true', serviceName: 'MISC', filename: 'alert_notification'},
  1464. {name: 'ambari.dispatch.credential.username', value: 'usr', serviceName: 'MISC', filename: 'alert_notification'},
  1465. {name: 'ambari.dispatch.credential.password', value: 'pwd', serviceName: 'MISC', filename: 'alert_notification'},
  1466. {name: 'some_p', value: 'some_v', serviceName: 'MISC', filename: 'alert_notification'}
  1467. ]);
  1468. installerStep8Controller.get('ajaxRequestsQueue').clear();
  1469. });
  1470. it('should add request to queue', function () {
  1471. installerStep8Controller.createNotification();
  1472. expect(installerStep8Controller.get('ajaxRequestsQueue.queue.length')).to.equal(1);
  1473. installerStep8Controller.get('ajaxRequestsQueue').runNextRequest();
  1474. var args = testHelpers.findAjaxRequest('name', 'alerts.create_alert_notification');
  1475. expect(args).exists;
  1476. });
  1477. describe('sent data should be valid', function () {
  1478. var data;
  1479. beforeEach(function () {
  1480. installerStep8Controller.createNotification();
  1481. data = installerStep8Controller.get('ajaxRequestsQueue.queue')[0].data.data.AlertTarget;
  1482. });
  1483. it('global is true', function () {
  1484. expect(data.global).to.be.true;
  1485. });
  1486. it('notification_type is EMAIL', function () {
  1487. expect(data.notification_type).to.equal('EMAIL');
  1488. });
  1489. it('alert_states are valid', function () {
  1490. expect(data.alert_states).to.eql(['OK', 'WARNING', 'CRITICAL', 'UNKNOWN']);
  1491. });
  1492. it('ambari.dispatch.recipients is valid', function () {
  1493. expect(data.properties['ambari.dispatch.recipients']).to.eql(['to@f.c']);
  1494. });
  1495. it('mail.smtp.host is valid', function () {
  1496. expect(data.properties['mail.smtp.host']).to.equal('h');
  1497. });
  1498. it('mail.smtp.port is valid', function () {
  1499. expect(data.properties['mail.smtp.port']).to.equal('25');
  1500. });
  1501. it('mail.smtp.from is valid', function () {
  1502. expect(data.properties['mail.smtp.from']).to.equal('from@f.c');
  1503. });
  1504. it('mail.smtp.starttls.enable is true', function () {
  1505. expect(data.properties['mail.smtp.starttls.enable']).to.equal(true);
  1506. });
  1507. it('mail.smtp.startssl.enable is false', function () {
  1508. expect(data.properties['mail.smtp.startssl.enable']).to.equal(false);
  1509. });
  1510. it('ambari.dispatch.credential.username is valid', function () {
  1511. expect(data.properties['ambari.dispatch.credential.username']).to.equal('usr');
  1512. });
  1513. it('ambari.dispatch.credential.password is valid', function () {
  1514. expect(data.properties['ambari.dispatch.credential.password']).to.equal('pwd');
  1515. });
  1516. it('custom property is valid', function () {
  1517. expect(data.properties.some_p).to.equal('some_v');
  1518. });
  1519. });
  1520. });
  1521. });
  1522. App.TestAliases.testAsComputedEqualProperties(getController(), 'isAllClusterDeleteRequestsCompleted', 'clusterDeleteRequestsCompleted', 'clusterNames.length');
  1523. describe('#deleteClusterSuccessCallback', function () {
  1524. beforeEach(function () {
  1525. sinon.stub(installerStep8Controller, 'showDeleteClustersErrorPopup', Em.K);
  1526. sinon.stub(installerStep8Controller, 'startDeploy', Em.K);
  1527. installerStep8Controller.setProperties({
  1528. clusterDeleteRequestsCompleted: 0,
  1529. clusterNames: ['c0', 'c1'],
  1530. clusterDeleteErrorViews: []
  1531. });
  1532. installerStep8Controller.deleteClusterSuccessCallback();
  1533. });
  1534. afterEach(function () {
  1535. installerStep8Controller.showDeleteClustersErrorPopup.restore();
  1536. installerStep8Controller.startDeploy.restore();
  1537. });
  1538. describe('no failed requests', function () {
  1539. it('before Delete Cluster request', function () {
  1540. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(1);
  1541. expect(installerStep8Controller.showDeleteClustersErrorPopup.called).to.be.false;
  1542. expect(installerStep8Controller.startDeploy.called).to.be.false;
  1543. });
  1544. it('after Delete Cluster request', function () {
  1545. installerStep8Controller.deleteClusterSuccessCallback();
  1546. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(2);
  1547. expect(installerStep8Controller.showDeleteClustersErrorPopup.called).to.be.false;
  1548. expect(installerStep8Controller.startDeploy.calledOnce).to.be.true;
  1549. });
  1550. });
  1551. it('one request failed', function () {
  1552. installerStep8Controller.deleteClusterErrorCallback({}, null, null, {});
  1553. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(2);
  1554. expect(installerStep8Controller.showDeleteClustersErrorPopup.calledOnce).to.be.true;
  1555. expect(installerStep8Controller.startDeploy.called).to.be.false;
  1556. });
  1557. });
  1558. describe('#deleteClusterErrorCallback', function () {
  1559. var request = {
  1560. status: 500,
  1561. responseText: '{"message":"Internal Server Error"}'
  1562. },
  1563. ajaxOptions = 'error',
  1564. error = 'Internal Server Error',
  1565. opt = {
  1566. url: 'api/v1/clusters/c0',
  1567. type: 'DELETE'
  1568. };
  1569. beforeEach(function () {
  1570. installerStep8Controller.setProperties({
  1571. clusterDeleteRequestsCompleted: 0,
  1572. clusterNames: ['c0', 'c1'],
  1573. clusterDeleteErrorViews: []
  1574. });
  1575. sinon.stub(installerStep8Controller, 'showDeleteClustersErrorPopup', Em.K);
  1576. installerStep8Controller.deleteClusterErrorCallback(request, ajaxOptions, error, opt);
  1577. });
  1578. afterEach(function () {
  1579. installerStep8Controller.showDeleteClustersErrorPopup.restore();
  1580. });
  1581. describe('should show error popup only if all requests are completed', function () {
  1582. it('Before Delete Cluster request fail', function () {
  1583. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(1);
  1584. expect(installerStep8Controller.showDeleteClustersErrorPopup.called).to.be.false;
  1585. });
  1586. it('After Delete Cluster request is failed', function () {
  1587. installerStep8Controller.deleteClusterErrorCallback(request, ajaxOptions, error, opt);
  1588. expect(installerStep8Controller.get('clusterDeleteRequestsCompleted')).to.equal(2);
  1589. expect(installerStep8Controller.showDeleteClustersErrorPopup.calledOnce).to.be.true;
  1590. });
  1591. });
  1592. describe('should create error popup body view', function () {
  1593. it('One failed request', function () {
  1594. expect(installerStep8Controller.get('clusterDeleteErrorViews')).to.have.length(1);
  1595. });
  1596. it('failed request url is valid', function () {
  1597. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.url')).to.equal('api/v1/clusters/c0');
  1598. });
  1599. it('failed request type is valid', function () {
  1600. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.type')).to.equal('DELETE');
  1601. });
  1602. it('failed request status is valid', function () {
  1603. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.status')).to.equal(500);
  1604. });
  1605. it('failed request message is valid', function () {
  1606. expect(installerStep8Controller.get('clusterDeleteErrorViews.firstObject.message')).to.equal('Internal Server Error');
  1607. });
  1608. });
  1609. });
  1610. describe('#showDeleteClustersErrorPopup', function () {
  1611. beforeEach(function () {
  1612. installerStep8Controller.setProperties({
  1613. isSubmitDisabled: true,
  1614. isBackBtnDisabled: true
  1615. });
  1616. sinon.stub(App.ModalPopup, 'show', Em.K);
  1617. installerStep8Controller.showDeleteClustersErrorPopup();
  1618. });
  1619. afterEach(function () {
  1620. App.ModalPopup.show.restore();
  1621. });
  1622. it('should show error popup and unlock navigation', function () {
  1623. expect(installerStep8Controller.get('isSubmitDisabled')).to.be.false;
  1624. expect(installerStep8Controller.get('isBackBtnDisabled')).to.be.false;
  1625. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1626. });
  1627. });
  1628. describe('#startDeploy', function () {
  1629. var stubbedNames = ['createCluster', 'createSelectedServices', 'createConfigurations',
  1630. 'applyConfigurationsToCluster', 'createComponents', 'registerHostsToCluster', 'createConfigurationGroups',
  1631. 'createMasterHostComponents', 'createSlaveAndClientsHostComponents', 'createAdditionalClientComponents',
  1632. 'createAdditionalHostComponents'],
  1633. cases = [
  1634. {
  1635. controllerName: 'installerController',
  1636. notExecuted: ['createAdditionalClientComponents'],
  1637. fileNamesToUpdate: [],
  1638. title: 'Installer, no configs to update'
  1639. },
  1640. {
  1641. controllerName: 'addHostController',
  1642. notExecuted: ['createConfigurations', 'applyConfigurationsToCluster', 'createAdditionalClientComponents'],
  1643. title: 'Add Host Wizard'
  1644. },
  1645. {
  1646. controllerName: 'addServiceController',
  1647. notExecuted: ['updateConfigurations'],
  1648. fileNamesToUpdate: [],
  1649. title: 'Add Service Wizard, no configs to update'
  1650. },
  1651. {
  1652. controllerName: 'addServiceController',
  1653. notExecuted: [],
  1654. fileNamesToUpdate: [''],
  1655. title: 'Add Service Wizard, some configs to be updated'
  1656. }
  1657. ];
  1658. beforeEach(function () {
  1659. sinon.stub(App, 'get').withArgs('isKerberosEnabled').returns(false);
  1660. stubbedNames.forEach(function (name) {
  1661. sinon.stub(installerStep8Controller, name, Em.K);
  1662. });
  1663. installerStep8Controller.setProperties({
  1664. serviceConfigTags: [],
  1665. content: {
  1666. controllerName: null
  1667. }
  1668. });
  1669. });
  1670. afterEach(function () {
  1671. App.get.restore();
  1672. stubbedNames.forEach(function (name) {
  1673. installerStep8Controller[name].restore();
  1674. });
  1675. installerStep8Controller.get.restore();
  1676. });
  1677. cases.forEach(function (item) {
  1678. describe(item.title, function () {
  1679. beforeEach(function () {
  1680. sinon.stub(installerStep8Controller, 'get')
  1681. .withArgs('ajaxRequestsQueue').returns({
  1682. start: Em.K
  1683. })
  1684. .withArgs('ajaxRequestsQueue.queue.length').returns(1)
  1685. .withArgs('wizardController').returns({
  1686. getDBProperty: function () {
  1687. return item.fileNamesToUpdate;
  1688. }
  1689. })
  1690. .withArgs('content.controllerName').returns(item.controllerName);
  1691. installerStep8Controller.startDeploy();
  1692. });
  1693. stubbedNames.forEach(function (name) {
  1694. it(name, function () {
  1695. expect(installerStep8Controller[name].called).to.equal(!item.notExecuted.contains(name));
  1696. });
  1697. });
  1698. });
  1699. });
  1700. });
  1701. describe('#getClientsMap', function () {
  1702. var cases = [
  1703. {
  1704. flag: 'isMaster',
  1705. result: {
  1706. c8: ['c1', 'c2'],
  1707. c9: ['c1', 'c2']
  1708. },
  1709. title: 'dependencies for masters'
  1710. },
  1711. {
  1712. flag: 'isSlave',
  1713. result: {
  1714. c8: ['c5', 'c6'],
  1715. c9: ['c5', 'c6']
  1716. },
  1717. title: 'dependencies for slaves'
  1718. },
  1719. {
  1720. flag: 'isClient',
  1721. result: {
  1722. c8: ['c9', 'c10'],
  1723. c9: ['c9', 'c10']
  1724. },
  1725. title: 'dependencies for clients'
  1726. },
  1727. {
  1728. flag: null,
  1729. result: {
  1730. c8: ['c1', 'c2', 'c5', 'c6', 'c9', 'c10'],
  1731. c9: ['c1', 'c2', 'c5', 'c6', 'c9', 'c10']
  1732. },
  1733. title: 'dependencies for all components'
  1734. }
  1735. ];
  1736. before(function () {
  1737. sinon.stub(App.StackServiceComponent, 'find').returns([
  1738. Em.Object.create({
  1739. componentName: 'c0',
  1740. isMaster: true,
  1741. dependencies: [
  1742. {
  1743. componentName: 'c1'
  1744. },
  1745. {
  1746. componentName: 'c2'
  1747. },
  1748. {
  1749. componentName: 'c4'
  1750. },
  1751. {
  1752. componentName: 'c5'
  1753. }
  1754. ]
  1755. }),
  1756. Em.Object.create({
  1757. componentName: 'c1',
  1758. isMaster: true,
  1759. dependencies: [
  1760. {
  1761. componentName: 'c4'
  1762. },
  1763. {
  1764. componentName: 'c5'
  1765. },
  1766. {
  1767. componentName: 'c8'
  1768. },
  1769. {
  1770. componentName: 'c9'
  1771. }
  1772. ]
  1773. }),
  1774. Em.Object.create({
  1775. componentName: 'c2',
  1776. isMaster: true,
  1777. dependencies: [
  1778. {
  1779. componentName: 'c1'
  1780. },
  1781. {
  1782. componentName: 'c2'
  1783. },
  1784. {
  1785. componentName: 'c8'
  1786. },
  1787. {
  1788. componentName: 'c9'
  1789. }
  1790. ]
  1791. }),
  1792. Em.Object.create({
  1793. componentName: 'c3',
  1794. isMaster: true,
  1795. dependencies: []
  1796. }),
  1797. Em.Object.create({
  1798. componentName: 'c4',
  1799. isSlave: true,
  1800. dependencies: [
  1801. {
  1802. componentName: 'c1'
  1803. },
  1804. {
  1805. componentName: 'c2'
  1806. },
  1807. {
  1808. componentName: 'c4'
  1809. },
  1810. {
  1811. componentName: 'c5'
  1812. }
  1813. ]
  1814. }),
  1815. Em.Object.create({
  1816. componentName: 'c5',
  1817. isSlave: true,
  1818. dependencies: [
  1819. {
  1820. componentName: 'c4'
  1821. },
  1822. {
  1823. componentName: 'c5'
  1824. },
  1825. {
  1826. componentName: 'c8'
  1827. },
  1828. {
  1829. componentName: 'c9'
  1830. }
  1831. ]
  1832. }),
  1833. Em.Object.create({
  1834. componentName: 'c6',
  1835. isSlave: true,
  1836. dependencies: [
  1837. {
  1838. componentName: 'c1'
  1839. },
  1840. {
  1841. componentName: 'c2'
  1842. },
  1843. {
  1844. componentName: 'c8'
  1845. },
  1846. {
  1847. componentName: 'c9'
  1848. }
  1849. ]
  1850. }),
  1851. Em.Object.create({
  1852. componentName: 'c7',
  1853. isSlave: true,
  1854. dependencies: []
  1855. }),
  1856. Em.Object.create({
  1857. componentName: 'c8',
  1858. isClient: true,
  1859. dependencies: [
  1860. {
  1861. componentName: 'c1'
  1862. },
  1863. {
  1864. componentName: 'c2'
  1865. },
  1866. {
  1867. componentName: 'c4'
  1868. },
  1869. {
  1870. componentName: 'c5'
  1871. }
  1872. ]
  1873. }),
  1874. Em.Object.create({
  1875. componentName: 'c9',
  1876. isClient: true,
  1877. dependencies: [
  1878. {
  1879. componentName: 'c4'
  1880. },
  1881. {
  1882. componentName: 'c5'
  1883. },
  1884. {
  1885. componentName: 'c8'
  1886. },
  1887. {
  1888. componentName: 'c9'
  1889. }
  1890. ]
  1891. }),
  1892. Em.Object.create({
  1893. componentName: 'c10',
  1894. isClient: true,
  1895. dependencies: [
  1896. {
  1897. componentName: 'c1'
  1898. },
  1899. {
  1900. componentName: 'c2'
  1901. },
  1902. {
  1903. componentName: 'c8'
  1904. },
  1905. {
  1906. componentName: 'c9'
  1907. }
  1908. ]
  1909. }),
  1910. Em.Object.create({
  1911. componentName: 'c11',
  1912. isClient: true,
  1913. dependencies: []
  1914. })
  1915. ]);
  1916. });
  1917. after(function () {
  1918. App.StackServiceComponent.find.restore();
  1919. });
  1920. cases.forEach(function (item) {
  1921. it(item.title, function () {
  1922. expect(installerStep8Controller.getClientsMap(item.flag)).to.eql(item.result);
  1923. });
  1924. });
  1925. });
  1926. describe('#showLoadingIndicator', function() {
  1927. beforeEach(function () {
  1928. sinon.spy(App.ModalPopup, 'show');
  1929. });
  1930. afterEach(function () {
  1931. App.ModalPopup.show.restore();
  1932. });
  1933. it('if popup doesn\'t exist should create another', function() {
  1934. installerStep8Controller.set('isSubmitDisabled', true);
  1935. installerStep8Controller.showLoadingIndicator();
  1936. expect(App.ModalPopup.show.calledOnce).to.equal(true);
  1937. });
  1938. });
  1939. describe('#updateKerberosDescriptor', function () {
  1940. var requestData = {artifactName: 'kerberos_descriptor',
  1941. data: {
  1942. artifact_data: 1234
  1943. }
  1944. };
  1945. beforeEach(function () {
  1946. sinon.stub(App.db, 'get').withArgs('KerberosWizard', 'kerberosDescriptorConfigs').returns(1234);
  1947. sinon.stub(installerStep8Controller, 'addRequestToAjaxQueue', Em.K);
  1948. sinon.stub(installerStep8Controller, 'get').withArgs('wizardController').returns(Em.Object.create({
  1949. getDBProperty: function() { return true; }
  1950. }));
  1951. });
  1952. afterEach(function () {
  1953. App.db.get.restore();
  1954. installerStep8Controller.addRequestToAjaxQueue.restore();
  1955. installerStep8Controller.get.restore();
  1956. });
  1957. it('should send request instantly', function () {
  1958. installerStep8Controller.updateKerberosDescriptor(true);
  1959. var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.update');
  1960. expect(args[0]).exists;
  1961. expect(args[0].data).to.be.eql(requestData);
  1962. expect(installerStep8Controller.addRequestToAjaxQueue.called).to.be.false;
  1963. });
  1964. it('should add request to the queue', function () {
  1965. installerStep8Controller.updateKerberosDescriptor(false);
  1966. var args = testHelpers.findAjaxRequest('name', 'admin.kerberos.cluster.artifact.update');
  1967. expect(args).not.exists;
  1968. expect(installerStep8Controller.addRequestToAjaxQueue.calledOnce).to.be.true;
  1969. expect(installerStep8Controller.addRequestToAjaxQueue.args[0][0].data).to.be.eql(requestData);
  1970. });
  1971. });
  1972. });