step8_test.js 58 KB

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