cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alena1...@apache.org
Subject git commit: updated refs/heads/master-6-17-stable to 23bcce2
Date Thu, 20 Jun 2013 20:27:00 GMT
Updated Branches:
  refs/heads/master-6-17-stable db4969e3d -> 23bcce2ee


CLOUDSTACK-3085: network implement - deploy internal lb vm for the ip only when:

* the load balancer contains lb rule in state "Active"
* when lb rule has at least one vm assigned to it


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/23bcce2e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/23bcce2e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/23bcce2e

Branch: refs/heads/master-6-17-stable
Commit: 23bcce2ee405e30f3547627c52c8c2ab1c45d790
Parents: db4969e
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Thu Jun 20 11:34:30 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Jun 20 13:08:59 2013 -0700

----------------------------------------------------------------------
 .../lb/dao/ApplicationLoadBalancerRuleDao.java  |  1 +
 .../dao/ApplicationLoadBalancerRuleDaoImpl.java | 18 +++++
 .../element/InternalLoadBalancerElement.java    | 74 +++++++++-----------
 3 files changed, 52 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/23bcce2e/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
index 47f1d36..aa765ad 100644
--- a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
+++ b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDao.java
@@ -32,5 +32,6 @@ public interface ApplicationLoadBalancerRuleDao extends GenericDao<ApplicationLo
     List<ApplicationLoadBalancerRuleVO> listBySourceIpAndNotRevoked(Ip sourceIp, long
sourceNetworkId);
     List<String> listLbIpsBySourceIpNetworkIdAndScheme(long sourceIpNetworkId, Scheme
scheme);
     long countBySourceIpAndNotRevoked(Ip sourceIp, long sourceIpNetworkId);
+    long countActiveBySourceIp(Ip sourceIp, long sourceIpNetworkId);
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/23bcce2e/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
index 6036b5a..67d0a78 100644
--- a/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
+++ b/engine/schema/src/org/apache/cloudstack/lb/dao/ApplicationLoadBalancerRuleDaoImpl.java
@@ -43,6 +43,7 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
     final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountBy;
     protected final SearchBuilder<ApplicationLoadBalancerRuleVO> NotRevokedSearch;
     final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountNotRevoked;
+    final GenericSearchBuilder<ApplicationLoadBalancerRuleVO, Long> CountActive;
     
     
     protected ApplicationLoadBalancerRuleDaoImpl() {
@@ -77,6 +78,13 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
         CountNotRevoked.and("state", CountNotRevoked.entity().getState(), Op.NEQ);
         CountNotRevoked.and("sourceIpNetworkId", CountNotRevoked.entity().getSourceIpNetworkId(),
Op.EQ);
         CountNotRevoked.done();
+        
+        CountActive = createSearchBuilder(Long.class);
+        CountActive.select(null, Func.COUNT, CountActive.entity().getId());
+        CountActive.and("sourceIp", CountActive.entity().getSourceIp(), Op.EQ);
+        CountActive.and("state", CountActive.entity().getState(), Op.EQ);
+        CountActive.and("sourceIpNetworkId", CountActive.entity().getSourceIpNetworkId(),
Op.EQ);
+        CountActive.done();
     }
 
     @Override
@@ -129,5 +137,15 @@ public class ApplicationLoadBalancerRuleDaoImpl extends GenericDaoBase<Applicati
         List<Long> results = customSearch(sc, null);
         return results.get(0);
     }
+    
+    @Override
+    public long countActiveBySourceIp(Ip sourceIp, long sourceIpNetworkId) {
+        SearchCriteria<Long> sc = CountActive.create();
+        sc.setParameters("sourceIp", sourceIp);
+        sc.setParameters("sourceIpNetworkId", sourceIpNetworkId);
+        sc.setParameters("state", State.Active);
+        List<Long> results = customSearch(sc, null);
+        return results.get(0);
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/23bcce2e/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
index 14b616c..18ac13b 100644
--- a/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
+++ b/plugins/network-elements/internal-loadbalancer/src/org/apache/cloudstack/network/element/InternalLoadBalancerElement.java
@@ -165,30 +165,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
             return true;
         }
         
