Search in sources :

Example 6 with LoadBalancingRule

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);
}
Also used : LoadBalancerDao(com.cloud.network.dao.LoadBalancerDao) LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) LoadBalancingRulesManager(com.cloud.network.lb.LoadBalancingRulesManager) Ip(com.cloud.utils.net.Ip) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) NetworkModel(com.cloud.network.NetworkModel) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)

Example 7 with LoadBalancingRule

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);
    }
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Example 8 with LoadBalancingRule

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);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 9 with LoadBalancingRule

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);
    }
}
Also used : NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) DomainRouterVO(com.cloud.vm.DomainRouterVO) Test(org.junit.Test)

Example 10 with LoadBalancingRule

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;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) HashMap(java.util.HashMap) Ip(com.cloud.utils.net.Ip) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)29 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)15 ArrayList (java.util.ArrayList)14 LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)11 Ip (com.cloud.utils.net.Ip)11 DomainRouterVO (com.cloud.vm.DomainRouterVO)10 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)8 Network (com.cloud.network.Network)8 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)8 Test (org.junit.Test)7 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)6 NetworkVO (com.cloud.network.dao.NetworkVO)6 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)6 LoadBalancerConfigCommand (com.cloud.agent.api.routing.LoadBalancerConfigCommand)5 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)5 Nic (com.cloud.vm.Nic)5 HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)4 Commands (com.cloud.agent.manager.Commands)4 DataCenterVO (com.cloud.dc.DataCenterVO)4