stack_service_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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('models/stack_service');
  20. describe('App.StackService', function () {
  21. App.store.load(App.StackService, {
  22. id: 'S1'
  23. });
  24. var ss = App.StackService.find('S1');
  25. ss.reopen({
  26. serviceComponents: []
  27. });
  28. describe('#isDFS', function () {
  29. it('service name is "SERVICE"', function () {
  30. ss.set('serviceName', 'SERVICE');
  31. ss.propertyDidChange('isDFS');
  32. expect(ss.get('isDFS')).to.be.false;
  33. });
  34. it('service name is "HDFS"', function () {
  35. ss.set('serviceName', 'HDFS');
  36. ss.propertyDidChange('isDFS');
  37. expect(ss.get('isDFS')).to.be.true;
  38. });
  39. it('service name is "GLUSTERFS"', function () {
  40. ss.set('serviceName', 'GLUSTERFS');
  41. ss.propertyDidChange('isDFS');
  42. expect(ss.get('isDFS')).to.be.true;
  43. });
  44. });
  45. describe('#isPrimaryDFS', function () {
  46. it('service name is "SERVICE"', function () {
  47. ss.set('serviceName', 'SERVICE');
  48. ss.propertyDidChange('isPrimaryDFS');
  49. expect(ss.get('isPrimaryDFS')).to.be.false;
  50. });
  51. it('service name is "HDFS"', function () {
  52. ss.set('serviceName', 'HDFS');
  53. ss.propertyDidChange('isPrimaryDFS');
  54. expect(ss.get('isPrimaryDFS')).to.be.true;
  55. });
  56. });
  57. describe('#configTypesRendered', function () {
  58. ss.set('configTypes', {
  59. 'core-site': {},
  60. 'hdfs-site': {},
  61. 'oozie-site': {}
  62. });
  63. it('service name is "SERVICE"', function () {
  64. ss.set('serviceName', 'SERVICE');
  65. ss.propertyDidChange('configTypesRendered');
  66. expect(ss.get('configTypesRendered')).to.eql({'core-site': {},'hdfs-site': {}, 'oozie-site': {}});
  67. });
  68. it('service name is "GLUSTERFS"', function () {
  69. ss.set('serviceName', 'GLUSTERFS');
  70. ss.propertyDidChange('configTypesRendered');
  71. expect(ss.get('configTypesRendered')).to.eql({'core-site': {},'hdfs-site': {}, 'oozie-site': {}});
  72. });
  73. it('service name is "HDFS"', function () {
  74. ss.set('serviceName', 'HDFS');
  75. ss.propertyDidChange('configTypesRendered');
  76. expect(ss.get('configTypesRendered')).to.eql({'core-site': {}, 'hdfs-site': {}, 'oozie-site': {}});
  77. });
  78. it('service name is "FALCON"', function () {
  79. ss.set('serviceName', 'FALCON');
  80. ss.propertyDidChange('configTypesRendered');
  81. expect(ss.get('configTypesRendered')).to.eql({'core-site': {}, 'hdfs-site': {}});
  82. });
  83. });
  84. describe('#displayNameOnSelectServicePage', function () {
  85. it('No coSelectedServices', function () {
  86. ss.set('serviceName', 'HDFS');
  87. ss.set('displayName', 'HDFS');
  88. ss.propertyDidChange('displayNameOnSelectServicePage');
  89. expect(ss.get('displayNameOnSelectServicePage')).to.equal('HDFS');
  90. });
  91. it('Present coSelectedServices', function () {
  92. ss.set('serviceName', 'YARN');
  93. ss.set('displayName', 'YARN');
  94. ss.propertyDidChange('displayNameOnSelectServicePage');
  95. expect(ss.get('displayNameOnSelectServicePage')).to.equal('YARN + MapReduce2');
  96. });
  97. });
  98. describe('#isHiddenOnSelectServicePage', function () {
  99. var testCases = [
  100. {
  101. serviceName: 'HDFS',
  102. isInstallable: true,
  103. result: false
  104. },
  105. {
  106. serviceName: 'MAPREDUCE2',
  107. isInstallable: true,
  108. result: true
  109. },
  110. {
  111. serviceName: 'KERBEROS',
  112. isInstallable: false,
  113. result: true
  114. }
  115. ];
  116. testCases.forEach(function (test) {
  117. it('service name - ' + test.serviceName, function () {
  118. ss.set('serviceName', test.serviceName);
  119. ss.set('isInstallable', test.isInstallable);
  120. ss.propertyDidChange('isHiddenOnSelectServicePage');
  121. expect(ss.get('isHiddenOnSelectServicePage')).to.equal(test.result);
  122. });
  123. });
  124. });
  125. describe('#isMonitoringService', function () {
  126. var testCases = [
  127. {
  128. serviceName: 'HDFS',
  129. result: false
  130. },
  131. {
  132. serviceName: 'GANGLIA',
  133. result: true
  134. }
  135. ];
  136. testCases.forEach(function (test) {
  137. it('service name - ' + test.serviceName, function () {
  138. ss.set('serviceName', test.serviceName);
  139. ss.propertyDidChange('isMonitoringService');
  140. expect(ss.get('isMonitoringService')).to.equal(test.result);
  141. });
  142. });
  143. });
  144. describe('#hasClient', function () {
  145. it('No client serviceComponents', function () {
  146. ss.set('serviceComponents', []);
  147. ss.propertyDidChange('hasClient');
  148. expect(ss.get('hasClient')).to.be.false;
  149. });
  150. it('Has client serviceComponents', function () {
  151. ss.set('serviceComponents', [Em.Object.create({isClient: true})]);
  152. ss.propertyDidChange('hasClient');
  153. expect(ss.get('hasClient')).to.be.true;
  154. });
  155. });
  156. describe('#hasMaster', function () {
  157. it('No master serviceComponents', function () {
  158. ss.set('serviceComponents', []);
  159. ss.propertyDidChange('hasMaster');
  160. expect(ss.get('hasMaster')).to.be.false;
  161. });
  162. it('Has master serviceComponents', function () {
  163. ss.set('serviceComponents', [Em.Object.create({isMaster: true})]);
  164. ss.propertyDidChange('hasMaster');
  165. expect(ss.get('hasMaster')).to.be.true;
  166. });
  167. });
  168. describe('#hasSlave', function () {
  169. it('No slave serviceComponents', function () {
  170. ss.set('serviceComponents', []);
  171. ss.propertyDidChange('hasSlave');
  172. expect(ss.get('hasSlave')).to.be.false;
  173. });
  174. it('Has slave serviceComponents', function () {
  175. ss.set('serviceComponents', [Em.Object.create({isSlave: true})]);
  176. ss.propertyDidChange('hasSlave');
  177. expect(ss.get('hasSlave')).to.be.true;
  178. });
  179. });
  180. describe('#hasNonMastersWithCustomAssignment', function () {
  181. it('No serviceComponents', function () {
  182. ss.set('serviceComponents', []);
  183. ss.propertyDidChange('hasNonMastersWithCustomAssignment');
  184. expect(ss.get('hasNonMastersWithCustomAssignment')).to.be.false;
  185. });
  186. it('All non-master serviceComponents are required on all hosts', function () {
  187. ss.set('serviceComponents', [Em.Object.create({isMaster: true}), Em.Object.create({isSlave: true, cardinality: 'ALL'}), Em.Object.create({isClient: true, cardinality: 'ALL'})]);
  188. ss.propertyDidChange('hasNonMastersWithCustomAssignment');
  189. expect(ss.get('hasNonMastersWithCustomAssignment')).to.be.false;
  190. });
  191. it('Has non-master serviceComponents not required on all hosts', function () {
  192. ss.set('serviceComponents', [Em.Object.create({isSlave: true}), Em.Object.create({isClient: true})]);
  193. ss.propertyDidChange('hasNonMastersWithCustomAssignment');
  194. expect(ss.get('hasNonMastersWithCustomAssignment')).to.be.true;
  195. });
  196. });
  197. App.TestAliases.testAsComputedEveryBy(ss, 'isClientOnlyService', 'serviceComponents', 'isClient', true);
  198. describe('#isNoConfigTypes', function () {
  199. it('configTypes is null', function () {
  200. ss.set('configTypes', null);
  201. ss.propertyDidChange('isNoConfigTypes');
  202. expect(ss.get('isNoConfigTypes')).to.be.true;
  203. });
  204. it('configTypes is empty', function () {
  205. ss.set('configTypes', {});
  206. ss.propertyDidChange('isNoConfigTypes');
  207. expect(ss.get('isNoConfigTypes')).to.be.true;
  208. });
  209. it('configTypes is correct', function () {
  210. ss.set('configTypes', {'key': {}});
  211. ss.propertyDidChange('isNoConfigTypes');
  212. expect(ss.get('isNoConfigTypes')).to.be.false;
  213. });
  214. });
  215. describe('#customReviewHandler', function () {
  216. it('service name is HDFS', function () {
  217. ss.set('serviceName', 'HDFS');
  218. ss.propertyDidChange('customReviewHandler');
  219. expect(ss.get('customReviewHandler')).to.be.undefined;
  220. });
  221. it('service name is HIVE', function () {
  222. ss.set('serviceName', 'HIVE');
  223. ss.propertyDidChange('customReviewHandler');
  224. expect(ss.get('customReviewHandler')).to.eql({
  225. "Database": "loadHiveDbValue"
  226. });
  227. });
  228. });
  229. describe('#configCategories', function () {
  230. it('HDFS service with no serviceComponents', function () {
  231. ss.set('serviceComponents', []);
  232. ss.set('serviceName', 'HDFS');
  233. ss.propertyDidChange('configCategories');
  234. expect(ss.get('configCategories').mapProperty('name')).to.eql([
  235. "General",
  236. "Advanced",
  237. "Advanced key"
  238. ]);
  239. });
  240. it('HDFS service with DATANODE serviceComponents', function () {
  241. ss.set('serviceComponents', [Em.Object.create({componentName: 'DATANODE'})]);
  242. ss.set('serviceName', 'HDFS');
  243. ss.propertyDidChange('configCategories');
  244. expect(ss.get('configCategories').mapProperty('name')).to.eql([
  245. "DATANODE",
  246. "General",
  247. "Advanced",
  248. "Advanced key"]);
  249. });
  250. it('HDFS service with custom serviceComponents', function () {
  251. ss.set('serviceComponents', [Em.Object.create({componentName: 'DATANODE'})]);
  252. ss.set('serviceName', 'HDFS');
  253. ss.set('configTypes', { key: { supports: {adding_forbidden: "false"}}});
  254. ss.propertyDidChange('configCategories');
  255. expect(ss.get('configCategories').mapProperty('name')).to.eql([
  256. "DATANODE",
  257. "General",
  258. "Advanced",
  259. "Advanced key",
  260. "Custom key"]);
  261. });
  262. });
  263. describe('#isDisabled', function () {
  264. var cases = [
  265. {
  266. isInstalled: true,
  267. isMandatory: true,
  268. clusterInstallCompleted: true,
  269. isDisabled: true
  270. },
  271. {
  272. isInstalled: true,
  273. isMandatory: true,
  274. clusterInstallCompleted: false,
  275. isDisabled: true
  276. },
  277. {
  278. isInstalled: true,
  279. isMandatory: false,
  280. clusterInstallCompleted: true,
  281. isDisabled: true
  282. },
  283. {
  284. isInstalled: true,
  285. isMandatory: false,
  286. clusterInstallCompleted: false,
  287. isDisabled: true
  288. },
  289. {
  290. isInstalled: false,
  291. isMandatory: true,
  292. clusterInstallCompleted: true,
  293. isDisabled: false
  294. },
  295. {
  296. isInstalled: false,
  297. isMandatory: true,
  298. clusterInstallCompleted: false,
  299. isDisabled: true
  300. },
  301. {
  302. isInstalled: false,
  303. isMandatory: false,
  304. clusterInstallCompleted: true,
  305. isDisabled: false
  306. },
  307. {
  308. isInstalled: false,
  309. isMandatory: false,
  310. clusterInstallCompleted: false,
  311. isDisabled: false
  312. }
  313. ];
  314. cases.forEach(function (testCase) {
  315. var title = 'isInstalled: {0}, isMandatory: {1}, clusterInstallCompleted: {2}, isDisabled: {3}'
  316. .format(testCase.isInstalled, testCase.isMandatory, testCase.clusterInstallCompleted, testCase.isDisabled);
  317. it(title, function () {
  318. ss.setProperties({
  319. isInstalled: testCase.isInstalled,
  320. isMandatory: testCase.isMandatory
  321. });
  322. App.set('router.clusterInstallCompleted', testCase.clusterInstallCompleted);
  323. expect(ss.get('isDisabled')).to.equal(testCase.isDisabled);
  324. });
  325. });
  326. });
  327. });