Updated Branches: refs/heads/master 2fbd0fd38 -> c8d904cae
Fixed load balancer configuration reader logic and added validations to load balancer context util Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/c8d904ca Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/c8d904ca Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/c8d904ca Branch: refs/heads/master Commit: c8d904cae85aa29f06c6992159fa467342cc4d8c Parents: 2fbd0fd Author: Imesh Gunaratne <[email protected]> Authored: Sun Dec 8 10:54:47 2013 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Sun Dec 8 10:54:47 2013 +0530 ---------------------------------------------------------------------- .../balancer/conf/LoadBalancerConfiguration.java | 19 +++++++++++-------- .../context/LoadBalancerContextUtil.java | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c8d904ca/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 ae811a0..cb2397d 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 @@ -420,19 +420,22 @@ public class LoadBalancerConfiguration { } cluster.addMember(member); } + // Add cluster to service service.addCluster(cluster); + // Add service to topology manager if not exists + try { + TopologyManager.acquireWriteLock(); + if(!TopologyManager.getTopology().serviceExists(service.getServiceName())) { + TopologyManager.getTopology().addService(service); + } + } finally { + TopologyManager.releaseWriteLock(); + } + // Add cluster to load balancer context LoadBalancerContextUtil.addClusterToLbContext(cluster); } - - // Add service to topology manager - try { - TopologyManager.acquireWriteLock(); - TopologyManager.getTopology().addService(service); - } finally { - TopologyManager.releaseWriteLock(); - } } } return configuration; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c8d904ca/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/LoadBalancerContextUtil.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/LoadBalancerContextUtil.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/LoadBalancerContextUtil.java index f644933..5854993 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/LoadBalancerContextUtil.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/LoadBalancerContextUtil.java @@ -33,10 +33,17 @@ public class LoadBalancerContextUtil { private static final Log log = LogFactory.getLog(LoadBalancerContextUtil.class); public static void addClusterToLbContext(Cluster cluster) { + if(cluster == null) + return; + // Add cluster to Map<ClusterId, Cluster> LoadBalancerContext.getInstance().addCluster(cluster); Service service = TopologyManager.getTopology().getService(cluster.getServiceName()); + if(service == null) { + throw new RuntimeException(String.format("Service not found: [cluster] %s", cluster.getClusterId())); + } + if (service.getServiceType() == ServiceType.SingleTenant) { // Add cluster to SingleTenantClusterMap for (String hostName : cluster.getHostNames()) { @@ -53,7 +60,14 @@ public class LoadBalancerContextUtil { public static void removeClusterFromLbContext(String clusterId) { Cluster cluster = LoadBalancerContext.getInstance().getCluster(clusterId); + if(cluster == null) { + return; + } + Service service = TopologyManager.getTopology().getService(cluster.getServiceName()); + if(service == null) { + throw new RuntimeException(String.format("Service not found: [cluster] %s", cluster.getClusterId())); + } if (service.getServiceType() == ServiceType.SingleTenant) { // Remove cluster from SingleTenantClusterMap for (String hostName : cluster.getHostNames()) {
