host_test.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. require('mappers/server_data_mapper');
  24. describe('MainHostController', function () {
  25. var hostController;
  26. // @todo add unit tests after bulk ops reimplementing
  27. describe.skip('#bulkOperation', function() {
  28. beforeEach(function() {
  29. hostController = App.MainHostController.create({
  30. bulkOperationForHostsRestart: function(){},
  31. bulkOperationForHosts: function(){},
  32. bulkOperationForHostComponentsRestart: function(){},
  33. bulkOperationForHostComponentsDecommission: function(){},
  34. bulkOperationForHostComponents: function(){},
  35. bulkOperationForHostsPassiveState: function(){}
  36. });
  37. sinon.spy(hostController, 'bulkOperationForHostsRestart');
  38. sinon.spy(hostController, 'bulkOperationForHosts');
  39. sinon.spy(hostController, 'bulkOperationForHostComponentsRestart');
  40. sinon.spy(hostController, 'bulkOperationForHostComponentsDecommission');
  41. sinon.spy(hostController, 'bulkOperationForHostComponents');
  42. sinon.spy(hostController, 'bulkOperationForHostsPassiveState');
  43. });
  44. afterEach(function() {
  45. hostController.bulkOperationForHosts.restore();
  46. hostController.bulkOperationForHostsRestart.restore();
  47. hostController.bulkOperationForHostComponentsRestart.restore();
  48. hostController.bulkOperationForHostComponentsDecommission.restore();
  49. hostController.bulkOperationForHostComponents.restore();
  50. hostController.bulkOperationForHostsPassiveState.restore();
  51. });
  52. it('RESTART for hosts', function() {
  53. var operationData = {
  54. action: 'RESTART'
  55. };
  56. hostController.bulkOperation(operationData, []);
  57. expect(hostController.bulkOperationForHostsRestart.calledOnce).to.equal(true);
  58. });
  59. it('START for hosts', function() {
  60. var operationData = {
  61. action: 'STARTED'
  62. };
  63. hostController.bulkOperation(operationData, []);
  64. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  65. });
  66. it('STOP for hosts', function() {
  67. var operationData = {
  68. action: 'INSTALLED'
  69. };
  70. hostController.bulkOperation(operationData, []);
  71. expect(hostController.bulkOperationForHosts.calledOnce).to.equal(true);
  72. });
  73. it('PASSIVE_STATE for hosts', function() {
  74. var operationData = {
  75. action: 'PASSIVE_STATE'
  76. };
  77. hostController.bulkOperation(operationData, []);
  78. expect(hostController.bulkOperationForHostsPassiveState.calledOnce).to.equal(true);
  79. });
  80. it('RESTART for hostComponents', function() {
  81. var operationData = {
  82. action: 'RESTART',
  83. componentNameFormatted: 'DataNodes'
  84. };
  85. hostController.bulkOperation(operationData, []);
  86. expect(hostController.bulkOperationForHostComponentsRestart.calledOnce).to.equal(true);
  87. });
  88. it('START for hostComponents', function() {
  89. var operationData = {
  90. action: 'STARTED',
  91. componentNameFormatted: 'DataNodes'
  92. };
  93. hostController.bulkOperation(operationData, []);
  94. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  95. });
  96. it('STOP for hostComponents', function() {
  97. var operationData = {
  98. action: 'INSTALLED',
  99. componentNameFormatted: 'DataNodes'
  100. };
  101. hostController.bulkOperation(operationData, []);
  102. expect(hostController.bulkOperationForHostComponents.calledOnce).to.equal(true);
  103. });
  104. it('DECOMMISSION for hostComponents', function() {
  105. var operationData = {
  106. action: 'DECOMMISSION',
  107. componentNameFormatted: 'DataNodes'
  108. };
  109. hostController.bulkOperation(operationData, []);
  110. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  111. });
  112. it('RECOMMISSION for hostComponents', function() {
  113. var operationData = {
  114. action: 'DECOMMISSION_OFF',
  115. componentNameFormatted: 'DataNodes'
  116. };
  117. hostController.bulkOperation(operationData, []);
  118. expect(hostController.bulkOperationForHostComponentsDecommission.calledOnce).to.equal(true);
  119. });
  120. });
  121. // @todo add unit tests after bulk ops reimplementing
  122. describe.skip('#bulkOperationForHosts', function() {
  123. beforeEach(function(){
  124. hostController = App.MainHostController.create({});
  125. sinon.spy($, 'ajax');
  126. });
  127. afterEach(function() {
  128. $.ajax.restore();
  129. });
  130. var tests = [
  131. {
  132. operationData: {},
  133. hosts: [],
  134. m: 'no hosts',
  135. e: false
  136. },
  137. {
  138. operationData: {
  139. actionToCheck: 'STARTED'
  140. },
  141. hosts: [
  142. Em.Object.create({
  143. hostComponents: Em.A([
  144. Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'NAMENODE', passiveState: 'OFF'}),
  145. Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE', passiveState: 'OFF'})
  146. ])
  147. })
  148. ],
  149. m: '1 host. components are in proper state',
  150. e: true
  151. },
  152. {
  153. operationData: {
  154. actionToCheck: 'INSTALLED'
  155. },
  156. hosts: [
  157. Em.Object.create({
  158. hostComponents: Em.A([
  159. Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'NAMENODE', passiveState: 'OFF'}),
  160. Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE', passiveState: 'OFF'})
  161. ])
  162. })
  163. ],
  164. m: '1 host. components are not in proper state',
  165. e: false
  166. },
  167. {
  168. operationData: {
  169. actionToCheck: 'INSTALLED'
  170. },
  171. hosts: [
  172. Em.Object.create({
  173. hostComponents: Em.A([
  174. Em.Object.create({isMaster: true, isSlave: false, host: {hostName:'host1'}, workStatus: 'INSTALLED', componentName: 'NAMENODE', passiveState: 'OFF'}),
  175. Em.Object.create({isMaster: false, isSlave: true, host: {hostName:'host1'}, workStatus: 'STARTED', componentName: 'DATANODE', passiveState: 'OFF'})
  176. ])
  177. })
  178. ],
  179. m: '1 host. some components are in proper state',
  180. e: true
  181. }
  182. ];
  183. tests.forEach(function(test) {
  184. it(test.m, function() {
  185. hostController.bulkOperationForHosts(test.operationData, test.hosts);
  186. expect($.ajax.called).to.equal(test.e);
  187. });
  188. });
  189. });
  190. // @todo add unit tests after bulk ops reimplementing
  191. describe.skip('#bulkOperationForHostsRestart', function() {
  192. beforeEach(function(){
  193. hostController = App.MainHostController.create({});
  194. sinon.spy($, 'ajax');
  195. });
  196. afterEach(function() {
  197. $.ajax.restore();
  198. });
  199. var tests = Em.A([
  200. {
  201. hosts: Em.A([]),
  202. m: 'No hosts',
  203. e: false
  204. },
  205. {
  206. hosts: Em.A([
  207. Em.Object.create({
  208. hostComponents: Em.A([Em.Object.create({passiveState: 'OFF'}), Em.Object.create({passiveState: 'OFF'})])
  209. })
  210. ]),
  211. m: 'One host',
  212. e: true
  213. }
  214. ]);
  215. tests.forEach(function(test) {
  216. it(test.m, function() {
  217. hostController.bulkOperationForHostsRestart({}, test.hosts);
  218. expect($.ajax.calledOnce).to.equal(test.e)
  219. });
  220. });
  221. });
  222. // @todo add unit tests after bulk ops reimplementing
  223. describe.skip('#bulkOperationForHostsPassiveState', function() {
  224. beforeEach(function(){
  225. hostController = App.MainHostController.create({});
  226. sinon.spy($, 'ajax');
  227. });
  228. afterEach(function() {
  229. $.ajax.restore();
  230. });
  231. var tests = [
  232. {
  233. hosts: Em.A([]),
  234. operationData: {},
  235. m: 'No hosts',
  236. e: false
  237. },
  238. {
  239. hosts: Em.A([
  240. Em.Object.create({
  241. passiveState: 'OFF'
  242. })
  243. ]),
  244. operationData: {
  245. state: 'OFF'
  246. },
  247. m: 'One host, but in state that should get',
  248. e: false
  249. },
  250. {
  251. hosts: Em.A([
  252. Em.Object.create({
  253. passiveState: 'OFF'
  254. })
  255. ]),
  256. operationData: {
  257. state: 'ON'
  258. },
  259. m: 'One host with proper state',
  260. e: true
  261. }
  262. ];
  263. tests.forEach(function(test) {
  264. it(test.m, function() {
  265. hostController.bulkOperationForHostsPassiveState(test.operationData, test.hosts);
  266. expect($.ajax.calledOnce).to.equal(test.e)
  267. });
  268. });
  269. });
  270. describe('#getRegExp()', function() {
  271. before(function() {
  272. hostController = App.MainHostController.create({});
  273. });
  274. var message = '`{0}` should convert to `{1}`',
  275. tests = [
  276. { value: '.*', expected: '.*' },
  277. { value: '.', expected: '.*' },
  278. { value: '.*.*', expected: '.*' },
  279. { value: '*', expected: '^$' },
  280. { value: '........', expected: '.*' },
  281. { value: '........*', expected: '.*' },
  282. { value: 'a1', expected: '.*a1.*' },
  283. { value: 'a1.', expected: '.*a1.*' },
  284. { value: 'a1...', expected: '.*a1.*' },
  285. { value: 'a1.*', expected: '.*a1.*' },
  286. { value: 'a1.*.a2.a3', expected: '.*a1.*.a2.a3.*' },
  287. { value: 'a1.*.a2...a3', expected: '.*a1.*.a2...a3.*' }
  288. ]
  289. tests.forEach(function(test){
  290. it(message.format(test.value, test.expected), function() {
  291. expect(hostController.getRegExp(test.value)).to.be.equal(test.expected);
  292. });
  293. });
  294. });
  295. });