step2_controller_test.js 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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/step2_controller');
  20. require('models/host_component');
  21. describe('App.ReassignMasterWizardStep2Controller', function () {
  22. var controller = App.ReassignMasterWizardStep2Controller.create({
  23. content: Em.Object.create({
  24. reassign: Em.Object.create({}),
  25. services: []
  26. }),
  27. renderComponents: Em.K,
  28. multipleComponents: []
  29. });
  30. controller.set('_super', Em.K);
  31. describe('#loadStep', function () {
  32. beforeEach(function () {
  33. sinon.stub(App.router, 'send', Em.K);
  34. sinon.stub(controller, 'loadStepCallback', Em.K);
  35. sinon.stub(controller, 'rebalanceSingleComponentHosts', Em.K);
  36. });
  37. afterEach(function () {
  38. controller.rebalanceSingleComponentHosts.restore();
  39. App.router.send.restore();
  40. controller.loadStepCallback.restore();
  41. });
  42. it('SECONDARY_NAMENODE is absent, reassign component is NAMENODE', function () {
  43. controller.set('content.reassign.component_name', 'NAMENODE');
  44. controller.set('content.masterComponentHosts', []);
  45. controller.loadStep();
  46. expect(controller.get('showCurrentHost')).to.be.false;
  47. expect(controller.get('componentToRebalance')).to.equal('NAMENODE');
  48. expect(controller.get('rebalanceComponentHostsCounter')).to.equal(1);
  49. });
  50. it('SECONDARY_NAMENODE is present, reassign component is NAMENODE', function () {
  51. controller.set('content.reassign.component_name', 'NAMENODE');
  52. controller.set('content.masterComponentHosts', [
  53. {
  54. component: 'SECONDARY_NAMENODE'
  55. }
  56. ]);
  57. controller.loadStep();
  58. expect(controller.get('showCurrentHost')).to.be.true;
  59. expect(controller.rebalanceSingleComponentHosts.calledWith('NAMENODE'));
  60. });
  61. it('SECONDARY_NAMENODE is absent, reassign component is not NAMENODE', function () {
  62. controller.set('content.reassign.component_name', 'COMP');
  63. controller.set('content.masterComponentHosts', []);
  64. controller.loadStep();
  65. expect(controller.get('showCurrentHost')).to.be.true;
  66. expect(controller.rebalanceSingleComponentHosts.calledWith('COMP'));
  67. });
  68. it('if HA is enabled then multipleComponents should contain NAMENODE', function () {
  69. sinon.stub(App,'get', function() {
  70. return true;
  71. });
  72. controller.loadStep();
  73. expect(controller.get('multipleComponents')).to.eql(['NAMENODE']);
  74. App.get.restore();
  75. });
  76. });
  77. describe('#loadComponents', function () {
  78. it('masterComponentHosts is empty', function () {
  79. controller.set('content.masterComponentHosts', []);
  80. controller.set('content.reassign.host_id', 1);
  81. expect(controller.loadComponents()).to.be.empty;
  82. expect(controller.get('currentHostId')).to.equal(1);
  83. });
  84. it('masterComponentHosts does not contain reassign component', function () {
  85. sinon.stub(App.HostComponent, 'find', function () {
  86. return [Em.Object.create({
  87. componentName: 'COMP1',
  88. serviceName: 'SERVICE'
  89. })];
  90. });
  91. controller.set('content.masterComponentHosts', [{
  92. component: 'COMP1',
  93. hostName: 'host1'
  94. }]);
  95. controller.set('content.reassign.host_id', 1);
  96. controller.set('content.reassign.component_name', 'COMP2');
  97. expect(controller.loadComponents()).to.eql([
  98. {
  99. "component_name": "COMP1",
  100. "display_name": "Comp1",
  101. "selectedHost": "host1",
  102. "isInstalled": true,
  103. "serviceId": "SERVICE",
  104. "isServiceCoHost": false,
  105. "color": "grey"
  106. }
  107. ]);
  108. expect(controller.get('currentHostId')).to.equal(1);
  109. App.HostComponent.find.restore();
  110. });
  111. it('masterComponentHosts contains reassign component', function () {
  112. sinon.stub(App.HostComponent, 'find', function () {
  113. return [Em.Object.create({
  114. componentName: 'COMP1',
  115. serviceName: 'SERVICE'
  116. })];
  117. });
  118. controller.set('content.masterComponentHosts', [{
  119. component: 'COMP1',
  120. hostName: 'host1'
  121. }]);
  122. controller.set('content.reassign.host_id', 1);
  123. controller.set('content.reassign.component_name', 'COMP1');
  124. expect(controller.loadComponents()).to.eql([
  125. {
  126. "component_name": "COMP1",
  127. "display_name": "Comp1",
  128. "selectedHost": "host1",
  129. "isInstalled": true,
  130. "serviceId": "SERVICE",
  131. "isServiceCoHost": false,
  132. "color": "green"
  133. }
  134. ]);
  135. expect(controller.get('currentHostId')).to.equal(1);
  136. App.HostComponent.find.restore();
  137. });
  138. });
  139. describe('#rebalanceSingleComponentHosts', function () {
  140. it('hosts is empty', function () {
  141. controller.set('hosts', []);
  142. expect(controller.rebalanceSingleComponentHosts()).to.be.false;
  143. });
  144. it('currentHostId matches one available host', function () {
  145. controller.set('hosts', [Em.Object.create({
  146. host_name: 'host1'
  147. })]);
  148. controller.set('currentHostId', 'host1');
  149. expect(controller.rebalanceSingleComponentHosts()).to.be.false;
  150. });
  151. var testCases = [
  152. {
  153. title: 'selectedHost = currentHostId and component_name = content.reassign.component_name',
  154. arguments: {
  155. selectedHost: 'host1',
  156. reassignComponentName: 'COMP1'
  157. },
  158. result: 'host3'
  159. },
  160. {
  161. title: 'selectedHost not equal to currentHostId and component_name = content.reassign.component_name',
  162. arguments: {
  163. selectedHost: 'host2',
  164. reassignComponentName: 'COMP1'
  165. },
  166. result: 'host2'
  167. },
  168. {
  169. title: 'selectedHost = currentHostId and component_name not equal to content.reassign.component_name',
  170. arguments: {
  171. selectedHost: 'host1',
  172. reassignComponentName: 'COMP2'
  173. },
  174. result: 'host1'
  175. }
  176. ];
  177. testCases.forEach(function (test) {
  178. it(test.title, function () {
  179. controller.set('hosts', [
  180. Em.Object.create({
  181. host_name: 'host3'
  182. }),
  183. Em.Object.create({
  184. host_name: 'host2'
  185. })
  186. ]);
  187. controller.set('currentHostId', 'host1');
  188. controller.set('content.reassign.component_name', test.arguments.reassignComponentName);
  189. controller.set('selectedServicesMasters', [Em.Object.create({
  190. component_name: 'COMP1',
  191. selectedHost: test.arguments.selectedHost
  192. })]);
  193. expect(controller.rebalanceSingleComponentHosts('COMP1')).to.be.true;
  194. expect(controller.get('selectedServicesMasters')[0].get('selectedHost')).to.equal(test.result);
  195. expect(controller.get('selectedServicesMasters')[0].get('availableHosts').mapProperty('host_name')).to.eql(['host2', 'host3']);
  196. });
  197. });
  198. });
  199. describe('#getIsSubmitDisabled', function () {
  200. var hostComponents = [];
  201. var isSubmitDisabled = false;
  202. beforeEach(function () {
  203. sinon.stub(App.HostComponent, 'find', function () {
  204. return hostComponents;
  205. });
  206. sinon.stub(controller, '_super', function() {
  207. return isSubmitDisabled;
  208. });
  209. });
  210. afterEach(function () {
  211. App.HostComponent.find.restore();
  212. controller._super.restore();
  213. });
  214. it('No host-components, reassigned equal 0', function () {
  215. expect(controller.getIsSubmitDisabled()).to.be.true;
  216. expect(controller.get('submitDisabled')).to.be.true;
  217. });
  218. it('Reassign component match existed components, reassigned equal 0', function () {
  219. controller.set('content.reassign.component_name', 'COMP1');
  220. hostComponents = [Em.Object.create({
  221. componentName: 'COMP1',
  222. hostName: 'host1'
  223. })];
  224. controller.set('servicesMasters', [{
  225. selectedHost: 'host1'
  226. }]);
  227. expect(controller.getIsSubmitDisabled()).to.be.true;
  228. expect(controller.get('submitDisabled')).to.be.true;
  229. });
  230. it('Reassign component do not match existed components, reassigned equal 1', function () {
  231. controller.set('content.reassign.component_name', 'COMP1');
  232. hostComponents = [Em.Object.create({
  233. componentName: 'COMP1',
  234. hostName: 'host1'
  235. })];
  236. controller.set('servicesMasters', []);
  237. expect(controller.getIsSubmitDisabled()).to.be.false;
  238. expect(controller.get('submitDisabled')).to.be.false;
  239. });
  240. it('Reassign component do not match existed components, reassigned equal 2', function () {
  241. controller.set('content.reassign.component_name', 'COMP1');
  242. hostComponents = [
  243. Em.Object.create({
  244. componentName: 'COMP1',
  245. hostName: 'host1'
  246. }),
  247. Em.Object.create({
  248. componentName: 'COMP1',
  249. hostName: 'host2'
  250. })
  251. ];
  252. controller.set('servicesMasters', []);
  253. expect(controller.getIsSubmitDisabled()).to.be.true;
  254. expect(controller.get('submitDisabled')).to.be.true;
  255. });
  256. it('submitDisabled is already true', function () {
  257. isSubmitDisabled = true;
  258. expect(controller.getIsSubmitDisabled()).to.be.true;
  259. expect(controller.get('submitDisabled')).to.be.true;
  260. });
  261. });
  262. });