step2_controller_test.js 9.6 KB

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