step4_controller_test.js 55 KB

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