cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chipchild...@apache.org
Subject git commit: refs/heads/4.1 - CLOUDSTACK-1537. Fixing Network Restart case for AutoScale
Date Thu, 21 Mar 2013 16:57:40 GMT
Updated Branches:
  refs/heads/4.1 7b8bc9eb8 -> 886c3a569


CLOUDSTACK-1537. Fixing Network Restart case for AutoScale


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

Branch: refs/heads/4.1
Commit: 886c3a56961c2ea941ca6f41af8e80afd3b50de7
Parents: 7b8bc9e
Author: Vijay venkatachalam <vijay.venkatachalam@citrix.com>
Authored: Tue Mar 19 21:04:35 2013 +0530
Committer: Chip Childers <chip.childers@gmail.com>
Committed: Thu Mar 21 16:53:42 2013 +0000

----------------------------------------------------------------------
 .../com/cloud/network/lb/LoadBalancingRule.java    |    4 +
 .../cloud/network/resource/NetscalerResource.java  |   27 +++-----
 .../src/com/cloud/network/NetworkManagerImpl.java  |   20 +-----
 .../network/lb/LoadBalancingRulesManager.java      |    1 +
 .../network/lb/LoadBalancingRulesManagerImpl.java  |   53 ++++++++++-----
 5 files changed, 53 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/886c3a56/api/src/com/cloud/network/lb/LoadBalancingRule.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/network/lb/LoadBalancingRule.java b/api/src/com/cloud/network/lb/LoadBalancingRule.java
index fb1d988..3bfada1 100644
--- a/api/src/com/cloud/network/lb/LoadBalancingRule.java
+++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java
@@ -128,6 +128,10 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer
{
         return lb;
     }
 
