Search in sources :

Example 1 with LoadBalancingRule

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

the class VirtualNetworkApplianceManagerImpl method finalizeNetworkRulesForNetwork.

protected void finalizeNetworkRulesForNetwork(final Commands cmds, final DomainRouterVO router, final Provider provider, final Long guestNetworkId) {
    s_logger.debug("Resending ipAssoc, port forwarding, load balancing rules as a part of Virtual router start");
    final ArrayList<? extends PublicIpAddress> publicIps = getPublicIpsToApply(router, provider, guestNetworkId);
    final List<FirewallRule> firewallRulesEgress = new ArrayList<FirewallRule>();
    // Fetch firewall Egress rules.
    if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Firewall, provider)) {
        firewallRulesEgress.addAll(_rulesDao.listByNetworkPurposeTrafficType(guestNetworkId, Purpose.Firewall, FirewallRule.TrafficType.Egress));
        // create egress default rule for VR
        createDefaultEgressFirewallRule(firewallRulesEgress, guestNetworkId);
    }
    // Re-apply firewall Egress rules
    s_logger.debug("Found " + firewallRulesEgress.size() + " firewall Egress rule(s) to apply as a part of domR " + router + " start.");
    if (!firewallRulesEgress.isEmpty()) {
        _commandSetupHelper.createFirewallRulesCommands(firewallRulesEgress, router, cmds, guestNetworkId);
    }
    if (publicIps != null && !publicIps.isEmpty()) {
        final List<RemoteAccessVpn> vpns = new ArrayList<RemoteAccessVpn>();
        final List<PortForwardingRule> pfRules = new ArrayList<PortForwardingRule>();
        final List<FirewallRule> staticNatFirewallRules = new ArrayList<FirewallRule>();
        final List<StaticNat> staticNats = new ArrayList<StaticNat>();
        final List<FirewallRule> firewallRulesIngress = new ArrayList<FirewallRule>();
        // StaticNatRules; PFVPN to reapply on domR start)
        for (final PublicIpAddress ip : publicIps) {
            if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.PortForwarding, provider)) {
                pfRules.addAll(_pfRulesDao.listForApplication(ip.getId()));
            }
            if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.StaticNat, provider)) {
                staticNatFirewallRules.addAll(_rulesDao.listByIpAndPurpose(ip.getId(), Purpose.StaticNat));
            }
            if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Firewall, provider)) {
                firewallRulesIngress.addAll(_rulesDao.listByIpAndPurpose(ip.getId(), Purpose.Firewall));
            }
            if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Vpn, provider)) {
                final RemoteAccessVpn vpn = _vpnDao.findByPublicIpAddress(ip.getId());
                if (vpn != null) {
                    vpns.add(vpn);
                }
            }
            if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.StaticNat, provider)) {
                if (ip.isOneToOneNat()) {
                    boolean revoke = false;
                    if (ip.getState() == IpAddress.State.Releasing) {
                        // for ips got struck in releasing state we need to delete the rule not add.
                        s_logger.debug("Rule revoke set to true for the ip " + ip.getAddress() + " becasue it is in releasing state");
                        revoke = true;
                    }
                    final StaticNatImpl staticNat = new StaticNatImpl(ip.getAccountId(), ip.getDomainId(), guestNetworkId, ip.getId(), ip.getVmIp(), revoke);
                    staticNats.add(staticNat);
                }
            }
        }
        // Re-apply static nats
        s_logger.debug("Found " + staticNats.size() + " static nat(s) to apply as a part of domR " + router + " start.");
        if (!staticNats.isEmpty()) {
            _commandSetupHelper.createApplyStaticNatCommands(staticNats, router, cmds, guestNetworkId);
        }
        // Re-apply firewall Ingress rules
        s_logger.debug("Found " + firewallRulesIngress.size() + " firewall Ingress rule(s) to apply as a part of domR " + router + " start.");
        if (!firewallRulesIngress.isEmpty()) {
            _commandSetupHelper.createFirewallRulesCommands(firewallRulesIngress, router, cmds, guestNetworkId);
        }
        // Re-apply port forwarding rules
        s_logger.debug("Found " + pfRules.size() + " port forwarding rule(s) to apply as a part of domR " + router + " start.");
        if (!pfRules.isEmpty()) {
            _commandSetupHelper.createApplyPortForwardingRulesCommands(pfRules, router, cmds, guestNetworkId);
        }
        // Re-apply static nat rules
        s_logger.debug("Found " + staticNatFirewallRules.size() + " static nat rule(s) to apply as a part of domR " + router + " start.");
        if (!staticNatFirewallRules.isEmpty()) {
            final List<StaticNatRule> staticNatRules = new ArrayList<StaticNatRule>();
            for (final FirewallRule rule : staticNatFirewallRules) {
                staticNatRules.add(_rulesMgr.buildStaticNatRule(rule, false));
            }
            _commandSetupHelper.createApplyStaticNatRulesCommands(staticNatRules, router, cmds, guestNetworkId);
        }
        // Re-apply vpn rules
        s_logger.debug("Found " + vpns.size() + " vpn(s) to apply as a part of domR " + router + " start.");
        if (!vpns.isEmpty()) {
            for (final RemoteAccessVpn vpn : vpns) {
                _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
            }
        }
        final List<LoadBalancerVO> lbs = _loadBalancerDao.listByNetworkIdAndScheme(guestNetworkId, Scheme.Public);
        final List<LoadBalancingRule> lbRules = new ArrayList<LoadBalancingRule>();
        if (_networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Lb, provider)) {
            // Re-apply load balancing rules
            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 Ip sourceIp = _networkModel.getPublicIpAddress(lb.getSourceIpAddressId()).getAddress();
                final LbSslCert sslCert = _lbMgr.getLbSslCert(lb.getId());
                final LoadBalancingRule loadBalancing = new LoadBalancingRule(lb, dstList, policyList, hcPolicyList, sourceIp, sslCert, lb.getLbProtocol());
                lbRules.add(loadBalancing);
            }
        }
        s_logger.debug("Found " + lbRules.size() + " load balancing rule(s) to apply as a part of domR " + router + " start.");
        if (!lbRules.isEmpty()) {
            _commandSetupHelper.createApplyLoadBalancingRulesCommands(lbRules, router, cmds, guestNetworkId);
        }
    }
    // Reapply dhcp and dns configuration.
    final Network guestNetwork = _networkDao.findById(guestNetworkId);
    if (guestNetwork.getGuestType() == GuestType.Shared && _networkModel.isProviderSupportServiceInNetwork(guestNetworkId, Service.Dhcp, provider)) {
        final Map<Network.Capability, String> dhcpCapabilities = _networkSvc.getNetworkOfferingServiceCapabilities(_networkOfferingDao.findById(_networkDao.findById(guestNetworkId).getNetworkOfferingId()), Service.Dhcp);
        final String supportsMultipleSubnets = dhcpCapabilities.get(Network.Capability.DhcpAccrossMultipleSubnets);
        if (supportsMultipleSubnets != null && Boolean.valueOf(supportsMultipleSubnets)) {
            final List<NicIpAliasVO> revokedIpAliasVOs = _nicIpAliasDao.listByNetworkIdAndState(guestNetworkId, NicIpAlias.State.revoked);
            s_logger.debug("Found" + revokedIpAliasVOs.size() + "ip Aliases to revoke on the router as a part of dhcp configuration");
            removeRevokedIpAliasFromDb(revokedIpAliasVOs);
            final List<NicIpAliasVO> aliasVOs = _nicIpAliasDao.listByNetworkIdAndState(guestNetworkId, NicIpAlias.State.active);
            s_logger.debug("Found" + aliasVOs.size() + "ip Aliases to apply on the router as a part of dhcp configuration");
            final List<IpAliasTO> activeIpAliasTOs = new ArrayList<IpAliasTO>();
            for (final NicIpAliasVO aliasVO : aliasVOs) {
                activeIpAliasTOs.add(new IpAliasTO(aliasVO.getIp4Address(), aliasVO.getNetmask(), aliasVO.getAliasCount().toString()));
            }
            if (activeIpAliasTOs.size() != 0) {
                _commandSetupHelper.createIpAlias(router, activeIpAliasTOs, guestNetworkId, cmds);
                _commandSetupHelper.configDnsMasq(router, _networkDao.findById(guestNetworkId), cmds);
            }
        }
    }
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) PublicIp(com.cloud.network.addr.PublicIp) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) LoadBalancerVO(com.cloud.network.dao.LoadBalancerVO) LbStickinessPolicy(com.cloud.network.lb.LoadBalancingRule.LbStickinessPolicy) StaticNatRule(com.cloud.network.rules.StaticNatRule) NicIpAliasVO(com.cloud.vm.dao.NicIpAliasVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) PublicIpAddress(com.cloud.network.PublicIpAddress) Network(com.cloud.network.Network) FirewallRule(com.cloud.network.rules.FirewallRule) LbSslCert(com.cloud.network.lb.LoadBalancingRule.LbSslCert) PortForwardingRule(com.cloud.network.rules.PortForwardingRule) StaticNat(com.cloud.network.rules.StaticNat) StaticNatImpl(com.cloud.network.rules.StaticNatImpl) LbHealthCheckPolicy(com.cloud.network.lb.LoadBalancingRule.LbHealthCheckPolicy) IpAliasTO(com.cloud.agent.api.routing.IpAliasTO) RemoteAccessVpn(com.cloud.network.RemoteAccessVpn)

