Search in sources :

Example 6 with LbStickinessPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method applyAutoScaleConfig.

private boolean applyAutoScaleConfig(LoadBalancerVO lb, AutoScaleVmGroupVO vmGroup, String currentState) throws ResourceUnavailableException {
    LbAutoScaleVmGroup lbAutoScaleVmGroup = getLbAutoScaleVmGroup(vmGroup, currentState, lb);
    /*
         * Regular config like destinations need not be packed for applying
         * autoscale config as of today.
         */
    List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
    Ip sourceIp = getSourceIp(lb);
    LoadBalancingRule rule = new LoadBalancingRule(lb, null, policyList, null, sourceIp, null, lb.getLbProtocol());
    rule.setAutoScaleVmGroup(lbAutoScaleVmGroup);
    if (!isRollBackAllowedForProvider(lb)) {
        // entries will be rollbacked.
        return false;
    }
    List<LoadBalancingRule> rules = Arrays.asList(rule);
    if (!applyLbRules(rules, false)) {
        s_logger.debug("LB rules' autoscale config are not completely applied");
        return false;
    }
    return true;
}
Also used : Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup)

Example 7 with LbStickinessPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy in project cloudstack by apache.

the class CommandSetupHelper method createApplyLoadBalancingRulesCommands.

public void createApplyLoadBalancingRulesCommands(final List<LoadBalancingRule> rules, final VirtualRouter router, final Commands cmds, final long guestNetworkId) {
    final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
    int i = 0;
    // We don't support VR to be inline currently
    final boolean inline = false;
    for (final LoadBalancingRule rule : rules) {
        final boolean revoked = rule.getState().equals(FirewallRule.State.Revoke);
        final String protocol = rule.getProtocol();
        final String lb_protocol = rule.getLbProtocol();
        final String algorithm = rule.getAlgorithm();
        final String uuid = rule.getUuid();
        final String srcIp = rule.getSourceIp().addr();
        final int srcPort = rule.getSourcePortStart();
        final List<LbDestination> destinations = rule.getDestinations();
        final List<LbStickinessPolicy> stickinessPolicies = rule.getStickinessPolicies();
        final LoadBalancerTO lb = new LoadBalancerTO(uuid, srcIp, srcPort, protocol, algorithm, revoked, false, inline, destinations, stickinessPolicies);
        lb.setLbProtocol(lb_protocol);
        lbs[i++] = lb;
    }
    String routerPublicIp = null;
    if (router instanceof DomainRouterVO) {
        final DomainRouterVO domr = _routerDao.findById(router.getId());
        routerPublicIp = domr.getPublicIpAddress();
        if (routerPublicIp == null) {
            routerPublicIp = router.getPublicIpAddress();
        }
    }
    final Network guestNetwork = _networkModel.getNetwork(guestNetworkId);
    final Nic nic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), router.getId());
    final NicProfile nicProfile = new NicProfile(nic, guestNetwork, nic.getBroadcastUri(), nic.getIsolationUri(), _networkModel.getNetworkRate(guestNetwork.getId(), router.getId()), _networkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _networkModel.getNetworkTag(router.getHypervisorType(), guestNetwork));
    final NetworkOffering offering = _networkOfferingDao.findById(guestNetwork.getNetworkOfferingId());
    String maxconn = null;
    if (offering.getConcurrentConnections() == null) {
        maxconn = _configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
    } else {
        maxconn = offering.getConcurrentConnections().toString();
    }
    final LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, routerPublicIp, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()), router.getPrivateIpAddress(), _itMgr.toNicTO(nicProfile, router.getHypervisorType()), router.getVpcId(), maxconn, offering.isKeepAliveEnabled());
    cmd.lbStatsVisibility = _configDao.getValue(Config.NetworkLBHaproxyStatsVisbility.key());
    cmd.lbStatsUri = _configDao.getValue(Config.NetworkLBHaproxyStatsUri.key());
    cmd.lbStatsAuth = _configDao.getValue(Config.NetworkLBHaproxyStatsAuth.key());
    cmd.lbStatsPort = _configDao.getValue(Config.NetworkLBHaproxyStatsPort.key());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, _routerControlHelper.getRouterControlIp(router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, _routerControlHelper.getRouterIpInNetwork(guestNetworkId, router.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(router.getDataCenterId());
    cmd.setAccessDetail(NetworkElementCommand.ZONE_NETWORK_TYPE, dcVo.getNetworkType().toString());
    cmds.addCommand(cmd);
}
Also used : DataCenterVO(com.cloud.dc.DataCenterVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) NetworkOffering(com.cloud.offering.NetworkOffering) Nic(com.cloud.vm.Nic) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) NicProfile(com.cloud.vm.NicProfile) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) Network(com.cloud.network.Network) DomainRouterVO(com.cloud.vm.DomainRouterVO) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 8 with LbStickinessPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy in project cloudstack by apache.

