step4_controller_test.js 54 KB

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