step6_controller_test.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. describe('App.ReassignMasterWizardStep6Controller', function () {
  22. beforeEach(function () {
  23. controller = App.ReassignMasterWizardStep6Controller.create({
  24. content: Em.Object.create({
  25. reassign: Em.Object.create(),
  26. reassignHosts: Em.Object.create()
  27. }),
  28. startServices: Em.K
  29. });
  30. sinon.stub(App.ajax, 'send', Em.K);
  31. });
  32. afterEach(function () {
  33. App.ajax.send.restore();
  34. });
  35. describe('#initializeTasks()', function () {
  36. it('No commands', function () {
  37. controller.set('commands', []);
  38. controller.set('hostComponents', []);
  39. controller.initializeTasks();
  40. expect(controller.get('tasks')).to.be.empty;
  41. });
  42. it('One command', function () {
  43. controller.set('commands', ['COMMAND1']);
  44. controller.initializeTasks();
  45. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  46. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  47. });
  48. });
  49. describe('#hideRollbackButton()', function () {
  50. it('No showRollback command', function () {
  51. controller.set('tasks', [Em.Object.create({
  52. showRollback: false
  53. })]);
  54. controller.hideRollbackButton();
  55. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  56. });
  57. it('showRollback command is present', function () {
  58. controller.set('tasks', [Em.Object.create({
  59. showRollback: true
  60. })]);
  61. controller.hideRollbackButton();
  62. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  63. });
  64. });
  65. describe('#onComponentsTasksSuccess()', function () {
  66. beforeEach(function () {
  67. sinon.stub(controller, 'onTaskCompleted', Em.K);
  68. });
  69. afterEach(function () {
  70. controller.onTaskCompleted.restore();
  71. });
  72. it('No host-components', function () {
  73. controller.set('multiTaskCounter', 0);
  74. controller.set('hostComponents', []);
  75. controller.onComponentsTasksSuccess();
  76. expect(controller.get('multiTaskCounter')).to.equal(1);
  77. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  78. });
  79. it('One host-component', function () {
  80. controller.set('multiTaskCounter', 0);
  81. controller.set('hostComponents', [
  82. {}
  83. ]);
  84. controller.onComponentsTasksSuccess();
  85. expect(controller.get('multiTaskCounter')).to.equal(1);
  86. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  87. });
  88. it('two host-components', function () {
  89. controller.set('multiTaskCounter', 0);
  90. controller.set('hostComponents', [
  91. {},
  92. {}
  93. ]);
  94. controller.onComponentsTasksSuccess();
  95. expect(controller.get('multiTaskCounter')).to.equal(1);
  96. expect(controller.onTaskCompleted.called).to.be.false;
  97. });
  98. });
  99. describe('#loadStep()', function () {
  100. var isHaEnabled = true;
  101. beforeEach(function () {
  102. controller.set('content.reassign.service_id', 'service1');
  103. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  104. sinon.stub(controller, 'initializeTasks', Em.K);
  105. sinon.stub(App, 'get', function () {
  106. return isHaEnabled;
  107. });
  108. });
  109. afterEach(function () {
  110. controller.onTaskStatusChange.restore();
  111. controller.initializeTasks.restore();
  112. App.get.restore();
  113. });
  114. it('reassign component is NameNode and HA enabled', function () {
  115. isHaEnabled = true;
  116. controller.set('content.reassign.component_name', 'NAMENODE');
  117. controller.loadStep();
  118. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  119. });
  120. it('reassign component is NameNode and HA disabled', function () {
  121. isHaEnabled = false;
  122. controller.set('content.reassign.component_name', 'NAMENODE');
  123. controller.loadStep();
  124. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  125. });
  126. it('reassign component is RESOURCEMANAGER', function () {
  127. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  128. controller.loadStep();
  129. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  130. });
  131. });
  132. describe('#deleteHostComponents()', function () {
  133. it('No host components', function () {
  134. controller.set('hostComponents', []);
  135. controller.set('content.reassignHosts.source', 'host1');
  136. controller.deleteHostComponents();
  137. expect(App.ajax.send.called).to.be.false;
  138. });
  139. it('delete two components', function () {
  140. controller.set('hostComponents', [1, 2]);
  141. controller.set('content.reassignHosts.source', 'host1');
  142. controller.deleteHostComponents();
  143. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  144. "hostName": "host1",
  145. "componentName": 1
  146. });
  147. expect(App.ajax.send.getCall(1).args[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. expect(App.ajax.send.calledOnce).to.be.true;
  181. });
  182. });
  183. describe('#putHostComponentsInMaintenanceMode()', function () {
  184. beforeEach(function(){
  185. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  186. controller.set('content.reassignHosts.source', 'source');
  187. });
  188. afterEach(function(){
  189. controller.onComponentsTasksSuccess.restore();
  190. });
  191. it('No host-components', function () {
  192. controller.set('hostComponents', []);
  193. controller.putHostComponentsInMaintenanceMode();
  194. expect(App.ajax.send.called).to.be.false;
  195. expect(controller.get('multiTaskCounter')).to.equal(0);
  196. });
  197. it('One host-components', function () {
  198. controller.set('hostComponents', [{}]);
  199. controller.putHostComponentsInMaintenanceMode();
  200. expect(App.ajax.send.calledOnce).to.be.true;
  201. expect(controller.get('multiTaskCounter')).to.equal(0);
  202. });
  203. });
  204. describe("#removeTasks()", function() {
  205. it("no tasks to delete", function() {
  206. controller.set('tasks', [Em.Object.create()]);
  207. controller.removeTasks([]);
  208. expect(controller.get('tasks').length).to.equal(1);
  209. });
  210. it("one task to delete", function() {
  211. controller.set('tasks', [Em.Object.create({command: 'task1'})]);
  212. controller.removeTasks(['task1']);
  213. expect(controller.get('tasks')).to.be.empty;
  214. });
  215. });
  216. describe("#startAllServices()", function() {
  217. beforeEach(function () {
  218. sinon.stub(controller, 'startServices', Em.K);
  219. });
  220. afterEach(function () {
  221. controller.startServices.restore();
  222. });
  223. it("", function () {
  224. controller.startAllServices();
  225. expect(controller.startServices.calledWith(true)).to.be.true;
  226. });
  227. });
  228. });