step4_controller_test.js 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623
  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. var data = {
  539. Clusters: {
  540. desired_configs: {
  541. 'hdfs-site': {tag: 1},
  542. 'core-site': {tag: 2},
  543. 'hbase-site': {tag: 3},
  544. 'mapred-site': {tag: 4},
  545. 'yarn-site': {tag: 5},
  546. 'oozie-site': {tag: 6},
  547. 'oozie-env': {tag: 2},
  548. 'webhcat-site': {tag: 7},
  549. 'yarn-env': {tag: 8},
  550. 'accumulo-site': {tag: 9},
  551. 'hive-site': {tag: 10},
  552. 'hive-env': {tag: 11}
  553. }
  554. }
  555. };
  556. var services = [];
  557. beforeEach(function () {
  558. sinon.stub(App.Service, 'find', function () {
  559. return services;
  560. });
  561. });
  562. afterEach(function () {
  563. App.Service.find.restore();
  564. });
  565. testCases.forEach(function (test) {
  566. it('get config of ' + test.componentName, function () {
  567. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  568. });
  569. });
  570. it('get config of NAMENODE when HBASE installed', function () {
  571. services = [
  572. {
  573. serviceName: 'HBASE'
  574. }
  575. ];
  576. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  577. "(type=hdfs-site&tag=1)",
  578. "(type=core-site&tag=2)",
  579. "(type=hbase-site&tag=3)"
  580. ]);
  581. });
  582. it('get config of NAMENODE when ACCUMULO installed', function () {
  583. services = [
  584. {
  585. serviceName: 'ACCUMULO'
  586. }
  587. ];
  588. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  589. "(type=hdfs-site&tag=1)",
  590. "(type=core-site&tag=2)",
  591. "(type=accumulo-site&tag=9)"
  592. ]);
  593. });
  594. });
  595. describe('#onLoadConfigsTags()', function () {
  596. beforeEach(function () {
  597. sinon.stub(controller, 'getConfigUrlParams', function () {
  598. return [];
  599. });
  600. controller.set('content.reassign.component_name', 'COMP1');
  601. controller.onLoadConfigsTags({});
  602. });
  603. afterEach(function () {
  604. controller.getConfigUrlParams.restore();
  605. });
  606. it('request is sent', function () {
  607. expect(App.ajax.send.calledOnce).to.be.true;
  608. });
  609. it('getConfigUrlParams is called with correct data', function () {
  610. expect(controller.getConfigUrlParams.calledWith('COMP1', {})).to.be.true;
  611. });
  612. });
  613. describe('#loadStep()', function () {
  614. var isHaEnabled = true;
  615. beforeEach(function () {
  616. controller.set('content.reassign.service_id', 'service1');
  617. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  618. sinon.stub(controller, 'initializeTasks', Em.K);
  619. sinon.stub(App, 'get', function () {
  620. return isHaEnabled;
  621. });
  622. });
  623. afterEach(function () {
  624. controller.onTaskStatusChange.restore();
  625. controller.initializeTasks.restore();
  626. App.get.restore();
  627. });
  628. it('reassign component is NameNode and HA enabled', function () {
  629. isHaEnabled = true;
  630. controller.set('content.reassign.component_name', 'NAMENODE');
  631. controller.loadStep();
  632. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  633. expect(controller.get('serviceName')).to.eql(['service1']);
  634. });
  635. it('reassign component is NameNode and HA disabled', function () {
  636. isHaEnabled = false;
  637. controller.set('content.reassign.component_name', 'NAMENODE');
  638. controller.loadStep();
  639. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  640. expect(controller.get('serviceName')).to.eql(['service1']);
  641. });
  642. it('reassign component is JOBTRACKER and HA enabled', function () {
  643. isHaEnabled = true;
  644. controller.set('content.reassign.component_name', 'JOBTRACKER');
  645. controller.loadStep();
  646. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  647. expect(controller.get('serviceName')).to.eql(['service1']);
  648. });
  649. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  650. isHaEnabled = true;
  651. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  652. controller.loadStep();
  653. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  654. expect(controller.get('serviceName')).to.eql(['service1']);
  655. });
  656. });
  657. describe('#saveConfigsToServer()', function () {
  658. beforeEach(function () {
  659. sinon.stub(controller, 'getServiceConfigData', Em.K);
  660. controller.saveConfigsToServer([1]);
  661. });
  662. afterEach(function () {
  663. controller.getServiceConfigData.restore();
  664. });
  665. it('getServiceConfigData is called with valid data', function () {
  666. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  667. });
  668. it('request is sent', function () {
  669. expect(App.ajax.send.calledOnce).to.be.true;
  670. });
  671. });
  672. describe('#setSecureConfigs()', function () {
  673. beforeEach(function () {
  674. this.stub = sinon.stub(App, 'get');
  675. });
  676. afterEach(function () {
  677. Em.tryInvoke(App.get, 'restore');
  678. });
  679. it('undefined component and security disabled', function () {
  680. var secureConfigs = [];
  681. this.stub.withArgs('isKerberosEnabled').returns(false);
  682. controller.set('secureConfigsMap', []);
  683. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  684. expect(secureConfigs).to.eql([]);
  685. });
  686. it('component exist and security disabled', function () {
  687. var secureConfigs = [];
  688. this.stub.withArgs('isKerberosEnabled').returns(false);
  689. controller.set('secureConfigsMap', [{
  690. componentName: 'COMP1'
  691. }]);
  692. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  693. expect(secureConfigs).to.eql([]);
  694. });
  695. it('undefined component and security enabled', function () {
  696. var secureConfigs = [];
  697. this.stub.withArgs('isKerberosEnabled').returns(true);
  698. controller.set('secureConfigsMap', []);
  699. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  700. expect(secureConfigs).to.eql([]);
  701. });
  702. it('component exist and security enabled', function () {
  703. var secureConfigs = [];
  704. this.stub.withArgs('isKerberosEnabled').returns(true);
  705. var configs = {'s1': {
  706. 'k1': 'kValue',
  707. 'p1': 'pValue'
  708. }};
  709. controller.set('secureConfigsMap', [{
  710. componentName: 'COMP1',
  711. configs: [{
  712. site: 's1',
  713. keytab: 'k1',
  714. principal: 'p1'
  715. }]
  716. }]);
  717. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  718. expect(secureConfigs).to.eql([
  719. {
  720. "keytab": "kValue",
  721. "principal": "pValue"
  722. }
  723. ]);
  724. });
  725. });
  726. describe('#getComponentDir()', function () {
  727. var configs = {
  728. 'hdfs-site': {
  729. 'dfs.name.dir': 'case1',
  730. 'dfs.namenode.name.dir': 'case2',
  731. 'dfs.namenode.checkpoint.dir': 'case3'
  732. },
  733. 'core-site': {
  734. 'fs.checkpoint.dir': 'case4'
  735. }
  736. };
  737. it('unknown component name', function () {
  738. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  739. });
  740. it('NAMENODE component', function () {
  741. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  742. });
  743. it('SECONDARY_NAMENODE component', function () {
  744. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  745. });
  746. });
  747. describe('#saveClusterStatus()', function () {
  748. var mock = {
  749. saveComponentDir: Em.K,
  750. saveSecureConfigs: Em.K
  751. };
  752. beforeEach(function () {
  753. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  754. sinon.stub(App.router, 'get', function() {
  755. return mock;
  756. });
  757. sinon.spy(mock, 'saveComponentDir');
  758. sinon.spy(mock, 'saveSecureConfigs');
  759. });
  760. afterEach(function () {
  761. App.clusterStatus.setClusterStatus.restore();
  762. App.router.get.restore();
  763. mock.saveSecureConfigs.restore();
  764. mock.saveComponentDir.restore();
  765. });
  766. it('componentDir undefined and secureConfigs is empty', function () {
  767. expect(controller.saveClusterStatus([], null)).to.be.false;
  768. });
  769. it('componentDir defined and secureConfigs is empty', function () {
  770. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  771. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  772. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  773. });
  774. it('componentDir undefined and secureConfigs has data', function () {
  775. expect(controller.saveClusterStatus([1], null)).to.be.true;
  776. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  777. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  778. });
  779. it('componentDir defined and secureConfigs has data', function () {
  780. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  781. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  782. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  783. });
  784. });
  785. describe('#onSaveConfigs()', function () {
  786. beforeEach(function () {
  787. sinon.stub(controller, 'onTaskCompleted', Em.K);
  788. });
  789. afterEach(function () {
  790. controller.onTaskCompleted.restore();
  791. });
  792. it('onTaskCompleted called once', function () {
  793. controller.onSaveConfigs();
  794. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  795. });
  796. });
  797. describe('#startZooKeeperServers()', function () {
  798. beforeEach(function () {
  799. sinon.stub(controller, 'updateComponent', Em.K);
  800. });
  801. afterEach(function () {
  802. controller.updateComponent.restore();
  803. });
  804. it('updateComponent called with valid arguments', function () {
  805. controller.set('content.masterComponentHosts', [{
  806. component: 'ZOOKEEPER_SERVER',
  807. hostName: 'host1'
  808. }]);
  809. controller.startZooKeeperServers();
  810. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  811. });
  812. });
  813. describe('#startNameNode()', function () {
  814. beforeEach(function () {
  815. sinon.stub(controller, 'updateComponent', Em.K);
  816. controller.set('content.masterComponentHosts', [{
  817. component: 'NAMENODE',
  818. hostName: 'host1'
  819. }]);
  820. });
  821. afterEach(function () {
  822. controller.updateComponent.restore();
  823. });
  824. it('reassign host does not match current', function () {
  825. controller.set('content.reassignHosts.source', 'host2');
  826. controller.startNameNode();
  827. expect(controller.updateComponent.calledWith('NAMENODE', ['host1'], 'HDFS', 'Start')).to.be.true;
  828. });
  829. it('reassign host matches current', function () {
  830. controller.set('content.reassignHosts.source', 'host1');
  831. controller.startNameNode();
  832. expect(controller.updateComponent.calledWith('NAMENODE', [], 'HDFS', 'Start')).to.be.true;
  833. });
  834. });
  835. describe('#startServices()', function () {
  836. beforeEach(function () {
  837. sinon.stub(App.router, 'get').returns({"skip.service.checks": "false"});
  838. controller.startServices();
  839. });
  840. afterEach(function () {
  841. App.router.get.restore();
  842. });
  843. it('request is sent', function () {
  844. expect(App.ajax.send.calledOnce).to.be.true;
  845. });
  846. });
  847. describe('#deleteHostComponents()', function () {
  848. it('No host components', function () {
  849. controller.set('hostComponents', []);
  850. controller.set('content.reassignHosts.source', 'host1');
  851. controller.deleteHostComponents();
  852. expect(App.ajax.send.called).to.be.false;
  853. });
  854. it('delete two components', function () {
  855. controller.set('hostComponents', [1, 2]);
  856. controller.set('content.reassignHosts.source', 'host1');
  857. controller.deleteHostComponents();
  858. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  859. "hostName": "host1",
  860. "componentName": 1
  861. });
  862. expect(App.ajax.send.getCall(1).args[0].data).to.eql({
  863. "hostName": "host1",
  864. "componentName": 2
  865. });
  866. });
  867. });
  868. describe('#onDeleteHostComponentsError()', function () {
  869. beforeEach(function () {
  870. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  871. sinon.stub(controller, 'onTaskError', Em.K);
  872. });
  873. afterEach(function () {
  874. controller.onComponentsTasksSuccess.restore();
  875. controller.onTaskError.restore();
  876. });
  877. it('task success', function () {
  878. var error = {
  879. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  880. };
  881. controller.onDeleteHostComponentsError(error);
  882. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  883. });
  884. it('unknown error', function () {
  885. var error = {
  886. responseText: ''
  887. };
  888. controller.onDeleteHostComponentsError(error);
  889. expect(controller.onTaskError.calledOnce).to.be.true;
  890. });
  891. });
  892. describe('#done()', function () {
  893. beforeEach(function () {
  894. sinon.stub(controller, 'removeObserver', Em.K);
  895. sinon.stub(App.router, 'send', Em.K);
  896. });
  897. afterEach(function () {
  898. controller.removeObserver.restore();
  899. App.router.send.restore();
  900. });
  901. it('submit disabled', function () {
  902. controller.set('isSubmitDisabled', true);
  903. controller.done();
  904. expect(App.router.send.called).to.be.false;
  905. });
  906. it('submit enabled and does not have manual steps', function () {
  907. controller.set('isSubmitDisabled', false);
  908. controller.set('content.hasManualSteps', false);
  909. controller.done();
  910. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  911. expect(App.router.send.calledWith('complete')).to.be.true;
  912. });
  913. it('submit enabled and has manual steps', function () {
  914. controller.set('isSubmitDisabled', false);
  915. controller.set('content.hasManualSteps', true);
  916. controller.done();
  917. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  918. expect(App.router.send.calledWith('next')).to.be.true;
  919. });
  920. });
  921. describe('#getServiceConfigData()', function () {
  922. var services = [];
  923. var stackServices = [];
  924. beforeEach(function () {
  925. sinon.stub(App.Service, 'find', function () {
  926. return services;
  927. });
  928. sinon.stub(App.StackService, 'find', function () {
  929. return stackServices;
  930. });
  931. });
  932. afterEach(function () {
  933. App.Service.find.restore();
  934. App.StackService.find.restore();
  935. });
  936. it('No services', function () {
  937. services = [];
  938. controller.set('content.reassign.component_name', 'COMP1');
  939. expect(controller.getServiceConfigData([])).to.eql([]);
  940. });
  941. it('No services in stackServices', function () {
  942. services = [Em.Object.create({serviceName: 'S1'})];
  943. stackServices = [];
  944. controller.set('content.reassign.component_name', 'COMP1');
  945. expect(controller.getServiceConfigData([])).to.eql([]);
  946. });
  947. it('Services in stackServices, but configTypesRendered is empty', function () {
  948. services = [Em.Object.create({serviceName: 'S1'})];
  949. stackServices = [Em.Object.create({
  950. serviceName: 'S1',
  951. configTypesRendered: {}
  952. })];
  953. controller.set('content.reassign.component_name', 'COMP1');
  954. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  955. });
  956. it('Services in stackServices, and configTypesRendered has data, but configs is empty', function () {
  957. services = [Em.Object.create({serviceName: 'S1'})];
  958. stackServices = [
  959. Em.Object.create({
  960. serviceName: 'S1',
  961. configTypesRendered: {'type1': {}}
  962. })
  963. ];
  964. controller.set('content.reassign.component_name', 'COMP1');
  965. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  966. });
  967. it('Services in stackServices, and configTypesRendered has data, and configs present', function () {
  968. services = [Em.Object.create({serviceName: 'S1'})];
  969. stackServices = [
  970. Em.Object.create({
  971. serviceName: 'S1',
  972. configTypesRendered: {'type1': {}}
  973. })
  974. ];
  975. var configs = {
  976. 'type1': {
  977. 'prop1': 'value1'
  978. }
  979. };
  980. controller.set('content.reassign.component_name', 'COMP1');
  981. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  982. });
  983. });
  984. describe('#cleanMySqlServer()', function () {
  985. beforeEach(function() {
  986. sinon.stub(App.HostComponent, 'find', function() {
  987. return Em.A([
  988. Em.Object.create({
  989. 'componentName': 'MYSQL_SERVER',
  990. 'hostName': 'host1'
  991. })
  992. ]);
  993. });
  994. });
  995. afterEach(function() {
  996. App.HostComponent.find.restore();
  997. });
  998. it('component_name is C1', function () {
  999. controller.set('content.reassign.component_name', 'C1');
  1000. controller.cleanMySqlServer();
  1001. expect(App.ajax.send.calledWith({
  1002. name: 'service.mysql.clean',
  1003. sender: controller,
  1004. data: {
  1005. host: 'host1'
  1006. },
  1007. success: 'startPolling',
  1008. error: 'onTaskError'
  1009. })).to.be.true;
  1010. });
  1011. it('component_name is MYSQL_SERVER', function () {
  1012. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1013. controller.set('content.reassignHosts.target', 'host2');
  1014. controller.cleanMySqlServer();
  1015. expect(App.ajax.send.calledWith({
  1016. name: 'service.mysql.clean',
  1017. sender: controller,
  1018. data: {
  1019. host: 'host2'
  1020. },
  1021. success: 'startPolling',
  1022. error: 'onTaskError'
  1023. })).to.be.true;
  1024. });
  1025. });
  1026. describe('#configureMySqlServer()', function () {
  1027. beforeEach(function() {
  1028. sinon.stub(App.HostComponent, 'find', function() {
  1029. return Em.A([
  1030. Em.Object.create({
  1031. 'componentName': 'MYSQL_SERVER',
  1032. 'hostName': 'host1'
  1033. })
  1034. ]);
  1035. });
  1036. });
  1037. afterEach(function() {
  1038. App.HostComponent.find.restore();
  1039. });
  1040. it('component_name is C1', function () {
  1041. controller.set('content.reassign.component_name', 'C1');
  1042. controller.configureMySqlServer();
  1043. expect(App.ajax.send.calledWith({
  1044. name: 'service.mysql.configure',
  1045. sender: controller,
  1046. data: {
  1047. host: 'host1'
  1048. },
  1049. success: 'startPolling',
  1050. error: 'onTaskError'
  1051. })).to.be.true;
  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. expect(App.ajax.send.calledWith({
  1058. name: 'service.mysql.configure',
  1059. sender: controller,
  1060. data: {
  1061. host: 'host2'
  1062. },
  1063. success: 'startPolling',
  1064. error: 'onTaskError'
  1065. })).to.be.true;
  1066. });
  1067. });
  1068. describe("#startRequiredServices()", function() {
  1069. beforeEach(function () {
  1070. sinon.stub(controller, 'startServices', Em.K);
  1071. });
  1072. afterEach(function () {
  1073. controller.startServices.restore();
  1074. });
  1075. it("component has related services", function() {
  1076. controller.set('content.reassign.component_name', 'JOBTRACKER');
  1077. controller.startRequiredServices();
  1078. expect(controller.startServices.calledWith(false, ['HDFS', 'ZOOKEEPER', 'HBASE', 'FLUME', 'SQOOP', 'STORM'])).to.be.true;
  1079. });
  1080. it("component does not have related services", function() {
  1081. controller.set('content.reassign.component_name', 'C1');
  1082. controller.startRequiredServices();
  1083. expect(controller.startServices.calledWith(true)).to.be.true;
  1084. });
  1085. });
  1086. describe("#startMySqlServer()", function() {
  1087. beforeEach(function () {
  1088. sinon.stub(App.HostComponent, 'find').returns([
  1089. Em.Object.create({
  1090. componentName: 'MYSQL_SERVER',
  1091. hostName: 'host1'
  1092. })
  1093. ]);
  1094. });
  1095. afterEach(function () {
  1096. App.HostComponent.find.restore();
  1097. });
  1098. it("valid request is sent", function() {
  1099. controller.startMySqlServer();
  1100. expect(App.ajax.send.calledWith({
  1101. name: 'common.host.host_component.update',
  1102. sender: controller,
  1103. data: {
  1104. context: "Start MySQL Server",
  1105. hostName: 'host1',
  1106. serviceName: "HIVE",
  1107. componentName: "MYSQL_SERVER",
  1108. HostRoles: {
  1109. state: "STARTED"
  1110. }
  1111. },
  1112. success: 'startPolling',
  1113. error: 'onTaskError'
  1114. })).to.be.true;
  1115. });
  1116. });
  1117. describe("#restartMySqlServer()", function() {
  1118. beforeEach(function () {
  1119. sinon.stub(App.HostComponent, 'find').returns([
  1120. Em.Object.create({
  1121. componentName: 'MYSQL_SERVER',
  1122. hostName: 'host1'
  1123. })
  1124. ]);
  1125. });
  1126. afterEach(function () {
  1127. App.HostComponent.find.restore();
  1128. });
  1129. it("valid request is sent", function() {
  1130. controller.set('content', Em.Object.create({
  1131. cluster: Em.Object.create({
  1132. name: 'cl1'
  1133. })
  1134. }));
  1135. controller.restartMySqlServer();
  1136. expect(App.ajax.send.calledWith({
  1137. name: 'restart.hostComponents',
  1138. sender: controller,
  1139. data: {
  1140. context: 'Restart MySql Server',
  1141. resource_filters: [{
  1142. component_name: "MYSQL_SERVER",
  1143. hosts: 'host1',
  1144. service_name: "HIVE"
  1145. }],
  1146. operation_level: {
  1147. level: "HOST_COMPONENT",
  1148. cluster_name: 'cl1',
  1149. service_name: "HIVE",
  1150. hostcomponent_name: "MYSQL_SERVER"
  1151. }
  1152. },
  1153. success: 'startPolling',
  1154. error: 'onTaskError'
  1155. })).to.be.true;
  1156. });
  1157. });
  1158. describe("#startNewMySqlServer()", function() {
  1159. beforeEach(function () {
  1160. controller.set('content', Em.Object.create({
  1161. reassignHosts: Em.Object.create({
  1162. target: 'host1'
  1163. })
  1164. }));
  1165. controller.startNewMySqlServer();
  1166. });
  1167. it('valid request is sent', function() {
  1168. expect(App.ajax.send.calledWith({
  1169. name: 'common.host.host_component.update',
  1170. sender: controller,
  1171. data: {
  1172. context: "Start MySQL Server",
  1173. hostName: 'host1',
  1174. serviceName: "HIVE",
  1175. componentName: "MYSQL_SERVER",
  1176. HostRoles: {
  1177. state: "STARTED"
  1178. }
  1179. },
  1180. success: 'startPolling',
  1181. error: 'onTaskError'
  1182. })).to.be.true;
  1183. });
  1184. });
  1185. describe("#setDynamicConfigs HIVE", function() {
  1186. beforeEach(function () {
  1187. controller.set('content.masterComponentHosts', [
  1188. {component: 'HIVE_METASTORE', hostName: 'host1'},
  1189. {component: 'HIVE_METASTORE', hostName: 'host3'},
  1190. {component: 'HIVE_SERVER', hostName: 'host4'}
  1191. ]);
  1192. controller.set('content.reassignHosts.source', 'host1');
  1193. controller.set('content.reassignHosts.target', 'host2');
  1194. });
  1195. it("reassign component is HIVE_METASTORE", function() {
  1196. var configs = {
  1197. 'hive-env': {
  1198. 'hive_user': 'hive_user',
  1199. 'webhcat_user': 'webhcat_user'
  1200. },
  1201. 'hive-site': {
  1202. 'hive.metastore.uris': ''
  1203. },
  1204. 'webhcat-site': {
  1205. 'templeton.hive.properties': 'thrift'
  1206. },
  1207. 'core-site': {
  1208. 'hadoop.proxyuser.hive_user.hosts': '',
  1209. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1210. }
  1211. };
  1212. App.MoveHmConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1213. configs = controller.setDynamicConfigs(configs, App.MoveHmConfigInitializer);
  1214. expect(configs['hive-site']['hive.metastore.uris']).to.equal('thrift://host3:9083,thrift://host2:9083');
  1215. expect(configs['webhcat-site']['templeton.hive.properties']).to.equal('thrift');
  1216. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host2,host3,host4');
  1217. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host2,host3,host4');
  1218. });
  1219. it("reassign component is HIVE_SERVER", function() {
  1220. controller.get('content.masterComponentHosts').pushObject({component: 'HIVE_SERVER', hostName: 'host1'});
  1221. var configs = {
  1222. 'hive-env': {
  1223. 'hive_user': 'hive_user',
  1224. 'webhcat_user': 'webhcat_user'
  1225. },
  1226. 'hive-site': {
  1227. 'hive.metastore.uris': ''
  1228. },
  1229. 'webhcat-site': {
  1230. 'templeton.hive.properties': 'thrift'
  1231. },
  1232. 'core-site': {
  1233. 'hadoop.proxyuser.hive_user.hosts': '',
  1234. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1235. }
  1236. };
  1237. App.MoveHsConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1238. configs = controller.setDynamicConfigs(configs, App.MoveHsConfigInitializer);
  1239. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host1,host2,host3,host4');
  1240. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host1,host2,host3,host4');
  1241. });
  1242. });
  1243. describe('#setDynamicConfigs RESOURCEMANAGER', function () {
  1244. beforeEach(function () {
  1245. sinon.stub(App, 'get').withArgs('isRMHaEnabled').returns(true);
  1246. });
  1247. afterEach(function () {
  1248. App.get.restore();
  1249. App.MoveRmConfigInitializer.cleanup();
  1250. });
  1251. it('HA enabled and resource manager 1', function () {
  1252. controller.set('content.reassignHosts.source', 'host1');
  1253. controller.set('content.reassignHosts.target', 'host3');
  1254. var configs = {
  1255. 'yarn-site': {
  1256. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1257. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1258. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1259. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1260. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1261. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1262. }
  1263. };
  1264. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1265. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1266. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1267. expect(configs['yarn-site']).to.eql({
  1268. 'yarn.resourcemanager.hostname.rm1': 'host3',
  1269. 'yarn.resourcemanager.webapp.address.rm1': 'host3:8088',
  1270. 'yarn.resourcemanager.webapp.https.address.rm1': 'host3:8443',
  1271. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1272. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1273. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1274. });
  1275. });
  1276. it('HA enabled and resource manager 2', function () {
  1277. controller.set('content.reassignHosts.source', 'host2');
  1278. controller.set('content.reassignHosts.target', 'host3');
  1279. var configs = {
  1280. 'yarn-site': {
  1281. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1282. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1283. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1284. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1285. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1286. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1287. }
  1288. };
  1289. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1290. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1291. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1292. expect(configs['yarn-site']).to.eql({
  1293. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1294. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1295. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1296. 'yarn.resourcemanager.hostname.rm2': 'host3',
  1297. 'yarn.resourcemanager.webapp.address.rm2': 'host3:8088',
  1298. 'yarn.resourcemanager.webapp.https.address.rm2': 'host3:8443'
  1299. });
  1300. });
  1301. });
  1302. describe('#setDynamicConfigs NAMENODE', function () {
  1303. var isHaEnabled = false;
  1304. beforeEach(function () {
  1305. sinon.stub(App, 'get', function () {
  1306. return isHaEnabled;
  1307. });
  1308. sinon.stub(App.Service, 'find', function () {
  1309. return [
  1310. {serviceName: 'HDFS'},
  1311. {serviceName: 'ACCUMULO'},
  1312. {serviceName: 'HBASE'}
  1313. ];
  1314. });
  1315. controller.set('content.reassignHosts.source', 'host1');
  1316. });
  1317. afterEach(function () {
  1318. App.get.restore();
  1319. App.Service.find.restore();
  1320. App.MoveNameNodeConfigInitializer.cleanup();
  1321. });
  1322. it('HA isn\'t enabled and HBASE and ACCUMULO service', function () {
  1323. isHaEnabled = false;
  1324. var configs = {
  1325. 'hbase-site': {
  1326. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  1327. },
  1328. 'accumulo-site': {
  1329. 'instance.volumes': 'hdfs://localhost:8020/apps/accumulo/data',
  1330. 'instance.volumes.replacements': ''
  1331. }
  1332. };
  1333. controller.set('content.reassignHosts.target', 'host2');
  1334. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1335. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1336. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host2:8020/apps/hbase/data');
  1337. expect(configs['accumulo-site']['instance.volumes']).to.equal('hdfs://host2:8020/apps/accumulo/data');
  1338. expect(configs['accumulo-site']['instance.volumes.replacements']).to.equal('hdfs://host1:8020/apps/accumulo/data hdfs://host2:8020/apps/accumulo/data');
  1339. });
  1340. it('HA enabled and namenode 1', function () {
  1341. isHaEnabled = true;
  1342. var configs = {
  1343. 'hdfs-site': {
  1344. 'dfs.nameservices': 's',
  1345. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  1346. 'dfs.namenode.https-address.s.nn1': 'host1:50470',
  1347. 'dfs.namenode.rpc-address.s.nn1': 'host1:8020'
  1348. }
  1349. };
  1350. controller.set('content.reassignHosts.target', 'host2');
  1351. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1352. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1353. expect(configs['hdfs-site']).to.eql({
  1354. "dfs.nameservices": "s",
  1355. "dfs.namenode.http-address.s.nn1": "host2:50070",
  1356. "dfs.namenode.https-address.s.nn1": "host2:50470",
  1357. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  1358. });
  1359. });
  1360. it('HA enabled and namenode 2', function () {
  1361. isHaEnabled = true;
  1362. var configs = {
  1363. 'hdfs-site': {
  1364. 'dfs.nameservices': 's',
  1365. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1366. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  1367. 'dfs.namenode.https-address.s.nn2': 'host2:50470',
  1368. 'dfs.namenode.rpc-address.s.nn2': 'host2:8020'
  1369. }
  1370. };
  1371. controller.set('content.reassignHosts.source', 'host2');
  1372. controller.set('content.reassignHosts.target', 'host3');
  1373. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1374. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1375. expect(configs['hdfs-site']).to.eql({
  1376. "dfs.nameservices": "s",
  1377. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1378. "dfs.namenode.http-address.s.nn2": "host3:50070",
  1379. "dfs.namenode.https-address.s.nn2": "host3:50470",
  1380. "dfs.namenode.rpc-address.s.nn2": "host3:8020"
  1381. });
  1382. });
  1383. });
  1384. describe('#setDynamicConfigs OOZIE_SERVER', function () {
  1385. it('should upodate hadoop.proxyuser.${oozie_user}.hosts', function () {
  1386. var configs = {
  1387. 'oozie-env': {
  1388. 'oozie_user': 'cool_dude'
  1389. },
  1390. 'core-site': {
  1391. 'hadoop.proxyuser.cool_dude.hosts': ''
  1392. }
  1393. };
  1394. controller.set('content.masterComponentHosts', [
  1395. {component: 'OOZIE_SERVER', hostName: 'host2'},
  1396. {component: 'OOZIE_SERVER', hostName: 'host3'},
  1397. {component: 'OOZIE_SERVER', hostName: 'host1'}
  1398. ]);
  1399. controller.set('content.reassignHosts.source', 'host1');
  1400. controller.set('content.reassignHosts.target', 'host4');
  1401. App.MoveOSConfigInitializer.setup(controller._getOsInitializerSettings(configs));
  1402. configs = controller.setDynamicConfigs(configs, App.MoveOSConfigInitializer);
  1403. App.MoveOSConfigInitializer.cleanup();
  1404. expect(configs['core-site']['hadoop.proxyuser.cool_dude.hosts']).to.equal('host2,host3,host4');
  1405. });
  1406. });
  1407. describe.skip("#prepareDBCheckAction()", function() {
  1408. beforeEach(function () {
  1409. sinon.stub(App.router, 'get').returns({
  1410. 'jdk_location': 'jdk_location',
  1411. 'jdk.name': 'jdk.name',
  1412. 'java.home': 'java.home'
  1413. });
  1414. sinon.stub(controller, 'getConnectionProperty').returns('prop1');
  1415. controller.set('content.reassignHosts', Em.Object.create({target: 'host1'}));
  1416. controller.reopen({
  1417. dbType: 'type1',
  1418. requiredProperties: [],
  1419. preparedDBProperties: {}
  1420. });
  1421. controller.prepareDBCheckAction();
  1422. });
  1423. afterEach(function () {
  1424. App.router.get.restore();
  1425. controller.getConnectionProperty.restore();
  1426. });
  1427. it('valid request is sent', function () {
  1428. var callArgs = App.ajax.send.getCall(0).args[0];
  1429. expect(callArgs.name).to.equal('cluster.custom_action.create');
  1430. expect(callArgs.success).to.equal('onCreateActionSuccess');
  1431. expect(callArgs.error).to.equal('onTaskError');
  1432. expect(callArgs.data).to.eql({
  1433. requestInfo: {
  1434. "context": "Check host",
  1435. "action": "check_host",
  1436. "parameters": {
  1437. "db_name": "type1",
  1438. "jdk_location": "jdk_location",
  1439. "jdk_name": "jdk.name",
  1440. "java_home": "java.home",
  1441. "threshold": 60,
  1442. "ambari_server_host": "",
  1443. "check_execute_list": "db_connection_check"
  1444. }
  1445. },
  1446. filteredHosts: ['host1']
  1447. });
  1448. });
  1449. });
  1450. });