the class LoadBalancingRulesManagerImpl method getLoadBalancerRuleToApply.

private LoadBalancingRule getLoadBalancerRuleToApply(LoadBalancerVO lb) {
    List<LbStickinessPolicy> policyList = getStickinessPolicies(lb.getId());
    Ip sourceIp = getSourceIp(lb);
    LbSslCert sslCert = getLbSslCert(lb.getId());
    LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, null, policyList, null, sourceIp, sslCert, lb.getLbProtocol());
    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;
}
Also used : LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) AutoScaleVmGroupVO(com.cloud.network.as.AutoScaleVmGroupVO) Ip(com.cloud.utils.net.Ip) PublicIp(com.cloud.network.addr.PublicIp) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbAutoScaleVmGroup(com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Example 9 with LbStickinessPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy 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
    final List<LoadBalancerVO> lbs = loadBalancerDao.listByNetworkIdAndScheme(_network.getId(), 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 10 with LbStickinessPolicy

use of com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy in project cloudstack by apache.

the class ApplicationLoadBalancerManagerImpl method createApplicationLoadBalancer.

protected ApplicationLoadBalancerRule createApplicationLoadBalancer(String name, String description, Scheme scheme, Network sourceIpNtwk, String sourceIp, int sourcePort, int instancePort, String algorithm, Account lbOwner, Network guestNtwk, Boolean forDisplay) throws NetworkRuleConflictException, InsufficientVirtualNetworkCapacityException {
    //Only Internal scheme is supported in this release
    if (scheme != Scheme.Internal) {
        throw new UnsupportedServiceException("Only scheme of type " + Scheme.Internal + " is supported");
    }
    //1) Validate LB rule's parameters
    validateLbRule(sourcePort, instancePort, algorithm, guestNtwk, scheme);
    //2) Validate source network
    validateSourceIpNtwkForLbRule(sourceIpNtwk, scheme);
    //3) Get source ip address
    Ip sourceIpAddr = getSourceIp(scheme, sourceIpNtwk, sourceIp);
    ApplicationLoadBalancerRuleVO newRule = new ApplicationLoadBalancerRuleVO(name, description, sourcePort, instancePort, algorithm, guestNtwk.getId(), lbOwner.getId(), lbOwner.getDomainId(), sourceIpAddr, sourceIpNtwk.getId(), scheme);
    if (forDisplay != null) {
        newRule.setDisplay(forDisplay);
    }
    //4) Validate Load Balancing rule on the providers
    LoadBalancingRule loadBalancing = new LoadBalancingRule(newRule, new ArrayList<LbDestination>(), new ArrayList<LbStickinessPolicy>(), new ArrayList<LbHealthCheckPolicy>(), sourceIpAddr, null, null);
    if (!_lbMgr.validateLbRule(loadBalancing)) {
        throw new InvalidParameterValueException("LB service provider cannot support this rule");
    }
    //5) Persist Load Balancer rule
    return persistLbRule(newRule);
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) UnsupportedServiceException(com.cloud.exception.UnsupportedServiceException) Ip(com.cloud.utils.net.Ip) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination)

Aggregations

LbStickinessPolicy (com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy)16 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)11 Ip (com.cloud.utils.net.Ip)10 LbHealthCheckPolicy (com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy)9 LoadBalancerVO (com.cloud.network.dao.LoadBalancerVO)7 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)7 ArrayList (java.util.ArrayList)7 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)5 PublicIp (com.cloud.network.addr.PublicIp)5 LbSslCert (com.cloud.network.lb.LoadBalancingRule.LbSslCert)5 DataCenterVO (com.cloud.dc.DataCenterVO)3 Network (com.cloud.network.Network)3 LoadBalancerConfigCommand (com.cloud.agent.api.routing.LoadBalancerConfigCommand)2 LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)2 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)2 NetworkModel (com.cloud.network.NetworkModel)2 LBStickinessPolicyVO (com.cloud.network.dao.LBStickinessPolicyVO)2 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)2 LbAutoScaleVmGroup (com.cloud.network.lb.LoadBalancingRule.LbAutoScaleVmGroup)2 LoadBalancingRulesManager (com.cloud.network.lb.LoadBalancingRulesManager)2