Search in sources :

Example 16 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class ElasticLoadBalancerManagerImpl method createApplyLoadBalancingRulesCommands.

private void createApplyLoadBalancingRulesCommands(List<LoadBalancingRule> rules, DomainRouterVO elbVm, Commands cmds, long guestNetworkId) {
    /* XXX: cert */
    LoadBalancerTO[] lbs = new LoadBalancerTO[rules.size()];
    int i = 0;
    for (LoadBalancingRule rule : rules) {
        boolean revoked = (rule.getState().equals(FirewallRule.State.Revoke));
        String protocol = rule.getProtocol();
        String algorithm = rule.getAlgorithm();
        String elbIp = rule.getSourceIp().addr();
        int srcPort = rule.getSourcePortStart();
        String uuid = rule.getUuid();
        List<LbDestination> destinations = rule.getDestinations();
        LoadBalancerTO lb = new LoadBalancerTO(uuid, elbIp, srcPort, protocol, algorithm, revoked, false, false, destinations);
        lbs[i++] = lb;
    }
    NetworkOffering offering = _networkOfferingDao.findById(guestNetworkId);
    String maxconn = null;
    if (offering.getConcurrentConnections() == null) {
        maxconn = _configDao.getValue(Config.NetworkLBHaproxyMaxConn.key());
    } else {
        maxconn = offering.getConcurrentConnections().toString();
    }
    LoadBalancerConfigCommand cmd = new LoadBalancerConfigCommand(lbs, elbVm.getPublicIpAddress(), _nicDao.getIpAddress(guestNetworkId, elbVm.getId()), elbVm.getPrivateIpAddress(), null, null, maxconn, offering.isKeepAliveEnabled());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_IP, elbVm.getPrivateIpAddress());
    cmd.setAccessDetail(NetworkElementCommand.ROUTER_NAME, elbVm.getInstanceName());
    //FIXME: why are we setting attributes directly? Ick!! There should be accessors and
    //the constructor should set defaults.
    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());
    cmds.addCommand(cmd);
}
Also used : NetworkOffering(com.cloud.offering.NetworkOffering) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) LoadBalancerConfigCommand(com.cloud.agent.api.routing.LoadBalancerConfigCommand)

Example 17 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class F5BigIpResource method execute.

