Hi Chamila, I couldn't apply our patches because there were some major refactoring, hence conflicts. I have re-done my changes and attached here. Can you also re-do the changes to python agent and send PR?
Once you send a PR, I can commit my changes and merge your changes. Thanks. On Sun, Dec 21, 2014 at 10:54 AM, Rajkumar Rajaratnam <rajkum...@wso2.com> wrote: > Hi, > > Please find the cartridge-agent patch implemented by Chamils for this > corresponding changes. > > Thanks. > > On Sat, Dec 13, 2014 at 9:37 PM, Rajkumar Rajaratnam <rajkum...@wso2.com> > wrote: > >> Hi, >> >> Did anyone get a chance to commit this changes? >> >> Thanks. >> >> On Fri, Dec 5, 2014 at 7:46 PM, Rajkumar Rajaratnam <rajkum...@wso2.com> >> wrote: >>> >>> Hi, >>> >>> I am attaching the patch for topology changes. >>> >>> @Chamila, >>> >>> Please do the changes in python agent accordingly. Basic idea is that >>> topology and topology events are carrying >>> >>> - list of private IPs >>> - list of public IPs >>> - a default public IP (for LB routing) >>> - a default private IP (for LB routing) >>> >>> Thanks. >>> >>> On Fri, Dec 5, 2014 at 10:59 AM, Reka Thirunavukkarasu <r...@wso2.com> >>> wrote: >>> >>>> HI Raj, >>>> >>>> On Fri, Dec 5, 2014 at 8:20 AM, Rajkumar Rajaratnam <rajkum...@wso2.com >>>> > wrote: >>>> >>>>> Okay. >>>>> >>>>> @Reka, Please let me know when are done with testing. >>>>> >>>> >>>> Sure..We are in the process of stabilising grouping feature in the >>>> master. Will update once we have the complete flow working fine.. >>>> >>>>> >>>>> I will make a diff in meantime. >>>>> >>>> >>>> +1. Anyway, you might need to rebase it when you apply it as we are >>>> also fixing bugs in the same code.. >>>> >>>> Thanks, >>>> Reka >>>> >>>>> >>>>> Thanks. >>>>> >>>>> On Fri, Dec 5, 2014 at 8:08 AM, Lakmal Warusawithana <lak...@wso2.com> >>>>> wrote: >>>>> >>>>>> Sure, shall we do this after complete full work flow test in grouping. >>>>>> >>>>>> On Fri, Dec 5, 2014 at 8:00 AM, Rajkumar Rajaratnam < >>>>>> rajkum...@wso2.com> wrote: >>>>>> >>>>>>> Hi, >>>>>>> >>>>>>> Please let me know the decision on this before code freeze. This is >>>>>>> a simple change to do. >>>>>>> >>>>>>> Thanks. >>>>>>> >>>>>>> On Fri, Dec 5, 2014 at 1:41 AM, Rajkumar Rajaratnam < >>>>>>> rajkum...@wso2.com> wrote: >>>>>>> >>>>>>>> Hi Devs, >>>>>>>> >>>>>>>> I have integrated multiple network interfaces support into the >>>>>>>> master branch and it is working fine. >>>>>>>> >>>>>>>> Now we should modify the topology to include list of private/public >>>>>>>> IP addresses. Currently topology and topology events supports max of >>>>>>>> one >>>>>>>> public IP and one private IP. >>>>>>>> >>>>>>>> Can I go ahead and do this change? >>>>>>>> >>>>>>>> Thanks. >>>>>>>> >>>>>>>> -- >>>>>>>> Rajkumar Rajaratnam >>>>>>>> Committer & PMC Member, Apache Stratos >>>>>>>> Software Engineer, WSO2 >>>>>>>> >>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> Rajkumar Rajaratnam >>>>>>> Committer & PMC Member, Apache Stratos >>>>>>> Software Engineer, WSO2 >>>>>>> >>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Lakmal Warusawithana >>>>>> Vice President, Apache Stratos >>>>>> Director - Cloud Architecture; WSO2 Inc. >>>>>> Mobile : +94714289692 >>>>>> Blog : http://lakmalsview.blogspot.com/ >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> Rajkumar Rajaratnam >>>>> Committer & PMC Member, Apache Stratos >>>>> Software Engineer, WSO2 >>>>> >>>> >>>> >>>> >>>> -- >>>> Reka Thirunavukkarasu >>>> Senior Software Engineer, >>>> WSO2, Inc.:http://wso2.com, >>>> Mobile: +94776442007 >>>> >>>> >>>> >>> >>> >>> -- >>> Rajkumar Rajaratnam >>> Committer & PMC Member, Apache Stratos >>> Software Engineer, WSO2 >>> >> >> >> -- >> Rajkumar Rajaratnam >> Committer & PMC Member, Apache Stratos >> Software Engineer, WSO2 >> > > > > -- > Rajkumar Rajaratnam > Committer & PMC Member, Apache Stratos > Software Engineer, WSO2 > > Mobile : +94777568639 > Blog : rajkumarr.com > -- Rajkumar Rajaratnam Committer & PMC Member, Apache Stratos Software Engineer, WSO2 Mobile : +94777568639 Blog : rajkumarr.com
diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/extensions/DefaultExtensionHandler.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/extensions/DefaultExtensionHandler.java index c7da75a..a069c5c 100644 --- a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/extensions/DefaultExtensionHandler.java +++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/extensions/DefaultExtensionHandler.java @@ -254,7 +254,7 @@ public class DefaultExtensionHandler implements ExtensionHandler { // check whether member activated event is received from the same cluster, lbcluster or service group if (ExtensionUtils.isRelevantMemberEvent(memberActivatedEvent.getServiceName(), memberActivatedEvent.getClusterId(), lbClusterId)) { Map<String, String> env = new HashMap<String, String>(); - env.put("STRATOS_MEMBER_ACTIVATED_MEMBER_IP", memberActivatedEvent.getMemberIp()); + env.put("STRATOS_MEMBER_ACTIVATED_MEMBER_IP", memberActivatedEvent.getDefaultPrivateIP()); env.put("STRATOS_MEMBER_ACTIVATED_MEMBER_ID", memberActivatedEvent.getMemberId()); env.put("STRATOS_MEMBER_ACTIVATED_CLUSTER_ID", memberActivatedEvent.getClusterId()); env.put("STRATOS_MEMBER_ACTIVATED_LB_CLUSTER_ID", lbClusterId); @@ -291,7 +291,7 @@ public class DefaultExtensionHandler implements ExtensionHandler { } boolean hasWKIpChanged = true; for (Member m : this.wkMembers) { - if (m.getMemberIp().equals(memberActivatedEvent.getMemberIp())) { + if (m.getDefaultPrivateIP().equals(memberActivatedEvent.getDefaultPrivateIP())) { hasWKIpChanged = false; } } @@ -422,7 +422,7 @@ public class DefaultExtensionHandler implements ExtensionHandler { Collection<Member> members = cluster.getMembers(); Map<String, String> env = new HashMap<String, String>(); - env.put("STRATOS_MEMBER_TERMINATED_MEMBER_IP", terminatedMember.getMemberIp()); + env.put("STRATOS_MEMBER_TERMINATED_MEMBER_IP", terminatedMember.getDefaultPrivateIP()); env.put("STRATOS_MEMBER_TERMINATED_MEMBER_ID", memberTerminatedEvent.getMemberId()); env.put("STRATOS_MEMBER_TERMINATED_CLUSTER_ID", memberTerminatedEvent.getClusterId()); env.put("STRATOS_MEMBER_TERMINATED_LB_CLUSTER_ID", lbClusterId); @@ -480,7 +480,7 @@ public class DefaultExtensionHandler implements ExtensionHandler { memberSuspendedEvent.getClusterId(), lbClusterId)) { Collection<Member> members = cluster.getMembers(); Map<String, String> env = new HashMap<String, String>(); - env.put("STRATOS_MEMBER_SUSPENDED_MEMBER_IP", suspendedMember.getMemberIp()); + env.put("STRATOS_MEMBER_SUSPENDED_MEMBER_IP", suspendedMember.getDefaultPrivateIP()); env.put("STRATOS_MEMBER_SUSPENDED_MEMBER_ID", memberSuspendedEvent.getMemberId()); env.put("STRATOS_MEMBER_SUSPENDED_CLUSTER_ID", memberSuspendedEvent.getClusterId()); env.put("STRATOS_MEMBER_SUSPENDED_LB_CLUSTER_ID", lbClusterId); @@ -536,7 +536,7 @@ public class DefaultExtensionHandler implements ExtensionHandler { memberStartedEvent.getClusterId(), lbClusterId)) { Collection<Member> members = cluster.getMembers(); Map<String, String> env = new HashMap<String, String>(); - env.put("STRATOS_MEMBER_STARTED_MEMBER_IP", startedMember.getMemberIp()); + env.put("STRATOS_MEMBER_STARTED_MEMBER_IP", startedMember.getDefaultPrivateIP()); env.put("STRATOS_MEMBER_STARTED_MEMBER_ID", memberStartedEvent.getMemberId()); env.put("STRATOS_MEMBER_STARTED_CLUSTER_ID", memberStartedEvent.getClusterId()); env.put("STRATOS_MEMBER_STARTED_LB_CLUSTER_ID", lbClusterId); @@ -594,9 +594,9 @@ public class DefaultExtensionHandler implements ExtensionHandler { return false; } Member apistoreMember = apistoreMemberList.get(0); - envParameters.put("STRATOS_WK_APISTORE_MEMBER_IP", apistoreMember.getMemberIp()); + envParameters.put("STRATOS_WK_APISTORE_MEMBER_IP", apistoreMember.getDefaultPrivateIP()); if (log.isDebugEnabled()) { - log.debug("STRATOS_WK_APISTORE_MEMBER_IP: " + apistoreMember.getMemberIp()); + log.debug("STRATOS_WK_APISTORE_MEMBER_IP: " + apistoreMember.getDefaultPrivateIP()); } List<Member> publisherMemberList = new ArrayList<Member>(); @@ -613,9 +613,9 @@ public class DefaultExtensionHandler implements ExtensionHandler { return false; } Member publisherMember = publisherMemberList.get(0); - envParameters.put("STRATOS_WK_PUBLISHER_MEMBER_IP", publisherMember.getMemberIp()); + envParameters.put("STRATOS_WK_PUBLISHER_MEMBER_IP", publisherMember.getDefaultPrivateIP()); if (log.isDebugEnabled()) { - log.debug("STRATOS_WK_PUBLISHER_MEMBER_IP: " + publisherMember.getMemberIp()); + log.debug("STRATOS_WK_PUBLISHER_MEMBER_IP: " + publisherMember.getDefaultPrivateIP()); } return true; @@ -668,16 +668,16 @@ public class DefaultExtensionHandler implements ExtensionHandler { wkMembers.add(member); this.wkMembers.add(member); if (log.isDebugEnabled()) { - log.debug("Found WKA: STRATOS_WK_MEMBER_IP: " + member.getMemberIp()); + log.debug("Found WKA: STRATOS_WK_MEMBER_IP: " + member.getDefaultPrivateIP()); } } } if (wkMembers.size() >= minCount) { int idx = 0; for (Member member : wkMembers) { - envParameters.put("STRATOS_WK_MEMBER_" + idx + "_IP", member.getMemberIp()); + envParameters.put("STRATOS_WK_MEMBER_" + idx + "_IP", member.getDefaultPrivateIP()); if (log.isDebugEnabled()) { - log.debug("STRATOS_WK_MEMBER_" + idx + "_IP: " + member.getMemberIp()); + log.debug("STRATOS_WK_MEMBER_" + idx + "_IP: " + member.getDefaultPrivateIP()); } idx++; } @@ -757,9 +757,9 @@ public class DefaultExtensionHandler implements ExtensionHandler { minManagerInstancesAvailable = true; int idx = 0; for (Member member : managerWkaMembers) { - envParameters.put("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP", member.getMemberIp()); + envParameters.put("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP", member.getDefaultPrivateIP()); if (log.isDebugEnabled()) { - log.debug("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP: " + member.getMemberIp()); + log.debug("STRATOS_WK_MANAGER_MEMBER_" + idx + "_IP: " + member.getDefaultPrivateIP()); } idx++; } @@ -833,9 +833,9 @@ public class DefaultExtensionHandler implements ExtensionHandler { minWorkerInstancesAvailable = true; int idx = 0; for (Member member : workerWkaMembers) { - envParameters.put("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP", member.getMemberIp()); + envParameters.put("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP", member.getDefaultPrivateIP()); if (log.isDebugEnabled()) { - log.debug("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP: " + member.getMemberIp()); + log.debug("STRATOS_WK_WORKER_MEMBER_" + idx + "_IP: " + member.getDefaultPrivateIP()); } idx++; } diff --git a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java index 994c589..79ac604 100644 --- a/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java +++ b/components/org.apache.stratos.cartridge.agent/src/main/java/org/apache/stratos/cartridge/agent/util/ExtensionUtils.java @@ -127,7 +127,7 @@ public class ExtensionUtils { Collection<Member> memberCollection = cluster.getMembers(); for (Member member : memberCollection) { if (member.getClusterId().equals(lbClusterId)) { - return new String[]{member.getMemberIp(), member.getMemberPublicIp()}; + return new String[]{member.getDefaultPrivateIP(), member.getDefaultPublicIP()}; } } } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java index 0201739..f4fc2f3 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/domain/MemberContext.java @@ -22,6 +22,7 @@ import org.apache.stratos.common.Properties; import org.apache.stratos.common.Property; import java.io.Serializable; +import java.util.Arrays; /** * Holds information about a Member. @@ -44,12 +45,16 @@ public class MemberContext implements Serializable { // Partition this member is in private Partition partition; - // Private ip address - private String privateIpAddress; - // Public ip address - private String publicIpAddress; - // Manually allocated ip - private String allocatedIpAddress; + // Default private ip address + private String defaultPrivateIP; + // Private ips + private String[] privateIPs; + // Default public ip address + private String defaultPublicIP; + // Public ips + private String[] publicIPs; + // Manually allocated ips + private String[] allocatedIPs; // Member initiated time private long initTime; // LB cluster id of this member @@ -113,28 +118,44 @@ public class MemberContext implements Serializable { this.partition = partition; } - public String getPublicIpAddress() { - return publicIpAddress; + public String getDefaultPublicIP() { + return defaultPublicIP; } - public void setPublicIpAddress(String publicIpAddress) { - this.publicIpAddress = publicIpAddress; + public void setDefaultPublicIP(String defaultPublicIP) { + this.defaultPublicIP = defaultPublicIP; + } + + public String[] getPublicIPs() { + return publicIPs; + } + + public void setPublicIPs(String[] publicIPs) { + this.publicIPs = publicIPs; } - public String getPrivateIpAddress() { - return privateIpAddress; + public String getDefaultPrivateIP() { + return defaultPrivateIP; + } + + public void setDefaultPrivateIP(String defaultPrivateIP) { + this.defaultPrivateIP = defaultPrivateIP; + } + + public String[] getPrivateIPs() { + return privateIPs; } - public void setPrivateIpAddress(String privateIpAddress) { - this.privateIpAddress = privateIpAddress; + public void setPrivateIPs(String[] privateIPs) { + this.privateIPs = privateIPs; } - public String getAllocatedIpAddress() { - return allocatedIpAddress; + public String[] getAllocatedIPs() { + return allocatedIPs; } - public void setAllocatedIpAddress(String allocatedIpAddress) { - this.allocatedIpAddress = allocatedIpAddress; + public void setAllocatedIPs(String[] allocatedIPs) { + this.allocatedIPs = allocatedIPs; } public long getInitTime() { @@ -252,9 +273,10 @@ public class MemberContext implements Serializable { public String toString() { return "MemberContext [memberId=" + memberId + ", instanceId=" + instanceId + ", clusterId=" + clusterId + ", partition=" + partition - + ", cartridgeType=" + cartridgeType + ", privateIpAddress=" + privateIpAddress - + ", publicIpAddress=" + publicIpAddress + ", allocatedIpAddress=" - + allocatedIpAddress + ", initTime=" + initTime + ", lbClusterId=" + lbClusterId + + ", cartridgeType=" + cartridgeType + ", defaultPrivateIP=" + defaultPrivateIP + + ", defaultPublicIP=" + defaultPublicIP + ", allocatedIPs=" + Arrays.toString(allocatedIPs) + + ", publicIPs=" + Arrays.toString(publicIPs) + ", privateIPs=" + Arrays.toString(privateIPs) + + ", initTime=" + initTime + ", lbClusterId=" + lbClusterId + ", networkPartitionId=" + networkPartitionId + ", instanceMetadata=" + instanceMetadata + ", properties=" + properties + "]"; } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java index c6e920d..a744eb1 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/functions/PodToMemberContext.java @@ -36,8 +36,10 @@ public class PodToMemberContext implements Function<Pod, MemberContext> { } MemberContext memberContext = new MemberContext(); memberContext.setMemberId(pod.getId()); - memberContext.setPrivateIpAddress(pod.getCurrentState().getHostIP()); - memberContext.setPublicIpAddress(pod.getCurrentState().getHostIP()); + memberContext.setDefaultPrivateIP(pod.getCurrentState().getHostIP()); + memberContext.setPrivateIPs(new String[]{pod.getCurrentState().getHostIP()}); + memberContext.setDefaultPublicIP(pod.getCurrentState().getHostIP()); + memberContext.setPublicIPs(new String[]{pod.getCurrentState().getHostIP()}); memberContext.setInitTime(System.currentTimeMillis()); return memberContext; diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsCloudStackIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsCloudStackIaas.java index bfe3af2..2cc1a96 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsCloudStackIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsCloudStackIaas.java @@ -27,8 +27,10 @@ import org.jclouds.compute.domain.TemplateBuilder; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.domain.Location; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeoutException; @@ -206,7 +208,7 @@ public class JcloudsCloudStackIaas extends JcloudsIaas { * So this method will find the IP that has been assigned to the vm and return it. */ @Override - public String associateAddress(NodeMetadata node) { + public List<String> associateAddresses(NodeMetadata node) { IaasProvider iaasInfo = getIaasProvider(); ComputeServiceContext context = iaasInfo.getComputeService().getContext(); @@ -240,7 +242,10 @@ public class JcloudsCloudStackIaas extends JcloudsIaas { throw new CloudControllerException(msg); } - return ip; + List<String> associatedIPs = new ArrayList<String>(); + associatedIPs.add(ip); + + return associatedIPs; } @Override diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsDockerIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsDockerIaas.java index 22feae0..dd7ec64 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsDockerIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsDockerIaas.java @@ -34,6 +34,7 @@ import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.Template; +import java.util.List; import java.util.Set; /** @@ -63,7 +64,7 @@ public class JcloudsDockerIaas extends JcloudsIaas { } @Override - public String associateAddress(NodeMetadata node) { + public List<String> associateAddresses(NodeMetadata node) { log.warn("Not implemented: DockerIaas.associateAddress()"); return null; } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsEC2Iaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsEC2Iaas.java index a66e656..23c62d0 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsEC2Iaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsEC2Iaas.java @@ -262,7 +262,7 @@ public class JcloudsEC2Iaas extends JcloudsIaas { } @Override - public synchronized String associateAddress(NodeMetadata node) { + public synchronized List<String> associateAddresses(NodeMetadata node) { IaasProvider iaasInfo = getIaasProvider(); @@ -328,7 +328,9 @@ public class JcloudsEC2Iaas extends JcloudsIaas { log.debug("Successfully associated an IP address " + ip + " for node with id: " + node.getId()); - return ip; + List<String> associatedIPs = new ArrayList<String>(); + associatedIPs.add(ip); + return associatedIPs; } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsGCEIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsGCEIaas.java index 969f65d..a4f3abb 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsGCEIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsGCEIaas.java @@ -214,10 +214,10 @@ public class JcloudsGCEIaas extends JcloudsIaas { } @Override - public String associateAddress(NodeMetadata node) { + public List<String> associateAddresses(NodeMetadata node) { // TODO - return ""; + return null; } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java index 653458a..6d1e7f3 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsIaas.java @@ -20,6 +20,7 @@ package org.apache.stratos.cloud.controller.iaases; import com.google.common.collect.ImmutableSet; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.stratos.cloud.controller.context.CloudControllerContext; @@ -36,6 +37,8 @@ import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.domain.Template; import org.jclouds.rest.ResourceNotFoundException; +import java.util.ArrayList; +import java.util.List; import java.util.Set; /** @@ -74,11 +77,11 @@ public abstract class JcloudsIaas extends Iaas { public abstract boolean createKeyPairFromPublicKey(String region, String keyPairName, String publicKey); /** - * This will obtain an IP address from the allocated list and associate that IP with this node. + * This will obtain an IP addresses from the allocated list and associate that IP with this node. * @param node Node to be associated with an IP. - * @return associated public IP. + * @return return list of associated public IPs. */ - public abstract String associateAddress(NodeMetadata node); + public abstract List<String> associateAddresses(NodeMetadata node); /** * This will obtain a predefined IP address and associate that IP with this node, if ip is already in use allocate ip from pool @@ -175,8 +178,7 @@ public abstract class JcloudsIaas extends Iaas { String autoAssignIpProp = getIaasProvider().getProperty(CloudControllerConstants.AUTO_ASSIGN_IP_PROPERTY); String preDefinedIp = getIaasProvider().getProperty(CloudControllerConstants.FLOATING_IP_PROPERTY); - String publicIp = ""; - String ip = ""; + List<String> associatedIPs = new ArrayList<String>(); // default behavior is autoIpAssign=false if ((autoAssignIpProp == null) || ((autoAssignIpProp != null) && autoAssignIpProp.equals("false"))) { @@ -187,7 +189,7 @@ public abstract class JcloudsIaas extends Iaas { if (log.isDebugEnabled()) { log.debug("CloudControllerServiceImpl:IpAllocator:preDefinedIp: invoking associatePredefinedAddress" + preDefinedIp); } - ip = associatePredefinedAddress(nodeMetadata, preDefinedIp); + String ip = associatePredefinedAddress(nodeMetadata, preDefinedIp); if (ip == null || "".equals(ip) || !preDefinedIp.equals(ip)) { // throw exception and stop instance creation @@ -199,6 +201,7 @@ public abstract class JcloudsIaas extends Iaas { destroyNode(nodeMetadata.getId(), memberContext); throw new CloudControllerException(msg); } + associatedIPs.add(ip); } else { String msg = "Invalid floating ip address configured: " + preDefinedIp + " - terminating node:" + memberContext.toString(); @@ -213,59 +216,52 @@ public abstract class JcloudsIaas extends Iaas { log.debug("CloudControllerServiceImpl:IpAllocator:no (valid) predefined floating ip configured, " + "selecting available one from pool"); } - // allocate an IP address - manual IP assigning mode - ip = associateAddress(nodeMetadata); - - if (ip != null) { - memberContext.setAllocatedIpAddress(ip); - if (log.isDebugEnabled()) { - log.debug("Allocated an ip address: " - + memberContext.toString()); - } else if (log.isInfoEnabled()) { - log.info("Allocated ip address [ " + memberContext.getAllocatedIpAddress() + - " ] to member with id: " + memberContext.getMemberId()); - } + + // allocate IP addresses - manual IP assigning mode from stratos point of view + associatedIPs = associateAddresses(nodeMetadata); + + // checking for null and empty is enough. If there are elements in this list, they are valid IPs + // because we are validating before putting into the list + if (associatedIPs == null || associatedIPs.isEmpty()) { + // throw exception and stop instance creation + String msg = "Error occurred while allocating floating ip addresses. Terminating node : " + memberContext.toString(); + log.error(msg); + // terminate instance + destroyNode(nodeMetadata.getId(), memberContext); + throw new CloudControllerException(msg); } } - - if (ip == null) { - String msg = "No IP address found. IP allocation failed for " + memberContext; - log.error(msg); - throw new CloudControllerException(msg); - } + + memberContext.setAllocatedIPs(associatedIPs.toArray(new String[associatedIPs.size()])); + log.info("Allocated IP addresses : "+ memberContext.toString()); // build the node with the new ip nodeMetadata = NodeMetadataBuilder.fromNodeMetadata(nodeMetadata) - .publicAddresses(ImmutableSet.of(ip)).build(); + .publicAddresses(associatedIPs).build(); } - // public ip - if (nodeMetadata.getPublicAddresses() != null && - nodeMetadata.getPublicAddresses().iterator().hasNext()) { - ip = nodeMetadata.getPublicAddresses().iterator().next(); - publicIp = ip; - memberContext.setPublicIpAddress(ip); - if (log.isDebugEnabled()) { - log.debug("Retrieving Public IP Address : " + memberContext.toString()); - } else if (log.isInfoEnabled()) { - log.info("Retrieving Public IP Address: " + memberContext.getPublicIpAddress() + - ", member id: " + memberContext.getMemberId()); - } + // public IPs + Set<String> publicIPAddresses = nodeMetadata.getPublicAddresses(); + if (publicIPAddresses != null && !publicIPAddresses.isEmpty()) { + memberContext.setPublicIPs(publicIPAddresses.toArray(new String[publicIPAddresses.size()])); + //TODO set a flag in cartridge definition to specify the default public IP or the interface + memberContext.setDefaultPublicIP(publicIPAddresses.iterator().next()); + log.info("Retrieving Public IP Addresses : " + memberContext.toString()); + } else { + memberContext.setPublicIPs(new String[0]); } - // private IP - if (nodeMetadata.getPrivateAddresses() != null && - nodeMetadata.getPrivateAddresses().iterator().hasNext()) { - ip = nodeMetadata.getPrivateAddresses().iterator().next(); - memberContext.setPrivateIpAddress(ip); - if (log.isDebugEnabled()) { - log.debug("Retrieving Private IP Address. " + memberContext.toString()); - } else if (log.isInfoEnabled()) { - log.info("Retrieving Private IP Address: " + memberContext.getPrivateIpAddress() + - ", member id: " + memberContext.getMemberId()); - } - } + // private IPs + Set<String> privateIPAddresses = nodeMetadata.getPrivateAddresses(); + if (privateIPAddresses != null && !privateIPAddresses.isEmpty()) { + memberContext.setPrivateIPs(privateIPAddresses.toArray(new String[privateIPAddresses.size()])); + //TODO set a flag in cartridge definition to specify the default private IP or the interface + memberContext.setDefaultPrivateIP(privateIPAddresses.iterator().next()); + log.info("Retrieving Private IP Addresses " + memberContext.toString()); + } else { + memberContext.setPrivateIPs(new String[0]); + } CloudControllerContext.getInstance().updateMemberContext(memberContext); @@ -332,9 +328,11 @@ public abstract class JcloudsIaas extends Iaas { // Destroy the node via jclouds getIaasProvider().getComputeService().destroyNode(nodeId); - // release allocated IP address - if (memberContext.getAllocatedIpAddress() != null) { - releaseAddress(memberContext.getAllocatedIpAddress()); + // releasing all allocated IPs + if (memberContext.getAllocatedIPs() != null) { + for (String allocatedIP : memberContext.getAllocatedIPs()) { + releaseAddress(allocatedIP); + } } if (log.isInfoEnabled()) { diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsOpenstackIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsOpenstackIaas.java index e16a074..d3386f2 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsOpenstackIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsOpenstackIaas.java @@ -19,6 +19,7 @@ package org.apache.stratos.cloud.controller.iaases; import java.util.LinkedHashSet; +import java.util.List; import java.util.Set; import java.util.concurrent.TimeoutException; @@ -223,9 +224,9 @@ public class JcloudsOpenstackIaas extends JcloudsIaas { } @Override - public synchronized String associateAddress(NodeMetadata node) { + public synchronized List<String> associateAddresses(NodeMetadata node) { //TODO return the list of IP addresses once the topology changes is done - return openstackNetworkingApi.associateAddresses(node).iterator().next(); + return openstackNetworkingApi.associateAddresses(node); } @Override diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsVCloudIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsVCloudIaas.java index 9f87dd4..d45e114 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsVCloudIaas.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/JcloudsVCloudIaas.java @@ -38,6 +38,7 @@ import org.wso2.carbon.utils.CarbonUtils; import java.io.File; import java.io.IOException; +import java.util.List; public class JcloudsVCloudIaas extends JcloudsIaas { @@ -189,10 +190,10 @@ public class JcloudsVCloudIaas extends JcloudsIaas { } @Override - public String associateAddress(NodeMetadata node) { + public List<String> associateAddresses(NodeMetadata node) { // TODO - return ""; + return null; } diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java index 354484b..6fcd52f 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/mock/MockIaasService.java @@ -154,8 +154,8 @@ public class MockIaasService { public void allocateIpAddress(String clusterId, MemberContext memberContext, Partition partition) { // Allocate mock ip addresses - memberContext.setPrivateIpAddress(MockIPAddressPool.getInstance().getNextPrivateIpAddress()); - memberContext.setPublicIpAddress(MockIPAddressPool.getInstance().getNextPublicIpAddress()); + memberContext.setDefaultPrivateIP(MockIPAddressPool.getInstance().getNextPrivateIpAddress()); + memberContext.setDefaultPublicIP(MockIPAddressPool.getInstance().getNextPublicIpAddress()); } public void releaseAddress(String ip) { diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/StatisticsDataPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/StatisticsDataPublisher.java index 0539e23..c2d51a2 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/StatisticsDataPublisher.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/StatisticsDataPublisher.java @@ -40,6 +40,7 @@ import org.wso2.carbon.databridge.commons.StreamDefinition; import org.wso2.carbon.utils.CarbonUtils; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -120,9 +121,9 @@ public class StatisticsDataPublisher { payload.add(""); } - payload.add(handleNull(memberContext.getPrivateIpAddress())); - payload.add(handleNull(memberContext.getPublicIpAddress())); - payload.add(handleNull(memberContext.getAllocatedIpAddress())); + payload.add(handleNull(Arrays.toString(memberContext.getPrivateIPs()))); + payload.add(handleNull(Arrays.toString(memberContext.getPublicIPs()))); + payload.add(handleNull(Arrays.toString(memberContext.getAllocatedIPs()))); Event event = new Event(); event.setPayloadData(payload.toArray()); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java index 9dced60..c8b0bbb 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/publisher/TopologyEventPublisher.java @@ -38,6 +38,7 @@ import org.apache.stratos.messaging.event.instance.status.InstanceStartedEvent; import org.apache.stratos.messaging.event.topology.*; import org.apache.stratos.messaging.util.Util; +import java.util.Arrays; import java.util.List; import java.util.Properties; import java.util.Set; @@ -145,8 +146,14 @@ public class TopologyEventPublisher { memberContext.getNetworkPartitionId(), memberContext.getPartition().getId(), memberContext.getInitTime()); instanceSpawnedEvent.setLbClusterId(memberContext.getLbClusterId()); - instanceSpawnedEvent.setMemberIp(memberContext.getPrivateIpAddress()); - instanceSpawnedEvent.setMemberPublicIp(memberContext.getPublicIpAddress()); + instanceSpawnedEvent.setDefaultPrivateIP(memberContext.getDefaultPrivateIP()); + if (memberContext.getPrivateIPs() != null) { + instanceSpawnedEvent.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs())); + } + instanceSpawnedEvent.setDefaultPublicIP(memberContext.getDefaultPublicIP()); + if (memberContext.getPublicIPs() != null) { + instanceSpawnedEvent.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); + } instanceSpawnedEvent.setProperties(CloudControllerUtil .toJavaUtilProperties(memberContext.getProperties())); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java index 26c3d4a..6220f24 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/messaging/topology/TopologyBuilder.java @@ -418,9 +418,15 @@ public class TopologyBuilder { Member member = new Member(service.getServiceName(), clusterId, memberId, instanceId, clusterInstanceId, networkPartitionId, partitionId, initTime); member.setStatus(MemberStatus.Created); - member.setMemberIp(memberContext.getPrivateIpAddress()); + member.setDefaultPrivateIP(memberContext.getDefaultPrivateIP()); + if (memberContext.getPrivateIPs() != null) { + member.setMemberPrivateIPs(Arrays.asList(memberContext.getPrivateIPs())); + } member.setLbClusterId(lbClusterId); - member.setMemberPublicIp(memberContext.getPublicIpAddress()); + member.setDefaultPublicIP(memberContext.getDefaultPublicIP()); + if (memberContext.getPublicIPs() != null) { + member.setMemberPublicIPs(Arrays.asList(memberContext.getPublicIPs())); + } member.setProperties(CloudControllerUtil.toJavaUtilProperties(memberContext.getProperties())); try { @@ -581,8 +587,10 @@ public class TopologyBuilder { memberActivatedEvent.addPort(port); } - memberActivatedEvent.setMemberIp(member.getMemberIp()); - memberActivatedEvent.setMemberPublicIp(member.getMemberPublicIp()); + memberActivatedEvent.setDefaultPrivateIP(member.getDefaultPrivateIP()); + memberActivatedEvent.setMemberPrivateIPs(member.getMemberPrivateIPs()); + memberActivatedEvent.setDefaultPublicIP(member.getDefaultPublicIP()); + memberActivatedEvent.setMemberPublicIPs(member.getMemberPublicIPs()); TopologyManager.updateTopology(topology); TopologyEventPublisher.sendMemberActivatedEvent(memberActivatedEvent); diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java index 465f0e8..6d27be3 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java @@ -55,10 +55,12 @@ public class PodActivationWatcher implements Runnable { if (log.isDebugEnabled()) { log.debug("Pod activation watcher running: [status] " + pod.getCurrentState().getStatus()); } - if (POD_STATE_RUNNING.equals(pod.getCurrentState().getStatus()) && memberContext.getPublicIpAddress() == null) { + if (POD_STATE_RUNNING.equals(pod.getCurrentState().getStatus()) && memberContext.getPublicIPs() == null) { String hostIP = pod.getCurrentState().getHost(); - memberContext.setPublicIpAddress(hostIP); - memberContext.setPrivateIpAddress(hostIP); + memberContext.setDefaultPublicIP(hostIP); + memberContext.setDefaultPrivateIP(hostIP); + memberContext.setPublicIPs(new String[]{hostIP}); + memberContext.setPrivateIPs(new String[]{hostIP}); cloudControllerContext.addMemberContext(memberContext); // trigger topology diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/topology/Member.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/topology/Member.java index 98f3052..fcad561 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/topology/Member.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/beans/topology/Member.java @@ -33,9 +33,11 @@ public class Member { private String partitionId; private String memberId; private String status; - private String memberIp; + private String defaultPrivateIP; + private List<String> memberPrivateIPs; private String lbClusterId; - private String memberPublicIp; + private String defaultPublicIP; + private List<String> memberPublicIPs; private List<PropertyBean> property; public String getServiceName() { @@ -77,8 +79,24 @@ public class Member { public void setMemberId(String memberId) { this.memberId = memberId; } + + public List<String> getMemberPrivateIPs() { + return memberPrivateIPs; + } - public String getStatus() { + public void setMemberPrivateIPs(List<String> memberPrivateIPs) { + this.memberPrivateIPs = memberPrivateIPs; + } + + public List<String> getMemberPublicIPs() { + return memberPublicIPs; + } + + public void setMemberPublicIPs(List<String> memberPublicIPs) { + this.memberPublicIPs = memberPublicIPs; + } + + public String getStatus() { return status; } @@ -86,12 +104,12 @@ public class Member { this.status = status; } - public String getMemberIp() { - return memberIp; + public String getDefaultPrivateIP() { + return defaultPrivateIP; } - public void setMemberIp(String memberIp) { - this.memberIp = memberIp; + public void setDefaultPrivateIP(String defaultPrivateIP) { + this.defaultPrivateIP = defaultPrivateIP; } public String getLbClusterId() { @@ -102,12 +120,12 @@ public class Member { this.lbClusterId = lbClusterId; } - public String getMemberPublicIp() { - return memberPublicIp; + public String getDefaultPublicIP() { + return defaultPublicIP; } - public void setMemberPublicIp(String memberPublicIp) { - this.memberPublicIp = memberPublicIp; + public void setDefaultPublicIP(String defaultPublicIP) { + this.defaultPublicIP = defaultPublicIP; } public List<PropertyBean> getProperty() { @@ -144,8 +162,10 @@ public class Member { + ", networkPartitionId=" + getNetworkPartitionId() + ", partitionId=" + getPartitionId() + ", status=" + getStatus() - + ", memberIp=" + getMemberIp() - + ", memberPublicIp=" + getMemberPublicIp() + + ", defaultPrivateIP=" + getDefaultPrivateIP() + + ", memberPrivateIPs=" + memberPrivateIPs.toString() + + ", defaultPublicIP=" + getDefaultPublicIP() + + ", memberPublicIPs=" + memberPublicIPs.toString() + ", lbClusterId=" + getLbClusterId() + ", property=" + getProperty() + "]"; } 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 9859864..bf68815 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 @@ -477,8 +477,10 @@ public class LoadBalancerConfiguration { memberId, "1", Constants.STATIC_NETWORK_PARTITION, Constants.STATIC_PARTITION, initTime); String ip = memberNode.getProperty(Constants.CONF_PROPERTY_IP); validateRequiredPropertyInNode(Constants.CONF_PROPERTY_IP, ip, String.format("member %s", memberId)); - - member.setMemberIp(ip); + List<String> memberPrivateIPs = new ArrayList<String>(); + memberPrivateIPs.add(ip); + member.setMemberPrivateIPs(memberPrivateIPs); + member.setDefaultPrivateIP(ip); Node portsNode = memberNode.findChildNodeByName(Constants.CONF_ELEMENT_PORTS); validateRequiredNode(portsNode, Constants.CONF_ELEMENT_PORTS, String.format("member %s", memberId)); 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 83002c9..ec25537 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 @@ -412,29 +412,29 @@ public class TenantAwareLoadBalanceEndpoint extends org.apache.synapse.endpoints if (LoadBalancerConfiguration.getInstance().isTopologyEventListenerEnabled()) { if (LoadBalancerConfiguration.getInstance().getTopologyMemberIpType() == MemberIpType.Public) { // Return member's public IP address - if (StringUtils.isBlank(member.getMemberPublicIp())) { + 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.getMemberPublicIp())); + log.debug(String.format("Using member public IP address: [member] %s [ip] %s", member.getMemberId(), member.getDefaultPublicIP())); } - return member.getMemberPublicIp(); + return member.getDefaultPublicIP(); } } // Return member's private IP address - if (StringUtils.isBlank(member.getMemberIp())) { + 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.getMemberIp())); + log.debug(String.format("Using member IP address: [member] %s [ip] %s", member.getMemberId(), member.getDefaultPrivateIP())); } - return member.getMemberIp(); + return member.getDefaultPrivateIP(); } /** diff --git a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/LoadBalancerTopologyEventReceiver.java b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/LoadBalancerTopologyEventReceiver.java index 657d18e..843e53e 100644 --- a/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/LoadBalancerTopologyEventReceiver.java +++ b/components/org.apache.stratos.load.balancer/src/main/java/org/apache/stratos/load/balancer/messaging/LoadBalancerTopologyEventReceiver.java @@ -364,39 +364,39 @@ public class LoadBalancerTopologyEventReceiver { } } - if (StringUtils.isNotBlank(member.getMemberIp())) { - LoadBalancerContext.getInstance().getMemberIpHostnameMap().put(member.getMemberIp(), hostname); + if (StringUtils.isNotBlank(member.getDefaultPrivateIP())) { + LoadBalancerContext.getInstance().getMemberIpHostnameMap().put(member.getDefaultPrivateIP(), hostname); if (log.isDebugEnabled()) { log.debug(String.format("Member private ip added to member-ip -> hostname map: [service] %s [cluster] " + "%s [member] %s [private-ip] %s", member.getServiceName(), member.getClusterId(), - member.getMemberId(), member.getMemberIp() + member.getMemberId(), member.getDefaultPrivateIP() )); } } - if (StringUtils.isNotBlank(member.getMemberPublicIp())) { - LoadBalancerContext.getInstance().getMemberIpHostnameMap().put(member.getMemberPublicIp(), hostname); + if (StringUtils.isNotBlank(member.getDefaultPublicIP())) { + LoadBalancerContext.getInstance().getMemberIpHostnameMap().put(member.getDefaultPublicIP(), hostname); if (log.isDebugEnabled()) { log.debug(String.format("Member public ip added to member-ip -> hostname map: [service] %s [cluster] " + "%s [member] %s [public-ip] %s", member.getServiceName(), member.getClusterId(), - member.getMemberId(), member.getMemberPublicIp() + member.getMemberId(), member.getDefaultPublicIP() )); } } } private void removeMemberIpsFromMemberIpHostnameMap(Member member) { - if (StringUtils.isNotBlank(member.getMemberIp())) { - LoadBalancerContext.getInstance().getMemberIpHostnameMap().remove(member.getMemberIp()); + if (StringUtils.isNotBlank(member.getDefaultPrivateIP())) { + LoadBalancerContext.getInstance().getMemberIpHostnameMap().remove(member.getDefaultPrivateIP()); if (log.isDebugEnabled()) { log.debug(String.format("Member private ip removed from member-ip -> hostname map: [private-ip] %s", - member.getMemberIp())); + member.getDefaultPrivateIP())); } } - if (StringUtils.isNotBlank(member.getMemberPublicIp())) { - LoadBalancerContext.getInstance().getMemberIpHostnameMap().remove(member.getMemberPublicIp()); + if (StringUtils.isNotBlank(member.getDefaultPublicIP())) { + LoadBalancerContext.getInstance().getMemberIpHostnameMap().remove(member.getDefaultPublicIP()); if (log.isDebugEnabled()) { log.debug(String.format("Member public ip removed from member-ip -> hostname map: [public-ip] %s", - member.getMemberPublicIp())); + member.getDefaultPublicIP())); } } } 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 a3c834d..0848a73 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 @@ -126,7 +126,7 @@ public class LoadBalancerConfigurationTest { String memberId = "m1"; Member m1 = cluster1.getMember(memberId); Assert.assertNotNull(String.format("%s, member not found: [member] %s", validationError, memberId), m1); - Assert.assertEquals(String.format("%s, member ip not valid", validationError), "10.0.0.10", m1.getMemberIp()); + Assert.assertEquals(String.format("%s, member ip not valid", validationError), "10.0.0.10", m1.getDefaultPrivateIP()); int proxyPort = 80; Port m1Http = m1.getPort(proxyPort); diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java index 032c19f..4b6f095 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/domain/topology/Member.java @@ -48,9 +48,11 @@ public class Member implements Serializable, LifeCycleStateTransitionBehavior<Me // Key: Port.proxy @XmlJavaTypeAdapter(MapAdapter.class) private final Map<Integer, Port> portMap; - private String memberPublicIp; + private List<String> memberPublicIPs; + private String defaultPublicIP; //private MemberStatus status; - private String memberIp; + private List<String> memberPrivateIPs; + private String defaultPrivateIP; @XmlJavaTypeAdapter(MapAdapter.class) private Properties properties; private String lbClusterId; @@ -148,12 +150,20 @@ public class Member implements Serializable, LifeCycleStateTransitionBehavior<Me this.properties = properties; } - public String getMemberIp() { - return memberIp; + public String getDefaultPrivateIP() { + return defaultPrivateIP; } - public void setMemberIp(String memberIp) { - this.memberIp = memberIp; + public void setDefaultPrivateIP(String defaultPrivateIP) { + this.defaultPrivateIP = defaultPrivateIP; + } + + public List<String> getMemberPrivateIPs() { + return memberPrivateIPs; + } + + public void setMemberPrivateIPs(List<String> memberPrivateIPs) { + this.memberPrivateIPs = memberPrivateIPs; } public String getPartitionId() { @@ -172,12 +182,20 @@ public class Member implements Serializable, LifeCycleStateTransitionBehavior<Me return networkPartitionId; } - public String getMemberPublicIp() { - return memberPublicIp; + public String getDefaultPublicIP() { + return defaultPublicIP; } - public void setMemberPublicIp(String memberPublicIp) { - this.memberPublicIp = memberPublicIp; + public void setDefaultPublicIP(String defaultPublicIP) { + this.defaultPublicIP = defaultPublicIP; + } + + public List<String> getMemberPublicIPs() { + return memberPublicIPs; + } + + public void setMemberPublicIPs(List<String> memberPublicIPs) { + this.memberPublicIPs = memberPublicIPs; } public String getInstanceId() { @@ -199,9 +217,11 @@ public class Member implements Serializable, LifeCycleStateTransitionBehavior<Me + ", partitionId=" + getPartitionId() + ", initTime=" + getInitTime() + ", portMap=" + getPorts() - + ", memberPublicIp=" + getMemberPublicIp() + + ", defaultPublicIP=" + getDefaultPublicIP() + + ", memberPublicIPs=" + memberPublicIPs.toString() + ", status=" + getStatus() - + ", memberIp=" + getMemberIp() + + ", defaultPrivateIP=" + getDefaultPrivateIP() + + ", memberPrivateIPs=" + memberPrivateIPs.toString() + ", lbClusterId=" + getLbClusterId() + ", properties=" + getProperties() + "]"; } diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/InstanceSpawnedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/InstanceSpawnedEvent.java index 36b4acb..05d30ff 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/InstanceSpawnedEvent.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/InstanceSpawnedEvent.java @@ -20,6 +20,7 @@ package org.apache.stratos.messaging.event.topology; import java.io.Serializable; +import java.util.List; import java.util.Properties; @@ -39,8 +40,10 @@ public class InstanceSpawnedEvent extends TopologyEvent implements Serializable private final long initTime; private String lbClusterId; - private String memberPublicIp; - private String memberIp; + private List<String> memberPublicIPs; + private String defaultPublicIP; + private List<String> memberPrivateIPs; + private String defaultPrivateIP; private Properties properties; @@ -92,20 +95,36 @@ public class InstanceSpawnedEvent extends TopologyEvent implements Serializable this.lbClusterId = lbClusterId; } - public String getMemberPublicIp() { - return memberPublicIp; + public String getDefaultPublicIP() { + return defaultPublicIP; } - public void setMemberPublicIp(String memberPublicIp) { - this.memberPublicIp = memberPublicIp; + public void setDefaultPublicIP(String defaultPublicIP) { + this.defaultPublicIP = defaultPublicIP; + } + + public List<String> getMemberPublicIPs() { + return memberPublicIPs; + } + + public void setMemberPublicIPs(List<String> memberPublicIPs) { + this.memberPublicIPs = memberPublicIPs; } - public String getMemberIp() { - return memberIp; + public String getDefaultPrivateIP() { + return defaultPrivateIP; } - public void setMemberIp(String memberIp) { - this.memberIp = memberIp; + public void setDefaultPrivateIP(String defaultPrivateIP) { + this.defaultPrivateIP = defaultPrivateIP; + } + + public List<String> getMemberPrivateIPs() { + return memberPrivateIPs; + } + + public void setMemberPrivateIPs(List<String> memberPrivateIPs) { + this.memberPrivateIPs = memberPrivateIPs; } public Properties getProperties() { diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberActivatedEvent.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberActivatedEvent.java index c00b2bc..3c22780 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberActivatedEvent.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/event/topology/MemberActivatedEvent.java @@ -44,10 +44,12 @@ public class MemberActivatedEvent extends TopologyEvent implements Serializable // Key: Port.proxy private Map<Integer, Port> portMap; - private String memberIp; + private List<String> memberPrivateIPs; + private String defaultPrivateIP; private String groupId; private String applicationId; - private String memberPublicIp; + private List<String> memberPublicIPs; + private String defaultPublicIP; public MemberActivatedEvent(String serviceName, String clusterId, String clusterInstanceId, String memberId, String instanceId, String networkPartitionId, String partitionId) { @@ -109,13 +111,21 @@ public class MemberActivatedEvent extends TopologyEvent implements Serializable public boolean portExists(Port port) { return this.portMap.containsKey(port.getProxy()); } + + public List<String> getMemberPrivateIPs() { + return memberPrivateIPs; + } + + public void setMemberPrivateIPs(List<String> memberPrivateIPs) { + this.memberPrivateIPs = memberPrivateIPs; + } - public String getMemberIp() { - return memberIp; + public String getDefaultPrivateIP() { + return defaultPrivateIP; } - public void setMemberIp(String memberIp) { - this.memberIp = memberIp; + public void setDefaultPrivateIP(String defaultPrivateIP) { + this.defaultPrivateIP = defaultPrivateIP; } public String getGroupId() { @@ -133,13 +143,21 @@ public class MemberActivatedEvent extends TopologyEvent implements Serializable public void setApplicationId(String applicationId) { this.applicationId = applicationId; } + + public List<String> getMemberPublicIPs() { + return memberPublicIPs; + } + + public void setMemberPublicIPs(List<String> memberPublicIp) { + this.memberPublicIPs = memberPublicIp; + } - public String getMemberPublicIp() { - return memberPublicIp; + public String getDefaultPublicIP() { + return defaultPublicIP; } - public void setMemberPublicIp(String memberPublicIp) { - this.memberPublicIp = memberPublicIp; + public void setDefaultPublicIP(String defaultPublicIP) { + this.defaultPublicIP = defaultPublicIP; } public String getInstanceId() { diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/InstanceSpawnedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/InstanceSpawnedMessageProcessor.java index d38b993..f3fca4c 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/InstanceSpawnedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/InstanceSpawnedMessageProcessor.java @@ -133,8 +133,10 @@ public class InstanceSpawnedMessageProcessor extends MessageProcessor { Member member = new Member(event.getServiceName(), event.getClusterId(), event.getMemberId(), event.getInstanceId(), event.getClusterInstanceId(), event.getNetworkPartitionId(), event.getPartitionId(), event.getInitTime()); - member.setMemberPublicIp(event.getMemberPublicIp()); - member.setMemberIp(event.getMemberIp()); + member.setDefaultPublicIP(event.getDefaultPublicIP()); + member.setMemberPublicIPs(event.getMemberPublicIPs()); + member.setDefaultPrivateIP(event.getDefaultPrivateIP()); + member.setMemberPrivateIPs(event.getMemberPrivateIPs()); member.setLbClusterId(event.getLbClusterId()); member.setProperties(event.getProperties()); cluster.addMember(member); diff --git a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberActivatedMessageProcessor.java b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberActivatedMessageProcessor.java index 36ab6d0..b66bbea 100644 --- a/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberActivatedMessageProcessor.java +++ b/components/org.apache.stratos.messaging/src/main/java/org/apache/stratos/messaging/message/processor/topology/MemberActivatedMessageProcessor.java @@ -98,7 +98,7 @@ public class MemberActivatedMessageProcessor extends MessageProcessor { } // Validate event properties - if ((event.getMemberIp() == null) || event.getMemberIp().isEmpty()) { + if ((event.getDefaultPrivateIP() == null) || event.getDefaultPrivateIP().isEmpty()) { throw new RuntimeException(String.format("No ip address found in member activated event: [service] %s [cluster] %s [member] %s", event.getServiceName(), event.getClusterId(), @@ -159,7 +159,8 @@ public class MemberActivatedMessageProcessor extends MessageProcessor { // Apply changes to the topology member.addPorts(event.getPorts()); - member.setMemberIp(event.getMemberIp()); + member.setDefaultPrivateIP(event.getDefaultPrivateIP()); + member.setMemberPrivateIPs(event.getMemberPrivateIPs()); if (!member.isStateTransitionValid(MemberStatus.Activated)) { log.error("Invalid State Transition from " + member.getStatus() + " to " + MemberStatus.Activated); } diff --git a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java index 7153232..581f033 100644 --- a/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java +++ b/components/org.apache.stratos.rest.endpoint/src/main/java/org/apache/stratos/rest/endpoint/util/converter/ObjectConverter.java @@ -627,16 +627,18 @@ public class ObjectConverter { memberBean.setLbClusterId(member.getLbClusterId()); memberBean.setNetworkPartitionId(member.getNetworkPartitionId()); memberBean.setPartitionId(member.getPartitionId()); - if (member.getMemberIp() == null) { - memberBean.setMemberIp("NULL"); + if (member.getDefaultPrivateIP() == null) { + memberBean.setDefaultPrivateIP("NULL"); } else { - memberBean.setMemberIp(member.getMemberIp()); + memberBean.setDefaultPrivateIP(member.getDefaultPrivateIP()); } - if (member.getMemberPublicIp() == null) { - memberBean.setMemberPublicIp("NULL"); + if (member.getDefaultPublicIP() == null) { + memberBean.setDefaultPublicIP("NULL"); } else { - memberBean.setMemberPublicIp(member.getMemberPublicIp()); + memberBean.setDefaultPublicIP(member.getDefaultPublicIP()); } + memberBean.setMemberPrivateIPs(member.getMemberPrivateIPs()); + memberBean.setMemberPublicIPs(member.getMemberPublicIPs()); memberBean.setStatus(member.getStatus().toString()); memberBean.setProperty(convertJavaUtilPropertiesToPropertyBeans(member.getProperties())); clusterBean.getMember().add(memberBean); @@ -672,16 +674,18 @@ public class ObjectConverter { memberBean.setNetworkPartitionId(member.getNetworkPartitionId()); memberBean.setPartitionId(member.getPartitionId()); memberBean.setMemberId(member.getMemberId()); - if (member.getMemberIp() == null) { - memberBean.setMemberIp("NULL"); + if (member.getDefaultPrivateIP() == null) { + memberBean.setDefaultPrivateIP("NULL"); } else { - memberBean.setMemberIp(member.getMemberIp()); + memberBean.setDefaultPrivateIP(member.getDefaultPrivateIP()); } - if (member.getMemberPublicIp() == null) { - memberBean.setMemberPublicIp("NULL"); + if (member.getDefaultPublicIP() == null) { + memberBean.setDefaultPublicIP("NULL"); } else { - memberBean.setMemberPublicIp(member.getMemberPublicIp()); + memberBean.setDefaultPublicIP(member.getDefaultPublicIP()); } + memberBean.setMemberPrivateIPs(member.getMemberPrivateIPs()); + memberBean.setMemberPublicIPs(member.getMemberPublicIPs()); memberBean.setServiceName(member.getServiceName()); memberBean.setStatus(member.getStatus().toString()); memberBean.setProperty(convertJavaUtilPropertiesToPropertyBeans(member.getProperties())); diff --git a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java index f7349d9..45feb6a 100644 --- a/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java +++ b/extensions/load-balancer/haproxy-extension/src/main/java/org/apache/stratos/haproxy/extension/HAProxyConfigWriter.java @@ -179,7 +179,7 @@ public class HAProxyConfigWriter { for (Member member : cluster.getMembers()) { if (member.getNetworkPartitionId().equals(HAProxyContext.getInstance().getNetworkPartitionId())) { backEndHttp.append("\tserver ").append(member.getMemberId()).append(" ") - .append(member.getMemberIp()).append(":").append(port.getValue()).append(NEW_LINE); + .append(member.getDefaultPrivateIP()).append(":").append(port.getValue()).append(NEW_LINE); } } backEndHttp.append(NEW_LINE); @@ -202,7 +202,7 @@ public class HAProxyConfigWriter { for (Member member : cluster.getMembers()) { if (member.getNetworkPartitionId().equals(HAProxyContext.getInstance().getNetworkPartitionId())) { backEndHttps.append("\tserver ").append(member.getMemberId()).append(" ") - .append(member.getMemberIp()).append(":").append(port.getValue()).append(NEW_LINE); + .append(member.getDefaultPrivateIP()).append(":").append(port.getValue()).append(NEW_LINE); } } backEndHttps.append(NEW_LINE);