step6_controller_test.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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/step6_controller');
  20. var controller;
  21. var testHelpers = require('test/helpers');
  22. describe('App.ReassignMasterWizardStep6Controller', function () {
  23. beforeEach(function () {
  24. controller = App.ReassignMasterWizardStep6Controller.create({
  25. content: Em.Object.create({
  26. reassign: Em.Object.create(),
  27. reassignHosts: Em.Object.create()
  28. }),
  29. startServices: Em.K
  30. });
  31. });
  32. describe('#initializeTasks()', function () {
  33. it('No commands', function () {
  34. controller.set('commands', []);
  35. controller.set('hostComponents', []);
  36. controller.initializeTasks();
  37. expect(controller.get('tasks')).to.be.empty;
  38. });
  39. it('One command', function () {
  40. controller.set('commands', ['COMMAND1']);
  41. controller.initializeTasks();
  42. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  43. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  44. });
  45. });
  46. describe('#hideRollbackButton()', function () {
  47. it('No showRollback command', function () {
  48. controller.set('tasks', [Em.Object.create({
  49. showRollback: false
  50. })]);
  51. controller.hideRollbackButton();
  52. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  53. });
  54. it('showRollback command is present', function () {
  55. controller.set('tasks', [Em.Object.create({
  56. showRollback: true
  57. })]);
  58. controller.hideRollbackButton();
  59. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  60. });
  61. });
  62. describe('#onComponentsTasksSuccess()', function () {
  63. beforeEach(function () {
  64. sinon.stub(controller, 'onTaskCompleted', Em.K);
  65. });
  66. afterEach(function () {
  67. controller.onTaskCompleted.restore();
  68. });
  69. it('One host-component', function () {
  70. controller.set('multiTaskCounter', 1);
  71. controller.set('hostComponents', [
  72. {}
  73. ]);
  74. controller.onComponentsTasksSuccess();
  75. expect(controller.get('multiTaskCounter')).to.equal(0);
  76. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  77. });
  78. it('two host-components', function () {
  79. controller.set('multiTaskCounter', 2);
  80. controller.set('hostComponents', [
  81. {},
  82. {}
  83. ]);
  84. controller.onComponentsTasksSuccess();
  85. expect(controller.get('multiTaskCounter')).to.equal(1);
  86. expect(controller.onTaskCompleted.called).to.be.false;
  87. });
  88. });
  89. describe('#loadStep()', function () {
  90. var isHaEnabled = true;
  91. beforeEach(function () {
  92. controller.set('content.reassign.service_id', 'service1');
  93. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  94. sinon.stub(controller, 'initializeTasks', Em.K);
  95. sinon.stub(App, 'get', function () {
  96. return isHaEnabled;
  97. });
  98. });
  99. afterEach(function () {
  100. controller.onTaskStatusChange.restore();
  101. controller.initializeTasks.restore();
  102. App.get.restore();
  103. });
  104. it('reassign component is NameNode and HA enabled', function () {
  105. isHaEnabled = true;
  106. controller.set('content.reassign.component_name', 'NAMENODE');
  107. controller.loadStep();
  108. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  109. });
  110. it('reassign component is NameNode and HA disabled', function () {
  111. isHaEnabled = false;
  112. controller.set('content.reassign.component_name', 'NAMENODE');
  113. controller.loadStep();
  114. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  115. });
  116. it('reassign component is RESOURCEMANAGER', function () {
  117. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  118. controller.loadStep();
  119. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  120. });
  121. });
  122. describe('#loadStep() for reassign NameNode with PXF service installed', function () {
  123. var serviceStub, hostComponentStub, pxfHosts, dataNodeHosts;
  124. var commands = [
  125. 'stopMysqlService',
  126. 'putHostComponentsInMaintenanceMode',
  127. 'stopHostComponentsInMaintenanceMode',
  128. 'deleteHostComponents',
  129. 'startAllServices'
  130. ];
  131. var reassignHosts = {
  132. "source": "c6401.ambari.apache.org",
  133. "target": "c6403.ambari.apache.org"
  134. };
  135. beforeEach(function () {
  136. controller.set('content.reassign.service_id', 'HDFS');
  137. controller.set('content.reassign.component_name', 'NAMENODE');
  138. controller.set('commands', commands.copy());
  139. controller.set('content.reassignHosts', reassignHosts);
  140. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  141. sinon.stub(controller, 'initializeTasks', Em.K);
  142. serviceStub = sinon.stub(App.Service.find(), 'someProperty');
  143. hostComponentStub = sinon.stub(App.HostComponent.find(), 'filterProperty');
  144. serviceStub.withArgs('serviceName', 'PXF').returns(true);
  145. });
  146. afterEach(function () {
  147. controller.onTaskStatusChange.restore();
  148. controller.initializeTasks.restore();
  149. serviceStub.restore();
  150. hostComponentStub.restore();
  151. });
  152. var setUpHosts = function (pxfHosts, dataNodeHosts) {
  153. hostComponentStub.withArgs('componentName', 'PXF').returns(pxfHosts);
  154. hostComponentStub.withArgs('componentName', 'DATANODE').returns(dataNodeHosts);
  155. };
  156. it('does not delete PXF from source host if PXF and DATANODE are not installed on the source host', function () {
  157. pxfHosts = [{"hostName": "c6402.ambari.apache.org"}];
  158. dataNodeHosts = [{"hostName": "c6402.ambari.apache.org"}];
  159. setUpHosts(pxfHosts, dataNodeHosts);
  160. controller.loadStep();
  161. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  162. });
  163. it('does not delete PXF from source host if PXF is not installed on the source host and DATANODE is installed on the source host', function () {
  164. pxfHosts = [{"hostName": "c6402.ambari.apache.org"}];
  165. dataNodeHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
  166. setUpHosts(pxfHosts, dataNodeHosts);
  167. controller.loadStep();
  168. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  169. });
  170. it('deletes PXF from source host if PXF is installed on the source host and DATANODE is not installed on the source host', function () {
  171. pxfHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
  172. dataNodeHosts = [{"hostName": "c6402.ambari.apache.org"}];
  173. setUpHosts(pxfHosts, dataNodeHosts);
  174. controller.loadStep();
  175. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'PXF']);
  176. });
  177. it('does not delete PXF from source host if PXF and DATANODE are installed on the source host', function () {
  178. pxfHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
  179. dataNodeHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
  180. setUpHosts(pxfHosts, dataNodeHosts);
  181. controller.loadStep();
  182. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  183. });
  184. it('does not install PXF on the target host if PXF is already installed on the target host', function () {
  185. pxfHosts = [{"hostName": "c6403.ambari.apache.org"}];
  186. setUpHosts(pxfHosts, []);
  187. controller.loadStep();
  188. expect(controller.get('commands').indexOf('installPxf')).to.eql(-1);
  189. });
  190. it('installs PXF on the target host if PXF is not installed on the target host', function () {
  191. pxfHosts = [{"hostName": "c6401.ambari.apache.org"}, {"hostName": "c6402.ambari.apache.org"}];
  192. setUpHosts(pxfHosts, []);
  193. controller.loadStep();
  194. expect(controller.get('commands').indexOf('installPxf')).to.eql(4);
  195. });
  196. });
  197. describe('#deleteHostComponents()', function () {
  198. it('No host components', function () {
  199. controller.set('hostComponents', []);
  200. controller.set('content.reassignHosts.source', 'host1');
  201. controller.deleteHostComponents();
  202. var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
  203. expect(args).not.exists;
  204. });
  205. it('delete two components', function () {
  206. controller.set('hostComponents', [1, 2]);
  207. controller.set('content.reassignHosts.source', 'host1');
  208. controller.deleteHostComponents();
  209. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  210. expect(args).to.have.property('length').equal(2);
  211. expect(args[0][0].data).to.eql({
  212. "hostName": "host1",
  213. "componentName": 1
  214. });
  215. expect(args[1][0].data).to.eql({
  216. "hostName": "host1",
  217. "componentName": 2
  218. });
  219. });
  220. });
  221. describe('#onDeleteHostComponentsError()', function () {
  222. beforeEach(function () {
  223. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  224. sinon.stub(controller, 'onTaskError', Em.K);
  225. });
  226. afterEach(function () {
  227. controller.onComponentsTasksSuccess.restore();
  228. controller.onTaskError.restore();
  229. });
  230. it('task success', function () {
  231. var error = {
  232. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  233. };
  234. controller.onDeleteHostComponentsError(error);
  235. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  236. });
  237. it('unknown error', function () {
  238. var error = {
  239. responseText: ''
  240. };
  241. controller.onDeleteHostComponentsError(error);
  242. expect(controller.onTaskError.calledOnce).to.be.true;
  243. });
  244. });
  245. describe('#stopMysqlService()', function () {
  246. it('stopMysqlService', function () {
  247. controller.stopMysqlService();
  248. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  249. expect(args[0]).exists;
  250. });
  251. });
  252. describe('#putHostComponentsInMaintenanceMode()', function () {
  253. beforeEach(function(){
  254. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  255. controller.set('content.reassignHosts.source', 'source');
  256. });
  257. afterEach(function(){
  258. controller.onComponentsTasksSuccess.restore();
  259. });
  260. it('No host-components', function () {
  261. controller.set('hostComponents', []);
  262. controller.putHostComponentsInMaintenanceMode();
  263. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  264. expect(args).not.exists;
  265. expect(controller.get('multiTaskCounter')).to.equal(0);
  266. });
  267. it('One host-components', function () {
  268. controller.set('hostComponents', [{}]);
  269. controller.putHostComponentsInMaintenanceMode();
  270. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  271. expect(args).exists;
  272. expect(controller.get('multiTaskCounter')).to.equal(1);
  273. });
  274. });
  275. describe("#removeTasks()", function() {
  276. it("no tasks to delete", function() {
  277. controller.set('tasks', [Em.Object.create()]);
  278. controller.removeTasks([]);
  279. expect(controller.get('tasks').length).to.equal(1);
  280. });
  281. it("one task to delete", function() {
  282. controller.set('tasks', [Em.Object.create({command: 'task1'})]);
  283. controller.removeTasks(['task1']);
  284. expect(controller.get('tasks')).to.be.empty;
  285. });
  286. });
  287. describe("#startAllServices()", function() {
  288. beforeEach(function () {
  289. sinon.stub(controller, 'startServices', Em.K);
  290. });
  291. afterEach(function () {
  292. controller.startServices.restore();
  293. });
  294. it("startServices is called with valid arguments", function () {
  295. controller.startAllServices();
  296. expect(controller.startServices.calledWith(true)).to.be.true;
  297. });
  298. });
  299. });