Updated Branches: refs/heads/master 8e8a1c99c -> f5d1a1083
Added functionality to configure member ip address type: private | public Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/f5d1a108 Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/f5d1a108 Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/f5d1a108 Branch: refs/heads/master Commit: f5d1a1083a16d5076ab96365c1019f19fadbd95d Parents: 8e8a1c9 Author: Imesh Gunaratne <[email protected]> Authored: Wed Feb 5 12:31:50 2014 -0500 Committer: Imesh Gunaratne <[email protected]> Committed: Wed Feb 5 12:31:50 2014 -0500 ---------------------------------------------------------------------- .../conf/LoadBalancerConfiguration.java | 32 ++++++++++++++++++-- .../load/balancer/conf/domain/MemberIpType.java | 31 +++++++++++++++++++ .../balancer/conf/domain/TenantIdentifier.java | 19 ++++++++++++ .../load/balancer/conf/util/Constants.java | 1 + .../TenantAwareLoadBalanceEndpoint.java | 32 +++++++++++++++++++- .../sample/configuration/loadbalancer1.conf | 6 ++++ .../sample/configuration/loadbalancer2.conf | 6 ++++ .../sample/configuration/loadbalancer3.conf | 6 ++++ .../distribution/src/main/conf/mincheck.drl | 2 +- .../src/main/conf/loadbalancer.conf | 8 ++++- 10 files changed, 138 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 337b94e..1acf574 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 @@ -23,6 +23,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.load.balancer.conf.domain.Algorithm; +import org.apache.stratos.load.balancer.conf.domain.MemberIpType; 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; @@ -57,6 +58,7 @@ public class LoadBalancerConfiguration { private String cepIp; private int cepPort; private boolean topologyEventListenerEnabled; + private MemberIpType topologyMemberIpType = MemberIpType.Private; private Map<String, Algorithm> algorithmMap; private String topologyServiceFilter; private String topologyClusterFilter; @@ -184,6 +186,14 @@ public class LoadBalancerConfiguration { this.topologyEventListenerEnabled = topologyEventListenerEnabled; } + public MemberIpType getTopologyMemberIpType() { + return topologyMemberIpType; + } + + public void setTopologyMemberIpType(MemberIpType type) { + topologyMemberIpType = type; + } + public Collection<Algorithm> getAlgorithms() { return algorithmMap.values(); } @@ -310,9 +320,15 @@ public class LoadBalancerConfiguration { } String topologyEventListenerEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER); - if (StringUtils.isNotBlank(topologyEventListenerEnabled)) { - configuration.setTopologyEventListenerEnabled(Boolean.parseBoolean(topologyEventListenerEnabled)); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TOPOLOGY_EVENT_LISTENER, topologyEventListenerEnabled, Constants.CONF_ELEMENT_LOADBALANCER); + configuration.setTopologyEventListenerEnabled(Boolean.parseBoolean(topologyEventListenerEnabled)); + + if(configuration.isTopologyEventListenerEnabled()) { + String topologyMemberIpType = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE); + validateRequiredPropertyInNode(Constants.CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE, topologyMemberIpType, Constants.CONF_ELEMENT_LOADBALANCER); + configuration.setTopologyMemberIpType(transformMemberIpType(topologyMemberIpType)); } + String statsPublisherEnabled = loadBalancerNode.getProperty(Constants.CONF_PROPERTY_CEP_STATS_PUBLISHER); if (StringUtils.isNotBlank(statsPublisherEnabled)) { configuration.setCepStatsPublisherEnabled(Boolean.parseBoolean(statsPublisherEnabled)); @@ -481,6 +497,18 @@ public class LoadBalancerConfiguration { return configuration; } + private MemberIpType transformMemberIpType(String topologyMemberIpType) { + if("private".equals(topologyMemberIpType)) { + return MemberIpType.Private; + } + else if("public".equals(topologyMemberIpType)) { + return MemberIpType.Public; + } + else { + throw new InvalidConfigurationException(String.format("Topology member ip address type is not valid: %s", topologyMemberIpType)); + } + } + private void validateRequiredNode(Node node, String nodeName) { if (node == null) { throw new RuntimeException(String.format("%s node was not found", nodeName)); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/MemberIpType.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/MemberIpType.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/MemberIpType.java new file mode 100644 index 0000000..f5132d6 --- /dev/null +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/conf/domain/MemberIpType.java @@ -0,0 +1,31 @@ +/* + * 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.conf.domain; + +/** + * Created with IntelliJ IDEA. + * User: imesh + * Date: 2/5/14 + * Time: 11:18 AM + * To change this template use File | Settings | File Templates. + */ +public enum MemberIpType { + Private, Public +} http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 index 4fb2a5b..344fc82 100644 --- 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 @@ -1,3 +1,22 @@ +/* + * 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.conf.domain; /** http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 cd26dd2..ce6b8e7 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 @@ -37,6 +37,7 @@ public class Constants { 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 = "topology-event-listener"; + public static final String CONF_PROPERTY_TOPOLOGY_MEMBER_IP_TYPE = "topology-member-ip-type"; 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 = "cep-stats-publisher"; http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 05417b3..0429da4 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 @@ -26,6 +26,7 @@ import org.apache.http.protocol.HTTP; import org.apache.stratos.load.balancer.RequestDelegator; import org.apache.stratos.load.balancer.algorithm.LoadBalanceAlgorithmFactory; 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.statistics.LoadBalancerStatisticsCollector; import org.apache.stratos.load.balancer.util.Constants; @@ -230,7 +231,7 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints } int memberPort = transportPort.getValue(); - org.apache.axis2.clustering.Member axis2Member = new org.apache.axis2.clustering.Member(member.getMemberIp(), memberPort); + org.apache.axis2.clustering.Member axis2Member = new org.apache.axis2.clustering.Member(getMemberIp(synCtx, member), memberPort); axis2Member.setDomain(member.getClusterId()); Port httpPort = member.getPort("http"); if (httpPort != null) @@ -244,6 +245,35 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints return axis2Member; } + 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.getMemberPublicIp())) { + 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.getMemberPublicIp())); + } + return member.getMemberPublicIp(); + } + } + // Return member's private IP address + if(StringUtils.isBlank(member.getMemberIp())) { + 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.getMemberIp())); + } + return member.getMemberIp(); + } + private String extractUrl(MessageContext synCtx) { Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx; org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext(); http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 bdb3fc4..0d315de 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 @@ -51,6 +51,12 @@ loadbalancer { mb-ip: localhost; mb-port: 5677; + # Topology member ip address type + # Provide this configuration if topology-event-listener is set to true. If this property is set to 'private' + # load balancer will delegate requests to member's private IP address. If it is set to 'public' requests will + # be delegated to member's public IP address. + topology-member-ip-type: private; + # Topology service filter # Provide service names in a comma separated list to filter incoming topology events if # topology_event_listener_enabled is set to true. This functionality could be used for hosting http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 31649c5..37325d1 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 @@ -51,6 +51,12 @@ loadbalancer { mb-ip: localhost; mb-port: 5677; + # Topology member ip address type + # Provide this configuration if topology-event-listener is set to true. If this property is set to 'private' + # load balancer will delegate requests to member's private IP address. If it is set to 'public' requests will + # be delegated to member's public IP address. + topology-member-ip-type: private; + # Topology service filter # Provide service names in a comma separated list to filter incoming topology events if # topology_event_listener_enabled is set to true. This functionality could be used for hosting http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 a6270da..b5d915f 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 @@ -51,6 +51,12 @@ loadbalancer { mb-ip: localhost; mb-port: 5677; + # Topology member ip address type + # Provide this configuration if topology-event-listener is set to true. If this property is set to 'private' + # load balancer will delegate requests to member's private IP address. If it is set to 'public' requests will + # be delegated to member's public IP address. + topology-member-ip-type: public; + # Topology service filter # Provide service names in a comma separated list to filter incoming topology events if # topology_event_listener_enabled is set to true. This functionality could be used for hosting http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl ---------------------------------------------------------------------- diff --git a/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl b/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl index 994c950..81db461 100755 --- a/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl +++ b/products/autoscaler/modules/distribution/src/main/conf/mincheck.drl @@ -54,7 +54,7 @@ dialect "mvel" when $ctxt : PartitionContext () eval(log.debug("Running minimum rule: [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId())) - eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Non termnated member count: " + $ctxt.getNonTerminatedMemberCount())) + eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Non terminated member count: " + $ctxt.getNonTerminatedMemberCount())) eval(log.debug("[min-check] [network-partition] " + $ctxt.getNetworkPartitionId() + " [partition] " + $ctxt.getPartitionId() + " Minimum member count: " + $ctxt.getMinimumMemberCount())) eval($ctxt.getNonTerminatedMemberCount() < $ctxt.getMinimumMemberCount()) http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/f5d1a108/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 03a9634..7b0d511 100644 --- a/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf +++ b/products/load-balancer/modules/distribution/src/main/conf/loadbalancer.conf @@ -45,6 +45,12 @@ loadbalancer { mb-ip: localhost; mb-port: 5677; + # Topology member ip address type + # Provide this configuration if topology-event-listener is set to true. If this property is set to 'private' + # load balancer will delegate requests to member's private IP address. If it is set to 'public' requests will + # be delegated to member's public IP address. + topology-member-ip-type: private; + # Topology service filter # Provide service names in a comma separated list to filter incoming topology events if # topology_event_listener_enabled is set to true. This functionality could be used for hosting @@ -64,7 +70,7 @@ loadbalancer { # topology-member-filter: lb-cluster-id=lb-cluster-id1; # Enable/disable cep statistics publisher - cep-stats-publisher: true; + cep-stats-publisher: false; # Complex event processor endpoint # Provide CEP ip address and port if cep-stats-publisher is set to true.
