You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/03/21 18:05:27 UTC
git commit: refs/heads/master - CLOUDSTACK-1537. Fixing Network
Restart case for AutoScale
Updated Branches:
refs/heads/master 0d1cd121c -> 61d8dde03
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/61d8dde0
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/61d8dde0
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/61d8dde0
Branch: refs/heads/master
Commit: 61d8dde033317fe7559bebe0d050444ffc1fabfb
Parents: 0d1cd12
Author: Vijay venkatachalam <vi...@citrix.com>
Authored: Tue Mar 19 21:04:35 2013 +0530
Committer: Chip Childers <ch...@gmail.com>
Committed: Thu Mar 21 16:59:15 2013 +0000
----------------------------------------------------------------------
.../com/cloud/network/lb/LoadBalancingRule.java | 8 ++
.../cloud/network/resource/NetscalerResource.java | 27 +++----
.../src/com/cloud/network/NetworkManagerImpl.java | 21 +-----
.../network/lb/LoadBalancingRulesManager.java | 1 +
.../network/lb/LoadBalancingRulesManagerImpl.java | 59 ++++++++++-----
5 files changed, 61 insertions(+), 55 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/61d8dde0/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 84526c5..3e11e8c 100644
--- a/api/src/com/cloud/network/lb/LoadBalancingRule.java
+++ b/api/src/com/cloud/network/lb/LoadBalancingRule.java
@@ -131,6 +131,10 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
return lb;
}
+ public void setDestinations(List<LbDestination> destinations) {
+ this.destinations = destinations;
+ }
+
public List<LbDestination> getDestinations() {
return destinations;
}
@@ -139,6 +143,10 @@ public class LoadBalancingRule implements FirewallRule, LoadBalancer {
return stickinessPolicies;
}
+ public void setHealthCheckPolicies(List<LbHealthCheckPolicy> healthCheckPolicies) {
+ this.healthCheckPolicies = healthCheckPolicies;
+ }
+
public List<LbHealthCheckPolicy> getHealthCheckPolicies() {
return healthCheckPolicies;
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/61d8dde0/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 4eb0ce2..c09869b 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
@@ -1756,23 +1756,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();
@@ -1827,7 +1815,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/61d8dde0/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 591910b..5136572 100755
--- a/server/src/com/cloud/network/NetworkManagerImpl.java
+++ b/server/src/com/cloud/network/NetworkManagerImpl.java
@@ -3091,27 +3091,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());
- List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies (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, hcPolicyList);
- 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/61d8dde0/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 da19f86..d98872a 100644
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManager.java
@@ -51,4 +51,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/61d8dde0/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 a06cbc5..80e75cd 100755
--- a/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
+++ b/server/src/com/cloud/network/lb/LoadBalancingRulesManagerImpl.java
@@ -338,7 +338,8 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
* Regular config like destinations need not be packed for applying
* autoscale config as of today.
*/
- LoadBalancingRule rule = new LoadBalancingRule(lb, null, null, null);
+ List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
+ LoadBalancingRule rule = new LoadBalancingRule(lb, null, policyList, null);
rule.setAutoScaleVmGroup(lbAutoScaleVmGroup);
if (!isRollBackAllowedForProvider(lb)) {
@@ -1199,18 +1200,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)) {
@@ -1471,6 +1463,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) {
@@ -1500,18 +1506,33 @@ 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, null);
+
+ 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);
+ List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
+ loadBalancing.setHealthCheckPolicies(hcPolicyList);
+ }
+
+ 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());
- List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
-
- LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList);
- rules.add(loadBalancing);
+ rules.add(getLoadBalancerRuleToApply(lb));
}
if (!_networkMgr.applyRules(rules, FirewallRule.Purpose.LoadBalancing, this, false)) {