service_config_test.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 configPropertyHelper = require('utils/configs/config_property_helper');
  20. require('models/configs/objects/service_config');
  21. var serviceConfig,
  22. group,
  23. configsData = [
  24. Ember.Object.create({
  25. category: 'c0',
  26. overrides: [
  27. {
  28. error: true,
  29. errorMessage: 'error'
  30. },
  31. {
  32. error: true
  33. },
  34. {}
  35. ]
  36. }),
  37. Ember.Object.create({
  38. category: 'c1',
  39. isValid: false,
  40. isVisible: true
  41. }),
  42. Ember.Object.create({
  43. category: 'c0',
  44. isValid: true,
  45. isVisible: true
  46. }),
  47. Ember.Object.create({
  48. category: 'c1',
  49. isValid: false,
  50. isVisible: false
  51. })
  52. ],
  53. configCategoriesData = [
  54. Em.Object.create({
  55. name: 'c0',
  56. slaveErrorCount: 1
  57. }),
  58. Em.Object.create({
  59. name: 'c1',
  60. slaveErrorCount: 2
  61. })
  62. ],
  63. components = [
  64. {
  65. name: 'NameNode',
  66. master: true
  67. },
  68. {
  69. name: 'SNameNode',
  70. master: true
  71. },
  72. {
  73. name: 'JobTracker',
  74. master: true
  75. },
  76. {
  77. name: 'HBase Master',
  78. master: true
  79. },
  80. {
  81. name: 'Oozie Master',
  82. master: true
  83. },
  84. {
  85. name: 'Hive Metastore',
  86. master: true
  87. },
  88. {
  89. name: 'WebHCat Server',
  90. master: true
  91. },
  92. {
  93. name: 'ZooKeeper Server',
  94. master: true
  95. },
  96. {
  97. name: 'Ganglia',
  98. master: true
  99. },
  100. {
  101. name: 'DataNode',
  102. slave: true
  103. },
  104. {
  105. name: 'TaskTracker',
  106. slave: true
  107. },
  108. {
  109. name: 'RegionServer',
  110. slave: true
  111. }
  112. ],
  113. masters = components.filterProperty('master'),
  114. slaves = components.filterProperty('slave'),
  115. groupNoErrorsData = [].concat(configsData.slice(2)),
  116. groupErrorsData = [configsData[1]];
  117. describe('App.ServiceConfig', function () {
  118. beforeEach(function () {
  119. serviceConfig = App.ServiceConfig.create();
  120. });
  121. describe('#errorCount', function () {
  122. it('should be 0', function () {
  123. serviceConfig.setProperties({
  124. configs: [],
  125. configCategories: []
  126. });
  127. expect(serviceConfig.get('errorCount')).to.equal(0);
  128. });
  129. it('should sum counts of all errors', function () {
  130. serviceConfig.setProperties({
  131. configs: configsData,
  132. configCategories: configCategoriesData
  133. });
  134. expect(serviceConfig.get('errorCount')).to.equal(6);
  135. expect(serviceConfig.get('configCategories').findProperty('name', 'c0').get('nonSlaveErrorCount')).to.equal(2);
  136. expect(serviceConfig.get('configCategories').findProperty('name', 'c1').get('nonSlaveErrorCount')).to.equal(1);
  137. });
  138. it('should include invalid properties with widgets', function() {
  139. serviceConfig.setProperties({
  140. configs: [
  141. Em.Object.create({
  142. isValid: false,
  143. widgetType: 'type',
  144. isVisible: true,
  145. category: 'some1'
  146. }),
  147. Em.Object.create({
  148. isValid: false,
  149. widgetType: 'type',
  150. isVisible: true,
  151. category: 'some2'
  152. }),
  153. Em.Object.create({
  154. isValid: false,
  155. widgetType: null,
  156. isVisible: true,
  157. category: 'some2'
  158. }),
  159. Em.Object.create({
  160. isValid: false,
  161. widgetType: 'type',
  162. isVisible: true
  163. })
  164. ],
  165. configCategories: [
  166. Em.Object.create({ name: 'some1', slaveErrorCount: 0}),
  167. Em.Object.create({ name: 'some2', slaveErrorCount: 0})
  168. ]
  169. });
  170. expect(serviceConfig.get('errorCount')).to.equal(4);
  171. });
  172. });
  173. });
  174. describe('App.Group', function () {
  175. beforeEach(function () {
  176. group = App.Group.create();
  177. });
  178. describe('#errorCount', function () {
  179. it('should be 0', function () {
  180. group.set('properties', groupNoErrorsData);
  181. expect(group.get('errorCount')).to.equal(0);
  182. });
  183. it('should be 1', function () {
  184. group.set('properties', groupErrorsData);
  185. expect(group.get('errorCount')).to.equal(1);
  186. });
  187. });
  188. });