cluster_controller_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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/global/cluster_controller');
  20. require('models/host_component');
  21. require('utils/http_client');
  22. require('models/service');
  23. require('models/host');
  24. require('utils/ajax/ajax');
  25. var modelSetup = require('test/init_model_test');
  26. describe('App.clusterController', function () {
  27. var controller = App.ClusterController.create();
  28. App.Service.FIXTURES = [
  29. {service_name: 'NAGIOS'}
  30. ];
  31. describe('#updateLoadStatus()', function () {
  32. controller.set('dataLoadList', Em.Object.create({
  33. 'item1': false,
  34. 'item2': false
  35. }));
  36. it('when none item is loaded then width should be "width:0"', function () {
  37. expect(controller.get('clusterDataLoadedPercent')).to.equal('width:0');
  38. });
  39. it('when first item is loaded then isLoaded should be false', function () {
  40. controller.updateLoadStatus.call(controller, 'item1');
  41. expect(controller.get('isLoaded')).to.equal(false);
  42. });
  43. it('when first item is loaded then width should be "width:50%"', function () {
  44. controller.updateLoadStatus.call(controller, 'item1');
  45. expect(controller.get('clusterDataLoadedPercent')).to.equal('width:50%');
  46. });
  47. it('when all items are loaded then isLoaded should be true', function () {
  48. controller.updateLoadStatus.call(controller, 'item2');
  49. expect(controller.get('isLoaded')).to.equal(true);
  50. });
  51. it('when all items are loaded then width should be "width:100%"', function () {
  52. controller.updateLoadStatus.call(controller, 'item2');
  53. expect(controller.get('clusterDataLoadedPercent')).to.equal('width:100%');
  54. });
  55. });
  56. describe('#loadClusterName()', function () {
  57. beforeEach(function () {
  58. modelSetup.setupStackVersion(this, 'HDP-2.0.5');
  59. sinon.spy(App.ajax, 'send');
  60. });
  61. afterEach(function () {
  62. modelSetup.restoreStackVersion(this);
  63. App.ajax.send.restore();
  64. });
  65. it('if clusterName is "mycluster" and reload is false then loadClusterName should return false', function () {
  66. controller.set('cluster', {Clusters: {cluster_name: 'mycluster'}});
  67. expect(controller.loadClusterName(false)).to.equal(false);
  68. });
  69. it('reload is true and clusterName is not empty', function () {
  70. controller.loadClusterName(true);
  71. expect(App.ajax.send.calledOnce).to.equal(true);
  72. expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
  73. });
  74. it('reload is false and clusterName is empty', function () {
  75. controller.set('cluster', {Clusters: {cluster_name: ''}});
  76. controller.loadClusterName(false);
  77. expect(App.ajax.send.calledOnce).to.equal(true);
  78. expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
  79. });
  80. });
  81. describe('#loadClusterNameSuccessCallback', function () {
  82. var test_data = {
  83. "items": [
  84. {
  85. "Clusters": {
  86. "cluster_name": "tdk",
  87. "version": "HDP-1.3.0"
  88. }
  89. }
  90. ]
  91. };
  92. it('Check cluster', function () {
  93. controller.loadClusterNameSuccessCallback(test_data);
  94. expect(controller.get('cluster.Clusters.cluster_name')).to.equal('tdk');
  95. expect(controller.get('cluster.Clusters.version')).to.equal('HDP-1.3.0');
  96. expect(App.get('clusterName')).to.equal('tdk');
  97. });
  98. });
  99. describe('#loadClusterNameErrorCallback', function () {
  100. controller.loadClusterNameErrorCallback();
  101. it('', function () {
  102. expect(controller.get('isLoaded')).to.equal(true);
  103. });
  104. });
  105. describe('#getServerClockSuccessCallback()', function () {
  106. var testCases = [
  107. {
  108. title: 'if server clock is 1 then currentServerTime should be 1000',
  109. data: {
  110. RootServiceComponents: {
  111. server_clock: 1
  112. }
  113. },
  114. result: 1000
  115. },
  116. {
  117. title: 'if server clock is 0 then currentServerTime should be 0',
  118. data: {
  119. RootServiceComponents: {
  120. server_clock: 0
  121. }
  122. },
  123. result: 0
  124. },
  125. {
  126. title: 'if server clock is 111111111111 then currentServerTime should be 111111111111000',
  127. data: {
  128. RootServiceComponents: {
  129. server_clock: 111111111111
  130. }
  131. },
  132. result: 111111111111000
  133. },
  134. {
  135. title: 'if server clock is 1111111111113 then currentServerTime should be 1111111111113',
  136. data: {
  137. RootServiceComponents: {
  138. server_clock: 1111111111113
  139. }
  140. },
  141. result: 1111111111113
  142. }
  143. ];
  144. var currentServerTime = App.get('currentServerTime');
  145. var clockDistance = App.get('clockDistance');
  146. testCases.forEach(function (test) {
  147. it(test.title, function () {
  148. controller.getServerClockSuccessCallback(test.data);
  149. expect(App.get('currentServerTime')).to.equal(test.result);
  150. App.set('clockDistance', clockDistance);
  151. App.set('currentServerTime', currentServerTime);
  152. });
  153. });
  154. });
  155. describe('#getUrl', function () {
  156. controller.set('clusterName', 'tdk');
  157. var tests = ['test1', 'test2', 'test3'];
  158. it('testMode = true', function () {
  159. App.testMode = true;
  160. tests.forEach(function (test) {
  161. expect(controller.getUrl(test, test)).to.equal(test);
  162. });
  163. });
  164. it('testMode = false', function () {
  165. App.testMode = false;
  166. tests.forEach(function (test) {
  167. expect(controller.getUrl(test, test)).to.equal(App.apiPrefix + '/clusters/' + controller.get('clusterName') + test);
  168. });
  169. });
  170. });
  171. describe('#gangliaUrl', function () {
  172. it('testMode = true', function () {
  173. App.testMode = true;
  174. expect(controller.get('gangliaUrl')).to.equal('http://gangliaserver/ganglia/?t=yes');
  175. });
  176. it('Ganglia service is absent', function () {
  177. App.testMode = false;
  178. controller.set('gangliaWebProtocol', '');
  179. expect(controller.get('gangliaUrl')).to.equal(null);
  180. });
  181. it('Ganglia doesn\'t have any components', function () {
  182. App.store.load(App.Service, {
  183. id: 'GANGLIA',
  184. service_name: 'GANGLIA'
  185. });
  186. controller.set('gangliaWebProtocol', '');
  187. expect(controller.get('gangliaUrl')).to.equal(null);
  188. expect(controller.get('isGangliaInstalled')).to.equal(true);
  189. });
  190. it('Ganglia Server doesn\'t have host', function () {
  191. App.store.load(App.HostComponent, {
  192. id: 'GANGLIA_SERVER_GANGLIA_host',
  193. component_name: 'GANGLIA_SERVER',
  194. service_id: 'GANGLIA',
  195. host_id: 'GANGLIA_host'
  196. });
  197. App.store.load(App.Service, {
  198. id: 'GANGLIA',
  199. service_name: 'GANGLIA',
  200. host_components: ['GANGLIA_SERVER_GANGLIA_host']
  201. });
  202. controller.set('gangliaWebProtocol', '');
  203. expect(controller.get('gangliaUrl')).to.equal(null);
  204. });
  205. it('Ganglia Server host is "GANGLIA_host"', function () {
  206. App.store.load(App.Host, {
  207. id: 'GANGLIA_host',
  208. host_name: 'GANGLIA_host',
  209. host_components: ['GANGLIA_SERVER_GANGLIA_host'],
  210. public_host_name: 'GANGLIA_host'
  211. });
  212. controller.set('gangliaWebProtocol', '');
  213. expect(controller.get('gangliaUrl')).to.equal("http://GANGLIA_host/ganglia");
  214. });
  215. it('singleNodeInstall = true', function () {
  216. App.set('singleNodeInstall', true);
  217. controller.set('gangliaWebProtocol', '');
  218. expect(controller.get('gangliaUrl')).to.equal("http://" + location.hostname + ":42080/ganglia");
  219. });
  220. it('singleNodeAlias is "alias"', function () {
  221. App.set('singleNodeAlias', 'alias');
  222. controller.set('gangliaWebProtocol', '');
  223. expect(controller.get('gangliaUrl')).to.equal("http://alias:42080/ganglia");
  224. App.set('singleNodeInstall', false);
  225. App.set('singleNodeAlias', '');
  226. });
  227. });
  228. describe('#nagiosUrl', function () {
  229. it('testMode = true', function () {
  230. App.testMode = true;
  231. controller.set('nagiosWebProtocol', '');
  232. expect(controller.get('nagiosUrl')).to.equal('http://nagiosserver/nagios');
  233. });
  234. it('Nagios service is absent', function () {
  235. App.testMode = false;
  236. controller.set('nagiosWebProtocol', '');
  237. expect(controller.get('nagiosUrl')).to.equal(null);
  238. });
  239. it('Nagios doesn\'t have any components', function () {
  240. App.store.load(App.Service, {
  241. id: 'NAGIOS',
  242. service_name: 'NAGIOS'
  243. });
  244. controller.set('nagiosWebProtocol', '');
  245. expect(controller.get('nagiosUrl')).to.equal(null);
  246. expect(controller.get('isNagiosInstalled')).to.equal(true);
  247. });
  248. it('NAGIOS Server doesn\'t have host', function () {
  249. App.store.load(App.HostComponent, {
  250. id: 'NAGIOS_SERVER_NAGIOS_host',
  251. component_name: 'NAGIOS_SERVER',
  252. service_id: 'NAGIOS',
  253. host_id: 'NAGIOS_host'
  254. });
  255. App.store.load(App.Service, {
  256. id: 'NAGIOS',
  257. service_name: 'NAGIOS',
  258. host_components: ['NAGIOS_SERVER_NAGIOS_host']
  259. });
  260. controller.set('nagiosWebProtocol', '');
  261. expect(controller.get('nagiosUrl')).to.equal(null);
  262. });
  263. it('NAGIOS Server host is "NAGIOS_host"', function () {
  264. App.store.load(App.Host, {
  265. id: 'NAGIOS_host',
  266. host_name: 'NAGIOS_host',
  267. host_components: ['NAGIOS_SERVER_NAGIOS_host'],
  268. public_host_name: 'NAGIOS_host'
  269. });
  270. controller.set('nagiosWebProtocol', '');
  271. expect(controller.get('nagiosUrl')).to.equal("http://NAGIOS_host/nagios");
  272. });
  273. it('singleNodeInstall = true', function () {
  274. App.set('singleNodeInstall', true);
  275. controller.set('nagiosWebProtocol', '');
  276. expect(controller.get('nagiosUrl')).to.equal("http://:42080/nagios");
  277. });
  278. it('singleNodeAlias is "alias"', function () {
  279. App.set('singleNodeAlias', 'alias');
  280. controller.set('nagiosWebProtocol', '');
  281. expect(controller.get('nagiosUrl')).to.equal("http://alias:42080/nagios");
  282. });
  283. });
  284. describe('#nagiosWebProtocol', function () {
  285. var testCases = [
  286. {
  287. title: 'if ambariProperties is null then nagiosWebProtocol should be "http"',
  288. data: null,
  289. result: 'http'
  290. },
  291. {
  292. title: 'if ambariProperties is empty object then nagiosWebProtocol should be "http"',
  293. data: {},
  294. result: 'http'
  295. },
  296. {
  297. title: 'if nagios.https is false then nagiosWebProtocol should be "http"',
  298. data: {'nagios.https': false},
  299. result: 'http'
  300. },
  301. {
  302. title: 'if nagios.https is true then nagiosWebProtocol should be "http"',
  303. data: {'nagios.https': true},
  304. result: 'https'
  305. }
  306. ];
  307. testCases.forEach(function (test) {
  308. it(test.title, function () {
  309. controller.set('ambariProperties', test.data);
  310. expect(controller.get('nagiosWebProtocol')).to.equal(test.result);
  311. });
  312. });
  313. });
  314. describe('#gangliaWebProtocol', function () {
  315. var testCases = [
  316. {
  317. title: 'if ambariProperties is null then nagiosWebProtocol should be "http"',
  318. data: null,
  319. result: 'http'
  320. },
  321. {
  322. title: 'if ambariProperties is empty object then nagiosWebProtocol should be "http"',
  323. data: {},
  324. result: 'http'
  325. },
  326. {
  327. title: 'if nagios.https is false then nagiosWebProtocol should be "http"',
  328. data: {'ganglia.https': false},
  329. result: 'http'
  330. },
  331. {
  332. title: 'if nagios.https is true then nagiosWebProtocol should be "http"',
  333. data: {'ganglia.https': true},
  334. result: 'https'
  335. }
  336. ];
  337. testCases.forEach(function (test) {
  338. it(test.title, function () {
  339. controller.set('ambariProperties', test.data);
  340. expect(controller.get('gangliaWebProtocol')).to.equal(test.result);
  341. });
  342. });
  343. });
  344. describe('#startPolling()', function () {
  345. beforeEach(function () {
  346. sinon.spy(App.updater, 'run');
  347. });
  348. afterEach(function () {
  349. App.updater.run.restore();
  350. });
  351. it('isWorking = false', function () {
  352. controller.set('isWorking', false);
  353. expect(App.updater.run.calledOnce).to.equal(false);
  354. expect(controller.startPolling()).to.equal(false);
  355. });
  356. it('isWorking = true', function () {
  357. controller.set('isWorking', true);
  358. expect(App.updater.run.calledOnce).to.equal(true);
  359. expect(controller.startPolling()).to.equal(true);
  360. });
  361. });
  362. describe('#clusterName', function () {
  363. var testCases = [
  364. {
  365. title: 'if cluster is null then clusterName should be null',
  366. data: null,
  367. result: null
  368. },
  369. {
  370. title: 'if cluster.Clusters.cluster_name is null then clusterName should be null',
  371. data: {
  372. Clusters: {
  373. cluster_name: null
  374. }
  375. },
  376. result: null
  377. },
  378. {
  379. title: 'if cluster.Clusters.cluster_name is null then clusterName should be null',
  380. data: {
  381. Clusters: {
  382. cluster_name: 'mycluster'
  383. }
  384. },
  385. result: 'mycluster'
  386. }
  387. ];
  388. testCases.forEach(function (test) {
  389. it(test.title, function () {
  390. controller.set('cluster', test.data);
  391. expect(controller.get('clusterName')).to.equal(test.result);
  392. });
  393. });
  394. });
  395. });