service_test.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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: 'HCATALOG',
  93. clientOnly: true
  94. },
  95. {
  96. name: 'WEBHCAT',
  97. configurable: true
  98. },
  99. {
  100. name: 'FLUME',
  101. configurable: true
  102. },
  103. {
  104. name: 'FALCON',
  105. configurable: true
  106. },
  107. {
  108. name: 'STORM',
  109. configurable: true
  110. },
  111. {
  112. name: 'OOZIE',
  113. configurable: true
  114. },
  115. {
  116. name: 'GANGLIA',
  117. configurable: true
  118. },
  119. {
  120. name: 'NAGIOS',
  121. configurable: true
  122. },
  123. {
  124. name: 'ZOOKEEPER',
  125. configurable: true
  126. },
  127. {
  128. name: 'PIG',
  129. configurable: true,
  130. clientOnly: true
  131. },
  132. {
  133. name: 'SQOOP',
  134. clientOnly: true
  135. },
  136. {
  137. name: 'HUE',
  138. configurable: true
  139. }
  140. ],
  141. clientsOnly = services.filterProperty('clientOnly').mapProperty('name'),
  142. configurable = services.filterProperty('configurable').mapProperty('name'),
  143. hostComponentsDataFalse = [
  144. [],
  145. [
  146. {
  147. staleConfigs: false
  148. }
  149. ],
  150. [
  151. {
  152. serviceName: 'HIVE',
  153. staleConfigs: false
  154. }
  155. ]
  156. ],
  157. hostComponentsDataTrue = [
  158. [
  159. Em.Object.create({
  160. staleConfigs: true,
  161. displayName: 'service0'
  162. })
  163. ],
  164. [
  165. Em.Object.create({
  166. host: {
  167. publicHostName: 'host0'
  168. },
  169. staleConfigs: true,
  170. displayName: 'service1'
  171. })
  172. ]
  173. ],
  174. restartData = {
  175. host0: ['service0', 'service1']
  176. };
  177. describe('App.Service', function () {
  178. beforeEach(function () {
  179. service = App.Service.createRecord(serviceData);
  180. });
  181. afterEach(function () {
  182. modelSetup.deleteRecord(service);
  183. });
  184. describe('#isInPassive', function () {
  185. it('should be true', function () {
  186. service.set('passiveState', 'ON');
  187. expect(service.get('isInPassive')).to.be.true;
  188. });
  189. it('should be false', function () {
  190. service.set('passiveState', 'OFF');
  191. expect(service.get('isInPassive')).to.be.false;
  192. });
  193. });
  194. describe('#healthStatus', function () {
  195. healthCases.forEach(function (item) {
  196. it('should be ' + item.health, function () {
  197. service.set('workStatus', item.status);
  198. expect(service.get('healthStatus')).to.equal(item.health);
  199. });
  200. });
  201. });
  202. statusPropertiesCases.forEach(function (item) {
  203. var status = item.status,
  204. property = item.property;
  205. describe('#' + property, function () {
  206. it('status ' + status + ' is for ' + property, function () {
  207. service.set('workStatus', status);
  208. expect(service.get(property)).to.be.true;
  209. var falseStates = statusPropertiesCases.mapProperty('property').without(property);
  210. var falseStatuses = [];
  211. falseStates.forEach(function (state) {
  212. falseStatuses.push(service.get(state));
  213. });
  214. expect(falseStatuses).to.eql([false]);
  215. });
  216. });
  217. });
  218. describe('#isClientsOnly', function () {
  219. clientsOnly.forEach(function (item) {
  220. it('should be true', function () {
  221. service.set('serviceName', item);
  222. expect(service.get('isClientsOnly')).to.be.true;
  223. });
  224. });
  225. it('should be false', function () {
  226. service.set('serviceName', 'HDFS');
  227. expect(service.get('isClientsOnly')).to.be.false;
  228. });
  229. });
  230. describe('#isConfigurable', function () {
  231. configurable.forEach(function (item) {
  232. it('should be true', function () {
  233. service.set('serviceName', item);
  234. expect(service.get('isConfigurable')).to.be.true;
  235. });
  236. });
  237. it('should be false', function () {
  238. service.set('serviceName', 'SQOOP');
  239. expect(service.get('isConfigurable')).to.be.false;
  240. });
  241. });
  242. describe('#displayName', function () {
  243. services.forEach(function (item) {
  244. var displayName = App.Service.DisplayNames[item.name];
  245. it('should return ' + displayName, function () {
  246. service.set('serviceName', item.name);
  247. expect(service.get('displayName')).to.equal(displayName);
  248. });
  249. });
  250. });
  251. describe('#isRestartRequired', function () {
  252. hostComponentsDataFalse.forEach(function (item) {
  253. it('should be false', function () {
  254. service.reopen({
  255. hostComponents: item
  256. });
  257. expect(service.get('isRestartRequired')).to.be.false;
  258. });
  259. });
  260. hostComponentsDataTrue.forEach(function (item) {
  261. it('should be true', function () {
  262. service.reopen({
  263. hostComponents: item
  264. });
  265. expect(service.get('isRestartRequired')).to.be.true;
  266. });
  267. });
  268. });
  269. describe('#restartRequiredMessage', function () {
  270. it('should form message for 2 services on 1 host', function () {
  271. service.set('restartRequiredHostsAndComponents', restartData);
  272. expect(service.get('restartRequiredMessage')).to.contain('host0');
  273. expect(service.get('restartRequiredMessage')).to.contain('service0');
  274. expect(service.get('restartRequiredMessage')).to.contain('service1');
  275. });
  276. });
  277. });