service_test.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. var modelSetup = require('test/init_model_test');
  20. require('models/service');
  21. var service,
  22. serviceData = {
  23. id: 'service'
  24. },
  25. healthCases = [
  26. {
  27. status: 'STARTED',
  28. health: 'green'
  29. },
  30. {
  31. status: 'STARTING',
  32. health: 'green-blinking'
  33. },
  34. {
  35. status: 'INSTALLED',
  36. health: 'red'
  37. },
  38. {
  39. status: 'STOPPING',
  40. health: 'red-blinking'
  41. },
  42. {
  43. status: 'UNKNOWN',
  44. health: 'yellow'
  45. },
  46. {
  47. status: 'ANOTHER',
  48. health: 'yellow'
  49. }
  50. ],
  51. statusPropertiesCases = [
  52. {
  53. status: 'INSTALLED',
  54. property: 'isStopped'
  55. },
  56. {
  57. status: 'STARTED',
  58. property: 'isStarted'
  59. }
  60. ],
  61. services = [
  62. {
  63. name: 'HDFS',
  64. configurable: true
  65. },
  66. {
  67. name: 'YARN',
  68. configurable: true
  69. },
  70. {
  71. name: 'MAPREDUCE2',
  72. configurable: true
  73. },
  74. {
  75. name:'TEZ',
  76. clientOnly: true,
  77. configurable: true
  78. },
  79. {
  80. name: 'HBASE',
  81. configurable: true
  82. },
  83. {
  84. name: 'HIVE',
  85. configurable: true
  86. },
  87. {
  88. name: 'FLUME',
  89. configurable: true
  90. },
  91. {
  92. name: 'FALCON',
  93. configurable: true
  94. },
  95. {
  96. name: 'STORM',
  97. configurable: true
  98. },
  99. {
  100. name: 'OOZIE',
  101. configurable: true
  102. },
  103. {
  104. name: 'GANGLIA',
  105. configurable: true
  106. },
  107. {
  108. name: 'ZOOKEEPER',
  109. configurable: true
  110. },
  111. {
  112. name: 'PIG',
  113. configurable: true,
  114. clientOnly: true
  115. },
  116. {
  117. name: 'SQOOP',
  118. clientOnly: true
  119. },
  120. {
  121. name: 'HUE',
  122. configurable: true
  123. }
  124. ],
  125. clientsOnly = services.filterProperty('clientOnly').mapProperty('name'),
  126. configurable = services.filterProperty('configurable').mapProperty('name'),
  127. hostComponentsDataFalse = [
  128. [],
  129. [
  130. {
  131. staleConfigs: false
  132. }
  133. ],
  134. [
  135. {
  136. service: {
  137. serviceName: 'HIVE'
  138. },
  139. staleConfigs: false
  140. }
  141. ]
  142. ],
  143. hostComponentsDataTrue = [
  144. [
  145. Em.Object.create({
  146. service: {
  147. serviceName: 'HDFS'
  148. },
  149. staleConfigs: true,
  150. displayName: 'service0'
  151. })
  152. ],
  153. [
  154. Em.Object.create({
  155. host: {
  156. publicHostName: 'host0'
  157. },
  158. service: {
  159. serviceName: 'HDFS'
  160. },
  161. staleConfigs: true,
  162. displayName: 'service1'
  163. })
  164. ]
  165. ],
  166. restartData = {
  167. host0: ['service0', 'service1']
  168. };
  169. describe('App.Service', function () {
  170. beforeEach(function () {
  171. service = App.Service.createRecord(serviceData);
  172. });
  173. afterEach(function () {
  174. modelSetup.deleteRecord(service);
  175. });
  176. describe('#isInPassive', function () {
  177. it('should be true', function () {
  178. service.set('passiveState', 'ON');
  179. expect(service.get('isInPassive')).to.be.true;
  180. });
  181. it('should be false', function () {
  182. service.set('passiveState', 'OFF');
  183. expect(service.get('isInPassive')).to.be.false;
  184. });
  185. });
  186. describe('#healthStatus', function () {
  187. healthCases.forEach(function (item) {
  188. it('should be ' + item.health, function () {
  189. service.set('workStatus', item.status);
  190. expect(service.get('healthStatus')).to.equal(item.health);
  191. });
  192. });
  193. });
  194. statusPropertiesCases.forEach(function (item) {
  195. var status = item.status,
  196. property = item.property;
  197. describe('#' + property, function () {
  198. it('status ' + status + ' is for ' + property, function () {
  199. service.set('workStatus', status);
  200. expect(service.get(property)).to.be.true;
  201. var falseStates = statusPropertiesCases.mapProperty('property').without(property);
  202. var falseStatuses = [];
  203. falseStates.forEach(function (state) {
  204. falseStatuses.push(service.get(state));
  205. });
  206. expect(falseStatuses).to.eql([false]);
  207. });
  208. });
  209. });
  210. describe('#isRestartRequired', function () {
  211. var mockHostComponentModel = function (mock) {
  212. sinon.stub(App.HostComponent, 'find', function () {
  213. return mock;
  214. });
  215. }
  216. beforeEach(function () {
  217. service.reopen({
  218. serviceName: 'HDFS'
  219. });
  220. });
  221. afterEach(function () {
  222. App.HostComponent.find.restore();
  223. });
  224. hostComponentsDataFalse.forEach(function (item) {
  225. it('should be false', function () {
  226. mockHostComponentModel(item);
  227. expect(service.get('isRestartRequired')).to.be.false;
  228. });
  229. });
  230. hostComponentsDataTrue.forEach(function (item) {
  231. it('should be true', function () {
  232. mockHostComponentModel(item);
  233. expect(service.get('isRestartRequired')).to.be.true;
  234. });
  235. });
  236. });
  237. describe('#restartRequiredMessage', function () {
  238. it('should form message for 2 services on 1 host', function () {
  239. service.set('restartRequiredHostsAndComponents', restartData);
  240. expect(service.get('restartRequiredMessage')).to.contain('host0');
  241. expect(service.get('restartRequiredMessage')).to.contain('service0');
  242. expect(service.get('restartRequiredMessage')).to.contain('service1');
  243. });
  244. });
  245. describe('#serviceTypes', function () {
  246. var testCases = [
  247. {
  248. serviceName: 'PIG',
  249. result: []
  250. },
  251. {
  252. serviceName: 'GANGLIA',
  253. result: ['MONITORING']
  254. },
  255. {
  256. serviceName: 'HDFS',
  257. result: ['HA_MODE']
  258. },
  259. {
  260. serviceName: 'YARN',
  261. result: ['HA_MODE']
  262. }
  263. ];
  264. testCases.forEach(function (test) {
  265. it('service name - ' + test.serviceName, function () {
  266. service.set('serviceName', test.serviceName);
  267. service.propertyDidChange('serviceTypes');
  268. expect(service.get('serviceTypes')).to.eql(test.result);
  269. });
  270. });
  271. });
  272. });