Search in sources :

Example 16 with LbStickinessPolicy

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

the class InternalLoadBalancerVMManagerImpl method createApplyLoadBalancingRulesCommands.

private void createApplyLoadBalancingRulesCommands(final List<LoadBalancingRule> rules, final VirtualRouter internalLbVm, final Commands cmds, final long guestNetworkId) {
    final LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
    int i = 0;
    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 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);
        lbs[i++] = lb;
    }
    final Network guestNetwork = _ntwkModel.getNetwork(guestNetworkId);
    final Nic guestNic = _nicDao.findByNtwkIdAndInstanceId(guestNetwork.getId(), internalLbVm.getId());
    final NicProfile guestNicProfile = new NicProfile(guestNic, guestNetwork, guestNic.getBroadcastUri(), guestNic.getIsolationUri(), _ntwkModel.getNetworkRate(guestNetwork.getId(), internalLbVm.getId()), _ntwkModel.isSecurityGroupSupportedInNetwork(guestNetwork), _ntwkModel.getNetworkTag(internalLbVm.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, guestNic.getIPv4Address(), guestNic.getIPv4Address(), internalLbVm.getPrivateIpAddress(), _itMgr.toNicTO(guestNicProfile, internalLbVm.getHypervisorType()), internalLbVm.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, getInternalLbControlIp(internalLbVm.getId()));
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_GUEST_IP, guestNic.getIPv4Address());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, internalLbVm.getInstanceName());
    final DataCenterVO dcVo = _dcDao.findById(internalLbVm.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) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

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