You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/03/03 14:14:20 UTC
[2/3] stratos git commit: Introducing load balancer topology provider
model to be able to provide the topology required for load balancing in a
generic manner
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/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
deleted file mode 100644
index 3fec1dd..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/LoadBalancerContextUtil.java
+++ /dev/null
@@ -1,475 +0,0 @@
-/*
- * 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.context;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.messaging.domain.tenant.Subscription;
-import org.apache.stratos.messaging.domain.tenant.SubscriptionDomain;
-import org.apache.stratos.messaging.domain.tenant.Tenant;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Service;
-import org.apache.stratos.messaging.message.receiver.tenant.TenantManager;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * Load balancer context utility class.
- */
-public class LoadBalancerContextUtil {
- private static final Log log = LogFactory.getLog(LoadBalancerContextUtil.class);
-
- /**
- * Add cluster against its host names.
- *
- * @param cluster
- */
- public static void addClusterAgainstHostNames(Cluster cluster) {
- 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()));
- }
-
- // Add cluster to ClusterIdClusterMap
- LoadBalancerContext.getInstance().getClusterIdClusterMap().addCluster(cluster);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster added to cluster-id -> cluster map: [cluster] %s ", cluster.getClusterId()));
- }
-
- // Add cluster to HostNameClusterMap
- for (String hostName : cluster.getHostNames()) {
- addClusterToHostNameClusterMap(hostName, cluster);
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster added to host/domain name -> cluster map: [hostName] %s [cluster] %s",
- hostName, cluster.getClusterId()));
- }
- }
- }
-
- /**
- * Remove cluster mapped against its host names.
- *
- * @param clusterId
- */
- public static void removeClusterAgainstHostNames(String clusterId) {
- Cluster cluster = LoadBalancerContext.getInstance().getClusterIdClusterMap().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()));
- }
-
- // Remove cluster from HostNameClusterMap
- for (String hostName : cluster.getHostNames()) {
- removeClusterFromHostNameClusterMap(hostName, cluster);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster removed from host/domain name -> clusters map: [host-name] %s [cluster] %s",
- hostName, cluster.getClusterId()));
- }
- }
-
- // Remove cluster from ClusterIdClusterMap
- LoadBalancerContext.getInstance().getClusterIdClusterMap().removeCluster(clusterId);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster removed from cluster-id -> cluster map: [cluster] %s ", cluster.getClusterId()));
- }
- }
-
- /**
- * Add clusters against host names, tenant id for the given service, cluster ids.
- *
- * @param serviceName
- * @param tenantId
- * @param clusterIds
- */
- public static void addClustersAgainstHostNamesAndTenantIds(String serviceName, int tenantId, Set<String> clusterIds) {
- try {
- TopologyManager.acquireReadLock();
-
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Service not found in topology: [service] %s", serviceName));
- }
- return;
- }
- Cluster cluster;
- for (String clusterId : clusterIds) {
- cluster = service.getCluster(clusterId);
- if (cluster != null) {
- // Add cluster against host names and tenant id
- addClusterAgainstHostNamesAndTenantId(serviceName, tenantId, cluster);
- } else {
- if (log.isWarnEnabled()) {
- log.warn(String.format("Cluster not found in service: [service] %s [cluster] %s", serviceName, clusterId));
- }
- }
- }
- } finally {
- TopologyManager.releaseReadLock();
- }
- }
-
- /**
- * Remove clusters mapped against host names and tenant id.
- *
- * @param serviceName
- * @param tenantId
- */
- public static void removeClustersAgainstHostNamesAndTenantIds(String serviceName, int tenantId, Set<String> clusterIds) {
- try {
- TopologyManager.acquireReadLock();
-
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Service not found in topology: [service] %s", serviceName));
- }
- return;
- }
- Cluster cluster;
- for (String clusterId : clusterIds) {
- cluster = service.getCluster(clusterId);
- if (cluster != null) {
- // Remove cluster mapped against host names and tenant id
- removeClusterAgainstHostNamesAndTenantId(serviceName, tenantId, cluster);
- } else {
- if (log.isWarnEnabled()) {
- log.warn(String.format("Cluster not found in service: [service] %s [cluster] %s", serviceName, clusterId));
- }
- }
- }
- } finally {
- TopologyManager.releaseReadLock();
- }
- }
-
- /**
- * Add clusters against domain name for the given service, cluster ids.
- *
- * @param serviceName
- * @param clusterId
- * @param domainName
- */
- public static void addClusterAgainstDomain(String serviceName, String clusterId, String domainName) {
- try {
- TopologyManager.acquireReadLock();
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Service not found in topology: [service] %s", serviceName));
- }
- return;
- }
- Cluster cluster = service.getCluster(clusterId);
- if (cluster != null) {
- addClusterAgainstDomain(serviceName, cluster, domainName);
- } else {
- if (log.isWarnEnabled()) {
- log.warn(String.format("Cluster not found in service: [service] %s [cluster] %s", serviceName, clusterId));
- }
- }
- } finally {
- TopologyManager.releaseReadLock();
- }
- }
-
- /**
- * Remove clusters mapped against domain name for the given service, cluster ids.
- *
- * @param serviceName
- * @param clusterId
- * @param domainName
- */
- public static void removeClusterAgainstDomain(String serviceName, String clusterId, String domainName) {
- try {
- TopologyManager.acquireReadLock();
-
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Service not found in topology: [service] %s", serviceName));
- }
- return;
- }
- Cluster cluster = service.getCluster(clusterId);
- if (cluster != null) {
- // Remove clusters mapped against domain names
- removeClusterAgainstDomain(cluster, domainName);
- } else {
- if (log.isWarnEnabled()) {
- log.warn(String.format("Cluster not found in service: [service] %s [cluster] %s", serviceName, clusterId));
- }
- }
- } finally {
- TopologyManager.releaseReadLock();
- }
- }
-
- /**
- * Find cluster from service name, tenant id.
- * Acquire a topology manager read lock appropriately.
- *
- * @param serviceName
- * @param tenantId
- * @return
- */
- @SuppressWarnings("unused")
- private static Cluster findCluster(String serviceName, int tenantId) {
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- throw new RuntimeException(String.format("Service not found: %s", serviceName));
- }
- for (Cluster cluster : service.getClusters()) {
- if (cluster.tenantIdInRange(tenantId)) {
- return cluster;
- }
- }
- return null;
- }
-
- /**
- * Add clusters against host names and tenant id to load balancer context.
- *
- * @param serviceName
- * @param tenantId
- * @param cluster
- */
- private static void addClusterAgainstHostNamesAndTenantId(String serviceName, int tenantId, Cluster cluster) {
- // Add clusters against host names
- if (log.isDebugEnabled()) {
- log.debug(String.format("Adding cluster to multi-tenant cluster map against host names: [service] %s " +
- "[tenant-id] %d [cluster] %s", serviceName, tenantId, cluster.getClusterId()));
- }
- for (String hostName : cluster.getHostNames()) {
- addClusterToMultiTenantClusterMap(hostName, tenantId, cluster);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster added to multi-tenant cluster map: [host-name] %s [tenant-id] %d [cluster] %s",
- hostName, tenantId, cluster.getClusterId()));
- }
- }
- }
-
- /**
- * Remove clusters mapped against host names and tenant id from load balancer context.
- *
- * @param serviceName
- * @param tenantId
- * @param cluster
- */
- private static void removeClusterAgainstHostNamesAndTenantId(String serviceName, int tenantId, Cluster cluster) {
- // Remove clusters mapped against host names
- if (log.isDebugEnabled()) {
- log.debug(String.format("Removing cluster from multi-tenant cluster map against host names: [service] %s " +
- "[tenant-id] %d [cluster] %s", serviceName, tenantId, cluster.getClusterId()));
- }
- for (String hostName : cluster.getHostNames()) {
- LoadBalancerContext.getInstance().getMultiTenantClusterMap().removeCluster(hostName, tenantId);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster removed from multi-tenant clusters map: [host-name] %s [tenant-id] %d [cluster] %s",
- hostName, tenantId, cluster.getClusterId()));
- }
- }
- }
-
-
- /**
- * Add clusters against domains to load balancer context.
- *
- * @param serviceName
- * @param cluster
- * @param domainName
- */
- private static void addClusterAgainstDomain(String serviceName, Cluster cluster, String domainName) {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Adding cluster to host/domain name -> cluster map against domain: [service] %s " +
- "[domain-name] %s [cluster] %s", serviceName, domainName, cluster.getClusterId()));
- }
- if (StringUtils.isNotBlank(domainName)) {
- addClusterToHostNameClusterMap(domainName, cluster);
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster added to host/domain name -> cluster map: [domain-name] %s [cluster] %s",
- domainName, cluster.getClusterId()));
- }
- }
- }
-
- /**
- * Remove clusters mapped against all subscription domain names for the given service, tenant, cluster ids.
- *
- * @param serviceName
- * @param tenantId
- * @param clusterIds
- */
- public static void removeClustersAgainstAllDomains(String serviceName, int tenantId, Set<String> clusterIds) {
- try {
- TenantManager.acquireReadLock();
- TopologyManager.acquireReadLock();
-
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Service not found in topology: [service] %s", serviceName));
- }
- return;
- }
- for (String clusterId : clusterIds) {
- Cluster cluster = service.getCluster(clusterId);
- Tenant tenant = TenantManager.getInstance().getTenant(tenantId);
- if (tenant != null) {
- for (Subscription subscription : tenant.getSubscriptions()) {
- if (subscription.getServiceName().equals(serviceName)) {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Removing cluster from host/domain name -> cluster map: [service] %s " +
- "[tenant-id] %d [domains] %s", serviceName, tenantId, subscription.getSubscriptionDomains()));
- }
- for (SubscriptionDomain subscriptionDomain : subscription.getSubscriptionDomains()) {
- removeClusterAgainstDomain(cluster, subscriptionDomain.getDomainName());
- }
- } else {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Tenant not subscribed to service: %s", serviceName));
- }
- }
- }
- }
- }
- } finally {
- TopologyManager.releaseReadLock();
- TenantManager.releaseReadLock();
- }
- }
-
- private static void removeClusterAgainstDomain(Cluster cluster, String domainName) {
- removeClusterFromHostNameClusterMap(domainName, cluster);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cluster removed from host/domain name -> cluster map: [domain-name] %s [cluster] %s",
- domainName, cluster.getClusterId()));
- }
- }
-
- /**
- * Add cluster to host/domain name cluster map.
- *
- * @param hostName
- * @param cluster
- */
- private static void addClusterToHostNameClusterMap(String hostName, Cluster cluster) {
- if (!LoadBalancerContext.getInstance().getHostNameClusterMap().containsCluster((hostName))) {
- LoadBalancerContext.getInstance().getHostNameClusterMap().addCluster(hostName, cluster);
- }
- }
-
- /**
- * Remove cluseter from host/domain names cluster map.
- *
- * @param hostName
- * @param cluster
- */
- private static void removeClusterFromHostNameClusterMap(String hostName, Cluster cluster) {
- if (LoadBalancerContext.getInstance().getHostNameClusterMap().containsCluster(hostName)) {
- LoadBalancerContext.getInstance().getHostNameClusterMap().removeCluster(hostName);
- }
- }
-
- /**
- * Add cluster to multi-tenant cluster map.
- *
- * @param hostName
- * @param tenantId
- * @param cluster
- */
- private static void addClusterToMultiTenantClusterMap(String hostName, int tenantId, Cluster cluster) {
- // Add hostName, tenantId, cluster to multi-tenant map
- Map<Integer, Cluster> clusterMap = LoadBalancerContext.getInstance().getMultiTenantClusterMap().getClusters(hostName);
- if (clusterMap == null) {
- clusterMap = new HashMap<Integer, Cluster>();
- clusterMap.put(tenantId, cluster);
- LoadBalancerContext.getInstance().getMultiTenantClusterMap().addClusters(hostName, clusterMap);
- } else {
- clusterMap.put(tenantId, cluster);
- }
- }
-
- public static void addContextPathAgainstDomain(String domainName, String appContext) {
- LoadBalancerContext.getInstance().getHostNameContextPathMap().addContextPath(domainName, appContext);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Context path added against domain name: [domain-name] %s [context-path] %s",
- domainName, appContext));
- }
- }
-
- public static void removeContextPathAgainstDomain(String domainName) {
- LoadBalancerContext.getInstance().getHostNameContextPathMap().removeContextPath(domainName);
- if (log.isDebugEnabled()) {
- log.debug(String.format("Context path removed against domain name: [domain-name] %s",
- domainName));
- }
- }
-
- public static void removeAppContextAgainstAllDomains(String serviceName, int tenantId) {
- try {
- TenantManager.acquireReadLock();
- TopologyManager.acquireReadLock();
-
- Service service = TopologyManager.getTopology().getService(serviceName);
- if (service == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Service not found in topology: [service] %s", serviceName));
- }
- return;
- }
-
- Tenant tenant = TenantManager.getInstance().getTenant(tenantId);
- if (tenant != null) {
- for (Subscription subscription : tenant.getSubscriptions()) {
- if (subscription.getServiceName().equals(serviceName)) {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Removing appContext against domain name: [service] %s " +
- "[tenant-id] %d [domains] %s", serviceName, tenantId, subscription.getSubscriptionDomains()));
- }
- for (SubscriptionDomain subscriptionDomain : subscription.getSubscriptionDomains()) {
- removeContextPathAgainstDomain(subscriptionDomain.getDomainName());
- }
- } else {
- if (log.isDebugEnabled()) {
- log.debug(String.format("Tenant not subscribed to service: %s", serviceName));
- }
- }
- }
- }
- } finally {
- TopologyManager.releaseReadLock();
- TenantManager.releaseReadLock();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ClusterIdClusterMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ClusterIdClusterMap.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ClusterIdClusterMap.java
deleted file mode 100644
index 958c1aa..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ClusterIdClusterMap.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.context.map;
-
-import org.apache.stratos.messaging.domain.topology.Cluster;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Cluster id, cluster map for accessing clusters using cluster id:
- * Map[ClusterId, Cluster]
- */
-public class ClusterIdClusterMap {
-
- private ConcurrentHashMap<String, Cluster> concurrentHashMap;
-
- public ClusterIdClusterMap() {
- concurrentHashMap = new ConcurrentHashMap<String, Cluster>();
- }
-
- public Cluster getCluster(String clusterId) {
- return concurrentHashMap.get(clusterId);
- }
-
- public boolean containsCluster(String clusterId) {
- return concurrentHashMap.containsKey(clusterId);
- }
-
- public void addCluster(Cluster cluster) {
- concurrentHashMap.put(cluster.getClusterId(), cluster);
- }
-
- public void removeCluster(String clusterId) {
- concurrentHashMap.remove(clusterId);
- }
-
- public void clear() {
- concurrentHashMap.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameAppContextMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameAppContextMap.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameAppContextMap.java
index 3e71093..993c41a 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameAppContextMap.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameAppContextMap.java
@@ -48,4 +48,8 @@ public class HostNameAppContextMap {
public boolean contains(String hostName) {
return concurrentHashMap.containsKey(hostName);
}
+
+ public void clear() {
+ concurrentHashMap.clear();
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameClusterMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameClusterMap.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameClusterMap.java
deleted file mode 100644
index c855dd3..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/HostNameClusterMap.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.context.map;
-
-import org.apache.stratos.messaging.domain.topology.Cluster;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Host/domain name cluster map for accessing clusters using host name:
- * Map[HostName, Cluster]
- */
-public class HostNameClusterMap {
-
- private ConcurrentHashMap<String, Cluster> concurrentHashMap;
-
- public HostNameClusterMap() {
- concurrentHashMap = new ConcurrentHashMap<String, Cluster>();
- }
-
- public Cluster getCluster(String hostName) {
- return concurrentHashMap.get(hostName);
- }
-
- public boolean containsCluster(String hostName) {
- return concurrentHashMap.containsKey(hostName);
- }
-
- public void addCluster(String hostName, Cluster cluster) {
- concurrentHashMap.put(hostName, cluster);
- }
-
- public void removeCluster(Cluster cluster) {
- for (String hostName : cluster.getHostNames()) {
- removeCluster(hostName);
- }
- }
-
- public void removeCluster(String hostName) {
- concurrentHashMap.remove(hostName);
- }
-
- public void clear() {
- concurrentHashMap.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/MultiTenantClusterMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/MultiTenantClusterMap.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/MultiTenantClusterMap.java
deleted file mode 100644
index d038fbc..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/MultiTenantClusterMap.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.context.map;
-
-import org.apache.stratos.messaging.domain.topology.Cluster;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Multi-tenant cluster map for accessing clusters using host name and tenant id:
- * Map[HostName, Map[TenantId,Cluster]]
- */
-public class MultiTenantClusterMap {
-
- private ConcurrentHashMap<String, Map<Integer, Cluster>> concurrentHashMap;
-
- public MultiTenantClusterMap() {
- concurrentHashMap = new ConcurrentHashMap<String, Map<Integer, Cluster>>();
- }
-
- public Cluster getCluster(String hostName, int tenantId) {
- Map<Integer, Cluster> clusterMap = getClusters(hostName);
- if (clusterMap != null) {
- if(clusterMap.containsKey(tenantId)) {
- return clusterMap.get(tenantId);
- }
- }
- return null;
- }
-
- public Map<Integer, Cluster> getClusters(String hostName) {
- return concurrentHashMap.get(hostName);
- }
-
- public boolean containsClusters(String hostName) {
- return concurrentHashMap.containsKey(hostName);
- }
-
- public void addClusters(String hostname, Map<Integer, Cluster> clusters) {
- concurrentHashMap.put(hostname, clusters);
- }
-
- public void removeClusters(String hostName) {
- concurrentHashMap.remove(hostName);
- }
-
- public void clear() {
- concurrentHashMap.clear();
- }
-
- public void removeCluster(String hostName, int tenantId) {
- Map<Integer, Cluster> clusterMap = getClusters(hostName);
- if(clusterMap != null) {
- if(clusterMap.containsKey(tenantId)) {
- clusterMap.remove(tenantId);
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ServiceNameServiceContextMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ServiceNameServiceContextMap.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ServiceNameServiceContextMap.java
deleted file mode 100644
index 99d563b..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/ServiceNameServiceContextMap.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.context.map;
-
-import org.apache.stratos.load.balancer.context.ServiceContext;
-
-import java.util.Collection;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Service name, service context map for accessing service contexts using service name:
- * Map[ServiceName, ServiceContext]
- */
-public class ServiceNameServiceContextMap {
-
- private ConcurrentHashMap<String, ServiceContext> concurrentHashMap;
-
- public ServiceNameServiceContextMap() {
- concurrentHashMap = new ConcurrentHashMap<String, ServiceContext>();
- }
-
- public Collection<ServiceContext> getServiceContexts() {
- return concurrentHashMap.values();
- }
-
- public ServiceContext getServiceContext(String serviceName) {
- return concurrentHashMap.get(serviceName);
- }
-
- public void addServiceContext(ServiceContext serviceContext) {
- concurrentHashMap.put(serviceContext.getServiceName(), serviceContext);
- }
-
- public void removeServiceContext(String serviceName) {
- concurrentHashMap.remove(serviceName);
- }
-
- public void clear() {
- concurrentHashMap.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/TenantIdSynapseEnvironmentServiceMap.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/TenantIdSynapseEnvironmentServiceMap.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/TenantIdSynapseEnvironmentServiceMap.java
deleted file mode 100644
index 7c59d07..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/context/map/TenantIdSynapseEnvironmentServiceMap.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * 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.context.map;
-
-import org.wso2.carbon.mediation.initializer.services.SynapseEnvironmentService;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Tenant id, synapse environment service map for accessing synapse environment services using
- * tenant id:
- * Map[TenantId, SynapseEnvironmentService]
- */
-public class TenantIdSynapseEnvironmentServiceMap {
-
- private ConcurrentHashMap<Integer, SynapseEnvironmentService> concurrentHashMap;
-
- public TenantIdSynapseEnvironmentServiceMap() {
- concurrentHashMap = new ConcurrentHashMap<Integer, SynapseEnvironmentService>();
- }
-
- public SynapseEnvironmentService getSynapseEnvironmentService(int tenantId) {
- return concurrentHashMap.get(tenantId);
- }
-
- public boolean containsSynapseEnvironmentService(int tenantId) {
- return concurrentHashMap.containsKey(tenantId);
- }
-
- public void addSynapseEnvironmentService(int tenantId, SynapseEnvironmentService synapseEnvironmentService) {
- concurrentHashMap.put(tenantId, synapseEnvironmentService);
- }
-
- public void removeSynapseEnvironmentService(int tenantId) {
- concurrentHashMap.remove(tenantId);
- }
-
- public Map<Integer, SynapseEnvironmentService> getTenantIdSynapseEnvironmentServiceMap() {
- return concurrentHashMap;
- }
-
- public void clear() {
- concurrentHashMap.clear();
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/RequestDelegator.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/RequestDelegator.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/RequestDelegator.java
index ac94654..99fcaa1 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/RequestDelegator.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/RequestDelegator.java
@@ -21,13 +21,13 @@ package org.apache.stratos.load.balancer.endpoint;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.load.balancer.context.AlgorithmContext;
import org.apache.stratos.load.balancer.algorithm.LoadBalanceAlgorithm;
-import org.apache.stratos.load.balancer.conf.LoadBalancerConfiguration;
+import org.apache.stratos.load.balancer.common.topology.TopologyProvider;
+import org.apache.stratos.load.balancer.common.domain.Cluster;
+import org.apache.stratos.load.balancer.common.domain.Member;
+import org.apache.stratos.load.balancer.context.AlgorithmContext;
import org.apache.stratos.load.balancer.context.ClusterContext;
import org.apache.stratos.load.balancer.context.LoadBalancerContext;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Member;
import java.util.ArrayList;
@@ -36,21 +36,30 @@ import java.util.ArrayList;
* according to the incoming request information.
*/
public class RequestDelegator {
+
private static final Log log = LogFactory.getLog(RequestDelegator.class);
private LoadBalanceAlgorithm algorithm;
+ private TopologyProvider topologyProvider;
- public RequestDelegator(LoadBalanceAlgorithm algorithm) {
+ public RequestDelegator(LoadBalanceAlgorithm algorithm, TopologyProvider topologyProvider) {
this.algorithm = algorithm;
+ this.topologyProvider = topologyProvider;
}
+ /**
+ * Find the next member in a cluster by applying a load balancing algorithm by the given host name.
+ * @param hostName host name of the cluster
+ * @param messageId synapse message id to be included in debugging logs
+ * @return
+ */
public Member findNextMemberFromHostName(String hostName, String messageId) {
if (hostName == null)
return null;
long startTime = System.currentTimeMillis();
- Cluster cluster = LoadBalancerContext.getInstance().getHostNameClusterMap().getCluster(hostName);
+ Cluster cluster = topologyProvider.getClusterByHostName(hostName);
if (cluster != null) {
if (log.isDebugEnabled()) {
log.debug(String.format("Cluster %s identified for request %s", cluster.getClusterId(), messageId));
@@ -59,7 +68,7 @@ public class RequestDelegator {
if (member != null) {
if (log.isDebugEnabled()) {
long endTime = System.currentTimeMillis();
- log.debug(String.format("Next member identified in %dms: [service] %s [cluster] %s [member] %s [request-id] %s",
+ log.debug(String.format("Next member identified in %dms: [service] %s [cluster] %s [member] %s [message-id] %s",
(endTime - startTime), member.getServiceName(), member.getClusterId(), member.getMemberId(), messageId));
}
}
@@ -73,11 +82,17 @@ public class RequestDelegator {
return null;
}
+ /**
+ * Find the next member in a cluster by applying a load balancing algorithm by the given host name and tenant id.
+ * @param hostName host name of the cluster
+ * @param tenantId tenant id of the incoming request
+ * @return
+ */
public Member findNextMemberFromTenantId(String hostName, int tenantId) {
long startTime = System.currentTimeMillis();
// Find cluster from host name and tenant id
- Cluster cluster = LoadBalancerContext.getInstance().getMultiTenantClusterMap().getCluster(hostName, tenantId);
+ Cluster cluster = topologyProvider.getClusterByHostName(hostName, tenantId);
if (cluster != null) {
Member member = findNextMemberInCluster(cluster);
if (member != null) {
@@ -98,13 +113,16 @@ public class RequestDelegator {
}
/**
+ * Find next member in the cluster by applying a load balancing algorithm.
+ *
* This operation should be synchronized in order to find a member
* correctly. This has no performance impact as per the load tests
* carried out.
*/
private synchronized Member findNextMemberInCluster(Cluster cluster) {
// Find algorithm context of the cluster
- ClusterContext clusterContext = LoadBalancerContext.getInstance().getClusterIdClusterContextMap().getClusterContext(cluster.getClusterId());
+ ClusterContext clusterContext = LoadBalancerContext.getInstance().
+ getClusterIdClusterContextMap().getClusterContext(cluster.getClusterId());
if (clusterContext == null) {
clusterContext = new ClusterContext(cluster.getServiceName(), cluster.getClusterId());
LoadBalancerContext.getInstance().getClusterIdClusterContextMap().addClusterContext(clusterContext);
@@ -119,7 +137,8 @@ public class RequestDelegator {
Member member = algorithm.getNextMember(algorithmContext);
if (member == null) {
if (log.isWarnEnabled()) {
- log.warn(String.format("Could not find a member in cluster: [service] %s [cluster] %s", cluster.getServiceName(), cluster.getClusterId()));
+ log.warn(String.format("Could not find a member in cluster: [service] %s [cluster] %s",
+ cluster.getServiceName(), cluster.getClusterId()));
}
}
return member;
@@ -129,10 +148,11 @@ public class RequestDelegator {
if (hostName == null)
return false;
- boolean valid = LoadBalancerContext.getInstance().getHostNameClusterMap().containsCluster(hostName);
- if ((!valid) && (LoadBalancerConfiguration.getInstance().isMultiTenancyEnabled())) {
- valid = LoadBalancerContext.getInstance().getMultiTenantClusterMap().containsClusters(hostName);
- }
+ boolean valid = topologyProvider.clusterExistsByHostName(hostName);
return valid;
}
+
+ public Cluster getCluster(String hostName) {
+ return topologyProvider.getClusterByHostName(hostName);
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/TenantAwareLoadBalanceEndpoint.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/TenantAwareLoadBalanceEndpoint.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/TenantAwareLoadBalanceEndpoint.java
index 8e41807..8a35b12 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/TenantAwareLoadBalanceEndpoint.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/endpoint/TenantAwareLoadBalanceEndpoint.java
@@ -23,9 +23,13 @@ import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.description.TransportInDescription;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.protocol.HTTP;
+import org.apache.stratos.load.balancer.algorithm.LoadBalanceAlgorithm;
import org.apache.stratos.load.balancer.algorithm.LoadBalanceAlgorithmFactory;
+import org.apache.stratos.load.balancer.common.domain.Cluster;
+import org.apache.stratos.load.balancer.common.domain.Member;
+import org.apache.stratos.load.balancer.common.domain.Port;
+import org.apache.stratos.load.balancer.common.topology.TopologyProvider;
import org.apache.stratos.load.balancer.conf.LoadBalancerConfiguration;
-import org.apache.stratos.load.balancer.conf.domain.MemberIpType;
import org.apache.stratos.load.balancer.conf.domain.TenantIdentifier;
import org.apache.stratos.load.balancer.context.LoadBalancerContext;
import org.apache.stratos.load.balancer.statistics.InFlightRequestDecrementCallable;
@@ -33,11 +37,7 @@ import org.apache.stratos.load.balancer.statistics.InFlightRequestIncrementCalla
import org.apache.stratos.load.balancer.statistics.LoadBalancerStatisticsExecutor;
import org.apache.stratos.load.balancer.util.LoadBalancerConstants;
import org.apache.stratos.messaging.domain.tenant.Tenant;
-import org.apache.stratos.messaging.domain.topology.Cluster;
-import org.apache.stratos.messaging.domain.topology.Member;
-import org.apache.stratos.messaging.domain.topology.Port;
import org.apache.stratos.messaging.message.receiver.tenant.TenantManager;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
@@ -84,7 +84,9 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints
public void init(SynapseEnvironment synapseEnvironment) {
super.init(synapseEnvironment);
- requestDelegator = new RequestDelegator(LoadBalanceAlgorithmFactory.createAlgorithm(algorithmClassName));
+ LoadBalanceAlgorithm algorithm = LoadBalanceAlgorithmFactory.createAlgorithm(algorithmClassName);
+ TopologyProvider topologyProvider = LoadBalancerConfiguration.getInstance().getTopologyProvider();
+ requestDelegator = new RequestDelegator(algorithm, topologyProvider);
synapseEnvironment.getSynapseConfiguration().setProperty(SynapseConstants.PROP_SAL_ENDPOINT_DEFAULT_SESSION_TIMEOUT, String.valueOf(sessionTimeout));
setDispatcher(new HttpSessionDispatcher());
}
@@ -252,7 +254,6 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints
throwSynapseException(synCtx, 403, String.format("You are unauthorized to access"));
}
} else {
-
member = requestDelegator.findNextMemberFromHostName(targetHost, synCtx.getMessageID());
}
@@ -260,12 +261,24 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints
return null;
// Create Axi2 member object
- org.apache.axis2.clustering.Member axis2Member = new org.apache.axis2.clustering.Member(
- getMemberIp(synCtx, member), -1);
+ return createAxis2Member(synCtx, targetHost, member);
+ }
+
+ /**
+ * Create axis2 member from load balancer member object.
+ * @param synCtx
+ * @param member
+ * @return
+ */
+ private org.apache.axis2.clustering.Member createAxis2Member(MessageContext synCtx, String clusterHostName,
+ Member member) {
+ org.apache.axis2.clustering.Member axis2Member =
+ new org.apache.axis2.clustering.Member(member.getHostName(), -1);
axis2Member.setDomain(member.getClusterId());
- axis2Member.setActive(member.isActive());
+ axis2Member.setActive(true);
// Set cluster id and member id in member properties
axis2Member.getProperties().setProperty(LoadBalancerConstants.CLUSTER_ID, member.getClusterId());
+ axis2Member.getProperties().setProperty(LoadBalancerConstants.CLUSTER_HOSTNAME, clusterHostName);
axis2Member.getProperties().setProperty(LoadBalancerConstants.MEMBER_ID, member.getMemberId());
// Update axis2 member ports
updateAxis2MemberPorts(synCtx, axis2Member);
@@ -364,7 +377,6 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints
}
/**
->>>>>>> 400
* Find topology member from axis2 member using cluster id and member id defined in axis2 member properties.
*
* @param synCtx
@@ -372,35 +384,38 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints
* @return
*/
private Member findMemberFromAxis2Member(MessageContext synCtx, org.apache.axis2.clustering.Member axis2Member) {
- String clusterId = axis2Member.getProperties().getProperty(LoadBalancerConstants.CLUSTER_ID);
+ String hostName = axis2Member.getProperties().getProperty(LoadBalancerConstants.CLUSTER_HOSTNAME);
String memberId = axis2Member.getProperties().getProperty(LoadBalancerConstants.MEMBER_ID);
- if (StringUtils.isBlank(clusterId) || StringUtils.isBlank(memberId)) {
+ if (StringUtils.isBlank(hostName)) {
if (log.isErrorEnabled()) {
- log.error(String.format("Could not find cluster id and/or member id properties in axis2 member: [cluster-id] %s " +
- "[member-id] %s", clusterId, memberId));
+ log.error(String.format("Could not find hostname in axis2 member: [hostname] %s ", hostName));
}
throwSynapseException(synCtx, 500, "Internal server error");
}
- try {
- TopologyManager.acquireReadLock();
- Cluster cluster = LoadBalancerContext.getInstance().getClusterIdClusterMap().getCluster(clusterId);
- if (cluster == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Cluster not found in load balancer context: [cluster-id] %s ", clusterId));
- }
- throwSynapseException(synCtx, 500, "Internal server error");
+ if (StringUtils.isBlank(memberId)) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Could not find member id in axis2 member: [member] %s ",
+ axis2Member.getHostName()));
}
- Member member = cluster.getMember(memberId);
- if (member == null) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Member not found in load balancer context: [cluster-id] %s [member-id] %s", clusterId, memberId));
- }
- throwSynapseException(synCtx, 500, "Internal server error");
+ throwSynapseException(synCtx, 500, "Internal server error");
+ }
+
+ Cluster cluster = requestDelegator.getCluster(hostName);
+ if (cluster == null) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Cluster not found in load balancer context: [hostname] %s ", hostName));
}
- return member;
- } finally {
- TopologyManager.releaseReadLock();
+ throwSynapseException(synCtx, 500, "Internal server error");
+ }
+ Member member = cluster.getMember(memberId);
+ if (member == null) {
+ if (log.isErrorEnabled()) {
+ log.error(String.format("Member not found in load balancer context: [hostname] %s [member-id] %s",
+ hostName, memberId));
+ }
+ throwSynapseException(synCtx, 500, "Internal server error");
}
+ return member;
}
/**
@@ -410,34 +425,34 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints
* @param member
* @return
*/
- private String getMemberIp(MessageContext synCtx, Member member) {
- if (LoadBalancerConfiguration.getInstance().isTopologyEventListenerEnabled()) {
- if (LoadBalancerConfiguration.getInstance().getTopologyMemberIpType() == MemberIpType.Public) {
- // Return member's public IP address
- if (StringUtils.isBlank(member.getDefaultPublicIP())) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Member public IP address not found: [member] %s", member.getMemberId()));
- }
- throwSynapseException(synCtx, 500, "Internal server error");
- }
- if (log.isDebugEnabled()) {
- log.debug(String.format("Using member public IP address: [member] %s [ip] %s", member.getMemberId(), member.getDefaultPublicIP()));
- }
- return member.getDefaultPublicIP();
- }
- }
- // Return member's private IP address
- if (StringUtils.isBlank(member.getDefaultPrivateIP())) {
- if (log.isErrorEnabled()) {
- log.error(String.format("Member IP address not found: [member] %s", member.getMemberId()));
- }
- throwSynapseException(synCtx, 500, "Internal server error");
- }
- if (log.isDebugEnabled()) {
- log.debug(String.format("Using member IP address: [member] %s [ip] %s", member.getMemberId(), member.getDefaultPrivateIP()));
- }
- return member.getDefaultPrivateIP();
- }
+// private String getMemberIp(MessageContext synCtx, Member member) {
+// if (LoadBalancerConfiguration.getInstance().isTopologyEventListenerEnabled()) {
+// if (LoadBalancerConfiguration.getInstance().getTopologyMemberIpType() == MemberIpType.Public) {
+// // Return member's public IP address
+// if (StringUtils.isBlank(member.getDefaultPublicIP())) {
+// if (log.isErrorEnabled()) {
+// log.error(String.format("Member public IP address not found: [member] %s", member.getMemberId()));
+// }
+// throwSynapseException(synCtx, 500, "Internal server error");
+// }
+// if (log.isDebugEnabled()) {
+// log.debug(String.format("Using member public IP address: [member] %s [ip] %s", member.getMemberId(), member.getDefaultPublicIP()));
+// }
+// return member.getDefaultPublicIP();
+// }
+// }
+// // Return member's private IP address
+// if (StringUtils.isBlank(member.getDefaultPrivateIP())) {
+// if (log.isErrorEnabled()) {
+// log.error(String.format("Member IP address not found: [member] %s", member.getMemberId()));
+// }
+// throwSynapseException(synCtx, 500, "Internal server error");
+// }
+// if (log.isDebugEnabled()) {
+// log.debug(String.format("Using member IP address: [member] %s [ip] %s", member.getMemberId(), member.getDefaultPrivateIP()));
+// }
+// return member.getDefaultPrivateIP();
+// }
/**
* Extract incoming request URL from message context.
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
index 9196371..33ce789 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/LoadBalancerServiceComponent.java
@@ -26,23 +26,23 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.common.clustering.DistributedObjectProvider;
import org.apache.stratos.common.threading.StratosThreadPool;
+import org.apache.stratos.load.balancer.common.event.receivers.LoadBalancerApplicationSignUpEventReceiver;
+import org.apache.stratos.load.balancer.common.event.receivers.LoadBalancerDomainMappingEventReceiver;
+import org.apache.stratos.load.balancer.common.event.receivers.LoadBalancerTopologyEventReceiver;
import org.apache.stratos.load.balancer.common.statistics.notifier.LoadBalancerStatisticsNotifier;
+import org.apache.stratos.load.balancer.common.topology.TopologyProvider;
import org.apache.stratos.load.balancer.conf.LoadBalancerConfiguration;
import org.apache.stratos.load.balancer.conf.configurator.CEPConfigurator;
import org.apache.stratos.load.balancer.conf.configurator.SynapseConfigurator;
import org.apache.stratos.load.balancer.conf.configurator.TopologyFilterConfigurator;
-import org.apache.stratos.load.balancer.context.LoadBalancerContext;
import org.apache.stratos.load.balancer.endpoint.EndpointDeployer;
import org.apache.stratos.load.balancer.exception.TenantAwareLoadBalanceEndpointException;
-import org.apache.stratos.load.balancer.messaging.receiver.LoadBalancerApplicationSignUpEventReceiver;
-import org.apache.stratos.load.balancer.messaging.receiver.LoadBalancerDomainMappingEventReceiver;
-import org.apache.stratos.load.balancer.messaging.receiver.LoadBalancerTenantEventReceiver;
-import org.apache.stratos.load.balancer.messaging.receiver.LoadBalancerTopologyEventReceiver;
import org.apache.stratos.load.balancer.statistics.LoadBalancerStatisticsCollector;
import org.apache.stratos.load.balancer.util.LoadBalancerConstants;
import org.apache.stratos.messaging.message.filter.topology.TopologyClusterFilter;
import org.apache.stratos.messaging.message.filter.topology.TopologyMemberFilter;
import org.apache.stratos.messaging.message.filter.topology.TopologyServiceFilter;
+import org.apache.stratos.messaging.message.receiver.tenant.TenantEventReceiver;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.config.xml.MultiXMLConfigurationBuilder;
import org.apache.synapse.core.SynapseEnvironment;
@@ -62,8 +62,7 @@ import org.wso2.carbon.utils.ConfigurationContextService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.io.File;
-import java.util.Map;
-import java.util.Set;
+import java.util.Collection;
import java.util.concurrent.ExecutorService;
/**
@@ -93,7 +92,7 @@ public class LoadBalancerServiceComponent {
private boolean activated = false;
private ExecutorService executorService;
private LoadBalancerTopologyEventReceiver topologyReceiver;
- private LoadBalancerTenantEventReceiver tenantReceiver;
+ private TenantEventReceiver tenantReceiver;
private LoadBalancerApplicationSignUpEventReceiver applicationSignUpEventReceiver;
private LoadBalancerDomainMappingEventReceiver domainMappingEventReceiver;
private LoadBalancerStatisticsNotifier statisticsNotifier;
@@ -102,14 +101,12 @@ public class LoadBalancerServiceComponent {
try {
ClusteringAgent clusteringAgent = ServiceReferenceHolder.getInstance().getAxisConfiguration().getClusteringAgent();
boolean clusteringEnabled = (clusteringAgent != null);
- LoadBalancerContext.getInstance().setClustered(clusteringEnabled);
-
if(log.isInfoEnabled()) {
log.info(String.format("Load balancer clustering is %s", (clusteringEnabled ? "enabled" : "disabled")));
}
// Register endpoint deployer
- SynapseEnvironmentService synEnvService = LoadBalancerContext.getInstance().getTenantIdSynapseEnvironmentServiceMap()
+ SynapseEnvironmentService synEnvService = ServiceReferenceHolder.getInstance()
.getSynapseEnvironmentService(MultitenantConstants.SUPER_TENANT_ID);
registerDeployer(ServiceReferenceHolder.getInstance().getAxisConfiguration(),
synEnvService.getSynapseEnvironment());
@@ -129,22 +126,28 @@ public class LoadBalancerServiceComponent {
executorService = StratosThreadPool.getExecutorService(LoadBalancerConstants.LOAD_BALANCER_THREAD_POOL_ID,
threadPoolSize);
+ TopologyProvider topologyProvider = LoadBalancerConfiguration.getInstance().getTopologyProvider();
+ if(topologyProvider == null) {
+ topologyProvider = new TopologyProvider();
+ LoadBalancerConfiguration.getInstance().setTopologyProvider(topologyProvider);
+ }
+
if (configuration.isMultiTenancyEnabled()) {
// Start tenant event receiver
- startTenantEventReceiver(executorService);
+ startTenantEventReceiver(executorService, topologyProvider);
}
if(configuration.isDomainMappingEnabled()) {
// Start application signup event receiver
- startApplicationSignUpEventReceiver(executorService);
+ startApplicationSignUpEventReceiver(executorService, topologyProvider);
// Start domain mapping event receiver
- startDomainMappingEventReceiver(executorService);
+ startDomainMappingEventReceiver(executorService, topologyProvider);
}
if (configuration.isTopologyEventListenerEnabled()) {
// Start topology receiver
- startTopologyEventReceiver(executorService);
+ startTopologyEventReceiver(executorService, topologyProvider);
if (log.isInfoEnabled()) {
if (TopologyServiceFilter.getInstance().isActive()) {
@@ -197,8 +200,9 @@ public class LoadBalancerServiceComponent {
}
}
- private void startTenantEventReceiver(ExecutorService executorService) {
- tenantReceiver = new LoadBalancerTenantEventReceiver();
+ private void startTenantEventReceiver(ExecutorService executorService, TopologyProvider topologyProvider) {
+
+ tenantReceiver = new TenantEventReceiver();
tenantReceiver.setExecutorService(executorService);
tenantReceiver.execute();
if (log.isInfoEnabled()) {
@@ -206,8 +210,8 @@ public class LoadBalancerServiceComponent {
}
}
- private void startDomainMappingEventReceiver(ExecutorService executorService) {
- domainMappingEventReceiver = new LoadBalancerDomainMappingEventReceiver();
+ private void startDomainMappingEventReceiver(ExecutorService executorService, TopologyProvider topologyProvider) {
+ domainMappingEventReceiver = new LoadBalancerDomainMappingEventReceiver(topologyProvider);
domainMappingEventReceiver.setExecutorService(executorService);
domainMappingEventReceiver.execute();
if (log.isInfoEnabled()) {
@@ -215,8 +219,8 @@ public class LoadBalancerServiceComponent {
}
}
- private void startApplicationSignUpEventReceiver(ExecutorService executorService) {
- applicationSignUpEventReceiver = new LoadBalancerApplicationSignUpEventReceiver();
+ private void startApplicationSignUpEventReceiver(ExecutorService executorService, TopologyProvider topologyProvider) {
+ applicationSignUpEventReceiver = new LoadBalancerApplicationSignUpEventReceiver(topologyProvider);
applicationSignUpEventReceiver.setExecutorService(executorService);
applicationSignUpEventReceiver.execute();
if (log.isInfoEnabled()) {
@@ -224,8 +228,9 @@ public class LoadBalancerServiceComponent {
}
}
- private void startTopologyEventReceiver(ExecutorService executorService) {
- topologyReceiver = new LoadBalancerTopologyEventReceiver();
+ private void startTopologyEventReceiver(ExecutorService executorService, TopologyProvider topologyProvider) {
+
+ topologyReceiver = new LoadBalancerTopologyEventReceiver(topologyProvider);
topologyReceiver.setExecutorService(executorService);
topologyReceiver.execute();
if (log.isInfoEnabled()) {
@@ -278,36 +283,41 @@ public class LoadBalancerServiceComponent {
protected void deactivate(ComponentContext context) {
try {
- Set<Map.Entry<Integer, SynapseEnvironmentService>> entrySet = LoadBalancerContext
- .getInstance().getTenantIdSynapseEnvironmentServiceMap().getTenantIdSynapseEnvironmentServiceMap().entrySet();
- for (Map.Entry<Integer, SynapseEnvironmentService> entry : entrySet) {
- unregisterDeployer(entry.getValue().getConfigurationContext()
- .getAxisConfiguration(), entry.getValue()
- .getSynapseEnvironment());
+ Collection<SynapseEnvironmentService> synapseEnvironmentServices =
+ ServiceReferenceHolder.getInstance().getSynapseEnvironmentServices();
+ for (SynapseEnvironmentService synapseEnvironmentService : synapseEnvironmentServices) {
+ unregisterDeployer(synapseEnvironmentService.getConfigurationContext()
+ .getAxisConfiguration(), synapseEnvironmentService.getSynapseEnvironment());
}
} catch (Exception e) {
log.warn("An error occurred while removing endpoint deployer", e);
}
// Terminate tenant receiver
- try {
- tenantReceiver.terminate();
- } catch (Exception e) {
- log.warn("An error occurred while terminating tenant event receiver", e);
+ if(tenantReceiver != null) {
+ try {
+ tenantReceiver.terminate();
+ } catch (Exception e) {
+ log.warn("An error occurred while terminating tenant event receiver", e);
+ }
}
// Terminate topology receiver
- try {
- topologyReceiver.terminate();
- } catch (Exception e) {
- log.warn("An error occurred while terminating topology event receiver", e);
+ if(topologyReceiver != null) {
+ try {
+ topologyReceiver.terminate();
+ } catch (Exception e) {
+ log.warn("An error occurred while terminating topology event receiver", e);
+ }
}
// Terminate statistics notifier
- try {
- statisticsNotifier.terminate();
- } catch (Exception e) {
- log.warn("An error occurred while terminating health statistics notifier", e);
+ if(statisticsNotifier != null) {
+ try {
+ statisticsNotifier.terminate();
+ } catch (Exception e) {
+ log.warn("An error occurred while terminating health statistics notifier", e);
+ }
}
// Shutdown executor service
@@ -402,13 +412,11 @@ public class LoadBalancerServiceComponent {
* new Synapse Instance
*/
protected void setSynapseEnvironmentService(SynapseEnvironmentService synapseEnvironmentService) {
- boolean alreadyCreated = LoadBalancerContext.getInstance()
- .getTenantIdSynapseEnvironmentServiceMap()
+ boolean alreadyCreated = ServiceReferenceHolder.getInstance()
.containsSynapseEnvironmentService(synapseEnvironmentService.getTenantId());
- LoadBalancerContext.getInstance().getTenantIdSynapseEnvironmentServiceMap()
- .addSynapseEnvironmentService(synapseEnvironmentService.getTenantId(),
- synapseEnvironmentService);
+ ServiceReferenceHolder.getInstance().addSynapseEnvironmentService(synapseEnvironmentService.getTenantId(),
+ synapseEnvironmentService);
if (activated) {
if (!alreadyCreated) {
try {
@@ -431,10 +439,8 @@ public class LoadBalancerServiceComponent {
*
* @param synapseEnvironmentService synapseEnvironment
*/
- protected void unsetSynapseEnvironmentService(
- SynapseEnvironmentService synapseEnvironmentService) {
- LoadBalancerContext.getInstance().getTenantIdSynapseEnvironmentServiceMap().removeSynapseEnvironmentService(
- synapseEnvironmentService.getTenantId());
+ protected void unsetSynapseEnvironmentService(SynapseEnvironmentService synapseEnvironmentService) {
+ ServiceReferenceHolder.getInstance().removeSynapseEnvironmentService(synapseEnvironmentService.getTenantId());
}
protected void setRegistryService(RegistryService regService) {
@@ -481,16 +487,12 @@ public class LoadBalancerServiceComponent {
protected void unsetSynapseRegistrationsService(
SynapseRegistrationsService synapseRegistrationsService) {
int tenantId = synapseRegistrationsService.getTenantId();
- if (LoadBalancerContext.getInstance().getTenantIdSynapseEnvironmentServiceMap()
- .containsSynapseEnvironmentService(tenantId)) {
- SynapseEnvironment env = LoadBalancerContext.getInstance()
- .getTenantIdSynapseEnvironmentServiceMap()
- .getSynapseEnvironmentService(tenantId)
+ if (ServiceReferenceHolder.getInstance().containsSynapseEnvironmentService(tenantId)) {
+ SynapseEnvironment env = ServiceReferenceHolder.getInstance().getSynapseEnvironmentService(tenantId)
.getSynapseEnvironment();
- LoadBalancerContext.getInstance().getTenantIdSynapseEnvironmentServiceMap()
- .removeSynapseEnvironmentService(
- synapseRegistrationsService.getTenantId());
+ ServiceReferenceHolder.getInstance().removeSynapseEnvironmentService(
+ synapseRegistrationsService.getTenantId());
AxisConfiguration axisConfig = synapseRegistrationsService
.getConfigurationContext().getAxisConfiguration();
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
index 54e9f25..e026ac5 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/internal/ServiceReferenceHolder.java
@@ -27,9 +27,13 @@ import org.apache.stratos.common.clustering.DistributedObjectProvider;
import org.apache.stratos.load.balancer.exception.TenantAwareLoadBalanceEndpointException;
import org.apache.synapse.config.SynapseConfiguration;
import org.wso2.carbon.mediation.dependency.mgt.services.DependencyManagementService;
+import org.wso2.carbon.mediation.initializer.services.SynapseEnvironmentService;
import org.wso2.carbon.registry.core.session.UserRegistry;
import org.wso2.carbon.user.core.service.RealmService;
+import java.util.Collection;
+import java.util.concurrent.ConcurrentHashMap;
+
/**
* Service reference holder keeps references of bind OSGi services.
*/
@@ -46,8 +50,10 @@ public class ServiceReferenceHolder {
private DependencyManagementService dependencyManager;
private RealmService realmService;
private DistributedObjectProvider distributedObjectProvider;
+ private ConcurrentHashMap<Integer, SynapseEnvironmentService> synapseEnvironmentServiceMap;
private ServiceReferenceHolder() {
+ synapseEnvironmentServiceMap = new ConcurrentHashMap<Integer, SynapseEnvironmentService>();
}
public static ServiceReferenceHolder getInstance() {
@@ -135,4 +141,24 @@ public class ServiceReferenceHolder {
public DistributedObjectProvider getDistributedObjectProvider() {
return distributedObjectProvider;
}
+
+ public SynapseEnvironmentService getSynapseEnvironmentService(int tenantId) {
+ return synapseEnvironmentServiceMap.get(tenantId);
+ }
+
+ public boolean containsSynapseEnvironmentService(int tenantId) {
+ return synapseEnvironmentServiceMap.containsKey(tenantId);
+ }
+
+ public void addSynapseEnvironmentService(int tenantId, SynapseEnvironmentService synapseEnvironmentService) {
+ synapseEnvironmentServiceMap.put(tenantId, synapseEnvironmentService);
+ }
+
+ public void removeSynapseEnvironmentService(int tenantId) {
+ synapseEnvironmentServiceMap.remove(tenantId);
+ }
+
+ public Collection<SynapseEnvironmentService> getSynapseEnvironmentServices() {
+ return synapseEnvironmentServiceMap.values();
+ }
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/mediators/LocationReWriter.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/mediators/LocationReWriter.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/mediators/LocationReWriter.java
index 88ec7bf..c8d0c2c 100644
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/mediators/LocationReWriter.java
+++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/mediators/LocationReWriter.java
@@ -19,6 +19,7 @@
package org.apache.stratos.load.balancer.mediators;
import org.apache.commons.lang3.StringUtils;
+import org.apache.stratos.load.balancer.common.topology.TopologyProvider;
import org.apache.stratos.load.balancer.conf.LoadBalancerConfiguration;
import org.apache.stratos.load.balancer.context.LoadBalancerContext;
import org.apache.stratos.load.balancer.util.LoadBalancerConstants;
@@ -66,8 +67,8 @@ public class LocationReWriter extends AbstractMediator {
// Check whether the location host is an ip address of a known member
String hostname = LoadBalancerContext.getInstance().getMemberIpHostnameMap().get(inLocationUrl.getHost());
if (StringUtils.isEmpty(hostname)) {
-
- if (!LoadBalancerContext.getInstance().getHostNameClusterMap().containsCluster(inLocationUrl.getHost())) {
+ TopologyProvider topologyProvider = LoadBalancerConfiguration.getInstance().getTopologyProvider();
+ if (topologyProvider.getClusterByHostName(inLocationUrl.getHost()) == null) {
if (log.isDebugEnabled()) {
log.debug(String.format("A hostname not found for ip: [ip-address] %s", inLocationUrl.getHost()));
}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerApplicationSignUpEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerApplicationSignUpEventReceiver.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerApplicationSignUpEventReceiver.java
deleted file mode 100644
index 37a0c97..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerApplicationSignUpEventReceiver.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.messaging.receiver;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.load.balancer.context.LoadBalancerContextUtil;
-import org.apache.stratos.messaging.domain.application.signup.ApplicationSignUp;
-import org.apache.stratos.messaging.domain.application.signup.DomainMapping;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.event.application.signup.CompleteApplicationSignUpsEvent;
-import org.apache.stratos.messaging.listener.application.signup.CompleteApplicationSignUpsEventListener;
-import org.apache.stratos.messaging.message.receiver.application.signup.ApplicationSignUpEventReceiver;
-
-/**
- * Load balancer application signup event receiver.
- */
-public class LoadBalancerApplicationSignUpEventReceiver extends ApplicationSignUpEventReceiver {
-
- private static final Log log = LogFactory.getLog(LoadBalancerApplicationSignUpEventReceiver.class);
-
- public LoadBalancerApplicationSignUpEventReceiver() {
- addEventListeners();
- }
-
- private void addEventListeners() {
- addEventListener(new CompleteApplicationSignUpsEventListener() {
- @Override
- protected void onEvent(Event event) {
- if (log.isDebugEnabled()) {
- log.debug("Complete application signup event received");
- }
- CompleteApplicationSignUpsEvent completeApplicationSignUpsEvent = (CompleteApplicationSignUpsEvent)event;
- for(ApplicationSignUp applicationSignUp : completeApplicationSignUpsEvent.getApplicationSignUps()) {
- if(applicationSignUp.getDomainMappings() != null) {
- for (DomainMapping domainMapping : applicationSignUp.getDomainMappings()) {
- if(domainMapping != null) {
- LoadBalancerContextUtil.addClusterAgainstDomain(
- domainMapping.getServiceName(),
- domainMapping.getClusterId(),
- domainMapping.getDomainName());
-
- LoadBalancerContextUtil.addContextPathAgainstDomain(domainMapping.getDomainName(),
- domainMapping.getContextPath());
- }
- }
- }
- }
- }
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/stratos/blob/c799abce/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerDomainMappingEventReceiver.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerDomainMappingEventReceiver.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerDomainMappingEventReceiver.java
deleted file mode 100644
index ea9238f..0000000
--- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/receiver/LoadBalancerDomainMappingEventReceiver.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.messaging.receiver;
-
-import org.apache.stratos.load.balancer.context.LoadBalancerContextUtil;
-import org.apache.stratos.messaging.event.Event;
-import org.apache.stratos.messaging.event.domain.mapping.DomainMappingAddedEvent;
-import org.apache.stratos.messaging.event.domain.mapping.DomainMappingRemovedEvent;
-import org.apache.stratos.messaging.listener.domain.mapping.DomainMappingAddedEventListener;
-import org.apache.stratos.messaging.listener.domain.mapping.DomainMappingRemovedEventListener;
-import org.apache.stratos.messaging.message.receiver.domain.mapping.DomainMappingEventReceiver;
-
-/**
- * Load balancer domain mapping event receiver.
- */
-public class LoadBalancerDomainMappingEventReceiver extends DomainMappingEventReceiver {
-
- public LoadBalancerDomainMappingEventReceiver() {
- addEventListeners();
- }
-
- private void addEventListeners() {
-
- addEventListener(new DomainMappingAddedEventListener() {
- @Override
- protected void onEvent(Event event) {
- DomainMappingAddedEvent domainMappingAddedEvent = (DomainMappingAddedEvent)event;
-
- LoadBalancerContextUtil.addClusterAgainstDomain(
- domainMappingAddedEvent.getServiceName(),
- domainMappingAddedEvent.getClusterId(),
- domainMappingAddedEvent.getDomainName());
-
- LoadBalancerContextUtil.addContextPathAgainstDomain(
- domainMappingAddedEvent.getDomainName(),
- domainMappingAddedEvent.getContextPath());
- }
- });
-
- addEventListener(new DomainMappingRemovedEventListener() {
- @Override
- protected void onEvent(Event event) {
- DomainMappingRemovedEvent domainMappingRemovedEvent = (DomainMappingRemovedEvent)event;
-
- LoadBalancerContextUtil.removeClusterAgainstDomain(
- domainMappingRemovedEvent.getServiceName(),
- domainMappingRemovedEvent.getClusterId(),
- domainMappingRemovedEvent.getDomainName());
-
- LoadBalancerContextUtil.removeContextPathAgainstDomain(
- domainMappingRemovedEvent.getDomainName());
- }
- });
- }
-}