step6_controller_test.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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('No host-components', function () {
  70. controller.set('multiTaskCounter', 0);
  71. controller.set('hostComponents', []);
  72. controller.onComponentsTasksSuccess();
  73. expect(controller.get('multiTaskCounter')).to.equal(1);
  74. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  75. });
  76. it('One host-component', function () {
  77. controller.set('multiTaskCounter', 0);
  78. controller.set('hostComponents', [
  79. {}
  80. ]);
  81. controller.onComponentsTasksSuccess();
  82. expect(controller.get('multiTaskCounter')).to.equal(1);
  83. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  84. });
  85. it('two host-components', function () {
  86. controller.set('multiTaskCounter', 0);
  87. controller.set('hostComponents', [
  88. {},
  89. {}
  90. ]);
  91. controller.onComponentsTasksSuccess();
  92. expect(controller.get('multiTaskCounter')).to.equal(1);
  93. expect(controller.onTaskCompleted.called).to.be.false;
  94. });
  95. });
  96. describe('#loadStep()', function () {
  97. var isHaEnabled = true;
  98. beforeEach(function () {
  99. controller.set('content.reassign.service_id', 'service1');
  100. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  101. sinon.stub(controller, 'initializeTasks', Em.K);
  102. sinon.stub(App, 'get', function () {
  103. return isHaEnabled;
  104. });
  105. });
  106. afterEach(function () {
  107. controller.onTaskStatusChange.restore();
  108. controller.initializeTasks.restore();
  109. App.get.restore();
  110. });
  111. it('reassign component is NameNode and HA enabled', function () {
  112. isHaEnabled = true;
  113. controller.set('content.reassign.component_name', 'NAMENODE');
  114. controller.loadStep();
  115. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  116. });
  117. it('reassign component is NameNode and HA disabled', function () {
  118. isHaEnabled = false;
  119. controller.set('content.reassign.component_name', 'NAMENODE');
  120. controller.loadStep();
  121. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  122. });
  123. it('reassign component is RESOURCEMANAGER', function () {
  124. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  125. controller.loadStep();
  126. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  127. });
  128. });
  129. describe('#deleteHostComponents()', function () {
  130. it('No host components', function () {
  131. controller.set('hostComponents', []);
  132. controller.set('content.reassignHosts.source', 'host1');
  133. controller.deleteHostComponents();
  134. var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
  135. expect(args).not.exists;
  136. });
  137. it('delete two components', function () {
  138. controller.set('hostComponents', [1, 2]);
  139. controller.set('content.reassignHosts.source', 'host1');
  140. controller.deleteHostComponents();
  141. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  142. expect(args).to.have.property('length').equal(2);
  143. expect(args[0][0].data).to.eql({
  144. "hostName": "host1",
  145. "componentName": 1
  146. });
  147. expect(args[1][0].data).to.eql({
  148. "hostName": "host1",
  149. "componentName": 2
  150. });
  151. });
  152. });
  153. describe('#onDeleteHostComponentsError()', function () {
  154. beforeEach(function () {
  155. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  156. sinon.stub(controller, 'onTaskError', Em.K);
  157. });
  158. afterEach(function () {
  159. controller.onComponentsTasksSuccess.restore();
  160. controller.onTaskError.restore();
  161. });
  162. it('task success', function () {
  163. var error = {
  164. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  165. };
  166. controller.onDeleteHostComponentsError(error);
  167. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  168. });
  169. it('unknown error', function () {
  170. var error = {
  171. responseText: ''
  172. };
  173. controller.onDeleteHostComponentsError(error);
  174. expect(controller.onTaskError.calledOnce).to.be.true;
  175. });
  176. });
  177. describe('#stopMysqlService()', function () {
  178. it('stopMysqlService', function () {
  179. controller.stopMysqlService();
  180. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  181. expect(args[0]).exists;
  182. });
  183. });
  184. describe('#putHostComponentsInMaintenanceMode()', function () {
  185. beforeEach(function(){
  186. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  187. controller.set('content.reassignHosts.source', 'source');
  188. });
  189. afterEach(function(){
  190. controller.onComponentsTasksSuccess.restore();
  191. });
  192. it('No host-components', function () {
  193. controller.set('hostComponents', []);
  194. controller.putHostComponentsInMaintenanceMode();
  195. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  196. expect(args).not.exists;
  197. expect(controller.get('multiTaskCounter')).to.equal(0);
  198. });
  199. it('One host-components', function () {
  200. controller.set('hostComponents', [{}]);
  201. controller.putHostComponentsInMaintenanceMode();
  202. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  203. expect(args).exists;
  204. expect(controller.get('multiTaskCounter')).to.equal(0);
  205. });
  206. });
  207. describe("#removeTasks()", function() {
  208. it("no tasks to delete", function() {
  209. controller.set('tasks', [Em.Object.create()]);
  210. controller.removeTasks([]);
  211. expect(controller.get('tasks').length).to.equal(1);
  212. });
  213. it("one task to delete", function() {
  214. controller.set('tasks', [Em.Object.create({command: 'task1'})]);
  215. controller.removeTasks(['task1']);
  216. expect(controller.get('tasks')).to.be.empty;
  217. });
  218. });
  219. describe("#startAllServices()", function() {
  220. beforeEach(function () {
  221. sinon.stub(controller, 'startServices', Em.K);
  222. });
  223. afterEach(function () {
  224. controller.startServices.restore();
  225. });
  226. it("startServices is called with valid arguments", function () {
  227. controller.startAllServices();
  228. expect(controller.startServices.calledWith(true)).to.be.true;
  229. });
  230. });
  231. });