Example 2 with LoadBalancingRule

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

the class NetworkHelperImpl method validateHAProxyLBRule.

@Override
public boolean validateHAProxyLBRule(final LoadBalancingRule rule) {
    final String timeEndChar = "dhms";
    int haproxy_stats_port = Integer.parseInt(_configDao.getValue(Config.NetworkLBHaproxyStatsPort.key()));
    if (rule.getSourcePortStart() == haproxy_stats_port) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Can't create LB on port " + haproxy_stats_port + ", haproxy is listening for  LB stats on this port");
        }
        return false;
    }
    String lbProtocol = rule.getLbProtocol();
    if (lbProtocol != null && lbProtocol.toLowerCase().equals(NetUtils.UDP_PROTO)) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Can't create LB rule as haproxy does not support udp");
        }
        return false;
    }
    for (final LoadBalancingRule.LbStickinessPolicy stickinessPolicy : rule.getStickinessPolicies()) {
        final List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
        if (LbStickinessMethod.StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
        } else if (LbStickinessMethod.StickinessMethodType.SourceBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
            // optional
            String tablesize = "200k";
            // optional
            String expire = "30m";
            /* overwrite default values with the stick parameters */
            for (final Pair<String, String> paramKV : paramsList) {
                final String key = paramKV.first();
                final String value = paramKV.second();
                if ("tablesize".equalsIgnoreCase(key)) {
                    tablesize = value;
                }
                if ("expire".equalsIgnoreCase(key)) {
                    expire = value;
                }
            }
            if (expire != null && !containsOnlyNumbers(expire, timeEndChar)) {
                throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: expire is not in timeformat: " + expire);
            }
            if (tablesize != null && !containsOnlyNumbers(tablesize, "kmg")) {
                throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: tablesize is not in size format: " + tablesize);
            }
        } else if (LbStickinessMethod.StickinessMethodType.AppCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
            // optional
            String length = null;
            // optional
            String holdTime = null;
            for (final Pair<String, String> paramKV : paramsList) {
                final String key = paramKV.first();
                final String value = paramKV.second();
                if ("length".equalsIgnoreCase(key)) {
                    length = value;
                }
                if ("holdtime".equalsIgnoreCase(key)) {
                    holdTime = value;
                }
            }
            if (length != null && !containsOnlyNumbers(length, null)) {
                throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: length is not a number: " + length);
            }
            if (holdTime != null && !containsOnlyNumbers(holdTime, timeEndChar) && !containsOnlyNumbers(holdTime, null)) {
                throw new InvalidParameterValueException("Failed LB in validation rule id: " + rule.getId() + " Cause: holdtime is not in timeformat: " + holdTime);
            }
        }
    }
    return true;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) Pair(com.cloud.utils.Pair)

