update_controller_test.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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('utils/updater');
  20. require('controllers/global/update_controller');
  21. describe('App.UpdateController', function () {
  22. var controller = App.UpdateController.create({
  23. clusterName: '',
  24. location: '',
  25. updateServiceMetric: function(){}
  26. });
  27. describe('#getUrl()', function () {
  28. it('testMode = true', function () {
  29. App.set('testMode', true);
  30. expect(controller.getUrl('test', '/real')).to.equal('test');
  31. });
  32. it('testMode = false', function () {
  33. App.set('testMode', false);
  34. expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters//real');
  35. });
  36. it('testMode = false', function () {
  37. App.set('testMode', false);
  38. controller.set('clusterName', 'mycluster');
  39. expect(controller.getUrl('test', '/real')).to.equal('/api/v1/clusters/mycluster/real');
  40. });
  41. });
  42. describe('#updateAll()', function () {
  43. beforeEach(function () {
  44. sinon.stub(App.updater, 'run', Em.K);
  45. });
  46. afterEach(function () {
  47. App.updater.run.restore();
  48. });
  49. it('isWorking = false', function () {
  50. controller.set('isWorking', false);
  51. expect(App.updater.run.called).to.equal(false);
  52. });
  53. it('isWorking = true, App.supports.hostOverrides = false', function () {
  54. App.supports.hostOverrides = false;
  55. controller.set('isWorking', true);
  56. expect(App.updater.run.callCount).to.equal(5);
  57. controller.set('isWorking', false);
  58. });
  59. it('isWorking = true, App.supports.hostOverrides = true', function () {
  60. App.supports.hostOverrides = true;
  61. controller.set('isWorking', true);
  62. expect(App.updater.run.callCount).to.equal(6);
  63. });
  64. });
  65. describe('#updateServiceMetricConditionally()', function () {
  66. var context = {
  67. callback: function(){}
  68. };
  69. beforeEach(function () {
  70. sinon.spy(controller, 'updateServiceMetric');
  71. sinon.spy(context, 'callback');
  72. });
  73. afterEach(function () {
  74. controller.updateServiceMetric.restore();
  75. context.callback.restore();
  76. });
  77. it('location is empty', function () {
  78. controller.set('location', '');
  79. controller.updateServiceMetricConditionally(context.callback);
  80. expect(controller.updateServiceMetric.called).to.equal(false);
  81. expect(context.callback.called).to.equal(true);
  82. });
  83. it('location is "/main/hosts"', function () {
  84. controller.set('location', '/main/hosts');
  85. controller.updateServiceMetricConditionally(context.callback);
  86. expect(controller.updateServiceMetric.called).to.equal(false);
  87. expect(context.callback.called).to.equal(true);
  88. });
  89. it('location is "/main/dashboard"', function () {
  90. controller.set('location', '/main/dashboard');
  91. controller.updateServiceMetricConditionally(context.callback);
  92. expect(controller.updateServiceMetric.called).to.equal(true);
  93. expect(context.callback.called).to.equal(false);
  94. });
  95. it('location is "/main/services/HDFS"', function () {
  96. controller.set('location', '/main/services/HDFS');
  97. controller.updateServiceMetricConditionally(context.callback);
  98. expect(controller.updateServiceMetric.called).to.equal(true);
  99. expect(context.callback.called).to.equal(false);
  100. });
  101. });
  102. describe('#getConditionalFields()', function () {
  103. var testCases = [
  104. {
  105. title: 'No services exist',
  106. services: [],
  107. result: []
  108. },
  109. {
  110. title: 'HDFS service',
  111. services: [
  112. {
  113. ServiceInfo: {
  114. service_name: 'HDFS'
  115. }
  116. }
  117. ],
  118. result: []
  119. },
  120. {
  121. title: 'FLUME service',
  122. services: [
  123. {
  124. ServiceInfo: {
  125. service_name: 'FLUME'
  126. }
  127. }
  128. ],
  129. result: ["host_components/metrics/flume/flume,"+
  130. "host_components/processes/HostComponentProcess"]
  131. },
  132. {
  133. title: 'YARN service',
  134. services: [
  135. {
  136. ServiceInfo: {
  137. service_name: 'YARN'
  138. }
  139. }
  140. ],
  141. result: ["host_components/metrics/yarn/Queue," +
  142. "ServiceComponentInfo/rm_metrics/cluster/activeNMcount," +
  143. "ServiceComponentInfo/rm_metrics/cluster/unhealthyNMcount," +
  144. "ServiceComponentInfo/rm_metrics/cluster/rebootedNMcount," +
  145. "ServiceComponentInfo/rm_metrics/cluster/decommissionedNMcount"]
  146. },
  147. {
  148. title: 'HBASE service',
  149. services: [
  150. {
  151. ServiceInfo: {
  152. service_name: 'HBASE'
  153. }
  154. }
  155. ],
  156. result: ["host_components/metrics/hbase/master/IsActiveMaster," +
  157. "ServiceComponentInfo/MasterStartTime," +
  158. "ServiceComponentInfo/MasterActiveTime," +
  159. "ServiceComponentInfo/AverageLoad," +
  160. "ServiceComponentInfo/Revision," +
  161. "ServiceComponentInfo/RegionsInTransition"]
  162. },
  163. {
  164. title: 'MAPREDUCE service',
  165. services: [
  166. {
  167. ServiceInfo: {
  168. service_name: 'MAPREDUCE'
  169. }
  170. }
  171. ],
  172. result: ["ServiceComponentInfo/AliveNodes," +
  173. "ServiceComponentInfo/GrayListedNodes," +
  174. "ServiceComponentInfo/BlackListedNodes," +
  175. "ServiceComponentInfo/jobtracker/*,"]
  176. },
  177. {
  178. title: 'STORM service',
  179. services: [
  180. {
  181. ServiceInfo: {
  182. service_name: 'STORM'
  183. }
  184. }
  185. ],
  186. result: ["metrics/api/v1/cluster/summary," +
  187. "metrics/api/v1/topology/summary"]
  188. }
  189. ];
  190. var testCasesByStackVersion = [
  191. {
  192. title: 'STORM service stack 2.1',
  193. services: [
  194. {
  195. ServiceInfo: {
  196. service_name: 'STORM'
  197. }
  198. }
  199. ],
  200. stackVersionNumber: '2.1',
  201. result: ["metrics/api/cluster/summary"]
  202. },
  203. {
  204. title: 'STORM service stack 2.2',
  205. services: [
  206. {
  207. ServiceInfo: {
  208. service_name: 'STORM'
  209. }
  210. }
  211. ],
  212. stackVersionNumber: '2.2',
  213. result: ["metrics/api/v1/cluster/summary,metrics/api/v1/topology/summary"]
  214. }
  215. ];
  216. testCases.forEach(function(test){
  217. it(test.title, function () {
  218. App.cache['services'] = test.services;
  219. expect(controller.getConditionalFields()).to.eql(test.result);
  220. });
  221. });
  222. testCasesByStackVersion.forEach(function(test) {
  223. it(test.title, function() {
  224. App.cache['services'] = test.services;
  225. sinon.stub(App, 'get', function(key) {
  226. if (key == 'currentStackVersionNumber') {
  227. return test.stackVersionNumber;
  228. }
  229. });
  230. expect(controller.getConditionalFields()).to.eql(test.result);
  231. App.get.restore();
  232. });
  233. });
  234. });
  235. });