step8_test.js 68 KB

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