InternalLb:

1) fixed the bug when the guest nic on internal lb vm wasnt set to be default
2) Don't send the rules to the internal lb vm if its in Stopped state
This commit is contained in:
Alena Prokharchyk 2013-04-24 13:02:32 -07:00
parent ca2fc30655
commit d73ca7ef73
5 changed files with 62 additions and 59 deletions

View File

@ -314,12 +314,13 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
@Override
public boolean applyLBRules(Network network, List<LoadBalancingRule> rules) throws ResourceUnavailableException {
//1) Get Internal LB VMs to destroy
Set<Ip> vmsToDestroy = getVmsToDestroy(rules);
//2) Get rules to apply
Map<Ip, List<LoadBalancingRule>> rulesToApply = getLbRulesToApply(rules);
s_logger.debug("Applying " + rulesToApply.size() + " on element " + this.getName());
for (Ip sourceIp : rulesToApply.keySet()) {
if (vmsToDestroy.contains(sourceIp)) {
@ -359,8 +360,6 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
if (!_internalLbMgr.applyLoadBalancingRules(network, rulesToApply.get(sourceIp), internalLbVms)) {
throw new CloudRuntimeException("Failed to apply load balancing rules for ip " + sourceIp.addr() +
" in network " + network.getId() + " on element " + this.getName());
} else {
return true;
}
}
}
@ -369,34 +368,13 @@ public class InternalLoadBalancerElement extends AdapterBase implements LoadBala
}
protected Map<Ip, List<LoadBalancingRule>> getLbRulesToApply(List<LoadBalancingRule> rules) {
//1) Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element
Map<Ip, List<LoadBalancingRule>> groupedRules = groupBySourceIp(rules);
//2) Apply only sets containing LB rules in transition state (Add/Revoke).
Map<Ip, List<LoadBalancingRule>> rulesToApply = new HashMap<Ip, List<LoadBalancingRule>>();
for (Ip sourceIp : groupedRules.keySet()) {
boolean apply = false;
List<LoadBalancingRule> rulesToCheck = groupedRules.get(sourceIp);
for (LoadBalancingRule ruleToCheck : rulesToCheck) {
if (ruleToCheck.getState() == FirewallRule.State.Revoke || ruleToCheck.getState() == FirewallRule.State.Add){
apply = true;
break;
}
}
if (apply) {
rulesToApply.put(sourceIp, rulesToCheck);
} else {
s_logger.debug("Not applying the lb rules for soure ip " + sourceIp + " on element " + this.getName()
+ " as there are no rules in transition state");
}
}
//Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element
Map<Ip, List<LoadBalancingRule>> rulesToApply = groupBySourceIp(rules);
return rulesToApply;
}
protected Set<Ip> getVmsToDestroy(List<LoadBalancingRule> rules) {
//1) Group rules by the source ip address as NetworkManager always passes the entire network lb config to the element
Map<Ip, List<LoadBalancingRule>> groupedRules = groupBySourceIp(rules);

View File

@ -108,6 +108,7 @@ import com.cloud.vm.NicProfile;
import com.cloud.vm.NicVO;
import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachine.State;
import com.cloud.vm.VirtualMachineGuru;
import com.cloud.vm.VirtualMachineManager;
import com.cloud.vm.VirtualMachineName;
@ -183,31 +184,26 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
}
NicProfile controlNic = null;
String defaultDns1 = null;
String defaultDns2 = null;
Network guestNetwork = null;
for (NicProfile nic : profile.getNics()) {
int deviceId = nic.getDeviceId();
boolean ipv4 = false, ipv6 = false;
if (nic.getIp4Address() != null) {
ipv4 = true;
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
}
if (nic.getIp6Address() != null) {
ipv6 = true;
buf.append(" eth").append(deviceId).append("ip6=").append(nic.getIp6Address());
buf.append(" eth").append(deviceId).append("ip6prelen=").append(NetUtils.getIp6CidrSize(nic.getIp6Cidr()));
}
buf.append(" eth").append(deviceId).append("ip=").append(nic.getIp4Address());
buf.append(" eth").append(deviceId).append("mask=").append(nic.getNetmask());
if (nic.isDefaultNic()) {
if (ipv4) {
buf.append(" gateway=").append(nic.getGateway());
}
if (ipv6) {
buf.append(" ip6gateway=").append(nic.getIp6Gateway());
}
buf.append(" gateway=").append(nic.getGateway());
defaultDns1 = nic.getDns1();
defaultDns2 = nic.getDns2();
}
if (nic.getTrafficType() == TrafficType.Management) {
if (nic.getTrafficType() == TrafficType.Guest) {
guestNetwork = _ntwkModel.getNetwork(nic.getNetworkId());
buf.append(" sshonguest=true");
} else if (nic.getTrafficType() == TrafficType.Management) {
buf.append(" localgw=").append(dest.getPod().getGateway());
} else if (nic.getTrafficType() == TrafficType.Control) {
controlNic = nic;
@ -233,14 +229,28 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
if (controlNic == null) {
throw new CloudRuntimeException("Didn't start a control port");
}
if (guestNetwork != null) {
String domain = guestNetwork.getNetworkDomain();
if (domain != null) {
buf.append(" domain=" + domain);
}
}
buf.append(" dns1=").append(defaultDns1);
if (defaultDns2 != null) {
buf.append(" dns2=").append(defaultDns2);
}
//FIXME - change if use other template for internal lb vm
String type = "vpcrouter";
String type = "elbvm";
buf.append(" type=" + type);
if (s_logger.isDebugEnabled()) {
s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
}
//FIXME - change it to DEBUG level later
// if (s_logger.isDebugEnabled()) {
// s_logger.debug("Boot Args for " + profile + ": " + buf.toString());
// }
s_logger.info("Boot Args for " + profile + ": " + buf.toString());
return true;
}
@ -272,7 +282,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
if (answer != null && answer instanceof CheckSshAnswer) {
CheckSshAnswer sshAnswer = (CheckSshAnswer) answer;
if (sshAnswer == null || !sshAnswer.getResult()) {
s_logger.warn("Unable to ssh to the VM: " + sshAnswer.getDetails());
s_logger.warn("Unable to ssh to the internal LB VM: " + sshAnswer.getDetails());
result = false;
}
} else {
@ -296,7 +306,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
if (answer != null && answer instanceof GetDomRVersionAnswer) {
GetDomRVersionAnswer versionAnswer = (GetDomRVersionAnswer)answer;
if (answer == null || !answer.getResult()) {
s_logger.warn("Unable to get the template/scripts version of router " + internalLbVm.getInstanceName() +
s_logger.warn("Unable to get the template/scripts version of internal LB VM " + internalLbVm.getInstanceName() +
" due to: " + versionAnswer.getDetails());
result = false;
} else {
@ -650,6 +660,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
DomainRouterVO internalLbVm = deployInternalLbVm(owner, dest, plan, params, internalLbProvider, offeringId, guestNetwork.getVpcId(),
networks, false);
if (internalLbVm != null) {
_routerDao.addRouterToGuestNetwork(internalLbVm, guestNetwork);
internalLbs.add(internalLbVm);
}
} finally {
@ -669,7 +680,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
//Form networks
List<Pair<NetworkVO, NicProfile>> networks = new ArrayList<Pair<NetworkVO, NicProfile>>(3);
//1) Guest network
//1) Guest network - default
if (guestNetwork != null) {
s_logger.debug("Adding nic for Internal LB in Guest network " + guestNetwork);
NicProfile guestNic = new NicProfile();
@ -685,6 +696,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
guestNic.setMode(guestNetwork.getMode());
String gatewayCidr = guestNetwork.getCidr();
guestNic.setNetmask(NetUtils.getCidrNetmask(gatewayCidr));
guestNic.setDefaultNic(true);
networks.add(new Pair<NetworkVO, NicProfile>((NetworkVO) guestNetwork, guestNic));
}
@ -759,7 +771,7 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
internalLbVm = new DomainRouterVO(id, routerOffering.getId(), internalLbProvider.getId(),
VirtualMachineName.getRouterName(id, _instance), template.getId(), template.getHypervisorType(),
template.getGuestOSId(), owner.getDomainId(), owner.getId(), false, 0, false,
RedundantState.UNKNOWN, false, false, vpcId);
RedundantState.UNKNOWN, false, false, VirtualMachine.Type.InternalLoadBalancerVm, vpcId);
internalLbVm.setRole(Role.INTERNAL_LB_VM);
internalLbVm = _itMgr.allocate(internalLbVm, template, routerOffering, networks, plan, null, owner);
} catch (InsufficientCapacityException ex) {
@ -853,8 +865,19 @@ InternalLoadBalancerVMManager, VirtualMachineGuru<DomainRouterVO> {
return true;
}
//FIXME - add validation for the internal lb vm state here
return sendLBRules(internalLbVms.get(0), rules, network.getId());
//only one internal lb vm is supported per ip address at this time
VirtualRouter lbVm = internalLbVms.get(0);
if (lbVm.getState() == State.Running) {
return sendLBRules(lbVm, rules, network.getId());
} else if (lbVm.getState() == State.Stopped || lbVm.getState() == State.Stopping) {
s_logger.debug("Internal LB VM " + lbVm.getInstanceName() + " is in " + lbVm.getState() +
", so not sending apply lb rules commands to the backend");
return true;
} else {
s_logger.warn("Unable to apply lb rules, Internal LB VM is not in the right state " + lbVm.getState());
throw new ResourceUnavailableException("Unable to apply lb rules; Internal LB VM is not in the right state", DataCenter.class, lbVm.getDataCenterId());
}
}
protected boolean sendLBRules(VirtualRouter internalLbVm, List<LoadBalancingRule> rules, long guestNetworkId) throws ResourceUnavailableException {

View File

@ -1487,9 +1487,10 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
public boolean applyLoadBalancersForNetwork(long networkId, Scheme scheme) throws ResourceUnavailableException {
List<LoadBalancerVO> lbs = _lbDao.listByNetworkIdAndScheme(networkId, scheme);
if (lbs != null) {
s_logger.debug("Applying load balancer rules of scheme " + scheme + " in network id=" + networkId);
return applyLoadBalancerRules(lbs, true);
} else {
s_logger.info("Network id=" + networkId + " doesn't have load balancer rules, nothing to apply");
s_logger.info("Network id=" + networkId + " doesn't have load balancer rules of scheme " + scheme + ", nothing to apply");
return true;
}
}
@ -1526,7 +1527,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
} else {
List<LbDestination> dstList = getExistingDestinations(lb.getId());
loadBalancing.setDestinations(dstList);
List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
List<LbHealthCheckPolicy> hcPolicyList = getHealthCheckPolicies(lb.getId());
loadBalancing.setHealthCheckPolicies(hcPolicyList);
}
@ -2011,7 +2012,7 @@ public class LoadBalancingRulesManagerImpl<Type> extends ManagerBase implements
public boolean applyLbRules(List<LoadBalancingRule> rules, boolean continueOnError) throws ResourceUnavailableException {
if (rules == null || rules.size() == 0) {
s_logger.debug("There are no rules to forward to the network elements");
s_logger.debug("There are no Load Balancing Rules to forward to the network elements");
return true;
}

View File

@ -1528,7 +1528,7 @@ public class VirtualNetworkApplianceManagerImpl extends ManagerBase implements V
for (int i = 0; i < count; i++) {
List<Pair<NetworkVO, NicProfile>> networks = createRouterNetworks(owner, isRedundant, plan, guestNetwork,
new Pair<Boolean, PublicIp>(publicNetwork, sourceNatIp));
//don't start the router as we are holding the network lock that needs to be released at the end of router allocation
//don't start the router as we are holding the network lock that needs to be released at the end of router allocation
DomainRouterVO router = deployRouter(owner, destination, plan, params, isRedundant, vrProvider, offeringId,
null, networks, false, null);

View File

@ -640,6 +640,7 @@ CREATE VIEW `cloud`.`domain_router_view` AS
data_center.id data_center_id,
data_center.uuid data_center_uuid,
data_center.name data_center_name,
data_center.networktype data_center_type,
data_center.dns1 dns1,
data_center.dns2 dns2,
data_center.ip6_dns1 ip6_dns1,