private synchronized Answer execute(LoadBalancerConfigCommand cmd, int numRetries) {
    try {
        long guestVlanTag = Long.parseLong(cmd.getAccessDetail(NetworkElementCommand.GUEST_VLAN_TAG));
        LoadBalancerTO[] loadBalancers = cmd.getLoadBalancers();
        for (LoadBalancerTO loadBalancer : loadBalancers) {
            boolean inline = loadBalancer.isInline();
            LbProtocol lbProtocol;
            try {
                if (loadBalancer.getProtocol() == null) {
                    lbProtocol = LbProtocol.tcp;
                } else {
                    lbProtocol = LbProtocol.valueOf(loadBalancer.getProtocol());
                }
            } catch (IllegalArgumentException e) {
                throw new ExecutionException("Got invalid protocol: " + loadBalancer.getProtocol());
            }
            LbAlgorithm lbAlgorithm;
            if (loadBalancer.getAlgorithm().equals("roundrobin")) {
                lbAlgorithm = LbAlgorithm.RoundRobin;
            } else if (loadBalancer.getAlgorithm().equals("leastconn")) {
                lbAlgorithm = LbAlgorithm.LeastConn;
            } else {
                throw new ExecutionException("Got invalid algorithm: " + loadBalancer.getAlgorithm());
            }
            String srcIp = inline ? tagAddressWithRouteDomain(loadBalancer.getSrcIp(), guestVlanTag) : loadBalancer.getSrcIp();
            int srcPort = loadBalancer.getSrcPort();
            String virtualServerName = genVirtualServerName(lbProtocol, srcIp, srcPort);
            boolean destinationsToAdd = false;
            for (DestinationTO destination : loadBalancer.getDestinations()) {
                if (!destination.isRevoked()) {
                    destinationsToAdd = true;
                    break;
                }
            }
            // Delete the virtual server with this protocol, source IP, and source port, along with its default pool and all pool members
            deleteVirtualServerAndDefaultPool(virtualServerName);
            if (!loadBalancer.isRevoked() && destinationsToAdd) {
                // Add the pool
                addPool(virtualServerName, lbAlgorithm);
                // Add pool members
                List<String> activePoolMembers = new ArrayList<String>();
                for (DestinationTO destination : loadBalancer.getDestinations()) {
                    if (!destination.isRevoked()) {
                        String destIp = inline ? tagAddressWithRouteDomain(destination.getDestIp(), guestVlanTag) : destination.getDestIp();
                        addPoolMember(virtualServerName, destIp, destination.getDestPort());
                        activePoolMembers.add(destIp + "-" + destination.getDestPort());
                    }
                }
                // Add the virtual server
                addVirtualServer(virtualServerName, lbProtocol, srcIp, srcPort, loadBalancer.getStickinessPolicies());
            }
        }
        saveConfiguration();
        return new Answer(cmd);
    } catch (ExecutionException e) {
        s_logger.error("Failed to execute LoadBalancerConfigCommand due to " + e);
        if (shouldRetry(numRetries)) {
            return retry(cmd, numRetries);
        } else {
            return new Answer(cmd, e);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) DestinationTO(com.cloud.agent.api.to.LoadBalancerTO.DestinationTO) Answer(com.cloud.agent.api.Answer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) IpAssocAnswer(com.cloud.agent.api.routing.IpAssocAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) ExternalNetworkResourceUsageAnswer(com.cloud.agent.api.ExternalNetworkResourceUsageAnswer) ExecutionException(com.cloud.utils.exception.ExecutionException)

Example 18 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO in project cloudstack by apache.

the class NetscalerElement method getElasticLBRulesHealthCheck.

public List<LoadBalancerTO> getElasticLBRulesHealthCheck(Network network, List<LoadBalancingRule> loadBalancingRules) throws ResourceUnavailableException {
    HealthCheckLBConfigAnswer answer = null;
    if (loadBalancingRules == null || loadBalancingRules.isEmpty()) {
        return null;
    }
    String errMsg = null;
    ExternalLoadBalancerDeviceVO lbDeviceVO = getExternalLoadBalancerForNetwork(network);
    if (lbDeviceVO == null) {
        s_logger.warn("There is no external load balancer device assigned to this network either network is not implement are already shutdown so just returning");
        return null;
    }
    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, null, rule.getHealthCheckPolicies(), rule.getLbSslCert(), rule.getLbProtocol());
            loadBalancersToApply.add(loadBalancer);
        }
    }
    if (loadBalancersToApply.size() > 0) {
        int numLoadBalancersForCommand = loadBalancersToApply.size();
        LoadBalancerTO[] loadBalancersForCommand = loadBalancersToApply.toArray(new LoadBalancerTO[numLoadBalancersForCommand]);
        HealthCheckLBConfigCommand cmd = new HealthCheckLBConfigCommand(loadBalancersForCommand);
        HostVO externalLoadBalancer = _hostDao.findById(lbDeviceVO.getHostId());
        answer = (HealthCheckLBConfigAnswer) _agentMgr.easySend(externalLoadBalancer.getId(), cmd);
        return answer.getLoadBalancers();
    }
    return null;
}
Also used : LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) ArrayList(java.util.ArrayList) LoadBalancerTO(com.cloud.agent.api.to.LoadBalancerTO) HealthCheckLBConfigCommand(com.cloud.agent.api.routing.HealthCheckLBConfigCommand) HostVO(com.cloud.host.HostVO) LbDestination(com.cloud.network.lb.LoadBalancingRule.LbDestination) ExternalLoadBalancerDeviceVO(com.cloud.network.dao.ExternalLoadBalancerDeviceVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) HealthCheckLBConfigAnswer(com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)

Example 19 with LoadBalancerTO

use of com.cloud.agent.api.to.LoadBalancerTO 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

LoadBalancerTO (com.cloud.agent.api.to.LoadBalancerTO)19 LbDestination (com.cloud.network.lb.LoadBalancingRule.LbDestination)12 ArrayList (java.util.ArrayList)12 LoadBalancerConfigCommand (com.cloud.agent.api.routing.LoadBalancerConfigCommand)10 LoadBalancingRule (com.cloud.network.lb.LoadBalancingRule)7 HealthCheckLBConfigAnswer (com.cloud.agent.api.routing.HealthCheckLBConfigAnswer)6 Nic (com.cloud.vm.Nic)5 Answer (com.cloud.agent.api.Answer)4 DataCenterVO (com.cloud.dc.DataCenterVO)4 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)4 HostVO (com.cloud.host.HostVO)4 ExternalLoadBalancerDeviceVO (com.cloud.network.dao.ExternalLoadBalancerDeviceVO)4 ConfigurationException (javax.naming.ConfigurationException)4 DestinationTO (com.cloud.agent.api.to.LoadBalancerTO.DestinationTO)3 NicTO (com.cloud.agent.api.to.NicTO)3 InsufficientCapacityException (com.cloud.exception.InsufficientCapacityException)3 InsufficientNetworkCapacityException (com.cloud.exception.InsufficientNetworkCapacityException)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)3 Network (com.cloud.network.Network)3 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)3