host_test.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. var validator = require('utils/validator');
  20. require('utils/component');
  21. require('utils/batch_scheduled_requests');
  22. require('controllers/main/host');
  23. describe('MainHostController', function () {
  24. var hostController;
  25. describe('#bulkOperation', function() {
  26. beforeEach(function() {
  27. hostController = App.MainHostController.create({
  28. bulkOperationForHostsRestart: function(){},
  29. bulkOperationForHosts: function(){},
  30. bulkOperationForHostComponentsRestart: function(){},
  31. bulkOperationForHostComponentsDecommission: function(){},
  32. bulkOperationForHostComponents: function(){}
  33. });
  34. sinon.spy(hostController, 'bulkOperationForHostsRestart');
  35. sinon.spy(hostController, 'bulkOperationForHosts');
  36. sinon.spy(hostController, 'bulkOperationForHostComponentsRestart');
  37. sinon.spy(hostController, 'bulkOperationForHostComponentsDecommission');
  38. sinon.spy(hostController, 'bulkOperationForHostComponents');
  39. });
  40. afterEach(function() {
  41. hostController.bulkOperationForHosts.restore();
  42. hostController.bulkOperationForHostsRestart.restore();
  43. hostController.bulkOperationForHostComponentsRestart.restore();
  44. hostController.bulkOperationForHostComponentsDecommission.restore();
  45. hostController.bulkOperationForHostComponents.restore();
  46. });
  47. it('RESTART for hosts', function() {
  48. var operationData = {
  49. action: 'RESTART'
  50. };
  51. hostController.bulkOperation(operationData, []);
  52. expect(hostController.bulkOperationForHostsRestart.calledOnce).to.be.true;
  53. });
  54. it('START for hosts', function() {
  55. var operationData = {
  56. action: 'STARTED'
  57. };
  58. hostController.bulkOperation(operationData, []);
  59. expect(hostController.bulkOperationForHosts.calledOnce).to.be.true;
  60. });
  61. it('STOP for hosts', function() {
  62. var operationData = {
  63. action: 'INSTALLED'
  64. };
  65. hostController.bulkOperation(operationData, []);
  66. expect(hostController.bulkOperationForHosts.calledOnce).to.be.true;
  67. });
  68. it('RESTART for hostComponents', function() {
  69. var operationData = {
  70. action: 'RESTART',
  71. componentNameFormatted: 'DataNodes'
  72. };
  73. hostController.bulkOperation(operationData, []);
  74. expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.be.true;
  75. });
  76. it('START for hostComponents', function() {
  77. var operationData = {
  78. action: 'STARTED',
  79. componentNameFormatted: 'DataNodes'
  80. };
  81. hostController.bulkOperation(operationData, []);
  82. expect(hostController.bulkOperationForHostComponents.calledOnce).to.be.true;
  83. });
  84. it('STOP for hostComponents', function() {
  85. var operationData = {
  86. action: 'INSTALLED',
  87. componentNameFormatted: 'DataNodes'
  88. };
  89. hostController.bulkOperation(operationData, []);
  90. expect(hostController.bulkOperationForHostComponents.calledOnce).to.be.true;
  91. });
  92. it('DECOMMISSION for hostComponents', function() {
  93. var operationData = {
  94. action: 'DECOMMISSION',
  95. componentNameFormatted: 'DataNodes'
  96. };
  97. hostController.bulkOperation(operationData, []);
  98. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.be.true;
  99. });
  100. it('RECOMMISSION for hostComponents', function() {
  101. var operationData = {
  102. action: 'DECOMMISSION_OFF',
  103. componentNameFormatted: 'DataNodes'
  104. };
  105. hostController.bulkOperation(operationData, []);
  106. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.be.true;
  107. });
  108. });
  109. describe('#bulkOperationForHosts', function() {
  110. beforeEach(function(){
  111. hostController = App.MainHostController.create({});
  112. sinon.spy($, 'ajax');
  113. });
  114. afterEach(function() {
  115. $.ajax.restore();
  116. });
  117. var tests = [
  118. {
  119. operationData: {},
  120. hosts: [],
  121. m: 'no hosts',
  122. e: false
  123. },
  124. {
  125. operationData: {
  126. actionToCheck: 'STARTED'
  127. },
  128. hosts: [
  129. Em.Object.create({
  130. hostComponents: Em.A([
  131. Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'NAMENODE'}),
  132. Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE'})
  133. ])
  134. })
  135. ],
  136. m: '1 host. components are in proper state',
  137. e: true
  138. },
  139. {
  140. operationData: {
  141. actionToCheck: 'INSTALLED'
  142. },
  143. hosts: [
  144. Em.Object.create({
  145. hostComponents: Em.A([
  146. Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'NAMENODE'}),
  147. Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE'})
  148. ])
  149. })
  150. ],
  151. m: '1 host. components are not in proper state',
  152. e: false
  153. },
  154. {
  155. operationData: {
  156. actionToCheck: 'INSTALLED'
  157. },
  158. hosts: [
  159. Em.Object.create({
  160. hostComponents: Em.A([
  161. Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'INSTALLED', componentName: 'NAMENODE'}),
  162. Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE'})
  163. ])
  164. })
  165. ],
  166. m: '1 host. some components are in proper state',
  167. e: true
  168. }
  169. ];
  170. tests.forEach(function(test) {
  171. it(test.m, function() {
  172. hostController.bulkOperationForHosts(test.operationData, test.hosts);
  173. expect($.ajax.called).to.equal(test.e);
  174. });
  175. });
  176. });
  177. describe('#bulkOperationForHostsRestart', function() {
  178. beforeEach(function(){
  179. hostController = App.MainHostController.create({});
  180. sinon.spy($, 'ajax');
  181. });
  182. afterEach(function() {
  183. $.ajax.restore();
  184. });
  185. var tests = [
  186. {
  187. hosts: Em.A([]),
  188. m: 'No hosts',
  189. e: false
  190. },
  191. {
  192. hosts: Em.A([
  193. Em.Object.create({
  194. hostComponents: Em.A([Em.Object.create({}), Em.Object.create({})])
  195. })
  196. ]),
  197. m: 'One host',
  198. e: true
  199. }
  200. ];
  201. tests.forEach(function(test) {
  202. it(test.m, function() {
  203. hostController.bulkOperationForHostsRestart({}, test.hosts);
  204. expect($.ajax.calledOnce).to.equal(test.e)
  205. });
  206. });
  207. });
  208. });