Example 3 with LoadBalancingRule

use of com.cloud.network.lb.LoadBalancingRule 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 4 with LoadBalancingRule

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

the class NetscalerElement method applyElasticLoadBalancerRules.

public boolean applyElasticLoadBalancerRules(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return true;
    }
    String errMsg = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        try {
            lbDeviceVO = allocateLoadBalancerForNetwork(network);
        } catch (Exception e) {
            errMsg = "Could not allocate a NetSclaer load balancer for configuring elastic load balancer rules due to " + e.getMessage();
            s_logger.error(errMsg);
            throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
        }
    }
    if (!isNetscalerDevice(lbDeviceVO.getDeviceName())) {
        errMsg = "There are no NetScaler load balancer assigned for this network. So NetScaler element can not be handle elastic load balancer rules.";
        s_logger.error(errMsg);
        throw new ResourceUnavailableException(errMsg, this.getClass(), 0);
    }
    List<LoadBalancerTO> loadBalancersToApply = new ArrayList<LoadBalancerTO>();
    for (int i = 0; i < loadBalancingRules.size(); i++) {
        LoadBalancingRule rule = loadBalancingRules.get(i);
        boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
        String protocol = rule.getProtocol();
        String algorithm = rule.getAlgorithm();
        String lbUuid = rule.getUuid();
        String srcIp = rule.getSourceIp().addr();
        int srcPort = rule.getSourcePortStart();
        List<LbDestination> destinations = rule.getDestinations();
        if ((destinations != null && !destinations.isEmpty()) || rule.isAutoScaleConfig()) {
            LoadBalancerTO loadBalancer = new LoadBalancerTO(lbUuid, srcIp, srcPort, protocol, algorithm, revoked, false, false, destinations, rule.getStickinessPolicies(), rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            if (rule.isAutoScaleConfig()) {
                loadBalancer.setAutoScaleVmGroup(rule.getAutoScaleVmGroup());
            }
            loadBalancersToApply.add(loadBalancer);
        }
    }
    if (loadBalancersToApply.size() > 0) {
        int numLoadBalancersForCommand = loadBalancersToApply.size();
        LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
        LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(loadBalancersForCommand, null);
        HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        Answer answer = _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
        if (answer == null || !answer.getResult()) {
            String details = (answer != null) ? answer.getDetails() : "details unavailable";
            String msg = "Unable to apply elastic load balancer rules to the external load balancer appliance in zone " + network.getDataCenterId() + " due to: " + details + ".";
            s_logger.error(msg);
            throw new ResourceUnavailableException(msg, DataCenter.class, network.getDataCenterId());
        }
    }
    return true;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) JSONException(org.json.JSONException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException) ServerApiException(org.apache.cloudstack.api.ServerApiException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InsufficientNetworkCapacityException(com.cloud.exception.InsufficientNetworkCapacityException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) ConfigurationException(javax.naming.ConfigurationException) HostVO(com.cloud.host.HostVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) Answer(com.cloud.agent.api.Answer) SetStaticNatRulesAnswer(com.cloud.agent.api.routing.SetStaticNatRulesAnswer) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) GlobalLoadBalancerConfigCommand(com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 5 with LoadBalancingRule

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

the class FirewallRules method accept.

@Override
public boolean accept(final NetworkTopologyVisitor visitor, final VirtualRouter router) throws ResourceUnavailableException {
    _router = router;
    _purpose = _rules.get(0).getPurpose();
    if (_purpose == Purpose.LoadBalancing) {
        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);
        _loadbalancingRules = new ArrayList<LoadBalancingRule>();
        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());
            _loadbalancingRules.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)

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