step8_test.js 60 KB

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