assign_master_components_test.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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('mixins/wizard/assign_master_components');
  20. var c;
  21. describe('App.AssignMasterComponents', function () {
  22. var baseObject = Em.Object.extend(App.AssignMasterComponents);
  23. var data;
  24. beforeEach(function () {
  25. c = baseObject.create();
  26. c.set('content', {});
  27. var hosts = [];
  28. for(var i = 1; i <= 4; ++i) {
  29. hosts.push(App.Host.createRecord({
  30. 'host_name': 'h' + i
  31. }));
  32. }
  33. c.set('hosts', hosts);
  34. data = {
  35. "resources": [
  36. {
  37. "recommendations": {
  38. "blueprint": {
  39. "host_groups": [
  40. {
  41. "name": "host-group-1",
  42. "components": [{"name": "c1"}, {"name": "c3"}, {"name": "c2"}]
  43. },
  44. {
  45. "name": "host-group-2",
  46. "components": [{"name": "c1"}, {"name": "c2"}]
  47. },
  48. {
  49. "name": "host-group-3",
  50. "components": [{"name": "c1"}]
  51. }
  52. ]
  53. },
  54. "blueprint_cluster_binding": {
  55. "host_groups": [
  56. {
  57. "name": "host-group-1",
  58. "hosts": [{"fqdn": "h1"}]
  59. },
  60. {
  61. "name": "host-group-3",
  62. "hosts": [{"fqdn": "h3"}]
  63. },
  64. {
  65. "name": "host-group-2",
  66. "hosts": [{"fqdn": "h2"}, {"fqdn": "h4"}]
  67. }
  68. ]
  69. }
  70. }
  71. }
  72. ]
  73. };
  74. });
  75. describe('#loadRecommendationsSuccessCallback', function () {
  76. it('should set recommendations', function() {
  77. c.loadRecommendationsSuccessCallback(data);
  78. expect(c.get('content.recommendations')).to.eq(data.resources[0].recommendations);
  79. });
  80. it('should set recommendedHostsForComponents', function() {
  81. c.loadRecommendationsSuccessCallback(data);
  82. var expected = {
  83. "c1": ["h1", "h2", "h4", "h3"],
  84. "c3": ["h1"],
  85. "c2": ["h1", "h2", "h4"]
  86. };
  87. expect(JSON.stringify(c.get('content.recommendedHostsForComponents'))).to.equal(JSON.stringify(expected));
  88. });
  89. });
  90. describe('#getHostForMaster', function () {
  91. var allMasters;
  92. beforeEach(function () {
  93. allMasters = [
  94. {
  95. "component_name": "c1",
  96. "selectedHost": "h1"
  97. },
  98. {
  99. "component_name": "c1",
  100. "selectedHost": "h2"
  101. },
  102. {
  103. "component_name": "c1",
  104. "selectedHost": "h3"
  105. },
  106. {
  107. "component_name": "c1",
  108. "selectedHost": "h4"
  109. },
  110. {
  111. "component_name": "c2",
  112. "selectedHost": "h1"
  113. },
  114. {
  115. "component_name": "c5",
  116. "selectedHost": "h1"
  117. }
  118. ];
  119. });
  120. it('should return the recommended host', function() {
  121. c.loadRecommendationsSuccessCallback(data);
  122. expect(c.getHostForMaster('c2', allMasters)).to.eq('h2');
  123. });
  124. it('should return the first available host from the list of existing hosts', function() {
  125. c.loadRecommendationsSuccessCallback(data);
  126. expect(c.getHostForMaster('c6', allMasters)).to.eq('h1');
  127. });
  128. it('should return the next available host from the list of existing hosts', function() {
  129. c.loadRecommendationsSuccessCallback(data);
  130. expect(c.getHostForMaster('c5', allMasters)).to.eq('h2');
  131. });
  132. it('should return false if the component is already on all hosts', function() {
  133. c.loadRecommendationsSuccessCallback(data);
  134. expect(c.getHostForMaster('c1', allMasters)).to.eq(false);
  135. });
  136. });
  137. describe('#sortComponentsByServiceName', function () {
  138. var components = [{
  139. "component_name": "METRICS_COLLECTOR",
  140. "serviceId": "AMBARI_METRICS"
  141. }, {
  142. "component_name": "ZOOKEEPER_SERVER",
  143. "serviceId": "ZOOKEEPER"
  144. }, {
  145. "component_name": "NAMENODE",
  146. "serviceId": "HDFS"
  147. }, {
  148. "component_name": "DRPC_SERVER",
  149. "serviceId": "STORM"
  150. }, {
  151. "component_name": "APP_TIMELINE_SERVER",
  152. "serviceId": "YARN"
  153. }, {
  154. "component_name": "RESOURCEMANAGER",
  155. "serviceId": "YARN"
  156. }, {
  157. "component_name": "SECONDARY_NAMENODE",
  158. "serviceId": "HDFS"
  159. }, {
  160. "component_name": "ZOOKEEPER_SERVER",
  161. "serviceId": "ZOOKEEPER"
  162. }, {
  163. "component_name": "HISTORYSERVER",
  164. "serviceId": "MAPREDUCE2"
  165. }, {
  166. "component_name": "HAWQSTANDBY",
  167. "serviceId": "HAWQ"
  168. }, {
  169. "component_name": "NIMBUS",
  170. "serviceId": "STORM"
  171. }, {
  172. "component_name": "HAWQMASTER",
  173. "serviceId": "HAWQ"
  174. }, {
  175. "component_name": "STORM_UI_SERVER",
  176. "serviceId": "STORM"
  177. }];
  178. it('should place ZOOKEEPER_SERVER one after another', function () {
  179. var sorted = c.sortComponentsByServiceName(components);
  180. expect(sorted.mapProperty('component_name').join('|').contains('ZOOKEEPER_SERVER|ZOOKEEPER_SERVER')).to.be.true;
  181. });
  182. it('should place HAWQMASTER just before HAWQSTANDBY', function () {
  183. var sorted = c.sortComponentsByServiceName(components);
  184. expect(sorted.mapProperty('component_name').join('|').contains('HAWQMASTER|HAWQSTANDBY')).to.be.true;
  185. });
  186. });
  187. });