Updated Branches: refs/heads/master 8d947038b -> aa550b6be
Added multi-tenancy configuration properties to load balancer configuration and optimized configuration reader validations Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/aa550b6b Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/aa550b6b Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/aa550b6b Branch: refs/heads/master Commit: aa550b6be2a72c92581d27d893856e408f0ce3af Parents: 8d94703 Author: Imesh Gunaratne <[email protected]> Authored: Sat Dec 7 23:19:36 2013 +0530 Committer: Imesh Gunaratne <[email protected]> Committed: Sat Dec 7 23:19:36 2013 +0530 ---------------------------------------------------------------------- .../conf/LoadBalancerConfiguration.java | 202 ++++++++++++------- .../conf/configurator/SynapseConfigurator.java | 4 +- .../balancer/conf/domain/TenantIdentifier.java | 8 + .../load/balancer/conf/util/Constants.java | 9 +- .../test/LoadBalancerConfigurationTest.java | 12 +- .../sample/configuration/loadbalancer1.conf | 17 +- .../sample/configuration/loadbalancer2.conf | 17 +- .../sample/configuration/loadbalancer3.conf | 17 +- .../src/main/conf/loadbalancer.conf | 15 +- .../config/lb/repository/conf/loadbalancer.conf | 6 +- 10 files changed, 199 insertions(+), 108 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/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 f615090..6b29482 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 @@ -22,20 +22,19 @@ package org.apache.stratos.load.balancer.conf; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.load.balancer.LoadBalancerContext; +import org.apache.stratos.load.balancer.context.LoadBalancerContext; import org.apache.stratos.load.balancer.conf.domain.Algorithm; +import org.apache.stratos.load.balancer.conf.domain.TenantIdentifier; import org.apache.stratos.load.balancer.conf.structure.Node; import org.apache.stratos.load.balancer.conf.structure.NodeBuilder; import org.apache.stratos.load.balancer.conf.util.Constants; import org.apache.stratos.load.balancer.exception.InvalidConfigurationException; -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.domain.topology.Service; +import org.apache.stratos.messaging.domain.topology.*; import org.apache.stratos.messaging.message.receiver.topology.TopologyManager; import java.io.File; import java.util.*; +import java.util.regex.Pattern; /** * Load balancer configuration definition. @@ -45,8 +44,8 @@ public class LoadBalancerConfiguration { private static volatile LoadBalancerConfiguration instance; private String defaultAlgorithmName; - private boolean failOver; - private boolean sessionAffinity; + private boolean failOverEnabled; + private boolean sessionAffinityEnabled; private long sessionTimeout; private boolean cepStatsPublisherEnabled; private String mbIp; @@ -54,10 +53,12 @@ public class LoadBalancerConfiguration { private String cepIp; private int cepPort; private boolean topologyEventListenerEnabled; - private boolean usePublicIpAddresses; private Map<String, Algorithm> algorithmMap; private String topologyServiceFilter; private String topologyClusterFilter; + private boolean multiTenancyEnabled; + private TenantIdentifier tenantIdentifier; + private String tenantIdentifierRegex; /** * Load balancer configuration is singleton. @@ -104,20 +105,20 @@ public class LoadBalancerConfiguration { this.defaultAlgorithmName = defaultAlgorithmName; } - public boolean isFailOver() { - return failOver; + public boolean isFailOverEnabled() { + return failOverEnabled; } - public void setFailOver(boolean failOver) { - this.failOver = failOver; + public void setFailOverEnabled(boolean failOverEnabled) { + this.failOverEnabled = failOverEnabled; } - public boolean isSessionAffinity() { - return sessionAffinity; + public boolean isSessionAffinityEnabled() { + return sessionAffinityEnabled; } - public void setSessionAffinity(boolean sessionAffinity) { - this.sessionAffinity = sessionAffinity; + public void setSessionAffinityEnabled(boolean sessionAffinityEnabled) { + this.sessionAffinityEnabled = sessionAffinityEnabled; } public long getSessionTimeout() { @@ -176,14 +177,6 @@ public class LoadBalancerConfiguration { this.topologyEventListenerEnabled = topologyEventListenerEnabled; } - public boolean isUsePublicIpAddresses() { - return usePublicIpAddresses; - } - - public void setUsePublicIpAddresses(boolean usePublicIpAddresses) { - this.usePublicIpAddresses = usePublicIpAddresses; - } - public Collection<Algorithm> getAlgorithms() { return algorithmMap.values(); } @@ -212,6 +205,30 @@ public class LoadBalancerConfiguration { return topologyClusterFilter; } + public boolean isMultiTenancyEnabled() { + return multiTenancyEnabled; + } + + public void setMultiTenancyEnabled(boolean multiTenancyEnabled) { + this.multiTenancyEnabled = multiTenancyEnabled; + } + + public void setTenantIdentifier(TenantIdentifier tenantIdentifier) { + this.tenantIdentifier = tenantIdentifier; + } + + public TenantIdentifier getTenantIdentifier() { + return tenantIdentifier; + } + + public void setTenantIdentifierRegex(String tenantIdentifierRegex) { + this.tenantIdentifierRegex = tenantIdentifierRegex; + } + + public String getTenantIdentifierRegex() { + return tenantIdentifierRegex; + } + private static class LoadBalancerConfigurationReader { private String property; @@ -249,19 +266,17 @@ public class LoadBalancerConfiguration { // Set load balancer properties String defaultAlgorithm = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM); - if (StringUtils.isBlank(defaultAlgorithm)) { - throw new InvalidConfigurationException("algorithm property was not found in loadbalancer node"); - } + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_ALGORITHM, defaultAlgorithm, "loadbalancer"); configuration.setDefaultAlgorithmName(defaultAlgorithm); String failOver = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_FAILOVER); if (StringUtils.isNotBlank(failOver)) { - configuration.setFailOver(Boolean.parseBoolean(failOver)); + configuration.setFailOverEnabled(Boolean.parseBoolean(failOver)); } String sessionAffinity = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_SESSION_AFFINITY); if (StringUtils.isNotBlank(sessionAffinity)) { - configuration.setSessionAffinity(Boolean.parseBoolean(sessionAffinity)); + configuration.setSessionAffinityEnabled(Boolean.parseBoolean(sessionAffinity)); } String sessionTimeout = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_SESSION_TIMEOUT); if (StringUtils.isNotBlank(sessionTimeout)) { @@ -270,35 +285,36 @@ public class LoadBalancerConfiguration { // Session timeout is not found, set default value configuration.setSessionTimeout(Constants.DEFAULT_SESSION_TIMEOUT); } - String topologyEventListenerEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER_ENABLED); + + String topologyEventListenerEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER); if (StringUtils.isNotBlank(topologyEventListenerEnabled)) { configuration.setTopologyEventListenerEnabled(Boolean.parseBoolean(topologyEventListenerEnabled)); } - String statsPublisherEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_STATS_PUBLISHER_ENABLED); + String statsPublisherEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_STATS_PUBLISHER); if (StringUtils.isNotBlank(statsPublisherEnabled)) { configuration.setCepStatsPublisherEnabled(Boolean.parseBoolean(statsPublisherEnabled)); } + String multiTenancyEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MULTI_TENANCY); + if (StringUtils.isNotBlank(multiTenancyEnabled)) { + configuration.setMultiTenancyEnabled(Boolean.parseBoolean(multiTenancyEnabled)); + } // Read mb ip, port, topology service filter and topology cluster filter if topology event listener is enabled if (configuration.isTopologyEventListenerEnabled()) { String mbIp = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_IP); - String mbPort = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_PORT); - if (StringUtils.isBlank(mbIp)) { - throw new InvalidConfigurationException(String.format("%s property was not found in loadbalancer node", Constants.CONF_PROPERTY_MB_IP)); - } - if (StringUtils.isBlank(mbPort)) { - throw new InvalidConfigurationException(String.format("%s property was not found in loadbalancer node", Constants.CONF_PROPERTY_MB_PORT)); - } - + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_MB_IP, mbIp, "loadbalancer"); configuration.setMbIp(mbIp); + + String mbPort = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_MB_PORT); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_MB_PORT, mbPort, "loadbalancer"); configuration.setMbPort(Integer.parseInt(mbPort)); String serviceFilter = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_SERVICE_FILTER); - if(StringUtils.isNotBlank(serviceFilter)) { + if (StringUtils.isNotBlank(serviceFilter)) { configuration.setTopologyServiceFilter(serviceFilter); } String clusterFilter = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_CLUSTER_FILTER); - if(StringUtils.isNotBlank(clusterFilter)) { + if (StringUtils.isNotBlank(clusterFilter)) { configuration.setTopologyClusterFilter(clusterFilter); } } @@ -306,39 +322,54 @@ public class LoadBalancerConfiguration { // Read cep ip and port if cep stats publisher is enabled if (configuration.isCepStatsPublisherEnabled()) { String cepIp = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_IP); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CEP_IP, cepIp, "loadbalancer"); + configuration.setCepIp(cepIp); + String cepPort = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_PORT); - if (StringUtils.isBlank(cepIp)) { - throw new InvalidConfigurationException(String.format("%s property was not found in loadbalancer node", Constants.CONF_PROPERTY_CEP_IP)); - } - if (StringUtils.isBlank(cepPort)) { - throw new InvalidConfigurationException(String.format("%s property was not found in loadbalancer node", Constants.CONF_PROPERTY_CEP_PORT)); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CEP_PORT, cepPort, "loadbalancer"); + configuration.setCepPort(Integer.parseInt(cepPort)); + } + + if (configuration.isMultiTenancyEnabled()) { + String tenantIdentifierStr = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TENANT_IDENTIFIER); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TENANT_IDENTIFIER, tenantIdentifierStr, "loadbalancer"); + + if (tenantIdentifierStr.equals(Constants.CONF_PROPERTY_VALUE_TENANT_ID)) { + configuration.setTenantIdentifier(TenantIdentifier.TenantId); + } else if (tenantIdentifierStr.equals(Constants.CONF_PROPERTY_VALUE_TENANT_DOMAIN)) { + configuration.setTenantIdentifier(TenantIdentifier.TenantDomain); + } else { + throw new InvalidConfigurationException(String.format("Tenant identifier %s is not valid", tenantIdentifierStr)); } - configuration.setCepIp(cepIp); - configuration.setCepPort(Integer.parseInt(cepPort)); + String tenantIdentifierRegex = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TENANT_IDENTIFIER_REGEX); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TENANT_IDENTIFIER_REGEX, tenantIdentifierRegex, "loadbalancer"); + try { + Pattern.compile(tenantIdentifierRegex); + } + catch (Exception e) { + throw new InvalidConfigurationException(String.format("Invalid tenant identifier regular expression: %s", tenantIdentifierRegex), e); + } + configuration.setTenantIdentifierRegex(tenantIdentifierRegex); } Node algorithmsNode = loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_ALGORITHMS); - if (loadBalancerNode == null) { - throw new RuntimeException(String.format("%s node was node found", Constants.CONF_ELEMENT_ALGORITHMS)); - } + validateRequiredNode(loadBalancerNode, Constants.CONF_ELEMENT_ALGORITHMS); + for (Node algorithmNode : algorithmsNode.getChildNodes()) { String className = algorithmNode.getProperty(Constants.CONF_PROPERTY_CLASS_NAME); - if (StringUtils.isBlank(className)) { - throw new InvalidConfigurationException(String.format("%s property was not found in algorithm %s", Constants.CONF_PROPERTY_CLASS_NAME, algorithmNode.getName())); - } + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_CLASS_NAME, className, "algorithm", algorithmNode.getName()); Algorithm algorithm = new Algorithm(algorithmNode.getName(), className); configuration.addAlgorithm(algorithm); } if (!configuration.isTopologyEventListenerEnabled()) { Node servicesNode = loadBalancerNode.findChildNodeByName(Constants.CONF_ELEMENT_SERVICES); - if (loadBalancerNode == null) { - throw new RuntimeException(String.format("%s node was not found", Constants.CONF_ELEMENT_SERVICES)); - } + validateRequiredNode(servicesNode, Constants.CONF_ELEMENT_SERVICES); for (Node serviceNode : servicesNode.getChildNodes()) { - Service service = new Service(serviceNode.getName()); + // TODO: Add service type to service node + Service service = new Service(serviceNode.getName(), ServiceType.SingleTenant); Node clustersNode = serviceNode.findChildNodeByName(Constants.CONF_ELEMENT_CLUSTERS); for (Node clusterNode : clustersNode.getChildNodes()) { @@ -346,45 +377,38 @@ public class LoadBalancerConfiguration { Cluster cluster = new Cluster(service.getServiceName(), clusterId, null); String algorithm = clusterNode.getProperty(Constants.CONF_PROPERTY_ALGORITHM); - if(StringUtils.isNotBlank(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())); - } + validateRequiredPropertyInNode(Constants.CONF_ELEMENT_HOSTS, hosts, "cluster", clusterNode.getName()); + String[] hostsArray = hosts.split(","); - for(String hostsName : hostsArray) { + for (String hostsName : hostsArray) { cluster.addHostName(hostsName.trim()); } Node membersNode = clusterNode.findChildNodeByName(Constants.CONF_ELEMENT_MEMBERS); - if (membersNode == null) { - throw new InvalidConfigurationException(String.format("%s node was not found in cluster %s", Constants.CONF_ELEMENT_MEMBERS, clusterId)); - } + validateRequiredNode(membersNode, Constants.CONF_ELEMENT_MEMBERS, String.format("cluster %s", clusterId)); for (Node memberNode : membersNode.getChildNodes()) { String memberId = memberNode.getName(); Member member = new Member(cluster.getServiceName(), cluster.getClusterId(), memberId); String ip = memberNode.getProperty(Constants.CONF_PROPERTY_IP); - if (StringUtils.isBlank(ip)) { - throw new InvalidConfigurationException(String.format("%s property was not found in member %s", Constants.CONF_PROPERTY_IP, memberId)); - } + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_IP, ip, String.format("member %s", memberId)); + member.setMemberIp(ip); Node portsNode = memberNode.findChildNodeByName(Constants.CONF_ELEMENT_PORTS); - if (portsNode == null) { - throw new InvalidConfigurationException(String.format("%s node was not found in member %s", Constants.CONF_ELEMENT_PORTS, memberId)); - } + validateRequiredNode(portsNode, Constants.CONF_ELEMENT_PORTS, String.format("member %s", memberId)); + for (Node portNode : portsNode.getChildNodes()) { String value = portNode.getProperty(Constants.CONF_PROPERTY_VALUE); - if (StringUtils.isBlank(value)) { - throw new InvalidConfigurationException(String.format("%s property was not found in port %s in member %s", Constants.CONF_PROPERTY_VALUE, portNode.getName(), memberId)); - } + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_VALUE, value, "port", String.format("member %s", memberId)); + String proxy = portNode.getProperty(Constants.CONF_PROPERTY_PROXY); - if (StringUtils.isBlank(proxy)) { - throw new InvalidConfigurationException(String.format("%s property was not found in port %s in member %s", Constants.CONF_PROPERTY_PROXY, portNode.getName(), memberId)); - } + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_PROXY, proxy, "port", String.format("member %s", memberId)); + Port port = new Port(portNode.getName(), Integer.valueOf(value), Integer.valueOf(proxy)); member.addPort(port); } @@ -407,5 +431,27 @@ public class LoadBalancerConfiguration { } return configuration; } + + private void validateRequiredNode(Node node, String nodeName) { + if (node == null) { + throw new RuntimeException(String.format("%s node was not found", nodeName)); + } + } + + private void validateRequiredNode(Node node, String nodeName, String parentNodeName) { + if (node == null) { + throw new RuntimeException(String.format("%s node was not found in %s", nodeName, parentNodeName)); + } + } + + private void validateRequiredPropertyInNode(String propertyName, String value, String nodeName) { + validateRequiredPropertyInNode(propertyName, value, nodeName, ""); + } + + private void validateRequiredPropertyInNode(String propertyName, String value, String nodeName, String nodeItem) { + if (StringUtils.isBlank(value)) { + throw new InvalidConfigurationException(String.format("%s property was not found in %s node %s", propertyName, nodeName, nodeItem)); + } + } } } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/configurator/SynapseConfigurator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/configurator/SynapseConfigurator.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/configurator/SynapseConfigurator.java index 37bb67f..056637b 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/configurator/SynapseConfigurator.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/configurator/SynapseConfigurator.java @@ -115,14 +115,14 @@ public class SynapseConfigurator { node.setTextContent(algorithmClassName); updated = true; } else if (parameter.getNodeValue().equals("failover")) { - String value = String.valueOf(configuration.isFailOver()); + String value = String.valueOf(configuration.isFailOverEnabled()); if (log.isDebugEnabled()) { log.debug(String.format("Setting failover = %s", value)); } node.setTextContent(value); updated = true; } else if (parameter.getNodeValue().equals("sessionAffinity")) { - String value = String.valueOf(configuration.isSessionAffinity()); + String value = String.valueOf(configuration.isSessionAffinityEnabled()); if (log.isDebugEnabled()) { log.debug(String.format("Setting sessionAffinity = %s", value)); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/TenantIdentifier.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/TenantIdentifier.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/TenantIdentifier.java new file mode 100644 index 0000000..4fb2a5b --- /dev/null +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/TenantIdentifier.java @@ -0,0 +1,8 @@ +package org.apache.stratos.load.balancer.conf.domain; + +/** + * Tenant identifier type. + */ +public enum TenantIdentifier { + TenantId, TenantDomain; +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/util/Constants.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/util/Constants.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/util/Constants.java index 248b55b..cc5181b 100755 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/util/Constants.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/util/Constants.java @@ -36,10 +36,10 @@ public class Constants { public static final String CONF_PROPERTY_FAILOVER = "failover"; public static final String CONF_PROPERTY_SESSION_AFFINITY = "session-affinity"; public static final String CONF_PROPERTY_SESSION_TIMEOUT = "session-timeout"; - public static final String CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER_ENABLED = "topology-event-listener-enabled"; + public static final String CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER = "topology-event-listener"; public static final String CONF_PROPERTY_MB_IP = "mb-ip"; public static final String CONF_PROPERTY_MB_PORT = "mb-port"; - public static final String CONF_PROPERTY_CEP_STATS_PUBLISHER_ENABLED = "cep-stats-publisher-enabled"; + public static final String CONF_PROPERTY_CEP_STATS_PUBLISHER = "cep-stats-publisher"; public static final String CONF_PROPERTY_CEP_IP = "cep-ip"; public static final String CONF_PROPERTY_CEP_PORT = "cep-port"; public static final String CONF_PROPERTY_CLASS_NAME = "class-name"; @@ -48,6 +48,11 @@ public class Constants { public static final String CONF_PROPERTY_PROXY = "proxy"; public static final String CONF_PROPERTY_TOPOLOGY_SERVICE_FILTER = "topology-service-filter"; public static final String CONF_PROPERTY_TOPOLOGY_CLUSTER_FILTER = "topology-cluster-filter"; + public static final String CONF_PROPERTY_MULTI_TENANCY = "multi-tenancy"; + public static final String CONF_PROPERTY_TENANT_IDENTIFIER = "tenant-identifier"; + public static final String CONF_PROPERTY_VALUE_TENANT_ID = "tenant-id"; + public static final String CONF_PROPERTY_VALUE_TENANT_DOMAIN = "tenant-domain"; + public static final String CONF_PROPERTY_TENANT_IDENTIFIER_REGEX = "tenant-identifier-regex"; public static final String CONF_DELIMITER_HOSTS = ","; public static final long DEFAULT_SESSION_TIMEOUT = 90000; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/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 d1e31a5..89ee6f3 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 @@ -21,6 +21,7 @@ package org.apache.stratos.load.balancer.test; import java.io.File; import java.net.URL; +import org.apache.stratos.load.balancer.conf.domain.TenantIdentifier; import org.apache.stratos.messaging.domain.topology.*; import org.junit.Assert; import org.junit.Test; @@ -68,15 +69,18 @@ public class LoadBalancerConfigurationTest { 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.assertTrue(String.format("%s, failover is not true", validationError), configuration.isFailOverEnabled()); + Assert.assertTrue(String.format("%s, session affinity is not true", validationError), configuration.isSessionAffinityEnabled()); 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.assertTrue(String.format("%s, topology event listener 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.assertTrue(String.format("%s, cep stats publisher 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()); + Assert.assertTrue(String.format("%s, multi-tenancy is not true", validationError), configuration.isMultiTenancyEnabled()); + Assert.assertEquals(String.format("%s, tenant-identifier is not valid", validationError), TenantIdentifier.TenantDomain, configuration.getTenantIdentifier()); + Assert.assertEquals(String.format("%s, tenant-identifier-regex is not valid", validationError), "t/(.+)/", configuration.getTenantIdentifierRegex()); } finally { LoadBalancerConfiguration.clear(); } http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/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 c135405..08e7f27 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 @@ -17,8 +17,8 @@ # Load balancer test configuration 1 # ----------------------------------- -# topology-event-listener-enabled = true -# cep-stats-publisher-enabled = true +# topology-event-listener = true +# cep-stats-publisher = true # loadbalancer { @@ -44,7 +44,7 @@ loadbalancer { # If this property is set to true, load balancer will listen to topology events and build # the topology configuration accordingly. If not static configuration given in the services # section will be used. - topology-event-listener-enabled: true; + topology-event-listener: true; # Message broker endpoint # Provide message broker ip address and port if topology_event_listener_enabled is set to true. @@ -64,14 +64,21 @@ loadbalancer { # topology-cluster-filter: cluster-id1, cluster-id2; # Enable/disable cep statistics publisher - cep-stats-publisher-enabled: true; + cep-stats-publisher: true; # Complex event processor endpoint # Provide CEP ip address and port if stats_publisher_enabled is set to true. cep-ip: localhost; cep-port: 7615; - # Load balancing algorithm class names. + # Multi-tenancy + # If this property is set to true, all incoming request URLs will be scanned using the given tenant-identifier-regex + # and matching tenant identifier value will be used to delegate the requests to the relevant cluster. + multi-tenancy: true; + tenant-identifier: tenant-domain; # Tenant identifier could either be tenant-id or tenant-domain. + tenant-identifier-regex: t/(.+)/; # Regular expression for extracting the tenant identifier value from the URL. + + # Load balancing algorithm class names algorithms { round-robin { # algorithm name class-name: org.apache.stratos.load.balancer.algorithm.RoundRobin; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/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 159bc2e..b60919a 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 @@ -17,8 +17,8 @@ # Load balancer test configuration 2 # ----------------------------------- -# topology-event-listener-enabled = false -# cep-stats-publisher-enabled = true +# topology-event-listener = false +# cep-stats-publisher = true # loadbalancer { @@ -44,7 +44,7 @@ loadbalancer { # If this property is set to true, load balancer will listen to topology events and build # the topology configuration accordingly. If not static configuration given in the services # section will be used. - topology-event-listener-enabled: false; + topology-event-listener: false; # Message broker endpoint # Provide message broker ip address and port if topology_event_listener_enabled is set to true. @@ -64,14 +64,21 @@ loadbalancer { # topology-cluster-filter: cluster-id1, cluster-id2; # Enable/disable cep statistics publisher - cep-stats-publisher-enabled: true; + cep-stats-publisher: true; # Complex event processor endpoint # Provide CEP ip address and port if stats_publisher_enabled is set to true. cep-ip: localhost; cep-port: 7615; - # Load balancing algorithm class names. + # Multi-tenancy + # If this property is set to true, all incoming request URLs will be scanned using the given tenant-identifier-regex + # and matching tenant identifier value will be used to delegate the requests to the relevant cluster. + multi-tenancy: true; + tenant-identifier: tenant-domain; # Tenant identifier could either be tenant-id or tenant-domain. + tenant-identifier-regex: t/(.+)/; # Regular expression for extracting the tenant identifier value from the URL. + + # Load balancing algorithm class names algorithms { round-robin { # algorithm name class-name: org.apache.stratos.load.balancer.algorithm.RoundRobin; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/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 dd9be36..8fbe48d 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 @@ -17,8 +17,8 @@ # Load balancer test configuration 3 # ----------------------------------- -# topology-event-listener-enabled = true -# cep-stats-publisher-enabled = false +# topology-event-listener = true +# cep-stats-publisher = false # loadbalancer { @@ -44,7 +44,7 @@ loadbalancer { # If this property is set to true, load balancer will listen to topology events and build # the topology configuration accordingly. If not static configuration given in the services # section will be used. - topology-event-listener-enabled: true; + topology-event-listener: true; # Message broker endpoint # Provide message broker ip address and port if topology_event_listener_enabled is set to true. @@ -64,14 +64,21 @@ loadbalancer { # topology-cluster-filter: cluster-id1, cluster-id2; # Enable/disable cep statistics publisher - cep-stats-publisher-enabled: false; + cep-stats-publisher: false; # Complex event processor endpoint # Provide CEP ip address and port if stats_publisher_enabled is set to true. # cep-ip: localhost; # cep-port: 7615; - # Load balancing algorithm class names. + # Multi-tenancy + # If this property is set to true, all incoming request URLs will be scanned using the given tenant-identifier-regex + # and matching tenant identifier value will be used to delegate the requests to the relevant cluster. + multi-tenancy: true; + tenant-identifier: tenant-domain; # Tenant identifier could either be tenant-id or tenant-domain. + tenant-identifier-regex: t/(.+)/; # Regular expression for extracting the tenant identifier value from the URL. + + # Load balancing algorithm class names algorithms { round-robin { # algorithm name class-name: org.apache.stratos.load.balancer.algorithm.RoundRobin; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf ---------------------------------------------------------------------- diff --git a/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf b/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf index 14c3f3b..038aa19 100644 --- a/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf +++ b/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf @@ -38,7 +38,7 @@ loadbalancer { # If this property is set to true, load balancer will listen to topology events and build # the topology configuration accordingly. If not static configuration given in the services # section will be used. - topology-event-listener-enabled: true; + topology-event-listener: true; # Message broker endpoint # Provide message broker ip address and port if topology_event_listener_enabled is set to true. @@ -58,14 +58,21 @@ loadbalancer { # topology-cluster-filter: cluster-id1, cluster-id2; # Enable/disable cep statistics publisher - cep-stats-publisher-enabled: true; + cep-stats-publisher: true; # Complex event processor endpoint # Provide CEP ip address and port if stats_publisher_enabled is set to true. cep-ip: localhost; cep-port: 7615; - # Load balancing algorithm class names. + # Multi-tenancy + # If this property is set to true, all incoming request URLs will be scanned using the given tenant-identifier-regex + # and matching tenant identifier value will be used to delegate the requests to the relevant cluster. + multi-tenancy: true; + tenant-identifier: tenant-domain; # Tenant identifier could either be tenant-id or tenant-domain. + tenant-identifier-regex: t/(.+)/; # Regular expression for extracting the tenant identifier value from the URL. + + # Load balancing algorithm class names algorithms { round-robin { # algorithm name class-name: org.apache.stratos.load.balancer.algorithm.RoundRobin; @@ -73,7 +80,7 @@ loadbalancer { } # Static topology configuration - # Define a static topology configuration if topology-event-listener-enabled is set to false. + # Define a static topology configuration if topology-event-listener is set to false. # A sample configuration has been given below: # # services { http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/aa550b6b/tools/stratos-installer/config/lb/repository/conf/loadbalancer.conf ---------------------------------------------------------------------- diff --git a/tools/stratos-installer/config/lb/repository/conf/loadbalancer.conf b/tools/stratos-installer/config/lb/repository/conf/loadbalancer.conf index 52d17a0..6a6e4ee 100644 --- a/tools/stratos-installer/config/lb/repository/conf/loadbalancer.conf +++ b/tools/stratos-installer/config/lb/repository/conf/loadbalancer.conf @@ -38,7 +38,7 @@ loadbalancer { # If this property is set to true, load balancer will listen to topology events and build # the topology configuration accordingly. If not static configuration given in the services # section will be used. - topology-event-listener-enabled: true; + topology-event-listener: true; # Message broker endpoint # Provide message broker ip address and port if topology_event_listener_enabled is set to true. @@ -58,7 +58,7 @@ loadbalancer { # topology-cluster-filter: cluster-id1, cluster-id2; # Enable/disable cep statistics publisher - cep-stats-publisher-enabled: true; + cep-stats-publisher: true; # Complex event processor endpoint # Provide CEP ip address and port if stats_publisher_enabled is set to true. @@ -73,7 +73,7 @@ loadbalancer { } # Static topology configuration - # Define a static topology configuration if topology-event-listener-enabled is set to false. + # Define a static topology configuration if topology-event-listener is set to false. # A sample configuration has been given below: # # services {