-        //1) Get all the Ips from the network having LB rules assigned
-        List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(),
Scheme.Internal);
-        
-        //2) Start those vms
-        for (String ip : ips) {
-            Ip sourceIp = new Ip(ip);
-            List<? extends VirtualRouter> internalLbVms;
-            try {
-                internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp, dest,
_accountMgr.getAccount(network.getAccountId()), null);
-            } catch (InsufficientCapacityException e) {
-                s_logger.warn("Failed to deploy element " + this.getName() + " for ip " +
sourceIp + " due to:", e);
-                return false;
-            } catch (ConcurrentOperationException e) {
-                s_logger.warn("Failed to deploy element " + this.getName() + " for ip " +
sourceIp + " due to:", e);
-                return false;
-            }
-            
-            if (internalLbVms == null || internalLbVms.isEmpty()) {
-                throw new ResourceUnavailableException("Can't deploy " + this.getName() +
" to handle LB rules",
-                        DataCenter.class, network.getDataCenterId());
-            }
-        }
-       
-        return true;
+        return implementInternalLbVms(network, dest);
     }
 
     
@@ -202,12 +179,23 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
         }
         
         if (vm.getType() == VirtualMachine.Type.User) {
-          //1) Get all the Ips from the network having LB rules assigned
-            List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(),
Scheme.Internal);
-            
-            //2) Start those vms
-            for (String ip : ips) {
-                Ip sourceIp = new Ip(ip);
+            return implementInternalLbVms(network, dest);
+        }
+        return true;
+    }
+
+
+    protected boolean implementInternalLbVms(Network network, DeployDestination dest) throws
ResourceUnavailableException {
+        //1) Get all the Ips from the network having LB rules assigned
+        List<String> ips = _appLbDao.listLbIpsBySourceIpNetworkIdAndScheme(network.getId(),
Scheme.Internal);
+        
+        //2) Start internal lb vms for the ips having active rules
+        for (String ip : ips) {
+            Ip sourceIp = new Ip(ip);
+            long active = _appLbDao.countActiveBySourceIp(sourceIp, network.getId());
+            if (active > 0) {
+                s_logger.debug("Have to implement internal lb vm for source ip " + sourceIp
+ " as a part of network " + network
+                        + " implement as there are " + active + " internal lb rules exist
for this ip");
                 List<? extends VirtualRouter> internalLbVms;
                 try {
                     internalLbVms = _internalLbMgr.deployInternalLbVm(network, sourceIp,
dest, _accountMgr.getAccount(network.getAccountId()), null);
@@ -223,7 +211,7 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
                     throw new ResourceUnavailableException("Can't deploy " + this.getName()
+ " to handle LB rules",
                             DataCenter.class, network.getDataCenterId());
                 }
-            }
+            }  
         }
         
         return true;
@@ -410,17 +398,21 @@ public class InternalLoadBalancerElement extends AdapterBase implements
LoadBala
     protected Map<Ip, List<LoadBalancingRule>> groupBySourceIp(List<LoadBalancingRule>
rules) {
         Map<Ip, List<LoadBalancingRule>> groupedRules = new HashMap<Ip, List<LoadBalancingRule>>();
         for (LoadBalancingRule rule : rules) {
-            Ip sourceIp = rule.getSourceIp();
-            if (!groupedRules.containsKey(sourceIp)) {
-                groupedRules.put(sourceIp, null);
-            }
-            
-            List<LoadBalancingRule> rulesToApply = groupedRules.get(sourceIp);
-            if (rulesToApply == null) {
-                rulesToApply = new ArrayList<LoadBalancingRule>();
+            if (rule.getDestinations() != null && !rule.getDestinations().isEmpty())
{
+                Ip sourceIp = rule.getSourceIp();
+                if (!groupedRules.containsKey(sourceIp)) {
+                    groupedRules.put(sourceIp, null);
+                }
+                
+                List<LoadBalancingRule> rulesToApply = groupedRules.get(sourceIp);
+                if (rulesToApply == null) {
+                    rulesToApply = new ArrayList<LoadBalancingRule>();
+                }
+                rulesToApply.add(rule);
+                groupedRules.put(sourceIp, rulesToApply);
+            } else {
+                s_logger.debug("Internal lb rule " + rule + " doesn't have any vms assigned,
skipping");
             }
-            rulesToApply.add(rule);
-            groupedRules.put(sourceIp, rulesToApply);
         }
         return groupedRules;
     }


Mime
View raw message