mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-1537. Fixing Network Restart case for AutoScale
This commit is contained in:
parent
0d1cd121c2
commit
61d8dde033
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)) {
|
||||
|
|
@ -1470,6 +1462,20 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
|
|||
return applyLoadBalancerRules(lbs, true);
|
||||
}
|
||||
|
||||
@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);
|
||||
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue