highAvailability_controller_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. require('controllers/main/admin/highAvailability_controller');
  20. require('models/host_component');
  21. require('models/host');
  22. require('utils/ajax/ajax');
  23. describe('App.MainAdminHighAvailabilityController', function () {
  24. var controller = App.MainAdminHighAvailabilityController.create();
  25. describe('#enableHighAvailability()', function () {
  26. var hostComponents = [];
  27. beforeEach(function () {
  28. sinon.stub(App.HostComponent, 'find', function(){
  29. return hostComponents;
  30. });
  31. sinon.spy(controller, "showErrorPopup");
  32. });
  33. afterEach(function () {
  34. controller.showErrorPopup.restore();
  35. App.HostComponent.find.restore();
  36. });
  37. it('Security enabled', function () {
  38. controller.set('securityEnabled', true);
  39. expect(controller.enableHighAvailability()).to.be.false;
  40. expect(controller.showErrorPopup.calledOnce).to.be.true;
  41. });
  42. it('NAMENODE in INSTALLED state', function () {
  43. controller.set('securityEnabled', false);
  44. hostComponents = [
  45. Em.Object.create({
  46. componentName: 'NAMENODE',
  47. workStatus: 'INSTALLED'
  48. }),
  49. Em.Object.create({
  50. componentName: 'ZOOKEEPER_SERVER',
  51. workStatus: 'INSTALLED'
  52. }),
  53. Em.Object.create({
  54. componentName: 'ZOOKEEPER_SERVER',
  55. workStatus: 'INSTALLED'
  56. }),
  57. Em.Object.create({
  58. componentName: 'ZOOKEEPER_SERVER',
  59. workStatus: 'INSTALLED'
  60. })
  61. ];
  62. sinon.stub(App.router, 'get', function(){
  63. return 3;
  64. });
  65. expect(controller.enableHighAvailability()).to.be.false;
  66. expect(controller.showErrorPopup.calledOnce).to.be.true;
  67. App.router.get.restore();
  68. });
  69. it('Cluster has less than 3 ZOOKEPER_SERVER components', function () {
  70. hostComponents = [
  71. Em.Object.create({
  72. componentName: 'NAMENODE',
  73. workStatus: 'STARTED'
  74. })
  75. ];
  76. sinon.stub(App.router, 'get', function(){
  77. return 3;
  78. });
  79. expect(controller.enableHighAvailability()).to.be.false;
  80. expect(controller.showErrorPopup.called).to.be.true;
  81. App.router.get.restore();
  82. });
  83. it('total hosts number less than 3', function () {
  84. controller.set('securityEnabled', false);
  85. hostComponents = [
  86. Em.Object.create({
  87. componentName: 'NAMENODE',
  88. workStatus: 'STARTED'
  89. }),
  90. Em.Object.create({
  91. componentName: 'ZOOKEEPER_SERVER',
  92. workStatus: 'INSTALLED'
  93. }),
  94. Em.Object.create({
  95. componentName: 'ZOOKEEPER_SERVER',
  96. workStatus: 'INSTALLED'
  97. }),
  98. Em.Object.create({
  99. componentName: 'ZOOKEEPER_SERVER',
  100. workStatus: 'INSTALLED'
  101. })
  102. ];
  103. sinon.stub(App.router, 'get', function () {
  104. return 1;
  105. });
  106. expect(controller.enableHighAvailability()).to.be.false;
  107. expect(controller.showErrorPopup.calledOnce).to.be.true;
  108. App.router.get.restore();
  109. });
  110. it('All checks passed', function () {
  111. controller.set('securityEnabled', false);
  112. hostComponents = [
  113. Em.Object.create({
  114. componentName: 'NAMENODE',
  115. workStatus: 'STARTED'
  116. }),
  117. Em.Object.create({
  118. componentName: 'ZOOKEEPER_SERVER',
  119. workStatus: 'INSTALLED'
  120. }),
  121. Em.Object.create({
  122. componentName: 'ZOOKEEPER_SERVER',
  123. workStatus: 'INSTALLED'
  124. }),
  125. Em.Object.create({
  126. componentName: 'ZOOKEEPER_SERVER',
  127. workStatus: 'INSTALLED'
  128. })
  129. ];
  130. sinon.stub(App.router, 'get', function(){
  131. return 3;
  132. });
  133. sinon.spy(App.router, 'transitionTo');
  134. expect(controller.enableHighAvailability()).to.be.true;
  135. expect(App.router.transitionTo.calledWith('main.admin.enableHighAvailability')).to.be.true;
  136. expect(controller.showErrorPopup.calledOnce).to.be.false;
  137. App.router.transitionTo.restore();
  138. App.router.get.restore();
  139. });
  140. });
  141. describe('#setSecurityStatus()', function () {
  142. beforeEach(function () {
  143. sinon.stub(App.ajax, "send", Em.K);
  144. });
  145. afterEach(function () {
  146. App.ajax.send.restore();
  147. });
  148. it('testMode = true', function () {
  149. App.testEnableSecurity = false;
  150. App.testMode = true;
  151. controller.set('securityEnabled', false);
  152. controller.set('dataIsLoaded', false);
  153. controller.setSecurityStatus();
  154. expect(controller.get('securityEnabled')).to.be.true;
  155. expect(controller.get('dataIsLoaded')).to.be.true;
  156. expect(App.ajax.send.called).to.be.false;
  157. });
  158. it('testMode = false', function () {
  159. App.testMode = false;
  160. controller.set('securityEnabled', false);
  161. controller.set('dataIsLoaded', false);
  162. controller.setSecurityStatus();
  163. expect(controller.get('securityEnabled')).to.be.false;
  164. expect(controller.get('dataIsLoaded')).to.be.false;
  165. expect(App.ajax.send.calledOnce).to.be.true;
  166. });
  167. });
  168. describe('#getSecurityStatusFromServerSuccessCallback()', function () {
  169. beforeEach(function () {
  170. sinon.stub(controller, "getServiceConfigsFromServer", Em.K);
  171. sinon.stub(controller, "showErrorPopup", Em.K);
  172. });
  173. afterEach(function () {
  174. controller.getServiceConfigsFromServer.restore();
  175. controller.showErrorPopup.restore();
  176. });
  177. it('desired_configs is empty', function () {
  178. var data = {
  179. Clusters: {
  180. desired_configs: {}
  181. }
  182. };
  183. controller.getSecurityStatusFromServerSuccessCallback(data);
  184. expect(controller.showErrorPopup.calledOnce).to.be.true;
  185. });
  186. it('desired_configs does not have "hadoop-env"', function () {
  187. var data = {
  188. Clusters: {
  189. desired_configs: {
  190. 'hdfs-site': {}
  191. }
  192. }
  193. };
  194. controller.getSecurityStatusFromServerSuccessCallback(data);
  195. expect(controller.showErrorPopup.calledOnce).to.be.true;
  196. });
  197. it('desired_configs has "hadoop-env"', function () {
  198. var data = {
  199. Clusters: {
  200. desired_configs: {
  201. 'hadoop-env': {
  202. tag: 1
  203. }
  204. }
  205. }
  206. };
  207. controller.getSecurityStatusFromServerSuccessCallback(data);
  208. expect(controller.get('tag')).to.equal(1);
  209. expect(controller.getServiceConfigsFromServer.calledOnce).to.be.true;
  210. expect(controller.showErrorPopup.called).to.be.false;
  211. });
  212. });
  213. describe('#getSecurityStatusFromServerSuccessCallback()', function () {
  214. beforeEach(function () {
  215. sinon.stub(controller, "getServiceConfigsFromServer", Em.K);
  216. sinon.stub(controller, "showErrorPopup", Em.K);
  217. });
  218. afterEach(function () {
  219. controller.getServiceConfigsFromServer.restore();
  220. controller.showErrorPopup.restore();
  221. });
  222. it('desired_configs is empty', function () {
  223. var data = {
  224. Clusters: {
  225. desired_configs: {}
  226. }
  227. };
  228. controller.getSecurityStatusFromServerSuccessCallback(data);
  229. expect(controller.showErrorPopup.calledOnce).to.be.true;
  230. });
  231. it('desired_configs does not have "hadoop-env"', function () {
  232. var data = {
  233. Clusters: {
  234. desired_configs: {
  235. 'hdfs-site': {}
  236. }
  237. }
  238. };
  239. controller.getSecurityStatusFromServerSuccessCallback(data);
  240. expect(controller.showErrorPopup.calledOnce).to.be.true;
  241. });
  242. it('desired_configs has "hadoop-env"', function () {
  243. var data = {
  244. Clusters: {
  245. desired_configs: {
  246. 'hadoop-env': {
  247. tag: 1
  248. }
  249. }
  250. }
  251. };
  252. controller.getSecurityStatusFromServerSuccessCallback(data);
  253. expect(controller.get('tag')).to.equal(1);
  254. expect(controller.getServiceConfigsFromServer.calledOnce).to.be.true;
  255. expect(controller.showErrorPopup.called).to.be.false;
  256. });
  257. });
  258. describe('#joinMessage()', function () {
  259. it('message is empty', function () {
  260. var message = [];
  261. expect(controller.joinMessage(message)).to.be.empty;
  262. });
  263. it('message is array from two strings', function () {
  264. var message = ['yes', 'no'];
  265. expect(controller.joinMessage(message)).to.equal('yes<br/>no');
  266. });
  267. it('message is string', function () {
  268. var message = 'hello';
  269. expect(controller.joinMessage(message)).to.equal('<p>hello</p>');
  270. });
  271. });
  272. describe('#getServiceConfigsFromServer()', function () {
  273. it('configs present', function () {
  274. sinon.stub(App.router.get('configurationController'), 'getConfigsByTags', function () {
  275. return {
  276. done: function (callback) {
  277. callback([{tag: '1'}]);
  278. }
  279. }
  280. });
  281. sinon.stub(controller, 'isSecurityEnabled', function(){
  282. return true;
  283. });
  284. controller.set('tag', '1');
  285. controller.getServiceConfigsFromServer();
  286. expect(App.router.get('configurationController').getConfigsByTags.calledWith([
  287. {
  288. siteName: "hadoop-env",
  289. tagName: '1'
  290. }
  291. ])).to.be.true;
  292. expect(controller.isSecurityEnabled.calledOnce).to.be.true;
  293. expect(controller.get('dataIsLoaded')).to.be.true;
  294. expect(controller.get('securityEnabled')).to.be.true;
  295. App.router.get('configurationController').getConfigsByTags.restore();
  296. controller.isSecurityEnabled.restore();
  297. });
  298. });
  299. describe('#isSecurityEnabled()', function () {
  300. it('properties is null', function () {
  301. expect(controller.isSecurityEnabled(null)).to.be.false;
  302. });
  303. it('properties is empty object', function () {
  304. expect(controller.isSecurityEnabled({})).to.be.false;
  305. });
  306. it('security_enabled is false', function () {
  307. expect(controller.isSecurityEnabled({security_enabled: false})).to.be.false;
  308. });
  309. it('security_enabled is true', function () {
  310. expect(controller.isSecurityEnabled({security_enabled: true})).to.be.true;
  311. });
  312. it('security_enabled is "true"', function () {
  313. expect(controller.isSecurityEnabled({security_enabled: 'true'})).to.be.true;
  314. });
  315. });
  316. });