+    public void setDestinations(List<LbDestination> destinations) {
+        this.destinations = destinations;
+    }
+
     public List<LbDestination> getDestinations() {
         return destinations;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/886c3a56/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
index abea464..30e4c73 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
@@ -1486,23 +1486,11 @@ public class NetscalerResource implements ServerResource {
         if(!isAutoScaleSupportedInNetScaler()) {
             throw new ExecutionException("AutoScale not supported in this version of NetScaler");
         }
-        if(vmGroupTO.getState().equals("new")) {
-            assert !loadBalancer.isRevoked();
-            createAutoScaleConfig(loadBalancer);
-        }
-        else if(loadBalancer.isRevoked() || vmGroupTO.getState().equals("revoke")) {
+        if(loadBalancer.isRevoked() || vmGroupTO.getState().equals("revoke")) {
             removeAutoScaleConfig(loadBalancer);
         }
-        else if(vmGroupTO.getState().equals("enabled")) {
-            assert !loadBalancer.isRevoked();
-            enableAutoScaleConfig(loadBalancer, false);
-        }
-        else if(vmGroupTO.getState().equals("disabled")) {
-            assert !loadBalancer.isRevoked();
-            disableAutoScaleConfig(loadBalancer, false);
-        } else {
-            ///// This should never happen
-            throw new ExecutionException("Unknown AutoScale Vm Group State :" + vmGroupTO.getState());
+        else {
+            createAutoScaleConfig(loadBalancer);
         }
         // AutoScale APIs are successful executed, now save the configuration.
         saveConfiguration();
@@ -1557,7 +1545,14 @@ public class NetscalerResource implements ServerResource {
         }
 
         // Create the autoscale config
-        enableAutoScaleConfig(loadBalancerTO, false);
+        if(!loadBalancerTO.getAutoScaleVmGroupTO().getState().equals("disabled")) {
+            // on restart of network, there might be vmgrps in disabled state, no need to
create autoscale config for them
+            enableAutoScaleConfig(loadBalancerTO, false);
+        }
+        else if(loadBalancerTO.getAutoScaleVmGroupTO().getState().equals("disabled")) {
+            disableAutoScaleConfig(loadBalancerTO, false);
+        }
+
         return true;
     }
 

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/886c3a56/server/src/com/cloud/network/NetworkManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/NetworkManagerImpl.java b/server/src/com/cloud/network/NetworkManagerImpl.java
index f6e32fb..bdc5577 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -3045,26 +3045,8 @@ public class NetworkManagerImpl extends ManagerBase implements NetworkManager,
L
             success = false;
         }
 
-        // remove all LB rules for the network
-        List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(networkId);
-        List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
-        for (LoadBalancerVO lb : lbs) {
-            s_logger.trace("Marking lb rule " + lb + " with Revoke state");
-            lb.setState(FirewallRule.State.Revoke);
-            List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
-            List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
-            // mark all destination with revoke state
-            for (LbDestination dst : dstList) {
-                s_logger.trace("Marking lb destination " + dst + " with Revoke state");
-                dst.setRevoked(true);
-            }
-
-            LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList);
-            lbRules.add(loadBalancing);
-        }
-
         try {
-            if (!_lbMgr.applyRules(network, Purpose.LoadBalancing, lbRules)) {
+            if (!_lbMgr.revokeLoadBalancersForNetwork(networkId)) {
                 s_logger.warn("Failed to cleanup lb rules as a part of shutdownNetworkRules");
                 success = false;
             }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/886c3a56/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java
index 9d7d22f..6f0c84f 100644
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java
@@ -49,4 +49,5 @@ public interface LoadBalancingRulesManager extends LoadBalancingRulesService
{
     boolean applyLoadBalancersForNetwork(long networkId) throws ResourceUnavailableException;
     String getLBCapability(long networkid, String capabilityName);
     boolean configureLbAutoScaleVmGroup(long vmGroupid, String currentState) throws ResourceUnavailableException;
+    boolean revokeLoadBalancersForNetwork(long networkId) throws ResourceUnavailableException;
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/886c3a56/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
index 531a428..a016cbc 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -887,18 +887,9 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
 
         if (apply) {
             try {
-                if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(loadBalancerId)) {
-                    // Get the associated VmGroup
-                    AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.listByAll(loadBalancerId,
null).get(0);
-                    if (!applyAutoScaleConfig(lb, vmGroup,vmGroup.getState())) {
-                        s_logger.warn("Unable to apply the autoscale config");
-                        return false;
-                    }
-                } else {
-                    if (!applyLoadBalancerConfig(loadBalancerId)) {
-                        s_logger.warn("Unable to apply the load balancer config");
-                        return false;
-                    }
+                if (!applyLoadBalancerConfig(loadBalancerId)) {
+                    s_logger.warn("Unable to apply the load balancer config");
+                    return false;
                 }
             } catch (ResourceUnavailableException e) {
                 if (rollBack && isRollBackAllowedForProvider(lb)) {
@@ -1142,6 +1133,20 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
     }
 
     @Override
+    public boolean revokeLoadBalancersForNetwork(long networkId) throws ResourceUnavailableException
{
+        List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(networkId);
+        if (lbs != null) {
+            for(LoadBalancerVO lb : lbs) { // called during restart, not persisting state
in db
+                lb.setState(FirewallRule.State.Revoke);
+            }
+            return applyLoadBalancerRules(lbs, false); // called during restart, not persisting
state in db
+        } else {
+            s_logger.info("Network id=" + networkId + " doesn't have load balancer rules,
nothing to revoke");
+            return true;
+        }
+    }
+
+    @Override
     public boolean applyLoadBalancersForNetwork(long networkId) throws ResourceUnavailableException
{
         List<LoadBalancerVO> lbs = _lbDao.listByNetworkId(networkId);
         if (lbs != null) {
@@ -1170,16 +1175,30 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase
implements
         return handled;
     }
 
+    private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) {
+
+        List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
+        LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList);
+
+        if (_autoScaleVmGroupDao.isAutoScaleLoadBalancer(lb.getId())) {
+            // Get the associated VmGroup
+            AutoScaleVmGroupVO vmGroup = _autoScaleVmGroupDao.listByAll(lb.getId(), null).get(0);
+            LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, vmGroup.getState(),
lb);
+            loadBalancing.setAutoScaleVmGroup(lbAutoScaleVmGroup);
+        } else {
+            List<LbDestination> dstList = getExistingDestinations(lb.getId());
+            loadBalancing.setDestinations(dstList);
+        }
+
+        return loadBalancing;
+    }
+
     @DB
     protected boolean applyLoadBalancerRules(List<LoadBalancerVO> lbs, boolean updateRulesInDB)
throws ResourceUnavailableException {
         Transaction txn = Transaction.currentTxn();
         List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
         for (LoadBalancerVO lb : lbs) {
-            List<LbDestination> dstList = getExistingDestinations(lb.getId());
-            List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
-
-            LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList);
-            rules.add(loadBalancing);
+            rules.add(getLoadBalancerRuleToApply(lb));
         }
 
         if (!_networkMgr.applyRules(rules, FirewallRule.Purpose.LoadBalancing, this, false))
{


Mime
View raw message