service_test.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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: 'MAPREDUCE',
  72. configurable: true
  73. },
  74. {
  75. name: 'MAPREDUCE2',
  76. configurable: true
  77. },
  78. {
  79. name:'TEZ',
  80. clientOnly: true,
  81. configurable: true
  82. },
  83. {
  84. name: 'HBASE',
  85. configurable: true
  86. },
  87. {
  88. name: 'HIVE',
  89. configurable: true
  90. },
  91. {
  92. name: 'FLUME',
  93. configurable: true
  94. },
  95. {
  96. name: 'FALCON',
  97. configurable: true
  98. },
  99. {
  100. name: 'STORM',
  101. configurable: true
  102. },
  103. {
  104. name: 'OOZIE',
  105. configurable: true
  106. },
  107. {
  108. name: 'GANGLIA',
  109. configurable: true
  110. },
  111. {
  112. name: 'NAGIOS',
  113. configurable: true
  114. },
  115. {
  116. name: 'ZOOKEEPER',
  117. configurable: true
  118. },
  119. {
  120. name: 'PIG',
  121. configurable: true,
  122. clientOnly: true
  123. },
  124. {
  125. name: 'SQOOP',
  126. clientOnly: true
  127. },
  128. {
  129. name: 'HUE',
  130. configurable: true
  131. }
  132. ],
  133. clientsOnly = services.filterProperty('clientOnly').mapProperty('name'),
  134. configurable = services.filterProperty('configurable').mapProperty('name'),
  135. hostComponentsDataFalse = [
  136. [],
  137. [
  138. {
  139. staleConfigs: false
  140. }
  141. ],
  142. [
  143. {
  144. serviceName: 'HIVE',
  145. staleConfigs: false
  146. }
  147. ]
  148. ],
  149. hostComponentsDataTrue = [
  150. [
  151. Em.Object.create({
  152. staleConfigs: true,
  153. displayName: 'service0'
  154. })
  155. ],
  156. [
  157. Em.Object.create({
  158. host: {
  159. publicHostName: 'host0'
  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. hostComponentsDataFalse.forEach(function (item) {
  212. it('should be false', function () {
  213. service.reopen({
  214. hostComponents: item
  215. });
  216. expect(service.get('isRestartRequired')).to.be.false;
  217. });
  218. });
  219. hostComponentsDataTrue.forEach(function (item) {
  220. it('should be true', function () {
  221. service.reopen({
  222. hostComponents: item
  223. });
  224. expect(service.get('isRestartRequired')).to.be.true;
  225. });
  226. });
  227. });
  228. describe('#restartRequiredMessage', function () {
  229. it('should form message for 2 services on 1 host', function () {
  230. service.set('restartRequiredHostsAndComponents', restartData);
  231. expect(service.get('restartRequiredMessage')).to.contain('host0');
  232. expect(service.get('restartRequiredMessage')).to.contain('service0');
  233. expect(service.get('restartRequiredMessage')).to.contain('service1');
  234. });
  235. });
  236. describe('#serviceTypes', function () {
  237. var testCases = [
  238. {
  239. serviceName: 'PIG',
  240. result: []
  241. },
  242. {
  243. serviceName: 'GANGLIA',
  244. result: ['MONITORING']
  245. },
  246. {
  247. serviceName: 'NAGIOS',
  248. result: ['MONITORING']
  249. },
  250. {
  251. serviceName: 'HDFS',
  252. result: ['HA_MODE']
  253. },
  254. {
  255. serviceName: 'YARN',
  256. result: ['HA_MODE']
  257. }
  258. ];
  259. testCases.forEach(function (test) {
  260. it('service name - ' + test.serviceName, function () {
  261. service.set('serviceName', test.serviceName);
  262. service.propertyDidChange('serviceTypes');
  263. expect(service.get('serviceTypes')).to.eql(test.result);
  264. });
  265. });
  266. });
  267. });