step4_controller_test.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/service/reassign/step4_controller');
  20. describe('App.ReassignMasterWizardStep4Controller', function () {
  21. var controller = App.ReassignMasterWizardStep4Controller.create({
  22. content: Em.Object.create({
  23. reassign: Em.Object.create(),
  24. reassignHosts: Em.Object.create()
  25. })
  26. });
  27. beforeEach(function () {
  28. sinon.stub(App.ajax, 'send', Em.K);
  29. });
  30. afterEach(function () {
  31. App.ajax.send.restore();
  32. });
  33. describe('#setAdditionalConfigs()', function () {
  34. beforeEach(function () {
  35. sinon.stub(App, 'get').withArgs('isHaEnabled').returns(true);
  36. });
  37. afterEach(function () {
  38. App.get.restore();
  39. });
  40. it('Component is absent', function () {
  41. controller.set('additionalConfigsMap', []);
  42. var configs = {};
  43. expect(controller.setAdditionalConfigs(configs, 'COMP1', '')).to.be.false;
  44. expect(configs).to.eql({});
  45. });
  46. it('configs for Hadoop 2 is present', function () {
  47. controller.set('additionalConfigsMap', [
  48. {
  49. componentName: 'COMP1',
  50. configs: {
  51. 'test-site': {
  52. 'property1': '<replace-value>:1111'
  53. }
  54. },
  55. configs_Hadoop2: {
  56. 'test-site': {
  57. 'property2': '<replace-value>:2222'
  58. }
  59. }
  60. }
  61. ]);
  62. var configs = {
  63. 'test-site': {}
  64. };
  65. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  66. expect(configs).to.eql({
  67. 'test-site': {
  68. 'property2': 'host1:2222'
  69. }
  70. });
  71. });
  72. it('ignore some configs for NameNode after HA', function () {
  73. controller.set('additionalConfigsMap', [
  74. {
  75. componentName: 'NAMENODE',
  76. configs: {
  77. 'test-site': {
  78. 'fs.defaultFS': '<replace-value>:1111',
  79. 'dfs.namenode.rpc-address': '<replace-value>:1111'
  80. }
  81. }
  82. }
  83. ]);
  84. var configs = {'test-site': {}};
  85. expect(controller.setAdditionalConfigs(configs, 'NAMENODE', 'host1')).to.be.true;
  86. expect(configs).to.eql({'test-site': {}});
  87. });
  88. });
  89. describe('#getHostComponentsNames()', function () {
  90. it('No host-components', function () {
  91. controller.set('hostComponents', []);
  92. expect(controller.getHostComponentsNames()).to.be.empty;
  93. });
  94. it('one host-components', function () {
  95. controller.set('hostComponents', ['COMP1']);
  96. expect(controller.getHostComponentsNames()).to.equal('Comp1');
  97. });
  98. it('ZKFC host-components', function () {
  99. controller.set('hostComponents', ['COMP1', 'ZKFC']);
  100. expect(controller.getHostComponentsNames()).to.equal('Comp1+ZKFC');
  101. });
  102. });
  103. describe('#testDBConnection', function() {
  104. beforeEach(function() {
  105. controller.set('requiredProperties', Em.A([]));
  106. controller.set('content.serviceProperties', Em.Object.create({'javax.jdo.option.ConnectionDriverName': 'mysql'}));
  107. controller.set('content.reassign.component_name', 'HIVE_SERVER');
  108. sinon.stub(controller, 'getConnectionProperty', Em.K);
  109. sinon.stub(App.router, 'get', Em.K);
  110. });
  111. afterEach(function() {
  112. controller.getConnectionProperty.restore();
  113. App.router.get.restore();
  114. });
  115. describe('tests database connection', function() {
  116. beforeEach(function () {
  117. sinon.stub(controller, 'prepareDBCheckAction', Em.K);
  118. });
  119. afterEach(function () {
  120. controller.prepareDBCheckAction.restore();
  121. });
  122. it('prepareDBCheckAction is called once', function() {
  123. controller.testDBConnection();
  124. expect(controller.prepareDBCheckAction.calledOnce).to.be.true;
  125. });
  126. });
  127. it('tests prepareDBCheckAction', function() {
  128. controller.prepareDBCheckAction();
  129. expect(App.ajax.send.calledOnce).to.be.true;
  130. });
  131. });
  132. describe('#removeUnneededTasks()', function () {
  133. var isHaEnabled = false;
  134. var commands;
  135. var commandsForDB;
  136. beforeEach(function () {
  137. sinon.stub(App, 'get', function () {
  138. return isHaEnabled;
  139. });
  140. commands = [
  141. { id: 1, command: 'stopRequiredServices' },
  142. { id: 2, command: 'cleanMySqlServer' },
  143. { id: 3, command: 'createHostComponents' },
  144. { id: 4, command: 'putHostComponentsInMaintenanceMode' },
  145. { id: 5, command: 'reconfigure' },
  146. { id: 6, command: 'installHostComponents' },
  147. { id: 7, command: 'startZooKeeperServers' },
  148. { id: 8, command: 'startNameNode' },
  149. { id: 9, command: 'deleteHostComponents' },
  150. { id: 10, command: 'configureMySqlServer' },
  151. { id: 11, command: 'startMySqlServer' },
  152. { id: 12, command: 'startNewMySqlServer' },
  153. { id: 13, command: 'startRequiredServices' }
  154. ];
  155. commandsForDB = [
  156. { id: 1, command: 'createHostComponents' },
  157. { id: 2, command: 'installHostComponents' },
  158. { id: 3, command: 'configureMySqlServer' },
  159. { id: 4, command: 'restartMySqlServer' },
  160. { id: 5, command: 'testDBConnection' },
  161. { id: 6, command: 'stopRequiredServices' },
  162. { id: 7, command: 'cleanMySqlServer' },
  163. { id: 8, command: 'putHostComponentsInMaintenanceMode' },
  164. { id: 9, command: 'reconfigure' },
  165. { id: 10, command: 'deleteHostComponents' },
  166. { id: 11, command: 'configureMySqlServer' },
  167. { id: 12, command: 'startRequiredServices' }
  168. ];
  169. });
  170. afterEach(function () {
  171. App.get.restore();
  172. });
  173. it('hasManualSteps is false', function () {
  174. controller.set('tasks', commands);
  175. controller.set('content.hasManualSteps', false);
  176. controller.removeUnneededTasks();
  177. expect(controller.get('tasks').mapProperty('id')).to.eql([1,3,4,5,6,9,12,13]);
  178. });
  179. it('reassign component is not NameNode and HA disabled', function () {
  180. controller.set('tasks', commands);
  181. controller.set('content.hasManualSteps', true);
  182. controller.set('content.reassign.component_name', 'COMP1');
  183. isHaEnabled = false;
  184. controller.removeUnneededTasks();
  185. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6]);
  186. });
  187. it('reassign component is not NameNode and HA enabled', function () {
  188. controller.set('tasks', commands);
  189. controller.set('content.hasManualSteps', true);
  190. controller.set('content.reassign.component_name', 'COMP1');
  191. isHaEnabled = true;
  192. controller.removeUnneededTasks();
  193. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6]);
  194. });
  195. it('reassign component is NameNode and HA disabled', function () {
  196. controller.set('tasks', commands);
  197. controller.set('content.hasManualSteps', true);
  198. controller.set('content.reassign.component_name', 'NAMENODE');
  199. isHaEnabled = false;
  200. controller.removeUnneededTasks();
  201. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6]);
  202. });
  203. it('reassign component is NameNode and HA enabled', function () {
  204. controller.set('tasks', commands);
  205. controller.set('content.hasManualSteps', true);
  206. controller.set('content.reassign.component_name', 'NAMENODE');
  207. isHaEnabled = true;
  208. controller.removeUnneededTasks();
  209. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6, 7, 8]);
  210. });
  211. it('reassign component is HiveServer and db type is mysql', function () {
  212. controller.set('tasks', commandsForDB);
  213. controller.set('content.hasManualSteps', false);
  214. controller.set('content.databaseType', 'mysql');
  215. controller.set('content.reassign.component_name', 'HIVE_SERVER');
  216. isHaEnabled = false;
  217. controller.removeUnneededTasks();
  218. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
  219. });
  220. it('reassign component is HiveServer and db type is not mysql', function () {
  221. controller.set('tasks', commandsForDB);
  222. controller.set('content.hasManualSteps', false);
  223. controller.set('content.databaseType', 'derby');
  224. controller.set('content.reassign.component_name', 'HIVE_SERVER');
  225. isHaEnabled = false;
  226. controller.removeUnneededTasks();
  227. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 6, 8, 9, 10, 12]);
  228. });
  229. it('reassign component is Oozie Server and db type is derby', function () {
  230. controller.set('tasks', commandsForDB);
  231. controller.set('content.hasManualSteps', true);
  232. controller.set('content.databaseType', 'derby');
  233. controller.set('content.reassign.component_name', 'OOZIE_SERVER');
  234. isHaEnabled = false;
  235. controller.removeUnneededTasks();
  236. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,6,8,9]);
  237. });
  238. it('reassign component is Oozie Server and db type is mysql', function () {
  239. controller.set('content.hasManualSteps', false);
  240. controller.set('content.databaseType', 'mysql');
  241. controller.set('content.reassign.component_name', 'OOZIE_SERVER');
  242. isHaEnabled = false;
  243. controller.set('tasks', commandsForDB);
  244. controller.removeUnneededTasks();
  245. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,3,4,5,6,7,8,9,10,11,12]);
  246. });
  247. it('reassign component is Metrics Collector', function () {
  248. controller.set('content.hasManualSteps', false);
  249. controller.set('content.databaseType', 'mysql');
  250. controller.set('content.reassign.component_name', 'METRICS_COLLECTOR');
  251. isHaEnabled = false;
  252. controller.set('tasks', commandsForDB);
  253. controller.removeUnneededTasks();
  254. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,5,6,8,10,12]);
  255. });
  256. it('reassign component is Mysql Server', function () {
  257. controller.set('content.hasManualSteps', false);
  258. controller.set('content.databaseType', 'mysql');
  259. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  260. isHaEnabled = false;
  261. controller.set('tasks', commandsForDB);
  262. controller.removeUnneededTasks();
  263. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,3,4,5,6,8,9,10,11,12]);
  264. });
  265. });
  266. describe("#stopRequiredServices()", function() {
  267. before(function () {
  268. sinon.stub(controller, 'stopServices', Em.K);
  269. });
  270. after(function () {
  271. controller.stopServices.restore();
  272. });
  273. it('stopServices is called with valid list of services', function() {
  274. controller.set('content.reassign.component_name', 'JOBTRACKER');
  275. controller.stopRequiredServices();
  276. expect(controller.stopServices.calledWith(['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'])).to.be.true;
  277. });
  278. });
  279. describe('#initializeTasks()', function () {
  280. beforeEach(function () {
  281. controller.set('tasks', []);
  282. sinon.stub(controller, 'getHostComponentsNames', Em.K);
  283. sinon.stub(controller, 'removeUnneededTasks', Em.K);
  284. this.mock = sinon.stub(controller, 'isComponentWithDB');
  285. });
  286. afterEach(function () {
  287. controller.removeUnneededTasks.restore();
  288. controller.getHostComponentsNames.restore();
  289. this.mock.restore();
  290. });
  291. it('No commands (isComponentWithDB = false)', function () {
  292. controller.set('commands', []);
  293. controller.set('commandsForDB', []);
  294. this.mock.returns(false);
  295. controller.initializeTasks();
  296. expect(controller.get('tasks')).to.be.empty;
  297. });
  298. it('No commands (isComponentWithDB = true)', function () {
  299. controller.set('commands', []);
  300. controller.set('commandsForDB', []);
  301. this.mock.returns(true);
  302. controller.initializeTasks();
  303. expect(controller.get('tasks')).to.be.empty;
  304. });
  305. it('One command', function () {
  306. controller.set('commands', ['COMMAND1']);
  307. controller.set('commandsForDB', ['COMMAND1']);
  308. controller.initializeTasks();
  309. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  310. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  311. });
  312. });
  313. describe('#hideRollbackButton()', function () {
  314. it('No showRollback command', function () {
  315. controller.set('tasks', [Em.Object.create({
  316. showRollback: false
  317. })]);
  318. controller.hideRollbackButton();
  319. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  320. });
  321. it('showRollback command is present', function () {
  322. controller.set('tasks', [Em.Object.create({
  323. showRollback: true
  324. })]);
  325. controller.hideRollbackButton();
  326. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  327. });
  328. });
  329. describe('#onComponentsTasksSuccess()', function () {
  330. beforeEach(function () {
  331. sinon.stub(controller, 'onTaskCompleted', Em.K);
  332. });
  333. afterEach(function () {
  334. controller.onTaskCompleted.restore();
  335. });
  336. it('No host-components', function () {
  337. controller.set('multiTaskCounter', 0);
  338. controller.set('hostComponents', []);
  339. controller.onComponentsTasksSuccess();
  340. expect(controller.get('multiTaskCounter')).to.equal(1);
  341. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  342. });
  343. it('One host-component', function () {
  344. controller.set('multiTaskCounter', 0);
  345. controller.set('hostComponents', [
  346. {}
  347. ]);
  348. controller.onComponentsTasksSuccess();
  349. expect(controller.get('multiTaskCounter')).to.equal(1);
  350. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  351. });
  352. it('two host-components', function () {
  353. controller.set('multiTaskCounter', 0);
  354. controller.set('hostComponents', [
  355. {},
  356. {}
  357. ]);
  358. controller.onComponentsTasksSuccess();
  359. expect(controller.get('multiTaskCounter')).to.equal(1);
  360. expect(controller.onTaskCompleted.called).to.be.false;
  361. });
  362. });
  363. describe('#stopServices()', function () {
  364. it('request is sent', function () {
  365. controller.stopServices();
  366. expect(App.ajax.send.calledOnce).to.be.true;
  367. });
  368. });
  369. describe('#createHostComponents()', function () {
  370. beforeEach(function () {
  371. sinon.stub(controller, 'createComponent', Em.K);
  372. });
  373. afterEach(function () {
  374. controller.createComponent.restore();
  375. });
  376. it('No host-components', function () {
  377. controller.set('hostComponents', []);
  378. controller.createHostComponents();
  379. expect(controller.get('multiTaskCounter')).to.equal(0);
  380. expect(controller.createComponent.called).to.be.false;
  381. });
  382. it('One host-component', function () {
  383. controller.set('hostComponents', ['COMP1']);
  384. controller.set('content.reassignHosts.target', 'host1');
  385. controller.set('content.reassign.service_id', 'SERVICE1');
  386. controller.createHostComponents();
  387. expect(controller.get('multiTaskCounter')).to.equal(0);
  388. expect(controller.createComponent.calledWith('COMP1', 'host1', 'SERVICE1')).to.be.true;
  389. });
  390. });
  391. describe('#onCreateComponent()', function () {
  392. beforeEach(function () {
  393. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  394. });
  395. afterEach(function () {
  396. controller.onComponentsTasksSuccess.restore();
  397. });
  398. it('onComponentsTasksSuccess is called once', function () {
  399. controller.onCreateComponent();
  400. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  401. });
  402. });
  403. describe('#putHostComponentsInMaintenanceMode()', function () {
  404. beforeEach(function(){
  405. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  406. controller.set('content.reassignHosts.source', 'source');
  407. });
  408. afterEach(function(){
  409. controller.onComponentsTasksSuccess.restore();
  410. });
  411. it('No host-components', function () {
  412. controller.set('hostComponents', []);
  413. controller.putHostComponentsInMaintenanceMode();
  414. expect(App.ajax.send.called).to.be.false;
  415. expect(controller.get('multiTaskCounter')).to.equal(0);
  416. });
  417. it('One host-components', function () {
  418. controller.set('hostComponents', [{}]);
  419. controller.putHostComponentsInMaintenanceMode();
  420. expect(App.ajax.send.calledOnce).to.be.true;
  421. expect(controller.get('multiTaskCounter')).to.equal(0);
  422. });
  423. });
  424. describe('#installHostComponents()', function () {
  425. beforeEach(function () {
  426. sinon.stub(controller, 'updateComponent', Em.K);
  427. });
  428. afterEach(function () {
  429. controller.updateComponent.restore();
  430. });
  431. it('No host-components', function () {
  432. controller.set('hostComponents', []);
  433. controller.installHostComponents();
  434. expect(controller.get('multiTaskCounter')).to.equal(0);
  435. expect(controller.updateComponent.called).to.be.false;
  436. });
  437. it('One host-component', function () {
  438. controller.set('hostComponents', ['COMP1']);
  439. controller.set('content.reassignHosts.target', 'host1');
  440. controller.set('content.reassign.service_id', 'SERVICE1');
  441. controller.installHostComponents();
  442. expect(controller.get('multiTaskCounter')).to.equal(0);
  443. expect(controller.updateComponent.calledWith('COMP1', 'host1', 'SERVICE1', 'Install', 1)).to.be.true;
  444. });
  445. });
  446. describe('#reconfigure()', function () {
  447. beforeEach(function () {
  448. sinon.stub(controller, 'loadConfigsTags', Em.K);
  449. });
  450. afterEach(function () {
  451. controller.loadConfigsTags.restore();
  452. });
  453. it('loadConfigsTags is called once', function () {
  454. controller.reconfigure();
  455. expect(controller.loadConfigsTags.calledOnce).to.be.true;
  456. });
  457. });
  458. describe('#loadConfigsTags()', function () {
  459. it('request is sent', function () {
  460. controller.loadConfigsTags();
  461. expect(App.ajax.send.calledOnce).to.be.true;
  462. });
  463. });
  464. describe('#getConfigUrlParams()', function () {
  465. var testCases = [
  466. {
  467. componentName: 'NAMENODE',
  468. result: [
  469. "(type=hdfs-site&tag=1)",
  470. "(type=core-site&tag=2)"
  471. ]
  472. },
  473. {
  474. componentName: 'SECONDARY_NAMENODE',
  475. result: [
  476. "(type=hdfs-site&tag=1)",
  477. "(type=core-site&tag=2)"
  478. ]
  479. },
  480. {
  481. componentName: 'JOBTRACKER',
  482. result: [
  483. "(type=mapred-site&tag=4)"
  484. ]
  485. },
  486. {
  487. componentName: 'RESOURCEMANAGER',
  488. result: [
  489. "(type=yarn-site&tag=5)"
  490. ]
  491. },
  492. {
  493. componentName: 'APP_TIMELINE_SERVER',
  494. result: [
  495. "(type=yarn-site&tag=5)",
  496. "(type=yarn-env&tag=8)"
  497. ]
  498. },
  499. {
  500. componentName: 'OOZIE_SERVER',
  501. result: [
  502. "(type=oozie-site&tag=6)",
  503. "(type=core-site&tag=2)",
  504. "(type=oozie-env&tag=2)"
  505. ]
  506. },
  507. {
  508. componentName: 'WEBHCAT_SERVER',
  509. result: [
  510. "(type=webhcat-site&tag=7)"
  511. ]
  512. },
  513. {
  514. componentName: 'HIVE_SERVER',
  515. result: [
  516. '(type=hive-site&tag=10)',
  517. '(type=webhcat-site&tag=7)',
  518. '(type=hive-env&tag=11)',
  519. '(type=core-site&tag=2)'
  520. ]
  521. },
  522. {
  523. componentName: 'HIVE_METASTORE',
  524. result: [
  525. '(type=hive-site&tag=10)',
  526. '(type=webhcat-site&tag=7)',
  527. '(type=hive-env&tag=11)',
  528. '(type=core-site&tag=2)'
  529. ]
  530. },
  531. {
  532. componentName: 'MYSQL_SERVER',
  533. result: [
  534. '(type=hive-site&tag=10)'
  535. ]
  536. },
  537. {
  538. componentName: 'HISTORYSERVER',
  539. result: [
  540. '(type=mapred-site&tag=4)'
  541. ]
  542. }
  543. ];
  544. var data = {
  545. Clusters: {
  546. desired_configs: {
  547. 'hdfs-site': {tag: 1},
  548. 'core-site': {tag: 2},
  549. 'hbase-site': {tag: 3},
  550. 'mapred-site': {tag: 4},
  551. 'yarn-site': {tag: 5},
  552. 'oozie-site': {tag: 6},
  553. 'oozie-env': {tag: 2},
  554. 'webhcat-site': {tag: 7},
  555. 'yarn-env': {tag: 8},
  556. 'accumulo-site': {tag: 9},
  557. 'hive-site': {tag: 10},
  558. 'hive-env': {tag: 11}
  559. }
  560. }
  561. };
  562. var services = [];
  563. beforeEach(function () {
  564. sinon.stub(App.Service, 'find', function () {
  565. return services;
  566. });
  567. });
  568. afterEach(function () {
  569. App.Service.find.restore();
  570. });
  571. testCases.forEach(function (test) {
  572. it('get config of ' + test.componentName, function () {
  573. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  574. });
  575. });
  576. it('get config of NAMENODE when HBASE installed', function () {
  577. services = [
  578. {
  579. serviceName: 'HBASE'
  580. }
  581. ];
  582. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  583. "(type=hdfs-site&tag=1)",
  584. "(type=core-site&tag=2)",
  585. "(type=hbase-site&tag=3)"
  586. ]);
  587. });
  588. it('get config of NAMENODE when ACCUMULO installed', function () {
  589. services = [
  590. {
  591. serviceName: 'ACCUMULO'
  592. }
  593. ];
  594. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  595. "(type=hdfs-site&tag=1)",
  596. "(type=core-site&tag=2)",
  597. "(type=accumulo-site&tag=9)"
  598. ]);
  599. });
  600. });
  601. describe('#onLoadConfigsTags()', function () {
  602. beforeEach(function () {
  603. sinon.stub(controller, 'getConfigUrlParams', function () {
  604. return [];
  605. });
  606. controller.set('content.reassign.component_name', 'COMP1');
  607. controller.onLoadConfigsTags({});
  608. });
  609. afterEach(function () {
  610. controller.getConfigUrlParams.restore();
  611. });
  612. it('request is sent', function () {
  613. expect(App.ajax.send.calledOnce).to.be.true;
  614. });
  615. it('getConfigUrlParams is called with correct data', function () {
  616. expect(controller.getConfigUrlParams.calledWith('COMP1', {})).to.be.true;
  617. });
  618. });
  619. describe('#loadStep()', function () {
  620. var isHaEnabled = true;
  621. beforeEach(function () {
  622. controller.set('content.reassign.service_id', 'service1');
  623. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  624. sinon.stub(controller, 'initializeTasks', Em.K);
  625. sinon.stub(App, 'get', function () {
  626. return isHaEnabled;
  627. });
  628. });
  629. afterEach(function () {
  630. controller.onTaskStatusChange.restore();
  631. controller.initializeTasks.restore();
  632. App.get.restore();
  633. });
  634. it('reassign component is NameNode and HA enabled', function () {
  635. isHaEnabled = true;
  636. controller.set('content.reassign.component_name', 'NAMENODE');
  637. controller.loadStep();
  638. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  639. expect(controller.get('serviceName')).to.eql(['service1']);
  640. });
  641. it('reassign component is NameNode and HA disabled', function () {
  642. isHaEnabled = false;
  643. controller.set('content.reassign.component_name', 'NAMENODE');
  644. controller.loadStep();
  645. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  646. expect(controller.get('serviceName')).to.eql(['service1']);
  647. });
  648. it('reassign component is JOBTRACKER and HA enabled', function () {
  649. isHaEnabled = true;
  650. controller.set('content.reassign.component_name', 'JOBTRACKER');
  651. controller.loadStep();
  652. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  653. expect(controller.get('serviceName')).to.eql(['service1']);
  654. });
  655. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  656. isHaEnabled = true;
  657. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  658. controller.loadStep();
  659. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  660. expect(controller.get('serviceName')).to.eql(['service1']);
  661. });
  662. });
  663. describe('#saveConfigsToServer()', function () {
  664. beforeEach(function () {
  665. sinon.stub(controller, 'getServiceConfigData', Em.K);
  666. controller.saveConfigsToServer([1]);
  667. });
  668. afterEach(function () {
  669. controller.getServiceConfigData.restore();
  670. });
  671. it('getServiceConfigData is called with valid data', function () {
  672. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  673. });
  674. it('request is sent', function () {
  675. expect(App.ajax.send.calledOnce).to.be.true;
  676. });
  677. });
  678. describe('#setSecureConfigs()', function () {
  679. beforeEach(function () {
  680. this.stub = sinon.stub(App, 'get');
  681. });
  682. afterEach(function () {
  683. Em.tryInvoke(App.get, 'restore');
  684. });
  685. it('undefined component and security disabled', function () {
  686. var secureConfigs = [];
  687. this.stub.withArgs('isKerberosEnabled').returns(false);
  688. controller.set('secureConfigsMap', []);
  689. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  690. expect(secureConfigs).to.eql([]);
  691. });
  692. it('component exist and security disabled', function () {
  693. var secureConfigs = [];
  694. this.stub.withArgs('isKerberosEnabled').returns(false);
  695. controller.set('secureConfigsMap', [{
  696. componentName: 'COMP1'
  697. }]);
  698. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  699. expect(secureConfigs).to.eql([]);
  700. });
  701. it('undefined component and security enabled', function () {
  702. var secureConfigs = [];
  703. this.stub.withArgs('isKerberosEnabled').returns(true);
  704. controller.set('secureConfigsMap', []);
  705. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  706. expect(secureConfigs).to.eql([]);
  707. });
  708. it('component exist and security enabled', function () {
  709. var secureConfigs = [];
  710. this.stub.withArgs('isKerberosEnabled').returns(true);
  711. var configs = {'s1': {
  712. 'k1': 'kValue',
  713. 'p1': 'pValue'
  714. }};
  715. controller.set('secureConfigsMap', [{
  716. componentName: 'COMP1',
  717. configs: [{
  718. site: 's1',
  719. keytab: 'k1',
  720. principal: 'p1'
  721. }]
  722. }]);
  723. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  724. expect(secureConfigs).to.eql([
  725. {
  726. "keytab": "kValue",
  727. "principal": "pValue"
  728. }
  729. ]);
  730. });
  731. });
  732. describe('#getComponentDir()', function () {
  733. var configs = {
  734. 'hdfs-site': {
  735. 'dfs.name.dir': 'case1',
  736. 'dfs.namenode.name.dir': 'case2',
  737. 'dfs.namenode.checkpoint.dir': 'case3'
  738. },
  739. 'core-site': {
  740. 'fs.checkpoint.dir': 'case4'
  741. }
  742. };
  743. it('unknown component name', function () {
  744. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  745. });
  746. it('NAMENODE component', function () {
  747. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  748. });
  749. it('SECONDARY_NAMENODE component', function () {
  750. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  751. });
  752. });
  753. describe('#saveClusterStatus()', function () {
  754. var mock = {
  755. saveComponentDir: Em.K,
  756. saveSecureConfigs: Em.K
  757. };
  758. beforeEach(function () {
  759. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  760. sinon.stub(App.router, 'get', function() {
  761. return mock;
  762. });
  763. sinon.spy(mock, 'saveComponentDir');
  764. sinon.spy(mock, 'saveSecureConfigs');
  765. });
  766. afterEach(function () {
  767. App.clusterStatus.setClusterStatus.restore();
  768. App.router.get.restore();
  769. mock.saveSecureConfigs.restore();
  770. mock.saveComponentDir.restore();
  771. });
  772. it('componentDir undefined and secureConfigs is empty', function () {
  773. expect(controller.saveClusterStatus([], null)).to.be.false;
  774. });
  775. it('componentDir defined and secureConfigs is empty', function () {
  776. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  777. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  778. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  779. });
  780. it('componentDir undefined and secureConfigs has data', function () {
  781. expect(controller.saveClusterStatus([1], null)).to.be.true;
  782. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  783. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  784. });
  785. it('componentDir defined and secureConfigs has data', function () {
  786. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  787. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  788. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  789. });
  790. });
  791. describe('#onSaveConfigs()', function () {
  792. beforeEach(function () {
  793. sinon.stub(controller, 'onTaskCompleted', Em.K);
  794. });
  795. afterEach(function () {
  796. controller.onTaskCompleted.restore();
  797. });
  798. it('onTaskCompleted called once', function () {
  799. controller.onSaveConfigs();
  800. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  801. });
  802. });
  803. describe('#startZooKeeperServers()', function () {
  804. beforeEach(function () {
  805. sinon.stub(controller, 'updateComponent', Em.K);
  806. });
  807. afterEach(function () {
  808. controller.updateComponent.restore();
  809. });
  810. it('updateComponent called with valid arguments', function () {
  811. controller.set('content.masterComponentHosts', [{
  812. component: 'ZOOKEEPER_SERVER',
  813. hostName: 'host1'
  814. }]);
  815. controller.startZooKeeperServers();
  816. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  817. });
  818. });
  819. describe('#startNameNode()', function () {
  820. beforeEach(function () {
  821. sinon.stub(controller, 'updateComponent', Em.K);
  822. controller.set('content.masterComponentHosts', [{
  823. component: 'NAMENODE',
  824. hostName: 'host1'
  825. }]);
  826. });
  827. afterEach(function () {
  828. controller.updateComponent.restore();
  829. });
  830. it('reassign host does not match current', function () {
  831. controller.set('content.reassignHosts.source', 'host2');
  832. controller.startNameNode();
  833. expect(controller.updateComponent.calledWith('NAMENODE', ['host1'], 'HDFS', 'Start')).to.be.true;
  834. });
  835. it('reassign host matches current', function () {
  836. controller.set('content.reassignHosts.source', 'host1');
  837. controller.startNameNode();
  838. expect(controller.updateComponent.calledWith('NAMENODE', [], 'HDFS', 'Start')).to.be.true;
  839. });
  840. });
  841. describe('#startServices()', function () {
  842. beforeEach(function () {
  843. sinon.stub(App.router, 'get').returns({"skip.service.checks": "false"});
  844. controller.startServices();
  845. });
  846. afterEach(function () {
  847. App.router.get.restore();
  848. });
  849. it('request is sent', function () {
  850. expect(App.ajax.send.calledOnce).to.be.true;
  851. });
  852. });
  853. describe('#deleteHostComponents()', function () {
  854. it('No host components', function () {
  855. controller.set('hostComponents', []);
  856. controller.set('content.reassignHosts.source', 'host1');
  857. controller.deleteHostComponents();
  858. expect(App.ajax.send.called).to.be.false;
  859. });
  860. it('delete two components', function () {
  861. controller.set('hostComponents', [1, 2]);
  862. controller.set('content.reassignHosts.source', 'host1');
  863. controller.deleteHostComponents();
  864. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  865. "hostName": "host1",
  866. "componentName": 1
  867. });
  868. expect(App.ajax.send.getCall(1).args[0].data).to.eql({
  869. "hostName": "host1",
  870. "componentName": 2
  871. });
  872. });
  873. });
  874. describe('#onDeleteHostComponentsError()', function () {
  875. beforeEach(function () {
  876. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  877. sinon.stub(controller, 'onTaskError', Em.K);
  878. });
  879. afterEach(function () {
  880. controller.onComponentsTasksSuccess.restore();
  881. controller.onTaskError.restore();
  882. });
  883. it('task success', function () {
  884. var error = {
  885. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  886. };
  887. controller.onDeleteHostComponentsError(error);
  888. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  889. });
  890. it('unknown error', function () {
  891. var error = {
  892. responseText: ''
  893. };
  894. controller.onDeleteHostComponentsError(error);
  895. expect(controller.onTaskError.calledOnce).to.be.true;
  896. });
  897. });
  898. describe('#done()', function () {
  899. beforeEach(function () {
  900. sinon.stub(controller, 'removeObserver', Em.K);
  901. sinon.stub(App.router, 'send', Em.K);
  902. });
  903. afterEach(function () {
  904. controller.removeObserver.restore();
  905. App.router.send.restore();
  906. });
  907. it('submit disabled', function () {
  908. controller.set('isSubmitDisabled', true);
  909. controller.done();
  910. expect(App.router.send.called).to.be.false;
  911. });
  912. it('submit enabled and does not have manual steps', function () {
  913. controller.set('isSubmitDisabled', false);
  914. controller.set('content.hasManualSteps', false);
  915. controller.done();
  916. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  917. expect(App.router.send.calledWith('complete')).to.be.true;
  918. });
  919. it('submit enabled and has manual steps', function () {
  920. controller.set('isSubmitDisabled', false);
  921. controller.set('content.hasManualSteps', true);
  922. controller.done();
  923. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  924. expect(App.router.send.calledWith('next')).to.be.true;
  925. });
  926. });
  927. describe('#getServiceConfigData()', function () {
  928. var services = [];
  929. var stackServices = [];
  930. beforeEach(function () {
  931. sinon.stub(App.Service, 'find', function () {
  932. return services;
  933. });
  934. sinon.stub(App.StackService, 'find', function () {
  935. return stackServices;
  936. });
  937. });
  938. afterEach(function () {
  939. App.Service.find.restore();
  940. App.StackService.find.restore();
  941. });
  942. it('No services', function () {
  943. services = [];
  944. controller.set('content.reassign.component_name', 'COMP1');
  945. expect(controller.getServiceConfigData([])).to.eql([]);
  946. });
  947. it('No services in stackServices', function () {
  948. services = [Em.Object.create({serviceName: 'S1'})];
  949. stackServices = [];
  950. controller.set('content.reassign.component_name', 'COMP1');
  951. expect(controller.getServiceConfigData([])).to.eql([]);
  952. });
  953. it('Services in stackServices, but configTypesRendered is empty', function () {
  954. services = [Em.Object.create({serviceName: 'S1'})];
  955. stackServices = [Em.Object.create({
  956. serviceName: 'S1',
  957. configTypesRendered: {}
  958. })];
  959. controller.set('content.reassign.component_name', 'COMP1');
  960. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  961. });
  962. it('Services in stackServices, and configTypesRendered has data, but configs is empty', function () {
  963. services = [Em.Object.create({serviceName: 'S1'})];
  964. stackServices = [
  965. Em.Object.create({
  966. serviceName: 'S1',
  967. configTypesRendered: {'type1': {}}
  968. })
  969. ];
  970. controller.set('content.reassign.component_name', 'COMP1');
  971. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  972. });
  973. it('Services in stackServices, and configTypesRendered has data, and configs present', function () {
  974. services = [Em.Object.create({serviceName: 'S1'})];
  975. stackServices = [
  976. Em.Object.create({
  977. serviceName: 'S1',
  978. configTypesRendered: {'type1': {}}
  979. })
  980. ];
  981. var configs = {
  982. 'type1': {
  983. 'prop1': 'value1'
  984. }
  985. };
  986. controller.set('content.reassign.component_name', 'COMP1');
  987. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  988. });
  989. });
  990. describe('#cleanMySqlServer()', function () {
  991. beforeEach(function() {
  992. sinon.stub(App.HostComponent, 'find', function() {
  993. return Em.A([
  994. Em.Object.create({
  995. 'componentName': 'MYSQL_SERVER',
  996. 'hostName': 'host1'
  997. })
  998. ]);
  999. });
  1000. });
  1001. afterEach(function() {
  1002. App.HostComponent.find.restore();
  1003. });
  1004. it('component_name is C1', function () {
  1005. controller.set('content.reassign.component_name', 'C1');
  1006. controller.cleanMySqlServer();
  1007. expect(App.ajax.send.calledWith({
  1008. name: 'service.mysql.clean',
  1009. sender: controller,
  1010. data: {
  1011. host: 'host1'
  1012. },
  1013. success: 'startPolling',
  1014. error: 'onTaskError'
  1015. })).to.be.true;
  1016. });
  1017. it('component_name is MYSQL_SERVER', function () {
  1018. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1019. controller.set('content.reassignHosts.target', 'host2');
  1020. controller.cleanMySqlServer();
  1021. expect(App.ajax.send.calledWith({
  1022. name: 'service.mysql.clean',
  1023. sender: controller,
  1024. data: {
  1025. host: 'host2'
  1026. },
  1027. success: 'startPolling',
  1028. error: 'onTaskError'
  1029. })).to.be.true;
  1030. });
  1031. });
  1032. describe('#configureMySqlServer()', function () {
  1033. beforeEach(function() {
  1034. sinon.stub(App.HostComponent, 'find', function() {
  1035. return Em.A([
  1036. Em.Object.create({
  1037. 'componentName': 'MYSQL_SERVER',
  1038. 'hostName': 'host1'
  1039. })
  1040. ]);
  1041. });
  1042. });
  1043. afterEach(function() {
  1044. App.HostComponent.find.restore();
  1045. });
  1046. it('component_name is C1', function () {
  1047. controller.set('content.reassign.component_name', 'C1');
  1048. controller.configureMySqlServer();
  1049. expect(App.ajax.send.calledWith({
  1050. name: 'service.mysql.configure',
  1051. sender: controller,
  1052. data: {
  1053. host: 'host1'
  1054. },
  1055. success: 'startPolling',
  1056. error: 'onTaskError'
  1057. })).to.be.true;
  1058. });
  1059. it('component_name is MYSQL_SERVER', function () {
  1060. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1061. controller.set('content.reassignHosts.target', 'host2');
  1062. controller.configureMySqlServer();
  1063. expect(App.ajax.send.calledWith({
  1064. name: 'service.mysql.configure',
  1065. sender: controller,
  1066. data: {
  1067. host: 'host2'
  1068. },
  1069. success: 'startPolling',
  1070. error: 'onTaskError'
  1071. })).to.be.true;
  1072. });
  1073. });
  1074. describe("#startRequiredServices()", function() {
  1075. beforeEach(function () {
  1076. sinon.stub(controller, 'startServices', Em.K);
  1077. });
  1078. afterEach(function () {
  1079. controller.startServices.restore();
  1080. });
  1081. it("component has related services", function() {
  1082. controller.set('content.reassign.component_name', 'JOBTRACKER');
  1083. controller.startRequiredServices();
  1084. expect(controller.startServices.calledWith(false, ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'])).to.be.true;
  1085. });
  1086. it("component does not have related services", function() {
  1087. controller.set('content.reassign.component_name', 'C1');
  1088. controller.startRequiredServices();
  1089. expect(controller.startServices.calledWith(true)).to.be.true;
  1090. });
  1091. });
  1092. describe("#startMySqlServer()", function() {
  1093. beforeEach(function () {
  1094. sinon.stub(App.HostComponent, 'find').returns([
  1095. Em.Object.create({
  1096. componentName: 'MYSQL_SERVER',
  1097. hostName: 'host1'
  1098. })
  1099. ]);
  1100. });
  1101. afterEach(function () {
  1102. App.HostComponent.find.restore();
  1103. });
  1104. it("valid request is sent", function() {
  1105. controller.startMySqlServer();
  1106. expect(App.ajax.send.calledWith({
  1107. name: 'common.host.host_component.update',
  1108. sender: controller,
  1109. data: {
  1110. context: "Start MySQL Server",
  1111. hostName: 'host1',
  1112. serviceName: "HIVE",
  1113. componentName: "MYSQL_SERVER",
  1114. HostRoles: {
  1115. state: "STARTED"
  1116. }
  1117. },
  1118. success: 'startPolling',
  1119. error: 'onTaskError'
  1120. })).to.be.true;
  1121. });
  1122. });
  1123. describe("#restartMySqlServer()", function() {
  1124. beforeEach(function () {
  1125. sinon.stub(App.HostComponent, 'find').returns([
  1126. Em.Object.create({
  1127. componentName: 'MYSQL_SERVER',
  1128. hostName: 'host1'
  1129. })
  1130. ]);
  1131. });
  1132. afterEach(function () {
  1133. App.HostComponent.find.restore();
  1134. });
  1135. it("valid request is sent", function() {
  1136. controller.set('content', Em.Object.create({
  1137. cluster: Em.Object.create({
  1138. name: 'cl1'
  1139. })
  1140. }));
  1141. controller.restartMySqlServer();
  1142. expect(App.ajax.send.calledWith({
  1143. name: 'restart.hostComponents',
  1144. sender: controller,
  1145. data: {
  1146. context: 'Restart MySql Server',
  1147. resource_filters: [{
  1148. component_name: "MYSQL_SERVER",
  1149. hosts: 'host1',
  1150. service_name: "HIVE"
  1151. }],
  1152. operation_level: {
  1153. level: "HOST_COMPONENT",
  1154. cluster_name: 'cl1',
  1155. service_name: "HIVE",
  1156. hostcomponent_name: "MYSQL_SERVER"
  1157. }
  1158. },
  1159. success: 'startPolling',
  1160. error: 'onTaskError'
  1161. })).to.be.true;
  1162. });
  1163. });
  1164. describe("#startNewMySqlServer()", function() {
  1165. beforeEach(function () {
  1166. controller.set('content', Em.Object.create({
  1167. reassignHosts: Em.Object.create({
  1168. target: 'host1'
  1169. })
  1170. }));
  1171. controller.startNewMySqlServer();
  1172. });
  1173. it('valid request is sent', function() {
  1174. expect(App.ajax.send.calledWith({
  1175. name: 'common.host.host_component.update',
  1176. sender: controller,
  1177. data: {
  1178. context: "Start MySQL Server",
  1179. hostName: 'host1',
  1180. serviceName: "HIVE",
  1181. componentName: "MYSQL_SERVER",
  1182. HostRoles: {
  1183. state: "STARTED"
  1184. }
  1185. },
  1186. success: 'startPolling',
  1187. error: 'onTaskError'
  1188. })).to.be.true;
  1189. });
  1190. });
  1191. describe("#setDynamicConfigs HIVE", function() {
  1192. beforeEach(function () {
  1193. controller.set('content.masterComponentHosts', [
  1194. {component: 'HIVE_METASTORE', hostName: 'host1'},
  1195. {component: 'HIVE_METASTORE', hostName: 'host3'},
  1196. {component: 'HIVE_SERVER', hostName: 'host4'}
  1197. ]);
  1198. controller.set('content.reassignHosts.source', 'host1');
  1199. controller.set('content.reassignHosts.target', 'host2');
  1200. });
  1201. it("reassign component is HIVE_METASTORE", function() {
  1202. var configs = {
  1203. 'hive-env': {
  1204. 'hive_user': 'hive_user',
  1205. 'webhcat_user': 'webhcat_user'
  1206. },
  1207. 'hive-site': {
  1208. 'hive.metastore.uris': ''
  1209. },
  1210. 'webhcat-site': {
  1211. 'templeton.hive.properties': 'thrift'
  1212. },
  1213. 'core-site': {
  1214. 'hadoop.proxyuser.hive_user.hosts': '',
  1215. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1216. }
  1217. };
  1218. App.MoveHmConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1219. configs = controller.setDynamicConfigs(configs, App.MoveHmConfigInitializer);
  1220. expect(configs['hive-site']['hive.metastore.uris']).to.equal('thrift://host3:9083,thrift://host2:9083');
  1221. expect(configs['webhcat-site']['templeton.hive.properties']).to.equal('thrift');
  1222. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host2,host3,host4');
  1223. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host2,host3,host4');
  1224. });
  1225. it("reassign component is HIVE_SERVER", function() {
  1226. controller.get('content.masterComponentHosts').pushObject({component: 'HIVE_SERVER', hostName: 'host1'});
  1227. var configs = {
  1228. 'hive-env': {
  1229. 'hive_user': 'hive_user',
  1230. 'webhcat_user': 'webhcat_user'
  1231. },
  1232. 'hive-site': {
  1233. 'hive.metastore.uris': ''
  1234. },
  1235. 'webhcat-site': {
  1236. 'templeton.hive.properties': 'thrift'
  1237. },
  1238. 'core-site': {
  1239. 'hadoop.proxyuser.hive_user.hosts': '',
  1240. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1241. }
  1242. };
  1243. App.MoveHsConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1244. configs = controller.setDynamicConfigs(configs, App.MoveHsConfigInitializer);
  1245. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host1,host2,host3,host4');
  1246. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host1,host2,host3,host4');
  1247. });
  1248. });
  1249. describe('#setDynamicConfigs RESOURCEMANAGER', function () {
  1250. beforeEach(function () {
  1251. sinon.stub(App, 'get').withArgs('isRMHaEnabled').returns(true);
  1252. });
  1253. afterEach(function () {
  1254. App.get.restore();
  1255. App.MoveRmConfigInitializer.cleanup();
  1256. });
  1257. it('HA enabled and resource manager 1', function () {
  1258. controller.set('content.reassignHosts.source', 'host1');
  1259. controller.set('content.reassignHosts.target', 'host3');
  1260. var configs = {
  1261. 'yarn-site': {
  1262. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1263. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1264. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1265. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1266. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1267. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1268. }
  1269. };
  1270. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1271. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1272. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1273. expect(configs['yarn-site']).to.eql({
  1274. 'yarn.resourcemanager.hostname.rm1': 'host3',
  1275. 'yarn.resourcemanager.webapp.address.rm1': 'host3:8088',
  1276. 'yarn.resourcemanager.webapp.https.address.rm1': 'host3:8443',
  1277. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1278. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1279. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1280. });
  1281. });
  1282. it('HA enabled and resource manager 2', function () {
  1283. controller.set('content.reassignHosts.source', 'host2');
  1284. controller.set('content.reassignHosts.target', 'host3');
  1285. var configs = {
  1286. 'yarn-site': {
  1287. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1288. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1289. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1290. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1291. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1292. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1293. }
  1294. };
  1295. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1296. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1297. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1298. expect(configs['yarn-site']).to.eql({
  1299. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1300. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1301. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1302. 'yarn.resourcemanager.hostname.rm2': 'host3',
  1303. 'yarn.resourcemanager.webapp.address.rm2': 'host3:8088',
  1304. 'yarn.resourcemanager.webapp.https.address.rm2': 'host3:8443'
  1305. });
  1306. });
  1307. });
  1308. describe('#setDynamicConfigs NAMENODE', function () {
  1309. var isHaEnabled = false;
  1310. beforeEach(function () {
  1311. sinon.stub(App, 'get', function () {
  1312. return isHaEnabled;
  1313. });
  1314. sinon.stub(App.Service, 'find', function () {
  1315. return [
  1316. {serviceName: 'HDFS'},
  1317. {serviceName: 'ACCUMULO'},
  1318. {serviceName: 'HBASE'}
  1319. ];
  1320. });
  1321. controller.set('content.reassignHosts.source', 'host1');
  1322. });
  1323. afterEach(function () {
  1324. App.get.restore();
  1325. App.Service.find.restore();
  1326. App.MoveNameNodeConfigInitializer.cleanup();
  1327. });
  1328. it('HA isn\'t enabled and HBASE and ACCUMULO service', function () {
  1329. isHaEnabled = false;
  1330. var configs = {
  1331. 'hbase-site': {
  1332. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  1333. },
  1334. 'accumulo-site': {
  1335. 'instance.volumes': 'hdfs://localhost:8020/apps/accumulo/data',
  1336. 'instance.volumes.replacements': ''
  1337. }
  1338. };
  1339. controller.set('content.reassignHosts.target', 'host2');
  1340. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1341. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1342. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host2:8020/apps/hbase/data');
  1343. expect(configs['accumulo-site']['instance.volumes']).to.equal('hdfs://host2:8020/apps/accumulo/data');
  1344. expect(configs['accumulo-site']['instance.volumes.replacements']).to.equal('hdfs://host1:8020/apps/accumulo/data hdfs://host2:8020/apps/accumulo/data');
  1345. });
  1346. it('HA enabled and namenode 1', function () {
  1347. isHaEnabled = true;
  1348. var configs = {
  1349. 'hdfs-site': {
  1350. 'dfs.nameservices': 's',
  1351. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  1352. 'dfs.namenode.https-address.s.nn1': 'host1:50470',
  1353. 'dfs.namenode.rpc-address.s.nn1': 'host1:8020'
  1354. }
  1355. };
  1356. controller.set('content.reassignHosts.target', 'host2');
  1357. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1358. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1359. expect(configs['hdfs-site']).to.eql({
  1360. "dfs.nameservices": "s",
  1361. "dfs.namenode.http-address.s.nn1": "host2:50070",
  1362. "dfs.namenode.https-address.s.nn1": "host2:50470",
  1363. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  1364. });
  1365. });
  1366. it('HA enabled and namenode 2', function () {
  1367. isHaEnabled = true;
  1368. var configs = {
  1369. 'hdfs-site': {
  1370. 'dfs.nameservices': 's',
  1371. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1372. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  1373. 'dfs.namenode.https-address.s.nn2': 'host2:50470',
  1374. 'dfs.namenode.rpc-address.s.nn2': 'host2:8020'
  1375. }
  1376. };
  1377. controller.set('content.reassignHosts.source', 'host2');
  1378. controller.set('content.reassignHosts.target', 'host3');
  1379. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1380. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1381. expect(configs['hdfs-site']).to.eql({
  1382. "dfs.nameservices": "s",
  1383. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1384. "dfs.namenode.http-address.s.nn2": "host3:50070",
  1385. "dfs.namenode.https-address.s.nn2": "host3:50470",
  1386. "dfs.namenode.rpc-address.s.nn2": "host3:8020"
  1387. });
  1388. });
  1389. });
  1390. describe('#setDynamicConfigs OOZIE_SERVER', function () {
  1391. it('should upodate hadoop.proxyuser.${oozie_user}.hosts', function () {
  1392. var configs = {
  1393. 'oozie-env': {
  1394. 'oozie_user': 'cool_dude'
  1395. },
  1396. 'core-site': {
  1397. 'hadoop.proxyuser.cool_dude.hosts': ''
  1398. }
  1399. };
  1400. controller.set('content.masterComponentHosts', [
  1401. {component: 'OOZIE_SERVER', hostName: 'host2'},
  1402. {component: 'OOZIE_SERVER', hostName: 'host3'},
  1403. {component: 'OOZIE_SERVER', hostName: 'host1'}
  1404. ]);
  1405. controller.set('content.reassignHosts.source', 'host1');
  1406. controller.set('content.reassignHosts.target', 'host4');
  1407. App.MoveOSConfigInitializer.setup(controller._getOsInitializerSettings(configs));
  1408. configs = controller.setDynamicConfigs(configs, App.MoveOSConfigInitializer);
  1409. App.MoveOSConfigInitializer.cleanup();
  1410. expect(configs['core-site']['hadoop.proxyuser.cool_dude.hosts']).to.equal('host2,host3,host4');
  1411. });
  1412. });
  1413. describe.skip("#prepareDBCheckAction()", function() {
  1414. beforeEach(function () {
  1415. sinon.stub(App.router, 'get').returns({
  1416. 'jdk_location': 'jdk_location',
  1417. 'jdk.name': 'jdk.name',
  1418. 'java.home': 'java.home'
  1419. });
  1420. sinon.stub(controller, 'getConnectionProperty').returns('prop1');
  1421. controller.set('content.reassignHosts', Em.Object.create({target: 'host1'}));
  1422. controller.reopen({
  1423. dbType: 'type1',
  1424. requiredProperties: [],
  1425. preparedDBProperties: {}
  1426. });
  1427. controller.prepareDBCheckAction();
  1428. });
  1429. afterEach(function () {
  1430. App.router.get.restore();
  1431. controller.getConnectionProperty.restore();
  1432. });
  1433. it('valid request is sent', function () {
  1434. var callArgs = App.ajax.send.getCall(0).args[0];
  1435. expect(callArgs.name).to.equal('cluster.custom_action.create');
  1436. expect(callArgs.success).to.equal('onCreateActionSuccess');
  1437. expect(callArgs.error).to.equal('onTaskError');
  1438. expect(callArgs.data).to.eql({
  1439. requestInfo: {
  1440. "context": "Check host",
  1441. "action": "check_host",
  1442. "parameters": {
  1443. "db_name": "type1",
  1444. "jdk_location": "jdk_location",
  1445. "jdk_name": "jdk.name",
  1446. "java_home": "java.home",
  1447. "threshold": 60,
  1448. "ambari_server_host": "",
  1449. "check_execute_list": "db_connection_check"
  1450. }
  1451. },
  1452. filteredHosts: ['host1']
  1453. });
  1454. });
  1455. });
  1456. });