assign_master_components_test.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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('recommendations')).to.eq(data.resources[0].recommendations);
  79. });
  80. it('should set recommendedHostsForComponents and content.recommendations for wizard page', function() {
  81. c.set('content.controllerName','installerController');
  82. c.loadRecommendationsSuccessCallback(data);
  83. var expected = {
  84. "c1": ["h1", "h2", "h4", "h3"],
  85. "c3": ["h1"],
  86. "c2": ["h1", "h2", "h4"]
  87. };
  88. expect(JSON.stringify(c.get('content.recommendedHostsForComponents'))).to.equal(JSON.stringify(expected));
  89. expect(c.get('content.recommendations')).to.eq(data.resources[0].recommendations);
  90. });
  91. });
  92. describe('#getHostForMaster', function () {
  93. var allMasters;
  94. beforeEach(function () {
  95. allMasters = [
  96. {
  97. "component_name": "c1",
  98. "selectedHost": "h1"
  99. },
  100. {
  101. "component_name": "c1",
  102. "selectedHost": "h2"
  103. },
  104. {
  105. "component_name": "c1",
  106. "selectedHost": "h3"
  107. },
  108. {
  109. "component_name": "c1",
  110. "selectedHost": "h4"
  111. },
  112. {
  113. "component_name": "c2",
  114. "selectedHost": "h1"
  115. },
  116. {
  117. "component_name": "c5",
  118. "selectedHost": "h1"
  119. }
  120. ];
  121. });
  122. it('should return the recommended host', function() {
  123. c.loadRecommendationsSuccessCallback(data);
  124. expect(c.getHostForMaster('c2', allMasters)).to.eq('h2');
  125. });
  126. it('should return the first available host from the list of existing hosts', function() {
  127. c.loadRecommendationsSuccessCallback(data);
  128. expect(c.getHostForMaster('c6', allMasters)).to.eq('h1');
  129. });
  130. it('should return the next available host from the list of existing hosts', function() {
  131. c.loadRecommendationsSuccessCallback(data);
  132. expect(c.getHostForMaster('c5', allMasters)).to.eq('h2');
  133. });
  134. it('should return false if the component is already on all hosts', function() {
  135. c.loadRecommendationsSuccessCallback(data);
  136. expect(c.getHostForMaster('c1', allMasters)).to.eq(false);
  137. });
  138. });
  139. describe('#sortComponentsByServiceName', function () {
  140. var components = [{
  141. "component_name": "METRICS_COLLECTOR",
  142. "serviceId": "AMBARI_METRICS"
  143. }, {
  144. "component_name": "ZOOKEEPER_SERVER",
  145. "serviceId": "ZOOKEEPER"
  146. }, {
  147. "component_name": "NAMENODE",
  148. "serviceId": "HDFS"
  149. }, {
  150. "component_name": "DRPC_SERVER",
  151. "serviceId": "STORM"
  152. }, {
  153. "component_name": "APP_TIMELINE_SERVER",
  154. "serviceId": "YARN"
  155. }, {
  156. "component_name": "RESOURCEMANAGER",
  157. "serviceId": "YARN"
  158. }, {
  159. "component_name": "SECONDARY_NAMENODE",
  160. "serviceId": "HDFS"
  161. }, {
  162. "component_name": "ZOOKEEPER_SERVER",
  163. "serviceId": "ZOOKEEPER"
  164. }, {
  165. "component_name": "HISTORYSERVER",
  166. "serviceId": "MAPREDUCE2"
  167. }, {
  168. "component_name": "HAWQSTANDBY",
  169. "serviceId": "HAWQ"
  170. }, {
  171. "component_name": "NIMBUS",
  172. "serviceId": "STORM"
  173. }, {
  174. "component_name": "HAWQMASTER",
  175. "serviceId": "HAWQ"
  176. }, {
  177. "component_name": "STORM_UI_SERVER",
  178. "serviceId": "STORM"
  179. }];
  180. it('should place ZOOKEEPER_SERVER one after another', function () {
  181. var sorted = c.sortComponentsByServiceName(components);
  182. expect(sorted.mapProperty('component_name').join('|').contains('ZOOKEEPER_SERVER|ZOOKEEPER_SERVER')).to.be.true;
  183. });
  184. it('should place HAWQMASTER just before HAWQSTANDBY', function () {
  185. var sorted = c.sortComponentsByServiceName(components);
  186. expect(sorted.mapProperty('component_name').join('|').contains('HAWQMASTER|HAWQSTANDBY')).to.be.true;
  187. });
  188. });
  189. App.TestAliases.testAsComputedOr(baseObject.create(),
  190. 'nextButtonDisabled', ['App.router.btnClickInProgress', 'submitDisabled', 'validationInProgress']);
  191. });