step8_test.js 58 KB

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