cluster_controller_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. require('utils/string_utils');
  26. var modelSetup = require('test/init_model_test');
  27. describe('App.clusterController', function () {
  28. var controller = App.ClusterController.create();
  29. App.Service.FIXTURES = [
  30. {service_name: 'GANGLIA'}
  31. ];
  32. describe('#updateLoadStatus()', function () {
  33. controller.set('dataLoadList', Em.Object.create({
  34. 'item1': false,
  35. 'item2': false
  36. }));
  37. it('when none item is loaded then width should be "width:0"', function () {
  38. expect(controller.get('clusterDataLoadedPercent')).to.equal('width:0');
  39. });
  40. it('when first item is loaded then isLoaded should be false', function () {
  41. controller.updateLoadStatus.call(controller, 'item1');
  42. expect(controller.get('isLoaded')).to.equal(false);
  43. });
  44. it('when first item is loaded then width should be "width:50%"', function () {
  45. controller.updateLoadStatus.call(controller, 'item1');
  46. expect(controller.get('clusterDataLoadedPercent')).to.equal('width:50%');
  47. });
  48. it('when all items are loaded then isLoaded should be true', function () {
  49. controller.updateLoadStatus.call(controller, 'item2');
  50. expect(controller.get('isLoaded')).to.equal(true);
  51. });
  52. it('when all items are loaded then width should be "width:100%"', function () {
  53. controller.updateLoadStatus.call(controller, 'item2');
  54. expect(controller.get('clusterDataLoadedPercent')).to.equal('width:100%');
  55. });
  56. });
  57. describe('#loadClusterName()', function () {
  58. beforeEach(function () {
  59. modelSetup.setupStackVersion(this, 'HDP-2.0.5');
  60. sinon.stub(App.ajax, 'send', function () {
  61. return {
  62. complete: function (callback) {
  63. App.set('clusterName', 'clusterNameFromServer');
  64. App.set('currentStackVersion', 'HDP-2.0.5');
  65. callback();
  66. }
  67. }
  68. });
  69. });
  70. afterEach(function () {
  71. modelSetup.restoreStackVersion(this);
  72. App.ajax.send.restore();
  73. });
  74. it('if clusterName is "mycluster" and reload is false then clusterName stays the same', function () {
  75. App.set('clusterName', 'mycluster');
  76. controller.loadClusterName(false);
  77. expect(App.ajax.send.called).to.be.false;
  78. expect(App.get('clusterName')).to.equal('mycluster');
  79. });
  80. it('reload is true and clusterName is not empty', function () {
  81. controller.loadClusterName(true);
  82. expect(App.ajax.send.calledOnce).to.be.true;
  83. expect(App.get('clusterName')).to.equal('clusterNameFromServer');
  84. expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
  85. });
  86. it('reload is false and clusterName is empty', function () {
  87. App.set('clusterName', '');
  88. controller.loadClusterName(false);
  89. expect(App.ajax.send.calledOnce).to.be.true;
  90. expect(App.get('clusterName')).to.equal('clusterNameFromServer');
  91. expect(App.get('currentStackVersion')).to.equal('HDP-2.0.5');
  92. });
  93. });
  94. describe('#loadClusterNameSuccessCallback', function () {
  95. var test_data = {
  96. "items": [
  97. {
  98. "Clusters": {
  99. "cluster_name": "tdk",
  100. "version": "HDP-1.3.0"
  101. }
  102. }
  103. ]
  104. };
  105. it('Check cluster', function () {
  106. controller.loadClusterNameSuccessCallback(test_data);
  107. expect(App.get('clusterName')).to.equal('tdk');
  108. expect(App.get('currentStackVersion')).to.equal('HDP-1.3.0');
  109. });
  110. });
  111. describe('#loadClusterNameErrorCallback', function () {
  112. controller.loadClusterNameErrorCallback();
  113. it('', function () {
  114. expect(controller.get('isLoaded')).to.equal(true);
  115. });
  116. });
  117. describe('#getServerClockSuccessCallback()', function () {
  118. var testCases = [
  119. {
  120. title: 'if server clock is 1 then currentServerTime should be 1000',
  121. data: {
  122. RootServiceComponents: {
  123. server_clock: 1
  124. }
  125. },
  126. result: 1000
  127. },
  128. {
  129. title: 'if server clock is 0 then currentServerTime should be 0',
  130. data: {
  131. RootServiceComponents: {
  132. server_clock: 0
  133. }
  134. },
  135. result: 0
  136. },
  137. {
  138. title: 'if server clock is 111111111111 then currentServerTime should be 111111111111000',
  139. data: {
  140. RootServiceComponents: {
  141. server_clock: 111111111111
  142. }
  143. },
  144. result: 111111111111000
  145. },
  146. {
  147. title: 'if server clock is 1111111111113 then currentServerTime should be 1111111111113',
  148. data: {
  149. RootServiceComponents: {
  150. server_clock: 1111111111113
  151. }
  152. },
  153. result: 1111111111113
  154. }
  155. ];
  156. var currentServerTime = App.get('currentServerTime');
  157. var clockDistance = App.get('clockDistance');
  158. testCases.forEach(function (test) {
  159. it(test.title, function () {
  160. controller.getServerClockSuccessCallback(test.data);
  161. expect(App.get('currentServerTime')).to.equal(test.result);
  162. App.set('clockDistance', clockDistance);
  163. App.set('currentServerTime', currentServerTime);
  164. });
  165. });
  166. });
  167. describe('#getUrl', function () {
  168. controller.set('clusterName', 'tdk');
  169. var tests = ['test1', 'test2', 'test3'];
  170. it('testMode = true', function () {
  171. App.testMode = true;
  172. tests.forEach(function (test) {
  173. expect(controller.getUrl(test, test)).to.equal(test);
  174. });
  175. });
  176. it('testMode = false', function () {
  177. App.testMode = false;
  178. tests.forEach(function (test) {
  179. expect(controller.getUrl(test, test)).to.equal(App.apiPrefix + '/clusters/' + controller.get('clusterName') + test);
  180. });
  181. });
  182. });
  183. describe("#createKerberosAdminSession()", function() {
  184. before(function () {
  185. sinon.stub(App.ajax, 'send', function() {
  186. return {success: Em.K}
  187. });
  188. });
  189. after(function () {
  190. App.ajax.send.restore();
  191. });
  192. it("make ajax call", function() {
  193. controller.createKerberosAdminSession("admin", "pass", {});
  194. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  195. name: 'common.cluster.update',
  196. sender: controller,
  197. data: {
  198. clusterName: App.get('clusterName'),
  199. data: [{
  200. session_attributes: {
  201. kerberos_admin: {principal: "admin", password: "pass"}
  202. }
  203. }]
  204. }
  205. });
  206. });
  207. });
  208. describe('#checkDetailedRepoVersion()', function () {
  209. var cases = [
  210. {
  211. currentStackName: 'HDP',
  212. currentStackVersionNumber: '2.1',
  213. isStormMetricsSupported: false,
  214. title: 'HDP < 2.2'
  215. },
  216. {
  217. currentStackName: 'HDP',
  218. currentStackVersionNumber: '2.3',
  219. isStormMetricsSupported: true,
  220. title: 'HDP > 2.2'
  221. },
  222. {
  223. currentStackName: 'BIGTOP',
  224. currentStackVersionNumber: '0.8',
  225. isStormMetricsSupported: true,
  226. title: 'not HDP'
  227. }
  228. ];
  229. beforeEach(function () {
  230. sinon.stub(App.ajax, 'send').returns({
  231. promise: Em.K
  232. });
  233. });
  234. afterEach(function () {
  235. App.ajax.send.restore();
  236. App.get.restore();
  237. });
  238. it('should check detailed repo version for HDP 2.2', function () {
  239. sinon.stub(App, 'get').withArgs('currentStackName').returns('HDP').withArgs('currentStackVersionNumber').returns('2.2');
  240. controller.checkDetailedRepoVersion();
  241. expect(App.ajax.send.calledOnce).to.be.true;
  242. });
  243. cases.forEach(function (item) {
  244. it(item.title, function () {
  245. sinon.stub(App, 'get', function (key) {
  246. return item[key] || Em.get(App, key);
  247. });
  248. controller.checkDetailedRepoVersion();
  249. expect(App.ajax.send.called).to.be.false;
  250. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  251. });
  252. });
  253. });
  254. describe('#checkDetailedRepoVersionSuccessCallback()', function () {
  255. var cases = [
  256. {
  257. items: [
  258. {
  259. repository_versions: [
  260. {
  261. RepositoryVersions: {
  262. repository_version: '2.1'
  263. }
  264. }
  265. ]
  266. }
  267. ],
  268. isStormMetricsSupported: false,
  269. title: 'HDP < 2.2.2'
  270. },
  271. {
  272. items: [
  273. {
  274. repository_versions: [
  275. {
  276. RepositoryVersions: {
  277. repository_version: '2.2.2'
  278. }
  279. }
  280. ]
  281. }
  282. ],
  283. isStormMetricsSupported: true,
  284. title: 'HDP 2.2.2'
  285. },
  286. {
  287. items: [
  288. {
  289. repository_versions: [
  290. {
  291. RepositoryVersions: {
  292. repository_version: '2.2.3'
  293. }
  294. }
  295. ]
  296. }
  297. ],
  298. isStormMetricsSupported: true,
  299. title: 'HDP > 2.2.2'
  300. },
  301. {
  302. items: null,
  303. isStormMetricsSupported: true,
  304. title: 'empty response'
  305. },
  306. {
  307. items: [],
  308. isStormMetricsSupported: true,
  309. title: 'no items'
  310. },
  311. {
  312. items: [{}],
  313. isStormMetricsSupported: true,
  314. title: 'empty item'
  315. },
  316. {
  317. items: [{
  318. repository_versions: []
  319. }],
  320. isStormMetricsSupported: true,
  321. title: 'no versions'
  322. },
  323. {
  324. items: [{
  325. repository_versions: [{}]
  326. }],
  327. isStormMetricsSupported: true,
  328. title: 'no version info'
  329. },
  330. {
  331. items: [{
  332. repository_versions: [
  333. {
  334. RepositoryVersions: {}
  335. }
  336. ]
  337. }],
  338. isStormMetricsSupported: true,
  339. title: 'empty version info'
  340. }
  341. ];
  342. cases.forEach(function (item) {
  343. it(item.title, function () {
  344. controller.checkDetailedRepoVersionSuccessCallback({
  345. items: item.items
  346. });
  347. expect(App.get('isStormMetricsSupported')).to.equal(item.isStormMetricsSupported);
  348. });
  349. });
  350. });
  351. describe('#checkDetailedRepoVersionErrorCallback()', function () {
  352. it('should set isStormMetricsSupported to default value', function () {
  353. controller.checkDetailedRepoVersionErrorCallback();
  354. expect(App.get('isStormMetricsSupported')).to.be.true;
  355. });
  356. });
  357. describe('#getAllUpgrades()', function () {
  358. beforeEach(function () {
  359. sinon.stub(App.ajax, 'send', Em.K);
  360. });
  361. afterEach(function () {
  362. App.ajax.send.restore();
  363. });
  364. it('should send request to get upgrades data', function () {
  365. controller.getAllUpgrades();
  366. expect(App.ajax.send.calledOnce).to.be.true;
  367. });
  368. });
  369. });