bulk_operations_controller_test.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. describe('BulkOperationsController', function () {
  20. var hostController;
  21. describe('#bulkOperation', function() {
  22. beforeEach(function() {
  23. hostController = App.BulkOperationsController.create({});
  24. sinon.stub(hostController, 'bulkOperationForHostsRestart', Em.K);
  25. sinon.stub(hostController, 'bulkOperationForHosts', Em.K);
  26. sinon.stub(hostController, 'bulkOperationForHostsReinstall', Em.K);
  27. sinon.stub(hostController, 'bulkOperationForHostComponentsRestart', Em.K);
  28. sinon.stub(hostController, 'bulkOperationForHostComponentsDecommission', Em.K);
  29. sinon.stub(hostController, 'bulkOperationForHostComponents', Em.K);
  30. sinon.stub(hostController, 'bulkOperationForHostComponentsAdd', Em.K);
  31. sinon.stub(hostController, 'bulkOperationForHostsPassiveState', Em.K);
  32. });
  33. afterEach(function() {
  34. hostController.bulkOperationForHosts.restore();
  35. hostController.bulkOperationForHostsRestart.restore();
  36. hostController.bulkOperationForHostsReinstall.restore();
  37. hostController.bulkOperationForHostComponentsRestart.restore();
  38. hostController.bulkOperationForHostComponentsDecommission.restore();
  39. hostController.bulkOperationForHostComponents.restore();
  40. hostController.bulkOperationForHostComponentsAdd.restore();
  41. hostController.bulkOperationForHostsPassiveState.restore();
  42. });
  43. it('RESTART for hosts', function() {
  44. var operationData = {
  45. action: 'RESTART'
  46. };
  47. hostController.bulkOperation(operationData, []);
  48. expect(hostController.bulkOperationForHostsRestart.calledOnce).to.equal(true);
  49. });
  50. it('START for hosts', function() {
  51. var operationData = {
  52. action: 'STARTED'
  53. };
  54. hostController.bulkOperation(operationData, []);
  55. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  56. });
  57. it('STOP for hosts', function() {
  58. var operationData = {
  59. action: 'INSTALLED'
  60. };
  61. hostController.bulkOperation(operationData, []);
  62. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  63. });
  64. it('REINSTALL for hosts', function() {
  65. var operationData = {
  66. action: 'REINSTALL'
  67. };
  68. hostController.bulkOperation(operationData, []);
  69. expect(hostController.bulkOperationForHostsReinstall.calledOnce).to.equal(true);
  70. });
  71. it('PASSIVE_STATE for hosts', function() {
  72. var operationData = {
  73. action: 'PASSIVE_STATE'
  74. };
  75. hostController.bulkOperation(operationData, []);
  76. expect(hostController.bulkOperationForHostsPassiveState.calledOnce).to.equal(true);
  77. });
  78. it('RESTART for hostComponents', function() {
  79. var operationData = {
  80. action: 'RESTART',
  81. componentNameFormatted: 'DataNodes'
  82. };
  83. hostController.bulkOperation(operationData, []);
  84. expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.equal(true);
  85. });
  86. it('START for hostComponents', function() {
  87. var operationData = {
  88. action: 'STARTED',
  89. componentNameFormatted: 'DataNodes'
  90. };
  91. hostController.bulkOperation(operationData, []);
  92. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  93. });
  94. it('STOP for hostComponents', function() {
  95. var operationData = {
  96. action: 'INSTALLED',
  97. componentNameFormatted: 'DataNodes'
  98. };
  99. hostController.bulkOperation(operationData, []);
  100. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  101. });
  102. it('ADD for hostComponents', function() {
  103. var operationData = {
  104. action: 'ADD',
  105. componentNameFormatted: 'DataNodes'
  106. };
  107. hostController.bulkOperation(operationData, []);
  108. expect(hostController.bulkOperationForHostComponentsAdd.calledOnce).to.equal(true);
  109. });
  110. it('DECOMMISSION for hostComponents', function() {
  111. var operationData = {
  112. action: 'DECOMMISSION',
  113. componentNameFormatted: 'DataNodes'
  114. };
  115. hostController.bulkOperation(operationData, []);
  116. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  117. });
  118. it('RECOMMISSION for hostComponents', function() {
  119. var operationData = {
  120. action: 'DECOMMISSION_OFF',
  121. componentNameFormatted: 'DataNodes'
  122. };
  123. hostController.bulkOperation(operationData, []);
  124. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  125. });
  126. });
  127. describe('#warnBeforeDecommissionSuccess()', function () {
  128. var mock = {
  129. showHbaseActiveWarning: Em.K,
  130. checkRegionServerState: Em.K
  131. };
  132. beforeEach(function () {
  133. hostController = App.BulkOperationsController.create({});
  134. sinon.stub(App.router, 'get', function () {
  135. return mock;
  136. });
  137. sinon.spy(mock, 'showHbaseActiveWarning');
  138. sinon.spy(mock, 'checkRegionServerState');
  139. });
  140. afterEach(function () {
  141. App.router.get.restore();
  142. mock.showHbaseActiveWarning.restore();
  143. mock.checkRegionServerState.restore();
  144. });
  145. it('items length more than 0', function () {
  146. hostController.warnBeforeDecommissionSuccess({items: [1]}, {}, {});
  147. expect(mock.showHbaseActiveWarning.calledOnce).to.be.true;
  148. });
  149. it('items length equal 0', function () {
  150. hostController.warnBeforeDecommissionSuccess({items: []}, {}, {hostNames: 'host1'});
  151. expect(mock.checkRegionServerState.calledWith('host1')).to.be.true;
  152. });
  153. });
  154. });