step5_test.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('controllers/installer/step5_controller');
  21. describe('App.InstallerStep5Controller', function () {
  22. var controller = App.InstallerStep5Controller.create();
  23. controller.get("selectedServices").pushObject({service_name: 'ZOOKEEPER'});
  24. var cpu = 2, memory = 4;
  25. var HOST = ['host1', 'host2', 'host3', 'host4', 'host5'];
  26. var hosts = [];
  27. HOST.forEach(function (_host) {
  28. controller.get('hosts').pushObject(Ember.Object.create({
  29. host_name: _host,
  30. cpu: cpu,
  31. memory: memory
  32. }));
  33. });
  34. var componentObj = Ember.Object.create({
  35. component_name: 'ZooKeeper',
  36. selectedHost: 'host2', // call the method that plays selectNode algorithm or fetches from server
  37. availableHosts: []
  38. });
  39. componentObj.set('availableHosts', controller.get('hosts').slice(0));
  40. componentObj.set('zId', 1);
  41. componentObj.set("showAddControl", true);
  42. componentObj.set("showRemoveControl", false);
  43. controller.get("selectedServicesMasters").pushObject(componentObj);
  44. describe('#getAvailableHosts()', function () {
  45. it('should generate available hosts for a new zookeeper service', function () {
  46. var hostsForNewZookeepers = controller.getAvailableHosts("ZooKeeper"),
  47. ok = true, i = 0, masters = null;
  48. //test that the hosts found, do not have Zookeeper master assigned to them
  49. for (i = 0; i < hostsForNewZookeepers.get("length"); i++) {
  50. masters = controller.get("selectedServicesMasters").filterProperty(hostsForNewZookeepers[i].get("host_name"));
  51. if (masters.findProperty("component_name", "ZooKeeper")) {
  52. ok = false;
  53. break;
  54. }
  55. }
  56. expect(ok).to.equal(true);
  57. })
  58. it('should return all hosts for services other than ZooKeeper', function () {
  59. var hostsForNewZookeepers = controller.getAvailableHosts("");
  60. expect(hostsForNewZookeepers.get("length")).to.equal(controller.get("hosts.length"));
  61. })
  62. })
  63. describe('#assignHostToMaster()', function () {
  64. it('should assign the selected host to the non-ZooKeeper master service', function () {
  65. //test non-zookeeper master
  66. var SERVICE_MASTER = "NameNode",
  67. HOST = "host4", ZID, status;
  68. var nonZookeeperObj = Ember.Object.create({
  69. component_name: SERVICE_MASTER,
  70. selectedHost: HOST, // call the method that plays selectNode algorithm or fetches from server
  71. availableHosts: []
  72. });
  73. controller.get("selectedServicesMasters").pushObject(nonZookeeperObj);
  74. controller.assignHostToMaster(SERVICE_MASTER, HOST);
  75. expect(controller.get("selectedServicesMasters").findProperty("component_name", SERVICE_MASTER).get("selectedHost")).to.equal(HOST);
  76. })
  77. it('should assign the selected host to the ZooKeeper master service', function () {
  78. //test non-zookeeper master
  79. var SERVICE_MASTER = "ZooKeeper",
  80. HOST = "host4", ZID = 2;
  81. //test zookeeper master assignment with
  82. if (controller.addZookeepers()) {
  83. controller.assignHostToMaster(SERVICE_MASTER, HOST, ZID);
  84. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").findProperty("zId", ZID).get("selectedHost")).to.equal(HOST);
  85. }
  86. })
  87. })
  88. describe('#addZookeepers()', function () {
  89. it('should add a new ZooKeeper', function () {
  90. var newLength = 0;
  91. if (controller.get("selectedServices").mapProperty("service_name").contains("ZOOKEEPER")
  92. && controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length") < controller.get("hosts.length")) {
  93. newLength = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length");
  94. controller.addZookeepers();
  95. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(newLength + 1);
  96. }
  97. })
  98. it('should add ZooKeepers up to the number of hosts', function () {
  99. var currentZooKeepers = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").length,
  100. success = true;
  101. //add ZooKeepers as long as possible
  102. if (currentZooKeepers) {
  103. while (success) {
  104. success = controller.addZookeepers();
  105. }
  106. var services = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper");
  107. var length = services.length;
  108. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").length).to.equal(controller.get("hosts.length"));
  109. }
  110. })
  111. })
  112. describe('#removeZookeepers()', function () {
  113. it('should remove a ZooKeeper', function () {
  114. if (controller.get("selectedServices").mapProperty("service_name").contains("ZOOKEEPER")) {
  115. if (controller.addZookeepers()) {
  116. newLength = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length");
  117. controller.removeZookeepers(2);
  118. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(newLength - 1);
  119. }
  120. }
  121. })
  122. it('should fail to remove a ZooKeeper if there is only 1', function () {
  123. var currentZooKeepers = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").length,
  124. success = true;
  125. //remove ZooKeepers as long as possible
  126. if (currentZooKeepers) {
  127. while (success) {
  128. success = controller.removeZookeepers(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("lastObject.zId"));
  129. }
  130. expect(controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").get("length")).to.equal(1);
  131. }
  132. })
  133. })
  134. describe('#rebalanceZookeeperHosts()', function () {
  135. it('should rebalance hosts for ZooKeeper', function () {
  136. //assign a host to a zookeeper and then rebalance the available hosts for the other zookeepers
  137. var zookeepers = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper"),
  138. aZookeeper = null, aHost = null, i = 0, ok = true;
  139. if (zookeepers.get("length") > 1) {
  140. aZookeeper = controller.get("selectedServicesMasters").filterProperty("component_name", "ZooKeeper").findProperty("zId", 1);
  141. aHost = aZookeeper.get("availableHosts")[0];
  142. aZookeeper.set("selectedHost", aHost.get("host_name"));
  143. controller.rebalanceZookeeperHosts();
  144. for (i = 0; i < zookeepers.get("length"); i++) {
  145. if (zookeepers[i].get("availableHosts").mapProperty("host_name").contains(aHost)) {
  146. ok = false;
  147. break;
  148. }
  149. }
  150. expect(ok).to.equal(true);
  151. }
  152. })
  153. })
  154. })