Updated Branches: refs/heads/master d40d83fcc -> ceb407eb0
Added support to manage multiple hostnames against a cluster and implemented unit tests to verify a complete load balancer configuration Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/5359937c Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/5359937c Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/5359937c Branch: refs/heads/master Commit: 5359937c7c8c3a3fe7f6f7c149435dc4234ac7ff Parents: d387d64 Author: Imesh Gunaratne <[email protected]> Authored: Tue Dec 3 15:30:01 2013 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Tue Dec 3 15:30:01 2013 +0530 ---------------------------------------------------------------------- .../controller/topology/TopologyBuilder.java | 11 +- .../load/balancer/LoadBalancerContext.java | 12 +- .../balancer/LoadBalancerTopologyReceiver.java | 24 +-- .../conf/LoadBalancerConfiguration.java | 30 +++- .../test/LoadBalancerConfigurationTest.java | 150 ++++++++++++++++--- .../sample/configuration/loadbalancer1.conf | 8 +- .../sample/configuration/loadbalancer2.conf | 10 +- .../sample/configuration/loadbalancer3.conf | 8 +- .../messaging/domain/topology/Cluster.java | 19 ++- .../messaging/domain/topology/Topology.java | 3 + .../topology/ClusterCreatedEventProcessor.java | 2 +- .../haproxy/extension/HAProxyConfigWriter.java | 29 ++-- 12 files changed, 226 insertions(+), 80 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java index 7b21c10..db350e1 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/topology/TopologyBuilder.java @@ -173,18 +173,15 @@ public class TopologyBuilder { if (service.clusterExists(registrant.getClusterId())) { //update the cluster cluster = service.getCluster(registrant.getClusterId()); - cluster. - setHostName(registrant.getHostName()); - cluster. - setAutoscalePolicyName(registrant.getAutoScalerPolicyName()); - cluster. - setTenantRange(registrant.getTenantRange()); + cluster.addHostName(registrant.getHostName()); + cluster.setAutoscalePolicyName(registrant.getAutoScalerPolicyName()); + cluster.setTenantRange(registrant.getTenantRange()); cluster.setProperties(props); } else { cluster = new Cluster(registrant.getCartridgeType(), registrant.getClusterId(), registrant.getAutoScalerPolicyName()); - cluster.setHostName(registrant.getHostName()); + cluster.addHostName(registrant.getHostName()); cluster.setTenantRange(registrant.getTenantRange()); cluster.setAutoscalePolicyName(registrant.getAutoScalerPolicyName()); cluster.setProperties(props); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerContext.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerContext.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerContext.java index e9080e7..8a89ebe 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerContext.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerContext.java @@ -206,10 +206,6 @@ public class LoadBalancerContext { // ClusterContextMap methods END // ClusterMap methods START - public Collection<Cluster> getClusters() { - return clusterMap.values(); - } - public Cluster getCluster(String hostName) { return clusterMap.get(hostName); } @@ -219,7 +215,13 @@ public class LoadBalancerContext { } public void addCluster(Cluster cluster) { - clusterMap.put(cluster.getHostName(), cluster); + for(String hostName : cluster.getHostNames()) { + addCluster(hostName, cluster); + } + } + + public void addCluster(String hostName, Cluster cluster) { + clusterMap.put(hostName, cluster); } public void removeCluster(String hostName) { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerTopologyReceiver.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerTopologyReceiver.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerTopologyReceiver.java index fdbca11..fba24e7 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerTopologyReceiver.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/LoadBalancerTopologyReceiver.java @@ -77,7 +77,7 @@ public class LoadBalancerTopologyReceiver implements Runnable { for(Service service : TopologyManager.getTopology().getServices()) { for(Cluster cluster : service.getClusters()) { if(hasActiveMembers(cluster)) { - addClusterToContext(cluster); + addClusterToLbContext(cluster); } } } @@ -118,7 +118,7 @@ public class LoadBalancerTopologyReceiver implements Runnable { log.error(String.format("Cluster not found in topology: [cluster] %s", memberActivatedEvent.getClusterId())); } } - addClusterToContext(cluster); + addClusterToLbContext(cluster); } finally { TopologyManager.releaseReadLock(); @@ -133,7 +133,7 @@ public class LoadBalancerTopologyReceiver implements Runnable { // Remove cluster from context ClusterRemovedEvent clusterRemovedEvent = (ClusterRemovedEvent)event; - removeClusterFromContext(clusterRemovedEvent.getHostName()); + removeClusterFromLbContext(clusterRemovedEvent.getHostName()); } finally { TopologyManager.releaseReadLock(); @@ -150,7 +150,9 @@ public class LoadBalancerTopologyReceiver implements Runnable { ServiceRemovedEvent serviceRemovedEvent = (ServiceRemovedEvent)event; for(Service service : TopologyManager.getTopology().getServices()) { for(Cluster cluster : service.getClusters()) { - removeClusterFromContext(cluster.getHostName()); + for(String hostName : cluster.getHostNames()) { + removeClusterFromLbContext(hostName); + } } } } @@ -162,16 +164,18 @@ public class LoadBalancerTopologyReceiver implements Runnable { return processorChain; } - private void addClusterToContext(Cluster cluster) { - if(!LoadBalancerContext.getInstance().clusterExists(cluster.getHostName())) { - LoadBalancerContext.getInstance().addCluster(cluster); - if(log.isDebugEnabled()) { - log.debug(String.format("Cluster added to load balancer context: [cluster] %s [hostname] %s", cluster.getClusterId(), cluster.getHostName())); + private void addClusterToLbContext(Cluster cluster) { + for(String hostName : cluster.getHostNames()) { + if(!LoadBalancerContext.getInstance().clusterExists(hostName)) { + LoadBalancerContext.getInstance().addCluster(hostName, cluster); + if(log.isDebugEnabled()) { + log.debug(String.format("Cluster added to load balancer context: [cluster] %s [hostname] %s", cluster.getClusterId(), hostName)); + } } } } - private void removeClusterFromContext(String hostName) { + private void removeClusterFromLbContext(String hostName) { if(LoadBalancerContext.getInstance().clusterExists(hostName)) { Cluster cluster = LoadBalancerContext.getInstance().getCluster(hostName); LoadBalancerContext.getInstance().removeCluster(hostName); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/LoadBalancerConfiguration.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/LoadBalancerConfiguration.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/LoadBalancerConfiguration.java index a0ff254..f615090 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/LoadBalancerConfiguration.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/LoadBalancerConfiguration.java @@ -66,12 +66,14 @@ public class LoadBalancerConfiguration { this.algorithmMap = new HashMap<String, Algorithm>(); } + /** + * Get load balancer configuration singleton instance. + * @return + */ public static synchronized LoadBalancerConfiguration getInstance() { if (instance == null) { synchronized (LoadBalancerConfiguration.class) { if (instance == null) { - // Clear load balancer context - LoadBalancerContext.getInstance().clear(); // Read load balancer configuration from file LoadBalancerConfigurationReader reader = new LoadBalancerConfigurationReader(); instance = reader.readFromFile(); @@ -81,6 +83,19 @@ public class LoadBalancerConfiguration { return instance; } + /** + * Clear load balancer configuration singleton instance and referencing contexts. + */ + public static synchronized void clear() { + synchronized (LoadBalancerConfiguration.class) { + instance = null; + // Clear load balancer context + LoadBalancerContext.getInstance().clear(); + // Clear topology + TopologyManager.getTopology().clear(); + } + } + public String getDefaultAlgorithmName() { return defaultAlgorithmName; } @@ -329,13 +344,20 @@ public class LoadBalancerConfiguration { for (Node clusterNode : clustersNode.getChildNodes()) { String clusterId = clusterNode.getName(); Cluster cluster = new Cluster(service.getServiceName(), clusterId, null); + + String algorithm = clusterNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM); + if(StringUtils.isNotBlank(algorithm)) { + cluster.setLoadBalanceAlgorithmName(algorithm); + } + String hosts = clusterNode.getProperty(Constants.CONF_ELEMENT_HOSTS); if (StringUtils.isBlank(hosts)) { throw new InvalidConfigurationException(String.format("%s node was not found in cluster %s", Constants.CONF_ELEMENT_HOSTS, clusterNode.getName())); } String[] hostsArray = hosts.split(","); - // TODO: Add multiple host-names to cluster - cluster.setHostName(hostsArray[0]); + for(String hostsName : hostsArray) { + cluster.addHostName(hostsName.trim()); + } Node membersNode = clusterNode.findChildNodeByName(Constants.CONF_ELEMENT_MEMBERS); if (membersNode == null) { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/test/java/org/apache/stratos/load/balancer/test/LoadBalancerConfigurationTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/test/java/org/apache/stratos/load/balancer/test/LoadBalancerConfigurationTest.java b/components/org.apache.stratos.load.balancer/src/test/java/org/apache/stratos/load/balancer/test/LoadBalancerConfigurationTest.java index 664d4d8..d1e31a5 100755 --- a/components/org.apache.stratos.load.balancer/src/test/java/org/apache/stratos/load/balancer/test/LoadBalancerConfigurationTest.java +++ b/components/org.apache.stratos.load.balancer/src/test/java/org/apache/stratos/load/balancer/test/LoadBalancerConfigurationTest.java @@ -1,40 +1,142 @@ /** -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at - -* http://www.apache.org/licenses/LICENSE-2.0 - -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + + * http://www.apache.org/licenses/LICENSE-2.0 + + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.stratos.load.balancer.test; import java.io.File; +import java.net.URL; +import org.apache.stratos.messaging.domain.topology.*; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; import org.apache.stratos.load.balancer.conf.LoadBalancerConfiguration; -import junit.framework.TestCase; +import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; /** * Test sample load balancer configurations. */ -public class LoadBalancerConfigurationTest extends TestCase { - private static String configPath = "src/test/resources/sample/configuration"; +@RunWith(JUnit4.class) +public class LoadBalancerConfigurationTest { + private static String configPath = File.separator + "sample" + File.separator + "configuration"; + + /** + * Test load balancer configuration parser using different configuration files. + */ + @Test + public final void testConfigurationParser() { + URL resourceUrl = this.getClass().getResource(configPath); + File folder = new File(resourceUrl.getFile()); + for (File configFile : folder.listFiles()) { + try { + System.setProperty("loadbalancer.conf.file", configFile.getAbsolutePath()); + LoadBalancerConfiguration.getInstance(); + } finally { + LoadBalancerConfiguration.clear(); + } + } + } - public final void testCreateLoadBalancerConfig() { - File folder = new File(configPath); - for(File configFile : folder.listFiles()) { + /** + * Test load balancer configuration read from a configuration file. + */ + @Test + public void testConfiguration() { + try { + String validationError = "Load balancer configuration validation failed"; + + URL resourceUrl = this.getClass().getResource(configPath + File.separator + "loadbalancer1.conf"); + File configFile = new File(resourceUrl.getFile()); System.setProperty("loadbalancer.conf.file", configFile.getAbsolutePath()); - LoadBalancerConfiguration.getInstance(); + LoadBalancerConfiguration configuration = LoadBalancerConfiguration.getInstance(); + + Assert.assertEquals(String.format("%s, algorithm not valid", validationError), "round-robin", configuration.getDefaultAlgorithmName()); + Assert.assertTrue(String.format("%s, failover is not true", validationError), configuration.isFailOver()); + Assert.assertTrue(String.format("%s, session affinity is not true", validationError), configuration.isSessionAffinity()); + Assert.assertEquals(String.format("%s, session timeout is not valid", validationError), 90000, configuration.getSessionTimeout()); + Assert.assertTrue(String.format("%s, topology event listener enabled is not true", validationError), configuration.isTopologyEventListenerEnabled()); + Assert.assertEquals(String.format("%s, mb ip is not valid", validationError), "localhost", configuration.getMbIp()); + Assert.assertEquals(String.format("%s, mb port is not valid", validationError), 5677, configuration.getMbPort()); + Assert.assertTrue(String.format("%s, cep stats publisher enabled is not true", validationError), configuration.isCepStatsPublisherEnabled()); + Assert.assertEquals(String.format("%s, cep ip is not valid", validationError), "localhost", configuration.getCepIp()); + Assert.assertEquals(String.format("%s, cep port is not valid", validationError), 7615, configuration.getCepPort()); + } finally { + LoadBalancerConfiguration.clear(); + } + } + + /** + * Test static topology configuration read from a file + */ + @Test + public final void testStaticTopology() { + URL resourceUrl = this.getClass().getResource(configPath + File.separator + "loadbalancer2.conf"); + File configFile = new File(resourceUrl.getFile()); + + System.setProperty("loadbalancer.conf.file", configFile.getAbsolutePath()); + LoadBalancerConfiguration.getInstance(); + + try { + String validationError = "Static topology validation failed"; + + TopologyManager.acquireReadLock(); + Topology topology = TopologyManager.getTopology(); + Assert.assertTrue(String.format("%s, services not found", validationError), topology.getServices().size() > 0); + + String serviceName = "app-server"; + Service appServer = topology.getService(serviceName); + Assert.assertNotNull(String.format("%s, service not found: [service] %s", validationError, serviceName), appServer); + + String clusterId = "app-server-cluster1"; + Cluster cluster1 = appServer.getCluster(clusterId); + Assert.assertNotNull(String.format("%s, cluster not found: [cluster] %s", validationError, clusterId), cluster1); + + String hostName = "cluster1.appserver.foo.org"; + Assert.assertTrue(String.format("%s, hostname not found: [hostname] %s", validationError, hostName), hostNameExist(cluster1, hostName)); + + hostName = "cluster1.org"; + Assert.assertTrue(String.format("%s, hostname not found: [hostname] %s", validationError, hostName), hostNameExist(cluster1, hostName)); + Assert.assertEquals(String.format("%s, algorithm not valid", validationError), "round-robin", cluster1.getLoadBalanceAlgorithmName()); + + String memberId = "m1"; + Member m1 = cluster1.getMember(memberId); + Assert.assertNotNull(String.format("%s, member not found: [member] %s", validationError, memberId), m1); + Assert.assertEquals(String.format("%s, member ip not valid", validationError), "10.0.0.10", m1.getMemberIp()); + + String portName = "http"; + Port m1Http = m1.getPort(portName); + Assert.assertNotNull(String.format("%s, port not found: [member] %s [port] %s", validationError, memberId, portName), m1Http); + Assert.assertEquals(String.format("%s, port value not valid: [member] %s [port] %s", validationError, memberId, portName), 8080, m1Http.getValue()); + Assert.assertEquals(String.format("%s, port proxy not valid: [member] %s [port] %s", validationError, memberId, portName), 80, m1Http.getProxy()); + + } finally { + TopologyManager.releaseReadLock(); + LoadBalancerConfiguration.clear(); + } + } + + private boolean hostNameExist(Cluster cluster, String hostName) { + for (String hostName_ : cluster.getHostNames()) { + if (hostName_.equals(hostName)) + return true; } + return false; } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer1.conf ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer1.conf b/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer1.conf index 794e0c2..c135405 100755 --- a/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer1.conf +++ b/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer1.conf @@ -15,9 +15,11 @@ # specific language governing permissions and limitations # under the License. -# Load balancer test configuration -# ---------------------------------- -# Test case: Verify topology-event-listener-enabled = true scenario +# Load balancer test configuration 1 +# ----------------------------------- +# topology-event-listener-enabled = true +# cep-stats-publisher-enabled = true +# loadbalancer { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer2.conf ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer2.conf b/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer2.conf index 5d1fd95..159bc2e 100755 --- a/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer2.conf +++ b/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer2.conf @@ -15,9 +15,11 @@ # specific language governing permissions and limitations # under the License. -# Load balancer test configuration -# ---------------------------------- -# Test case: Verify topology-event-listener-enabled = false scenario +# Load balancer test configuration 2 +# ----------------------------------- +# topology-event-listener-enabled = false +# cep-stats-publisher-enabled = true +# loadbalancer { @@ -80,7 +82,7 @@ loadbalancer { app-server { # service name, a unique identifier to identify a service clusters { app-server-cluster1 { # cluster id, a unique identifier to identify a cluster - hosts: cluster1.appserver.foo.org; # comma separated hostname list + hosts: cluster1.appserver.foo.org, cluster1.org; # comma separated hostname list algorithm: round-robin; # algorithm name members { m1 { # member id, a unique identifier to identify a member http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer3.conf ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer3.conf b/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer3.conf index 3cd20be..dd9be36 100755 --- a/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer3.conf +++ b/components/org.apache.stratos.load.balancer/src/test/resources/sample/configuration/loadbalancer3.conf @@ -15,9 +15,11 @@ # specific language governing permissions and limitations # under the License. -# Load balancer test configuration -# ---------------------------------- -# Test case: Verify cep-stats-publisher-enabled = false scenario +# Load balancer test configuration 3 +# ----------------------------------- +# topology-event-listener-enabled = true +# cep-stats-publisher-enabled = false +# loadbalancer { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java index 16ec972..e0981a8 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Cluster.java @@ -34,7 +34,7 @@ public class Cluster implements Serializable { private String serviceName; private String clusterId; - private String hostName; + private List<String> hostNames; private String tenantRange; private String autoscalePolicyName; private String deploymentPolicyName = "economy-deployment"; @@ -44,11 +44,13 @@ public class Cluster implements Serializable { // Key: Member.memberId private Map<String, Member> memberMap; + private String loadBalanceAlgorithmName; private Properties properties; public Cluster(String serviceName, String clusterId, String autoscalePolicyName) { this.serviceName = serviceName; this.clusterId = clusterId; + this.hostNames = new ArrayList<String>(); this.autoscalePolicyName = autoscalePolicyName; this.memberMap = new HashMap<String, Member>(); } @@ -61,12 +63,12 @@ public class Cluster implements Serializable { return clusterId; } - public String getHostName() { - return hostName; + public List<String> getHostNames() { + return hostNames; } - public void setHostName(String hostName) { - this.hostName = hostName; + public void addHostName(String hostName) { + this.hostNames.add(hostName); } public String getTenantRange() { @@ -146,5 +148,12 @@ public class Cluster implements Serializable { this.deploymentPolicyName = deploymentPolicy; } + public String getLoadBalanceAlgorithmName() { + return loadBalanceAlgorithmName; + } + + public void setLoadBalanceAlgorithmName(String loadBalanceAlgorithmName) { + this.loadBalanceAlgorithmName = loadBalanceAlgorithmName; + } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java index a510087..57e99e8 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Topology.java @@ -66,4 +66,7 @@ public class Topology implements Serializable { return this.serviceMap.containsKey(serviceName); } + public void clear() { + this.serviceMap.clear(); + } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedEventProcessor.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedEventProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedEventProcessor.java index bd3dca6..a4d09ba 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedEventProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/ClusterCreatedEventProcessor.java @@ -88,7 +88,7 @@ public class ClusterCreatedEventProcessor extends MessageProcessor { // Apply changes to the topology Cluster cluster = new Cluster(event.getServiceName(), event.getClusterId(), event.getAutoscalingPolicyName()); - cluster.setHostName(event.getHostName()); + cluster.addHostName(event.getHostName()); cluster.setTenantRange(event.getTenantRange()); service.addCluster(cluster); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/5359937c/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java ---------------------------------------------------------------------- diff --git a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java index d282a76..e35e593 100644 --- a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java +++ b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java @@ -66,21 +66,22 @@ public class HAProxyConfigWriter { } for (Port port : service.getPorts()) { - - String frontendId = cluster.getClusterId() + "-proxy-" + port.getProxy(); - String backendId = frontendId + "-members"; - - frontendBackendCollection.append("frontend ").append(frontendId).append(NEW_LINE); - frontendBackendCollection.append("\tbind ").append(cluster.getHostName()).append(":").append(port.getProxy()).append(NEW_LINE); - frontendBackendCollection.append("\tdefault_backend ").append(backendId).append(NEW_LINE); - frontendBackendCollection.append(NEW_LINE); - frontendBackendCollection.append("backend ").append(backendId).append(NEW_LINE); - - for (Member member : cluster.getMembers()) { - frontendBackendCollection.append("\tserver ").append(member.getMemberId()).append(" ") - .append(member.getMemberIp()).append(":").append(port.getValue()).append(NEW_LINE); + for(String hostName : cluster.getHostNames()) { + String frontendId = cluster.getClusterId() + "-host-" + hostName + "-proxy-" + port.getProxy(); + String backendId = frontendId + "-members"; + + frontendBackendCollection.append("frontend ").append(frontendId).append(NEW_LINE); + frontendBackendCollection.append("\tbind ").append(hostName).append(":").append(port.getProxy()).append(NEW_LINE); + frontendBackendCollection.append("\tdefault_backend ").append(backendId).append(NEW_LINE); + frontendBackendCollection.append(NEW_LINE); + frontendBackendCollection.append("backend ").append(backendId).append(NEW_LINE); + + for (Member member : cluster.getMembers()) { + frontendBackendCollection.append("\tserver ").append(member.getMemberId()).append(" ") + .append(member.getMemberIp()).append(":").append(port.getValue()).append(NEW_LINE); + } + frontendBackendCollection.append(NEW_LINE); } - frontendBackendCollection.append(NEW_LINE); } } }
