use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.
the class LoadBalancingRules method accept.
@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
_router = router;
LoadBalancerDao loadBalancerDao = visitor.getVirtualNetworkApplianceFactory().getLoadBalancerDao();
// For load balancer we have to resend all lb rules for the network or vpc
final List<LoadBalancerVO> lbs = loadBalancerDao.listByNetworkIdOrVpcIdAndScheme(_network.getId(), _network.getVpcId(), Scheme.Public);
// We are cleaning it before because all the rules have to be sent to the router.
_rules.clear();
LoadBalancingRulesManager lbMgr = visitor.getVirtualNetworkApplianceFactory().getLbMgr();
NetworkModel networkModel = visitor.getVirtualNetworkApplianceFactory().getNetworkModel();
for (final LoadBalancerVO lb : lbs) {
final List<LbDestination> dstList = lbMgr.getExistingDestinations(lb.getId());
final List<LbStickinessPolicy> policyList = lbMgr.getStickinessPolicies(lb.getId());
final List<LbHealthCheckPolicy> hcPolicyList = lbMgr.getHealthCheckPolicies(lb.getId());
final LbSslCert sslCert = lbMgr.getLbSslCert(lb.getId());
final Ip sourceIp = networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
_rules.add(loadBalancing);
}
return visitor.visit(this);
}
use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.
the class InternalLoadBalancerVMManagerImpl method finalizeLbRulesForIp.
protected void finalizeLbRulesForIp(final Commands cmds, final DomainRouterVO internalLbVm, final Provider provider, final Ip sourceIp, final long guestNtwkId) {
s_logger.debug("Resending load balancing rules as a part of start for " + internalLbVm);
final List<ApplicationLoadBalancerRuleVO> lbs = _lbDao.listBySrcIpSrcNtwkId(sourceIp, guestNtwkId);
final List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
if (_ntwkModel.isProviderSupportServiceInNetwork(guestNtwkId, Service.Lb, provider)) {
// Re-apply load balancing rules
for (final ApplicationLoadBalancerRuleVO lb : lbs) {
final List<LbDestination> dstList = _lbMgr.getExistingDestinations(lb.getId());
final List<LbStickinessPolicy> policyList = _lbMgr.getStickinessPolicies(lb.getId());
final List<LbHealthCheckPolicy> hcPolicyList = _lbMgr.getHealthCheckPolicies(lb.getId());
final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp);
lbRules.add(loadBalancing);
}
}
s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of Intenrnal LB vm" + internalLbVm + " start.");
if (!lbRules.isEmpty()) {
createApplyLoadBalancingRulesCommands(lbRules, internalLbVm, cmds, guestNtwkId);
}
}
use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.
the class InternalLBVMManagerTest method applyWithEmptyVmsSet.
@Test(expected = CloudRuntimeException.class)
public void applyWithEmptyVmsSet() {
boolean result = false;
final List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
final LoadBalancingRule rule = new LoadBalancingRule(null, null, null, null, null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} catch (final ResourceUnavailableException e) {
} finally {
assertFalse("Got success when tried to apply with the empty internal lb vm list", result);
}
}
use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.
the class InternalLBVMManagerTest method applyToVmInStoppingState.
@Test
public void applyToVmInStoppingState() throws ResourceUnavailableException {
boolean result = false;
final List<DomainRouterVO> vms = new ArrayList<DomainRouterVO>();
vm.setState(State.Stopping);
vms.add(vm);
final List<LoadBalancingRule> rules = new ArrayList<LoadBalancingRule>();
final LoadBalancingRule rule = new LoadBalancingRule(null, null, null, null, null, null, null);
rules.add(rule);
try {
result = _lbVmMgr.applyLoadBalancingRules(new NetworkVO(), rules, vms);
} finally {
assertTrue("Rules failed to apply to vm in Stopping state", result);
}
}
use of com.cloud.network.lb.LoadBalancingRule in project cloudstack by apache.
the class InternalLoadBalancerElement method groupBySourceIp.
protected Map<Ip, List<LoadBalancingRule>> groupBySourceIp(List<LoadBalancingRule> rules) {
Map<Ip, List<LoadBalancingRule>> groupedRules = new HashMap<Ip, List<LoadBalancingRule>>();
for (LoadBalancingRule rule : rules) {
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");
}
}
return groupedRules;
}
Aggregations