summary_test.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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/service/info/summary');
  20. function getController() {
  21. return App.MainServiceInfoSummaryController.create();
  22. }
  23. describe('App.MainServiceInfoSummaryController', function () {
  24. var controller;
  25. beforeEach(function () {
  26. controller = App.MainServiceInfoSummaryController.create();
  27. });
  28. App.TestAliases.testAsComputedOr(getController(), 'showTimeRangeControl', ['!isServiceWithEnhancedWidgets', 'someWidgetGraphExists']);
  29. describe('#setRangerPlugins', function () {
  30. var cases = [
  31. {
  32. isLoaded: true,
  33. isRangerPluginsArraySet: false,
  34. expectedIsRangerPluginsArraySet: true,
  35. title: 'cluster loaded, ranger plugins array not set'
  36. },
  37. {
  38. isLoaded: false,
  39. isRangerPluginsArraySet: false,
  40. expectedIsRangerPluginsArraySet: false,
  41. title: 'cluster not loaded, ranger plugins array not set'
  42. },
  43. {
  44. isLoaded: false,
  45. isRangerPluginsArraySet: true,
  46. expectedIsRangerPluginsArraySet: true,
  47. title: 'cluster not loaded, ranger plugins array set'
  48. },
  49. {
  50. isLoaded: true,
  51. isRangerPluginsArraySet: true,
  52. expectedIsRangerPluginsArraySet: true,
  53. title: 'cluster loaded, ranger plugins array set'
  54. }
  55. ];
  56. beforeEach(function () {
  57. sinon.stub(App.Service, 'find').returns([
  58. Em.Object.create({
  59. serviceName: 'HDFS'
  60. }),
  61. Em.Object.create({
  62. serviceName: 'YARN'
  63. }),
  64. Em.Object.create({
  65. serviceName: 'HIVE'
  66. })
  67. ]);
  68. sinon.stub(App.StackService, 'find').returns([
  69. Em.Object.create({
  70. serviceName: 'HDFS',
  71. displayName: 'HDFS',
  72. configTypes: {
  73. 'ranger-hdfs-plugin-properties': {}
  74. }
  75. }),
  76. Em.Object.create({
  77. serviceName: 'HIVE',
  78. displayName: 'Hive',
  79. configTypes: {
  80. 'hive-env': {}
  81. }
  82. }),
  83. Em.Object.create({
  84. serviceName: 'HBASE',
  85. displayName: 'HBase',
  86. configTypes: {
  87. 'ranger-hbase-plugin-properties': {}
  88. }
  89. }),
  90. Em.Object.create({
  91. serviceName: 'KNOX',
  92. displayName: 'Knox',
  93. configTypes: {
  94. 'ranger-knox-plugin-properties': {}
  95. }
  96. }),
  97. Em.Object.create({
  98. serviceName: 'STORM',
  99. displayName: 'Storm',
  100. configTypes: {
  101. 'ranger-storm-plugin-properties': {}
  102. }
  103. }),
  104. Em.Object.create({
  105. serviceName: 'YARN',
  106. displayName: 'YARN',
  107. configTypes: {}
  108. })
  109. ]);
  110. });
  111. afterEach(function () {
  112. App.Service.find.restore();
  113. App.StackService.find.restore();
  114. });
  115. cases.forEach(function (item) {
  116. it(item.title, function () {
  117. controller.set('isRangerPluginsArraySet', item.isRangerPluginsArraySet);
  118. App.set('router.clusterController.isLoaded', item.isLoaded);
  119. expect(controller.get('isRangerPluginsArraySet')).to.equal(item.expectedIsRangerPluginsArraySet);
  120. expect(controller.get('rangerPlugins').filterProperty('isDisplayed').mapProperty('serviceName').sort()).to.eql(['HDFS', 'HIVE']);
  121. });
  122. });
  123. });
  124. describe('#getRangerPluginsStatus', function () {
  125. var data = {
  126. 'Clusters': {
  127. 'desired_configs': {
  128. 'ranger-hdfs-plugin-properties': {
  129. 'tag': 'version1'
  130. },
  131. 'hive-env': {
  132. 'tag': 'version2'
  133. },
  134. 'ranger-hbase-plugin-properties': {
  135. 'tag': 'version3'
  136. }
  137. }
  138. }
  139. },
  140. cases = [
  141. {
  142. isPreviousRangerConfigsCallFailed: false,
  143. ajaxRequestSent: true,
  144. title: 'initial case'
  145. },
  146. {
  147. isPreviousRangerConfigsCallFailed: true,
  148. hdfsTag: 'version1',
  149. hiveTag: 'version2',
  150. hbaseTag: 'version3',
  151. ajaxRequestSent: true,
  152. title: 'previous call failed'
  153. },
  154. {
  155. isPreviousRangerConfigsCallFailed: false,
  156. hdfsTag: 'version2',
  157. hiveTag: 'version2',
  158. hbaseTag: 'version3',
  159. ajaxRequestSent: true,
  160. title: 'configs changed'
  161. },
  162. {
  163. isPreviousRangerConfigsCallFailed: false,
  164. hdfsTag: 'version1',
  165. hiveTag: 'version2',
  166. hbaseTag: 'version3',
  167. ajaxRequestSent: false,
  168. title: 'configs unchanged'
  169. }
  170. ];
  171. beforeEach(function () {
  172. sinon.stub(App.ajax, 'send', Em.K);
  173. sinon.stub(App.Service, 'find').returns([
  174. Em.Object.create({
  175. serviceName: 'HDFS'
  176. }),
  177. Em.Object.create({
  178. serviceName: 'HIVE'
  179. }),
  180. Em.Object.create({
  181. serviceName: 'HBASE'
  182. }),
  183. Em.Object.create({
  184. serviceName: 'YARN'
  185. })
  186. ]);
  187. });
  188. afterEach(function () {
  189. App.ajax.send.restore();
  190. App.Service.find.restore();
  191. });
  192. cases.forEach(function (item) {
  193. it(item.title, function () {
  194. controller.set('isPreviousRangerConfigsCallFailed', item.isPreviousRangerConfigsCallFailed);
  195. controller.get('rangerPlugins').findProperty('serviceName', 'HDFS').tag = item.hdfsTag;
  196. controller.get('rangerPlugins').findProperty('serviceName', 'HBASE').tag = item.hbaseTag;
  197. controller.getRangerPluginsStatus(data);
  198. expect(App.ajax.send.calledOnce).to.equal(item.ajaxRequestSent);
  199. if (item.ajaxRequestSent) {
  200. expect(App.ajax.send.getCall(0).args[0].data.urlParams.contains('ranger-yarn-plugin-properties')).to.be.false;
  201. }
  202. });
  203. });
  204. });
  205. describe('#getRangerPluginsStatusSuccess', function () {
  206. it('relevant plugin statuses are set', function () {
  207. controller.getRangerPluginsStatusSuccess({
  208. 'items': [
  209. {
  210. 'type': 'ranger-hdfs-plugin-properties',
  211. 'properties': {
  212. 'ranger-hdfs-plugin-enabled': 'Yes'
  213. }
  214. },
  215. {
  216. 'type': 'hive-env',
  217. 'properties': {
  218. 'hive_security_authorization': 'Ranger'
  219. }
  220. },
  221. {
  222. 'type': 'ranger-hbase-plugin-properties',
  223. 'properties': {
  224. 'ranger-hbase-plugin-enabled': ''
  225. }
  226. }
  227. ]
  228. });
  229. expect(controller.get('isPreviousRangerConfigsCallFailed')).to.be.false;
  230. expect(controller.get('rangerPlugins').findProperty('serviceName', 'HDFS').status).to.equal(Em.I18n.t('alerts.table.state.enabled'));
  231. expect(controller.get('rangerPlugins').findProperty('serviceName', 'HIVE').status).to.equal(Em.I18n.t('alerts.table.state.enabled'));
  232. expect(controller.get('rangerPlugins').findProperty('serviceName', 'HBASE').status).to.equal(Em.I18n.t('common.unknown'));
  233. });
  234. });
  235. describe('#getRangerPluginsStatusError', function () {
  236. it('should set isPreviousRangerConfigsCallFailed to true', function () {
  237. controller.getRangerPluginsStatusError();
  238. expect(controller.get('isPreviousRangerConfigsCallFailed')).to.be.true;
  239. });
  240. });
  241. describe("#getActiveWidgetLayout() for Enhanced Dashboard", function () {
  242. before(function () {
  243. sinon.stub(App.ajax, 'send');
  244. });
  245. after(function () {
  246. App.ajax.send.restore();
  247. });
  248. it("make GET call", function () {
  249. var controller = App.MainServiceInfoSummaryController.create({
  250. isServiceWithEnhancedWidgets: true,
  251. content: Em.Object.create({serviceName: 'HDFS'})
  252. });
  253. controller.getActiveWidgetLayout();
  254. expect(App.ajax.send.getCall(0).args[0].name).to.equal('widgets.layouts.active.get');
  255. });
  256. });
  257. describe("#getActiveWidgetLayoutSuccessCallback()", function () {
  258. beforeEach(function () {
  259. sinon.stub( App.widgetLayoutMapper, 'map');
  260. sinon.stub( App.widgetMapper, 'map');
  261. });
  262. afterEach(function () {
  263. App.widgetLayoutMapper.map.restore();
  264. App.widgetMapper.map.restore();
  265. });
  266. it("isWidgetLayoutsLoaded should be set to true", function () {
  267. var controller = App.MainServiceInfoSummaryController.create({
  268. isServiceWithEnhancedWidgets: true,
  269. content: Em.Object.create({serviceName: 'HDFS'})
  270. });
  271. controller.getActiveWidgetLayoutSuccessCallback({items:[{
  272. WidgetLayoutInfo: {}
  273. }]});
  274. expect(controller.get('isWidgetsLoaded')).to.be.true;
  275. });
  276. });
  277. describe("#hideWidgetSuccessCallback()", function () {
  278. beforeEach(function () {
  279. sinon.stub(App.widgetLayoutMapper, 'map');
  280. sinon.stub(controller, 'propertyDidChange');
  281. });
  282. afterEach(function () {
  283. App.widgetLayoutMapper.map.restore();
  284. controller.propertyDidChange.restore();
  285. });
  286. it("", function () {
  287. var params = {
  288. data: {
  289. WidgetLayoutInfo: {
  290. widgets: [
  291. {
  292. id: 1
  293. }
  294. ]
  295. }
  296. }
  297. };
  298. controller.hideWidgetSuccessCallback({}, {}, params);
  299. expect(App.widgetLayoutMapper.map.calledWith({
  300. items: [{
  301. WidgetLayoutInfo: {
  302. widgets: [
  303. {
  304. WidgetInfo: {
  305. id: 1
  306. }
  307. }
  308. ]
  309. }
  310. }]
  311. })).to.be.true;
  312. expect(controller.propertyDidChange.calledWith('widgets')).to.be.true;
  313. });
  314. });
  315. });