host_test.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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. var hostsManagement = require('utils/hosts');
  21. require('utils/batch_scheduled_requests');
  22. require('controllers/main/host');
  23. require('mappers/server_data_mapper');
  24. describe('MainHostController', function () {
  25. var hostController, db;
  26. // @todo add unit tests after bulk ops reimplementing
  27. describe('#bulkOperation', function() {
  28. beforeEach(function() {
  29. hostController = App.MainHostController.create({});
  30. sinon.stub(hostController, 'bulkOperationForHostsRestart', Em.K);
  31. sinon.stub(hostController, 'bulkOperationForHosts', Em.K);
  32. sinon.stub(hostController, 'bulkOperationForHostComponentsRestart', Em.K);
  33. sinon.stub(hostController, 'bulkOperationForHostComponentsDecommission', Em.K);
  34. sinon.stub(hostController, 'bulkOperationForHostComponents', Em.K);
  35. sinon.stub(hostController, 'bulkOperationForHostsPassiveState', Em.K);
  36. });
  37. afterEach(function() {
  38. hostController.bulkOperationForHosts.restore();
  39. hostController.bulkOperationForHostsRestart.restore();
  40. hostController.bulkOperationForHostComponentsRestart.restore();
  41. hostController.bulkOperationForHostComponentsDecommission.restore();
  42. hostController.bulkOperationForHostComponents.restore();
  43. hostController.bulkOperationForHostsPassiveState.restore();
  44. });
  45. it('RESTART for hosts', function() {
  46. var operationData = {
  47. action: 'RESTART'
  48. };
  49. hostController.bulkOperation(operationData, []);
  50. expect(hostController.bulkOperationForHostsRestart.calledOnce).to.equal(true);
  51. });
  52. it('START for hosts', function() {
  53. var operationData = {
  54. action: 'STARTED'
  55. };
  56. hostController.bulkOperation(operationData, []);
  57. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  58. });
  59. it('STOP for hosts', function() {
  60. var operationData = {
  61. action: 'INSTALLED'
  62. };
  63. hostController.bulkOperation(operationData, []);
  64. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  65. });
  66. it('PASSIVE_STATE for hosts', function() {
  67. var operationData = {
  68. action: 'PASSIVE_STATE'
  69. };
  70. hostController.bulkOperation(operationData, []);
  71. expect(hostController.bulkOperationForHostsPassiveState.calledOnce).to.equal(true);
  72. });
  73. it('RESTART for hostComponents', function() {
  74. var operationData = {
  75. action: 'RESTART',
  76. componentNameFormatted: 'DataNodes'
  77. };
  78. hostController.bulkOperation(operationData, []);
  79. expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.equal(true);
  80. });
  81. it('START for hostComponents', function() {
  82. var operationData = {
  83. action: 'STARTED',
  84. componentNameFormatted: 'DataNodes'
  85. };
  86. hostController.bulkOperation(operationData, []);
  87. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  88. });
  89. it('STOP for hostComponents', function() {
  90. var operationData = {
  91. action: 'INSTALLED',
  92. componentNameFormatted: 'DataNodes'
  93. };
  94. hostController.bulkOperation(operationData, []);
  95. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  96. });
  97. it('DECOMMISSION for hostComponents', function() {
  98. var operationData = {
  99. action: 'DECOMMISSION',
  100. componentNameFormatted: 'DataNodes'
  101. };
  102. hostController.bulkOperation(operationData, []);
  103. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  104. });
  105. it('RECOMMISSION for hostComponents', function() {
  106. var operationData = {
  107. action: 'DECOMMISSION_OFF',
  108. componentNameFormatted: 'DataNodes'
  109. };
  110. hostController.bulkOperation(operationData, []);
  111. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  112. });
  113. });
  114. describe('#getRegExp()', function() {
  115. before(function() {
  116. hostController = App.MainHostController.create({});
  117. });
  118. var message = '`{0}` should convert to `{1}`',
  119. tests = [
  120. { value: '.*', expected: '.*' },
  121. { value: '.', expected: '.*' },
  122. { value: '.*.*', expected: '.*' },
  123. { value: '*', expected: '^$' },
  124. { value: '........', expected: '.*' },
  125. { value: '........*', expected: '.*' },
  126. { value: 'a1', expected: '.*a1.*' },
  127. { value: 'a1.', expected: '.*a1.*' },
  128. { value: 'a1...', expected: '.*a1.*' },
  129. { value: 'a1.*', expected: '.*a1.*' },
  130. { value: 'a1.*.a2.a3', expected: '.*a1.*.a2.a3.*' },
  131. { value: 'a1.*.a2...a3', expected: '.*a1.*.a2...a3.*' }
  132. ];
  133. tests.forEach(function(test){
  134. it(message.format(test.value, test.expected), function() {
  135. expect(hostController.getRegExp(test.value)).to.be.equal(test.expected);
  136. });
  137. });
  138. });
  139. describe('#warnBeforeDecommissionSuccess()', function () {
  140. var mock = {
  141. showHbaseActiveWarning: Em.K,
  142. checkRegionServerState: Em.K
  143. };
  144. beforeEach(function () {
  145. hostController = App.MainHostController.create({});
  146. sinon.stub(App.router, 'get', function () {
  147. return mock;
  148. });
  149. sinon.spy(mock, 'showHbaseActiveWarning');
  150. sinon.spy(mock, 'checkRegionServerState');
  151. });
  152. afterEach(function () {
  153. App.router.get.restore();
  154. mock.showHbaseActiveWarning.restore();
  155. mock.checkRegionServerState.restore();
  156. });
  157. it('items length more than 0', function () {
  158. hostController.warnBeforeDecommissionSuccess({items: [1]}, {}, {});
  159. expect(mock.showHbaseActiveWarning.calledOnce).to.be.true;
  160. });
  161. it('items length equal 0', function () {
  162. hostController.warnBeforeDecommissionSuccess({items: []}, {}, {hostNames: 'host1'});
  163. expect(mock.checkRegionServerState.calledWith('host1')).to.be.true;
  164. });
  165. });
  166. describe('#getQueryParameters', function() {
  167. beforeEach(function() {
  168. hostController = App.MainHostController.create({});
  169. sinon.spy(hostController, 'getRegExp');
  170. sinon.stub(App.db, 'getFilterConditions', function() {
  171. return [{
  172. iColumn: 1,
  173. skipFilter: false,
  174. type: "string",
  175. value: "someval"
  176. }];
  177. });
  178. });
  179. afterEach(function() {
  180. App.db.getFilterConditions.restore();
  181. hostController.getRegExp.restore();
  182. });
  183. it('should call #getRegExp with value `someval` on host name filter', function() {
  184. hostController.getQueryParameters();
  185. expect(hostController.getRegExp.calledWith('someval')).to.ok;
  186. });
  187. it('result should include host name filter converted value', function() {
  188. expect(hostController.getQueryParameters().findProperty('key', 'Hosts/host_name').value).to.equal('.*someval.*');
  189. });
  190. });
  191. describe('#getSortProps', function () {
  192. beforeEach(function () {
  193. db = {mainHostController: [
  194. {name: 'hostName', status: 'sorting'}
  195. ]};
  196. hostController = App.MainHostController.create({});
  197. sinon.stub(App.db, 'getSortingStatuses', function (k) {
  198. return db[k];
  199. });
  200. sinon.stub(App.db, 'setSortingStatuses', function (k, v) {
  201. db[k] = Em.typeOf(v) === 'array' ? v : [v];
  202. });
  203. });
  204. afterEach(function () {
  205. App.db.getSortingStatuses.restore();
  206. App.db.setSortingStatuses.restore();
  207. });
  208. it('should set default sorting condition', function () {
  209. hostController.getSortProps();
  210. expect(db.mainHostController).to.eql([{name: 'hostName', status: 'sorting_asc'}]);
  211. });
  212. });
  213. describe('#setRackId', function () {
  214. beforeEach(function () {
  215. sinon.stub(hostsManagement, 'setRackInfo', Em.K);
  216. });
  217. afterEach(function () {
  218. hostsManagement.setRackInfo.restore();
  219. });
  220. it('should call setRackInfo with appropriate arguments', function () {
  221. var mockedHost = Em.Object.create({
  222. rack: 'rackId'
  223. });
  224. hostController.setRackId({
  225. context: mockedHost
  226. });
  227. expect(hostsManagement.setRackInfo.calledWith({message: Em.I18n.t('hosts.host.details.setRackId')}, [mockedHost], 'rackId')).to.be.true;
  228. });
  229. });
  230. });