step4_controller_test.js 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  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. 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. var isHadoop2Stack = false;
  35. beforeEach(function () {
  36. sinon.stub(App, 'get', function () {
  37. return isHadoop2Stack;
  38. });
  39. });
  40. afterEach(function () {
  41. App.get.restore();
  42. });
  43. it('Component is absent', function () {
  44. controller.set('additionalConfigsMap', []);
  45. var configs = {};
  46. expect(controller.setAdditionalConfigs(configs, 'COMP1', '')).to.be.false;
  47. expect(configs).to.eql({});
  48. });
  49. it('Component is present', function () {
  50. controller.set('additionalConfigsMap', [
  51. {
  52. componentName: 'COMP1',
  53. configs: {
  54. 'test-site': {
  55. 'property1': '<replace-value>:1111'
  56. }
  57. }
  58. }
  59. ]);
  60. var configs = {
  61. 'test-site': {}
  62. };
  63. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  64. expect(configs).to.eql({
  65. 'test-site': {
  66. 'property1': 'host1:1111'
  67. }
  68. });
  69. });
  70. it('configs_Hadoop2 is present but isHadoop2Stack = false', function () {
  71. isHadoop2Stack = false;
  72. controller.set('additionalConfigsMap', [
  73. {
  74. componentName: 'COMP1',
  75. configs: {
  76. 'test-site': {
  77. 'property1': '<replace-value>:1111'
  78. }
  79. },
  80. configs_Hadoop2: {
  81. 'test-site': {
  82. 'property2': '<replace-value>:2222'
  83. }
  84. }
  85. }
  86. ]);
  87. var configs = {
  88. 'test-site': {}
  89. };
  90. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  91. expect(configs).to.eql({
  92. 'test-site': {
  93. 'property1': 'host1:1111'
  94. }
  95. });
  96. });
  97. it('configs_Hadoop2 is present but isHadoop2Stack = true', function () {
  98. isHadoop2Stack = true;
  99. controller.set('additionalConfigsMap', [
  100. {
  101. componentName: 'COMP1',
  102. configs: {
  103. 'test-site': {
  104. 'property1': '<replace-value>:1111'
  105. }
  106. },
  107. configs_Hadoop2: {
  108. 'test-site': {
  109. 'property2': '<replace-value>:2222'
  110. }
  111. }
  112. }
  113. ]);
  114. var configs = {
  115. 'test-site': {}
  116. };
  117. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  118. expect(configs).to.eql({
  119. 'test-site': {
  120. 'property2': 'host1:2222'
  121. }
  122. });
  123. });
  124. });
  125. describe('#getHostComponentsNames()', function () {
  126. it('No host-components', function () {
  127. controller.set('hostComponents', []);
  128. expect(controller.getHostComponentsNames()).to.be.empty;
  129. });
  130. it('one host-components', function () {
  131. controller.set('hostComponents', ['COMP1']);
  132. expect(controller.getHostComponentsNames()).to.equal('Comp1');
  133. });
  134. it('ZKFC host-components', function () {
  135. controller.set('hostComponents', ['COMP1', 'ZKFC']);
  136. expect(controller.getHostComponentsNames()).to.equal('Comp1+ZKFC');
  137. });
  138. });
  139. describe('#removeUnneededTasks()', function () {
  140. var isHaEnabled = false;
  141. beforeEach(function () {
  142. sinon.stub(App, 'get', function () {
  143. return isHaEnabled;
  144. });
  145. controller.set('tasks', [
  146. {id: 1},
  147. {id: 2},
  148. {id: 3},
  149. {id: 4},
  150. {id: 5},
  151. {id: 6},
  152. {id: 7},
  153. {id: 8},
  154. {id: 9}
  155. ]);
  156. });
  157. afterEach(function () {
  158. App.get.restore();
  159. });
  160. it('hasManualSteps is false', function () {
  161. controller.set('content.hasManualSteps', false);
  162. controller.removeUnneededTasks();
  163. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5, 8, 9]);
  164. });
  165. it('reassign component is not NameNode and HA disabled', function () {
  166. controller.set('content.hasManualSteps', true);
  167. controller.set('content.reassign.component_name', 'COMP1');
  168. isHaEnabled = false;
  169. controller.removeUnneededTasks();
  170. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5]);
  171. });
  172. it('reassign component is not NameNode and HA enabled', function () {
  173. controller.set('content.hasManualSteps', true);
  174. controller.set('content.reassign.component_name', 'COMP1');
  175. isHaEnabled = true;
  176. controller.removeUnneededTasks();
  177. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5]);
  178. });
  179. it('reassign component is NameNode and HA disabled', function () {
  180. controller.set('content.hasManualSteps', true);
  181. controller.set('content.reassign.component_name', 'NAMENODE');
  182. isHaEnabled = false;
  183. controller.removeUnneededTasks();
  184. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5]);
  185. });
  186. it('reassign component is NameNode and HA enabled', function () {
  187. controller.set('content.hasManualSteps', true);
  188. controller.set('content.reassign.component_name', 'NAMENODE');
  189. isHaEnabled = true;
  190. controller.removeUnneededTasks();
  191. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5, 6, 7]);
  192. });
  193. });
  194. describe('#initializeTasks()', function () {
  195. beforeEach(function () {
  196. controller.set('tasks', []);
  197. sinon.stub(controller, 'getHostComponentsNames', Em.K);
  198. sinon.stub(controller, 'removeUnneededTasks', Em.K);
  199. });
  200. afterEach(function () {
  201. controller.removeUnneededTasks.restore();
  202. controller.getHostComponentsNames.restore();
  203. });
  204. it('No commands', function () {
  205. controller.set('commands', []);
  206. controller.initializeTasks();
  207. expect(controller.get('tasks')).to.be.empty;
  208. });
  209. it('One command', function () {
  210. controller.set('commands', ['COMMAND1']);
  211. controller.initializeTasks();
  212. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  213. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  214. });
  215. });
  216. describe('#hideRollbackButton()', function () {
  217. it('No showRollback command', function () {
  218. controller.set('tasks', [Em.Object.create({
  219. showRollback: false
  220. })]);
  221. controller.hideRollbackButton();
  222. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  223. });
  224. it('showRollback command is present', function () {
  225. controller.set('tasks', [Em.Object.create({
  226. showRollback: true
  227. })]);
  228. controller.hideRollbackButton();
  229. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  230. });
  231. });
  232. describe('#onComponentsTasksSuccess()', function () {
  233. beforeEach(function () {
  234. sinon.stub(controller, 'onTaskCompleted', Em.K);
  235. });
  236. afterEach(function () {
  237. controller.onTaskCompleted.restore();
  238. });
  239. it('No host-components', function () {
  240. controller.set('multiTaskCounter', 0);
  241. controller.set('hostComponents', []);
  242. controller.onComponentsTasksSuccess();
  243. expect(controller.get('multiTaskCounter')).to.equal(1);
  244. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  245. });
  246. it('One host-component', function () {
  247. controller.set('multiTaskCounter', 0);
  248. controller.set('hostComponents', [
  249. {}
  250. ]);
  251. controller.onComponentsTasksSuccess();
  252. expect(controller.get('multiTaskCounter')).to.equal(1);
  253. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  254. });
  255. it('two host-components', function () {
  256. controller.set('multiTaskCounter', 0);
  257. controller.set('hostComponents', [
  258. {},
  259. {}
  260. ]);
  261. controller.onComponentsTasksSuccess();
  262. expect(controller.get('multiTaskCounter')).to.equal(1);
  263. expect(controller.onTaskCompleted.called).to.be.false;
  264. });
  265. });
  266. describe('#getStopServicesData()', function () {
  267. it('restarting YARN component', function () {
  268. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  269. sinon.stub(App.Service, 'find', function () {
  270. return [
  271. {
  272. serviceName: 'HDFS'
  273. },
  274. {
  275. serviceName: 'SERVICE1'
  276. }
  277. ];
  278. });
  279. expect(controller.getStopServicesData()).to.eql({
  280. "ServiceInfo": {
  281. "state": "INSTALLED"
  282. },
  283. "context": "Stop required services",
  284. "urlParams": "ServiceInfo/service_name.in(SERVICE1)"
  285. });
  286. App.Service.find.restore();
  287. });
  288. it('restarting non-YARN component', function () {
  289. controller.set('content.reassign.component_name', 'NAMENODE');
  290. expect(controller.getStopServicesData()).to.eql({
  291. "ServiceInfo": {
  292. "state": "INSTALLED"
  293. },
  294. "context": "Stop all services"
  295. });
  296. });
  297. });
  298. describe('#stopServices()', function () {
  299. it('', function () {
  300. sinon.stub(controller, 'getStopServicesData', Em.K);
  301. controller.stopServices();
  302. expect(App.ajax.send.calledOnce).to.be.true;
  303. expect(controller.getStopServicesData.calledOnce).to.be.true;
  304. controller.getStopServicesData.restore();
  305. });
  306. });
  307. describe('#createHostComponents()', function () {
  308. beforeEach(function () {
  309. sinon.stub(controller, 'createComponent', Em.K);
  310. });
  311. afterEach(function () {
  312. controller.createComponent.restore();
  313. });
  314. it('No host-components', function () {
  315. controller.set('hostComponents', []);
  316. controller.createHostComponents();
  317. expect(controller.get('multiTaskCounter')).to.equal(0);
  318. expect(controller.createComponent.called).to.be.false;
  319. });
  320. it('One host-component', function () {
  321. controller.set('hostComponents', ['COMP1']);
  322. controller.set('content.reassignHosts.target', 'host1');
  323. controller.set('content.reassign.service_id', 'SERVICE1');
  324. controller.createHostComponents();
  325. expect(controller.get('multiTaskCounter')).to.equal(0);
  326. expect(controller.createComponent.calledWith('COMP1', 'host1', 'SERVICE1')).to.be.true;
  327. });
  328. });
  329. describe('#onCreateComponent()', function () {
  330. it('', function () {
  331. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  332. controller.onCreateComponent();
  333. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  334. controller.onComponentsTasksSuccess.restore();
  335. });
  336. });
  337. describe('#putHostComponentsInMaintenanceMode()', function () {
  338. beforeEach(function(){
  339. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  340. controller.set('content.reassignHosts.source', 'source');
  341. });
  342. afterEach(function(){
  343. controller.onComponentsTasksSuccess.restore();
  344. });
  345. it('No host-components', function () {
  346. controller.set('hostComponents', []);
  347. controller.putHostComponentsInMaintenanceMode();
  348. expect(App.ajax.send.called).to.be.false;
  349. expect(controller.get('multiTaskCounter')).to.equal(0);
  350. });
  351. it('One host-components', function () {
  352. controller.set('hostComponents', [{}]);
  353. controller.putHostComponentsInMaintenanceMode();
  354. expect(App.ajax.send.calledOnce).to.be.true;
  355. expect(controller.get('multiTaskCounter')).to.equal(0);
  356. });
  357. });
  358. describe('#installHostComponents()', function () {
  359. beforeEach(function () {
  360. sinon.stub(controller, 'updateComponent', Em.K);
  361. });
  362. afterEach(function () {
  363. controller.updateComponent.restore();
  364. });
  365. it('No host-components', function () {
  366. controller.set('hostComponents', []);
  367. controller.installHostComponents();
  368. expect(controller.get('multiTaskCounter')).to.equal(0);
  369. expect(controller.updateComponent.called).to.be.false;
  370. });
  371. it('One host-component', function () {
  372. controller.set('hostComponents', ['COMP1']);
  373. controller.set('content.reassignHosts.target', 'host1');
  374. controller.set('content.reassign.service_id', 'SERVICE1');
  375. controller.installHostComponents();
  376. expect(controller.get('multiTaskCounter')).to.equal(0);
  377. expect(controller.updateComponent.calledWith('COMP1', 'host1', 'SERVICE1', 'Install', 1)).to.be.true;
  378. });
  379. });
  380. describe('#reconfigure()', function () {
  381. it('', function () {
  382. sinon.stub(controller, 'loadConfigsTags', Em.K);
  383. controller.reconfigure();
  384. expect(controller.loadConfigsTags.calledOnce).to.be.true;
  385. controller.loadConfigsTags.restore();
  386. });
  387. });
  388. describe('#loadConfigsTags()', function () {
  389. it('', function () {
  390. controller.loadConfigsTags();
  391. expect(App.ajax.send.calledOnce).to.be.true;
  392. });
  393. });
  394. describe('#getConfigUrlParams()', function () {
  395. var testCases = [
  396. {
  397. componentName: 'NAMENODE',
  398. result: [
  399. "(type=hdfs-site&tag=1)",
  400. "(type=core-site&tag=2)"
  401. ]
  402. },
  403. {
  404. componentName: 'SECONDARY_NAMENODE',
  405. result: [
  406. "(type=hdfs-site&tag=1)",
  407. "(type=core-site&tag=2)"
  408. ]
  409. },
  410. {
  411. componentName: 'JOBTRACKER',
  412. result: [
  413. "(type=mapred-site&tag=4)"
  414. ]
  415. },
  416. {
  417. componentName: 'RESOURCEMANAGER',
  418. result: [
  419. "(type=yarn-site&tag=5)"
  420. ]
  421. },
  422. {
  423. componentName: 'APP_TIMELINE_SERVER',
  424. result: [
  425. "(type=yarn-site&tag=5)"
  426. ]
  427. },
  428. {
  429. componentName: 'OOZIE_SERVER',
  430. result: [
  431. "(type=oozie-site&tag=6)"
  432. ]
  433. },
  434. {
  435. componentName: 'WEBHCAT_SERVER',
  436. result: [
  437. "(type=webhcat-site&tag=7)"
  438. ]
  439. }
  440. ];
  441. var data = {
  442. Clusters: {
  443. desired_configs: {
  444. 'hdfs-site': {tag: 1},
  445. 'core-site': {tag: 2},
  446. 'hbase-site': {tag: 3},
  447. 'mapred-site': {tag: 4},
  448. 'yarn-site': {tag: 5},
  449. 'oozie-site': {tag: 6},
  450. 'webhcat-site': {tag: 7}
  451. }
  452. }
  453. };
  454. var services = [];
  455. beforeEach(function () {
  456. sinon.stub(App.Service, 'find', function () {
  457. return services;
  458. })
  459. });
  460. afterEach(function () {
  461. App.Service.find.restore();
  462. });
  463. testCases.forEach(function (test) {
  464. it('get config of ' + test.componentName, function () {
  465. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  466. })
  467. });
  468. it('get config of NAMENODE when HBASE installed', function () {
  469. services = [
  470. {
  471. serviceName: 'HBASE'
  472. }
  473. ];
  474. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  475. "(type=hdfs-site&tag=1)",
  476. "(type=core-site&tag=2)",
  477. "(type=hbase-site&tag=3)"
  478. ]);
  479. })
  480. });
  481. describe('#onLoadConfigsTags()', function () {
  482. it('', function () {
  483. sinon.stub(controller, 'getConfigUrlParams', function () {
  484. return [];
  485. });
  486. controller.set('content.reassign.component_name', 'COMP1');
  487. controller.onLoadConfigsTags({});
  488. expect(App.ajax.send.calledOnce).to.be.true;
  489. expect(controller.getConfigUrlParams.calledWith('COMP1', {})).to.be.true;
  490. controller.getConfigUrlParams.restore();
  491. });
  492. });
  493. describe('#onLoadConfigs()', function () {
  494. beforeEach(function () {
  495. sinon.stub(controller, 'setAdditionalConfigs', Em.K);
  496. sinon.stub(controller, 'setSecureConfigs', Em.K);
  497. sinon.stub(controller, 'setSpecificNamenodeConfigs', Em.K);
  498. sinon.stub(controller, 'setSpecificResourceMangerConfigs', Em.K);
  499. sinon.stub(controller, 'getComponentDir', Em.K);
  500. sinon.stub(controller, 'saveClusterStatus', Em.K);
  501. sinon.stub(controller, 'saveConfigsToServer', Em.K);
  502. controller.set('content.reassignHosts.target', 'host1');
  503. });
  504. afterEach(function () {
  505. controller.setAdditionalConfigs.restore();
  506. controller.setSecureConfigs.restore();
  507. controller.setSpecificNamenodeConfigs.restore();
  508. controller.setSpecificResourceMangerConfigs.restore();
  509. controller.getComponentDir.restore();
  510. controller.saveClusterStatus.restore();
  511. controller.saveConfigsToServer.restore();
  512. });
  513. it('component is not NAMENODE', function () {
  514. controller.set('content.reassign.component_name', 'COMP1');
  515. controller.onLoadConfigs({items: []});
  516. expect(controller.setAdditionalConfigs.calledWith({}, 'COMP1', 'host1')).to.be.true;
  517. expect(controller.setSecureConfigs.calledWith([], {}, 'COMP1')).to.be.true;
  518. expect(controller.setSpecificNamenodeConfigs.called).to.be.false;
  519. expect(controller.getComponentDir.calledWith({}, 'COMP1')).to.be.true;
  520. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  521. expect(controller.saveConfigsToServer.calledWith({})).to.be.true;
  522. });
  523. it('component is NAMENODE, has configs', function () {
  524. controller.set('content.reassign.component_name', 'NAMENODE');
  525. controller.onLoadConfigs({items: [
  526. {
  527. type: 'hdfs-site',
  528. properties: {}
  529. }
  530. ]});
  531. expect(controller.setAdditionalConfigs.calledWith({'hdfs-site': {}}, 'NAMENODE', 'host1')).to.be.true;
  532. expect(controller.setSecureConfigs.calledWith([], {'hdfs-site': {}}, 'NAMENODE')).to.be.true;
  533. expect(controller.setSpecificNamenodeConfigs.calledWith({'hdfs-site': {}}, 'host1')).to.be.true;
  534. expect(controller.getComponentDir.calledWith({'hdfs-site': {}}, 'NAMENODE')).to.be.true;
  535. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  536. expect(controller.saveConfigsToServer.calledWith({'hdfs-site': {}})).to.be.true;
  537. });
  538. it('component is RESOURCEMANAGER, has configs', function () {
  539. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  540. controller.onLoadConfigs({items: [
  541. {
  542. type: 'hdfs-site',
  543. properties: {}
  544. }
  545. ]});
  546. expect(controller.setAdditionalConfigs.calledWith({'hdfs-site': {}}, 'RESOURCEMANAGER', 'host1')).to.be.true;
  547. expect(controller.setSecureConfigs.calledWith([], {'hdfs-site': {}}, 'RESOURCEMANAGER')).to.be.true;
  548. expect(controller.setSpecificResourceMangerConfigs.calledWith({'hdfs-site': {}}, 'host1')).to.be.true;
  549. expect(controller.getComponentDir.calledWith({'hdfs-site': {}}, 'RESOURCEMANAGER')).to.be.true;
  550. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  551. expect(controller.saveConfigsToServer.calledWith({'hdfs-site': {}})).to.be.true;
  552. });
  553. });
  554. describe('#loadStep()', function () {
  555. var isHaEnabled = true;
  556. beforeEach(function () {
  557. controller.set('content.reassign.service_id', 'service1');
  558. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  559. sinon.stub(controller, 'initializeTasks', Em.K);
  560. sinon.stub(App, 'get', function () {
  561. return isHaEnabled;
  562. });
  563. });
  564. afterEach(function () {
  565. controller.onTaskStatusChange.restore();
  566. controller.initializeTasks.restore();
  567. App.get.restore();
  568. });
  569. it('reassign component is NameNode and HA enabled', function () {
  570. isHaEnabled = true;
  571. controller.set('content.reassign.component_name', 'NAMENODE');
  572. controller.loadStep();
  573. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  574. expect(controller.get('serviceName')).to.eql(['service1']);
  575. });
  576. it('reassign component is NameNode and HA disabled', function () {
  577. isHaEnabled = false;
  578. controller.set('content.reassign.component_name', 'NAMENODE');
  579. controller.loadStep();
  580. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  581. expect(controller.get('serviceName')).to.eql(['service1']);
  582. });
  583. it('reassign component is JOBTRACKER and HA enabled', function () {
  584. isHaEnabled = true;
  585. controller.set('content.reassign.component_name', 'JOBTRACKER');
  586. controller.loadStep();
  587. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  588. expect(controller.get('serviceName')).to.eql(['service1']);
  589. });
  590. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  591. isHaEnabled = true;
  592. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  593. controller.loadStep();
  594. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  595. expect(controller.get('serviceName')).to.eql(['service1']);
  596. });
  597. });
  598. describe('#saveConfigsToServer()', function () {
  599. beforeEach(function () {
  600. sinon.stub(controller, 'getServiceConfigData', Em.K);
  601. });
  602. afterEach(function () {
  603. controller.getServiceConfigData.restore();
  604. });
  605. it('', function () {
  606. controller.saveConfigsToServer([1]);
  607. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  608. expect(App.ajax.send.calledOnce).to.be.true;
  609. });
  610. });
  611. describe('#setSpecificNamenodeConfigs()', function () {
  612. var isHaEnabled = false;
  613. var service = Em.Object.create();
  614. beforeEach(function () {
  615. sinon.stub(App, 'get', function () {
  616. return isHaEnabled;
  617. });
  618. sinon.stub(App.Service, 'find', function () {
  619. return service;
  620. });
  621. controller.set('content.reassignHosts.source', 'host1');
  622. });
  623. afterEach(function () {
  624. App.get.restore();
  625. App.Service.find.restore();
  626. });
  627. it('HA isn\'t enabled and no HBASE service', function () {
  628. isHaEnabled = false;
  629. var configs = {};
  630. controller.setSpecificNamenodeConfigs(configs, 'host1');
  631. expect(configs).to.eql({});
  632. });
  633. it('HA isn\'t enabled and HBASE service', function () {
  634. isHaEnabled = false;
  635. service = Em.Object.create({
  636. isLoaded: true
  637. });
  638. var configs = {
  639. 'hbase-site': {
  640. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  641. }
  642. };
  643. controller.setSpecificNamenodeConfigs(configs, 'host1');
  644. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host1:8020/apps/hbase/data');
  645. });
  646. it('HA enabled and namenode 1', function () {
  647. isHaEnabled = true;
  648. var configs = {
  649. 'hdfs-site': {
  650. 'dfs.nameservices': 's',
  651. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  652. 'dfs.namenode.https-address.s.nn1': '',
  653. 'dfs.namenode.rpc-address.s.nn1': ''
  654. }
  655. };
  656. controller.setSpecificNamenodeConfigs(configs, 'host2');
  657. expect(configs['hdfs-site']).to.eql({
  658. "dfs.nameservices": "s",
  659. "dfs.namenode.http-address.s.nn1": "host2:50070",
  660. "dfs.namenode.https-address.s.nn1": "host2:50470",
  661. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  662. });
  663. });
  664. it('HA enabled and namenode 2', function () {
  665. isHaEnabled = true;
  666. var configs = {
  667. 'hdfs-site': {
  668. 'dfs.nameservices': 's',
  669. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  670. 'dfs.namenode.https-address.s.nn2': '',
  671. 'dfs.namenode.rpc-address.s.nn2': ''
  672. }
  673. };
  674. controller.setSpecificNamenodeConfigs(configs, 'host1');
  675. expect(configs['hdfs-site']).to.eql({
  676. "dfs.nameservices": "s",
  677. "dfs.namenode.http-address.s.nn2": "host1:50070",
  678. "dfs.namenode.https-address.s.nn2": "host1:50470",
  679. "dfs.namenode.rpc-address.s.nn2": "host1:8020"
  680. });
  681. });
  682. });
  683. describe('#setSpecificResourceMangerConfigs()', function () {
  684. var isRMHaEnabled = false;
  685. var service = Em.Object.create();
  686. beforeEach(function () {
  687. sinon.stub(App, 'get', function () {
  688. return isRMHaEnabled;
  689. });
  690. controller.set('content.reassignHosts.source', 'host1');
  691. });
  692. afterEach(function () {
  693. App.get.restore();
  694. });
  695. it('HA isn\'t enabled', function () {
  696. isRMHaEnabled = false;
  697. var configs = {};
  698. controller.setSpecificResourceMangerConfigs(configs, 'host1');
  699. expect(configs).to.eql({});
  700. });
  701. it('HA enabled and resource manager 1', function () {
  702. isRMHaEnabled = true;
  703. var configs = {
  704. 'yarn-site': {
  705. 'yarn.resourcemanager.hostname.rm1': 'host1'
  706. }
  707. };
  708. controller.setSpecificResourceMangerConfigs(configs, 'host2');
  709. expect(configs['yarn-site']).to.eql({
  710. 'yarn.resourcemanager.hostname.rm1': 'host2'
  711. });
  712. });
  713. it('HA enabled and resource manager 2', function () {
  714. isRMHaEnabled = true;
  715. var configs = {
  716. 'yarn-site': {
  717. 'yarn.resourcemanager.hostname.rm2': 'host2'
  718. }
  719. };
  720. controller.setSpecificResourceMangerConfigs(configs, 'host1');
  721. expect(configs['yarn-site']).to.eql({
  722. 'yarn.resourcemanager.hostname.rm2': 'host1'
  723. });
  724. });
  725. });
  726. describe('#setSecureConfigs()', function () {
  727. it('undefined component and security disabled', function () {
  728. var secureConfigs = [];
  729. controller.set('content.securityEnabled', false);
  730. controller.set('secureConfigsMap', []);
  731. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  732. expect(secureConfigs).to.eql([]);
  733. });
  734. it('undefined component and security enabled', function () {
  735. var secureConfigs = [];
  736. controller.set('content.securityEnabled', true);
  737. controller.set('secureConfigsMap', []);
  738. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  739. expect(secureConfigs).to.eql([]);
  740. });
  741. it('component exist and security disabled', function () {
  742. var secureConfigs = [];
  743. controller.set('content.securityEnabled', false);
  744. controller.set('secureConfigsMap', [{
  745. componentName: 'COMP1'
  746. }]);
  747. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  748. expect(secureConfigs).to.eql([]);
  749. });
  750. it('component exist and security enabled', function () {
  751. var secureConfigs = [];
  752. var configs = {'s1': {
  753. 'k1': 'kValue',
  754. 'p1': 'pValue'
  755. }};
  756. controller.set('content.securityEnabled', true);
  757. controller.set('secureConfigsMap', [{
  758. componentName: 'COMP1',
  759. configs: [{
  760. site: 's1',
  761. keytab: 'k1',
  762. principal: 'p1'
  763. }]
  764. }]);
  765. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  766. expect(secureConfigs).to.eql([
  767. {
  768. "keytab": "kValue",
  769. "principal": "pValue"
  770. }
  771. ]);
  772. });
  773. });
  774. describe('#getComponentDir()', function () {
  775. var isHadoop2Stack = false;
  776. beforeEach(function () {
  777. sinon.stub(App, 'get', function () {
  778. return isHadoop2Stack;
  779. });
  780. });
  781. afterEach(function () {
  782. App.get.restore();
  783. });
  784. var configs = {
  785. 'hdfs-site': {
  786. 'dfs.name.dir': 'case1',
  787. 'dfs.namenode.name.dir': 'case2',
  788. 'dfs.namenode.checkpoint.dir': 'case3'
  789. },
  790. 'core-site': {
  791. 'fs.checkpoint.dir': 'case4'
  792. }
  793. };
  794. it('unknown component name', function () {
  795. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  796. });
  797. it('NAMENODE component and isHadoop2Stack is false', function () {
  798. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case1');
  799. });
  800. it('NAMENODE component and isHadoop2Stack is true', function () {
  801. isHadoop2Stack = true;
  802. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  803. });
  804. it('SECONDARY_NAMENODE component and isHadoop2Stack is true', function () {
  805. isHadoop2Stack = true;
  806. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  807. });
  808. it('SECONDARY_NAMENODE component and isHadoop2Stack is false', function () {
  809. isHadoop2Stack = false;
  810. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case4');
  811. });
  812. });
  813. describe('#saveClusterStatus()', function () {
  814. var mock = {
  815. saveComponentDir: Em.K,
  816. saveSecureConfigs: Em.K
  817. };
  818. beforeEach(function () {
  819. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  820. sinon.stub(App.router, 'get', function() {
  821. return mock;
  822. });
  823. sinon.spy(mock, 'saveComponentDir');
  824. sinon.spy(mock, 'saveSecureConfigs');
  825. });
  826. afterEach(function () {
  827. App.clusterStatus.setClusterStatus.restore();
  828. App.router.get.restore();
  829. mock.saveSecureConfigs.restore();
  830. mock.saveComponentDir.restore();
  831. });
  832. it('componentDir undefined and secureConfigs is empty', function () {
  833. expect(controller.saveClusterStatus([], null)).to.be.false;
  834. });
  835. it('componentDir defined and secureConfigs is empty', function () {
  836. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  837. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  838. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  839. });
  840. it('componentDir undefined and secureConfigs has data', function () {
  841. expect(controller.saveClusterStatus([1], null)).to.be.true;
  842. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  843. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  844. });
  845. it('componentDir defined and secureConfigs has data', function () {
  846. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  847. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  848. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  849. });
  850. });
  851. describe('#onSaveConfigs()', function () {
  852. beforeEach(function () {
  853. sinon.stub(controller, 'onTaskCompleted', Em.K);
  854. });
  855. afterEach(function () {
  856. controller.onTaskCompleted.restore();
  857. });
  858. it('', function () {
  859. controller.onSaveConfigs();
  860. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  861. });
  862. });
  863. describe('#startZooKeeperServers()', function () {
  864. beforeEach(function () {
  865. sinon.stub(controller, 'updateComponent', Em.K);
  866. });
  867. afterEach(function () {
  868. controller.updateComponent.restore();
  869. });
  870. it('', function () {
  871. controller.set('content.masterComponentHosts', [{
  872. component: 'ZOOKEEPER_SERVER',
  873. hostName: 'host1'
  874. }]);
  875. controller.startZooKeeperServers();
  876. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  877. });
  878. });
  879. describe('#startNameNode()', function () {
  880. beforeEach(function () {
  881. sinon.stub(controller, 'updateComponent', Em.K);
  882. });
  883. afterEach(function () {
  884. controller.updateComponent.restore();
  885. });
  886. it('reassign host does not match current', function () {
  887. controller.set('content.masterComponentHosts', [{
  888. component: 'NAMENODE',
  889. hostName: 'host1'
  890. }]);
  891. controller.set('content.reassignHosts.source', 'host2');
  892. controller.startNameNode();
  893. expect(controller.updateComponent.calledWith('NAMENODE', ['host1'], 'HDFS', 'Start')).to.be.true;
  894. });
  895. it('reassign host matches current', function () {
  896. controller.set('content.masterComponentHosts', [{
  897. component: 'NAMENODE',
  898. hostName: 'host1'
  899. }]);
  900. controller.set('content.reassignHosts.source', 'host1');
  901. controller.startNameNode();
  902. expect(controller.updateComponent.calledWith('NAMENODE', [], 'HDFS', 'Start')).to.be.true;
  903. });
  904. });
  905. describe('#startServices()', function () {
  906. beforeEach(function () {
  907. sinon.stub(controller, 'getStartServicesData', Em.K);
  908. });
  909. afterEach(function () {
  910. controller.getStartServicesData.restore();
  911. });
  912. it('', function () {
  913. controller.startServices();
  914. expect(controller.getStartServicesData.calledOnce).to.be.true;
  915. expect(App.ajax.send.calledOnce).to.be.true;
  916. });
  917. });
  918. describe('#getStartServicesData()', function () {
  919. beforeEach(function () {
  920. sinon.stub(App.Service, 'find', function () {
  921. return [
  922. {serviceName: 'SERVICE1'},
  923. {serviceName: 'SERVICE2'}
  924. ]
  925. })
  926. });
  927. afterEach(function () {
  928. App.Service.find.restore();
  929. });
  930. it('No unrelated services', function () {
  931. controller.set('unrelatedServicesMap', {
  932. 'COMP1': ['SERVICE1']
  933. });
  934. controller.set('content.reassign.component_name', 'COMP2');
  935. expect(controller.getStartServicesData()).to.eql({
  936. "context": "Start all services",
  937. "ServiceInfo": {
  938. "state": "STARTED"
  939. },
  940. "urlParams": "params/run_smoke_test=true"
  941. });
  942. });
  943. it('Present unrelated services', function () {
  944. controller.set('unrelatedServicesMap', {
  945. 'COMP1': ['SERVICE1']
  946. });
  947. controller.set('content.reassign.component_name', 'COMP1');
  948. expect(controller.getStartServicesData()).to.eql({
  949. "context": "Start required services",
  950. "ServiceInfo": {
  951. "state": "STARTED"
  952. },
  953. "urlParams": "ServiceInfo/service_name.in(SERVICE2)"
  954. });
  955. });
  956. });
  957. describe('#deleteHostComponents()', function () {
  958. it('No host components', function () {
  959. controller.set('hostComponents', []);
  960. controller.set('content.reassignHosts.source', 'host1');
  961. controller.deleteHostComponents();
  962. expect(App.ajax.send.called).to.be.false;
  963. });
  964. it('delete two components', function () {
  965. controller.set('hostComponents', [1, 2]);
  966. controller.set('content.reassignHosts.source', 'host1');
  967. controller.deleteHostComponents();
  968. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  969. "hostName": "host1",
  970. "componentName": 1
  971. });
  972. expect(App.ajax.send.getCall(1).args[0].data).to.eql({
  973. "hostName": "host1",
  974. "componentName": 2
  975. });
  976. });
  977. });
  978. describe('#onDeleteHostComponentsError()', function () {
  979. beforeEach(function () {
  980. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  981. sinon.stub(controller, 'onTaskError', Em.K);
  982. });
  983. afterEach(function () {
  984. controller.onComponentsTasksSuccess.restore();
  985. controller.onTaskError.restore();
  986. });
  987. it('task success', function () {
  988. var error = {
  989. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  990. }
  991. controller.onDeleteHostComponentsError(error);
  992. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  993. });
  994. it('unknown error', function () {
  995. var error = {
  996. responseText: ''
  997. }
  998. controller.onDeleteHostComponentsError(error);
  999. expect(controller.onTaskError.calledOnce).to.be.true;
  1000. });
  1001. });
  1002. describe('#done()', function () {
  1003. beforeEach(function () {
  1004. sinon.stub(controller, 'removeObserver', Em.K);
  1005. sinon.stub(App.router, 'send', Em.K);
  1006. });
  1007. afterEach(function () {
  1008. controller.removeObserver.restore();
  1009. App.router.send.restore();
  1010. });
  1011. it('submit disabled', function () {
  1012. controller.set('isSubmitDisabled', true);
  1013. controller.done();
  1014. expect(App.router.send.called).to.be.false;
  1015. });
  1016. it('submit enabled and does not have manual steps', function () {
  1017. controller.set('isSubmitDisabled', false);
  1018. controller.set('content.hasManualSteps', false);
  1019. controller.done();
  1020. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  1021. expect(App.router.send.calledWith('complete')).to.be.true;
  1022. });
  1023. it('submit enabled and has manual steps', function () {
  1024. controller.set('isSubmitDisabled', false);
  1025. controller.set('content.hasManualSteps', true);
  1026. controller.done();
  1027. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  1028. expect(App.router.send.calledWith('next')).to.be.true;
  1029. });
  1030. });
  1031. describe('#getServiceConfigData()', function () {
  1032. var services = [];
  1033. var stackServices = [];
  1034. beforeEach(function () {
  1035. sinon.stub(App.Service, 'find', function () {
  1036. return services;
  1037. });
  1038. sinon.stub(App.StackService, 'find', function () {
  1039. return stackServices;
  1040. });
  1041. });
  1042. afterEach(function () {
  1043. App.Service.find.restore();
  1044. App.StackService.find.restore();
  1045. });
  1046. it('No services', function () {
  1047. services = [];
  1048. controller.set('content.reassign.component_name', 'COMP1');
  1049. expect(controller.getServiceConfigData([])).to.eql([]);
  1050. });
  1051. it('No services in stackServices', function () {
  1052. services = [Em.Object.create({serviceName: 'S1'})];
  1053. stackServices = [];
  1054. controller.set('content.reassign.component_name', 'COMP1');
  1055. expect(controller.getServiceConfigData([])).to.eql([]);
  1056. });
  1057. it('Services in stackServicesm but configTypesRendered is empty', function () {
  1058. services = [Em.Object.create({serviceName: 'S1'})];
  1059. stackServices = [Em.Object.create({
  1060. serviceName: 'S1',
  1061. configTypesRendered: {}
  1062. })];
  1063. controller.set('content.reassign.component_name', 'COMP1');
  1064. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  1065. });
  1066. it('Services in stackServicesm and configTypesRendered has data, but configs is empty', function () {
  1067. services = [Em.Object.create({serviceName: 'S1'})];
  1068. stackServices = [
  1069. Em.Object.create({
  1070. serviceName: 'S1',
  1071. configTypesRendered: {'type1': {}}
  1072. })
  1073. ];
  1074. controller.set('content.reassign.component_name', 'COMP1');
  1075. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  1076. });
  1077. it('Services in stackServicesm and configTypesRendered has data, and configs present', function () {
  1078. services = [Em.Object.create({serviceName: 'S1'})];
  1079. stackServices = [
  1080. Em.Object.create({
  1081. serviceName: 'S1',
  1082. configTypesRendered: {'type1': {}}
  1083. })
  1084. ];
  1085. var configs = {
  1086. 'type1': {
  1087. 'prop1': 'value1'
  1088. }
  1089. };
  1090. controller.set('content.reassign.component_name', 'COMP1');
  1091. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  1092. });
  1093. });
  1094. });